This reference is meant to contain commands and other pieces of info that are hard to keep in mind all the time, but that come in handy every now and then while trying to accomplish tasks in a Linux shell.
If some of the commands mentioned below are not available on your system, you can check my Linux Mint Software Checklist where I have listed all of the packages / software sources I add to a fresh LM installation.
I assume most Linux users are probably aware of the following commands, and hence I won't be touching on them in this reference: sudo
, su
, pwd
, ls
, cd
, mkdir
, mv
, cp
, rm
, touch
, echo
, cat
, grep
, less
, view
, vim
.
If you don't know what they do, make sure to check them out before proceeding further (if you need some learning materials, take a look at the links in the end of this document).
apropos docker
- show names / descriptions of man pages matching a keywordman bash
- show the manual page for a commandtldr tar
- show examples of using a commmand (find out more at tldr.sh)
lsb_release -a
- print distribution-specific infoinxi -F
- print the detailed system / hardware infowhoami
- return the current user nameuname -a
- print out some basic system info (e.g. Kernel version)ps -p $$
- print out which shell is in useuptime
- show the time the system was up and the load averagesdate
- show the current date and timelsusb
- list USB deviceslspci
- list PCI deviceslsblk
- list block devices (e.g. disk partitions and loopback devices)
top
- show linux processes, cpu utilization, memory usage etchtop
- an "improved" version oftop
glances
- an alternative tohtop
, includes disk and network statsvmstat 1
- print out (every second) the resource utilization in a tabular formatfree
- display the amount of free and used memoryiostat 1
- report (every second) read/write and other statistics for devices and partitionss-tui
- show graphs of frequency, utilization and temprature of CPU, as well as the power usagesudo powertop
- power consumption / power management toolstress -c 4
- run 4 CPU-loading workers (can also stress-test memory, io etc.)sudo tlp-stat --battery
- show the battery charge and capacity
ps aux | grep java
- show running java processespstree
- show running prcesses as a treekill pid
- send a signal for the process to terminate (orkill -9 pid
to forcefully terminate the process)crontab -l
- list (edit) cron jobs of the current userreboot
- signal system to rebootpoweroff
- send the ACPI signal to the system to power down (works great with Alt+F2 in Cinnamon/Gnome)halt
- terminate all processes and stop all the CPU functions (but leave it powered on)shutdown -h now
- shut down the system now (similar topoweroff
)
dmesg --level err,warn
- show errors / warnings in the kernel ring buffersudo systemctl start|stop|restart|reload docker
- start/stop/restart/reload a systemd unit (e.g. docker daemon)sudo service --status-all
- show status of all services (can also start/stop/restart/reload individual services)journalctl -b
- show all journald messages from this bootstrace -f script.py
- trace system callsman 2 open
- shows a manual for a system call
dpkg -l
- lists all installed packagesdpkg -S /usr/bin/ab
- shows the package owning a fileapt search linux-image-*
- searches repos for a packageapt policy linux-image-4.13.0-45
- shows repositories that contain the package
whereis ls
- locate the binary, source, man page for a commandln -s file symlink
- create a symbolic link to a file / foldermd5sum file.tar.gz
- calculate MD5 checksumfind ~/Document -name *.sh
- find files under the given directorytar xzf source.tar.gz
- extract a gzipped tarball in the current directorygzip -d source.gz
- decompress a gzipped filezip -r my.zip ~/Documents
- package and compress a directory as a zip filesed -i -e 's/find/replace/g' filename
- replaces a string in a fileperl -p -i -e 's/find/replace/g' filenames
- replaces a string in one or more files
id
- print current user and group IDssudo useradd john
- create a new usersudo passwd john
- change password of the user (or justpasswd
for the current user)sudo userdel -r john
- remove the user and their home directorysudo groupadd visitor
- create a new group (groupdel
to delete a group)sudo adduser john visitor
- add the user to the groupw
andwho
- show who is logged in and their activitychmod u+x script.py
- make a file executable by the user owning itchown ubuntu:ubuntu ~/Applications
- change ownership of a file / directoryfinger john
- show info about a user
file -s /dev/nvme0n1
- determine file type (especially useful to get info on filesystem types)df -h
- report disk space usagedu -sh ~/Documents
- estimate file / directory space usagedd if=file.iso of=/dev/usb_drive status=progress
- make a bootable usb drive from an isohybrid filesync
- write all pending writes on all disks (e.g. to make suredd
is finished)sync; echo 1 > /proc/sys/vm/drop_caches
- clean PageCache (may come in handy when benchmarking)findmnt
- list (or search in) all mounted file systemsmount /dev/sdb2 /media/myusername/usb/
- mount a file system (e.g. usb drive)umount /dev/sdb*
- unmount a file system (e.g. usb drive)mkfs.ext4 /dev/sdb2
(and bunch of othermkfs.*
) - create a filesystem in a disk partitionsudo fdisk -l
- list / manipulate disk partitions (using MBR, hence only for <2TB disks)gdisk
- GPTfdisk
(supports disks >2TB)sudo parted -l
- an alternative tofdisk
/gdisk
rsync
- sync files to / from a remote host
ssh -L 9999:remote-postgres:5432 bastion-host
- connect remotely to servers / create tunnels to access resources from a different networkscp myapp.jar remote-server:/tmp/myapp-1.0.jar
- copy file(s) securely over SSHwget http://example.com/backup.zip
- non-interactive download of files over HTTP(S) and FTPcurl -XGET http://example.com/api/v1/user/123
- transfer data over HTTP, FTP and other protocolsab -n 100 url
- Apache HTTP server benchmarking tool (WARNING! don't DDoS servers you don't own)
nmcli
- a cli tool for controlling NetworkManagerping 8.8.8.8
- test connectity between host and provided IPtraceroute 8.8.8.8
ortracepath 8.8.8.8
- trace packets route to a hostdig example.com
ornslookup example.com
- tools for "interrogating" DNS name serversip address
(or now deprecatedifconfig
) - show / manipulate network interfacesip route
(or now deprecatedroute
) - show / manipulate the IP routing tableip link set eth0 up/down
(ifup
/ifdown
) - enable / disable a network interfacess -a
(or now deprecatednetstat
) - list open socketsss -lntup
(orsudo netstat -ltup
) - list ports that are being listened on & PIDs holding those portslsof -i :8080
- show the process listening on a local portiw
(or now deprecatedifconfig
) - show / manipulate wireless devicestcpdump -i eth0 port 80
- capture traffic off a network interfacetcpflow -c -i eth0 port 80
- capture and save traffic for analysis / debuggingnmap
- network exploration tool / port scannernc
(or more versatilesocat
) - listen on / connect to ports, forward packets etc.ipcalc 192.168.1.1/24
- calculate details of a given CIDR
env
- print all environment variableshistory
- print the history of executed commandswhich
- locate a command in $PATHcat args.txt | xargs command
- turn each line of input into an argument for a commandalias l='ls -l'
- create an alias for the commandsleep 30 > output.log 2>&1 &
- run a command in the background, redirecting its output to a filejobs
- list processes started by the current shell (e.g. with&
or by pressing Ctrl+Z)fg
- run a previously suspended (or started in backgroud) process (spawed by the current shell) in the foregroundbg
- run a previously suspended process in the backgroundnohup sleep 30 &
- allow the process to outlive the shell that it was started from (by ignoring HUP signal)time sleep 1
- measure time the command takes to executewatch
- run a command repeatedly, monitoring the outputcat my.txt | head -n 10
- limit output to first n linestail -n 10 -f output.log
- show last n lines and then keep reading from (following) the fileecho "hello" | tee trace.txt
- read from std in and write to std out cloning output to a file / another commandcat output.log | grep keyword | wc -l
- count the number of (lines or words), here only those containing a keyword due togrep
vmstat 1 | awk '{print $1}'
- use AWK programming language (here used to extract 1st column of a tabular output)cat file.json | jq .
- prettify / process JSON
cal
- display a calendarbc
- start a calculator language interpretorstartx
- initialize an X session (very unlikely that you will ever need to use this command)xrandr --output DP-2-2 --same-as eDP-1
- list / manage displaysupdate-grub
- generate grub config file (delegates togrub-mkconfig
)
umount /dev/sdb*
sudo fdisk -l
and figure out how the USB drive is called (e.g./dev/sdb
)sudo mkfs.vfat /dev/sdb -I
dd if=~/Documents/ISOs/linuxmint-19-cinnamon-64bit-beta.iso of=/dev/sdb status=progress
sudo hdparm -Tt /dev/sda
- to get the read performanceioping -c 10 -s 1M /tmp
- to measure latency using 10 requests of 1 megabyte eachfio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=/tmp/random_read_write.fio --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75
dd if=/dev/zero of=/tmp/output conv=fdatasync bs=384k count=1k; rm -f /tmp/output
- to test the write performance
NOTE: Before Bash executes the shell-related dot files mentioned below, it also executes commands from /etc/profile
or /etc/bash.bashrc
(all depending on the type of the shell). You can find more info on this topic in man bash
.
.bash_profile
- is executed (by Bash) for interactive login shells (in my case it simply sources.bashrc
).bashrc
- is executed (by Bash) for interactive non-login shells (e.g. the ones started by Tmux, Guake or any other GUI Terminal).bash_aliases
- (at least in my case) is sourced directly by.bashrc
, and contains various command aliases / functions.profile
- is executed (by Sh, or other shell types if their config is missing) for interactive login shells.inputrc
- configuration of GNU readline (I only use it to make Bash auto-completion ignore case).selected_editor
- allows setting the default text editor, which, for example, is opened bycrontab -e
.xsessionrc
- is executed on Debian / Ubuntu / Linux Mint by X startup scripts on a GUI login.gitconfig
- global configuration for Git (the version control tools).npmrc
- configuration fornpm
, NodeJS package manager.tmux.conf
- configration for Tmux.ssh/config
- configuration for SSH client (allows defining aliases for hosts, keys to be used for each server etc.).gnupg/gpg.conf
- gpg/gpg2 configuration.gnupg/gpg-agent.conf
- gpg agent configuration (if you are using gpg-agent instead of ssh-agent).vimrc
- configuration for VIM editor (see Example vimrc)
~/.xsession-errors
- error log produced by X server (look here if you have troubles logging into the system)~/.local/share/applications/
- stores user-specific desktop files (place your custom desktop files here)/etc/fstab
- static file system configuration (link to wiki)/etc/passwd
- a system-wide list of all users, their IDs, home directories etc./etc/group
- a system-wide list of all groups (and their members)/etc/hostname
- contains hostname of the pc/etc/hosts
- local DNS resolution rules/usr/lib/jvm/
- directory whereapt
/dpkg
will install Java/var/log
- contains logs generated by the OS and other apps
A list of links to other similar pages or good reference points for specific topics:
- Bash shortcuts
- Vim shortcuts
- Tmux shotcuts
- Linux Mint Community: Terminal Command Reference
- Linux Commands - A practical reference
- 100 Useful Unit Commands
- Deprecated Linux networking commands
- Advanced Bash-Scripting Guide
- Bash scripting cheatsheet
- Guide to using YubiKey as a SmartCard for GPG and SSH
- Linux DD Command - 15 Examples with All Options