You can run the top command to view additional information about the current system status and usage, such as uptime, average load, and total number of processes. If the installed memory usage is displayed, the top 15 processes are:
# top -b -o +%MEM | head -n 22
The output must be sorted in descending order using +%MEM (note the plus sign), option b is to run top in batch mode, o is to specify the sorting process field, head uses the program to display the first few lines of the file, and option n indicates the number of lines to display.
If using top output to redirect or save to a file in Linux:
# top -b -o +%MEM | head -n 22 > topreport.txt
The top utility provides more dynamic information when it lists processes on a Linux system.
Sort by RAM/CPU usage in Linux:
# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
The Ps o/format option supports user-specified output formats, such as PID, PPID, and CMD. sort can be used to sort, which is sorted in ascending order by default. Monitoring Linux servers is one of the jobs of a system administrator. It is necessary to regularly check which files/folders are taking up more disk space to find unwanted junk files and free them from the hard disk.
Find the largest directory/file in Linux:
# du -a /home|sort -n -r|head -n 5
The top 5 directories in the partition can be found in the output.
If you want to display the largest directory in the current working directory:
# du -a | sort -n -r | head -n 5
The du option is used to estimate the file space usage, a is to display all files and folders, sort is used to sort text files, n can be compared by string values, r is to invert the comparison results, head is the first part of the output file, and n is the first n lines of printing. If you need to output the file in a readable format:
# du -hs * | sort -rh | head -5
The above command will display the top-level directories that take up more disk space. If you feel that there are unimportant directories, you can delete them to free up space. Display the maximum folder/directory:
# du -Sh | sort -rh | head -5
Find only the maximum file size:
# find -type f -exec du -Sh {} + | sort -rh | head -n 5
To find the largest file in a specific location:
# find /home/tecmint/Downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5
or
# find /home/tecmint/Downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 5