Skip to content

Instantly share code, notes, and snippets.

Last active Oct 23, 2022
What would you like to do?
Linux keyboard shortcuts and commands

Web version:

Keyboard shortcuts

ctrl + u: delete everything behind cursor

ctrl + w: delete word behind cursor

ctrl + k: delete everything in front of cursor

ctrl + a: move cursor to beginning

ctrl + e: move cursor to end

ctrl + c: cancel

alt+left/right arrow: jump back/forward one word


cd -: go back to previous path

cd: (no directory) goes to home folder

apropos <keyword>: search for command (ex: apropos "locate the binary" to find "whereis" command)

man <command>: manual for command (ex: man "apropos") opens in less

<command> ——help: summary for most commands (ex: file ——help)

su <username>: switch to <username>

sudo -i: switch to root

sudo -k: end/expire sudo session

which <command>: find where <command> is located

head -n#: displays first # lines of file (# defaults to 10 if not specified)

tail -n#: displays last # lines of file (# defaults to 10 if not specified)

grep -in “needle” haystack.txt: search for "needle" (ignore case) in haystack.txt and print line numbers

-i: ignore case

-v: only print lines that match results

-n: print line numbers

less +G: open less at the last line

less +F: open less with forward forever (live update)

    ctrl + c then q to exit

sort -u <file>: lists unique lines from <file> (if there are duplicates it will only show once)

df -h: get free space (-h for human readable)


nano is a text editor. It's a more user friendly than vi(m). There's no wrong answer.

Open files with nano <filename>

ctrl + w: search ("where")

ctrl + v: move down 1 screen

ctrl + y: move up 1 screen

ctrl + x: exit


less is a file viewer based on more (seriously)

Open files with less <filename>

Navigating in less

h: help

q: quit

e: forward one line

y: backward one line

f: forward one window

b: backward one window

shift + F: forward forever (live update)

g: go to first line

shift + G: go to last line

Permissions in ls

- <rwx for user> <rwx for group> <rwx for others>

- can be D for directory, L for link, - for files


aaron@ubuntu-test:~$ ls -l
-rwxr-xr-- 1 aaron aaron 0 Oct 23 17:11

-rwxr-xr——: user can read write and execute

-rwxr-xr——: group can read and execute

-rwxr-xr——: others can read

output redirection

1> file.txt: send standard output (not errors) to file.txt (overwrite)

>: same as “1>”

2> file.txt: send error output to file.txt (overwrite)

>> file.txt: send output to file.txt (append)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment