Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

add softlink to a directory Centos linux

Posted on 2012-03-21
9
Medium Priority
?
878 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
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 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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

596 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