This tutorial is done on:
thanhnguyen@thanhnguyen:~$ lsb_release -irWhat is locate.
Distributor ID: Ubuntu
Release: 12.04
NAME
locate - find files by name
So clearly, locate is the command line that can help you find files in your system base on the file name.
SYNOPSIS
SYNOPSIS
locate [OPTION]... PATTERN...
How does locate do?
In your system, there are databases that contain the information of all files.
The first, you need update these databases with:
The locate will read these databases and list filename of files that matching at least one of the PATTERNs.
By default, locate just check filenames in the database but does not sure that the these files are really exist or not. Moreover, it never report the files created after the most recent update of databases. It is main reason that why we always have to update databases before.
Note: database is a binary file (non-text file). But you can read it with:
For example, this command will list absolute path of all files named file1 and all directories named dir1:
In your system, there are databases that contain the information of all files.
The first, you need update these databases with:
updatedb
thanhnguyen@thanhnguyen:~$ updatedbThis command will read / to look for information of files and archive them in the databases.
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'
thanhnguyen@thanhnguyen:~$ sudo updatedb
thanhnguyen@thanhnguyen:~$
The locate will read these databases and list filename of files that matching at least one of the PATTERNs.
By default, locate just check filenames in the database but does not sure that the these files are really exist or not. Moreover, it never report the files created after the most recent update of databases. It is main reason that why we always have to update databases before.
Note: database is a binary file (non-text file). But you can read it with:
strings dbpath | lessFor example:
/var/lib/mlocate/mlocate.dbThe basic syntax of locate is:
.........
SM<L
/etc/depmod.d
ubuntu.conf
SM<L
/etc/dhcp
dhclient-enter-hooks.d
dhclient-exit-hooks.d
dhclient.conf
/etc/dhcp/dhclient-enter-hooks.d
avahi-autoipd
debug
resolvconf
samba
/etc/dhcp/dhclient-exit-hooks.d
....................
locate filenameWhen used without any options, locate display every absolute pathname of files that user have access permission.
For example, this command will list absolute path of all files named file1 and all directories named dir1:
locate file1 dir1For example:
thanhnguyen@thanhnguyen:~$ locate des.csv github
/home/thanhnguyen/des.csv
/home/thanhnguyen/github
/home/thanhnguyen/github/pho
/home/thanhnguyen/github/pypitop
/home/thanhnguyen/github/python
/home/thanhnguyen/github/saltstack
/home/thanhnguyen/github/flaskr/achemy.sql
/home/thanhnguyen/github/flaskr/flaskr.py
> lsb_release -ir
Trả lờiXóatoo verbose, lsb_release --help too see all of available options
> locale
why don't use "find"? when to use locale instead of find?
Can be use:
Xóathanhnguyen@thanhnguyen:~/Downloads$ lsb_release -d
Description: Ubuntu 12.04.5 LTS