golb

Commands

Basic commands

create a file

touch
# touch FILE

create a folder

mkdir
# mkdir DIR

delete a folder

rmdir
# rmdir DIR
rm -r
# rm -r DIR

compare file

diff
# diff FILE_1 FILE_2
cmp
# cmp FILE_1 FILE_2
comm
# comm FILE_1 FILE_2

compression

gzip
gunzip
# gzip FILE
bzip2
# bzip2 FILE

get information about a file

file <file>
# file temp.txt

delete duplicate lines

uniq

get limits of the OS

ulimit -a

fusion files

cat
# cat FILE_1 FILE_2
paste
# paste FILE_1 FILE_2

set file mode creation mask

umask

Redirection

# override to FILE
cmd > FILE
# append to FILE
cmd >> FILE
cmd >& FILE
cmd &> FILE

redirect stdout and stderr to FILE

Standard input

cmd < FILE
cmd <<< "string"

Pipe

CMD_1 | CMD_2

Multiple commands

CMD_1 ; CMD_2 ; CMD_3

Background task

CMD &

Conditional commands

CMD_1 && CMD_2
CMD_1 || CMD_2

See kill signals

# show all signals
kill -L
kill -SIGKILL <PID>
kill -9 <PID>

Others

pstree
kill
crontab
nice
write
mesg
telnet
ssh
ftp

Shell tricks

!! # last command
 ls # with a trailing space -> not in history

disown -a && exit # leave terminal but don't kill running processes

Switch between background and foreground

command &
fg # change to foreground
# pause with CTRL+Z
bg # sent it to background

tar && untar

# create
# -c create -v verbose -z gzip -f archivename
tar -cvzf archive.tar.gz directory

# extract
# -x extract -v verbose -f archivename -C directory
tar -xvf archive.tar.gz -C extracted

zip && unzip

# create
zip -r archivename.zip directory

# extract
unzip archivename.zip -d extracted

Grep everything

grep -rni "pandoc" *
grep -rni "pandoc" ./**/Makefile # in specific file

# or use ripgrep https://github.com/BurntSushi/ripgrep

systemctl and journalctl

SERVICE=service_name.service
systemctl start $SERVICE
journalctl -u $SERVICE -f

Get disk space with df

df -h

# also know type of partition
df -Th

Get size of files with du or dust

cargo install du-dust

dust
# or
du -d 1 -h | sort -h

screen command

# start new "infinite" shell - read the manual for more info
# CTRL + A then "D" to leave
screen

# list screens shell
screen -ls

# resume screen shell
screen -r <screen_id>

Alternatives:

IPs

Args

Command net-tools Command iproute2 Description
ifconfig -a ip addr Show IP address
arp -a ip neigh Show ARP table
route ip route Show network interfaces
netstat -g ip maddress multicast