Linux Fundamentals: 10, basic commands (4)

Source: Internet
Author: User

Query file type and file Location command)


File

Role: View the file type (the file type under Linux does not differentiate after the prefix name)

Syntax: file [options] filename

=================================================================================[[email protected]  ~]# file /etc/passwd/etc/passwd: ascii text                #文本文档 [[email protected] ~]# file /etc/etc:  directory                        #目录文档 [[email protected] ~]# file /bin/ls           #二进制文件/bin/ls: elf 32-bit lsb executable,  intel 80386, version 1  (SYSV), dynamically linked  (uses shared  LIBS), for gnu/linux 2.6.18, stripped[[email protected] ~]# file  test11.gz        #压缩文件test11 .gz: gzip compressed data,  was  "Test11",  FROM&NBSp unix, last modified: thu mar  5 05:30:10 2015========================= ========================================================

which

Function: Search command with

Syntax: which command

PS: Search only under the system-defined path path.

=================================================================================[[email protected] ~]# which Chkconfig/sbin/chkconfig#which can only check commands under PATH variable paths [[email protected] ~]# which Cd/usr/bin/which:no CD in (/usr/local/ Sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin) [[email protected] ~]# type CDCD is a shell builtin #因为此命 Order is a system built-in command, so you cannot find the # extension, path variable in path [[email protected] ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/ sbin:/usr/bin:/root/bin=================================================================================

Whereis

Function: Locates Source/binary and manuals sections for specified files.

Syntax: whereis [options] Keyword

Options:

-B only find files in binary format;

-M only find files under the manual path of the instruction manual file;

-S only find files from source;

-U finds other special files that are not in the above three parameters.

=================================================================================[[email protected] doc]# Whereis Vimvim:/usr/bin/vim/usr/share/vim/usr/share/man/man1/vim.1.gz[[email protected] doc]# whereis-m Vimvim:/usr/share/ Man/man1/vim.1.gz[[email protected] doc]# whereis-b Vimvim:/usr/bin/vim/usr/share/vim============================= ====================================================

Locate

Role: Querying files from a specific database

Syntax: Locate keywords

Installation: Yum install-y mlocate, need to update the database with updatedb command after installation is complete

Database files:/var/lib/mlocate/mlocat.db

================================================================================= #安装locate [[email protected] Doc ]# Yum install mlocate# before use updatedb [[email protected] doc]# Locate Test11.gzlocate:can not stat () '/var/lib/mlocate/ Mlocate.db ': No such file or Directory[[email protected] doc]# Updatedb[[email protected] doc]# locate Test11.gz/root/test 11.gz#db file location [[email protected] doc]# ls-l/var/lib/mlocate/mlocate.db-rw-r-----. 1 root slocate 769272 Mar 15:39/var/lib/mlocate/mlocate.db======================================================= ==========================


Find

Description: The most powerful query tool.

Syntax: Find [-h] [-l] [-p] [-D debugopts] [-olevel] [path ...] [Expression]

An expression:

    • -mtime to change the file content time for the search criteria query file

We agreed in advance to push forward 24 hours from the present time for the 1th day, N=1. And so on the first day and then push forward 24 hours is the 2nd day, n=2 ...

-mtime N-N+1 is a number, meaning to query the first day of the day 24 hours of the contents of the document changed;

-mtime +n: Meaning to query n+1 days ago (without n+1 day itself) has been changed the contents of the document;

-mtime-n: Lists files that have been altered in n days (including the N-day itself);

-newer File:file is a saved file that lists files earlier than the file was modified.



650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5A/DF/wKiom1T-oirDeStgAAAKfO9k6YI413.gif "title=" Find_ Time.gif "alt=" Wkiom1t-oirdestgaaakfo9k6yi413.gif "/>

Excerpt from the bird's-brother tutorial

As you can see, when the n=4

-mtime 4 is the search for the 5th day to change the content of the file;

-mtime +4 is a query 5 days ago To change the content of the file;

-mtime-4 is a file that queries for changes to content within 4 days.

    • -mmin with-mtime, just n does not represent the number of days, represents minutes.

    • -type querying files by file type for search criteria

File type: F (normal file), D (directory file), l (link file), s (socket), p (pipeline), C (character file) and B (block device).

    • -I ignores case of query condition

    • -inum queries the file with the inode number of the file for the query criteria.

    • -maxdepth followed by numbers, the number of layers representing the maximum query path, 0,1,2 ...

