File Search/which/whereis/locate/find/grep

Source: Internet
Author: User

Which # Find a fixed directory #

[[Email protected] Home] # Which Ba

/Usr/bin/which: No Ba in (/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin: /usr/sbin:/usr/bin:/root/bin)

[[Email protected] Home] # Which ls

Alias ls = 'ls -- color = auto'

/Bin/ls

We can see that the which command only queries these specified directories.

Whereis # The Help file is also displayed to us #

[[Email protected] Home] # whereis ls

Ls:/bin/ls/usr/share/man/Man1/ls.1.gz/usr/share/man/man1p/ls.1p.gz

[[Email protected] Home] #

650) This. width = 650; "Title =" Clipboard "style =" border-top: 0px; border-Right: 0px; Background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; padding-Right: 0px; "Border =" 0 "alt =" Clipboard "src =" http://img1.51cto.com/attachment/201408/11/8976580_1407764118TCcK.png "Height =" 32 "/>

Locate case:

In the/home/huxiaoming directory, two new files, 1.txtand 2.txt, are created.

[[Email protected] huxiaoming] # locate 1.txt

/Etc/pki/nssdb/pkcs11.txt

/Usr/share/cups/charmaps/iso-8859-1.txt

/Usr/share/cups/charmaps/iso-8859-11.txt

/Usr/share/cups/charmaps/windows-1251.txt

/Usr/share/cups/charmaps/windows-1361.txt

/Usr/share/doc/dstat-0.7.0/dstat.1.txt

/Usr/share/Vim/vim72/doc/gui_x11.txt.gz

/Usr/share/Vim/vim72/doc/usr_01.txt.gz

/Usr/share/Vim/vim72/doc/usr_11.txt.gz

/Usr/share/Vim/vim72/doc/usr_21.txt.gz

/Usr/share/Vim/vim72/doc/usr_31.txt.gz

/Usr/share/Vim/vim72/doc/usr_41.txt.gz

[[Email protected] huxiaoming] # locate 2.txt

/Usr/share/cups/charmaps/iso-8859-2.txt

/Usr/share/cups/charmaps/windows-1252.txt

/Usr/share/cups/charmaps/windows-932.txt

/Usr/share/doc/certmonger-0.61/dogtag-notes-2.txt

/Usr/share/doc/python-lxml-2.2.3/doc/lxml2.txt

/Usr/share/doc/vim-common-7.2.411/readme_os2.txt

/Usr/share/Vim/vim72/doc/gui_w32.txt.gz

/Usr/share/Vim/vim72/doc/OS _os2.txt.gz

/Usr/share/Vim/vim72/doc/OS _win32.txt.gz

/Usr/share/Vim/vim72/doc/usr_02.txt.gz

/Usr/share/Vim/vim72/doc/usr_12.txt.gz

/Usr/share/Vim/vim72/doc/usr_22.txt.gz

/Usr/share/Vim/vim72/doc/usr_32.txt.gz

/Usr/share/Vim/vim72/doc/usr_42.txt.gz

No newly added files are found, because we need to execute the command to update the directory tree.

[[Email protected] huxiaoming] # updatedb updates the directory tree

[[Email protected] huxiaoming] # locate 2.txt

/Home/huxiaoming/2.txt.

[[Email protected] huxiaoming] # Cat/etc/cron. daily/mlocate. cron

#! /Bin/sh

Nodevs = $ (</proc/filesystems awk '$1 = "nodev" {print $2 }')

Renice + 19-p $>/dev/null 2> & 1

Ionice-C2-N7-p $>/dev/null 2> & 1

/Usr/bin/updatedb-F "$ nodevs"

In fact, the system executes an mlocate. cron every day to update the directory tree.

Find command --- Search in current directory

[[Email protected] huxiaoming] # Find 1.txt

1. txt

[[Email protected] huxiaoming] # cd/

[[Email protected]/] # Find 1.txt

