Docs
General
Storage

Storage Usage

Start by running this to see which root path is taking up the most space.

du -cha --max-depth=1 / | grep -E "^[0-9\.]*[MG]"

The [MG] limits the lines to be either MBs or GBs. If your disk is big enough add add T as well for TBs.

The command might return some errors on /proc, /sys, and /dev since they are not real files on disk. However, it should still provide valid output for the rest of the directories in root. After finding the biggest directory, rerun the command again narrow down the search.

For example, if /var takes up unnecessary space, run this next.

du -cha --max-depth=1 /var | grep -E "^[0-9\.]*[MG]"

Commands

# 10 largest files in /var
du -ah /var | sort -n -r | head -n 10
 
# mount disk usage and availability
df -h
 
# storage usage visualization
ncdu

Unlinked Storage Hogging

Display pid of resources that processes are holding onto even if the origin is deleted.

lsof | grep deleted | awk '{print $2}'

Applications using unlinked files can be printed using lsof +L1. Removing those files using their ids and killing the processes holding them.

# Extract the processes
lsof | grep deleted | awk '{print $2}' > ids
#!/bin/bash
input="./ids"
while IFS= read -r line
do
  kill -9 "$line"
done < "$input"

Recursive Delete

To delete a specific file recursively from current directory and all sub directories

find . -name "*.bak" -type f -delete
 
# run this first just to be safe
# it will list all files to be deleted
find . -name "*.bak" -type f

Make sure that -delete is the last argument of the command. If you put it before the -name *.bak argument, it will delete everything.

Site Permissions

Site permissions when popping up a new site.

sudo chown -R www-data:www-data loc/
sudo chmod -R 774 loc/

Manual Fonts

For a single user place fonts in:

~/.local/share/fonts

For system-wide fonts place them in:

/usr/local/share/fonts
 
# don't touch this
# it's only for pacman
/usr/share/fonts/

Source (opens in a new tab)

Tar

Compress a file into zst. You need zstd installed.

tar acf files.tar.zst files/

Decompress a file from zst

tar axf files.tar.zst

Specific Sized Files

Create a file with a specific size. Write the size as 5M or 10G.

truncate -s <size> <file.txt>

Binary Executables

To run binary executables from the terminal without having to specify the full path, you can add the directory containing the executable to the PATH environment variable. This can be done mainly in two ways.

First by adding the path of the executable into your respective shell's config file.

# bash
echo "export PATH=$PATH:/path/to/executable" >> ~/.bashrc
 
# fish
echo "set -gx PATH $PATH /path/to/executable" >> ~/.config/fish/config.fish

Second by moving the executable into a directory that is already in the PATH variable. Like /usr/local/bin. This is the recommended way.

sudo mv /path/to/executable /usr/local/bin