?
Solved

add softlink to a directory Centos linux

Posted on 2012-03-21
9
Medium Priority
?
872 Views
Last Modified: 2012-03-31
I wish to create a link to /usr/local/apache/htdocs by simply typing in "htdocs" at the prompt. I was reading other sites but I couldn't get it to work. Do I have to be root all the time to make this link work or can I be logged in as my own personal user?

In a related question, I wish to create link to:
/home/vkimura/Downloads/PhpStorm-303/bin/phpstorm.sh by simply typing in at any prompt "pstorm"

Thank you for your help,
Victor
0
Comment
Question by:Victor Kimura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Assisted Solution

by:1ly4me
1ly4me earned 1000 total points
ID: 37751705
Yes you can create soft link to a file and can run under any user.
Create soft link as root user,
#ln -s /home/vkimura/Downloads/PhpStorm-303/bin/phpstorm.sh /pstorm
Make sure the file phpstorm.sh has execute permission for all users. (Generally 755 permission for that file.)

That soft link pstorm, can be executed under any user, for ex for under test user run the file as
#./pstorm not as pstorm
0
 

Author Comment

by:Victor Kimura
ID: 37755164
Hi 1ly4me,

Am I doing something wrong? I changed the permission to 755 for phpstorm.sh

[root@seokingdomheaven vkimura]# ln -s /home/vkimura/Downloads/PhpStorm-303/bin/phpstorm.sh /pstorm
[root@seokingdomheaven vkimura]# pstorm
bash: pstorm: command not found
[root@seokingdomheaven vkimura]# ./pstorm
bash: ./pstorm: No such file or directory
[root@seokingdomheaven vkimura]#  ln -s /home/vkimura/Downloads/PhpStorm-303/bin/phpstorm.sh /pstorm
ln: creating symbolic link `/pstorm' to `/home/vkimura/Downloads/PhpStorm-303/bin/phpstorm.sh': File exists
[root@seokingdomheaven vkimura]# pstorm
bash: pstorm: command not found
[root@seokingdomheaven vkimura]# ./pstorm
bash: ./pstorm: No such file or directory
0
 
LVL 5

Assisted Solution

by:1ly4me
1ly4me earned 1000 total points
ID: 37756345
Type 'pwd' at the command prompt, it will return working directory.
[root@seokingdomheaven vkimura]#pwd
/home/vkimura/  -  It should return something like that.
You have created the soft link on '/' directory, which means on the base directory.

[root@seokingdomheaven vkimura]#cd /    
[root@seokingdomheaven vkimura]#./pstrom

This should work
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:Victor Kimura
ID: 37762465
Hi 1ly4me,

Oh, I see. How can I make the shortcut to work for all directories?
0
 
LVL 5

Expert Comment

by:1ly4me
ID: 37786760
I couldn't get what are you trying to set up?
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 500 total points
ID: 37787192
various solutions:
1. independent from shell (assuming that /home/vkimura/ is in your PATH environment variable)

   ln -s /home/vkimura/Downloads/PhpStorm-303/bin/phpstorm.sh /home/vkimura/pstorm

2. depends on shell:

   # sh and alike
   alias pstorm=/home/vkimura/Downloads/PhpStorm-303/bin/phpstorm.sh
 
   # csh and alike
   alias pstorm /home/vkimura/Downloads/PhpStorm-303/bin/phpstorm.sh

if you want these aliases permanent, you need to add these commands to the proper rc-file of the corresponding shell
0
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 37789970
If htdocs a directory or a command? I'll assume it's a directory and you want to be able to change directory to it by typing just htdocs.
Add this line to .bashrc in your home directory
alias htdocs="cd /usr/local/apache/htdocs"

Open in new window

To link to your pstorm.sh command (and indeed to htdocs if it was a command after all), you need to create a symbolic link in a directory that is in your PATH. You can see what that is by typing echo $PATH or env|grep PATH at the command prompt. Do you have a bin directory in your home directory? If you do, you should see it in PATH. If you don't, you should make one
cd; mkdir bin

Open in new window

Next time you log in, you should see /home/vkimura/bin in the list when you echo $PATH. Now all you have to do is make a symbolic link in the new bin directory
cd ~/bin
ln -s ~/Downloads/PhpStorm-303/bin/phpstorm.sh phpstorm

Open in new window

(Instead of the tilde ("~")you could type /home/vkimura, but the Bash shell will do that expansion for you).
You can do all the above when logged in as yourself - in fact the new commands will only work when you are so logged in. There is no need to change permissions on symbolic links - actually it's impossible to do that.
0
 

Author Closing Comment

by:Victor Kimura
ID: 37790839
Thank you all. That's very helpful.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question