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 chmod from sorted by
Terminal - Commands using chmod - 80 results
find . -name "*" -print0 | xargs -0 -I {} chmod 777 {}
2010-10-11 19:05:41
User: aardvark4
Functions: chmod find xargs
-7

This will handle the case that the filename has spaces or other characters that need to be escaped.

chmod -R u=rwX,g=rX,o=rX .
for i in `find .`; do [ -d $i ] && chmod 755 $i || chmod 644 $i; done
2010-08-31 22:27:32
User: binfalse
Functions: chmod
-8

Reconstruct standard permissions for directories and files in current directory

find . -type d -exec chmod XXXX {} \;
chmod -R u=rw-x+X,g=r-x+X,o= .
2010-07-16 18:42:00
User: donnoman
Functions: chmod
Tags: bash Ubuntu
-1

forces user to rw, group to r, and other to no access.

files will not be marked executable.

directories will be executable for users and groups only.

chmod 644 $(find . -type f)
2010-06-10 07:57:53
User: takeshin
Functions: chmod find
7

To apply only to dirs:

chmod 755 $(find . -type d)

Use -R parameters for recursive walk.

echo -n "convert " > itcombino.sh; printf "IMG_%00004u.png " {1..1121} >> itcombino.sh; echo -n "-layers merge _final.png" >> itcombino.sh; chmod +x itcombino.sh && ./itcombino.sh
2010-05-22 03:56:30
User: IsraelTorres
Functions: chmod echo printf
1

This one liner; combines all sequentially numbered files; in this example IMG_0001.png to IMG_1121.png by generating the shell script, making the shell script executable and then running the shell script to combine the 1121 png into a single png file named _final.png

tested on Mac OS X 10.6.3 with ImageMagick 6.5.8-0 2009-11-22 Q16 http://www.imagemagick.org

find . -type d -name .svn -exec chmod g+s "{}" \;
2010-04-27 16:51:00
User: mitzip
Functions: chmod find
2

The above command will set the GID bit on all directories named .svn in the current directory recursively. This makes the group ownership of all .svn folders be the group ownership for all files created in that folder, no matter the user.

This is useful for me as the subversion working directory on my server is also the live website and needs to be auto committed to subversion every so often via cron as well as worked on by multiple users. Setting the GID bit on the .svn folders makes sure we don't have a mix of .svn metadata created by a slew of different users.

chmod --reference file1 file2
2010-03-31 12:05:48
User: rpavlick
Functions: chmod
Tags: chmod chown chgrp
41

Also works with:

chgrp --reference file1 file2 chown --reference file1 file2
chmod -R 774 .
find . -print -exec chmod 777 {} \;
2009-12-23 13:16:31
User: ringlerun
Functions: chmod find
-10

sometimes if directories are too deep, chmod -R fails... in those cases, a find comes in most handy :)

find | xargs chmod 777
chmod -R -x+X *
find . -type f | while read f; do chmod -x "$f"; done
find . ! -type d -exec chmod -x {}\;
2009-11-08 21:27:08
User: drashkeev
Functions: chmod find
1

Useful if you have copied files from an OS without a permission structure (for example, DOS) and you need to disable all executable files but want to be able to descend into your directories.

find public_html/stuff -type d -exec chmod 755 {} + -or -type f -exec chmod 644 {} +
2009-07-26 11:10:10
User: recursiverse
Functions: chmod find
7

Good for fixing web permissions. You might also want to do something like this and skip files or directories that begin with a period:

find public_html/stuff -not -name ".*" \( -type d -exec chmod 755 {} + -o -type f -exec chmod 644 {} + \)

...or include a special case for scripts:

find public_html/stuff -type d -exec chmod 755 {} + -or -type f -name "*.pl" -exec chmod 755 {} + -or -exec chmod 644 {} +
find . -type f ! -perm /g=r -exec chmod g+r {} +
2009-06-17 13:39:59
User: sanmiguel
Functions: chmod find
Tags: find chmod
3

Makes any files in the current directory (and any sub-directories) group-readable.

Using the "! -perm /g=r" limits the number of files to only those that do not already have this property

Using "+" on the end of the -exec body tells find to build the entire command by appending all matching files before execution, so invokes chmod once only, not once per file.

find . -type d -exec chmod 755 {} \;
2009-06-07 08:17:06
User: marssi
Functions: chmod find
Tags: find chmod
1

"find . -type d -print0 | xargs -0 chmod 755"

thanks masterofdisaster

find ./ -type f -exec chmod 644 {} \;
chmod +x FILES
sudo chmod -R g=u-w,g+X *
find . -iname "*wav" > step1 ; sed -e 's/\(^.*\)wav/\"\1wav\" \"\1mp3\"/' step1 > step2 ; sed -e 's/^/lame /' step2 > step3 ; chmod +x step3 ; ./step3
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/$$