Hi,
You could use the find command to find and delete the bak and jpg files. The general syntax for find is:
find <targetdir> <test(s)> <action(s)>
- <targetdir> being the starting point from where find starts to look (find is recursive, so subdirs are automatically included),
- <test(s)> in your case you want to look for files that end with .bak or .jpg
- <action(s)> in your case this will be a delete from the files found.
You would end up with something like this:
find /XFOLDER -type f -name "*.bak" -o -name "*.jpg" -exec rm {} \;
/XFOLDER needs to be replaced by the input given to the script:
Code:
#!/bin/bash
# check if target was supplied
if [[ $# != 1 ]]
then
echo "Usage: tree_cleaner <dir>"
exit 1
fi
targetDir="$1"
# testing without the rm part, only show what would have been removed.
find ${targetDir} -type f -name "*.bak" -o -name "*.jpg"
# Remove the above find line and uncomment this line if the above works.
#find ${targetDir} -type f -name "*.bak" -o -name "*.jpg" -exec rm {} \;
exit 0
Here's a good site that deals with (bash) scripting:
Advanced Bash-Scripting Guide
And here you can find a bit more info about the find command:
find (Linux in a Nutshell, 5th Edition)
Hope this helps.