0% found this document useful (0 votes)
3 views

Linux commands cheat sheet

This document is a comprehensive cheat sheet for Linux commands, covering basic commands, file permissions, text editors, networking commands, and system management. It includes examples and explanations for commands like 'cd', 'ls', 'chmod', 'vi', and 'dd', among others. The cheat sheet is designed to be a quick reference for users to efficiently navigate and utilize Linux systems.

Uploaded by

krishna raut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Linux commands cheat sheet

This document is a comprehensive cheat sheet for Linux commands, covering basic commands, file permissions, text editors, networking commands, and system management. It includes examples and explanations for commands like 'cd', 'ls', 'chmod', 'vi', and 'dd', among others. The cheat sheet is designed to be a quick reference for users to efficiently navigate and utilize Linux systems.

Uploaded by

krishna raut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Linux Commands Cheat Sheet

by ralema56 via cheatography.com/78049/cs/19072/

Quick basic commands Quick basic commands (cont) iptables (firewall)

cd change directory, case &> will include output and errors iptables -h list commands
(Example: sensitive --list list the rule in a chain or all
cd apt chains
Desktop)
apt list | grep Type a word to highlight --verbose details
cd home directory in red or -v
. this directory apt | grep searchword --line​-nu​‐ print line numbers when
cd .. go up one directory search mbers listing
cd - change dir to previous apt install app name --version or version number
working dir apt app name -V
pwd print working directory remove --list​-rules list rules
ls list contents, -a all, -h human apt update or -S
readable apt upgrade --numeric numeric output of addresses

ll LL list direct​ories with RW or -n and ports


permis​sions Permis​sions
Permission Attribute Examples
la LA list all including hidden id Display user idenity
-rwx------ read, write, execute by file's
sudo super user privileges chmod Change a files mode
owner only
mkdir <di​‐ create direct​ories umask Set the default file permis​sions
-rw------- read and write by owner only
rna​me> su Run a shell as another user
<di​rna​‐ -rw-r--r-- read and write owner, read
sudo Execute a command as another
me2> group, read world
user
cp <path copy contents to current -rwxr-xr-x read, write, execute owner.
chown Change a file's owner
and locati​‐ directory, cp by itself will read and execute everyone
chgrp Change a file's group ownership else.
ons> . overwrite files silently
passwd Change a user's password lrwxrwxrwx A symbolic link with dummy
mv <it​‐ move file(s) to location
em1> <it​‐ permis​sions
Reading, Writing, Executing -rw-r--r--
em2> drwxr-x--- Directory. read, write, execute
directory Example -rw-r--r-- owner. Read and execute
rm -i <it​‐ delete file, -i intera​ctive - col1. Regular file group.
em> confir​mation d col1. Directory
Changing passwords
alias lists alias commands l col1. A symbolic link. Dummy
alert <"me​‐ sends a message to notifi​‐ values. passwd with sudo you can change a
ssa​ge"> cations [user] user password
c col1. A charcater special file.
> emptyD​‐ make an empty text file Modem passwd change your password
OC.txt b col1. A block special file. Ex.
chown
> standard out to .txt (will CD, HDD.
overwrite) chown syntax use
r Read only
[owner​][:​[gr​‐
>> append standard out .txt will w Write
oup]] file..
(not overwrite)
x Executable
bob change ownership from
ls -la will print the directory
current to bob
/usr/bin > contents to a text file
ls-out​‐ bob:users change file ownership to
put.txt bob and group to users

By ralema56 Not published yet. Sponsored by Readable.com


cheatography.com/ralema56/ Last updated 15th March, 2019. Measure your website readability!
Page 1 of 8. https://readable.com
Linux Commands Cheat Sheet
by ralema56 via cheatography.com/78049/cs/19072/

chown (cont) vi or vim text editor (cont) vi or vim text editor (cont)

