Reputation: 109
I found this command line when I was checking a Bash Script! My question is what does this command do and is this command correct?
find / -name "*.src" | xargs cp ~/Desktop/Log.txt
Upvotes: 0
Views: 97
Reputation: 11593
What the command is
find / -name "*.src"
Explanation: Recursively find all regular files, directories, and symlinks in /
, for which the filename ends in .src
|
Explanation: Redirect stdout from the command on the left side of the pipe to stdin of the command on the right side
xargs cp ~/Desktop/Log.txt
Explanation: Build a cp
command, taking arguments from stdin and appending them into a space-delimited list at the end of the command. If the pre-defined buffer space of xargs
(generally bounded by ARG_MAX
) is exhausted multiple cp
commands will be executed,
e.g. xargs cp arg100 .... arg900
could be processed as cp a100 ... a500; cp a501 ... a900
Note The behavior of your cp
varies a lot depending on its arguments
~/Desktop/Log.txt
is the only argument, cp
will throw stderrcp
is a directory
cp
and the first one is a regular file. Then the contents of the second argument file will be overwritten by the contents of the first argumentcp
will throw a stderrSo all in all, there are too many variables here for the behavior of your command to really ever be precisely defined. As such, I suspect, you wanted to do something else.
What it probably should have been
My guess is the author of the command probably wanted to redirect stdout to a log file (note the log file will be overwritten each time you run the command)
find / -name "*.src" > ~/Desktop/Log.txt
Additionally, if you are just looking for regular files with the .src
extension, you should also add the -type f
option to find
find / -type f -name "*.src" > ~/Desktop/Log.txt
Upvotes: 2
Reputation: 592
find the files or directory with .src
extension in /
and copy file ~/Desktop/Log.txt
as the find result's filename
for example if the output of the find command is
file.src
directory1.src
file2.src
xargs
command will execute cp ~/Desktop/Log.txt file.src directory1.src file2.src
which does not make any sense.
Upvotes: 3
Reputation: 3367
It finds every file or directory that match the pattern *.src
from /
.
Then copy the file ~/Desktop/Log.txt
to every result of previous command.
Upvotes: 0