1. Cheat Sheet Linux Terminal
1.1 Resource
1.1.1 Online
1.1.2 Download
1.2 Bash Commands
| Command Line |
Explanation |
| uname -a |
Show system and kernel |
| head -n1 /etc/issue |
Show distri-bution |
| mount |
Show mounted filesy-stems |
| date |
Show system date |
| uptime |
Show uptime |
| whoami |
Show your username |
| man_command_ |
Show manual for_command_ |
1.3 Bash Shortcuts
| Command Line |
Explanation |
| CTRL-c |
Stop current command |
| CTRL-z |
Sleep program |
| CTRL-a |
Go to start of line |
| CTRL-e |
Go to end of line |
| CTRL-u |
Cut from start of line |
| CTRL-k |
Cut to end of line |
| CTRL-r |
Search history |
| !! |
Repeat last command |
| !abc |
Run last command starting with_abc_ |
| !abc:p |
Print last command starting with_abc_ |
| !$ |
Last argument of previous command |
| ALT-. |
Last argument of previous command |
| !* |
All arguments of previous command |
| abc--123 |
Run previous command, replacing_abc_with_123_ |
1.4 Bash Variables
| Command Line |
Explanation |
| env |
Show environment variables |
| echo_$NAME_ |
Output value of_$NAME_variable |
| export_NAME_=value |
Set_$NAME_to_value_ |
| $PATH |
Executable search path |
| $HOME |
Home directory |
| $SHELL |
Current shell |
1.5 IO Redirection
| Command Line |
Explanation |
| cmd < file |
Input of cmd from file |
| cmd1 < cmd2 |
Output of cmd2 as file input to cmd1 |
| cmd > file |
Standard output (stdout) of cmd to file |
| cmd |
Discard stdout of cmd |
| cmd >> file |
Append stdout to file |
| cmd 2> file |
Error output (stderr) of cmd to file |
| cmd >&2 |
stdout to same place as stderr |
| cmd 2>&1 |
stderr to same place as stdout |
| cmd &> file |
Every output of cmd to file |
1.6 Pipes
| Command Line |
Explanation |
| cmd1 | cmd2 |
stdout of cmd1 to cmd2 |
| cmd1 |& cmd2 |
stderr of cmd1 to cmd2 |
1.7 Command Lists
| Command Line |
Explanation |
| cmd1 ; cmd2 |
Run cmd1 then cmd2 |
| cmd1 && cmd2 |
Run cmd2 if cmd1 is successful |
| cmd1 || cmd2 |
Run cmd2 if cmd1 is not successful |
| cmd |
Run cmd in a subshell |
1.8 Directory Operations
| Command Line |
Explanation |
| pwd |
Show current directory |
| mkdir_dir_ |
Make directory_dir_ |
| cd_dir_ |
Change directory to_dir_ |
| cd .. |
Go up a directory |
| ls |
List files |
1.9 ls Options
| Command Line |
Explanation |
| -a |
Show all (including hidden) |
| -R |
Recursive list |
| -r |
Reverse order |
| -t |
Sort by last modified |
| -S |
Sort by file size |
| -l |
Long listing format |
| -1 |
One file per line |
| -m |
Comma-----separated output |
| -Q |
Quoted output |
1.10 Search Files
| Command Line |
Explanation |
| grep pattern files |
Search for pattern in files |
| grep -i |
Case insens-itive search |
| grep -r |
Recursive search |
| grep -v |
Inverted search |
| grep -o |
Show matched part of file only |
| find /dir/ -name name* |
Find files starting with name in dir |
| find /dir/ -user name |
Find files owned by name in dir |
| find /dir/ -mmin num |
Find files modifed less than num minutes ago in dir |
| whereis command |
Find binary / source / manual for command |
| locate file |
Find file (quick search of system index) |
1.11 File Operations
| Command Line |
Explanation |
| touch file1 |
Create file1 |
| cat file1 file2 |
Concat-enate files and output |
| less file1 |
View and paginate file1 |
| file file1 |
Get type of file1 |
| cp file1 file2 |
Copy file1 to file2 |
| mv file1 file2 |
Move file1 to file2 |
| rm file1 |
Delete file1 |
| head file1 |
Show first 10 lines of file1 |
| tail file1 |
Show last 10 lines of file1 |
| tail -f file1 |
Output last lines of file1 as it changes |
1.12 Process Management
| Command Line |
Explanation |
| ps |
Show snapshot of processes |
| top |
Show real time processes |
| kill_pid_ |
Kill process with id_pid_ |
| pkill_name_ |
Kill process with name_name_ |
| killall_name_ |
Kill all processes with names beginning_name_ |
1.13 Nano Shortcuts
1.13.1 Files
| Command Line |
Explanation |
| Ctrl-R |
Read file |
| Ctrl-O |
Save file |
| Ctrl-X |
Close file |
1.13.2 Images
| Command Line |
Explanation |
| ALT-A |
Start marking text |
| CTRL-K |
Cut marked text or line |
| CTRL-U |
Paste text |
1.13.3 Navigate File
| Command Line |
Explanation |
| ALT-/ |
End of file |
| CTRL-A |
Beginning of line |
| CTRL-E |
End of line |
| CTRL-C |
Show line number |
| CTRL-_ |
Go to line number |
1.13.4 Search File
| Command Line |
Explanation |
| CTRL-W |
Find |
| ALT-W |
Find next |
| CTRL-\ |
Search and replace |
1.14 Screen Shortcuts
| Command Line |
Explanation |
| screen |
Start a screen session. |
| screen -r |
Resume a screen session. |
| screen -list |
Show your current screen sessions. |
| CTRL-A |
Activate commands for screen. |
| CTRL-A c |
Create a new instance of terminal. |
| CTRL-A n |
Go to the next instance of terminal. |
| CTRL-A p |
Go to the previous instance of terminal. |
| CTRL-A " |
Show current instances of terminals. |
| CTRL-A A |
Rename the current instance. |
1.15 File Permissions
| Command Line |
Explanation |
| 4 |
read ® |
| 2 |
write (w) |
| 1 |
execute (x) |
| chmod 644 file |
Change mode of file torw-r--r-- |
| chmod -R 750 folder |
Recursively chmod folder and contents torwxr-x-- |
| chown usr:grp file |
Change file owner to usr, and group to grp |
Last update:
2024-02-12
Created:
2024-01-30