:admins change group owner to admins, double tap ESC if you don't know where x delete the current character
the owner is unchanged you are in vi 3x delete the current character and the
bob: change the current owner to bob Navi​gating Command Mode 2 after it
and change the group to the login H or left left one character dd delete the current line
group for bob arrow 5dd delete the current line and the next
J or down one line 4 lines
text editors
down dW delete from the current cursor
gedit GUI (installed in Ubuntu) arrow position to the beginning of the next
kedit KDE default K or up up one line word
kate sudo apt install kate arrow d$ delete from the current cursor
nano command line based (installed in L or right right one character position to the end of the line
Ubuntu) arrow d0 delete from the current cursor
vi or vi IMproved (installed in Ubuntu) 0 (zero) go to the beginning of the position to the beginning of the line
vim current line d^ delete from the current cursor
emacs sudo apt install emacs-gtk SHIFT-6 to the first non whitespace location to the first non whitespace
(^) character on the current line character line
text editing basics SHIFT-4 to the end on the current line dG from the current line to the end of
make a backup cp <fi​len​ame> <fi​‐ ($) the file
before editing len​ame.ba​k> W to the beginning of the next d20g from the current line to the 20th line
nano <fi​len​ame> load a text in nano word, or punctu​ation characters of the file
SHIFT- to the beginning of the next COPY​ING
nano text editor W (W) word, ignore punctu​ation yy y stands for yank which is copy, yy
characters copies the current line
^X to quit nano, ^ mean CTRL
B to the beginning of the previous
^O CTRL-O save the file
word or character

vi or vim text editor SHIFT B to the beginning of the previous


(B) word or character, ignoring
vi start vim
punctu​ation
vi newdoc.txt create a blank text doc in
CTRL-F down on page
vi from command line
or page
:q quit
down
:q! quit without saving
CTRL-B up one page
vi starts in press i to go to insert text or page
command mode up
mode
number​- to the line number, example 1G
press ESC to exit insert mode with SH​IFT- moves to the first line of the file
exit insert ESC G
mode
SHIFT- to the last line of the file
:w save the file, or write to G
file
Cutting, Copying, Pasting Text
DELETE TEXT aka CUT TEXT

By ralema56 Not published yet. Sponsored by Readable.com


cheatography.com/ralema56/ Last updated 15th March, 2019. Measure your website readability!
Page 2 of 8. https://readable.com
Linux Commands Cheat Sheet
by ralema56 via cheatography.com/78049/cs/19072/

vi or vim text editor (cont) vi or vim text editor (cont) Technical commands (cont)

5yy copies the current line and vi file1 file2 file3 cat somete​‐ to read the file with cat
the next 4 lines :n switch to the next file xt.txt
yW from the cursor location to :N switch to the previous file | pipe connects input to
the beginning of the next output
:buffers lists open files
word ls /bin example sort 2 dirs binaries
:buffers switch to buffer file 2
y$ from the cursor location to /usr/bin |sort
2
the end of the current line | less
:e open another file from vi.
y0 from the current cursor sort alphab​etize a list
example :e filena​me.txt
location to the beginning of uniq used with sort, removes
:r copy an entire file to the vi
the line duplicates
session. example :r myfile.txt
y^ from the current cursor grep pattern finding
location to the first non
Networking commands head checks the first 10 lines of a
whitespace character in
file. -n # (to adjust #)
line ping send en ICMP echo request to
network hosts tail checks the last 10 lines of a
yG from the current line to the
file. -n#
end of the file traceroute print the route packets trace to
a network host tail -f /var/l​‐ -f is a real time log file
y20G from the current line to the
og/​mes​‐ viewer switch​(CTRL-C to
20th line of the file netstat print the network connec​tions,
sages quit)
routing tables, interface stats,
PAST​ING
masquerade connec​tions, and tee for use with pipe
p pastes the current copied
multi cast member​ships echo *D display everything with a
text below the current line
ftp file transfer program capital D
P pastes the copied text
lftp an improved ftp echo command line calculator
above the current line
$((2+2))
wget non intera​ctive network
Join lines J
downloader echo "​$(c​‐ calendar
vi has the maybe I will add a cheat al)​"
ssh openSSH SSH client (remote
ability to do sheet for this later
login) history a list of all commands used
search and
scp secure copy (remote copy history: !88 !88 will use number 88 in
replace
program) history
/searc​htext searches vi
sftp secure ftp
:%s/Li​ne/​‐ will search and replace USB checking
line/g Line with line globally
Technical commands lsusb list connected USB devices
EDIT MULTIPLE FILES
cat (brings files CTRL-D to quit,
dpkg
together, uses input) tell cat EOF
cat > somete​xt.txt; this a simple way to dpkg --list list all installed
is some text to be add text to a text packages
saved file -r or --remove remove a package
-P or --purge
--log=​<fi​len​ame> log changes made
-i or --install <.deb file install a deb file
name>

