Linux Commands Cheat Sheet - Merged

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Linux Command Cheat Sheet Share This Cheat Sheet

Basic commands File management File Utilities Memory & Processes


| Pipe (redirect) output find search for a file tr -d translate or delete character free -m display free and used system
memory
sudo [command] run < command> in superuser ls -a -C -h list content of directory uniq -c -u report or omit repeated lines
mode killall stop all process by name
rm -r -f remove files and directory split -l split file into pieces
nohup [command] run < command> immune to sensors CPU temperature
hangup signal locate -i find file, using updatedb(8) wc -w print newline, word, and byte
database counts for each file top display current processes, real
man [command] display help pages of time monitoring
< command> cp -a -R -i copy files or directory head -n output the first part of files
kill -1 -9 send signal to process
[command] & run < command> and send task du -s disk usage cut -s remove section from file
to background service manage or run sysV init script
file -b -i identify the file type diff -q file compare, line by line [start|stop|restart]
>> [fileA] append to fileA, preserving
existing contents mv -f -i move files or directory join -i join lines of two files on a ps aux display current processes,
common field snapshot
> [fileA] output to fileA, overwriting grep, egrep, fgrep -i -v print lines matching pattern
contents more, less view file content, one page at a dmesg -k display system messages
time
echo -n display a line of text
sort -n sort lines in text file
xargs build command line from File compression
previous output comm -3 compare two sorted files, line Disk Utilities
tar xvfz create or extract .tar or .tgz by line
1>2& Redirect stdout to stderr files df -h, -i File system usage
cat -s concatenate files to the
fg %N go to task N gzip, gunzip, zcat create, extract or view .gz files standard output
mkfs -t -V create file system
jobs list task uuencode, uudecode create or extract .Z files tail -f output last part of the file
resize2fs update a filesystem, after
lvextend*
ctrl-z suspend current task zip, unzip -v create or extract .ZIP files
fsck -A -N file system check & repair
rpm create or extract .rpm files
Scripting pvcreate create physical volume
bzip2, bunzip2 create or extract .bz2 files
File permission awk, gawk pattern scanning mount -a -t mount a filesystem
rar create or extract .rar files
chmod -c -R chmod file read, write and tsh tiny shell fdisk -l edit disk partition
executable permission
"" anything within double quotes lvcreate create a logical volume
is unchanged except \ and $
touch -a -t modify (or create) file timestamp File Editor umount -f -v umount a filesystem
chown -c -R change file ownership '' anything within single quote is
ex basic editor unchanged
chgrp -c -R change file group permission
vi visual editor python "object-oriented programming
touch -a -t modify (or create) file language" Misc Commands
timestamp nano pico clone
bash GNU bourne-again SHell
view view file only pwd -P print current working directory
ksh korn shell
emacs extensible, customizable editor bc high precision calculator
php general-purpose scripting
Network sublime yet another text editor language expr evaluate expression

