Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Location
    Ireland
    Posts
    1

    Unanswered: Create a script to find and delete files question

    I use the extension .tmp do show temporary files. However, these files could be in any one of several folders. Create a script to find and delete these.
    This is a question i have for college and cannot do it. Does anyone know how to do it. Thanks!

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Look at the 'find' command. It will search directories for files that meet a variety of criteria.
    for your particular instance use:
    Code:
    find ./ -name "*.tmp"

  3. #3
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Wink

    Quote Originally Posted by kitaman View Post
    Look at the 'find' command. It will search directories for files that meet a variety of criteria.
    for your particular instance use:
    Code:
    find ./ -name "*.tmp"
    And...check out the "-exec" option of the find command to add the command to remove the files.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  4. #4
    Join Date
    Feb 2006
    Posts
    173
    Provided Answers: 1
    Create list of files with extension '*.tmp' to a file:
    Code:
    find / -type f -name '*.tmp' -print 2>>/dev/null > /tmp/tmp_files_list.txt


    Review and validate you are sure you want to delete files and if necessary edit file to remove any file names you do not want to delete:
    Code:
    less /tmp/tmp_files_list.txt


    Remove files:
    Code:
    for file in $(</tmp/tmp_files_list.txt)
      do
        rm $file
      done


    hth

Posting Permissions

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