Find the answer to your Linux question:
Results 1 to 4 of 4
for d in /tmp/aaa /tmp/bkk /tmp/bbb /tmp/ccc; do if [ -d "$d" ]; then /usr/bin/tmpwatch -f 720 "$d" fi done would this remove the folders aaa bbb and ccc or ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    2

    tmpwatch script


    for d in /tmp/aaa /tmp/bkk /tmp/bbb /tmp/ccc; do
    if [ -d "$d" ]; then
    /usr/bin/tmpwatch -f 720 "$d"
    fi
    done


    would this remove the folders aaa bbb and ccc or their content?


    THX a lot

  2. #2
    Linux User
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    260
    This script would remove the aaa, bbb, ccc and bkk directories in the /tmp directory, and the contents of aaa, bbb, ccc, and bkk, as long as these directories last access times were all more than 720 hours ago.

  3. #3
    Just Joined!
    Join Date
    Apr 2011
    Posts
    2
    Quote Originally Posted by ramin.honary View Post
    This script would remove the aaa, bbb, ccc and bkk directories in the /tmp directory, and the contents of aaa, bbb, ccc, and bkk, as long as these directories last access times were all more than 720 hours ago.
    thank you for your answer,
    i have tested it and it only removed the files in aaa bbb and ccc... why?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux User
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    260
    Quote Originally Posted by Cybertronix View Post
    thank you for your answer,
    i have tested it and it only removed the files in aaa bbb and ccc... why?
    There are many reasons why "tmpwatch" will not delete directories.

    Are you sure the "/tmp/bkk" directory and all of it's contained files have NOT been accessed within the past 720 hours? Accessing a file inside of a sub-directory of "/tmp/bkk" will not affect the access time of the "/tmp/bkk" directory, but it will ignore this contained file as it was last accessed within the past 720 hours, and so the "/tmp/bkk" directory will not be completely empty. If a directory is not completely empty first, it will not be deleted.

    Another reason "tmpwatch" will avoid deleting a file is if there is a daemon process that has that file open. If the daemon process opened the file when it first started, and it started more than 720 hours ago, the access time of that file will be older than 720 hours ago, but "tmpwatch" will see that the file is "in-use" (still open in the daemon process) and so it will not delete that file.

    One other possibility is that this directory contains a fifo (named pipe) or a special block/character device. You need to specify "tmpwatch -a -f" to delete "all" kinds of files (see the "tmpwatch" manpage).

    Programs like "tmpwatch" need to be used very carefully -- misusing it can cause problems on your system weeks or months after you have initiated the command, long after you forgot about it. This makes tracking down problems extremely difficult! To avoid such problems, the "tmpwatch" program is designed to be as cautious as possible, deleting only simple files, empty directories, and symbolic links (without following the link), and only deleting files that are not currently opened by any users programs or daemon processes. It also will not delete other types of files unless you explicitly state on the command line that you want to delete fifos and block/character devices as well.

    Be especially careful when using "tmpwatch -a -f" because like "sudo rm -Rf", it can cause serious damage.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •