From the course: Linux Tips
Managing space on the file system - Linux Tutorial
From the course: Linux Tips
Managing space on the file system
- [Instructor] On any system, managing the available storage space is important. In this episode, I want to show you a few tools to view the available space and to find large files that you might want to keep an eye on if you're running low on disk space. The first tool I want to show you is df and it gives you very high-level view of how much space is available on your file systems. I like to use it with the -h option for human-readable sizes. Here, I can see that I have 87 gigabytes available of the 98 gigabytes available on my root file system. We can use also use the command with the path to show just one file system to narrow down the display a little bit. I'll write df -h and slash for the root file system. And here I can see that isolated from all of the other things. To take a look at storage on the system from the other side so to speak, we can see how much space a certain file or directory takes up. To do that, we'll use the du command followed by some options and the path to look at. Let's take a look at the etc directory to see how much space it takes up. du reports the size for each file and it recurses into directories and that can be useful, but here it's kind of annoying. So we can use a few options to make this a bit easier to read. I'll write du -hd1 /etc. The h option displays the sizes as human readable instead of as blocks. And d sets the depth to display. I set that to 1 so whenever du finds a directory, it goes to maximum depth of one directory. It'll still add up everything inside those directories, but we won't see a line for each deeper item. We'll get the summary of the sizes for each directory that's one level deeper than etc and this can be useful. I'll run that, but if we just want the size of the directory, we can tell du to go zero directories deep with du -hd0 /etc and we can get the same result with du -sh and the path. Here, s stands for summary. So du is good for exploring how much space a file or a directory takes up. And there's some interesting tools based on du like duviz, dutree, and ncdu, but they're not part of the standard complement of tools so I won't go over them here. A third way of looking at space is to find files larger than a given size. Rather than hunting around for big directories and trying to peer down what files contribute to the size of the folders, we can use the find command to look for large files. I'll type find and then a slash for the root of the file system. Then, I'll look for object of type file with a size greater than two megabytes. The +2M here looks for files taking up more than two megabytes. And I could use a minus to look for files smaller than a specified size too. I'd also use capital G for gigabytes and lowercase k for kilobytes. Okay, there's a few files larger than two megabytes on my system. We can add a little more information here by sending the results of the search through ls to get the size of the files. And for that, we'll use the exec option and send the response through ls with -sh for summary and human-readable sizes. After that, I'll use a set of braces to represent the result for each line and then I'll add an escape semicolon. And here on the left, I can see the size of the files that my user has permission to access. We can take this one step further by sorting the results by size, piping them through sort with -h for human size sorting. Once again, I can see the size of each file on the left, but now they're sorted. This kind of thing can be useful for periodic reports that you make into script and run automatically. If you're working with a system where lots of people store files, you can summarize large files now and then, and see if those files represent a problem in terms of space. You can also wrap up the output of df in a script for a report on what percentage of the file system is free or to look for a minimum amount of free space. But remember, if you're using bash to do math, you'll want to use numeric values, not human-readable values so you don't have to parse as much. One tricky place to manage free space is the boot file system. Occasionally, if your boot file system is on a partition that's too small, a long history of updates or a broken-up date can end up filling up the file system causing problems with later updates or with booting the system at all. It's important to keep an eye on the free space on boot and manage it in a way that's appropriate for your system. You can use apt autoremove on Debian and use rpm in the Red Hat ecosystem to remove old kernels that you're not using. And when you're done, run update-grub to remove those old kernels from the boot menu. If you have lots of users storing files on your system, it can be worth looking into quotes as well. Quotas limit users to only taking up a pre-defined amount of space so if you get your math right, you can prevent them from filling up your storage completely. Running out of space is one of those things you don't want to have sneak up on you. When a system is out of space, it can cause all sorts of interesting problems including preventing the system from starting up correctly. So if you manage many systems or just one, keep an eye on your available space.
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
Foundations: What's Linux?5m 26s
-
Foundations: Distros10m 50s
-
(Locked)
Foundations: Installing Linux in a virtual machine6m 30s
-
(Locked)
Foundations: USB installer7m 46s
-
(Locked)
Foundations: Installing Linux5m 17s
-
(Locked)
Foundations: Dual-booting your system4m 18s
-
(Locked)
Foundations: Core Utilities4m 40s
-
(Locked)
Foundations: Linux on a VPS4m 2s
-
(Locked)
Linux on Azure7m 21s
-
(Locked)
Google Cloud Platform3m 37s
-
(Locked)
Linux on DigitalOcean6m 39s
-
-
-
System basics: The Linux file system6m 35s
-
(Locked)
System basics: The command line5m 23s
-
(Locked)
System basics: Keyboard shortcuts1m 40s
-
(Locked)
System basics: sudo access and root4m 57s
-
(Locked)
System basics: Explore a system4m 38s
-
(Locked)
System basics: Exploring Bash7m
-
(Locked)
System basics: Bash scripting basics4m 59s
-
(Locked)
System basics: The Bash prompt6m 2s
-
(Locked)
System basics: Bash output redirection4m 57s
-
(Locked)
Bash expansions and substitutions4m 23s
-
Bash aliases and functions4m 7s
-
(Locked)
Bash operators6m 55s
-
Logs5m 4s
-
(Locked)
Grub3m 19s
-
(Locked)
SysV init4m 43s
-
(Locked)
Systemd5m 29s
-
(Locked)
Cron8m 7s
-
(Locked)
Understanding chroot3m 16s
-
(Locked)
System basics: User and group management8m 39s
-
(Locked)
System basics: Service management3m 44s
-
(Locked)
Backing up data with rsync5m 35s
-
(Locked)
Splitting and combining files3m 3s
-
(Locked)
Environment configuration files2m 43s
-
(Locked)
Working with dotfiles1m 43s
-
(Locked)
Exploring the PATH variable3m 51s
-
(Locked)
Browsing with the directory stack3m 19s
-
(Locked)
Finding or locating files3m 52s
-
(Locked)
Working with swap4m 29s
-
(Locked)
Read and write caches3m 5s
-
(Locked)
Terminals, consoles, and TTYs4m 27s
-
(Locked)
Exploring journalctl5m 2s
-
-
-
Files on Linux4m 10s
-
(Locked)
File system basics: Archives6m 22s
-
(Locked)
File system basics: Permissions 1014m 43s
-
(Locked)
Loop devices4m 35s
-
(Locked)
Configuring group file shares4m 37s
-
Managing space on the file system5m 3s
-
(Locked)
Overlay file systems4m 17s
-
Bind mounts2m
-
(Locked)
Modifying the file system table7m 44s
-
(Locked)
Sticky bit4m 39s
-
(Locked)
Access control lists4m 6s
-
-
-
Working with text: Vim 1015m 15s
-
(Locked)
Working with text: Emacs 1015m 42s
-
(Locked)
Working with text: nano 1015m 29s
-
(Locked)
Working with text: grep4m 23s
-
(Locked)
Working with text: Regular expressions4m 57s
-
(Locked)
Working with text: sed7m 24s
-
(Locked)
Working with text: AWK2m 51s
-
(Locked)
Working with text: cut and sort4m 14s
-
(Locked)
Working with text: ed 1016m 17s
-
-
-
Package management: Basics6m 59s
-
(Locked)
aptitude5m 43s
-
(Locked)
dpkg2m 20s
-
(Locked)
yum and DNF4m 58s
-
(Locked)
RPM3m 24s
-
(Locked)
Creating your own packages3m 12s
-
(Locked)
Adding third-party repositories with APT7m 6s
-
(Locked)
Adding third-party repositories with Yum1m 46s
-
(Locked)
Create a local APT repository7m 25s
-
(Locked)
Create an APT repository for your network5m 56s
-
(Locked)
Mirror repositories to save bandwidth3m 5s
-
(Locked)
Zypper4m 17s
-
(Locked)
Using Flatpak4m 11s
-
(Locked)
Using snaps3m 15s
-
(Locked)
Package management: PPAs4m 24s
-
(Locked)
Homebrew package management7m 43s
-
(Locked)
Using AppImage apps2m 34s
-
-
-
Remote files: curl and wget4m 42s
-
(Locked)
SSH: Secure access8m 8s
-
(Locked)
SSH: Transferring files with scp and sftp5m 59s
-
(Locked)
SSH: Managing and distributing keys6m 34s
-
(Locked)
SSH: Tunnels3m 46s
-
(Locked)
Browsing the web through a proxy server4m 28s
-
(Locked)
X11 forwarding2m 52s
-
(Locked)
Using a SOCKS proxy4m 53s
-
(Locked)
Using a Squid proxy8m 43s
-
(Locked)
Using mosh5m 11s
-
(Locked)
SSH: Reverse tunnel4m 1s
-
-
-
Process management: ps4m 30s
-
(Locked)
Process management: top4m 53s
-
(Locked)
Process management: htop6m 11s
-
(Locked)
Process management: System load2m 53s
-
(Locked)
Process management: fg, bg, and kill4m 35s
-
(Locked)
Manage terminal sessions with screen4m 17s
-
(Locked)
Manage terminal sessions with tmux3m 16s
-
(Locked)
Customizing tmux3m 32s
-
-
-
Firewall basics4m 5s
-
(Locked)
Understanding iptables6m 41s
-
(Locked)
Exploring UFW: Uncomplicated firewall5m 29s
-
(Locked)
File checksums3m 48s
-
(Locked)
Services: Network Time Protocol (NTP)3m 45s
-
(Locked)
Encrypting files7m 14s
-
(Locked)
Encrypted filesystems6m 58s
-
AppArmor4m 2s
-
(Locked)
Security systems: SELinux4m 33s
-
(Locked)
Firewalls: firewalld7m 41s
-
-
-
(Locked)
Disks and partitions6m 42s
-
(Locked)
Logical volume management9m 58s
-
(Locked)
Create a RAID array9m 10s
-
(Locked)
Repairing a RAID array4m 44s
-
(Locked)
Local IP address5m 15s
-
(Locked)
Predictable network interface names4m 51s
-
(Locked)
DNS5m 40s
-
(Locked)
VPN1m 43s
-
(Locked)
Exploring system hardware5m 7s
-
(Locked)
Drivers and modules4m 16s
-
(Locked)
Understanding QEMU and KVM2m 49s
-
(Locked)
Creating a VM with QEMU and KVM3m 46s
-
(Locked)
Private networking6m 37s
-
(Locked)
Routing and forwarding4m 26s
-
(Locked)
DHCP4m 55s
-
(Locked)
Network troubleshooting7m 42s
-
(Locked)
Wi-Fi on Linux4m 14s
-
(Locked)
Set up a secure tunnel with WireGuard8m 38s
-
(Locked)
Scanning network ports with Nmap4m 28s
-
(Locked)
-
-
(Locked)
Desktops: Basics3m 8s
-
(Locked)
Desktops: GNOME4m 41s
-
(Locked)
Desktops: Xfce4m 5s
-
(Locked)
Desktops: KDE Plasma Desktop2m 28s
-
(Locked)
Desktops: LXQt3m 42s
-
(Locked)
Desktops: i3wm5m 8s
-
(Locked)
Sharing your desktop with VNC5m 8s
-
(Locked)
Remote desktop login with xrdp5m 14s
-
(Locked)
Display geometry with GRUB5m 21s
-
(Locked)
Display geometry with xrandr4m 4s
-
(Locked)
-
-
(Locked)
Exploring Windows Subsystem for Linux2m 20s
-
(Locked)
Windows Subsystem for Linux7m 20s
-
(Locked)
Exploring virtualization5m 28s
-
(Locked)
Exploring containers5m 19s
-
(Locked)
Exploring Fedora3m 8s
-
(Locked)
Ubuntu desktop 18.042m
-
(Locked)
Changing the default shell3m 30s
-
(Locked)
Exploring other shells2m 5s
-
(Locked)
Blocking ads on your network with Pi-hole6m 35s
-
(Locked)
Exploring CentOS2m 6s
-
(Locked)
Exploring Zsh5m 41s
-
(Locked)
Osquery4m 28s
-
(Locked)
Exploring fish5m 21s
-
Exploring csh and tcsh2m 34s
-
(Locked)
Using diff to compare files3m 54s
-
(Locked)
Using xargs3m 41s
-
(Locked)
Configuring and managing logs4m 32s
-
(Locked)
Job control3m 59s
-
(Locked)
Using watch and time3m 5s
-
(Locked)
Recording a terminal session3m 14s
-
(Locked)
Exploring Debian1m 49s
-
(Locked)
Exploring SUSE Linux7m 33s
-
(Locked)
Exploring Arch Linux16m 44s
-
(Locked)
Exploring Alpine Linux6m 18s
-
(Locked)
Exploring Linux Mint5m 14s
-
(Locked)
Exploring Amazon Linux5m 8s
-
(Locked)
UNIX time and the 2038 problem6m 36s
-
(Locked)
Visual file management with Midnight Commander5m 42s
-
(Locked)
Terminal on the go5m 1s
-
(Locked)
FUSE and SSHFS3m 54s
-
(Locked)
Removing Linux4m 44s
-
(Locked)
WSL distros on Windows 103m 13s
-
(Locked)
Embedded Linux4m 25s
-
(Locked)
Exploring Netboot2m 43s
-
(Locked)
Exploring ZFS3m 53s
-
(Locked)
Docker on Linux5m 24s
-
(Locked)
-
-
(Locked)
Planning a home server6m 11s
-
(Locked)
Backups with rsync6m 18s
-
Linux on an old PC6m 7s
-
(Locked)
Creating a disk image with dd3m 54s
-
(Locked)
Mounting and writing disk images with dd7m 1s
-
(Locked)
Migrating to a new distro4m 33s
-
(Locked)
Planning a portable bootable disk3m 12s
-
(Locked)
Creating a portable bootable disk5m 30s
-
(Locked)
Host your own Apache web server5m 32s
-
(Locked)
Set up Let’s Encrypt on a web server5m 3s
-
Host a personal cloud with Nextcloud4m 50s
-
(Locked)
Hosting email services3m 7s
-
(Locked)
Set up a print server with CUPS6m 5s
-
(Locked)
Create a network PDF printer4m 37s
-
(Locked)
Remote logging with Rsyslog7m 12s
-
(Locked)
Set up a Git server4m 15s
-
(Locked)
NGINX web server4m 11s
-
(Locked)
Share files with a Samba server3m 35s
-
(Locked)
Set up an NFS server3m 58s
-
(Locked)
Monitoring your server2m 49s
-
(Locked)
Exploring Internet Relay Chat (IRC)6m 6s
-
(Locked)
Keep on learning!35s
-
(Locked)