Vous êtes sur la page 1sur 2

Linux Command Line Cheat Sheet

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

Bash Commands Bash Variables Command Lists

uname -a Show system and kernel env Show enviro​nment cmd1 ; cmd2

head -n1 /etc/issue Show distri​bution variables Run cmd1 then cmd2

mount Show mounted echo $NAME Output value of $NAME cmd1 && cmd2

filesy​stems variable Run cmd2 if cmd1 is successful

date Show system date export NAME=value Set $NAME to value cmd1 || cmd2

$PATH Executable search path Run cmd2 if cmd1 is not successful


uptime Show uptime
$HOME Home directory cmd &
whoami Show your username
Run cmd in a subshell
man command Show manual for $SHELL Current shell

command Directory Operations


IO Redirection
pwd Show current directory
Bash Shortcuts cmd < file
Input of cmd from file mkdir dir Make directory dir
CTRL-c Stop current command
cmd1 <(cmd2) cd dir Change directory to dir
CTRL-z Sleep program
Output of cmd2 as file input to cmd1 cd .. Go up a directory
CTRL-a Go to start of line
cmd > file ls List files
CTRL-e Go to end of line
Standard output (stdout) of cmd to file
CTRL-u Cut from start of line
cmd > /dev/null ls Options
CTRL-k Cut to end of line Discard stdout of cmd
-a Show all (including hidden)
CTRL-r Search history cmd >> file
-R Recursive list
!! Repeat last command Append stdout to file
-r Reverse order
!abc Run last command starting with cmd 2> file
Error output (stderr) of cmd to file -t Sort by last modified
abc
cmd 1>&2 -S Sort by file size
!abc:p Print last command starting with
abc stdout to same place as stderr -l Long listing format

!$ Last argument of previous cmd 2>&1 -1 One file per line


command stderr to same place as stdout -m Comma-​sep​arated output
ALT-. Last argument of previous cmd &> file
-Q Quoted output
command Every output of cmd to file

!* All arguments of previous cmd refers to a command. Search Files


command
grep pattern files Search for pattern in
^abc^123 Run previous command, replacing Pipes
files
abc with 123
cmd1 | cmd2 grep -i Case insens​itive
stdout of cmd1 to cmd2 search
cmd1 |& cmd2 grep -r Recursive search
stderr of cmd1 to cmd2
grep -v Inverted search

grep -o Show matched part of


file only

find /dir/ -name name* Find files starting with


name in dir

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


cheatography.com/davechild/ Last updated 27th June, 2014. Measure your website readability!
www.addedbytes.com Page 1 of 2. https://readability-score.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 CTRL-A
name in dir top Show real time processes Activate commands for screen.

find /dir/ -mmin num Find files modifed less CTRL-A c


kill pid Kill process with id pid
than num minutes ago in Create a new instance of terminal.
pkill name Kill process with name name
dir
CTRL-A n
killall name Kill all processes with names
whereis command Find binary / source / Go to the next instance of terminal.
beginning name
manual for command
CTRL-A p
locate file Find file (quick search of Go to the previous instance of terminal.
Nano Shortcuts
system index) CTRL-A "
Files
Show current instances of terminals.
File Operations Ctrl-R Read file
CTRL-A A
touch file1 Ctrl-O Save file Rename the current instance.
Create file1 Ctrl-X Close file More screen info at:
cat file1 file2 Cut and Paste http:/​/ww​w.g​nu.o​rg​/so​ftw​are​/sc​reen/
Concat​enate files and output
ALT-A Start marking text
less file1 File Permissions
CTRL-K Cut marked text or line
View and paginate file1
chmod 775 file
CTRL-U Paste text
file file1 Change mode of file to 775
Get type of file1 Navigate File
chmod -R 600 folder
cp file1 file2 ALT-/ End of file
Recurs​ively chmod folder to 600
Copy file1 to file2 CTRL-A Beginning of line chown user:group file
mv file1 file2 CTRL-E End of line Change file owner to user and group to
Move file1 to file2 group
CTRL-C Show line number
rm file1
CTRL-_ Go to line number
Delete file1 File Permission Numbers
Search File
head file1 First digit is owner permis​sion, second is group
Show first 10 lines of file1 CTRL-W Find
and third is everyone.
tail file1 ALT-W Find next
Calculate permission digits by adding numbers
Show last 10 lines of file1 CTRL-\ Search and replace below.
tail -f file1 More nano info at: 4 read (r)
Output last lines of file1 as it changes http:/​/ww​w.n​ano​-ed​ito​r.o​rg/​doc​s.php 2 write (w)

1 execute (x)
Watch a Command Screen Shortcuts

watch -n 5 'ntpq -p' screen


Issue the 'ntpq -p' command every 5 Start a screen session.
seconds and display output
screen -r
Resume a screen session.

screen -list
Show your current screen sessions.

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


cheatography.com/davechild/ Last updated 27th June, 2014. Measure your website readability!
www.addedbytes.com Page 2 of 2. https://readability-score.com

Vous aimerez peut-être aussi