Search code examples
unixpiping

delete files and directories in a directory according to the names of another directory


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