Logs command

Technical issues/questions of an intermediate or advanced nature.
User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Logs command

Post#1 by Ed_P » 25 Oct 2022, 19:00

What is the command to purge log data older than say 60 days?

Added in 2 hours 11 minutes 41 seconds:
Ok, I've read up on the logrotate command but I'm not sure it does what I want which is to set the logs to 7 days max. Any advice?
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Logs command

Post#2 by Rava » 26 Oct 2022, 02:34

Ed_P wrote:
25 Oct 2022, 21:11
I've read up on the logrotate command but I'm not sure it does what I want which is to set the logs to 7 days max. Any advice?
man logrotate 8 says

Code: Select all

       # sample logrotate configuration file
       compress

       /var/log/messages {
           rotate 5
           weekly
           postrotate
               /usr/bin/killall -HUP syslogd
           endscript
       }
I think you can try adding a rm after

Code: Select all

 /usr/bin/killall -HUP syslogd
and best keep the text indentation - it might be an important part of its syntax.

First check which are the oldest now compressed files, and then look for a pattern that matches all the oldest files.
Then add that rm and its fitting for the older files only pattern into your logrotate setup file.


Currently my system is too freshly booted so I cannot assist you there:

Code: Select all

root@porteus:/var/log# ls -o messages*
-rw-r----- 1 root 251623 2022-10-26 04:28 messages
root@porteus:/var/log# ls -o *gz *xz
/bin/ls: cannot access '*gz': No such file or directory
/bin/ls: cannot access '*xz': No such file or directory

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Logs command

Post#3 by Ed_P » 26 Oct 2022, 05:35

Thanks Rava. :friends: Do you know what the current rotates are set to and where that setting is located?

This is what I see:

Code: Select all

guest@porteus:~$ ls -oh /var/log/*log*
-rw-r--r-- 1 root  54K Oct 26 01:19 /var/log/Xorg.0.log
-rw-r--r-- 1 root  46K Oct 25 14:44 /var/log/Xorg.0.log.old
-rw-r--r-- 1 root    0 Feb 13  2021 /var/log/faillog
-rw-r--r-- 1 root    0 Apr  7  2000 /var/log/lastlog
-rw-r----- 1 root 1.2K Oct 25 14:44 /var/log/lxdm.log
-rw-r----- 1 root 1.8K Oct 25 14:44 /var/log/lxdm.log.old
-rw-r----- 1 root    0 Dec  4  2021 /var/log/maillog
-rw-r----- 1 root 7.6K Oct 26 01:19 /var/log/syslog
guest@porteus:~$ ls -oh /var/log/*mess*
-rw-r----- 1 root 203K Oct 26 01:21 /var/log/messages
guest@porteus:~$ ls -oh /var/log/*gz *xz
/bin/ls: cannot access '/var/log/*gz': No such file or directory
/bin/ls: cannot access '*xz': No such file or directory
guest@porteus:~$ 
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Logs command

Post#4 by Rava » 26 Oct 2022, 07:48

Ed_P wrote:
26 Oct 2022, 05:35
Do you know what the current rotates are set to and where that setting is located?
No, I do not. ncmprhnsbl might know. Could also be there is currently no setup file for that and the system works with defaults.

Code: Select all

guest@porteus:~$ ls -oh /var/log/*log*
-rw-r--r-- 1 root  54K Oct 26 01:19 /var/log/Xorg.0.log
-rw-r--r-- 1 root  46K Oct 25 14:44 /var/log/Xorg.0.log.old
-rw-r--r-- 1 root    0 Feb 13  2021 /var/log/faillog
-rw-r--r-- 1 root    0 Apr  7  2000 /var/log/lastlog
-rw-r----- 1 root 1.2K Oct 25 14:44 /var/log/lxdm.log
-rw-r----- 1 root 1.8K Oct 25 14:44 /var/log/lxdm.log.old
-rw-r----- 1 root    0 Dec  4  2021 /var/log/maillog
-rw-r----- 1 root 7.6K Oct 26 01:19 /var/log/syslog
Seen that, seems what you want is adding a

Code: Select all

rm /var/log/*log*.old
. :)

When you figured out which setup file to create new, or which one to tweak. :D
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Logs command

Post#5 by Ed_P » 26 Oct 2022, 16:25

My prior files stats were from my safe system, no changes saved, these are from my changes=EXIT system.

Code: Select all

guest@porteus:~$ ls -oh /var/log/*log*
-rw-r--r-- 1 root  61K Oct 26 12:16 /var/log/Xorg.0.log
-rw-r--r-- 1 root  66K Oct 22 23:31 /var/log/Xorg.0.log.old
-rw-r--r-- 1 root    0 Feb 13  2021 /var/log/faillog
-rw-r--r-- 1 root  292 Jul  2  2021 /var/log/lastlog
-rw-r----- 1 root 1.2K Oct 26 12:15 /var/log/lxdm.log
-rw-r----- 1 root 1.6K Oct 22 23:31 /var/log/lxdm.log.old
-rw-r----- 1 root    0 Dec  4  2021 /var/log/maillog
-rw-r--r-- 1 root 8.2K Jan 17  2022 /var/log/slim.log
-rw-r----- 1 root 275K Oct 26 12:16 /var/log/syslog
-rw-r----- 1 root  39K Aug 11 20:04 /var/log/syslog.1.gz
guest@porteus:~$ ls -oh /var/log/*mess*
-rw-r----- 1 root 652K Oct 26 12:18 /var/log/messages
-rw-r----- 1 root 111K Oct  9 19:29 /var/log/messages.1.gz
guest@porteus:~$ 
And as you can see the logs are considerably bigger and I do have some .gz files.
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Logs command

Post#6 by Rava » 26 Oct 2022, 16:51

Then you want to delete these most probably

Code: Select all

rm /var/log/*log*.old /var/log/*.gz
Do a

Code: Select all

ls -oh /var/log/*log*.old /var/log/*.gz
first as dry run to see if all files get deleted you want deleted and none get deleted you want to keep.

My freshly booted system with no changes= cheatcode gives me this:

Code: Select all

guest@porteus:~$ ls -oh /var/log/*log*.old /var/log/*.gz
/bin/ls: cannot access '/var/log/*log*.old': No such file or directory
/bin/ls: cannot access '/var/log/*.gz': No such file or directory
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Logs command

Post#7 by Ed_P » 26 Oct 2022, 22:25

Rava wrote:
26 Oct 2022, 16:51
first as dry run to see if all files get deleted you want deleted

Code: Select all

guest@porteus:~$ ls -oh /var/log/*log*.old /var/log/*.gz
-rw-r--r-- 1 root  66K Oct 22 23:31 /var/log/Xorg.0.log.old
-rw-r----- 1 root  37K Aug 11 00:02 /var/log/debug.1.gz
-rw-r----- 1 root 1.6K Oct 22 23:31 /var/log/lxdm.log.old
-rw-r----- 1 root 111K Oct  9 19:29 /var/log/messages.1.gz
-rw-r----- 1 root  37K Aug 11 01:29 /var/log/secure.1.gz
-rw-r----- 1 root  39K Aug 11 20:04 /var/log/syslog.1.gz
-rw-r--r-- 1 root  16K Aug 11 00:02 /var/log/wtmp.1.gz
guest@porteus:~$ 

:good: Thank you Rava. :)

Rather than deleting them, and creating .wh files, is there a command to move them to trash like nemo supports?
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Logs command

Post#8 by Rava » 26 Oct 2022, 22:51

Ed_P wrote:
26 Oct 2022, 22:25
is there a command to move them to trash like nemo supports?
Dunno. If the trash is e.g. /root/Thrash then just use this

Code: Select all

mv /var/log/*log*.old /var/log/*.gz /root/Thrash
Of course if nemo uses some kind of Trash control file then the above mv approach will not cover that. Look it up on the web if people found a manual way of emulating the precise method of "move files to trash like nemo". :D
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Logs command

Post#9 by Ed_P » 28 Oct 2022, 20:18

Rava wrote:
26 Oct 2022, 22:51
Dunno. If the trash is e.g. /root/Thrash
From my changes-exit.conf file:

Code: Select all

!/root/.local/share/Trash/

!/home/guest/.local/share/Trash/

Code: Select all

guest@porteus:~$ ls -ohr /home/guest/.local/share/Trash
total 0
drwxr-xr-x 2 guest 880 Oct 28 11:34 info/
drwxr-xr-x 2 guest 880 Oct 28 11:34 files/
drwx------ 2 guest  40 Oct  7 18:46 expunged/
guest@porteus:~$ 
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Logs command

Post#10 by Rava » 28 Oct 2022, 20:26

Then /home/guest/.local/share/Trash is trash for guest, but like I said, you have to figure out how "info/" works. Aka /home/guest/.local/share/Trash/info/

Added in 1 minute 10 seconds:
On my XFCE 4.16 box I only get this:

Code: Select all

guest@porteus:/$ ls -ohr /home/guest/.local/share/Trash
/bin/ls: cannot access '/home/guest/.local/share/Trash': No such file or directory
Added in 7 minutes 15 seconds:
thunar displays a "Trash" but won't tell me where exactly that folder lies:
Image
(the dark violet areas are just privacy-censored folders and devices)
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Logs command

Post#11 by Ed_P » 28 Oct 2022, 20:44

A related thread: What Makes save.dat File Grow? There A "Prune" App For It?

Current settings: /etc/logrotate.conf

Added in 4 minutes 57 seconds:
Rava wrote:
28 Oct 2022, 20:34
Then /home/guest/.local/share/Trash is trash for guest, but like I said, you have to figure out how "info/" works. Aka /home/guest/.local/share/Trash/info/

Code: Select all

guest@porteus:~$  ls -ohr /home/guest/.local/share/Trash/info
total 8.0K
-rw------- 1 guest 118 Oct  8 15:12 Screenshot\ from\ 2022-10-05\ 00-20-29.png.trashinfo
-rw------- 1 guest 118 Oct  8 15:12 Screenshot\ from\ 2022-10-04\ 21-01-27.png.trashinfo
guest@porteus:~$  ls -ohr /home/guest/.local/share/Trash/files
total 324K
-rw-r--r-- 1 guest 188K Oct  5 00:20 Screenshot\ from\ 2022-10-05\ 00-20-29.png
-rw-r--r-- 1 guest 136K Oct  4 21:01 Screenshot\ from\ 2022-10-04\ 21-01-27.png
guest@porteus:~$  cat /home/guest/.local/share/Trash/info/*
[Trash Info]
Path=/home/guest/Pictures/Screenshot%20from%202022-10-04%2021-01-27.png
DeletionDate=2022-10-08T15:12:07
[Trash Info]
Path=/home/guest/Pictures/Screenshot%20from%202022-10-05%2000-20-29.png
DeletionDate=2022-10-08T15:12:07
guest@porteus:~$ 
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Logs command

Post#12 by Rava » 28 Oct 2022, 21:07

^
Not that hard to emulate as a script, now, is it.
Just capture the current date and time when doing the delete = move to Trash like so

Code: Select all

MYDeletionDate=$(date +%Y-%m-%dT%H:%M:%S)
echo $MYDeletionDate
done in terminal as example

Code: Select all

guest@porteus:~$ MYDeletionDate=$(date +%Y-%m-%dT%H:%M:%S)
guest@porteus:~$ echo $MYDeletionDate
2022-10-28T23:06:37
HTH.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Logs command

Post#13 by Ed_P » 28 Oct 2022, 21:42

Thank you Rava. :friends:

In that I can't imagine me restoring a deleted log file and I don't save my trash folders when I shutdown I'm not overly concerned about the info files. :) For my USB installed system straight deleting should be okay.
Ed

donald
Full of knowledge
Full of knowledge
Posts: 2073
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

Logs command

Post#14 by donald » 31 Oct 2022, 23:29

Rava wrote:
28 Oct 2022, 20:34
On my XFCE 4.16 box I only get this:

Code: Select all

guest@porteus:/$ ls -ohr /home/guest/.local/share/Trash
/bin/ls: cannot access '/home/guest/.local/share/Trash': No such file or directory
Added in 7 minutes 15 seconds:
thunar displays a "Trash" but won't tell me where exactly that folder lies:
Image
(the dark violet areas are just privacy-censored folders and devices)
Those files/folder(s) are created when you actually send a file to Trash.

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Logs command

Post#15 by Rava » 01 Nov 2022, 00:34

donald wrote:
31 Oct 2022, 23:29
Those files/folder(s) are created when you actually send a file to Trash.
Depends.
On one of my internal partitions (sda4) I created an empty test file in /mnt/sda4/tmp/TEST .
Cave! deleting any file via [delete] or via [shift]+[delete] makes no difference on sda4.
Usually [shift]+[delete] means: really delete, not move to Thrash, while [delete] means "move to Trash"

But like I wrote, if I use [delete] or [shift]+[delete] I always get this warning window
Image
and after that this is what my Trash looks like:
Image


… …

You might wonder "How could that be"…

I presume it is because in the root of /mnt/sda4 I have this empty file:

Code: Select all

guest@porteus:/mnt/sda4$ ls -o .Trash-1000 
-rwxrwxrwx 1 guest 0 2022-01-31 05:36 .Trash-1000
and Linux would move files "deleted via moving to Trash" when the file was on "/mnt/sda4" into a folder called "/mnt/sda4/.Trash-1000/" … but since Linux cannot create that folder because it already exists as a file… I get the above error message instead. :D

So, your above assumption is only correct if a user did not create a .Trash-1000 file in the root partition of the device where (s)he deletes the file. :)

Added in 8 minutes 42 seconds:
On USB sticks I often create these empty files from keeping some OS (especially SM-Witless-OS) from creating Thrash folders:

Code: Select all

$recycle.bin
LOST.DIR
Recycled
Recycler
System Volume Information
That worked fine for me for up to SM-Witless-OS 7, I never had V8 or V10 so I do not know if I need to add more empty files for these OS versions to also twist these into not bothering with my USB sticks. :)
Cheers!
Yours Rava

Post Reply