Reference Linux Commands

[bash]
# 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 {}
[/bash]

[bash]
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
[/bash]

File System Managment
[bash]
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
[/bash]
Compressing Tars

[bash]
tar cf dir.tar dir/
tar czf dir.tar.gz dir/
tar cjf dir.tar.bz2 dir/
[/bash]

Decompressing Tars

[bash]
tar xf dir.tar
tar xzf dir.tar.gz
tar xjf dir.tar.bz2
[/bash]

Resume and scp transfer

[bash]
rsync –partial –progress –rsh=ssh host:remote_file local_file
rsync -P -e ssh host:<remote file> <local file>
[/bash]

Find ports without detection that are open

[bash]
nmap -FsS domain.com
[/bash]

SED

[bash]
sed -i -e ‘s/-/t-/’ file.txt"
[/bash]

Update iptables firewall

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

Count fail2ban ip blocks

[bash]
iptables -nvL | grep -A 100000 ‘Chain fail2ban-SSH’ | wc -l
[/bash]

Remove ip address from iptables fail2ban list

[bash]
iptables -nL | grep -A 100000 ‘Chain fail2ban-SSH’
iptables -D fail2ban-SSH <line number>
[/bash]

Common everyday should know

[bash]
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
[/bash]

Leave a Reply

Your email address will not be published. Required fields are marked *