Linux :: Commands

The Linux Command Line

chapter 1

date
cal
command1 && command2 # command 2 runs only if command 1 exit successuflly
command1; command 2 # command2 runs regardless of command1 outcome

chapter 2

pwd
cd # cd -: return to previous dir
ls

chapter 3

ls
file
less

chapter 4

cp
mv
mkdir
rm
ln file link # hardlink: ls -l will tell how many links are there for the file; ls -i will tell inode number pointing to data content; hard links cannot reference dir 
ln -s item link # symbolic link
[abc]* # any file begins with either "a", "b" or "c"

chapter 5

type – Indicate how a command name is interpreted
which – find command location
help – Get help for shell builtins
man – Display a commands manual page
apropos – Display a list of appropriate commands; same as 'man -k'
info – Display a commands info entry
whatis – Display one-line manual page descriptions
alias – Create an alias for a command; unalias; no argument will display all alias

chapter 6

> # short for 1>, stdout redirection
&> # short for "> output 2>&1"
| pipe  
cat # can accept multiple files
sort
uniq # uniq -d: list of duplicates
grep
wc # line, word and byte counts; -l only lines
head
tail -f /var/log/messages
tee

chapter 7

echo
$((expression)) # arithmetic expansion
{A,B,C}; {1..5} # brace expansion
$VAR # variable
$(ls) # command sub
double quote: allow expansion
single quote: as is

chapter 8

clear
history # !499 repeat line 499 in history

chapter 9

id # id of the user
chmod # ugoa+/-/= rwx; 
umask
su # su - : login shell, short for -l
sudo # sudo -l: list of commands
chown usr:group file
chgrp
passwd

chapter 10

ps
top
command & # put to background; Ctrl+Z to pause
jobs
bg %1
fg %1
kill -9 pid
killall
shutdown # -h, -r now
pstree
vmstat
xload
tload

chapter 11

printenv # print part or all of the environment
set # set options
export # export environment to subsequently programs
alias 

chapter 12 - vim

chapter 13

PS1="\[\033[s\033[0;0H\033[0;41m\033[K\033[1;33m\t\033[0m\033[u\]
<\u@\h \W>\$ "
export PS1

chapter 14 - package management

chapter 15

mount
umount
fsck # file system check
fdisk
mkfs
dd if=input_file of=output_file [bs=block_size [count=blocks]]
genisoimage (mkisofs)
wodim (cdrecord)
md5sum /path/to/file

chapter 16 - networking

ping
traceroute/tracepath
ip
netstat
ftp/lftp
wget
ssh
scp
sftp

chapter 17 - searching

locate # controlled by updatedb
find
xargs
touch
stat

chapter 18 - regular expressions

grep: global regular expression print
-i ignore case
-v invert match

anchors: ^ caret, beginning of the line, end$ of the line
grep -i '^..j.r$' /usr/share/dict/words # crossword puzzler helper

bracket expression [abc] a or b or c