This summary focuses on Debian and Debian-based distributions.
Command | Action |
---|---|
clear |
clear screen |
exit |
exit the shell (builtin) |
history |
command history (builtin) |
logout |
log out of the shell (builtin) |
reset |
reset console |
Key | Action |
---|---|
Tab |
completion |
C-a /C-e |
cursor to line start/end |
M-b /M-f |
previous/next word (back/forward) |
C-k |
delete everything till line end ("kill") |
C-w |
delete previous word |
C-y |
paste what we cut ("yank") |
C-r |
reverse history search (C-r for more) |
C-c |
send SIGINT to the running process |
C-d |
send end-of-file symbol to console |
C-z |
stop running process (use fg /bg to resume) |
Command | Action |
---|---|
apt list |
list available packages |
apt list --installed |
list installed packages |
apt update |
download list of available packages |
apt upgrade |
install upgrades |
apt search <package> |
package lookup |
apt info <package> |
package info |
apt install <package> |
install a package |
apt remove <package> |
remove a package |
apt autoremove |
remove no longer needed |
Command | Action |
---|---|
apropos <keyword> |
search for keyword in descriptions |
man <page> |
manual page |
whatis <page> |
short summary |
See also https://manpages.debian.org/
###cd
: change directory (builtin)
cd <dir>
cp <source> <destination>
Some useful options:
-R
,-r
,--recursive
: copy directories recursively
df -h
Some useful options:
-h
,--human-readable
This prints the actual directory size
du -sh <directory>
Some useful options:
-h
,--human-readable
-s
,--summarize
: display only a total
See man find
; here's a recursive search by pattern:
find -name '*.java'
head foo.txt
less foo.txt
Some useful options:
+/<pattern>
,--pattern=<pattern>
: highlight occurrences of<pattern>
To create a symlink:
ln -s <source> <target>
Some useful options:
-1
: one file per line-a
,--all
: show hidden files-h
,--human-readable
: human-readable file size-l
: long listing format-t
: sort by time, newest first-r
,--reverse
: reverse sort order
mkdir <directory>
Some useful options:
-p
,--parents
: make parent directories as needed
mv <source> <destination>
pwd
rm <file>
Some useful options:
-f
,--force
: ignore nonexistent files-r
,-R
,--recursive
: remove directories recursively
stat <file>
tail foo.txt
Some useful options:
-f
,--follow
: output appended data as the file grows (e.g. for logs)
touch foo.txt
This command is available from the package tree
.
tar -czvf files.tar.gz files
zip -r files.zip files/
tar -xvf files.tar.bz2
unzip files.zip -d /path/to/unzip
tar -tvf files.tar.bz2
unzip -l files.zip
Some tar
options:
-c
,--create
-f
,--file
-t
,--list
-v
,--verbose
-x
,--extract
Common compression methods for -c
:
-z
,--gzip
-j
,--bzip2
-J
,--xz
--lzip
cat file1.txt [file2.txt ...]
diff foo1.txt foo2.txt
Read man grep
.
Example of recursive search, ignoring the case:
grep -r -i 'foobar' .
A few useful options:
-i
,--ignore-case
-r
,--recursive
E.g. for a basic regex substitution:
sed s/foo/bar/g text.txt
sort foo.txt
Some useful options:
-f
,--ignore-case
-R
,--random-sort
-r
,--reverse
-u
,--unique
wc -l foo.txt
Some useful options:
-c
,--bytes
-m
,--chars
-l
,--lines
-w
,--words
This is to run commands as another user. As root
by default:
su
sudo <command>
As another user:
su <user>
sudo -u <user> <command>
whoami
id <user>
passwd
passwd <login>
Some useful options:
-d
,--delete
-e
,--expire
-l
,--lock
-u
,--unlock
useradd --create-home --shell /bin/bash <username>
Some useful options:
-m
,--create-home
-s
,--shell <shell>
-G
,--groups
<group1>,<group2>,...
E.g. to add to a group:
usermod -aG <group> <user>
Some useful options:
-a
,--append
-d
,--home
`-G
,--groups
<group1>,<group2>,...
-l
,--login
<new-login>
-s
,--shell
<shell>
-L
,--lock
-U
,--unlock
userdel <user>
Some useful options:
--remove
: remove home directory
Number | Permissions |
---|---|
0 |
--- |
1 |
--x |
2 |
-w- |
3 |
-wx |
4 |
r-- |
5 |
r-x |
6 |
rw- |
7 |
rwx |
chmod 644 <file>
chmod +x <file>
chmod -x <file>
chown <owner> <file>
chgrp <group> <file>
Useful option: -R
, --recursive
Install procps
package.
pidof java
Some useful options:
-e
: list all processes-C bash
: e.g. processes with commandbash
-U root
: e.g. processes run byroot
pstree
Despite its name, kill
and killall
send any signal.
kill <pid>
,killall <name>
: sendsSIGTERM
by default.- With option
-KILL
: sendsSIGKILL
.
top
Some useful options:
-i
,--include
: include response headers-v
,--verbose
: verbose mode-H
,--header
'Accept: application/json'
: send custom header
Example of sending a file via PUT:
curl -v -H 'Content-Type: application/json' -X PUT --data @"file.json" http://foo.org/bar
Some useful options:
-O
,--output-document
: specifies output file-c
,--continue
: continue with a partially downloaded file
Some useful options:
-D
,--list-interfaces
-i eth0
,--interface=eth0
: look only foreth0
-c <num>
: exit after receiving<num>
packets-s <len>
,--snapshot-length=<len>
: length of packet in bytes to capture-A
: ASCII output of contents-X
: HEX output of contents
E.g. to capture 10
TCP packets from eth0
and show their hex contents:
sudo tcpdump -i eth0 -c 10 -X tcp