Command to select and move mutiple files from list in text file
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Command to select and move mutiple files from list in text file
Sorry for my ignorance, but my unix knowledge is limited. I've searched the web for a couple of hours and not found the solution to my problem which I'm sure is solvable with a couple of compounded unix commands.
Here's the situation :
I have a server running Linux with thousands of jpg images in one folder. I want to move a selection of these images to another folder so that I can modify them. I know the names of the files I want to move, I have the filenames in a text file. Is there anyway I can use a mv command to do this, but to get the mv command to read the filenames from my textfile rather than having to enter them manually ?
The folder containing the files is /var/www/file
I want to move the selected files to /var/www/file/temp/m
All help would be gratefully appreciated.
Thanks !
Last edited by steve.paris; 11-25-2005 at 07:33 AM.
or I've used cp instead of mv and then just deleted the original file after it's copied over.
I don't know if you'd have to do that a file at a time, or whether you could copy/move whole directories (that might need a switch/arguement or something, but that should be listed in the man page).
I have to presume that you would have got the man pages installed as default during you main install - so theres a link in my sig about how to decypher the man page format if you're unfamiliar with them.
Personally I prefer to log in to root graphically and then just drag and drop the files to where I want them! (child of a "windows world" and all that ).
Thanks for taking the time to reply to my message.
To answer your question, Yes, I've been through the man pages for mv and cp, and I can't find a way of passing an array of filenames to the command (I need to move 1000's of files and I'd rather like to avoid doing it one by one...). It is not about moving whole directories, just a selection of files in one directory.
I have the filenames that I need to move in a text file.
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304
Rep:
i've done crap like editing the text file with a word processor or text editor and using find and replace to change each filename into a command. like put a mv at the beginning of each line and the destination directory at the end.
Yes, that could be a work around solution if there is no other way... .
But could you tell me how I could run the thousands of mv commands automatically from the text file ? My Unix knowledge is limited to one command at a time over SSH
Thanks,
Steve
Last edited by steve.paris; 11-25-2005 at 07:10 AM.
Thanks !!
So, just to be sure (I"ll be doing this "live")... I make my textfile (/var/www/file/filenames.txt) with one filename per line and do (from the directory) and enter the following command :
for i in 'filenames.txt' ;do mv "$i" /var/www/file/temp/m ; done
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304
Rep:
if you don't use the right thingie ` not ' then it's not gonna work. if you don't type the destination directory correctly, you may delete all the files.
Firstly, I'd like to thank you all who have helped me out on this. I've tried both suggested solutions and the one proposed by whansard works perfectly :
Quote:
for i in `cat filename`;do mv "$i" destination; done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.