Linux Quick Reference Commands
Note
The "Command Example" are intended to be used within the a Linux terminal or console.
Archive Management
| Action | Command Example |
| Compress gzip | gzip -c file > foo.gz |
| Compress tar (directory) | tar -cvf archive.tar /home/username |
| Compress tar/gzip | tar -cvzf archive.tar.gz /home/foo/myfiles /home/foo/readme.txt |
| Compress tar/bzip2 | tar -cvfj archive.tar.bz2 /home/php |
| Compress tar (list of files/dirs) | tar -cvf archive.tar -I list_of_files_or_directories.txt |
| Compress tar/xz | tar -cvJf archive.tar.xz /directory/containing/files/* |
| Compress tar/zstd | tar -caf archive.tar.zst /directory/containing/files/* |
| Compress tar/zstd | tar --zstd -cf archive.tar.zst /directory/containing/files/ |
| Compress zstd | zstd file1.txt file2.text file3.txt |
| Decompress zstd | zstd -d archive.zst |
| Decompress tar/zstd | tar -I zstd -xvf archive.tar.zst |
| Decompress tar/zstd | unzstd files.zst |
| Decompress gzip | gunzip archive.gz |
| Decompress tar/bzip2 | tar -xvf videos-14-09-12.tar.bz2 |
| Decompress tar/gz | tar -zxvf archive.tar.gz |
| Decompress tar, specific files only | tar -xvf archive.tar '*.sql' |
| List archive contents tar/bzip2 | tar -jtvf archive.tar.bz2 |
| List archive contents tar/zstd) | tar -tf archive.tar.zst |
| List archive contents zip | unzip -l archive.zip |
| List archive contents zip | zip -sf archive.zip |
| List archive contents zip | zipinfo archive.zip |
| List archive contents rar | unrar l archive.rar |
File Management
| Action | Command Example | Notes |
| Determine File Type | file filename | Man page |
| Describes format/characteristics (images) | identify filename | Man page |
| Display file status | stat filename | Man page |
| Display technical/tag information (audio/video) | mediainfo filename | |
File Systems
| Action | Command Example |
| BTRFS Add Device | btrfs device add /dev/sdc /mnt |
| BTRFS Balance Devices | btrfs filesystem balance /mnt |
| BTRFS Change RAID Level | btrfs balance start -mconvert=RAIDLEVEL -dconvert=RAIDLEVEL /path/to/mount |
| BTRFS Change Label | btrfs filesystem label |
| BTRFS Show Devices | btrfs filesystem show |
| BTRFS Scan Devices | btrfs device scan |
| BTRFS Scrub Filesystem Start | btrfs scrub status /dev/sde |
| BTRFS Scrub Filesystem Status | btrfs scrub start /dev/sde |
| BTRFS Used/Free Space | btrfs filesystem df -h /mnt/backup-data/ |
| Action | Command Example | Info |
| Disk free space | df -h | |
| Disk Usage | t=$(df|awk 'NR!=1{sum+=$2}END{print sum}');du / --exclude /proc --exclude /sys --max-depth=1|sed '$d'|sort -rn -k1 | awk -v t=$t 'OFMT="%d" {M=64; for (a=0;a<$1;a++){if (a>c){c=a}}br=a/c;b=M*br;for(x=0;x<b;x++) {printf "\033[1;31m" "|" "\033[0m"}print " "$2" "(a/t*100)"% total"}' | More |
| Disk Information | di | |
| Disk Partitions, list | fdisk -l | |
| Disk Partitioning, fdisk | fdisk -H 224 -S 56 /dev/sdb1 | |
| Disk Partitioning, gdisk | gdisk | |
| Disk Image - Create | dd if=/dev/sdb of=~/image.img | |
| Disk Image - Write | dd bs=4M if=~/image.img of=/dev/devicename | |
Package Management
| Action | Command Example |
| List packages | sudo apt list --installed |
| List packages | sudo dpkg-query -l |
Schedule Job
| Action | Command Example |
| Crontab as another user edit | crontab -u username -e |
| Crontab as another user list | crontab -u username -l |
| Crontab as current user edit | crontab -e |
| Crontab as current user list | crontab -l |