↑ ↓ select, Enter open, Esc close

#disk-space

26 one-liners with this tag.

All one-liners tagged disk-space

Empty a file without deleting it

$truncate -s 0 -- /var/www/vhosts/example.com/logs/error_log
destructiveFilesystem

Analyze disk usage interactively with ncdu

$ncdu -x /var
harmlessFilesystem

Calculate the total size of all files of one type

$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f -iname '*.mp4' -printf '%s\n' | awk '{s+=$1; n++} END {printf "%d Dateien, %.1f MB\n", n, s/1048576}'
harmlessFilesystem

Check inode usage of filesystems

$df -ih -x tmpfs -x devtmpfs -x squashfs
harmlessFilesystem

Clean up unused Docker data

#docker system prune
cautionDocker

Delete downloaded package files from the apt cache

#du -sh /var/cache/apt/archives && apt clean
cautionDebian and APT

Disk usage of all webspaces under /var/www/vhosts

#du -sh /var/www/vhosts/*/ 2>/dev/null | sort -rh | head -20
harmlessPlesk

Find deleted files still held open

#lsof -nP +L1
harmlessFilesystem

Find the 20 largest tables on the server

#mysql -e 'SELECT table_schema, table_name, ROUND((data_length + index_length) / 1024 / 1024, 1) AS mb, table_rows FROM information_schema.tables ORDER BY data_length + index_length DESC LIMIT 20;'
harmlessMySQL and MariaDB

Find the largest files in a directory

$find /var/www/vhosts -type f -size +500M -exec ls -lh {} + 2>/dev/null | sort -k5 -rh | head -20
harmlessFilesystem

Find the largest files in the entire Git history

$git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | awk '$1=="blob"' | sort -k3 -rn | head -n 20
harmlessGit

Find the largest log files on the server

#du -ah /var/log 2>/dev/null | sort -rh | head -20
harmlessLogs

Force log rotation immediately

#logrotate -vf /etc/logrotate.d/nginx
cautionLogs

List installed packages sorted by size

$dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -rn | head -n 20
harmlessDebian and APT

Mailbox disk usage per domain in Plesk

#du -sh /var/qmail/mailnames/*/ 2>/dev/null | sort -rh | head -20
harmlessPlesk

Permanently limit the size of the systemd journal

#mkdir -p /etc/systemd/journald.conf.d && printf '[Journal]\nSystemMaxUse=500M\n' > /etc/systemd/journald.conf.d/size.conf && systemctl restart systemd-journald
cautionsystemd

Remove dangling Docker images

#docker image prune
cautionDocker

Show details and disk usage of a Plesk subscription

#plesk bin subscription --info example.com
harmlessPlesk

Show disk space used by the systemd journal

#journalctl --disk-usage
harmlesssystemd

Show Docker disk usage by images, containers and volumes

#docker system df -v
harmlessDocker

Show free disk space on all filesystems

$df -hT -x tmpfs -x devtmpfs -x squashfs
harmlessFilesystem

Show the disk usage of Docker containers

#docker ps -a --size
harmlessDocker

Show the size of all databases in MB

#mysql -e 'SELECT table_schema AS db, ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS mb FROM information_schema.tables GROUP BY table_schema ORDER BY mb DESC;'
harmlessMySQL and MariaDB

Show the size of all subdirectories

$du -xh -d 1 /var/www/vhosts 2>/dev/null | sort -rh | head -20
harmlessFilesystem

Show the size of WordPress database tables

$wp db size --tables --path=/var/www/vhosts/example.com/httpdocs
harmlessWP-CLI

Shrink the systemd journal to a maximum size

#journalctl --vacuum-size=500M
destructivesystemd

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.