A Shortcut for Creating Shortcuts
If you come from the world of Windows, you undoubtedly understand the concept of a shortcut. In the Linux world, shortcuts do exist, but they're generally referred to as symbolic links, or symlinks. They are so named because, like shortcuts, a symlink is really just a symbolic placeholder or link to the file or directory you're trying to get at.
Of course, the world of pretty graphics and windows provides ways of creating symlinks. However, for the impatient, the command line allows you to do the job with less clicking around. Let's have a look at an example.
Suppose I'm working on a Web site, and I want all of the Web site files to be located in /home/jonesy/public_html/websites/testing/site1. I need to have quick access to this directory on a pretty regular basis, so it would be nice to have a shortcut on my desktop so I can get to it in a single click. It also would be nice to be able to drag files to the folder without having to browse to it first.
In this scenario, we call /home/jonesy/public_html/websites/testing/site1 the source directory, and I create that directory using the mkdir command. Follow along at home:
mkdir -p /home/jonesy/public_html/websites/testing/site1
Remember to change jonesy to your own login name.
Again, we've just created the source directory. The mkdir command creates a directory anywhere you have permission to do so. The -p option tells mkdir to create any parent directories along the way that don't already exist.
We call the symlink itself the target, and it points to the source we just created. Note that we can call the target whatever we want. In this case, I just call it site1. To make a link that shows up on my desktop, I open up Konsole and run the following command:
@cx:ln -s /home/jonesy/public_html/websites/testing/site1<\n>/home/jonesy/Desktop/site1
Again, remember to change jonesy in the above command to your own login name.
The ln command can make other types of links besides symbolic links, so it's important to remember to feed it the -s option to let it know that you want to create a symbolic link. Though it happens, it is relatively rare to use the ln command without the -s option, even for hard-core geeks.
For Aspiring Geeks
If you forget the -s option, you'll create what's called a hard link. Though the differences are subtle, they are significant. Depending on the location of the link in relationship to the source, you can generate an error, because hard links cannot cross drive partition boundaries. In the guts of the system, the plain facts are that a hard link is actually just another alternative name for the same bunch of data stored somewhere on the disk (in technical terms, the hard link and the original file would point to the same inode).
But Wait! There's More!
Of course, making a link to a particular file is exactly like making a link to a directory. So, if I want to make a link to my favorite photo (/home/jonesy/Photos/mypic.jpg) on my desktop, I can do it like this:
ln -s /home/jonesy/Photos/mypic.jpg /home/jonesy/Desktop/
I threw in a little trick in the above command. Because I didn<\#213>t want the symlink to have a different name from the file it points to, I simply use a . (period), which is shorthand for saying, don't change the name.
For more information about the ln command, try running
man ln
, which is the manual or man page for the ln command.
About the Author
Brian Jones is a system/network/database administrator and sometime Web developer for the Computer Science Department at Princeton University. He is also a freelance writer and editor, spending most of his freelance time writing about technology for various Web and print publications. In his free time, he enjoys brewing beer, home recording and playing billiards.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- RSS Feeds
- Readers' Choice Awards
- Tech Tip: Really Simple HTTP Server with Python
- DynDNS
3 hours 5 min ago - Reply to comment | Linux Journal
3 hours 37 min ago - All the articles you talked
6 hours 1 min ago - All the articles you talked
6 hours 4 min ago - All the articles you talked
6 hours 5 min ago - myip
10 hours 30 min ago - Keeping track of IP address
12 hours 21 min ago - Roll your own dynamic dns
17 hours 35 min ago - Please correct the URL for Salt Stack's web site
20 hours 46 min ago - Android is Linux -- why no better inter-operation
23 hours 1 min ago



Comments
A Shortcut for Creating Shortcuts
Why not just press and hold Ctrl+Shift keys together while draging a file or a folder to your Desktop.? It will creat a shortcut on the desktop in the same image as the original file and/or folder.
Cheers!
Neb
I found this guide on
I found this guide on shortcuts/symbolic links really useful. OK some of the formatting may be a bit confusing
but if you have any experience with Linux at all it's fine. I have to use Linux more and more for my job and I must admit I feel like I've got 1 hand tied behind my back when I use linux as I have 10 years+ experience with windows. It's frustrating when you know what you want to do but don't know how! Good work :)
minor article issues
Nice, quick introduction to symlinks for beginners. However, I noticed a couple of minor issues.
1. Why did you need to open Konsole to run the first ln command when presumably you already had it open to run the mkdir command?
2. I would also wager there are some formatting issues with the first ls command:
doesn't look quite right (the @cx: at the start ought to be removed and the <\n> in the middle ought to be replaced with a space).
3. Besides the . in the jpeg filename, I don't see the . you're referring to in the explanation of the second ln command.
4. "didn<\#213>t" should probably be "didn't"
Oh, no, please, no
First it was renaming "directories" to "folders" and nowadays noone knows what a directory is.
And now symlinks to shortcuts?
Noooooooooo!