#:1#
# commandlinefu.com by David Winterbottom
#:2#
# commandlinefu.com by David Winterbottom
#:3#
# commandlinefu.com by David Winterbottom
# Randomize lines (opposite of | sort)
perl -wl -e '@f=<>; for $i (0 .. $#f) { $r=int rand ($i+1); @f[$i, $r]=@f[$r,$i]
if ($i!=$r); } chomp @f; print join $/, @f;' try.txt
# Randomize lines (opposite of | sort)
random -f
# Randomize lines (opposite of | sort)
cat ~/SortedFile.txt | perl -wnl -e '@f=<>; END{ foreach $i (reverse 0 .. $#f) {
$r=int rand ($i+1); @f[$i, $r]=@f[$r,$i] unless ($i==$r); } chomp @f; foreach
$line (@f){ print $line; }}'
# Output files without comments or empty lines
function catv { egrep -v "^$|^#" ${*} ; }
# Replace all tabs with spaces in an application
grep -PL "\t" -r . | grep -v ".svn" | xargs sed -i 's/\t/ /g'
# wrap long lines of a text
fold -s -w 90 file.txt
# Display a File with Line Number
nl filename | more
# Load another file in vim
:split
# Pipe STDOUT to vim
tail -1000 /some/file | vim -
# Add a line to a file using sudo
echo "foo bar" | sudo tee -a /path/to/some/file
# Output files without comments or empty lines
grep -v "^\($\|#\)"
# See which files differ in a diff
diff dir1 dir2 | diffstat
# Delete line number 10 from file
sed -i '10d'
# Efficiently print a line deep in a huge log file
sed '1000000!d;q' < massive-log-file.log
#:4#
# commandlinefu.com by David Winterbottom
# Sort all running processes by their memory & CPU usage
ps aux --sort=%mem,%cpu
# View Processeses like a fu, fu
pstree -p
# View Processeses like a fu, fu
command ps -Hacl -F S -A f
# Will email user@example.com when all Rsync processes have finished.
$(while [ ! -z "$(pgrep rsync)" ]; do echo; done; echo "rsync done" | mailx user
@example.com) > /dev/null &
# Check processes runed not by you
ps aux | grep -v `whoami`
# Manually Pause/Unpause Firefox Process with POSIX-Signals
killall -STOP -m firefox
# View process statistics in realtime
top
# Find out current working directory of a process
echo COMMAND | xargs -ixxx ps -C xxx -o pid= | xargs -ixxx ls -l /proc/xxx/cwd
# Click on a GUI window and show its process ID and command used to run the proc
ess
xprop | awk '/PID/ {print $3}' | xargs ps h -o pid,cmd
#:5#
# commandlinefu.com by David Winterbottom
# Simple read and write test with Iozone
iozone -s 2g -r 64 -i 0 -i 1 -t 1
# locate a filename, make sure it exists and display it with full details
locate -e somefile | xargs ls -l
# currently mounted filesystems in nice layout
column -t /proc/mounts
# Which files/dirs waste my disk space
du -aB1m|awk '$1 >= 100'
# Check if filesystem hangs
ls /mnt/badfs &
# Migrate existing Ext3 filesystems to Ext4
tune2fs -O extents,uninit_bg,dir_index /dev/yourpartition
# 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; s
udo swapon /swapfile
# List files recursively sorted by modified time
find /home/fizz -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
# automount samba shares as devices in /mnt/
sudo vi /etc/fstab; Go//smb-share/gino /mnt/place smbfs defaults,username=gino,p
assword=pass 0 0:wq; mount //smb-share/gino
# Find all directories on filesystem containing more than 99MB
du -hS / | perl -ne '(m/\d{3,}M\s+\S/ || m/G\s+\S/) && print'
# currently mounted filesystems in nice layout
mount | column -t
# Move a file up a directory.
mv file_name.extension ..
#:6#
# commandlinefu.com by David Winterbottom
# Simple XML tag extract with sed
sed -n 's/.*\([^<]*\)<\/foo>.*/\1/p'
# Working random fact generator
lynx -dump randomfunfacts.com | grep -A 3 U | sed 1D
# Alias to edit and source your .bashrc file
alias vb='vim ~/.bashrc; source ~/.bashrc'
#:7#
# commandlinefu.com by David Winterbottom
# Write and run a quick C program
cat | gcc -x c -o a.out - && ./a.out && rm a.out
# List symbols from a dynamic library (.so file)
nm --dynamic
# display typedefs, structs, unions and functions provided by a header file
cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less
#:8#
# commandlinefu.com by David Winterbottom
# List symbols from a dynamic library (.so file)
nm --dynamic
#:9#
# commandlinefu.com by David Winterbottom
#:10#
# commandlinefu.com by David Winterbottom
# Easily decode unix-time (funtion)
utime(){ perl -e "print localtime($1).\"\n\"";}
# convert unixtime to human-readable
perl -e 'print scalar(gmtime(1234567890)), "\n"'
# convert unixtime to human-readable
echo "0t${currentEpoch}=Y" | /usr/bin/adb
# 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'; dat
e -d '16 hour'
# decoding Active Directory date format
ldapsearch -v -H ldap:// -x -D cn=,cn=,dc=,dc
= -w -b ou=,dc=,dc= -s sub sAMAccountNam
e=* '*' | perl -pne 's/(\d{11})\d{7}/"DATE-AD(".scalar(localtime($1-11644473600)
).")"/e'
# print date 24 hours ago
date --date=yesterday
#:11#
# commandlinefu.com by David Winterbottom
# Show Network IP and Subnet
ipcalc $(ifconfig eth0 | grep "inet addr:" | cut -d':' -f2,4 | sed 's/.+Bcast:/\
//g') | awk '/Network/ { print $2 } '
# Show Network IP and Subnet
IP=`ifconfig eth0 | grep "inet addr:" | ips |cut -d ":" -f 2 | cut -d " " -f 1`;
SUBNET=`ifconfig eth0 | grep "inet addr:" | ips |cut -d ":" -f 3 | cut -d " " -f
1`;RANGE=`ipcalc $IP/$SUBNET | grep "Network:" | cut -d ' ' -f 4`;echo $RANGE
# Get your external IP address
wget -qO - http://www.sputnick-area.net/ip;echo
# Get your external IP address
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//
'
# Get your external IP address
lynx --dump http://ip.boa.nu|sed -e 's/^[[:space:]]*//' -e 's/*[[:space:]]$//'|g
rep -v ^$
# Get your external IP address
wget -O - -q ip.boa.nu
# Get your external IP address
curl whatismyip.org
# Get your external IP address with the best commandlinefu.com command
eval $(curl -s http://www.commandlinefu.com/commands/matching/external/ZXh0ZXJuY
Ww=/sort-by-votes/plaintext|sed -n '/^# Get your external IP address$/{n;p;q}')
# Get your external IP address with a random commandlinefu.com command
IFS=$'\n';cl=($(curl -s http://www.commandlinefu.com/commands/matching/external/
ZXh0ZXJuYWw=/sort-by-votes/plaintext|sed -n '/^# Get your external IP address$/{
n;p}'));c=${cl[$(( $RANDOM % ${#cl[@]} ))]};eval $c;echo "Command used: $c"
# Get your external IP address
exec 3<>/dev/tcp/whatismyip.com/80; echo -e "GET /automation/n09230945.asp HTTP/
1.0\r\nHost: whatismyip.com\r\n" >&3; a=( $(cat <&3) ); echo ${a[${#a[*]}-1]};
# Get your external IP address
echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" | n
c whatismyip.com 80 | tail -n1
# Get your external IP address
curl ip.appspot.com
# List Network Tools in Linux
apropos network |more
# send echo to socket network
echo foo | netcat 192.168.1.2 25
# send echo to socket network
echo "foo" > /dev/tcp/192.168.1.2/25
# Another way to see the network interfaces
ip addr show
# Echo the local IP addresses of the machines on your local network
for i in 192.168.1.{61..71};do ping -c 1 $i &> /dev/null && echo $i;fi;done
# Resolve the "all display buffers are busy, please try later" error on a Foundr
y
dm display-buffer reset
# Get your external IP address
fetch -q -o - http://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]
]{1,3}'
# Get your external IP address
curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).
*/\1/g'
# Delete all aliases for a network interface on a (Free)BSD system
ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 dele
te
# Get all IPs via ifconfig
ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'
# What is My WAN IP?
curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
# Show established network connections
lsof -i | grep -i estab
# One-Liner to Display IP Addresses
python -c "import socket; print '\n'.join(socket.gethostbyname_ex(socket.gethost
name())[2])"
#:12#
# commandlinefu.com by David Winterbottom
# Manage "legacy" service run control links
sudo find /etc/rc{1..5}.d -name S99myservice -type l -exec sh -c 'NEWFN=`echo {}
| sed 's/S99/K99/'` ; mv -v {} $NEWFN' \;
# Run a file system check on your next boot.
sudo touch /forcefsck
# List all files opened by a particular command
lsof -c dhcpd
# List files opened by a PID
lsof -p 15857
#:13#
# commandlinefu.com by David Winterbottom
# backup local MySQL database into a folder and removes older then 5 days backup
s
mysqldump -uUSERNAME -pPASSWORD database | gzip > /path/to/db/files/db-backup-`d
ate +%Y-%m-%d`.sql.gz ;find /path/to/db/files/* -mtime +5 -exec rm {} \;
# Get a MySQL DB dump from a remote machine
ssh user@host "mysqldump -h localhost -u mysqluser -pP@$$W3rD databasename | gzi
p -cf" | gunzip -c > database.sql
# Transfer sqlite3 data to mysql
sqlite3 mydb.sqlite3 '.dump' | grep -vE '^(BEGIN|COMMIT|CREATE|DELETE)|"sqlite_s
equence"' | sed -r 's/"([^"]+)"/`\1`/' | tee mydb.sql | mysql -p mydb
# Determine configure options used for MySQL binary builds
grep CONFIG $(which mysqlbug)
# Determine configure options used for MySQL binary builds
cat `whereis mysqlbug | awk '{print $2}'` | grep 'CONFIGURE_LINE='
# Explanation of system and MySQL error codes
perror NUMBER
# positions the mysql slave at a specific master position
slave start; SELECT MASTER_POS_WAIT('master.000088','8145654'); slave stop;
# raw MySQL output to use in pipes
mysql DATABASE -N -s -r -e 'SQL COMMAND'
# Passwordless mysql{,dump,admin} via my.cnf file
echo -e "[client]\nuser = YOURUSERNAME\npassword = YOURPASSWORD" > ~/.my.cnf
# Load multiple sql script in mysql
cat schema.sql data.sql test_data.sql | mysql -u user --password=pass dbname
# 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=d
bname &
# Monitor server load as well as running MySQL processes
watch -n 1 uptime\;myqladmin --user= --password= --verbose proce
sslist
# 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
# Monitor the queries being run by MySQL
watch -n 1 mysqladmin --user= --password= processlist
#:14#
# commandlinefu.com by David Winterbottom
# Batch image resize
for a in `ls`; do echo $a && convert $a -resize x $a; done
# Find corrupted jpeg image files
find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"
# sync a directory of corrupted jpeg with a source directory
for i in *jpg; do jpeginfo -c $i | grep -E "WARNING|ERROR" | cut -d " " -f 1 | x
args -I '{}' find /mnt/sourcerep -name {} -type f -print0 | xargs -0 -I '{}' cp
-f {} ./ ; done
# Add a shadow to picture
convert {$file_in} \( +clone -background black -shadow 60x5+10+10 \) +swap -back
ground none -layers merge +repage {$file_out}
# Scale,Rotate, brightness, contrast,...with Image Magick
convert -rotate $rotate -scale $Widthx$Height -modulate $brightness -contrast $c
ontrast -colorize $red%,$green%,$blue% $filter file_in.png file_out.png
# Use ImageMagick to get an image's properties
identify -ping imageName.png
# Determine an image's dimensions
identify -format "%wx%h" /path/to/image.jpg
#:15#
# commandlinefu.com by David Winterbottom
# Display summary of git commit ids and messages for a given branch
git log --pretty='format:%Cgreen%H %Cred%ai %Creset- %s'
# Display summary of git commit ids and messages for a given branch
git log master | awk '/commit/ {id=$2} /\s+\w+/ {print id, $0}'
#:16#
# commandlinefu.com by David Winterbottom
# Display all readline binding that use CTRL
bind -p | grep -F "\C"
#:17#
# commandlinefu.com by David Winterbottom
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 2)
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac copy -ovc l
avc -lavcopts vcodec=mpeg4 -vf scale=320:-2,expand=:240:::1 -ffourcc xvid -o out
put.avi dvd.avi
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 1)
mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -o dvd.
avi dvd://0
# Convert a MOV captured from a digital camera to a smaller AVI
ffmpeg -i input.mov -b 4096k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi
# Rip DVD to YouTube ready MPEG-4 AVI file using mencoder
mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourc
c xvid -vf scale=320:-2,expand=:240:::1 -o output.avi dvd://0
# Get the total length of all video / audio in the current dir (and below) in H:
m:s
find -type f -name "*.avi" -print0 | xargs -0 mplayer -vo dummy -ao dummy -iden
tify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02
d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
# Use heading subtitle file as watermark using mencoder
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -la
meopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1
-o output.avi input.flv
# View webcam output using GStreamer pipeline
gst-launch-0.10 autovideosrc ! video/x-raw-yuv,framerate=\(fraction\)30/1,width=
640,height=480 ! ffmpegcolorspace ! autovideosink
# Record audio and video from webcam using mencoder
mencoder tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0:fps=30:ou
tfmt=yuy2:forceaudio:alsa:adevice=hw.2,0 -ovc lavc -lavcopts vcodec=mpeg4:vbitra
te=1800 -ffourcc xvid -oac mp3lame -lameopts cbr=128 -o output.avi
# View webcam output using mplayer
mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:out
fmt=yuy2
# Record audio and video from webcam using ffmpeg
ffmpeg -f alsa -r 16000 -i hw:2,0 -f video4linux2 -s 800x600 -i /dev/video0 -r 3
0 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi
# Extract audio track from a video file using mencoder
mencoder -of rawaudio -ovc copy -oac mp3lame -o output.mp3 input.avi
# Substitute audio track of video file using mencoder
mencoder -ovc copy -audiofile input.mp3 -oac copy input.avi -o output.avi
# Remove sound from video file using mencoder
mencoder -ovc copy -nosound input.avi -o output.avi
# FLV to AVI with subtitles and forcing audio sync using mencoder
mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=12
8 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv
# Convert a VMWare screencast into a flv file
mencoder -of avi -ovc lavc movie.avi -o movie2.avi; ffmpeg -i movie2.avi -r 12
-b 100 movie.flv
# Record a webcam output into a video file.
ffmpeg -an -f video4linux -s 320x240 -b 800k -r 15 -i /dev/v4l/video0 -vcodec mp
eg4 myvideo.avi
# Encode a file to MPEG4 format
mencoder video.avi lavc -lavcopts vcodec=mpeg4:vbitrate=800 newvideo.avi
# Record camera's output to a avi file
mencoder -tv device=/dev/video1 tv:// -ovc copy -o video.avi
# Record a screencast and convert it to an mpeg
ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg
# extracting audio and video from a movie
ffmpeg -i source_movie.flv -vcodec mpeg2video target_video.m2v -acodec copy targ
et_audio.mp3
# removing syncronization problems between audio and video
ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_vide
o.flv
# Create a video that is supported by youtube
ffmpeg -i mymovie.mpg -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vco
dec flv mytarget.flv
# Copy the sound content of a video to an mp3 file
ffmpeg -i source.flv -vn acodec copy destination.mp3
# Find your graphics chipset
lspci |grep VGA
# play high-res video files on a slow processor
mplayer -framedrop -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all
#:18#
# commandlinefu.com by David Winterbottom
#:19#
# commandlinefu.com by David Winterbottom
# Update Ping.fm status
curl -d api_key="$api_key" -d user_app_key="$user_app_key -d body="$body" -d pos
t_method="default" http://api.ping.fm/v1/user.post
# Watching Command
watch 'cat /proc/loadavg'
#:20#
# commandlinefu.com by David Winterbottom
#:21#
# commandlinefu.com by David Winterbottom
# FAST and NICE Search and Replace for Strings in Files
nice -n19 sh -c 'S=askapache && R=htaccess; find . -type f|xargs -P5 -iFF grep -
l -m1 "$S" FF|xargs -P5 -iFF sed -i -e s%${S}%${R}% FF'
#:22#
# commandlinefu.com by David Winterbottom
# Prints per-line contribution per author for a GIT repository
git ls-files | while read i; do git blame $i | sed -e 's/^[^(]*(//' -e 's/^\([^[
:digit:]]*\)[[:space:]]\+[[:digit:]].*/\1/'; done | sort | uniq -ic | sort -nr
# Prints per-line contribution per author for a GIT repository
git ls-files | xargs -n1 -d'\n' -i git-blame {} | perl -n -e '/\s\((.*?)\s[0-9]{
4}/ && print "$1\n"' | sort -f | uniq -c -w3 | sort -r
# Awk: Perform a rolling average on a column of data
awk 'BEGIN{size=5} {mod=NR%size; if(NR<=size){count++}else{sum-=array[mod]};sum+
=$1;array[mod]=$1;print sum/count}' file.dat
# dstat - a mix of vmstat, iostat, netstat, ps, sar...
dstat -ta
#:23#
# commandlinefu.com by David Winterbottom
#:24#
# commandlinefu.com by David Winterbottom
#:25#
# commandlinefu.com by David Winterbottom
#:26#
# commandlinefu.com by David Winterbottom
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 1)
mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -o dvd.
avi dvd://0
# 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
# Get the total length of all video / audio in the current dir (and below) in H:
m:s
find -type f -name "*.avi" -print0 | xargs -0 mplayer -vo dummy -ao dummy -iden
tify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02
d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
# Record MP3 audio via ALSA using ffmpeg
ffmpeg -f alsa -ac 2 -i hw:1,0 -acodec libmp3lame -ab 96k output.mp3
# Record audio and video from webcam using ffmpeg
ffmpeg -f alsa -r 16000 -i hw:2,0 -f video4linux2 -s 800x600 -i /dev/video0 -r 3
0 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi
# Extract audio from Mythtv recording to Rockbox iPod using ffmpeg
ffmpeg -ss 0:58:15 -i DavidLettermanBlackCrowes.mpg -acodec copy DavidLettermanB
lackCrowes.ac3
# extracting audio and video from a movie
ffmpeg -i source_movie.flv -vcodec mpeg2video target_video.m2v -acodec copy targ
et_audio.mp3
# removing syncronization problems between audio and video
ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_vide
o.flv
# Create a video that is supported by youtube
ffmpeg -i mymovie.mpg -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vco
dec flv mytarget.flv
# Copy the sound content of a video to an mp3 file
ffmpeg -i source.flv -vn acodec copy destination.mp3
# create an mp3 with variable bitrate
lame -h -V 6 track9.wav track9.mp3
# Extract track 9 from a CD
mplayer -fs cdda://9 -ao pcm:file=track9.wav
# 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
# covert m4a audio files to wav
find . -name '*.m4a' | xargs -I audiofile mplayer -ao pcm "audiofile" -ao pcm:fi
le="audiofile.wav"
# Split lossless audio (ape, flac, wav, wv) by cue file
cuebreakpoints | shnsplit -o
"|grep
-oE "
"|sed -e 's/<\/p>/\n/g' -e 's/
//g' -e
's/
//g'|perl -ne 'use HTML::Entities;print decode_entities($_),"
\n"'|head -1
#:457#
# commandlinefu.com by David Winterbottom
# Random line from bash.org (funny IRC quotes)
curl -s http://bash.org/?random1|grep -oE "
.*
.*"|grep
-oE "
"|sed -e 's/<\/p>/\n/g' -e 's/
//g' -e
's/
//g'|perl -ne 'use HTML::Entities;print decode_entities($_),"
\n"'|head -1
#:458#
# commandlinefu.com by David Winterbottom
# Random line from bash.org (funny IRC quotes)
curl -s http://bash.org/?random1|grep -oE "
.*
.*"|grep
-oE "
"|sed -e 's/<\/p>/\n/g' -e 's/
//g' -e
's/
//g'|perl -ne 'use HTML::Entities;print decode_entities($_),"
\n"'|head -1
#:459#
# commandlinefu.com by David Winterbottom
# Convert decimal numbers to binary
function decToBin { echo "ibase=10; obase=2; $1" | bc; }
# no more line wrapping in your terminal
function nowrap { export COLS=`tput cols` ; cut -c-$COLS ; unset COLS ; }
# search for a file in PATH
function sepath { echo $PATH |tr ":" "\n" |sort -u |while read L ; do cd "$L" 2>
/dev/null && find . \( ! -name . -prune \) \( -type f -o -type l \) 2>/dev/null
|sed "s@^\./@@" |egrep -i "${*}" |sed "s@^@$L/@" ; done ; }
# bash/ksh function: given a file, cd to the directory it lives
function fcd () { [ -f $1 ] && { cd $(dirname $1); } || { cd $1 ; } pwd }
# Create a list of binary numbers
echo {0..1}{0..1}{0..1}{0..1}
# Expand shell variables in sed scripts
expanded_script=$(eval "echo \"$(cat ${sed_script_file})\"") && sed -e "${expand
ed_script}" your_input_file
#:460#
# commandlinefu.com by David Winterbottom
# Safely store your gpg key passphrase.
pwsafe -qa "gpg keys"."$(finger `whoami` | grep Name | awk '{ print $4" "$5 }')"
#:461#
# commandlinefu.com by David Winterbottom
# Safely store your gpg key passphrase.
pwsafe -qa "gpg keys"."$(finger `whoami` | grep Name | awk '{ print $4" "$5 }')"
#:462#
# commandlinefu.com by David Winterbottom
# Safely store your gpg key passphrase.
pwsafe -qa "gpg keys"."$(finger `whoami` | grep Name | awk '{ print $4" "$5 }')"
#:463#
# commandlinefu.com by David Winterbottom
# Define an alias with a correct completion
old='apt-get'; new="su-${old}"; command="sudo ${old}"; alias "${new}=${command}"
; $( complete | sed -n "s/${old}$/${new}/p" ); alias ${new}; complete -p ${new}
# Inserts the results of an autocompletion in the command line
ESC *
# Ultra shortcut for ssh root@
alias s='ssh -l root'
#:464#
# commandlinefu.com by David Winterbottom
# locate a filename, make sure it exists and display it with full details
locate -e somefile | xargs ls -l
# Search commandlinefu.com from the command line using the API
cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ |
openssl base64)/plaintext"; }
# Search and replace in multiple files and save them with the same names - quick
ly and effectively!
for files in $(ls -A directory_name); do sed 's/search/replaced/g' $files > $fil
es.new && mv $files.new $files; done;
#:465#
# commandlinefu.com by David Winterbottom
# recursive search and replace old with new string, inside files
$rpl -R oldstring newstring folder
# Open in TextMate Sidebar files (recursively) with names matching REGEX_A and n
ot matching REGEX_B
mate - `find * -type f -regex 'REGEX_A' | grep -v -E 'REGEX_B'`
# Search and replace in multiple files and save them with the same names - quick
ly and effectively!
for files in $(ls -A directory_name); do sed 's/search/replaced/g' $files > $fil
es.new && mv $files.new $files; done;
#:466#
# commandlinefu.com by David Winterbottom
# FAST and NICE Search and Replace for Strings in Files
nice -n19 sh -c 'S=askapache && R=htaccess; find . -type f|xargs -P5 -iFF grep -
l -m1 "$S" FF|xargs -P5 -iFF sed -i -e s%${S}%${R}% FF'
# How to run a command on a list of remote servers read from a file
dsh -M -c -f servers -- "command HERE"
# Search and replace in multiple files and save them with the same names - quick
ly and effectively!
for files in $(ls -A directory_name); do sed 's/search/replaced/g' $files > $fil
es.new && mv $files.new $files; done;
#:467#
# commandlinefu.com by David Winterbottom
# Search and replace in multiple files and save them with the same names - quick
ly and effectively!
for files in $(ls -A directory_name); do sed 's/search/replaced/g' $files > $fil
es.new && mv $files.new $files; done;
#:468#
# commandlinefu.com by David Winterbottom
# Search and replace in multiple files and save them with the same names - quick
ly and effectively!
for files in $(ls -A directory_name); do sed 's/search/replaced/g' $files > $fil
es.new && mv $files.new $files; done;
#:469#
# commandlinefu.com by David Winterbottom
# Get an IP address out of fail2ban jail
iptables -D fail2ban-SSH -s -j DROP
#:470#
# commandlinefu.com by David Winterbottom
# Extract all urls from last firefox sessionstore used in a portable way.
perl -lne 'print for /url":"\K[^"]+/g' $(ls -t ~/.mozilla/firefox/*/sessionstore
.js | sed q)
# Get number of diggs for a news URL
curl -s "http://services.digg.com/stories?link=$NEWSURL&appkey=http://www.whatev
er.com&type=json" | python -m simplejson.tool | grep diggs
# Validate and pretty-print JSON expressions.
echo '{"json":"obj"}' | python -m simplejson.tool
#:471#
# commandlinefu.com by David Winterbottom
# validate the syntax of a perl-compatible regular expression
perl -we 'my $regex = eval {qr/.*/}; die "$@" if $@;'
# Check if variable is a number
if [ "$testnum" -eq "$testnum" 2>/dev/null ]; then echo It is numeric; fi
# quick and easy way of validating a date format of yyyy-mm-dd and returning a b
oolean
echo 2006-10-10 | grep -c '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'
#:472#
# commandlinefu.com by David Winterbottom
# wrap long lines of a text
fold -s -w 90 file.txt
#:473#
# commandlinefu.com by David Winterbottom
# wrap long lines of a text
fold -s -w 90 file.txt
#:474#
# commandlinefu.com by David Winterbottom
# Randomize lines (opposite of | sort)
perl -wl -e '@f=<>; for $i (0 .. $#f) { $r=int rand ($i+1); @f[$i, $r]=@f[$r,$i]
if ($i!=$r); } chomp @f; print join $/, @f;' try.txt
# Randomize lines (opposite of | sort)
random -f
# Randomize lines (opposite of | sort)
cat ~/SortedFile.txt | perl -wnl -e '@f=<>; END{ foreach $i (reverse 0 .. $#f) {
$r=int rand ($i+1); @f[$i, $r]=@f[$r,$i] unless ($i==$r); } chomp @f; foreach
$line (@f){ print $line; }}'
# List all text files (exclude binary files)
find . -type f -exec file {} \; | grep ".*: .* text" | cut -f 1 -d :
# List all text files (exclude binary files)
find . | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;"
# Remove CR from Windows- / DOS-textfiles
dos2unix file.txt
# Remove CR from Windows- / DOS-textfiles
tr -d '\r' < ${input_txt} > ${output_txt}
# write text or append to a file
cat <<.>> somefilename
# wrap long lines of a text
fold -s -w 90 file.txt
#:475#
# commandlinefu.com by David Winterbottom
# wrap long lines of a text
fold -s -w 90 file.txt
#:476#
# commandlinefu.com by David Winterbottom
# IFS - use entire lines in your for cycles
export IFS=$(echo -e "\n")
# wrap long lines of a text
fold -s -w 90 file.txt
#:477#
# commandlinefu.com by David Winterbottom
# Convert a file from ISO-8859-1 (or whatever) to UTF-8 (or whatever)
tcs -f 8859-1 -t utf /some/file
#:478#
# commandlinefu.com by David Winterbottom
# mount an iso
mount -o loop -t iso9660 my.iso /mnt/something
# How to copy CD/DVD into hard disk (.iso)
dd if=/dev/cdrom of=whatever.iso
# Output a SSL certificate start or end date
date --date="$(openssl x509 -in xxxxxx.crt -noout -startdate | cut -d= -f 2)" --
iso-8601
# Convert a file from ISO-8859-1 (or whatever) to UTF-8 (or whatever)
tcs -f 8859-1 -t utf /some/file
# Mount a .iso file in UNIX/Linux
mount /path/to/file.iso /mnt/cdrom -oloop
#:479#
# commandlinefu.com by David Winterbottom
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
# Function that outputs dots every second until command completes
sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; do
ne; }; export -f sleeper
# Put the machine to sleep after the download(wget) is done
while [ -n "`pgrep wget`" ]; do sleep 2 ;done; [ -e "/tmp/nosleep"] || echo mem
>/sys/power/state
# Multiple Timed Execution of subshells sleeping in the background using job con
trol and sleep.
S=$SSH_TTY && (sleep 3 && echo -n 'Peace... '>$S & ) && (sleep 5 && echo -n 'Lov
e... '>$S & ) && (sleep 7 && echo 'and Intergalactic Happiness!'>$S & )
# Mac Sleep Timer
sudo pmset schedule sleep "08/31/2009 00:00:00"
#:480#
# commandlinefu.com by David Winterbottom
# Mac Sleep Timer
sudo pmset schedule sleep "08/31/2009 00:00:00"
#:481#
# commandlinefu.com by David Winterbottom
# Mac Sleep Timer
sudo pmset schedule sleep "08/31/2009 00:00:00"
#:482#
# commandlinefu.com by David Winterbottom
# Verbosely delete files matching specific name pattern, older than 15 days.
find /backup/directory -name "FILENAME_*" -mtime +15 -exec rm -vf {};
# Verbosely delete files matching specific name pattern, older than 15 days.
rm -vf /backup/directory/**/FILENAME_*(m+15)
# Verbosely delete files matching specific name pattern, older than 15 days.
find /backup/directory -name "FILENAME_*" -mtime +15 | xargs rm -vf
# Remove all .svn folders inside a folder
find . -name "\.svn" -exec rm -rf {} ";"
#:483#
# commandlinefu.com by David Winterbottom
# Copy data using gtar
gtar cpf - . | (cd /dest/directory; gtar xpf -)
#:484#
# commandlinefu.com by David Winterbottom
# Copy data using gtar
gtar cpf - . | (cd /dest/directory; gtar xpf -)
#:485#
# commandlinefu.com by David Winterbottom
# Updating the status on identi.ca using curl.
curl -u USER:PASS -d status="NEW STATUS" http://identi.ca/api/statuses/update.xm
l
#:486#
# commandlinefu.com by David Winterbottom
# Display a block of text with vim with offset, like with AWK
vim -e -s -c 'g/start_pattern/+1,/stop_pattern/-1 p' -cq file.txt
# How to Find the Block Size
/sbin/dumpe2fs /dev/hda2 | grep 'Block size'
#:487#
# commandlinefu.com by David Winterbottom
# Updating the status on identi.ca using curl.
curl -u USER:PASS -d status="NEW STATUS" http://identi.ca/api/statuses/update.xm
l
#:488#
# commandlinefu.com by David Winterbottom
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 1)
mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -o dvd.
avi dvd://0
# Rip DVD to YouTube ready MPEG-4 AVI file using mencoder
mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourc
c xvid -vf scale=320:-2,expand=:240:::1 -o output.avi dvd://0
# Dump dvd from a different machine onto this one.
ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso
# How to copy CD/DVD into hard disk (.iso)
dd if=/dev/cdrom of=whatever.iso
# Rip a DVD to AVI format
mencoder dvd://1 -aid 128 -o track-1.avi -oac copy -ovc lavc -lavcopts vcodec=mp
eg4
#:489#
# commandlinefu.com by David Winterbottom
# Rip a DVD to AVI format
mencoder dvd://1 -aid 128 -o track-1.avi -oac copy -ovc lavc -lavcopts vcodec=mp
eg4
#:490#
# commandlinefu.com by David Winterbottom
# Creates Solaris alternate boot environment on another zpool.
lucreate -n be1 [-c be0] -p zpool1
# Creating a ZFS Storage Pool by Using Files
zpool create tank /path/to/file/a /path/to/file/b
# Creating a Mirrored Storage Pool using Zpool
zpool create tank mirror c0t0d0 c0t1d0 mirror c0t2d0 c0t3d0
#:491#
# commandlinefu.com by David Winterbottom
# Creating a ZFS Storage Pool by Using Files
zpool create tank /path/to/file/a /path/to/file/b
# Creating a Mirrored Storage Pool using Zpool
zpool create tank mirror c0t0d0 c0t1d0 mirror c0t2d0 c0t3d0
#:492#
# commandlinefu.com by David Winterbottom
# find largest file in /var
find /var -mount -ls -xdev | /usr/bin/sort -nr +6 | more
#:493#
# commandlinefu.com by David Winterbottom
# 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
#:494#
# commandlinefu.com by David Winterbottom
# Make ogg file from wav file
oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'
# 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
#:495#
# commandlinefu.com by David Winterbottom
# 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
#:496#
# commandlinefu.com by David Winterbottom
# Manually Pause/Unpause Firefox Process with POSIX-Signals
killall -STOP -m firefox
#:497#
# commandlinefu.com by David Winterbottom
# Manually Pause/Unpause Firefox Process with POSIX-Signals
killall -STOP -m firefox
#:498#
# commandlinefu.com by David Winterbottom
# Download file with multiple simultaneous connections
aria2c -s 4 http://my/url
# Manually Pause/Unpause Firefox Process with POSIX-Signals
killall -STOP -m firefox
#:499#
# commandlinefu.com by David Winterbottom
# Use heading subtitle file as watermark using mencoder
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -la
meopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1
-o output.avi input.flv
# FLV to AVI with subtitles and forcing audio sync using mencoder
mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=12
8 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv
# Grab all .flv files from a webpage to the current working directory
wget `lynx -dump http://www.ebow.com/ebowtube.php | grep .flv$ | sed 's/[[:blank
:]]\+[[:digit:]]\+\. //g'`
# convert all files in a dir of a certain type to flv
for f in *.m4a; do ffmpeg -i "$f" "${f%.m4a}.flv"; done
# 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
#:500#
# commandlinefu.com by David Winterbottom
# Connect to SMTP server using STARTTLS
openssl s_client -starttls smtp -crlf -connect 127.0.0.1:25
# Create AUTH PLAIN string to test SMTP AUTH session
printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /'
# Email HTML content
mailx bar@foo.com -s "HTML Hello" -a "Content-Type: text/html" < body.htm
#:501#
# commandlinefu.com by David Winterbottom
# List out classes in of all htmls in directory
find . -name '*.html' -exec 'sed' 's/.*class="\([^"]*\?\)".*/\1/ip;d' '{}' ';'
|sort -su
# Save an HTML page, and covert it to a .pdf file
wget $URL | htmldoc --webpage -f "$URL".pdf - ; xpdf "$URL".pdf &
# Email HTML content
mailx bar@foo.com -s "HTML Hello" -a "Content-Type: text/html" < body.htm
#:502#
# commandlinefu.com by David Winterbottom
# Extract tar.gz in a single command
gunzip < foo.tar.gz | tar xvf -
#:503#
# commandlinefu.com by David Winterbottom
# copy working directory and compress it on-the-fly while showing progress
tar -cf - . | pv -s $(du -sb . | awk '{print $1}') | gzip > out.tgz
# backup local MySQL database into a folder and removes older then 5 days backup
s
mysqldump -uUSERNAME -pPASSWORD database | gzip > /path/to/db/files/db-backup-`d
ate +%Y-%m-%d`.sql.gz ;find /path/to/db/files/* -mtime +5 -exec rm {} \;
# back up your commandlinefu contributed commands
curl http://www.commandlinefu.com/commands/by//rss|gzip ->command
linefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz
# Run gunzipped sql file in PostGres, adding to the library since I couldnt find
this command anywhere else on the web.
gzip -dc /tmp/pavanlimo.gz | psql -U user db
# create tar.gz archive
tar -pczf archive_name.tar.gz /path/to/dir/or/file
# clone a hard drive to a remote directory via ssh tunnel, and compressing the i
mage
# dd if=/dev/sda | gzip -c | ssh user@ip 'dd of=/mnt/backups/sda.dd'
# Create a tar.gz in a single command
tar cvf - foodir | gzip > foo.tar.gz
#:504#
# commandlinefu.com by David Winterbottom
# Return threads count of a process
ps -o thcount -p
# Count the total number of files in each immediate subdirectory
ps -ef | grep pmon
# Count the total number of files in each immediate subdirectory
find . -type f -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn
# 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
# Get lines count of a list of files
find . -name "*.sql" -print0 | wc -l --files0-from=-
# Function that counts recursively number of lines of all files in specified fol
ders
count() { find $@ -type f -exec cat {} + | wc -l; }
#:505#
# commandlinefu.com by David Winterbottom
# List files recursively sorted by modified time
find /home/fizz -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
#:506#
# commandlinefu.com by David Winterbottom
# Eclipse needs to know the path to the local maven repository. Therefore the cl
asspath variable M2_REPO has to be set.
mvn -Declipse.workspace= eclipse:add-maven-repo
# Skipping tests in Maven
mvn -Dmaven.test.skip=true install
# Creating a Maven project
mvn archetype:create -DgroupId=my.work -DartifactId=MyProject
# Maven Install 3rd party JAR
mvn install:install-file -Dfile= -DgroupId= -DartifactId
= -Dversion= -Dpackaging= -DgeneratePom=true
#:507#
# commandlinefu.com by David Winterbottom
# View SuSE version
cat /etc/SuSE-release
#:508#
# commandlinefu.com by David Winterbottom
# Preview of a picture in a terminal
img test.jpg
# Find which jars contain a class
find . -name "*.jar" | while read file; do echo "Processing ${file}"; jar -tvf $
file | grep "Foo.class"; done
# Maven Install 3rd party JAR
mvn install:install-file -Dfile= -DgroupId= -DartifactId
= -Dversion= -Dpackaging= -DgeneratePom=true
#:509#
# commandlinefu.com by David Winterbottom
# find files containing text
grep -lir "sometext" * > sometext_found_in.log
# find files containing text
grep -lir "some text" *
#:510#
# commandlinefu.com by David Winterbottom
# Output Detailed Process Tree for any User
psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
# View Processeses like a fu, fu
pstree -p
# View Processeses like a fu, fu
command ps -Hacl -F S -A f
# View and review the system process tree.
pstree -Gap | less -r
#:511#
# commandlinefu.com by David Winterbottom
# Using scapy to get the IP of the iface used to contact local gw (i.e. supposed
host IP)
python -c "import scapy.all; print [x[4] for x in scapy.all.conf.route.routes if
x[2] != '0.0.0.0'][0]"
#:512#
# commandlinefu.com by David Winterbottom
# Get last changed revision to all eclipse projects in a SVN working copy
find . -iname ".project"| xargs -I {} dirname {} | LC_ALL=C xargs -I {} svn info
{} | grep "Last Changed Rev\|Path" | sed "s/Last Changed Rev: /;/" | sed "s/Pat
h: //" | sed '$!N;s/\n//'
# Eclipse needs to know the path to the local maven repository. Therefore the cl
asspath variable M2_REPO has to be set.
mvn -Declipse.workspace= eclipse:add-maven-repo
#:513#
# commandlinefu.com by David Winterbottom
# display typedefs, structs, unions and functions provided by a header file
cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less
#:514#
# commandlinefu.com by David Winterbottom
# Outputs a 10-digit random number
head -c10 <(echo $RANDOM$RANDOM$RANDOM)
# Substitution cipher
echo "Decode this"| tr [a-zA-Z] $(echo {a..z} {A..Z}|grep -o .|sort -R|tr -d "\n
")
# Print a random 8 digit number
jot -s '' -r -n 8 0 9
# Print a random 8 digit number
jot -r -n 8 0 9 | rs -g 0
# Random number generation within a range N, here N=10
echo $(( $RANDOM % 10 + 1 ))
# Generate random password
randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}
# Randomize lines in a file
awk 'BEGIN{srand()}{print rand(),$0}' SOMEFILE | sort -n | cut -d ' ' -f2-
#:515#
# commandlinefu.com by David Winterbottom
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 1)
mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -o dvd.
avi dvd://0
# 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
# Record MP3 audio via ALSA using ffmpeg
ffmpeg -f alsa -ac 2 -i hw:1,0 -acodec libmp3lame -ab 96k output.mp3
# FLV to AVI with subtitles and forcing audio sync using mencoder
mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=12
8 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv
# create an mp3 with variable bitrate
lame -h -V 6 track9.wav track9.mp3
#:516#
# commandlinefu.com by David Winterbottom
# urldecoding
printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g
')
# urldecoding
sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
#:517#
# commandlinefu.com by David Winterbottom
# urldecoding
printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g
')
# urldecoding
sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
#:518#
# commandlinefu.com by David Winterbottom
# Informations sur les connexions reseau
netstat -taupe
# Lire une video dans une console Linux
mplayer -vo caca foo.avi
#:519#
# commandlinefu.com by David Winterbottom
# Lire une video dans une console Linux
mplayer -vo caca foo.avi
#:520#
# commandlinefu.com by David Winterbottom
# Informations sur les connexions reseau
netstat -taupe
#:521#
# commandlinefu.com by David Winterbottom
# Informations sur les connexions reseau
netstat -taupe
#:522#
# commandlinefu.com by David Winterbottom
# Organize a TV-Series season
season=1; for file in $(ls) ; do dir=$(echo $file | sed 's/.*S0$season\(E[0-9]\{
2\}\).*/\1/'); mkdir $dir ; mv $file $dir; done
#:523#
# commandlinefu.com by David Winterbottom
# Organize a TV-Series season
season=1; for file in $(ls) ; do dir=$(echo $file | sed 's/.*S0$season\(E[0-9]\{
2\}\).*/\1/'); mkdir $dir ; mv $file $dir; done
#:524#
# commandlinefu.com by David Winterbottom
# Compress archive(s) or directory(ies) and split the output file
rar a -m5 -v5M -R myarchive.rar /home/
#:525#
# commandlinefu.com by David Winterbottom
# Copy a folder tree through ssh using compression (no temporary files)
ssh 'tar -cz //' | tar -xvz
# Uncompress a CSS file
cat somefile.css | awk '{gsub(/{|}|;/,"&\n"); print}' >> uncompressed.css
# Compress archive(s) or directory(ies) and split the output file
rar a -m5 -v5M -R myarchive.rar /home/
#:526#
# commandlinefu.com by David Winterbottom
# Split a tarball into multiple parts
tar cf - |split -bM - .tar.
# Compress archive(s) or directory(ies) and split the output file
rar a -m5 -v5M -R myarchive.rar /home/
#:527#
# commandlinefu.com by David Winterbottom
# change ownership en masse of files owned by a specific user, including files a
nd directories with spaces
find . -uid 0 -print0 | xargs -0 chown foo:foo
#:528#
# commandlinefu.com by David Winterbottom
# change ownership en masse of files owned by a specific user, including files a
nd directories with spaces
find . -uid 0 -print0 | xargs -0 chown foo:foo
#:529#
# commandlinefu.com by David Winterbottom
# List of directories sorted by number of files they contain.
sort -n <( for i in $(find . -maxdepth 1 -mindepth 1 -type d); do echo $(find $i
| wc -l) ": $i"; done;)
#:530#
# commandlinefu.com by David Winterbottom
# Remove an old gmetric statistic
gmetric -n $METRIC_NAME -v foo -t string -d 10
#:531#
# commandlinefu.com by David Winterbottom
# Display Dilbert strip of the day
display http://dilbert.com$(curl -s dilbert.com|grep -Po '"\K/dyn/str_strip(/0+)
{4}/.*strip.[^\.]*\.gif')
# Show display type
ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*; find /var/spool/postfix/ -name $id -exec less {} \;
# Remove all mail in Postfix mail queue.
postsuper -d ALL
#:534#
# commandlinefu.com by David Winterbottom
# Uncompress a CSS file
cat somefile.css | awk '{gsub(/{|}|;/,"&\n"); print}' >> uncompressed.css
#:535#
# commandlinefu.com by David Winterbottom
# Split a tarball into multiple parts
tar cf - |split -bM - .tar.
# Create a simple backup
tar pzcvf /result_path/result.tar.gz /target_path/target_folder
# List contents of tar archive within a compressed 7zip archive
7z x -so testfile.tar.7z | tar tvf -
# Create a tar archive using 7z compression
tar cf - /path/to/data | 7z a -si archivename.tar.7z
# Extract multiple file in a directory
for i in *.tar.gz; do tar -xzf $i; done
# tar per directory
cd ; for i in `ls ./`; do tar czvf "$i".tar.gz "$i" ; done
# Archive every file in /var/logs
find /var/logs -name * | xargs tar -jcpf logs_`date +%Y-%m-%e`.tar.bz2
#:536#
# commandlinefu.com by David Winterbottom
# 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:"%Cg
reen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r
#:537#
# commandlinefu.com by David Winterbottom
# Convert decimal numbers to binary
function decToBin { echo "ibase=10; obase=2; $1" | bc; }
# Easily decode unix-time (funtion)
utime(){ perl -e "print localtime($1).\"\n\"";}
# Add the sbin directories to your PATH if it doesn't already exist in ZSH.
path+=( /sbin /usr/sbin /usr/local/sbin ); path=( ${(u)path} );
# Postpone a command [zsh]
# A quick shell command to weed out the small wallpapers
for i in ~/Desktop/Personal/Wallpapers/*.jpg ; { size=$((`identify -format "%wx%
h" $i | sed 's/x/*/'`)) ; if [[ $size -lt 800001 ]] then ; rm -f "$i" ; fi; }
# Changing the terminal title to the last shell command
[[ "x$TERM" == "xrxvt" || "x$XTERM_VERSION" == xXTerm* || "x$COLORTERM" == 'gnom
e-terminal' && "x$SHELL" == */bin/zsh ]] && preexec () { print -Pn "\e]0;$1\a" }
# Changing the terminal title to the last shell command
if [ "$SHELL" = '/bin/zsh' ]; then case $TERM in rxvt|*term|linux) preexec () {
print -Pn "\e]0;$1\a" };; esac; fi
# Show directories in the PATH, one per line
print -l $path
# Verbosely delete files matching specific name pattern, older than 15 days.
rm -vf /backup/directory/**/FILENAME_*(m+15)
# Remove empty directories
rmdir **/*(/^F)
# Delete empty directories with zsh
rm -d **/*(/^F)
# Create a list of binary numbers
echo {0..1}{0..1}{0..1}{0..1}
# See smbstatus all the time
while (( $i != 0 )) { smbstatus; sleep 5; clear }
#:538#
# commandlinefu.com by David Winterbottom
# 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 i
fconfig wlan0:0
# Changing tha mac adresse
sudo ifconfig eth0 hw ether 00:01:02:03:04:05
#:539#
# commandlinefu.com by David Winterbottom
# Synchronize both your system clock and hardware clock and calculate/adjust tim
e drift
ntpdate pool.ntp.org && hwclock --systohc && hwclock --adjust
#:540#
# commandlinefu.com by David Winterbottom
# Binary Clock
watch -n 1 'echo "obase=2;`date +%s`" | bc'
# Synchronize both your system clock and hardware clock and calculate/adjust tim
e drift
ntpdate pool.ntp.org && hwclock --systohc && hwclock --adjust
#:541#
# commandlinefu.com by David Winterbottom
# 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 }
#:542#
# commandlinefu.com by David Winterbottom
# Get names of files in /dev, a USB device is attached to
ls -la /dev/disk/by-id/usb-*
# Remove the boot loader from a usb stick
dd if=/dev/zero of=/dev/sdb bs=446 count=1
#:543#
# commandlinefu.com by David Winterbottom
# find files larger than 1 GB, everywhere
find / -type f -size +1000000000c
# Another way to calculate sum size of all files matching a pattern
find . -iname '*.jar' | xargs du -ks | cut -f1 | xargs echo | sed "s/ /+/g" | bc
#:544#
# commandlinefu.com by David Winterbottom
# Find jpeg images and copy them to a central location
find . -iname "*.jpg" -print0 | tr '[A-Z]' '[a-z]' | xargs -0 cp --backup=number
ed -dp -u --target-directory {location} &
# Copy all documents PDF in disk for your home directory
find / -name "*.pdf" -exec cp -t ~/Documents/PDF {} +
# Copy all documents PDF in disk for your home directory
for i in `find / -name *.pdf`; do cp -v $i $HOME; done
#:545#
# commandlinefu.com by David Winterbottom
# Remove an unnecessary suffix from a file name for all files in a directory
for f in $(ls *.xml.skippy); do mv $f `echo $f | sed 's|.skippy||'`; done
# Command to build one or more network segments - with for
seg() { for b in $(echo $1); do for x in $(seq 10); do echo $b.$x; done; done }
# Command to build one or more network segments - with while
seg() { echo -e "$1" | while read LINE; do for b in $(seq 10); do echo $LINE.$b;
done; done; }
# download all the presentations from UTOSC2009
b="http://2009.utosc.com"; for p in $( curl -s $b/presentation/schedule/ | grep
/presentation/[0-9]*/ | cut -d"\"" -f2 ); do f=$(curl -s $b$p | grep "/static/sl
ides/" | cut -d"\"" -f4); if [ -n "$f" ]; then echo $b$f; curl -O $b$f; fi done
# Notify Gnome user of files modified today
OLDIFS=$IFS; IFS=$(echo -en "\n\b"); for f in `find -daystart -mtime 0 -type f -
printf "%f\n"`; do notify-send -t 0 "$f downloaded" ; done; IFS=$OLDIFS
# Adding Color Escape Codes to global CC array for use by echo -e
declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$
ii]="\033[0;3${i}m"; done
# Show only existing executable dirs in PATH using only builtin bash commands
for p in ${PATH//:/ }; do [[ -d $p && -x $p ]] && echo $p; done
# search for a file in PATH
type
# search for a file in PATH
which
# search for a file in PATH
for L in `echo :$PATH | tr : '\n'`; do F=${L:-"."}/fileName; if [ -f ${F} -o -h
${F} ]; then echo ${F}; break; fi; done
# Convert ogg to mp3
for x in *.ogg; do ffmpeg -i "$x" "`basename "$x" .ogg`.mp3"; done
# List all groups and the user names that were in each group
for u in `cut -f1 -d: /etc/passwd`; do echo -n $u:; groups $u; done | sort
# Copy all documents PDF in disk for your home directory
find / -name "*.pdf" -exec cp -t ~/Documents/PDF {} +
# Batch image resize
for a in `ls`; do echo $a && convert $a -resize x $a; done
# IFS - use entire lines in your for cycles
export IFS=$(echo -e "\n")
# Copy all documents PDF in disk for your home directory
for i in `find / -name *.pdf`; do cp -v $i $HOME; done
#:546#
# commandlinefu.com by David Winterbottom
# Ultimate current directory usage command
ncdu
# ncdu - ncurses disk usage
ncdu directory_name
#:547#
# commandlinefu.com by David Winterbottom
# Ultimate current directory usage command
ncdu
# ncdu - ncurses disk usage
ncdu directory_name
#:548#
# commandlinefu.com by David Winterbottom
# Analyse compressed Apache access logs for the most commonly requested pages
zcat access_log.*.gz | awk '{print $7}' | sort | uniq -c | sort -n | tail -n 20
# Determine what an process is actually doing
sudo strace -pXXXX -e trace=file
# benchmark web server with apache benchmarking tool
ab -n 9000 -c 900 localhost:8080/index.php
# List apache2 virtualhosts
/usr/sbin/apache2ctl -S 2>&1 | perl -ne 'm@.*port\s+([0-9]+)\s+\w+\s+(\S+)\s+\((
.+):.*@ && do { print "$2:$1\n\t$3\n"; $root = qx{grep DocumentRoot $3}; $root =
~ s/^\s+//; print "\t$root\n" };'
# Know which modules are loaded on an Apache server
apache2 -t -D DUMP_MODULES
#:549#
# commandlinefu.com by David Winterbottom
# Checks apache's access_log file, strips the search queries and shoves them up
your e-mail
awk '/q=/{print $11}' /var/log/httpd/access_log.4 | awk -F 'q=' '{print $2}' | s
ed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1
# Checks apache's access_log file, strips the search queries and shoves them up
your e-mail
cat /var/log/httpd/access_log | grep q= | awk '{print $11}' | awk -F 'q=' '{prin
t $2}' | sed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1 | mail youremail@isp.c
om -s "[your-site] search strings for `date`"
# Know which modules are loaded on an Apache server
apache2 -t -D DUMP_MODULES
#:550#
# commandlinefu.com by David Winterbottom
# Hiding and Show files on Mac OS X
setfile -a V foo.bar; setfile -a v foo.bar;
# Open Finder from the current Terminal location
open .
#:551#
# commandlinefu.com by David Winterbottom
# For a $FILE, extracts the path, filename, filename without extension and exten
sion.
FILENAME=`echo ${FILE##*/}`;FILEPATH=`echo ${FILE%/*}`;NOEXT=`echo ${FILENAME%\.
*}`;EXT=`echo ${FILE##*.}`
#:552#
# commandlinefu.com by David Winterbottom
# Write and run a quick C program
cat | gcc -x c -o a.out - && ./a.out && rm a.out
# Create a directory and change into it at the same time
md () { mkdir -p "$@" && cd "$@"; }
# Search back through previous commands
Ctrl-R
# Go to parent directory of filename edited in last command
cd `dirname $_`
# Go to parent directory of filename edited in last command
cd !$:h
# Count to 65535 in binary (for no apparent reason)
a=`printf "%*s" 16`;b=${a//?/{0..1\}}; echo `eval "echo $b"`
# For a $FILE, extracts the path, filename, filename without extension and exten
sion.
FILENAME=`echo ${FILE##*/}`;FILEPATH=`echo ${FILE%/*}`;NOEXT=`echo ${FILENAME%\.
*}`;EXT=`echo ${FILE##*.}`
#:553#
# commandlinefu.com by David Winterbottom
# For a $FILE, extracts the path, filename, filename without extension and exten
sion.
FILENAME=`echo ${FILE##*/}`;FILEPATH=`echo ${FILE%/*}`;NOEXT=`echo ${FILENAME%\.
*}`;EXT=`echo ${FILE##*.}`
#:554#
# commandlinefu.com by David Winterbottom
# 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
# scp a good script from host A which has no public access to host C, but with a
hop by host B
ssh middlehost "ssh -a root@securehost '> nicescript'" < nicescript
# scp a good script from host A which has no public access to host C, but with a
hop by host B
cat nicescript |ssh middlehost "cat | ssh -a root@securehost 'cat > nicescript'"
# Easily scp a file back to the host you're connecting from
mecp () { scp "$@" ${SSH_CLIENT%% *}:Desktop/; }
#:555#
# commandlinefu.com by David Winterbottom
# Pipe the result of a command to IRC (channel or query)
function my_irc { tmp=`mktemp`; cat > $tmp; { echo -e "USER $username x x :$ircn
ame\nNICK $nick\nJOIN $target"; while read line; do echo -e "PRIVMSG $target :$l
ine"; done < $tmp; } | nc $server > /dev/null ; rm $tmp; }
#:556#
# commandlinefu.com by David Winterbottom
# determine if tcp port is open
nmap -p 80 hostname
# determine if tcp port is open
nc -zw2 www.example.com 80 && echo open
# determine if tcp port is open
if (nc -zw2 www.example.com 80); then echo open; fi
# 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
# Get Futurama quotations from slashdot.org servers
echo -e "HEAD / HTTP/1.1\nHost: slashdot.org\n\n" | nc slashdot.org 80 | head -n
5 | tail -1 | cut -f2 -d-
# Using netcat to copy files between servers
On target: "nc -l 4000 | tar xvf -" On source: "tar -cf - . | nc target_ip 4000"
# Pipe the result of a command to IRC (channel or query)
function my_irc { tmp=`mktemp`; cat > $tmp; { echo -e "USER $username x x :$ircn
ame\nNICK $nick\nJOIN $target"; while read line; do echo -e "PRIVMSG $target :$l
ine"; done < $tmp; } | nc $server > /dev/null ; rm $tmp; }
#:557#
# commandlinefu.com by David Winterbottom
# Convert "man page" to text file
man ls | col -b > ~/Desktop/man_ls.txt
#:558#
# commandlinefu.com by David Winterbottom
# Twit Amarok "now playing" song
curl -u : -d status="Amarok, now playing: $(dcop amarok default
nowPlaying)" http://twitter.com/statuses/update.json
#:559#
# commandlinefu.com by David Winterbottom
# See non printable caracters like tabulations, CRLF, LF line terminators ( colo
red )
od -c | grep --color '\\.'
# Outputs a 10-digit random number
n=$RANDOM$RANDOM$RANDOM; let "n %= 10000000000"; echo $n
# Outputs a 10-digit random number
echo $RANDOM$RANDOM$RANDOM |cut -c3-12
# Outputs a 10-digit random number
head -c4 /dev/urandom | od -N4 -tu4 | sed -ne '1s/.* //p'
# urlencode
(Command too long..See sample Output..)
#:560#
# commandlinefu.com by David Winterbottom
# Inserts the results of an autocompletion in the command line
ESC *
#:561#
# commandlinefu.com by David Winterbottom
# Use FileMerge to compare two files
opendiff
#:562#
# commandlinefu.com by David Winterbottom
# find out how much space are occuipied by files smaller than 1024K (sic) - impr
oved
find dir -size -1024k -type f -print0 | du --files0-from - -bc
# find out how much space are occuipied by files smaller than 1024K
find dir -size -1024k -type f | xargs -d $'\n' -n1 ls -l | cut -d ' ' -f 5 | se
d -e '2,$s/$/+/' -e '$ap' | dc
# Sum of the total resident memory Stainless.app is using.
ps -ec -o command,rss | grep Stainless | awk -F ' ' '{ x = x + $2 } END { print
x/(1024) " MB."}'
# Sum columns from CSV column $COL
perl -F',' -ane '$a += $F[3]; END { print $a }' test.csv
# Sum columns from CSV column $COL
awk -F ',' '{ x = x + $4 } END { print x }' test.csv
# Sum columns from CSV column $COL
perl -ne 'split /,/ ; $a+= $_[3]; END {print $a."\n";}' -f ./file.csv
# Do quick arithmetic on numbers from STDIN with any formatting using a perl one
liner.
perl -ne '$sum += $_ for grep { /\d+/ } split /[^\d\-\.]+/; print "$sum\n"'
#:563#
# commandlinefu.com by David Winterbottom
# Do quick arithmetic on numbers from STDIN with any formatting using a perl one
liner.
perl -ne '$sum += $_ for grep { /\d+/ } split /[^\d\-\.]+/; print "$sum\n"'
#:564#
# commandlinefu.com by David Winterbottom
# Do quick arithmetic on numbers from STDIN with any formatting using a perl one
liner.
perl -ne '$sum += $_ for grep { /\d+/ } split /[^\d\-\.]+/; print "$sum\n"'
#:565#
# commandlinefu.com by David Winterbottom
# Do quick arithmetic on numbers from STDIN with any formatting using a perl one
liner.
perl -ne '$sum += $_ for grep { /\d+/ } split /[^\d\-\.]+/; print "$sum\n"'
#:566#
# commandlinefu.com by David Winterbottom
# count how many times a string appears in a (source code) tree
$ grep -or string path/ | wc -l
# count how many times a string appears in a (source code) tree
grep -rc logged_in app/ | cut -d : -f 2 | awk '{sum+=$1} END {print sum}'
# Do quick arithmetic on numbers from STDIN with any formatting using a perl one
liner.
perl -ne '$sum += $_ for grep { /\d+/ } split /[^\d\-\.]+/; print "$sum\n"'
#:567#
# commandlinefu.com by David Winterbottom
# Check if variable is a number
if [ "$testnum" -eq "$testnum" 2>/dev/null ]; then echo It is numeric; fi
# Do quick arithmetic on numbers from STDIN with any formatting using a perl one
liner.
perl -ne '$sum += $_ for grep { /\d+/ } split /[^\d\-\.]+/; print "$sum\n"'
#:568#
# commandlinefu.com by David Winterbottom
#:569#
# commandlinefu.com by David Winterbottom
# Print text string vertically, one character per line.
echo "vertical text" | fold -1
# Print text string vertically, one character per line.
echo "vertical text" | grep -o '.'
# Merges given files line by line
paste -d ',:' file1 file2 file3
#:570#
# commandlinefu.com by David Winterbottom
# Get absolut path to your bash-script
script_path=$(cd $(dirname $0);pwd)
#:571#
# commandlinefu.com by David Winterbottom
# Extract the daily average number of iops
for x in `seq -w 1 30`; do sar -b -f /var/log/sa/sa$x | gawk '/Average/ {print $
2}'; done
#:572#
# commandlinefu.com by David Winterbottom
# Typing the current date ( or any string ) via a shortcut as if the keys had be
en actually typed with the hardware keyboard in any application.
xvkbd -xsendevent -text $(date +%Y%m%d)
# get xclip to own the clipboard contents
xclip -o -selection clipboard | xclip -selection clipboard
# Paste OS X clipboard contents to a file on a remote machine
pbpaste | ssh user@hostname 'cat > ~/my_new_file.txt'
# cat large file to clipboard with speed-o-meter
pv large.xml | xclip
# pipe output of a command to your clipboard
some command|xsel --clipboard
# Paste the contents of OS X clipboard into a new text file
pbpaste > newfile.txt
#:573#
# commandlinefu.com by David Winterbottom
# Use QuickLook from the command line without verbose output
qlook() { qlmanage -p "$@" >& /dev/null & }
#:574#
# commandlinefu.com by David Winterbottom
# Create a random file of a specific size
dd if=/dev/zero of=testfile.txt bs=1M count=10
#:575#
# commandlinefu.com by David Winterbottom
# get newest jpg picture in a folder
cp `ls -x1tr *.jpg | tail -n 1` newest.jpg
#:576#
# commandlinefu.com by David Winterbottom
# Instant mirror from your laptop + webcam (fullscreen+grab)
mplayer -fs -vf screenshot,mirror tv://
# Instant mirror from your laptop + webcam
mplayer tv:// -vf mirror
# View webcam output using GStreamer pipeline
gst-launch-0.10 autovideosrc ! video/x-raw-yuv,framerate=\(fraction\)30/1,width=
640,height=480 ! ffmpegcolorspace ! autovideosink
# Record audio and video from webcam using mencoder
mencoder tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0:fps=30:ou
tfmt=yuy2:forceaudio:alsa:adevice=hw.2,0 -ovc lavc -lavcopts vcodec=mpeg4:vbitra
te=1800 -ffourcc xvid -oac mp3lame -lameopts cbr=128 -o output.avi
# View webcam output using mplayer
mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:out
fmt=yuy2
# Record audio and video from webcam using ffmpeg
ffmpeg -f alsa -r 16000 -i hw:2,0 -f video4linux2 -s 800x600 -i /dev/video0 -r 3
0 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi
# Record a webcam output into a video file.
ffmpeg -an -f video4linux -s 320x240 -b 800k -r 15 -i /dev/v4l/video0 -vcodec mp
eg4 myvideo.avi
# get newest jpg picture in a folder
cp `ls -x1tr *.jpg | tail -n 1` newest.jpg
#:577#
# commandlinefu.com by David Winterbottom
# Match non-empty lines
grep -v "^\W$"
#:578#
# commandlinefu.com by David Winterbottom
# 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
#:579#
# commandlinefu.com by David Winterbottom
# 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
#:580#
# commandlinefu.com by David Winterbottom
# Using gdiff only select lines that are common between two files
gdiff --unified=10000 input.file1 inpute.file2 | egrep -v "(^\+[a-z]|^\-[a-z])"|
sort > outputfile.sorted
#:581#
# commandlinefu.com by David Winterbottom
# Using gdiff only select lines that are common between two files
gdiff --unified=10000 input.file1 inpute.file2 | egrep -v "(^\+[a-z]|^\-[a-z])"|
sort > outputfile.sorted
#:582#
# commandlinefu.com by David Winterbottom
# 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
#:583#
# commandlinefu.com by David Winterbottom
# How to watch files
watch -d 'ls -l'
# Watching Command
watch 'cat /proc/loadavg'
# watch iptables counters
watch --interval 0 'iptables -nvL | grep -v "0 0"'
# Get a regular updated list of zombies
watch "ps auxw | grep [d]efunct"
# Get a regular updated list of zombies
watch "ps auxw | grep 'defunct' | grep -v 'grep' | grep -v 'watch'"
# Follow the most recently updated log files
ls -drt /var/log/* | tail -n5 | xargs sudo tail -n0 -f
# Display a cool clock on your terminal
watch -t -n1 "date +%T|figlet"
#:584#
# commandlinefu.com by David Winterbottom
# Get lines count of a list of files
find . -name "*.sql" -print0 | wc -l --files0-from=-
#:585#
# commandlinefu.com by David Winterbottom
# Update your OpenDNS network ip
wget -q --user= --password= 'https://updates.opendns.com/nic
/update?hostname=your_opendns_hostname&myip=your_ip' -O -
#:586#
# commandlinefu.com by David Winterbottom
# Update your OpenDNS network ip
wget -q --user= --password= 'https://updates.opendns.com/nic
/update?hostname=your_opendns_hostname&myip=your_ip' -O -
#:587#
# commandlinefu.com by David Winterbottom
# Convert decimal numbers to binary
function decToBin { echo "ibase=10; obase=2; $1" | bc; }
# Function to output an ASCII character given its decimal equivalent
chr () { echo -en "\0$(printf %x $1)"}
# Function to output an ASCII character given its decimal equivalent
chr() { printf \\$(printf %o $1); }
# Function to output an ASCII character given its decimal equivalent
chr () { printf \\$(($1/64*100+$1%64/8*10+$1%8)); }
# Create a list of binary numbers
echo {0..1}{0..1}{0..1}{0..1}
#:588#
# commandlinefu.com by David Winterbottom
# Convert decimal numbers to binary
function decToBin { echo "ibase=10; obase=2; $1" | bc; }
# Adding Color Escape Codes to global CC array for use by echo -e
declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$
ii]="\033[0;3${i}m"; done
# Create a list of binary numbers
echo {0..1}{0..1}{0..1}{0..1}
#:589#
# commandlinefu.com by David Winterbottom
# Migrate existing Ext3 filesystems to Ext4
tune2fs -O extents,uninit_bg,dir_index /dev/yourpartition
#:590#
# commandlinefu.com by David Winterbottom
# Migrate existing Ext3 filesystems to Ext4
tune2fs -O extents,uninit_bg,dir_index /dev/yourpartition
#:591#
# commandlinefu.com by David Winterbottom
# Set an alarm to wake up [2]
echo "aplay path/to/song" |at [time]
#:592#
# commandlinefu.com by David Winterbottom
# Function that outputs dots every second until command completes
sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; do
ne; }; export -f sleeper
# Force hard reset on server
echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger
# Find removed files still in use via /proc
find -L /proc/*/fd -links 0 2>/dev/null
#:593#
# commandlinefu.com by David Winterbottom
# Fill up disk space (for testing)
tail $0 >> $0
# Fill up disk space (for testing)
dd if=/dev/zero of=/fs/to/fill/dummy00 bs=8192 count=$(df --block-size=8192 / |
awk 'NR!=1 {print $4-100}')
# Find removed files still in use via /proc
find -L /proc/*/fd -links 0 2>/dev/null
#:594#
# commandlinefu.com by David Winterbottom
#:595#
# commandlinefu.com by David Winterbottom
# replace spaces in filenames with underscores
rename 'y/ /_/' *
#:596#
# commandlinefu.com by David Winterbottom
# floating point shell calculator
calc() { awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'; }
# floating point bash calculator w/o precision
b(){ echo "scale=${2:-2}; $1" | bc -l; }
# Define a quick calculator function
? () { echo "$*" | bc -l; }
#:597#
# commandlinefu.com by David Winterbottom
# Define a quick calculator function
? () { echo "$*" | bc -l; }
#:598#
# commandlinefu.com by David Winterbottom
# Check if filesystem hangs
ls /mnt/badfs &
#:599#
# commandlinefu.com by David Winterbottom
# Check if filesystem hangs
ls /mnt/badfs &
#:600#
# commandlinefu.com by David Winterbottom
# Recursive when needed
rm strangedirs -rf
#:601#
# commandlinefu.com by David Winterbottom
# Back up a PLESK Installation
/opt/psa/bin/pleskbackup server -v --output-file=plesk_server.bak
#:602#
# commandlinefu.com by David Winterbottom
# throttle bandwidth with cstream
tar -cj /backup | cstream -t 777k | ssh host 'tar -xj -C /backup'
#:603#
# commandlinefu.com by David Winterbottom
# throttle bandwidth with cstream
tar -cj /backup | cstream -t 777k | ssh host 'tar -xj -C /backup'
#:604#
# commandlinefu.com by David Winterbottom
# 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
#:605#
# commandlinefu.com by David Winterbottom
# Shows how many percents of all avaliable packages are installed in your gentoo
system
echo $((`eix --only-names -I | wc -l` * 100 / `eix --only-names | wc -l`))%
# Resume an emerge, and keep all object files that are already built
FEATURES=keepwork emerge --resume
#:606#
# commandlinefu.com by David Winterbottom
# Resume an emerge, and keep all object files that are already built
FEATURES=keepwork emerge --resume
#:607#
# commandlinefu.com by David Winterbottom
# Check if you need to run LaTeX more times to get the refefences right
egrep "(There were undefined references|Rerun to get (cross-references|the bars)
right)" texfile.log
#:608#
# commandlinefu.com by David Winterbottom
# pipe output of a command to your clipboard
some command|xsel --clipboard
#:609#
# commandlinefu.com by David Winterbottom
# live ssh network throughput test
pv /dev/zero|ssh $host 'cat > /dev/null'
# live ssh network throughput test
yes | pv | ssh $host "cat > /dev/null"
# copy working directory and compress it on-the-fly while showing progress
tar -cf - . | pv -s $(du -sb . | awk '{print $1}') | gzip > out.tgz
# Duplicate a directory tree using tar and pipes
(cd /source/dir ; tar cv .)|(cd /dest/dir ; tar xv)
# cat large file to clipboard with speed-o-meter
pv large.xml | xclip
#:610#
# commandlinefu.com by David Winterbottom
# get xclip to own the clipboard contents
xclip -o -selection clipboard | xclip -selection clipboard
# encode image to base64 and copy to clipboard
uuencode -m $1 /dev/stdout | sed '1d' | sed '$d' | tr -d '\n' | xclip -selection
clipboard
# preprocess code to be posted in comments on this site
sed 's/^/$ /' "$script" | xclip
# cat large file to clipboard with speed-o-meter
pv large.xml | xclip
#:611#
# commandlinefu.com by David Winterbottom
# backup all your commandlinefu.com favourites to a plaintext file
clfavs(){ URL="http://www.commandlinefu.com";wget -O - --save-cookies c --post-d
ata "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;}
# Log a command's votes
while true; do curl -s http://www.commandlinefu.com/commands/view/3643/log-a-com
mands-votes | grep 'id="num-votes-' | sed 's;.*id="num-votes-[0-9]*">\([0-9\-]*\
);\1;' >> votes; sleep 10; done
# Get ethernet card information.
ethtool eth0
# Get the information about the internet usage from the commandline.
vnstat
# Search commandlinefu.com from the command line using the API
cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ |
openssl base64)/plaintext"; }
# print latest (top 10, top 3 or *) commandlinefu.com commands
wget -qO - http://www.commandlinefu.com/feed/tenup | xmlstarlet sel -T -t -o '&l
t;x>' -n -t -m rss/channel/item -o '<y>' -n -v description -o '</y&g
t;' -n -t -o '</x>' | xmlstarlet sel -T -t -m x/y -v code -n
# back up your commandlinefu contributed commands
curl http://www.commandlinefu.com/commands/by//rss|gzip ->command
linefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz
# Search commandlinefu from the command line
(curl -d q=grep http://www.commandlinefu.com/search/autocomplete) | egrep 'autoc
omplete|votes|destination' | perl -pi -e 's/a style="display:none" class="destin
ation" href="//g;s/<[^>]*>//g;s/">$/\n\n/g;s/^ +//g;s/^\//http:\/\/commandlinefu
.com\//g'
#:612#
# commandlinefu.com by David Winterbottom
# ignore hidden directory in bash completion (e.g. .svn)
Add to ~/.inputrc: set match-hidden-files off
# ignore hidden directory in bash completion (e.g. .svn)
bind 'set match-hidden-files off'
#:613#
# commandlinefu.com by David Winterbottom
# Scan computers OS and open services on all network
nmap -O 192.168.1.1/24
#:614#
# commandlinefu.com by David Winterbottom
# Scan computers OS and open services on all network
nmap -O 192.168.1.1/24
#:615#
# commandlinefu.com by David Winterbottom
# Functions to display, save and restore $IFS
ifs () { echo -n "${IFS}"|hexdump -e '"" 10/1 "'\''%_c'\''\t" "\n"' -e '"" 10/1
"0x%02x\t" "\n\n"'|sed "s/''\|\t0x[^0-9]//g; $,/^$/d"
# Notify Gnome user of files modified today
OLDIFS=$IFS; IFS=$(echo -en "\n\b"); for f in `find -daystart -mtime 0 -type f -
printf "%f\n"`; do notify-send -t 0 "$f downloaded" ; done; IFS=$OLDIFS
# IFS - use entire lines in your for cycles
export IFS=$(echo -e "\n")
#:616#
# commandlinefu.com by David Winterbottom
# Printing multiple years with Unix cal command
for y in $(seq 2009 2011); do cal $y; done
#:617#
# commandlinefu.com by David Winterbottom
# Outputs files with ascii art in the intended form.
iconv -f437 -tutf8 asciiart.nfo
#:618#
# commandlinefu.com by David Winterbottom
# Outputs files with ascii art in the intended form.
iconv -f437 -tutf8 asciiart.nfo
#:619#
# commandlinefu.com by David Winterbottom
# Show only existing executable dirs in PATH using only builtin bash commands
for p in ${PATH//:/ }; do [[ -d $p && -x $p ]] && echo $p; done
# Test if the given argument is a valid ip address.
perl -e '$p=qr!(?:0|1\d{0,2}|2(?:[0-4]\d?|5[0-5]?|[6-9])?|[3-9]\d?)!;print((shif
t=~m/^$p\.$p\.$p\.$p$/)?1:0);' 123.123.123.123
#:620#
# commandlinefu.com by David Winterbottom
# Test if the given argument is a valid ip address.
perl -e '$p=qr!(?:0|1\d{0,2}|2(?:[0-4]\d?|5[0-5]?|[6-9])?|[3-9]\d?)!;print((shif
t=~m/^$p\.$p\.$p\.$p$/)?1:0);' 123.123.123.123
#:621#
# commandlinefu.com by David Winterbottom
# kill some process (same as others) but parsing to a variable
pkill -9 -f program
#:622#
# commandlinefu.com by David Winterbottom
# Carriage return for reprinting on the same line
while true; do echo -ne "$(date)\r"; sleep 1; done
# Watch number of lines being processed on a clear screen
cat /dev/urandom|awk 'BEGIN{"tput cuu1" | getline CursorUp; "tput clear" | getli
ne Clear; printf Clear}{num+=1;printf CursorUp; print num}'
#:623#
# commandlinefu.com by David Winterbottom
# Know when you will type :q in your term instead of vi(m), the alias will chewe
d you out.
alias :q='tput setaf 1; echo >&2 "this is NOT vi(m) :/"; tput sgr0'
# Watch number of lines being processed on a clear screen
cat /dev/urandom|awk 'BEGIN{"tput cuu1" | getline CursorUp; "tput clear" | getli
ne Clear; printf Clear}{num+=1;printf CursorUp; print num}'
#:624#
# commandlinefu.com by David Winterbottom
# Fast grepping (avoiding UTF overhead)
export LANG=C; grep string longBigFile.log
#:625#
# commandlinefu.com by David Winterbottom
# Split a tarball into multiple parts
tar cf - |split -bM - .tar.
# Unarchive entire folder
for f in *;do case "$(echo $f|sed "s/.*\.\([a-z\.]*\)/\1/g")" in zip)unzip -qqo
$f&&rm $f;;tar.gz|tar.bz2)tar xf $f&&rm $f;;rar)unrar e -o+ -r -y $f&&rm $f;;7z)
7z e -qqo $f;;esac;done
# List contents of tar archive within a compressed 7zip archive
7z x -so testfile.tar.7z | tar tvf -
# Create a tar archive using 7z compression
tar cf - /path/to/data | 7z a -si archivename.tar.7z
#:626#
# commandlinefu.com by David Winterbottom
# Create a tar archive using 7z compression
tar cf - /path/to/data | 7z a -si archivename.tar.7z
#:627#
# commandlinefu.com by David Winterbottom
# List contents of tar archive within a compressed 7zip archive
7z x -so testfile.tar.7z | tar tvf -
# Create a tar archive using 7z compression
tar cf - /path/to/data | 7z a -si archivename.tar.7z
#:628#
# commandlinefu.com by David Winterbottom
# Create a zip file ignoring .svn files
zip -r foo.zip DIR -x "*/.svn/*"
# Create a zip file ignoring .svn files
find . -not \( -name .svn -prune \) -type f | xargs zip XXXXX.zip
# Create a tar archive using 7z compression
tar cf - /path/to/data | 7z a -si archivename.tar.7z
#:629#
# commandlinefu.com by David Winterbottom
# Create a tar archive using 7z compression
tar cf - /path/to/data | 7z a -si archivename.tar.7z
#:630#
# commandlinefu.com by David Winterbottom
# monitor network traffic and throughput in real time
iptraf
# Test network performance, copying from the mem of one box, over the net to the
mem of another
dd if=/dev/zero bs=256M count=1 | nc [remoteIP] [remotePort] and on the other ho
st nc -l port >/dev/null
#:631#
# commandlinefu.com by David Winterbottom
# Create a file list of all package files installed on your Red-Hat-like system
for easy grepping
for i in `rpm -qva | sort ` ; do ; echo "===== $i =====" ; rpm -qvl $i ; done >
/tmp/pkgdetails
#:632#
# commandlinefu.com by David Winterbottom
# Duplicate a directory tree using tar and pipes
(cd /source/dir ; tar cv .)|(cd /dest/dir ; tar xv)
# Duplicate a directory tree using tar and pipes
(cd /source/dir ; tar cvf - .)|(cd /dest/dir ; tar xvpf -)
#:633#
# commandlinefu.com by David Winterbottom
# Duplicate a directory tree using tar and pipes
(cd /source/dir ; tar cv .)|(cd /dest/dir ; tar xv)
# Duplicate a directory tree using tar and pipes
(cd /source/dir ; tar cvf - .)|(cd /dest/dir ; tar xvpf -)
#:634#
# commandlinefu.com by David Winterbottom
# Send Reminders from your Linux Server to Growl on a Mac
remind -z1 -k'echo %s |ssh @ "growlnotify"' ~/.reminders &
#:635#
# commandlinefu.com by David Winterbottom
# Send Reminders from your Linux Server to Growl on a Mac
remind -z1 -k'echo %s |ssh @ "growlnotify"' ~/.reminders &
#:636#
# commandlinefu.com by David Winterbottom
# Run gunzipped sql file in PostGres, adding to the library since I couldnt find
this command anywhere else on the web.
gzip -dc /tmp/pavanlimo.gz | psql -U user db
#:637#
# commandlinefu.com by David Winterbottom
#:638#
# commandlinefu.com by David Winterbottom
# Kill a process with its name
pkill $1
#:639#
# commandlinefu.com by David Winterbottom
# Kill a process with its name
pkill $1
#:640#
# commandlinefu.com by David Winterbottom
# Pause and Resume Processes
stop () { ps -ec | grep $@ | kill -SIGSTOP `awk '{print $1}'`; }
# Return threads count of a process
ps -o thcount -p
# Output Detailed Process Tree for any User
psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
# Print text string vertically, one character per line.
echo "vertical text" | fold -1
# Function that outputs dots every second until command completes
sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; do
ne; }; export -f sleeper
# Print text string vertically, one character per line.
echo "vertical text" | grep -o '.'
# Will email user@example.com when all Rsync processes have finished.
$(while [ ! -z "$(pgrep rsync)" ]; do echo; done; echo "rsync done" | mailx user
@example.com) > /dev/null &
# View open file descriptors for a process.
lsof -p | wc -l
# Kill a process with its name
pkill $1
# Click on a GUI window and show its process ID and command used to run the proc
ess
xprop | awk '/PID/ {print $3}' | xargs ps h -o pid,cmd
#:641#
# commandlinefu.com by David Winterbottom
# Create more threads with less stack space
ulimit -s 64
#:642#
# commandlinefu.com by David Winterbottom
# To find how Apache has been compiled from commandline
httpd2 -V
# Get the information about the Apache loaded modules from command line
httpd2 -M
# List apache2 virtualhosts
/usr/sbin/apache2ctl -S 2>&1 | perl -ne 'm@.*port\s+([0-9]+)\s+\w+\s+(\S+)\s+\((
.+):.*@ && do { print "$2:$1\n\t$3\n"; $root = qx{grep DocumentRoot $3}; $root =
~ s/^\s+//; print "\t$root\n" };'
#:643#
# commandlinefu.com by David Winterbottom
#:644#
# commandlinefu.com by David Winterbottom
# Provides external IP, Country and City in a formated manner.
geoip () { curl -s "http://www.geoiptool.com/?IP=$1" | html2text | egrep --colo
r 'City:|IP Address:|Country:' }
# geoip information
geoiplookup www.commandlinefu.com
# geoip information
geo(){ curl -s "http://www.geody.com/geoip.php?ip=$(dig +short $1)"| sed '/^IP:/
!d;s/<[^>][^>]*>//g'; }
# find geographical location of an ip address
lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|sed -nr s/'^.*My IP addres
s city: (.+)$/\1/p'
#:645#
# commandlinefu.com by David Winterbottom
# Open windows executable, file, or folder from cygwin terminal
explorer $( cygpath "/path/to/file_or_exe" -w )
#:646#
# commandlinefu.com by David Winterbottom
# Open windows executable, file, or folder from cygwin terminal
explorer $( cygpath "/path/to/file_or_exe" -w )
#:647#
# commandlinefu.com by David Winterbottom
# Open windows executable, file, or folder from cygwin terminal
explorer $( cygpath "/path/to/file_or_exe" -w )
#:648#
# commandlinefu.com by David Winterbottom
# Open windows executable, file, or folder from cygwin terminal
explorer $( cygpath "/path/to/file_or_exe" -w )
#:649#
# commandlinefu.com by David Winterbottom
# OSX command to take badly formatted xml from the clipboard, cleans it up and p
uts it back into the clipboard.
pbpaste | tidy -xml -wrap 0 | pbcopy
#:650#
# commandlinefu.com by David Winterbottom
# OSX command to take badly formatted xml from the clipboard, cleans it up and p
uts it back into the clipboard.
pbpaste | tidy -xml -wrap 0 | pbcopy
#:651#
# commandlinefu.com by David Winterbottom
# OSX command to take badly formatted xml from the clipboard, cleans it up and p
uts it back into the clipboard.
pbpaste | tidy -xml -wrap 0 | pbcopy
#:652#
# commandlinefu.com by David Winterbottom
# Search trought pidgin's conversation logs for "searchterm", and output the res
ult.
grep -Ri searchterm ~/.purple/logs/* | sed -e 's/<.*?>//g'
# Tail the most recently modified file
ls -t1 | head -n1 | xargs tail -f
# Follow tail by name (fix for rolling logs with tail -f)
tail -F file
#:653#
# commandlinefu.com by David Winterbottom
# validate xml in a shell script.
xmlproc_parse.python-xml &>/dev/null || exit 1
# Lists unambigously names of all xml elements used in files in current director
y
grep -Eho '<[a-ZA-Z_][a-zA-Z0-9_-:]*' * | sort -u | cut -c2-
# Simple XML tag extract with sed
sed -n 's/.*\([^<]*\)<\/foo>.*/\1/p'
#:654#
# commandlinefu.com by David Winterbottom
# get events from google calendar for a given dates range
wget -q -O - 'URL/full?orderby=starttime&singleevents=true&start-min=2009-06-01&
start-max=2009-07-31' | perl -lane '@m=$_=~m/(.+?)(.+?)][^>]*>//g'; }
# Check if a .no domain is available
check_dns_no() { for i in $* ; do if `wget -O - -q http://www.norid.no/domenenav
nbaser/whois/?query=$i.no | grep "no match" &>/dev/null` ; then echo $i.no "avai
lable" ; fi ; sleep 1 ;done }
# Perform a reverse DNS lookup
dig -x 74.125.45.100
# Query Wikipedia via console over DNS
dig +short txt .wp.dg.cx
#:664#
# commandlinefu.com by David Winterbottom
# Query Wikipedia via console over DNS
dig +short txt .wp.dg.cx
#:665#
# commandlinefu.com by David Winterbottom
# Query Wikipedia via console over DNS
dig +short txt .wp.dg.cx
#:666#
# commandlinefu.com by David Winterbottom
# Check reverse DNS
nslookup {ip}
# Check reverse DNS
dig +short -x {ip}
# Check reverse DNS
dig -x {IP}
# Check reverse DNS
host {checkIp or hostname} [dns server]
# Check if a .no domain is available
check_dns_no() { for i in $* ; do if `wget -O - -q http://www.norid.no/domenenav
nbaser/whois/?query=$i.no | grep "no match" &>/dev/null` ; then echo $i.no "avai
lable" ; fi ; sleep 1 ;done }
# List of reverse DNS records for a subnet
nmap -R -sL 209.85.229.99/27 | awk '{if($3=="not")print"("$2") no PTR";else prin
t$3" is "$2}' | grep '('
# Use dig instead of nslookup
dig google.com
# Query Wikipedia via console over DNS
dig +short txt .wp.dg.cx
#:667#
# commandlinefu.com by David Winterbottom
# Get Futurama quotations from slashdot.org servers
curl -sI http://slashdot.org/ | sed -nr 's/X-(Bender|Fry)(.*)/\1\2/p'
#:668#
# commandlinefu.com by David Winterbottom
# from the console, start a second X server
xinit -- :1
#:669#
# commandlinefu.com by David Winterbottom
# Check if a domain is available and get the answer in just one line
whois domainnametocheck.com | grep match
# Query ip pools based on successive netnames via whois
net=DTAG-DIAL ; for (( i=1; i<30; i++ )); do whois -h whois.ripe.net $net$i | gr
ep '^inetnum:' | sed "s;^.*:;$net$i;" ; done
#:670#
# commandlinefu.com by David Winterbottom
# Query ip pools based on successive netnames via whois
net=DTAG-DIAL ; for (( i=1; i<30; i++ )); do whois -h whois.ripe.net $net$i | gr
ep '^inetnum:' | sed "s;^.*:;$net$i;" ; done
#:671#
# commandlinefu.com by David Winterbottom
# Query ip pools based on successive netnames via whois
net=DTAG-DIAL ; for (( i=1; i<30; i++ )); do whois -h whois.ripe.net $net$i | gr
ep '^inetnum:' | sed "s;^.*:;$net$i;" ; done
#:672#
# commandlinefu.com by David Winterbottom
# Query ip pools based on successive netnames via whois
net=DTAG-DIAL ; for (( i=1; i<30; i++ )); do whois -h whois.ripe.net $net$i | gr
ep '^inetnum:' | sed "s;^.*:;$net$i;" ; done
#:673#
# commandlinefu.com by David Winterbottom
# Shows how many percents of all avaliable packages are installed in your gentoo
system
echo $((`eix --only-names -I | wc -l` * 100 / `eix --only-names | wc -l`))%
#:674#
# commandlinefu.com by David Winterbottom
# Batch image resize
for a in `ls`; do echo $a && convert $a -resize x $a; done
#:675#
# commandlinefu.com by David Winterbottom
# Easily decode unix-time (funtion)
utime(){ perl -e "print localtime($1).\"\n\"";}
# Convert a MOV captured from a digital camera to a smaller AVI
ffmpeg -i input.mov -b 4096k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi
# Function to output an ASCII character given its decimal equivalent
chr () { echo -en "\0$(printf %x $1)"}
# Function to output an ASCII character given its decimal equivalent
chr() { printf \\$(printf %o $1); }
# Function to output an ASCII character given its decimal equivalent
chr () { printf \\$(($1/64*100+$1%64/8*10+$1%8)); }
# Quick and dirty convert to flash
ffmpeg -i inputfile.mp4 outputfile.flv
# Remove CR from Windows- / DOS-textfiles
dos2unix file.txt
# Remove CR from Windows- / DOS-textfiles
tr -d '\r' < ${input_txt} > ${output_txt}
# Remove ^M characters at end of lines in vi
:%s/^V^M//g
# Batch image resize
for a in `ls`; do echo $a && convert $a -resize x $a; done
#:676#
# commandlinefu.com by David Winterbottom
# Copy with progress
copy(){ cp -v "$1" "$2"&watch -n 1 'du -h "$1" "$2";printf "%s%%\n" $(echo `du -
h "$2"|cut -dG -f1`/0.`du -h "$1"|cut -dG -f1`|bc)';}
#:677#
# commandlinefu.com by David Winterbottom
# copy working directory and compress it on-the-fly while showing progress
tar -cf - . | pv -s $(du -sb . | awk '{print $1}') | gzip > out.tgz
# Copy with progress
copy(){ cp -v "$1" "$2"&watch -n 1 'du -h "$1" "$2";printf "%s%%\n" $(echo `du -
h "$2"|cut -dG -f1`/0.`du -h "$1"|cut -dG -f1`|bc)';}
#:678#
# commandlinefu.com by David Winterbottom
# Create AUTH PLAIN string to test SMTP AUTH session
printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /'
#:679#
# commandlinefu.com by David Winterbottom
# List out classes in of all htmls in directory
find . -name '*.html' -exec 'sed' 's/.*class="\([^"]*\?\)".*/\1/ip;d' '{}' ';'
|sort -su
# Create AUTH PLAIN string to test SMTP AUTH session
printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /'
#:680#
# commandlinefu.com by David Winterbottom
# Chage default shell for all users [FreeBSD]
cd /usr/home && for i in *;do chsh -s bash $i;done
# Nicely display permissions in octal format with filename
stat -f '%Sp %p %N' * | rev | sed -E 's/^([^[:space:]]+)[[:space:]]([[:digit:]]{
4})[^[:space:]]*[[:space:]]([^[:space:]]+)/\1 \2 \3/' | rev
# Delete all aliases for a network interface on a (Free)BSD system
ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 dele
te
#:681#
# commandlinefu.com by David Winterbottom
# Define an alias with a correct completion
old='apt-get'; new="su-${old}"; command="sudo ${old}"; alias "${new}=${command}"
; $( complete | sed -n "s/${old}$/${new}/p" ); alias ${new}; complete -p ${new}
# Delete all aliases for a network interface on a (Free)BSD system
ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 dele
te
#:682#
# commandlinefu.com by David Winterbottom
# Delete all aliases for a network interface on a (Free)BSD system
ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 dele
te
#:683#
# commandlinefu.com by David Winterbottom
# Find and display most recent files using find and perl
find $HOME -type f -print0 | perl -0 -wn -e '@f=<>; foreach $file (@f){ (@el)=(s
tat($file)); push @el, $file; push @files,[ @el ];} @o=sort{$a->[9]<=>$b->[9]} @
files; for $i (0..$#o){print scalar localtime($o[$i][9]), "\t$o[$i][-1]\n";}'|ta
il
# Nicely display permissions in octal format with filename
stat -f '%Sp %p %N' * | rev | sed -E 's/^([^[:space:]]+)[[:space:]]([[:digit:]]{
4})[^[:space:]]*[[:space:]]([^[:space:]]+)/\1 \2 \3/' | rev
#:684#
# commandlinefu.com by David Winterbottom
# View the octal dump of a file
od -vt x1 /tmp/spaghettifile
# Nicely display permissions in octal format with filename
stat -f '%Sp %p %N' * | rev | sed -E 's/^([^[:space:]]+)[[:space:]]([[:digit:]]{
4})[^[:space:]]*[[:space:]]([^[:space:]]+)/\1 \2 \3/' | rev
#:685#
# commandlinefu.com by David Winterbottom
# command to change the exif date time of a image
exiftool -DateTimeOriginal='2009:01:01 02:03:04' file.jpg
# Move all images in a directory into a directory hierarchy based on year, month
and day based on exif information
exiftool '-Directory a.tar.bz2
# echo something backwards
echo linux|rev
#:687#
# commandlinefu.com by David Winterbottom
# Disable annoying sound emanations from the PC speaker
sudo rmmod pcspkr
#:688#
# commandlinefu.com by David Winterbottom
# Use Linux coding style in C program
indent -linux helloworld.c
#:689#
# commandlinefu.com by David Winterbottom
# Go get those photos from a Picasa album
wget 'link of a Picasa WebAlbum' -O - |perl -e'while(<>){while(s/"media":{"conte
nt":\[{"url":"(.+?\.JPG)//){print "$1\n"}}' |wget -w1 -i -
# Download a TiVo Show
curl -s -c /tmp/cookie -k -u tivo:$MAK --digest "$(curl -s -c /tmp/cookie -k -u
tivo:$MAK --digest https://$tivo/nowplaying/index.html | sed 's;.*Download MPEG-PS.*;\1;' | sed 's|\&|\&|')" | tivodecode -m $MAK --
- > tivo.mpg
# Go get those photos from a Picasa album
echo 'Enter Picasa album RSS URL:"; read -e feedurl; GET "$feedurl" |sed 's/\n
wgetli
st
# 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 &
# Put the machine to sleep after the download(wget) is done
while [ -n "`pgrep wget`" ]; do sleep 2 ;done; [ -e "/tmp/nosleep"] || echo mem
>/sys/power/state
# Download Youtube Playlist
y=http://www.youtube.com;for i in $(curl -s $f|grep -o "url='$y/watch?v=[^']*'")
;do d=$(echo $i|sed "s;url\='$y/watch?v=\(.*\)';\1;");wget -O $d.flv "$y/get_vid
eo.php?video_id=$d&t=$(curl -s "$y/watch?v=$d"|sed -n 's/.*, "t": "\([^"]*\)", .
*/\1/p')";done
# Download file with multiple simultaneous connections
aria2c -s 4 http://my/url
# use curl to resume a failed download
cat file-that-failed-to-download.zip | curl -C - http://www.somewhere.com/file-I
-want-to-download.zip >successfully-downloaded.zip
#:690#
# commandlinefu.com by David Winterbottom
# use curl to resume a failed download
cat file-that-failed-to-download.zip | curl -C - http://www.somewhere.com/file-I
-want-to-download.zip >successfully-downloaded.zip
#:691#
# commandlinefu.com by David Winterbottom
# Sort your music
for file in *.mp3;do mkdir -p "$(mp3info -p "%a/%l" "$file")" && ln -s "$file" "
$(mp3info -p "%a/%l/%t.mp3" "$file")";done
#:692#
# commandlinefu.com by David Winterbottom
# Sort your music
for file in *.mp3;do mkdir -p "$(mp3info -p "%a/%l" "$file")" && ln -s "$file" "
$(mp3info -p "%a/%l/%t.mp3" "$file")";done
#:693#
# commandlinefu.com by David Winterbottom
# Sort your music
for file in *.mp3;do mkdir -p "$(mp3info -p "%a/%l" "$file")" && ln -s "$file" "
$(mp3info -p "%a/%l/%t.mp3" "$file")";done
#:694#
# commandlinefu.com by David Winterbottom
# Send email with one or more binary attachments
echo "Body goes here" | mutt -s "A subject" -a /path/to/file.tar.gz recipient@ex
ample.com
#:695#
# commandlinefu.com by David Winterbottom
# Send a local file via email
mpack -s "Backup: $file" "$file" email@id.com
# Send a local file via email
mutt your@email_address.com -s "Message Subject Here" -a attachment.jpg &1 | perl -ne 'm@.*port\s+([0-9]+)\s+\w+\s+(\S+)\s+\((
.+):.*@ && do { print "$2:$1\n\t$3\n"; $root = qx{grep DocumentRoot $3}; $root =
~ s/^\s+//; print "\t$root\n" };'
#:706#
# commandlinefu.com by David Winterbottom
# Simple read and write test with Iozone
iozone -s 2g -r 64 -i 0 -i 1 -t 1
# Testing reading speed with dd
sync; time `dd if=/dev/cciss/c0d1p1 of=/dev/null bs=1M count=10240`
# Testing writing speed with dd
sync; time `dd if=/dev/zero of=bigfile bs=1M count=2048 && sync`
# Compression formats Benchmark
for a in bzip2 lzma gzip;do echo -n>$a;for b in $(seq 0 256);do dd if=/dev/zero
of=$b.zero bs=$b count=1;c=$(date +%s%N);$a $b.zero;d=$(date +%s%N);total=$(echo
$d-$c|bc);echo $total>>$a;rm $b.zero *.bz2 *.lzma *.gz;done;done
# benchmark web server with apache benchmarking tool
ab -n 9000 -c 900 localhost:8080/index.php
#:707#
# commandlinefu.com by David Winterbottom
# Get your public ip
python -c "import socket; s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.
connect(('google.com', 80)); print s.getsockname()[0]"
# Display IP adress of the given interface in a most portable and reliable way.
That should works on many platforms.
x=IO::Interface::Simple; perl -e 'use '$x';' &>/dev/null || cpan -i "$x"; perl -
e 'use '$x'; my $ip='$x'->new($ARGV[0]); print $ip->address,$/;'
# Show local/public IP adresses with or without interface argument using a shell
function for Linux and MacOsX
MyIps(){ echo -e "local:\n$(ifconfig $1 | grep -oP 'inet (add?r:)?\K(\d{1,3}\.){
3}\d{1,3}')\n\npublic:\n$(curl -s sputnick-area.net/ip)"; }
# Return IP Address
perl -e '$_=`ifconfig eth0`;/\d+.\d+.\d+.\d+ /; print $&,"\n";'
# Return IP Address
ifconfig|while read i;do [[ $i =~ inet.*B ]]&&r=${i%%B*}&&echo ${r/*[tr]:/};done
# Show local IP
ifconfig eth0 | grep "inet:" | cut -d ":" -f2 | cut -d " " -f1
# Return IP Address
ifconfig -a| awk 'BEGIN{FS="[ :]+"} /Bcast/{print $4}'
# Return IP Address
ifconfig -a|grep Bcast:|cut -d\: -f2|awk '{print $1}'
# Return IP Address
ifconfig | awk '/inet /{sub(/^[^:]+:/,"",$2); print $2}'
# Return IP Address
/usr/sbin/ifconfig -a|awk -F" " 'NR==4{print $2}'
# Get your external IP address
curl ip.appspot.com
# regex to match an ip
echo 127.0.0.1 | egrep -e '^(([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-4])\.){3}([01]?[0
-9]{1,2}|2[0-4][0-9]|25[0-4])$'
# regex to match an ip
perl -wlne 'print $1 if /(([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25
[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5]))/' iplist
# regex to match an ip
echo 254.003.032.3 | grep -P '^((25[0-4]|2[0-4]\d|[01]?[\d]?[1-9])\.){3}(25[0-4]
|2[0-4]\d|[01]?[\d]?[1-9])$'
# regex to match an ip
echo "123.32.12.134" | grep -P '([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4
]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])'
# find all active IP addresses in a network
arp-scan -l
# find all active IP addresses in a network
nmap -sP 192.168.0.*
# Get internal and external IP addresses
ips(){ for if in ${1:-$(ip link list|grep '^.: '|cut -d\ -f2|cut -d: -f1)};do c
ur=$(ifconfig $if|grep "inet addr"|sed 's/.*inet addr:\([0-9\.]*\).*/\1/g');prin
tf '%-5s%-15s%-15s\n' $if $cur $(nc -s $cur sine.cluenet.org 128 2>/dev/null||ec
ho $cur);done;}
# Get own public IP address
wget -qO- whatismyip.org
#:708#
# commandlinefu.com by David Winterbottom
# Get a list of all your VirtualBox virtual machines by name and UUID from the s
hell
VBoxManage list vms
# run a VirtualBox virtual machine without a gui
VBoxHeadless -s
#:709#
# commandlinefu.com by David Winterbottom
# Save VM running as headless
VBoxManage controlvm ServidorProducao savestate
# Running VirtualBox as headless
nohup VBoxHeadless -p 3052 -startvm ServidorProducao &
# run a VirtualBox virtual machine without a gui
VBoxHeadless -s
#:710#
# commandlinefu.com by David Winterbottom
# Get a list of all your VirtualBox virtual machines by name and UUID from the s
hell
VBoxManage list vms
#:711#
# commandlinefu.com by David Winterbottom
# get time in other timezones
tzwatch
# get time in other timezones
tzwatch
# get time in other timezones
let utime=$offsetutc*3600+$(date --utc +%s)+3600; date --utc --date=@${utime}
#:712#
# commandlinefu.com by David Winterbottom
# floating point shell calculator
calc() { awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'; }
# floating point bash calculator w/o precision
b(){ echo "scale=${2:-2}; $1" | bc -l; }
# get time in other timezones
tzwatch
# get time in other timezones
tzwatch
# get time in other timezones
let utime=$offsetutc*3600+$(date --utc +%s)+3600; date --utc --date=@${utime}
#:713#
# commandlinefu.com by David Winterbottom
# get time in other timezones
tzwatch
# get time in other timezones
tzwatch
# get time in other timezones
let utime=$offsetutc*3600+$(date --utc +%s)+3600; date --utc --date=@${utime}
#:714#
# commandlinefu.com by David Winterbottom
# pipe commands from a textfile to a telnet-server with netcat
nc $telnetserver 23 < $commandfile
#:715#
# commandlinefu.com by David Winterbottom
# complete extraction of a debian-package
dpkg-deb -x $debfile $extractdir; dpkg-deb -e $debfile $extractdir/DEBIAN;
#:716#
# commandlinefu.com by David Winterbottom
# 32 bits or 64 bits?
getconf LONG_BIT
#:717#
# commandlinefu.com by David Winterbottom
# 32 bits or 64 bits?
sudo lshw -C cpu|grep width
# 32 bits or 64 bits?
getconf LONG_BIT
#:718#
# commandlinefu.com by David Winterbottom
# 32 bits or 64 bits?
sudo lshw -C cpu|grep width
# 32 bits or 64 bits?
getconf LONG_BIT
#:719#
# commandlinefu.com by David Winterbottom
# A fun thing to do with ram is actually open it up and take a peek. This comman
d will show you all the string (plain text) values in ram
sudo strings /dev/mem
# A fun thing to do with ram is actually open it up and take a peek. This comman
d will show you all the string (plain text) values in ram
strings /dev/mem|less
#:720#
# commandlinefu.com by David Winterbottom
# back up your commandlinefu contributed commands
curl http://www.commandlinefu.com/commands/by//rss|gzip ->command
linefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz
#:721#
# commandlinefu.com by David Winterbottom
# Output Detailed Process Tree for any User
psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
# Sort all running processes by their memory & CPU usage
ps aux --sort=%mem,%cpu
# get users process list
ps -u
# View Processeses like a fu, fu
pstree -p
# View Processeses like a fu, fu
command ps -Hacl -F S -A f
# Get a regular updated list of zombies
watch "ps auxw | grep [d]efunct"
# Get a regular updated list of zombies
watch "ps auxw | grep 'defunct' | grep -v 'grep' | grep -v 'watch'"
#:722#
# commandlinefu.com by David Winterbottom
# Get a regular updated list of zombies
watch "ps auxw | grep [d]efunct"
# Get a regular updated list of zombies
watch "ps auxw | grep 'defunct' | grep -v 'grep' | grep -v 'watch'"
#:723#
# commandlinefu.com by David Winterbottom
# Watch changeable interrupts continuously
watch -n1 'cat /proc/interrupts
# CPU model
cat /proc/cpuinfo
# detected hardware and boot messages
sudo dmesg
# get debian version number
lsb_release -a
# get kernel version
uname -a
# System load information alongside process information in a similar style to to
p.
atop
# detect the Super I/O chip on your computer, tell you at which configuration po
rt it is located and can dump all the register contents.
superiotool
# parses the BIOS memory and prints information about all structures (or entry p
oints) it knows of.
biosdecode
# x86info
x86info
# get basic information out of your computer
lspci
# On Mac OS X, runs System Profiler Report and e-mails it to specified address.
system_profiler | mail -s "$HOSTNAME System Profiler Report" user@domain.com
#:724#
# commandlinefu.com by David Winterbottom
# Preview of a picture in a terminal
img test.jpg
#:725#
# commandlinefu.com by David Winterbottom
# Download file with multiple simultaneous connections
aria2c -s 4 http://my/url
#:726#
# commandlinefu.com by David Winterbottom
# Download file with multiple simultaneous connections
aria2c -s 4 http://my/url
#:727#
# commandlinefu.com by David Winterbottom
# Click on a GUI window and show its process ID and command used to run the proc
ess
xprop | awk '/PID/ {print $3}' | xargs ps h -o pid,cmd
#:728#
# commandlinefu.com by David Winterbottom
# find only current directory (universal)
find . \( ! -name . -prune \) \( -type f -o -type l \)
#:729#
# commandlinefu.com by David Winterbottom
#:730#
# commandlinefu.com by David Winterbottom
# move a lot of files over ssh
rsync -az /home/user/test user@sshServer:/tmp/
# move a lot of files over ssh
tar -cf - /home/user/test | gzip -c | ssh user@sshServer 'cd /tmp; tar xfz -'
# Batch file name renaming (copying or moving) w/ glob matching.
for x in *.ex1; do mv "${x}" "${x%ex1}ex2"; done
#:731#
# commandlinefu.com by David Winterbottom
# Open in TextMate Sidebar files (recursively) with names matching REGEX_A and n
ot matching REGEX_B
mate - `find * -type f -regex 'REGEX_A' | grep -v -E 'REGEX_B'`
#:732#
# commandlinefu.com by David Winterbottom
# Set default "New Page" as HTML in TextMate
defaults write com.macromates.textmate OakDefaultLanguage 17994EC8-6B1D-11D9-AC3
A-000D93589AF6
# Open files of the same name in TextMate
mate - `find . -name 'filename'`
# Open in TextMate Sidebar files (recursively) with names matching REGEX_A and n
ot matching REGEX_B
mate - `find * -type f -regex 'REGEX_A' | grep -v -E 'REGEX_B'`
#:733#
# commandlinefu.com by David Winterbottom
# Open in TextMate Sidebar files (recursively) with names matching REGEX_A and n
ot matching REGEX_B
mate - `find * -type f -regex 'REGEX_A' | grep -v -E 'REGEX_B'`
#:734#
# commandlinefu.com by David Winterbottom
# Remove empty directories
rmdir **/*(/^F)
# Remove empty directories
find . -type d -empty -delete
#:735#
# commandlinefu.com by David Winterbottom
# Checking total connections to each Ip inserver
netstat -alpn | grep :80 | awk '{print $4}' |awk -F: '{print $(NF-1)}' |sort |
uniq -c | sort -n
#:736#
# commandlinefu.com by David Winterbottom
# print latest (top 10, top 3 or *) commandlinefu.com commands
wget -qO - http://www.commandlinefu.com/feed/tenup | xmlstarlet sel -T -t -o '&l
t;x>' -n -t -m rss/channel/item -o '<y>' -n -v description -o '</y&g
t;' -n -t -o '</x>' | xmlstarlet sel -T -t -m x/y -v code -n
#:737#
# commandlinefu.com by David Winterbottom
# Go get those photos from a Picasa album
wget 'link of a Picasa WebAlbum' -O - |perl -e'while(<>){while(s/"media":{"conte
nt":\[{"url":"(.+?\.JPG)//){print "$1\n"}}' |wget -w1 -i -
# Go get those photos from a Picasa album
echo 'Enter Picasa album RSS URL:"; read -e feedurl; GET "$feedurl" |sed 's/\n
wgetli
st
# Check your unread Gmail from the command line
curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'p
rint "\t" if //; print "$2\n" if /<(title|name)>(.*)<\/\1>/;'
# Check your unread Gmail from the command line
curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr
-d '\n' | awk -F '' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
# print latest (top 10, top 3 or *) commandlinefu.com commands
wget -qO - http://www.commandlinefu.com/feed/tenup | xmlstarlet sel -T -t -o '&l
t;x>' -n -t -m rss/channel/item -o '<y>' -n -v description -o '</y&g
t;' -n -t -o '</x>' | xmlstarlet sel -T -t -m x/y -v code -n
#:738#
# commandlinefu.com by David Winterbottom
# Add
rename 's/^/prefix/' *
#:739#
# commandlinefu.com by David Winterbottom
# Will email user@example.com when all Rsync processes have finished.
$(while [ ! -z "$(pgrep rsync)" ]; do echo; done; echo "rsync done" | mailx user
@example.com) > /dev/null &
#:740#
# commandlinefu.com by David Winterbottom
# monitor network traffic and throughput in real time
iptraf
# Grab an interface's IP from ifconfig without screen clutter
ifconfig eth1 | grep inet\ addr | awk '{print $2}' | cut -d: -f2 | sed s/^/eth1:
\ /g
# retrieve the source address used to contact a given host
python -c 'import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
; s.connect(("", )); print s.getsockname()[0] ; s.close() ;' 2>
/dev/null
# List open TCP/UDP ports
netstat -ltun
# Get ethernet card information.
ethtool eth0
# checks if host /service is up on a host that doesn't respond to ping
while true; do clear; nmap ${hostname} -PN -p ${hostport}; sleep 5; done
#:741#
# commandlinefu.com by David Winterbottom
# amixer : raise volume and unmute if necessary
amixer -c 0 set Master 1+ unmute
#:742#
# commandlinefu.com by David Winterbottom
# Normalize volume in your mp3 library
find . -type d -exec sh -c "normalize-audio -b \"{}\"/*.mp3" \;
# amixer : raise volume and unmute if necessary
amixer -c 0 set Master 1+ unmute
#:743#
# commandlinefu.com by David Winterbottom
# avi to ogv (Ogg Theora)
ffmpeg2theora input.avi
#:744#
# commandlinefu.com by David Winterbottom
# Unarchive entire folder
for f in *;do case "$(echo $f|sed "s/.*\.\([a-z\.]*\)/\1/g")" in zip)unzip -qqo
$f&&rm $f;;tar.gz|tar.bz2)tar xf $f&&rm $f;;rar)unrar e -o+ -r -y $f&&rm $f;;7z)
7z e -qqo $f;;esac;done
#:745#
# commandlinefu.com by David Winterbottom
# Unarchive entire folder
for f in *;do case "$(echo $f|sed "s/.*\.\([a-z\.]*\)/\1/g")" in zip)unzip -qqo
$f&&rm $f;;tar.gz|tar.bz2)tar xf $f&&rm $f;;rar)unrar e -o+ -r -y $f&&rm $f;;7z)
7z e -qqo $f;;esac;done
#:746#
# commandlinefu.com by David Winterbottom
# 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
#:747#
# commandlinefu.com by David Winterbottom
# Create Encrypted WordPress MySQL Backup without any DB details, just the wp-co
nfig.php
eval $(sed -e "s/^d[^D]*DB_\([NUPH]\).*',[^']*'\([^']*\)'.*/_\1='\2';/" -e "/^_/
!d" wp-config.php) && mysqldump --opt --add-drop-table -u$_U -p$_P -h$_H $_N | g
pg -er AskApache >`date +%m%d%y-%H%M.$_N.sqls`
#:748#
# commandlinefu.com by David Winterbottom
# Create Encrypted WordPress MySQL Backup without any DB details, just the wp-co
nfig.php
eval $(sed -e "s/^d[^D]*DB_\([NUPH]\).*',[^']*'\([^']*\)'.*/_\1='\2';/" -e "/^_/
!d" wp-config.php) && mysqldump --opt --add-drop-table -u$_U -p$_P -h$_H $_N | g
pg -er AskApache >`date +%m%d%y-%H%M.$_N.sqls`
#:749#
# commandlinefu.com by David Winterbottom
# backup local MySQL database into a folder and removes older then 5 days backup
s
mysqldump -uUSERNAME -pPASSWORD database | gzip > /path/to/db/files/db-backup-`d
ate +%Y-%m-%d`.sql.gz ;find /path/to/db/files/* -mtime +5 -exec rm {} \;
# Get a MySQL DB dump from a remote machine
ssh user@host "mysqldump -h localhost -u mysqluser -pP@$$W3rD databasename | gzi
p -cf" | gunzip -c > database.sql
# Backup all MySQL Databases to individual files
mysql -e 'show databases' | sed -n '2,$p' | xargs -I DB 'mysqldump DB > DB.sql'
# Create Encrypted WordPress MySQL Backup without any DB details, just the wp-co
nfig.php
eval $(sed -e "s/^d[^D]*DB_\([NUPH]\).*',[^']*'\([^']*\)'.*/_\1='\2';/" -e "/^_/
!d" wp-config.php) && mysqldump --opt --add-drop-table -u$_U -p$_P -h$_H $_N | g
pg -er AskApache >`date +%m%d%y-%H%M.$_N.sqls`
#:750#
# commandlinefu.com by David Winterbottom
# Create Encrypted WordPress MySQL Backup without any DB details, just the wp-co
nfig.php
eval $(sed -e "s/^d[^D]*DB_\([NUPH]\).*',[^']*'\([^']*\)'.*/_\1='\2';/" -e "/^_/
!d" wp-config.php) && mysqldump --opt --add-drop-table -u$_U -p$_P -h$_H $_N | g
pg -er AskApache >`date +%m%d%y-%H%M.$_N.sqls`
#:751#
# commandlinefu.com by David Winterbottom
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
# Schedule a script or command in x num hours, silently run in the background ev
en if logged out
echo "nohup command rm -rf /phpsessions 1>&2 &>/dev/null 1>&2 &>/dev/null&" | at
now + 3 hours 1>&2 &>/dev/null
# Silently Execute a Shell Script that runs in the background and won't die on H
UP/logout
nohup /bin/sh myscript.sh 1>&2 &>/dev/null 1>&2 &>/dev/null&
#:752#
# commandlinefu.com by David Winterbottom
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
# Silently Execute a Shell Script that runs in the background and won't die on H
UP/logout
nohup /bin/sh myscript.sh 1>&2 &>/dev/null 1>&2 &>/dev/null&
#:753#
# commandlinefu.com by David Winterbottom
# FAST and NICE Search and Replace for Strings in Files
nice -n19 sh -c 'S=askapache && R=htaccess; find . -type f|xargs -P5 -iFF grep -
l -m1 "$S" FF|xargs -P5 -iFF sed -i -e s%${S}%${R}% FF'
# Function that outputs dots every second until command completes
sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; do
ne; }; export -f sleeper
# Schedule a script or command in x num hours, silently run in the background ev
en if logged out
( ( sleep 2h; your-command your-args ) & )
# Schedule a script or command in x num hours, silently run in the background ev
en if logged out
echo "nohup command rm -rf /phpsessions 1>&2 &>/dev/null 1>&2 &>/dev/null&" | at
now + 3 hours 1>&2 &>/dev/null
# Silently Execute a Shell Script that runs in the background and won't die on H
UP/logout
nohup /bin/sh myscript.sh 1>&2 &>/dev/null 1>&2 &>/dev/null&
#:754#
# commandlinefu.com by David Winterbottom
# Silently Execute a Shell Script that runs in the background and won't die on H
UP/logout
nohup /bin/sh myscript.sh 1>&2 &>/dev/null 1>&2 &>/dev/null&
#:755#
# commandlinefu.com by David Winterbottom
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
# power off system in X hours form the current time, here X=2
echo init 0 | at now + 2 hours
# Schedule a script or command in x num hours, silently run in the background ev
en if logged out
echo "nohup command rm -rf /phpsessions 1>&2 &>/dev/null 1>&2 &>/dev/null&" | at
now + 3 hours 1>&2 &>/dev/null
#:756#
# commandlinefu.com by David Winterbottom
# Read aloud a text file in Ubuntu (and other Unixes with espeak installed
espeak -f text.txt
#:757#
# commandlinefu.com by David Winterbottom
# Read aloud a text file in Ubuntu (and other Unixes with espeak installed
espeak -f text.txt
#:758#
# commandlinefu.com by David Winterbottom
# 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
# Search commandlinefu.com from the command line using the API
cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ |
openssl base64)/plaintext"; }
#:759#
# commandlinefu.com by David Winterbottom
# (Git) Revert files with changed mode, not content
git diff --numstat | awk '{if ($1 == "0" && $1 == "0") print $3}' | xargs git c
heckout HEAD
# Show changed files, ignoring permission, date and whitespace changes
git diff --numstat -w --no-abbrev | perl -a -ne '$F[0] != 0 && $F[1] !=0 && prin
t $F[2] . "\n";'
#:760#
# commandlinefu.com by David Winterbottom
# View Processeses like a fu, fu
pstree -p
# View Processeses like a fu, fu
command ps -Hacl -F S -A f
#:761#
# commandlinefu.com by David Winterbottom
# View Processeses like a fu, fu
pstree -p
# View Processeses like a fu, fu
command ps -Hacl -F S -A f
#:762#
# commandlinefu.com by David Winterbottom
# Pipe stdout and stderr, etc., to separate commands
some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr)
# Multiple Timed Execution of subshells sleeping in the background using job con
trol and sleep.
S=$SSH_TTY && (sleep 3 && echo -n 'Peace... '>$S & ) && (sleep 5 && echo -n 'Lov
e... '>$S & ) && (sleep 7 && echo 'and Intergalactic Happiness!'>$S & )
#:763#
# commandlinefu.com by David Winterbottom
# Start xterm in given directory
( cd /my/directory; xterm& )
# Multiple Timed Execution of subshells sleeping in the background using job con
trol and sleep.
S=$SSH_TTY && (sleep 3 && echo -n 'Peace... '>$S & ) && (sleep 5 && echo -n 'Lov
e... '>$S & ) && (sleep 7 && echo 'and Intergalactic Happiness!'>$S & )
#:764#
# commandlinefu.com by David Winterbottom
# Function that outputs dots every second until command completes
sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; do
ne; }; export -f sleeper
# Multiple Timed Execution of subshells sleeping in the background using job con
trol and sleep.
S=$SSH_TTY && (sleep 3 && echo -n 'Peace... '>$S & ) && (sleep 5 && echo -n 'Lov
e... '>$S & ) && (sleep 7 && echo 'and Intergalactic Happiness!'>$S & )
#:765#
# commandlinefu.com by David Winterbottom
# Connect to SMTP server using STARTTLS
openssl s_client -starttls smtp -crlf -connect 127.0.0.1:25
#:766#
# commandlinefu.com by David Winterbottom
# Use curl on Windows to bulk-download the Savitabhabhi Comic Strip (for Adults)
for /L %%x in (1,1,16) do mkdir %%x & curl -R -e http://www.kirtu.com -o %%x/#1.
jpg http://www.kirtu.com/toon/content/sb%x/english/sb%x_en_[001-070].jpg
# Remove ^M characters at end of lines in vi
:%s/^V^M//g
#:767#
# commandlinefu.com by David Winterbottom
# Remove ^M characters at end of lines in vi
:%s/^V^M//g
#:768#
# commandlinefu.com by David Winterbottom
# Save iptables firewall info
sudo iptables-save > /etc/iptables.up.rules
#:769#
# commandlinefu.com by David Winterbottom
# replace old htaccess php AddHandler values with new one
find /var/www/ -type f -name ".htaccess" -exec perl -pi -e 's/AddHandler[\s]*php
(4|5)-cgi/AddHandler x-httpd-php\1/' {} \;
#:770#
# commandlinefu.com by David Winterbottom
# replace old htaccess php AddHandler values with new one
find /var/www/ -type f -name ".htaccess" -exec perl -pi -e 's/AddHandler[\s]*php
(4|5)-cgi/AddHandler x-httpd-php\1/' {} \;
#:771#
# commandlinefu.com by David Winterbottom
# floating point shell calculator
calc() { awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'; }
# floating point bash calculator w/o precision
b(){ echo "scale=${2:-2}; $1" | bc -l; }
# floating point operations in shell scripts
echo $((3.0/5.0))
# floating point operations in shell scripts
echo "5 k 3 5 / p" | dc
# floating point operations in shell scripts
bc -l <<< s(3/5)
# floating point operations in shell scripts
echo "scale=4; 3 / 5" | bc
#:772#
# commandlinefu.com by David Winterbottom
# purge old stale messages on a qmail queue
for i in `grep "unable to stat" /var/log/syslog | cut -d "/" -f 3 | sort | uniq`
; do find /var/qmail/queue -name $i -type f -exec rm -v {} \; ; done
#:773#
# commandlinefu.com by David Winterbottom
# Incase you miss the famous 'C:\>' prompt
export PS1='C:${PWD//\//\\\}>'
# Day Date Time> Instead of $ or # at the terminal
export PS1='\D{%a %D %T}> '
#:774#
# commandlinefu.com by David Winterbottom
# power off system in X hours form the current time, here X=2
echo init 0 | at now + 2 hours
#:775#
# commandlinefu.com by David Winterbottom
# List all groups and the user names that were in each group
for u in `cut -f1 -d: /etc/passwd`; do echo -n $u:; groups $u; done | sort
#:776#
# commandlinefu.com by David Winterbottom
# Show account security settings
chage -l
#:777#
# commandlinefu.com by David Winterbottom
# Ruby - nslookup against a list of IP`s or FQDN`s
while read n; do host $n; done < list
# Perform a reverse DNS lookup
dig -x 74.125.45.100
# DNS cache snooping
for i in `cat names.txt`; do host -r $i [nameserver]; done
#:778#
# commandlinefu.com by David Winterbottom
# Cleanup firefox's database.
find ~/Library/Application\ Support/Firefox/ -type f -name "*.sqlite" -exec sqli
te3 {} VACUUM \;
# Cleanup firefox's database.
find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
# 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)
#:779#
# commandlinefu.com by David Winterbottom
# Transfer sqlite3 data to mysql
sqlite3 mydb.sqlite3 '.dump' | grep -vE '^(BEGIN|COMMIT|CREATE|DELETE)|"sqlite_s
equence"' | sed -r 's/"([^"]+)"/`\1`/' | tee mydb.sql | mysql -p mydb
# Cleanup firefox's database.
find ~/Library/Application\ Support/Firefox/ -type f -name "*.sqlite" -exec sqli
te3 {} VACUUM \;
# Cleanup firefox's database.
find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
# 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)
#:780#
# commandlinefu.com by David Winterbottom
# watch iptables counters
watch --interval 0 'iptables -nvL | grep -v "0 0"'
#:781#
# commandlinefu.com by David Winterbottom
# Print a row of 50 hyphens
perl -le'print"-"x50'
# Print a row of 50 hyphens
jot -s '' -b '-' 50
# Print a random 8 digit number
jot -s '' -r -n 8 0 9
# Print a random 8 digit number
jot -r -n 8 0 9 | rs -g 0
#:782#
# commandlinefu.com by David Winterbottom
# Print a random 8 digit number
jot -s '' -r -n 8 0 9
# Print a random 8 digit number
jot -r -n 8 0 9 | rs -g 0
#:783#
# commandlinefu.com by David Winterbottom
# one-liner mpc track changer using dmenu
mpc play $(sed -n "s@^[ >]\([0-9]\+\)) $(mpc playlist|cut -d' ' -f3-|dmenu -i -p
'song name'||echo void)@\1@p" < <(mpc playlist))
# Download Youtube Playlist
y=http://www.youtube.com;for i in $(curl -s $f|grep -o "url='$y/watch?v=[^']*'")
;do d=$(echo $i|sed "s;url\='$y/watch?v=\(.*\)';\1;");wget -O $d.flv "$y/get_vid
eo.php?video_id=$d&t=$(curl -s "$y/watch?v=$d"|sed -n 's/.*, "t": "\([^"]*\)", .
*/\1/p')";done
#:784#
# commandlinefu.com by David Winterbottom
# Get number of diggs for a news URL
curl -s "http://services.digg.com/stories?link=$NEWSURL&appkey=http://www.whatev
er.com&type=json" | python -m simplejson.tool | grep diggs
#:785#
# commandlinefu.com by David Winterbottom
# Resolve the "all display buffers are busy, please try later" error on a Foundr
y
dm display-buffer reset
#:786#
# commandlinefu.com by David Winterbottom
# Resolve the "all display buffers are busy, please try later" error on a Foundr
y
dm display-buffer reset
#:787#
# commandlinefu.com by David Winterbottom
#:788#
# commandlinefu.com by David Winterbottom
# Download all the Super Mario World Hacks from smwcentral.net
smw=http://www.smwcentral.net;for f in $(curl -s "$smw/?p=hacks"|grep -o "downlo
ad.php?id=[0-9]*&type=hack"); do i=$(echo $f|sed "s/download.php?id=\([0-9]*
\)&type=hack/\1/");wget -O $i "$smw/download.php?id=$id&type=hack";unzip -qq
o $i;rm $i;done
#:789#
# commandlinefu.com by David Winterbottom
# convert unixtime to human-readable
perl -e 'print scalar(gmtime(1234567890)), "\n"'
# convert unixtime to human-readable
echo "0t${currentEpoch}=Y" | /usr/bin/adb
#:790#
# commandlinefu.com by David Winterbottom
# List all available commands (bash, ksh93)
printf "%s\n" ${PATH//:/\/* }
# List all available commands
in bash hit "tab" twice and answer y
# Get the absolute path of a file
absolute_path () { readlink -f "$1"; };
# Add the sbin directories to your PATH if it doesn't already exist in ZSH.
path+=( /sbin /usr/sbin /usr/local/sbin ); path=( ${(u)path} );
# Get absolut path to your bash-script
script_path=$(cd $(dirname $0);pwd)
# Show Directories in the PATH Which does NOT Exist
(IFS=:;for p in $PATH; do test -d $p || echo $p; done)
# Show only existing executable dirs in PATH using only builtin bash commands
for p in ${PATH//:/ }; do [[ -d $p && -x $p ]] && echo $p; done
# search for a file in PATH
type
# search for a file in PATH
which
# search for a file in PATH
for L in `echo :$PATH | tr : '\n'`; do F=${L:-"."}/fileName; if [ -f ${F} -o -h
${F} ]; then echo ${F}; break; fi; done
# search for a file in PATH
function sepath { echo $PATH |tr ":" "\n" |sort -u |while read L ; do cd "$L" 2>
/dev/null && find . \( ! -name . -prune \) \( -type f -o -type l \) 2>/dev/null
|sed "s@^\./@@" |egrep -i "${*}" |sed "s@^@$L/@" ; done ; }
# find files in $PATH that were not installed through dpkg
echo -e "${PATH//://\n}" >/tmp/allpath; grep -Fh -f /tmp/allpath /var/lib/dpkg/i
nfo/*.list|grep -vxh -f /tmp/allpath >/tmp/installedinpath ; find ${PATH//:/ } |
grep -Fxv -f /tmp/installedinpath
# Show directories in the PATH, one per line
echo src::${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~
/^\//{$1=pwd"/"$1}{print $1}'
# Show directories in the PATH, one per line
echo $PATH | tr \: \\n
# Show directories in the PATH, one per line
print -l $path
# Show directories in the PATH, one per line
echo "${PATH//:/$'\n'}"
#:791#
# commandlinefu.com by David Winterbottom
# Download all the Super Mario World Hacks from smwcentral.net
smw=http://www.smwcentral.net;for f in $(curl -s "$smw/?p=hacks"|grep -o "downlo
ad.php?id=[0-9]*&type=hack"); do i=$(echo $f|sed "s/download.php?id=\([0-9]*
\)&type=hack/\1/");wget -O $i "$smw/download.php?id=$id&type=hack";unzip -qq
o $i;rm $i;done
#:792#
# commandlinefu.com by David Winterbottom
# Download all the Super Mario World Hacks from smwcentral.net
smw=http://www.smwcentral.net;for f in $(curl -s "$smw/?p=hacks"|grep -o "downlo
ad.php?id=[0-9]*&type=hack"); do i=$(echo $f|sed "s/download.php?id=\([0-9]*
\)&type=hack/\1/");wget -O $i "$smw/download.php?id=$id&type=hack";unzip -qq
o $i;rm $i;done
#:793#
# commandlinefu.com by David Winterbottom
# Download all the Super Mario World Hacks from smwcentral.net
smw=http://www.smwcentral.net;for f in $(curl -s "$smw/?p=hacks"|grep -o "downlo
ad.php?id=[0-9]*&type=hack"); do i=$(echo $f|sed "s/download.php?id=\([0-9]*
\)&type=hack/\1/");wget -O $i "$smw/download.php?id=$id&type=hack";unzip -qq
o $i;rm $i;done
#:794#
# commandlinefu.com by David Winterbottom
# Download a TiVo Show
curl -s -c /tmp/cookie -k -u tivo:$MAK --digest "$(curl -s -c /tmp/cookie -k -u
tivo:$MAK --digest https://$tivo/nowplaying/index.html | sed 's;.*Download MPEG-PS.*;\1;' | sed 's|\&|\&|')" | tivodecode -m $MAK --
- > tivo.mpg
# Download all the Super Mario World Hacks from smwcentral.net
smw=http://www.smwcentral.net;for f in $(curl -s "$smw/?p=hacks"|grep -o "downlo
ad.php?id=[0-9]*&type=hack"); do i=$(echo $f|sed "s/download.php?id=\([0-9]*
\)&type=hack/\1/");wget -O $i "$smw/download.php?id=$id&type=hack";unzip -qq
o $i;rm $i;done
#:795#
# commandlinefu.com by David Winterbottom
# Unlock your KDE4.3 session remotely
qdbus org.kde.screenlocker /MainApplication quit
#:796#
# commandlinefu.com by David Winterbottom
# Unlock your KDE4.3 session remotely
qdbus org.kde.screenlocker /MainApplication quit
#:797#
# commandlinefu.com by David Winterbottom
# Unlock your KDE4.3 session remotely
qdbus org.kde.screenlocker /MainApplication quit
#:798#
# commandlinefu.com by David Winterbottom
#:799#
# commandlinefu.com by David Winterbottom
#:800#
# commandlinefu.com by David Winterbottom
# securely locate file and dir
slocate filename/dirname
#:801#
# commandlinefu.com by David Winterbottom
# google search
perl -e '$i=0;while($i<10){open(WGET,qq/|xargs lynx -dump/);printf WGET qq{http:
//www.google.com/search?q=site:g33kinfo.com&hl=en&start=$i&sa=N},$i+=10}'|grep '
\/\/g33kinfo.com\/'
# Seach google from the command line in Unofficial google shell
http://goosh.org
# how to run firefox in safe mode from command line
firefox --safe-mode
#:802#
# commandlinefu.com by David Winterbottom
# floating point operations in shell scripts
echo "5 k 3 5 / p" | dc
#:803#
# commandlinefu.com by David Winterbottom
# Add user to group on OS X 10.5
sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username
#:804#
# commandlinefu.com by David Winterbottom
# Change Title of Terminal Window to Verbose Info useful at Login
echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s
%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\
1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
# Add user to group on OS X 10.5
sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username
#:805#
# commandlinefu.com by David Winterbottom
# Chage default shell for all users [FreeBSD]
cd /usr/home && for i in *;do chsh -s bash $i;done
# Add user to group on OS X 10.5
sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username
#:806#
# commandlinefu.com by David Winterbottom
# Run a bash script in debug mode, show output and save it on a file
bash -x test.sh 2>&1 | tee out.test
#:807#
# commandlinefu.com by David Winterbottom
#:808#
# commandlinefu.com by David Winterbottom
# How to watch files
watch -d 'ls -l'
# How to know the total number of packages available
apt-cache stats
#:809#
# commandlinefu.com by David Winterbottom
# badblocks for floppy
/sbin/badblocks -v /dev/fd0 1440
#:810#
# commandlinefu.com by David Winterbottom
# Update Ping.fm status
curl -d api_key="$api_key" -d user_app_key="$user_app_key -d body="$body" -d pos
t_method="default" http://api.ping.fm/v1/user.post
#:811#
# commandlinefu.com by David Winterbottom
# Update Ping.fm status
curl -d api_key="$api_key" -d user_app_key="$user_app_key -d body="$body" -d pos
t_method="default" http://api.ping.fm/v1/user.post
#:812#
# commandlinefu.com by David Winterbottom
# Add another tty device using mknod command
sudo mknod /dev/ttyS4 c 4 68
#:813#
# commandlinefu.com by David Winterbottom
# Add another tty device using mknod command
sudo mknod /dev/ttyS4 c 4 68
#:814#
# commandlinefu.com by David Winterbottom
# Show display adapter, available drivers, and driver in use
lspci -v | perl -ne '/VGA/../^$/ and /VGA|Kern/ and print'
#:815#
# commandlinefu.com by David Winterbottom
# alias to close terminal with :q
alias ':q'='exit'
#:816#
# commandlinefu.com by David Winterbottom
# Put the machine to sleep after the download(wget) is done
while [ -n "`pgrep wget`" ]; do sleep 2 ;done; [ -e "/tmp/nosleep"] || echo mem
>/sys/power/state
#:817#
# commandlinefu.com by David Winterbottom
# Transfer sqlite3 data to mysql
sqlite3 mydb.sqlite3 '.dump' | grep -vE '^(BEGIN|COMMIT|CREATE|DELETE)|"sqlite_s
equence"' | sed -r 's/"([^"]+)"/`\1`/' | tee mydb.sql | mysql -p mydb
# Dump dvd from a different machine onto this one.
ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso
# Hexadecimal dump of a file, pipe, or anything
cat testfile | hexdump -C
#:818#
# commandlinefu.com by David Winterbottom
# Check your unread Gmail from the command line
curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'p
rint "\t" if //; print "$2\n" if /<(title|name)>(.*)<\/\1>/;'
# Check your unread Gmail from the command line
curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr
-d '\n' | awk -F '' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
#:819#
# commandlinefu.com by David Winterbottom
# Detect encoding of a text file
file -i
#:820#
# commandlinefu.com by David Winterbottom
# Easy and fast access to often executed commands that are very long and complex
.
some_very_long_and_complex_command # label
#:821#
# commandlinefu.com by David Winterbottom
# show current directory
xdg-open .
#:822#
# commandlinefu.com by David Winterbottom
# Search through files, ignoring .svn
ack -ai 'searchterm'
#:823#
# commandlinefu.com by David Winterbottom
# When need to compress the Zope Database
python fsrecovery.py -P 0 -f /Data.fs /Data.fs.packed
#:824#
# commandlinefu.com by David Winterbottom
#:825#
# commandlinefu.com by David Winterbottom
# search for a file in PATH
type
# search for a file in PATH
which
# search for a file in PATH
for L in `echo :$PATH | tr : '\n'`; do F=${L:-"."}/fileName; if [ -f ${F} -o -h
${F} ]; then echo ${F}; break; fi; done
#:826#
# commandlinefu.com by David Winterbottom
# Extract all urls from last firefox sessionstore used in a portable way.
perl -lne 'print for /url":"\K[^"]+/g' $(ls -t ~/.mozilla/firefox/*/sessionstore
.js | sed q)
# Perform sed substitution on all but the last line of input
sed -e "$ ! s/$/,/"
# Print text string vertically, one character per line.
echo "vertical text" | fold -1
# Print text string vertically, one character per line.
echo "vertical text" | grep -o '.'
#:827#
# commandlinefu.com by David Winterbottom
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 2)
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac copy -ovc l
avc -lavcopts vcodec=mpeg4 -vf scale=320:-2,expand=:240:::1 -ffourcc xvid -o out
put.avi dvd.avi
# Use heading subtitle file as watermark using mencoder
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -la
meopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1
-o output.avi input.flv
# Record audio and video from webcam using mencoder
mencoder tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0:fps=30:ou
tfmt=yuy2:forceaudio:alsa:adevice=hw.2,0 -ovc lavc -lavcopts vcodec=mpeg4:vbitra
te=1800 -ffourcc xvid -oac mp3lame -lameopts cbr=128 -o output.avi
# Record audio and video from webcam using ffmpeg
ffmpeg -f alsa -r 16000 -i hw:2,0 -f video4linux2 -s 800x600 -i /dev/video0 -r 3
0 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi
# FLV to AVI with subtitles and forcing audio sync using mencoder
mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=12
8 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv
#:828#
# commandlinefu.com by David Winterbottom
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 2)
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac copy -ovc l
avc -lavcopts vcodec=mpeg4 -vf scale=320:-2,expand=:240:::1 -ffourcc xvid -o out
put.avi dvd.avi
# Rip DVD to YouTube ready MPEG-4 AVI file using mencoder
mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourc
c xvid -vf scale=320:-2,expand=:240:::1 -o output.avi dvd://0
# Use heading subtitle file as watermark using mencoder
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -la
meopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1
-o output.avi input.flv
# Record audio and video from webcam using mencoder
mencoder tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0:fps=30:ou
tfmt=yuy2:forceaudio:alsa:adevice=hw.2,0 -ovc lavc -lavcopts vcodec=mpeg4:vbitra
te=1800 -ffourcc xvid -oac mp3lame -lameopts cbr=128 -o output.avi
# Record audio and video from webcam using ffmpeg
ffmpeg -f alsa -r 16000 -i hw:2,0 -f video4linux2 -s 800x600 -i /dev/video0 -r 3
0 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi
# FLV to AVI with subtitles and forcing audio sync using mencoder
mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=12
8 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv
#:829#
# commandlinefu.com by David Winterbottom
# Use heading subtitle file as watermark using mencoder
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -la
meopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1
-o output.avi input.flv
# FLV to AVI with subtitles and forcing audio sync using mencoder
mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=12
8 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv
#:830#
# commandlinefu.com by David Winterbottom
# find only current directory (universal)
find . \( ! -name . -prune \) \( -type f -o -type l \)
#:831#
# commandlinefu.com by David Winterbottom
# send echo to socket network
echo foo | netcat 192.168.1.2 25
# send echo to socket network
echo "foo" > /dev/tcp/192.168.1.2/25
#:832#
# commandlinefu.com by David Winterbottom
# Get the time from NIST.GOV
cat ", )); print s.getsockname()[0] ; s.close() ;' 2>
/dev/null
# send echo to socket network
echo foo | netcat 192.168.1.2 25
# send echo to socket network
echo "foo" > /dev/tcp/192.168.1.2/25
#:833#
# commandlinefu.com by David Winterbottom
# send echo to socket network
echo foo | netcat 192.168.1.2 25
# send echo to socket network
echo "foo" > /dev/tcp/192.168.1.2/25
#:834#
# commandlinefu.com by David Winterbottom
# send echo to socket network
echo foo | netcat 192.168.1.2 25
# send echo to socket network
echo "foo" > /dev/tcp/192.168.1.2/25
#:835#
# commandlinefu.com by David Winterbottom
# retrieve the source address used to contact a given host
python -c 'import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
; s.connect(("", )); print s.getsockname()[0] ; s.close() ;' 2>
/dev/null
# send echo to socket network
echo foo | netcat 192.168.1.2 25
# send echo to socket network
echo "foo" > /dev/tcp/192.168.1.2/25
#:836#
# commandlinefu.com by David Winterbottom
# preprocess code to be posted in comments on this site
sed 's/^/$ /' "$script" | xclip
#:837#
# commandlinefu.com by David Winterbottom
# Extract audio from Mythtv recording to Rockbox iPod using ffmpeg
ffmpeg -ss 0:58:15 -i DavidLettermanBlackCrowes.mpg -acodec copy DavidLettermanB
lackCrowes.ac3
#:838#
# commandlinefu.com by David Winterbottom
# Find iPod's fwguid
lsusb -v | grep -o "[0-9A-Z]{16}"
# Extract audio from Mythtv recording to Rockbox iPod using ffmpeg
ffmpeg -ss 0:58:15 -i DavidLettermanBlackCrowes.mpg -acodec copy DavidLettermanB
lackCrowes.ac3
#:839#
# commandlinefu.com by David Winterbottom
# Extract audio from Mythtv recording to Rockbox iPod using ffmpeg
ffmpeg -ss 0:58:15 -i DavidLettermanBlackCrowes.mpg -acodec copy DavidLettermanB
lackCrowes.ac3
#:840#
# commandlinefu.com by David Winterbottom
# View the newest xkcd comic.
wget `lynx --dump http://xkcd.com/|grep png`
# View the newest xkcd comic.
curl -s 'xkcd.com' | awk -F\" '/^\n\n
\n %s\n %s\n %s\n\
n\n", $6, $4, $2)}'
# View the newest xkcd comic.
lynx --dump --source http://www.xkcd.com | grep `lynx --dump http://www.xkcd.com
| egrep '(png|jpg)'` | grep title | cut -d = -f2,3 | cut -d '"' -f2,4 | sed -e
's/"/|/g' | awk -F"|" ' { system("display " $1);system("echo "$2); } '
# View the newest xkcd comic.
xkcd(){ local f=$(curl -s http://xkcd.com/);display $(echo "$f"|grep -Po '(?<=")
http://imgs.xkcd.com/comics/[^"]+(png|jpg)');echo "$f"|awk '//dev/null &&
trap 1 ) & )
# Show only existing executable dirs in PATH using only builtin bash commands
for p in ${PATH//:/ }; do [[ -d $p && -x $p ]] && echo $p; done
#:848#
# commandlinefu.com by David Winterbottom
# Change Title of Terminal Window to Verbose Info useful at Login
echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s
%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\
1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
#:849#
# commandlinefu.com by David Winterbottom
# Change Title of Terminal Window to Verbose Info useful at Login
echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s
%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\
1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
#:850#
# commandlinefu.com by David Winterbottom
# Change Title of Terminal Window to Verbose Info useful at Login
echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s
%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\
1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
#:851#
# commandlinefu.com by David Winterbottom
# Change Title of Terminal Window to Verbose Info useful at Login
echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s
%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\
1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
#:852#
# commandlinefu.com by David Winterbottom
# Output Detailed Process Tree for any User
psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
# Change Title of Terminal Window to Verbose Info useful at Login
echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s
%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\
1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
#:853#
# commandlinefu.com by David Winterbottom
# Change Title of Terminal Window to Verbose Info useful at Login
echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s
%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\
1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
#:854#
# commandlinefu.com by David Winterbottom
# Change Title of Terminal Window to Verbose Info useful at Login
echo -ne "\033]0;`id -un`:`id -gn`@`hostname||uname -n|sed 1q` `who -m|sed -e "s
%^.* \(pts/[0-9]*\).*(\(.*\))%[\1] (\2)%g"` [`uptime|sed -e "s/.*: \([^,]*\).*/\
1/" -e "s/ //g"` / `ps aux|wc -l`]\007"
#:855#
# commandlinefu.com by David Winterbottom
# 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 &
#:856#
# commandlinefu.com by David Winterbottom
# 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 &
#:857#
# commandlinefu.com by David Winterbottom
# Track X Window events in chosen window
xev -id `xwininfo | grep 'Window id' | awk '{print $4}'`
#:858#
# commandlinefu.com by David Winterbottom
# Track X Window events in chosen window
xev -id `xwininfo | grep 'Window id' | awk '{print $4}'`
#:859#
# commandlinefu.com by David Winterbottom
# Show apps that use internet connection at the moment. (Multi-Language)
ss -p
#:860#
# commandlinefu.com by David Winterbottom
# View a sopcast stream
(sp-sc sop://broker.sopcast.com:3912/6002 3900 8900 &>/dev/null &); sleep 10; mp
layer http://localhost:8900/tv.asf
#:861#
# commandlinefu.com by David Winterbottom
# View a sopcast stream
(sp-sc sop://broker.sopcast.com:3912/6002 3900 8900 &>/dev/null &); sleep 10; mp
layer http://localhost:8900/tv.asf
#:862#
# commandlinefu.com by David Winterbottom
# Adding Color Escape Codes to global CC array for use by echo -e
declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$
ii]="\033[0;3${i}m"; done
#:863#
# commandlinefu.com by David Winterbottom
# 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;d
one
# Remove color codes (special characters) with sed
sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g
# Adding Color Escape Codes to global CC array for use by echo -e
declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$
ii]="\033[0;3${i}m"; done
#:864#
# commandlinefu.com by David Winterbottom
# 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;d
one
# Remove color codes (special characters) with sed
sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g
# Adding Color Escape Codes to global CC array for use by echo -e
declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$
ii]="\033[0;3${i}m"; done
#:865#
# commandlinefu.com by David Winterbottom
# 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;d
one
# Adding Color Escape Codes to global CC array for use by echo -e
declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$
ii]="\033[0;3${i}m"; done
#:866#
# commandlinefu.com by David Winterbottom
# Clean your broken terminal
stty sane
# Adding Color Escape Codes to global CC array for use by echo -e
declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$
ii]="\033[0;3${i}m"; done
#:867#
# commandlinefu.com by David Winterbottom
# Adding Color Escape Codes to global CC array for use by echo -e
declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$
ii]="\033[0;3${i}m"; done
#:868#
# commandlinefu.com by David Winterbottom
# Function that outputs dots every second until command completes
sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; do
ne; }; export -f sleeper
#:869#
# commandlinefu.com by David Winterbottom
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 2)
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac copy -ovc l
avc -lavcopts vcodec=mpeg4 -vf scale=320:-2,expand=:240:::1 -ffourcc xvid -o out
put.avi dvd.avi
# Use heading subtitle file as watermark using mencoder
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -la
meopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1
-o output.avi input.flv
# FLV to AVI with subtitles and forcing audio sync using mencoder
mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=12
8 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv
#:870#
# commandlinefu.com by David Winterbottom
# Use heading subtitle file as watermark using mencoder
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -la
meopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1
-o output.avi input.flv
#:871#
# commandlinefu.com by David Winterbottom
# List all text files (exclude binary files)
find . -type f -exec file {} \; | grep ".*: .* text" | cut -f 1 -d :
# List all text files (exclude binary files)
find . | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;"
#:872#
# commandlinefu.com by David Winterbottom
# Go get those photos from a Picasa album
wget 'link of a Picasa WebAlbum' -O - |perl -e'while(<>){while(s/"media":{"conte
nt":\[{"url":"(.+?\.JPG)//){print "$1\n"}}' |wget -w1 -i -
# Go get those photos from a Picasa album
echo 'Enter Picasa album RSS URL:"; read -e feedurl; GET "$feedurl" |sed 's/\n
wgetli
st
#:873#
# commandlinefu.com by David Winterbottom
# Convert mp3/wav file to asterisk ulaw for music on hold (moh)
sox -v 0.125 -V -t au -r 8000 -U -b -c 1 resample -ql
#:874#
# commandlinefu.com by David Winterbottom
# Convert mp3/wav file to asterisk ulaw for music on hold (moh)
sox -v 0.125 -V -t au -r 8000 -U -b -c 1 resample -ql
#:875#
# commandlinefu.com by David Winterbottom
# Execute a command with a timeout
timeout 10 sleep 11
#:876#
# commandlinefu.com by David Winterbottom
# Show current pathname in title of terminal
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007";'
#:877#
# commandlinefu.com by David Winterbottom
# dolphins on the desktop (compiz)
xwinwrap -ni -argb -fs -s -st -sp -nf -b -- /usr/libexec/xscreensaver/atlantis -
count 20 -window-id WID &
#:878#
# commandlinefu.com by David Winterbottom
# Quick command line math
expr 512 \* 7
#:879#
# commandlinefu.com by David Winterbottom
# Quick command line math
expr 512 \* 7
#:880#
# commandlinefu.com by David Winterbottom
# 32 bits or 64 bits?
sudo lshw -C cpu|grep width
#:881#
# commandlinefu.com by David Winterbottom
# Use colordiff in side-by-side mode, and with automatic column widths.
colordiff -yW"`tput cols`" /path/to/file1 /path/to/file2
# svn diff $* | colordiff | lv -c
svn diff $* | colordiff | lv -c
#:882#
# commandlinefu.com by David Winterbottom
# svn diff $* | colordiff | lv -c
svn diff $* | colordiff | lv -c
#:883#
# commandlinefu.com by David Winterbottom
# 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
#:884#
# commandlinefu.com by David Winterbottom
# 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
#:885#
# commandlinefu.com by David Winterbottom
# 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
#:886#
# commandlinefu.com by David Winterbottom
# List Network Tools in Linux
apropos network |more
#:887#
# commandlinefu.com by David Winterbottom
# List Network Tools in Linux
apropos network |more
#:888#
# commandlinefu.com by David Winterbottom
# Get all members from one AD group and put them in another AD group
for /F "DELIMS=""" %i in ('dsquery group -name SourceGroupName ^| dsget group -m
embers') do dsquery group -name TargetGroupName | dsmod group -addmbr %i
#:889#
# commandlinefu.com by David Winterbottom
# Create a single-use TCP proxy with debug output to stderr
socat -v tcp4-l: tcp4::
#:890#
# commandlinefu.com by David Winterbottom
# Compression formats Benchmark
for a in bzip2 lzma gzip;do echo -n>$a;for b in $(seq 0 256);do dd if=/dev/zero
of=$b.zero bs=$b count=1;c=$(date +%s%N);$a $b.zero;d=$(date +%s%N);total=$(echo
$d-$c|bc);echo $total>>$a;rm $b.zero *.bz2 *.lzma *.gz;done;done
# Log a command's votes
while true; do curl -s http://www.commandlinefu.com/commands/view/3643/log-a-com
mands-votes | grep 'id="num-votes-' | sed 's;.*id="num-votes-[0-9]*">\([0-9\-]*\
);\1;' >> votes; sleep 10; done
#:891#
# commandlinefu.com by David Winterbottom
# Log a command's votes
while true; do curl -s http://www.commandlinefu.com/commands/view/3643/log-a-com
mands-votes | grep 'id="num-votes-' | sed 's;.*id="num-votes-[0-9]*">\([0-9\-]*\
);\1;' >> votes; sleep 10; done
#:892#
# commandlinefu.com by David Winterbottom
# Watch a TiVo File On Your Computer
curl -s -c /tmp/cookie -k -u tivo:$MAK --digest http://$tivo/download/$filename
| tivodecode -m $MAK -- - | mplayer - -cache-min 50 -cache 65536
# Download a TiVo Show
curl -s -c /tmp/cookie -k -u tivo:$MAK --digest "$(curl -s -c /tmp/cookie -k -u
tivo:$MAK --digest https://$tivo/nowplaying/index.html | sed 's;.*Download MPEG-PS.*;\1;' | sed 's|\&|\&|')" | tivodecode -m $MAK --
- > tivo.mpg
#:893#
# commandlinefu.com by David Winterbottom
# Download a TiVo Show
curl -s -c /tmp/cookie -k -u tivo:$MAK --digest "$(curl -s -c /tmp/cookie -k -u
tivo:$MAK --digest https://$tivo/nowplaying/index.html | sed 's;.*Download MPEG-PS.*;\1;' | sed 's|\&|\&|')" | tivodecode -m $MAK --
- > tivo.mpg
#:894#
# commandlinefu.com by David Winterbottom
# Download a TiVo Show
curl -s -c /tmp/cookie -k -u tivo:$MAK --digest "$(curl -s -c /tmp/cookie -k -u
tivo:$MAK --digest https://$tivo/nowplaying/index.html | sed 's;.*Download MPEG-PS.*;\1;' | sed 's|\&|\&|')" | tivodecode -m $MAK --
- > tivo.mpg
#:895#
# commandlinefu.com by David Winterbottom
# Install a LAMP server in a Debian based distribution
sudo tasksel install lamp-server
#:896#
# commandlinefu.com by David Winterbottom
# Install a LAMP server in a Debian based distribution
sudo tasksel install lamp-server
#:897#
# commandlinefu.com by David Winterbottom
# Install a LAMP server in a Debian based distribution
sudo tasksel install lamp-server
#:898#
# commandlinefu.com by David Winterbottom
#:899#
# commandlinefu.com by David Winterbottom
# Change user, assume environment, stay in current dir
su -- user
#:900#
# commandlinefu.com by David Winterbottom
# Perform a reverse DNS lookup
dig -x 74.125.45.100
#:901#
# commandlinefu.com by David Winterbottom
# Perform a reverse DNS lookup
dig -x 74.125.45.100
#:902#
# commandlinefu.com by David Winterbottom
# Open your application to a specific size and location
command -geometry 120x30+1280+0
#:903#
# commandlinefu.com by David Winterbottom
# 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 && dhcli
ent
#:904#
# commandlinefu.com by David Winterbottom
# most dangerous command ever.
# hdparm -mRuUwx --dco-restore --drq-hsm-error --fwdownload --security-unlock PW
D --security-set-pass PWD --security-disable PWD --security-erase PWD --security
-erase-enhanced PWD --user-master USER --security-mode MODE [device]
# Securely destroy data on given device
# for i in $(seq 1 25); do dd if=/dev/urandom of= bs=1M ; done
#:905#
# commandlinefu.com by David Winterbottom
# Clean up poorly named TV shows.
rename -v 's/.*[s,S](\d{2}).*[e,E](\d{2}).*\.avi/SHOWNAME\ S$1E$2.avi/' poorly.n
amed.file.s01e01.avi
#:906#
# commandlinefu.com by David Winterbottom
# change newlines to spaces (or commas or whatever). Acts as a filter or can hav
e c/l args
alias nl2space="perl -ne 'push @F, \$_; END { chomp @F; print join(qq{ }, @F) ,
qq{\n};}' "
#:907#
# commandlinefu.com by David Winterbottom
# Show bash's function definitions you defined in .bash_profile or .bashrc
declare -f [ function_name ]
# change newlines to spaces (or commas or whatever). Acts as a filter or can hav
e c/l args
alias nl2space="perl -ne 'push @F, \$_; END { chomp @F; print join(qq{ }, @F) ,
qq{\n};}' "
#:908#
# commandlinefu.com by David Winterbottom
# change newlines to spaces (or commas or whatever). Acts as a filter or can hav
e c/l args
alias nl2space="perl -ne 'push @F, \$_; END { chomp @F; print join(qq{ }, @F) ,
qq{\n};}' "
#:909#
# commandlinefu.com by David Winterbottom
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
# FAST and NICE Search and Replace for Strings in Files
nice -n19 sh -c 'S=askapache && R=htaccess; find . -type f|xargs -P5 -iFF grep -
l -m1 "$S" FF|xargs -P5 -iFF sed -i -e s%${S}%${R}% FF'
#:910#
# commandlinefu.com by David Winterbottom
# Perform sed substitution on all but the last line of input
sed -e "$ ! s/$/,/"
# FAST and NICE Search and Replace for Strings in Files
nice -n19 sh -c 'S=askapache && R=htaccess; find . -type f|xargs -P5 -iFF grep -
l -m1 "$S" FF|xargs -P5 -iFF sed -i -e s%${S}%${R}% FF'
#:911#
# commandlinefu.com by David Winterbottom
# FAST and NICE Search and Replace for Strings in Files
nice -n19 sh -c 'S=askapache && R=htaccess; find . -type f|xargs -P5 -iFF grep -
l -m1 "$S" FF|xargs -P5 -iFF sed -i -e s%${S}%${R}% FF'
#:912#
# commandlinefu.com by David Winterbottom
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
# FAST and NICE Search and Replace for Strings in Files
nice -n19 sh -c 'S=askapache && R=htaccess; find . -type f|xargs -P5 -iFF grep -
l -m1 "$S" FF|xargs -P5 -iFF sed -i -e s%${S}%${R}% FF'
#:913#
# commandlinefu.com by David Winterbottom
# Encrypted archive with openssl and tar
openssl des3 -salt -in unencrypted-data.tar -out encrypted-data.tar.des3
#:914#
# commandlinefu.com by David Winterbottom
# Changing the terminal title to the last shell command
[[ "x$TERM" == "xrxvt" || "x$XTERM_VERSION" == xXTerm* || "x$COLORTERM" == 'gnom
e-terminal' && "x$SHELL" == */bin/zsh ]] && preexec () { print -Pn "\e]0;$1\a" }
# Changing the terminal title to the last shell command
if [ "$SHELL" = '/bin/zsh' ]; then case $TERM in rxvt|*term|linux) preexec () {
print -Pn "\e]0;$1\a" };; esac; fi
#:915#
# commandlinefu.com by David Winterbottom
# Changing the terminal title to the last shell command
[[ "x$TERM" == "xrxvt" || "x$XTERM_VERSION" == xXTerm* || "x$COLORTERM" == 'gnom
e-terminal' && "x$SHELL" == */bin/zsh ]] && preexec () { print -Pn "\e]0;$1\a" }
# Changing the terminal title to the last shell command
if [ "$SHELL" = '/bin/zsh' ]; then case $TERM in rxvt|*term|linux) preexec () {
print -Pn "\e]0;$1\a" };; esac; fi
#:916#
# commandlinefu.com by David Winterbottom
# More precise BASH debugging
env PS4=' ${BASH_SOURCE}:${LINENO}(${FUNCNAME[0]}) ' sh -x /etc/profile
#:917#
# commandlinefu.com by David Winterbottom
# Get last changed revision to all eclipse projects in a SVN working copy
find . -iname ".project"| xargs -I {} dirname {} | LC_ALL=C xargs -I {} svn info
{} | grep "Last Changed Rev\|Path" | sed "s/Last Changed Rev: /;/" | sed "s/Pat
h: //" | sed '$!N;s/\n//'
#:918#
# commandlinefu.com by David Winterbottom
# sort lines by length
awk '{print length, $0;}' | sort -nr
#:919#
# commandlinefu.com by David Winterbottom
# Comment out a line in a file
sed -i '19375 s/^/#/' file
#:920#
# commandlinefu.com by David Winterbottom
# Resize a Terminal Window
printf "\e[8;70;180;t"
# Using column to format a directory listing
(printf "PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME\n" \ ; ls
-l | sed 1d) | column -t
#:921#
# commandlinefu.com by David Winterbottom
# Outputs a 10-digit random number
tr -c -d 0-9 < /dev/urandom | head -c 10
#:922#
# commandlinefu.com by David Winterbottom
# live ssh network throughput test
pv /dev/zero|ssh $host 'cat > /dev/null'
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
#:923#
# commandlinefu.com by David Winterbottom
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
#:924#
# commandlinefu.com by David Winterbottom
# Schedule Nice Background Commands That Won't Die on Logout - Alternative to no
hup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null &&
trap 1 ) & )
#:925#
# commandlinefu.com by David Winterbottom
# Functions to display, save and restore $IFS
ifs () { echo -n "${IFS}"|hexdump -e '"" 10/1 "'\''%_c'\''\t" "\n"' -e '"" 10/1
"0x%02x\t" "\n\n"'|sed "s/''\|\t0x[^0-9]//g; $,/^$/d"
#:926#
# commandlinefu.com by David Winterbottom
# Functions to display, save and restore $IFS
ifs () { echo -n "${IFS}"|hexdump -e '"" 10/1 "'\''%_c'\''\t" "\n"' -e '"" 10/1
"0x%02x\t" "\n\n"'|sed "s/''\|\t0x[^0-9]//g; $,/^$/d"
#:927#
# commandlinefu.com by David Winterbottom
# autossh + ssh + screen = super rad perma-sessions
AUTOSSH_POLL=1 autossh -M 21010 hostname -t 'screen -Dr'
#:928#
# commandlinefu.com by David Winterbottom
# download all the presentations from UTOSC2009
b="http://2009.utosc.com"; for p in $( curl -s $b/presentation/schedule/ | grep
/presentation/[0-9]*/ | cut -d"\"" -f2 ); do f=$(curl -s $b$p | grep "/static/sl
ides/" | cut -d"\"" -f4); if [ -n "$f" ]; then echo $b$f; curl -O $b$f; fi done
#:929#
# commandlinefu.com by David Winterbottom
# Makefile argument passing
make [target] VAR=foobar
#:930#
# commandlinefu.com by David Winterbottom
# 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
#:931#
# commandlinefu.com by David Winterbottom
# 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
#:932#
# commandlinefu.com by David Winterbottom
# 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
#:933#
# commandlinefu.com by David Winterbottom
# Shorten url with is.gd using curl, perl
curl -s "http://is.gd/api.php?longurl=[long_url]"
# Get full URL via http://untr.im/api/ajax/api
URL=[target.URL]; curl -q -d "url=$URL" http://untr.im/api/ajax/api | awk -F 'hr
ef="' '{print $3}' | awk -F '" rel="' '{print $1}'
#:934#
# commandlinefu.com by David Winterbottom
# Shorten url with is.gd using curl, perl
curl -s "http://is.gd/api.php?longurl=[long_url]"
# Get full URL via http://untr.im/api/ajax/api
URL=[target.URL]; curl -q -d "url=$URL" http://untr.im/api/ajax/api | awk -F 'hr
ef="' '{print $3}' | awk -F '" rel="' '{print $1}'
#:935#
# commandlinefu.com by David Winterbottom
# Get full URL via http://untr.im/api/ajax/api
URL=[target.URL]; curl -q -d "url=$URL" http://untr.im/api/ajax/api | awk -F 'hr
ef="' '{print $3}' | awk -F '" rel="' '{print $1}'
#:936#
# commandlinefu.com by David Winterbottom
# Get full URL via http://untr.im/api/ajax/api
URL=[target.URL]; curl -q -d "url=$URL" http://untr.im/api/ajax/api | awk -F 'hr
ef="' '{print $3}' | awk -F '" rel="' '{print $1}'
#:937#
# commandlinefu.com by David Winterbottom
# A quick shell command to weed out the small wallpapers
for i in ~/Desktop/Personal/Wallpapers/*.jpg ; { size=$((`identify -format "%wx%
h" $i | sed 's/x/*/'`)) ; if [[ $size -lt 800001 ]] then ; rm -f "$i" ; fi; }
#:938#
# commandlinefu.com by David Winterbottom
# Copy a file over SSH without SCP
uuencode -m
# encode image to base64 and copy to clipboard
uuencode -m $1 /dev/stdout | sed '1d' | sed '$d' | tr -d '\n' | xclip -selection
clipboard
#:939#
# commandlinefu.com by David Winterbottom
# create SQL-statements from textfile with awk
for each in `cut -d " " -f 1 inputfile.txt`; do echo "select * from table where
id = \"$each\";"; done
#:940#
# commandlinefu.com by David Winterbottom
# Compression formats Benchmark
for a in bzip2 lzma gzip;do echo -n>$a;for b in $(seq 0 256);do dd if=/dev/zero
of=$b.zero bs=$b count=1;c=$(date +%s%N);$a $b.zero;d=$(date +%s%N);total=$(echo
$d-$c|bc);echo $total>>$a;rm $b.zero *.bz2 *.lzma *.gz;done;done
#:941#
# commandlinefu.com by David Winterbottom
# Partition a new disk as all one partition tagged as "LInux LVM"
echo -e "n\np\n1\n\n\nt\n8e\nw" | fdisk /dev/sdX
#:942#
# commandlinefu.com by David Winterbottom
# Convert a MOV captured from a digital camera to a smaller AVI
ffmpeg -i input.mov -b 4096k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi
#:943#
# commandlinefu.com by David Winterbottom
# Convert a MOV captured from a digital camera to a smaller AVI
ffmpeg -i input.mov -b 4096k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi
#:944#
# commandlinefu.com by David Winterbottom
# Convert a MOV captured from a digital camera to a smaller AVI
ffmpeg -i input.mov -b 4096k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi
#:945#
# commandlinefu.com by David Winterbottom
# 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
#:946#
# commandlinefu.com by David Winterbottom
# Set creation timestamp of a file to the creation timestamp of another
touch -r "$FILE1" "$FILE2"
#:947#
# commandlinefu.com by David Winterbottom
# Remove CR LF from a text file
flip -u $FILE
# Convert Windows/DOS Text Files to Unix
Convert Windows/DOS Text Files to Uni
# Convert Windows/DOS Text Files to Unix
flip -u
#:948#
# commandlinefu.com by David Winterbottom
# Return IP Address
ifconfig -a| awk 'BEGIN{FS="[ :]+"} /Bcast/{print $4}'
# Return IP Address
ifconfig -a|grep Bcast:|cut -d\: -f2|awk '{print $1}'
# Get a text on a position on the file and store in a variable with a specific s
eparator
TIMEUNIT=$( cat a | grep -n "timescale" | awk -F ":" '{ print $1 } ' )
#:949#
# commandlinefu.com by David Winterbottom
# one-liner mpc track changer using dmenu
mpc play $(sed -n "s@^[ >]\([0-9]\+\)) $(mpc playlist|cut -d' ' -f3-|dmenu -i -p
'song name'||echo void)@\1@p" < <(mpc playlist))
#:950#
# commandlinefu.com by David Winterbottom
# one-liner mpc track changer using dmenu
mpc play $(sed -n "s@^[ >]\([0-9]\+\)) $(mpc playlist|cut -d' ' -f3-|dmenu -i -p
'song name'||echo void)@\1@p" < <(mpc playlist))
#:951#
# commandlinefu.com by David Winterbottom
# What is my ip?
alias whatismyip="wget -q -O - http://whatismyip.com/automation/n09230945.asp"
#:952#
# commandlinefu.com by David Winterbottom
# Add the sbin directories to your PATH if it doesn't already exist in ZSH.
path+=( /sbin /usr/sbin /usr/local/sbin ); path=( ${(u)path} );
#:953#
# commandlinefu.com by David Winterbottom
# Creates Solaris alternate boot environment on another zpool.
lucreate -n be1 [-c be0] -p zpool1
#:954#
# commandlinefu.com by David Winterbottom
# Attach all discovered iscsi nodes
iscsiadm -m node -l
# Open-iscsi target discovery
iscsiadm -m discovery -t sendtargets -p 192.168.20.51
#:955#
# commandlinefu.com by David Winterbottom
# most dangerous command ever.
# hdparm -mRuUwx --dco-restore --drq-hsm-error --fwdownload --security-unlock PW
D --security-set-pass PWD --security-disable PWD --security-erase PWD --security
-erase-enhanced PWD --user-master USER --security-mode MODE [device]
#:956#
# commandlinefu.com by David Winterbottom
# most dangerous command ever.
# hdparm -mRuUwx --dco-restore --drq-hsm-error --fwdownload --security-unlock PW
D --security-set-pass PWD --security-disable PWD --security-erase PWD --security
-erase-enhanced PWD --user-master USER --security-mode MODE [device]
#:957#
# commandlinefu.com by David Winterbottom
# 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;d
one
#:958#
# commandlinefu.com by David Winterbottom
# 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;d
one
#:959#
# commandlinefu.com by David Winterbottom
# Get your external IP address
wget -qO - http://www.sputnick-area.net/ip;echo
# Get your external IP address
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//
'
# Get your external IP address
lynx --dump http://ip.boa.nu|sed -e 's/^[[:space:]]*//' -e 's/*[[:space:]]$//'|g
rep -v ^$
# Get your external IP address
wget -O - -q ip.boa.nu
# Get your external IP address
curl whatismyip.org
# Get your external IP address with the best commandlinefu.com command
eval $(curl -s http://www.commandlinefu.com/commands/matching/external/ZXh0ZXJuY
Ww=/sort-by-votes/plaintext|sed -n '/^# Get your external IP address$/{n;p;q}')
# Get your external IP address with a random commandlinefu.com command
IFS=$'\n';cl=($(curl -s http://www.commandlinefu.com/commands/matching/external/
ZXh0ZXJuYWw=/sort-by-votes/plaintext|sed -n '/^# Get your external IP address$/{
n;p}'));c=${cl[$(( $RANDOM % ${#cl[@]} ))]};eval $c;echo "Command used: $c"
# Get your external IP address
exec 3<>/dev/tcp/whatismyip.com/80; echo -e "GET /automation/n09230945.asp HTTP/
1.0\r\nHost: whatismyip.com\r\n" >&3; a=( $(cat <&3) ); echo ${a[${#a[*]}-1]};
# Get your external IP address
echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" | n
c whatismyip.com 80 | tail -n1
#:960#
# commandlinefu.com by David Winterbottom
# Binary Clock
watch -n 1 'echo "obase=2;`date +%s`" | bc'
#:961#
# commandlinefu.com by David Winterbottom
# Sum of the total resident memory Stainless.app is using.
ps -ec -o command,rss | grep Stainless | awk -F ' ' '{ x = x + $2 } END { print
x/(1024) " MB."}'
#:962#
# commandlinefu.com by David Winterbottom
# Test speaker channels
speaker-test -D plug:surround51 -c 6 -l 1 -t wav
#:963#
# commandlinefu.com by David Winterbottom
# List the CPU model name
sed -n 's/^model name[ \t]*: *//p' /proc/cpuinfo
# List the CPU model name
grep "model name" /proc/cpuinfo
#:964#
# commandlinefu.com by David Winterbottom
# Build an exhaustive list of maildir folders for mutt
find ~/Maildir/ -mindepth 1 -type d | egrep -v '/cur$|/tmp$|/new$' | xargs
#:965#
# commandlinefu.com by David Winterbottom
# Build an exhaustive list of maildir folders for mutt
find ~/Maildir/ -mindepth 1 -type d | egrep -v '/cur$|/tmp$|/new$' | xargs
#:966#
# commandlinefu.com by David Winterbottom
# Count emails in an MBOX file
grep -c '^From ' mbox_file
#:967#
# commandlinefu.com by David Winterbottom
#:968#
# commandlinefu.com by David Winterbottom
# Upload images to omploader.org from the command line.
ompload() { curl -F file1=@"$1" http://omploader.org/upload|awk '/Info:|File:|Th
umbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}';}
#:969#
# commandlinefu.com by David Winterbottom
# search ubuntu packages to find which package contains the executable program p
rogramname
apt-file find bin/programname
#:970#
# commandlinefu.com by David Winterbottom
# Decode a MIME message
munpack file.txt
#:971#
# commandlinefu.com by David Winterbottom
# Decode a MIME message
munpack file.txt
#:972#
# commandlinefu.com by David Winterbottom
# Find all dot files and directories
printf "%s\n" .*
# Find all dot files and directories
ls -d .*
# Find all dot files and directories
echo .*
# Find all dot files and directories
printf "%s\n" .*
# Find all dot files and directories
ls -a | egrep "^\.\w"
#:973#
# commandlinefu.com by David Winterbottom
# Watch a TiVo File On Your Computer
curl -s -c /tmp/cookie -k -u tivo:$MAK --digest http://$tivo/download/$filename
| tivodecode -m $MAK -- - | mplayer - -cache-min 50 -cache 65536
#:974#
# commandlinefu.com by David Winterbottom
# geoip information
geoiplookup www.commandlinefu.com
# geoip information
geo(){ curl -s "http://www.geody.com/geoip.php?ip=$(dig +short $1)"| sed '/^IP:/
!d;s/<[^>][^>]*>//g'; }
#:975#
# commandlinefu.com by David Winterbottom
# 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
# Real time satellite wheather wallpaper
curl http://www.cpa.unicamp.br/imagens/satelite/ult.gif | xli -onroot -fill stdi
n
# kalarm 1 per minute simplest e-mail beacom for Geovision surveillance DVR
curl http://www.spam.la/?f=sender | grep secs| awk '{print; exit}' | osd_cat -i
40 -d 30 -l 2
#:976#
# commandlinefu.com by David Winterbottom
# kalarm 1 per minute simplest e-mail beacom for Geovision surveillance DVR
curl http://www.spam.la/?f=sender | grep secs| awk '{print; exit}' | osd_cat -i
40 -d 30 -l 2
#:977#
# commandlinefu.com by David Winterbottom
# Be notified about overheating of your CPU and/or motherboard
sensors | grep "Core 1" | [[ `sed -e 's/^.*+\([0-9]\{2,3\}\).*(.*/\1/'` -gt 50 ]
] && notify-send "Core 1 temperature exceeds 50 degrees"
#:978#
# commandlinefu.com by David Winterbottom
# Be notified about overheating of your CPU and/or motherboard
sensors | grep "Core 1" | [[ `sed -e 's/^.*+\([0-9]\{2,3\}\).*(.*/\1/'` -gt 50 ]
] && notify-send "Core 1 temperature exceeds 50 degrees"
#:979#
# commandlinefu.com by David Winterbottom
# Listen to BBC Radio from the command line.
bbcradio() { local s;echo "Select a station:";select s in 1 1x 2 3 4 5 6 7 "Asia
n Network an" "Nations & Local lcl";do break;done;s=($s);mplayer -playlist "http
://www.bbc.co.uk/radio/listen/live/r"${s[@]: -1}".asx";}
#:980#
# commandlinefu.com by David Winterbottom
# 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');}
#:981#
# commandlinefu.com by David Winterbottom
# Short Information about loaded kernel modules
awk '{print $1}' "/proc/modules" | xargs modinfo | awk '/^(filename|desc|depends
)/'
# Short Information about loaded kernel modules
modinfo $(cut -d' ' -f1 /proc/modules) | sed '/^dep/s/$/\n/; /^file\|^desc\|^dep
/!d'
# Short Information about loaded kernel modules
lsmod | sed -e '1d' -e 's/\(\([^ ]*\) \)\{1\}.*/\2/' | xargs modinfo | sed -e '/
^dep/s/$/\n/g' -e '/^file/b' -e '/^desc/b' -e '/^dep/b' -e d
# Short Information about loaded kernel modules
lsmod | cut -d' ' -f1 | xargs modinfo | egrep '^file|^desc|^dep' | sed -e'/^dep/
s/$/\n/g'
#:982#
# commandlinefu.com by David Winterbottom
# Short Information about loaded kernel modules
awk '{print $1}' "/proc/modules" | xargs modinfo | awk '/^(filename|desc|depends
)/'
# Short Information about loaded kernel modules
modinfo $(cut -d' ' -f1 /proc/modules) | sed '/^dep/s/$/\n/; /^file\|^desc\|^dep
/!d'
# Short Information about loaded kernel modules
lsmod | sed -e '1d' -e 's/\(\([^ ]*\) \)\{1\}.*/\2/' | xargs modinfo | sed -e '/
^dep/s/$/\n/g' -e '/^file/b' -e '/^desc/b' -e '/^dep/b' -e d
# Short Information about loaded kernel modules
lsmod | cut -d' ' -f1 | xargs modinfo | egrep '^file|^desc|^dep' | sed -e'/^dep/
s/$/\n/g'
#:983#
# commandlinefu.com by David Winterbottom
# 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
# 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
#:984#
# commandlinefu.com by David Winterbottom
# 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
#:985#
# commandlinefu.com by David Winterbottom
# Burn a directory of mp3s to an audio cd.
alias burnaudiocd='mkdir ./temp && for i in *.[Mm][Pp]3;do mpg123 -w "./temp/${i
%%.*}.wav" "$i";done;cdrecord -pad ./temp/* && rm -r ./temp'
# 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
#:986#
# commandlinefu.com by David Winterbottom
# 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
#:987#
# commandlinefu.com by David Winterbottom
# View the latest astronomy picture of the day from NASA.
apod(){ local x=http://antwrp.gsfc.nasa.gov/apod/;feh $x$(curl -s ${x}astropix.h
tml|grep -Pom1 'image/\d+/.*\.\w+');}
#:988#
# commandlinefu.com by David Winterbottom
# View the latest astronomy picture of the day from NASA.
apod(){ local x=http://antwrp.gsfc.nasa.gov/apod/;feh $x$(curl -s ${x}astropix.h
tml|grep -Pom1 'image/\d+/.*\.\w+');}
#:989#
# commandlinefu.com by David Winterbottom
# View the latest astronomy picture of the day from NASA.
apod(){ local x=http://antwrp.gsfc.nasa.gov/apod/;feh $x$(curl -s ${x}astropix.h
tml|grep -Pom1 'image/\d+/.*\.\w+');}
#:990#
# commandlinefu.com by David Winterbottom
# Simple read and write test with Iozone
iozone -s 2g -r 64 -i 0 -i 1 -t 1
#:991#
# commandlinefu.com by David Winterbottom
# Remove an IP address ban that has been errantly blacklisted by denyhosts
denyhosts-remove $IP_ADDRESS
#:992#
# commandlinefu.com by David Winterbottom
# Burn a directory of mp3s to an audio cd.
alias burnaudiocd='mkdir ./temp && for i in *.[Mm][Pp]3;do mpg123 -w "./temp/${i
%%.*}.wav" "$i";done;cdrecord -pad ./temp/* && rm -r ./temp'
#:993#
# commandlinefu.com by David Winterbottom
# Checks apache's access_log file, strips the search queries and shoves them up
your e-mail
awk '/q=/{print $11}' /var/log/httpd/access_log.4 | awk -F 'q=' '{print $2}' | s
ed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1
# Checks apache's access_log file, strips the search queries and shoves them up
your e-mail
cat /var/log/httpd/access_log | grep q= | awk '{print $11}' | awk -F 'q=' '{prin
t $2}' | sed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1 | mail youremail@isp.c
om -s "[your-site] search strings for `date`"
#:994#
# commandlinefu.com by David Winterbottom
# DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 1)
mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -o dvd.
avi dvd://0
#:995#
# commandlinefu.com by David Winterbottom
# List all symbolic links in current directory
find /path -type l
# List all symbolic links in current directory
ls -lah | grep ^l
# List all symbolic links in current directory
\ls -1 | xargs -l readlink
#:996#
# commandlinefu.com by David Winterbottom
# Mount a Windows share on the local network (Ubuntu) with user rights and use a
specific samba user
sudo mount -t cifs -o credentials=/path/to/credenials //hostname/sharename /moun
t/point
#:997#
# commandlinefu.com by David Winterbottom
# Get your bash scripts to handle options (-h, --help etc) and spit out auto-for
matted help or man page when asked!!
process-getopt
#:998#
# commandlinefu.com by David Winterbottom
# configify the list of gems on ur machine. the quick hack
gem list --local | python -c "import sys;import re;l=sys.stdin.readlines();x=['c
onfig.gem \"'+line[:-1][:line.index(' ')] + '\" , ' +line[:-1][line.index(' '):]
.replace('(',':version => \"').replace(')','')+'\"' for line in l];print '\n'.jo
in(x)"
# configify the list of gems on ur machine. the quick hack
gem list --local | python -c "import sys;import re;l=sys.stdin.readlines();x=['c
onfig.gem :'+line[:-1][:line.index(' ')] + ' , ' +line[:-1][line.index(' '):].re
place('(',':version => ').replace(')','') for line in l];print '\n'.join(x)"
#:999#
# commandlinefu.com by David Winterbottom
# Get names of files in /dev, a USB device is attached to
ls -la /dev/disk/by-id/usb-*
#:1000#
# commandlinefu.com by David Winterbottom
# Get names of files in /dev, a USB device is attached to
ls -la /dev/disk/by-id/usb-*
#:1001#
# commandlinefu.com by David Winterbottom
# View a random xkcd comic
wget -q http://dynamic.xkcd.com/comic/random/ -O-| sed -n '/\n\n
\n %s\n %s\n %s\n\
n\n", $6, $4, $2)}'
# View the newest xkcd comic.
lynx --dump --source http://www.xkcd.com | grep `lynx --dump http://www.xkcd.com
| egrep '(png|jpg)'` | grep title | cut -d = -f2,3 | cut -d '"' -f2,4 | sed -e
's/"/|/g' | awk -F"|" ' { system("display " $1);system("echo "$2); } '
# View the newest xkcd comic.
xkcd(){ local f=$(curl -s http://xkcd.com/);display $(echo "$f"|grep -Po '(?<=")
http://imgs.xkcd.com/comics/[^"]+(png|jpg)');echo "$f"|awk '/\n\n
\n %s\n %s\n %s\n\
n\n", $6, $4, $2)}'
# View the newest xkcd comic.
lynx --dump --source http://www.xkcd.com | grep `lynx --dump http://www.xkcd.com
| egrep '(png|jpg)'` | grep title | cut -d = -f2,3 | cut -d '"' -f2,4 | sed -e
's/"/|/g' | awk -F"|" ' { system("display " $1);system("echo "$2); } '
# View the newest xkcd comic.
xkcd(){ local f=$(curl -s http://xkcd.com/);display $(echo "$f"|grep -Po '(?<=")
http://imgs.xkcd.com/comics/[^"]+(png|jpg)');echo "$f"|awk '/ /sys/block/sdb/queue/rotational
#:1005#
# commandlinefu.com by David Winterbottom
# set your ssd disk as a non-rotating medium
sudo echo 0 > /sys/block/sdb/queue/rotational
#:1006#
# commandlinefu.com by David Winterbottom
# Shorten url with is.gd using curl, perl
curl -s "http://is.gd/api.php?longurl=[long_url]"
# Match a URL
egrep 'https?://([[:alpha:]]([-[:alnum:]]+[[:alnum:]])*\.)+[[:alpha:]]{2,3}(:\d+
)?(/([-\w/_\.]*(\?\S+)?)?)?'
# Match a URL
cho "(Something like http://foo.com/blah_blah)" | awk '{for(i=1;i<=NF;i++){if($i
~/^(http|ftp):\/\//)print $i}}'
# Match a URL
echo "(Something like http://foo.com/blah_blah)" | grep -oP "\b(([\w-]+://?|www[
.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))"
#:1007#
# commandlinefu.com by David Winterbottom
# Match a URL
egrep 'https?://([[:alpha:]]([-[:alnum:]]+[[:alnum:]])*\.)+[[:alpha:]]{2,3}(:\d+
)?(/([-\w/_\.]*(\?\S+)?)?)?'
# Match a URL
cho "(Something like http://foo.com/blah_blah)" | awk '{for(i=1;i<=NF;i++){if($i
~/^(http|ftp):\/\//)print $i}}'
# Match a URL
echo "(Something like http://foo.com/blah_blah)" | grep -oP "\b(([\w-]+://?|www[
.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))"
#:1008#
# commandlinefu.com by David Winterbottom
# Match a URL
egrep 'https?://([[:alpha:]]([-[:alnum:]]+[[:alnum:]])*\.)+[[:alpha:]]{2,3}(:\d+
)?(/([-\w/_\.]*(\?\S+)?)?)?'
# Match a URL
cho "(Something like http://foo.com/blah_blah)" | awk '{for(i=1;i<=NF;i++){if($i
~/^(http|ftp):\/\//)print $i}}'
# Match a URL
echo "(Something like http://foo.com/blah_blah)" | grep -oP "\b(([\w-]+://?|www[
.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))"
#:1009#
# commandlinefu.com by David Winterbottom
# generate random password
openssl rand -base64 6
# generate random password
pwgen -Bs 10 1
#:1010#
# commandlinefu.com by David Winterbottom
# ruby one-liner to get the current week number
ruby -rdate -e 'p DateTime.now.cweek'
# perl one-liner to get the current week number
date +%V
# ruby one-liner to get the current week number
ruby -e 'require "date"; puts DateTime.now.cweek'
# perl one-liner to get the current week number
perl -e 'use Date::Calc qw(Today Week_Number); $weekn = Week_Number(Today); prin
t "$weekn\n"'
#:1011#
# commandlinefu.com by David Winterbottom
# ruby one-liner to get the current week number
ruby -rdate -e 'p DateTime.now.cweek'
# ruby one-liner to get the current week number
ruby -e 'require "date"; puts DateTime.now.cweek'
#:1012#
# commandlinefu.com by David Winterbottom
# Convert encoding of given files from one encoding to another
iconv -f utf8 -t utf16 /path/to/file
#:1013#
# commandlinefu.com by David Winterbottom
# Return threads count of a process
ps -o thcount -p
#:1014#
# commandlinefu.com by David Winterbottom
# Return threads count of a process
ps -o thcount -p
#:1015#
# commandlinefu.com by David Winterbottom
# Router discovery
traceroute 2>/dev/null -n google.com | awk '/^ *1/{print $2;exit}'
# Router discovery
sudo arp-scan 192.168.1.0/24 -interface eth0
#:1016#
# commandlinefu.com by David Winterbottom
# Extract all urls from the last firefox sessionstore.js file used.
sed -e 's/{"url":/\n&/g' ~/.mozilla/firefox/*/sessionstore.js | cut -d\" -f4
# Extract all urls from the last firefox sessionstore.js file used.
grep -oP '"url":"\K[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q)
# Show local/public IP adresses with or without interface argument using a shell
function for Linux and MacOsX
MyIps(){ echo -e "local:\n$(ifconfig $1 | grep -oP 'inet (add?r:)?\K(\d{1,3}\.){
3}\d{1,3}')\n\npublic:\n$(curl -s sputnick-area.net/ip)"; }
#:1017#
# commandlinefu.com by David Winterbottom
#:1018#
# commandlinefu.com by David Winterbottom
# Use curl on Windows to bulk-download the Savitabhabhi Comic Strip (for Adults)
for /L %%x in (1,1,16) do mkdir %%x & curl -R -e http://www.kirtu.com -o %%x/#1.
jpg http://www.kirtu.com/toon/content/sb%x/english/sb%x_en_[001-070].jpg
#:1019#
# commandlinefu.com by David Winterbottom
# Use curl on Windows to bulk-download the Savitabhabhi Comic Strip (for Adults)
for /L %%x in (1,1,16) do mkdir %%x & curl -R -e http://www.kirtu.com -o %%x/#1.
jpg http://www.kirtu.com/toon/content/sb%x/english/sb%x_en_[001-070].jpg
#:1020#
# commandlinefu.com by David Winterbottom
# Quickly batch resize images
mogrify -geometry 800x600 *.jpg
#:1021#
# commandlinefu.com by David Winterbottom
# copy ACL of one file to another using getfacl and setfacl
getfacl | setfacl -f -
#:1022#
# commandlinefu.com by David Winterbottom
# copy ACL of one file to another using getfacl and setfacl
getfacl | setfacl -f -
#:1023#
# commandlinefu.com by David Winterbottom
# copy ACL of one file to another using getfacl and setfacl
getfacl | setfacl -f -
#:1024#
# commandlinefu.com by David Winterbottom
#:1025#
# commandlinefu.com by David Winterbottom
# Collect a lot of icons from /usr/share/icons (may overwrite some, and complain
a bit)
mkdir myicons; find /usr/share/icons/ -type f -exec cp {} ./myicons/ \;
# Collect a lot of icons from /usr/share/icons (may overwrite some, and complain
a bit)
mkdir myicons && find /usr/share/icons/ -type f | xargs cp -t myicons
#:1026#
# commandlinefu.com by David Winterbottom
# Find jpeg images and copy them to a central location
find . -iname "*.jpg" -print0 | tr '[A-Z]' '[a-z]' | xargs -0 cp --backup=number
ed -dp -u --target-directory {location} &
#:1027#
# commandlinefu.com by David Winterbottom
#:1028#
# commandlinefu.com by David Winterbottom
# extract plain text from MS Word docx files
unzip -p some.docx word/document.xml | sed -e 's/<[^>]\{1,\}>//g; s/[^[:print:]]
\{1,\}//g'
#:1029#
# commandlinefu.com by David Winterbottom
# urldecoding
perl -pe 's/%([0-9a-f]{2})/sprintf("%s", pack("H2",$1))/eig'
#:1030#
# commandlinefu.com by David Winterbottom
# Analyse compressed Apache access logs for the most commonly requested pages
zcat access_log.*.gz | awk '{print $7}' | sort | uniq -c | sort -n | tail -n 20
#:1031#
# commandlinefu.com by David Winterbottom
# Analyse compressed Apache access logs for the most commonly requested pages
zcat access_log.*.gz | awk '{print $7}' | sort | uniq -c | sort -n | tail -n 20
#:1032#
# commandlinefu.com by David Winterbottom
# validate xml in a shell script using xmllint
xmllint --noout some.xml 2>&1 >/dev/null || exit 1
#:1033#
# commandlinefu.com by David Winterbottom
# 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
#:1034#
# commandlinefu.com by David Winterbottom
# 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
#:1035#
# commandlinefu.com by David Winterbottom
# 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
#:1036#
# commandlinefu.com by David Winterbottom
# hanukkah colored bash prompt
export PS1="\e[0;34m[\u\e[0;34m@\h[\e[0;33m\w\e[0m\e[0m\e[0;34m]#\e[0m "
#:1037#
# commandlinefu.com by David Winterbottom
# hanukkah colored bash prompt
export PS1="\e[0;34m[\u\e[0;34m@\h[\e[0;33m\w\e[0m\e[0m\e[0;34m]#\e[0m "
#:1038#
# commandlinefu.com by David Winterbottom
# 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
#:1039#
# commandlinefu.com by David Winterbottom
# 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";
#:1040#
# commandlinefu.com by David Winterbottom
# Open a RemoteDesktop from terminal
rdesktop -a 16 luigi:3052
#:1041#
# commandlinefu.com by David Winterbottom
# Sniffing network to generate a pcap file in CLI mode on a remote host and open
it via local Wireshark ( GUI ).
tcpdump -v -i -s 0 -w /tmp/sniff.pcap port # On the remote si
de
#:1042#
# commandlinefu.com by David Winterbottom
# analyze traffic remotely over ssh w/ wireshark
mkfifo /tmp/fifo; ssh-keygen; ssh-copyid root@remotehostaddress; sudo ssh root@r
emotehost "tshark -i eth1 -f 'not tcp port 22' -w -" > /tmp/fifo &; sudo wiresha
rk -k -i /tmp/fifo;
# analyze traffic remotely over ssh w/ wireshark
sudo ssh -Y remoteuser@remotehost sudo wireshark
# analyze traffic remotely over ssh w/ wireshark
ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i -
#:1043#
# commandlinefu.com by David Winterbottom
# analyze traffic remotely over ssh w/ wireshark
mkfifo /tmp/fifo; ssh-keygen; ssh-copyid root@remotehostaddress; sudo ssh root@r
emotehost "tshark -i eth1 -f 'not tcp port 22' -w -" > /tmp/fifo &; sudo wiresha
rk -k -i /tmp/fifo;
# analyze traffic remotely over ssh w/ wireshark
sudo ssh -Y remoteuser@remotehost sudo wireshark
# analyze traffic remotely over ssh w/ wireshark
ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i -
#:1044#
# commandlinefu.com by David Winterbottom
# analyze traffic remotely over ssh w/ wireshark
mkfifo /tmp/fifo; ssh-keygen; ssh-copyid root@remotehostaddress; sudo ssh root@r
emotehost "tshark -i eth1 -f 'not tcp port 22' -w -" > /tmp/fifo &; sudo wiresha
rk -k -i /tmp/fifo;
# analyze traffic remotely over ssh w/ wireshark
sudo ssh -Y remoteuser@remotehost sudo wireshark
# analyze traffic remotely over ssh w/ wireshark
ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i -
#:1045#
# commandlinefu.com by David Winterbottom
# analyze traffic remotely over ssh w/ wireshark
mkfifo /tmp/fifo; ssh-keygen; ssh-copyid root@remotehostaddress; sudo ssh root@r
emotehost "tshark -i eth1 -f 'not tcp port 22' -w -" > /tmp/fifo &; sudo wiresha
rk -k -i /tmp/fifo;
# analyze traffic remotely over ssh w/ wireshark
sudo ssh -Y remoteuser@remotehost sudo wireshark
# analyze traffic remotely over ssh w/ wireshark
ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i -
#:1046#
# commandlinefu.com by David Winterbottom
# Watch postgresql calls from your application on localhost
sudo tcpdump -nnvvXSs 1514 -i lo0 dst port 5432
#:1047#
# commandlinefu.com by David Winterbottom
# p is for pager
p() { l=$LINES; case $1 in do) shift; IFS=$'\n' _pg=( $("$@") ) && _pgn=0 && p r
;; r) echo "${_pg[*]:_pgn:$((l-4))}";; d) (( _pgn+=l-4 )); (( _pgn=_pgn>=${#
_pg[@]}?${#_pg[@]}-l+4:_pgn )); p r;; u) (( _pgn=_pgn<=l-4?0:_pgn-$l-4 )); p r
;; esac; }
#:1048#
# commandlinefu.com by David Winterbottom
#:1049#
# commandlinefu.com by David Winterbottom
# display embeded comments for every --opt, usefull for auto documenting your sc
ript
vim -n -es -c 'g/# CommandParse/+2,/^\s\+esac/-1 d p | % d | put p | %<' -c 'g/^
\([-+]\+[^)]\+\))/,/^\(\s\+[^- \t#]\|^$\)/-1 p' -c 'q!' $0
#:1050#
# commandlinefu.com by David Winterbottom
# display embeded comments for every --opt, usefull for auto documenting your sc
ript
vim -n -es -c 'g/# CommandParse/+2,/^\s\+esac/-1 d p | % d | put p | %<' -c 'g/^
\([-+]\+[^)]\+\))/,/^\(\s\+[^- \t#]\|^$\)/-1 p' -c 'q!' $0
#:1051#
# commandlinefu.com by David Winterbottom
# Slightly better compressed archives
find . \! -type d | rev | sort | rev | tar c --files-from=- --format=ustar | bzi
p2 --best > a.tar.bz2
#:1052#
# commandlinefu.com by David Winterbottom
# Copy a file over SSH without SCP
uuencode -m
#:1053#
# commandlinefu.com by David Winterbottom
# Copy a file over SSH without SCP
ssh HOST cat < LOCALFILE ">" REMOTEFILE
# Copy a file over SSH without SCP
uuencode -m
#:1054#
# commandlinefu.com by David Winterbottom
# Recursive chmod all files and directories within the current directory
chmod -R 774 .
# Recursive chmod all files and directories within the current directory
find . -print -exec chmod 777 {} \;
# Recursive chmod all files and directories within the current directory
find | xargs chmod 777
# Recursive chmod all files and directories within the current directory
chmod -R 777 *
#:1055#
# commandlinefu.com by David Winterbottom
# Pause and Resume Processes
stop () { ps -ec | grep $@ | kill -SIGSTOP `awk '{print $1}'`; }
#:1056#
# commandlinefu.com by David Winterbottom
# Pause and Resume Processes
stop () { ps -ec | grep $@ | kill -SIGSTOP `awk '{print $1}'`; }
#:1057#
# commandlinefu.com by David Winterbottom
# monitor network traffic and throughput in real time
iptraf
#:1058#
# commandlinefu.com by David Winterbottom
# external projector for presentations
xrandr --auto
#:1059#
# commandlinefu.com by David Winterbottom
# external projector for presentations
xrandr --auto
#:1060#
# commandlinefu.com by David Winterbottom
# external projector for presentations
xrandr --auto
#:1061#
# commandlinefu.com by David Winterbottom
# external projector for presentations
xrandr --auto
#:1062#
# commandlinefu.com by David Winterbottom
# external projector for presentations
xrandr --auto
#:1063#
# commandlinefu.com by David Winterbottom
# Setup a persistant SSH tunnel w/ pre-shared key authentication
autossh -f -i /path/to/key -ND local-IP:PORT User@Server
#:1064#
# commandlinefu.com by David Winterbottom
# Setup a persistant SSH tunnel w/ pre-shared key authentication
autossh -f -i /path/to/key -ND local-IP:PORT User@Server
#:1065#
# commandlinefu.com by David Winterbottom
# Chage default shell for all users [FreeBSD]
cd /usr/home && for i in *;do chsh -s bash $i;done
#:1066#
# commandlinefu.com by David Winterbottom
# Resize a Terminal Window
printf "\e[8;70;180;t"
#:1067#
# commandlinefu.com by David Winterbottom
# Resize a Terminal Window
printf "\e[8;70;180;t"
#:1068#
# commandlinefu.com by David Winterbottom
# Overloading unix system until crash
echo && :(){ :|:& };:
#:1069#
# commandlinefu.com by David Winterbottom
# Overloading unix system until crash
echo && :(){ :|:& };:
#:1070#
# commandlinefu.com by David Winterbottom
# Overloading unix system until crash
echo && :(){ :|:& };:
#:1071#
#:1072#
#:1073#
#:1074#
#:1075#
#:1076#
#:1077#
#:1078#
#:1079#
#:1080#
#:1081#
#:1082#
#:1083#
#:1084#
#:1085#
#:1086#
#:1087#
#:1088#
#:1089#
#:1090#
#:1091#
#:1092#
#:1093#
#:1094#
#:1095#
#:1096#
#:1097#
#:1098#
#:1099#
#:1100#
#:1101#
#:1102#
#:1103#
#:1104#
#:1105#
#:1106#
#:1107#
#:1108#
#:1109#
#:1110#
#:1111#
#:1112#
#:1113#
#:1114#
#:1115#
#:1116#
#:1117#
#:1118#
#:1119#
#:1120#
#:1121#
#:1122#
#:1123#
#:1124#
#:1125#
#:1126#
#:1127#
#:1128#
#:1129#
#:1130#
#:1131#
#:1132#
#:1133#
#:1134#
#:1135#
#:1136#
#:1137#
#:1138#
#:1139#
#:1140#
#:1141#
#:1142#
#:1143#
#:1144#
#:1145#
#:1146#
#:1147#
#:1148#
#:1149#
#:1150#
#:1151#
#:1152#
#:1153#
#:1154#
#:1155#
#:1156#
#:1157#
#:1158#
#:1159#
#:1160#
#:1161#
#:1162#
#:1163#
#:1164#
#:1165#
#:1166#
#:1167#
#:1168#
#:1169#
#:1170#
#:1171#
#:1172#
#:1173#
#:1174#
#:1175#
#:1176#
#:1177#
#:1178#
#:1179#
#:1180#
#:1181#
#:1182#
#:1183#
#:1184#
#:1185#
#:1186#
#:1187#
#:1188#
#:1189#
#:1190#
#:1191#
#:1192#
#:1193#
#:1194#
#:1195#
#:1196#
#:1197#
#:1198#
#:1199#
#:1200#
#:1201#
#:1202#
#:1203#
#:1204#
#:1205#
#:1206#
#:1207#
#:1208#
#:1209#
#:1210#
#:1211#
#:1212#
#:1213#
#:1214#
#:1215#
#:1216#
#:1217#
#:1218#
#:1219#
#:1220#