The Type,whatis,whereis,which,locate,find of Linux commands

Source: Internet
Author: User
Tags builtin touch command

First: type--Query the type of a command

-Query a command for internal or external commands;

-linux commands include internal commands and external commands, you can use the type command to query whether a command is an internal command or an external command;

-Method of distinguishing internal and external commands: there is an external command in the system where there is a storage location, there is no internal command for the storage location, because the internal command and the shell are a piece, so the location is not found;

-in fact, the type command is primarily auxiliary to view the Help documentation for a command, and if help is used, the internal command is obtained as a "helper command", or "command--help" if the external command is available.

[[Email protected] ~]# type mkdir//mkdir storage location in/bin/directory, then mkdir is external command

mkdir Is/bin/mkdir

[[Email protected] ~]# type passwd//passwd is also an external command

passwd is/usr/bin/passwd

[[Email protected] ~]# type cd//CD and help two commands are internal commands because they have no storage location, and a shell piece

CD is a shell builtin

[[Email protected] ~]# type help

Help is a shell builtin

[[Email protected] ~]# type mkdir passwd//after which you can query the location of the command with multiple options simultaneously

mkdir Is/bin/mkdir

passwd is/usr/bin/passwd

Second: The man portal of the whatis--query command

The individual thinks that the Whatis command, like the Type command, is also an auxiliary command that assists the man with this help command;

The following option is a command that queries the command to query the entry of time with the Man command.

[[email protected] ~]# Whatis passwd//Can see passwd This command man entrance is 1, and 5, then you can use "Man 5//passwd" or "Man 1 passwd" To obtain the help documentation for the corresponding passwd command;

passwd (1)-Update user ' s authentication tokens

passwd (5)-Password file

passwd (RPM)-the passwd utility for setting/changing passwords using PAM

passwd [sslpasswd] (1SSL)-Compute password hashes

[Email protected] ~]# Whatis mkdir

mkdir (1)-Make directories

mkdir (1p)-Make directories

mkdir (2)-Create a directory

mkdir (3p)-Make a directory

Third: whereis--finder /manuals /source files

Whereis is also a secondary command that queries the location of commands in a Linux system and the location of the help documents being queried for commands;

[[email protected] zhangsp]# whereis pwd mkdir passwd ls//view pwd,mkdir,passwd,ls four out of The location of the command in the Linux system, and the location of the command's Help document;

PWD:/bin/pwd/usr/share/man/man1p/pwd.1p.gz/usr/share/man/man1/pwd.1.gz

mkdir:/bin/mkdir/usr/share/man/man1p/mkdir.1p.gz/usr/share/man/man1/mkdir.1.gz/usr/share/man/man3p/mkdir.3p.gz /usr/share/man/man2/mkdir.2.gz

passwd:/usr/bin/passwd/etc/passwd/usr/share/man/man5/passwd.5.gz/usr/share/man/man1/passwd.1.gz

LS:/bin/ls/usr/share/man/man1p/ls.1p.gz/usr/share/man/man1/ls.1.gz

Fourth: which--Find the storage location of executable (external command, script) in Linux system

The location of the which command search is $path;

The $path of the root user and the normal user can be viewed with the echo $PATH command:

As you can see below, because the CD is an internal command, it cannot be found in the path where the $path exists, and the others have a location

[[email protected] zhangsp]# which CD LS mkdir pwd

Alias ls= ' ls--color=tty '

/bin/ls

/usr/bin/which:no CD in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin :/usr/bin:/root/bin)

/bin/mkdir

/bin/pwd

Fifth: locate--a fuzzy query in the database (including files and documents in Linux)

Because the search in the real index, so fast, but there are shortcomings, when the index library is not updated, there may be errors!

1) Use UpdateDB to create/update the Locate index library (use the command uadatedb command to update the index library)

[Email protected] ~]# UpdateDB

2) Use Locate to find the file/directory containing the specified keyword

[[Email protected] ~]# Locate Inittab//You can find all files or directories in the Linux system that contain inittab characters

/etc/inittab

/usr/share/man/man5/inittab.5.gz

/usr/share/terminfo/a/ansi+inittabs

/usr/share/vim/vim70/syntax/inittab.vim

[Email protected] ~]# locate mkdir

/bin/mkdir

/usr/bin/gnomevfs-mkdir

/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/auto/posix/mkdir.al

/usr/share/man/man1/mkdir.1.gz

/usr/share/man/man1p/mkdir.1p.gz

/usr/share/man/man2/mkdir.2.gz

/usr/share/man/man2/mkdirat.2.gz

/usr/share/man/man3p/mkdir.3p.gz

3) Delete/New added file object, need to update the index library to reflect the effect

For example: Create AAA directory and Bb.txt file under current directory, copy Bb.txt to AAA directory, and then use locate query without result

, then update the database index, where the query can find the location of the two bb.txt files.

[[email protected] ~]# ls

