You are on page 1of 2

Linux Command Line Cheat Sheet

by Dave Child (DaveChild) via cheatography.com/1/cs/49/

Bash Commands Bash Variables (cont) Command Lists

uname -a Show system and export NAME=value Set $NAME to value cmd1 ; cmd2
kernel $PATH Executable search Run cmd1 then cmd2
head -n1 /etc/issue Show distri​bution path
cmd1 && cmd2
mount Show mounted filesy​‐ $HOME Home directory
Run cmd2 if cmd1 is successful
stems $SHELL Current shell
cmd1 || cmd2
date Show system date
Run cmd2 if cmd1 is not successful
uptime Show uptime IO Redire​ction
cmd &
whoami Show your username cmd < file
Run cmd in a subshell
man command Show manual for Input of cmd from file
command cmd1 <(cmd2)
Directory Operations
Output of cmd2 as file input to cmd1
Bash Shortcuts pwd Show current directory
cmd > file
CTRL-c Stop current command mkdir dir Make directory dir
Standard output (stdout) of cmd to file
CTRL-z Sleep program cd dir Change directory to dir
cmd > /dev/null
CTRL-a Go to start of line cd .. Go up a directory
Discard stdout of cmd
CTRL-e Go to end of line ls List files
cmd >> file
CTRL-u Cut from start of line
Append stdout to file ls Options
CTRL-k Cut to end of line
cmd 2> file -a Show all (including hidden)
CTRL-r Search history
Error output (stderr) of cmd to file -R Recursive list
!! Repeat last command
-r Reverse order
!abc Run last command starting with cmd 1>&2
abc -t Sort by last modified
stdout to same place as stderr
!abc:p Print last command starting -S Sort by file size
cmd 2>&1
with abc -l Long listing format
stderr to same place as stdout
!$ Last argument of previous -1 One file per line
cmd &> file
command -m Comma-​sep​arated output
Every output of cmd to file
ALT-. Last argument of previous -Q Quoted output
command cmd refers to a command.
!* All arguments of previous Search Files
command Pipes
grep pattern files Search for pattern
^abc^123 Run previous command, cmd1 | cmd2 in files
replacing abc with 123 stdout of cmd1 to cmd2 grep -i Case insens​itive
cmd1 |& cmd2 search
Bash Variables
stderr of cmd1 to cmd2 grep -r Recursive search
env Show enviro​nment
grep -v Inverted search
variables
grep -o Show matched
echo $NAME Output value of $NAME
part of file only
variable
find /dir/ -name name* Find files starting
with name in dir

By Dave Child (DaveChild) Published 28th October, 2011. Sponsored by Readable.com


cheatography.com/davechild/ Last updated 29th February, 2020. Measure your website readability!
aloneonahill.com Page 1 of 2. https://readable.com
Linux Command Line Cheat Sheet
by Dave Child (DaveChild) via cheatography.com/1/cs/49/

Search Files (cont) Process Management Screen Shortcuts (cont)

find /dir/ -user name Find files owned by ps Show snapshot of processes screen -list
name in dir top Show real time processes Show your current screen sessions.
find /dir/ -mmin num Find files modifed kill pid Kill process with id pid CTRL-A
less than num
pkill name Kill process with name name Activate commands for screen.
minutes ago in dir
killall name Kill all processes with names CTRL-A c
whereis command Find binary / source /
beginning name
manual for command Create a new instance of terminal.

locate file Find file (quick Nano Shortcuts CTRL-A n


search of system Go to the next instance of terminal.
Files
index)
Ctrl-R Read file CTRL-A p

File Operations Ctrl-O Save file Go to the previous instance of terminal.

touch file1 Ctrl-X Close file CTRL-A "

Create file1 Cut and Paste Show current instances of terminals.

cat file1 file2 ALT-A Start marking text CTRL-A A

Concat​enate files and output CTRL-K Cut marked text or line Rename the current instance.
CTRL-U Paste text More screen info at:
less file1
Navigate File http:/​/ww​w.g​nu.o​rg​/so​ftw​are​/sc​reen/
View and paginate file1
ALT-/ End of file
file file1
File Permis​sions
CTRL-A Beginning of line
Get type of file1
chmod 775 file
CTRL-E End of line
cp file1 file2
Change mode of file to 775
CTRL-C Show line number
Copy file1 to file2
CTRL-_ Go to line number chmod -R 600 folder
mv file1 file2
Search File Recurs​ively chmod folder to 600
Move file1 to file2
CTRL-W Find chown user:group file
rm file1
ALT-W Find next Change file owner to user and group to
Delete file1 group
CTRL-\ Search and replace
head file1
More nano info at:
File Permission Numbers
Show first 10 lines of file1 http:/​/ww​w.n​ano​-ed​ito​r.o​rg/​doc​s.php
First digit is owner permis​sion, second is
tail file1
Screen Shortcuts group and third is everyone.
Show last 10 lines of file1
Calculate permission digits by adding
screen
tail -F file1
numbers below.
Start a screen session.
Output last lines of file1 as it changes
4 read (r)
screen -r
2 write (w)
Watch a Command Resume a screen session.
1 execute (x)
watch -n 5 'ntpq -p'
Issue the 'ntpq -p' command every 5
seconds and display output

By Dave Child (DaveChild) Published 28th October, 2011. Sponsored by Readable.com


cheatography.com/davechild/ Last updated 29th February, 2020. Measure your website readability!
aloneonahill.com Page 2 of 2. https://readable.com

You might also like