netstat -r -v print network information, sed stream editor csh, tcsh C shell cal print calender
routing and connections
pico simple editor perl Practical Extraction and Report export assign or remove environment
telnet user interface to the TELNET Language variable
protocol
source [file] load any functions file into the ` [command] backquote, execute command
tcpdump dump network traffic Directory Utilities current shell, requires the file
to be executable date -d print formatted date
ssh -i openSSH client
mkdir create a directory $[variable] if set, access the variable
ping -c print routing packet trace to
host network rmdir remove a directory

Read the Blog Post »


Compiled by Alvin Khoo bit.ly/Linux-Commands
Linux Commands Cheat Sheet
Hardware Information Searching File Commands Directory Navigation

dmesg show bootup messages grep [pattern] search for a specific pattern in a ls list files in directory cd .. move up one level in the directory
[file_name] file tree structure
cat /proc/cpuinfo show CPU information ls -a list all files, including hidden
grep -r [pattern] search recursively for a specific cd change directory to $HOME
free -h show free and used memory (-m flag [directory_name] pattern in a directory pwd show the directory currently
indicates memory in MB) working in cd /chosen/directory change to specified directory
locate [name] find all files and directories by a
lshw list information about hardware specific name mkdir [directory] create a new directory
configuration
find [/folder/location] list names that begin with [a] in rm [file_name] remove a file
lsblk list information about block devices -name [a] [/folder/location]
rm -r [directory_name] remove a directory recursively
lspci -tv show PCI devices in a tree-like diagram find [/folder/location] list files larger than 100M in a
-size [+100M] particular folder rm -rf [directory_name] remove a directory recursively Users
lsusb -tv show USB devices in a tree-like without requiring confirmation
diagram
id show details of the active user
cp [file_name1] [file_name2] copy the contents of the first file to
dmidecode show hardware information from the the second file
last show the last logins onto the
BIOS
system
cp -r [directory_name1] recursively copy the contents of the
hdparm -i /dev/[disk] show information about disk data [directory_name2] first directory into the second
who show who is logged into the system
File Transfer directory
hdparm -tT /dev/[disk] conduct a read speed test on disk
w show who is logged in and their
mv [file_name1] rename file_name1 to file_name2
activity
badblocks -s /dev/[disk] test for unreadable blocks on disk scp [file_name.txt] securely copy a specific file to a [file_name2]
[server/tmp] server directory
groupadd add a new group
ln -s /path/to/[file_name] create a symbolic link to a file
[group_name]
rsync -a synchronize the contents of a [link_name]
[/your/directory] specific directory with a backup
adduser [user_name] add new user
[/backup/] directory touch [file_name] create a new file

usermod -aG add a user to a group


File Compression more [file_name] show the contents of a file
[group_name]
[user_name]
head [file_name] show the first 10 lines of a file
tar cf [compressed_file. create an archived file from a file userdel [user_name] delete a user
tar] [file_name] tail [file_name] show the last 10 lines of a file
Process Related usermod use for changing / modifying user
tar xf [compressed_file. extract archived file gpg -c [file_name] encrypt a file
information
tar]
ps show a snapshot of active gpg [file_name.gpg] decrypt a file
tar czf create a gzip compressed tar file processes
[compressed_file.tar.gz] wc print the number of words, lines,
pstree show processes as a tree and bytes in a file
gzip [file_name] compress a file with the .gz
extension pmap shows a memory usage map of
processes Disk Usage
top show all running processes

kill [process_id] kill a process under a given ID System Information df -h show free and used space on
mounted systems

Package Installation pkill [proc_name] kill a process under the specified df -i show free inodes on mounted
uname -r show system information
name filesystems
yum search find a package by a related uname -a show kernel release information
killall [proc_name] kill all processes labelled proc fdisk -l show disk partitions, sizes, and
[keyword] keyword
uptime show how long the system has been types
bg list and resume stopped jobs in
yum info show package information and running, including load average
the background du -ah show disk usage for all files and
[package_name] summary
hostname show system hostname directory
fg bring the most recent suspended
yum install install a package using the YUM job to the foreground
hostname -i show the IP address of the system du -sh show disk usage of current
[package_name. package manager
directory
rpm] fg [job] bring a particular job to the
last reboot show system reboot history
foreground findmnt show target mount point for all
dnf install install a package using the DNF
date show current time and date filesystems
[package_name. package manager lsof list files opened by processes
rpm]
timedatectl query and change the system clock mount [device_path] mount a device
[mount_point]
rpm -i install an rpm package from a local
[package_name. file cal show current calender month and
rpm] day

rpm -e w show logged in users in the system


[package_name. remove an rpm package File Permission whoami show user you are using
rpm]

finger show information about a user


Keyboard Shortcuts
tar zxvf chmod 777 [file_name] give read, write, and execute
[source_code.tar.gz] install software from source code [username]
permission to everyone
cd [source_code] Ctrl + C kill current process running in the
./configure chmod 755 [file_name] give full permission to owner, and terminal
make read and execute permission to
make install group and others Ctrl + Z stop current process (can be
resumed in the foreground with fg
chmod 766 [file_name] give full permission to owner, and or in the background with bg)
read and write permission to
group and others
Network
Ctrl + W cut one word before the cursor and
add it to clipboard
chown [user] change the file ownership ip addr show show IP addresses and network
SSH Login [file_name] interfaces Ctrl + U cut part of the line before the
cursor and add it to clipboard
chown [user]: [group] change the owner and group ip address add assign an IP address to interface
ssh user@host connect to host as user [file_name] ownership of a file [IP_address] eth0 Ctrl + K cut part of the line after the cursor
and add it to clipboard
ssh host securely connect to host via SSH ifconfig show IP addresses of all network
default port 22 interfaces Ctrl + Y paste from clipboard

ssh -p [port] user@host connect to host using a particular netstat -pnltu show active (listening) ports Ctrl + R recall last command that matches
port the provided characters
netstat -nutlp show tcp and udp ports and their
telnet host connect to host via telnet default programs Ctrl + O run the previously recalled
port 23 command
whois [domain] show more information about a
domain Ctrl + G exit command history without
running a command
dig [domain] show DNS information about a
domain !! repeat the last command

dig -x host reverse lookup on domain exit log out of current session

dig -x reverse lookup of an IP address


[ip_address]

host [domain] do an IP lookup for a domain

hostname -I show the local IP address

wget [file_name] download a file from a domain

You might also like