The command you claim to be executing doesn't match the error message you're getting, but either way this answer should clarify some things.
First, note that if there are any files matching *jpg
in the current directory, the pattern *jpg
will be expanded on the command line of find
. You need to quote the pattern to protect from that.
With the command you've given, what gets executed is something like
cd directory && mv -f file
But mv
expects two arguments: a source file and a destination.
You need to pass a target directory, and since you're using -execdir
, the target directory will be interpreted relative to each directory where there are .jpg
files. Note that the directory must exist. If you want to move all .jpg
files to a single directory, create it first, then run
find -iname '*.jpg' -execdir mv -f {} /common-destination-directory
If you want to move all files to a relative path, for example move them to the images
subdirectory relative to where they are, you will need to create the directory first.
find -iname '*.jpg' -execdir mkdir -p images \; -execdir mv -f {} images \;
With GNU utilities (i.e. on Linux) you can optimize a little by running mv
only once per directory:
find -iname '*.jpg' -execdir mkdir -p images \; -execdir mv -t images {} +
According to your strace
output, and I have no idea about the reason, the open()
function prefix filenames with /proc/
:
open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 4
fcntl64(4, F_SETFD, FD_CLOEXEC) = 0
getdents64(4, /* 21 entries */, 32768) = 664
getgid32() = 0
stat64("/proc/index.php", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/.svn", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/init-dist.php", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/landing-page.html", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
[...]
stat64("/proc/js", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/extras", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/sitemaps", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getdents64(4, /* 0 entries */, 32768) = 0
Best Answer
The syntax of
find
is not like what you have written, please read the manual pageman find
to get detailed idea.For example if you want to find files named
index.php
on the current directory and all the sub directories under it, you can use:If you want to search for files having names say
findex.php
,index.phpfoo
,index.php
you need to use:*
is a glob pattern meaning zero or more characters.On the other hand if you want to look in the current directory only :