Part of the job of cleaning up heavily loaded file systems involves locating and removing files that have not been used recently. You can locate unused files using the ls or find commands.
Other ways to conserve disk space include emptying temporary directories such as the ones located in /var/tmp or /var/spool, and deleting core and crash dump files.
How to List the Newest Files
List files, displaying the most recently created or changed files first, by using the ls -t command.
$ ls -t [directory] |
-t | Sorts listings by latest time stamp first. |
directory | Directory you want to search. |
Example–Listing the Newest Files
The following example shows how to use ls -tl to locate the most recent files within the /var/adm directory. The sulog file was created or edited most recently.
$ ls -tl /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 other 0 Sep 19 03:10 messages -rw-r--r-- 1 root other 0 Sep 12 03:10 messages.0 -rw-r--r-- 1 root root 11510 Sep 10 16:13 messages.1 -rw-r--r-- 1 root root 0 Sep 10 16:12 vold.log drwxr-xr-x 2 root sys 512 Sep 10 15:33 sm.bin drwxrwxr-x 5 adm adm 512 Sep 10 15:19 acct drwxrwxr-x 2 adm sys 512 Sep 10 15:19 sa -rw------- 1 uucp bin 0 Sep 10 15:17 aculog -rw-rw-rw- 1 root bin 0 Sep 10 15:17 spellhist drwxr-xr-x 2 adm adm 512 Sep 10 15:17 log drwxr-xr-x 2 adm adm 512 Sep 10 15:17 passwd |
How to Find and Remove Old or Inactive Files
-
- Become superuser.
- Find files that have not been accessed for a specified number of days and list them in a file.
# find directory -type f[-atime + nnn] [-mtime + nnn] -print > filename
- Remove the inactive files that you listed in the previous step.
# rm `cat filename`
filename File created in previous step which contains the list of inactive files.
Example–Finding and Removing Old or Inactive Files
The following example locates regular files in /var/adm and its directories that have not been accessed in the last 60 days and saves the list of inactive files in /var/tmp/deadfiles. These files are then removed with the rm command.
# find /var/adm -type f -atime +60 -print > /var/tmp/deadfiles & # more /var/tmp/deadfiles /var/adm/log/asppp.log /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` # |
How to Clear Out Temporary Directories
-
- Become superuser.
- Change to the /var/tmp directory.
# cd /var/tmp
- Delete the files and subdirectories in the current directory.
# rm -r *
Change to other directories containing unnecessary temporary or obsolete subdirectories and files, and delete them by repeating Step 3 above.
Example–Clearing Out Temporary Directories
The following example shows how to clear out the /var/tmp directory, and verifies that all files and subdirectories were removed.
# cd /var/tmp # ls deadfiles wxconAAAa0003r:0.0 wxconAAAa000NA:0.0 test_dir wxconAAAa0003u:0.0 wxconAAAa000cc:0.0 wxconAAAa000zs:0.0 # rm -r * # ls # |
How to Find and Delete core Files
-
- Become superuser.
- Change the directory to where you want to start the search.
- Find and remove any core files in this directory and its subdirectories.
# find . -name core -exec rm {} \;
Example–Finding and Deleting core Files
The following example shows how to find and remove core files from the user account belonging to jones using the find command.
# cd /home/jones # find . -name core -exec rm {} \; |
How to Delete Crash Dump Files
Crash dump files can be very large, so if you have enabled your system to store these files, do not retain them for longer than necessary.
-
- Become superuser.
- Change to the directory where crash dump files are stored.
# cd /var/crash/system
system System that created the crash dump files. Caution : Be sure you are in the right directory before completing the following step. The next step deletes all files in the current directory.
- Remove the crash dump files.
# rm *
- Verify the crash dump files are removed.
# ls
Example–Deleting Crash Dump Files
The following example shows how to remove crash dump files from the system venus, and how to verify that the crash dump files were removed.
# cd /var/crash/venus # rm * # ls |
0 Comments