LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-20-2015, 04:40 AM   #1
wavelength72
LQ Newbie
 
Registered: Jun 2015
Distribution: F21
Posts: 12

Rep: Reputation: Disabled
How to make a symbolic link on the command line


Hi, the path to one of my folders is pretty long:

cd here/here/here/here/here/here

I was wondering if there's a way to make a link (in a terminal) so I only have to type in:

cd here

to get there

Thanks!
 
Old 06-20-2015, 04:44 AM   #2
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
yep, can be done
make a folder called "here"
mount the folder

Code:
mount --bind /here/there/somewhere/else /here
putt hat in your rc, somewhere, that...depends on your distro...
Edit - an extra entry in the fstab should do...

Last edited by ButterflyMelissa; 06-20-2015 at 04:47 AM.
 
Old 06-20-2015, 04:52 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Code:
ln -s here/here/here/here/here/here there
Read the man page on ln for more info.

Notice I used a relative path (as you did). But you might want an absolute path depending on where the link is and how it is used.

Various mount operations (as Thor_2.0 suggested) might be better alternatives in some situations. But I don't see any hint in your original post that a mount would be better than a symbolic link.

For things you need to type in a lot, using an environment variable, and alias or a script is usually better than a symbolic link or mount:
Code:
export there=/absolutepathto/here
cd $there
That first line should be in some login or bash startup script so you edit it into there once then don't need to type it again.
The word export in that first line may not be necessary, depending on how you use "there".

Last edited by johnsfine; 06-20-2015 at 05:01 AM.
 
1 members found this post helpful.
Old 06-20-2015, 04:55 AM   #4
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan with some Tiny Core, Fatdog, Haiku, & BSD thrown in.
Posts: 5,444

Rep: Reputation: Disabled
In a terminal in your /home directory
Code:
ln -s here/here/here/here/here/here here
then you can just use
Code:
cd here
from your /home directory
then
Code:
cd
on its own will take you back to your /home directory.
 
Old 06-20-2015, 05:07 AM   #5
wavelength72
LQ Newbie
 
Registered: Jun 2015
Distribution: F21
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thanks for the immediate replies.

Thinking things through, perhaps I should tell more.

I have a mounted external HDD. I've already changed all the links to ~/home/Documents (etc) to point to the same folders on the external HDD. I use nemo to get to these folders. The original folders in home are still there and get used sometimes. They're backed up daily to the duplicate folders on the HDD.

The problem I'm facing is that I constantly have to change directories to the external HDD or type in an absolute path to either open something or look at the contents of a folder.

For example, if I want to confirm the naming convention of a folder in my software directory on the external HDD I have to type:

ls /run/media/win7/storage/Software (don't ask me why it's called 'win7' please)

From any prompt location in the CLI, I would simply like to type in:

ls /here/Software to get a directory listing. Similarly, making a directory in Software before wgetting a file and then wgetting the file to that location would be easier if I had some sort of symbolic link too.

Do I have to actually make a folder to represent the location since the location already exists? The external HDD is already auto-mounted on boot.

I am new to this, and trying to move over to the CLI instead of GUI, so please be gentle with your answers and assume I'm a noob who doesn't know how to do anything.

Thanks.

Last edited by wavelength72; 06-20-2015 at 05:08 AM. Reason: spelling errors
 
Old 06-20-2015, 05:53 AM   #6
wavelength72
LQ Newbie
 
Registered: Jun 2015
Distribution: F21
Posts: 12

Original Poster
Rep: Reputation: Disabled
OK. I just used:

Quote:
Originally Posted by fatmac
Code:
ln -s here/here/here/here/here/here there
Which is great, but only works from the home directory. I need it to work from anywhere.

johnsfine,

I'm not sure how to make a batch script or where to put it (F21). Can you give instructions or point to some?

Thanks
 
Old 06-20-2015, 11:22 AM   #7
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
Quote:
I need it to work from anywhere.
The mount does that...
create a script that mounts the folder, and in the future, you can add more stuff...add this to the crontab as @reboot
It is one option, there are more enlightened ones that may have something better than that...
Thor
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can I make a symbolic link that is dynamic link->$HOME/file? croog Linux - General 4 10-14-2012 07:55 PM
how to create symbolic link fr command line kaykav Linux - Newbie 2 11-24-2010 07:46 PM
[SOLVED] Trying to write a command line script that will make symbolic links dave247 Programming 5 10-21-2010 12:24 PM
The command to make a symbolic link Gins Linux - General 10 11-12-2006 01:58 PM
cannot make symbolic link dave`2005 Debian 3 10-08-2005 10:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration