Linux link to bin

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

I want to make a symbolic link in Linux. I have written this Bash command where the first path is the folder I want link into and the second path is the compiled source.

ln -s '+basebuild+'/IpDome-kernel/kernel /home/build/sandbox/gen2/basebuild/IpDome-kernel/kernal 

18 Answers 18

To create a new symlink (will fail if symlink exists already):

ln -s /path/to/file /path/to/symlink 

To create or update a symlink:

ln -sf /path/to/file /path/to/symlink 

Here’s a mnemonic for you: l(i)n(k) -s(ymbolic) (the fact that the last parameter is optional helps you figure out that it’s not the target) (btw leaving out the path to the symlink creates a link in the current directory with the same basename as the target)

I spent several minutes trying to figure out why this did not work for me. It created a self-looped link. It seems that the /path/to/file should be absolute and not relative to the «current folder». Perhaps point this out in the answer?

@AbhishekAnand it’s been a couple years, but I just wanted to leave the note that it does work with relative paths; it just needs to be relative to the resulting symbolic link’s directory and not the current directory. What you write as the first path argument is actually, verbatim, the text that’s going to be inside the symbolic link; that’s why, when it’s relative, it must be relative to the link.

Where the -s makes it symbolic.

I like to phrase it this way: ln -s where-the-symlink-should-point where-to-place-the-symlink-itself .

ln -s EXISTING_FILE_OR_DIRECTORY SYMLINK_NAME 

Except it isn’t the new symlink name. It is the name or a full path (relative to cur dir or absolute) for the new symlink including the name.

ln -s EXISTING_FILE_OR_DIRECTORYSYMLINK_NAME and don’t put a trailing slash on the symlink, as it’s not a directory

You can have a look at the man page here:

(Because an ASCII picture is worth a thousand characters.)

An arrow may be a helpful mnemonic, especially since that’s almost exactly how it looks in Emacs’ dired.

And big picture so you don’t get it confused with the Windows’ version

You could also look at these as

The from-here should not exist yet, it is to be created, while the to-here should already exist (IIRC).

(I always get mixed up on whether various commands and arguments should involve a pre-existing location, or one to be made.)

Читайте также:  Горячие клавиши linux mint копировать вставить

EDIT: It’s still sinking in slowly for me; I have another way I’ve written in my notes.

ln -s (target exists) (link is made) mklink (link is made) (target exists) 

In Emacs’ dired , it’s super easy, as you put cursor over your target, press S , and type the directory where you’d like the link to be created. Shortens the gap between imagining the desired result and typing. See gnu.org/software/emacs/manual/html_node/emacs/….

Another mnemonic for ON: ln -s oldname newname , these words are used in the Go OS library too golang.org/pkg/os/#Symlink

ln -s source_file target_file 

that is the opposite definition of «target» compared to man ln , which calls it ln -s TARGET LINK_NAME

'ln -s '+basebuild+'/IpDome-kernel/kernel /home/build/sandbox/gen2/basebuild/IpDome-kernel/kernal' 

This will indeed create a symbolic link ( -s ) from the file/directory:

/home/build/sandbox/gen2/basebuild/IpDome-kernel/kernal 

Here’s a few ways to help you remember:

First, there’s the man page for ln . You can access this via searching «man ln» in google, or just open a terminal window and type man ln and you’ll get the same information. The man page clearly states:

ln [OPTION]. [-T] TARGET LINK_NAME (1st form)

If having to search or read through a man page every time isn’t for you, maybe you’ll have an easier time remembering that all nix commands work the same way :

cp /file/that/exists /location/for/new/file mv /file/that/exists /location/its/moving/to ln /file/that/exists /the/new/link 

cp copies a file that currently exists (the first argument) to a new file (the second argument).
mv moves a file that currently exists (the first argument) to a new place (the second argument)

Likewise ln links a file that currently exists (the first argument) to a new link (the second argument) *

The final option I would like to suggest is you can create your own man pages that are easy to read and easy (for you) to find/remember. Just make a simple shell script that gives you the hint you need. For example ♦ :

