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
Solved

add softlink to a directory Centos linux

Posted on 2012-03-21
9
857 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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.

790 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