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 by sharfah from sorted by
Terminal - Commands by sharfah - 46 results
pwdx pid
head -$(($RANDOM % $(wc -l < file.txt) +1 )) file.txt | tail -1
find . -type f ! -name "*html"
echo string | tr '[:lower:]' '[:upper:]'
history -c
touch -amct [[CC]YY]MMDDhhmm[.ss] FILE
2009-05-27 14:33:22
User: sharfah
Functions: touch
1

-a for access time, -m for modification time, -c do not create any files, -t timestamp

ssh -C -X user@remotehost gui_command
2009-05-21 17:52:24
User: sharfah
Functions: ssh
-2

Run GUI apps on another machine remotely through SSH.

-C is for data compression and -X enables X11 forwarding.

getconf ARG_MAX
2009-05-21 14:27:35
User: sharfah
Functions: getconf
1

Get max number of arguments that can be accepted by the exec() system call.

find . -name "*.jar" | while read file; do echo "Processing ${file}"; jar -tvf $file | grep "Foo.class"; done
cat /etc/SuSE-release
2009-05-20 17:28:12
User: sharfah
Functions: cat
Tags: SuSE
-3

Displays SuSE release information

unset TMOUT
2009-05-20 14:57:50
User: sharfah
Functions: unset
7

Unset TMOUT or set it to 0 in order to prevent shell autologout. TMOUT is the number of seconds after which the present shell will be killed if it has been idle for that long.

mvn -Dmaven.test.skip=true install
2009-05-20 12:55:10
User: sharfah
Tags: maven
-4

the maven.test.skip property can be added to other goals too.

mvn archetype:create -DgroupId=my.work -DartifactId=MyProject
2009-05-20 12:53:23
User: sharfah
Tags: maven
-5

This will create a new directory called MyProject with a pom.xml and the following tree structure:

MyProject

|-->pom.xml

|-->src

| |-->main

| | |-->java

| | | |-->my

| | | | |-->work

| | | | | |-->App.java

| |-->test

| | |-->java

| | | |-->my

| | | | |-->work

| | | | | |-->AppTest.java

who -b
2009-05-19 11:52:54
User: sharfah
Functions: who
15

Displays time of last system boot

sar -r
2009-05-19 11:47:38
User: sharfah
-2

Report memory and swap space utilization statistics e.g. memory free/used, swap free/used

kill -0 [pid]
2009-05-19 11:37:20
User: sharfah
Functions: kill
Tags: kill
5

Send signal 0 to the process. The return status ($?) can be used to determine if the process is running. 0 if it is, non-zero otherwise.

tar cvf - foodir | gzip > foo.tar.gz
2009-05-19 11:33:51
User: sharfah
Functions: gzip tar
Tags: tar gzip
-8

Where foodir is the directory you want to zip up.

gunzip < foo.tar.gz | tar xvf -
find . -type d -exec rmdir {} \;
2009-05-19 08:59:15
User: sharfah
Functions: find rmdir
Tags: find rm
1

Deletes empty directories and prints an error if directory is not empty.

TOM=`perl -w -e '@tom=localtime(time+86400);printf "%d%.2d%.2d",$tom[5]+1900,$tom[4]+1,$tom[3];'`
2009-05-19 08:54:27
User: sharfah
Tags: perl
-2

Returns tomorrow's date in the format yyyyMMdd

YEST=`perl -w -e '@yest=localtime(time-86400);printf "%d%.2d%.2d",$yest[5]+1900,$yest[4]+1,$yest[3];'`
2009-05-19 08:54:06
User: sharfah
Tags: perl
-2

Returns yesterday's date in the format yyyyMMdd