


What is the difference between symbolic links and hard links in linux
Difference: 1. File renaming or file movement will not change the link direction when using a hard link. File renaming or file moving when using a symbolic link will break the link; 2. Hard links can only link files, symbols Links can link files and folders; 3. Symbolic links can be created across different file systems, but hard links cannot be created across different file systems.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What is the difference between symbolic links and hard links in Linux
There are two different types of links in Linux, soft links and hard links. Modify one of them. The hard link points to the node (inode ), the soft link points to the path
Soft link file is also called a symbolic link. This file contains the path name of another file, similar to the shortcut under win
Difference:
File renaming or file moving
File renaming and file moving are both for Linux systems Change of absolute file path. For hard links, file renaming or file movement will not change the link direction, while for soft links, file renaming or file movement will break the link. At this time, when the file content is modified through the soft link, a new one will be created. The new inode is associated with the original file name and file data block.
File deletion
The rm command or the unlink of nodejs actually reduces the number of inode links by 1. For the previous hard link, delete test_hard.txt so that the link number of inode1 becomes 1. When the link number becomes 0, the system will release the inode, and new files created later can use the inode number of the inode. . At this time, there is no inode pointing to the file data block, so the file cannot be found. But in fact, the file data is still stored in the hard disk, so you can often see some tools on the Internet to help recover accidentally deleted files. The number of soft link inode links is 1. If the soft link is deleted, the system will release the inode.
Linking files and folders
Soft links can link files and folders, but hard links can only link files.
Create links in different file systems
Soft links can be created across different file systems, but hard links cannot, because hard links share an inode and different files Systems have different inode tables.
Application scenarios
Hard link
File backup: In order to prevent important files from being accidentally deleted, file backup is a A good idea, but copying files will consume disk space. Hard links can realize file backup without taking up disk space.
File sharing: When multiple people jointly maintain the same file, they can create a hard link in a private directory through a hard link. Everyone's modifications can be synchronized to the source file, but it also prevents one person from accidentally The problem is that if you delete it, you will lose the file.
File classification: Different file resources need to be classified. For example, if a movie is classified as foreign and suspense, then we can create hard links in the foreign folder and the suspense folder respectively, so that Avoid wasting disk space by duplicating movies. Some people may say, isn’t it also possible to use soft links? Yes, but not in a good way. Because once the source file is moved or renamed, the soft link becomes invalid.
Soft link
Shortcut: For files with deep paths, it is not convenient to find them. Use soft links to create shortcuts on the desktop to quickly open and edit files.
Flexible switching of program versions: For programs that have multiple versions on the machine at the same time, you can quickly switch program versions by changing the direction of the soft link. It is mentioned here that switching the python version can be done in this way.
Dynamic library version management: I don’t know much about it, you can read here for details.
Summary
The Linux system manages files through inodes, which store information such as the number of file bytes, file permissions, number of links, and data block locations.
The hard link shares the inode with the source file. Except for the different file name, everything else is the same as the source file. Hard links cannot be created to folders, and hard links cannot be created to files in different file systems.
Soft links are similar to windows shortcuts and have independent inodes. Soft links can be created to folders or files on different file systems.
The modified file contents of hard links and soft links will be synchronized to the source file, because essentially they are all data blocks pointing to the source file.
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of What is the difference between symbolic links and hard links in linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to back up VS Code configurations and extensions? Manually backup the settings file: Copy the key JSON files (settings.json, keybindings.json, extensions.json) to a safe location. Take advantage of VS Code synchronization: enable synchronization with your GitHub account to automatically back up all relevant settings and extensions. Use third-party tools: Back up configurations with reliable tools and provide richer features such as version control and incremental backups.
