I am installing p4v in /opt, but /usr/bin is on my path. Is it possible to create a soft or symbolic link for p4v from /opt to /usr/bin, so I can just type "p4v" since /usr/bin is in my path?
-
1http://stackoverflow.com/questions/1951742/how-to-symlink-a-file-in-linux – Dante Aug 08 '16 at 11:21
-
ln -s /path/to/file /path/to/symlink – Mr.Epic Fail Mar 11 '22 at 10:07
8 Answers
See man ln.
To create a symlink at /usr/bin/bar which references the original file /opt/foo, use:
ln -s /opt/foo /usr/bin/bar
You would need to apply the above command as root (i.e. with sudo).
- 2,672
- 27,999
-
2I am using:
sudo ln –s /etc/apache2/sites-available/redmine /etc/apache2/sites-enabled/000-redminegetting error:ln: target '/etc/apache2/sites-enabled/000-redmine' is not a directory– RAJ ... Aug 04 '12 at 07:29 -
@RAJ...: Perhaps an example can help
ln -s /etc/vim/vimrc /home/paf/Copy/Programming/Apps/Tools/Vim– pablofiumara Nov 11 '13 at 18:31 -
1The Ubuntu documentation says " Creates hard links by default, symbolic links with --symbolic." Will the above solution create a symbolic link as asked by OP? – dev May 26 '15 at 05:27
-
5I though César wanted to put his files in the /opt and /usr/bin to have the symbolic link, not other way around. – mishap Nov 26 '15 at 23:41
-
5@mishap is right as far as I'm concerned. It's the other way around. – Daniel Szmulewicz Dec 18 '15 at 17:05
-
Could you explain what is a link that is not symbolic? What is the difference between
ls file ../otherandcp file ../other. I was missing the-soption for quite some time now and got frustrated... – Augustin Riedinger Jun 01 '16 at 07:30 -
@AugustinRiedinger see: http://stackoverflow.com/questions/185899/what-is-the-difference-between-a-symbolic-link-and-a-hard-link and http://askubuntu.com/questions/108771/what-is-the-difference-between-a-hard-link-and-a-symbolic-link – Michał Šrajer Jun 02 '16 at 14:13
-
is this answer not backwards????????? not just for the OP, but for anyone trying to use it??? – Andrew Feb 24 '18 at 02:14
-
@Andrew This is correct for creating a symbolic link
/usr/bin/barthat points to file/folder/opt/foo. Per 'man ln, the target file/folder comes first, then the link name:ln [OPTION]... [-T] TARGET LINK_NAME (1st form)` – kevinmicke Mar 07 '18 at 20:18 -
2@kevinmicke after your explanation finally realized that the explanation of the answer was stated in reverse order from the command, making my brain (and others') read it backwards – Andrew Mar 07 '18 at 21:00
-
Note that target must be absolute not relative paths – Diego Andrés Díaz Espinoza Sep 14 '18 at 01:13
-
NOTE: Pay attention in creating links with relative paths; you must make the target relative to the link itself, not the directory you're running the command. – MAChitgarha Jan 25 '19 at 13:40
The error is that you are writing the command wrong. The correct way is
ln -s /<full>/<path>/<to>/<file> /usr/local/bin
- 54,385
- 721
- 5
- 3
-
-
Thanks, I totally missed that I needed the absolute path to the linked file. – Andy R Jun 14 '19 at 08:58
If the 'p4v' executable is at /opt/bin/p4v, you can simply run:
sudo ln -s /opt/bin/p4v /usr/bin/p4v
sudo chmod ugo+x /usr/bin/p4v
It would be better to add /opt/bin (or wherever the executable is) to your path:
echo "export PATH=\$PATH:/opt/bin" >> ~/.profile
reset
- 37,204
Check the software location by this.
which application-name #replace for the application you are looking for
for example
which skype
output will be this.
/usr/bin/skype
To create the soft link. for example you want to create the soft link for skype on your desktop
ln -s /usr/bin/skype ~/Desktop/
For more information about ln.
man ln
or
ln --help
- 1,948
This template was more helpful for me than the above answers. Probably not more correct, just less obfuscated:
ln -s <path/to/real/file-or-folder> <symlink path>
Just replace the parts in <>'s
- 11,247
- 51
ln -s -n ./TargetDirectory ./Nickname
Note, this works if you both nodes are below you in the same tree. You can use relative notation
- -s command makes it a symbolic link
- -n makes it possible de create a folder-type symlink
- 197,895
- 55
- 485
- 740
-
1Welcome to askubuntu.com. In this case the
$to indicate a command line prompt is a style choice, and not likely to be a problem. However bear in mind that including things in a code block other than the code and its output can cause confusion. – J. Starnes Dec 12 '17 at 00:42
I have found that it is easier to go to where you want the link to be and then create the link using sudo ln -s /path/to/source/file, than doing ln -s target source.
So in your case I would do cd /usr/bin then sudo ln -s /opt/bin/pv4. The other way has not been working in my case.
- 181
- 1
- 3
If it is saying target is not a folder, it means there are spaces in your folder names eg: New Folder has a space
You need to edit the path and add a backslash \ after every space in the paths
eg:
ln -s /opt/bin /usr/var/New\ Folder
-
3This is not an answer to the OPs question. Please wait until you have enough reputation to add comments. – derHugo Nov 09 '17 at 05:59