Perform action on certain files in a directory tree
 
My task was to remove certain files in a whole directory tree. These were all files called .DS_Store and all files beginning with a dot and an unterline (._*).

The solution was to use the find command to get all the wanted files first. I made this inside the directory "/test". It worked like this:

find /test -name "._*"
find /test -name ".DS_Store"

With the command xargs, it is possible to execute commands on the output of another command (the find command in our example). This works like below:

find /test -name "._*" | xargs rm
find /test -name ".DS_Store" | xargs rm

All together, I put this in a script where you just have to change the variable dir to whatever you want it to be and you can use it:
# This Script cleans the following files in the whole directory tree:
# .DS_Store
# ._* (all files that begin with "._"

echo " ______________________________________________________"
echo "|                           |"
echo "| Cleanup Script to clean a dir from some files    |"
echo "| Cleanupfile(s) 1:  .DS_Store            |"
echo "| Cleanupfile(s) 2:  ._*               |"
echo "|______________________________________________________|"
echo " "
echo "Please wait... "



dir='/test/ordner'

echo "Performing cleanup on dir $dir"


find $dir -name "._*" | xargs rm >/dev/null
find $dir -name ".DS_Store" | xargs rm >/dev/null



echo " "
echo " ______________________________________________________"
echo "|                           |"
echo "| Cleanup Script done                 |"
echo "|______________________________________________________|"
 
admin / Dec 01, 2006
   
 
 
Login: 
Pass: 
 
 
     
     
2004 - 2017 / lookass.ch
makememad@lookass.ch