Vdubjunkie Posted January 18, 2003 Report Share Posted January 18, 2003 Hello all.. Here is my latest question. I would like to move a group of files using wildcard but only when they meet a size requirement. More or less only those which downloaded completely. I will be doing this on an ongoing basis, and the filenames will be different from day to day. I'm sure a script can be written and altered as necessary.. and would like to know about that.. but I am wondering whether this would also be able to be entered directly on the command line.. as a related question.. is the only limitation where you can no longer enter a command via command line and must switch to a script where you go into multiple lines and variables and what not? Hopefully that was a little clearer than mud!! Aru, if you read this, I told you I would hit you up, and you now have a better idea of how much/little I know.. I was assuming some type of statement like, if s(size)=51200000, mv filena* ../other I know my syntax may not be exact either, but is the premise workable? Thanks in advance to aanybody willing to help this "green" scripter. oh yeah, and i know not to actually use s(size) the parenthesis were for description.. :o Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted January 18, 2003 Report Share Posted January 18, 2003 Try this while in the directory of the files you want to move: [omar@omarserenity tmp]$ find -size +80000 > large The 80000 is the size of the file you want (or larger) That puts the names of the files in a file called large. Then type this (with a carriage return at the end of each line: [omar@omarserenity tmp]$ while read line; do > mv $line /home/omar/whatever > done < large Quote Link to comment Share on other sites More sharing options...
aru Posted January 18, 2003 Report Share Posted January 18, 2003 while what Omar said is 100% correct, it can be done in just one step, just using find: [arusabal@localhost ~]$ find . -size +80000 -type f -exec mv {} path_to_new_dir/; Quote Link to comment Share on other sites More sharing options...
Vdubjunkie Posted January 18, 2003 Author Report Share Posted January 18, 2003 Very cool. Thank you both. It is good to see it from two points of view as well to help me learn this stuph. I do have a question though. Since I am working with live data and in fear of freaking it up, am I replacing the ' f ' in -type f with my own string of what files I want to move? and are the {} supposed to be verbatim...? or did i get it backward, and ' f ' is left as is where {} has my string in between them? told you I was a green scripter... but I do have the desire to learn it right rather than always asking others forever how to do what I need done! oh yeah, how do I paste somebody else's exact text with the preamble of "aru said:" or whatever it is.. Quote Link to comment Share on other sites More sharing options...
aru Posted January 18, 2003 Report Share Posted January 18, 2003 Very cool. Thank you both. It is good to see it from twopoints of view as well to help me learn this stuph. I do have a question though. Since I am working with live data and in fear of freaking it up, am I replacing the ' f ' in -type f with my own string of what files I want to move? no, "-type" is related to the type of archive (f=file, d=directory, l=link...) what do you want goes with the "-name" or "-regex" flags, as: -name "*.txt" -regex "[0-9].*txt" and are the {} supposed to be verbatim...? ... the "{}" string is automatically substituted with the match that find gets at each time, so the "-exec" will work as moving the matched file to the desired directory told you I was a green scripter...but I do have the desire to learn it right rather than always asking others forever how to do what I need done! that's good!!! remeber that everything is on the man pages (check the find man page to get a full description of the flags it can use) :) oh yeah, how do I paste somebody else's exact text withthe preamble of "aru said:" or whatever it is.. instead of use the "postreply" button use the "quote" one ;) Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted January 18, 2003 Report Share Posted January 18, 2003 So, if you want it to only grab *.rpm files that are greater than 80k, you would do $ find . -size +80000 -type f -name *.rpm -exec mv {} path_to_new_dir/; I don't think you would even need the '-type f' if you did the '-name *.rpm'. Quote Link to comment Share on other sites More sharing options...
aru Posted January 18, 2003 Report Share Posted January 18, 2003 So, if you want it to only grab *.rpm files that are greater than 80k, you would do $ find . -size +80000 -type f -name *.rpm -exec mv {} path_to_new_dir/; I don't think you would even need the '-type f' if you did the '-name *.rpm'. remember to quote "*.rpm"; if not, the shell will expand it causing a mess ;) Quote Link to comment Share on other sites More sharing options...
Vdubjunkie Posted January 19, 2003 Author Report Share Posted January 19, 2003 I've said it b4, and I'm certian I'll say it again.. Aru, you rock.. so maybe I was saying it to myself before, but now.. it's getting posted. I need to look through my personal settings, because I don't see a button for quote, just the post reply and whatever the one is for new.. No biggie. Not nearly as important. So, here was my final command. find . -size +51199999c -type f -name "cs-pd*" -exec mv {} ../other/buried/folder Well, with the exception of the bogus folder.. I love this stuff. BTW, not that it is a big deal, but I was happy that I was able to figure out for myself that I had to add the ' c ' to the end of the -size n statement to utilize the same size I was getting posted from my ls -ltr cmd. A lot of stuff on deep commands in the man pages are still a bit cryptic to me, but I'll catch on. Who knows, I might be able to pick up on this scripting stuph. Quote Link to comment Share on other sites More sharing options...
Vdubjunkie Posted January 19, 2003 Author Report Share Posted January 19, 2003 ok, im gonna go all out.. i dig this stuff so hard. im not kidding you, i've probably typed out this command 40 times with slight variations already.. i feel like I really understand it and am getting used to it. what I'm thinking next is this.. I don't want you to just spell it out for me, but having a reasonable understanding of how "green" I am, help me onto the path of scripting something which would take user interface for the variables I change i.e. the regexp, the size and the final path. If anything tricky would be encountered by this, maybe help me along with it too. It would be cool to have the script in a directory other than the one I am working in, but not require me to put the directory in, just assume current dir. I'm sure this is simply a common string added in directly following the find command, but.. did I mention that I LOVE this stuff? Quote Link to comment Share on other sites More sharing options...
aru Posted January 19, 2003 Report Share Posted January 19, 2003 ok, im gonna go all out..i dig this stuff so hard. im not kidding you, i've probably typed out this command 40 times with slight variations already.. i feel like I really understand it and am getting used to it. good!! what I'm thinking next is this.. I don't want you to just spell it out for me, but having a reasonable understanding of how "green" I am, help me onto the path of scripting something which would take user interface for the variables I change i.e. the regexp, the size and the final path. So you want hints? OK :D For example, to read user's input within a script use the "read" builtin; ie: echo -n "enter a value: " read variable echo "The value you entered was "$variable"" But that is damn slow in daily basis usage; so you might want to read the parameters used from the command line (with "postitonal parameters" or with "getopts"), or from STDIN (with redirections or pipes). Here are three great resources of info: [*]Bash reference manual [*]Me! :roll: --> you can ask me whatever you want about bash. I'll be glad to answer you If you want to learn (I know why I'm saying this) If anything tricky would be encountered by this, maybe help me along with it too. Of course, I'll be very glad. But I know that you want to do it your own, make your own mistakes, and search yourself for the answers (that's the REAL way to learn); and then if you think you need help or advice, then ask, so that way the answer will really teach you. :D It would be cool to have the script in a directory other than the one I am working in, but not require me to put the directory in, just assume current dir. I'm sure this is simply a common string added in directly following the find command, but.. There are lots of approaches to this. First, my advice is to create a user's bin directory and add it to the users $PATH, so your user will be able to call the script from everywhere. The script whereever it is placed will inherit the current $PWD variable (that is, the path of the dir where it was called from, so you don't need to tell it where it has to do the job if the job has to be done from the current directory). If you call the script from another directory different of the directory where it has to do the stuff, then I use to have this code in my scripts: CWD="some_path" # directory of work cd $CWD simple, isn't it? did I mention that I LOVE this stuff? Me too!!!!!!!! :roll: Quote Link to comment Share on other sites More sharing options...
Vdubjunkie Posted January 23, 2003 Author Report Share Posted January 23, 2003 [*]Me! :roll: --> you can ask me whatever you want about bash. I'll be glad to answer you If you want to learn (I know why I'm saying this) Well, so far this has proved to be not only a good resource, but an interactive and pleasant one too. Honestly, the attitude of so much of the "help" out there on the internet was what kept me from going full force with linux several years ago. It's people like you that help to change all that Of course, I'll be very glad. But I know that you want to do it your own, make your own mistakes, and search yourself for the answers (that's the REAL way to learn); and then if you think you need help or advice, then ask, so that way the answer will really teach you. :D I imagine by now you can tell, but I'll say it anyway.. I really appreciate this, and will take you up on the offer again... ..and again.. :P I will have a good time finding the answers to the questions posed in my mind from reading your response. Looks like this little project of mine will really help me to learn some good starter scripting. I'll let you know how it goes! simple, isn't it? I'm hoping it will become that way :roll: Vdubjunkie says: linux is like evolution.. once Windows offers no more challenges, you evolve or stay planar Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.