Iv. Linux/UNIX operating command accumulation [chmod, chown, tail], chmodchown

Source: Internet
Author: User

Iv. Linux/UNIX operating command accumulation [chmod, chown, tail], chmodchown
In Linux/UNIX, users often use the text interface to set the system or operating system. The author is constantly in touch with this command during his work, therefore, this article has been specially developed, prepared, and started. This article mainly records some of the operating commands you encounter in Linux/UNIX at ordinary times, record and sort them out, one can deepen your impression, and the other can be recorded and shared. We hope that you will give instructions and explanations on inappropriate or ambiguous aspects so that you can learn and improve them together.

[For more information, see http://blog.csdn.net/mahoking]

014 Linux chmod command

1 Command Format
Chmod [option] [file] format chmod [option] [file]
2. command functions
The userdel command sets the read, write, and execute permissions for folders (files.
3 common examples
Command description
Syntax structure:

Chmod abc file
A, B, and c represent a number, indicating the permissions of the User, Group, and Other respectively.
R = 4, w = 2, x = 1
If you want the rmx attribute, 4 + 2 + 1 = 7;
If you want rm-attribute, 4 + 2 = 6;
If the r-x attribute is required, 4 + 1 = 5;


Example 01
Command: chmod 777 testFile.txt
Input: [root @ localhost root] # chmod 777 testFile.txt
Note:
Change the read and write permissions of testfile.txt. All users on the local machine can perform all operations on this file.

015 Linux chown command

1 Command Format

Chown [option] [owner] format chown [option] [user]
2. command functions
Use chown to change the owner and group of the file. When changing the file owner or group, you can use the user name and user ID settings. Normal users cannot change their files to other owners. The operation permission is generally administrator.
3 common examples


Example 01

Command: chown mail: mail testLog2014.log
Input: [root @ localhost root] # chown mail: mail testLog2014.log
Note:
Change the owner and group of the file. In this example, the testLog2014.log file is specified to the mail User and mail group. If the command is chown: mail testLog2014.log, The testLog2014.log file is specified to the mail group, and the owner remains unchanged.

Example 02
Command: chown-R-v root: mail testDir

Input:
[Root @ localhost root] # chown-R-v root: mail testDir
The owner of "testDir/log2014.log" has been changed to root: mail.
The owner of "testDir/linklog. log" has been changed to "root: mail ".
The owner of "testDir/log2015.log" has been changed to root: mail.
The owner of "testDir/log2013.log" has been changed to root: mail.
The owner of "testDir/log2012.log" has been retained as root: mail.
The owner of "testDir/log2017.log" has been changed to root: mail.
The owner of "testDir/log2016.log" has been changed to root: mail.
The owner of "testDir" has been changed to root: mail.
Note:
Change the owner and group of all files in the specified directory and Its subdirectories.
-R processes all files in the specified directory and Its subdirectories.
-V displays detailed processing information.

016 Linux tail command

1 Command Format
Tail [option] [file] format: tail [option] [file]
2. command functions
The tail command writes the file to the standard output from the specified point. You can use the-f option of the tail command to conveniently check the changing log file. The tail content of the filename is displayed on the screen and refreshed continuously, so that you can see the latest file content.
3 common examples


Example 01

Command: tail-f fileName
Input: [root @ localhost root] # tail-f fileName
Note:
-F if the input File is a regular File or if the File parameter specifies FIFO (first-in-first-out), the tail command will not terminate after the last specified unit of the input File is copied, instead, read and copy additional units from the input file (when these units are available ). If the File parameter is not specified and the standard input is a pipe, the-f flag is ignored. The tail-f command can be used to monitor the growth of files being written by another process.



Q: What is the difference between the chmod command and the chown command in LINUX?

File/directory permission setting command: chmod

This is one of the most common commands for Linux system administrators. It is used to change the access permissions of files or directories. This command has two usage methods:

Use the text setting method that contains letters and operator expressions

Syntax format: chmod [who] [opt] [mode] File/directory name

Which indicates the object, which is one or a combination of the following letters:

U: indicates the file owner.
G: indicates the same group of users.
O: other users
A: indicates all users.
Opt indicates the operation, which can be:
+: Add a permission.
-: Cancel a permission.
=: Grant the given permissions and cancel the original permissions.
Mode indicates the permission:
R: readable
W: writable
X: executable

For example, to add the read and write permissions for file a.txt to users in the same group:

Chmod g + rw a.txt

Set by number

The number setting rule is simpler: chmod [mode] File Name

The key is the mode value. At first many beginners will be confused. In fact, it is very simple. We regard rwx as a binary number. If there is 1, there is 0, then rwx r-x r--can be expressed:

111 101 100

Convert each three digits into a decimal number, that is, 754.

For example, we want to grant the permission for the.txt file:

Other users in the same group
Readable is yes
Writable is executable

Then, we first obtain the permission string rw-r -- Based on the table above, and convert it to the binary number 110 110 100, and then convert each three digits into a decimal number, we get 664, So we run the following command:

Chmod 664 a.txt

Command name: chown
Permission: root
Usage: chown [-cfhvR] [-- help] [-- version] user [: group] file...
Note: Linux/Unix is a multi-person, multi-job operating system. All archives have owners. Chown can be used to change the owner of an archive. Generally, this command is only used by the system administrator (root). Generally, users do not have the permission to change the owner of another user's archive or change their owner to another user. Only the system administrator (root) has such permissions.
Calculation:
User: user IDgroup of the new owner: user group of the new owner (group)-c: if the owner of the file has indeed changed, the change action is displayed-f: if the archive owner cannot be changed, do not display the error message-h: only the link is changed, not the file that the link actually points to-v: show owner change details-R: perform the same owner change on all files in the current directory and sub-directories (I .e., change one by one in the way of delivery) -- help: show auxiliary description -- version: display version
Example:
Set the owner of the file file1.txt to user jessie of the users Group:
Chown jessie: users file1.txt
Set all files in the current directory and sub-directory owner to user lamport of users Group:
Chown-R lamport: users *... full text>

How to use linux Command chown

Chown [-cfhvR] [-- help] [-- version] user [: group] file...
User: user ID group of the new archive owner: user group of the new archive owner-c: If the archive owner does change, the change action is displayed-f: if the archive owner cannot be changed, do not display the error message-h: only the link is changed, not the file that the link actually points to-v: show owner change details-R: perform the same owner change on all files in the current directory and sub-directories (I .e., change one by one in the way of delivery) -- help: show auxiliary description -- version: display version

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.