Find the answer to your Linux question:
Results 1 to 4 of 4
I made a script that deletes all files over X number of days old from a specific directory. Now I want to expand it to include a whitelist of files ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2

    getting touch to accept input from a file

    I made a script that deletes all files over X number of days old from a specific directory. Now I want to expand it to include a whitelist of files that should never be deleted.

    Basically, the script will perform "touch" on all files that are listed in whitelist.txt. Then it will delete all files over X days old.

    I'm having trouble getting "touch" to accept the contents of the whitelist text file. I've tried several different types of redirection, but the result is always along the lines of: touch: illegal option or a usage explanation.

    And to boot, it needs to handle files with spaces in their names.

    Thanks

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Code:
    while read file; do touch "$file"; done < foo
    Or even

    Code:
    cat foo | while read file; do touch "$file"; done

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2
    Thank you. That worked perfectly.

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    As a general note, there is a utility to do this already:
    Code:
    cat whitelist | xargs touch
    xargs takes its input and runs the given command on every line of input. Check its man page for more details.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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