I usually use the find command to automatically copy certain multimedia files from directory A to directory B. I use the following command:
for f in `find ./ -name "*.mkv" -mtime -24h`; do cp $f rename/ ; done
This totally does what I want, but now that I have transferred the command into an executable script (let's call it mmcopy
, it works perfectly) I wonder whether I could improve the script to do the following:
When I type mmcopy
on the command line, I would like to parse two operators/variables to the script, namely a variable of the file extension and a variable to the mtime operator, so I can specify which kind of files should be copied and how old these files may be.
E.g.: I want to automatically copy (all) .jpg
files in a directory that are newer than 3 days, the commandline should look like mmcopy jpg -3d
How would I have to change my script in order to be able to so?
mmcopy jpg -3d
then you can use the variables$1
and$2
in your script, which will expand tojpg
and-3d
respectively. These variables are called positional parameters. – Ernest A Mar 22 '15 at 18:29