Linux Command Line Cheat Sheet
by
Dave Child (DaveChild)
via
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
cd dir
Change directory to dir
mount
Show mounted filesystems
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
grep pattern
Search for pattern in files
!abc:p
Print last command starting with abc
More nano info at:
files
!$
Last argument of previous command
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
screen
^abc^
Run previous command, replacing abc
grep -o
Show matched part of file only
Start a screen session.
123
with 123
find /dir/ -name
Find files starting with name in dir
screen -r
name*
Resume a screen session.
Bash Variables
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
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