General discussion

Locked

moving files

By cozmos9 ·
I want to move a bunch of files using mv or other commands. The files to be moved are either in an input file or piped from grep. Explicit examples would be appreciated.

Thanks to all.

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

moving files

by cpfeiffe In reply to moving files

If they are in an input file and assuming they will all follow the same pattern (ex. file1 becomes file1.old, filexyz becomes filexyz.old) you can write a small for loop in a script or run it from the command line if you'd like.

for FILE in `cat input_file`
do
mv $FILE $NEWFILE
done

This also works if you just want to move the files to a new directory and not change the name
for FILE in `cat input_file`
do
mv $FILE /new_directory
done

Or you can still change the name in the new directory to
for FILE in `cat input_file`
do
mv $FILE /new_directory/newfile
done

This basically says that you will cat the input file and for each line (identified by variable $FILE) you want to execute the mv command on that line (variable) and move it to the new destination. The ` ` are just a way of enclosing an executable command. You can also do this with your grep in this manner

for FILE in `your commands piped from grep`
do
mv $FILE wherever
done


I hope this helps.

Collapse -

moving files

by cozmos9 In reply to moving files

Poster rated this answer

Collapse -

moving files

by cozmos9 In reply to moving files

This question was closed by the author

Back to Linux Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums