brennanhm.ca

Curiosity to the Extreme

Linux Commands

File System

CommandDescriptionOptionsExampleSource
ls
List directory contents
-l list file details, -t sort by date, -h human readable sizes, -S sort by size
ls -l -t
mv
Rename or move a file
 
mv index.html index.php
cp
Copy file or directory from one location to another
-r recursive
cp -r mintupdate /home/santa/development
rm
Delete files and directories
-r recursive, -f force (no confirm messages)
rm -rf /home/santa/rudolf
Source
mkdir
Make new directory
-p Make parent directories as needed
mkdir -p isodir/boot/grub
ln -s [filename] [desktop_folder]
Create a desktop shortcut
 
ln -s /media/data/docs/linuxknowledge.odt /home/username/Desktop/
find . -name '[search pattern]'
Search recursively from working directory and find files matching a pattern
-name base of filename matches search pattern
find . -name '*.itk'
Source
du | sort -n
List directories and their sizes. Sort so largest come last.
 
du | sort -n
Source
mount -t vboxsf -o uid=[uid],gid=[gid] [sharename] [mount point]
Mount a Virtual Box Shared Folder on the client VM
-o options
mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename
Source
fdisk
List partition details
-l list
sudo fdisk -l
shred -u [filename]
Securely erase files (3x overwrite)
-u truncate and remove file after overwriting
shred -u will.odf
Source
find
Set group owner for all new files created within a directory tree
 
find /your/path/here -type d -exec chmod g+s /var/www/html {} \;
Source

General

CommandDescriptionOptionsExampleSource
dmesg -T
show syslog (dmesg) with readable timestamp (-T)
 
dmesg -T | grep error
gksu [command]
Graphical version of sudo (GTK+ frontend for su and sudo)
 
gksu gedit
ldconfig -p | grep [library]
Check if library is installed
 
ldconfig -p | grep libjpeg
glxinfo | grep OpenGL
Get OpenGL info
 
glxinfo | grep OpenGL
sudo shutdown
Reboot system
-v verbose -r restart
sudo shutdown -r -v now
md5sum [filename]
Check md5sum
 
md5sum linux*.iso
[script] 2>&1 | tee [output_file]
Redirect output from script to both a file and stdout. 2>&1 includes the STD_ERR. tee will redirect the output to file and also display it on the console.
 
backup 2>&1 | tee backupoutput.txt
dpkg -l [packagename]
Check if package is installed
 
dpkg -l *ssh*
wall < [messagefile]
Send broadcast message (as administrator)
 
wall < message.txt
tar xzvf [filename.tar.gz]
Uncompress tar and gz archive
x – extract archive z – filter through gzip v – verbose (show details) f – filename of archive
tar xzvf archive.tar.gz
uname -a
Check kernel version
a - all information, r - print kernel release
uname -a
grep -rnw /path/to/somewhere -e pattern
Search for a string within multiple files recursively
 
grep -rnw /tmp -e prot_init
which
Find out where a program is located in the file system
 
which git
man [application]
Read the manual for the specified application
 
man ls
gpg --gen-key
Create a GPG key
 
gpg --gen-key
Source
gpg --send-keys --keyserver keyserver.ubuntu.com [Key ID]
Send a key to Ubuntu's key server, which other key servers then synchronize with
 
gpg --send-keys --keyserver keyserver.ubuntu.com 43CDE61D
Source
echo $0
Displays what type of shell is running
 
echo $0
Source
lesspipe [deb file]
List contents of Debian deb package file
 
lesspipe hello.deb
Source
gpg --output [doc] --decrypt [doc.gpg]
Decrypt document
 
gpg --output mail --decrypt mail.gpg
Source
rngd -f -r /dev/urandom
Generate random bytes. Can be used for key generation.
 
