3

I have file in ../new-path/ dir.

lrwxrwxrwx 1 root root   32 Sep  6 19:43 test1.conf -> ../new-path1/test1.conf

When I edit it with Vim using sudo vim test1.conf on under Vim dialog said.

"test1.conf" [Permissions Denied]

how I edit it anyway on symlink using Vim. I really newbie about symlink.

NOTE

I did try this post, it will remove files/folders and symbolic link of course, but I need only remove the symbolic link as an independent file without it removed or it unlinks cause I don't have backup anything.

EDIT1

The output of lsattr $(readlink -f test1.conf)

--------------e---- ./test2.conf
--------------e---- ./default-ssl.conf
lsattr: Operation not supported While reading flags on ./test1.conf

EDIT2

The output of ls -l ../new-path1/test1.conf

lrwxrwxrwx 1 root root 32 Sep 10 14:13 ../new-path1/test1.conf -> ../new-path1/test1.conf

Thanks for anyone advice, Hope anyone can help me.

  • What is the output of lsattr $(readlink -f test1.conf)? – Ravexina Sep 7 '18 at 8:52
  • @Ravexina Edit updated sir – abu-ahmed al-khatiri Sep 7 '18 at 8:55
  • 1
    What are the permissions of ../new-path1/test1.conf ? Please update your question with the output of ls -l ../new-path1/test1.conf. – Soren A Sep 10 '18 at 9:52
2

Your symlink

test1.conf -> ../new-path1/test1.conf

is a dead link. It points to a non-existing directory. You said there's a file below ../new-path/ but the link points to ../new-path1 instead. Fix the link:

ln -fs ../new-path/test1.conf test1.conf

After your edit it got clear that you created a self-referencing symlink from ../new-path1/test1.conf to ../new-path1/test1.conf, i.e. in the directory new-path1 exists a symlink named test1.conf that points to itself. So test1.conf is a symlink to test1.conf which is a symlink to test1.conf which is a … :

pduck@host> ls -L ../new-path/test1.conf 
ls: cannot access '../new-path/test1.conf': Too many levels of symbolic links

Drop that symlink (rm test1.conf) and create it afresh and make it point to an existing file.

| improve this answer | |
  • didn't work sir, i still cannot edit with vim. – abu-ahmed al-khatiri Sep 10 '18 at 7:15
  • if use rm so i remove the file and symbolic file but it's file very important, i don't have backup for that file – abu-ahmed al-khatiri Sep 10 '18 at 10:15
  • The symlink doesn't point to a file. It points to itself. As in test1.conf → test1.conf → test1.conf → test1.conf → test1.conf → test1.conf → test1.conf etc. – PerlDuck Sep 10 '18 at 10:16
  • i did and i lose my test1.conf sir – abu-ahmed al-khatiri Sep 10 '18 at 10:17
2
+50

What is a (soft) symbolic link (short name symlink)?

A symlink is a pointer to a file, which is located somewhere else on your harddrive. Symlinks are used to make your work with files easier. In Windows there are similar pointers called shortcuts, which are used for the desktop, so you don't have to click into a folder to start a program. Instead you put a shortcut on your desktop pointing towards the program inside a folder, located somewhere else on the system.

Symlink does the same thing on linux, BUT it is for the console/the system and has nothing to with Graphics by itself. So programs and users on a linux file system can create these pointers to find files in a more efficient way.

How to create a symlink? How does it work?

I'm in my home folder and will create a testfolder and a testfile.

pwd
/home/simmel

Create folder and file

mkdir testfolder
touch testfolder/testfile

Listing it will show

ls -la testfolder 
total 40
drwxr-xr-x  2 simmel simmel  4096 Sep 11 16:19 .
drwxr-xr-x 88 simmel simmel 24576 Sep 11 16:22 ..
-rw-r--r--  1 simmel simmel     0 Sep 11 16:19 testfile

Now I'll create a symlink in my home folder into the testfolder

pwd
/home/simmel

ln -s testfolder/testfile

ls -la testfile       
lrwxrwxrwx 1 simmel simmel 19 Sep 11 16:24 testfile -> testfolder/testfile

If you have problems accessing a file which is symlinked, always take a look at the file or folder itself and NOT the symlink.

ls -la on the symlink states rwx for everyone, but that is not true at all! You need to take a look at the file inside the folder (see above) which clearly states

ls -la testfolder 
total 40
drwxr-xr-x  2 simmel simmel  4096 Sep 11 16:19 .
drwxr-xr-x 88 simmel simmel 24576 Sep 11 16:22 ..
-rw-r--r--  1 simmel simmel     0 Sep 11 16:19 testfile

That means, the folder can be fully accessed by the user simmel (read, write, execute), the group simmel can only read and execute, so can anybody else on the system. If I change the rights or ownership on the file or the folder, things will be different. So let's say we do soemthing like giving the file to root.

sudo chown root:root testfolder/testfile

ls -la
total 40
drwxr-xr-x  2 simmel simmel  4096 Sep 11 16:19 .
drwxr-xr-x 88 simmel simmel 24576 Sep 11 16:29 ..
-rw-r--r--  1 root   root       0 Sep 11 16:19 testfile

As you can see, the file is now owned by root and changes can only be made by root, but the user simmel still can read it. Let us see what the symlink says, did it change in any way?

ls -la testfile 
lrwxrwxrwx 1 simmel simmel 19 Sep 11 16:24 testfile -> testfolder/testfile

Nope, it is still the same. So don't rely on looking at the symlink itself, take a close look at the target.

In Ubuntu the rights of a symlink do not matter at all (different in BSD e.g.).

A symlink points to a folder and/or file. To get permissions to a symlinked folder/file you need to modify the rights of the folder/file itself.

In other words, if you decide to change the ownership or the mode of a symlink you are going to change the ownership or mode to the folder/file itself.

What happenend with your file?

To be honest I can only guess what happenend. The suggestion of PerlDuck was that you or someone else accidently did this

ln -s testfile testfile

This would be a symlink pointing towards itself. A dead link, because it does not point towards a file somewhere else on the file system, but back to itself. If you are using a coloured terminal you would even see red colour in the terminal, showing you that this link is utterly broken.

BUT, to create such a dead link, there could not have been a file with the same name in the same directory. This does not work.

So I'm still hoping, that your file isn't gone, try to find it.

do

sudo find / -name test1.conf

maybe you are lucky and it is still there.

If you can't find it, your file might be lost forever and you'll have to create a new one.

| improve this answer | |
  • I still don't get it sir, how i unlink testfile -> testfolder/testfile to testfile file without remove it sir, i really a noob sir – abu-ahmed al-khatiri Sep 11 '18 at 14:39
  • i still little confuse sir, how i edit file on symlink using vim if it don't need to unlink sir – abu-ahmed al-khatiri Sep 11 '18 at 14:47
  • how do i unlink without remove it sir? i stiil a noob sir – abu-ahmed al-khatiri Sep 11 '18 at 14:49
  • i did sudo vim file or symlink i still get "permission denied " sir – abu-ahmed al-khatiri Sep 11 '18 at 14:52
  • sudo vim <your symlink name goes here> – s1mmel Sep 11 '18 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.