With the ls –t command, you can generate a list of files in a directory and sort them according to their respective time stamps. By default, the files will be listed from the newest files to the oldest. The following example lists the files in /var/adm starting from the most recent file.
$ ls -t /var/adm total 134 -rw------- 1 root root 315 Sep 24 14:00 sulog -r--r--r-- 1 root other 350700 Sep 22 11:04 lastlog -rw-r--r-- 1 root bin 4464 Sep 22 11:04 utmpx -rw-r--r-- 1 adm adm 20088 Sep 22 11:04 wtmpx -rw-r--r-- 1 root root 11510 Sep 10 16:13 messages.1 drwxrwxr-x 5 adm adm 512 Sep 10 15:19 acct drwxrwxr-x 2 adm sys 512 Sep 10 15:19 sa drwxr-xr-x 2 adm adm 512 Sep 10 15:17 log
You can then remove old files that you determine as no longer needed.
The find command enables you to search for files within a defined time range that you can mark for deletion.
For more information, see Using Your Assigned Administrative Rights in Securing Users and Processes in Oracle Solaris 11.3.
# find directory -type f[-atime +nnn] [-mtime +nnn] -print > output-file &
Identifies the directory you want to search. Subdirectories below are also searched.
Specifies the number of days that files that have not been accessed.
Specifies the number of days that files have not been modified.
Refers to the file to which the output of the command will be written.
If some files in the list are still needed, remove their filenames from the output file.
# rm `cat output-file`
The following example shows files in the /var/adm directory and the subdirectories that have not been accessed in the last 60 days. The /var/tmp/deadfiles file contains the list of inactive files. The rm command removes these inactive files.
# find /var/adm -type f -atime +60 -print > /var/tmp/deadfiles & # more /var/tmp/deadfiles /var/adm/aculog /var/adm/spellhist /var/adm/wtmpx /var/adm/sa/sa13 /var/adm/sa/sa27 /var/adm/sa/sa11 /var/adm/sa/sa23 /var/adm/sulog /var/adm/vold.log /var/adm/messages.1 /var/adm/messages.2 /var/adm/messages.3 # rm `cat /var/tmp/deadfiles` #