Reference Linux Commands

# find largest 15 directories or files
find . -type d -print0 | xargs -0 du -s | sort -n | tail -15 | cut -f2 | xargs -I{} du -sh {}
find . -type f -print0 | xargs -0 du -s | sort -n | tail -15 | cut -f2 | xargs -I{} du -sh {}
scp localfile user@remotecomputer:/path/to/target/dir
diff file1 file2
dd if=/dev/cdrom | bzip2 | ssh user@domain.com 'bunzip2 | cat > file.iso'
useradd -M -G group user
ssh host 'cat >> .ssh/authorized_keys2' < .ssh/id_rsa.pub

File System Managment

fdisk /dev/sda
df -h 
resize2fs /dev/sdb2
mke2fs /dev/sda1
mkfs.ext3 /dev/sda1
mkfs.ext4 /dev/sda1
//Upgrading from ext3 to ext4
umount /dev/sda2
tune2fs -O extents,uninit_bg,dir_index /dev/sda2
e2fsck -pf /dev/sda2
mount /dev/sda2 /home

Compressing Tars

tar cf dir.tar dir/
tar czf dir.tar.gz dir/
tar cjf dir.tar.bz2 dir/

Decompressing Tars

tar xf dir.tar
tar xzf dir.tar.gz
tar xjf dir.tar.bz2

Resume and scp transfer

rsync --partial --progress --rsh=ssh host:remote_file local_file
rsync -P -e ssh host:<remote file> <local file>

Find ports without detection that are open

nmap -FsS domain.com

SED

sed -i -e 's/-/t-/' file.txt"

Update iptables firewall

/etc/init.d/fail2ban stop
iptables-restore < /system/configuration/firewall.txt
/etc/init.d/iptables save
/etc/init.d/fail2ban start

Count fail2ban ip blocks

iptables -nvL | grep -A 100000 'Chain fail2ban-SSH' | wc -l

Remove ip address from iptables fail2ban list

iptables -nL | grep -A 100000 'Chain fail2ban-SSH'
iptables -D fail2ban-SSH <line number>

Common everyday should know

ls
cd
mv
rm
cp
man
ssh
awk
sed
mysql -u root -p
grep
head
tail
watch
whois
dig
host
curl
htop
kill
echo
cat
zip
g++
javac
vim
clear

Leave a Reply