-   Linux - General (
-   -   how to use the output of a file for input of a command (

sneak 05-12-2004 07:06 AM

how to use the output of a file for input of a command

I have copied the contens of a bin directory to my /usr/bin directory.
and now I want to remove all the files that i copied in there.
but i don't want to type all of the files after the rm command. so I figured: why dont I just take the input of the list command from the first bin directory and use it on the remove command in the other.

so why wont this work?

ls > remfiles
cp remfiles /usr/bin
cd /usr/bin
rm < remfiles

(as root off course)

javpra 05-12-2004 08:09 AM

ls > remfiles only copies the output of the "ls" command to the file "remfiles" not the actual files/programs.. The "<" is used for redirection of output/input. I am not sure how many files you are trying to move and delete. If it is a relatively small amount you can type a partial file name and press the TAB key and the shell will automatically complete the rest of the file name. If all the files are of the same type , for example .wav files, you can type
rm *.wav
and all files of that type will be removed. Likewise if you want to copy all files of a type you can use the command
cp *.wav /usr/bin
and all .wav files will be copied to /usr/bin. I hope this is of some help.

Ma3oiS 05-12-2004 09:21 AM


ls > remfiles            # OK
cp remfiles /usr/bin    # OK
cd /usr/bin              # OK
rm < remfiles            # bad - should be rm -f `cat remfiles`
# and you should add:
rm remfiles

With rm, files to operate on must be specified as parameters because rm doesn't read standard input.
'rm -f' will not ask you if you really want to delete files

All times are GMT -5. The time now is 11:09 AM.