How to kill processes holding up a File system
To check all processes running on a file system.
#fuser -vm <File system>
To kill all processes running on a file system
#ps -lf -p $(fuser -c <File System> 2> /dev/null) | awk ‘{ print $4 }’ | xargs kill
To kill zombie processes
kill -HUP $(ps -A -ostat,ppid | awk ‘/[zZ]/{print $2}’)
or
kill -HUP $(ps -A -ostat,ppid | grep -e ‘[zZ]’| awk ‘{ print $2 }’)
Removing files by dates
#find . -type f -mtime XXX -maxdepth 1 -exec rm {} \;
The ‘.’ tells it to work in the current directory
The ‘-type f’ tells it to only look at files, not links or directories
The ‘-maxdepth 1’ tells it to only work in the current directory, rather than diving into subdirectories
The ‘-mtime XXX’ tell it to only match files that were last modified XXX*24 hours ago, so use whatever number you want in place of XXX
The ‘-exec rm {} \;’ tells it to remove any files that have matched all the other conditions. You can put pretty much any command after ‘-exec’. The curly braces will be replaced by the file name it is looking at. Command in ‘-exec’ have to be terminated by ‘\;’.
Also, the numeric parameters (like mtime) default to exact if you don’t include a sign, greater than if you include +, and less than if you include -. You probably want to delete everything older than a certain age, so you would use something like “+30”. For instance:
-mtime 30 ===> Exactly 30 days old
-mtime +30 ==> Older than 30 days old
-mtime -30 ==> Newer than 30 days old
I’ll echo John’s statement. Be very, very careful with “find”. When you first try it, I would recommend replacing the “-exec rm {}\;” with “-ls”. That will just show a directory listing of the affected files instead of removing them.
#find . -type f -maxdepth 1 -name “pimg-aiw*” -atime +31 ! -path “./*.sh” ! -path “./check/” -exec rm -r {} \;
find . = Find starting from this directory
type f = Only files
maxdepth 1 = Stay only on this level and no other sub-directories
name “pimg-aiw*” = Only look for files names that start with “pimg-aiw”
atime +31 = Only find file that was accessed 31 Days or OLDER
! -path “./*.sh” = Exclude any file with the “.sh” file extension
! -path “./check/” = Exclude any file named “check”
-exec rm -r {} \; = Execute the command “rm -r” until file stop running in this directory