Linux commands to modify files: 1. "vi" or "vim" command, which can be used to modify the content of the file; 2. "mv" command, which can be used to modify the name of the file; 3. "chmod", The "chgrp" and "chown" commands can be used to modify the permissions of the file; 4. The "touch" command can modify the time of the file.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
linux modify the contents of the file
The command is: vi,vim
vi editor, equivalent to Notepad, has editing functions, but weaker
vim is a complex editor, equivalent to Windows editplus, notepad Wait
Steps:
1. Execute vi world.txt to enter the editor (default command mode),
2 , click a or i to enter the editing mode, type: hello linux world!
3. Then press the esc key on the keyboard to exit the editing mode (enter the command mode),
4. Finally, type colon:,
5. Type wq again to save and exit.
Linux changes the name of the file
The command is: mv
mv (full spelling in English :move file) command is used to rename a file or directory, or move a file or directory to another location.
Syntax:
mv [options] source dest
mv [options] source... directory
Copy after login
The format is as follows:
mv source_file(文件) dest_file(文件)
Copy after login
Change the source file name source_file to the target file name dest_file.
linux modify file permissions
The commands are: chmod,chgrp,chown
chmod command
The chmod command is very important and is used to change the access permissions of files or directories. It is used by users to control access permissions to files or directories.
Take a folder named "cc" under the main folder as an example. The following is a step-by-step introduction on how to modify permissions:
1. Open the terminal. Enter "su" (without quotation marks)
2. You will be asked to enter your password next. Enter your root password.
3. Assume that my folder is in the home directory and the address is /var/home/dengchao/cc. Suppose I want to change the file permissions to 777, then enter chmod 777 /var/home/userid/cc in the terminal and the permissions of the folder will become 777.
If you want to modify the permissions of folders and subfolders, you can use chmod -R 777 /var/home/userid/cc
The specific permissions (such as the meaning of 777, etc.) are explained below :
1.777 has 3 digits, the highest digit 7 is to set the file owner access permissions, the second digit is to set the group access permissions, and the lowest digit is to set the access permissions of others.
The permissions of each of them are represented by numbers. Specifically, there are these permissions:
r (Read, permission value is 4): For files, it has the permission to read the file content; for directories, it has the permission to browse the directory .
w (Write, permission value is 2): For files, it has the permission to add and modify file contents; for directories, it has the permission to delete and move files in the directory.
x (eXecute, execution, permission value is 1): For files, the user has the permission to execute the file; for directories, the user has the permission to enter the directory.
2. First, let’s look at how to determine the permission value on a single bit. For example, the highest bit represents the file owner permission value. When the number is 7, 7 is represented by “rwx” – {4 (r) 2(w) 1(x)=7}–And if the value is 6, use “rw-” to represent –{4(r) 2(w) 0(x)=6}–, “-” It means that it does not have permission, here it means that it does not have "execution" permission.
If we set the access rights of other users to "r–", the value is 4 0 0 = 4
Many beginners will be confused at first, but it is actually very simple. Treat rwx as a binary number. If it is present, it is represented by 1, and if it is not, it is represented by 0. Then rwx can be represented as: 111
, and 111 in binary is 7.
3. Let’s take a look at how to determine the permissions on 3 digits. If we want to set permissions for a file, the specific permissions are as follows:
The file owner has "read", "write", and "execute" permissions, group users have "read" permissions, and other users have "read" permissions. "Permissions, the corresponding letters are expressed as "rwx r– r–", and the corresponding numbers are 744
Generally, the highest digit represents the file owner permission value, the second digit represents the group user permission, and the lowest bit indicates other user permissions.
The above is the detailed content of What are the commands to modify files in Linux?. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn