DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Debugging Core Dump Files on Linux - A Detailed Guide
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Understanding ldd: The Linux Dynamic Dependency Explorer
  • OpenCV Integration With Live 360 Video for Robotics

Trending

  • How to Convert Between PDF and TIFF in Java
  • The Role of Functional Programming in Modern Software Development
  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  • Key Considerations in Cross-Model Migration
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. How to Make a Symbolic Link on Linux

How to Make a Symbolic Link on Linux

Let's look at how symbolic links work in Linux.

By 
Johnny Simpson user avatar
Johnny Simpson
DZone Core CORE ·
Jul. 11, 22 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
4.4K Views

Join the DZone community and get the full member experience.

Join For Free

Symbolic links are a link on Linux systems that point to another file or folder. It means that navigating to one of these files may run a file that exists somewhere else, or it may bring you to a folder somewhere completely different, based on how it is defined. For example, a symbolic link called /etc/link maybe defined to bring you to /var/www/httpdocs.

Types of Symbolic Links on Linux and Mac

There are two types of symbolic links on Linux systems - hard links, and soft links.

  • Hard links are similar to another name for the same file or directory. They can only exist for files or directories on the same file system.
  • Symbolic/Soft links are like shortcuts to files or directories, rather than direct mappings to them. They can point to files or directories on different file systems.

The type of symbolic link you make can affect how other commands work on Linux on those files or folders. For example, hard links can be useful if we want to easily delete the reference when using commands like rm.

For many basic uses, a symbolic or soft link works. Let's look at how to create them.

How to Create Symbolic Links on Linux and Mac

Creating symbolic links on Linux is relatively straightforward. to do it, we use the ln command. By default, this command only makes hard links. To create a symbolic or soft link, we use the -s command. For example, the below code will make a soft link to /var/name.txt from /etc/name.txt:

Shell
 
ln -s /var/name.txt /etc/name.txt

If the file /etc/name.txt/ already exists, this function will throw an error. Instead, if you still want to make the file, use the -f option to overwrite name.txt:

Shell
 
ln -sf /var/name.txt /etc/name.txt

Symbolic links to directories also work in exactly the same way:

Shell
 
ln -sf /var /etc/fakevar

Removing Symbolic Links

If you find yourself needing to remove an already created symbolic link, just use the unlink command. For example, in our above code, we linked to /var/name.txt from /etc/name.txt. To remove this symbolic link, we could write:

Shell
 
unlink /etc/name.txt

This command will actually remove the symbolic link entirely - so it won't appear in your directory system anymore. So, you can also just simply remove the file using the rm command:

Shell
 
rm /etc/name.txt

Symbolic links are useful shortcuts to other files or directories. They differ from hard links in that hard links refer directly to the same file, and share the same permissions and owners. Symbolic links on the other hand may differ from the file or folder they link to.

Symbolic link Links Linux (operating system)

Published at DZone with permission of Johnny Simpson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Debugging Core Dump Files on Linux - A Detailed Guide
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Understanding ldd: The Linux Dynamic Dependency Explorer
  • OpenCV Integration With Live 360 Video for Robotics

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!