You were very close. Assuming current working directory is directory_B:
ls ~/path/to/directory_A | xargs rm
Question
This may be a simple question: I accidentally copied a whole directory (call it A) to another directory (call it B), and now I want to delete all the "directory_A files" from directory B. I realize that maybe piping is a good idea, but I don't know how to do that... can I write in command line: (assume I am currently in directory B)
ls ~/path/to/directory_A | rm -f
Thanks a lot!
Solution
You were very close. Assuming current working directory is directory_B:
ls ~/path/to/directory_A | xargs rm
OTHER TIPS
cd directoryA
ls directoryA > /tmp/t.lis
cd directoryB
while read fname
do
rm "$fname"
done</tmp/t.lis
One approach to this.