================================================================================= #查询家目录一天之内修改过的文件 [[email  Protected] ~]# find . -mtime 0|xargs ls -dldr-xr-x---.  5 root  ROOT  4096 MAR 10 14:50 .-RW-------.  1 root root 12863  mar  9 23:19 ./.bash_history-rw-r--r--.  1 root root    175 mar 10 00:04 ./.bashrc-rw-r--r--.  1 root root    96  MAR 10 01:17 ./CRONTAB.SH-RW-------.  1 root root   129  mar 10 15:52 ./.lesshst-rw-r--r--.  1 root root      8 mar 10 00:23 ./newfile# querying Common Files under the DIR4 directory [[Email protected] ~]# find  ./dir4 -type f|xargs ls -l-rw-r--r--.  1 root root 0 mar   5 04:58 ./dir4/03/test03-rw-r--r--.  1 root root 0 mar  5 04:35 ./dir4/03/ Test4-rw-r--r--.  1 root root 0 mar  5 04:34 ./dir4/dir3/test3# How do I not query the normal files under subdirectories? [[email protected] ~]# find ./dir4 -maxdepth 1 -type f     #由于dir4下面没有普通文件, so empty [[email protected] ~]# find ./dir4 -maxdepth 2 - type f    #当我们向下延伸一层后, can be found on the 2-layer file./dir4/dir3/test3./dir4/03/test03./dir4/03/test4============= ====================================================================

-perm Permissions Detailed

-perm Digital Permissions (3-bit), indicating that the match must match this right strictly

-perm-Digital Permissions (3-bit), indicating that the match must be not less than this permission

-perm/Digital Permissions (3-bit), which indicates that any group in the match Ugo contains any of the normal permissions in the required permission.

-perm/Digital Permissions (4-bit), and 3-bit digital permission rules are the same, except that special permissions and normal permissions are considered separately

-perm+ Digital Permissions (3-bit), has been/replaced

================================================================================= #分别创建不同权限的文件 [[email  protected] ~]# ll perm|awk  ' nr>1{printf ("perm:%-11sname:%s\n", $1,$9)} ' perm:----------     name:001perm:-----w----   name:002perm:---------x     name:003perm:-r--------     name:004perm:---------t    name : 005perm:-r-s------     name:006perm:-------rw-    name:007perm:- --x------     name:017perm:-----w-rw-   name:037perm:----rw-rw-    name:077perm:---x-w-r--    name:177perm:--w-rw-rw-  name:377perm:- rw-rw-rw-  name:777# Find permission 066  that is---rw-rw-[[email protected] perm]# find .  -perm 066 -ls |sed  ' s/[[:space:]]\+/ /g ' |cut -d  '   '  -f  3,11 ----rw-rw- ./077     #只有数字 "066" Match strictly [[email protected] perm]# find . -perm  /066 -ls|sed  ' s/[[:space:]]\+/ /g ' |cut -d  '   '  -f 3,11-----w----  ./002     #/066, as long as the 9-bit permission has all matching R or W---x-w-r-- ./177-------rw- ./007-- w-rw-rw- ./377----rw-rw- ./077-rw-rw-rw- ./777-----w-rw- ./037[[email protected]  perm]# find . -perm -066 -ls|sed  ' s/[[:space:]]\+/ /g ' |cut -d   '   '  -f 3,11--w-rw-rw- ./377     #- 066, as long as no less than 066 permissions are matched----rw-rw- ./077-rw-rw-rw- ./777================================================== ===============================

Stat

Role: View three times

Syntax: Stat file/dir

=================================================================================[[email protected]  ~]# stat test11.gz  file:  ' test11.gz '   Size: 122              Blocks: 8           io block: 4096   regular filedevice: 802h/2050d       Inode: 12133       Links:  1access:  (0644/-rw-r--r--)   Uid:  (    0/    root)    Gid:  (    0/    root) access: 2015-03-10  14:50:52.616930866 +0800Modify: 2015-03-05 05:30:10.555977000 +0800Change:  2015-03-10 14:50:44.910931488 +0800================================================================= ================

PS: Changing CTime does not necessarily change mtime

PS: Change Mtime will be changed CTime


This article is from the "30 Demon People" blog, please make sure to keep this source http://301ren.blog.51cto.com/8887653/1619114

Linux Fundamentals: 10, basic commands (4)

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.