golb

Useful commands on Linux

Cool commands

!! # last command
sudo !! # last command as root

mkdir -p /mnt/ram; mount -t tmpfs tmpfs /mnt/ram -o size=4096M # create a ram disk

ls # with a trailing space -> not in history
disown -a && exit # leave terminal but don't kill running processes

Basic commmands

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

zip
# zip ARCHIVE.zip FILE
gzip
gunzip
# gzip FILE
bzip2
# bzip2 FILE

get information about a 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"

Pipes

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

Switch between background and foreground

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