Category: bash
-
Sniffing tcp with tcpdump
sudo tcpdump -ni lo0 -s 0 -A tcp port 3000
-
Set automatic httpd daemon start
This comand set executions permissions to the script and with chkconfig we create a Start link to the rc.d system. chmod 755 /etc/init.d/httpd ; chkconfig –add httpd /etc/init.d/httpd start
-
Dirty script to find out free storage space in mount points
Dirty script to find out free storage space. for path in `mount | awk ‘/^\/dev/ {print $3}’`; do df -h “$path”; done;
-
Nat with iptables
Example of nat in iptables. YourIP=1.2.3.4 YourPort=80 TargetIP=2.3.4.5 TargetPort=22 iptables -t nat -A PREROUTING –dst $YourIP -p tcp –dport $YourPort -j DNAT \ –to-destination $TargetIP:$TargetPort iptables -t nat -A POSTROUTING -p tcp –dst $TargetIP –dport $TargetPort -j SNAT \ –to-source $YourIP iptables -t nat -A OUTPUT –dst $YourIP -p tcp –dport $YourPort -j DNAT \…
-
Find symbolic links to directory
find . -lname ‘*directory_name*’ 2>/dev/null
-
Check if an input is numeric or char
With this script you can check if an argument to a script is numeric, char or alphanumeric. [[ -z “$1” ]] && echo “I cant work without an input” && exit 1 INPUT=”$@” [[ “$INPUT” == ?(+|-)+([0-9]) ]] && echo “$INPUT is numeric” && exit 0 [[ “$INPUT” == +([a-zA-Z]) ]] && echo “$INPUT is…
-
How to generate a tar gz file from a file list
Easy example of tar use. We provide a list of files to archive them in one tar file. tar zcvf myFile.tar.gz file1.txt file2.txt file3.txt file4.txt
-
List large files in Linux
Command to find and list all files above a defined size. Works for debian based distros and Centos. If the output its wrong in other systems, you can play with awk params. find . -type f -size +50000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’
-
Mirror two local directories with rsync
To copy 2 directories in a little more advanded way you can use rsync. # mirror Dir to Dir2 cd ~/Dir rsync -vaz ~/Dir2 .