Ovewrite a symbolic link to your executable JAR file - linux

I want to create or ovewrite a symbolic link to a executable JAR file:
sudo ln -s /var/elcor/elCorApp-1.0.0-SNAPSHOT.jar /etc/init.d/elcor
ln: failed to create symbolic link '/etc/init.d/elcor': File exists
but the file already exists

Use ln -sf:
The -f or --force is used to update a link's target or destination.
So should be
sudo ln -sf /var/elcor/elCorApp-1.0.0-SNAPSHOT.jar /etc/init.d/elcor

Related

Flutter for fedora 37

I'm trying to install flutter on Fedora 37 with snapd but it's not working. Whenever I try to use the command:
sudo snap install flutter --classic
I get the error:
Classic confinement requires snaps under /snap or symlink from /snap to /var/lib/snapd/snap.
Then I run the command:
sudo ln -s /var/lib/snapd/snap /snap
I get the error:
Failed to create symbolic link "snap/snap": File exists.
How do I fix this or find another way to use flutter on Fedora 37?
[ninal#fedora ~]$ sudo ln -s /var/lib/snapd/snap /snap
ln: failed to create symbolic link '/snap/snap': File exists
[ninal#fedora ~]$ sudo snap install flutter --classic
error: cannot install "flutter": classic confinement requires snaps under /snap
or symlink from /snap to /var/lib/snapd/snap
[ninal#fedora ~]$
Sudo or not, ln -s will always fail if the link file already exists. In order to overwrite there is a --force option you can use overwrite an existing link file.
However, the error message "snap/snap": File exists. indicates that you already have a directory named /snap in which a new snap symlink is attempted to be created.
So ln behaves in two different modes, either the last argument is the name of
the link file or
a directory where the link file is to be created within
$ cd /tmp
$ mkdir -p a/b/c
$ ln -s /tmp/a/b # First time, create "b" symlink in /tmp
$ ln -s /tmp/a/b # Second time, fails since symlink exists
ln: failed to create symbolic link './b': File exists
$ ln -sf /tmp/a/b # Succeds, overwrites existing symlink
$ mkdir c
$ ln -s /tmp/a/b/c c # First time, create "c" symlink inside /tmp/c directory
$ ln -s /tmp/a/b/c c # Second time, fails since symlink exists
ln: failed to create symbolic link 'c/c': File exists
$
For your particular scenario you need to get rid of the existing /snap directory to create the expected symlink.
sudo mv /snap /snap.old
sudo ln -s /var/lib/snapd/snap /snap

How can I create a soft link(symbolic link) under /sys/kernel/config/nvmet/ports?

Since I am trying to configure the NVMet-RDMA target on the server, I want to create a symbolic link by the following command(according to https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_storage_devices/overview-of-nvme-over-fabric-devicesmanaging-storage-devices#setting-up-nvme-rdma-target-using-nvmetcli_nvme-over-fabrics-using-rdma):
sudo ln -s /sys/kernel/config/nvmet/subsystems/testnqn /sys/kernel/config/nvmet/ports/1/subsystems/testnqn
but this command returns errors like "argument invalid". What should I do?
don't put the name of the file in the target link argument:
sudo ln -s /sys/kernel/config/nvmet/subsystems/testnqn /sys/kernel/config/nvmet/ports/1/subsystems/
it will have the same name of the original.

Symbolic Link broken after creation

The links get broken right after I create them.
I use ln correctly. ln -s SOURCE TARGET
Create symbolic link
$ sudo ln -s ./sites-available/examble.domain.com ./sites-enabled
Compile NGINX - fails due to broken symbolic links
Note: The problem is not related to NGINX, NGINX compilation was just there to help me realize that the problem exists. The solution described below applies to any other related problem.
$ sudo nginx -t
nginx: [emerg] open() "/etc/nginx/sites-enabled/example.domain.com" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62
nginx: configuration file /etc/nginx/nginx.conf test failed
Confirm that the symbolic links are broken
$ file ./sites-enabled/example.domain.com
./sites-enabled/example.domain.com: broken symbolic link to ./sites-available/example.domain.com
The problem is that SOURCE is not re-interpreted when placed to the target directory.
So, if your file that you want to link is ~/file and you want to link it to ~/folder using:
ln -s ./file ./folder/
Then the symbolic link will think that file is at ~/folder/file instead of ~/file
So, instead, you have to get into the directory ~/folder and execute the ln command from there.
So, Problem is ...
ln needs the relative SOURCE directory to TARGET directory. Not the relative SOURCE directory to your current one.
Final Solution
# Getting into the folder
cd ./sites-enabled
# Creating symbolic link
ln -s ../sites-available/example.domain.com ./

My first app run an ASP.NET core on ubuntu linux, failed to create symbolic link error?

I have been trying to follow this tutorial.
How to Run an ASP.NET Core on Linux
I am getting an error at this stage :
sudo ln -s /etc/nginx/sites-available/hellomvc.com.conf /etc/nginx/sites-enabled/
error is
ln: failed to create symbolic link './hellomvc.com.conf': File exists.
What does it mean ?
Man is your friend
When discovering a new command like ln, it could be interesting to look at the manual:
man ln
It would have told you that ln -s create a symbolic link to a file.
Unix: Everything is a file
Even symbolic link is a file and obviously it means that if a file with the same name exists already in the same directory, ln won't overwrite it and will fail with a File exists. error.
If you want to execute the command at each build and create the link when there is no link already created, you should use test or [:
if [ ! -f /etc/nginx/sites-enabled/hellomvc.com.conf ]
then
sudo ln -s /etc/nginx/sites-available/hellomvc.com.conf /etc/nginx/sites-enabled/
fi
By the way, it only checks that a file with the given name already exists and it doesn't check that the target of the link is the expected one.

How to link a directory A to /var/www/root like below?

How to do the trick?
UPDATE
I did ln -s A /var/www/root by mistake,how to undo it?
You need to use the ln command to create a link. By default such a link is a hard link. Since you cannot create a hard link to a directory you need to create a symbolic link by using the -s option.
ln -s /var/www/root A
So, try: ln -s /var/www/root A
Use a symbolic link:
ln -s /var/www/root A

Resources