Commands using locate (17)

  • [Update! Thanks to a tip from ioggstream, I've fixed both of the bugs mentioned below.] You, yes, 𝙔𝙊𝙐, can be the terror of the Internet! Why use normal, boring bullet points in your text, when you could use a ROTATED HEAVY BLACK HEART BULLET (❥)!? (Which would also be an awesome band name, by the way).  This script makes it easy to find unusual characters from the command line. You can then cut and paste them or, if you're using a GTK application, type Control+Shift+U followed by the code point number (e.g., 2765) and then a SPACE.  USAGE: Put this script in a file (I called mine "ugrep") and make it executable. Run it from the command line like so,  ugrep heart  The output will look like this,  ☙ U+2619 REVERSED ROTATED FLORAL HEART BULLET ♡ U+2661 WHITE HEART SUIT ♥ U+2665 BLACK HEART SUIT ❣ U+2763 HEAVY HEART EXCLAMATION MARK ORNAMENT ❤ U+2764 HEAVY BLACK HEART ❥ U+2765 ROTATED HEAVY BLACK HEART BULLET ❦ U+2766 FLORAL HEART ❧ U+2767 ROTATED FLORAL HEART BULLET ⺖ U+2E96 CJK RADICAL HEART ONE ⺗ U+2E97 CJK RADICAL HEART TWO ⼼ U+2F3C KANGXI RADICAL HEART  You can, of course, use regular expressions. For example, if you are looking for the "pi" symbol, you could do this:  ugrep '\bpi\b'  REQUIREMENTS: Although this is written in Bash, it assumes you have Perl installed because it greps through the Perl Unicode character name module (/usr/lib/perl5/Unicode/CharName.pm). Note that it would not have made more sense to write this in Perl, since the CharName.pm module doesn't actually include a subroutine for looking up a character based on the description. (Weird.)  BUGS: In order to fit this script in the commandlinefu limits, a couple bugs were added. ① Astral characters beyond the BMP (basic multilingual plane) are not displayed correctly, but see below. ② Perl code from the perl module being grepped is sometimes extraneously matched.  MISFEATURES: Bash's printf cannot, given a Unicode codepoint, print the resulting character to the terminal. GNU's coreutils printf (usually "/usr/bin/printf") can do so, but it is brokenly pedantic about how many hexadecimal digits follow the escape sequence and will actually die with an error if you give the wrong number. This is especially annoying since Unicode code points are usually variable length with implied leading zeros. The CharNames.pm file represents BMP characters as 4 hexits, but astral characters as 5. In the actual version of this script that I use, I've kludged around this misfeature by zero-padding to 8 hexits like so,  /usr/bin/printf "\U$(printf "%08x" 0x$hex)"  TIP 1: The author recommends "xsel" for command line cut-and-paste. For example,  ugrep biohazard | xsel  TIP 2: In Emacs, instead of running this command in a subshell, you can type Unicode code points directly by pressing Control-Q first, but you'll likely want to change the default input from octal to hexadecimal. (setq read-quoted-char-radix 16).  TIP 3: Of course, if you're using X, and you want to type one of the more common unusual characters, it's easiest of all to do it with your Compose (aka Multi) key. For example, hitting [Compose] <3 types ♥. Show Sample Output


    12
    egrep -i "^[0-9a-f]{4,} .*$*" $(locate CharName.pm) | while read h d; do /usr/bin/printf "\U$(printf "%08x" 0x$h)\tU+%s\t%s\n" $h "$d"; done
    hackerb9 · 2010-12-31 16:47:59 15
  • To start, you first need to make sure updatedb has been run/updatedb, and initialized the db: su -l root -c updatedb This locate command is provided through the mlocate package, installed by default on most GNU/Linux distributions. It's available on the BSDs as well. Not sure about support for proprietary UNIX systems. The output is self-explanatory- it provides an overview of how many directories and files are on your system. Show Sample Output


    7
    locate -S
    atoponce · 2010-06-25 14:39:49 3

  • 6
    locate searchstring | xargs ls -l
    pixel · 2009-02-06 00:02:35 49
  • Checks the apache configuration syntax, if is OK then restart the service otherwise opens the configuration file with VIM on the line where the configuration fails.


    3
    ( apache2ctl -t && service apache2 restart || (l=$(apache2ctl -t 2>&1|head -n1|sed 's/.*line\s\([0-9]*\).*/\1/'); vim +$l $(locate apache2.conf | head -n1)))
    cicatriz · 2010-11-26 18:12:08 78
  • Ever use 'locate' to find a common phrase in a filename or directory name? Often you'll get a huge list of matches, many of which are redundant, and typically the results are not sorted. This command will 'locate' your search phrase, then show you a sorted list of just the relevant directories, with no duplications. So, for example, maybe you have installed several versions of the java jre and you want to track down every directory where files matching "java" might exist. Well, a 'locate java' is likely to return a huge list with many repeated directories since many files in one directory could contain the phrase "java". This command will whittle down the results to a minimal list of unique directory names where your search phrase finds a match.


    2
    for i in $(locate your_search_phrase); do dirname $i; done | sort | uniq
    realbrewer · 2009-02-05 14:03:20 24
  • use the locate command to find files on the system and verify they exist (-e) then display each one in full details. Show Sample Output


    1
    locate -e somefile | xargs ls -l
    nadavkav · 2009-08-23 13:16:59 3
  • Finds all cert files on a server and lists them, finding out, which one is a symbolic link and which is true. You want to do this when a certificate expires and you want to know which files to substitute with the new cert. Show Sample Output


    0
    for crt in $(locate -r '.+\.crt' | grep -v "/usr/share/ca-certificates/"); do ls -la $crt; done
    udog · 2010-08-23 12:22:48 5
  • MAC OSX doesn't come with a locate command, This will do the same thing as the locate command on a typical Linux OS. Simply add it to your ~/.bash_profile


    0
    alias locate='if [ $((`date +%s`-`eval $(stat -s /var/db/locate.database); echo $st_mtime`)) -gt 3600 ]; then echo "locate: db is too old!">/dev/stderr; sudo /usr/libexec/locate.updatedb; fi; locate -i'
    jhyland87 · 2013-01-21 17:45:50 4
  • Another way to view some code by keyword and basic regular expression


    0
    locate *\\.php|xargs grep --color=always -i -5 "namespace\s.*\W"|less
    unixmonkey14859 · 2014-02-28 13:52:15 7
  • Find all books on my systems and move them into folder. The -0 switches are to handle spaces etc. in the filenames. Why would you need this? Locate uses an index, so it's super quick, and xargs is more elegant than a for loop.


    0
    locate -0 -i *barthes* | xargs -0 mv -t ~/'Library/Books/Barthes, Roland'
    qdrizh · 2014-11-16 18:26:35 11
  • Uses "locate" instead of "find", "sort -u" instead of "sort | uniq" and it's case insensitive. Show Sample Output


    0
    locate -i /pattern/ | xargs -n1 dirname | sort -u
    dardo1982 · 2015-05-09 21:22:05 9
  • May require the locate package. Locate is awesome, it creates a small file database which is updated once a day or so, or you can do a force update with 'updatedb'. Then you just type in 'locate' with the name of the file or folder that you want and off it goes. Show Sample Output


    0
    locate *.desktop
    Vallamost · 2016-09-21 23:47:39 16
  • scare hell out of user of just amuse by playing random .wav short files


    0
    while true; do locate *.wav | sed "{${RANDOM:1:2}q;d;}" | xargs aplay; sleep 10; done &> /dev/null &
    dav23r · 2017-08-25 15:11:54 18
  • Escapes spaces in paths.


    -1
    locate -i yourfilename | sed 's/ /\\ /g' | xargs ls -lah | less
    unixmonkey23919 · 2011-07-26 13:00:39 4
  • This command allow you quick find any executable by keyword(s) in your system. NOTE: Sometime this command will output like this: `hello.py.launch': No such file or directory this is normal behaviour Show Sample Output


    -1
    find $(locate hello) -type f -executable -print|grep -E "hello\$"
    unixmonkey14859 · 2012-08-18 07:51:53 5
  • Greps located files for an expression. Example greps all LaTeX files for 'foo': locate *.tex | xargs grep foo To avoid searching thousands of files with grep it could be usefull to test first how much files are returned by locate: locate -c *.tex


    -2
    locate searchstring | xargs grep foo
    zimon · 2009-04-16 12:51:24 5

  • -2
    locate munin | xargs rm -r
    strzel_a · 2011-03-14 11:47:00 4

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

Check if the files in current directory has the RPATH variable defined
Using gentoo prefix portage I got in a situation where some packages did not contain the needed RPATH variable. This command helped me to find out which ones I should recompile

Look for English words in /dev/urandom
* to get the English dictionary: wget http://www.mavi1.org/web_security/wordlists/webster-dictionary.txt

how to export a table in .csv file
Exports the result of query in a csv file

diff the same file in two directories.
This is useful when you're diffing two files of the same name in radically different directory trees. For example: Set $ path1='/some/long/convoluted/path/to/all/of/your/source/from/a/long/dead/machine' then $ path2='/local/version/of/same/file' then run the command. Much easier on the eyes when you're looking back across your command history, especially if you're doing the same diff over and over again.

copy from host1 to host2, through your host
Good if only you have access to host1 and host2, but they have no access to your host (so ncat won't work) and they have no direct access to each other.

colorize sequences of digits
Credits go to Flatcap https://www.commandlinefu.com/commands/by/flatcap

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

List all open ports and their owning executables
Particularly useful on OS X where netstat doesn't have -p option.

Advanced python tracing
Trace python statement execution and syscalls invoked during that simultaneously

Show a zoomable world map
show a zoomable world map


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: