You are on page 1of 1

CLI Cheat Sheet

Directory operations IO redirection

pwd Current directory cmd >> file Append stdout of cmd to file

mkdir dir Create directory dir cmd 2> file Error output of cmd to file

cd dir Change directory to dir cmd &> file Every output of cmd to file

cd .. Go up a directory
Search files
cd Got to home directory
grep pattern file Search for pattern in file
ls List files
grep -i Case insensitive search

ls options grep -r recursive

-a Show all (incl. hidden) find /dir/ -name Find files starting with name in
name dir
-l Long listing format
whereis cmd Find binary/source for
-1 One file per line command

-t Sort by last modified


File operations

Bash shortcuts touch file Create file

CTRL+c Stop current command cat file1 file2 Concatenate files

less file View file


CTRL+r Reverse search in bash history

CTRL+a Jump to start of line vi file View file using vim editor

CTRL+e Jump to end of line cp file1 file2 Copy file1 to file2

!! (or arrow up) Repeat last command mv file1 file2 Move (rename) file1 to file2

rm file Remove file


!abc Repeat last command starting
with abc

Pipes
Bash variables
cmd1 | cmd2 stdout of cmd1 to cmd2
env Show environment variables
cmd1 |& cmd2 stderr of cmd1 to cmd2
echo $NAME Output value of $NAME variable

export Set $NAME to value Command lists


NAME=value
cmd1; cmd2 Run cmd1 then cmd2
echo $PATH Output executable search path
cmd1 && cmd2 Run cmd2 if cmd1 is successful

IO redirection cmd1 || cmd2 Run cmd2 if cmd1 is not


successful
cmd > file Standard output (stdout) of cmd
to file

You might also like