moving files
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.
Linux
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.
by cpfeiffe
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.
by cozmos9
by cozmos9
This discussion is closed to new replies.
Sort by Trending