Public
snipts » bash
showing 1-20 of 518 snipts for bash
-
∞ pack a directory and all its content into a tarfile (compressed)
tar zcvf nameofnewarchiv.tar path/to/dir/to/backup
-
∞ number of file open by command
lsof | awk '{printf("%s\n",$1)}' | sort | uniq -c | sort -n -
∞ Remove backup files (*~) recursively
find . -name '*~' -print -delete -
∞ Remove .svn files from a directory
find . -name ".svn" -exec rm -rf {} \;
-
∞ suchen in linux
grep -H -r "muster" * -
∞ install Drush from CVS HEAD on any unix server
## ## Installs Drush (the Drupal Shell command line utility) from CVS HEAD ## on any UNIX machine, such that all users that have /usr/local/bin in ## their $PATH can use Drush (granted they have access to a Drupal install). ## ## cd /usr/local/src cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d drush-HEAD contributions/modules/drush/ curl -O http://download.pear.php.net/package/Console_Table-1.1.3.tgz tar zxvf Console_Table-1.1.3.tgz cp Console_Table-1.1.3/Table.php drush-HEAD/includes/table.inc ln -s /usr/local/src/drush-HEAD/drush /usr/local/bin/drush ## ## now any user that has /usr/local/bin in their $PATH can use Drush. ## ## ## ... later on, to keep drush up to date, run the following: #cd /usr/local/src/drush-HEAD #cvs update -dPA
-
∞ Add +x to all *.html files in a directory
find ~/path/to/site/ -type f -name '*.htm*' -exec chmod +x {} \;
-
∞ find and delete
find . -name "FILE-TO-FIND"-exec rm -rf {} \;
-
∞ Correct permissions for svn files in project
find -name .svn -exec sudo chmod 777 {} \; find $(find -name .svn) -type d -exec sudo chmod 777 {} \; find $(find -name .svn) ! -type d -exec sudo chmod 664 {} \;
-
∞ download, unzip and remove zipfile in one step
curl http://dow.nloadaddre.ss/filename.tar.gz | tar xvz
-
∞ Bash Script ToDo in iCal
#!/bin/sh arch -i386 osascript << EOF set theSummary to "Backup HDD with SuperDuper!" set bkpDate to (current date) + 14 * days tell application "iCal" make todo at end of events of (item 1 of every calendar) with properties {summary:theSummary, due date:bkpDate} end tell EOF
-
∞ get a process id
ps aux | grep processname | grep -v grep | awk '{print $2}' -
∞ Massive operations on files containing spaces in their names
# This example shows how to copy all the files located in the "name" # directory to the "dest" directory taking care of the white spaces # in the filenames, if any. find ${path} -name "${name}" | while read i do cp "$i" ${dest} done
-
∞ limit rate pings with iptables
iptables -A INPUT -p icmp -m limit --limit 39.6/m --limit-burst 1 -j DROP # it will cause 2 out of 3 icmp replies to fail when executing a ping like # ping -c 3 -i 1 -w 3 10.10.10.10 # # we needed 1 out of 3 successful ping replies in, so that's 2/3 ~= 0.67 replies per second # since we cannot use less than 0 values, we up the scale to the minute, so # 0.67 * 60 = 39.6 replies in 1 minute :-)
-
∞ tar Befehl
tar cvzf filename.tar.gz file.jpg # packe 'file.jpg' in 'filename.tar.gz' tar cvzf filename.tar.gz folder/ # packe 'folder/*' in 'filename.tar.gz' tar xvzf filename.tar.gz # entpackee 'filename.tar.gz'
-
∞ Little bash script created by Fabián Gallina, to play radio streaming from the bash console.
#!/bin/bash case "$1" in mitre) # Radio Mitre 792 AM URII='mms://streammitre.uigc.net/mitrevivo' ;; rp) # Rock and Pop URII="mms://200.59.146.10/rockandpop-ba" ;; delplata) # Del Plata AM 1030 URII='mms://delplata.telecomdatacenter.com.ar/delplata' ;; radio10) URII='http://radio10.telecomdatacenter.com.ar/radio10' ;; jamming) URII='http://www.alsolnet.com/stream/jamming3/vivo.asx' ;; continental) # AM 590 Continental URII='http://66.175.96.10/arcontinental' ;; los40) # Los 40 Principales URII='http://66.175.96.10/ARLOS40P' ;; mega) # Mega 98.3 Puro Rock Nacional URII='http://mega.telecomdatacenter.com.ar/mega' ;; fm100) # FM 100 99.9 rtsp://g2.prima.com.ar/vivo/cadena100.rm URII='rtsp://g2.prima.com.ar/vivo/cadena100.rm' ;; fmsi) # 89.1 FM BA San Isidro URII='http://streaming.euro-web.com.ar:8000' ;; sapiens) # radio fm sapiens de olavarria URII='http://cast.radiosapiens.com:8016' ;; *) echo " Uso: radio.sh opción mitre ( Radio Mitre 792 AM ) rp ( Rock and Pop ) los40 ( Los 40 Principales ) fm100 ( FM 100 99.9 ) delplata ( AM 1030 ) continental ( AM 590 ) mega ( Mega 98.3 Puro Rock Nacional ) fmsi ( 89.1 FM BA San Isidro ) tn24 ( TN 24 Horas ) " exit 1 ;; esac FILETYPE=$(echo $URII|awk -F . '{print $NF}') case $FILETYPE in asx) PLAYLIST='-playlist' ;; *) PLAYLIST='' ;; esac mplayer -af lavcresample=44100 -cache 32 $PLAYLIST "$URII"
-
∞ create and apply a patch between files in two directories
# produces a patch between the files in the 2 dirs # -c : special context for output # -r : directory recursively # -B : ignore blanks diff -crB before_dir after_dir > foo.patch # if you want to patch before_dir now cd before_dir # -p n : strip the smallest prefix containing n number of slashes # you can do a dry run by adding --dry-run # or use a backup of the file before it gets patched with -b patch -p1 < ../foo.patch
-
∞ install svn on shared host
#Install subversion on a shared host curl -O http://subversion.tigris.org/downloads/subversion-1.6.9.tar.gz curl -O http://subversion.tigris.org/downloads/subversion-deps-1.6.9.tar.gz curl -O http://www.openssl.org/source/openssl-0.9.8l.tar.gz tar zxvf openssl-0.9.8l.tar.gz tar zxvf subversion-1.6.9.tar.gz tar zxvf subversion-deps-1.6.9.tar.gz cd openssl-0.9.8l/ ./config shared --prefix=$HOME/installs && make clean && make && make install cd ../ export CFLAGS="-O2 -g -I$HOME/installs/include" export LDFLAGS="-L$HOME/installs/lib" export CPP="gcc -E -I$HOME/installs/include" cd subversion-1.6.9/neon/ ./configure --with-ssl=openssl --prefix=$HOME/installs cd ../ ./configure --with-ssl --prefix=$HOME/installs --with-neon=$HOME/installs/bin/neon-config make clean && make && make install echo 'store-plaintext-passwords=no' >> ~/.subversion/servers
-
∞ elapsed time between two log records
#!/bin/bash # # parses the time (in seconds) that elapsed between 2 consecutive entries # each matching to pattern1 and pattern2. # date format : [DDD] [MMM] [dd] [hh]:[mm]:[ss] [YYYY] # example : Tue May 12 06:49:44 2009 # # substitute the patterns at will # # limitation : it works for entries having the same year # # example # Tue May 12 06:49:41 2009 - pattern1 # Tue May 12 06:49:44 2009 - pattern2 # # it should output : # 3 # awk ' BEGIN{ m["Jan"]="01"; m["Feb"]="02"; m["Mar"]="03"; m["Apr"]="04"; m["May"]="05"; m["Jun"]="06"; m["Jul"]="07"; m["Aug"]="08"; m["Sep"]="09"; m["Oct"]="10"; m["Nov"]="11"; m["Dec"]="12"; d["Sun"]="01"; d["Mon"]="02"; d["Tue"]="03"; d["Wed"]="04"; d["Thu"]="05"; d["Fri"]="06"; d["Sat"]="07"; s=0; # start timestamp e=0; # end timestamp } /pattern1/ { dt1=$0; gsub(":"," ",$4); spec1=sprintf("%s %s %s %s",$5,d[$1],m[$2],$4); s=mktime(spec1); } /pattern2/ { dt2=$0; gsub(":"," ",$4); spec2=sprintf("%s %s %s %s",$5,d[$1],m[$2],$4); e=mktime(spec2); print e-s; e=s=0; }' < $1
-
∞ Recursively change permissions to directories only
# This example sets permissions 600 to directories only recursively. # To do the same with files instead of directories, simply put a "!" before "-type". find . -type d -exec chmod 600 {} \;



Linux in a Nutshell