LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to make a symbolic link on the command line (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-make-a-symbolic-link-on-the-command-line-4175545927/)

wavelength72 06-20-2015 04:40 AM

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!

ButterflyMelissa 06-20-2015 04:44 AM

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...

johnsfine 06-20-2015 04:52 AM

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".

fatmac 06-20-2015 04:55 AM

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.

wavelength72 06-20-2015 05:07 AM

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.

wavelength72 06-20-2015 05:53 AM

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

ButterflyMelissa 06-20-2015 11:22 AM

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


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