Encyclopedia of Linux Common Commands ---> File Processing Commands (1)

File processing commands

1. Command format and directory processing command ls

Command format: 命令 [-选项] [参数]
Example: ls -la /etc
 
 
Explanation:
(1) Individual commands are for your use and do not follow this command
(2) When there are multiple options, they can be written together
(3) Simplified options and complete options -a is equal to -all
 
 
                        directory processing command: ls
 
command name: ls
command English original meaning:
the path of the list command: /bin/ls
execution authority: all users
Function description: display directory files
Syntax: ls option [-ald] [file or directory]
option:
        -a display all files, including Hidden files
         -l Detailed information display
        -d View directory attributes
 
 
 
Give a chestnut:

Insert picture description here
The above picture can be divided into seven parts:

The first part: the file type and permissions are divided into two parts. The first character is divided into one part, which represents the type of a file (owner, group, others). Common file types:-stands for file d stands for a directory l stands for
uncommon file types for soft connections : character device files, block device files, socket files, pipe files are system special files, generally not used To proceed.
The second part: the pending reference count, which represents how many times the file has been called or referenced. This reference count is only useful for files and directories in the hard link.
The third part: the owner of the file. The
fourth part: the group to which the file belongs. The
fifth part: the size of the file-h (human) humanized display size. The
sixth part: the time when the file was last modified. Creation time) Linux has no concept of creation time. There are access time, last access time, file status modification time, file data modification time, if a file has not been modified, it is the file creation time.
Part 7: File name

Tips:
(1) The execution permission x is the highest permission for the file. It is good if the permission is enough. As long as it is enough to use, the maximum permission is not given. Generally, it is enough to read and write the file. When running (when it is a command or a script), if it is a log, it is not necessary. The first three represent the permissions of the owner, and so on

(2) If you want to see the attributes of a directory, use the -d option. -ld used together.
For node i, each file and directory has its own id number, and the system relies on this index number to search and query this file. ls -i (inode) see the i node of the file

Small summary:

ls -a (you can see hidden files) -l (detailed information of the file) -d (see the detailed information of the directory) -h (humanized display size) -i (can query the i node of any file)
 
 
 

2. Directory processing commands

2.1 mkdir command

Directory processing command: mkdir
command English original meaning:
path of the make directories command: /bin/mkdir
execution authority: all users
Syntax: mkdir -p [directory name]
Function description: create a new directory
                  -p
 
 
What is recursive creation? ? ? For example: mkdir /tmp/test/abc Because there is no test directory, but you want to create a subdirectory under this directory, you must add the -p option. (Recursive creation)
 
 
 

2.2 cd command

Directory processing command: cd
command English original meaning: change directory
command path: shell built-in command
execution authority: all users
syntax: cd [directory]
function description: switch directory
 

For example:
cd /tmp/test switch to the specified directory
cd… back to the previous directory
  
 
 

2.3 pwd command

Directory processing command: pwd
command English original meaning: print working directory
command path: /bin/pwd
execution authority: all users
syntax: pwd
function description: display the current directory
 
 
 

2.4 rmdir command

Directory processing command: rmdir
command English original meaning: remove empty directories
command path: /bin/rmdir
execution authority: all users
syntax: rmdir [directory name]
function description: delete empty directories
 

Tips:
(1) If you want to create a directory in Windows, you can only create one directory, and you can create multiple directories under the Linux command line.
(2) rmdir can only delete empty directories. If there are contents in the directories, they cannot be deleted. So I don't use it much because it's too vegetable.
 
 
 

2.5 cp command

Directory processing command: cp
command English original meaning:
path of copy command: /bin/cp
execution permission: all users
Syntax: cp -rp [original file or directory] [target directory]
        -r copy directory
        -p retain file attributes
Function description: copy
 
 
Tips for files or directories :
(1) If you copy files, you can directly hit the cp command to copy multiple files at the same time. If you copy a file to another location, it is equivalent to creating a new file in another location, so the final time will change.
If you make a backup of a log and don't want the last change time of the file to change, you can add an option -p (you can save the attributes of the copied file) and you can change the name when you can copy it.
(2) If it is a directory, add an option -r
 
 
  

2.6 mv command

Directory processing command: mv
command English original meaning:
path of move command: /bin/mv
execution permission: all users
Syntax: mv [original file or directory] [target directory]
Function description: cut file, rename
 
 
Tip: you can cut one Or multiple directories and files, this is different from cp, mv does not need to add the -r option.
 
 
 
 

2.7 rm command

Directory processing command: rm
command English original meaning:
path of remove command: /bin/rm
execution authority: all users
syntax: rm -rf [file or directory]
          -r delete directory
          -f mandatory execution
Function description: delete file
 

Tips:
(1) Windows has two chances to return: when you clear the recycle bin when you delete a file
(2) There is only one chance in Linux (without -r) if you delete it, can you recover it? Recovery software is available, but depending on the situation, not all deletions can be recovered. If you want to delete a directory, you need to add the option -r.

Tips:
(1) Before deleting any files, make corresponding backups.
(2) Once the accidental deletion is found, try not to do too many read and write operations on the hard disk after confirming the situation, including searching, etc. The more read and write operations you do, the less likely it is to recover.
(3) It is best not to happen.
 
 
 

3. File processing commands

3.1 touch command

File processing command: touch
Command path: /bin/touch
Execution authority: All users
Syntax: touch [File name]
Function description: Create empty file
 

Tip: If you want to add a file name with spaces when creating a new file, you need to enclose it in double quotes, otherwise it is equivalent to creating two files
 
 
 

3.2 cat command

File processing command: cat
Command path: /bin/cat
Execution authority: all users
Syntax: cat [file name]
Function description: Display file content
                  -n Display line number (number)
Tip: If it is a very long file, use more Come to view, but you can't turn up. This is also a shortcoming of cat.
 
 
 

3.3 tac command

File processing command: The tac
path where the command is located: /usr/bin/tac
Execution authority: all users
Syntax: tac [file name]
Function description: Display file content (reverse list)
 

Tips: Without the parameter -n, the number of lines cannot be displayed
 
 
 

3.4 more command

File processing command: more
the path where the command is located: /bin/more
Execution authority: all users
Syntax: more [file name]

Operate in the text:
  (space) or f to turn page
 (Enter) to wrap
 q or Q to exit
Function description: display the content of the file in pages
  
Disadvantages: you can not turn pages up, the less command solves this defect.
 
 

3.5 less command

File processing command: less
Command path: /usr/bin/less
Execution authority: all users
Syntax: less [File name]
Function description: Display file content in pages (page up)

Tips: Less can turn the page up, and some functions of more are basically available. You can also use the up arrow of pgup to operate and search function: /Search keywords and press n (next) to search down.
 
 
 

3.6 head command

The above commands are used when browsing the full text. If you only want to see the first few lines or the last few lines, you can use the head and tail commands.
 
File processing commands: head
Command path: /usr/bin/head
Execution permission : Head [file name]
Function description: Display the first few lines of the file
                  -n Specify the number of lines
 
 
Tip: If head does not specify the first few lines, and directly use head to add the file name, the first ten lines will be displayed by default
 
 
 

3.7 tail command

File processing command: tail
Command path: /usr/bin/tail
Execution authority: all users
Syntax: tail [File name]
Function description: Display the next few lines of the file
 -n Specify the number of lines
  -f Dynamically display the end of the file
 
 
Tips: tail If the number of lines is not specified, the last ten lines are also displayed by default. Add -f to display the content dynamically. If the log changes, then the content will be displayed in real time.
 
 
 

4. Link commands

4.1 ln command

File processing command: ln
Command English original meaning:
Path of link command: /bin/ln
Execution authority: All users
Syntax: ln -s [Original file] [Target file]
-s Create soft link
Function description: Generate link file for
 
 
example:
ln -s /etc/issue /tmp/issue.soft Create a soft link to the file /etc/issue /tmp/issue.soft
ls /etc/issue /tmp/issue.hard Create a hard link to the file /etc/issue /tmp /issue.hard
 
 
 

4.2 Soft Link Features

1. lrwxrwxrwx l stands for soft link
2. The file is not big because it is just a link file
3. /tmp/issue.soft -> /etc/issue The arrow points to the source file. When you query with ls -l, you can see the source file who is it.
 
 
Tips: The soft link file is equivalent to a shortcut in Windows. The permissions of the connection file are all rwx, (the newly created soft connection files are all rwx) files that everyone can operate, but this permission does not determine the permissions of the original file, similar to windows shortcuts, it is convenient and quick to find frequently used files Things to facilitate planning and management. Soft connections are still used more, and the file size is still relatively small.
 
Take a chestnut: soft connection is similar to that in Windows, it is equivalent to giving you the directory of D drive as a shortcut on a desktop, which is convenient to enter the directory to find files
  
 
 

4.3 Characteristics of hard links

1. Copy cp -p + synchronous update. For example, enter the content echo "www.lampbrother.net" >> /etc/issue in the source file, and the hard link file will also display the content.
2. Recognize by i-node
3. Cannot cross partitions
4. Cannot use tips for directories
 
 
:

(1) How to distinguish hard link files? ? ? (The i-node of the hard-linked file is the same as the original file), which can be distinguished by the ls -i option. A file has only one i-node, and an i-node corresponds to more than one file. A hard link is a chestnut, and an i-node maps to multiple If one file is deleted, the other file still exists. This is different from soft link. Why can hard links be updated synchronously? ? ? When writing to a file, the operation is performed at the kernel level. In fact, it is aimed at the i node. Because this i node is mapped to these two files at the same time, it can be updated simultaneously.

(2) Hard links are rarely used in Linux, and there are not many application scenarios. If you write a script on the Linux server, if you do not finish writing halfway, entrust someone to generate a hard link and store it in it. In frequently used directories, one can be updated synchronously, and the other is equivalent to making a backup (to prevent accidental deletion by the client).
 
 
 

4.4 The obvious difference between soft link and hard link

 
(1) Hard links cannot cross partitions, and soft links can cross partitions.

(2) Hard links cannot be used for directories, soft links can be used for directories

Guess you like

Origin blog.csdn.net/weixin_46818279/article/details/108374662
Recommended