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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

Commands using seq from sorted by
Terminal - Commands using seq - 88 results
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!

comm -13 <(od -vw1 -tu1 dummy.txt|cut -c9-|sort -u) <(seq 0 127|sort)|perl -pe '$_=chr($_)'|od -c
2012-01-09 01:32:20
User: bazzargh
Functions: comm cut od perl seq sort
Tags: bash
0

Search in decimal rather than hex. od dumps the character list, cut to remove offsets, sort -u gives the used characters. seq gives the comparison list, but we need this sorted alphabetically for comm, which does the filtering. I drop to perl to convert back to characters (is there a better way?) and then use od to dump them in a print-safe format.

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]}'
2011-11-13 10:36:18
User: benoit_c_lbn
Functions: awk seq
Tags: sed
1

It's allways strange for me to see sed and awk in the same command line if you can avoid it

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)}'
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")}'
2011-10-22 18:41:09
User: kev
Functions: awk sed seq
Tags: sed awk
11

seq -s ' ' 1 9 | sed -n ':a;p;s/ *\w$//;h;/^$/t;b a;q' | tac | awk '{for(i=1;i

1x1=1

1x2=2 2x2=4

1x3=3 2x3=6 3x3=9

1x4=4 2x4=8 3x4=12 4x4=16

1x5=5 2x5=10 3x5=15 4x5=20 5x5=25

1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36

1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49

1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64

1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81

seq 20 | sed '5,6 { w out.txt }' #Can't print correctly. See sample output
2011-08-29 10:17:47
User: totti
Functions: sed seq
Tags: sed
0

Can't print correctly in the command field.

There is a new line before } as follows

seq 20 | sed -n '5,6 { w out.txt

}'

parallel -a <(seq 0 20) mkdir /tmp/dir1/{}
seq 1 255 | parallel -j+0 'nc -w 1 -z -v 192.168.1.{} 80'
2011-06-11 14:40:51
User: devrick0
Functions: seq
2

It takes over 5 seconds to scan a single port on a single host using nmap

time (nmap -p 80 192.168.1.1 &> /dev/null)

real 0m5.109s

user 0m0.102s

sys 0m0.004s

It took netcat about 2.5 minutes to scan port 80 on the class C

time (for NUM in {1..255} ; do nc -w 1 -z -v 192.168.1.${NUM} 80 ; done &> /dev/null)

real 2m28.651s

user 0m0.136s

sys 0m0.341s

Using parallel, I am able to scan port 80 on the entire class C in under 2 seconds

time (seq 1 255 | parallel -j255 'nc -w 1 -z -v 192.168.1.{} 80' &> /dev/null)

real 0m1.957s

user 0m0.457s

sys 0m0.994s

seq 20 | awk 'ORS=NR%5?FS:RS'
2011-05-26 11:39:34
User: kev
Functions: awk seq
Tags: awk
0

seq 20 | awk '{line=line sep $0; sep=" "} !(NR%5){print line; line=sep=""}'

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
seq -s "+" 3 | bc
seq -f"%g^2" -s "+" 10 | bc
echo $(($(seq -s* 10)))
2011-02-10 18:44:53
User: minduim
Functions: echo seq
Tags: math factorial
1

Same as the seq/bc solution but without bc.

seq -s^2+ 11 |rev| cut -d'+' -f2- | rev | bc
2011-02-10 08:41:14
User: rubenmoran
Functions: cut rev seq
Tags: seq sum math
-2

I can't put the last ^2 with seq, so I reverse it to delete the last +N. So for doing sum(N^2) you have to do sum((N+1)^2). Must be a better way.

seq -s* 10 |bc
seq 1 2 99999999 | sed 's!^!4/!' | paste -sd-+ | bc -l
2011-02-09 23:36:07
User: flatcap
Functions: bc paste sed seq
Tags: sed seq bc paste math
0

Calculate pi from the infinite series 4/1 - 4/3 + 4/5 - 4/7 + ...

This expansion was formulated by Gottfried Leibniz: http://en.wikipedia.org/wiki/Leibniz_formula_for_pi

I helped rubenmoran create the sum of a sequence of numbers and he replied with a command for the sequence: 1 + 2 -3 + 4 ...

This set me thinking. Transcendental numbers!

seq provides the odd numbers 1, 3, 5

sed turns them into 4/1 4/3 4/5

paste inserts - and +

bc -l does the calculation

Note: 100 million iterations takes quite a while. 1 billion and I run out of memory.

seq 1000 | paste -sd+- | bc
seq 10 | paste -sd* | bc
seq 100000 | paste -sd+ | bc
seq -w 50 | sort -R | head -6 |fmt|tr " " "-"
(netstat -atn | awk '{printf "%s\n%s\n", $4, $4}' | grep -oE '[0-9]*$'; seq 32768 61000) | sort -n | uniq -u | head -n 1
for i in $(seq 300) ; do ethtool -s eth0 autoneg on ; sleep 2 ; done
2010-10-31 18:15:54
User: christian773
Functions: seq sleep
-3

use this comand to see which switch port your network interface is using.

but remind, there is no network traffic for 10 minutes or how long you run the comand.

if you start the comand via ssh, port will come up again after the "for loop" has endet