rngd -f -r /dev/urandom
Source
grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/* | grep [ppa name]
Check if PPA is already installed
 
grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/* | grep fogger
Source
sudo rsync --dry-run --exclude-from=[exclude file] -av -e ssh [source dir] [uname]@[domain]:[dest dir]
Synchronize files from local directory to remote directory on remote server via SSH
--dry-run Don't actually do anything (for testing), -e enable SSH, --exclude-from File containing exclusions, --progress show progress
 
sudo rsync -av --delete --dry-run [source dir] [dest dir] 2>&1 | tee [logfile.txt]
Backup directory contents using rsync
-a archive (include permissions, owner, group, etc), -v verbose, --dry-run testing (don't actually do anything), tee - copy console output to file as well
 
su root
Launch a root shell
 
su root
lsb_release
Print distribution specific information (lsb = Linux Standard Base)
-c displays codename of distro, -s short output, -u show ubuntu codename
lsb_release -u -c -s
free
Show memory usage information
-h show output to the shortest three digit unit
free -h
Source
update-grub
Update grub configuration file
 
sudo update-grub
Source
crontab
Schedule tasks to run automatically
-e Edit -l List
sudo crontab -e
Source

Hardware

CommandDescriptionOptionsExampleSource
inxi -Fxz
Hardware and system details
-F Full output, -n Network, -z Hide personal info
inxi -Fxz
lspci
List PCI devices
-nn Show PCI vendor and device codes as both numbers and names, -k Show kernel drivers handling each device and also kernel modules capable of handling it
lspci -nnk
Source
lsusb
List USB buses and the devices connected to them
 
lsusb
Source
lsblk
List drive partitions and their mount points
 
lsblk
Source
xinput
Get keyboard and mouse (input devices) details
 
xinput
Source
ubuntu-drivers devices
List available graphics drivers
 
ubuntu-drivers devices
Source
alsamixer
Sound and audio troubleshooting
 
alsamixer
Source
sudo dd if=/dev/urandom of=/dev/sdX bs=1M && watch -n[sec] kill -USR1 `pidof dd`
Securely erase hard drive and view progress. Note, those are backticks around the pidof dd command.
 
sudo dd if=/dev/zero of=/dev/sdb bs=1M && watch -n10 kill -USR1 `pidof dd`
sudo fsck.ext4 -p -f -C0 [partition]
Check for errors in a file system of an unmounted partition
-C0 show progress bar, -f force check even if dirty bit not set, -p automatically repair file system, -c scan for bad blocks
sudo fsck.ext4 -f -c -C0 /dev/sdc1
Source
sudo rmmod [module name]
Dynamically remove a module from the kernel
 
sudo rmmod iwlmvm
sudo modprobe [module name]
Add and remove modules from the kernel
-r Remove module
sudo modprobe iwlmvm

Linux Mint

CommandDescriptionOptionsExampleSource
mintinstall
Launch Software Manager from command line
 
mintinstall
Source
Ctl + Alt + [Fkey]
Access and cycle through TTY lines and get back to GUI.
 
Ctrl + alt + F1-F6 Ctrl + alt + F8 (for GUI)
Ctrl + Alt + Esc
Restart Cinnamon desktop
 
 
Source

Networking

CommandDescriptionOptionsExampleSource
rfkill
Block or unblock RF devices
list - list all rfkill capable devices
rfkill list
Source
iw [WIFI adatper] get power_save
Get power save mode of wireless adapter
 
iw wlan0 get power_save
Source
sudo iw [WIFI adapter] set power_save off
Disable power save mode on wireless adapter
 
sudo iw wlan0 set power_save off
Source
sudo ifconfig [adapter] [ip address] sudo ifconfig [adapter] del [ip address]
Set static IP address Remove static IP address
 
sudo ifconfig eth0 192.168.1.100 sudo ifconfig eth0 del 192.168.1.100
sudo iwlist [adapter] s
List wireless networks
 
sudo iwlist wlan0 s
sudo ufw status
Get status of Uncomplicated Firewall
 
sudo ufw status
sudo ufw delete [rule]
Delete existing firewall rule
 
sudo ufw delete allow ssh
nm-tool
Display network adapter information
 
nm-tool
nm-tool | grep DNS
Get machine's DNS servers
 
nm-tool | grep DNS
Source
dig @[dns server] [domain]
DNS lookups
 
dig @8.8.8.8 stackoverflow.com
Source

Processes

CommandDescriptionOptionsExampleSource
ps
List running processes
 -A show all processes
ps aux
pkill -f [string]
Kill all processes that contain the word [string]
-f full command line is used (The pattern is normally only matched against the process name)
pkill -f firefox
Source
top
Check process prioritiy under “PR” column
 
top
pstree
Show process tree
 
pstree
./program_name; echo $?
Get return value of program after it executes
 
pkexec synaptic; echo $?
Source

User Management

CommandDescriptionOptionsExampleSource
sudo adduser [username] [groupname]
Add user to group
 
sudo adduser brennan vboxusers
sudo userdel [username] && sudo rm -r /home/[username]
Delete user and their home directory
 
sudo userdel mrgrinch && sudo rm -r /home/mrgrinch
less /etc/passwd | grep [uname]
Get details about a specific user
 
less /etc/passwd | grep santa
Source
usermod -s /sbin/nologin myuser
Disable shell (login access) for a specific user
 
usermod -s /sbin/nologin santa
Source