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 search from sorted by
Terminal - Commands tagged search - 28 results
function google () { st="$@"; open "http://www.google.com/search?q=${st}"; }
2014-05-07 03:14:05
User: plasticphyte
3

Searches Google, but requires no "", and will also search all terms input in the CL, eg:

> google foo bar

returns search URL "

You could also use awk to replace all spaces with a +, which is how the Google search handles spaces, but that makes it more than one line.

gsettings get org.gnome.desktop.background picture-uri | xargs nautilus
grep -c "search_string" /path/to/file
2013-12-10 18:13:54
User: meatflag
Functions: grep
0

-c will count the number of times your search matches in the file.

sed -n '/jan\|Jan\|JAN\|JAn\|jAn\|jAN\|jaN/p' data.txt > jan-only-data.txt
/foo
2013-10-09 08:40:06
User: knoppix5
Tags: man search
-3

Will highlight search term i.e. "foo" across entire man page (scroll up or down to see)

/term_to_search_for+Enter

That is how to find things ;)

/Enter

(slash+empty string+Enter) will jump to the next occurence of previous searched item.

google() { gg="https://www.google.com/search?q=";q="";if [[ $1 ]]; then for arg in "$@" ; do q="$q+$arg"; done ; if [[ -f /usr/bin/chromium ]]; then chromium "$gg"$q; else firefox -new-tab "$gg"$q; fi else echo 'Usage: google "[seach term]"'; fi }
google() { gg="https://www.google.com/search?q="; ff="firefox"; if [[ $1 ]]; then "$ff" -new-tab "$gg"$(echo ${1//[^a-zA-Z0-9]/+}); else echo 'Usage: google "[seach term]"'; fi }
2013-08-01 22:21:53
User: lowjax
Functions: echo
2

Usage: google "[search string]"

Example: google "something im searching for"

This will launch firefox and execute a google search in a new tab with the provided search string.

You must provide the path to your Firefox binary if using cygwin to $ff or create an alias like follows:

alias firefox='/cygdrive/c/Program Files (x86)/Mozilla Firefox/firefox.exe'

Most Linux flavors with Firefox installed will use just ff="firefox" and even OSX.

vim ~/.inputrc
2013-04-23 02:50:11
User: ekinertac
Functions: vim
Tags: bash search
-8

This allows you to search through your history using the up and down arrows ? i.e. type "cd /" and press the up arrow and you'll search through everything in your history that starts with "cd /".

grep -i -h 'account.journal.cashbox.line' *.py
grep -lir 'aMethodName' * | grep -v 'target'
2012-10-15 12:50:21
User: hay
Functions: grep
0

Finds all files recursively from your working directory, matching 'aMethodName', except if 'target' is in that file's path.

Handy for finding text without matching all your files in target or subversion directories.

<ctrl+r>
2012-04-15 16:42:32
User: moollaza
1

"What it actually shows is going to be dependent on the commands you've previously entered.

When you do this, bash looks for the last command that you entered that contains the substring "ls", in my case that was "lsof ...". If the command that bash finds is what you're looking for, just hit Enter to execute it. You can also edit the command to suit your current needs before executing it (use the left and right arrow keys to move through it).

If you're looking for a different command, hit Ctrl+R again to find a matching command further back in the command history. You can also continue to type a longer substring to refine the search, since searching is incremental.

Note that the substring you enter is searched for throughout the command, not just at the beginning of the command." - http://www.linuxjournal.com/content/using-bash-history-more-efficiently

recoll -t -q "keyword" | grep message/rfc822 | sed -s 's,^.*\('$MAILDIR'[^]]*\)\].*$,\"\1\",' | xargs ln -sft $MAILDIR/bingo/cur/
aptitude search ^tin
2011-10-20 17:51:36
0

# Search for an available package on Debian systems using a regex so it only matches packages starting with 'tin'.

man <command> then type h
2011-10-16 09:49:56
User: stanix
Functions: man type
-5

Read all chapters up to 'Jumping', improve your effectiveness of wirking in terminal.

Most useful are the Moving and Searching commands

less file.ext
2011-09-13 10:29:27
User: totti
Functions: less
Tags: less text search
-4

Use the following key binding to search

----------------------------------------------------------------

ng

: Jump to line number n. Default is the start of the file.

nG

: Jump to line number n. Default is the end of the file.

/pattern

: Search for pattern. Regular expressions can be used. [/ = slash] Press / and then Enter to repeat the previous search pattern. Press ESC and then u to undo search highlighting.

n

: Go to next match (after a successful search).

N

: Go to previous match.

mletter

: Mark the current position with letter.

'letter

: Return to position letter. [' = single quote]

'^ or g

: Go to start of file.

'$ or G

: Go to end of file.

s

: Save current content (got from another program like grep) in a file.

= or Ctrl+g

: File information.

F

: continually read information from file and follow its end. Useful for logs watching. Use Ctrl+c to exit this mode.

-option

: Toggle command-line option -option.

h

: Help.

perl -ne 'print if m{\Q/*\E}x .. m{\Q*/\E}x or m{\/\/}x' *.c
2011-07-12 04:41:49
User: dbr
Functions: perl
0

more idiomatic version of the same, using the flip-flop-operator; also printing lines with '//'-style comments

aptitude search ~d "irc client"|grep -i "irc client"
2011-07-11 19:48:55
User: tomjrace
Functions: grep
0

This is the best way I have found to search out an application when I am not sure the title.

Grep is just to remove anything that does not contain the term in the title or short description (lots of things might include the search term in the description, such as libraries used by the application)

perl -e 'my $in_comment = 0; while (<>) { $in_comment = 1 if m{\Q/*\E}; print if $in_comment; $in_comment = 0 if m{\Q*/\E}; }' *.cpp
2011-07-08 00:17:27
User: doherty
Functions: perl
1

This is a naive way of finding source code comments in source code files that use C-like comments: // and /*...*/

google "search terms" #see description for more details
2011-07-04 09:37:39
User: husmanahmed
Functions: more
0

Inspired by: http://www.commandlinefu.com/commands/view/8744/search-google-on-os-x

#!/bin/bash if [ -n "$1" ] then firefox 'http://www.google.com/search?q="'$1'"' else firefox 'http://www.google.com' fi

Ive aliased this script as 'google' on my system and I can type 'google "search terms"' to open firefox with my search terms. My first post here, if there are any improvements to be made please let me know in the comments.

alias google='open http://www.google.com/search?q="'
2011-06-29 20:23:20
Functions: alias
1

Syntax:

google query_with_spaces "

so, make sure to end your query with a double quote

The command is too big to fit here. :( Look at the description for the command, in readable form! :)
2011-01-05 02:45:28
User: hunterm
Functions: at command
-6

Yep, now you can finally google from the command line!

Here's a readable version "for your pleasure"(c):

google() { # search the web using google from the commandline # syntax: google google query=$(echo "$*" | sed "s:%:%25:g;s:&:%26:g;s:+:%2b:g;s:;:%3b:g;s: :+:g") data=$(wget -qO - "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=$query") title=$(echo "$data" | tr '}' '\n' | sed "s/.*,\"titleNoFormatting//;s/\":\"//;s/\",.*//;s/\\u0026/'/g;s/\\\//g;s/#39\;//g;s/'amp;/\&/g" | head -1) url="$(echo "$data" | tr '}' '\n' | sed 's/.*"url":"//;s/".*//' | head -1)" echo "${title}: ${url} | http://www.google.com/search?q=${query}" }

Enjoy :)

find . -name "*noticia*" -name "*jhtm*" -name "*.tpl" -exec grep -li "id=\"col-direita\"" '{}' \; | xargs -n1 mate
svn up -r PREV # revert
2010-07-07 23:09:00
1

* Add comment with # in your command

* Later you can search that command on that comment with CTRL+R

In the title command, you could search it later by invoking the command search tool by first typing CTRL+R and then typing "revert"

filterous -dntb --tag Bash < bookmarks.xml
2010-07-07 07:42:11
User: l0b0
2

You can install filterous with

sudo apt-get install libxslt1-dev; sudo easy_install -U filterous