Go to main content

Managing Devices in Oracle® Solaris 11.4

Exit Print View

Updated: November 2020
 
 

Removing Old or Inactive Files

Use the ls –t command to 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
-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 use this information to remove old files that you determine you no longer need.

How to Identify Old or Inactive Files for Deletion

  1. Become an administrator.

    For more information, see Using Your Assigned Administrative Rights in Securing Users and Processes in Oracle Solaris 11.4.

  2. Send a list of files that have not been accessed for a specified number of days to an output file.
    # find directory -type f[-atime +nnn] [-mtime +nnn] -print > output-file &
    directory

    The directory you want to search, which includes its subdirectories.

    –atime +nnn

    The number of days that files that have not been accessed.

    –mtime +nnn

    The number of days that files have not been modified.

    output-file

    The file to which the output of the command will be written.

  3. Ensure that all of the files listed in the output file can be safely removed.

    If some files in the list are still needed, delete them from the output file.

  4. Remove the files that are listed in the output file.
    # rm `cat output-file`
Example 36  Finding and Removing Old or Inactive Files

This example creates a list of the files in the /var/share/adm directory and its subdirectories that have not been accessed in the last 60 days in a file named /var/tmp/deadfiles. The rm command removes the inactive files listed in the /var/tmp/deadfiles file.

# find /var/adm -type f -atime +60 -print > /var/tmp/deadfiles &
# more /var/tmp/deadfiles
/var/adm/aculog
/var/adm/spellhist
/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`
#