Sep 8, 2018

DD, DU & DF - The Three Linux Commands You Should Commit To Memory

Over the course of my Linux use, I've found these three commands to be very helpful and they are worth committing to memory.

DD, the low-level data dumping utility is a dangerous but also one of the most useful commands when used lucidly. For instance, burning an ISO image to USB stick is just one command away:

sudo dd if=ubuntu-18.04.1-desktop-amd64.iso of=/dev/sdb bs=1M

Furthermore, if you want to "hard-wipe" your disk completely so that all data is permanently erased beyond recovery (for example, before handing your laptop in an exchange offer, or to a technician for repairs), all you need to remember is this one command:

sudo dd if=/dev/zero of=/dev/sda

This will wipe your disk entirely and there is no recovery possible, though some sysadmins are of the opinion that you should repeat the above at least three times to be absolutely sure!

DU, or the disk usage command is used for quickly estimating the drive space used in a folder or partition. For example, to display the space used by each file and folder in the current directory, you can simply run:

techtudor@ubuntu:/data/iso$ du -sh *
2.2G    ubuntu-18.04.1-desktop-amd64.iso
techtudor@ubuntu:/data/iso$

Another common use case is that you want to sort all current folder contents in the order of their size:

techtudor@ubuntu:/data/java$ du -sh * | sort -h
512     apache-ant-1.9.4-bin.tar.bz2.sha512
44K     hamcrest-core-1.3.jar
112K    flyingsaucer-R8-users-guide.pdf
112K    gs-serving-web-content-master.zip
136K    sqlite-jdbc-3.7.2-javadoc.jar
772K    yuicompressor-2.4.8.jar
848K    libGDX
957K    log4j
15M     tomcat
21M     javafx_samples-2_2_55-linux.zip
63M     gradle-2.4-all.zip

DF is finally used for estimating disk space but for the entire disk rather than a directory or folder. df -h is all you need to show which partition is how much full.


techtudor@ubuntu:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           384M  1.4M  383M   1% /run
/dev/sda2        49G   12G   35G  26% /
tmpfs           1.9G   15M  1.9G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda3       366G  128G  239G  35% /data
tmpfs           384M   32K  384M   1% /run/user/1000

After mastering DD, DU & DF commands, and making a habit of using them in your daily errands, you'll rarely ever need to open your actual file-manager such as nautilus or thunar!

No comments:

Post a Comment