10/29/11

Linux Command Line Cheat Sheet by DaveChild

Source: http://www.cheatography.com/davechild/cheat-sheets/linux-command-line/

Bash Commands

uname -aShow system and kernel
head -n1 /etc/issueShow distribution
mountShow mounted filesystems
dateShow system date
uptimeShow uptime
whoamiShow your username
man commandShow manual forcommand

Bash Shortcuts

CTRL-cStop current command
CTRL-zSleep program
CTRL-aGo to start of line
CTRL-eGo to end of line
CTRL-uCut from start of line
CTRL-kCut to end of line
CTRL-rSearch history
!!Repeat last command
!abcRun last command starting with abc
!abc:pPrint last command starting with abc
!$Last argument of previous command
!*All arguments of previous command
^abc^123Run previous command, replacing abc with 123

Bash Variables

envShow environment variables
echo $NAMEOutput value of $NAMEvariable
exportNAME=valueSet $NAME to value
$PATHExecutable search path
$HOMEHome directory
$SHELLCurrent shell

IO Redirection

command <fileRead input of commandfrom file
command >fileWrite output of commandto file
command > /dev/nullDiscard output ofcommand
command >>fileAppend output to file
command1 |command2Pipe output of command1to command2

Directory Operations

pwdShow current directory
mkdir dirMake directory dir
cd dirChange directory to dir
cd ..Go up a directory
lsList files
 

ls Options

-aShow all (including hidden)
-RRecursive list
-rReverse order
-tSort by last modified
-SSort by file size
-lLong listing format
-1One file per line
-mComma-separated output
-QQuoted output

Search Files

grep patternfilesSearch for pattern in files
grep -iCase insensitive search
grep -rRecursive search
grep -vInverted search
find /dir/ -name name*Find files starting with namein dir
find /dir/ -user nameFind files owned by name indir
find /dir/ -mmin numFind files modifed less thannum minutes ago in dir
whereiscommandFind binary / source / manual for command
locate fileFind file (quick search of system index)

File Operations

touchfile1Create file1
cat file1file2Concatenate files and output
less file1View and paginate file1
file file1Get type of file1
cp file1file2Copy file1 to file2
mv file1file2Move file1 to file2
rm file1Delete file1
head file1Show first 10 lines of file1
tail file1Show last 10 lines of file1
tail -ffile1Output last lines of file1 as it changes

Process Management

psShow snapshot of processes
topShow real time processes
kill pidKill process with id pid
pkillnameKill process with name name
killallnameKill all processes with names beginning name
 

Nano Shortcuts

Files
Ctrl-RRead file
Ctrl-OSave file
Ctrl-XClose file
Cut and Paste
ALT-AStart marking text
CTRL-KCut marked text or line
CTRL-UPaste text
Navigate File
ALT-/End of file
CTRL-ABeginning of line
CTRL-EEnd of line
CTRL-CShow line number
CTRL-_Go to line number
Search File
CTRL-WFind
ALT-WFind next
CTRL-\Search and replace

Screen Shortcuts

screenStart a screen session.
screen -rResume a screen session.
screen -listShow your current screen sessions.
CTRL-AActivate commands for screen.
CTRL-A cCreate a new instance of terminal.
CTRL-A nGo to the next instance of terminal.
CTRL-A pGo to the previous instance of terminal.
CTRL-A "Show current instances of terminals.
CTRL-A ARename the current instance of terminal.

File Permissions

chmod 775fileChange mode of file to 775
chmod -R 600 folderRecursively chmod folder to 600
chownuser:groupfileChange file owner to userand group to group

File Permission Numbers

The first digit is the owner permission, the second the group and the third for everyone.
Calculate each of the three permission digits by adding the numeric values of the permissions below.
4read (r)
2write (w)
1execute (x)

No comments:

Quick HTTP to HTTPS - Apache2

There are several methods for redirecting your Apache-based website visitors who might type your servers URL using the plain (non-secure) HT...