### Commands tagged seq (24) the last day the last week the last month all time sorted by date votes

• Another combination of seq and awk. Not very efficient, but sufficiently quick. Show Sample Output

14
seq 50| awk 'BEGIN {a=1; b=1} {print a; c=a+b; a=b; b=c}'
· 2009-03-24 20:39:24
• Print a row of characters across the terminal. Uses tput to establish the current terminal width, and generates a line of characters just long enough to cross it. In the example '#' is used. It's possible to use a repeating sequence by dividing the columns by the number of characters in the sequence like this: seq -s'~-' 0 \$(( \$(tput cols) /2 )) | tr -d '[:digit:]' or seq -s'-~?' 0 \$(( \$(tput cols) /3 )) | tr -d '[:digit:]' You will lose chararacters at the end if the length isn't cleanly divisible. Show Sample Output

6
seq -s'#' 0 \$(tput cols) | tr -d '[:digit:]'
· 2010-04-01 09:06:44
• "seq 100" outputs 1,2,..,100, separated by newlines. awk adds them up and displays the sum. "seq 1 2 11" outputs 1,3,..,11. Variations: 1+3+...+(2n-1) = n^2 seq 1 2 19 | awk '{sum+=\$1} END {print sum}' # displays 100 1/2 + 1/4 + ... = 1 seq 10 | awk '{sum+=1/(2**\$1)} END {print sum}' # displays 0.999023 Show Sample Output

4
seq 100 | awk '{sum+=\$1} END {print sum}'
· 2009-03-24 20:30:40
• Displays six rows and five columns of random numbers between 0 and 1. If you need only one column, you can dispense with the "for" loop. Show Sample Output

3
seq 6 | awk '{for(x=1; x<=5; x++) {printf ("%f ", rand())}; printf ("\n")}'
· 2009-03-24 21:33:38
• print multiple increasing years using cal - calendar -. You can also try seq Start Increment End

3
for y in \$(seq 2009 2011); do cal \$y; done
· 2009-07-10 10:07:46
• 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

3
seq 1 255 | parallel -j+0 'nc -w 1 -z -v 192.168.1.{} 80'
· 2011-06-11 14:40:51
• unset PROMPT_COMMAND to disable. Show Sample Output

2
PROMPT_COMMAND='seq \$COLUMNS | xargs -IX printf "%Xs\r" @'
· 2010-11-24 14:34:21

