Bird Brother Linux private kitchens notes Chapter VI (b)

File content query

Direct access to the file contents

Check the contents of a file can use the command cat / tac / nl.

# [cat|tac|nl] 文件

Difference:
1.cat directly to the output file contents on the screen and output to start from the first line at the bottom
same 2.tal and cat, but is beginning tal output from the first line to the last line in turn
3.nl you can add line numbers to print, the first line can display 1/01/001 ...

Turn Pages inquiry

more

Spacebar: turn Next
Enter: turn next line
/ string: look down the string
: F: shows the currently displayed file name and line number
q: leave
B: turning back

less

Spacebar | [PageDown]: Next turn
[PageUp]: Previous turn
/ string: look down the string
string: look up the string?
Q: leave
g: jump to the first line of
G : Jump to the last line

Intercept file

When the file is too large, too much content, which we can extract a few lines to see.
head (the first few lines removed)

# head [-n number] 文件

-n: representatives from the beginning to display a few lines. So we write the number of numbers, if you want to display in front five rows, then it is

head -n 5 file

tail (lines later withdrawn)

tail [-n number] 文件

number and said the same.
But if you only see the first 11-20 rows it? We can first take the first 20 rows, then take back ten rows. So it is necessary to use the pipeline. Refresher, this line is the pipe symbol "|", referred to the pipeline. (Gab ╭ (╯ ^ ╰) ╮)

head -n 20 文件 | tail -n 20


Non-plain text file od

If we need to see non-text files, such as how to view / h usr / bin / passwd execute this file contents. Since the execution file is usually binary file (binary), if we use those commands to view the above, there will be garbled situation. And view these files, we can use the od command.

od [-t TYPE] 文件
TYPE: 
   a:使用默认的字符来输出
   c:使用ASCII字符来输出
   d[size]: (decimal)使用十进制来输出,每个整数占用 size bytes;
   f[size]: (floating)使用浮点数来输出,每个整数占用 size bytes;
   o[size]: (octal)使用八进制来输出,每个整数占用 size bytes;
   x[size]: (hexadecimal)使用十六进制来输出,每个整数占用 size bytes;


The default file permissions and privileges hide

Default File Permissions: umask

When we create a file or directory, then his authority is how much? This is necessary to use this command umask, and used as follows:

#umask //查看当前默认的权限值
0002


Hidden file attributes

chattr (configuration files hidden attributes)
that, besides the nine rwx permissions, as well as the hidden attribute (really sad), the directive takes effect only Linux file systems Ext2 / Ext3 / Ext4 the other file systems may not fully support the directive (now 9102 years, I do not know do not fully support it ...)

# chattr [+-=] [options] 文件或目录
选项:
+ : 增加某一个参数
- : 移除某一个参数
= : 重新设置参数。  
  
参数(options)
a : 该文件只能增加数据,不能删除数据,也不能修改数据,只有root用户能设定该参数。
i : 该文件不能删除、改名、设定连结,还无法写入或新增数据!只有root用户能设定该参数。
... 
eg: 
# sudo chattr +a file1 //把file1文件设置隐藏属性i
# rm -f test
rm: cannot remove 'test': Operation not permitted //提示不能执行该操作哦,因为设置了隐藏属性i,是不能删除该文件的。



lsattr (show hidden file attributes)
After using chattr hidden attribute set, you can use the lsattr to view it

# lsattr [-adR] 文件或目录
a : 查看隐藏文件属性
d : 如果是目录,仅列出目录本身的属性、而非目录内的文件属性
R : 连同子目录也一并列出


Special file permissions: SUID, SGID, SBIT

In fact, in addition to file permissions rwx, there are special privileges and roles s t, s and t, respectively, into the thirteenth chapter and Chapter XVI Description (in accordance with the schedule I write this blog do not know to wait until these years, I have wanted understanding of child boots went Soso).

Set UID

When this s appears on the owner of the file permissions x, e.g. [-rwsr-xr-x], this time is called Set UID, referred SUID special permissions SUID special features are as follows:

SUID permission only valid binary program
executed by permissions to execute the program needs to have a change of x
during the execution of the present program rights only in the effective
execution of the program will have the rights owners

Set GID

When the flag s flag in the x-belonging group, e.g. [-rwx - s - x], at this time becomes Set GID, referred SGID. For file has the following features:

SGID binary program useful to
implementers need to have the appropriate permissions x
user executes the program will be supported by the program group

For directory has the following features

If the user has the r and x permissions on the directory, you can enter the directory
user in effective group in this directory will become the group's catalog (valid when the user group is to create a file, the file belongs to the default group )
purpose: w If the user has permission to file the new user group established by the same group that directory.

Sticky Bit

Referred SBIT, only valid directories:

Users have for this directory w, x permissions
users to create files in this directory, only you and the root user has permission to delete files.

SUID / SGID / SBIT permissions

4 is the SUID
2 is SGID
. 1 is SBIT

The fifth chapter talked about the command to modify the permissions, as add special permission is as follows:

chmod 4755 filename //这里的4为SUID的特殊权限 后面的755就和以前的一样


Observation File Type: file

If you need to know is what type of a file, for example, belongs to ASCII, binary or other documents. It is to use this type

$ file test_file 
test_file: ASCII text //返回ASCII 的纯文本文件


Search instructions and documents

Instruction inquiry which

$ which [-a] command
-a : 将所有PATH目录中可以知道的指令列出

例如:
$ which service
/usr/sbin/service


Queries find the file name

格式: find [PATH] [option]
$ find /home mtime 0 //查看home目录下24小时之内被修改的文件
$ find /home -user vagrant //查询home目录下用户为vagrant的目录或文件
/home/vagrant
/home/vagrant/.cache
...

$ find /home -name test_file //查询home目录下名为test_file的文件
/home/vagrant/test_file

Epilogue

After seeing Linux Chapter VI Bird Brother, I almost put the article mentioned command has to write on, but something more detailed in the article may not be written here, and I personally feel that writing this article I am more consumption a long time,
the biggest reason is that no matter what commands are written up, anyway, would write the book when it comes. The more I write, the more behind the discovery, the article can not copy the contents of the book, should write the contents of the more commonly used above was more appropriate.
Otherwise I might as well see the article of junior partner to read better, so I could write next articles reality of the more common things as much as possible (I think the common things that may not really used).
Well, after all, write more articles will have accumulated, write faster, but under the circumstances I would quickly ensure the correctness of the content as much as possible.
If deficiencies article, please leave a message or send a message to [email protected] pointed out in the comments section, thank you.

Guess you like

Origin www.cnblogs.com/Johnson-lin/p/10970010.html