UNCLASSIFIED TIPS .... * share the current directory tree (via http) at http://$HOSTNAME:8000/ >> python -m SimpleHTTPServer * Copy ssh keys to user@host to enable password-less ssh logins. >> $ssh-copy-id user@host * start a tunnel from some machine's port 80 to your local post 2001 >> ssh -N -L2001:localhost:80 somemachine * Empty a file >> > file.txt * Mount a temporary ram partition >> mount -t tmpfs tmpfs /mnt -o size=1024m * Mount folder/filesystem through SSH >> sshfs name@server:/path/to/folder /path/to/mount/point * Like top, but for files >> watch -d -n 2 'df; ls -FlAt;' * currently mounted filesystems in nice layout >> mount | column -t * Mac Sleep Timer >> sudo pmset schedule sleep "08/31/2009 00:00:00" * Scale,Rotate, brightness, contrast,...with Image Magick >> convert -rotate $rotate -scale $Widthx$Height -modulate $brightness -contrast $contrast -colorize $red%,$green%,$blue% $filter file_in.png file_out.png * Find status of all symlinks >> symlinks -r $(pwd) * Propagate a directory to another and create symlink to content >> lndir sourcedir destdir * decoding Active Directory date format >> ldapsearch -v -H ldap:// -x -D cn=,cn=,dc=,dc= -w -b ou=,dc=,dc= -s sub sAMAccountName=* '*' | perl -pne 's/(\d{11})\d{7}/"DATE-AD(".scalar(localtime($1-11644473600)).")"/e' * Show the power of the home row on the Dvorak Keyboard layout >> egrep -ci ^[aoeuidhtns-]+$ /usr/share/dict/words * Quick case-insenstive partial filename search >> alias lg='ls --color=always | grep --color=always -i' * Watch the progress of 'dd' >> dd if=/dev/urandom of=file.img bs=4KB& pid=$! * Processor / memory bandwidthd? in GB/s >> dd if=/dev/zero of=/dev/null bs=1M count=32768 * Print all the lines between 10 and 20 of a file >> sed -n '10,20p' * Attach screen over ssh >> ssh -t remote_host screen -r * To print a specific line from a file >> sed -n 5p * Search commandlinefu.com from the command line using the API >> cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; } * Share a terminal screen with others >> % screen -r someuser/ * Show directories in the PATH, one per line >> ( IFS=:; for p in $PATH; do echo $p; done ) * list all executables in your path >> ls $(echo $PATH | sed 's/:/ /g') * Tweak system files without invoking a root shell >> echo "Whatever you need" | sudo tee [-a] /etc/system-file.cfg * Batch resize all images in the current directory that are bigger >> mogrify -resize 800\> * * Execute a sudo command remotely, without displaying the password >> stty -echo; ssh HOSTNAME "sudo some_command"; stty echo * VMware Server print out the state of all registered Virtual >> for vm in $(vmware-cmd -l);do echo -n "${vm} ";vmware-cmd ${vm} getstate|awk '{print $2 " " $3}';done * Mount proc >> mount -t proc{,,} * ps a process keeping the header info so you know what the columns >> ps auxw |egrep "PID|process_to_look_at" * take execution time of several commands >> time { ; ; ; } * Change the ownership of all files owned by one user. >> find /home -uid 1056 -exec chown 2056 {} \; * Forward port 8888 to remote machine for SOCKS Proxy >> ssh -D 8888 user@site.com * Open up a man page as PDF (#OSX) >> function man2pdf(){ man -t ${1:?Specify man as arg} | open -f -a preview; } * Lists all directories under the current dir excluding the .svn >> find . \( -type d -name .svn -prune \) -o -type d -print * Tired of switching between proxy and no proxy? here's the >> iptables -t nat -A OUTPUT -d ! 10.0.0.0/8 -p tcp --dport 80 -j DNAT --to-destination 10.1.1.123:3128 * Unixtime >> date +%s * take a look to command before action >> find /tmp -type f -printf 'rm "%p";\n' * Add existing user to a group >> usermod -a -G groupname username * Watch for when your web server returns >> watch -n 15 curl -s --connect-timeout 10 http://www.google.com/ * Look for IPv4 address in files. >> alias ip4grep "grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}'" * fuman, an alternative to the 'man' command that shows commandlinefu tips >> fuman(){ lynx -width=$COLUMNS -nonumbers -dump "http://www.commandlinefu.com/commands/using/$1" | less * Reconnect to screen without disconnecting other sessions >> screen -xR * list your device drivers >> lspci -vv * change directory up a number of levels >> function ..(){ for ((j=${1:-1},i=0;i> tr '\000' '\377' < /dev/zero | dd of=allones bs=1024 count=2k * Print stack trace of a core file without needing to enter gdb >> alias gdbbt="gdb -q -n -ex bt -batch" * Remove color codes (special characters) with sed >> sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g * calulate established tcp connection of local machine >> netstat -an|grep -ci "tcp.*established" * Using column to format a directory listing >> (printf "PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME\n" \ ; ls -l | sed 1d) | column -t * Enable programmable bash completion in debian lenny >> aptitude install bash-completion ; source /etc/bash_completion * Port scan a range of hosts with Netcat. >> for i in {21..29}; do nc -v -n -z -w 1 192.168.0.$i 443; done * Remove color codes (special characters) with sed >> sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" * calulate established tcp connection of local machine >> netstat -an | awk '$1 ~ /[Tt][Cc][Pp]/ && $NF ~ /ESTABLISHED/{i++}END{print "Connected:\t", i}' * Change Title of Terminal Window to Verbose Info useful at Login >> echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g"` / `ps aux|wc -l`]\007" * display statistics about the lines of code in 'c' code files >> find . -name \*.c | xargs wc -l | tail -1 | awk '{print $1}' * To get internet connection information . >> sudo /bin/netstat -tpee * Copy via tar pipe while preserving file permissions (cp does not!; >> cp -pr olddirectory newdirectory * Show GCC-generated optimization commands when using the >> cc -march=native -E -v - &1 | grep cc1 * for all who don't have the watch command >> watch() { t=$1; shift; while test :; do clear; date=$(date); echo -e "Every "$t"s: $@ \t\t\t\t $date"; $@; sleep $t; done } * Check which files are opened by Firefox then sort by largest size. >> FFPID=$(pidof firefox-bin) && lsof -p $FFPID | awk '{ if($7>0) print ($7/1024/1024)" MB -- "$9; }' | grep ".mozilla" | sort -rn * Find the process you are looking for minus the grepped one >> ps -C command * make 100 directories with leading zero, 001...100, using bash3.X >> mkdir $(printf '%03d\n' {1..100}) * Batch file name renaming (copying or moving) w/ glob matching. >> for x in *.ex1; do mv "${x}" "${x%ex1}ex2"; done * Change Windows Domain password from Linux >> smbpasswd -r -U * Testing php configuration >> php -r "phpinfo\(\);" * use wget to check if a remote file exists >> wget --spider -v http://www.server.com/path/file.ext * 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)';} * Faster find and move using the find and xargs commands. Almost as >> find . -maxdepth 2 -name "*somepattern" -print0 | xargs -0 -I "{}" echo mv "{}" /destination/path * Show in a web server, running in the port 80, how many ESTABLISHED >> netstat -ant | grep :80 | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n * Count all conections estabilished on gateway >> cat /proc/net/ip_conntrack | grep ESTABLISHED | grep -c -v ^# * Donwload media from *.rm from an url of type http://.../*.ram >> wget -O- | wget -i - * find all non-html files >> find . -type f ! -name "*html" * find external links in all html files in a directory list >> find . -name '*.html' -print0| xargs -0 -L1 cat |sed "s/[\"\<\>' \t\(\);]/\n/g" |grep "http://" |sort -u * Search through files, ignoring .svn >> grep -R . --exclude-dir='.svn' * Delete files if not have some extension >> ls -1 |grep -v .jpg |xargs rm * Matrix Style >> echo -e "\e[31m"; 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; * Colorize matching string without skipping others >> egrep --color=auto 'usb|' /var/log/messages * List programs with open ports and connections >> netstat -ntauple * Alternative size (human readable) of files and directories >> du -ms * .[^.]*| sort -nk1 * Uniformly correct filenames in a directory >> for i in *;do mv "$i" "$(echo $i | sed s/PROBLEM/FIX/g)";done * Show your account and windows policy settings with Results of >> rsop.msc * Set an alarm to wake up >> sleep 5h && rhythmbox path/to/song * Get a shell with a not available account >> su - -s /bin/sh -c "/bin/sh" * Size(k) of directories(Biggest first) >> find . -depth -type d -exec du -s {} \; | sort -k1nr * Efficiently extract lines between markers >> sed -n '/START/,${/STOP/q;p}' * load changes without logging in and out vim >> :source ~/.vimrc * purge installed but unused linux headers, image, or modules >> dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge * Sort lines using the Xth characted as the start of the sort string >> sort -k1.x * List commands with a short summary >> find `echo "${PATH}" | tr ':' ' '` -type f | while read COMMAND; do man -f "${COMMAND##*/}"; done * Another way to calculate sum size of all files matching a pattern >> find . -iname '*.jar' | xargs du -ks | cut -f1 | xargs echo | sed "s/ /+/g" | bc * Poor man's nmap for a class C network from rfc1918 >> ( nw=192.168.0 ; h=1; while [ $h -lt 255 ] ; do ( ping -c2 -i 0.2 -W 0.5 -n $nw.$h & ); h=$[ $h + 1 ] ; done ) | awk '/^64 bytes.*/ { gsub( ":","" ); print $4 }' | sort -u * Random numbers with Ruby >> ruby -e "puts (1..20).map {rand(10 ** 10).to_s.rjust(10,'0')}" * find listening ports by pid >> lsof -nP +p 24073 | grep -i listen | awk '{print $1,$2,$7,$8,$9}' * Lock your KDE4 remotely (via regular KDE lock) >> DISPLAY=:0 /usr/lib/kde4/libexec/krunner_lock --forcelock >/dev/null 2>&1 & * List last opened tabs in firefox browser >> F="$HOME/.moz*/fire*/*/session*.js" ; grep -Go 'entries:\[[^]]*' $F | cut -d[ -f2 | while read A ; do echo $A | sed s/url:/\n/g | tail -1 | cut -d\" -f2; done * Break lines after, for example 78 characters, but don't break >> fold -w 78 -s file-to-wrap * Function that counts recursively number of lines of all files in >> count() { find $@ -type f -exec cat {} + | wc -l; } * Go to the next sibling directory in alphabetical order, version 2 >> cd ../"$(ls -F ..|grep '/'|grep -A1 `basename $PWD`|tail -n 1)" * find largest file in /var >> find /var -mount -ls -xdev | /usr/bin/sort -nr +6 | more * Show established network connections >> lsof -i | grep -i estab * Start screen with name and run command >> screen -dmS "name_me" echo "hi" * Replace Solaris vmstat numbers with human readable format >> vmstat 1 10 | /usr/xpg4/bin/awk -f ph-vmstat.awk * Browse shared folder when you're the only Linux user >> smbclient -U userbob //10.1.1.75/Shared * connect to all screen instances running >> screen -ls | grep pts | gawk '{ split($1, x, "."); print x[1] }' | while read i; do gnome-terminal -e screen\ -dx\ $i; done * Use ImageMagick to get an image's properties >> identify -ping imageName.png * Show apps that use internet connection at the moment. >> lsof -P -i -n | cut -f 1 -d " "| uniq | tail -n +2 * send echo to socket network >> echo "foo" > /dev/tcp/192.168.1.2/25 * Colorized grep in less >> grep --color=always | less -R * Search recursively to find a word or phrase in certain file >> find . -name "*.[ch]" -exec grep -i -H "search pharse" {} \; * Recursively change permissions on files, leave directories alone. >> find ./ -type f -exec chmod 644 {} \; * ensure your ssh tunnel will always be up (add in crontab) >> [[ $(COLUMNS=200 ps faux | awk '/grep/ {next} /ssh -N -R 4444/ {i++} END {print i}') ]] || nohup ssh -N -R 4444:localhost:22 user@relay & * Download from Rapidshare Premium using wget - Part 1 >> wget --save-cookies ~/.cookies/rapidshare --post-data "login=USERNAME&password=PASSWORD" -O - https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi > /dev/null * Recursively lists all files in the current directory, except the >> find . -wholename './.snapshot' -prune -o -print * Monitor Linux/MD RAID Rebuild >> watch -n 5 -d cat /proc/mdstat * memcache affinity: queries local memcached for stats, calculates >> echo -en "stats\r\n" "quit\r\n" | nc localhost 11211 | tr -s [:cntrl:] " "| cut -f42,48 -d" " | sed "s/\([0-9]*\)\s\([0-9]*\)/ \2\/\1*100/" | bc -l * nmap IP block and autogenerate comprehensive Nagios service >> nmap -sS -O -oX /tmp/nmap.xml 10.1.1.0/24 -v -v && perl nmap2nagios.pl -v -r /tmp/10net.xml -o /etc/nagios/10net.cfg * Convert df command to posix; uber GREPable >> df -P * List top 20 IP from which TCP connection is in SYN_RECV state >> netstat -pant 2> /dev/null | grep SYN_ | awk '{print $5;}' | cut -d: -f1 | sort | uniq -c | sort -n | tail -20 * Show what a given user has open using lsof >> lsof -u www-data * Counts number of lines >> find . \( -name '*.h' -o -name '*.cc' \) | xargs grep . | wc -l * show all programs connected or listening on a network port >> alias nsl 'netstat -f inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail +2' * Show number of NIC's, ports per nic and PCI address >> lspci | grep Ether | awk '{ VAR=$1; split(VAR,ARR,"."); count[ARR[1]]++; LINE=$0; split(LINE,LINEARR,":"); LINECOUNT[ARR[1]]=LINEARR[3]; } END { for(i in count) { printf("PCI address: %s\nPorts: %d\nCard Type: %s\n", i, count[i], LINECOUNT[i]) } }' * locate bin, src, and man file for a command >> whereis somecommand * Display all readline binding that use CTRL >> bind -p | grep -F "\C" * Synchronise a file from a remote server >> rsync -av -e ssh user@host:/path/to/file.txt . * Is it a terminal? >> isatty(){ test -t $1; } * create disk copy over the net without temp files >> SOURCE: dd if=/dev/sda bs=16065b | netcat ip-target 1234 TARGET: netcat -l -p 1234 | dd of=/dev/mapper/laptop bs=16065b STATS on target: watch -n60 -- kill -USR1 $(pgrep dd) * Write a listing of all directories and files on the computer to an archive >> sudo ls -RFal / | gzip > all_files_list.txt.gz * Collect a lot of icons from /usr/share/icons (may overwrite some, >> mkdir myicons && find /usr/share/icons/ -type f | xargs cp -t myicons * copy ACL of one file to another using getfacl and setfacl >> getfacl | setfacl -f - * determine if tcp port is open >> nmap -p 80 hostname * determine if tcp port is open >> if (nc -zw2 www.example.com 80); then echo open; fi * Strace all signals processes based on a name ( The processes >> straceprocessname(){ x=( $(pgrep "$@") ); [[ ${x[@]} ]] || return 1; strace -vf ${x[@]/#/-p }; } * last.fm rss parser >> awk '//{gsub(/.*|<\/link>.*/,"");print "
  • "t"" } //{gsub(/.*<title>|<\/title>.*/,"");t=$0 }' file * last.fm rss parser >> egrep "<link>|<title>" recenttracks.rss | awk 'ORS=NR%2?" ":"\n"' | awk -F "" '{print $2, $1}' | sed -e 's/\/\\/\">/' -e 's/\//' -e 's/$/\<\/a\>\<\/li\>/g' -e '1,1d' -e 's/^[ \t]*//' * Mount a partition from dd disk image >> mount -o loop,offset=$((512*x)) /path/to/dd/image /mount/path * Sorted list of established destination connections >> netstat | awk '/EST/{print $5}' | sort * List all symbolic links in current directory >> \ls -1 | xargs -l readlink * remove files and directories with acces time older than a given >> touch -t "YYYYMMDDhhmm.ss" dummy ; find . -anewer dummy * Show sorted list of files with sizes more than 1MB in the current >> du | sort -nr | cut -f2- | xargs du -hs * exit if another instance is running >> if [ `fuser $0|wc -w` -gt "1" ];then exit; fi * convert wav files to ogg >> oggenc *.wav * Find files recursively that were updated in the last hour ignoring >> find . -mmin -60 -not -path "*svn*" -print|more * Clean your broken terminal >> reset * umount all nfs mounts on machine >> mount | grep : | awk {'print $3'} | xargs sudo umount -v * Get your external IP address with a random commandlinefu.com >> IFS=$'\n';cl=($(curl -s http://www.commandlinefu.com/commands/matching/external/ZXh0ZXJuYWw=/so rt-by-votes/plaintext|sed -n '/^# Get your external IP address$/{n;p}'));c=${cl[$(( $RANDOM % ${#cl[@]} ))]};eval $c;echo "Command used: $c" * Postpone a command [zsh] >> * Counts number of lines (in source code excluding comments) >> find . -name '*.java' | xargs -L 1 cpp -fpreprocessed | grep . | wc -l * Empty a file >> truncate -s0 file * grep -v with multiple patterns. >> grep test somefile | grep -v -e error -e critical -e warning * Set creation timestamp of a file to the creation timestamp of >> touch -r "$FILE1" "$FILE2" * Commit command to history file immedeately after execution >> PROMPT_COMMAND="history -a" * Make directories for and mount all iso files in a folder >> for file in *.iso; do mkdir `basename $file | awk -F. '{print $1}'`; sudo mount -t iso9660 -o loop $file `basename $file | awk -F. '{print $1}'`; done * disk space email alert >> [ $(df / | perl -nle '/([0-9]+)%/ && print $1') -gt 90 ] && df -hP | mutt -s "Disk Space Alert -- $(hostname)" admin@example.com * Stop long commands wrapping around and over-writing itself in the >> shopt -s checkwinsize * download all the presentations from UTOSC2009 >> b="http://2009.utosc.com"; for p in $( curl -s $b/presentation/schedule/ | grep /presentation/[0-9]*/ | cut -d"\"" -f2 ); do f=$(curl -s $b$p | grep "/static/slides/" | cut -d"\"" -f4); if [ -n "$f" ]; then echo $b$f; curl -O $b$f; fi done * Functions to display, save and restore $IFS >> ifs () { echo -n "${IFS}"|hexdump -e '"" 10/1 "'\''%_c'\''\t" "\n"' -e '"" 10/1 "0x%02x\t" "\n\n"'|sed "s/''\|\t0x[^0-9]//g; $,/^$/d" * Schedule Nice Background Commands That Won't Die on Logout - >> ( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null && trap 1 ) & ) * Go get those photos from a Picasa album >> wget 'link of a Picasa WebAlbum' -O - |perl -e'while(<>){while(s/"media":{"content":\[{"url":"(.+?\.JPG)//){print "$1\n"}}' |wget -w1 -i - * 32 bits or 64 bits? >> sudo lshw -C cpu|grep width * Show current pathname in title of terminal >> export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007";' * print all except first collumn >> cut -f 2- -d " " * Search for a string inside all files in the current directory >> find . -type f -exec grep -i \; * Convert mp3/wav file to asterisk ulaw for music on hold (moh) >> sox -v 0.125 -V -t au -r 8000 -U -b -c 1 resample -ql * Find and display most recent files using find and perl >> find $HOME -type f -print0 | perl -0 -wn -e '@f=<>; foreach $file (@f){ (@el)=(stat($file)); push @el, $file; push @files,[ @el ];} @o=sort{$a->[9]<=>$b->[9]} @files; for $i (0..$#o){print scalar localtime($o[$i][9]), "\t$o[$i][-1]\n";}'|tail * create SQL-statements from textfile with awk >> $ awk '{printf "select * from table where id = %c%s%c;\n",39,$1,39; }' inputfile.txt * Send a local file via email >> cat filename | mail -s "Email subject" user@example.com * Track X Window events in chosen window >> xev -id `xwininfo | grep 'Window id' | awk '{print $4}'` * Test file system performance >> bonnie++ -n 0 -u 0 -r -s <2 x physical ram> -f -b -d * (Git) Revert files with changed mode, not content >> git diff --numstat | awk '{if ($1 == "0" && $1 == "0") print $3}' | xargs git checkout HEAD * Instant mirror from your laptop + webcam >> mplayer tv:// -vf mirror * Instant mirror from your laptop + webcam >> cvlc v4l2:// :vout-filter=transform :transform-type=vflip :v4l2-width=320 :v4l2-height=240 -f & * Shorten any Url using bit.ly API, using your API Key which >> curl "http://api.bit.ly/shorten?version=2.0.1&longUrl=&login=&apiKey=" * Archive all SVN repositories in platform indepenent form >> budir=/tmp/bu.$$;for name in repMainPath/*/format;do dir=${name%/format};bufil=dumpPath/${dir##*/};svnadmin hotcopy --clean-logs $dir $budir;svnadmin dump --delta $budir>$bufil;rm -rf $budir;done * Archive all SVN repositories in platform indepenent form >> find repMainPath -maxdepth 1 -mindepth 1 -type d | while read dir; do echo processing $dir; sudo svnadmin dump --deltas $dir >dumpPath/`basename $dir`; done * Record audio and video from webcam using ffmpeg >> ffmpeg -f alsa -r 16000 -i hw:2,0 -f video4linux2 -s 800x600 -i /dev/video0 -r 30 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi * search for a file in PATH >> type * preprocess code to be posted in comments on this site >> sed 's/^/$ /' "$script" | xclip * List symbols from a dynamic library (.so file) >> nm --dynamic * send echo to socket network >> echo foo | netcat 192.168.1.2 25 * Display the standard deviation of a column of numbers with awk >> awk '{delta = $1 - avg; avg += delta / NR; mean2 += delta * ($1 - avg); } END { print sqrt(mean2 / NR); }' * Convert a flv video file to avi using mencoder >> mencoder -oac mp3lame -lameopts cbr=128 -ovc xvid -xvidencopts * Compute running average for a column of numbers >> awk '{avg += ($1 - avg) / NR;} END { print avg; }' * Route outbound SMTP connections through a addtional IP address >> iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source IP_TO_ROUTE_THROUGH * Check if x509 certificate file and rsa private key match >> diff <(openssl x509 -noout -modulus -in server.crt ) <( openssl rsa -noout -modulus -in server.key ) * Clone IDE Hard Disk >> sudo dd if=/dev/hda1 of=/dev/hdb2 * Update Ping.fm status >> curl -d api_key="$api_key" -d user_app_key="$user_app_key -d body="$body" -d post_method="default" http://api.ping.fm/v1/user.post * Send a signed and encrypted email from the command line >> echo "SECRET MESSAGE" | gpg -e --armor -s | sendmail USER@DOMAIN.COM * Convert ogg to mp3 >> for x in *.ogg; do ffmpeg -i "$x" "`basename "$x" .ogg`.mp3"; done * fetch all revisions of a specific file in an SVN repository >> svn log fileName | sed -ne "/^r\([0-9][0-9]*\).*/{;s//\1/;s/.*/svn cat fileName@& > fileName.r&/p;}" | sh -s * Ultimate current directory usage command >> du -a --max-depth=1 | sort -n | cut -d/ -f2 | sed '$d' | while read i; do if [ -f $i ]; then du -h "$i"; else echo "$(du -h --max-depth=0 "$i")/"; fi; done * Start a terminal with three open tabs >> gnome-terminal --tab --tab --tab * Edit all files found having a specific string found by grep >> grep -Hrli 'foo' * | xargs vim * floating point operations in shell scripts >> bc -l <<< s(3/5) * Reinstall Grub >> sudo grub-install --recheck /dev/sda1 * Print all fields in a file/output from field N to the end of the >> cut -f N- file.dat * dstat- this command is powerful one to monitor system activity . >> dstat -afv * get diskusage of files modified during the last n days >> sudo find /var/log/ -mtime -7 -type f | xargs du -ch | tail -n1 * Debian: Mark all dependent packages as manualy installed. >> sudo aptitude unmarkauto $(apt-cache depends some-deb-meta-package-name | grep Depends | cut -d: -f2) * An alarm clock using xmms2 and at >> echo "xmms2 play" | at 6:00 * convert strings toupper/tolower with tr >> echo "aBcDeFgH123" | tr a-z A-Z * resume scp-filetransfer with rsync >> rsync --partial --progress --rsh=ssh user@host:remote-file local-file * Unaccent an entire directory tree with files. >> find /dir | awk '{print length, $0}' | sort -nr | sed 's/^[[:digit:]]* //' | while read dirfile; do outfile="$(echo "$(basename "$dirfile")" | unaccent UTF-8)"; mv "$dirfile" "$(dirname "$dirfile")/$outfile"; done * Update twitter via curl as Function >> tweet(){ curl -u "$1" -d status="$2" "http://twitter.com/statuses/update.xml"; } * Make a ready-only filesystem ?writeable? by unionfs >> mount -t unionfs -o dirs=/tmp/unioncache=rw:/mnt/readonly=ro unionfs /mnt/unionfs * Download Youtube Playlist >> y=http://www.youtube.com;for i in $(curl -s $f|grep -o * Show account security settings >> chage -l * floating point operations in shell scripts >> echo "scale=4; 3 / 5" | bc * Search for an active process without catching the search-process >> ps -ef | awk '/process-name/ && !/awk/ {print}' * Read aloud a text file in Ubuntu (and other Unixes with espeak >> espeak -f text.txt * Read aloud a text file in Mac OS X >> say -f file.txt * Schedule a script or command in x num hours, silently run in the >> echo "nohup command rm -rf /phpsessions 1>&2 &>/dev/null 1>&2 &>/dev/null&" | at now + 3 hours 1>&2 &>/dev/null * diff will usually only take one file from STDIN. This is a method >> diff <(cd /path-1; find . -type f -print | egrep -i '\.m4a$|\.mp3$') <(cd /path-2; find . f -print | egrep -i '\.m4a$|\.mp3$') * total text files in current dir >> file -i * | grep -c 'text/plain' * Compress blank lines in VIM >> :g/^\s*$/,/\S/-j|s/.*// * Lists the size of certain file in every 10 seconds >> watch -n 10 'du -sk testfile' * show the real times iso of epochs for a given column >> perl -F' ' -MDate::Format -pale 'substr($_, index($_, $F[1]), length($F[1]), time2str("%C", $F[1]))' file.log * Switch to the previous branch used in git(1) >> git checkout - * Preview of a picture in a terminal >> img test.jpg * Get info on RAM Slots and Max RAM. >> dmidecode 2.9 | grep "Maximum Capacity"; dmidecode -t 17 | grep Size * Sum columns from CSV column $COL >> perl -F',' -ane '$a += $F[3]; END { print $a }' test.csv * Testing php configuration >> php -r phpinfo(); * Count the number of pages of all PDFs in current directory and >> find . -name \*.pdf -exec pdfinfo {} \; | grep Pages | sed -e "s/Pages:\s*//g" | awk '{ sum += $1;} END { print sum; }' * Replace Every occurrence of a word in a file >> perl -p -i -e 's/this/that/g' filename * Update program providing java on Debian >> update-java-alternatives * Get a list of all your VirtualBox virtual machines by name and >> VBoxManage list vms * run a VirtualBox virtual machine without a gui >> VBoxHeadless -s * Generate random password >> randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;} * Get your internal IP address and nothing but your internal IP >> ifconfig $devices | grep "inet addr" | sed 's/.*inet addr:\([0-9\.]*\).*/\1/g' * Delete empty directories with zsh >> rm -d **/*(/^F) * Nicely display permissions in octal format with filename >> stat -c '%A %a %n' * * Base conversions with bc >> echo "obase=2; 27" | bc -l * Remind yourself to leave in 15 minutes >> leave +15 * Start a command on only one CPU core >> taskset -c 0 your_command * Show biggest files/directories, biggest first with 'k,m,g' >> du --max-depth=1 | sort -r -n | awk '{split("k m g",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "v[s]"\t"$2}' * How to establish a remote Gnu screen session that you can >> ssh -t user@some.domain.com /usr/bin/screen -xRR * Instead of writing a multiline if/then/else/fi construct you can >> [[ test_condition ]] && if_true_do_this || otherwise_do_that * Get info about remote host ports and OS detection >> nmap -sS -P0 -sV -O * Convert PDF to JPG >> for file in `ls *.pdf`; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 $file `echo $file | sed 's/\.pdf$/\.jpg/'`; done * Analyse an Apache access log for the most common IP addresses >> tail -10000 access_log | awk '{print $1}' | sort | uniq -c | sort -n | tail * Create an audio test CD of sine waves from 1 to 99 Hz >> (echo CD_DA; for f in {01..99}; do echo "$f Hz">&2; sox -nt cdda -r44100 -c2 $f.cdda synth 30 sine $f; echo TRACK AUDIO; echo FILE \"$f.cdda\" 0; done) > cdrdao.toc && cdrdao write cdrdao.toc && rm ??.cdda cdrdao.toc * Run a file system check on your next boot. >> sudo touch /forcefsck * Monitor bandwidth by pid >> nethogs -p eth0 * List only the directories >> ls -d */ * Show current working directory of a process >> pwdx pid * use vim to get colorful diff output >> svn diff | view - * Go to parent directory of filename edited in last command >> cd !$:h * Find Duplicate Files (based on MD5 hash) >> find -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 33 | cut -c 35- * Quickly (soft-)reboot skipping hardware checks >> /sbin/kexec -l /boot/$KERNEL --append="$KERNELPARAMTERS" --initrd=/boot/$INITRD; sync; /sbin/kexec -e * Relocate a file or directory, but keep it accessible on the old >> mv $1 $2 && ln -s $2/$(basename $1) $(dirname $1) * a short counter >> yes '' | cat -n * List all files opened by a particular command >> lsof -c dhcpd * Brute force discover >> sudo zcat /var/log/auth.log.*.gz | awk '/Failed password/&&!/for invalid user/{a[$9]++}/Failed password for invalid user/{a["*" $11]++}END{for (i in a) printf "%6s\t%s\n", a[i], i|"sort -n"}' * Put readline into vi mode >> set -o vi * Tweet from Terminal to twitter ! >> curl -u yourusername:yourpassword -d status=?Your Message Here? * Quick key/value display within /proc or /sys >> grep -r . /sys/class/net/eth0/statistics * Use Linux coding style in C program >> indent -linux helloworld.c * echo something backwards >> echo linux|rev * Delete all aliases for a network interface on a (Free)BSD system >> ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 delete * Show log message including which files changed for a given commit >> git --no-pager whatchanged -1 --pretty=medium * Grab all .flv files from a webpage to the current working >> wget `lynx -dump http://www.ebow.com/ebowtube.php | grep .flv$ | sed 's/[[:blank:]]\+[[:digit:]]\+\. //g'` * from the console, start a second X server >> xinit -- :1 * cooking a list of numbers for calculation >> echo $( du -sm /var/log/* | cut -f 1 ) | sed 's/ /+/g' * Force hard reset on server >> echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger * ISO info >> isoinfo -d -i filename.iso * Batch File Rename with awk and sed >> ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/sh * rename a file to its md5sum >> md5sum * | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done * Make shell (script) low priority. Use for non interactive tasks >> renice 19 -p $$ * Mount iso to /mnt on Solaris >> mount -F hsfs -o ro `lofiadm -a /sol-10-u7-ga-sparc-dvd.iso` /mnt * Run the last command as root - (Open)Solaris version with RBAC >> pfexec !! * Make ogg file from wav file >> oggenc --tracknum='track' track.cdda.wav -o 'track.ogg' * Buffer in order to avoir mistakes with redirections that empty >> buffer () { tty -s && return; tmp=$(mktemp); cat > "${tmp}"; if [ -n "$1" ] && ( ( [ -f "$1" ] && [ -w "$1" ] ) || ( ! [ -a "$1" ] && [ -w "$(dirname "$1")" ] ) ); then mv -f "${tmp}" "$1"; else echo "Can't write in \"$1\""; rm -f "${tmp}"; fi } * Change to $HOME - zsh, bash4 >> ~ * Run skype using your GTK theme >> skype --disable-cleanlooks -style GTK * Pick a random line from a file >> sort -R file.txt | head -1 * Simple XML tag extract with sed >> sed -n 's/.*\([^<]*\)<\/foo>.*/\1/p' * Display screen window number in prompt >> [[ "$WINDOW" ]] && PS1="\u@\h:\w[$WINDOW]\$ " * Convert numbers to SI notation >> $ awk '{ split(sprintf("%1.3e", $1), b, "e"); p = substr("yzafpnum_kMGTPEZY", (b[2]/3)+9, 1); o = sprintf("%f", b[1] * (10 ^ (b[2]%3))); gsub(/\./, p, o); print substr( gensub(/_[[:digit:]]*/, "", "g", o), 1, 4); }' < test.dat * Matrix Style >> while true ; do IFS="" read i; echo "$i"; sleep .01; done < <(tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]") * restart apache only if config works >> alias restart='apache2ctl configtest && apache2ctl restart' * List apache2 virtualhosts >> /usr/sbin/apache2ctl -S 2>&1 | perl -ne 'm@.*port\s+([0-9]+)\s+\w+\s+(\S+)\s+\((.+):.*@ && do { print "$2:$1\n\t$3\n"; $root = qx{grep DocumentRoot $3}; $root =~ s/^\s+//; print "\t$root\n" };' * OSX command to take badly formatted xml from the clipboard, cleans >> pbpaste | tidy -xml -wrap 0 | pbcopy * this toggles mute on the Master channel of an alsa soundcard >> amixer sset Master toggle * whois surfing my web ? >> watch lsof -i :80 * Single Line Twitter-Tracker >> WRDS="word1 word2 wordN"; while [ 1 ];do curl -s http://twitter.com/statuses/public_timeline.rss |grep '' |cut -d '>' -f 2 |cut -d '<' -f 1 > .twitt.tmp && for word in $WRDS;do grep --color=auto -i $word .twtt.tmp;done;sleep 300;done * Paste OS X clipboard contents to a file on a remote machine >> pbpaste | ssh user@hostname 'cat > ~/my_new_file.txt' * find out which directories in /home have the most files currently >> lsof |awk ' {if ( $0 ~ /home/) print substr($0, index($0,"/home") ) }'|cut -d / -f 1-4|sort|uniq -c|sort -bgr * Hear the mice moving >> while true; do beep -l66 -f`head -c2 /dev/input/mice|hexdump -d|awk 'NR==1{print $2%10000}'`; done * write text or append to a file >> cat <<.>> somefilename * Printing multiple years with Unix cal command >> for y in $(seq 2009 2011); do cal $y; done * ignore hidden directory in bash completion (e.g. .svn) >> bind 'set match-hidden-files off' * Alternative size (human readable) of files and directories >> du -ms * | sort -nk1 * cat large file to clipboard with speed-o-meter >> pv large.xml | xclip * Remove annoying files from recently extracted zip archive >> unzip -lt foo.zip | grep testing | awk '{print $2}' | xargs rm -r * Puts every word from a file into a new line >> tr ' \t' '\n' OUTFILE * find files larger than 1 GB, everywhere >> find / -type f -size +1000000000c * Resume an emerge, and keep all object files that are already >> FEATURES=keepwork emerge --resume * Throttling Bandwidth On A Mac >> sudo ipfw pipe 1 config bw 50KByte/s;sudo ipfw add 1 pipe 1 src-port 80 * Dump the root directory to an external hard drive >> dump -0 -M -B 4000000 -f /media/My\ Passport/Fedora10bckup/root_dump_fedora -z2 / * Using netcat to copy files between servers >> On target: "nc -l 4000 | tar xvf -" On source: "tar -cf - . | nc target_ip 4000" * Dump a configuration file without comments or whitespace... >> grep -v "\ *#\|^$" /etc/path/to.config * c_rehash replacement >> for file in *.pem; do ln -s $file `openssl x509 -hash -noout -in $file`.0; done * Check if filesystem hangs >> ls /mnt/badfs & * Trim linebreaks >> cat myfile.txt | tr -d '\n' * SVN Status log to CSV >> svn log | tr -d '\n' | sed -r 's/-{2,}/\n/g' | sed -r 's/ * Monitor RX/TX packets and any subsquent errors >> watch 'netstat -aniv' * Most simple way to get a list of open ports >> netstat -lnp * Merge several pdf files into a single file >> pdftk $* cat output $merged.pdf * Get lines count of a list of files >> find . -name "*.sql" -print0 | wc -l --files0-from=- * Given application name print its environment variables >> sudo sed 's/\o0/\n/g' "/proc/$(pidof -x firefox)/environ" ;# replace firefox * Deleting Files from svn which are missing >> svn status | grep '!' | sed 's/!/ /' | xargs svn del --force * Record a webcam output into a video file. >> ffmpeg -an -f video4linux -s 320x240 -b 800k -r 15 -i /dev/v4l/video0 -vcodec mpeg4 myvideo.avi * %s across multiple files with Vim >> :set nomore :argdo %s/foo/bar/g | update * import gpg key from the web >> curl -s http://defekt.nl/~jelle/pubkey.asc | gpg --import * Give any files that don't already have it group read permission >> find . -type f ! -perm /g=r -exec chmod g+r {} + * Recursive cat - concatenate files (filtered by extension) across >> find . -type f -name *.ext -exec cat {} > file.txt \; * Lists unambigously names of all xml elements used in files in >> grep -h -o '<[^/!?][^ >]*' * | sort -u | cut -c2- * Search and replace text in all php files with ruby >> ruby -i.bkp -pe "gsub(/search/, 'replace')" *.php * Do quick arithmetic on numbers from STDIN with any formatting >> perl -ne '$sum += $_ for grep { /\d+/ } split /[^\d\-\.]+/; print "$sum\n"' * extract all urls from firefox sessionstore >> sed -e "s/\[{/\n/g" -e "s/}, {/\n/g" sessionstore.js | grep url | awk -F"," '{ print $1 }'| sed -e "s/url:\"\([^\"]*\)\"/\1/g" -e "/^about:blank/d" > session_urls.txt * Display or use a random file from current directory via a small >> $ i=(*);echo ${i[RANDOM%(${#i[@]}+1)]]} * Convert AVI to iPhone MP4 >> ffmpeg -i [source].avi -f mp4 -vcodec mpeg4 -b 250000 -s 480?320 -acodec aac -ar 24000 -ab 64 -ac 2 [destination].mp4 * Monitoring wifi connection by watch command (refresh every 3s), >> watch -d -n 3 "iw dev wlan0 station dump; iwconfig wlan0" * swap stdout and stderr >> $command 3>&1 1>&2 2>&3 * Run a bash script in debug mode, show output and save it on a >> bash -x script.sh 2> log * files and directories in the last 1 hour >> find ./* -ctime -1 | xargs ls -ltr --color * Synchronize both your system clock and hardware clock and >> ntpdate pool.ntp.org && hwclock --systohc && hwclock --adjust * Non Numeric Check >> if [ -z $(echo $var | grep [0-9]) ]; then echo "NON NUMERIC"; fi * Find chronological errors or bad timestamps in a Subversion >> URL=http://svn.example.org/project; diff -u <(TZ=UTC svn -q log -r1:HEAD $URL | grep \|) <(TZ=UTC svn log -q $URL | grep \| | sort -k3 -t \|) * Remove all mail in Postfix mail queue. >> postsuper -d ALL * Scrollable Colorized Long Listing - Hidden Files Sorted Last >> less -Rf <( cat <(ls -l --color=always) <(ls -ld --color=always .*) ) * Awk: Perform a rolling average on a column of data >> awk 'BEGIN{size=5} {mod=NR%size; if(NR<=size){count++}else{sum-=array[mod]};sum+=$1;array[mod]=$1;print sum/count}' file.dat * 'Fix' a typescript file created by the 'script' program to remove >> cat typescript | perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | col -b > typescript-processed * Replace all tabs with spaces in an application >> grep -PL "\t" -r . | grep -v ".svn" | xargs sed -i 's/\t/ /g' * Convert string to uppercase >> echo string | tr '[:lower:]' '[:upper:]' * List of directories sorted by number of files they contain. >> sort -n <( for i in $(find . -maxdepth 1 -mindepth 1 -type d); do echo $(find $i | wc -l) ": $i"; done;) * mplayer -af scaletempo >> mplayer -af scaletempo -speed 1.5 file.avi * extracting audio and video from a movie >> ffmpeg -i source_movie.flv -vcodec mpeg2video target_video.m2v -acodec copy target_audio.mp3 * Extract track 9 from a CD >> mplayer -fs cdda://9 -ao pcm:file=track9.wav * Word-based diff on reformatted text files >> diff -uw <(fmt -1 {file1, file2}) * Getting Screen's Copy Buffer Into X's Copy Buffer (on Linux) >> Type "c-a b" in gnu screen after updating your .screenrc (See Description below). * using scanner device from command line >> scanimage -d mustek_usb --resolution 100 --mode Color > image.pnm * extract audio from flv to mp3 >> ffmpeg -i input.flv -f mp3 -vn -acodec copy ouput.mp3 * Lists the supported memory types and how much your board can >> sudo dmidecode -t 5,16 * Update a tarball >> tar -tf file.tar | tar -T - -uf file.tar * get a process list by listen port >> netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1 * find string into one pdf file >> find / -iname '*.pdf' -print -exec pdftotext '{}' - \; | grep --color -i "unix" * Find which jars contain a class >> find . -name "*.jar" | while read file; do echo "Processing ${file}"; jar -tvf $file | grep "Foo.class"; done * user 'tr' to convert mixed case in a file to lower case >> tr "[:upper:]" "[:lower:]" < file * Backup your OpenWRT config (only the config, not the whole >> curl -d 'username=root&password=your-good-password' "http://router/cgi-bin/luci/admin/system/backup?backup=kthxbye" > `date +%Y%d%m`_config_backup.tgz * Email HTML content >> mailx bar@foo.com -s "HTML Hello" -a "Content-Type: text/html" < body.htm * convert all files in a dir of a certain type to flv >> for f in *.m4a; do ffmpeg -i "$f" "${f%.m4a}.flv"; done * Validate date, also a date within a leap year >> date -d2009-05-18 > /dev/null 2>&1 ; echo $? * remove audio trac from a video file >> mencoder -ovc copy -nosound ./movie.mov -o ./movie_mute.mov * copies 20 most recently downloaded mp3 files (such as from Miro) >> find . -name \*.mp3 -printf "%C+ %h/%f\n" | sort -r | head -n20 | awk '{print "\""$2"\""}' | xargs -I {} cp {} ~/tmp * Make a directory named with the current date >> mkdir `date --iso` * Duplicating service runlevel configurations from one server to >> chkconfig --list | fgrep :on | sed -e 's/\(^.*\)*0:off/\1:/g' -e 's/\(.\):on/\1/g' -e 's/.:off//g' | tr -d [:blank:] | awk -F: '{print$2,$1}' | ssh host 'cat > foo' * Validate and pretty-print JSON expressions. >> echo '{"json":"obj"}' | python -m simplejson.tool * Find and delete oldest file of specific types in directory tree >> find / \( -name "*.log" -o -name "*.mylogs" \) -exec ls -lrt {} \; | sort -k6,8 | head -n1 | cut -d" " -f8- | tr -d '\n' | xargs -0 rm * Remove all backup files in my home directory >> find ~user/ -name "*~" -exec rm {} \; * Get an IP address out of fail2ban jail >> iptables -D fail2ban-SSH -s -j DROP * Safe Delete >> shred -n33 -zx file; rm file * Search for files older than 30 days in a directory and list only >> find /var/www/html/ -type f -mtime +30 -exec basename {} \; * Working random fact generator >> lynx -dump randomfunfacts.com | grep -A 3 U | sed 1D * Mac OS X: Change Color of the ls Command >> export LSCOLORS=gxfxcxdxbxegedabagacad * split source code to page with numbers >> pr -l 40 bitree.c > printcode; split -40 printcode -d page_ * Pick a random image from a directory (and subdirectories) every >> while true; do xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s "$(find -type f -iregex '.*\.\(bmp\|gif\|jpg\|png\)$' | sort -R | head -1)"; sleep 30m; done * Change wallpaper for xfce4 >= 4.6.0 >> xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s * Prevent non-root users from logging in >> touch /etc/nologin * Display time of accounts connection on a system >> ac -p * Change Gnome wallpaper >> gconftool-2 -t string -s /desktop/gnome/background/picture_filename * Clone current directory into /destination verbosely >> find . | cpio -pumdv /destination * Mount a disk image (dmg) file in Mac OSX >> hdiutil attach somefile.dmg * Connect to all running screen instances >> for i in `screen -ls | perl -ne'if(/^\s+\d+\.([^\s]+)/){print $1, " "}'`; do gnome-terminal -e "screen -x $i"; done * compare two Microsoft Word documents >> meld <(antiword microsoft_word_a.doc) <(antiword microsoft_word_b.doc) * Mount important virtual system directories under chroot'ed >> for i in sys dev proc; do sudo mount --bind /$i /mnt/xxx/$i; done * Set Time Zone in Ubuntu >> sudo dpkg-reconfigure tzdata * convert plain .avi movies to .mpeg >> ffmpeg -i movie.avi -y -f vcd -vcodec mpeg1video -map 0.0:0.0 -b 1150 -s 352x240 -r 29.97 -g 12 -qmin 3 -qmax 13 -acodec mp2 -ab 224 -ar 44100 -ac 2 -map 0.1:0.1 movie.mpg * Summarise the size of all files matching a simple regex >> find /path/to/my/files/ -type f -name "*txt*" | xargs du -k | awk 'BEGIN{x=0}{x=x+$1}END{print x}' * Root shell >> sudo -i * Remove all hidden files in a directory >> rm -r .??* * Prints any IP out of a file >> perl -ne 'while (/([0-9]+\.){3}[0-9]+/g) {print "$&\n"};' file.txt * Dump HTTP header using wget >> wget --server-response --spider http://www.example.com/ * backup your entire hosted website using cPanel backup interface >> wget --http-user=YourUsername --http-password=YourPassword http://YourWebsiteUrl:2082/getbackup/backup-YourWebsiteUrl-`date +"%-m-%d-%Y"`.tar.gz * Copy input sent to a command to stderr >> rev <<< 'lorem ipsum' | tee /dev/stderr | rev * create a simple version of ls with extended output >> alias l='ls -CFlash' * Make info pages much less painful >> pinfo date * print battery , thermal , and cooling info >> acpi -tc * View a man page on a nice interface >> yelp man:foo * Emptying a text file in one shot >> :1,$d * find an unused unprivileged TCP port >> netstat -atn | awk ' /tcp/ {printf("%s\n",substr($4,index($4,":")+1,length($4) )) }' | sed -e "s/://g" | sort -rnu | awk '{array [$1] = $1} END {i=32768; again=1; while (again == 1) {if (array[i] == i) {i=i+1} else {print i; again=0}}}' * Change files case, without modify directories, recursively >> find ./ -name '*.JPG' -type f -execdir rename -f 'y/A-Z/a-z/' {} \+ * force unsupported i386 commands to work on amd64 >> setarch i386 [command [args]] * Combine all .mpeg files in current directory into one big one. >> cat *.mpg > all.mpg * Output system statistics every 5 seconds with timestamp >> while [ 1 ]; do echo -n "`date +%F_%T`" ; vmstat 1 2 | tail -1 ; sleep 4; done * Tail a log file with long lines truncated >> tail -f logfile.log | cut -b 1-80 * Spell check the text in clipboard (paste the corrected clipboard >> xclip -o > /tmp/spell.tmp; aspell check /tmp/spell.tmp ; cat /tmp/spell.tmp | xclip * Display information sent by browser >> nc -l 8000 * Determine the version of a specific package with RPM >> rpm -q --qf "%{VERSION}\n" redhat-release * add a gpg key to aptitute package manager in a ubuntu system >> wget -q http://xyz.gpg -O- | sudo apt-key add - * Quick calculator at the terminal >> echo "$math_expr" | bc -l * Remove embedded fonts from a pdf. >> gs -sDEVICE=pswrite -sOutputFile=- -q -dNOPAUSE With-Fonts.pdf -c quit | ps2pdf - > No-Fonts.pdf * Quick plotting of a function >> seq 0 0.1 20 | awk '{print $1, cos(0.5*$1)*sin(5*$1)}' | graph -T X * Add thousand separator with sed, in a file or within pipe >> sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' filename * Downsample mp3s to 128K >> for f in *.mp3 ; do lame --mp3input -b 128 "$f" ./resamp/"$f" ; done * start vim in diff mode >> vimdiff file{1,2} * Time Synchronisation with NTP >> ntpdate ntp.ubuntu.com pool.ntp.org * Lists architecture of installed RPMs >> rpm -qa --queryformat "%{NAME} %{ARCH}\n" * Display usb power mode on all devices >> for i in `find /sys/devices/*/*/usb* -name level` ; do echo -n "$i: " ; cat $i ; done * Display a list of RPMs installed on a particular date >> rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | grep "Thu 05 Mar" * create a backup for all directories from current dir >> find -maxdepth 1 -type d -print0 | xargs -0 -I {} tar -cvzf {}.tar.gz {} * Display 6 largest installed RPMs sorted by size (descending) >> rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 # six largest RPMs * Convert embedded spaces in filenames to "_" (underscore) >> ls -1 | grep " " | awk '{printf("mv \"%s\" ",$0); gsub(/ /,"_",$0); printf("%s\n",$0)}' | sh # rename filenames: spaces to "_" * Display kernel profile of currently executing functions in >> lockstat -I -i 977 -s 30 -h sleep 1 > /tmp/profile.out * List all the files that have been deleted while they were still >> lsof | egrep "^COMMAND|deleted" * Search through all installed packages names (on RPM systems) >> rpm -qa \*code\* * Binary injection >> echo -n $HEXBYTES | xxd -r -p | dd of=$FILE seek=$((0x$OFFSET)) bs=1 conv=notrunc * Forwards connections to your port 2000 to the port 22 of a remote >> ssh -NL 2000:remotehost:22 remotehost * Change the extension of a filename by using rename to convert >> rename .JPG .jpg *.JPG * Repeatedly send a string to stdout-- useful for going through >> yes "text" | annoying_installer_program # "text" defaults to the letter y * Remove annoying OS X DS_Store folders >> find . -name .DS_Store -exec rm {} \; * Copy the text from the 3rd line to the 9th line into a new file >> :3,9w new_file * cat stdout of multiple commands >> cat <( command1 arg arg ) <( command2 arg ) ... * Find commets in jpg files. >> find / -name "*.jpg" -print -exec rdjpgcom '{}' ';' * View a file with less, starting at the end of the file >> less +G * vi case insensitive search >> :set ic * "hidden" remote shell >> ssh -T user@host /bin/bash -i * Find all files with root SUID or SGID executables >> sudo find / -type f \( -perm /4000 -a -user root \) -ls -o \( -perm /2000 -a -group root \) -ls * Delete empty directories recursively >> find -depth -type d -empty -exec rmdir -v {} \; * Remove several files with ease >> rm file{1..10} * Prints new content of files >> tail -f file1 (file2 .. fileN) * Extract icons from windows exe/dll >> wrestool -x --output . -t14 /path/to/your-file.exe * Know which version dpkg/apt considers more recent >> dpkg --compare-versions 1.0-2ubuntu5 lt 1.1-1~raphink3 && echo y || echo n * make a list of movies(.m3u). >> find $HOME -type f -print | perl -wnlaF'/' -e 'BEGIN{ print "#EXTM3U"; } /.+\.wmv$|.+\.mpg$|.+\.vob$/i and print "#EXTINF:$F[-1]\nfile://$&";' > movies.m3u * Replace "space" char with "dot" char in current directory file >> ls -1 | while read a; do mv "$a" `echo $a | sed -e 's/\ /\./g'`; done * sort ugly text >> sort -bdf * Recursive Search and Replace >> perl -pi -e's///g' `grep -Rl //*` * remove all snapshots from all virtual machines in vmware esx >> time vmware-cmd -l | while read x; do printf "$x"; vmware-cmd "$x" removesnapshots; done * Print the last modified file >> ls -t1 | head -n1 * Symlink all files from a base directory to a target directory >> for f in $(ls -d /base/*); do ln -s $f /target; done && ls -al /target * Create passwords and store safely with gpg >> tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 10 | gpg -e -r medha@nerdish.de > password.gpg * Type strait into a file from the terminal. >> cat /dev/tty > FILE * convert a pdf to jpeg >> sips -s format jpeg Bild.pdf --out Bild.jpg * Cleanly manage tempfiles in scripts >> TMPROOT=/tmp; TMPDIR=$(mktemp -d $TMPROOT/somedir.XXXXXX); TMPFILE=$(mktemp $TMPROOT/somefile.XXXXXX); trap "rm -rf $TMPDIR $TMPFILE; exit" INT TERM EXIT; some treatment using $TMPDIR and $TMPFILE; exit 0 * 1:1 copy of a volume >> find / -xdev -print | cpio -pdmuv /mnt/mydisk * sort through source to find most common authors >> find . -type f -name "*.java" -print0 | xargs -0 -n 1 svn blame | sed -n 's/^[^a-z]*\([a-z]*\).*$/\1/p' | sort | uniq -c | sort -n * Drop or block attackers IP with null routes >> sudo route add xxx.xxx.xxx.xxx gw 127.0.0.1 lo * split a string (3) >> OLD_IFS="$IFS"; IFS=: ARRAY=($PATH); echo ${ARRAY[2]}; IFS="$OLD_IFS" * get your terminal back after it's been clobbered >> reset * Set file access control lists >> setfacl -m u:john:r-- myfile * Compress logs older than 7 days >> find /path/to/files -type f -mtime +7 | grep -v \.gz | xargs gzip * restore the contents of a deleted file for which a descriptor is >> N="filepath" ; P=/proc/$(lsof +L1 | grep "$N" | awk '{print $2}')/fd ; ls -l $P | sed -rn "/$N/s/.*([0-9]+) ->.*/\1/p" | xargs -I_ cat $P/_ > "$N" * Quickest way to sort/display # of occurences >> "some line input" | sort | uniq -c | sort -nr * Kill any lingering ssh processes >> for i in `ps aux | grep ssh | grep -v grep | awk {'print $2'}` ; do kill $i; done * Copy a file from a remote server to your local box using >> rsync -Pz user@remotehost:/path/file.dat . * Show current iptables rules, with line numbers >> iptables -nL -v --line-numbers * Find out the last times your system was rebooted (for the duration >> last reboot * Follow a new friend on twitter >> curl -u USERNAME:PASSWORD -d "" http://twitter.com/friendships/create/NAMEOFNEWFRIEND.xml?follow=true * checking space availabe on all /proc/mounts points (using Nagios >> check_disk -w 15% -c 10% $(for x in $(cat /proc/mounts |awk '{print $2}')\; do echo -n " -p $x "\; done) * doing some floating point math >> echo "8000000/(20*6*86400)" | bc -l * List all active access_logs for currently running Apache or >> lsof -p $(netstat -ltpn|awk '$4 ~ /:80$/ {print substr($7,1,index($7,"/")-1)}')| awk '$9 ~ /access.log$/ {print $9| "sort -u"}' * Empty the linux buffer cache >> sync && echo 3 > /proc/sys/vm/drop_caches * Delete .svn directories and content recursively >> `find . -iname ".svn" -type d | sed -e "s/^/rm -rfv /g"` * Clean up after a poorly-formed tar file >> tar ztf tar-lacking-subdirectory.tar.gz | xargs rm * Simple complete system backup excluding files or directories >> tar zcpf backup.tgz --exclude=/proc --exclude=backup.tgz / * Comma insertions >> perl -pe '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse' * Double your disk read performance in a single command >> blockdev --setra 1024 /dev/sdb * Check ps output to see if file is running, if not start it >> ps -C thisdaemon || { thisdaemon & } * Generate a Random Password >> dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev * Find files with root setuids settings >> sudo find / -user root -perm -4000 -print * Make a high definition VNC >> vncserver -nohttpd -name hidef-server -depth 24 -geometry 1440x900 * generate random number >> echo $RANDOM * Finding the number of cpu's >> grep -c -e '^cpu[0-9]\+' /proc/stat * find text in a file >> find /directory/to/search/ -type f -print0 | xargs -0 grep "findtext" >> find /directory/to/search/ -type f | xargs grep "findtext" ##(the difference?) * Recursively move folders/files and preserve their permissions and >> cd /source/directory; tar cf - . | tar xf - -C /destination/directory * Output files without comments or empty lines >> grep -v "^\($\|#\)" * faster version of ls * >> echo * * remove leading blank lines >> sed '/./,$!d' * Search inside a folder of jar/zip files >> find . -name "*.jar" | xargs -tn1 jar tvf | grep --color "SearchTerm" * Netstat Connection Check >> netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | tail * Display command lines visible on commandlinefu.com homepage >> ruby -ropen-uri -e 'require "hpricot";(Hpricot(open("http://commandlinefu.com"))/".command").each{| c| puts c.to_plain_text}' * Delete line number 10 from file >> sed -i '10d' * Gzip files older than 10 days matching * >> find . -type f -name "*" -mtime +10 -print -exec gzip {} \; * Determine an image's dimensions >> identify -format "%wx%h" /path/to/image.jpg * Mac OS-X-> copy and paste things to and from the clipboard from >> command | pbcopy && pbpaste * Email a file to yourself >> uuencode $file $file | /usr/bin/mailx -s "$file" ${USER} * List all execs in $PATH, usefull for grepping the resulting list >> find ${PATH//:/ } -executable -type f -printf "%f\n" * purge all packages marked with 'rc' >> sudo dpkg --purge `dpkg -l | awk '/^r/{print $2}'` * Print trending topics on Twitter >> wget http://search.twitter.com/trends.json -O - --quiet | ruby -rubygems -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))' * Show sorted list of files with sizes more than 1MB in the current >> du -hs * | grep '^[0-9,]*[MG]' | sort -rn * Concatenates lines using sed >> sed -e :a -e '/$/N;s/\n/ /;ta' * Display your ${PATH}, one directory per line >> echo $PATH | tr : \\n * Copy text to the clipboard >> cat SomeFile.txt | pbcopy * HTTP Get of a web page via proxy server with login credentials >> curl -U username[:password] -x proxyserverIP:proxyserverPort webpageURI * shut of the screen. >> xset dpms force standby * List the files any process is using >> lsof +p xxxx * Find files that have been modified on your system in the past 60 >> sudo find / -mmin 60 -type f * Intercept, monitor and manipulate a TCP connection. >> mkfifo /tmp/fifo; cat /tmp/fifo | nc -l -p 1234 | tee -a to.log | nc machine port | tee -a from.log > /tmp/fifo * Use tee + process substitution to split STDOUT to multiple >> some_command | tee >(command1) >(command2) >(command3) ... | command4 * Copy your ssh public key to a server from a machine that doesn't >> cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys" * Colorful man >> apt-get install most && update-alternatives --set pager /usr/bin/most * View the newest xkcd comic. >> xkcd(){ local f=$(curl -s http://xkcd.com/);display $(echo "$f"|grep -Po '(?<=")http://imgs.xkcd.com/comics/[^"]+(png|jpg)');echo "$f"|awk '/> rename -v 's/.*[s,S](\d{2}).*[e,E](\d{2}).*\.avi/SHOWNAME\ S$1E$2.avi/' poorly.named.file.s01e01.avi * Execute a command with a timeout >> timeout 10 sleep 11 * Search for a string inside all files in the current directory >> grep -RnisI * * redirect stdout and stderr each to separate files and print both >> (some_command 2>&1 1>&3 | tee /path/to/errorlog ) 3>&1 1>&2 | tee /path/to/stdoutlog * Find files that were modified by a given command >> touch /tmp/file ; $EXECUTECOMMAND ; find /path -newer /tmp/file * Have an ssh session open forever >> autossh -M50000 -t server.example.com 'screen -raAd mysession' * throttle bandwidth with cstream >> tar -cj /backup | cstream -t 777k | ssh host 'tar -xj -C /backup' * replace spaces in filenames with underscores >> rename 'y/ /_/' * * Save an HTML page, and covert it to a .pdf file >> wget $URL | htmldoc --webpage -f "$URL".pdf - ; xpdf "$URL".pdf & * Compare two directory trees. >> diff <(cd dir1 && find | sort) <(cd dir2 && find | sort) * Resume scp of a big file >> rsync --partial --progress --rsh=ssh $file_source $user@$host:$destination_file * Install a Firefox add-on/theme to all users >> sudo firefox -install-global-extension /path/to/add-on * iso-8859-1 to utf-8 safe recursive rename >> detox -r -s utf_8 /path/to/old/win/files/dir * recursive search and replace old with new string, inside files >> $ grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/' * Terminate a frozen SSH-session >> RETURN~. * Get Cisco network information >> tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000' * Copy stdin to your X11 buffer >> ssh user@host cat /path/to/some/file | xclip * Check if running in an X session >> if [ ! -z "${DISPLAY}" ]; then someXcmd ; fi * delete unversioned files in a checkout from svn >> svn st | grep "^\?" | awk "{print \$2}" | xargs rm -rf * Rsync between two servers >> rsync -zav --progress original_files_directory/ root@host(IP):/path/to/destination/ * replace XX by YY in the the current directory and cd to it. ( in >> cd XX YY * Show a line when a "column" matchs >> awk '{ FS = OFS = "#" } { if ($9==1234) print }' filename*.log > bigfile.log * Split and join with split and cat. >> split -b 1k file ; cat x* > file * run command on a group of nodes in parallel >> echo -n m{1..5}.cluster.net | xargs -d' ' -n1 -P5 -I{} ssh {} 'uptime' * Sort IP addresses >> sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 /file/of/ip/addresses * Check executable shared library usage >> ldd * fix broken permissions >> find /path -type d -perm 777 -exec chmod 755 {} \; * Use color grep by default >> alias grep 'gnu grep -i --color=auto' * finding cr-lf files aka dos files with ^M characters >> find $(pwd) -type f -exec grep -l "$(echo "\r")" {} \; * Make a thumbnail image of first page of a PDF. >> convert -resize 200 -sharpen 40 some_file.pdf[0] some_file.jpg * Import/clone a Subversion repo to a git repo >> git svn --authors-file=some-authors-file clone svn://address/of/svn/repo new-git-dir * Gives you what's between first string and second string included. >> sed "s/^ABC/+ABC/" > curl -s http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' * Getting GnuPG Public Keys From KeyServer >> gpg --keyserver pgp.surfnet.nl --recv-key 19886493 * Binary search/replace >> xxd < orig | sed 's/A/B/' | sed 's/HEXA/HEXB/' | xxd -r > new * "I Feel Lucky" for Google Images >> echo -n "search> ";read QUERY && wget -O - `wget -O - -U "Mozilla/5.0" "http://images.google.com/images?q=${QUERY}" 2>/dev/null |sed -e 's/","http/\n","http/g' |awk -F \" '{print $3}' |grep -i http: |head -1` > "$QUERY" * modify a file in place with perl >> perl -pi -e 's/THIS/THAT/g' fileglob* * Create a DOS floppy image >> dd if=/dev/zero bs=1024 count=1440 > floppy.img && mkdosfs floppy.img * Test for Weak SSL Ciphers >> openssl s_client -connect [host]:[sslport] -cipher LOW * Translate your terminal into Swedish Chef >> perl -e '$b="bork"; while(){$l=`$_ 2>&1`; $l=~s/[A-Za-z]+/$b/g; * Change every instance of OLD to NEW in file FILE >> sed -i 's/OLD/NEW/g' FILE * Getting started with tcpdump >> tcpdump -nli eth0; tcpdump -nli eth0 src or dst w.x.y.z; tcpdump -nli eth0 port 80; tcpdump -nli eth0 proto udp * Dump root ext3 fs over ssh >> dump 0f - / | bzip -c9 | ssh user@host "cat > /home/user/root.dump.bz2" * Resets a terminal that has been messed up by binary input >> reset * Display total Kb/Mb/Gb of a folder and each file >> du -hc * * easily convert one unit to another >> units "2048 bytes" "kibibytes" * show the date every rpm was installed >> rpm -qa --last * To find the count of each open file on a system (that supports >> sudo lsof | awk '{printf("%s %s %s\n", $1, $3, $NF)}' | grep -v "(" | sort -k 4 | gawk '$NF==prv{ct++;next} {printf("%d %s\n",ct,$0);ct=1;prv=$NF}' | uniq | sort -nr * rgrep: recursive grep without .svn >> alias rgrep="find . \( ! -name .svn -o -prune \) -type f -print0 | xargs -0 grep" * get a directory from one machine to another using tar and ssh >> ssh somemachine "cd some dir; tar zcpf - somedirname" |tar zxpf - * A nice command for summarising repeated information >> alias counts=sort | uniq -c | sort -nr * Command to keep an SSH connection open >> watch -n 30 uptime * Run a command on a remote machine >> ssh user@host "ps aux | grep httpd | wc -l" * Display a list of all PHP classes that are called statically >> find . -name "*\.php" | xargs grep -o --color "\w\+::\w\+" | cut -d":" -f2 | sort | uniq -c * 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 * Every Nth line position # (AWK) >> awk 'NR%3==1' file * 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 * 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 * Rename .JPG to .jpg recursively >> find /path/to/images -name '*.JPG' -exec bash -c 'mv "$1" "${1/%.JPG/.jpg}"' -- {} \; * Prints line numbers >> grep -n "^" * Print a row of 50 hyphens >> python -c 'print "-" * 50' * Resize a Terminal Window >> printf "\e[8;70;180;t" * Pretty man pages under X >> function manpdf() {man -t $1 | ps2pdf - - | epdfview -} * Pretty man pages under X >> vman(){ T=/tmp/$$.pdf;man -t $1 |ps2pdf - >$T; xpdf $T; rm -f $T; } * Print a row of 50 hyphens >> perl -le'print"-"x50' * Do a search-and-replace in a file after making a backup >> sed -i.bak 's/old/new/g' file * view certificate details >> openssl x509 -in filename.crt -noout -text * analyze traffic remotely over ssh w/ wireshark >> mkfifo /tmp/fifo; ssh-keygen; ssh-copyid root@remotehostaddress; sudo ssh root@remotehost "tshark -i eth1 -f 'not tcp port 22' -w -" > /tmp/fifo &; sudo wireshark -k -i /tmp/fifo; * Solaris get PID socket >> pfiles -F /proc/* 2>/dev/null | awk '/^[0-9]+/{proc=$1};/[s]ockname: AF_INET/{print proc $0}' * Batch convert PNG to JPEG >> for i in *.png; do convert "$i" "${i%.png}.jpg" && rm "$i" && echo "$i is converted."; done * pipe output to notify-send >> echo 'Desktop SPAM!!!' | while read SPAM_OUT; do notify-send "$SPAM_OUT"; done * Display _something_ when an X app fails >> xlaunch(){ T=/tmp/$$;sh -c "$@" >$T.1 2>$T.2;S=$?;[ $S -ne 0 ]&&{ echo -e "'$@' failed with error $S\nSTDERR:\n$(cat $T.2)\nSTDOUT:\n$(cat $T.1)\n"|xmessage -file -;};rm -f $T.1 $T.2;} * mount an iso >> mount -o loop -t iso9660 my.iso /mnt/something * monitor network traffic and throughput in real time >> iptraf * find out how much space are occuipied by files smaller than 1024K >> find dir -size -1024k -type f -print0 | du --files0-from - -bc * reload config >> source .bashrc * Create aliases for common vim minibuffer/cmd typos >> command! -nargs=1 Vs vs * find out how much space is occupied by files smaller than 1024K >> find dir -size -1024k -type f | xargs -d $'\n' -n1 ls -l | cut -d ' ' -f 5 | sed -e '2,$s/$/+/' -e '$ap' | dc * List folders containing only PNGs >> find . -name '*png' -printf '%h\0' | xargs -0 ls -l --hide=*.png | grep -ZB1 ' 0$' * Find the location of the currently loaded php.ini file >> php -i | grep php.ini * Test file system type before further commands execution >> DIR=. ; FSTYPE=$(df -TP ${DIR} | grep -v Type | awk '{ print $2 }') ; echo "${FSTYPE}" * See entire packet payload using tcpdump. >> tcpdump -nnvvXSs 1514 -i * Sniffing network to generate a pcap file in CLI mode on a remote >> tcpdump -v -i -s 0 -w /tmp/sniff.pcap port # On the * Read just the IP address of a device >> /sbin/ip -f inet addr | sed -rn 's/.*inet ([^ ]+).*(eth[[:digit:]]*(:[[:digit:]]+)?)/\2 \1/p' | column -t * Random colours at random locations >> p(){ printf "\033[%d;%dH\033[4%dm \033[m" $((RANDOM%LINES+1)) $((RANDOM%COLUMNS+1)) $((RANDOM%8)); }; clear;while :;do p; sleep .001;done * output stats from a running dd command to see its progress >> watch -n60 --kill -USR1 $(pgrep dd) * Freshening up RKhunter >> rkhunter --versioncheck --update --propupd --check * Expedient hard disk temprature and load cycle stats >> watch -d 'sudo smartctl -a /dev/sda | grep Load_Cycle_Count ; sudo smartctl -a /dev/sda | grep Temp' * Show permissions of current directory and all directories upwards >> dir=$(pwd); while [ ! -z "$dir" ]; do ls -ld "$dir"; dir=${dir%/*}; done; ls -ld / * Display IP adress of the given interface in a most portable and >> 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,$/;' * convert video format to youtube flv format >> ffmpeg -i Your_video_file -s 320x240 FILE.flv * 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 * validate xml in a shell script. >> xmlproc_parse.python-xml &>/dev/null || exit 1 * validate xml in a shell script using xmllint >> xmllint --noout some.xml 2>&1 >/dev/null || exit 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 * Collect a lot of icons from /usr/share/icons (may overwrite some, >> mkdir myicons; find /usr/share/icons/ -type f -exec cp {} ./myicons/ \; * list all opened ports on host >> time { i=0; while [ $(( i < 65535 )) -eq 1 ] ; do nc -zw2 localhost $((++i)) && echo port $i opened ; done; } * Get your public ip >> curl -s http://sputnick-area.net/ip * 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)}' * View a random xkcd comic >> wget -q http://dynamic.xkcd.com/comic/random/ -O-| sed -n '/> ipcs * recursive search and replace old with new string, inside files >> $rpl -R oldstring newstring folder * recursive search and replace old with new string, inside files >> find . -type f -exec sed -i s/oldstring/newstring/g {} + * Find and copy scattered mp3 files into one directory >> find . -type f -iname '*.mp3' -exec cp {} ~/mp3/ \; * 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 * 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 {} + * Quickly batch resize images >> mogrify -geometry 800x600 *.jpg * Update twitter via curl (and also set the "from" bit) >> curl -u twitter-username -d status="Hello World, Twitter!" -d source="cURL" http://twitter.com/statuses/update.xml * Monitoring sessions that arrive at your server >> watch -n 1 -d "finger" * Download streaming video in mms >> mimms mms://Your_url.wmv * Ruby - nslookup against a list of IP`s or FQDN`s >> while read n; do host $n; done < list * Fill up disk space (for testing) >> tail $0 >> $0 * Show local/public IP adresses with or without interface argument >> MyIps(){ 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)"; } * Audible warning when a downloading is finished >> while [ "$(ls $filePart)" != "" ]; do sleep 5; done; mpg123 /home/.../warning.mp3 * mount a cdrom >> mount -t iso9660 /dev/cdrom /media/cdrom * Return IP Address >> perl -e '$_=`ifconfig eth0`;/\d+.\d+.\d+.\d+ /; print $&,"\n";' * Return IP Address >> ifconfig|while read i;do [[ $i =~ inet.*B ]]&&r=${i%%B*}&&echo ${r/*[tr]:/};done * Capture data in ASCII. 1500 bytes >> tcpdump -ieth0 -n tcp port 80 -A -s1500 * Find file containing namespace in a directory of jar files. >> for f in *.jar; do if jar -tf $f | grep -q javax.servlet; then echo $f; fi; done * View the newest xkcd comic. >> curl -s 'xkcd.com' | awk -F\" '/^\n\n\n %s\n %s\n %s\n\n\n", $6, $4, $2)}' * find all writable (by user) files in a directory tree (use 4 for >> find . -type f -perm +200 -print * show how many regex you use in your vim today >> cat ~/.viminfo | sed -n '/^:[0-9]\+,\([0-9]\+\|\$\)s/p' * find read write traffic on disk since startup >> iostat -m -d /dev/sda1 * urldecoding >> perl -pe 's/%([0-9a-f]{2})/sprintf("%s", pack("H2",$1))/eig' * Pull up remote desktop for other than gnome/kde eg fluxbox >> rdp() { ssh $1 sh -c 'PATH=$PATH:/usr/local/bin; x11vnc -q -rfbauth ~/.vnc/passwd -display :0' & sleep 4; vncviewer $1:0 & } * Get your bash scripts to handle options (-h, --help etc) and spit >> process-getopt * urldecoding >> printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g') * In (any) vi, add a keystroke to format the current paragraph. >> map ^A !}fmt * Convert decimal numbers to binary >> function decToBin { echo "ibase=10; obase=2; $1" | bc; } * Find all dotfiles and dirs >> find -mindepth 1 -maxdepth 1 -name .\* * watch the previous command >> watch -n1 -d !! * List all symbolic links in current directory >> ls -lah | grep ^l * Find all dot files and directories >> ls -d .* * Debian Runlevel configuration tool >> rcconf * Checks apache's access_log file, strips the search queries and >> awk '/q=/{print $11}' /var/log/httpd/access_log.4 | awk -F 'q=' '{print $2}' | sed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1 * Show sorted list of files with sizes more than 1MB in the current >> ls -l | awk '$5 > 1000000' | sort -k5n * rotate the compiz cube via command line >> wmctrl -o 1280,0 * 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 * check the status of 'dd' in progress >> while killall -USR1 dd; do sleep 5; done * Both view and pipe the file without saving to disk >> cat /path/to/some/file.txt | tee /dev/pts/0 | wc -l * Get ethX mac addresses >> ip link | grep 'link/ether' | awk '{print $2}' * Grab an interface's IP from ifconfig without screen clutter >> ifconfig eth1 | grep inet\ addr | awk '{print $2}' | cut -d: -f2 | sed s/^/eth1:\ /g * Display top 5 processes consuming CPU >> ps -eo pcpu,user,pid,cmd | sort -r | head -5 * Open-iscsi target discovery >> iscsiadm -m discovery -t sendtargets -p 192.168.20.51 * Creates Solaris alternate boot environment on another zpool. >> lucreate -n be1 [-c be0] -p zpool1 * one-liner mpc track changer using dmenu >> mpc play $(sed -n "s@^[ >]\([0-9]\+\)) $(mpc playlist|cut -d' ' -f3-|dmenu -i -p 'song name'||echo void)@\1@p" < <(mpc playlist)) * A function to find the newest file of a set. >> newest () { candidate=''; for i in "$@"; do [[ -f $i ]] || continue; [[ * Erase empty files >> find . -type f -size 0 -delete * Monitor a file's size >> watch -n 60 du /var/log/messages * Remove CR LF from a text file >> tr -d '\r\n' < input_file.txt > output_file.txt * Check a server is up. If it isn't mail me. >> curl -fs brandx.jp.sme 2&>1 > /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk * On Screen micro display for battery and CPU temperature. >> acpi -t | osd_cat -p bottom * set wallpaper on windowmaker in one line >> wmsetbg -s -u path_to_wallpaper * List your largest installed packages (on Debian/Ubuntu) >> sed -ne '/^Package: \(.*\)/{s//\1/;h;};/^Installed-Size: \(.*\)/{s//\1/;G;s/\n/ /;p;}' /var/lib/dpkg/status | sort -rn * Get decimal ascii code from character >> echo -n a | od -d | sed -n "s/^.* //gp" * get the ascii number with bash builtin printf >> printf "%d\n" "'A" "'B" * Function to output an ASCII character given its decimal >> chr () { echo -en "\0$(printf %x $1)"} * Function to output an ASCII character given its decimal >> chr() { printf \\$(printf %o $1); } * Less a grep result, going directly to the first match in the >> argv=("$@"); rest=${argv[@]:1}; less -JMN +"/$1" `grep -l $1 $rest` * Execute a command before display the bash prompt >> PROMPT_COMMAND=command * gzip all files in a directory separately >> gzip * * gzip all files in a directory separately >> ls | xargs -n1 gzip * MoscowML with editable input-line and history >> rlwrap mosml * 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 * Get absolut path to your bash-script >> PATH=$(cd ${0%/*}; pwd) * 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}' * remove the last of all html files in a directory >> for f in *.html; do sed '$d' -i "$f"; done * Makefile argument passing >> make [target] VAR=foobar * List only the directories >> tree -dL 1 * convert filenames in current directory to lowercase >> find my_root_dir -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \; * Directory Tree >> tree -d * Directory Tree >> find . -type d -print | sed -e 's;[^/]*/;..........;g'|awk '{print $0"-("NR-1")"}' * VIM: when Ctrl-D and Ctrl-U only scroll one line, reset to default >> :set scroll=0 * Check if variable is a number >> if [ "$testnum" -eq "$testnum" 2>/dev/null ]; then echo It is numeric; fi * print crontab entries for all the users that actually have a file >> for USER in `cut -d ":" -f1 /dev/null 2>&1; if [ ! ${?} -ne 0 ]; then echo -en "--- crontab for ${USER} ---\n$(crontab -u ${USER} -l)\n"; fi; done * Print a list of the 30 last modified mp3s sorted by last first >> find ~/Music -daystart -mtime -60 -name *mp3 -printf "%T@\t%p\n" | sort -f -r | head -n 30 | cut -f 2 * Print text string vertically, one character per line. >> echo "vertical text" | fold -1 * Generate SHA1 hash for each file in a list >> find . -type f -exec sha1sum {} >> SHA1SUMS \; * Benchmark report generator >> hardinfo -am benchmark.so -f html > report.html * Changing the terminal title to the last shell command >> if [ "$SHELL" = '/bin/zsh' ]; then case $TERM in rxvt|*term|linux) preexec () { print -Pn "\e]0;$1\a" };; esac; fi * Force an fsck on reboot >> shutdown -rF now * Grep auth log and print ip of attackers >> egrep 'Failed password for invalid' /var/log/secure | awk '{print $13}' | uniq * Generate SHA1 hash for each file in a list >> ls [FILENAME] | xargs openssl sha1 * Notify Gnome user of files modified today >> OLDIFS=$IFS; IFS=$(echo -en "\n\b"); for f in `find -daystart -mtime 0 -type f -printf "%f\n"`; do notify-send -t 0 "$f downloaded" ; done; IFS=$OLDIFS * Download a TiVo Show >> curl -s -c /tmp/cookie -k -u tivo:$MAK --digest "$(curl -s -c * Create a single-use TCP proxy with copy to stdout >> gate() { mkfifo /tmp/sock1 /tmp/sock2 &> /dev/null && nc -p $1 -l < /tmp/sock1 | tee /tmp/sock2 & PID=$! && nc $2 $3 < /tmp/sock2 | tee /tmp/sock1; kill -KILL $PID; rm -f /tmp/sock1 /tmp/sock2 ; } * 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;/> $ cdrdao read-cd --read-raw --datafile FILE_NAME.bin --device /dev/cdrom --driver generic-mmc-raw FILE_NAME.toc * Remove blank lines from a file using grep and save output to new >> grep -v "^$" filename > newfilename * Search for a string inside all files in the current directory >> grep -r * .[!.]* * Search for a string inside all files in the current directory >> ack * Search for a string inside all files in the current directory >> find . -type f -print0 | xargs -0 grep -i * calulate established tcp connection of local machine >> netstat -an | grep -Ec '^tcp.+ESTABLISHED$' * 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 * 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/' * Delete all but the latest 5 files, ignoring directories >> ls -lt|grep ^-|awk 'NR>5 { print $8 }'|xargs -r rm * Delete all but the latest 5 files >> ls -t | tail +6 | xargs rm * 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/$/\'\)/ * Remove all files but one starting with a letter(s) >> rm -rf [a-bd-zA-Z0-9]* c[b-zA-Z0-9]* * Setting reserved blocks percentage to 1% >> sudo tune2fs -m 1 /dev/sda4 * find only current directory (universal) >> find . \( ! -name . -prune \) \( -type f -o -type l \) * Ultimate current directory usage command >> find . -maxdepth 1 ! -name '.' -execdir du -0 -s {} + | sort -znr | gawk 'BEGIN{ORS=RS="\0";} {sub($1 "\t", ""); print $0;}' | xargs -0 du -hs * Output files without comments or empty lines >> function catv { egrep -v "^$|^#" ${*} ; } * List hostnames of all IPs >> for IP in $(/sbin/ifconfig | fgrep addr: | sed 's/.*addr:\([[0-9.]*\) .*/\1/') ; do host $IP | awk '{print $5}'; done * A DESTRUCTIVE command to render a drive unbootable >> dd if=/dev/zero of=/dev/fd0 bs=512 count=1 * Ripping VCD in Linux >> cdrdao read-cd --device ATA:1,1,0 --driver generic-mmc-raw --read-raw image.toc * create date-stamped tar archive of files in a directory tree (with subfolders) >> tar czf /path/archive_of_foo.`date -I`.tgz /path/foo * Creae a tar file for backup info >> tar --create --file /path/$HOSTNAME-my_name_file-$(date -I).tar.gz --atime-preserve -p -P --same-owner -z /path/ * Force logout after 24 hours idle >> fuser -k `who -u | awk '$6 == "old" { print "/dev/"$2'}` * Find all PowerPC applications on OS X >> system_profiler SPApplicationsDataType | perl -nl -e '@al=<>; $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;}}' * List out classes in of all htmls in directory >> find . -name '*.html' -exec 'sed' 's/.*class="\([^"]*\?\)".*/\1/ip;d' '{}' ';' |sort -su * Makes a Zenity select list based on entries in your >> grep -oE "ssid=\".*\"" /etc/wpa_supplicant.conf | cut -c6- | sed s/\"//g | zenity --list --title="Choose Access Point" --column="SSID" * Ultimate current directory usage command >> find . -maxdepth 1 -type d|xargs du -a --max-depth=0|sort -rn|cut -d/ -f2|sed '1d'|while read i;do echo "$(du -h --max-depth=0 "$i")/";done;find . -maxdepth 1 -type f|xargs du -a|sort -rn|cut -d/ -f2|sed '$d'|while read i;do du -h "$i";done * bash function to check for something every 5 seconds >> function checkfor () { while :; do $*; sleep 5; done; } * Copy a file structure without files >> find * -type d -exec mkdir /where/you/wantem/\{\} \; * Efficiently print a line deep in a huge log file >> sed '1000000!d;q' < massive-log-file.log * Harder, Faster, Stronger SSH clients >> ssh -4 -C -c blowfish-cbc * Duplicate several drives concurrently >> dd if=/dev/sda | tee >(dd of=/dev/sdb) | dd of=/dev/sdc * backup all your commandlinefu.com favourites to a plaintext file >> clfavs(){ URL="http://www.commandlinefu.com";wget -O - --save-cookies c --post-data "username=$1&password=$2&submit=Let+me+in" $URL/users/signin;for i in `seq 0 25 $3`;do wget -O - --load-cookies c $URL/commands/favourites/plaintext/$i >>$4;done;rm -f c;} * Cleanup firefox's database. >> find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \; * Terminal - Show directories in the PATH, one per line with sed and >> tr : '\n' <<<$PATH * get all pdf and zips from a website using wget >> wget --reject html,htm --accept pdf,zip -rl1 url * Release memory used by the Linux kernel on caches >> free && sync && echo 3 > /proc/sys/vm/drop_caches && free * find and delete empty dirs, start in current working dir >> find . -empty -type d -exec rmdir {} + * Triple monitoring in screen >> tmpfile=$(mktemp) && echo -e 'startup_message off\nscreen -t top htop\nsplit\nfocus\nscreen -t nethogs nethogs wlan0\nsplit\nfocus\nscreen -t iotop iotop' > $tmpfile && sudo screen -c $tmpfile * Show me a histogram of the busiest minutes in a log file: >> cat /var/log/secure.log | awk '{print substr($0,0,12)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}' * Print a great grey scale demo ! >> yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done * DELETE all those duplicate files but one based on md5 hash >> find . -type f -print0|xargs -0 md5sum|sort|perl -ne 'chomp;$ph=$h;($h,$f)=split(/\s+/,$_,2);print "$f"."\x00" if ($h eq $ph)'|xargs -0 rm -v -- * coloured tail >> tail -f FILE | perl -pe 's/KEYWORD/\e[1;31;43m$&\e[0m/g' * Display current bandwidth statistics >> ifstat -nt * restoring some data from a corrupted text file >> ( cat badfile.log ; tac badfile.log | tac ) > goodfile.log * How to run X without any graphics hardware >> startx -- `which Xvfb` :1 -screen 0 800x600x24 && DISPLAY=:1 x11vnc * Run a bash script in debug mode, show output and save it on a file >> bash -x test.sh 2>&1 | tee out.test * Add user to group on OS X 10.5 >> sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username * to see about php configure >> $php_dir/bin/php -i | grep configure * Terminal - Show directories in the PATH, one per line with sed and >> sed 's/:/\n/g' <<<$PATH * Download entire commandlinefu archive to single file >> for x in `seq 0 25 $(curl "http://www.commandlinefu.com/commands/browse"|grep "Terminal - All commands" |perl -pe 's/.+(\d+),(\d+).+/$1$2/'|head -n1)`; do curl "http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$ x" ; done > a.txt * 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 * Remotely sniff traffic and pass to snort >> sniff_host: tcpdump -nn -i eth1 -w - | nc 192.168.0.2 666 * Verbosely delete files matching specific name pattern, older than >> rm -vf /backup/directory/**/FILENAME_*(m+15) * power off system in X minutes >> shutdown -h 60 * Search for matches each at start of line with egrep >> egrep '^(January|April|May)' text.log * Copy via tar pipe while preserving file permissions (run this >> tar -C /oldirectory -cvpf - . | tar -C /newdirector -xvf - * watch iptables counters >> watch --interval 0 'iptables -nvL | grep -v "0 0"' * Remove empty directories >> rmdir **/*(/^F) * Ping sweep without NMAP >> for i in `seq 1 255`; do ping -c 1 10.10.10.$i | tr \\n ' ' | awk '/1 received/ {print $2}'; done * follow the content of all files in a directory >> find dir/ -type f | xargs tail -fqn0 * View Processeses like a fu, fu >> pstree -p * Not a kismet replacement... >> watch -n .5 "iwlist wlan0 scan" * clear the cache from memory >> sync; echo 3 > /proc/sys/vm/drop_caches * Show changed files, ignoring permission, date and whitespace >> git diff --numstat -w --no-abbrev | perl -a -ne '$F[0] != 0 && $F[1] !=0 && print $F[2] . "\n";' * Scrape commands from commandline fu's 1st page >> curl -s http://www.commandlinefu.com/commands/browse|egrep '("Fin.*and"|
    .*
    )'|sed 's/<[^<]*>//g'|ruby -rubygems -pe 'require "cgi"; $_=sprintf("\n\n%-100s\n\t#%-20s",CGI.unescapeHTML($_).chomp.strip, gets.lstrip) if $.%2' * The command used by applications in OS X to determine whether a >> plutil -lint plist-file * Resolve a list of domain names to IP addresses >> awk < file.name '{ system("resolveip -s " $1) }' * 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 out when your billion-second anniversary is (was). >> date -j -v +1000000000S -f %m%d%Y mmddYYYY * Find out when your billion-second anniversary is (was). (on OS X) >> date -j -v +1000000000S -f %m%d%Y mmddyyyy * Find out when your billion-second anniversary is (was). >> date -d12/31/1970+1000000000sec * Shrink more than one blank lines to one in VIM. >> :%v/./,/./-j * Have netcat listening on your ports and use telnet to test >> SERVER: nc -l p 666 CLIENT: telnet -l -p 666 * return external ip >> host -t a dartsclink.com | sed 's/.*has address //' * Searches $PATH for files using grep >> IFS=:; find $PATH | grep pattern * Find >> xwininfo * open in textmate sidebar files (recursively) with names matching >> mate - `find * -type f -regex 'REGEX_A' | grep -v -E 'REGEX_B'` * View a colorful logfile using less >> < /var/log/syslog ccze -A | less -R * Generate random IP addresses >> nmap -n -iR 0 -sL | cut -d" " -f 2 * Get the size of all the directories in current directory >> du -hd 1 * Convert every eps in a directory to pdf >> for f in *.eps;do ps2pdf -dEPSCrop $f `basename $f .eps`.pdf; done * Remove newlines from output >> awk /./ filename * Remove newlines from output >> cat filename | grep . * A fun thing to do with ram is actually open it up and take a peek. >> strings /dev/mem|less * complete extraction of a debian-package >> dpkg-deb -x $debfile $extractdir; dpkg-deb -e $debfile $extractdir/DEBIAN; * Get the size of all the directories in current directory >> sudo du -sh $(ls -d */) 2> /dev/null * Get the ip registered to a domain on OpenWRT >> nslookup commandlinefu.com|sed 's/[^0-9. ]//g'|tail -n 1|awk -F " " '{print $2}' * Test http request every second, fancy display. >> watch -n 1 nc localhost 80 '<> typeset -f * tar copy >> tar cf - dir_to_cp/ | (cd path_to_put/ && tar xvf -) * Nicely display permissions in octal format with filename >> stat -f '%Sp %p %N' * | rev | sed -E 's/^([^[:space:]]+)[[:space:]]([[:digit:]]{4})[^[:space:]]*[[:space:]]( [^[:space:]]+)/\1 \2 \3/' | rev * Shows how many percents of all avaliable packages are installed in >> echo $((`eix --only-names -I | wc -l` * 100 / `eix --only-names | wc -l`))% * Installing debian on fedora (chrooted) >> debootstrap --arch i386 lenny /opt/debian ftp://debian.das.ufsc.br/pub/debian/ * Updating to Fedora 11 >> yum clean all ; rpm -Uvh http://download.fedora.redhat.com/pub/fedora/linux/releases/11/Fedora/i 386/os/Packages/fedora-release-11-1.noarch.rpm ; yum -y upgrade ; reboot * Which files/dirs waste my disk space >> du -aB1m|awk '$1 >= 100' * Query ip pools based on successive netnames via whois >> net=DTAG-DIAL ; for (( i=1; i<30; i++ )); do whois -h whois.ripe.net $net$i | grep '^inetnum:' | sed "s;^.*:;$net$i;" ; done * Get Futurama quotations from slashdot.org servers >> curl -sI http://slashdot.org/ | sed -nr 's/X-(Bender|Fry)(.*)/\1\2/p' * Get all IPs via ifconfig >> ifconfig | awk '/ddr:[0-9]/ {sub(/addr:/, ""); print $2}' * Make a statistic about the lines of code >> find . -type f -name "*.c" -exec cat {} \; | wc -l * txt2html >> recode ..HTML < file.txt > file.html * List all installed Debian packages >> dpkg --get-selections | grep -v deinstall | cut -f 1 * Tail the most recently modified file >> ls -t1 | head -n1 | xargs tail -f * 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 * Combine two mp3's or more into 1 long mp3 >> cat 1.mp3 2.mp3 > combined.mp3 * Get the SUM of visual blocked digits in vim >> vmap y:$omap:'a,$!awk '{sum+=$0}END{print "SUM:" sum}'dd'>p * Recursive replace of directory and file names in the current >> for i in `find -name '*oldname*'`; do "mv $i ${i/oldname/newname/}"; done * Recursive replace of directory and file names in the current >> find . *oldname* | grep oldname | perl -p -e 's/^(.*)(oldname)(.*$)/mv $1$2$3 $1newname$3/' | sh * Get all IPs via ifconfig >> ifconfig | awk -F':| +' '/ddr:/{print $4}' * Output a SSL certificate start or end date >> date --date="$(openssl x509 -in xxxxxx.crt -noout -startdate | cut -d= -f 2)" --iso-8601 * Efficient count files in directory (no recursion) >> perl -e 'if(opendir D,"."){@a=readdir D;print $#a-1,"\n"}' * get events from google calendar for a given dates range >> wget -q -O - 'URL/full?orderby=starttime&singleevents=true&start-min=2009-06-01&star t-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];}'; * get delicious bookmarks on your shell (text version :-)) >> curl -u 'username' https://api.del.icio.us/v1/posts/all | sed 's/^.*href=//g;s/>.*$//g;s/"//g' | awk '{print $1}' | grep 'http' * search string in _all_ revisions >> for i in `git log --all --oneline --format=%h`; do git grep SOME_STRING $i; done * Read just the IP address of a device >> /sbin/ifconfig | awk -F'[ :]+' '/inet addr/{print $4}' * Second pass dvd rip... The set of commands was too long, so I had >> mencoder dvd://<title> -dvd-device <device> -aid 128 -info srcform='ripped by mencoder' -oac mp3lame -lameopts abr:br=128 -ovc xvid -xvidencopts pass=2:bitrate=-700000 -ofps 30000/1001 -o '<outputfile.avi>' * First pass dvd rip... The set of commands was too long, so I had >> mencoder dvd://<title> -dvd-device <device> -aid 128 -info srcform='ripped by mencoder' -oac mp3lame -lameopts abr:br=128 -ovc xvid -xvidencopts pass=1:chroma_opt:vhq=4:bvhq=1:quant_type=mpeg -vf pp=de,crop=0:0:0:0, -ofps 30000/1001 -o '/dev/null' * Add temporary entry to authorized_keys >> Keys=$HOME/.ssh/authorized_keys;Back=$Keys.tmp.bak;Time=${1:-15};cp $Keys $Back;cat /dev/stdin >>$Keys;echo mv $Back $Keys|at now+${Time}minutes; * A command's package details >> dpkg -S `which nm` | cut -d':' -f1 | (read PACKAGE; echo "[${PACKAGE}]"; dpkg -s "${PACKAGE}"; dpkg -L "${PACKAGE}") | less * Test your total disk IO capacity, regardless of caching, to find >> time (dd if=/dev/zero of=blah.out bs=256M count=1 ; sync ) * git remove files which have been deleted >> git ls-files -z --deleted | xargs -0 git rm * Find files with lines that do not match a pattern >> fmiss() { grep -RL "$*" * } * Copy 3 files from 3 different servers and adds server name tag to >> for i in `seq 1 3`; do scp finku@server$i:file.txt server$i-file.txt; done * extract all tgz in current dir >> ls *tgz | xargs -n1 tar xzf * Compare a remote file with a local file >> vimdiff scp://[user@]host1/<file> scp://[user@]host2/<file> * Search commandlinefu from the command line >> (curl -d q=grep http://www.commandlinefu.com/search/autocomplete) | egrep 'autocomplete|votes|destination' | perl -pi -e 's/a style="display:none" class="destination" href="//g;s/<[^>]*>//g;s/">$/\n\n/g;s/^ +//g;s/^\//http:\/\/commandlinefu.com\//g' * Check if you need to run LaTeX to update the TOC >> cp texfile.toc texfile.toc.bak; latex texfile.tex; cmp -s texfile.toc texfile.toc.bak; if [ $? -ne 0 ]; then latex texfile.tex; fi * clone a hard drive to a remote directory via ssh tunnel, and >> # dd if=/dev/sda | gzip -c | ssh user@ip 'dd of=/mnt/backups/sda.dd' * Solaris - check ports/sockets which process has opened >> /usr/proc/bin/pfiles $PID | egrep "sockname|port" * Access partitions inside a LVM volume >> kpartx -a /dev/mapper/space-foobar * Log the current memory statistics frequently to syslog >> while true; do { $(which logger) -p local4.notice `free -m | grep Mem`; sleep 60; } done & * Encode a file to MPEG4 format >> mencoder video.avi lavc -lavcopts vcodec=mpeg4:vbitrate=800 newvideo.avi * Record camera's output to a avi file >> mencoder -tv device=/dev/video1 tv:// -ovc copy -o video.avi * list all crontabs for users >> cut -d: -f1 /etc/passwd | grep -vE "#" | xargs -i{} crontab -u {} -l * Adding formatting to an xml document for easier reading >> xmllint --format <filename> > <output file> * Find Files That Exceed a Specified Size Limit >> find directory -size +nnn * get newest jpg picture in a folder >> cp `ls -x1tr *.jpg | tail -n 1` newest.jpg * Use QuickLook from the command line without verbose output >> qlook() { qlmanage -p "$@" >& /dev/null & } * Skip to next selection in playlist >> killall -2 mpg321 * Show all usernames and passwords for Plesk email addresses >> mysql -uadmin -p` cat /etc/psa/.psa.shadow` -Dpsa -e"select mail_name,name,password from mail left join domains on mail.dom_id = domains.id inner join accounts where mail.account_id = accounts.id;" * The Chronic: run a command every N seconds in the background >> chronic () { t=$1; shift; while true; do $@; sleep $t; done & } * eDirectory LDAP Search for Statistics >> ldapsearch -h ldapserver.willeke.com -p389 -b "" -s base -D cn=admin,ou=administration,dc=willeke,dc=com -w secretpwd "(objectclass=*)" chainings removeEntryOps referralsReturned listOps modifyRDNOps repUpdatesIn repUpdatesOut strongAuthBinds addEntryOps * Pipe the result of a command to IRC (channel or query) >> function my_irc { tmp=`mktemp`; cat > $tmp; { echo -e "USER $username x x :$ircname\nNICK $nick\nJOIN $target"; while read line; do echo -e "PRIVMSG $target :$line"; done < $tmp; } | nc $server > /dev/null ; rm $tmp; } * Phrack 66 is out, but the .tar.gz is not there yet on >> mkdir phrack66; (cd phrack66; for n in {1..17} ; do echo "http://www.phrack.org/issues.html?issue=66&id=$n&mode=txt" ; done | xargs wget) * Recursively create a TAGS file for an entire source tree. TAGS >> ctags -R * ncdu - ncurses disk usage >> ncdu directory_name * Change permissions of every directory in current directory >> find . -type d -exec chmod 755 {} \; * rsync over ssh via non-default ssh port >> rsync -e 'ssh -p PORT' user@host:SRC DEST * Configuring proxy client on terminal >> export http_proxy=<user>:<pass>@<server>:<port> ftp_proxy=<user>:<pass>@<server>:<port> * Check wireless link quality with dialog box >> while [ i != 0 ]; do sleep 1 | dialog --clear --gauge "Quality: " 0 0 $(cat /proc/net/wireless | grep $WIRELESSINTERFACE | awk '{print $3}' | tr -d "."); done * change ownership en masse of files owned by a specific user, >> find . -uid 0 -print0 | xargs -0 chown foo:foo * Clear history >> history -c * Change timestamp on a file >> touch -amct [[CC]YY]MMDDhhmm[.ss] FILE * Show the last 20 sessions logged on the machine >> last -n 20 * Show LAN IP with ip(8) >> ip route show dev eth0 | awk '{print $7}' * Create a video that is supported by youtube >> ffmpeg -i mymovie.mpg -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv mytarget.flv * Copy the sound content of a video to an mp3 file >> ffmpeg -i source.flv -vn acodec copy destination.mp3 * Alias for quick command-line volume set (works also remotely via >> alias setvol='aumix -v' * Unlock your KDE4 session remotely (for boxes locked by KDE lock >> killall -s 9 krunner_lock * Using scapy to get the IP of the iface used to contact local gw >> python -c "import scapy.all; print [x[4] for x in scapy.all.conf.route.routes if x[2] != '0.0.0.0'][0]" * Backup with SSH in a archive >> ssh -i $PRIVATEKEY $HOST -C 'cd $SOURCE; tar -cz --numeric-owner .' | tee $DESTINATION/backup.tgz | tar -tz * Listen to a file >> while true; do cat /usr/src/linux/kernel/signal.c > /dev/dsp; done * Updating the status on identi.ca using curl. >> curl -u USER:PASS -d status="NEW STATUS" http://identi.ca/api/statuses/update.xml * Copy data using gtar >> gtar cpf - . | (cd /dest/directory; gtar xpf -) * burn initial session on a growable DVD using growisofs >> growisofs -Z /dev/dvd -J -r "directory name to burn on DVD" * dump 1KB of data from ram to file >> dd if=/dev/mem of=file.dump bs=1024 skip=0 count=1 * Change framebuffer font >> setfont cybercafe * Report information about executable launched on system >> aureport -x * Print summary of referers with X amount of occurances >> awk -F\" '{print $4}' *.log | grep -v "eviljaymz\|\-" | sort | uniq -c | awk -F\ '{ if($1>500) print $1,$2;}' | sort -n * cpu and memory usage top 10 under Linux >> ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f%\t%.2f%\n",num[user], user, cpu[user], mem[user]) }' * Convert from octal format to umask >> perm=( 6 4 4 ) ; for elem in ${perm[@]}; do echo `expr 7 - $elem` ; * mail with attachment >> tar cvzf - data1 data2 | uuencode data.tar.gz | mail -s 'data' you@host.fr * find/edit your forgotten buddy pounces for pidgin >> vim ~/.purple/pounces.xml * Display formatted routes >> routel * 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 * Burn CD/DVD from an iso, eject disc when finished. >> cdrecord dev=0,0,0 -v -eject yourimage.iso * Add a line from 1 file after every line of another (shuffle files >> sed '/^/R addfile' targetfile > savefile * Find the modified time (mtime) for a file >> date -r foo * Jump to a song in your XMMS2 playlist, based on song title/artist >> function jumpTo { xmms2 jump `xmms2 list | grep -i '$1' | head -n 1 | tail -n 1 | sed -re 's@.+\[(.+)/.+\] (.+)@\1@'`; } * Use mtr to create a text file report >> mtr --report --report-cycles 10 www.google.com > google_net_report.txt * Get the current svn branch/tag (Good for PS1/PROMPT_COMMAND cases) >> svn info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$' * Change the default editor for modifying the sudoers list. >> sudo update-alternatives --config editor * Simple word scramble >> shuf -n1 /usr/share/dict/words | tee >(sed -e 's/./&\n/g' | shuf | tr -d '\n' | line) > /tmp/out * Show all mergeinfo for a svn subtree >> find . \( -type d -name .svn -prune \) -o -print | while read file ; do mergeinfo=`svn propget svn:mergeinfo $file` ; [ "$mergeinfo" != "" ] && echo -e "$file\n $mergeinfo\n" ; done * SVN Command line branch merge >> /usr/local/bin/svn merge -r {rev_num}:HEAD https://{host}/{project}/branches/{branch_name} . * Propagate X session cookies on a different user and login as that >> read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $u * Display only hosts up in network >> nmap -sP your network/submask | awk "/^Host/"'{ print $2 }' * Recursive Line Count >> find ./ -not -type d | xargs wc -l | cut -c 1-8 | awk '{total += $1} END {print total}' * sorting file contents into individual files with awk >> awk '{print > $3".txt"}' FILENAME * Copy files and directories from a remote machine to the local >> ssh user@host "(cd /path/to/remote/top/dir ; tar cvf - ./*)" | tar xvf - * Then end of the UNIX epoch >> date -d @$(echo $((2 ** 31 - 1))) * View an info page on a nice interface >> yelp info:foo * Flush DNS cache in MacOS 10.5 >> dscacheutil -flushcache * list services running (as root) >> service --status-all | grep running * Watch your freebox flux, through a other internet connection (for >> vlc -vvv http://mafreebox.freebox.fr/freeboxtv/playlist.m3u --sout * convert a .mp4 to a .avi >> ffmpeg -i "/path/to/file.mp4" "/path/to/file.avi" * convert a .wmv to a .avi >> mencoder "/path/to/file.wmv" -ofps 23.976 -ovc lavc -oac copy -o "/path/to/file.avi" * Watch the National Debt clock >> watch -n 10 "wget -q http://www.brillig.com/debt_clock -O - | grep debtiv.gif | sed -e 's/.*ALT=\"//' -e 's/\".*//' -e 's/ //g'" * Use find to get around Argument list too long problem >> find . -name 'junkfiles-*' -print0 | xargs -0 rm * Easily run a program in the background without losing output >> function fork () { tf=$(tempfile -d /tmp -p $1.);echo -n "$tf "; $@ &>$tf& } * 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 } * which procs have $PATH_REGEX open? >> find /proc -regex '/proc/[0-9]+/smaps' -exec grep -l "$PATH_REGEX" {} \; | cut -d'/' -f2 * add static arp entry to default gateway, arp poison protection >> arp -s $(route -n | awk '/^0.0.0.0/ {print $2}') \ $(arp -n | grep `route -n | awk '/^0.0.0.0/ {print $2}'`| awk '{print $3}') * burn a isofile to cd or dvd >> cdrecord -v dev=/dev/cdrom yourimage.iso * keep an eye on system load changes >> watch -n 7 -d 'uptime | sed s/.*users,//' * Mount an smb share on linux >> mount -t smbfs //$server/share /local/mount -o rw,username=$USER * Display the standard deviation of a column of numbers with awk >> awk '{sum+=$1; sumsq+=$1*$1} END {print sqrt(sumsq/NR - (sum/NR)**2)}' file.dat * Averaging columns of numbers >> awk '{sum1+=$1; sum2+=$2} END {print sum1/NR, sum2/NR}' file.dat * Convert a mp3 file to m4a >> mplayer -vo null -vc null -ao pcm:fast:file=file.wav file.mp3; faac -b 128 -c 44100 -w file.wav * Creates a proxy based on tsocks. >> alias tproxy='ssh -ND 8118 user@server&; export LD_PRELOAD="/usr/lib/libtsocks.so"' * Delete empty, 24-hours-old directories recursively, without >> find . -regex "[^.]*" -depth -empty -type d -mtime +1 -exec rmdir -v {} \; * Download and extract a *tar.gz file with curl. >> curl http://domain.com/file.tar.gz | tar zx * Display duplicated lines in a file >> cat file.txt | sort | uniq -dc * Configure a serial line device so you can evaluate it with a >> stty -F "/dev/ttyUSB0" 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke time 5 min 1 line 0 * Quicker move to parent directory >> alias ..='cd ..' * Count number of bytes that are different between 2 binary files >> cmp -l file1.bin file2.bin | wc -l * Update your journal >> vi ~/journal/$(date +%F) * Doing some floating point calculations with rounding (e.g. at the >> echo '123/7' |bc -l |xargs printf "%.3f\n" * Send test prints to networked printer. >> echo "test" | lp -d $PRINTER * rsync + find >> rsync -avz -e ssh --files-from=<(find -mtime +30 -mtime -60) source dest * Use -t when using find and cp >> find . -name "*.pdf" -print0 | xargs -0 cp -t downloads/ * Go to directory or creat it and go to >> [[ -d dir ]] || mkdir dir ; cd dir * 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; } * print lib path of perl >> perl -e 'print map { $_ . "\n" } @INC;' * Create a random password encrypted with md5 with custom lenght >> echo -n $mypass | md5sum | awk {'print $1'} * Make ls output better visible on dark terminals in bash >> unalias ls * nohup that doesn't generate nohup.out >> nohup <command> 2> /dev/null > /dev/null & * Ping a range of addresses >> nmap -sP -T Insane 192.168.1.1-254 * unrar all part1 files in a directory >> ls -1 *.part1.rar | xargs -d '\n' -L 1 unrar e * Rotate a video file by 90 degrees CW >> mencoder -vf rotate=1 -ovc lavc -oac copy "$1" -o "$1"-rot.avi * Connect to remote machine with other enconding charset >> LC_ALL=fr_FR luit ssh root@remote_machine_ip * Search for files in rpm repositorys. (Mandriva linux) >> urpmf lib/blah * Stream the latest offering from your fave netcasts/podcasts >> vlc --one-instance --playlist-enqueue -q $(while read netcast; do wget -q $netcast -O - |grep enclosure | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p'|head -n1; done <netcast.txt) * NICs, IPs, and Mac >> ifconfig -a | nawk 'BEGIN {FS=" "}{RS="\n"}{ if($1~ /:/) {printf "%s ", $1}}{ if($1=="inet") {print " -- ",system("arp "$2)}}'|egrep -v "^[0-9]$" * Help shell find freshly installed applications (re: PATH) >> rehash * replace a character/word/string in a file using vim >> :%s/old/new/g * Recurse through directories easily >> find . -type f | while read file; do cp $file ${file}.bak; done * Read almost everything (Changelog.gz, .tgz, .deb, .png, .pdf, >> less -r <some file> * pinky - user info >> pinky -l <username> * Know your distro >> lsb-release -a * easy C shell math calculators >> alias calc 'echo "scale=4;\!*"|bc -l'; alias xcalc 'echo "\!*"|bc -l' * Label EXT2/EXT3 File System >> e2label /dev/vg0/lv0 MyFiles * Mac OS X - List all of my machine's IP addresses >> ifconfig | awk '/inet / {print $2}' * disable caps lock >> xmodmap -e "remove Lock = Caps_Lock" * Show every subdirectory (zsh) >> ls -ld **/*(/) * Show directories >> ls -l | grep ^d * Watch movies in your terminal >> mplayer -vo caca MovieName.avi * Scan a gz file for non-printable characters and display each line >> zcat a_big_file.gz | sed -ne "$(zcat a_big_file.gz | tr -d "[:print:]" | cat -n | grep -vP "^ *\d+\t$" | cut -f 1 | sed -e "s/\([0-9]\+\)/\1=;\1p;/" | xargs)" | tr -c "[:print:]\n" "?" * Get information about libraries currently installed on a system. >> rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}\n'|egrep 'compat|glibc|gcc|libst|binu'|sort * mplayer -vo aa foo.mpg >> Play "foo.mpg" in your terminal using ASCII characters * Scans for open ports using telnet >> HOST=127.0.0.1;for((port=1;port<=65535;++port)); do echo -en "$port ";if echo -en "open $HOST $port\nlogout\quit" | telnet 2>/dev/null | grep 'Connected to' > /dev/null; then echo -en "\n\nport $port/tcp is open\n\n";fi;done | grep open * listen to an offensive fortune >> fortune -o | espeak * Show what PID is listening on port 80 on Linux >> netstat -alnp | grep ::80 * Run a command if today is the last day of the month >> if [[ `:$(cal);echo $_` == `date +%d` ]]; then ROTATE_MONTHLY_TABLES_SCRIPT;fi * check the status of 'dd' in progress >> ps auxww |grep " dd " |grep -v grep |awk '{print $2}' |while read pid; do kill -USR1 $pid; done * Compare two CSV files, discarding any repeated lines >> cat foo.csv bar.csv | sort -t "," -k 2 | uniq * Simple way to envoke a secure vnc session through ssh enabled >> vncviewer -via root@your.dyndns.com 192.168.1.1 * Display email addresses that have been sent to by a postfix >> sed -n -e '/postfix\/smtp\[.*status=sent/s/^.*to=<\([^>]*\).*$/\1/p' /var/log/mail.log | sort -u * read a file line by line and perform some operation on each line >> while read line; do echo "$(date),$(hostname),$line"; done < somefile.txt * Benchmark a hard drive >> sudo hdparm -Tt /dev/sda * get some information about the parent process from a given >> ps -o ppid= <given pid> | xargs ps -p * auto terminal title change >> echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007" * Show a listing of open mailbox files (or whatever you want to >> lsof | grep "/var/spool/mail/" * Watch YouTube and other Flash videos via mplayer (or whatever) >> mplayer $(ls -t /tmp/Flash*|head -1) * apt-get via sudo >> apt-get () { [ "$1" = source ] && (command apt-get "$@";true) || sudo apt-get "$@" } * Grab mp3 files from your favorite netcasts, mp3blog, or sites >> wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off -i ~/sourceurls.txt * Simple example of the trap command >> trap "echo \"$0 process $$ killed on $(date).\"; exit " HUP INT QUIT ABRT TERM STOP * Redirect STDIN >> < /path/to/file.txt grep foo * clear current line >> CTRL+u * ls -hog --> a more compact ls -l >> ls -hog * Transfer SSH public key to another machine in one step >> ssh-keygen; ssh-copy-id user@host; ssh user@host * Get all the keyboard shortcuts in screen >> ^A ? * convert uppercase files to lowercase files >> rename 'y/A-Z/a-z/' * * Switch 2 characters on a command line. >> ctrl-t * Start a new command in a new screen window >> alias s='screen -X screen'; s top; s vi; s man ls; * live ssh network throughput test >> yes | pv | ssh $host "cat > /dev/null" * Numbers guessing game >> A=1;B=100;X=0;C=0;N=$[$RANDOM%$B+1];until [ $X -eq $N ];do read -p "N between $A and $B. Guess? " X;C=$(($C+1));A=$(($X<$N?$X:$A));B=$(($X>$N?$X:$B));done;echo "Took you $C tries, Einstein"; * a trash function for bash >> trash <file> * Make sure a script is run in a terminal. >> [ -t 0 ] || exit 1 * Matrix Style >> echo -e "\e[32m"; while :; do for i in {1..16}; do r="$(($RANDOM % 2))"; if [[ $(($RANDOM % 5)) == 1 ]]; then if [[ $(($RANDOM % 4)) == 1 ]]; then v+="\e[1m $r "; else v+="\e[2m $r "; fi; else v+=" "; fi; done; echo -e "$v"; v=""; done * Remove blank lines from a file using grep and save output to new >> grep . filename > newfilename * Identify long lines in a file >> awk 'length>72' file * Show directories in the PATH, one per line >> echo "${PATH//:/$'\n'}" * check open ports >> lsof -Pni4 | grep LISTEN * Move all images in a directory into a directory hierarchy based >> exiftool '-Directory<DateTimeOriginal' -d %Y/%m/%d dir * Smiley Face Bash Prompt >> PS1="\`if [ \$? = 0 ]; then echo \e[33\;40m\\\^\\\_\\\^\e[0m; else echo \e[36\;40m\\\-\e[0m\\\_\e[36\;40m\\\-\e[0m; fi\` \u \w:\h)" * Convert "man page" to text file >> man ls | col -b > ~/Desktop/man_ls.txt * Find if the command has an alias >> type -all command * Share a 'screen'-session >> screen -x * Show all detected mountable Drives/Partitions/BlockDevices >> hwinfo --block --short * When feeling down, this command helps >> sl * Update Ogg Vorbis file comments >> for f in *.ogg; do vorbiscomment -l "$f" | sed 's/peter gabriel/Peter * Encode text in Base64 using Perl >> perl -e 'use MIME::Base64; print encode_base64("encode me plz");' * List empty any directories >> ls -ld **/*(/^F) * rsync over ssh >> rsync -avz -e ssh username@hostname:/path/to/remote/dir/ /path/to/local/dir/ * Compress a file or directory keeping the owner and permissions >> tar -jcvf /folder/file.tar.bz2 --same-owner --same-permissions /folder/ * A signal trap that logs when your script was killed and what other >> trap "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 * listen to ram >> cat /dev/mem > /dev/audio * 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}'` * HDD Performance Write Test >> dd if=/dev/zero of=10gb bs=1M count=10240 * Copy a file and force owner/group/mode >> install -o user -g group -m 755 /path/to/file /path/to/dir/ * Delete newline >> tr -d "\n" < file1 > file2 * Make the Mac OS X Dock 2D once more (10.5 and above only) >> defaults write com.apple.Dock no-glass -boolean YES; killall Dock * Find files with the same names in several directories. >> ls -1 . dir2 dir3|sort|uniq -d * re-assign line numbers >> perl -pe 's/\d+/++$n/e' file.txt * reset an hanging terminal session >> ^J tput sgr0 ^J * Create a 100MB file for testing transfer speed >> dd if=/dev/random of=bigfile bs=1024 count=102400 * Number of CPU's in a system >> grep "processor" /proc/cpuinfo | wc -l * send substituted text to a command without echo, pipe >> nc localhost 10000 <<< "message" * phpinfo from the command line >> echo "<?php phpinfo(); ?>" | php > phpinfo.txt * read Windows ACLs from Linux >> smbcacls //server/sharename file -U username * Umount only the NFS related to 'string' >> for i in `df -P |grep string|cut -f2 -d%|cut -c2-100`; do umount -l -f $i;done * Find files with at least one exec bit set >> find . -type f -perm +0111 -print * Get your default route >> ip route | grep default | awk '{print $3}' * List all files/folders in working directory with their total size >> du --max-depth=1 -m * Show a calendar >> cal [[month] year] * Check for Firewall Blockage. >> iptables -L -n --line-numbers | grep xx.xx.xx.xx * Finds all files from / on down over specified size. >> find / -type f -size +25M -exec ls -lh {} \; | awk '{ print $5 " " $6$7 ": " $9 }' * Mount a windows partition in a dual boot linux installation with >> mount -o -t ntfs-3g /dev/sda1 /mnt/windows/c force * tar pipe to copy files, alternate to cp -Ra >> (cd /orignl/path tar -cf - . ) | (cd /dst/dir;tar -xvf -) * 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 * find all files containing a pattern, open them using vi and place >> find . -type f -exec grep -l pattern {} \; | xargs vi +/pattern * converts a directory full of source tarballs into a bzr repository >> bzr init .;for file in `ls *.bz2`; do bzr import $file; bzr ci -m $file; done * Test python regular expressions >> rgx_match() { python -c "import re; print re.search('$1','$2').groups()"; } * Perform a C-style loop in Bash. >> for (( i = 0; i < 100; i++ )); do echo "$i"; done * Pipe a textfile to vim and move the cursor to a certain line >> zcat /usr/share/doc/vim-common/README.gz | vim -g +23 - * Convert PNG to GIF >> for file in *.png; do convert "$file" "$(basename $file .png).gif"; done * Turns hidden applications transparent in the Mac OS X dock. >> defaults write com.apple.Dock showhidden -bool YES * Creat a new user with no shell. Useful to provide other services >> useradd -s /sbin/nologin nicdev * 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" * It decripts all pgp files in a selection folder and move the >> 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; * Show device drivers and their properties (Windows XP) >> driverquery /si /fo table * relabel current konsole tab >> alias rk='d=$(dcop|grep $PPID) && s=$(dcop $d konsole currentSession) && dcop $d $s renameSession' * Mortality Countdown >> while [ 0 ]; do expr 2365200000 \- `date +%s` \- `date --date "YYYY-mm-dd HH:MM:ss" +%s`; sleep 1; clear; done * set prompt and terminal title to display hostname, user ID and >> export PS1='\[\e]0;\h \u \w\a\]\n\[\e[0;34m\]\u@\h \[\e[33m\]\w\[\e[0;32m\]\n\$ ' * Show one line summaries of all DEB packages installed on Ubuntu >> dpkg --list '*linux*' | grep '^ii' * Create a git alias that will pull and fast-forward the current >> git config --global --add alias.ff "pull --no-commit -v" ; git ff * Getting the ip address of eth0 >> ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}' * tunnel vnc port >> ssh -L 5900:localhost:5900 user@exampleserver.com * Find public IP when behind a random router (also see description) >> alias pubip='GET http://www.whatismyip.com/automation/n09230945.asp && echo' * Remove multiple same rpm packages >> rpm -e --allmatches filename.rpm * KDE Mixer Master Mute/Unmute >> alias mute="dcop kmix Mixer0 toggleMasterMute\(\) ; dcop kmix Mixer0 * Automatically create a rar archive >> rar a -m0 "${PWD##*/}.rar" * * Display the linux host infomation. >> hostinfo.sh * Recover cvs ": no such repository" error >> find ./* -name 'CVS' | awk '{print "dos2unix " $1 "/*"}' | awk '{system($0)}' * Recursive Ownership Change >> chown -cR --from=olduser:oldgroup newuser:newgroup * * Name a backup/archive file based on current date and time >> archivefile=filename-$(date +%Y%m%d-%H%M).tar.gz * Erase DVD RW >> dvd+rw-format /dev/dvd * ZSH prompt. ':)' after program execution with no error, ':(' after >> PROMPT=$'%{\e[0;32m%}%B[%b%{\e[0m%}%n%{\e[0;32m%}@%{\e[0m%}%(4c,./%1~,% ~)%{\e[0;32m%}%B]%b% %(?,%{\e[0;32m%}:%)%{\e[0m%},%{\e[0;31m%}:(%{\e[0m%}) %# ' * Separates each frame of a animated gif file to a counted file, >> convert +adjoin animatedImage.gif test.gif ; convert +append test*.gif * convert hex to decimal ; decimal to hex >> echo 16i `echo "F" | tr '[a-f]' '[A-F]'` p | dc ; echo 16o "15" p | dc * Better recursive grep with pretty colors... requires ruby and gems >> rak "what you're searching for" dir/path * Change size of lots of image files. >> for File in *.jpg; do mogrify -resize 1024 -quality 96 $File; done * list file descriptors opened by a process >> ls -al /proc/<PID>/fd * finding more large files >> find / -xdev -size +1024 -exec ls -al {} \; | sort -r -k 5 * cloning partition tables under Solaris >> prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2 * Use nroff to view the man pages >> nroff -u0 -Tlp -man /usr/openwin/man/man1/Xsun.1 | col -x | less * See the top 10 IP addresses in a web access log >> # cut -d ' ' -f1 /var/log/nginx/nginx-access.log | sort | uniq -c | sort -nr | head -10 | nl * E-mail a traditional Berkeley mbox to another recipient as >> formail -Y -s /usr/sbin/sendmail bar@example.com < /var/mail/foo * search user defined function in c language >> cflow file.c | grep ':$' | sed 's/ <.*//' * Adhoc tar backup >> tar -cvzf - /source/path | ssh <targethostname> -l <username> dd of=/destination/path/backupfile.tgz * Get a process's pid by supplying its name >> pidof () { ps acx | egrep -i $@ | awk '{print $1}'; } * play all mp4 files on home directory >> find ~ -name '*.mp4' | xargs mplayer * Convert a date to timestamp >> date --utc --date "2009-02-06 09:57:54" +%s * 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 * List open sockets protocol/address/port/state/PID/program name >> sudo netstat -punta * The simplest way to transport information over a network >> (on destination machine) nc -l 1234 > whatever; (on source machine) nc destination 1234 < whatever; * tar a directory and send it to netcat >> tar cfvz - /home/user | netcat -l -p 10000 * Ride another SSH agent >> export SSH_AUTH_SOCK=`find /tmp/ssh* -type s -user [user] -mtime -1 | head -1` * Prepare B&W scans for clean looking, searchable PDF >> convert pagexxx.png -filter Cubic -resize 200% -threshold 50% -compress Group4 pagexxx.tiff; tiff2pdf -z -p letter -ro -x 1200 -y 1200 -o pagexxx.pdf pagexxx.tiff * Periodic Log Deletion >> find /path/to/dir -type f -mtime +[#] -exec rm -f {} \; * in-place search/replace with datestamped backup >> sed -i.`date +%Y%m%d` -e 's/pattern/replace' [filename] * Unrar multiple directories into current working directory >> for x in */*.rar; do unrar x $x; done * Validate openssh key & print checksum >> ssh-keygen -l -f [pubkey] | awk '{print $2}' | tr -ds ':' '' | egrep -ie "[a-f0-9]{32}" * Get line count for any file ending with extension recursively >> find . -name "*.py" | xargs wc -l * Search for in which package the specified file is included. >> /bin/rpm -qf /etc/passwd /etc/issue /etc/httpd/conf/httpd.conf * List just the executable files (or directories) in current >> ls -dF `find . -maxdepth 1 \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print` * [WinXP]Use as a shortcut in the SendTo menu to open a cmd window >> C:\WINDOWS\system32\cmd.exe /t:0A /k cd /d * Function to remove a directory from your PATH >> pathrm() { PATH=`echo $PATH | sed -e "s=^${1}:==;s=:${1}$==;s=:${1}:=:="`; } * move all the .bak backup copies to their original names (rename >> for i in *.bak ; do nuname=`echo $i | sed 's/\.[^\.]*$//'`; echo renaming $i to $nuname;mv $i $nuname; done * Print all lines in a file that are not a certain length >> awk 'length($0)!=12 {print}' your_file_name * Creates a SSHFS volume on MacOS X (better used as an alias). Needs >> mkdir /Volumes/sshdisk 2> /dev/null; sshfs user@server:/ * Get me yesterday's date, even if today is 1-Mar-2008 and yesterday >> TZ=XYZ24 date * look for a function reference in a library set >> nm --defined-only --print-file-name lib*so 2>/dev/null | grep ' pthread_create$' * diff directories, quick cut and paste to view the changes >> diff -q dir1/ dir2/ | grep differ | awk '{ print "vimdiff " $2 " " $4 }' * Flush and then immediately start watching a file >> (> errors.log) && tail -f !^ * Ping a URL sending output to file and STDOUT >> ping google.com | tee ping-output.txt * Display PHP files that directly instantiate a given class >> find . -name "*.php" -exec grep \-H "new filter_" {} \; * Creates a customized search command >> alias cr='find . 2>/dev/null -regex '\''.*\.\(c\|cpp\|pc\|h\|hpp\|cc\)$'\'' | xargs grep --color=always -ni -C2' * Add SVN keywords property to all PHP and Javascript files >> find . \( -name "*.php" -o -name "*.js" \) -exec svn propset svn:keywords Id {} \; * Prevent overwriting file when using redirection >> set -o noclobber * Poor man's ntpdate >> date -s "`curl -sI www.example.com | sed -n 's/^Date: //p'`" * sirve para ver la salida de un comando en pantalla y al mismo >> find / -name *.conf | tee salida * Poor man's ntpdate >> date -s "$(echo -e "HEAD / HTTP/1.0\n" | nc www.example.com 80 | sed -ne 's/^Date: \(.*\)$/\1/p')" * get bofh excuse from a trusted source :-) >> telnet bofh.jeffballard.us 666 * 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 * Fix borked character coding in a tty. >> LC_ALL=C man -c man * use sed to simulate rpad and lpad >> ls / | sed -e :a -e 's/^.\{1,15\}$/&_/;ta' * Print a row of 50 hyphens >> echo - | sed -e :a -e 's/^.\{1,50\}$/&-/;ta' * Print a row of 50 hyphens >> jot -s '' -b '-' 50 * Prints line numbers >> nl <filename> * Determine what process is listening on a port on Solaris, without >> 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 * Change your swappiness Ratio under linux >> echo 50 > /proc/sys/vm/swappiness * paged 'ls' in color >> ls -lah --color=always | most * 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' \; * Replace spaces in filename >> for i in *\ *; do if [ -f "$i" ]; then mv "$i" ${i// /_}; fi; done * Replace strings in files >> sed -i -e 's/war/peace/g' * * 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 * convert wav into mp3 using lame >> lame -V2 rec01.wav rec01.mp3 * Find and print pattern location from all files on command line >> find . -exec grep $foo {} \; -print * Display the output of a command from the first line until the >> command | sed '/regex/q' * Read just the IP address of a device >> ifconfig -l | xargs -n1 ipconfig getifaddr 2> /dev/null * Display the list of all opened tabs from Firefox via a python >> python <<< $'import minjson\nf = open("sessionstore.js", "r")\njdata = minjson.read(f.read())\nf.close()\nfor win in jdata.get("windows"):\n\tfor tab in win.get("tabs"):\n\t\ti = tab.get("index") - 1\n\t\tprint tab.get("entries")[i].get("url")' * Pause and Resume Processes >> stop () { ps -ec | grep $@ | kill -SIGSTOP `awk '{print $1}'`; } * upload a file via ftp >> curl -u user:passwd -T /home/dir/local_file_to_upload ftp://your_host.com/subdir/ * floating point shell calculator >> calc() { awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'; } * 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 * floating point bash calculator w/o precision >> b(){ echo "scale=${2:-2}; $1" | bc -l; } * copy partition table from /dev/sda to /dev/sdb >> sfdisk -d /dev/sda | sed 's/sda/sdb/g' | sfdisk /dev/sdb * Display the output of a command from the first line until the >> <command> | perl -pe '/<regex/ && exit;' * Display the output of a command from the first line until the >> <your command here> | perl -n -e 'print "$_" if 1 ... /<regex>/;' * Randomize lines (opposite of | sort), or use 'shuf' better. >> 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 * Sum using awk >> ps -ylC httpd --sort:rss | awk '{ SUM += $8 } END { print SUM/1024 }' * Monitor the Kernel Ring Buffer >> watch 'dmesg | tail -15' * 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"; } * display embeded comments for every --opt, usefull for auto >> vim -n -es -c 'g/# CommandParse/+2,/^\s\+esac/-1 d p | % d | put p | %<' -c 'g/^\([-+]\+[^)]\+\))/,/^\(\s\+[^- \t#]\|^$\)/-1 p' -c 'q!' $0 * 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; } * Sometimes you just want a quick way to find out if a certain user >> getent shadow | grep '^[^:]\+:!' | cut -d: -f1 * Sometimes you just want a quick way to find out if a certain user >> getent shadow | while IFS=: read a b c; do grep -q '!' <<< "$b" && echo "$a LOCKED" || echo "$a not locked"; done * Sometimes you just want a quick way to find out if a certain user ?? >> 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 * report what tape is in autoloader mailslot (using barcode label) >> mtx -f /dev/sg13 status | grep EXPORT | cut -c 56-63 * count and number lines of output, useful for counting number of >> ps aux | grep [h]ttpd | cat -n * Create SSH key exchange from one host to the other >> cat ~/.ssh/id_rsa.pub | ssh <remote_host> "xargs --null echo >> ~/.ssh/authorized_keys" * Check general system error on AIX >> errpt -a | more * Mostly silent FLAC checking (only errors are displayed) >> flac -ts *.flac * Send a local file via email >> { echo -e "$body"; uuencode "$outfile" "$outfile"; } | mail -s "$subject" "$destaddr" ; * Display / view the contents of the manifest within a Java jar >> $ unzip -p some-jar-file.jar META-INF/MANIFEST.MF * Optimal way of deleting huge numbers of files >> find /path/to/dir/ -type f -exec rm {} + * Extract all urls from the last firefox sessionstore.js file used. >> grep -oP '"url":"\K[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q) * Router discovery >> traceroute 2>/dev/null -n google.com | awk '/^ *1/{print $2;exit}' * prints line numbers >> perl -pe 'print "$. "' <file> * Use curl on Windows to bulk-download the Savitabhabhi Comic Strip >> for /L %%x in (1,1,16) do mkdir %%x & curl -R -e http://www.kirtu.com * Know when you will type :q in your term instead of vi(m), the >> alias :q='tput setaf 1; echo >&2 "this is NOT vi(m) :/"; tput sgr0' * Salvage a borked terminal >> echo <ctrl+v><ctrl+o><enter> * Search trought pidgin's conversation logs for "searchterm", and >> grep -Ri searchterm ~/.purple/logs/* | sed -e 's/<.*?>//g' * Shorten url with is.gd using curl, perl >> curl -s "http://is.gd/api.php?longurl=[long_url]" * get MAC address of default gateway >> netstat -nr | awk 'BEGIN {while ($1!="default") getline; g=$2;} (g==$1) {print $2; exit;}' * Finding all numbers that are bigger then 1 in vim >> /^\([2-9]\d*\|1\d+\) * Show Network IP and Subnet >> ipcalc $(ifconfig eth0 | grep "inet addr:" | cut -d':' -f2,4 | sed 's/.+Bcast:/\//g') | awk '/Network/ { print $2 } ' * Router discovery >> awk 'NR==2 {print $1}' /proc/net/arp * Return IP Address >> ifconfig -a| awk 'BEGIN{FS="[ :]+"} /Bcast/{print $4}' * 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 * 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` * 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); } ' * Watch those evil Red Hat states code D Uninterruptible sleep >> watch -n 1 "ps aux | sed -n 's/ D /&/p'" * lists contents of a tar file >> tar -tf /path/to/file.tar * convert flv into avi file and mp3 sound >> mencoder input.flv -ovc lavc -oac mp3lame -o output.avi * generate random password >> cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | sed 1q * use the short username by default for network authentication >> defaults write /Library/Preferences/com.apple.NetworkAuthorization UseShortName -bool YES * ffmpeg -i movie.mpg -vhook '/usr/lib/vhook/watermark.so -f >> ffmpeg -i movie.mpg -vhook '/usr/lib/vhook/watermark.so -f overlay.png -m 1 -t 222222' -an mm.flv * Match a URL >> echo "(Something like http://foo.com/blah_blah)" | grep -oP "\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))" * Run command in an ftp session >> ftp>!w * 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)" * configify the list of gems on ur machine. the quick hack >> gem list --local | python -c "import sys;import * Find in all files in the current directory, just a find shorthand >> grep -H -n "pattern" * * Find all dot files and directories >> printf "%s\n" .* * List the biggest accessible files/dirs in current directory, >> du -ms * 2>/dev/null |sort -nr|head * Make all GUI stuff show up on the display connected to the >> DISPLAY=:0.0; export DISPLAY * Set the master volume to 90% (Ubuntu) >> aumix -v 90 * DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder >> mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -o dvd.avi dvd://0 * Find iPod's fwguid >> lsusb -v | grep -o "[0-9A-Z]{16}" * Show sorted list of files with sizes more than 1MB in the current >> find . -maxdepth 1 -type f -size +1M -printf "%f:%s\n" | sort -t":" -k2 * Get your external IP address >> wget -qO - http://www.sputnick-area.net/ip;echo * force change password for all user >> while IFS=: read u x; do passwd -e "$u"; done < /etc/passwd * Find all dot files and directories >> printf "%s\n" .* * Testing reading speed with dd >> sync; time `dd if=/dev/cciss/c0d1p1 of=/dev/null bs=1M count=10240` * Testing writing speed with dd >> sync; time `dd if=/dev/zero of=bigfile bs=1M count=2048 && sync` * Better "hours of video" summary for each file/dir in the current >> 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$' * Find all videos under current directory >> find ./ -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 * force change password for all user >> getent passwd|cut -d: -f1|xargs -n1 passwd -e * system beep off >> setterm -bfreq 0 * 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:' } * geoip information >> geoiplookup www.commandlinefu.com * shell function to turn start and length in to a range suitable >> range () { end=$(echo "$1 + $2 - 1" | bc); echo "$1-$end"; } * slice a fixed number of characters from the output of a command, >> slice(){ cut -c$((${#1}+1))-; }; ls -l | slice "-rw-r--r--" * slice a fixed number of characters from the output of a command, >> slice="-rw-r--r-- "; ls -l | cut -c $(echo "$slice" | wc -c)- * 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" * Start the x11vnc server >> x11vnc -display :0 -scale 6/7 -rfbauth vncpass -forever * Create x11vnc server authentication file >> x11vnc -storepasswd your_new_apssword ~/my_vnc_pass * List all available commands >> in bash hit "tab" twice and answer y * geoip information >> geo(){ curl -s "http://www.geody.com/geoip.php?ip=$(dig +short $1)"| sed '/^IP:/!d;s/<[^>][^>]*>//g'; } * Show a script or config file without comments >> egrep -v "^[[:blank:]]*($|#|//|/\*| \*|\*/)" somefile * Create a simple backup >> tar pzcvf /result_path/result.tar.gz /target_path/target_folder * 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 * Get ethX mac addresses >> ifconfig | awk '/HW/ {print $5}' * Get ethX mac addresses >> ip link show eth0 | grep "link/ether" | awk '{print $2}' * Build an exhaustive list of maildir folders for mutt >> find ~/Maildir/ -mindepth 1 -type d | egrep -v '/cur$|/tmp$|/new$' | xargs * 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."}' * Make sure a script is run in a terminal. >> tty > /dev/null 2>&1 || { aplay error.wav ; exit 1 ;} * Attach all discovered iscsi nodes >> iscsiadm -m node -l * Add the sbin directories to your PATH if it doesn't already exist >> path+=( /sbin /usr/sbin /usr/local/sbin ); path=( ${(u)path} ); * Search vmware vmx files if Linux guests are set to sync time to >> 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; * Empty a file >> > [filename].txt * Erase empty files >> find . -size 0 -exec rm '{}' \; * Receiving alerts about commands who exit with failure >> export PROMPT_COMMAND='( x=$? ; let x!=0 && echo shell returned $x )' * 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 * 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 * Get ssh server fingerprints >> ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub && ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub * Remove CR LF from a text file >> flip -u $FILE * 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 * grep -v with multiple patterns. >> sed -n '/test/{/error\|critical\|warning/d;p}' somefile * view the system console remotely >> sudo cat /dev/vcs1 | fold -w 80 * Download all Delicious bookmarks >> curl -u username -o bookmarks.xml https://api.del.icio.us/v1/posts/all * Schedule a download at a later time >> echo 'wget url' | at 01:00 * Add calendar to desktop wallpaper >> convert -font -misc-fixed-*-*-*-*-*-*-*-*-*-*-*-* -fill black -draw "text 270,260 \" `cal` \"" testpic.jpg newtestpic.jpg * create dir tree >> mkdir -p doc/{text/,img/{wallpaper/,photos/}} * Backup your hard drive with dd >> sudo dd if=/dev/sda of=/media/disk/backup/sda.backup * Extract audio from a video >> ffmpeg -i video.avi -f mp3 audio.mp3 * Quick glance at who's been using your system recently >> last | grep -v "^$" | awk '{ print $1 }' | sort -nr | uniq -c * Get Dell Service Tag Number from a Dell Machine >> sudo dmidecode | grep Serial\ Number | head -n1 * change directory to actual path instead of symlink path >> cd `pwd -P` * Generat a Random MAC address >> MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'` * Get list of servers with a specific port open >> nmap -sT -p 80 -oG - 192.168.1.* | grep open * ssh tunnel with auto reconnect ability >> while [ ! -f /tmp/stop ]; do ssh -o ExitOnForwardFailure=yes -R 2222:localhost:22 target "while nc -zv localhost 2222; do sleep 5; done"; sleep 5;done * Use last argument of last command >> file !$ * A function to output a man page as a pdf file >> function man2pdf(){ man -t ${1:?Specify man as arg} | ps2pdf -dCompatibility=1.3 - - > ${1}.pdf; } * Save current layout of top >> <Shift + W> * Mount the first NTFS partition inside a VDI file (VirtualBox Disk >> mount -t ntfs-3g -o ro,loop,uid=user,gid=group,umask=0007,fmask=0117,offset=0x$(hd -n 1000000 image.vdi | grep "eb 52 90 4e 54 46 53" | cut -c 1-8) image.vdi /mnt/vdi-ntfs * Use all the cores or CPUs when compiling >> make -j 4 * List programs with open ports and connections >> lsof -i * Create a list of binary numbers >> echo {0..1}{0..1}{0..1}{0..1} * Create a system overview dashboard on F12 key >> bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m""" * Find last reboot time >> who -b * Start screen in detached mode >> screen -d -m [<command>] * Ctrl+S Ctrl+Q terminal output lock and unlock >> Ctrl+S Ctrl+Q * StopWatch, toilet version, amazing format inside terminal >> export I=$(date +%s); watch -t -n 1 'T=$(date * 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' * Show bash's function definitions you defined in .bash_profile or >> declare -f [ function_name ] * List bash functions defined in .bash_profile or .bashrc >> set | fgrep " ()" * Show current folder permission recursively from /, useful for >> pushd .> /dev/null; cd /; for d in `echo $OLDPWD | sed -e 's/\// /g'`; do cd $d; echo -n "$d "; ls -ld .; done; popd >/dev/null * Convert Windows/DOS Text Files to Unix >> flip -u <filenames> * create a motion jpeg (MJPEG) with the jpg file from current >> mencoder mf://image1.jpg,image2.jpg,image3.jpg -mf w=800:h=600:fps=25:type=jpeg -ovc copy -oac copy -o output.avi * Create a mpeg4 video from a jpeg picture sequence (e.g. for pencil >> mencoder mf://*.jpg -mf w=800:h=600:fps=25:type=jpeg -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi * 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 } * 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; } * 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 * Set default "New Page" as HTML in TextMate >> defaults write com.macromates.textmate OakDefaultLanguage 17994EC8-6B1D-11D9-AC3A-000D93589AF6 * 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 * Copy recursivelly files of specific filetypes >> rsync -rvtW --progress --include='*.wmv' --include='*.mpg' --exclude='*.*' <sourcedir> <destdir> * encode image to base64 and copy to clipboard >> uuencode -m $1 /dev/stdout | sed '1d' | sed '$d' | tr -d '\n' | xclip -selection clipboard * Battery real life energy vs predicted remaining plotted >> echo start > battery.txt; watch -n 60 'date >> battery.txt ; acpi -b >> battery.txt' * Do you really believe on Battery Remaining Time? Confirm it from >> echo start > battery.txt; watch -n 60 'date >> battery.txt' * Get decimal ascii code from character >> ord() { printf "%d\n" "'$1"; } * Testing hard disk writing speed >> time dd if=/dev/zero of=TEST bs=4k count=512000 * 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 decimal ascii code from character >> ord () { seq 1 127 | while read i; do echo `chr $i` $i; done | grep "^$1 " | cut -c '3-' } * 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\/' * 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`" * 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; } * Convert video type from mpg to wmv >> mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq -oac * Creating sequence of number with text >> seq 10 |xargs -n1 echo Printing line * Proxy all web traffic via ssh >> Putty -d 8080 [server] * colored tail >> tail -f FILE | grep --color=always KEYWORD * GZip all files in a directory separately >> for file in *.foo; do gzip "$file"; done * Command to resolve name from Ip address, passing only the last >> 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/.$//' * Monitor a file's size >> while [ 1 ]; do du /var/log/messages;sleep 60; done * Check if variable is a number >> echo $X | egrep "^[0-9]+$" * View firewall config including devices on linux w/netfilter >> iptables -L -n -v * sort lines by length >> awk '{print length, $0;}' | sort -nr * Get last changed revision to all eclipse projects in a SVN working >> 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//' * Convert unix timestamp to date >> date -ud "1970-01-01 + 1234567890 seconds" * List only locally modified files with CVS >> cvs -n update 2>null | grep -i "M " | sed s/"M "// * Bashbuiltin printf >> cat file.txt | while read line; do printf "%7.2f -> %7.2f\n" $line; done * 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 * List open TCP/UDP ports >> lsof -i tcp -i udp * List open TCP/UDP ports >> netstat -ltun * List open TCP/UDP ports >> netstat -anp --tcp --udp | grep LISTEN * Get length of array in zsh >> $foo[(I)$foo[-1]] * 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]*) * Are 64-bit applications supported on my Solaris OS? >> isainfo -vb * convert string to array >> s=124890; array=($(echo $s | sed 's/./& /g')); echo ${array[@]}; echo * convert string to array >> s="124890";for i in $(seq 0 1 $((${#s}-1))); do arr[$i]=${s:$i:1}; done * Open your application to a specific size and location >> command -geometry 120x30+1280+0 * 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 * Colorized grep in less >> ack --pager='less -r' * futz.me - Send yourself notes from the command line >> lynx "futz.me/xxx hey this is a test" * Find duplicate dir in path >> echo $PATH|tr : '\n'|sort|uniq -d * 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; }}' * find . -name "*.txt" | xargs sed -i "s/old/new/" >> find . -name "*.txt" | xargs sed -i "s/old/new/" * svn diff $* | colordiff | lv -c >> svn diff $* | colordiff | lv -c * Recursive Ownership Change >> sudo chown -R user2:user2 /../../somedirectory * Execute a command with a timeout >> perl -e "alarm 10; exec @ARGV" "somecommand" * Show which include directories your installation of Perl is >> perl -le 'print join $/, @INC' * Dump all of perl's config info >> perl -le 'use Config; foreach $i (keys %Config) {print "$i : @Config{$i}"}' * 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 all text files (exclude binary files) >> find . | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;" * Learn how to stop mistyping "ls" the fun way >> apt-get install sl; sl * List the size (in human readable form) of all sub folders from the >> du -h --max-depth=1 * Query Wikipedia via console over DNS >> dig +short txt <keyword>.wp.dg.cx * Display the top ten running processes - sorted by memory usage >> ps aux | sort -nk +4 | tail * A very simple and useful stopwatch >> time read (ctrl-d to stop) * Place the argument of the most recent command on the shell >> 'ALT+.' or '<ESC> .' * Quick access to the ascii table. >> man ascii * Shutdown a Windows machine from Linux >> net rpc shutdown -I ipAddressOfWindowsPC -U username%password * Execute a command without saving it in the history >> <space>command * Jump to a directory, execute a command and jump back to current >> (cd /tmp && ls) * Clear the terminal screen >> ctrl-l * Backticks are evil >> echo "The date is: $(date +%D)" * Reboot machine when everything is hanging >> <alt> + <print screen/sys rq> + <R> - <S> - <E> - <I> - <U> - <B> * Watch Network Service Activity in Real-time >> lsof -i * Easily search running processes (alias). >> alias 'ps?'='ps ax | grep ' * Rip audio from a video file. >> mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile <output-file> <input-file> * Matrix Style >> tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]" * Watch Star Wars via telnet >> telnet towel.blinkenlights.nl * Stream YouTube URL directly to mplayer. >> mplayer -fs $(echo "http://youtube.com/get_video.php?$(curl -s $youtube_url | sed -n "/watch_fullscreen/s;.*\(video_id.\+\)&title.*;\1;p")") * Use heading subtitle file as watermark using mencoder >> mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac * Send a local file via email >> cat filename | uuencode filename | mail -s "Email subject" user@example.com * Bulk copy large blocks of data between File Systems (run as root >> tar cpof - src |( cd des; tar xpof -) * list the last week's added files in xmms2's library >> xmms2 mlib search added \> $(echo $(date +%s) - 604800|bc) * View a sopcast stream >> (sp-sc sop://broker.sopcast.com:3912/6002 3900 8900 &>/dev/null &); sleep 10; mplayer http://localhost:8900/tv.asf * Show only existing executable dirs in PATH using only builtin bash >> for p in ${PATH//:/ }; do [[ -d $p && -x $p ]] && echo $p; done * warped and shagadelic webcam view with gstreamer >> gst-launch-0.10 v4l2src ! ffmpegcolorspace ! warptv ! ffmpegcolorspace ! autovideosink * for loop with leading zero in bash 3 >> printf "%02u " {3..20}; echo * for loop with leading zeros >> for s in `seq -f %02.0f 5 15`; do echo $s; done * Substitution cipher >> echo "Decode this"| tr [a-zA-Z] $(echo {a..z} {A..Z}|grep -o .|sort -R|tr -d "\n ") * 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])$' * replace @ symbol with new line character, to get new line >> %s/@/^v[M]/g * Record MP3 audio via ALSA using ffmpeg >> ffmpeg -f alsa -ac 2 -i hw:1,0 -acodec libmp3lame -ab 96k output.mp3 * Tar a directory and its sub-directory >> tar cvfz dir_name.tgz dir/ * http://www.merriam-webster.com/dictionary/ultimate >> ultimate * Run remote web page, but don't save the results >> wget -q --spider http://server/cgi/script * Mount an ISO image on Mac OS X >> hdiutil mount sample.iso * 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 * find files in $PATH that were not installed through dpkg >> echo -e "${PATH//://\n}" >/tmp/allpath; grep -Fh -f /tmp/allpath * Create a zip file ignoring .svn files >> find . -not \( -name .svn -prune \) -type f | xargs zip XXXXX.zip * Search OpenSolaris packages and show only the pkg names >> pkg search SEARCH_TERM | awk '{print $NF}' | sed -e 's;.*/\(.*\)\@.*;\1;' | sort -u * Put the machine to sleep after the download(wget) is done >> while [ -n "`pgrep wget`" ]; do sleep 2 ;done; [ -e "/tmp/nosleep"] || echo mem >/sys/power/state * View the octal dump of a file >> od -vt x1 /tmp/spaghettifile * Add another tty device using mknod command >> sudo mknod /dev/ttyS4 c 4 68 * badblocks for floppy >> /sbin/badblocks -v /dev/fd0 1440 * How to watch files >> watch -d 'ls -l' * Watching Command >> watch 'cat /proc/loadavg' * See if your mac can run 64-bit && if it the kernel is loaded >> ioreg -l -p IODeviceTree | grep -o EFI[0-9]. && system_profiler SPSoftwareDataType |grep 64 * bash/ksh function: given a file, cd to the directory it lives >> function fcd () { [ -f $1 ] && { cd $(dirname $1); } || { cd $1 ; } pwd } * Edit all files found having a specific string found by grep >> grep -ir 'foo' * | awk -F '{print $1}' | xargs vim * Edit all files found having a specific string found by grep >> grep -ir 'foo' * | awk '{print $1}' | sed -e 's/://' | xargs vim * list all hd partitions >> fdisk -l |grep -e '^/' |awk '{print $1}'|sed -e "s|/dev/||g" * find files containing text >> grep -lir "sometext" * > sometext_found_in.log * Another way to see the network interfaces >> ip addr show * scp a good script from host A which has no public access to host >> ssh middlehost "ssh -a root@securehost '> nicescript'" < nicescript * 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 * Do a search-and-replace in a file after making a backup >> for file in <filename>; do cp $file{,.bak} && sed 's/old/new/g' $file.bak > $file; done * Resolve the "all display buffers are busy, please try later" error >> dm display-buffer reset * Get number of diggs for a news URL >> curl -s "http://services.digg.com/stories?link=$NEWSURL&appkey=http://www.whate ver.com&type=json" | python -m simplejson.tool | grep diggs * Verbosely delete files matching specific name pattern, older than >> find /backup/directory -name "FILENAME_*" -mtime +15 -exec rm -vf {}; * locate a filename, make sure it exists and display it with full >> locate -e somefile | xargs ls -l * List files and sizes >> find / -type f -exec wc -c {} \; | sort -nr | head -100 * power off system in X hours form the current time, here X=2 >> echo init 0 | at now + 2 hours * 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 * delete all DrWeb status, failure and other messages on a postfix >> mailq | grep DrWEB | awk {'print $1'} | sed s/*//g | postsuper -d - * less an message on a postfix mailsystem with a specific >> id=<XXXX>; find /var/spool/postfix/ -name $id -exec less {} \; * 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/' {} \; * Have a list of directories in a file, ending with newlines and >> cat filename | tr '\n' '\0' | du -hsc ?files0-from=- * 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 * Remove CR from Windows- / DOS-textfiles >> dos2unix file.txt * Watch changeable interrupts continuously >> watch -n1 'cat /proc/interrupts * Merge ( directories [looking for improvement] >> (cd SRC; find . -type d -exec mkdir TARGET/{} ";"; find . -type f -exec mv {} TARGET/{} ";") * total text files in current dir >> file -i * | grep 'text/plain' | wc -l * An easter egg built into python to give you the Zen of Python >> echo "import this" | python * checks if host /service is up on a host that doesn't respond to >> while true; do clear; nmap ${hostname} -PN -p ${hostport}; sleep 5; done * 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 * Analyze awk fields >> tr " " "\n" | nl * Add "prefix" on a bunch of files >> for a in *; do mv $a prefix${a}; done * Get Interface's IP on Mac >> ipconfig getifaddr <Interface> * 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 * pipe commands from a textfile to a telnet-server with netcat >> nc $telnetserver 23 < $commandfile * Copy files from list with hierarchy >> cat files.txt | xargs tar -cv | tar -x -c $DIR/ * Send SNMP traps >> sudo snmptrap -m ALL -v 2c -c public trapserver "" UCD-DEMO-MIB::ucdDemoPublic SNMPv2-MIB::sysLocation.0 s "Just here" * Create more threads with less stack space >> ulimit -s 64 * 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 ... * Convert a batch of images to a Video >> mencoder "mf://frame_*.bmp" -mf w=720:h=480:fps=30:type=bmp -ovc lavc * Command to display how much resource is taken by cpu and which >> pidstat -C "ffmpeg" -u * Lists unambigously names of all xml elements used in files in >> grep -Eho '<[a-ZA-Z_][a-zA-Z0-9_-:]*' * | sort -u | cut -c2- * 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 * Batch image resize >> for a in `ls`; do echo $a && convert $a -resize <Width>x<Height> $a; done * skipping five lines, at top, then at bottom >> seq 1 12 | sed 1,5d ; seq 1 12 | head --lines=-5 * 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 * Gentoo: Get the size of all installed packets, sorted >> equery s | sed 's/(\|)/ /g' | sort -n -k 9 | gawk '{print $1" "$9/1048576"m"}' * Get all IPs via ifconfig >> ipconfig getpacket en0 | grep yi| sed s."yiaddr = "."en0: ". ipconfig getpacket en1 | grep yi| sed s."yiaddr = "."en1: ". * 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 * Change a text files contents without opening it, or intermediate >> print 'g/'delete this line'/delete\nwq' | ex file.txt * Change open file descriptors limit. >> ulimit -n <value> * ignore hidden directory in bash completion (e.g. .svn) >> Add to ~/.inputrc: set match-hidden-files off * Send Reminders from your Linux Server to Growl on a Mac >> remind -z1 -k'echo %s |ssh <user>@<host> "growlnotify"' ~/.reminders & * what?s running on a given port on your machine? >> lsof -i -n -P | grep :80 * Test your total disk IO capacity, regardless of caching, to find >> time dd if=/dev/zero of=blah.out oflag=direct bs=256M count=1 * Create a file list of all package files installed on your >> for i in `rpm -qva | sort ` ; do ; echo "===== $i =====" ; rpm -qvl $i ; done > /tmp/pkgdetails * Test network performance, copying from the mem of one box, over >> dd if=/dev/zero bs=256M count=1 | nc [remoteIP] [remotePort] and on the other host nc -l port >/dev/null * Fast grepping (avoiding UTF overhead) >> export LANG=C; grep string longBigFile.log * 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}' * Sorting by rows >> infile=$1 for i in $(cat $infile) do echo $i | tr "," "\n" | sort -n | tr "\n" "," | sed "s/,$//" echo done * kill some process (same as others) but parsing to a variable >> pkill -9 -f program * 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((shi ft=~m/^$p\.$p\.$p\.$p$/)?1:0);' 123.123.123.123 * SSH monitor >> ssh root@server 'tail --max-unchanged-stats=10 -n0 -F /var/log/auth.log ' | grep Accepted | while read l ; do kdialog --title "SSH monitor" --passivepopup "$l" 3; done * Printing multiple years with Unix cal command >> for y in 2009 2010 2011; do cal $y; done * 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; * Migrate gems from one ruby installation to another >> /originalInstall/gem list | tr -d '(),' | xargs -L 1 sudo ./gemInst.sh * Find files with lines that do not match a pattern >> fmiss() { grep -cR "$*" * | grep -E ':0$' | cut -d: -f1 ; } * Scan computers OS and open services on all network >> nmap -O 192.168.1.1/24 * bbs in utf8 console >> luit -encoding gbk telnet bbs.sysu.edu.cn * Puts every word from a file into a new line >> sed -r 's/[ \t\r\n\v\f]+/\^J/g' INFILE > OUTFILE * Overwrite local files from copies in a flat directory, even if >> for 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 * Frequency Sweep >> l=500; x=500; y=200; d=-15;for i in `seq $x $d $y`; do beep -l $l -f $i;done * get a list of running virtual machines from the command line >> vmrun list * run vmware virtual machine from the command line without the gui >> vmrun start /path/to/virtual_machine.vmx nogui * Check if you need to run LaTeX more times to get the refefences >> egrep "(There were undefined references|Rerun to get (cross-references|the bars) right)" texfile.log * 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 > * Compile a latex doc to generate index >> ruby -e " 3.times { system 'pdflatex mydoc.tex' } " * Convert man page to PDF >> man -Tps ls >> ls_manpage.ps && ps2pdf ls_manpage.ps * Calculator on the go >> echo 2+3 |bc * Find which package a file belongs to on Solaris >> pkgchk -l -p <full path to the file> * Open Vim with two windows >> vim -c new myfile * Quickly clean log files (assuming you don't want them anymore) >> for file in `find /var/log/ -type f -size +5000k`; do > $file; done * 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 * 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 * 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 * Untar file with absolute pathname to relative location >> pax -r -s ',^/,,' -f file.tar * Print multiline text starting and ending at specific regexps with >> man fetchmail | perl -ne 'undef $/; print $1 if m/^.*?(-k \| --keep.*)-K \| --nokeep.*$/smg' * Open a Remote Desktop (RDP) session with a custom resolution. >> mstsc /w:1500 /h:900 /v:www.example.com * 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; * String Capitalization >> echo "${STRING}" | tr '[A-Z]' '[a-z]' | awk '{print toupper(substr($0,1,1))substr($0,2);}' * vim insert current filename >> :r! echo % * Match non-empty lines >> grep -v "^\W$" <filename> * find large files >> ls -s | sort -nr | more * Create a random file of a specific size >> dd if=/dev/zero of=testfile.txt bs=1M count=10 * 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 * Send multiple attachments using mailx >> (uuencode foo.txt foo.txt; uuencode /etc/passwd passwd.txt)|mailx -s "Pandaren!" someone@cmdfu.com * Extract multiple file in a directory >> for i in *.tar.gz; do tar -xzf $i; done * 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 * I hate `echo X | Y` >> base64 -d <<< * Rsync remote data as root using sudo >> rsync --rsync-path 'sudo rsync' username@source:/folder/ /local/ * find the process that is using a certain port e.g. port 3000 >> lsof -P | grep ':3000' * Check Ram Speed and Type in Linux >> sudo dmidecode --type 17 | more * Grep for word in directory (recursive) >> grep --color=auto -iRnH "$search_word" $directory * List of commands you use most often >> history | awk '{print $2}' | sort | uniq -c | sort -rn | head * Recursively remove .svn directories from the current location >> find . -type d -name '.svn' -print0 | xargs -0 rm -rdf * find process associated with a port >> fuser [portnumber]/[proto] * Get http headers for an url >> curl -I www.commandlinefu.com * copy working directory and compress it on-the-fly while showing >> tar -cf - . | pv -s $(du -sb . | awk '{print $1}') | gzip > out.tgz * Clean your broken terminal >> stty sane * geoip information >> curl -s "http://www.geody.com/geoip.php?ip=$(curl -s icanhazip.com)" | sed '/^IP:/!d;s/<[^>][^>]*>//g' * Unbelievable Shell Colors, Shading, Backgrounds, Effects for >> for c in `seq 0 255`;do t=5;[[ $c -lt 108 ]]&&t=0;for i in `seq $t 5`;do echo -e "\e[0;48;$i;${c}m|| $i:$c `seq -s+0 $(($COLUMNS/2))|tr -d '[0-9]'`\e[0m";done;done * How fast is the connexion to a URL, some stats from curl >> URL="http://www.google.com";curl -L --w "$URL\nDNS %{time_namelookup}s conn %{time_connect}s time %{time_total}s\nSpeed %{speed_download}bps Size %{size_download}bytes\n" -o/dev/null -s $URL * Emulate a dual-screen using vnc >> x2vnc {-west|-east|-north|-south} computer-ip:display-number * Remove the boot loader from a usb stick >> dd if=/dev/zero of=/dev/sdb bs=446 count=1 * Archive every file in /var/logs >> find /var/logs -name * | xargs tar -jcpf logs_`date +%Y-%m-%e`.tar.bz2 * 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 * Remove an old gmetric statistic >> gmetric -n $METRIC_NAME -v foo -t string -d 10 * 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' * Eclipse needs to know the path to the local maven repository. >> mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo * Do a quick check on the harware specifications on a set of Linux >> clear; 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 * Get max number of arguments >> getconf ARG_MAX * 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"' * Shows the torrent file name along with the trackers url >> grep -ao -HP "http://[^/]*/" * * Delete Empty Directories >> find . -type d -exec rmdir {} \; * Convert a videos audio track to ogg vorbis. >> INPUT=<input_video> && ffmpeg -i "$INPUT" -vn -f wav - | oggenc -o ${INPUT%%.*}.ogg - * 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= * covert m4a audio files to wav >> find . -name '*.m4a' | xargs -I audiofile mplayer -ao pcm "audiofile" * How to Find the Block Size >> /sbin/dumpe2fs /dev/hda2 | grep 'Block size' * 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 * alias for etckeeper, to commit changes after moification of etc >> function ec() { ec_var="`pwd`" && cd /etc/ && sudo bzr commit -m "$@" && cd $ec_var; } * Syslog System Reporting in a shell >> tail -f --retry /var/log/syslog /var/log/auth.log | ccze -A * view the system memory in clear text >> hexdump -e '90/1 "%_p" "\n"' /dev/mem | less * prints message in given argument on on center of screen >> function echox { echo `tput cup $(($(tput lines))) $(( ($(tput cols) - $(echo "${#1}"))/2 ))`"$1"`tput cup $(tput lines) $(( $(tput cols)-1 ))`; } * fetch 1600 jokes from robsjokes.com into a single file, which is >> 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 * Rearrange words from a file >> perl -lane 'print "$F[0]:$F[1]:$F[2]"' myfile * Remove unused libs/packages >> aptitude remove $(deborphan) * 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 * Reads in the ~/.Xdefaults >> alias xdef_load='xrdb -merge ~/.Xdefaults' * Search gdb help pages >> gdb command: apropos <keyword> * One liner gdb attach to Acrobat >> (acroread &);sleep 2;gdb /opt/Adobe/Reader8/Reader/intellinux/bin/acroread `pidof ld-linux.so.2` * Convert ip address in hexadecimal >> gethostip 208.69.34.230 -x * 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 * Give information about your graphic chipset >> lshw -C display * Find your graphics chipset >> lspci |grep VGA * Laminate files line by line >> lam -f 1.4 myfile * Convert Raw pictures to jpg >> for img in $( ls *.CR2 ); do convert $img $img.jpg; done * Get a summary of network devices in the system >> $ for i in `ls --color=none /sys/class/net`; do echo "# $i"; sudo ethtool $i | grep -E "Link|Speed" ; done * 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 thread count for process on Solaris >> ps -L -p <pid> | wc -l * Need an ascii art font for you readme text ? >> toilet -f big ReadMe * When feeling boring this command help too >> bb * Start a vnc session on the currently running X session >> x0vnc4server -display :0 -PasswordFile ~/.vnc/passwd * dos2unix >> $ perl -pi -e 's/\r\n/\n/g' <finelame> * Send Disk usage via email >> #!/bin/sh #du.sh i=`hostname -i` df -h > /tmp/space.txt echo "server $i " >> /tmp/space.txt uuencode /tmp/space.txt space.txt | mail -s "HDD usage $i" email@email.com * List installed rpm named and arquitecture. >> rpm -qa --queryformat "%{NAME} %{ARCH}\n" * Execute a command with the last parameter of a previous command >> ls !$ * Number of seconds to certain unix date >> echo $( (( $( (2**31 -1) ) - $(date +%s) )) ) * Get the version of sshd on a remote system >> ssh -vN hostname 2>&1 | grep "remote software version" * log your PC's motherboard and CPU temperature along with the >> 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 * Delete more than one month old thumbnails from home directory >> find ~/.thumbnails/ -type f -atime +30 -print0 | xargs -0 rm * Clean up after improper deletes in subversion >> svn rm `svn status | grep "\!" | cut -c 8-` * 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 * Given NOPASSWD privileges on a remote SSH server, sftp as root >> sftp -s "sudo /usr/lib/sftp-server" user@host * Simple countdown from a given date >> watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l' * Clean the /boot directory >> rpm -q kernel-2* | grep -v $(uname -r) | xargs yum erase -y * Apply all pending updates to Mandriva Linux system (2008.0 and >> urpmi --auto-update --force # apply all pending updates (Mandriva Linux) * Dns zone transfer >> host -la domain.com * Adds characters at the beginning of the name of a file >> rename 's/.*/[it]$&/' *.pdf * Disable all iptables rules without disconnecting yourself >> iptables -F && iptables -X && iptables -P INPUT ACCEPT && iptables -OUTPUT ACCEPT * Show the files that you've modified in an SVN tree >> svn status | egrep '^(M|A)' | egrep -o '[^MA\ ].*$' * 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`' * Show the ordered header line (with field names) of a CSV file >> function headers { head -1 $* | tr ',' '\12' | pr -t -n ; } * A bash function to show the files most recently modified in the >> function t { ls -ltch $* | head -20 ; } * Send an http HEAD request w/curl >> curl -i -X HEAD http://localhost/ * Lists open ports >> netstat -antuwp | egrep "(^[^t])|(^tcp.*LISTEN)" * alias to show my own configured ip >> alias showip="ifconfig eth0 | grep 'inet addr:' | sed 's/.*addr\:\(.*\) Bcast\:.*/\1/'" * do a release upgrade in ubuntu >> do-release-upgrade * List all rpms on system by name, version and release numbers, and >> rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}\n' * Remove leading zeros in multiple columns with sed >> sed 's/\b\(0*\)//g' filename * How to know if your NIC receive link >> watch ethtool eth0 * Strip out time difference entries when verifying rpms on x86_64 >> rpm -Va | grep -v "\.\.\.\.\.\.\.T" * Compare a file with the output of a command or compare the output >> vimdiff foo.c <(bzr cat -r revno:-2 foo.c) * host - DNS lookup utility >> host google.com * list files not owned by any user or group >> find / -nouser -o -nogroup -print * Kill all processes that don't belong to root/force logoff >> for i in $(pgrep -v -u root);do kill -9 $i;done * Display an updating clock in sh variants >> while true; do date; sleep 1; done * Zip all subdirectories into zipfiles >> for f in `find . \( ! -name . -prune \) -type d -print`; do zip $f.zip $f; done * Replace words with sed >> sed /BEGIN/,/END/s/xxx/yyy/g input.txt * shell alternative to 'basename' >> echo ${file##*/} * Revert back all files currently checked out by Perforce SCM for >> ropened='p4 opened | awk -F# "{print \$1}" | p4 -x - revert' * Print the list of all files checked out by Perforce SCM >> alias opened='p4 opened | awk -F# "{print \$1}"' * Alias for displaying a process tree nicely >> alias pst='pstree -Alpha' * How many world writeable files on your system? (Mandriva Linux >> # wc -l /var/log/security/writable.today * Resets terminal in its original state >> ^[c (ctrl-v esc-c) * set timestamp in exif of a image >> exiv2 -M"set Exif.Photo.DateTimeOriginal `date "+%Y:%m:%d %H:%M:%S"`" filename.jpg * Remove/replace newline characters. >> sed ':a;N;$!ba;s/\n/ /g' * 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")}' * Copy all files. All normal files, all hidden files and all files >> cp ./* .[!.]* ..?* /path/to/dir * 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 * View the list of files and directories in an archive with less. >> less file.tar.gz * Generate secure password to userwith chpasswd >> echo "encryptedpassword"|openssl passwd -1 -stdin * Edit the /etc/sudoers config file the right way. >> visudo * package most recent files in project >> find ~/project -mtime -1 -type f -print | tar jcvf myfiles.tar.bz2 -T - * ls to show hidden file, but not . or .. >> ls -A * 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/</UNAUTHORIZED IP -/g' * 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; } * AIX: Determine what filesets are missing to reach a TL >> instfix -icq | grep 5300-07_AIX_ML | grep ":-:" * Extract the contents of an RPM package to your current directory >> rpm2cpio /path/to/file.rpm | cpio -i -d * SVN Clean >> svn status | grep ^? | awk '{print $2}' | xargs rm -rf * Use the page up key to complete the command. >> echo "\"\e[5~\": history-search-backward" >> ~/.inputrc * Generate a specification file for file integrity scanning. >> mtree -c -K sha256digest -X mtree.exclude -p /path > host.mtree * Show hidden files in OS X >> defaults write com.apple.Finder AppleShowAllFiles TRUE * Diff with colour highlighting >> svn diff ARGUMENTS_FOR_DIFF | source-highlight --out-format=esc --src-lang=diff * 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 * Current sub-folders sizes >> du -sh * * Make a DVD ISO Image from a VIDEO_TS folder on MacOSX >> hdiutil makehybrid -udf -udf-volume-name DVD_NAME -o MY_DVD.iso /path/ * Summarize size of all files of given type in all subdirectories >> SUM=0; for FILESIZE in `find /tmp -type f -iname \*pdf -exec du -b {} * Open a file at the specified line >> emacs +400 code.py * Alias to edit and source your .bashrc file >> alias vb='vim ~/.bashrc; source ~/.bashrc' * Check the last 15 package operations (on yum systems) >> tail -n 15 /var/log/yum.log | tac * 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}') * Generate the CPU utilization report >> sar -u 2 5 * cp the file >> cp /some/path/to/myfile{,.back} * Remount root in read-write mode. >> sudo mount -o remount,rw / * search the pattern from bzip2'ed file >> bzgrep -i "pattern" pattern.bz2 * Add new files/directory to subversion repository >> svn status | grep '^\?' | sed -e 's/^\?//g' | xargs svn add * exclude file(s) from rsync >> rsync -vazuK --exclude "*.mp3" --exclude "*.svn*" * user@host:/path * 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' * Parse tektronic csv files >> awk 'BEGIN {FS=","} {loc = $4, val=$5; getline < "f0001ch1.csv"; print loc,val,$5}' f0001ch2.csv > data * find distro name / release version >> $ cat /etc/*-release * search installed files of package, that doesn't remember his name >> rpm -qa | grep PACKAGENAME | xargs rpm -q --filesbypkg * Allows incoming traffic from specific IP address to port 80 >> sudo ufw allow proto tcp from 1.2.3.4 to any port 80 * Send current job to the background >> ^Z then bg * Add all not commited files to svn >> svn st | grep ^? | xargs svn add 2> /dev/null * Grep the process excluding the grep itself. >> ps -ef | grep [t]clsh * 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} * 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 * catch all the txt files into a start_dir tree and copy them into >> find start_dir -name *.txt | xargs -J % cp % end_dir/ * opening your helper script without knowing the path (zsh) >> less =rcsyslog * Easily move around many directories >> a() { alias $1=cd\ $PWD; } * moreplayingaround >> curl -s -u username:passwd http://twitter.com/statuses/friends_timeline.rss|grep title|sed -ne 's/<\/*title>//gp' |festival --tts * grep or >> egrep 'string1|string2' file * Remove all directories less than 1 MB in size in or below current >> find . -type d -execdir du -sh '{}' ';' | grep -E "[0-9]+K" | sed 's/^[0-9\.]\+K[\t ]\+//' | tr "\n" "\0" | xargs -0 rm -rf * pushd rotates the stack so that the second directory comes at the >> pushd +2; pushd -2 * 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 * A simple X11 tea timer >> $(STEEP=300; sleep $STEEP; xmessage "Your tea is done") & * send files via ssh-xfer >> cat somefilehere.txt | ssh-xfer nametocallfile.txt - * Remove blank lines from a file >> grep -v "^$" file * Runs a command without hangups. >> nohup <command> & * Add new file under svn version control. >> svn st | grep ^\? | awk '{print $2}' | xargs svn add * Show some details of recent Leopard Time Machine activity - shell: >> syslog -F '$Time $Message' -k Sender /System/Library/CoreServices/backupd -k Time ge -72h | tail -n 30 * Update obsolete CVS Root files >> find cvsdir -name Root -exec sed -i 's/oldserver/newserver/' {} \; * ps grep with header >> psg () { ps auxwww | egrep "$1|PID" | grep -v grep } * Simple calculator >> while true; do read i; echo $[$i]; done * Print total size of specified files and subdirectories >> du -sk * | awk '{print $1} END {print "[+z1<y]sy\nlyx\np"}' | dc * List all files fred* unless in a junk directory >> ls **/fred*~*junk*/* * psg (ps grep) function if you don't have pgrep or don't know how >> 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)" ; } * 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[@]} )) ]}\"" * Paged, colored svn diff >> svn diff $* | colordiff | less -r * Convert AVI to WMV >> ffmpeg -i movie.avi -s 320x240 -b 1000k -vcodec wmv2 -ar 44100 -ab 56000 -ac 2 -y movie.wmv * set open firmware password command mode >> /usr/local/bin/OFPW -mode 1 * what the free memory grow or shink >> watch -d "free -mt" * Add a newline to the end of a cpp file >> find . -iname "*.cpp" -exec perl -ni -e 'chomp; print "$_\n"' {} \; * View video cam from remote machine during ssh session >> xawtv -remote -bpp 16 -noxv-video -geometry 160x120 -device /dev/video0 * Disable Mac OS X Dashboard >> defaults write com.apple.dashboard mcx-disabled -boolean YES; killall * Delete all ".svn" directories from current path (recursive) >> find . -name ".svn" -exec rm -rf {} \; * Sort files by date >> ls -lrt * Exit shell faster >> ^D * 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 * recursively change file name extensions >> find . -type f -name \*.c | while read f; do mv $f "`basename $f .c`".C; done * Generate a random number in a range >> START=20; END=50 echo $(($START+(`od -An -N2 -i /dev/random`)%($END-$START+1))) * Recall last argument of previous command >> cd !$ * See which files differ in a diff >> diff dir1 dir2 | diffstat * Stripping ^M at end of each line for files >> perl -pi -e 's:^V^M::g' <filenames> * Clean all .pyc files from current project. It cleans all the files >> find . -name "*.pyc" -exec rm {} \; * Locate Hacked Files and Dump. >> find . -type f -name '*.html' -exec grep -H HACKED {} \; > hacklog.txt * search into contents of python module >> srchpymod() { python -c "import $1; print filter(lambda x: x.find('$2') >= 0, dir($1))"; }; * Make a pipe organ sound using XMMS and Python >> xmms `python -c "print \"tone://\" + \";\".join([str(22*(2**x)) for x in range(9)])"` * exim statistics about mails from queue >> exim -bp | exiqsumm -c * Command line invocation of ImageMagick to resize a file >> convert panorama_rainbow_2005.jpg -resize 40% panorama_rainbow_compress.jpg * 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 * git log1 alias >> git config --global alias.log1 "log --pretty=oneline --abbrev-commit" * Activate the mandatory proxy under ubuntu >> gconftool-2 --set "/system/http_proxy/use_http_proxy" --type boolean true * hours before the time()==1234567890 >> echo $(( (1234567890 - `date -u +\%s`) / 60 / 60 )) * Set your computer's clock, using HTTP and HTP (HTTP Time >> htpdate -P proxy www.google.com www.yahoo.com www.commandlinefu.com * List all Windows services on the command line >> sc queryex type= service state= all | find "_NAME" * teatimer >> sleep 3m; play bigben.wav * bash chop >> alias chop="tr -d '\r\n'" * Enable Basic Security Mode (BSM) Auditing --Solaris >> /etc/security/bsmconv * Copy the full path of a file to the clipboard (requires xclip or >> >realpath ./somefile.c | xclip -selection c * alias dir to ls -al >> alias dir="ls -al" * @mail.com by adding the line in list.txt >> while read line; do echo -e "$line@mail.com"; done < list.txt * Resize all JPEGs in a directory >> mogrify -resize 1024 *.jpg * svn diff ignore whitespace >> svn diff --diff-cmd diff -x -uw /path/to/file * Remove CVS root files under current directory >> find . -name Root -print | xargs rm -f * 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' * Checks the syntax of all PHP files in and below the current >> find . -name "*.php" -exec php -l {} \; | sed -e "/^No syntax/d" * Set date and time >> sudo date -s "26 OCT 2008 19:30:00" * Erase CD RW >> wodim -v dev=/dev/dvd -blank=fast * Convert from a decimal number to a binary number >> echo 'ibase=10; obase=2; 127' | bc * git branch point >> git merge-base branch1 branch2 * git merge --dry-run >> git merge --no-commit --no-ff * Format a password file for John the Ripper from Cisco configs >> sed -n 's/[ :]/_/g; s/^\(.\{1,\}\)_5_\($1$[$./0-9A-Za-z]\{27,31\}\)_*$/\1:\2/p' < cisco-device-config > passwd * (tcsh alias)Reverse an IPv4 address. It is useful to looking the >> alias ip4rev "echo \!* | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1/'" * Convert HTML file into valid XML >> tidy -asxhtml -numeric < index.html > index.xml * 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 * Quick aliases for going up a directory tree >> alias ::='cd ../../' * displays comments from random jpeg files. >> find ~/random_jpegs/folder -name "*.jpg" -exec rdjpgcom {} \; * Change size of lots of image files. File names are read from a >> ( while read File; do mogrify -resize 1024 -quality 96 $File; done ) < filelist * List shared libraries recognized by the system >> ldconfig -p | grep <somenewlib.so> * check rpm pkg content w/o installation >> rpm -qlp <package.rpm> * Switch on eeepc camera >> sudo echo 1 > /proc/acpi/asus/camera * grep selectively >> find /path -name \*.php -user nobody -exec grep -nH whatever {} \; * find out about a process >> cat /proc/<PID>/environ * 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 * file sizes of current directory >> ls -la | awk '{print $5, " " ,$9}' | sort -rn * move files without actually touching them >> cd /some/directory \&\& tar cf - | cd /some/directory \&\& tar xvf - */ * Using psnup to get two pages per page >> psnup -2 file.ps | lpr * printing with psnup >> psnup -4 -pa4 -Pa4 file.ps file2.ps * to get how many users logged in and logged out and how many times >> last | awk '$1!~/wtmp/{logs[$1]++}END{for (i in logs) print i, logs[i]}' * To get how many users logged in and logged out and how many times >> last | awk '{ print $1 }' | sort | uniq -c | grep -v wtmp * To get the different name field nformation on rpm packages >> rpm -qa --qf '%{name}' * To get the latest information on rpm packages >> rpm -qa --last * Show all local disk and UFS mounts on Solaris >> df -kFufs * Add audio CD to xmms2 playlist >> xmms2 addpls cdda:// * View latest apache access log >> view `ls -1 access_log.* | tail -n 1` * Serve one or more git repositories >> git daemon --reuseaddr --verbose --export-all --base-path=/parent/of/bare/git/repos * change to the selected directory for zsh users >> alias scd='dirs -v; echo -n "select number: "; read newdir; cd -"$newdir"' * Perl check if library is installed >> perl -e "use SOAP::Lite" * encode HTML entities >> perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txt * Force file system check >> touch /forcefsk * Show all occurences of STRING with filename and line number for >> find DIR -name "FILE" -exec grep -IHn STRING {} \; * find and kill a zombie process >> kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'` * make non-printable characters visible >> cat -A * quick integer CPU benchmark >> echo '2^2^20' | time bc > /dev/null * Get all IPs via ifconfig >> ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1' * Get all these commands in a text file with description. >> for x in `jot - 0 2400 25`; do curl "http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$ x" ; done > commandlinefu.txt * Get all IPs via ifconfig >> ifconfig | perl -nle'/dr:(\S+)/ && print $1' * Show git branches by date - useful for showing active branches >> for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r * Set your profile so that you resume or start a screen session on >> echo "screen -DR" >> ~/.bash_profile * Purge configuration files of removed packages on debian based >> sudo aptitude purge `dpkg --get-selections | grep deinstall | awk '{print $1}'` * Grep colorized >> grep -i --color=auto * Diff files on two remote hosts. >> diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list) * beep when a server goes offline >> while true; do [ "$(ping -c1W1w1 server-or-ip.com | awk '/received/ {print $4}')" != 1 ] && beep; sleep 1; done * Cut out a piece of film from a file. Choose an arbitrary length >> ffmpeg -vcodec copy -acodec copy -i orginalfile -ss 00:01:30 -t 0:0:20 newfile * Run the Firefox Profile Manager >> firefox -no-remote -P * Append stdout and stderr to a file, and print stderr to the screen >> somecommand 2>&1 >> logfile | tee -a logfile * Delete the specified line >> sed -i 8d ~/.ssh/known_hosts * git remove files which have been deleted >> git rm $(git ls-files --deleted) * Pipe STDOUT to vim >> tail -1000 /some/file | vim - * Calculates the date 2 weeks ago from Saturday the specified >> date -d '2 weeks ago Saturday' +%Y-%m-%d * Add your public SSH key to a server in one command >> cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys' * pattern match in awk - no grep >> awk '/pattern1/ && /pattern2/ && !/pattern3/ {print}' * Echo the latest commands from commandlinefu on the console >> wget -O - http://www.commandlinefu.com/commands/browse/rss 2>/dev/null | awk '/\s*<title/ {z=match($0, /CDATA\[([^\]]*)\]/, b);print b[1]} /\s*<description/ {c=match($0, /code>(.*)<\/code>/, d);print d[1]"\n"} ' * scping files with streamlines compression (tar gzip) >> tar czv file1 file2 folder1 | ssh user@server tar zxv -C /destination * Optimal way of deleting huge numbers of files >> find /path/to/dir -type f -print0 | xargs -0 rm * convert vdi to vmdk (virtualbox hard disk conversion to vmware >> VBoxManage internalcommands converttoraw winxp.vdi winxp.raw && qemu-img convert -O vmdk winxp.raw winxp.vmdk && rm winxp.raw * Kill processes that have been running for more than a week >> find /proc -user myuser -maxdepth 1 -type d -mtime +7 -exec basename {} \; | xargs kill -9 * Change user, assume environment, stay in current dir >> su -- user * List Network Tools in Linux >> apropos network |more * Search filenames with given pattern; each one is transfered via >> 'ls -1 *<pattern>* | while read file; do scp $file user@host:/path/; if * JVM Garbage Collector Stats >> jstat -gc [jvmpid] * Convert Windows/DOS Text Files to Unix >> dos2unix dostxt unixtxt * Reset the time stamps on a file >> touch -acm yyyymmddhhMM.ss [file] * Convert PDFLaTeX PDF to Illustrator-usable EPS >> gs -dNOCACHE -dNOPAUSE -dBATCH -dSAFER -sDEVICE=epswrite -dEPSCrop -sOutputFile=out.eps in.pdf * List files in an RPM package >> rpm --query --filesbypackage [packagename] * List RPM packages installed in current tree >> find $PWD -exec rpm --query -f {} \; | sort -u | grep -v "not owned" * See whether your compiled Apache is prefork or worker MPM >> /usr/sbin/httpd -l * Rotate the X screen via xrandr >> xrandr --output [youroutput] --rotate [right|left|normal] -d [yourdisplay] * Customizable Search Context >> echo -n search\>\ ; read SEARCH_STRING && sed -n "/$SEARCH_STRING/{n;p;n;p;n;p;q}" [file-to-search] * ps with parent/child process tree >> ps auxf * Create files of arbitrary size in Windows >> fsutil file createnew FILENAME filesize(inbytes) * Convert an ssh2 public key to openssh format >> ssh-keygen -i -f $sshkeysfile >> authorized_keys * (Inside of a shell script) Make executable a BeanShell script >> ///bin/true; exec java bsh.Interpreter "$0" "$@" * list process ids for given program >> pidof httpd * Create etags file of .c, .cpp, and .h files in all subdirectories >> find . -regex ".*\.[cChH]\(pp\)?" -print | etags - * simple perl global search and replace in files >> perl -pi -e 's/localhost/replacementhost/g' *.php * 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)}' * view all lines without comments. >> grep -v "^#" file.txt | more * search for files or directories, then show a sorted list >> for i in $(locate your_search_phrase); do dirname $i; done | sort | uniq * List all packages with no dependencies (yum based system) >> package-cleanup --leaves --all * Find the process ID of such program: >> pgrep xterm * Link all the files in this directory to that directory >> cd /this/directory; for f in *; do ln -s `pwd`/$f /that/directory; done * cpuinfo >> cat /proc/cpuinfo * look for a header reference in a shared library >> strings libc-2.2.5.so | grep stat.h * Shows the largest files in your archives >> tar -tvjf backup.tar.bz2 | sort -nrk 3 | head * Start urxvt and do whatever is needed to open the screen session >> screen -ls | grep main && urxvt -name screen -e screen -x main || urxvt -name screen -e screen -R -S main * SSH to a machine's internet address if it is not present on your >> ping localip -c 1 -W 1 &> /dev/null && ssh localip || ssh globalip * infile search and replace on N files >> perl -pi -e's/foo/bar/g' file1 file2 fileN * Retrieve a list of all webpages on a site >> URL=www.example.com && wget -rq --spider --force-html "http://$URL" && find $URL -type d > url-list.txt && rm -rf $URL * Find the files that contain a certain term >> find /path/to/dir -type f -exec grep \-H "search term" {} \; * Analyse a PHP file for instantations and static calls >> grep -o "\(new \(\w\+\)\|\w\+::\)" file.php | sed 's/new \|:://' | sort | uniq -c | sort * 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 - * Print a row of 50 hyphens >> printf "%50s\n"|tr ' ' - * analyze traffic remotely over ssh w/ wireshark >> sudo ssh -Y remoteuser@remotehost sudo wireshark * Get name of first configured interface >> ifconfig | grep -B 1 "inet addr:" | head -1 | cut -d" " -f1 * Empty a file >> truncate foobar.txt * Find all uses of PHP constants in a set of files >> $class=ExampleClass; $path=src; for constant in `grep ' const ' $class.php | awk '{print $2;}'`; do grep -r "$class::$constant" $path; done * Copy a file over SSH without SCP >> uuencode -m <filename> <filename> * Tar - Compress by excluding folders >> tar -cvf /path/dir.tar /path/dir* --exclude "/path/dir/name" --exclude "/path/dir/opt" * Print line numbers >> sed = <file> | sed 'N;s/\n/\t/' * prints line numbers >> sed '/./=' infile | sed '/^/N; s/\n/ /' * show your locale language keyboard setting >> locale | grep LANG= * Format a flooppy with windows compatible disk >> mformat -f 1440 A: * mount a msdos formated floppy disk >> mount -t msdos /dev/fd0 /mnt/floppy * prints line numbers >> while read str; do echo "$((++i)) - $str"; done < infile * prints line numbers >> cat infile | while read str; do echo "$((++i)) - $str" ; done; * prints line numbers >> grep -n . datafile ; * prints line numbers >> perl -ne 'print "$. - $_"' infile.txt * Show Network IP and Subnet >> IP=`ifconfig eth0 | grep "inet addr:" | ips |cut -d ":" -f 2 | cut -d " " -f 1`;SUBNET=`ifconfig eth0 | grep "inet addr:" | ips |cut -d ":" -f 3 | cut -d " " -f 1`;RANGE=`ipcalc $IP/$SUBNET | grep "Network:" | cut -d ' ' -f 4`;echo $RANGE * ruby one-liner to get the current week number >> ruby -e 'require "date"; puts DateTime.now.cweek' * Match a URL >> echo "(Something like http://foo.com/blah_blah)" | awk '{for(i=1;i<=NF;i++){if($i~/^(http|ftp):\/\//)print $i}}' * List files that DO NOT match a pattern >> printf "%s\n" !(pattern) ## ksh, or bash with shopt -s extglob * Mount a Windows share on the local network (Ubuntu) with user >> sudo mount -t cifs -o credentials=/path/to/credenials //hostname/sharename /mount/point * Simple read and write test with Iozone >> iozone -s 2g -r 64 -i 0 -i 1 -t 1 * kalarm 1 per minute simplest e-mail beacom for Geovision >> curl http://www.spam.la/?f=sender | grep secs| awk '{print; exit}' | osd_cat -i 40 -d 30 -l 2 * Show a script or config file without comments >> sed -e '/^[[:blank:]]*#/d; s/[[:blank:]][[:blank:]]*#.*//' -e '/^$/d' -e '/^\/\/.*/d' -e '/^\/\*/d;/^ \* /d;/^ \*\//d' /a/file/with/comments * Get your external IP address >> exec 3<>/dev/tcp/whatismyip.com/80; echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" >&3; a=( $(cat <&3) ); echo ${a[${#a[*]}-1]}; * What is my ip? >> alias whatismyip="wget -q -O - http://whatismyip.com/automation/n09230945.asp" * Get a text on a position on the file and store in a variable >> TIMEUNIT=$(awk '/timescale/{print NR}' a) * Useful if you need to see compiler errors while edit a code >> CRTL + L * 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"; } * What is my ip? >> w3m http://amit-agarwal.co.in/mystuff/getip_txt.php will return the ip in text format. * What is my ip? >> w3m miip.cl | grep ip * Show current folder permission from /, useful for debugging ssh >> 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}}' * 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 * Transforms a file to all uppercase. >> perl -i -ne 'print uc $_' $1 * search for a TAB characters in a text file >> grep $'\t' file.txt * List only the directories >> ls -F|grep / * Make perl crash >> perl -e '$x = []; push @$x, eval { $x = 1; return $x = 1; }' * List open TCP/UDP ports >> ss -ltu * 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" } * shell function to diff two zip files. >> unzip_diff () { dir1="/tmp/diff/$1"; dir2="/tmp/diff/$2"; mkdir -p $dir1 $dir2; unzip $1 -d $dir1>/dev/null; unzip $2 -d $dir2>/dev/null; diff -q $dir1 $dir2; rm -rf /tmp/diff ; } * change newlines to spaces (or commas or whatever). Acts as a >> alias nl2space="perl -ne 'push @F, \$_; END { chomp @F; print join(qq{ }, @F) , qq{\n};}' " * List dot-files and dirs, but not "." and ".." >> ls .[!.]* * get Hong Kong weather infomation from HK Observatory >> wget -q -O - 'http://wap.weather.gov.hk/' | sed -r 's/<[^>]+>//g;/^UV/q' | grep -v '^$' * List all text files (exclude binary files) >> find . -type f -exec file {} \; | grep ".*: .* text" | cut -f 1 -d : * 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;" * dolphins on the desktop (compiz) >> xwinwrap -ni -argb -fs -s -st -sp -nf -b -- /usr/libexec/xscreensaver/atlantis -count 20 -window-id WID & * Show apps that use internet connection at the moment. >> netstat -lantp | grep -i establ | awk -F/ '{print $2}' | uniq | sort * 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])$' * regex to match an ip >> perl -wlne 'print $1 if * List debian package installed by size >> wajig large * get users process list >> ps -u<user> * Delete all but the latest 5 files >> ls -t | awk 'NR>5 {system("rm \"" $0 "\"")}' * Open files of the same name in TextMate >> mate - `find . -name 'filename'` * Check variable has been set >> : ${VAR:?unset variable} * view file content with echo >> echo "$(</etc/issue)" * search for a file in PATH >> which <filename> * 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 * 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 ; } * Hexadecimal dump of a file, pipe, or anything >> cat testfile | hexdump -C * Capitalize the word with dd >> echo capitalize | { dd bs=1 count=1 conv=ucase 2> /dev/null; cat ;} * Make a statistic about the lines of code >> find . -type f -name '*.c' -exec wc -l {} \; | awk '{sum+=$1} END {print sum}' * show all upd tcp an icmp traffic but ssh >> tcpdump -n -v tcp or udp or icmp and not port 22 * Edit all files found having a specific string found by grep >> find . -type f -exec grep -qi 'foo' {} \; -print0 | xargs -0 vim * Edit all files found having a specific string found by grep >> find . -exec grep foobar /dev/null {} \; | awk -F: '{print $1}' | xargs vi * 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 * Sort a character string >> echo sortmeplease|sed 's/./&\n/g'|sort|tr -d '\n' * Sort a character string >> echo sortmeplease | awk '{l=split($1,a,"");asort(a);while(x<=l){printf "%s",a[x];x++ }print "";}' * Today's date on a yearly calendar... >> cal -y * 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 * Print all fields in a file/output from field N to the end of the >> awk '{print substr($0, index($0,$N))}' * Install not signed packeges with yum >> yum --nogpgcheck install "examplePackage" * Search gpg keys from commandline >> gpg --search-keys * Check the backdoors and security.chkrootkit is a tool to locally >> chkrootkit -x | less * Quick system hardware overview >> curl http://flip-edesign.com/scripts/system_info | bash * To find how Apache has been compiled from commandline >> httpd2 -V * Get the information about the Apache loaded modules from command >> httpd2 -M * How to check webserver by Nikto >> nikto.pl -h yourwebserver * Use dig instead of nslookup >> dig google.com * Emulate sleep in DOS/BAT >> ping -n 1 -w 10000 224.0.0.0 * Restart nautilus >> nautilus -q * Day Date Time> Instead of $ or # at the terminal >> export PS1='\D{%a %D %T}> ' * Remove ^M characters at end of lines in vi >> :%s/^V^M//g * 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 * Create a multi-part RAR archive >> rar a -v[SIZE] [archivename] [files] * omit grep >> ps aux | grep [c]ommandname * avi to ogv (Ogg Theora) >> ffmpeg2theora input.avi * Generate a Universally Unique Identifier (UUID) >> uuid * Find the process you are looking for minus the grepped one >> ps aux | grep process-name | grep -v "grep" * 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 * Get internal and external IP addresses >> ips(){ for if in ${1:-$(ip link list|grep '^.: '|cut -d\ -f2|cut -d: -f1)};do cur=$(ifconfig $if|grep "inet addr"|sed 's/.*inet addr:\([0-9\.]*\).*/\1/g');printf '%-5s%-15s%-15s\n' $if $cur $(nc -s $cur sine.cluenet.org 128 2>/dev/null||echo $cur);done;} * Get your external IP address >> wget -O - http://checkip.dyndns.org|sed 's/[^0-9.]//g' * Get your external IP address >> fetch -q -o - http://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' * Get your external IP address >> html2text http://checkip.dyndns.org | grep -i 'Current IP Address:'|cut * command to display info about the core specified >> schedtool 1 * Play music from pure data >> sudo cat /usr/share/icons/*/*/* > /dev/dsp * 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 * netstat to daemons >> netstat -tanp | grep -i listen * save a manpage to plaintext file >> man -P cat ls > man_ls.txt * Recursive replace of directory and file names in the current >> find -name '*oldname*' -print0 | xargs -0 rename 's/oldname/newname/' * AND search using grep to search for multiple strings. >> grep "string1.*string2.*string3" text.log * Open windows executable, file, or folder from cygwin terminal >> explorer $( cygpath "/path/to/file_or_exe" -w ) * Read just the IP address of a device >> /sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " " |egrep -v "^$" * Read just the IP address of a device >> /sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " " * Quick alias for case-insensitive grep >> alias grip="grep -i" * View open file descriptors for a process. >> lsof -p <process_id> | wc -l * Change password in list of xml files with for and sed >> for i in *.xml; do sed -i 's/foo/bar/g' "$i"; done * recursive grep of text files >> grep -Ir foo * * Back up a PLESK Installation >> /opt/psa/bin/pleskbackup server -v --output-file=plesk_server.bak * Uninstall all MacPorts that are no longer active >> sudo port installed | grep -v 'active\|The' | xargs sudo port uninstall * Puts every word from a file into a new line >> < <infile> tr ' \t' '\n' | tr -s '\n' > <outfile> * 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/ $//" * remove unnecessary architecture code from Mac OS X Universal >> ditto --arch i386 doubleTwist.app doubleTwist_i386.app * Mac OS X (laptops ??) only : control hibernation state more >> sudo pmset -a hibernatemode 1 * 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 * retrieve GMT time from websites ( generally accruate ) >> w3m -dump_head www.fiat.com | awk '/Date+/{print $6, $7}' * Show display type >> ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | * 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 * display only tcp >> netstat -4tnape * Find the full path of an already running process >> readlink -f /proc/<pid>/cmdline * create an mp3 with variable bitrate >> lame -h -V 6 track9.wav track9.mp3 * Alternative way to get the root directory size in megabytes >> expr $(fdisk -s ` grep ' / ' /etc/mtab |cut -d " " -f1`) / 1024 * List files recursively sorted by modified time >> find /home/fizz -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort * Unix security checker >> tiger * 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 * display portion of a file >> cat -n FILE | grep -C3 "^[[:blank:]]\{1,5\}NUMBER[[:blank:]]" * quick and easy way of validating a date format of yyyy-mm-dd and >> echo 2006-10-10 | grep -c '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' * Encrypted Tarballs >> tar -cf - folder/ | gpg -c > folder.tpg * Clears Firefox` cache without clicking around >> rm_cache() { rm -f $HOME/.mozilla/firefox/<profile>/Cache/* }; alias rmcache='rm_cache' * Generate padded numbers 001 002 ... 100 >> echo 00{1..9} 0{10..99} 100 * Expand shell variables in sed scripts >> expanded_script=$(eval "echo \"$(cat ${sed_script_file})\"") && sed -e "${expanded_script}" your_input_file * 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 * 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' * Sed file spacing >> sed G * Retrieve Plesk Admin Password >> cat /etc/psa/.psa.shadow * 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/ * set open firmware password command mode to require password to >> /usr/local/bin/OFPW -mode 1 * Sets OpenFirmware pasword on a mac >> /usr/local/bin/OFPW -pass thepassword * 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 * Precide a bunch of files with a number in a pattern for example >> i=10;for o in *.mp3; do i=$(printf "%02d" $i); mv $o $i$o; ((i = $i + 2)); done * Remove blank lines from a file >> sed -i.bak '/^[[:space:]]*$/d' file_name * Find all python modules that use the math module >> find . -name "*.py" -exec grep -n -H -E "^(import|from) math" {} \; * Dump HTTP header using lynx or w3m >> lynx -dump -head http://www.example.com/ * Change all instances of a word in all files in the current >> perl -pi -e 's/foo/bar/g' $(grep -rl foo ./*) * Change all instances of a word in all files in the current >> perl -pi -e 's/foo/bar/g' $(grep -l foo ./*) * Rename *.MP3 *.Mp3 *.mP3 etc.. to *.mp3. >> find ./ -iname "*.mp3" -type f -printf "mv '%p' '%p'\n" | sed -e "s/mp3'$/mp3'/I" | sh * Grab your bibtex file from CiteULike. >> curl -o <bibliography> "http://www.citeulike.org/bibtex/user/<user>" * 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`' * print the date of the unix epoch in a human readable form using >> perl -e 'print scalar localtime $ARGV[0],"\n" ' epoch * Snmpwalk a hosts's entire OID tree with SNMP V2 >> snmpwalk -v2c -c <community> -m ALL <HOST_IP> . * List nearbies >> /usr/sbin/arp -i eth0 | awk '{print $3}' | sed 1d * Find the median file modification time of files in a directory >> date -d "@$(find dir -type f -printf '%C@\n' | sort -n | sed -n "$(($(find dir -type f | wc -l)/2))p")" +%F * Quick alias for playing music. >> alias mux='clear && cd ~/Music/ && ls && echo -n "File> " && read msi && mplayer ~/Music/$msi' * Enable V4l2 Webcams >> gst-launch v4l2src * for loop, counting forward for backward >> for i in {1..15}; do echo $i; done * Display laptop battery information >> cat /proc/acpi/battery/BAT1/info * 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 * Store mp3 playlist on variable and play with mpg123 >> PLAYLIST=$(ls -1) ; mpg123 -C $PLAYLIST * Using awk to sum/count a column of numbers. >> cat count.txt | awk '{ sum+=$1} END {print sum}' * Show amigable path >> alias path='echo $PATH | tr ":" "\n"' * SVN Add Recursively >> svn status | grep "^\?" | awk '{print $2}' | xargs svn add * Singularize all files in a directory >> for x in *s.yml; do mv $x `echo $x | sed 's/s\.yml/\.yml/'`; done * Activate on-the-fly GTK accels >> gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels true * 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) }' * Run a complete update unattended on Debian based GNU/Linux >> sudo apt-get update && sudo apt-get dist-upgrade -y * Log output from a cronjob to a file, but also e-mail if a string >> some_cronjobed_script.sh 2>&1 | tee -a output.log | grep -C 1000 ERROR * Read the Useless Use of Cat Awards page >> elinks http://partmaps.org/era/unix/award.html * Traffic stat on ethernet interface >> ethtool -S eth0 * know which version of the program is installed on your Debian and >> aptitude show $PROGRAM | grep Vers * sending message to a logined user of group >> write user anytext * Show top-level subdirectories (zsh) >> ls -ld *(/) * Toggle cdrom device >> eject -T [cdrom_device] * Filtering IP address from ifconfig usefule in scripts >> IPADDR=`ifconfig eth0 | grep -i inet | awk -F: '{print $2}'| awk '{print $1}'` * ps -ef | grep PROCESS | grep -v grep | awk '{print $2}' | xargs >> ps -ef | grep PROCESS | grep -v grep | awk '{print $2}' | xargs kill -9 * 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 } * quickly show me interesting data about my processes >> alias mine='ps xco pid,command,%cpu,%mem,state' * 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 * top ten of biggest files/dirs in $PWD >> du -sm *|sort -rn|head -10 * Loopback mount .iso on FreeBSD >> mount -t cd9660 /dev/`mdconfig -a -t vnode -f discimg.iso` /cdrom * Recursively delete .svn folders >> find . -name .svn | xargs rm -rf * Files modified today >> ls *(m-1) * webcam player in ascii art >> gst-launch v4l2src ! aasink * 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) * HDD Performance Read Test >> dd if=10gb of=/dev/zero bs=1M count=10240 * Receive, sign and send GPG key id >> caff <keyid> * Put the wireless card into monitor mode >> airmon-ng start <interface> <channel> * Uncompress a directory full of tarred files (*.gz) >> for i in *.tar.gz *.tgz; do tar -zxvf $i; done * [WinXP] Convert FAT32 Hard Drive to NTFS without losing all data >> CONVERT D: /FS:NTFS * Remap "New Folder" to Command+N, "New Finder Window" to >> defaults write com.apple.finder NSUserKeyEquivalents -dict 'New Finder Window' '@$N' 'New Folder' '@N'; killall Finder * cat ~/.ssh/id_rsa.pub | ssh user@site.com "cat - >> >> concatenate local RSA to remote machine's authorized_keys * Ultimate current directory usage command >> ncdu * Analyze awk fields >> awk '{print NR": "$0; for(i=1;i<=NF;++i)print "\t"i": "$i}' * Twitter update from terminal (pok3's snipts ?) >> curl -u YourUsername:YourPassword -d status="Your status message go here" http://twitter.com/statuses/update.xml * VIM: Replace a string with an incrementing number between marks 'a >> :let i=0 | 'a,'bg/ZZZZ/s/ZZZZ/\=i/ | let i=i+1 * Multiple SSH Tunnels >> ssh -L :: -L :: @ * Run a command, store the output in a pastebin on the internet and >> ls | curl -F 'sprunge=<-' http://sprunge.us | xclip * find files containing text >> grep -lir "some text" * * wrap long lines of a text >> fold -s -w 90 file.txt * Create directory named after current date >> mkdir $(date +%Y%m%d) * Given process ID print its environment variables >> sed 's/\o0/\n/g' /proc/INSERT_PID_HERE/environ * Monitor dynamic changes in the dmesg log. >> watch "dmesg |tail -15" * Monitor TCP opened connections >> watch -n 1 "netstat -tpanl | grep ESTABLISHED" * Pause Current Thread >> ctrl-z * quickly change all .html extensions on files in folder to .htm >> for i in *.html ; do mv $i ${i%.html}.htm ; done * Sort dotted quads >> sort -nt . -k 1,1 -k 2,2 -k 3,3 -k 4,4 * Find recursively, from current directory down, files and >> find ./ -name '*' -exec rename 's/\s+/_/g' {} \; * Another Curl your IP command >> curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g' * count IPv4 connections per IP >> netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | sed s/::ffff:// | cut -d: -f1 | sort | uniq -c | sort -n * cycle through a 256 colour palette >> yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done * track flights from the command line >> flight_status() { if [[ $# -eq 3 ]];then offset=$3; else offset=0; fi; curl "http://mobile.flightview.com/TrackByRoute.aspx?view=detail&al="$1"&fn= "$2"&dpdat=$(date +%Y%m%d -d ${offset}day)" 2>/dev/null |html2text |grep ":"; } * Typing the current date ( or any string ) via a shortcut as if >> xvkbd -xsendevent -text $(date +%Y%m%d) * analyze traffic remotely over ssh w/ wireshark >> ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i - * Amazing real time picture of the sun in your wallpaper >> curl http://sohowww.nascom.nasa.gov/data/realtime/eit_195/512/latest.jpg | xli -onroot -fill stdin * Backup a local drive into a file on the remote host via ssh >> dd if=/dev/sda | ssh user@server 'dd of=sda.img' * Kill the terminal(window/tab) you work in [suicide] >> kill -9 $$ * find forms in a symfony 1.2 project >> find apps/ -name "*.svn-base" -prune -o -print -name "*.php" | xargs grep -E 'new .+Form\(' * Avoid using seq and pad numbers with leading zeros >> for i in {001..999}; print $i * List all users >> cut -d: -f1 /etc/passwd | sort * 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 \| * reverse order of file >> sed '1!G;h;$!d' * convert Unix newlines to DOS newlines >> sed 's/$'"/`echo \\\r`/" * Quickly switch to login window (#OSX) >> /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend * 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 * Improvement of curl + Twitter >> echo "Set Twitter Status" ; read STATUS; curl -u user:pass -d status="$STATUS" http://twitter.com/statuses/update.xml * OS-X... create a quick look from the command line >> qlmanage -p "yourfilename" * Delete everything on hda >> dd if=/dev/zero of=/dev/hda * 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 * Add a 1 pixel padding around an image. >> convert -bordercolor Transparent -border 1x1 in.png out.png * Compress Images using convert (ImageMagick) in a bulk >> find . -maxdepth 1 -iname '*jpg' -exec convert -quality 60 {} lowQ/{} \; * grep the command-line-fu archive >> clgrep keyword * Allow to shorten the prompt. Useful when the it is taking too >> PS1='$' * Graphic mode for root >> startx -- :1 * Make sure your compiler is using ccache >> watch ccache -s * Run one of your auto test programs from GNU make >> gmake runtestsingle testsingle=udtime * 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 * Change default terminal emulator >> update-alternatives --config x-terminal-emulator * bkup the old files >> find <dir> -type f -mtime +<days> -exec scp -r {} user@backuphost:/data/bkup \; * mem leak check >> ps gv [pid] | head -2 * Commit all the changes in your java code >> svn st | grep /main/java | awk '{print $2}' | xargs echo | xargs svn ci -m "my comment here" * Nice directory listings >> alias ll="ls -lh --color=auto" * set the time of system >> sudo date mmddhhxxyyyy * Graphically compare two directory hierarchies without Subversion >> xxdiff -r --exclude=.svn * add line number for each line >> cat -n file.txt * Make syslog reread its configuration file >> pkill -HUP syslogd * show physical disk using >> df -x tmpfs | grep -vE "(gvfs|procbususb|rootfs)" * hello, world >> perl -e "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')" * backup file. (for bash) >> cp -p file-you-want-backup{,_`date +%Y%m%d`} # for bash * list files by testing the ownership >> ls -la | awk '$3 == "oracle" || $3 == "root" {print $9}' * 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 * Renaming jpg extension files at bunch >> find . -name "*.jpg" | perl -ne'chomp; $name = $_; $quote = chr(39); s/[$quote\\!]/_/ ; print "mv \"$name\" \"$_\"\n"' * plink ssh connect >> plink lyu0@mysshserver -pw 123456 * Save and merge tcsh history across windows and sessions >> Use history -S in your .logout file * search package descriptions (apt) >> apt-cache search someregex * rows2columns >> perl -le 'print join ", ", map { chomp; $_ } <>' * 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 * Get to the user for using system. >> ps awwux|awk '{print $1}'|sort|uniq * change the all files which contains xxxxx to yyyyyy >> grep -r -l xxxxx . | xargs perl -i -pe "s/xxxxx/yyyyy/g" * Delete Text Editor's Backup >> find . -name "*~" -exec rm {} \; * revert one or more changesets in svn >> svn merge -r 1337:1336 PATH PATH * Import an entire directory into clearcase >> ct mkelem -nc `find ./ -name "*" | xargs` * Check out hijacked files in clearcase >> cleartool co -nc `cleartool ls -recurse | grep "hijacked" | sed s/\@\@.*// | xargs` * ktadd >> kadmin -p admin@NOC.NBIRN.NET -q "ktadd -k /etc/krb5.keytab host/hostname" * addprinc >> kadmin -p admin@NOC.NBIRN.NET -q "addprinc -randkey host/host" * a pseudo-random coin flip in python >> echo "import random; print(random.choice(['heads', 'tails']))" | python * Create a hard-to-guess password >> dd if=/dev/urandom bs=16 count=1 2>/dev/null | base64 * Extract raw URLs from a file >> egrep -ie "<*HREF=(.*?)>" index.html | awk -F\" '{print $2}' | grep :// * add a little color to your prompt >> PS1="\[\033[44;1;37m\]\u\[\033[0m\]@\h\\$ " * Make bash look like DOS >> export PS1='C:${PWD//\//\\\}>' * Clearcase find branch >> ct find -avobs -nxname -element 'brtype(branch_name)' -print 2>/dev/null * Edit any script executable by the user. >> nano `which script` * Identify a PKCS#8 Private Key >> openssl ans1parse -inform DER < [priv key] * Convert a PKCS#8 private key to PEM format >> openssl pkcs8 -inform DER -nocrypt -in [priv key] -out [pem priv key] * Turn /path/to/dir and subdirectories into a project tree >> chgrp -R [projgroup] ; find /path/to/dir -type d -exec chmod g+s {} \; * For files owned by root only, change ownership to a non-privileged >> find /path/to/dir -user root -exec chown [nonprivuser] {} \; * Using Git, stage all manually deleted files. >> for x in `git status | grep deleted | awk '{print $3}'`; do git rm $x; done * Share the current tree over the web >> python -c "import SimpleHTTPServer;SimpleHTTPServer.test()" * make a .bak backup copy of all files in directory >> for i in * ; do cp $i $i.bak; done * Find all processes running under your username. >> ps -ef | grep $USER * kill all foo process >> ps -ef | grep [f]oo | awk '{print $2}' | xargs kill -9 * list all file-types (case-insensitive extensions) including >> find /path/to/dir -type f |sed 's/^.*\///'|grep -o '\.[^.]*$'|sort -f|uniq -i * while series of video and subtitles have unmatched file names, >> 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 * Replaces every ocurrences of 'old' for 'new' in all files >> perl -i -pe "s/old/new/g" * * locate a command >> which somecommand * Search through files, ignoring .svn >> find . -type f -print0 | grep -vzZ '.svn' | xargs -0 grep --color -nEHi "SEARCHTERM" * cd canonical (resolve any symlinks) >> alias cdc='cd `pwd -P`' * creates a bash function to remove certain lines from SSH >> function sshdel { perl -i -n -e "print unless (\$. == $1)" ~/.ssh/known_hosts; } * Check if file is greater than 20 bytes, such as an empty gzip >> BACKUP_FILE_SIZE=`eval ls -l ${BACKUP_FILE} | awk {'print $5'}`; if [ * Press Any Key to Continue >> read enterKey * oneliner to open several times same application >> for i in $(seq 5); do xpenguins & done * View entire process string >> /usr/ucb/ps -auxgww * oneliner to open several times same application >> i="0"; while [ $i -lt 5 ] ; do xpenguins & i=$[$i+1] ; done * wget ? server to server files transfer >> wget -H -r ?level=1 -k -p http://www.domain.com/folder/ * copy partition table from /dev/sda to /dev/sdb >> sfdisk /dev/sdb <(sfdisk -d /dev/sda| perl -pi -e 's/sda/sdb/g') * Open a RemoteDesktop from terminal >> rdesktop -a 16 luigi:3052 * Save VM running as headless >> VBoxManage controlvm ServidorProducao savestate * Running VirtualBox as headless >> nohup VBoxHeadless -p 3052 -startvm ServidorProducao & * Normalize volume in your mp3 library >> find . -type d -exec sh -c "normalize-audio -b \"{}\"/*.mp3" \; * Ruby - nslookup against a list of IP`s or FQDN`s >> ruby -e 'File.foreach("list") {|i| print `nslookup #{i}`}' * Killing multiplpe process for one program like apache, wget, >> ps ax| awk '/[h]ttpd/{print $1}'| xargs kill -9 * Show the meta information on a package (dependency , statuts ..) >> apt-cache show Your_package * List content of a package (debian derivative distro) >> dpkg -L Your_Package * Killing multiplpe process for one program like apache, wget, >> ps aux| grep -v grep| grep httpd| awk {'print $2'}| xargs kill -9 * Return IP Address >> ifconfig -a|grep Bcast:|cut -d\: -f2|awk '{print $1}' * Return IP Address >> ifconfig | awk '/inet /{sub(/^[^:]+:/,"",$2); print $2}' * Return IP Address >> /usr/sbin/ifconfig -a|awk -F" " 'NR==4{print $2}' * search for a pattern (regex) in all text files (ignoring binary >> egrep -i "somepattern" `find . -type f -print` * ruby one-liner to get the current week number >> ruby -rdate -e 'p DateTime.now.cweek' * Mail text file (/tmp/scream-dump) contents from linux box with >> mail -s scream-dump user@example.com < /tmp/scream-dump * perl one-liner to get the current week number >> perl -e 'use Date::Calc qw(Today Week_Number); $weekn = Week_Number(Today); print "$weekn\n"' * http://xname.cc/text/video-streaming-on-wan.pdf (encode.sh) >> ./encode.sh [ h264 | xvid | theora | mpeg4 ] * generate random password >> tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 10 | sed 1q * getting your current ip on your e-mail >> mail -s "`curl -s whatismyip.org`" youremail@yourserver.com < * Sorted list of established destination connections >> netstat | grep EST | awk '{print $5}' | sort * Find in all files in the current directory, just a find shorthand >> find ./ -name $1 -exec grep -H -n $2 '{}' ';' * List all symbolic links in current directory >> ls -F | sed -n 's/@$//p' * Mount a Windows share on the local network (Ubuntu) >> sudo mount -t cifs //$ip_or_host/$sharename /mnt * Checks apache's access_log file, strips the search queries and >> cat /var/log/httpd/access_log | grep q= | awk '{print $11}' | awk -F 'q=' '{print $2}' | sed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1 | mail youremail@isp.com -s "[your-site] search strings for `date`" * remove files and directories with acces time older than a given >> find <dir> -printf '%p : %A@\n' | awk '{FS=" : " ; if($2 < <time in epoc> ) print $1 ;}' | xargs rm --verbose -fr ; * Remove an unnecessary suffix from a file name for all files in a >> for f in $(ls *.xml.skippy); do mv $f `echo $f | sed 's|.skippy||'`; done * Write and run a quick C program >> alias cstdin='echo "Ctrl-D when done." && gcc -Wall -o ~/.stdin.exe ~/.stdin.c && ~/.stdin.exe' * Script to rip the audio from the youtube video you have open in >> video=$(ls /tmp | grep -e Flash\w*); ffmpeg -i /tmp/$video -f mp3 -ab 192k ~/ytaudio.mp3 * Pipe ls output into less >> function lsless() { ls "$@" | less; } * Find all dot files and directories >> ls -a | egrep "^\.\w" * List files in tarballs >> for F in $(find ./ -name "*.tgz") ; do tar -tvzf $F ; done * bash / vim workflow >> zsh$ M-v * List files in tarballs >> find <path> -name "*.tgz" -or -name "*.tar.gz" | while read file; do echo "$file: "; tar -tzf $file; done * Count emails in an MBOX file >> grep -c '^From ' mbox_file * Press Any Key to Continue >> echo -n "Press any key to continue..." && read * umount all nfs mounts on machine >> mount | awk '/:/ { print $3 } ' | xargs sudo umount * Get ethX mac addresses >> sudo ifconfig -a | grep eth | grep HW | cut -d' ' -f11 * Get your external IP address with the best commandlinefu.com >> eval $(curl -s http://www.commandlinefu.com/commands/matching/external/ZXh0ZXJuYWw=/so rt-by-votes/plaintext|sed -n '/^# Get your external IP address$/{n;p;q}') * Go up multiple levels of directories quickly and easily. >> alias ..="cd .." ...="cd ../.." ....="cd ../../.." * Get a text on a position on the file and store in a variable with >> TIMEUNIT=$( cat a | grep -n "timescale" | awk -F ":" '{ print $1 } ' ) * Useful if you need to see compiler errors while edit a code >> alias clear='( for ((i=1;i<$LINES;i++)) ; do echo "" ; done ) ; clear' * Mount an external FAT32 USB HDD >> sudo mount -t vfat /dev/sdb1 /mnt/sdb1 * Forward connections >> ssh -g -L 8080:localhost:80 root@$HOST * tail, with specific pattern colored >> tail -f file | egrep --color=always $\|PATTERN * Compress files and delete the uncompressed ones >> for i in `ls`; do tar cvjf $i.tar.bz2 $i && rm -r $i; done * Outputs a 10-digit random number >> n=$RANDOM$RANDOM$RANDOM; let "n %= 10000000000"; echo $n * Simple Find >> find / -name FILENAME * print crontab entries for all the users that actually have a >> for USER in `ls /var/spool/cron`; do echo "=== crontab for $USER ==="; echo $USER; done * Transforms a file to all uppercase. >> perl -pi -e 's/([[:lower:]]+)/uc $1/gsex' file * Laminate a file >> awk '{print(substr($0,1,5))}' file * Get all members from one AD group and put them in another AD group >> for /F "DELIMS=""" %i in ('dsquery group -name SourceGroupName ^| dsget group -members') do dsquery group -name TargetGroupName | dsmod group -addmbr %i * Remove blank lines from a file and save output to new file >> sed '/^$/d' file >newfile * regex to match an ip >> echo "123.32.12.134" | grep -P '([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])' * Checks your unread Gmail from the command line (or use imap etc) >> curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/; * Search through files, ignoring .svn >> ack -ai 'searchterm' * show current directory >> xdg-open . * show current directory >> gnome-open . * Show directories in the PATH, one per line >> echo src::${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/" $1}{print $1}' * bash function to check for something every 5 seconds >> watch -n <seconds> <command> * Sort a character string >> echo sortmeplease | grep -o . | sort | tr -d '\n'; echo * free swap >> free -m | awk '/Swap/ {print $4}' * rkhunter (Rootkit Hunter) is a Unix-based tool that scans for >> rkhunter --check * Securely edit the sudo file over the network >> visudo * Securely look at the group file over the network >> vigr * Securely seeing the password file over the network >> vipw * dos2unix recursively >> find . -type f -exec dos2unix {} + * Get the information about the internet usage from the commandline. >> vnstat * find dis1k space >> du -s `find . -maxdepth 1 \! -name '.'` | sort -n | tail * Print man pages to PDF (yes, another one) >> man -t [command] | lp -d PDF -t [command].pdf * Find the average QTime for all queries ran within the last hour >> cat /service/solr/log/main/current | tai64nlocal | grep "\(`date '+%F %H'`\|`date '+%F %H %M' | awk '{print $1" 0"$2-1":"$3}'`\)" | grep QTime | awk '{print $NF}' | awk -F\= '{ s += $2} END {print s/NR}' * Echo the local IP addresses of the machines on your local network >> for i in 192.168.1.{61..71};do ping -c 1 $i &> /dev/null && echo $i;fi;done * YES = NO >> yes | tr 'y' 'n' * Update iptables firewall with a temp ruleset >> sudo iptables-restore < /etc/iptables.test.rules * Emulate sleep in DOS/BAT >> echo sleep() begins: %TIME% && FOR /l %a IN (10,-1,1) do (ECHO 1 >NUL %as&ping -n 2 -w 1 127.0.0.1>NUL) && echo sleep() end: %TIME% * Remove CR from Windows- / DOS-textfiles >> tr -d '\r' < ${input_txt} > ${output_txt} * Emptying a text file in one shot >> ggdG * CPU model >> cat /proc/cpuinfo * Multiple Timed Execution of subshells sleeping in the background >> S=$SSH_TTY && (sleep 3 && echo -n 'Peace... '>$S & ) && (sleep 5 && echo -n 'Love... '>$S & ) && (sleep 7 && echo 'and Intergalactic Happiness!'>$S & ) * parses the BIOS memory and prints information about all structures >> biosdecode * x86info >> x86info * Lists the size of certain file in every 10 seconds >> while true ; do du -sk testfile ; sleep 10 ; done * Turn Regular quotes ("") into curly quotes (??) >> smartypants | php -r "echo mb_decode_numericentity(file_get_contents('php://stdin'),array(0x0000,0 xFFFF,0x0000,0xFFFF),'UTF-8');" * List path of binaries >> echo $PATH|awk -F: ' { for (i=1; i <= NF; i++) print $i }' * Get your external IP address >> html2text http://checkip.dyndns.org | grep -i 'Current IP Address:'|cut -d' ' -f4 * find . -name "*.gz" | xargs -n 1 -I {} bash -c "gunzip -c {} | >> Rezip a bunch of files * ssh autocomplete >> complete -W "$(echo `cat .bash_history | egrep '^ssh ' | sort | uniq | sed 's/^ssh //'`;)" ssh * Get all IPs via ifconfig >> ifconfig | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1 * Read just the IP address of a device >> /sbin/ifconfig eth0 | grep "inet addr" | sed -e 's/.*inet addr:\(.*\) B.*/\1/g' * Read just the IP address of a device >> ifconfig $DEVICE | perl -lne '/inet addr:([\d.]+)/ and print $1' * Command for getting the list of files with perms, owners, groups >> find / | xargs ls -l | tr -s ' ' | cut -d ' ' -f 1,3,4,9 * count how many times a string appears in a (source code) tree >> grep -rc logged_in app/ | cut -d : -f 2 | awk '{sum+=$1} END {print sum}' * kill some process (same as others) but parsing to a variable >> tokill=`ps -fea|grep process|awk '{ printf $2" "}'`; kill -9 $tokill; * Move files around local filesystem with tar without wasting space >> tar -C <source> -cf - . | tar -C <destination> -xf - * find a word in multiple files avoiding svn >> grep -r 'keyword keyword2' your/path/ | grep -v svn * Display which distro is installed >> test `uname` = Linux && lsb_release -a || ( test `uname` = SunOS && cat /etc/release || uname -rms ) * Alternative size (human readable) of directories (biggest last) >> function duf { du -sk "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done; } * Use FileMerge to compare two files >> opendiff <file1> <file2> * tar per directory >> cd <YOUR_DIRECTORY>; for i in `ls ./`; do tar czvf "$i".tar.gz "$i" ; done * search for groups in ldap >> ldapsearch -H ldap://localhost:389 -D cn=username,ou=users,dc=domain -x -W -b ou=groups,dc=domain '(member=cn=username,ou=users,dc=domain)' | grep ^dn | sed "s/dn\: cn=\([^,]*\),ou=\([^,]*\),.*/\2 \1/" * Mac, ip, and hostname change - sweet! >> ifconfig eth0 down hw ether (newmacaddresshere) && ifconfig eth0 up && ifconfig eth0 (newipaddresshere) netmask 255.255.255.0 up && /bin/hostname (newhostnamehere) * Uncompress a CSS file >> cat somefile.css | awk '{gsub(/{|}|;/,"&\n"); print}' >> uncompressed.css * print random commandlinefu.com submission >> lynx -source http://www.commandlinefu.com/commands/random | sed 's/<[^>]*>//g' | head -1037 | tail -10 | sed -e 's/^[ \t]*//' | sed '/^$/d' | head -2 * Mount a CD-ROM on Solaris (SPARC) >> mkdir -p /cdrom/unnamed_cdrom ; mount -F hsfs -o ro `ls -al /dev/sr* |awk '{print "/dev/" $11}'` /cdrom/unnamed_cdrom * Kill an orphan console >> skill -KILL -t ttyS0 * Run Remote GUI Programs Using SSH Forwarding >> ssh -C -X user@remotehost gui_command * Scan for viruses >> clamscan -ir --bell ~user/ * Get Tomorrow's Date >> TOM=`perl -w -e '@tom=localtime(time+86400);printf "%d%.2d%.2d",$tom[5]+1900,$tom[4]+1,$tom[3];'` * Get Yesterday's Date >> YEST=`perl -w -e '@yest=localtime(time-86400);printf "%d%.2d%.2d",$yest[5]+1900,$yest[4]+1,$yest[3];'` * Creating a ZFS Storage Pool by Using Files >> zpool create tank /path/to/file/a /path/to/file/b * Creating a Mirrored Storage Pool using Zpool >> zpool create tank mirror c0t0d0 c0t1d0 mirror c0t2d0 c0t3d0 * Creating a RAID-Z Storage Pool >> zpool create tank raidz c0t0d0 c0t1d0 c0t2d0 c0t3d0 c0t4d0 c0t5d0 * Remove all .svn folders inside a folder >> find . -name "\.svn" -exec rm -rf {} ";" * alias for lsof -i -T -n >> alias lso="sudo lsof -i -T -n" * Do an OR search using grep to look for more than one search term >> grep -i '<searchTerm>\|<someOtherSearchTerm>' <someFileName> * Display a File with Line Number >> nl filename | more * Shred an complete disk, by overwritting its content 10 times >> sudo shred -zn10 /dev/sda * Quickly determine lines in terminal >> _llines=100; while [ $_llines -gt 1 ]; do echo $_llines; _llines=$(($_llines-1)); done * Enable Hibernate in OS X >> sudo pmset -a hibernatemode 1 * IP address of current host >> hostname -i * Find the svn directory that a commit was made in. Usefull if you >> echo "12345,12346" |sed -e's/ //'|tr "," "\n"| while read line; do echo -n $line" "; svn log -vr $line https://url/to/svn/repository/|grep "/"|head -1|cut -d"/" -f2; done * Append output to the beginning of a file. >> command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmp * gzip vs bzip2 at compressing random strings? >> < /dev/urandom tr -dc A-Za-z0-9_ | head -c $((1024 * 1024)) | tee >(gzip -c > out.gz) >(bzip2 -c > out.bz) > /dev/null * Show live HTTP requests being made on OS X >> sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*" * Display all installed ISO/IEC 8859 manpages >> for i in $(seq 1 11) 13 14 15 16; do man iso-8859-$i; done * List SMTP connections by host >> cat /var/log/secure | grep smtp | awk '{print $9}' | cut -f2 -d= | sort | uniq -c | sort -n | tail * Not so simple countdown from a given date >> watch -tn1 'bc<<<"`date -d'\''friday 21:00'\'' +%s`-`date +%s`"|perl -ne'\''@p=gmtime($_);printf("%dd %02d:%02d:%02d\n",@p[7,2,1,0]);'\' * Get own public IP address >> wget -qO- whatismyip.org * Add some color to ls file and folder listings >> eval "`dircolors -b`" * Quickly make schema changes in Django >> while true ; do scripts/bootstrap.py ; ./manage.py runserver ; done * Convert files with CR-terminated lines (as created by Mac OS X >> function crtonl { perl -i -ape 's/\r/\n/g;' $* ; } * Find files modified in the last 5 days, no more than 2 levels >> find . -type f -depth -3 -mtime -5 * Easy Regex based mass renaming >> ls /some/directory | sed -rn -e 's/input_file_regex/mv -v & output_file_name/p' | sh * Shows your WAN IP, when you`re sitting behind a router >> alias myip='curl -s www.wieistmeineip.de | egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"' * List your FLAC albums >> find -iname '*.flac' | sed 's:/[^/]*$::' | uniq * Kills all processes for a certain program >> kill -9 $(pidof process) * startx output to log file >> startx > startx.log 2>&1 * simulates the DOS tree command that you might be missing >> find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' * Copy files from one dir to another using tar. >> tar cf - . | (cd /new/dir; tar xvf -) * read a column of a file with table like data >> echo 1 2 3 > FILE; while read -a line; do echo ${line[2]}; done < FILE * Recursively deletes folders named DIR >> find . -type d -name DIR -exec rm -r {} \; * remove file named 1 after fat fingeriing :w! in vi >> :rm 1 * Generic date format >> date --iso * Speak your horoscope with the command line >> curl -s 'http://www.trynt.com/astrology-horoscope-api/v2/?m=2&d=23' | xmlstarlet sel -t -m '//horoscope' -v 'horoscope' | festival --tts * Copy All mp3 files in iTunes into one folder (Example: Music on >> find ~/Music/iTunes/ -name *.mp3 -exec cp {} ~/Desktop/Music/ \; * batch convert OGG to WAV >> for f in *.ogg ; do mplayer -quiet -vo null -vc dummy -ao pcm:waveheader:file="$f.wav" "$f" ; done * watch porn on older mobile phones >> function encode4phone() { ffmpeg -acodec libamr_nb -vcodec h263 -i "$1" -s qcif -b 200k -ac 1 -ab 7.4k -ar 8000 "$1.3gp" } * Query for installed packages on RHEL boxes, and format the output >> rpm -qa --queryformat 'Installed on %{INSTALLTIME:date}\t%{NAME}-%{VERSION}-%{RELEASE}: %{SUMMARY}\n' * Say the current time (Mac OS X) >> date "+The time is %H:%M" | say * Show "Max" settings for PHP >> php -i|grep -i max * determine if CPU is 32-bit or 64-bit >> grep lm /proc/cpuinfo * More precise BASH debugging >> env PS4=' ${BASH_SOURCE}:${LINENO}(${FUNCNAME[0]}) ' sh -x /etc/profile * is today the end of the month? >> [ `date --date='next day' +'%B'` == `date +'%B'` ] || echo 'end of month' * Create a directory and change into it at the same time >> md () { mkdir -p "$@" && cd "$@"; } * Show Directories in the PATH Which does NOT Exist >> (IFS=:;for p in $PATH; do test -d $p || echo $p; done) * Testing hard disk reading speed >> hdparm -t /dev/sda * Identify differences between directories (possibly on different >> diff <(ssh server01 'cd config; find . -type f -exec md5sum {} \;| sort -k 2') <(ssh server02 'cd config;find . -type f -exec md5sum {} \;| sort -k 2') * Print text string vertically, one character per line. >> echo "vertical text" | grep -o '.' * Show directories in the PATH, one per line >> echo $PATH | tr \: \\n * display an embeded help message from bash script header >> [ "$1" == "--help" ] && { sed -n -e '/^# Usage:/,/^$/ s/^# \?//p' < $0; exit; } * Send data securly over the net. >> cat /etc/passwd | openssl aes-256-cbc -a -e -pass pass:password | netcat -l -p 8080 * Replace spaces in filenames with underscorees >> rename -v 's/ /_/g' * * bash: hotkey to put current commandline to text-editor >> bash-hotkey: <CTRL+x+e> * move a lot of files over ssh >> tar -cf - /home/user/test | gzip -c | ssh user@sshServer 'cd /tmp; tar xfz -' * print file without duplicated lines using awk >> awk '!a[$0]++' file * Cleanup firefox's database. >> pgrep -u `id -u` firefox-bin || find ~/.mozilla/firefox -name '*.sqlite'|(while read -e f; do echo 'vacuum;'|sqlite3 "$f" ; done) * vim easter egg >> $ vim ... :help 42 * Change proccess affinity. >> taskset -cp <core> <pid> * Download file with multiple simultaneous connections >> aria2c -s 4 http://my/url * A fun thing to do with ram is actually open it up and take a >> sudo strings /dev/mem * Pick a random line from a file >> shuf -n1 file.txt * Use xdg-open to avoid hard coding browser commands >> xdg-open http://gmail.com * Search commandlinefu from the CLI >> curl -sd q=Network http://www.commandlinefu.com/search/autocomplete |html2text -width 100 * pipe output of a command to your clipboard >> some command|xsel --clipboard * Using bash inline "here document" with three less-than symbols on >> <<<"k=1024; m=k*k; g=k*m; g" bc * Colored SVN diff >> svn diff <file> | vim -R - * show open ports on computer >> netstat -an | grep -i listen * Checking total connections to each Ip inserver >> netstat -alpn | grep :80 | awk '{print $4}' |awk -F: '{print $(NF-1)}' |sort | uniq -c | sort -n * Convert images (foo.gif => foo.jpg) >> for i in **/*.gif; convert $i $i:r.jpg * Updating twitter with from curl >> curl -u userid:password -d status="New Twitter Message" http://twitter.com/statuses/update.xml * Inserting a decimal every third digit >> perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/' * Forget fortunes in your terminal this grabs a random >> wget -qO - snubster.com|sed -n '65p'|awk 'gsub(/<span><br>.*/,"")&&1'|perl -p -e 's:myScroller1.addItem\("<span class=atHeaderOrange>::g;s:</span> <span class=snubFontSmall>::g;s:":":g;s:^:\n:g;s:$:\n:' * Double Compile system and world on gentoo >> emerge -e system && emerge -e system && emerge -e world && emerge -e world * Finding hostname and the IP Address of your machine >> host `hostname` * Force log creation when running an msi install >> msiexec.exe /i product.msi /l* c:\folder\LogFileName.txt * Execute a command if a file exists >> grep -sq "" /etc/lsb-release && lsb_release -rd * strip ^M character from files in VI >> :%s/<control-VM>//g * Cleanly quit KDE4 apps >> kquitapp plasma * Remove files/directory with spaces. >> find -name "*.exe" -printf "\"%p\"\n" | xargs /bin/rm * Calculates fake folder checksum based on folder's files' md5sums >> find path/to/folder/ -type f -print0 | xargs -0 -n 1 md5sum | awk '{print $1}' | sort | md5sum | awk '{print $1}' * use perl instead of sed >> echo "sed -e"|perl -pe 's/sed -e/perl -pe/' * Contextual Menu Cleanup (OSX) >> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks /LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user * Outputs current folder svn revision >> LC_ALL=C svn info | grep Revision | awk '{print $2}' * Current directory files and subdirectories ordered by size >> du -ks * | sort -n * Print the current battery status >> acpi | cut -d '%' -f1 | cut -d ',' -f2 * Mount a windows partition in a dual boot linux >> mount -o auto -t ntfs /dev/hda1 /windows * Unmount locked filesystems. >> umount -l /media/foo * Extract .daa files with PowerISO >> ./poweriso extract $USER/file.daa / -od $USER/file_extracted * Takes a multi line df or bdf and turns it into just one line >> bdf | awk '(NF<5){f=$1; next} (NF>5){f=$1} {print f, $2, $3, $NF}' * Launch an Explorer window with a file selected >> explorer /select,[file] * Broadcast message to all logged in terminal users. >> cat welcome | wall * To retrieve a normal prompt >> PS1='$PWD$ ' * kill all processes of a program >> kill -9 $(pidof *program*) * Open the Windows Explorer from the current directory >> explorer /e,. * Save the network interface info into a text file, so that you can >> netsh interface ip dump > current-interfaces.txt * how to like to know if a host is ON >> for ip in $(seq 1 25); do ping -c 1 192.168.0.$ip>/dev/null; [ $? -eq 0 ] && echo "192.168.0.$ip UP" || : ; done * edit files in current and subdir, remove all lines that containing >> grep -r "sampleString" . |uniq | cut -d: -f1 | xargs sed -i "/sampleString/d" * get line#1000 from text. >> head -1000 < lines.txt | tail -1 * watch filesizes (c.f. logfiles, file downloading, etc.) >> while [ 1 ]; do date; ls -l /path/to/dir; sleep 1; done * Fast searh Ubntu software repo >> alias acs='apt-cache search' * color grep with specification of colors with GREP_COLOR env >> setenv GREP_COLOR '1;37;41' * reset the bizzarre gone junk terminal to normal >> echo "Xc" | tr "Xo" "\033\017 * example usage of sar >> sar -g 5 5 * umount all nfs mounts on machine >> mount | grep : | tr -s ' ' -d 3 | xargs umount -v * Display a list of upgradeable packages (apt) >> apt-show-versions -u * GUID generator >> guid(){ lynx -nonumbers -dump http://www.famkruithof.net/uuid/uuidgen | grep "\w\{8\}-" | tr -d ' '; } * search for the content in a directory >> find . -exec grep "test" '{}' /dev/null \; -print * Get the size of every directories and files in a path recursively >> for i in $(ls /the/path); do du -hs /the/path/$i; done * shows the space of a folder in bytes ever two seconds. >> watch "df | grep /this/folder/" * Ring the system bell after finishing a long script/compile >> myLongScript && echo -e '\a' || (echo -e '\a'; sleep 1; echo -e '\a') * Print only the even lines of a file >> awk '{if (NR % 2 == 0) print $0}' file.txt * kill all processes with name or argument >> pkill -f foo * find and kill a pid for APP >> ps -ef | grep APP | awk '/grep/!{print$2}' | xargs -i kill {} * Search for a running process through grep >> ps -e | grep SearchStringHere * Print a row of 50 hyphens >> ALT-50 - * generate random password >> openssl rand -base64 1000 | tr "[:upper:]" "[:lower:]" | tr -cd "[:alnum:]" | tr -d "lo" | cut -c 1-8 | pbcopy * oneliner to open several times same application >> for ((i=0;i<5;i++)) ; do xpenguins & done * Set Permission to user and group >> chown -R webuser:webgroup /var/www/vhosts/domain.com/httpdocs * Get your public ip >> wget -qO - http://cfaj.freeshell.org/ipaddr.cgi * Show the meta information on a package (dependency , statuts ..) >> aptitude show packages_name * Return IP Address >> awk '/inet end/ {print $3}' <(ifconfig eth0) * Show local IP >> ifconfig eth0 | grep "inet:" | cut -d ":" -f2 | cut -d " " -f1 * Fill up disk space (for testing) >> dd if=/dev/zero of=/fs/to/fill/dummy00 bs=8192 count=$(df --block-size=8192 / | awk 'NR!=1 {print $4-100}') * List files that DO NOT match a pattern >> ls *[^p][^a][^t]* ; # or shopt -s extglob; ls !(*pattern*) * List all symbolic links in current directory >> ls -l `ls -l |awk '/^l/ {print $8}'` * Random password generating function >> mkpasswd() { head -c $(($1)) /dev/urandom | uuencode - | sed -n 's/.//;2s/\(.\{'$1'\}\).*/\1/p' ;} * Compress and Backup a disk image >> dd if=/dev/<device location> | gzip -c /<path to backup location>/<disk image name>.img.gz * bash / vim workflow >> vim - * Delete everything on hda >> dd if=/dev/zero of=/dev/hda bs=16M * Remove lines that contain a specific pattern($1) from file($2). >> function rmatch { echo "$(grep -v "$1" "$2")">"$2";} * Get your external IP address >> wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//' * Get your external IP address >> curl whatismyip.org * Get your external IP address >> echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" | nc whatismyip.com 80 | tail -n1 * Clear your history saved into .bash_history file! >> echo "" > .bash_history * remove the last of all html files in a directory >> a=($(ls *html)) && a=${a[$(expr ${#a[@]} - 1)]} && rm $a * Checking DNS zone on Name servers directly >> host <domain> <nameserver name> * convert .rpm to .deb using alien >> sudo alien --to-deb Your_PackAge.rpm * Create Bootable USB from ISO file >> xcopy D:\*.* /s/e/f E:\ * floating point operations in shell scripts >> echo $((3.0/5.0)) * Ultimate current directory usage command >> O=$IFS;IFS=$'\n'; D=$(for f in *;do [[ -d $f ]] && du -sh "$f";done | * Ultimate current directory usage command >> ls -shF --color * Seach google from the command line in Unofficial google shell >> http://goosh.org * This command will tell the last login and reboot related >> last * How to run a specific command in remote server by ssh >> ssh user@remotehost [anycommand](i.e uptime,w) * securely locate file and dir >> slocate filename/dirname * Save iptables firewall info >> sudo iptables-save > /etc/iptables.up.rules * Emptying a text file in one shot in VIM >> :!>test.txt * get debian version number >> lsb_release -a * System load information alongside process information in a similar >> atop * detect the Super I/O chip on your computer, tell you at which >> superiotool * get basic information out of your computer >> lspci * Output all Files in Directory w/ Details to Filelist >> ls -laR > /path/to/filelist * Testing php configuration >> echo "<?php phpinfo(); ?>" >> /srv/www/htdocs/test.php * Install NMAP 5.0 ,Short and sweet command to do it >> sudo wget -c "http://nmap.org/dist/nmap-5.00.tar.bz2" && bzip2 -cd nmap-5.00.tar.bz2 | tar xvf - && cd nmap-5.00 && ./configure && make && sudo make install * Pick a random line from a file >> shuf file.txt | head -n 1 * Pick a random line from a file >> head -$(($RANDOM % $(wc -l < file.txt) +1 )) file.txt | tail -1 * Read just the IP address of a device >> ip addr|grep "inet " * create tar.gz archive >> tar -pczf archive_name.tar.gz /path/to/dir/or/file * let w3m usecookie >> alias w3m='w3m -cookie' * Move files around local filesystem with tar without wasting space >> tar -C <source_dir> -cf . | tar -C <dest_dir> -xf - * List all files in current directory by size >> du -sh * * Outputs size of /example/folder in human readable format. >> du -hs /example/folder/ * Remove all files previously extracted from a tar(.gz) file. >> for i in $(tar -tf <file.tar.gz>); do rm $i; done; * Alternative size (human readable) of directories (biggest first) >> function duf { du -k $@ | sort -rn | perl -ne '($s,$f)=split(/\t/,$_,2);for(qw(K M G T)){if($s<1024){$x=($s<10?"%.1f":"%3d");printf("$x$_\t%s",$s,$f);last}; $s/=1024}' } * Recursive when needed >> rm strangedirs -rf * Check processes runed not by you >> ps aux | grep -v `whoami` * urlencode >> (Command too long..See sample Output..) * Copy all documents PDF in disk for your home directory >> for i in `find / -name *.pdf`; do cp -v $i $HOME; done * See smbstatus all the time >> while (( $i != 0 )) { smbstatus; sleep 5; clear } * unzip all zip files under a current directory in the directory >> for f in `find ./ -name "*.zip"` ; do p=`pwd`; d=`dirname $f`; cd $d; b=`basename $f`; unzip $b; cd $p; done * greps the man pages to find utilities >> apropos keyword * View SuSE version >> cat /etc/SuSE-release * Quickly assess quality of project by greping the SVN commit logs >> svn log | grep "bodge\|fudge\|hack\|dirty" * aliases for apt-get >> alias agi="sudo apt-get install" #package_names * List installed hardware >> kudzu -p * Graphical display of wireless links >> wmwave * Go to the last directory invoked on command line >> cd !$ * Search and replace in multiple files and save them with the same >> for files in $(ls -A directory_name); do sed 's/search/replaced/g' $files > $files.new && mv $files.new $files; done; * A bash prompt which shows the bash-version >> PS1="$BLUE[$CYAN\u$BLUE@$CYAN\h$WHITE-bash \v:$GREEN\w$BLUE]$WHITE \$ " * Find all jpgs on the PC (DOS command) >> for %f in (c) do dir %f:\*.jpg /s /p * Delete an hard disk entry in Virtualbox registry >> sed -i '/Centos/d' VirtualBox.xml * count occurences of each word in novel David Copperfield >> wget -q -O- http://www.gutenberg.org/dirs/etext96/cprfd10.txt | sed '1,419d' | tr "\n" " " | tr " " "\n" | perl -lpe 's/\W//g;$_=lc($_)' | grep "^[a-z]" | awk 'length > 1' | sort | uniq -c | awk '{print $2"\t"$1}' * remove unneeded configuration files in debian >> dpkg-query -l| grep -v "ii " | grep "rc " | awk '{print $2" "}' | tr -d "\n" | xargs aptitude purge -y * Remove packages by pattern on debian and based systems >> sudo apt-get remove --purge `dpkg -l | awk '{print $2}' | grep gnome` && apt-get autoremove * Check cobbler environment >> cobbler check * How many Non-free software is on your machine ? >> vrms * Randomize the order of lines in a text file. >> awk 'BEGIN {srand()} {print int(rand()*1000000) "\t" $0}' FILE | sort -n | cut -f 2- * Find 'foo' in located files >> locate searchstring | xargs grep foo * Join lines >> echo -e "aa\nbb\ncc\ndd\n123" | sed -e :a -e "/$/N; s/\n/;/; ta" * remove exact phrase from multiple files >> grep -r "mystring" . |uniq | cut -d: -f1 | xargs sed -i "s/mystring//" * convert all WAVs from any format (MS ADPCM) to PCM >> for file in $(find -type f -iname "*wav"); do mv $file "$file"_orig.WAV; mplayer -ao pcm "$file"_orig.WAV -ao pcm:file=$file; done * Quickly backup your current directory >> alias backup_dir='mkdir -p .backup && cp * .backup' * Print out "string" between "match1" and "match2" >> echo "string" | sed -e 's/.*match1//' -e 's/match2.*$//' * Look for a string in one of your codes, excluding the files with >> find . -type f -exec grep StringToFind \{\} --with-filename \;|sed -e '/svn/d'|sed -e '/~/d' * Copy files over network using compression >> on the listening side: sudo nc -lp 2022 | sudo tar -xvf - and on the sending side: tar -cvzf - ./*| nc -w 3 name_of_listening_host 2022 * bind a web server in $PWD >> python -c "import SimpleHTTPServer;SimpleHTTPServer.test()" * recursively delete .svn folders from a directory >> rm -rf `find . -type d -name .svn` * Binary editor >> bvi [binary-file] * find a class or file within a number of jar files >> for i in `find . | grep jar$`; do echo $i; jar tvf $i | grep 'search-string'; done; * Recursive file content search >> find . -name *.php | xargs grep -i -n 'TERM' * Convert a bunch of oggs into mp3s >> for x in *.ogg; do ffmpeg -i "$x" "`basename "$x" .ogg`.mp3" * extract a certain number of lines from a file and dump them to >> grep '' -m X file1 > file2 * Read a gzipped text file directly with less. >> less textfile.gz * Removes Apple "garbage" >> find . -name *DS_Store -exec echo rm {} \; * rcs - local backup of any text configuration file before >> ci -l /etc/rc.conf * Generate MD5 hash for a string >> echo -n "string" | md5sum - * Listen to the OS X system's voices >> for person in Alex Bruce Fred Kathy Vicki Victoria ; do say -v $person "Hello, my name is $person"; sleep 1; done * Move a file up a directory. >> mv file_name.extension .. * Basic Local Port Scan >> [command too long] * Read Nth column (e.g. 2nd column) of a row of data in a file that >> grep 'HOME.*' data.txt | awk '{print $2}' | awk '{FS="/"}{print $NF}' OR USE ALTERNATE WAY awk '/HOME/ {print $2}' data.txt | awk -F'/' '{print $NF}' * Get top 10 largest directories under cwd >> du | sort -n | tail -11 | head * Download a complete podcast >> wget -c -v -S -T 100 --tries=0 `curl -s http://ms1.espectador.com/ podcast/espectador/la_venganza_sera_terrible.xml | grep -v xml | grep link | sed 's/]*>//g'` * Edit a file using vi or vim in read-only mode >> vi -R filename * Creates a minimalist xorg.conf >> dpkg-reconfigure -phigh xserver-xorg * Delete tens of thousans of files at one go >> rm -rf `ls | head -5000` * stores the number of lines of "file" in a variable to use in a >> count=`wc -l file | cut -d ' ' -f1` * Run the previous command with sudo >> sudo !! * uppercase >> tr [a-z] [A-Z] * sets volume via command line >> amixer -c 0 set PCM 2dB+ * ctrl -k and ctrl -y for cut and paste >> ctrl k , ctrl y * xxcopy everything from one Windows box to another >> xxcopy x:\folder1 y:\folder2 /s /h /tca /tcc /tcw /yy * Quick scrape of recent mobile home dir file sync for Mac Admins - >> tail -n 20 ~/Library/Logs/FileSyncAgent.log * Generate load on your CPU >> while true; do /bin/true; done * Convert *.mp3 files to *.wav for recording audio cd's >> ls |while read line ; do mpg321 -w "$line.wav" "$line" ; done * LSD: List directory files in current directory >> ls -l !* | /usr/bin/grep '^d' * rm all files you grep >> find . | grep deleteme | while read line; do rm $line; done * prints long line >> sed -n '/^.\{10\}/p' * View your machine firewall settings >> iptables -L -n -v * best command for searching files >> find / -name \*string\* * Directly change directory without having to specify drive letter >> cd /d d:\Windows * backup the old files >> tar -zcps <dir> -X <(find <dir> -type f -mtime -<days>) |ssh user@backuphost tar -xzpsC /data/bkup * Run ADSL connection >> pon dsl-provider * Stage added, updated, and DELETED files for commit >> git add -u * Display directory hierarchy listing as a tree >> ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' * set fan speed (ATI cards) >> aticonfig --pplib-cmd "set fanspeed 0 <number>" * Find files containing "text" >> grep -lir "text to find" * * Execute AccuRev pop command to retrieve missing files from a >> accurev stat -M -fl | awk '{print "\"" $0 "\""}' | xargs accurev pop * Place a filename at the beginning of the line to make it easier >> Place a filename at the beginning of the line to make it easier to edit the search at the end of the command. * UNIX one-liner to kill a hanging Firefox process >> kill -HUP ` ps -aef | grep -i firefox | sort -k 2 -r | sed 1d | awk ' { print $2 } ' ` * Backup the first 1MB of your volume >> dd if=/dev/sdX of=/root/sdX.bin bs=1M count=1 * Ignore the specified signal >> trap '' 1 2 20 24(signal number) * Recursive chmod all files and directories within the current >> chmod -R 777 * * List the size (in human readable form) of all sub folders from the >> ls | xargs du -sh * copying files using sed to rename based on regular expression >> ls "*.mp3" | awk '{print("cp "$1" /folder/"$1)}' | sed -e 's/foo/bar/' | /bin/bash * yesterday >> perl -lne 'use POSIX; print strftime("%Y-%m-%d", localtime(time() - 86400));' * Replace text in several files >> perl -p -i -e ?s/New/Old/g? *.html * Remove executable bit from all files in the current directory >> find . -type f | while read f; do chmod -x "$f"; done * Get your external IP address >> lynx --dump http://ip.boa.nu|sed -e 's/^[[:space:]]*//' -e 's/*[[:space:]]$//'|grep -v ^$ * Update your system every day at the lunch time (12:00) >> (crontab -e) 00 12 * * * apt-get update (/etc/init.d/cron restart) * Get the 10 biggest files/folders for the current direcotry >> ls -1rSA | tail * To print a specific line from a file >> awk '{if (NR == 3) print}' <file> * Create a list of sequential logins >> seq -w 100 | sed 's/^/login/' * Start xterm in given directory >> ( cd /my/directory; xterm& ) * Start xterm in given directory >> xterm -e "cd /my/directory; bash" * Count the total number of files in each immediate subdirectory >> ps -ef | grep pmon * Sneaky logout >> rm ~/.bash_history && kill -9 $$ * List dot-files and dirs, but not . or .. >> ls .??* * run command with opposite return code >> not () { "$@" && return 1 || return 0; } * The 1 millionth fibonacci number >> gcc -x c -o /tmp/out - -lgmp <<< '#include <stdlib.h> ... SEE SAMPLE OUTPUT FOR FULL COMMAND * Show directories in the PATH, one per line >> print -l $path * Download all the Super Mario World Hacks from smwcentral.net >> smw=http://www.smwcentral.net;for f in $(curl -s "$smw/?p=hacks"|grep -o "download.php?id=[0-9]*&type=hack"); do i=$(echo $f|sed "s/download.php?id=\([0-9]*\)&type=hack/\1/");wget -O $i "$smw/download.php?id=$id&type=hack";unzip -qqo $i;rm $i;done * Read aloud a text file in Mac OS X >> say `cat /path/to/textfile.txt` * Add a directory with a name to /etc/passwd to get quick access >> function qcd { useradd -No -s /bin/false -u 999 -g 999 -lf -1 -d $1 $2 ; } * make 100 directories with leading zero, 001...100, using bash3.X >> mkdir 0{0..9}{0..9};mv 000 100 * Kill a process with its name >> ps -u $USER |grep $1 | awk '{ print $1}'| xargs kill * Repeat last executed command >> !! * Monitor Applications application that are connected/new >> while true; do netstat -p |grep "tcp"|grep --color=always "/[a-z]*";sleep 1;done * Duplicate a directory tree using tar and pipes >> (cd /source/dir ; tar cvf - .)|(cd /dest/dir ; tar xvpf -) * unzip all .zip files in /example/directory >> cd /example/directory && unzip \*.zip * Search through files, ignoring .svn (less accurate/slower but >> find . ! -path \*.svn\* * Move files around local filesystem with tar without wasting space >> tar -C <source_dir> -cf . | tar -C <dest_dir> -xf * Quick findstring recursively in dirs (Alias from long find with >> alias findstring="find . -type f -print | xargs grep $1" * Kill a daemon by name, not by PID >> kill_daemon() { echo "Daemon?"; read dm; kill -15 $(netstat -atulpe | grep $dm | cut -d '/' -f1 | awk '{print $9}') }; alias kd='kill_daemon * Delete all files more t han 7 days old >> rm -rf `find -maxdepth 1 -mindepth 1 -mtime +7` * Skipping tests in Maven >> mvn -Dmaven.test.skip=true install * Creating a Maven project >> mvn archetype:create -DgroupId=my.work -DartifactId=MyProject * kill process by name >> pkill * Find which version of Linux You are Running >> lsb_release -d * journaling directories >> mkdir `date | sed 's/[: ]/_/g'` * Encoding with base64 >> echo "Hello world" | base64 * Use md5 to generate a pretty hard to crack password >> echo "A great password" | md5sum * compile openvm-tools >> m-a a-i open-vm * When you have time to consume >> moon-buggy * Reset scrambled screen >> cat [ENTER]^V^O[ENTER]^D * redirect wget output to the terminal, instead of a file >> wget -q -O - "$@" <url> * Remove rpm package by pattern >> yum erase `yum list installed | grep 'php'` * Rename files that have number, space and hyphen >> for f in * ; do mv -- "$f" "${f/[0-9][0-9] \- /}" ; done * zip all files in a directory, one file per zip >> for i in $( find . ); do echo zipping file: $i zip $i.zip $i done * Displays a 3-Month Calendar >> cal -3 * list connected usb devices >> lsusb * Chmod directories to add executable & read permission to the group >> sudo chmod -R g=u-w,g+X * * Print the ten largest files >> ls -Sl * | head * use a literal bang (exclamation point) in a command >> echo '!'whammy * easly monitor mem usage >> watch -n1 --differences cat /proc/meminfo * find all references to a server in web.config files with >> ls \\someserver\c$\inetpub\wwwroot -r -i web.config | Select-String "SomeMachineName" * Snmpwalk a hosts's entire OID tree with SNMP V3 with SHA >> snmpwalk -v3 -On -u <user> -l AuthPriv -a SHA -A <auth_password> -X <encryption_password> -m ALL <HOST_IP> . * Snmpwalk a hosts's entire OID tree with SNMP V3 with SHA >> snmpwalk -v3 -On -u <user> -l AuthNoPriv -a SHA -A <auth_password> -m ALL <HOST_IP> . * Snmpwalk a hosts's entire OID tree with SNMP V3 with MD5 >> snmpwalk -v3 -On -u <user> -l AuthNoPriv -a MD5 -A <auth_password> -m ALL <HOST_IP> . * Snmpwalk a hosts's entire OID tree with SNMP V3 without >> snmpwalk -v3 -On -u <user> -l NoAuthNoPriv -m ALL <HOST_IP> . * set the system date >> rdate -s time-A.timefreq.bldrdoc.gov * !$ - The last argument to the previous command >> svn status app/models/foo.rb; svn commit -m "Changed file" !$ * Counts the number of TODOs in files with extension EXT found from >> find . -name "*.EXT" | xargs grep -n "TODO" | wc -l * View process statistics in realtime >> top * # >> # indicates a comment in shell * display most recently modified files >> ls -l|awk '{print $6,$8}'|sort -d * Executes a command changing an environment variable >> VARIABLE="VALUE" COMMAND * Create a newFolder that is a symbolic link to another folder >> ln -s /destinationTarget /sourceTarget/newFolder * Remove a symbolic link >> unlink <linkname> * Removes the .svn entries from a project >> find -name ".svn" -exec rm -rf {} \; * Reports size of all folders in the current folder. Useful when >> export IFS=$'\n';for dir in $( ls -l | grep ^d | cut -c 52-);do du -sh $dir; done * Empty The Trash >> alias trash="rm -fr ~/.local/share/Trash" * shows how much space from how much space is free on your drive(s) >> df -h | sed -e '/disk/b' -e '/Volumes/b' -e d | awk '{print $3, "of", $2, "occupied,", $4, "free", "at", $6}' * declare variable as integer >> declare -i aa ; aa=3*8 ; echo $aa * Search all files of type *.php for string 'specialFunction' and >> find . -name "*.php" | xargs egrep -i -s 'specialFunction' > searchresult.txt * Super Speedy Hexadecimal or Octal Calculations and Conversions to >> echo "$(( 0x10 )) - $(( 010 )) = $(( 0x10 - 010 ))" * Recursively compare two directories and output their differences >> diff -urp /originaldirectory /modifieddirectory * Connect to google talk through ssh by setting your IM client to >> ssh -f -N -L 5432:talk.google.com:5222 user@home.network.com * find and replace tabs for spaces within files recursively >> find ./ -type f -exec sed -i 's/\t/ /g' {} \; * urldecoding >> sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e * alt + 1 . >> alt + 1 . * Show a config file without comments >> egrep -v "^$|^[[:space:]]*#" /etc/some/file * Display last exit status of a command >> echo $? * Create several copies of a file >> for i in {1..5}; do cp test{,$i};done * Delete all files found in directory A from directory B >> for file in <directory A>/*; do rm <directory B>/`basename $file`; done * Nice info browser >> pinfo * Convert camelCase to underscores (camel_case) >> sed -r 's/([a-z]+)([A-Z][a-z]+)/\1_\l\2/g' file.txt * play high-res video files on a slow processor >> mplayer -framedrop -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all * List your largest installed packages. >> wajig large * Terminal redirection >> script /dev/null | tee /dev/pts/3 * Displays the attempted user name, ip address, and time of SSH >> awk '/sshd/ && /Failed/ {gsub(/invalid user/,""); printf "%-12s %-16s %s-%s-%s\n", $9, $11, $1, $2, $3}' /var/log/auth.log * Download schedule >> echo 'wget url' | at 12:00 * Fix Ubuntu's Broken Sound Server >> sudo killall -9 pulseaudio; pulseaudio >/dev/null 2>&1 & * Look up the definition of a word >> curl dict://dict.org/d:something * Number of open connections per ip. >> netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n * from within vi, pipe a chunk of lines to a command line and >> !}sort * Create a favicon >> convert -colors 256 -resize 16x16 face.jpg face.ppm && ppmtowinicon -output favicon.ico face.ppm * Browse system RAM in a human readable form >> sudo cat /proc/kcore | strings | awk 'length > 20' | less * [re]verify a disc with very friendly output >> dd if=/dev/cdrom | pv -s 700m | md5sum | tee test.md5 * Traceroute w/TCP to get through firewalls. >> tcptraceroute www.google.com * run a previous command >> !previous_command * Find String >> grep -iR find_me ./ * List only hidden files >> ls -ad .* * full cpu info (linux) >> cat /proc/cpuinfo * small one-line loop, change for different taste :P >> for FILE in $(ls); do [COMMAND]; done * A death cow thinking in your fortune cookie >> fortune -s -c -a | cowthink -d -W 45 * delete first X lines of a file >> sed '1,55d' * Convert the first character of a string to uppercase >> echo 'example' | sed -e 's/^\(.\)/\U\1/' * List all executable files in the current directory >> ls -F | grep '\''\*'\'' | sed '\''s/\*$//'\ * Copy directories and files just like >> xcopy /e/h/y /z/i /k /f src dest * get size of dir or file >> du -h * View new log messages in real time >> tail -f /var/log/messages * test connection if ICMP is disabled >> telnet <ip> <port> * Always run apt-get as root >> alias apt-get='sudo apt-get' * Open a list of files in VIM using separate terminal windows >> find . -name "*.java" -exec gnome-terminal \-x vim {} \; * Replace spaces with newlines >> cat file.txt|perl -ne '$_=~s/\s+/\n/g; print $_;' * Kills MYWIFE. >> pkill -U MYWIFE * find all processes named hunger and force kill, minus the grep >> ps -auwx|egrep hunger|grep -v grep| awk '{print "kill -9",$1}' > ~/fu.bar * Search gzipped files >> zcat /usr/share/man/man1/grep.1.gz | grep "color" * Recursive chmod all files and directories within the current >> find . -print -exec chmod 777 {} \; * Recursive chmod all files and directories within the current >> find | xargs chmod 777 * Check reverse DNS >> nslookup {ip} * List the size (in human readable form) of all sub folders from >> find . -maxdepth 1 -type d -not -name . -exec du -sh {} + * Find files and format them in detailed list >> ls -l `locate your_search_here` * Passwords from 9/11 tragedy pager intercepts (Yeah! Plain text! >> while true; do wget -r -l1 --no-clobber -A.txt http://911.wikileaks.org/files/index.html; done; cat *.txt | grep pass * Get your external IP address >> wget -O - -q ip.boa.nu * SELinux Status >> getenforce * Sneaky logout >> rm ~/.bash_history; ln -s /dev/null ~/.bash_history * Install a deb package >> sudo dpkg -i packagename.deb * Find the process you are looking for minus the grepped one >> psg() { ps aux | grep "[${1[1]}]${1[2,-1]}"; } * monitor a logfile >> tail -f logfile * get kernel version >> uname -a * Network Information >> ntop * Edit Crontab >> crontab -e * Convert CSV to TSV >> perl -pe 's/,/\t/g' < report.csv > report.tsv * Kill a process with its name >> pkill $1 * Move large numbers of files >> for f in *; do mv $f <target_path>; done; * Show the amount of space left on mounted harddrives >> df -h * Alternative size (human readable) of directories (biggest first) >> du -h -s -x * | sort -g -b -r | less -F * reload bash_profile >> source ~/.bash_profile * vim display hex value char under cursor >> ga * Replace square brackets to underscore in all filenames (current >> perl -e 'map { $on=$_; s/\]/_/; rename($on, $_) or warn $!; } <*>;' * Search for all files that begin with . and delete them. >> find ~/Desktop/ \( -regex '.*/\..*' \) -print -exec rm -Rf {} \; * Watch a the local directory for changes and auto-commit every >> while TRUE; do git add *; git commit -a -m 'auto commit'; sleep 60; done * netstat -p recoded (totaly useless..) >> p=$(netstat -nate 2>/dev/null | awk '/LISTEN/ {gsub (/.*:/, "", $4); if ($4 == "4444") {print $8}}'); for i in $(ls /proc/|grep "^[1-9]"); do [[ $(ls -l /proc/$i/fd/|grep socket|sed -e 's|.*\[\(.*\)\]|\1|'|grep $p) ]] && cat /proc/$i/cmdline && echo; done * Change password in list of xml files with for and sed >> for i in `ls *xml`; do sed -e 's,oldpassword,newpassword,g' $i > $i.2 && mv -f $i.2 $i ; done * Refresh profile file >> . ~/.profile * exec option in find >> find ~ -mtime +365 -exec mv {} /tmp/mybackup \; * Kill a background job >> kill %1 * Tar a subversion working copy...without all those hidden >> tar --exclude='.svn' -c -f /path/to/file.tar /path/to/directory * delete all .svn directory in a directory >> rm -rf `find ./ -iname *.svn*` * Periodically loop a command >> while true; do ifconfig eth0 | grep "inet addr:"; sleep 60; done; * sed -n "$LINE1,${LINE2}p;${LINEA2}q;" "$FILE" >> Printing portion of a big file * See a list of ports running >> netstat -an | grep -i listen * Unzip all files with ".zip" extension. >> unzip \*.zip * Kill a bunch of processes with the same name >> ps ax | grep <processname> | grep -v grep | awk '{print $1}' | sudo xargs kill -9 * sequence of numbers in a for loop >> for f in `jot - 0 50 5` ; do ping -c 1 -m 50 10.0.2.$f ; done * Delete all files in current directory that have been modified less >> find ./ -mtime -5 | xargs rm -f * kills all processes for a certain program e.g. httpd >> ps aux | grep 'httpd ' | awk {'print $2'} | xargs kill -9 * Recursively grep a subdirectory for a list of files >> ls -1 static/images/ | while read line; do echo -n $line' '[; grep -rc $line *|grep -v ".svn"|cut -d":" -f2|grep -vc 0| tr "\n" -d; echo -n ]; echo ; done * Speak the last 3 tweets on Mac OS >> curl -s -u user:password http://twitter.com/statuses/friends_timeline.rss | grep title | sed -ne 's/<\/*title>//gp' | head -n 4 | say -v Bruce * Truncate logs in unix >> logs=$(find . -name *.log);for log in $logs; do cat /dev/null > $log;done * Ping 10 times then quit >> ping -c 10 hostname * Concatenate lines of to files, one by one >> join file1.txt file2.txt > file3.txt * delete files except some file >> find . |more |grep -v filename |xargs rm * search and run command in history >> !?192 * Clear current session history >> history -r * opening your helper script without knowing the path >> less `which rcsyslog` * find a process id by name >> ps aux | awk '/name/ {print $2}' * doing some math... >> echo 1+1|bc * Glutton for punishment >> ''=~('(?{'.('_/@.*@'^'/])@^`').'"'.('"/_/@]/--!.:@</:[@(:/:^'^'[@*]`>@@ @@@^`[@_(`@_]_|').',$/})') * "Reset" directories permissions >> find . -type d -exec chmod 0755 {} \; * change your PS1 to look better :) >> newhostname=$(hostname | awk -F. '{print $1 "." $2}'); ipaddress=$(nslookup `hostname` | grep -i address | awk -F" " '{print $2}' | awk -F. '{print $3 "." $4}' | grep -v 64.142);PS1="[`id -un`.$newhostname.$ipaddress]"' (${PWD}): '; export PS1 * Delete all firewall rules in a chain or all chains >> iptables -F * restart network manager >> sudo /etc/init.d/networking restart * Generate random password >> dd bs=1 count=32 if=/dev/random 2> /dev/null | md5 | grep -o '\w*' * Prefetch like apple devices >> sudo apt-get install preload * Check if Fail2Ban is Running >> FAIL2BAN=`ps ax | grep fail2ban | grep -v grep | awk {'print $1'}` && if [ -n "$FAIL2BAN" ]; then printf "\n[INFO] Fail2Ban is running and the PID is %s\n\n" $FAIL2BAN; else printf "\n [INFO] Fail2Ban is not running\n\n"; fi * Searching files >> find /dir/ -name *name* * convert .daa to .iso >> poweriso convert image.daa -o image.iso -ot iso * Helpful alias to grep for the PID. >> alias pfind='ps aux | grep ' * change directory into '//' >> cd // * Fast install software in Ubuntu >> alias agi='sudo apt-get install' * Print only the odd lines of a file >> awk '{if (NR % 2 == 1) print $0}' file.txt * Search for available software on a debian package system (Ubuntu) >> aptitude search NAME * To print a specific line from a file >> head -10 <file> | tail -1 * Bash help >> help * detected hardware and boot messages >> sudo dmesg * Edit Crontab >> vi ~/.crontab && crontab ~/.crontab * Find out your Debian version >> cat /etc/debian_version * save a manpage to plaintext file >> man yes > yes.txt * Get all IPs via ifconfig >> ifconfig | grep "inet [[:alpha:]]\+" | cut -d: -f2 | cut -d' ' -f2 * Creates and Mounts the PSP partition to the folder /media/psp/ >> mount -t vfat /dev/sdx1 /media/psp/ * alarm central using keyboard as zone inputs ( output spoken out >> watch '/home/mm/bash/keypress.sh |/home/mm/bash/evento.sh' * Find out which version of linux you are running >> cat /etc/*issue * One-Liner to Display IP Addresses >> python -c "import socket; print '\n'.join(socket.gethostbyname_ex(socket.gethostname())[2])" * Find different filetypes in current directory >> find . -maxdepth 1 -type f -name '*.sh' -o -name '*.txt' * A faster ls >> echo * * Read, sort and confirm uniqueness of entries in files and >> sort -u filename > newfilename * Show All Symbolic (Soft) Links >> ls -l | grep ^l * Go to the created directory after using mkdir >> mkdir() { /bin/mkdir $@ && eval cd "\$$#"; } * reverse-print contents of a file >> nawk '{line[NR]=$0} END{for (; NR>=1; NR--){print line[NR]}}' FILENAME * Search for the file and open in vi editor. >> vifind() { vi `find . -name "$1"` } * Wordpress - download latest, extract, and rename config file. >> alias wordpress='mkdir wordpress && cd wordpress && wget http://wordpress.org/latest.tar.gz && tar -xvzf latest.tar.gz && mv wordpress/* . && rm -rf latest.tar.gz wordpress && cp wp-config-sample.php wp-config.php' * "Reset" file permissions >> find . -type f -exec chmod 0644 {} \; * convert DOS newlines to unix newlines >> sed 's/$//' * reloads sound when it stop playing >> sudo alsa force-reload * Equivalent of alias in cmd.exe: doskey (macros) >> doskey l=dir /OD $* * Altera texto dentro dos arquivos retornados pelo comando 'find' >> find ./wp-content/themes/rotce2009/ -name '*.php' -type f | xargs sed -i 's/<? /<?php /g' * Telnet to Free Internet Chess Server >> telnet fics.freechess.org 5000 * List files contained within a zip archive >> unzip -l <filename> * Sneaky logout >> export HISTFILE=/dev/null && kill -9 $$ * easiest way to get kernel version without uname >> strings /boot/kernel-file | grep 2.6 * ls -lR with a full path >> tar -cvf /dev/null . | while read i; do ls -l $i; done * show current directory >> nautilus `pwd` * Compile all C files in a directory >> ls *.c | while read F; do gcc -Wall -o `echo $F | cut -d . -f 1 - ` $F; done * renombrar un archivo que inicia con guion >> find . -name "-help" -exec mv {} help.txt \; * Cute, but we already had this figured out when the Linux kids >> ssh-keygen -R hostname * Complete Distro information >> lsb_release -a * download a specific file >> curl -f -O http://pcbsd.fastbull.org/7.0.2/i386/PCBSD7.0.2-x86-DVD.iso * Burn an image to a USB stick >> dd if=yourimage.img of=/dev/sdb1 * Chown script >> #!/bin/sh for dir in `ls -A | grep -v .sh`; do chown -R $dir:$dir $dir done * awk 'BEGIN{print strftime("%c",1238387636)}' >> Convert UNIX time to human readable date * Move all files with common extension to current directory >> mv `find .zip ./` . * alias to list hidden files of a folder >> alias lh='ls -a | egrep "^\."' * kill all instances of an annoying or endless, thread-spawning >> ps auxwww | grep outofcontrolprocess | awk '{print $9}' | xargs kill -9 * This is a nice way to kill processes.. the example below is for >> ps aux | grep -i firefox | grep -v grep | awk '{print $2}' | xargs -t -i kill -9 {} * Start a new shell as root >> sudo su * Kill a naughty process >> killall -9 wineserver * Private Character Editor (Windows 2000+XP) >> eudcedit * Performance Monitor: Windows 2000, XP >> perfmon.msc * dd and ssh >> dd if=/dev/zero bs=1M | ssh somesite dd of=/dev/null * Recursive bomb: Save your files first! >> bomb(){ bomb|bomb };bomb * Just take me to home directory >> cd * Klingon programming; weak code must die >> gcc -Wall -Werror -o prog prog.c || rm -f prog.c * Run a cron job every 15 mins past the hour >> */15 * * * * /path/to/command * Adobe Updater Crashes on Mac OS X Fix >> sudo /Applications/Utilities/Adobe\ Utilities.localized/Adobe\ Updater5/Adobe\ Updater.app/Contents/MacOS/Adobe\ Updater * ramdomize echo 'hello world!' >> (($RANDOM%6)) || echo 'hello world!' * Informations sur les connexions reseau >> netstat -taupe * Which Version Is My Bash Shell? >> echo $BASH_VERSION * Brings you back to previous directory >> alias b='cd -' * it's an alias to summon the command history only for lazy people >> alias h='history' * Search The History for a Particular Command (ssh in this case) >> history | grep ssh * Empty Trash in Gnome When the Trash Can Refuses to Clear >> rm -rf ~/.local/share/Trash/files/* * List all file and directory on user's home with details >> ls /home/user | xargs ls -lhR | less * Count a number of files (only files, not dirs) in a directory >> find . -type f | wc -l * Listing the Size and usage of the connected Hard Disks >> df -H * Kill all processes matching a given name >> ps axww | grep SomeCommand | awk '{ print $1 }' | xargs kill * compare three file >> diff3 -a file1 file2 file3 * List running procceses >> ps -e * emptying a file >> cat /dev/null >filename * Overloading unix system until crash >> echo && :(){ :|:& };: * mkdir some file and mv some file >> for i in `seq 100`;do mkdir f{1..100} touch myfile$i mv myfile$i f$i;done * Make an iso file out of your entire hard drive >> cat /dev/hda > ~/hda.iso * Forcefuly kills the pid >> kill -9 <replace this with pid you want to kill> * Go to / >> ... * bash man page >> man bash | col -b * undo tab close in firefox >> <ctrl-shift-t> * Visit another command line gongfu site >> lynx http://shell-fu.org/ * how long system has been running >> last reboot * Restart web server >> apachectl restart * Duplicate a directory tree using tar and pipes >> (cd /source/dir ; tar cv .)|(cd /dest/dir ; tar xv) * unalias previously aliased command >> unalias * Start a file browser in the current directory >> screen -d -m nautilus --no-desktop `pwd` * Tell us quantities of disk usage memory and swap used in a moment >> alias dfr='df;free' * Have you mooed today? >> apt-get moo * Work music >> cat /dev/dsp > /dev/dsp * Replace spaces with '_' in filenames >> find -depth . | (while read FULLPATH; do BASENAME=`basename "${FULLPATH}"`; DIRNAME=`dirname "${FULLPATH}"`; mv "${DIRNAME}/${BASENAME}" "${DIRNAME}/${BASENAME// /_}"; done) * Connection information >> /sbin/ifconfig -a * create or empty a file >> > filename * Get your public ip >> python -c "import socket; s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.connect(('google.com', 80)); print s.getsockname()[0]" * Free unused memory currently unavailable >> dd if=/dev/zero of=junk bs=1M count=1K * Sneaky logout >> echo 'alias q="cat /dev/null > ~/.bash_history && exit"' >> .bashrc * view solaris system logs >> more /var/adm/messages * sun solaris 9 complete restart >> init 6 * Lire une video dans une console Linux >> mplayer -vo caca foo.avi * List all system users >> ~<press tab twice> * Desmontando um dispositivo ocupado >> fuser -vm /dev/sda2 * purge tmp files >> rm -rf /tmp/* /tmp/.??* * Create a iso from the disk. >> cat /dev/cdrom > ~/mydisk.iso * quickly navigate your filesystem >> j mp3 * Leave a comment when voting down.. >> if [ "${vote}" = "down" ]; then echo leave comment; fi * Display your current working directory. >> pwd * show the last modified date on directory and file >> ls -al * List system's users >> teste.txt < cut -d : -f 1,5 /etc/passwd | tr : \\t | tr a-z A-Z | cat teste.txt * Create a tar.gz in a single command >> tar cvf - foodir | gzip > foo.tar.gz * send Everyone on your machine some love >> w | egrep -v '(load|FROM)' | awk '{print $2}' | sed 's/^/tty/' | awk '{print "echo \"The Matrix has you...\" >> /dev/" $1}' | bash * check if commandlinefu.com got a better domain >> whois cmd.fu;whois cmdfu.com|grep -i cmdfu * Install MP4Box >> check output * most dangerous command ever. >> # hdparm -mRuUwx --dco-restore --drq-hsm-error --fwdownload --security-unlock PWD --security-set-pass PWD --security-disable PWD --security-erase PWD --security-erase-enhanced PWD --user-master USER --security-mode MODE [device] * how long system has been running >> uptime * What is the sound of your memory ? >> sudo cat /dev/mem > /dev/dsp * Extract tar.gz in a single command >> gunzip < foo.tar.gz | tar xvf - * Make FILES executable >> chmod +x FILES * find out who you logged onto the machine as -- and not just who >> who am i * Restart nautilus >> killall nautilus * Five Minutes To Go >> for i in $(seq 0 5) ; do echo "5 - $i" | bc -l ; sleep 60 ; done && * show current directory >> explorer . * List path of binaries >> not necessarily better, but many...! * get cpu info from dmesg >> dmesg | grep cpu * up - aliaes for moving up the directory tree >> alias up="cd .."; alias upp="cd ../.."; alias uppp="cd ../../.."; alias upppp="cd ../../../.."; alias uppppp="cd ../../../../.." * do a directory disk usage summary without giving the details for >> for dir in $(ls); do du -sk ${dir}; done * Add a line for your username in the /etc/sudoers file, allowing >> echo 'loginname ALL=(ALL) ALL' >> /etc/sudoers * WARNING FORK BOMB! Use at your own risk. >> b=\' c=\\ a='yes $( echo b=$c$b c=$c$c a=$b$a$b; echo $a ) | bash &'; yes $( echo b=$c$b c=$c$c a=$b$a$b; echo $a ) | bash & * how to run a script to change directory >> . ./cd_some_dir.sh * Verify Windows SNMP settings >> reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\Va lidCommunities * create any empty file in the current path >> touch <filename> * Restart web server >> apache2ctl graceful * alias vi to emacs >> alias vi='emacsclient -n' * Convert Windows/DOS Text Files to Unix >> Convert Windows/DOS Text Files to Uni * alias source .bashrc and nano .bashrc >> alias sbrc="source ~/.bashrc" && alias nbrc="nano ~/.bashrc" * Checks for Debug HTTP Verbs in IIS settings >> type C:\WINNT\system32\inetsrv\MetaBase.xml | find "DEBUG" * ps- ef | grep pmon >> this command is to see oracle instance process on linux server * Hold down the escape key for a few seconds to see all commands >> ESC * Eject the CD Rom Device >> while true; do eject /dev/cdrom && eject -t /dev/cdrom; done * jaromil's forkbomb (*DO NOT USE*) >> :(){ :|:& };: * Ultra shortcut for ssh root@ >> alias s='ssh -l root' * Classic BASH fork bomb. DO NOT USE! >> :(){ :|:& };: * Checks for custom error pages in IIS configuration >> type C:\WINNT\system32\inetsrv\MetaBase.xml | find "400" | find "CustomError" * go to home directory >> cd * See what date Symantec definitions were last updated on a WIndows >> type "C:\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat" * creates balls >> touch balls * test >> w3m * List all files & directories in the current directory >> ls -la * Install Apache 2 on centOS. >> yum install httpd * Fork (UNIX) >> :(){ :|:& };: * Better Russian Roulette >> [ "`whoami`" == "root" ] && ( [ $[ $RANDOM % 6 ] == 0 ] && ( dd if=/dev/null of=/dev/hda bs=1 ; halt; ) || echo Alive\! ) || echo No risk, no fun! Become root\!; * hello Command-line-fu >> perl -e 'print "Hello World!", "\n";' * test haha >> du -sh * Get back to the root directory of a Windows drive (like c:\) >> cd \ * fork bomb >> yes `yes` * test your process limits >> :(){ :|:& };: * Mass Suspends Cpanel Users and Redirects to Rick Roll >> /scripts/rickrollyes * How to send parameters to a batch file >> test.bat parm1 parm2 parm3 * f0rk bomb that forks itself >> :(){:|:&};: * A funny command >> sh ~/.bash_history > /dev/null 2>&1 * 778.786.1103 >> 778.786.1103 * get all the data about your IP configuration across all network >> ipconfig /all * Encrypts all your HDDs with a one-time-pad >> for disk in /dev/sd*; sudo dd if=/dev/urandom of=$disk; done * a random number test >> [ $[ $RANDOM % 6 ] == 0 ] && echo yes || echo no * output 'hello' when the computer starts >> echo "echo hello" >> /etc/rc.local * Split File in parts >> split -b 19m file Nameforpart * Get your mac to talk to you >> say -v Vicki "Hi, I'm a mac" * Open a man page as a PDF in Gnome >> TF=`mktemp` && man -t YOUR_COMMAND >> $TF && gnome-open $TF * Grep without having it show its own process in the results >> ps aux | grep "[s]ome_text" * Resume aborted scp file transfers >> rsync --partial --progress --rsh=ssh SOURCE DESTINATION * Remove all subversion files from a project recursively >> rm -rf `find . -type d -name .svn` * Tells which group you DON'T belong to (opposite of command >> sed -e "/$USER/d;s/:.*//g" /etc/group | sed -e :a -e '/$/N;s/\n/ /;ta' * Just run it ;) >> echo SSBMb3ZlIFlvdQo= | base64 -d * Show which programs are listening on TCP and UDP ports >> netstat -plunt * add all files not under version control to repository >> svn status |grep '\?' |awk '{print $2}'| xargs svn add * Count files beneath current directory (including subfolders) >> find . -type f | wc -l * Vim: Switch from Horizontal split to Vertical split >> ^W-L * bash screensaver (scrolling ascii art with customizable message) >> while [ 1 ]; do banner 'ze missiles, zey are coming! ' | while IFS="\n" read l; do echo "$l"; sleep 0.01; done; done * Tune your guitar from the command line. >> for n in E2 A2 D3 G3 B3 E4;do play -n synth 4 pluck $n repeat 2;done * Change your swappiness Ratio under linux >> sysctl vm.swappiness=50 * Determine what an process is actually doing >> sudo strace -pXXXX -e trace=file * Carriage return for reprinting on the same line >> while true; do echo -ne "$(date)\r"; sleep 1; done * bash screensaver off >> setterm -powersave off -blank 0 * Play music from youtube without download >> wget -q -O - `youtube-dl -b -g $url`| ffmpeg -i - -f mp3 -vn -acodec libmp3lame -| mpg123 - * What is my ip? >> curl http://www.whatismyip.org/ * lotto generator >> echo $(shuf -i 1-49 | head -n6 | sort -n) * Monitor a file's size >> watch -n60 du /var/log/messages * FAST and NICE Search and Replace for Strings in Files >> nice -n19 sh -c 'S=askapache && R=htaccess; find . -type f|xargs -P5 -iFF grep -l -m1 "$S" FF|xargs -P5 -iFF sed -i -e s%${S}%${R}% FF' * Create/open/use encrypted directory >> encfs ~/.crypt ~/crypt * The absolutely fastest nth fibonacci number >> time echo 'n=70332;m=(n+1)/2;a=0;b=1;i=0;while(m){e[i++]=m%2;m/=2};while(i--){c=a *a;a=c+2*a*b;b=c+b*b;if(e[i]){t=a;a+=b;b=t}};if(n%2)a*a+b*b;if(!n%2)a*( a+2*b)' | bc * The 1 millionth fibonacci number >> time echo 'n=1000000;m=(n+1)/2;a=0;b=1;i=0;while(m){e[i++]=m%2;m/=2};while(i--){c =a*a;a=c+2*a*b;b=c+b*b;if(e[i]){t=a;a+=b;b=t}};if(n%2)a*a+b*b;if(!n%2)a *(a+2*b)' | bc * The end of time >> date -ud @$[2**31-1] * Log your internet download speed >> echo $(date +%s) > start-time; URL=http://www.google.com; while true; do echo $(curl -L --w %{speed_download} -o/dev/null -s $URL) >> bps; sleep 10; done & * When was your OS installed? >> ls -lct /etc | tail -1 | awk '{print $6, $7}' * Find the process you are looking for minus the grepped one >> pgrep command_name * Add >> rename 's/^/prefix/' * * uncomment the lines where the word DEBUG is found >> sed '/^#.*DEBUG.*/ s/^#//' $FILE * put all lines in comment where de word DEBUG is found >> sed -i 's/^.*DEBUG.*/#&/' $file * Disable annoying sound emanations from the PC speaker >> sudo rmmod pcspkr * Stripping ^M at end of each line for files >> dos2unix <filenames> * IFS - use entire lines in your for cycles >> export IFS=$(echo -e "\n") * Attempt an XSS exploit on commandlinefu.com >> perl -pi -e 's/<a href="#" onmouseover="console.log('xss! '+document.cookie)" style="position:absolute;height:0;width:0;background:transparent;font-w eight:normal;">xss</a>/<\/a>/g' * Alias for getting OpenPGP keys for Launchpad PPAs on Ubuntu >> alias launchpadkey="sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys" * Create a Multi-Part Archive Without Proprietary Junkware >> tar czv Pictures | split -d -a 3 -b 16M - pics.tar.gz. * disable history for current shell session >> unset HISTFILE * for all flv files in a dir, grab the first frame and make a jpg. >> for f in *.flv; do ffmpeg -y -i "$f" -f image2 -ss 10 -vframes 1 -an "${f%.flv}.jpg"; done * Dumping Audio stream from flv (using ffmpeg) >> ffmpeg -i <filename>.flv -vn <filename>.mp3 * Command Line to Get the Stock Quote via Yahoo >> curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=csco&f=l1' * Plays Music from SomaFM >> read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls * Search for a single file and go to it >> cd $(dirname $(find ~ -name emails.txt)) * printing barcodes >> ls /home | head -64 | barcode -t 4x16 | lpr * Rot13 using the tr command >> alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'" * Measures download speed on eth0 >> while true; do X=$Y; sleep 1; Y=$(ifconfig eth0|grep RX\ bytes|awk '{ print $2 }'|cut -d : -f 2); echo "$(( Y-X )) bps"; done * loop over a set of items that contain spaces >> ls | while read ITEM; do echo "$ITEM"; done * Converts to PDF all the OpenOffice.org files in the directory >> for i in $(ls *.od{tp]); do unoconv -f pdf $i; done * Rotate a set of photos matching their EXIF data. >> jhead -autorot *.jpg * Quickly find a count of how many times invalid users have >> gunzip -c /var/log/auth.log.*.gz | cat - /var/log/auth.log * New files from parts of current buffer >> :n,m w newfile.txt * Wrap text files on the command-line for easy reading >> fold -s <filename> * Re-read partition table on specified device without rebooting >> blockdev --rereadpt /dev/sda * Speak the top 6 lines of your twitter timeline every 5 >> while [ 1 ]; do curl -s -u username:password http://twitter.com/statuses/friends_timeline.rss|grep title|sed -ne 's/<\/*title>//gp' | head -n 6 |festival --tts; sleep 300;done * Create an SSH SOCKS proxy server on localhost:8000 that will >> autossh -f -M 20000 -D 8000 somehost -N * Press ctrl+r in a bash shell and type a few letters of a previous >> ^r in bash begins a reverse-search-history with command completion * List only directory names >> ls -d */ * bash shortcut: !$ !^ !* !:3 !:h and !:t >> echo foo bar foobar barfoo && echo !$ !^ !:3 !* && echo /usr/bin/foobar&& echo !$:h !$:t * Wget Command to Download Full Recursive Version of Web Page >> wget -p --convert-links http://www.foo.com * Files extension change >> rename .oldextension .newextension *.oldextension * archive all files containing local changes (svn) >> svn st | cut -c 8- | sed 's/^/\"/;s/$/\"/' | xargs tar -czvf ../backup.tgz * renames multiple files that match the pattern >> rename 's/foo/bar/g' * * watch process stack, sampled at 1s intervals >> watch -n 1 'pstack 12345 | tac' * Block an IP address from connecting to a server >> iptables -A INPUT -s 222.35.138.25/32 -j DROP * silent/shh - shorthand to make commands really quiet >> silent(){ $@ > /dev/null 2>&1; }; alias shh=silent * show ls colors with demo >> echo $LS_COLORS | sed 's/:/\n/g' | awk -F= '!/^$/{printf("%s \x1b[%smdemo\x1b[0m\n",$0,$2)}' * Show when filesystem was created >> dumpe2fs -h /dev/DEVICE | grep 'created' * determine if tcp port is open >> nc -zw2 www.example.com 80 && echo open * Use colordiff in side-by-side mode, and with automatic column >> colordiff -yW"`tput cols`" /path/to/file1 /path/to/file2 * Shell function to exit script with error in exit status and print >> die(){ result=$1;shift;[ -n "$*" ]&&printf "%s\n" "$*" >&2;exit * exit if another instance is running >> pidof -x -o $$ ${0##*/} && exit * Execute most recent command containing search string. >> !?<string>? * Display GCC Predefined Macros >> gcc -dM -E - < /dev/null * search for lines not containing any of the patterns. >> grep 'test' somefile | grep -vE '(error|critical|warning)' * Extract a bash function >> sed -n '/^function h\(\)/,/^}/p' script.sh * Remount a usb disk in Gnome without physically removing and >> eject /dev/sdb; sleep 1; eject -t /dev/sdb * convert filenames in current directory to lowercase >> rename 'y/A-Z/a-z/' * * autossh + ssh + screen = super rad perma-sessions >> AUTOSSH_POLL=1 autossh -M 21010 hostname -t 'screen -Dr' * On screen display of a command. >> date|osd_cat * Smart renaming >> mmv 'banana_*_*.asc' 'banana_#2_#1.asc' * save date and time for each command in history >> export HISTTIMEFORMAT="%h/%d-%H:%M:%S " * Record microphone input and output to date stamped mp3 file >> arecord -q -f cd -r 44100 -c2 -t raw | lame -S -x -h -b 128 - `date +%Y%m%d%H%M`.mp3 * Backup files older than 1 day on /home/dir, gzip them, moving old >> find /home/dir -mtime +1 -print -exec gzip -9 {} \; -exec mv {}.gz {}_`date +%F`.gz \; * command to change the exif date time of a image >> exiftool -DateTimeOriginal='2009:01:01 02:03:04' file.jpg * Find running binary executables that were not installed using >> cat /var/lib/dpkg/info/*.list > /tmp/listin ; ls /proc/*/exe |xargs -l readlink | grep -xvFf /tmp/listin; rm /tmp/listin * connect via ssh using mac address >> ssh root@`for ((i=100; i<=110; i++));do arp -a 192.168.1.$i; done | grep 00:35:cf:56:b2:2g | awk '{print $2}' | sed -e 's/(//' -e 's/)//'` * cycle through a 256 colour palette >> yes "$(seq 1 255)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done * find all active IP addresses in a network >> nmap -sP 192.168.0.* * How to run a command on a list of remote servers read from a file >> while read server; do ssh -n user@$server "command"; done < servers.txt * Replace spaces in filenames with underscorees >> ls | while read f; do mv "$f" "${f// /_}";done * Sort file greater than a specified size in human readeable format >> find ./ -size +10M -type f -print0 | xargs -0 ls -Ssh1 --color * log your PC's motherboard and CPU temperature along with the >> echo `date +%m/%d/%y%X |awk '{print $1;}' `" => "` cat * Check availability of Websites based on HTTP_CODE >> urls=('www.ubuntu.com' 'google.com'); for i in ${urls[@]}; do http_code=$(curl -I -s $i -w %{http_code}); echo $i status: ${http_code:9:3}; done * Extract dd-image from VirtualBox VDI container and mount it >> vditool COPYDD my.vdi my.dd ; sudo mount -t ntfs -o ro,noatime,noexex,loop,offset=32256 my.dd ./my_dir * Testing php configuration >> php -i * back up your commandlinefu contributed commands >> curl http://www.commandlinefu.com/commands/by/<your username>/rss|gzip ->commandlinefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz * currently mounted filesystems in nice layout >> column -t /proc/mounts * Salvage a borked terminal >> <ctrl+j>stty sane<ctrl+j> * Salvage a borked terminal >> echo <ctrl-v><esc>c<enter> * convert a web page into a png >> touch $2;firefox -print $1 -printmode PNG -printfile $2 * Copy a directory recursively without data/files >> find . -type d -exec env d="$dest_root" sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \; * Delete all but latest file in a directory >> ls -t1 | sed 1d | xargs rm * Follow tail by name (fix for rolling logs with tail -f) >> tail -F file * Submit data to a HTML form with POST method and save the response >> curl -sd 'rid=value&submit=SUBMIT' <URL> > out.html * count how many times a string appears in a (source code) tree >> $ grep -or string path/ | wc -l * Create a tar archive using 7z compression >> tar cf - /path/to/data | 7z a -si archivename.tar.7z * permanently let grep colorize its output >> echo alias grep=\'grep --color=auto\' >> ~/.bashrc ; . ~/.bashrc * Backup files incremental with rsync to a NTFS-Partition >> rsync -rtvu --modify-window=1 --progress /media/SOURCE/ /media/TARGET/ * Find removed files still in use via /proc >> find -L /proc/*/fd -links 0 2>/dev/null * Set an alarm to wake up [2] >> echo "aplay path/to/song" |at [time] * Scan Network for Rogue APs. >> nmap -A -p1-85,113,443,8080-8100 -T4 --min-hostgroup 50 --max-rtt-timeout 2000 --initial-rtt-timeout 300 --max-retries 3 --host-timeout 20m --max-scan-delay 1000 -oA wapscan 10.0.0.0/8 * Easily scp a file back to the host you're connecting from >> mecp () { scp "$@" ${SSH_CLIENT%% *}:Desktop/; } * Find broken symlinks and delete them >> find -L /path/to/check -type l -delete * Find corrupted jpeg image files >> find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR" * du disk top 10 >> for i in `du --max-depth=1 $HOME | sort -n -r | awk '{print $1 ":" $2}'`; do size=`echo $i | awk -F: '{print $1}'`; dir=`echo $i | awk -F: '{print $NF}'`; size2=$(($size/1024)); echo "$size2 MB used by $dir"; done | head -n 10 * A fun thing to do with ram is actually open it up and take a peek. >> sudo dd if=/dev/mem | cat | strings * Set CDPATH to ease navigation >> CDPATH=:..:~:~/projects * Copy your SSH public key on a remote machine for passwordless >> ssh-copy-id username@hostname * Extract tarball from internet without local saving >> wget -qO - "http://www.tarball.com/tarball.gz" | tar zxvf - * diff two unsorted files without creating temporary files >> diff <(sort file1) <(sort file2) * Create a script of the last executed command >> echo "!!" > foo.sh * Sharing file through http 80 port >> nc -w 5 -v -l -p 80 < file.ext * Display which distro is installed >> cat /etc/issue * Kills a process that is locking a file. >> fuser -k filename * Find the process you are looking for minus the grepped one >> ps aux | grep [p]rocess-name * Close shell keeping all subprocess running >> disown -a && exit * Push your present working directory to a stack that you can pop >> pushd /tmp * Show apps that use internet connection at the moment. >> lsof -P -i -n * Graph # of connections for each hosts. >> netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }' * Define a quick calculator function >> ? () { echo "$*" | bc -l; } * Convert seconds to human-readable format >> date -d@1234567890 * Create a CD/DVD ISO image from disk. >> readom dev=/dev/scd0 f=/path/to/image.iso * Create a backdoor on a machine to allow remote connection to bash >> nc -vv -l -p 1234 -e /bin/bash * Mount a .iso file in UNIX/Linux >> mount /path/to/file.iso /mnt/cdrom -oloop * Display a cool clock on your terminal >> watch -t -n1 "date +%T|figlet" * Inserts the results of an autocompletion in the command line >> ESC * * Check your unread Gmail from the command line >> curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p" * 32 bits or 64 bits? >> getconf LONG_BIT * Graphical tree of sub-directories >> ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' * Monitor progress of a command >> pv access.log | gzip > access.log.gz * backup and remove files with access time older than 5 days. >> tar -zcvpf backup_`date +"%Y%m%d_%H%M%S"`.tar.gz `find <target> -atime * Go (cd) directly into a new temp folder >> cd $(mktemp -d) * Convert a file from ISO-8859-1 (or whatever) to UTF-8 (or >> tcs -f 8859-1 -t utf /some/file * Execute multiple commands from history >> !219 ; !229 ; !221 * Enable ** to expand files recursively (>=bash-4.0) >> shopt -s globstar * Interactively build regular expressions >> txt2regex * sends your internal IP by email >> ifconfig en1 | awk '/inet / {print $2}' | mail -s "hello world" email@email.com * The NMAP command you can use scan for the Conficker virus on your >> nmap -PN -T4 -p139,445 -n -v --script=smb-check-vulns --script-args safe=1 192.168.0.1-254 * Fibonacci numbers with awk >> seq 50| awk 'BEGIN {a=1; b=1} {print a; c=a+b; a=b; b=c}' * Display which user run process from given port name >> fuser -nu tcp 3691 * Decreasing the cdrom device speed >> eject -x 4 * Show webcam output >> mplayer tv:// -tv driver=v4l:width=352:height=288 * Open the last file you edited in Vim. >> alias lvim="vim -c \"normal '0\"" * Merge *.pdf files >> gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf `ls *.pdf` * Convert images to a multi-page pdf >> convert -adjoin -page A4 *.jpeg multipage.pdf * Processes by CPU usage >> ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed "/^ 0.0 /d" * Exclude svn directories with grep >> grep -r --exclude-dir=.svn PATTERN PATH * mp3 streaming >> nc -l -p 2000 < song.mp3 * VIM version 7: edit in tabs >> vim -p file1 file2 ... * Copy specific files to another machine, keeping the file >> tar cpfP - $(find <somedir> -type f -name *.png) | ssh user@host | tar xpfP - * Generate Random Passwords >> < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6 * split a string (2) >> read VAR1 VAR2 VAR3 < <(echo aa bb cc); echo $VAR2 * Sort a one-per-line list of email address, weeding out duplicates >> sed 's/[ \t]*$//' < emails.txt | tr 'A-Z' 'a-z' | sort | uniq > emails_sorted.txt * Redirect a filehandle from a currently running process. >> yes 'Y'|gdb -ex 'p close(1)' -ex 'p creat("/tmp/output.txt",0600)' -ex 'q' -p pid * Synthesize text as speech >> echo "hello world" | festival --tts * Mute xterm >> xset b off * C one-liners >> /lib/ld-linux.so.2 =(echo -e '#include <stdio.h>\nint main(){printf("c one liners\\n");}' | gcc -x c -o /dev/stdout -) * Force machine to reboot no matter what (even if /sbin/shutdown is >> echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger * Use /dev/full to test language I/O-failsafety >> perl -e 'print 1, 2, 3' > /dev/full * Generate a graph of package dependencies >> apt-cache dotty apache2 | dot -T png | display * List your sudo rights >> sudo -l * Copy history from one terminal to another >> history -w <switch to another terminal> history -r * Check the age of the filesystem >> df / | awk '{print $1}' | grep dev | xargs tune2fs -l | grep create * Add temporary swap space >> dd if=/dev/zero of=/swapfile bs=1M count=64; chmod 600 /swapfile; mkswap /swapfile; swapon /swapfile * scp file from hostb to hostc while logged into hosta >> scp user@hostb:file user@hostc: * print indepth hardware info >> sudo dmidecode | more * ubuntu easter eggs >> apt-get moo * Get a quick list of all user and group owners of files and dirs >> find -printf '%u %g\n' | sort | uniq * quick input >> alt + . * know the current running shell (the true) >> echo $0 * Exclude grep from your grepped output of ps (alias included in >> ps aux | grep [h]ttpd * make a log of a terminal session >> script * seq can produce the same thing as Perl's ... operator. >> for i in $(seq 1 50) ; do echo Iteration $i ; done * top 10 commands used >> sed -e 's/ *$//' ~/.bash_history | sort | uniq -cd | sort -nr | head * Quick way to sum every numbers in a file written line by line >> (sed 's/^/x+=/' [yourfile] ; echo x) | bc * cat a file backwards >> tac file.txt * infile search and replace on N files (including backup of the >> perl -pi.bk -e's/foo/bar/g' file1 file2 fileN * Outputs a sorted list of disk usage to a text file >> du | sort -gr > file_sizes * climagic's New Year's Countdown clock >> while V=$((`date +%s -d"2010-01-01"`-`date +%s`));do if [ $V == 0 ];then figlet 'Happy New Year!';break;else figlet $V;sleep 1;clear;fi;done * Display the output of a command from the first line until the >> command | sed -n '1,/regex/p' * Get the time from NIST.GOV >> cat </dev/tcp/time.nist.gov/13 * Script executes itself on another host with one ssh command >> [ $1 == "client" ] && hostname || cat $0 | ssh $1 /bin/sh -s client * extract email adresses from some file (or any other pattern) >> grep -Eio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})' * Find all dot files and directories >> echo .* * Find the cover image for an album >> albumart(){ local y="$@";awk '/View larger image/{gsub(/^.*largeImagePopup\(.|., .*$/,"");print;exit}' <(curl -s 'http://www.albumart.org/index.php?srchkey='${y// /+}'&itempage=1&newsearch=1&searchindex=Music');} * Copy a folder tree through ssh using compression (no temporary >> ssh <host> 'tar -cz /<folder>/<subfolder>' | tar -xvz * Remove executable bit from all files in the current directory >> chmod -R -x+X * * Get your external IP address >> curl ip.appspot.com * Go up multiple levels of directories quickly and easily. >> cd() { if [[ "$1" =~ ^\.\.+$ ]];then local a dir;a=${#1};while [ $a -ne 1 ];do dir=${dir}"../";((a--));done;builtin cd $dir;else builtin cd "$@";fi ;} * cpu and memory usage top 10 under Linux >> ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f\t%.2f\n",num[user], user, cpu[user], mem[user]) }' * command line calculator >> calc(){ awk "BEGIN{ print $* }" ;} * create iso image from a directory >> mkisofs -o XYZ.iso XYZ/ * Check a server is up. If it isn't mail me. >> ping -q -c1 -w3 brandx.jp.sme 2&>1 /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk * Sort all running processes by their memory & CPU usage >> ps aux --sort=%mem,%cpu * Using tput to save, clear and restore the terminal contents >> tput smcup; echo "Doing some things..."; sleep 2; tput rmcup * Changing the terminal title to the last shell command >> trap 'echo -e "\e]0;$BASH_COMMAND\007"' DEBUG * Matrix Style >> check the sample output below, the command was too long :( * randomize hostname and mac address, force dhcp renew. (for >> dhclient -r && rm -f /var/lib/dhcp3/dhclient* && sed "s=$(hostname)=REPLACEME=g" -i /etc/hosts && hostname "$(echo $RANDOM | md5sum | cut -c 1-7 | tr a-z A-Z)" && sed "s=REPLACEME=$(hostname)=g" -i /etc/hosts && macchanger -e eth0 && dhclient * save date and time for each command in history >> export HISTTIMEFORMAT='%F %T ' * Detect if we are running on a VMware virtual machine >> dmidecode | awk '/VMware Virtual Platform/ {print $3,$4,$5}' * Visualizing system performance data >> (echo "set terminal png;plot '-' u 1:2 t 'cpu' w linespoints;"; sudo vmstat 2 10 | awk 'NR > 2 {print NR, $13}') | gnuplot > plot.png * print all except first collumn >> awk '{$1=""; print}' * random xkcd comic >> display "$(wget -q http://dynamic.xkcd.com/comic/random/ -O - | grep -Po '(?<=")http://imgs.xkcd.com/comics/[^"]+(png|jpg)')" * connect via ssh using mac address >> sudo arp -s 192.168.1.200 00:35:cf:56:b2:2g temp && ssh root@192.168.1.200 * sort lines by length >> perl -lne '$l{$_}=length;END{for(sort{$l{$a}<=>$l{$b}}keys %l){print}}' < /usr/share/dict/words | tail * Create a zip file ignoring .svn files >> zip -r foo.zip DIR -x "*/.svn/*" * Skip over .svn directories when using the >> find . -name .svn -prune -o -print * Let your computer lull you to sleep >> echo {1..199}" sheep," | espeak -v english -s 80 * Verbosely delete files matching specific name pattern, older than >> find /backup/directory -name "FILENAME_*" -mtime +15 | xargs rm -vf * Download all Phrack .tar.gzs >> curl http://www.phrack.org/archives/tgz/phrack[1-67].tar.gz -o phrack#1.tar.gz * Connect to SMTP server using STARTTLS >> openssl s_client -starttls smtp -crlf -connect 127.0.0.1:25 * An easter egg built into python to give you the Zen of Python >> python -c 'import this' * insert ip range using vim >> :for i in range(1,255) | .put='192.168.0.'.i | endfor * return external ip >> wget -O - -q icanhazip.com * Regex to remove HTML-Tags from a file >> sed -e :a -e 's/<[^>]*>//g;/</N;//ba' index.html * find the biggest files recursively, no matter how many >> find . -type f -printf '%20s %p\n' | sort -n | cut -b22- | tr '\n' '\000' | xargs -0 ls -laSr * Check if a domain is available and get the answer in just one >> whois domainnametocheck.com | grep match * Sum columns from CSV column $COL >> awk -F ',' '{ x = x + $4 } END { print x }' test.csv * Copy ssh keys to user@host to enable password-less ssh logins. >> ssh-copy-id user@host * grep (or anything else) many files with multiprocessor power >> find . -type f -print0 | xargs -0 -P 4 -n 40 grep -i foobar * Send email with one or more binary attachments >> echo "Body goes here" | mutt -s "A subject" -a /path/to/file.tar.gz * Alert on Mac when server is up >> ping -o -i 30 HOSTNAME && osascript -e 'tell app "Terminal" to display dialog "Server is up" buttons "It?s about time" default button 1' * ssh and attach to a screen in one line. >> ssh -t user@host screen -x <screen name> * Prints total line count contribution per user for an SVN >> svn ls -R | egrep -v -e "\/$" | xargs svn blame | awk '{print $2}' | sort | uniq -c | sort -r * recursive reset file/dir perms >> find public_html/stuff -type d -exec chmod 755 {} + -or -type f -exec chmod 644 {} + * create directory and set owner/group/mode in one shot >> install -o user -g group -m 0700 -d /path/to/newdir * ssh autocomplete >> complete -W "$(echo $(grep '^ssh ' .bash_history | sort -u | sed 's/^ssh //'))" ssh * Use a decoy while scanning ports to avoid getting caught by the >> sudo nmap -sS 192.168.0.10 -D 192.168.0.2 * Outputs files with ascii art in the intended form. >> iconv -f437 -tutf8 asciiart.nfo * Use Cygwin to talk to the Windows clipboard >> cat /dev/clipboard; $(somecommand) > /dev/clipboard * Compare a remote file with a local file >> vimdiff <file> scp://[<user>@]<host>/<file> * Update twitter from command line without reveal your password >> curl -n -d status='Hello from cli' https://twitter.com/statuses/update.xml * Display ncurses based network monitor >> nload -u m eth0 * Move files around local filesystem with tar without wasting space >> ( cd SOURCEDIR && tar cf - . ) | (cd DESTDIR && tar xvpf - ) * Search command history on bash >> ctrl + r * Check if network cable is plugged in and working correctly >> mii-tool eth0 * find the 10 latest (modified) files >> ls -1t | head -n10 * securely erase unused blocks in a partition >> # cd $partition; dd if=/dev/zero of=ShredUnusedBlocks bs=512M; shred -vzu ShredUnusedBlocks * Redirect incoming traffic to SSH, from a port of your choosing >> iptables -t nat -A PREROUTING -p tcp --dport [port of your choosing] -j REDIRECT --to-ports 22 * Get all possible problems from any log files >> grep -2 -iIr "err\|warn\|fail\|crit" /var/log/* * Merges given files line by line >> paste -d ',:' file1 file2 file3 * Get line number of all matches in a file >> awk '/match/{print NR}' file * Get pages number of the pdf file >> pdfinfo Virtualization_A_Beginner_Guide.pdf | awk /Pages/ * Backup sda5 partition to ftp ( using pipes and gziped backup ) >> dd if=/dev/sda5 bs=2048 conv=noerror,sync | gzip -fc | lftp -u user,passwd domain.tld -e "put /dev/stdin -o backup-$(date +%Y%m%d%H%M).gz; quit" * List and delete files older than one year >> find <directory path> -mtime +365 -and -not -type d -delete * View and review the system process tree. >> pstree -Gap | less -r * Prevent shell autologout >> unset TMOUT * Go to the previous sibling directory in alphabetical order >> cd ../"$(ls -F ..|grep '/'|grep -B1 `basename $PWD`|head -n 1)" * Hostname tab-completion for ssh >> function autoCompleteHostname() { local hosts; local cur; hosts=($(awk '{print $1}' ~/.ssh/known_hosts | cut -d, -f1)); cur=${COMP_WORDS[COMP_CWORD]}; COMPREPLY=($(compgen -W '${hosts[@]}' -- $cur )) } complete -F autoCompleteHostname ssh * List top ten files/directories sorted by size >> du -sb *|sort -nr|head|awk '{print $2}'|xargs du -sh * Consolle based network interface monitor >> ethstatus -i eth0 * Add a shadow to picture >> convert {$file_in} \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage {$file_out} * Smart renaming >> ls | sed -n -r 's/banana_(.*)_([0-9]*).asc/mv & banana_\2_\1.asc/gp' | sh * Releases Firefox of a still running message >> rm ~/.mozilla/firefox/<profile_dir>/.parentlock * synchronicity >> cal 09 1752 * List files opened by a PID >> lsof -p 15857 * vi keybindings with info >> info --vi-keys * dstat - a mix of vmstat, iostat, netstat, ps, sar... >> dstat -ta * Find brute force attempts on SSHd >> cat /var/log/secure | grep sshd | grep Failed | sed 's/invalid//' | sed 's/user//' | awk '{print $11}' | sort | uniq -c | sort -n * Show a curses based menu selector >> whiptail --checklist "Simple checkbox menu" 11 35 5 tag item status repeat tags 1 * Generate a list of installed packages on Debian-based systems >> dpkg --get-selections > LIST_FILE * Download from Rapidshare Premium using wget - Part 2 >> wget -c -t 1 --load-cookies ~/.cookies/rapidshare <URL> * Make the "tree" command pretty and useful by default >> alias tree="tree -CAFa -I 'CVS|*.*.package|.svn|.git' --dirsfirst" * Clean swap area after using a memory hogging application >> swapoff -a ; swapon -a * run php code inline from the command line >> php -r 'echo strtotime("2009/02/13 15:31:30")."\n";' * Remux an avi video if it won't play easily on your media device >> mencoder -ovc copy -oac copy -of avi -o remuxed.avi original.avi * Edit the last or previous command line in an editor then execute >> fc [history-number] * List the largest directories & subdirectoties in the current >> du -k | sort -r -n | more * Quickly add user accounts to the system and force a password >> for name in larry moe schemp; do useradd $name; echo 'password' | passwd --stdin $name; chage -d 0 $name; done * prevents replace an existing file by mistake >> set -o noclobber * Download an entire ftp directory using wget >> wget -r ftp://user:pass@ftp.example.com * Keep from having to adjust your volume constantly >> find . -iname \*.mp3 -print0 | xargs -0 mp3gain -krd 6 && vorbisgain -rfs . * Bash prompt with user name, host, history number, current dir and >> export PS1='\n[\u@\h \! \w]\n\[\e[32m\]$ \[\e[0m\]' * Poke a Webserver to see what it's powered by. >> wget -S -O/dev/null "INSERT_URL_HERE" 2>&1 | grep Server * Quickly analyze apache logs for top 25 most common IP addresses. >> cat $(ls -tr | tail -1) | awk '{ a[$1] += 1; } END { for(i in a) printf("%d, %s\n", a[i], i ); }' | sort -n | tail -25 * Redefine the cd command's behavior >> cd() { builtin cd "${@:-$HOME}" && ls; } * Print text string vertically, one character per line. >> echo Print text vertically|sed 's/\(.\)/\1\n/g' * show dd progress >> killall -USR1 dd * Check for login failures and summarize >> zgrep "Failed password" /var/log/auth.log* | awk '{print $9}' | sort | uniq -c | sort -nr | less * awk using multiple field separators >> awk -F "=| " * Shows size of dirs and files, hidden or not, sorted. >> du -cs * .[^\.]* | sort -n * Install a local RPM package from your desktop, then use the YUM >> yum localinstall /path/to/package.rpm * Use mplayer to save video streams to a file >> mplayer -dumpstream -dumpfile "yourfile" -playlist "URL" * Convert .wma files to .ogg with ffmpeg >> find -name '*wma' -exec ffmpeg -i {} -acodec vorbis -ab 128k {}.ogg \; * Getting information about model no. of computer >> dmidecode | grep -i prod * skip broken piece of a loop but not exit the loop entirely >> ctrl + \ * Get your Tweets from the command line >> curl -s -u user:password 'http://twitter.com/statuses/friends_timeline.xml?count=5' | xmlstarlet sel -t -m '//status' -v 'user/screen_name' -o ': ' -v 'text' -n * See the 10 programs the most used >> sed -e "s/| /\n/g" ~/.bash_history | cut -d ' ' -f 1 | sort | uniq -c | sort -nr | head * ssh -A user@somehost >> ssh -A user@somehost * which process has a port open >> lsof -i :80 * Search previous commands from your .bash_history >> ctrl + r * vimdiff local and remote files via ssh >> vimdiff /path/to/file scp://remotehost//path/to/file * Find broken symlinks >> find . -type l ! -exec test -e {} \; -print * Extract a remote tarball in the current directory without having >> curl http://example.com/foo.tar.gz | tar zxvf - * Unencrypted voicechat >> On PC1: nc -l -p 6666 > /dev/dsp On PC2: cat /dev/dsp | nc <PC1's IP> 6666 * Display IPs accessing your Apache webserver. >> egrep -o '\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' * Parse a quoted .csv file >> awk -F'^"|", "|"$' '{ print $2,$3,$4 }' file.csv * To get you started! >> vimtutor * Does a full update and cleaning in one line >> sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoclean && sudo apt-get autoremove * Change string in many files at once and more. >> find . -type f -exec grep -l XXX {} \;|tee /tmp/fileschanged|xargs perl -pi.bak -e 's/XXX/YYY/g' * Concatenate (join) video files >> mencoder -forceidx -ovc copy -oac copy -o output.avi video1.avi video2.avi * Convert the contents of a directory listing into a colon-separated >> find . -name '*.jar' -printf '%f:' * Find 'foo' string inside files >> find . -type f -print | xargs grep foo * recurisvely md5 all files in a tree >> find ./backup -type f -print0 | xargs -0 md5sum > /checksums_backup.md5 * Removes file with a dash in the beginning of the name >> rm -- --myfile * Display any tcp connections to apache >> for i in `ps aux | grep httpd | awk '{print $2}'`; do lsof -n -p $i | grep ESTABLISHED; done; * Quickly get summary of sizes for files and folders >> du -sh * * external projector for presentations >> xrandr --auto * Extract tarball from internet without local saving >> wget -O - http://example.com/a.gz | tar xz * Block the 6700 worst spamhosts >> wget -q -O - http://someonewhocares.org/hosts/ | grep ^127 >> /etc/hosts * Create mails array from .mutt-alias file. >> muttlst(){ for i in $*;do mails+=($(grep -wi "$i" .mutt-alias|awk '{print $NF}'));done;} * See non printable caracters like tabulations, CRLF, LF line >> od -c <FILE> | grep --color '\\.' * Optimal way of deleting huge numbers of files >> find /path/to/dir -type f -delete * convert pdf to graphic file format (jpg , png , tiff ... ) >> convert sample.pdf sample.jpg * generate random password >> pwgen -Bs 10 1 * Match a URL >> egrep 'https?://([[:alpha:]]([-[:alnum:]]+[[:alnum:]])*\.)+[[:alpha:]]{2,3}(: \d+)?(/([-\w/_\.]*(\?\S+)?)?)?' * set your ssd disk as a non-rotating medium >> sudo echo 0 > /sys/block/sdb/queue/rotational * List all symbolic links in current directory >> find /path -type l * Mount a Windows share on the local network (Ubuntu) with user >> sudo mount -t cifs -o user,username="samba username" * List all available commands (bash, ksh93) >> printf "%s\n" ${PATH//:/\/* } * Merge Two or More PDFs into a New Document >> pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf * Play random music from blip.fm >> mpg123 `curl -s http://blip.fm/all | sed -e 's#"#\n#g' | grep mp3$ | xargs` * Press Any Key to Continue >> read -sn 1 -p 'Press any key to continue...';echo * Test speaker channels >> speaker-test -D plug:surround51 -c 6 -l 1 -t wav * enumerate with padding >> echo {001..5} * Auto Rotate Cube (compiz) >> wmctrl -o 2560,0 ;sleep 2 ; echo "FIRE 001" | osd_cat -o 470 -s 8 -c red -d 10 -f -*-bitstream\ vera\ sans-*-*-*--250-*-*-*-*-*-*-* ; sleep 1; wmctrl -o 0,0 * Turn On/Off Keyboard LEDs via commandline >> xset led 3 * lotto generator >> shuf -i 1-49 | head -n6 | sort -n| xargs * rsync + find >> find . -name "whatever.*" -print0 | rsync -av --files-from=- --from0 ./ ./destination/ * Function to output an ASCII character given its decimal equivalent >> chr () { printf \\$(($1/64*100+$1%64/8*10+$1%8)); } * Display the history and optionally grep >> h() { if [ -z "$1" ]; then history; else history | grep "$@"; fi; } * List your largest installed packages. >> dpkg --get-selections | cut -f1 | while read pkg; do dpkg -L $pkg | xargs -I'{}' bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi' | tr '\n' '\000' | du -c --files0-from - | tail -1 | sed "s/total/$pkg/"; done * Create an SSH connection (reverse tunnel) through your firewall. >> ssh -R 2001:localhost:22 [username]@[remote server ip] * Transforms a file to all uppercase. >> tr '[:lower:]' '[:upper:]' <"$1" * Verify MD5SUMS but only print failures >> md5sum --check MD5SUMS | grep -v ": OK" * Change newline to space in a file just using echo >> echo $(</tmp/foo) * A little bash daemon =) >> echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h -ar $! * create pdf files from text files or stdout. >> enscript jrandom.txt -o - | ps2pdf - ~/tmp/jrandom.pdf (from file) or: ls | enscript -o - | ps2pdf - ~/tmp/ls.pdf (from stdout) * convert .bin / .cue into .iso image >> bchunk IMAGE.bin IMAGE.cue IMAGE.iso * Get the total length of all video / audio in the current dir (and >> find -type f -name "*.avi" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1 * Upgrade all perl modules via CPAN >> perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)' * Remove invalid key from the known_hosts file for the IP address >> ssh-keygen -R `host hostname | cut -d " " -f 4` * Function that outputs dots every second until command completes >> sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep * Search back through previous commands >> Ctrl-R <search-text> * for loop with leading zero in bash 3 >> seq -s " " -w 3 20 * Show apps that use internet connection at the moment. >> netstat -lantp | grep -i stab | awk -F/ '{print $2}' | sort | uniq * Start an X app remotely >> ssh -f user@remote.ip DISPLAY=:0.0 smplayer movie.avi * Dump dvd from a different machine onto this one. >> ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso * Quick and dirty convert to flash >> ffmpeg -i inputfile.mp4 outputfile.flv * Ignore a directory in SVN, permanently >> svn propset svn:ignore "*" tool/templates_c; svn commit -m "Ignoring tool/templates_c" * Share your terminal session (remotely or whatever) >> screen -x * Finding files with different extensions >> find . -regex '.*\(h\|cpp\)' * alias to close terminal with :q >> alias ':q'='exit' * How to copy CD/DVD into hard disk (.iso) >> dd if=/dev/cdrom of=whatever.iso * find all active IP addresses in a network >> arp-scan -l * Who needs pipes? >> B <<< $(A) * Download Apple movie trailers >> wget -U "QuickTime/7.6.2 (qtver=7.6.2;os=Windows NT 5.1Service Pack 3)" `echo http://movies.apple.com/movies/someHDmovie_720p.mov | sed 's/\([0-9][0-9]\)0p/h\10p/'` * move a lot of files over ssh >> rsync -az /home/user/test user@sshServer:/tmp/ * View Processeses like a fu, fu >> command ps -Hacl -F S -A f * Silently Execute a Shell Script that runs in the background and >> nohup /bin/sh myscript.sh 1>&2 &>/dev/null 1>&2 &>/dev/null& * Get the size of all the directories in current directory (Sorted >> sudo du -ks $(ls -d */) | sort -nr | cut -f2 | xargs -d '\n' du -sh 2> /dev/null * Convert filenames from ISO-8859-1 to UTF-8 >> convmv -r -f ISO-8859-1 -t UTF-8 --notest * * grep certain file with the extension '.c' or '.h' recursively >> grep -r --include="*.[ch]" pattern . * Get a regular updated list of zombies >> watch "ps auxw | grep [d]efunct" * Remove newlines from output >> grep . filename * Get the size of all the directories in current directory >> du --max-depth=1 * Conficker Detection with NMAP >> nmap -PN -d -p445 --script=smb-check-vulns --script-args=safe=1 IP-RANGES * Get the 10 biggest files/folders for the current direcotry >> du -s * | sort -n | tail * Run a command only when load average is below a certain threshold >> echo "rm -rf /unwanted-but-large/folder" | batch * Reuse all parameter of the previous command line >> !* * Open Finder from the current Terminal location >> open . * Bring the word under the cursor on the :ex line in Vim >> :<C-R><C-W> * Generate a random password 30 characters long >> strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo * escape any command aliases >> \[command] * Job Control >> ^Z $bg $disown * Create a persistent connection to a machine >> ssh -MNf <user>@<host> * Sort the size usage of a directory tree by gigabytes, kilobytes, >> du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e' * check site ssl certificate dates >> echo | openssl s_client -connect www.google.com:443 2>/dev/null |openssl x509 -dates -noout * Binary Clock >> watch -n 1 'echo "obase=2;`date +%s`" | bc' * return external ip >> curl icanhazip.com * Record a screencast and convert it to an mpeg >> ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg * directly ssh to host B that is only accessible through host A >> ssh -t hostA ssh hostB * Show a 4-way scrollable process tree with full details. >> ps awwfux | less -S * which program is this port belongs to ? >> lsof -i tcp:80 * quickly rename a file >> mv filename.{old,new} * Download all images from a site >> wget -r -l1 --no-parent -nH -nd -P/tmp -A".gif,.jpg" http://example.com/images * Pipe stdout and stderr, etc., to separate commands >> some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr) * Easy and fast access to often executed commands that are very >> some_very_long_and_complex_command # label * Remove all files previously extracted from a tar(.gz) file. >> tar -tf <file.tar.gz> | xargs rm -r * Add Password Protection to a file your editing in vim. >> vim -x <FILENAME> * Send pop-up notifications on Gnome >> notify-send ["<title>"] "<body>" * create an incremental backup of a directory using hard links >> rsync -a --delete --link-dest=../lastbackup $folder $dname/ * How many files in the current directory ? >> find . -maxdepth 1 -type f | wc -l * how many packages installed on your archlinux? >> pacman -Q|wc -l * Get Futurama quotations from slashdot.org servers >> echo -e "HEAD / HTTP/1.1\nHost: slashdot.org\n\n" | nc slashdot.org 80 | egrep "Bender|Fry" | sed "s/X-//" * Change the case of a single word in vim >> g~w * Find the dates your debian/ubuntu packages were installed. >> ls /var/lib/dpkg/info/*.list -lht |less * Follow the most recently updated log files >> ls -drt /var/log/* | tail -n5 | xargs sudo tail -n0 -f * vmstat/iostat with timestamp >> vmstat 1 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}' * Search Google from the command line >> curl -A Mozilla http://www.google.com/search?q=test |html2text -width 80 * Format ps command output >> ps ax -o "%p %U %u %x %c %n" * Matrix Style >> LC_ALL=C tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]" * stop windows update >> runas /user:administrator net stop wuauserv * Get the canonical, absolute path given a relative and/or >> readlink -f ../super/symlink_bon/ahoy * Migrate existing Ext3 filesystems to Ext4 >> tune2fs -O extents,uninit_bg,dir_index /dev/yourpartition * Twit Amarok "now playing" song >> curl -u <user>:<password> -d status="Amarok, now playing: $(dcop amarok default nowPlaying)" http://twitter.com/statuses/update.json * Apply substitution only on the line following a marker >> sed '/MARKER/{N;s/THIS/THAT/}' * LDAP search to query an ActiveDirectory server >> ldapsearch -LLL -H ldap://activedirectory.example.com:389 -b 'dc=example,dc=com' -D 'DOMAIN\Joe.Bloggs' -w 'p@ssw0rd' '(sAMAccountName=joe.bloggs)' * Read a keypress without echoing it >> stty cbreak -echo; KEY=$(dd bs=1 count=1 2>/dev/null); stty -cbreak echo * change exif data in all jpeg's >> for f in *.jpg; do exif --ifd=0 --tag=0x0110 --set-value="LOMO LC-A" --output=$f $f; exif --ifd=0 --tag=0x010f --set-value="LOMO" --output=$f $f; done } * Setup an ssh tunnel >> ssf -f -N -L 4321:home.network.com:25 user@home.network.com * remote diff with side-by-side ordering. >> ssh $HOST -l$USER cat /REMOTE/FILE | sdiff /LOCAL/FILE - * combine `mkdir foo && cd foo` into a single function `mcd foo` >> function mcd() { [ -n "$1" ] && mkdir -p "$@" && cd "$1"; } * Get video information with ffmpeg >> ffmpeg -i filename.flv * Follow the flow of a log file >> tailf file.log * Print IP of any interface. Useful for scripts. >> ip route show dev ppp0 | awk '{ print $7 }' * Launch a VirtualBox virtual machine >> VBoxManage startvm "name" * Date shows dates at other times/dates >> date -d '2 weeks ago' * Twitpic upload and Tweet >> curl --form username=from_twitter --form password=from_twitter --form media=@/path/to/image --form-string "message=tweet" http://twitpic.com/api/uploadAndPost * eth-tool summary of eth# devices >> for M in 0 1 2 3 ; do echo eth$M ;/sbin/ethtool eth$M | grep -E "Link|Speed" ; done * Record output of any command using 'tee' at backend; mainly can be >> ssh user@server | tee logfilename * Get the IP address of a machine. Just the IP, no junk. >> /sbin/ifconfig -a | awk '/(cast)/ { print $2 }' | cut -d':' -f2 | head -1 * Convert images (jpg, png, ...) into a PDF >> convert images*.* <my_pdf>.pdf * backup a directory in a timestamped tar.gz >> tar -czvvf backup$(date "+%Y%m%d_%H%M%S").tar.gz /path/to/dir * Execute a command on logout >> trap cmd 0 * Show a Command's Short Description >> whatis [command-name] * Hiding password while reading it from keyboard >> save_state=$(stty -g);echo -n "Password: ";stty -echo;read password;stty "$save_state";echo "";echo "You inserted $password as password" * List files above a given threshold >> find . -type f -size +25000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }' * rapidshare download script in 200 characters >> u=`curl -d 'dl.start=Free' $(curl $1|perl -wpi -e 's/^.*"(http:\/\/rs.*)" method.*$/$1/'|egrep '^http'|head -n1)|grep "Level(3) \#2"|perl -wpi -e 's/^.*(http:\/\/rs[^\\\\]*).*$/$1/'`;sleep 60;wget $u * Find the 20 biggest directories on the current filesystem >> du -xk | sort -n | tail -20 * Use a Gmail virtual disk (GmailFS) on Ubuntu >> mount.gmailfs none /mount/path/ [-o username=USERNAME[,password=PASSWORD][,fsname=VOLUME]] [-p] * Find all directories on filesystem containing more than 99MB >> du -hS / | perl -ne '(m/\d{3,}M\s+\S/ || m/G\s+\S/) && print' * Pack up some files into a tarball on a remote server without >> tar -czf - * | ssh example.com "cat > files.tar.gz" * Kill all processes beloging to a single user. >> kill -9 `ps -u <username> -o "pid="` * Add a function you've defined to .bashrc >> addfunction () { declare -f $1 >> ~/.bashrc ; } * Transfer large files/directories with no overhead over the >> ssh user@host "cd targetdir; tar cfp - *" | dd of=file.tar * Quickly generate an MD5 hash for a text string using OpenSSL >> echo -n 'text to be encrypted' | openssl md5 * Enable automatic typo correction for directory names >> shopt -s cdspell * Create a backup of file being edited while using vi >> :!cp % %- * Display calendar with specific national holidays and week numbers >> gcal -K -q GB_EN 2009 # display holidays in UK/England for 2009 (with week numbers) * Edit the Last Changed File >> vim $( ls -t | head -n1 ) * Fast command-line directory browsing >> function cdls { cd $1; ls; } * Create a bunch of dummy files for testing >> touch {1..10}.txt * Add a Clock to Your CLI >> export PS1="${PS1%\\\$*}"' \t \$ ' * Converts a single FLAC file with associated cue file into multiple >> cuebreakpoints "$2" | shnsplit -o flac "$1" * Mount a partition from within a complete disk dump >> INFILE=/path/to/your/backup.img; MOUNTPT=/mnt/foo; PARTITION=1; mount "$INFILE" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "$INFILE" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ] * Installing True-Type fonts >> ttmkfdir mkfontdir fc-cache /usr/share/fonts/miscttf * See how many % of your memory firefox is using >> ps -o %mem= -C firefox-bin | sed -s 's/\..*/%/' * Replicate a directory structure dropping the files >> for x in `find /path/ -type d | cut -b bytesoffoldername-`; do mkdir -p newpath/$x; done * useful tail on /var/log to avoid old logs or/and gzipped files >> tail -f *[!.1][!.gz] * Trojan inverse shell >> nc -l -p 2000 -e /bin/bash * Add forgotten changes to the last git commit >> git commit --amend * Check the status of a network interface >> mii-tool [if] * New command with the last argument of the previous command. >> command !$ * Convert a bunch of HTML files from ISO-8859-1 to UTF-8 file >> for x in `find . -name '*.html'` ; do iconv -f ISO-8859-1 -t UTF-8 $x > "$x.utf8"; rm $x; mv "$x.utf8" $x; done * Find out current working directory of a process >> echo COMMAND | xargs -ixxx ps -C xxx -o pid= | xargs -ixxx ls -l /proc/xxx/cwd * Mount and umount iso files >> function miso () { mkdir ~/ISO_CD && sudo mount -o loop "$@" ~/ISO_CD && cd ~/ISO_CD && ls; } function uiso () { cd ~ && sudo umount ~/ISO_CD && rm -r ~/ISO_CD; } * find .txt files inside a directory and replace every occurrance >> find . -name '*.txt' -exec sed -ir 's/this/that/g' {} \; * for too many arguments by * >> echo *.log | xargs <command> * Find files that are older than x days >> find . -type f -mtime +7 -exec ls -l {} \; * show lines that appear in both file1 and file2 >> comm -1 -2 <(sort file1) <(sort file2) * connect to X login screen via vnc >> x11vnc -display :0 -auth $(ps -ef|awk '/xauth/ {print $15}'|head -1) -forever -bg & * use vi key bindings at the command line >> set -o vi * ionice limits process I/O, to keep it from swamping the system >> ionice -c3 find / * convert filenames in current directory to lowercase >> for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done * Change the window title of your xterm >> echo "^[]0;My_Title_Goes _Here^G" * recursively change file name from uppercase to lowercase (or >> find . -type f|while read f; do mv $f `echo $f |tr '[:upper:]' '[ :lower:]'`; done * Always tail/edit/grep the latest file in a directory of >> tail -f /path/to/timestamped/files/file-*(om[1]) * Show all programs on UDP and TCP ports with timer information >> netstat -putona * Get contents from hosts, passwd, groups even if they're in >> getent [group|hosts|networks|passwd|protocols|services] [keyword] * Show a passive popup in KDE >> kdialog --passivepopup <text> <timeout> * Octal ls >> ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)pri ntf("%0o ",k);print}' * Unix time to local time >> date -R -d @1234567890 * Create a mirror of a local folder, on a remote server >> rsync -e "/usr/bin/ssh -p22" -a --progress --stats --delete -l -z -v -r -p /root/files/ user@remote_server:/root/files/ * a find and replace within text-based files, to locate and rewrite >> find . -name "*.txt" | xargs perl -pi -e 's/old/new/g' * do a full file listing of every file found with locate >> locate searchstring | xargs ls -l * Reset terminal that has been buggered by binary input or similar >> stty sane * list processes with established tcp connections (without netstat) >> lsof -i -n | grep ESTABLISHED * Change default shell for all users [FreeBSD] >> cd /usr/home && for i in *;do chsh -s bash $i;done * scan folder to check syntax error in php files >> find . -name "*.php" -exec php -l {} \; * count and number lines of output, useful for counting number of >> ps aux | grep [a]pache2 | nl * List all TCP opened ports on localhost in LISTEN mode >> netstat -nptl * list all opened ports on host >> sudo lsof -P -i -n -sTCP:LISTEN * Determining the excat memory usages by certain PID >> pmap -d <<pid>> * Output Detailed Process Tree for any User >> psu(){ command ps -Hcl -F S f -u ${1:-$USER}; } * Create subdirectory and move files into it >> (ls; mkdir subdir; echo subdir) | xargs mv * Use the arguments used in the last command >> mkdir !* * Display GCC Predefined Macros >> gcc -dM -E - <<<'' * Enable cd by variable names >> shopt -s cdable_vars * validate the syntax of a perl-compatible regular expression >> perl -we 'my $regex = eval {qr/.*/}; die "$@" if $@;' * Perform sed substitution on all but the last line of input >> sed -e "$ ! s/$/,/" * Count the total number of files in each immediate subdirectory >> find . -type f -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn * Comment out a line in a file >> sed -i '19375 s/^/#/' file * Insert a comment on command line for reminder >> ls -alh #mycomment * List dot-files and dirs, but not . or .. >> ls -A * batch edit >> find . -name "*.txt" -exec sed -i "s/old/new/" {} \; * Quick command line math >> expr 512 \* 7 * Show apps that use internet connection at the moment. >> netstat -lantp | grep -i establ | awk -F/ '{print $2}' | sort | uniq * no more line wrapping in your terminal >> function nowrap { export COLS=`tput cols` ; cut -c-$COLS ; unset COLS ; } * Edit your command in vim ex mode by <ctrl-f> >> <ctrl-f> in ex mode in vim * Create a large test file (taking no space). >> dd bs=1 seek=2TB if=/dev/null of=ext3.test * Parallel file downloading with wget >> wget -nv http://en.wikipedia.org/wiki/Linux -O- | egrep -o "http://[^[:space:]]*.jpg" | xargs -P 10 -r -n 1 wget -nv * How to run a command on a list of remote servers read from a file >> dsh -M -c -f servers -- "command HERE" * Unlock your KDE4.3 session remotely >> qdbus org.kde.screenlocker /MainApplication quit * get the latest version >> mirror=ftp://somemirror.com/with/alot/versions/but/no/latest/link; latest=$(curl -l $mirror/ 2>/dev/null | grep util | tail -1); wget $mirror/$latest * Remotely sniff traffic and pass to snort >> ssh root@pyramid \ "tcpdump -nn -i eth1 -w -" | snort -c /etc/snort/snort.conf -r - * Copy structure >> structcp(){ ( mkdir -pv $2;f="$(realpath "$1")";t="$(realpath "$2")";cd "$f";find * -type d -exec mkdir -pv $t/{} \;);} * for all who don't have the watch command >> watch() { while test :; do clear; date=$(date); echo -e "Every "$1"s: $2 \t\t\t\t $date"; $2; sleep $1; done } * Terminal redirection >> script -f /dev/pts/3 * Get the 10 biggest files/folders for the current direcotry >> du -sk * |sort -rn |head * Copy all documents PDF in disk for your home directory >> find / -name "*.pdf" -exec cp -t ~/Documents/PDF {} + * grep certain file types recursively >> find . -name "*.[ch]" | xargs grep "TODO" * On Mac OS X, runs System Profiler Report and e-mails it to >> system_profiler | mail -s "$HOSTNAME System Profiler Report" user@domain.com * Get a regular updated list of zombies >> watch "ps auxw | grep 'defunct' | grep -v 'grep' | grep -v 'watch'" * Define an alias with a correct completion >> old='apt-get'; new="su-${old}"; command="sudo ${old}"; alias "${new}=${command}"; $( complete | sed -n "s/${old}$/${new}/p" ); alias ${new}; complete -p ${new} * Go to parent directory of filename edited in last command >> cd `dirname $_` * find and delete empty directories recursively >> find . -depth -type d -empty -exec rmdir -v {} + * Who invoked me? / Get parent command >> ps -o comm= -p $(ps -o ppid= -p $$) * Sort IPV4 ip addresses >> sort -t. -k1,1n -k2,2n -k3,3n -k4,4n * Save man pages to pdf >> man -t man | ps2pdf - > man.pdf * zsh only: access a file when you don't know the path, if it is in >> file =top * Using the urxvt terminal daemon >> urxvtd -q -o -f * Search through files, ignoring .svn >> find . -not \( -name .svn -prune \) -type f -print0 | xargs --null grep <searchTerm> * quickly backup or copy a file with bash >> cp -bfS.bak filename filename * show installed but unused linux headers, image, or modules >> dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' * detach remote console for long running operations >> dtach -c /tmp/wires-mc mc * Paste the contents of OS X clipboard into a new text file >> pbpaste > newfile.txt * Count to 65535 in binary (for no apparent reason) >> a=`printf "%*s" 16`;b=${a//?/{0..1\}}; echo `eval "echo $b"` * Huh? Where did all my precious space go ? >> ls -la | sort -k 5bn * Monitor logs in Linux using Tail >> find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f * Zip a directory on Mac OS X and ignore .DS_Store (metadata) >> zip -vr example.zip example/ -x "*.DS_Store" * Filter IPs out of files >> egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' file.txt * display typedefs, structs, unions and functions provided by a library >> cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less * Skip over .svn directories when using the "find" command. >> find . -not \( -name .svn -prune \) * Simplification of "sed 'your sed stuff here' file > file2 && mv >> sed -i 'your sed stuff here' file * Check if a process is running >> kill -0 [pid] * Go to the next sibling directory in alphabetical order >> for d in `find .. -mindepth 1 -maxdepth 1 -type d | sort`; do if [[ `basename $d` > `basename $PWD` ]]; then cd $d; break; fi; done