• 2
seq -f"%g^2" -s "+" 10 | bc
· 2011-02-12 23:35:57
• This is a slightly modified version of the knoppix5 user oneliner (https://www.commandlinefu.com/commands/view/24571/draw-line-separator). Show Sample Output

1
seq -s '*' 40 | tr -dc '[*\n]'
· 2019-07-01 07:24:47
• Uses 'seq' with formatting parameter to generate the necessary padded sequence. Change '%02.0f' to how many digits you need (for 3, use %03.0f, etc) and replace 5 & 15 with your desired min and max. Show Sample Output

0
for s in `seq -f %02.0f 5 15`; do echo \$s; done
· 2009-09-18 13:21:38
• Nice command to create a list, you can create too with for command, but this is so faster. Show Sample Output

0
seq 10 |xargs -n1 echo Printing line
· 2009-10-15 11:05:35
• If you want a sequence that can be plotted, do: seq 8 | awk '{print "e(" \$0 ")" }' | bc -l | awk '{print NR " " \$0}' Other bc functions include s (sine), c (cosine), l (log) and j (bessel). See the man page for details. Show Sample Output

0
seq 8 | awk '{print "e(" \$0 ")" }' | bc -l
· 2010-08-14 02:52:39
• yt2mp3(){ for j in `seq 1 301`;do i=`curl -s gdata.youtube.com/feeds/api/users/\$1/uploads\?start-index=\$j\&max-results=1|grep -o "watch[^&]*"`;ffmpeg -i `wget youtube.com/\$i -qO-|grep -o 'url_map"[^,]*'|sed -n '1{s_.*|__;s_\\\__g;p}'` -vn -ab 128k "`youtube-dl -e \${i#*=}`.mp3";done;} squeezed the monster (and nifty ☺) command from 7776 from 531 characters to 284 characters, but I don't see a way to get it down to 255. This is definitely a kludge!

0
Command in description (Your command is too long - please keep it to less than 255 characters)
· 2011-02-03 08:25:42
• 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. Show Sample Output

0
seq 1 2 99999999 | sed 's!^!4/!' | paste -sd-+ | bc -l
· 2011-02-09 23:36:07
• In order to create, let's say, 10 directories with a single process we can use the command: mkdir test{1,2,3,4,5,6,7,8,9,10} something extremely boring to type! Why not use seq? seq -s, 1 10 and use its output inside the curly braces? The obvious solution mkdir test{\$(seq -s, 1 10)} is, unfortunately, too naive and doesn't work. The answer is the order of the shell expansions (feature of Bourne Shell, actually), where brace expansion happens before command substitution (according to Bash's manual). The solution is to put another level of substitution, using the powerful and mystic command eval. I found the trick in a similar problem in the post at http://stackoverflow.com/questions/6549037/bash-brace-expansion-in-scripts-not-working-due-to-unwanted-escaping

0
eval "mkdir test{\$(seq -s, 1 10)}"
· 2011-07-23 17:09:01

• 0
for i in `seq -w 1 50`; do wget --continue \ http://commandline.org.uk/images/posts/animal/\$i.jpg; done
· 2011-08-19 20:06:16
• creates 100 directories f(1-100) with a file in each matched to the directory (/f1/myfile1, .. /f98/myfile98,/f99/myfile99/,/f100/myfile100,etc ) Show Sample Output

0
for i in `seq 100`; do mkdir f\${i}; touch ./f\${i}/myfile\$i ;done
· 2011-09-29 01:03:46
• 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! Show Sample Output

0
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
• change the time that you would like to have as print interval and just use it to say whatever you want to Show Sample Output

0
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
• 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).

0
for times in \$(seq 10) ; do puppet agent -t && break ; done
· 2013-04-03 14:24:36

• 0
for y in {2009..2013}; do cal \$y; done
· 2013-07-01 08:28:23
• 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. Show Sample Output

-2
seq -s^2+ 11 |rev| cut -d'+' -f2- | rev | bc
· 2011-02-10 08:41:14
• With counter format [001, 002, ..., 999] , nice with pictures or wallpapers collections.

-4
for file in \$(seq -f '%03.f' 1 \$TOTAL ); do echo "(\$file/\$TOTAL)"; curl -f -O http://domain.com/Name_\$file.ext; done
· 2010-01-12 15:23:44
• Suppose you have 11 marbles, 4 of which are red, the rest being blue. The marbles are indistinguishable, apart from colour. How many different ways are there to arrange the marbles in a line? And how many ways are there to arrange them so that no two red marbles are adjacent? There are simple mathematical solutions to these questions, but it's also possible to generate and count all possibilities directly on the command line, using little more than brace expansion, grep and wc! The answer to the question posed above is that there are 330 ways of arranging the marbles in a line, 70 of which have no two red marbles adjacent. See the sample output. To follow the call to marbles 11 4: after c=''; for i in \$(seq \$1); do c+='{b,r}'; done;, \$c equals {b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r} After x=\$(eval echo \$c), and brace expansion, \$x equals bbbbbbbbbbb bbbbbbbbbbr ... rrrrrrrrrrb rrrrrrrrrrr, which is all 2^11 = 2048 strings of 11 b's and r's. After p=''; for i in \$(seq \$2); do p+='b*r'; done;, \$p equals b*rb*rb*rb*r Next, after y=\$(grep -wo "\${p}b*" Finally, grep -vc 'rr' Show Sample Output

-4
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"; }
· 2010-08-27 23:04:33

### What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

### Check These Out

Restore a local drive from the image on remote host via ssh

get delicious bookmarks on your shell (text version :-))
a variation of avi4now's command - thanks by the way!

Download latest NVIDIA Geforce x64 Windows7-8 driver from Nvidia's website. Pulls the latest download version (which includes beta). This is the "English" version. The following command includes a 'sed' line to replace "english" with "international" if needed. You can also replace the starting subdomain with "eu." "uk." and others. Enjoy this one liner! 1 character under the max :) \$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}' | sed -e "s/english/international/" | cut -d '=' -f3 | cut -d '&' -f1)"

Create a mirror of a local folder, on a remote server
Create a exact mirror of the local folder "/root/files", on remote server 'remote_server' using SSH command (listening on port 22) (all files & folders on destination server/folder will be deleted)

list files recursively by size

Create QR codes from a URL.
QR codes are those funny square 2d bar codes that everyone seems to be pointing their smart phones at. Try the following... \$ qrurl http://xkcd.com Then open qr.*.png in your favorite image viewer. Point your the bar code reader on your smart phone at the code, and you'll shortly be reading xkcd on your phone. URLs are not the only thing that can be encoded by QR codes... short texts (to around 2K) can be encoded this way, although this function doesn't do any URL encoding, so unless you want to do that by hand it won't be useful for that.

copy from host1 to host2, through your host
This is a 'nocd' alternative :)

One line Perl Script to determine the largest file sizes on a Linux Server
This one line Perl script will display the smallest to the largest files sizes in all directories on a server.

Convert CSV to JSON

Get the canonical, absolute path given a relative and/or noncanonical path
readlink -f accepts a relative, noncanonical path and emits the corresponding canonical, absolute path.