Find: '1.txt ': no such file or directory

If you want to find the entire hard disk, run the following command to start searching directory trees from the root directory.

[[Email protected]/] # Find/-name 1.txt

/Home/huxiaoming/1.txt

Some find skills in Regular Expressions

For example, I want to configure the NIC, but I only remember that the configuration file is probably named IFC ....

Find/etc/-name "* IFC *"

[[Email protected]/] # Find/etc-name "* ifcfg-eth0 *"-exec VI {}\;

{Indicates the searched file} can be executed directly by adding a parameter after-exec.

Two Display Methods: One-Al and the other always uses ls as a command to call

650) This. width = 650; "Title =" Clipboard [1] "style =" border-top: 0px; border-Right: 0px; Background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; padding-Right: 0px; "Border =" 0 "alt =" Clipboard [1] "src =" http://img1.51cto.com/attachment/201408/11/8976580_14077641198WN1.png "Height =" 17 "/>

650) This. width = 650; "Title =" Clipboard [2] "style =" border-top: 0px; border-Right: 0px; Background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-Right: 0px; "Border =" 0 "alt =" Clipboard [2] "src =" http://img1.51cto.com/attachment/201408/11/8976580_1407764119atuc.png "Height =" 20 "/>

There are also some advanced skills

Delete the. txt file as prompted.

[[Email protected]/] # Find/home-name "*. txt *"-OK RM {}\;

<RM.../home/huxiaoming/2.txt>? No

<RM.../home/huxiaoming/1.txt>? Yes

[[Email protected]/] # Find/home-name "*. txt *"-OK ls {}\; # whether the action after finding needs to be interacted #

<Ls.../home/huxiaoming/2.txt>? Yes

/Home/huxiaoming/2.txt

How to batch search folders belonging to some users:

[[Email protected]/] # Find/home-user huxiaoming-type D-ls # Show All without type #

129793 4 drwx ------ 2 huxiaoming 4096 mar 18/home/huxiaoming

[[Email protected]/] # Find/home-user huxiaoming-ls

129793 4 drwx ------ 2 huxiaoming 4096 mar 18/home/huxiaoming

129795 4-RW-r -- 1 huxiaoming 18 Jul 9 2013/home/huxiaoming/. bash_logout

129794 4-RW-r -- 1 huxiaoming 176 Jul 9 2013/home/huxiaoming/. bash_profile

129798 4-RW ------- 1 huxiaoming 25 mar 13 20:11/home/huxiaoming/. bash_history

129797 4-RW ------- 1 huxiaoming 778 Mar 13/home/huxiaoming/. viminfo

129796 4-RW-r -- 1 huxiaoming 124 Jul 9 2013/home/huxiaoming/. bashrc

Grep command

Search for text contained in some files

[[Email protected] ~] # Grep huxiaoming/etc/passwd

Huxiaoming: X: 500: 500:/home/huxiaoming:/bin/bash

[[Email protected] ~] # Grep-r huxiaoming/home

[[Email protected] ~] # Grep-r huxiaoming/etc

/Etc/group: huxiaoming: X: 500:

Grep:/etc/alternatives/JRE/lib/Audio/Default. sf2: no such file or directory

Grep:/etc/alternatives/jre_openjdk/lib/Audio/Default. sf2: no such file or directory

Grep:/etc/alternatives/jre_1.7.0/lib/Audio/Default. sf2: no such file or directory

/Etc/passwd: huxiaoming: X: 500: 500:/home/huxiaoming:/bin/bash

/Etc/shadow: huxiaoming: $6 $ v77h3vfz $ response. zjwvxlauckkzwx3dovx0: 16141: 0: 99999: 7 :::

/Etc/gshadow: huxiaoming :! ::

/Etc/sudoers: user_alias admins = huxiaoming

/Etc/sudoers. tmp: user_alias admins = huxiaoming

Binary file/etc/. sudoers. tmp. SWP matches

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.