3 ms·
Is there a command/short-cut to storing the path(s) returned from a find command? Currently I do something like: find . -name somefile.txt -print Then copy an
by siavosh 14y ago
Is there a command/short-cut to storing the path(s) returned from a find command? Currently I do something like:
find . -name somefile.txt -print
Then copy and paste the results manually into a cd command for example. I feel like there's a much better way somewhere.
- ralph 14y agocd `find -name foo`
- Tyr42 14y agoxargs? Here is an example from the man page: >For example, the following command will copy the list of >files and directories which start with > an uppercase letter in the current directory >to destdir: /bin/ls -1d [A-Z]* | xargs -J % cp -rp % destdir You can use this with find really nicely. find . -name somefile.txt -print0 | xargs -0 -J % cp -rp % destdir Note the -print0 and -0 flags (zero). This will use a null byte as a separator instead of spaces to avoid failing on files with spaces in their names.