Sebastian Zeki
Sebastian Zeki

Reputation: 6874

How to find and move from the current directory in bash

I'm trying to move a script from the directory I'm in to another directory after I have performed a find in the current directory. Although I don't get an error nothing happens. I don't know why. Can you help?

 find . -name ScriptsFlowchart.xml -execdir mv {} Users/me/Desktop/SequencingScripts/{} \;

Upvotes: 1

Views: 220

Answers (1)

Paulo Amaral
Paulo Amaral

Reputation: 863

Try using -exec instead of -execdir and drop {} in target definition.

find . -name ScriptsFlowchart.xml -exec mv {} Users/me/Desktop/SequencingScripts/ \;

{} will retrieve the file path relative to current dir. So you must run the mv command from the current dir as well (using -exec).

From find manual page:

-execdir command ;

Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find.

If that's in a bash script, try reading $? right after running the command to check if there were any errors (if equals 0, runs successfully).

Upvotes: 2

Related Questions