How to find a specific file, and move it to the specific directory /var/tmp?

For example I want to find the file 0914_Jul-2014.gz.

Remark, the file 0914_Jul-2014.gz, is under ~300 subdirectories:


An example: when I do a

find /usr -name '0914_Jul-2014.gz' -exec mv {} /var/tmp

The result is

mv: cannot stat: File name too long



You can use find:

find /usr -name '0914_Jul-2014.gz' -exec mv {} /var/tmp \;

Or for extremely nested directory hierarchies

find /usr -name '0914_Jul-2014.gz' -execdir mv {} /var/tmp \;

Although as the documentation states you must ensure that your $PATH environment variable does not reference the current directory (namely .) if you use -execdir

  • I get File name too long ( because the .gz file is under 300 sub dir ) – maihabunash Dec 18 '14 at 17:14
  • see my update in the question – maihabunash Dec 18 '14 at 17:26
  • 1
    @maihabunash, change -exec to -execdir and give it a shot. Before doing that make sure your PATH variable does not reference current directory (ie it does not contain .) – iruvar Dec 18 '14 at 17:52
  • yes its work , create answer and I will vote for you – maihabunash Dec 18 '14 at 17:58
  • @maihabunash, added to jordanm's answer and upvoted ;-). – iruvar Dec 18 '14 at 18:25

Use locate to find the file:

locate <file_name>

Then use mv to move the file

mv <location/file_name> <new_location/file_name>
  • The path to the file is already known. There is no way locate could be in any way useful. – Gilles Dec 18 '14 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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