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 tagged chmod from sorted by
Terminal - Commands tagged chmod - 20 results
chmod --reference=file1 file2
find /var/www/ -type f -print0 | xargs -0 chmod 644
find /var/www/ -type f -print0 | xargs -0 chmod 644
2013-03-28 11:10:30
User: FiloSottile
Functions: chmod find xargs
Tags: find xargs chmod
-1

xargs is a more elegant approach to executing a command on find results then -exec as -exec is meant as a filtering flag.

chmod u+x **/*.sh
pwd|grep -o '/'|perl -ne '$x.="./.";print`readlink -f $x`'|xargs -tn1 chmod 755
2013-03-14 12:03:44
Functions: chmod grep perl pwd xargs
0

`pwd` returns the current path

`grep -o` prints each slash on new line

perl generates the paths sequence: './.', './../.', ...

`readlink` canonicalizes paths (it makes the things more transparent)

`xargs -tn1` applies chmod for each of them. Each command applied is getting printed to STDERR.

find . -type f -exec chmod a-x {} +
2012-06-11 12:50:56
User: sanmiguel
Functions: chmod find
Tags: find xargs chmod
4

Using `-exec cmd {} +` causes find to build the command using all matching filenames before execution, rather than once per file.

find . -type f -exec chmod -x {} \;
chmod -R u=rwX,go=rX .
find ./ -type f -exec chmod 644 {} +
inotifywait -mrq -e CREATE --format %w%f /path/to/dir | while read FILE; do chmod g=u "$FILE"; done
2010-10-21 23:36:02
User: dooblem
Functions: chmod read
6

Listens for events in the directory. Each created file is displayed on stdout. Then each fileline is read by the loop and a command is run.

This can be used to force permissions in a directory, as an alternative for umask.

More details:

http://en.positon.org/post/A-solution-to-the-umask-problem%3A-inotify-to-force-permissions

find . -exec chmod 777 {} \;
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.

vix(){ vim +'w | set ar | silent exe "!chmod +x %" | redraw!' $@; }
2010-05-27 21:12:48
User: dooblem
Functions: ar set vim
Tags: vim vi chmod
2
vix /tmp/script.sh

Open a file directly with execution permission.

Put the function in your .bashrc

You can also put this in your vimrc:

command XX w | set ar | silent exe "!chmod +x %" | redraw!

and open a new file like this:

vi +XX /tmp/script.sh
chmod --reference file1 file2
2010-03-31 12:05:48
User: rpavlick
Functions: chmod
Tags: chmod chown chgrp
39

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
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 {} \;