Linux File Operation commands, linux operation commands

Source: Internet
Author: User

Linux File Operation commands, linux operation commands

1

Bytes ----------------------------------------------------------------------------------------------

View directory: ls-a or ls-r

View the log file: cat file name. log
--------------------------------------------------------------------------
Command head, tail, and sed for viewing part of File Content in Linux
Cat, less, more, and vim, which are the most common methods for viewing File Content in Linux

--------------------------------------------------------------------------

2

----------------------------------------------------------------------------------

Delete a folder instance:
Rm-rf/var/log/httpd/access
The/var/log/httpd/access Directory and all files and folders under it will be deleted.


Delete a file instance:
Rm-f/var/log/httpd/access. log

The file/var/log/httpd/access. log will be forcibly deleted.

Bytes ---------------------------------------------------------------------------------------------------

3

Operation File
1: Operate the file $ vi file name
2: after entering the page, move it up, down, left, and right on the keyboard. You can delete it, but you cannot insert it (you cannot enter it) after vi, is in command mode )」
3: Press "I" to enter "Insert mode". Then you can start to enter the text.
4: You can only enter the text all the time. If you find that you have entered the wrong word! To move the word back with the light mark key, you must first Press ESC to switch to command mode and then delete the text.
5: Save and exit in command mode. Click the ":" colon to enter Last line mode. For example:
: W filename (enter "w filename" to save the article with the specified filename)
: Wq (enter "wq" to save the disk and exit vi)
: Q! (Enter q !, Force exit vi without saving the disk)


(
Press ctrl + B to move the screen to the back.
Press ctrl + f to move the screen to the front.
Press ctrl + u to move the screen to the rear half of the page.
Press ctrl + d to move the screen to front.
Press the number "0": to move to the beginning of the article.
Press G to move to the end of the article.
Press "$" to move to "end of line" of the row where the cursor is located ".
Press ^ to move to the first row of the row where the cursor is located"
Press w to jump to the beginning of the next word
Press "e": move the cursor to the end of the next word
Press "B": the cursor returns to the beginning of the previous word
Press # l to move the cursor to the # position of the row, such as 5l and 56l.
)
(
Delete text
"X": deletes the "Next" character at the cursor position every time you press it.
"# X": for example, "6x" indicates deleting the "Next" to the cursor position.
"X": uppercase X. Each time you press it, the "front" character of the cursor is deleted.
"# X": for example, "20X" indicates to delete the "front" of the cursor.
Dd: Delete the row where the cursor is located.
「 # Dd 」: delete from the row where the cursor is located # Row

Copy
"Yw": copy the character at the end of the cursor to the buffer zone.
# Yw: Copy # words to the buffer zone
"Yy": copy the row where the cursor is located to the buffer zone.
"# Yy": for example, "6yy" indicates copying 6 lines of text from the row where the cursor is located "down.
P: place the characters in the buffer to the cursor position. Note: All copy commands related to "y" must work with "p" to complete the copy and paste function.

Replace
"R": Replace the character at the cursor position.
"R": Replace the character wherever the cursor goes until you press the "ESC" key.

)
Certificate ------------------------------------------------------------------------------------------------------------------------------------------------


What are the common linux directory file operation commands?

1. List of the most common commands
The following lists the ten commands that are frequently used in linux. Here is a brief introduction. For detailed usage, refer to the following content.

Cat: displays the file content.

Cd to change the directory path.

Cp, copy the file.

Find to find the file.

Grep: Search and filter information.

Ls to list directory information.

More, display by page.

Rm: delete a file or directory.

Vi: Call the vi text editor.

Who: displays logon user information.

2. chmod ---- change the access mode of one or more files)
Chmod [options] mode files

Only file owners or privileged users can use this function to change the file access mode. Mode can be in the digital format or in the who opcode permission format. Which is optional. The default value is a (all users ). Only one opcode can be selected ). You can specify multiple modes separated by commas.

