Authority and content display of Ubuntu file

Time:2021-6-25

File permission and content display

file right

Setting file permissions (character setting method)

Grammar:chmod [who] [+ | – | =] [mode] file name

explain: [who] may be one or a combination of the following characters:

u(user): denotes“user“, and file or directoryowner

g(Group): denotes “group”Users in the same group

o(other): ExpressOther users

a(all): denote “All users

[+ | – | =] :+Indicates to add a permission;It means to cancel a permission;=Indicates that a given permission is granted

[mode]: R (readability), w (writable), X (executable)

✦ character setting method

Example 1: set the properties of test1 as follows: the file owner (U) increases the execution authority, the user in the same group as the file owner (g) increases the execution authority, and other users (o) increases the execution authority.

​ $ chmod a+x test1

Example 2: set the properties of test2 as follows: the file owner (U) increases the execution authority, the user in the same group as the file owner (g) increases the execution authority, and other users (o) delete the write and execution authority.

​ $ chmod ug+w,o-wx test2

Example 3: delete the execution permission of the file test3. The following three commands are available

​ $ chmod a-x test3

​ $ chmod -x test3

​ $ chmod ugo-x test3

Example 4: change the execution permission of file test4 to rwxrw RW.

​ $ chmod u=rwx,g=rw,o=rw test4

✦ numerical setting method

->Numerical calculation: R: 4, W: 2, X: 1

Grammar:Chmod numeric file name

Numerical calculation: if the permission is [- rwxrw ---]
ower=rwx=(111)2=4+2+1=7
group=rw-=(110)2=4+2+0=6
other=---=(000)2=0
Understanding: mode can be divided into three octal digits, and each octal digit is converted into a binary digit,
1 corresponding to give the corresponding permissions, 0 corresponding to cancel the corresponding permissions.

✦ numerical setting method example

Example 1: set the attribute of file AAA as the file owner (U) has read and write permissions, the user (g) in the same group as the file owner has read permissions, and other users (o) have read permissions.

​ $ chmod 644 aaa

Example 2: set the attribute of file AAA as the file owner (U) read / write / executable right, the user (g) in the same group as the file owner (g) read / executable right, and other users (o) have no permission.

​ $ chmod 750 bbb

File content display

cat

cat: view files and display them on the screen

Syntax: cat file name

​ – N displays the line number

​ – A shows all the characters in the file, including hidden characters

more

more: display file contents by page

​ Syntax: more file name

​ ⇨ display after reading the document

​ ⇨ press space to page forward

​ ⇨ Ctrl + F page forward

​ ⇨ Ctrl + B page back

​ ⇨ press Q to exit the viewed file

less

less: display file contents by page

​ Syntax: less file name

​ ⇨ display while reading, start fast

​ ⇨ press space to page forward

​ ⇨ Ctrl + F page forward

​ ⇨ Ctrl + B page back

​ ⇨ press Q to exit the viewed file

​ ▣ less extends the function of the more command

✦ view the first few lines of data in the file: understand the data format in the file

Windows needs to open all the files to see the data

head [-n number] file

-n: Followed by a number, on behalf of the display file several lines of meaning

example: head – N 15 test / / view the first 15 lines of the test file

​ head test // The first 10 lines are output by default

tail

✦ view the data at the end of the file: used to view the system log

tail [-n number] file

-n: Followed by a number, on behalf of the display file several lines of meaning

example: Tail – N 15 test / / view the last 15 lines of the test file

​ tail test // The default output is the last 10 lines