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/
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.
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
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:
It's allways strange for me to see sed and awk in the same command line if you can avoid it
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
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
}'
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
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.
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.
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
This will turn it in an infinite loop and also shows random words from a file, so it won't be the same each time and also not just a number.
Create a progress dialog with custom title and text using zenity.
using seq inside a subshell instead of a bash sequence to create increments.
splits a postscript file into multiple postscript files. for each page of the input file one output file will be generated. The files will be numbered for example 1_orig.ps 2_orig.ps ...
The psselect commad is part of the psutils package
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'