Run a command on the output of a first command
$ find /home/user/ -mtime -3 -print -exec cp {} /media/username/usb-stick/ \;
will copy files created or modified within the last three days to the USB stick mounted.
The beginning of this command is the usual find
command, with the option -mtime
in this example.
We add the option -print
so the shell shows what’s being copied.
Then comes -exec
which runs the command cp
, in this example, on the selected files. The curly brackets i.e. {}
come along with usage of -exec
and are replaced by the current file name being processed.
;
tells -exec
that it is the end of the command.
Backslash i.e. \
is just here to escaped ;
.
Nota Bene: -exec
executes the command on each find (not as a batch).
To learn more about the option -exec
, run $ man find
.
To learn more about the option -mtime
, check out: https://yctct.com/find-mtime
The utility find was published in 1971 and is copyleft-licensed.
personal computing command-line interface (cli) gnu linux trisquel shell literacy office applications wiki exec