Both the locate command and the Slocate command are used to locate files or directories.
Locate is different from find: find is to go to the hard drive, locate only in/var/lib/slocate database. This database contains all the local file information. The Linux system automatically creates this database and updates it automatically once a day, so you can't find the latest changed files using the Locate command. In order to avoid this situation, you can use the UpdateDB command before using locate, manually update the database, locate faster than find, it is not really looking, but to check the database,
[Email protected]/]# UpdateDB
[Email protected]/]#
Search all files in the ETC directory that begin with SH:
[Email protected] ~]$ locate/etc/sh
/etc/shadow
/etc/shadow-
/etc/shells
Searches all files that begin with M in the user's home directory, and ignores the case:
[Email protected] ~]$ locate-i ~/m
/home/srd/music
Find all passwd files, but show only - a
[Email protected]/]# locate-n passwd
/etc/passwd
/etc/passwd-
/etc/pam.d/passwd
/etc/security/opasswd
/home/srd/cc/python-3.5.0/lib/test/keycert.passwd.pem
/home/srd/cc/python-3.5.0/lib/test/ssl_key.passwd.pem
/lib64/security/pam_passwdqc.so
/lib64/security/pam_unix_passwd.so
/usr/bin/gpasswd
/usr/bin/htpasswd
[email protected] 2015]# LL
Total 4251356
-rw-rw-r--. 1 SRD srd 4353378304 Jan 13:52 1.iso
-rw-r--r--. 2 root root Jan 17:58 1.txt
MV can rename and move files
[[Email protected] 2015]# MV 1.iso 2.iso
[email protected] 2015]# LL
Total 4251356
-rw-r--r--. 2 root root Jan 17:58 1.txt
-rw-rw-r--. 1 SRD srd 4353378304 Jan 13:52 2.iso
RM Delete files and directories
RmDir only empty directories can be deleted
[email protected] 2015]# LL
Total 4251356
-rw-rw-r--. 1 SRD srd 4353378304 Jan 13:52 1.iso
-rw-r--r--. 2 root root Jan 17:58 1.txt
Touch modify file Time properties and create files
[email protected] 2015]# Touch test1
[email protected] 2015]# Touch test2
[email protected] 2015]# Touch test2
[email protected] 2015]# Touch test3
[email protected] 2015]# Touch test4
[email protected] 2015]# Touch TEST5
[email protected] 2015]# LL
Total 4251356
-rw-rw-r--. 1 SRD srd 4353378304 Jan 13:52 1.iso
-rw-r--r--. 2 root root Jan 17:58 1.txt
-rw-r--r--. 1 root root 0 Jan 11:17 test1
-rw-r--r--. 1 root root 0 Jan 11:17 test2
-rw-r--r--. 1 root root 0 Jan 11:17 test3
-rw-r--r--. 1 root root 0 Jan 11:17 test4
-rw-r--r--. 1 root root 0 Jan 11:17 test5
Rename renaming
[Email protected] 2015]# rename test SRD test?
[email protected] 2015]# LL
Total 4251356
-rw-rw-r--. 1 SRD srd 4353378304 Jan 13:52 1.iso
-rw-r--r--. 2 root root Jan 17:58 1.txt
-rw-r--r--. 1 root root 0 Jan 11:17 srd1
-rw-r--r--. 1 root root 0 Jan 11:17 srd2
-rw-r--r--. 1 root root 0 Jan 11:17 srd3
-rw-r--r--. 1 root root 0 Jan 11:17 srd4
-rw-r--r--. 1 root root 0 Jan 11:17 Srd5
Which find file absolute path
[email protected] 2015]# which passwd
/usr/bin/passwd
Whereis is used to find binary files for instructions, general files with locate
[Email protected] 2015]# Whereis passwd
passwd:/usr/bin/passwd/etc/passwd/usr/share/man/man1/passwd.1.gz/usr/share/man/man5/passwd.5.gz
Linux Learning note 6 locate/slocate MV which