By ralema56 Not published yet. Sponsored by Readable.com


cheatography.com/ralema56/ Last updated 15th March, 2019. Measure your website readability!
Page 3 of 8. https://readable.com
Linux Commands Cheat Sheet
by ralema56 via cheatography.com/78049/cs/19072/

chmod octal chart umask new file default permis​sions system stuff (cont)
(cont)
octal binary - filemode PATH a colon separated list of direct​ories
0 000 --- 1000 set to a directory prevents files from that are searched when you enter
being deleted in shared directory the name of an executable
1 001 --x
the last three are octal permis​sions program
2 010 -w-
PS1 prompt string 1, defines the
3 011 -wx
system stuff contents of shell prompt
4 100 r--
printenv | system inform​ation PWD current working directory
5 101 r-x less TERM the name of your terminal type
6 110 rw- printenv views the contents of a TZ time zone
7 111 rwx USER variable, example USER
USER your username
example owner, group, world contains your user name
setting set | less display shell and enviro​‐ Storage Media command overview
octal 600 nment variables
mount mount a file system
binary seems somewhat echo echo can be used to view
umount un-mount a file system (pay
irrelevant $HOME single variables
attention to the spelling of the
chmod symbolic notation alias lists all alias commands command Umount)
u user [command]; to get a notifi​cation when a fdisk partition table manipu​lator
g group alert command is done(an alias
fsck check and repair a filesystem
[message] in ubuntu)
o others, world fdformat format a floppy disk
below are **
a all mkfs make a filesystem
some
example notation dd write block-​ori​ented data
variables of
u+x add execute permission for the interest directly to a device
owner geniso​‐ create an ISO 9660 image file
DISPLAY the name of your display
u-x remove execute permission enviroment image
from the owner (mkisos)
EDITOR the default text editor
+x add execute for everyone, wodim write data to an optical storage
SHELL name of the shell running
same as a+x (cdrecord)
HOME path to home directory
o-rw remove read and write for md5sum calculate MD5 checksum
LANG keyboard language
everyone but owner and group LISTING DEVICES AND FILESY​STEMS
OLD_PWD the previous working
u+x,go=rx add excute for owner, group /etc/fstab is a list of devices
directory
and world changed to read and
mount will view a list of mounted
execute PAGER the name of the program
filesy​stems
used for paging output.
Usually is app less ls /dev list devices
umask new file default permis​sions

umask 0022 ubuntu default


# 4000 sets program ownership to
position app
0---
2000 sets group ownership for
shared direct​ories

By ralema56 Not published yet. Sponsored by Readable.com


cheatography.com/ralema56/ Last updated 15th March, 2019. Measure your website readability!
Page 4 of 8. https://readable.com
Linux Commands Cheat Sheet
by ralema56 via cheatography.com/78049/cs/19072/

Storage Media command overview (cont) system startup stuff (cont) Moving data directly to and from devices
with dd (cont)
/dev/fd* floppy disks ~/.bashrc a users personal
/dev/hd* hard drives startup file dd if=/de​v/sdb copy 2 identical usb
files that start with a is -a option when of=/de​v/sdc drives that are the same
/dev/lp* printers
period are hidden searching with ls size
/dev/sd* SCSI disks
dd if=/de​v/sdb make a raw image of the
/dev/sr* Optical drives CD/DVD
fdisk commands of=fla​sh_​dri​‐ drive
readers and burners
ve.img
sudo umount unmount the partition
sudo tail -f to see real time device
/dev/sdb1
/var/l​og/​‐ changes in the system creating CD-ROM images
sudo fdisk mount the entire drive
syslog
/dev/sdb dd if=/de​‐ copy the contents of a cd to
MOVING DEV MOUNT LOCATI​ONS v/cdrom an image file
fdsik commands
sudo mkdir make a dir to mount flash of=ubu​‐
p print partition tables
/mnt/flash drive ntu.iso
l list known partition
sudo moves the location to the new cdrdao is used for audio cds
types
mount one (use the proper device creating an iso from a collection of files
/dev/sdb1 name before moving) t change a partitions
geniso​image if you had a directory called
/mnt/flash system id
-o cd- /cd-ro​m-f​iles, you could use
df display disk space df -h for w write partition changes
rom.iso -R - this command to make an
human readable q quit fdisk J ~/cd-r​om-​‐ image of the directory
files
system startup stuff creating a new filesystem with mkfs
the -R -J the allow the use of long
/etc/p​‐ a global config​uration script that sudo mkfs -t make an ext3 filesystem options filenames
rofile applies to all users ext3 on device sdb1 partition defined
~/.bas​‐ a users personal startup file. can /dev/sdb1 mounting an iso image directly
h_p​rofile override the global config script sudo mkfs -t make a fat32 silesystem using the -o loop with mount
~/.bas​‐ if ~/.bas​h_p​rofile is not found, vfat /dev/sdb1 on device sdb1
mkdir /mnt/i​‐ then the next line down
h_login bash attempts to read this one
so_​image
testing and repairing filesy​stems with
~/.profile if neither bash profile or login
mount -t mounts the iso as a virtual
fsck
are found this is run. this is the
iso9660 -o drive
default in Ubuntu sudo fsck checks the filesystem on
loop
/etc/b​‐ a global config script that applies /dev/sdb1 sdb1 partition
image.iso
ash​/bas to all users /mnt/i​so_​‐
hrc Moving data directly to and from devices
image
with dd
blanking a RW CD
dd raw copy tool (dd
wodim there are other types of
has 2 names, data
dev=/d​‐ blanking
definition and destroy
ev/cdrw
disk)
blank=fast
dd if=inp​ut_file syntax to dd raw
writing an image file
of=out​put​_file copy
wodim writes an image to cd
[bs=bl​ock​_size
dev=/d​‐
[count​=bl​ocks]]
ev/cdrw
image.iso

