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.


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

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Create a listing of all possible permissions and their octal representation.

Terminal - Create a listing of all possible permissions and their octal representation.
touch /tmp/$$;for N in `seq -w 0 7777|grep -v [89]`; do chmod $N /tmp/$$; P=`ls -l /tmp/$$ | awk '{print $1}'`; echo $N $P; done;rm /tmp/$$
2009-03-05 15:24:41
User: jyoder
Functions: awk chmod echo touch
3
Create a listing of all possible permissions and their octal representation.

Alternatives

There are 2 alternatives - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

awesome

Comment by linuxrawkstar 390 weeks ago

Interesting, but is there actually any practical application?

Comment by goodevilgenius 390 weeks ago

Practical? Eh. I have a buddy that just can't seem to understand setting perms and how the different octal values work. So I wrote this for him. I was assuming that looking at the patterns would help explain what value impacted what permission, but instead he saved it to a file and just searches for the permission string he wants. I guess it works either way. :D

Comment by jyoder 390 weeks ago

I'd never use $$ for temporary files, better use mktemp.

Comment by OJM 390 weeks ago

There are several problems with this:

* The use of /tmp/$$ isn't portable across shells, making it a Bash-ism. As already mentioned, use mktmep, or just choose an actual filename, like /tmp/FILE. If you insist on '$$', then quote it, as should be the first rule of all shell variables and filenames.

* The use of backticks is a nightmare for maintenance and readability. Use $() instead. Unless you absolutely need portability to the archaic Unix shells, such as Bourne, $() is much more readable and functional.

* The for loop is looping through numbers 0 to 7777, but our binary friends for permissions don't include permissions with the number '8' or '9' like 0999 or 3898, and so forth. Bit-shifting should be used here.

* Further, the grep -v [89] is another Bash-ism, making this "one-liner" non-portable.

* The endless scroll of nearly 7000 lines isn't teaching anything to anybody. Instead of the endless scrollback, the user should be asked for input, the input should be validated as a permission, then echoed back in octal to show the permission set. It's clean, and it actually teaches.

* This is why shell-scripting sucks. Rather, use a more capable language, such as Perl, Python or Ruby. Shell scripts should only be used as simple solutions to simple problems.

Comment by atoponce 389 weeks and 5 days ago

@stoponce: /tmp/$$ is portable. Even Sun's braindead /bin/sh (which is far from POSIX compliance) understands it. It doesn't understand $(), though.

Looping from 0 to 7777 (decimal) and then removing all numbers that contain the digits 8 or 9 is a perfect way to generate octal numbers. There's no need for bit-shifting here.

grep -v [89] is not a bashism, but it will fail if the current directory happens to contain a file named "8" or "9" (or both), whether bash or another shell. Therefore the pattern needs to be put in quotes.

Comment by inof 377 weeks and 2 days ago

Your point of view

You must be signed in to comment.