Ls: Cannot Read Symbolic Link 'documents and Settings': Permission Denied
What is Symbolic link in Linux and why is it used?
A symbolic link, also known as a symlink or a soft link , is a special type of file that simply points to another file or directory but like shortcuts in Windows. Creating symbolic link is like creating alias to an actual file.
If you try to admission the symbolic link, you actually access the target file to which the symlink points to. Changes performed on the content of the link file changes the content of the actual target file.
If you employ the ls command with choice -l, this is what a symbolic link looks like:
lrwxrwxrwx i abhishek abhishek 23 Jul 2 08:51 link_prog -> newdir/test_dir/prog.py
In about Linux distributions, the links are displayed in a unlike color than the residual of the entries and then that y'all can distinguish the links from the regular files and directories.
Symbolic links offer a convenient way to organize and share files. They provide quick access to long and confusing directory paths. They are heavily used in linking libraries in Linux.
Now that y'all know a footling about the symbolic links, permit'south see how to create them.
How to create a symbolic link in Linux
To create a symbolic link to target file from link proper name , you can utilise the ln command with -s option like this:
ln -south target_file link_name
The -s option is important here. It determines that the link is soft link. If you don't utilise it, information technology will create a hard link. I'll explain the difference between soft links and difficult links in a different commodity.
Things to keep in listen about symbolic links
Symbolic links could be confusing at times therefore you should keep note of a few things.
Changes made to link are reflected in the original file
That'due south the whole purpose of the links after all. You access the target file by accessing the link. You tin can make changes to the target file through the links. Permit'south see with example.
I accept a file prog.py in newdir/test_dir. It has the following attributes:
-rw-r--r-- i abhishek abhishek 163 Apr 13 15:07 newdir/test_dir/prog.py
At present, I'll create a soft link to this file in my present directory:
ln -due south newdir/test_dir/prog.py link_prog
Here are the attributes of the newly created link:
lrwxrwxrwx 1 abhishek abhishek 23 Jul 2 08:51 link_prog -> newdir/test_dir/prog.py
Observe the 50 (information technology's L, not ane) at the offset of the line? If yous are familiar with the file permissions in Linux, you lot would know that the '50' signifies link and thus it tells you lot that this file is actually a link. To refresh your memory, – means file, and d means directory.
At present if I use this link to alter the content or the attributes, the same will be reflected in the target file. For instance, I am using touch control on the soft link and you'll notice that it changes the timestamp of the target file.
impact link_prog ls -l newdir/test_dir/prog.py -rw-r--r-- one abhishek abhishek 163 Jul 2 ten:04 newdir/test_dir/prog.py
Does information technology link to a file or a directory? Yous may not know!
How would y'all know if the link points to file or a directory? You lot cannot know that until y'all follow the path and access the target file itself.
You can create links to non-real file or directory
Yes, that's totally possible. This is why you should be careful while creating soft links in Linux. The target file to which yous are linking doesn't need to be. You won't become any mistake or alarm for creating link to a file/directory that does non exist.
You'll get error only when y'all endeavour to access the target file, either through the link or on its own. The ls command volition still piece of work though.
ln -southward non_existant_dir link_dir less link_dir link_dir: No such file or directory
The symbolic links are created with 777 permission simply information technology means zero
Did yous observe the file permission on the symbolic link? The symlinks are ever created with 777 permission (rwxrwxrwx). For regular file, this would mean that anyone can access the file. But that's not the case for the links.
lrwxrwxrwx 1 abhishek abhishek 23 Jul 2 08:51 link_prog -> newdir/test_dir/prog.py
If the file permissions on the links were treated as it is, whatever user could create a symlink to a secure file and access it freely. That would exist a major security outcome. Thankfully, that doesn't happen. Because the permission on the target files matter, not the permission on links.
You lot may use the chmod command to change the permission on the link simply it will alter the permission of the linked file, non the link itself.
You tin link to a link of a link aka chained symbolic link
You can brand a symbolic link that points to another link and and then on. This is called chained symbolic link. Information technology'south meliorate to avoid them as it creates more than confusion.
Well, that's information technology. I presume you have a better knowledge of the soft links now and you lot know how to create symbolic links in Linux. You lot may read about the symlinks command that can assistance you find broken symlinks in Linux and manage them easily.
If you have questions or suggestions, please get out a annotate beneath.
durkinstrajamoned88.blogspot.com
Source: https://linuxhandbook.com/symbolic-link-linux/
0 Response to "Ls: Cannot Read Symbolic Link 'documents and Settings': Permission Denied"
ارسال یک نظر