- Nikhil Bhaskar
- July 2, 2021
How to Maintain System Files in Linux.
In Linux user tasks is to prevent file systems become completely full because when a server runs out of space the result are changeable. We can create, remove & modify files that depending on how we can manage the root file system and it is divided into different partitions or volumes, those result will be more or less serious but in any case unacceptable.
We have multiple commands to maintain system file.
List available free space.
df -h
Here is the command output.
List a specific directory.
df -h /home
Here is the command output.
List file systems in order of occupation.
df -h | awk '{print $5 " " $6}' | sort -n | tail -5
Here is the command output.
Show Directory size.
du -h -s /var/log
Here is the command output.
Remove files
rm -rf /path/of/file
or
>/path/of/file
Count the number of files in a directory.
ls -l /var/log | wc -l
Show the larger files in a filesystem.
du -k /var/log | sort -n | tail -5
Here is the command output.
List the largest files in a directory.
ls -lSr | tail -5
or
ls -lSr /path/of/directory | tail -5
Here is the command output.
Calculate the size of specific files.
du -ch /var/log/*.log | grep total
Find large files between 100 MB or 1 GB.
find . -type f -size +100M -ls
or
find . -type f -size +100M -size -1G -ls
List the recently modified files.
ls -larth /var/log | tail -5
Here is the command output.
Find old files.
find /var/log -mtime +90 -ls
or
find /var/log -mtime +90 -ls -exec rm {} \;
Find empty files.
find . -type f -size 0b -ls
or
find . -type f -empty -ls
Show Package and compress directory content.
tar -zcvf var_log.`date +%Y%m%d`.tar.gz /var/log/*.log
Find files in Recycle Bin/Trash.
find / -iname "*trash*" -ls