You are on page 1of 2

Linux Command Line Cheat Sheet

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

Bash Commands Directory Operations Nano Shortcuts

uname -a Show system and kernel pwd Show current directory Files

head -n1 /etc/issue Show distribution mkdir dir Make directory dir Ctrl-R Read file

mount Show mounted filesystems cd dir Change directory to dir Ctrl-O Save file

date Show system date cd .. Go up a directory Ctrl-X Close file

uptime Show uptime ls List files Cut and Paste

whoami Show your username ALT-A Start marking text


ls Options
man command Show manual for command CTRL-K Cut marked text or line
-a Show all (including hidden) CTRL-U Paste text
Bash Shortcuts -R Recursive list Navigate File
CTRL-c Stop current command -r Reverse order ALT-/ End of file
CTRL-z Sleep program -t Sort by last modified CTRL-A Beginning of line
CTRL-a Go to start of line -S Sort by file size CTRL-E End of line
CTRL-e Go to end of line -l Long listing format CTRL-C Show line number
CTRL-u Cut from start of line -1 One file per line CTRL-_ Go to line number
CTRL-k Cut to end of line -m Comma-separated output Search File
CTRL-r Search history -Q Quoted output CTRL-W Find
!! Repeat last command ALT-W Find next
Search Files
!abc Run last command starting with abc CTRL-\ Search and replace
!abc:p Print last command starting with abc grep pattern Search for pattern in files
More nano info at:
files
!$ Last argument of previous command http://www.nano-editor.org/docs.php
grep -i Case insensitive search
ALT-. Last argument of previous command
grep -r Recursive search Screen Shortcuts
!* All arguments of previous command
grep -v Inverted search
^abc^ Run previous command, replacing abc screen
123 with 123 grep -o Show matched part of file only Start a screen session.

find /dir/ -name Find files starting with name in dir screen -r
Bash Variables name* Resume a screen session.

find /dir/ -user Find files owned by name in dir screen -list
env Show environment variables
name Show your current screen sessions.
echo $NAME Output value of $NAME
find /dir/ -mmin Find files modifed less than num CTRL-A
variable
num minutes ago in dir Activate commands for screen.
export NAME =v Set $NAME to value
whereis Find binary / source / manual for CTRL-A c
alue
command command Create a new instance of terminal.
$PATH Executable search path
locate file Find file (quick search of system CTRL-A n
$HOME Home directory
index) Go to the next instance of terminal.
$SHELL Current shell
CTRL-A p
File Operations Go to the previous instance of terminal.
IO Redirection
touch file1 CTRL-A "
cmd < file Create file1 Show current instances of terminals.
Input of cmd from file
cat file1 file2 CTRL-A A
cmd1 <(cmd2 ) Concatenate files and output Rename the current instance.
Output of cmd2 as file input to cmd1
less file1 More screen info at:
cmd > file View and paginate file1 http://www.gnu.org/software/screen/
Standard output (stdout) of cmd to file
file file1
cmd > /dev/null Get type of file1 File Permissions
Discard stdout of cmd
cp file1 file2 chmod 775 file
cmd >> file Copy file1 to file2 Change mode of file to 775
Append stdout to file
mv file1 file2 chmod -R 600 folder
cmd 2> file Move file1 to file2 Recursively chmod folder to 600
Error output (stderr) of cmd to file
rm file1 chown user :g roup file
cmd 1>&2 Delete file1 Change file owner to user and group to group
stdout to same place as stderr
head file1
cmd 2>&1 Show first 10 lines of file1 File Permission Numbers
stderr to same place as stdout
tail file1
The first digit is the owner permission, the second the
cmd &> file Show last 10 lines of file1
group and the third for everyone.
Every output of cmd to file
Every output of cmd to file
tail -f file1 Calculate each of the three permission digits by
cmd refers to a command. Output last lines of file1 as it changes adding the numeric values of the permissions below.

4 read (r)
Pipes Process Management
2 write (w)
cmd1 | cmd2 ps Show snapshot of processes
1 execute (x)
stdout of cmd1 to cmd2 top Show real time processes
cmd1 |& cmd2 kill pid Kill process with id pid
stderr of cmd1 to cmd2
pkill Kill process with name name
name
Command Lists
killall Kill all processes with names beginning
cmd1 ; cmd2 name name
Run cmd1 then cmd2

cmd1 && cmd2


Run cmd2 if cmd1 is successful

cmd1 || cmd2
Run cmd2 if cmd1 is not successful

cmd &
Run cmd in a subshell

Cheatographer Cheat Sheet Sponsor

Dave Child (DaveChild) This cheat sheet was published on 28th October, 2011 FeedbackFair, increase your conversion rate today!
cheatography.com/davechild/ and was last updated on 1st February, 2012. Try it free!
www.addedbytes.com http://www.FeedbackFair.com

You might also like