HI Ralph
Like the -print option, very useful
Will try to remember the single quotes
pr -tnv deletefiles.sh give
mit@Thinky:~/scripts$ pr -tnv deletefile.sh
1v#!/bin/bash
2v# delete files older than 7 days old
3vfind /var/log/ -name '*.log*' -type f -mtime +7 -print
I know the second line is not needed but when I come to look at in 6
months it might just remind me what the script does.
and ls -l deletefile.sh gives
mit@Thinky:~/scripts$ ls -l deletefile.sh
-rwxrwxr-x 1 mit mit 104 Apr 22 21:29 deletefile.sh
So now for a second question -name '*log*' I assume that this looks for
a file name with log in it regardless of where in the name it finds
logs, so it will select "file.log" as well as "file.log.2.gz".
The reason I ask it that it is selecting some compressed log files like
file.log.2.gz but ignoring other which are like 5 weeks old.
Tim H
On 22/04/2025 10:14, Ralph Corderoy wrote:
Hi Tim,
Bob wrote:
Tim wrote:
find /var/log/ -name "*.log" -type f -mtime +7 -delete
Start with -print instead of -delete so if you have a bug you don't
delete the wrong files.
Also, use '' instead of "" in general as the shell interprets less
within them, i.e. the contents are more literal. Both will work in the
above case, but it's a habit to form: Use '', drop back to "" when
needed.
But if you insist try adding the "shebang" header to the start of your
script.
#!/bin/sh
Then show up precisely what's in the file...
pr -tnv deletefile.sh
Also you did remember to "chmod +x deletefile.sh" ?
...and information about the file:
ls -l deletefile.sh
--
Next meeting: Online, Jitsi, Tuesday, 2025-05-06 20:00
Check to whom you are replying
Meetings, mailing list, IRC, ... https://dorset.lug.org.uk
New thread, don't hijack: mailto:dorset@mailman.lug.org.uk