Symbolic Link broken after creation - linux

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

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.

cp: target '/root/var/www/html/' is not a directory

I am using Ubuntu windows 10 bash and I'd like to move a project from /mnt/i/Projects/Template to run it on Apache server which located in /var/www/html.
I tried to copy a folder from a direct to new directly but unfortunately I got an error which is:
cp -r /mnt/i/Projects/Template ~/var/www/html/
cp: target '/root/var/www/html/' is not a directory
I would like to test those templates with Apache and I tried to change Apache directly.
Another test I did:
root#DESKTOP-4PBGG1N:/var/www# ls -ld ~/var ~/var/www ~/var/www/html
ls: cannot access '/root/var': No such file or directory
ls: cannot access '/root/var/www': No such file or directory
ls: cannot access '/root/var/www/html': No such file or directory
First of all the directory for the apache server is not in root it's just "/var/www/html". If it still doesn't work you probably doesn't have apache installed, you can do that by running these two lines "lsb_release -a" and "sudo apt-get install apache2". There will come an error when trying to launch the apache server (with "sudo service apache2 start"), but just ignore it you can still use it without any problems. Hope it helps ;)
try creating directory if the only problem is '/root/var/www/html/' not being a directory
# mkdir -pv ~/var/www/html/
# cp -r /mnt/i/Projects/Template ~/var/www/html/
before that just make sure that apache is installed and configured
have a nice day
For instance you have a file in Documents called index.php and to be copied in the /root/var/www/html/ directory you have to do it this way:
First don't forget to use sudo to be super user and then
- sudo cp -Rv index.php /var/www/html or
- sudo cp -Rv index.php /root/var/www/html
And you will get this output: 'index.php' -> '/var/www/html/index.php'
-R for copy folders &
-v for see what folders and files are copied

Ovewrite a symbolic link to your executable JAR file

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

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.

Resources