(Bash) `cp`, `mv` with wildcard
- Use
find -name <NAME_TO_CAPTURE>
to capture filenames to copy or move, then dispatch those files tocp
ormv
using-exec
- E.g.
find /home/admin -name "*.txt" -exec mv '{}' /home/admin/txtfiles/ \;
- Wildcard string (e.g.
"*.txt"
) must be enclosed by quotes {}
denotes each of the captured filenames\;
at the end is semi-colon escaped to denote end of command for-exec
- E.g.
- Another approach using
xargs
- E.g.
ls -1 *.txt | xargs -I{} mv /home/admin/{} /home/admin/txtfiles/{}
ls -1
printsls
output one-file-per-line-I{}
makes{}
the placeholder for standard input (implies-x -L 1
where-L 1
makesxargs
consider at most 1 line per command)
- E.g.
References:
Written on March 25, 2021