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 ...
- 10-23-2008 #1Just 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
- 10-24-2008 #2Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Or evenCode:while read file; do touch "$file"; done < foo
Code:cat foo | while read file; do touch "$file"; done
- 10-24-2008 #3Just Joined!
- Join Date
- Oct 2008
- Posts
- 2
Thank you. That worked perfectly.
- 10-25-2008 #4
As a general note, there is a utility to do this already:
xargs takes its input and runs the given command on every line of input. Check its man page for more details.Code:cat whitelist | xargs touch
DISTRO=Arch
Registered Linux User #388732


Reply With Quote