I have a script that deletes files 7 days or older and then logs them to a folder. It logs and deletes everything correctly but when I open up the log file for viewing, its very sloppy.
log=$HOME/Deleted/$(date)
find $HOME/OldLogFiles/ -type f -mtime +7 -delete -print > "$log"
The log file is difficult to read
Example File Output: (when opened in notepad)
/home/u0146121/OldLogFiles/file1.txt/home/u0146121/OldLogFiles/file2.txt/home/u0146121/OldLogFiles/file3.txt
Is there anyway to log the file nicer and cleaner? Maybe with the Filename, date deleted, and how old it was?
Any suggestions help!
pastetrick – mpy Jun 27 '13 at 21:13date; -exec rm -f "{}" ;|paste - - >> $logthat looks right but i keep getting this error and i dont know why
./test.sh: line 3: $log: ambiguous redirect find: ‘ls’ terminated by signal 13 find: ‘ls’ terminated by signal 13
– mkrouse Jun 28 '13 at 14:27logcontains white spaces (as it is derived fromdate:Fr Jun 28 16:49:19 CEST 2013), so the redirection>> $logshould read>> "$log"like in your question. And probably you want to enclose also the ls parameter{}in quotes, like in thermstatement:... -exec ls -latr "{}" ...– mpy Jun 28 '13 at 14:54What is the "-rwxr-xr-x 1 u0146121 Domain Users" part? Can I modify that at all?
– mkrouse Jun 28 '13 at 15:12ls -land you will see the-rwxr-xr-x...part (this are the permission/owner/group), too. Useman lsfor a more detailed explanation of thelscommand. If you don't like that, simply omit the-lparameter in the find command:...-exec ls -atr "{}". However then you will lose the modification date, too. I don't know an easy solution right now if you want to keep the date (that would make another good question). – mpy Jun 28 '13 at 15:25-aoption oflsis meaningless when applied to file argument(s). (ls –l .bashrcworks fine; you don’t need to sayls –la.) And the-tand-roptions are meaningful only when you have multiple arguments, or one (or more) directory argument(s). So, since you’re saying-type f, you might as well say just-exec ls -l {}. – Scott - Слава Україні Jun 29 '13 at 19:01