Linux Basics: 8, document properties, basic commands Introduction (3)

Source: Internet
Author: User
Tags syslog

Document properties)

We all know that under Windows, if we want to view the properties of a file or directory file, we can view it by right-clicking on the target file and selecting Properties. Also under the Linux file also has its own attributes, Next is my personal summary on this issue, will be in the most concise way to express.


Document Properties View command: Ls-l

============================================================================[[email protected] ~]#  LS -LTOTAL 40-RW-------.  1 root root  967 feb 13 05:17  anaconda-ks.cfg-rw-r--r--.  1 root root   72 Mar  9  21:42 crontab.shdrwxr-xr-x. 4 root root 4096 mar  5 05:00  Dir4-rw-r--r--.  1 root root 8749 feb 13 05:17 install.log-rw-r--r--.  1 root root 3161 feb 13 05:15 install.log.syslog-rw-r--r--.  1  root root  512 feb 18 19:34 mbr.bin-rw-r--r--.  1 root  Root  183 mar  5 05:30 test11-rw-r--r--.  1 root root    14 mar  5 05:33 test22-rw-r--r--.  1 root root     0 mar  5 05:28 test33[permission bit] [inode number of connections] [main] [group] [size] [mtime] [file name]= ===========================================================================


Let's take "-rw-r--r--. 1 root root 19:34 mbr.bin" as an example


Permission bits

-rw-r--r--. 1 root root 19:34 mbr.bin

[1] [234] [567] [890]

The 1th digit represents the file type:

-Normal file

D catalog File

L Link File

B-Block device file (storage device)

s socket file (for communication)

P Pipe File

...


第2-4位 to represent the owner's rights

R-read;w-write;x-execute corresponding to the "read, write, execute" Three permissions, the owner if you do not have this permission is displayed as "-"


第5-7位 permissions on behalf of a group

R-read;w-write;x-execute corresponding to the "read, write, execute" Three permissions, the owner if you do not have this permission is displayed as "-"


第8-0位 on behalf of other people

R-read;w-write;x-execute corresponding to the "read, write, execute" Three permissions, the owner if you do not have this permission is displayed as "-"


PS: As for the last point of the permission bit, that is the existence of SELinux, if the file has SELinux context is displayed "."

PS: Execute permissions for a directory file, represents whether it is possible to enter the meaning of this directory.


Inode Connection Number

-rw-r--r--. 1 root root 19:34 mbr.bin

Represents the number of files with the same inode number as this file (for inode details, we'll discuss later)


Owner

-rw-r--r--. 1 root root 19:34 mbr.bin

Represents which user this file belongs to


Genus Group

-rw-r--r--. 1 root root 19:34 mbr.bin

Represents which user group this file belongs to


File size

-rw-r--r--. 1 root root 19:34 mbr.bin

The default size is in bytes, and we can use the LS-LH command to let it display units

==================================================================================[[email protected]  ~]# LS -LHTOTAL 40K-RW-------.  1 root root  967 feb 13  05:17 anaconda-ks.cfg-rw-r--r--.  1 root root   72 Mar   9 21:42 crontab.shdrwxr-xr-x. 4 root root 4.0K Mar  5  05:00 dir4-rw-r--r--.  1 root root 8.6k feb 13 05:17 install.log     #不是以字节为单位的会显示单位-rw-r--r--.  1 root root 3.1k feb 13 05:15  install.log.syslog-rw-r--r--.  1 root root  512 feb 18 19:34  mbr.bin        #以字节为单位的依旧不会显示-rw-r--r--.  1 root root   183 mar  5 05:30 test11-rw-r--r--.  1 root root    14 mar  5&Nbsp;05:33 test22-rw-r--r--.  1 root root    0 mar  5  05:28 test33==================================================================================


Mtime

-rw-r--r--. 1 root root 19:34 mbr.bin

File modification (Modify) time


File name

-rw-r--r--. 1 root root 19:34 mbr.bin



Commands related to file attributes)

chmod

Role: Modify file permissions

Grammar

chmod [Options] [u=rwx,][g=rwx,][o=rwx] filename

chmod 744 filename #r =4,w=2,x=1

chmod u+x filename

Options:

-R recursively changes all files under subdirectories and subdirectories.

================================================================================== #chmod  [Options] [u=rwx ,][g=rwx,][o=rwx] filename[[email protected] ~]# chmod u=rwx,g=rwx,o=rwx mbr.bin [[email protected] ~]# ls -l mbr.bin-rwxrwxrwx. 1 root root 512  feb 18 19:34 mbr.bin# can change permissions for a role individually [[email protected] ~]# chmod o=  MBR.BIN[[EMAIL PROTECTED] ~]# LS -L MBR.BIN-RWXRWX---.  1 root  root 512 feb 18 19:34 mbr.bin#chmod 744 filename    personally feel most commonly used [[ email protected] ~]# chmod 700 mbr.bin[[email protected] ~]# ls - L MBR.BIN-RWX------.  1 root root 512 feb 18 19:34 mbr.bin#chmod  u+x filename    very convenient for special cases [[email protected] ~]# chmod g+rw  Mbr.bin[[email proTECTED] ~]# LS -L MBR.BIN-RWXRW----.  1 root root 512 feb 18  19:34 mbr.bin==================================================================================


Chown

Role: Modify the file belongs to the main, belong to the group

Syntax: chown [options] user:group filename

Options:

-R recursively changes all files under subdirectories and subdirectories.

