It's best to search distribution's manual/official help pages before trying commands found on Internet, including ones here. Certain seemingly short commands can instantly break your installation and - rarely - command parameters differ, leading to behavior different from expected.
In all examples, cat could be replaced with less with few crucial considerations:
- less opens file in interactive browser (and is not always installed in container images) - suitable for browsing content of file by human
- cat prints entire content of file in terminal (potentially locking it and erasing commands history if file is long) - suitable for use both in scripts and manually
Notes regarding easy of use
- human-friendly - can be interpreted at a glance (the default)
- script-friendly - have somewhat stable formatting making it easy to parse
- verbose - sometimes hard to read manually
General info
Getting information about shell built-in functions and commands.
help
Shows help page for built-inhelp command
man
Shows manual entry page for commandman command
Persistent sessions
Preventing programs terminating due to connectivity issues.
tmux
- Open tmux session (programs running in it will continue to do so even if your ssh connection is interrupted
and ssh session terminates)
tmux
- List open tmux sessions
tmux ls
- Reattach to open tmux session (to resume work)
tmux a
- Reattach to open tmux session SESSION_ID (to resume work)
tmux a -t SESSION_ID
Disk and space
Checking space usage and available disks.
Information about disk devices (script-friendly, verbose)
cat /proc/diskstats
df
- Lists disk usages (sizes in human-friendly format, file system names included)
df -hT
- Lists disk usages (sizes in human-friendly format, file system names included, some formats excluded and
sorted)
df -hTx tmpfs -x vfat|sort -r
lsblk
Lists block devices excluding loop device (for example, snap devices)lsblk -e 7
Lists block devices with serial number (if any)
lsblk -o +SERIAL
System info
- Shows OS information
less /etc/os-release
- Memory info (script-friendly, verbose - 55 lines)
cat /proc/meminfo
-
swap info (script-friendly)
less /proc/swaps
- Load average info (script-friendly, somewhat verbose - 5 values; first 3 are jobs that are in the run queue
- state R - or waiting for disk IO - state D averaged over 1, 5 and 15 minutes then number of
processes/threads that are currently being executed - up to number of vCPUs slash and total numer of
processes/threads then PID of the process most recently created on the system)
cat /proc/loadavg
- CPU info (script-friendly, verbose)
cat /proc/cpuinfo
htop
Start program listing system CPU/memory loads and list of processeshtop
free
Memory and swap info (sizes in human-friendly format)free -h
swapon
swap info (human-friendly)swapon --show
uptime
Current hour, uptime then load averages over 1/5/15 minutesuptime
dmidecode
DMI - Desktop Management Interface (SMBIOS - System Management BIOS) table content in human-readable format (description of hardware components, serial numbers, BIOS revisionsudo dmidecode
Display value of DMI string identified by KEYWORD:
-s
,
--string
(skipping KEYWORD prints available options). Most of those can be read directly from sysfs at
/sys/devices/virtual/dmi/id
sudo dmidecode --string KEYWORD
Display entries of type TYPE:
-t
,
--type
(skipping TYPE prints available options)
sudo dmidecode --type TYPE
DMI types:
Type | Information |
---|---|
0 | BIOS |
1 | System |
2 | Baseboard |
3 | Chassis |
4 | Processor |
5 | Memory Controller |
6 | Memory Module |
7 | Cache |
8 | Port Connector |
9 | System Slots |
10 | On Board Devices |
11 | OEM Strings |
12 | System Configuration Options |
13 | BIOS Language |
14 | Group Associations |
15 | System Event Log |
16 | Physical Memory Array |
17 | Memory Device |
18 | 32-bit Memory Error |
19 | Memory Array Mapped Address |
20 | Memory Device Mapped Address |
21 | Built-in Pointing Device |
22 | Portable Battery |
23 | System Reset |
24 | Hardware Security |
25 | System Power Controls |
26 | Voltage Probe |
27 | Cooling Device |
28 | Temperature Probe |
29 | Electrical Current Probe |
30 | Out-of-band Remote Access |
31 | Boot Integrity Services |
32 | System Boot |
33 | 64-bit Memory Error |
34 | Management Device |
35 | Management Device Component |
36 | Management Device Threshold Data |
37 | Memory Channel |
38 | IPMI Device |
39 | Power Supply |
40 | Additional Information |
41 | Onboard Devices Extended Information |
42 | Management Controller Host Interface |
Keyword | Type |
---|---|
bios | 0, 13 |
system | 1, 12, 15, 23, 32 |
baseboard | 2, 10, 41 |
chassis | 3 |
processor | 4 |
memory | 5, 6, 16, 17 |
cache | 7 |
connector | 8 |
slot | 9 |
Logs
journalctl
Continuously display logs of servicesudo journalctl -u SERVICE_NAME -f
Further details: page about systemd
dmesg
Checking kernel logssudo dmesg
Log file
less /var/log/dmesg
tail
Print file content and continue printing it as it comestail -f path_to_file
Searching for things
find
Helps find file based on its properties or name.- List all files in current directory and its subdirectories
find . -type f | less
- List all files in /path directory and its subdirectories with names ending with .html
find /path -name *.pdf -type f | less
- List all files and directories in current directory and its subdirectories that are not owned by USER
find . \! -user USER
- Execute COMMAND with relative path to all files and directories in current directory and its subdirectories
find . -exec COMMAND {} \;
grep
Helps locate file containing specific content.- Finds FOOBAR in all files in current directory
grep -s "FOOBAR" *
- Finds FOOBAR in all files in current directory or its subdirectories
grep -rs "FOOBAR" *
- Finds all instances of FO followed by any number of any characters (new lines included) then AR in all
files in current directory or its subdirectories
grep -rse "FO.*AR" *
- Finds all instances of FO followed by any number of most characters (new lines not included) then AR in
all files in current directory or its subdirectories
grep -rse "FO*AR" *
- Finds all instances of FO followed by any two characters (number of dots, new lines included) then AR in
all files in current directory or its subdirectories
grep -rse "FO..AR" *
Other
- Reboots system to UEFI/BIOS
systemctl reboot --firmware-setup
- Minimal image viewer
sudo apt install feh
feh PATH
- Minimal PDF viewer
sudo apt install evince
evince PATH
- Minimal video player
sudo apt install ffmpeg
ffplay PATH
Last update: 2024-08-10