By ralema56 Not published yet. Sponsored by Readable.com


cheatography.com/ralema56/ Last updated 15th March, 2019. Measure your website readability!
Page 5 of 8. https://readable.com
Linux Commands Cheat Sheet
by ralema56 via cheatography.com/78049/cs/19072/

MD5 checksum ps (running processes) (cont) netstat

md5sum will give you the md5 top display tasks with the top netstat -tulpn
image.iso checksum value active ones -l (L) display listening sockets
md5sum a cd-r write in disc at once jobs list active jobs -n don't resolve names
/dev/cdrom can be checked like this bg place a job in the background -p display PID
fg place a job in the foreground -s an overview - statistics
lynis (audit​ing​,ha​rde​ning)
kill send a signal to a process via -g group member​ships
sudo apt install install it
PID
lynis -r router table
killall kill process by name
lynis audit perform local security -i interface table
shutdown shut down or reboot the system
system scan
xlogo creates a nonsense xlogo app Custom​izing the Prompt
lynis show version
for debuging and testing ps
version adjust how the prompt is displayed and
controls
operates
--verbose details
[CTRL-c] terminates programs started in
echo display the current prompt
--pentest non privileged scan
terminal
$PS1 setup
xlogo & & will make a program start in
systemctl (services) ps1_ol​‐ make a backup before making
the background
d="$​‐ changes called ps1_old. check
systemctl -all or - see all loaded
fg %1 will bring the program to the PS1​" with echo $ps1_old
a processes
foreground
PS1="$p​‐ restore the original
list-units list units currently in
[CTRL-z] stops or pauses a process s1_​old​"
memory
bg %1 put program in background PS1= clear all prompt data (no visible
list-s​ockets list sockets currently in
killall killall xlogo for example if prompt)
memory
[process multiples are running PROMPT ubuntu default value is: [\u@\h
list-u​nit​-files list installed unit files
name] VALUES \W]\$
poweroff turn the computer off
pstree outputs a process list in a tree PS1="\$ " a minimal prompt
reboot shutdown and restart pattern
\a ASCII bell. Makes the
is-sys​tem​-ru​nning checks to see if the vmstat system resource snapshot computer beep
system is running [vmstat5] for continuous feed
\d current date in day, month,
--type service -- searching for running xload GUI draws a graph, showing date format
state running services sys stats overtime
\h hostname of the local machine
tload a terminal version of xload minus the domain
ps (running processes)
tload a terminal version of xload \H full hostname
ps -e all running processes
\j number of jobs in the current
ps aux | search for telnet running
shell
grep telnet
\l name of the current terminal
ps #### # = number for PID to view
device
ps -aux custom running process
\n a newline character
search
\r a carriage return
ps --help list more commands
\s name of the shell program
all
\t current time in 24hour H:M:S
ps report a snapshot of the
current running processes \T current time in 12hour format

By ralema56 Not published yet. Sponsored by Readable.com


cheatography.com/ralema56/ Last updated 15th March, 2019. Measure your website readability!
Page 6 of 8. https://readable.com
Linux Commands Cheat Sheet
by ralema56 via cheatography.com/78049/cs/19072/

Custom​izing the Prompt (cont) Custom​izing the Prompt (cont) Searching for files commands (cont)

\@ current time in 12hour am/pm \033[1;37m white find ~ type f find files with the name .jpg
format BACK​GROUND COLOR -name "​*.J​‐ larger than 1 mb and count
\A current time in 24 hour H:M PG" -size them
\033[0;40m black
+1M | wc -l
\u username of the current user \033[0;41m red
find test
\v version number of the shell \033[0;42m green
-cmin n match files of dirs whose
\V version and release number \033[0;43m brown
content was modified
of the shell
\033[0;44m blue exactly n minutes ago
\w name of the current working
\033[0;45m purple -cnewer file match files or direct​ories
directory
\033[0;46m cyan whose content was last
\W last part of the working
modified more recently than
\033[0;47m light gray
directory
the file named
\! history number of the current
Searching for files commands -ctime match files or dirs that were
command
modified within the last
locate find files by name
\# number of commands entered 24hours
in shell find search for files in directory
-empty match empty files or dirs
hierarchy
\$ displays the $ character
-group match files or dirs belonging
unless you have root, in that xargs build and execute command
name to a group
case it displays # lines from standard input
-iname like name but case sensitive
\[ the start of a series of one or touch change file times
pattern
more non-pr​inting characters stat display file or filesystem status
-inum n match files with inode
\] the end of a non-pr​inting locate (find files the easy way)
number n
character sequence locate locate will search for any string
-mmin n match files of dir whose
COLOR TEXT bin/zip with bin and zip
contents were modified n
\033[0;30m black locate zip and fancier search mins ago
\033[0;31m red | grep bin
-mtime n match files or dirs whose
\033[0;32m green find (find files the hard way) contents where modified n
find ~ a list of direct​ories in our home 24 hours ago
\033[0;33m brown
dir -name match files with wildcard
\033[0;34m blue
find ~ | wc use word count to find how pattern pattern
\033[0;35m purple
-l many files -newer file match files or dirs whose
\033[0;36m cyan
find ~ - find how many direct​ories with content was modifies more
\033[0;37m light grey recently than specified file
type d | word count
\033[1;30m dark grey wc -l
\033[1;31m light red find ~ - find regular files with word
\033[1;32m light green type f | wc count
-l
\033[1;33m yellow
\033[1;34m light blue
\033[1;35m light purple
\033[1;36m light cyan

By ralema56 Not published yet. Sponsored by Readable.com


cheatography.com/ralema56/ Last updated 15th March, 2019. Measure your website readability!
Page 7 of 8. https://readable.com
Linux Commands Cheat Sheet
by ralema56 via cheatography.com/78049/cs/19072/

Searching for files commands (cont) Searching for files commands (cont)

-nouser match files or dirs that do find ~ (-type f -not - test for bad files
not belong to a user perms 0600) -or (- and direct​ories
-nogroup match files that do not type d -not -perms
belong to a group 0700)

-perm mode match files that have actions for find


permission set to a specific -delete delete the
mode currently matching
-samefile match files with the same file(see warning)
name inode number, similar to - -ls perform the
inum test equivalent of ls -
-size n match file of size n dils on the
matching file.
-type c match files of c type
-print output the full
-user name match files or dir belonging
pathname of the
to user name
file
find logical operat​ors
-print0 used to correctly
-and match if both sides are true,
print file names
also known as -a
with spaces
-or match is one side is true
-quit quit once a match
also known as -o
has been made
-not match if the following test is
warning for delete
false, also know as -!
always use -print as a substitute for -delete
() group tests together to form
to see what will be deleted
larger expres​sions
find ~ -type f -name -print the files to
exam​ples
'*.BAK' -print output before
-type f -and testing for bad permis​sions deleting
-not -perms by testing for good ones
find ~ -type f -name then proceed if
0600
'*.BAK' -delete you wish to delete
still

By ralema56 Not published yet. Sponsored by Readable.com


cheatography.com/ralema56/ Last updated 15th March, 2019. Measure your website readability!
Page 8 of 8. https://readable.com

You might also like