==================================================================================[[email protected]  ~]# LS -L MBR.BIN-RWXRWX---.  1 root root 512 Feb 18  19:34 mbr.bin[[email protected] ~]# chown nagios:nagios mbr.bin[[email  PROTECTED] ~]# LS -L MBR.BIN-RWXRWX---.  1 nagios nagios 512 feb The  18 19:34 mbr.bin# can also be individually altered to belong to the master or group [[email protected] ~]# chown root  MBR.BIN[[EMAIL PROTECTED] ~]# LS -L MBR.BIN-RWXRWX---.  1 root nagios  512 feb 18 19:34 mbr.bin# individually modified genus Group [[email protected]01 ~]# chown : ROOT MBR.BIN[[EMAIL PROTECTED] ~]# LS -L MBR.BIN-RWXRWX---.  1 root  root 512 feb 18 19:34 mbr.bin================================================== ================================

Umask

Function: To control the initial permissions of the new directory file and the normal file by setting the Umask value

Configuration file (Initialize):

Global/etc/profile

Personal ~/.BASHRC # "~" is the home directory meaning

Grammar:

View Umask

Modify umask=022

Principle:

The default full permission for the catalog file is 777 (RWXRWXRWX)

Lose umask 022 (----w--w-), so the new directory file has permission (rwxr-xr-x) 755;

The default full permission for normal files is 666 (rw-rw-rw-)

Umask 022 (----w--w-) is lost, so the new directory file permission is (rw-r--r--) 644.

==================================================================================[[email protected] ~]# umask0022# The first 0 we will introduce later, it represents the special permission bit of umask# create ordinary file [[email protected] ~]# Touch newfile;ls-l newfile-rw-r--r--. 1 root root 0 Mar 00:10 newfile#022+644=666# Create a catalog file [[email protected] ~]# mkdir newdir;ls-ld newdirdrwxr-xr-x. 2 root root 4096 Mar 00:13 newdir#022+755=777===================================================================== =============

PS: The default full permissions for normal files are 666 because normal files do not require execute permissions by default.


Chattr

Role: Set hidden permissions for a file

Syntax: chattr + hide Permissions filename

Hide Permissions:

A This file will only add information, and cannot delete or modify the data, only the root can set this property

I this file will not be able to do content, name, permissions, set the connection file and so on any modification

================================================================================== #隐藏权限a [[email protected ] ~]# cat newfilehi                                           #原内容 [[email protected] ~]# chattr  +a newfile[[email protected] ~]# echo > newfile-bash: newfile:  Operation not permitted    #单纯的修改内容被拒绝了 [[email protected] ~]#  echo good >>newfile[[email protected] ~]# cat newfilehi                                            #成功追加了新内容good #i Hidden permissions I[[email protected] ~]# chattr +i test11[[email protected] ~]# echo  good > test11         #修改内容被拒绝-bash: test11:  permission denied[[email protected] ~]# echo good >> test11         #追加内容被拒绝-bash: test11: permission denied[[email  protected] ~]# rm -rf test11               #删除文件被拒绝rm: cannot remove  ' test11 ':  operation not permitted[[ email protected] ~]# mv test11 testaa            #修改文件名称被拒绝mv: cannot move  ' test11 '  to  ' testaa ':  operation not  permitted==================================================================================



Lsattr

Function: View hidden properties of a file

Syntax: lsattr filename

Options:

-R along with the subdirectory data is displayed together.

-D If a directory is followed, listing the properties of the directory itself, not the file attributes within the directory

================================================================================== #查看文件特殊权限 [[email protected] ~] # lsattr test11 newfile----i--------e-test11-----a-------e-newfile# Delete file special permissions [[email protected] ~]# chattr-i test11[[ Email protected] ~]# chattr-a newfile[[email protected] ~]# lsattr test11 newfile-------------e-test11-------------E-ne wfile==================================================================================


Extended command)

History/!

Function: View and Invoke History commands

Configuration file (number of initialized history records):

Global/etc/profile

Personal ~/.BASHRC

Grammar:

History

!! Executes the previous command

!n executes the nth command in ~/.bash_history

!-n executes the reciprocal nth command in ~/.bash_history.

Keyword Execution keyword match the penultimate command, for example!CP is the last command to execute the CP

================================================================================== #查看命令history [[email  protected] ~]# history|tail  784  ls -l /etc -d  785   ls -d  786  ls -ld /etc  787  ls /etc   788  ls good  789  echo $?  790  ls  newfile  791  echo $?  792  history|grep  793   history|tail #!! Represents the execution of the previous command  #[[email protected] ~]# !! history|tail            #这里显示了真正执行的命令   784   ls -l /etc -d  785  ls -d  786  ls  -ld /etc  787  ls /etc  788  ls good   789  echo $?  790   ls newfile  791  echo $?  792  history|grep  793   history|tail==================================================================================


echo $?

function: To see if the previous command succeeded, 0 succeeded, not 0 failed

================================================================================== #echo $? The result is 0, which represents the previous command execution succeeded [[ Email protected] ~]# ls newfilenewfile[[email protected] ~]# echo $?0#echo $? The result is not 0, representing the previous command execution failed [[email protected] ~]# ls g Oodls:cannot access good:no such file or Directory[[email protected] ~]# echo $?2======================================= ===========================================


!$

Action: The last argument of the previous command, with tab or space as the interval of the parameter.

================================================================================== #情形1 [[email protected] ~]# ls-l /etc-ddrwxr-xr-x. 00:04/etc[[email root root 4096 Mar protected] ~]# ls! $ls-D. #情形2 [[email protected] ~]# ls-ld/etcdrwxr-xr-x. 00:04/etc[[email root root 4096 Mar protected] ~]# ls! $ls/etc ... Content omitted ... #对比情形1和情形2, we can probably understand the role of "!$". ==================================================================================

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

Linux Basics: 8, document properties, basic commands Introduction (3)

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.