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 chown from sorted by
Terminal - Commands using chown - 14 results
sudo tar -zcvf $(hostname)-etc-back-`date +%d`-`date +%m`-`date +%y`.tar.gz /etc && sudo chown $USER:$USER $(hostname)-etc-back*
2013-08-18 12:49:11
User: thanosme
Functions: chown sudo tar
Tags: backup tar date
0

Back up /etc directory with a name based on the current date and the hostname of the machine, then chown the file for the current user for use.

find . | while read line; do test `stat -c %u $line` -eq 1003 && chown android:android $line && echo $line; done
chown davidp:users /some/long/path/file && chmod g+rx $_
2012-06-20 16:40:14
Functions: chmod chown
Tags: $_
0

Using $_ in the chmod command saved a good bit of typing ? obviously the $_ will contain the path to the file we?re talking about, as it was the last argument to the previous command.

source: http://www.preshweb.co.uk/2007/07/bashs-_-variable-last-argument/

find . -user root | xargs sudo chown me:me
2012-04-24 18:29:13
Functions: chown find sudo xargs
-2

be careful where you execute this from

do a 'sudo ls' beforehand to prime sudo to not ask for your password

sudo chown -R nobody:admin /Applications/XAMPP/xamppfiles/htdocs/
for x in `find /dir_w_wrong_ownership/`; do y=`echo "$x" | sed 's,/dir_w_wrong_ownership/,/backup_dir/,'`; chown --reference $y $x; done;
2011-02-21 22:15:33
User: foucault
Functions: chown sed
0

requires: a directory with borked permissions and a backup directory that has the correct permissions.

works with chown or chmod

alias restoremod='chgrp users -R .;chmod u=rwX,g=rX,o=rX -R .;chown $(pwd |cut -d / -f 3) -R .'
2010-12-28 11:42:43
User: Juluan
Functions: alias chmod chown cut pwd users
2

I often use it at my work, on an ovh server with root ssh access and often have to change mod after having finished an operation.

This command, replace the user, group and mod by the one required by apache to work.

chown -R webuser:webgroup /var/www/vhosts/domain.com/httpdocs
sudo chown -R user2:user2 /../../somedirectory
2009-09-23 21:27:45
User: bkn390
Functions: chown sudo
-1

This will change the ownership of /../../somedirectory as well as all its subdirectories so they will be be owned by user2 - typically used when a directory is owned by root:root

find . -uid 0 -print0 | xargs -0 chown foo:foo
2009-05-27 19:52:13
User: abcde
Functions: chown find xargs
1

In the example, uid 0 is root. foo:foo are the user:group you want to make owner and group. '.' is the "current directory and below." -print0 and -0 indicate that filenames and directories "are terminated by a null character instead of by whitespace."

#!/bin/sh for dir in `ls -A | grep -v .sh`; do chown -R $dir:$dir $dir done
find /home -uid 1056 -exec chown 2056 {} \;
2009-02-17 19:42:50
Functions: chown find
5

Finds all files in /home owned by UID 1056 and changes to 2056.

chown -cR --from=olduser:oldgroup newuser:newgroup *
2009-02-10 16:55:09
User: haithamg
Functions: chown
1

Changing files ownership in a directory recursivley from a user to another

find /path/to/dir -user root -exec chown [nonprivuser] {} \;
2009-02-05 16:42:14
User: wwest4
Functions: chown find
0

useful if you want to start running a svc as a non-privileged user instead of root.