Command Line Cheat Sheet

Directories

pwd: print working directory

cd <directory>: change directory to <directory>

cd ..: change directory to parent one

ls: list directory contents

ls -la: list detailed directory contents, including hidden files

mkdir <directory>: create new directory named <directory>

Output

cat <file>: output the contents of <file>

less <file>: output the contents of <file> using the less command(which supports paginations etc.)

head <file>: output the first 10 lines of <file>

<cmd> <file>: impose <cmd> on <file>

clear: clear the command line window

Files

rm <file>: delete <file>

rm -r <directory>: clear contents of <directory>

rm -f <file>: force-delete <file>

rm -rf <directory>: force clear <directory>

mv <file-old> <file-new>: rename <file-old>

mv <file> <directory>: move file to <directory>

cp <file> <directory>: copy <file> to <directory>

cp -r <directory1> <directory2>: copy whole <directory1> to <directory2>(overwrit)

touch <file>: Update file or create file

Permissions

chmod 755 <file>: change permission of <file> to 755

chmod -R 600 <directory>: change permission of <directory> and its content to 600

chown <user>:<group> <file>: Change ownership of <file> to <user> and <group>

find <dir> -name ‘<file>’: find all files named <file> inside <dir>(support regex)

grep ‘<text>’ <file>: output all occurrence of <text> inside <file>(add -i for case-insensitivity)

grep -rl ‘text’ <dir>: search for all files container <text> inside <dir>

Network

ping <host>: ping <host> and display status

whois <domain>: output whois information for <domain>

curl -O <url/to/file>: download <file>(via HTTP[S] or FTP)

ssh <username>@<host>: establish an SSH connection to <host> with user <username>

scp <file> <user>@<host>:/remote/path: Copy <file> to a remote <host>

Processes

ps ax: output currently running process

top: display live information about currently running processes

kill <pid>: Quit process with ID

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×