Anaconda-ks.cfg Desktop Install.log Install.log.syslog

[email protected] ~]# Touch bb.txt

[email protected] ~]# CP bb.txt aaa/

[[email protected] ~]# ls aaa/

Bb.txt

[[Email protected] ~]# Locate Bb.txt//Although bb.txt exists, the query bb.txt is no result when there is no time to update the database

[Email protected] ~]# UpdateDB

[[Email protected] ~]# Locate Bb.txt//Update query again after the results can be queried

/root/bb.txt

/root/aaa/bb.txt

[Email protected] ~]#

Sixth: find--accurate multi-criteria search for files or directories (typically for special file searches)

1) Use-type to find by type

The type here refers to the normal file (f), directory (d), block device file (b), character device file (c), and so on. A block device is a device that reads data in chunks (such as hard disks, memory, and so on), while a character device refers to a device that reads data by a single character (such as a keyboard, mouse, and so on).

Such as:

--1

[[email protected] ~]# find/boot/-type L//Query the symbolic link file under the/boot directory, and if you do not specify a directory, the current directory is implicitly considered/boot/grub/menu.lst

[Email protected] ~]# ll-h/boot/grub/menu.lst

lrwxrwxrwx 1 root root 02-10 21:03/boot/grub/menu.lst-/grub.conf

--2

[Email protected] ~]# find/boot/-type d//Query the/boot directory for the directory, and its own

/boot/

/boot/lost+found

/boot/grub

[Email protected] ~]# ll-f/boot/

Total 6333

-rw-r--r--1 root root 67857 2012-11-29 Config-2.6.18-348.el5

Drwxr-xr-x 2 root root 1024x768 02-10 21:03 grub/

-RW-------1 root root 2837626 02-10 21:54 initrd-2.6.18-348.el5.img

drwx------2 root root 12288 02-11 04:45 lost+found/

-rw-r--r--1 root root 118626 2012-11-29 symvers-2.6.18-348.el5.gz

-rw-r--r--1 root root 1282424 2012-11-29 System.map-2.6.18-348.el5

-rw-r--r--1 root root 2125660 2012-11-29 Vmlinuz-2.6.18-348.el5

[Email protected] ~]#

2) Use-name to find by name

[[email protected] ~]# find/boot-name ' *grub* '//Find an object with the name "Grub" under the/boot directory

/boot/grub

/boot/grub/grub.conf

3) combine multiple conditions to find

---You can use- A to match multiple conditions (all must be met),-a can be omitted, for example, only the boot directory name contains "grub" of ordinary files

[[email protected] ~]# find/boot/-name ' *grub* '-a-type f

/boot/grub/grub.conf

[[email protected] ~]# find/boot/-name ' *grub* '-type f

/boot/grub/grub.conf

---You can use- o to match multiple conditions simultaneously (just one of them), and-o cannot be omitted, such as looking for an object under the/boot directory with a name beginning with Vmlinuz and a name menu.lst

[Email protected] ~]# find/boot-name "vmlinuz*"-o-name "Menu.lst"

/boot/vmlinuz-2.6.18-348.el5

/boot/grub/menu.lst

Note: When writing wildcard characters, use single and double quotes as the same effect

4) Use-size to find by size, specify capacity unit K (lowercase), M, G

--Specifies whether the specified capacity is exceeded by "-size + size". For example, look for files larger than 2MB in the/boot directory

[Email protected] ~]# find/boot-size +2m

/boot/initrd-2.6.18-348.el5.img

/boot/vmlinuz-2.6.18-348.el5

[Email protected] ~]# ll-h/boot/initrd-2.6.18-348.el5.img/boot/vmlinuz-2.6.18-348.el5

-RW-------1 root root 2.8M 02-10 21:54/boot/initrd-2.6.18-348.el5.img

-rw-r--r--1 root root 2.1M 2012-11-29/boot/vmlinuz-2.6.18-348.el5

---Specify whether to be less than the specified capacity through "-size-size", for example, to find ordinary files with a capacity less than 2KB in the/boot/grub directory

[Email protected] ~]# find/boot/grub/-size-2k-type F

/boot/grub/device.map

/boot/grub/grub.conf

/boot/grub/stage1

[Email protected] ~]# ll-h/boot/grub/device.map/boot/grub/grub.conf/boot/grub/stage1

-rw-r--r--1 root root 02-10 21:03/boot/grub/device.map

-RW-------1 root root 598 02-10 21:03/boot/grub/grub.conf

-rw-r--r--1 root root 02-10 21:03/boot/grub/stage1

5) Use-exec to specify executable statements to process the lookup results

In the processing statement, {} in place of the search result, last with \; Indicates the end of processing (note a space between the preceding execution statement).

--The above find found in the/boot directory larger than 2MB file operation, can be directly connected with the LS command-exec to list the detailed properties

[Email protected] ~]# find/boot-size +2m-exec ls-lh {} \;

