Basics
Basic Linux commands and concepts.
Commands
Definitions
.
,./
: Current directory.<your_variable>
: A variable.<your_variable>...
: Multiple variables.
Informational
-
which <command>...
: Show the path of a command. -
whatis <command>...
: Briefly describe a command. -
wc -<option>... <file>...
: Count lines, words, and characters. -
grep -<option>... <pattern> <file>...
: Search for patterns in files and return matching lines. -
less
: Open output in a controllable pager.q
: Quit.space
: Scroll down (next page).b
: Scroll up (previous page).g
: Go to the beginning.G
: Go to the end./<pattern>
: Search forward (down).?<pattern>
: Search backward (up).n
: Repeat search in the same direction (next result).N
: Repeat search in the opposite direction (previous result).h
: Help.
-
cat -<option>... <file>...
: Print file contents to the standard output (terminal).
File & Directory
-
OUTPUT > <file>...
: Redirect output to files (>
: overwrites,>>
: appends). -
mkdir -<option>... <directory>...
: Create directories. -
rm -<option>... <file/directory>...
: Delete files/directories. -
cp -<option>... <source>... <destination>
: Copy files and directories (mv to move). -
touch <file>...
: Create empty files. -
find <directory>... -name <pattern> -<option>
: Search for files and directories.
Process & Monitoring
-
du -<option>... <file/directory>...
: Show disk usage. -
pidof <program_name>...
: Show the PID(s) of a running process. -
ps -<option>...
: View running processes. -
lsof -<option>... <pattern>...
: List open files and their processes. -
kill -<signal> <PID>
: Send a signal to a process.Signal Name Number Description SIGHUP
1
Reload config. Tells a program to restart or reload its settings. Often used after editing config files. SIGINT
2
Graceful stop. Sent when you press Ctrl + C to stop a program. SIGQUIT
3
Like SIGINT
(2
), but also creates a debug log (core dump).SIGABRT
6
Tells a program to abort/cancel (used when something goes wrong). SIGKILL
9
Force-stops a program immediately. SIGTERM
15
Asks a program to stop nicely. (Default signal for kill
) -
watch -<option>... <command -option>...
: Re-run a command periodically.
Command Chaining
-
cmd1 ; cmd2 ; cmd3
: Run commands in order, regardless of success. -
cmd1 && cmd2 && cmd3
: Run next only if the previous succeeds. -
cmd1 || cmd2 || cmd3
: Run next only if the previous fails. -
cmd1 | cmd2 | cmd3
: Pipe output of one command to the next.