LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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



Reply
 
Search this Thread
Old 11-25-2005, 07:15 AM   #1
steve.paris
LQ Newbie
 
Registered: Nov 2005
Posts: 5

Rep: Reputation: 0
Unhappy 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 08:33 AM.
 
Old 11-25-2005, 07:38 AM   #2
bigjohn
Senior Member
 
Registered: Jun 2002
Location: UK .
Distribution: *buntu (usually Kubuntu)
Posts: 2,675
Blog Entries: 9

Rep: Reputation: 45
sorry to state the obvious steve.paris, but have you looked at the man pages for both mv and cp ???

because whenever I've wanted to move stuff with CLI i've either just done
Code:
mv /home/john/something /home/john/differentdirectory/something
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 ).

regards

John
 
Old 11-25-2005, 07:43 AM   #3
steve.paris
LQ Newbie
 
Registered: Nov 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Hi there,

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.

I hope this makes my request clearer.

Thanks,

Steve
 
Old 11-25-2005, 07:53 AM   #4
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix, 98,2000 + various
Posts: 3,171

Rep: Reputation: 52
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.
 
Old 11-25-2005, 08:01 AM   #5
steve.paris
LQ Newbie
 
Registered: Nov 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Hi there,

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 08:10 AM.
 
Old 11-25-2005, 08:42 AM   #6
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix, 98,2000 + various
Posts: 3,171

Rep: Reputation: 52
source textfilename
 
Old 11-25-2005, 08:50 AM   #7
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix, 98,2000 + various
Posts: 3,171

Rep: Reputation: 52
maybe this will make you happy
for i in `cat filename`;do mv "$i" destination; done

try at your own peril
 
Old 11-25-2005, 09:36 AM   #8
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 77
Quote:
for i in `cat filename`;do mv "$i" destination; done

try at your own peril
Don't doubt yourself, that's exactly how you do it...
 
Old 11-25-2005, 09:43 AM   #9
steve.paris
LQ Newbie
 
Registered: Nov 2005
Posts: 5

Original Poster
Rep: Reputation: 0
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

Is this right ? Thanks so much !

Steve
 
Old 11-25-2005, 10:03 AM   #10
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix, 98,2000 + various
Posts: 3,171

Rep: Reputation: 52
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.
 
Old 11-25-2005, 05:01 PM   #11
abeltagui
LQ Newbie
 
Registered: Nov 2005
Posts: 2

Rep: Reputation: 0
Try This

cat text.file |xargs mv --target-directory /YourTargetDirectory

Last edited by abeltagui; 11-25-2005 at 05:18 PM.
 
Old 11-27-2005, 01:44 PM   #12
steve.paris
LQ Newbie
 
Registered: Nov 2005
Posts: 5

Original Poster
Rep: Reputation: 0
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
Thanks to you all !

Steve
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 01:01 PM
copy a file to mutiple files Radical-Rick Programming 6 07-11-2006 04:47 PM
Command to run another command against a list of files psweetma Linux - General 3 11-09-2005 06:29 PM
Send emails to list in text file using RedHat9 MrEase Linux - Newbie 1 04-24-2004 08:35 PM
Move file command? oldrelac Linux - Newbie 10 08-08-2003 12:58 PM


All times are GMT -5. The time now is 09:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration