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

All commands from sorted by
Terminal - All commands - 11,960 results
netstat -ntlp | grep -w 80 | awk '{print $7}' | cut -d/ -f1
find / -iname '*.pdf' -print -exec pdftotext '{}' - \; | grep --color -i "unix"
find . -not \( -name .svn -prune \)
2009-05-20 19:45:24
User: mbirk
Functions: find
Tags: svn find
5

The "find" command can be annoying when used inside of a Subversion (or CVS) working directory. Obviously, you can combine this with other predicates and commands to create a more elaborate pipeline:

find /var/svn -type f -not \( -name .svn -prune \) -print0 | xargs -0 md5sum

Note: You can use my "dont-go-there.sh" script to wrap the "find" command and do this automatically at http://forwardlateral.com/blog/2006/02/27/dont-go-there/

grep -lir "some text" *
2009-05-20 19:44:35
User: decept
Functions: grep
Tags: find text
22

-l outputs only the file names

-i ignores the case

-r descends into subdirectories

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

function mcd() { [ -n "$1" ] && mkdir -p "$@" && cd "$1"; }
2009-05-20 16:41:48
Functions: cd mkdir
4

I find that I create a directory and then cd into that directory quite often. I found this little function on the internets somewhere and thought I'd share it. Just copy-paste it into you ~/.bash_profile and then `source ~/.bash_profile`.

hddtemp /dev/sda /dev/sdb /dev/hda /dev/hdb | gawk '{print $NF}' | perl -n -e '$_ =~ s/(\d+)/print "$1 "/eg }{ print "\n"'
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.

unset HISTFILE
2009-05-20 14:46:18
User: syssyphus
Functions: unset
14

this will cause any commands that you have executed in the current shell session to not be written in your bash_history file upon logout

grep -ao -HP "http://[^/]*/" *
2009-05-20 14:45:34
User: binarycodes
Functions: grep
2

Replace * with any filename matching glob or an individual filename

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

cd "$(mktemp -d)"
2009-05-20 11:48:12
User: Weboide
Functions: cd
Tags: bash directory
8

This command create a new temp directory using mktemp (to avoid collisions) and change the current working directory to the created directory.

find /home/fizz -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
tr "[:upper:]" "[:lower:]" < file
fold -w 78 -s file-to-wrap
2009-05-19 19:33:10
User: GeckoDH
Functions: fold
3

Per default, linux/unix shells are configured with a width of 80 characters.

If you like to edit a phrase or string on a line with more than 80 characters it might take long to go there (for example a line with 1000 characters and you like to edit the 98th word which is character 598-603).

Maybe you might wish to use 78 characters, because if you forward the text via mail and the text will be quoted (2 extra characters at the beginning to the line "> "), you use 80 characters, otherwise 82, which are lame.

mencoder -aid 2 -oac copy file.avi -o english.mp3
notifyme -C `cat /etc/passwd | cut -d: -f1`
2009-05-19 19:17:05
Functions: cut
4

Notifyme is a program that listen in background for users login, and report on login and logout. Users can be specified from a list or in a ~/notify.rc file. -C options force to display messages on the center of the screen.See man notifyme for more details. Part of notifyme package, tested on Debian.

screen -x
2009-05-19 19:10:52
User: GeckoDH
Functions: screen
13

Ater person A starts his screen-session with `screen`, person B can attach to the srceen of person A with `screen -x`. Good to know, if you need or give support from/to others.

tiger
2009-05-19 19:07:11
-2

From man tiger : Tiger is a package consisting of Bourne Shell scripts, C code and data files which is used for checking for security problems on a UNIX system. It scans system configuration files, file systems, and user configuration files for possible security problems and reports them.

mytop --prompt
2009-05-19 19:04:57
0

mytop is a top like monitor for displaying Mysql server statistic and performance. Part of mytop package ,tested on Debian.

sed -i 'your sed stuff here' file
count() { find $@ -type f -exec cat {} + | wc -l; }
who -b
2009-05-19 11:52:54
User: sharfah
Functions: who
15

Displays time of last system boot