Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using seq from sorted by
Terminal - Commands using seq - 84 results
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"
for times in $(seq 10) ; do puppet agent -t && break ; done
2013-04-03 14:24:36
User: funollet
Functions: break seq times
-1

The example runs 'puppet' in a loop for 10 times, but exits the loop before if it returns 0 (that means "no changes on last run" for puppet).

for a in $(seq 5 8); do cat twit.txt | cut -d " " -f$a | grep "^@" | sort -u; done > followlst.txt
2013-03-29 21:07:09
User: xmuda
Functions: cat cut grep seq sort
-6

Go to "https://twitter.com/search/realtime?q=%23TeamFollowBack&src=hash" and then copy al the text on the page. If you scroll down the page will be bigger. Then put al the text in a text file called twit.txt

If you follow the user there is a high probability the users give you follow back.

To follow all the users you can use an iMacros script.

for i in $(seq -w 0 100) ; do mv prefix$(( 10#$i )).jpg prefix${i}.jpg ; done
for count in $(seq 2 1001); do say "$count sheeps";sleep 2;done
for count in $(seq 2 1001); do espeak "$count sheeps";sleep 2;done
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))
2013-01-13 18:23:44
User: claudius
Functions: column printf seq
Tags: bash color colors
0

Shows the ?rendering? for each of the 256 colours in both the bold and normal variant. Using seq is helpful to get even lines, passing $((COLUMNS*2)) to column sort-of-handles the nonprintable characters.

seq 10| shuf | head -1
2012-11-21 03:57:02
Functions: head seq
0

Above command will generate a random number between 1 to 10.

seq 2 100 | factor | sed '/ .* / d ; s/:.*//'
for i in $(seq 1 100 | sort -R); do echo $i; sleep 5; done
2012-09-25 17:47:32
Functions: echo seq sleep sort
3

Random choose numbers from 1 to 100 with 5 seconds interval without duplicates.

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)
2012-08-28 09:11:18
User: michel_p
Functions: awk diff echo grep seq sort
0

The command will make it easy to determine free IP ranges in a crowded sub-net.

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; # usage: seq 1 4; seq 0 4
seq 1 5 | xargs -I"#" date --date="today -# days" +'%Y-%m-%d'
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
2012-05-17 10:54:45
Functions: echo mv seq
0

This command takes a few changes to get to the file format, but once you have that, you're good to go. Set your environment variables and then change the text "front" and "back" to whatever you're files start and end with. You'll end up with some easily sort-able files.

up() { local x='';for i in $(seq ${1:-1});do x="$x../"; done;cd $x; }
2012-05-16 04:21:41
User: evil
Functions: cd seq
Tags: cd
8

I wrote this a long time ago, wondering why this wasn't floating around somewhere out there (at least not where I could find).. this seems much more simple than multiple aliases and can cd out of directories easier.

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 }
2012-04-19 08:16:34
Functions: cd echo seq
Tags: alias cd
2

Change n directories up, without parameters change one up

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
seq -f 'echo %g' $NUM | sh
2012-04-03 19:02:08
User: nati
Functions: seq
0

shorter loop than for loop

seq -f 'echo %g' $NUM | sh

for i in {0..$NUM}; do echo $i done

seq 1 1000000 | while read i; do echo -en "\r$i"; done
for i in $(seq 1 20); do while read line; do echo "$i: $line"; done<$i.py; done
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
2012-03-04 22:52:36
User: akira88
Functions: cut grep seq wget
Tags: wget comic
0

A simple script for download all the MegaTokyo strips from the first to the last one

pktsize=1516;for i in $( seq $pktsize -8 1450 ) ; do ping -M do -s $i -c 1 slashdot.org; done
2012-02-21 01:58:07
Functions: ping seq
0

Linux - starting with a packetsize that must be split into two packets, count down by 8 bytes, and try to send the packet using the "Don't Fragment" option. The actual MTU (the size of the actual PING packet) is (in this example) 1460 data bytes + 20 bytes IP header + 8 bytes PING request = 1488

sayspeed() { for i in $(seq 1 `echo "$1"|wc -c`); do echo -n "`echo $1 |cut -c ${i}`"; sleep 0.1s; done; echo "";}
2012-02-11 05:51:42
User: kundan
Functions: echo seq sleep wc
0

change the time that you would like to have as print interval

and just use it to say whatever you want to

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"
2012-01-27 12:26:33
User: captaincomic
Functions: seq
0

Put this code in a bash script. The script expects the PDF file as its only parameter.

It will add a header to the PDF containing the page numbers and output it to a file with the suffix "-header.pdf"

Requires enscript, ps2pdf and pdftk.

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"";}
2012-01-20 21:18:16
User: bbbco
Functions: echo seq
0

Ever need to get some text that is a specific number of characters long? Use this function to easily generate it! Doesn't look pretty, but sure does work for testing purposes!