In your .bash_aliases file you can place something like:

commandsfx() < echo "Symlink: ln -s /path/to/file /path/to/symlink" echo "Copy: cp /file/to/copy /destination/to/send/copy" >alias 'cmds'=commandsfx 

Then when you need it, from the command line just type cmds and you’ll get back the proper syntax in a way you can quickly read and understand it. You can make these functions as advanced as you’d like to get what what information you need, it’s up to you. You could even make them interactive so you just have to follow the prompts.. something like:

makesymlink() < echo "Symlink name:" read sym echo "File to link to:" read fil ln -s $fil $sym >alias 'symlink'=makesymlink 

* — well obviously they can all take different parameters and do different things and can work on files as well as directories. but the premise is the same
♦ — examples using the bash shell

Источник

It isn’t recommended to mess with /bin and with /usr/bin even though this will work it is somewhat unsafe. Also, you don’t need to place your symlinks there.

I’ve had the same problem like you mentioned. It’s cumbersome to navigate to your scripts and call them like ./myscript each and every time. Here is what I did.

Читайте также:  Linux find which kernel is running

Define your own bin-directory

You can create your own bin-directory and put your scripts there. Create it with

Now you will need to tamper with the PATH environment variable. This is a sensitive area. If you mess up the PATH variable you won’t be able to execute commands with relative paths anymore. If that happens ls might not work any more /bin/ls will still do.

What I’m going to show right now will only affect the current running terminal session. So if anything goes wrong you simply log out with Ctrl + D and everything is like it was before.

echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games export PATH=$PATH:~/bin echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/madmike/bin 

The echo -command shows what’s in $PATH before and after. export allows you to change the environment variable. Your additional bin-directory is appended to the end of the variable. This means your commands have the least priority should there be more than one command with the same name. This is good, since you don’t want to override essential system commands.

To make the changes permanent, edit your ~/.bashrc file.

add export PATH=$PATH:~/bin to the end of that file.

Now every new terminal-session will have the $PATH variable expanded with your directory.

Источник

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?

8 Answers 8

To create a symlink at /usr/bin/bar which references the original file /opt/foo , use:

You would need to apply the above command as root (i.e. with sudo ).

I am using: sudo ln –s /etc/apache2/sites-available/redmine /etc/apache2/sites-enabled/000-redmine getting error: ln: target ‘/etc/apache2/sites-enabled/000-redmine’ is not a directory

The Ubuntu documentation says » Creates hard links by default, symbolic links with —symbolic.» Will the above solution create a symbolic link as asked by OP?

I though César wanted to put his files in the /opt and /usr/bin to have the symbolic link, not other way around.

@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

The error is that you are writing the command wrong. The correct way is

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 

Check the software location by this.

which application-name #replace for the application you are looking for 

To create the soft link. for example you want to create the soft link for skype on your desktop

For more information about ln .

This template was more helpful for me than the above answers. Probably not more correct, just less obfuscated:

Читайте также:  Настройка прокси linux исключения

Just replace the parts in <> ‘s

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

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

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

ln -s /opt/bin /usr/var/New\ Folder 

This is not an answer to the OPs question. Please wait until you have enough reputation to add comments.

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.

You must log in to answer this question.

Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.

Источник

I’m assuming you want to be able to call these executables without typing out the full path each time. Am I right?

Add your folder to the default path, and that’ll do it:

Just create the folder and insure that you have the following in ~/.profile

# set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi 

In Ubuntu 20.04, a user’s ~/.profile file by defaut contains the statement:

# set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi 

Hence all a user has to do is to:

  1. Create the private bin directory. Either via the nautilus GUI or via issuing the command mkdir ~/bin in the terminal.
  2. Reload the ~/.profile file. You do this by typing executing the terminal command source ~/.profile .
  3. Copy and paste your executable into the ~/bin directory or create a link to your executable into the ~/bin directory.

You must log in to answer this question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.17.43536

Ubuntu and the circle of friends logo are trade marks of Canonical Limited and are used under licence.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Оцените статью
Adblock
detector