当前位置: 代码迷 >> 综合 >> The basics of how to use Linux (如何使用Linux,基础笔记五)
  详细解决方案

The basics of how to use Linux (如何使用Linux,基础笔记五)

热度:91   发布时间:2023-09-30 04:46:35.0

“In the Linux system, any thing is file.” In this blog, we are going to see some commands which can manipulate files, and those operations include “copy”,“move”,“rename”,“create”,“remove” and “create link”.

  1. Before we learn those commands, we need know a feature of Linux, “Wildcards”. “Wildcards” provides special characters to help you rapidly specify groups of filenames, so this feature can make file operations more efficient.

Using wildcards allows you to select filename based on patterns of characters. If you used the “Regular Expression”, you would be familar with this feature.

e.g.
The basics of how to use Linux (如何使用Linux,基础笔记五)
List all files which their name contains “32”.

some patterns and rules are shown below:
The basics of how to use Linux (如何使用Linux,基础笔记五)
The basics of how to use Linux (如何使用Linux,基础笔记五)
The basics of how to use Linux (如何使用Linux,基础笔记五)

  1. Create Directories : “mkdir”

“mkdir” means creating directorie, this command can create one directory or multiple dirs at same time.
e.g. Make a directory
The basics of how to use Linux (如何使用Linux,基础笔记五)
e.g. Make multiple directories
The basics of how to use Linux (如何使用Linux,基础笔记五)

  1. Copy files and directories : “cp”

“cp” can be used by two ways.

3.1. To copy the single file or directory “item1” to file or directory “item2”

The basics of how to use Linux (如何使用Linux,基础笔记五)
e.g.The basics of how to use Linux (如何使用Linux,基础笔记五)

3.2. To copy multiple items (either files or directories) into a directory.
The basics of how to use Linux (如何使用Linux,基础笔记五)

e.g.
The basics of how to use Linux (如何使用Linux,基础笔记五)

Tips: We can use this commands with some options

The basics of how to use Linux (如何使用Linux,基础笔记五)

  1. Move and remove files : “mv”

The “mv” command can move a itme into another item, or we can use it to change item’s name.

4.1. To move or rename file or directory “item1” to “item2”
The basics of how to use Linux (如何使用Linux,基础笔记五)

e.g.
The basics of how to use Linux (如何使用Linux,基础笔记五)

e.g.
The basics of how to use Linux (如何使用Linux,基础笔记五)

4.2. To move one or more items from one directory to another

The basics of how to use Linux (如何使用Linux,基础笔记五)

Tips: We can use this commands with some options
The basics of how to use Linux (如何使用Linux,基础笔记五)

  1. Remove files and Directories : “rm”

The “rm” command is used to delete files and directories.

The basics of how to use Linux (如何使用Linux,基础笔记五)

e.g.
The basics of how to use Linux (如何使用Linux,基础笔记五)

Tips : We can use this commands with some options
The basics of how to use Linux (如何使用Linux,基础笔记五)

  1. Hard link and symbolic link

6.1. A hard link is indistinguishable from file itself. When a hard link is deleted, the link is removed but the contents of file itself continue to exit(that is, its space is not deallocated) until all links to the file are deteted.

Tow limitations of hard link:

  1. A hard link cannot reference a file outside its own file system. This means a link may not reference a file that is not on the same disk portion as the link itself.
  2. A hard link may not reference a directory.

Creat a hard link:
The basics of how to use Linux (如何使用Linux,基础笔记五)

6.2. Symbolic links were created to overcome the limitations of hard links. Symbolic links work by creating a special type of file that contains a text pointer to the referenced file or directory.

A file pointed to by a symbolic link, and the symbolic link itself are largely indistinguishable from one another. For example, if you write some something to the symbolic link, the referenced file is also written to. However when you delete a symbolic link, only the link is deleted, not the file itself. If the file is deleted before the symbolic link, the link will continue to exist, but will point to nothing. In this case, the link is said to be broken.

Create a symbolic link:
The basics of how to use Linux (如何使用Linux,基础笔记五)