Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm not very familiar with all the tricks of grep/find/awk/xargs quite yet, so be patient with me =]

I have a particular file type say *.xxx, in random places throughout a certain directory. How can I find all such files, and move them to a folder in my home directory on Unix (that may not exist yet)?

share|improve this question

Use find with the exec option, but first create the target folder.

mkdir -p /home/somewhere/else
find /somewhere -iname "*.xxx"

This will list everything that would be moved. Now if you're sure these are the files you want to move, execute the following:

find /somewhere -iname "*.xxx" -exec mv '{}' /home/somewhere/else/ \;

In the exec line, '{}' will be substituted with the actual file name, and it will be moved to the target. Likewise, to copy, just exchange mv with cp. The \; is needed to terminate the command.

If you want a confirmation before each file operation that would overwrite an already existing file, you can add the -i option after mv or cp, respectively.

No need for grep, xargs and their likes. This would unnecessarily complicate things.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.