-RW-------1 root root 2.8M 02-10 21:54/boot/initrd-2.6.18-348.el5.img

-rw-r--r--1 root root 2.1M 2012-11-29/boot/vmlinuz-2.6.18-348.el5


--In the/boot/grub directory to find the size of less than 2KB ordinary files can also be directly used-exec Street LS command list detailed properties

[Email protected] ~]# find/boot/grub/-size-2k-type f-exec ls-lh {} \;

-rw-r--r--1 root root 02-10 21:03/boot/grub/device.map

-RW-------1 root root 598 02-10 21:03/boot/grub/grub.conf

-rw-r--r--1 root root 02-10 21:03/boot/grub/stage1

6) Use-mtime to find if it has been modified within the specified date

Find-name "file?. * "-mtime +30//Search in current directory 30 days ago (-mtime +30) changed files

Find-name "file?. * "-mtime-30//Find the modified file within 30 days (-mtime +30) in the current directory

Find-name "file?. * "-mtime 30//In the current directory query 30th day (-mtime 30) modified files

About + 30: for >31;-30 to <29;30 for =30 (30-31)

Extended

7) Use-user,-group to find documents belonging to the specified user, group

--Query the directory belonging to the ZHANGSP user under the root directory

[[email protected] ~]# Find/-user zhangsp-type d//Query root directory belonging to ZHANGSP users

/home/zhangsp

/home/zhangsp/.mozilla

/home/zhangsp/.mozilla/plugins

...

--Find the device belonging to the Print Group LP in the/dev/directory and use LS to list its detailed properties

[Email protected] ~]# find/dev/-group lp-exec ls-lh {} \;

CRW-RW----1 Root LP 6, 0 02-12 12:36/dev/lp0

CRW-RW----1 root LP, 3 02-12 12:35/DEV/PARPORT3

CRW-RW----1 root LP, 2 02-12 12:35/dev/parport2

CRW-RW----1 root LP, 1 02-12 12:35/dev/parport1

CRW-RW----1 root LP, 0 02-12 12:35/dev/parport0

[Email protected] ~]#

8) Use-perm to find documents that specify permissions

In the/etc/init.d/directory, look for a document that starts with auto and has exactly 755 permissions.

[[email protected] ~]# find/etc/init.d/-name ' auto* '-perm 0755

/etc/init.d/autofs

[Email protected] ~]# find/etc/init.d/-name ' auto* '-perm 0755-exec ls-lh {} \;

-rwxr-xr-x 1 root root 3.9K 2012-11-12/etc/init.d/autofs

Note: Touch command--can modify the modified date of a file that already exists, or you can create an empty file and set its date (parameter-T)

The sixth one in find is not tested and can be tested with touch;

Process:

[[Email protected] test]# Date//Current date is February 12, 2014

Wednesday, February 12, 2014 22:22:57 CST

[Email protected] test]# touch-t 1308121030 file1.doc//created on August 12, 13 10:30 file File.doc

[Email protected] test]# touch-t 02101020 file2.doc//Do not write year mark current year

[[email protected] test]# touch-t 1109291122 file3.doc//creation of FILE3.DOC file dated September 29, 11 11:22

[[email protected] test]# ll-h file*//Use ll to view the date of the file

-rw-r--r--1 root root 0 2013-08-12 File1.doc

-rw-r--r--1 root root 0 02-10 10:20 File2.doc

-rw-r--r--1 root root 0 2011-09-29 File3.doc

[[email protected] test]# ls

File1.doc File2.doc File3.doc

[[email protected] test]# find/home/test/-name ' file* '-mtime +40

/home/test/file1.doc

/home/test/file3.doc

[Email protected] test]# find/home/test/-name ' file* '-mtime +40-exec ls-lh {} \;

Show files modified before 40, you can see that there are two formally open dates older files

-rw-r--r--1 root root 0 2013-08-12/home/test/file1.doc

-rw-r--r--1 root root 0 2011-09-29/home/test/file3.doc

[Email protected] test]# find/home/test/-name ' file* '-mtime-40-exec ls-lh {} \;

Displays files modified in the last 40 days of the/home/test/directory

-rw-r--r--1 root root 0 02-10 10:20/home/test/file2.doc

Summarize:

The Type,whatis,which,whereis are for the command:

Type,whatis is generally used to see if the command is internal or external;

Which search path is the user's environment variables, and Whereis in the command-related directory and command help related directory search;

Locate and find are for files:

Locate search in the index, fast, but need to update the database;

Find in Linux file system search, slow, but full;

。。。 Learning for so long, some things learn to forget, forget to learn, and then forget, good memory than rotten pen, do a note one hours, write a blog need two hours, all when deepened memory!

    used to think of a command behind only one option, and later used a lot of options, such as: type pwd whatis passwd This command, clearly know the type can be followed by many options, or the habit of type Pwd,type Whatis ... Separate to use, later have to change, is conducive to improve efficiency!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.