Options:

-C, -- changes
Only output the information of the changed File

-F, -- silent, -- quiet
When the chmod mode cannot be changed, the file user is not notified.

-- Help
Output help information.

-R, -- recursive
Recursively traverse sub-directories and apply modifications to all files and sub-directories in the directory

-- Reference = filename
Set the permission by referring to the filename permission.

-V, -- verbose
Whether the modification is successful or not, the information of each file is output.

-- Version
Output version information.

Who

U
User

G
Group

O
Others

A
All users (default)

Opcode

+
Add Permissions

-
Delete permission

=
Reassign Permissions

Permission

R
Read

W
Write

X
Run

S
Set the ID of a user (or group)

T
Sets sticky bit to prevent files or directories from being deleted by non-owners.

U
Current User Permissions

G
Current permissions of the Group

O
Current permissions of other users

In most cases, we use three Octal numbers to indicate permissions. The first one is the owner permission, the second is the group permission, and the third is the permission of other users, each permission is determined by the sum of four (read), two (write), and one (execution) values. For example, 6 (4 + 2) indicates that you have the read and write permissions, and 7 (4 + 2 + 1) indicates that you have the read, write, and execution permissions.

You can also set the fourth digit, which is located before the three-digit permission sequence. The fourth digit is 4, 2, and 1, which means the following:

4. Set the user ID during execution to authorize the process based on the file owner, instead of the user who creates the process.

2. Set the user group ID during execution to authorize the process based on the file group, instead of the user who creates the process.

1. Set the adhesion position.

Instance:

$ Chmod u + x file: add the execution permission to the file owner.
$ Chmod 751 the file owner is assigned the read, write, and execute permissions (7) to the file owner, and the read and execute permissions (5) to the file group, assign execution (1) permissions to other users
$ Chmod u = rwx, g = rx, o = x file
$ Chmod = r file: Assign read permissions to all users
$ Chmod 444 file: Same as above
$ Chmod a-wx, a + r is the same as above.
$ Chmod-R u + r directory recursively assign read permissions to the owner of all files and subdirectories in the directory
$ Chmod 4755 sets the ID to assign read, write, and execute permissions to the owner, and assign read and execute permissions to the group and other users.

3. chgrp ---- modify... the remaining full text>

Linux commands

1. cp command
This command is used to copy the given file or directory to another file or directory. It is very powerful like the copy command in MSDOS.
Syntax: cp [Option] source file or directory target file or directory
The options are as follows:
-A this option is usually used when copying directories. It retains links and file attributes, and Recursively copies directories. Its role is equal to the combination of dpR options.
-D: the link is retained during copy.
-F delete an existing target file without prompting.
-I and f options are opposite. A prompt is displayed asking the user to confirm before overwriting the target file. When the answer is y, the target file will be overwritten, which is an interactive copy.
-P in addition to copying the source file content, cp also copies the modification time and access permissions to the new file.
-If the source file provided by r is a directory file, cp will recursively copy all subdirectories and files in the directory. The target file must be a directory name.
-L do not copy, but only link files.
2. mv command
You can use the mv command to rename a file or directory or move the file from one directory to another. This command is like a combination of ren and move in MSDOS.
Syntax: mv [Option] source file or directory target file or directory
The options are as follows:
-I interactive operation. If the mv operation will overwrite the existing target file, the system will ask whether to rewrite the file and ask the user to Answer y or n. This will avoid overwrite the file by mistake.
-F prohibit interactive operations. When an mv operation overwrites an existing target file, no instructions are given. If this option is specified, the I option will no longer work.
3. mkdir command
Function: create a directory (similar to the md command in MSDOS ).
Syntax: mkdir [Option] dir-name
-M sets the access permission for the new directory. You can also set it using the chmod command.
-P can be a path name. If some directories in the path do not exist, after this option is added, the system automatically creates those directories that do not exist, that is, multiple directories can be created at a time.

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.