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 fold from sorted by
Terminal - Commands using fold - 18 results
strings /dev/urandom | tr -cd '[:alnum:]' | fold -w 30 | head -n 1
2014-12-11 06:21:51
User: atoponce
Functions: fold head strings tr
1

This command is similar to the alternate, except with head(1), you can pick as many passwords as you wish to generate by changing the number of lines you wish to preview.

tr -dc 'A-Za-z0-9!@#$%^&*' < /dev/urandom | fold -w 12 | head -n 1
xxd -p /dev/urandom |fold -60|head -30|sed 's/\(..\)/\1 /g'
2013-02-19 22:18:52
User: psifertex
Functions: fold head sed
1

Replaces hexdump with the more succint xxd, and the sed was unnecessarily complex.

curl -s 'http://xkcd.com/rss.xml' | xpath '//item[1]/description/text()' 2>&1 | sed -n 's/.*title="\([^"]*\)".*/\1/p' | fold -s
2013-02-16 22:38:26
User: putnamhill
Functions: fold sed
Tags: sed curl fold xpath
0

I look at xkcd in my news reader, but it displays the image's title attribute only for a few seconds which makes reading the longer ones more challenging. So I use this to display it in my console.

hexdump -v -e '"%u"' </dev/urandom|fold -60|head -n 30|sed 's/\(.\{2\}\)/\1 /g'
2013-02-16 12:56:24
User: knoppix5
Functions: fold head hexdump sed
6

or

od /dev/urandom -w60 -An|sed 's/ ..../ /g'|head -n 30

(this one lacks digits 8 and 9)

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)"
2012-11-09 00:40:22
User: cnyg
Functions: cat fold head python tr
1

Generate a 18 character password from character set a-zA-Z0-9 from /dev/urandom, pipe the output to Python which prints the password on standard out and in crypt sha512 form.

a=$(stty -a -F /dev/tty1| awk -F'[ ;]' '/columns/ { print $9 }'); fold -w$a /dev/vcs1;echo
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
2010-12-02 22:04:49
User: __
Functions: echo fold read
4

Like 7171, but fixed typo, uses fewer variables, and even more cryptic!

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
tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
fold -w 1 <file> | grep -c <character>
tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 10 | sed 1q
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | sed 1q
echo "vertical text" | fold -1
fold -w 78 -s file-to-wrap
2009-05-19 19:33:10
User: GeckoDH
Functions: fold
3

Per default, linux/unix shells are configured with a width of 80 characters.

If you like to edit a phrase or string on a line with more than 80 characters it might take long to go there (for example a line with 1000 characters and you like to edit the 98th word which is character 598-603).

Maybe you might wish to use 78 characters, because if you forward the text via mail and the text will be quoted (2 extra characters at the beginning to the line "> "), you use 80 characters, otherwise 82, which are lame.

fold -s -w 90 file.txt
2009-05-11 23:00:25
User: vincentp
Functions: fold
11

wraps text lines at the specified width (90 here).

-s option is to force to wrap on blank characters

-b count bytes instead of columns

sudo cat /dev/vcs1 | fold -w 80
2009-04-15 08:49:48
User: animoid
Functions: cat fold sudo
16

This will view the console and assumes the screen is 80 characters wide.

Use /dev/vcs2 for the next virtual console.. etc.

fold -s <filename>
2009-02-26 05:06:51
User: neutral
Functions: fold
9

fold wraps text at 80 characters wide, and with the -s flag, only causes wrapping to occur between words rather than through them.