Error message

Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in _menu_load_objects() (line 579 of /var/www/smapper/html/includes/menu.inc).

Linux

File commands

head       => output the first 10 lines of a file

tail           => output the last 10 lines of a file

tail –f      => out the last 10 lines of files as it grows

more      => view contents of file

less         => view contents of file and allows forward an  backward movement

pwd        => show the current path

mkdir      => create a directory

ls –la       => show all information about files/directories

rm           => delete file

rm –r      => delete directory recursively

rm –f      => forcefully delete file

rm –rf     => forcefully delete directory recursively

cp test1 test2        => copy test1 to test2

mv           => move file from one directory to another

mv test1 test3       => rename file

cat > test                => output file content to test file

zcat         => output gzip file content to screen

wc           => show the number of new lines, words, characters

wc – l      => show line count

gpg –c    => encrypt file

gpg test.gpg           => decrypt file

diff file1 file2        =>compare two files for differencesvm

tr

count       => count the number of lines in a file

wcz

uniq        => show uniq info in file

sort –k#                 => sort file according to selected column#

md5sum file1       =>generate md5sum for file

sha1sum file1       =>generate sha1sume for file

System Commands

df   => display hard drive device information

df -a     => dispaly all hard drive  devices information

df -h     => display hard drive device information in human readable format GB

 

 

Network

ip addr show      => show all network interfaces and ip address

ip address add   => set ip address

dig          => get DNS information for domain

dig – x   => reverse lookup

wget      => download file

netstat -plunt    => show all active listening ports

netstat –nAinet                => show active connections

route –n => show routing table

route add -net 172.16.0.0/24 gw 192.168.1.5 dev eth0

route –del           => same format at route add

arping –I eth# host          =>send arp information

 

Process Related

ps           => show active process

ps –ef   => show full process info

pgrep    => show pid for process name

ps –aux => show process resource info

top         => task manager that updates

htop      => same as top but interactive

cmon     => system monitor tool

kill #       => stop process by pid number

 

Search

grep       =>search for pattern in files

grep –r => search recursively for pattern in directory

grep –v => exclude from search

locate    => locate patterns

updated               =>update locate database

fine / -name       => find files based on name

find ./Dir –iname              => Find a file in your current directory and

       ignore the case of the file name

SSH

ssh user@host  =>connect to host as user

ssh -i /path/to/id_rsa user@serverip      =>ssh using id_rsa file

ssh -p port user@host   => ssh with non standard port

vi ~./ssh/know_hosts    => view ssh know host and keys

 

firewall

example of allowing inbound ssh connections from a specific IP address

iptables -A INPUT -p tcp -s IP -d $SERVER_IP --sport 1024:65535 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -p tcp -s $SERVER_IP -d IP --sport 22 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT

 

iptables –L          =>List all rules

iptables –F          =>flush the rules

 

ufw enable         =>turn ufw on

ufw disable         =>turn ufw off

ufw status           =>show status of ufw

ufw status verbose         =>check status with more information

ufw allow 22       =>allow ssh by port

ufw allow ssh     =>allow ssh by name on default port

ufw allow 53/tcp              =>allow tcp port 53

ufw deny http   =>deny web traffic on default port 80

 

ngrep

ngrep –f               => read bfp filter from file

ngrep –d              => specific interface to listen on

 

tcpdump

tcpdump –i         => specific interface

tpcudmp –ni      => no name resolution

tcpdump –r        => read packet capture

tcpdump –w      => write packets to file

 

Packages

dpkg –r => remove package

dpkg –l => list packages

dpkg –i => install package

dpkg –S =>Search for a filename from installed packages

apt-get search   =>search for packages

 

Install from source

./configure

make

make install

 

Critical system files

/var/log                => Directory for logs

/var/log/messages          => System messages

/etc/crontab      =>System-wide cron file

/etc/passwd      =>list of user accounts

/etc/shadow      => encrypted passwords

/etc/init.d/         => startup files

/etc/network/  => network settings and scripts

/etc/resolve.conf            => DNS configuration

 

zipped

tar –cvf file.tar /dir/        => create a tar ball and output to a directory

tar –xvf file.tar  => extract files

guzip      => .gz files

guunzip    => extract .gz files