Linux command to list large files in a folder
ls -lSsh /path | List large files in the path and sort by size Example: ls -lSsh /var/log |
ls -lSsh /path | head -n 10 | List top 10 large files in the path Example: ls -lSsh /var/log | head -n 10 |
ls –help | l = List one per line S = sort by size, largest files first s = print the allocated size of each file in blocks h = human readable |
Linux command to truncate size of large files
truncate -s {size_MB_GB} {file_and_path} | Truncate command to either shrink or expand the size of a file |
Replace with the desired size in bytes, kilobytes (K), megabytes (M), gigabytes (G), or terabytes (T), and with the name of the file you want to truncate.
Example:
truncate -s 800MB /var/log/user.log
Note that this command will permanently delete any data in the file that is beyond the specified size. So, make sure to back up any important data before truncating a file.