Solved

add softlink to a directory Centos linux

Posted on 2012-03-21
9
838 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
9 Comments
 
LVL 5

Assisted Solution

by:1ly4me
1ly4me earned 250 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 250 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
 

Author Comment

by:Victor Kimura
ID: 37762465
Hi 1ly4me,

Oh, I see. How can I make the shortcut to work for all directories?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 125 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 34

Accepted Solution

by:
Duncan Roe earned 125 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now