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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



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!

Top Tags



Commands using su from sorted by
Terminal - Commands using su - 15 results
su <username>
su - wsadmin
# su -c "psql -d maillog -c \"copy (select date,sender,destination,subject from maillog where destination like '%domain.com%') to '/tmp/mails.csv' with csv;\" " postgres
2013-02-13 13:03:17
User: Risthel
Functions: su

This command will "su" the execution of the command to the postgres user(implies that you are already logger as root), and export the result of the query to a file on the csv format.

You'll need to adequate the fields and database information to one of your choice/need.

su -c 'sync; echo 3 > /proc/sys/vm/drop_caches'
su -c "!!"
2012-02-21 15:38:30
User: mesuutt
Functions: su

Same as `sudo !!`. If you do not have permission to be sudo or sudo does not installed on your system, you can use this.

# su - <user> ; script /dev/null ; screen -r
2011-07-04 16:26:10
User: dmmst19
Functions: screen script su
Tags: screen su pty

Normally, if you su to another user from root and try to resume that other user's screen session, you will get an error like "Cannot open your terminal '/dev/pts/0' - please check." This is because the other user doesn't have permission for root's pty. You can get around this by running a "script" session as the new user, before trying to resume the screen session. Note you will have to execute each of the three commands separately, not all on the same line as shown here.

Credit: I found this at http://www.hjackson.org/blog/archives/2008/11/29/cannot-open-your-terminal-dev-pts-please-check.

apt-get -y install git-core gitosis; adduser --home /home/git --gecos "git user" git; su git -c "ssh-keygen -t rsa -f /home/git/.ssh/id_rsa; gitosis-init < ~/.ssh/id_rsa"
2010-12-19 20:37:12
User: strzel_a
Functions: apt install su

After, check if working by executing this command locally :

git clone [email protected]:repositories/gitosis-admin.git

Tutorial :


su - -m -p git
su -c "vncserver -depth 32 -geometry 1024x768" username
su - $user -c <command>
su username -c "xauth add ${HOSTNAME}/unix:${DISPLAY//[a-zA-Z:_-]/} $(xauth list | grep -o '[a-zA-Z0-9_-]*\ *[0-9a-zA-Z]*$'); bash"
2010-04-02 10:08:25
User: michelsberg
Functions: su

When you remotely log in like "ssh -X userA:host" and become a different user with "su UserB", X-forwarding will not work anymore since /home/UserB/.Xauthority does not exist.

This will use UserA's information stored in .Xauthority for UserB to enable X-forwarding.

Watch http://prefetch.net/blog/index.php/2008/04/05/respect-my-xauthority/ for details.

su -- user
2009-09-28 04:23:43
User: matthewdavis
Functions: su
Tags: bash root su

I've used this a number of times troubleshooting user permissions. Instead of just 'su - user' you can throw another hyphen and stay in the original directory.

su - <user> -s /bin/sh -c "/bin/sh"
su -c "truecrypt --non-interactive truecrypt-file cryptshare -p PASSWORD"
2009-05-22 21:11:29
User: tatwright
Functions: su

This is useful for use in scripts.

Note that this will leak your password to ps, so this shouldn't be used on shared machines. Use key files for this

read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $u