Octal ls

ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
Do ls with permissions written in octal form.
Sample Output
644 -rw-r--r-- 1 iarno users 8947 2008-06-25 10:15 index.html
755 drwxr-xr-x 2 iarno users 4096 2008-06-01 10:31 js

By: iArno
2009-02-13 19:20:54

What Others Think

use of command "stat" works too, eg: stat -c%a\ %n * or stat --printf="%a\t%s\t\t%n\t\n" * etc... (man stat for more info) depending on what you exactly want to do...
gniourf_gniourf · 643 weeks and 6 days ago
zsh function ols() { ls $* | awk '{k=0;for(i=0;i }
susannakaukinen · 641 weeks and 1 day ago
you need to change instead of "i+2" "i+1" cuz it does not give good results.
RanyAlbeg · 606 weeks ago
im sorry . forget what i said :)
RanyAlbeg · 606 weeks ago
Thanks for this! It's pretty much what I wanted! I can always say "I wish I can use this to see my colors in the terminal!" and other stupid bits, but I was able to do this in ~/.bash_profile: alias lo="ls -l | awk '{k=0;for(i=0;i
AboveUnrefined · 486 weeks and 6 days ago
Sorry for the previous, but the escapes added killed my previous comment! In the alias I just enclosed in double quotes and then added escapes as needed, basically before the $ and other double quotes
AboveUnrefined · 486 weeks and 6 days ago
find . -maxdepth 1 -name ".git" -prune -o -printf "%#m %p\n" | sed -r -e "s/^([0-9]+)\\s\\.\\//\\1 /" | sort -k1
Tatsh · 302 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

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.

Share Your Commands

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: