Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check if there are symbolic links pointing to a directory?

Tags:

linux

symlink

I have a folder on my server to which I had a number of symbolic links pointing. I've since created a new folder and I want to change all those symbolic links to point to the new folder. I'd considered replacing the original folder with a symlink to the new folder, but it seems that if I continued with that practice it could get very messy very fast.

What I've been doing is manually changing the symlinks to point to the new folder, but I may have missed a couple.

Is there a way to check if there are any symlinks pointing to a particular folder?

like image 668
nickf Avatar asked Sep 19 '08 07:09

nickf


People also ask

Can a symbolic link point to a directory?

Symlink, also known as a symbolic link in Linux, creates a link to a file or a directory for easier access. To put it in another way, symlinks are links that points to another file or folder in your system, quite similar to the shortcuts in Windows.

How do you tell if a folder is a symbolic link Windows 10?

In Command Prompt, run this command: dir /AL /S c:\ A list of all of the symbolic links in the c:\ directory will be returned.

How do I find only directories and soft links in a particular directory?

The first way is by using the ls command in UNIX which displays files, directories, and links in any directory and the other way is by using UNIX find command which has the ability to search any kind of file e.g. file, directory, or link.

How to tell if a folder is a symbolic link?

The folder icon will be different. The icon of the folder would have an arrow. The output of ls -l will clearly indicate that the folder is a symbolic link and it will also list the folder where it points to. $ ls -l total 4 drwxr-xr-x 2 t domain users 4096 mai 24 15:56 original lrwxrwxrwx 1 t domain users 8 mai 24 15:56 symbolic -> original

What is a symbolic link in Linux?

Here symbolic is a symbolic link pointing to original folder. The starting l in lrwxrwxrwx represents a symbolic link, while d represents folder ( directory ), and - represents file. readlink -f /usr/lib/jvm/jre-9 /usr/lib/jvm/java-9-openjdk-9.0.4.11-6.fc28.x86_64

What are symlink links (symlinks)?

Symbolic Links (Symlinks) are essentially shortcuts to another file or folder. If you are using a lot of symbolic links, you may want to quickly render a complete list of them for reference. Here’s how. What Are Symbolic Links? What Are Symbolic Links? RELATED What Are Computer Files and Folders?

How to programmatically check if an object is a directory?

You'll note my ~/vids is a symbolic link to my ~/Videos/ directory If you want to check programmatically whether a given object is a plain directory or a symbolic link to a directory you may use the test command. Note that it returns is directory for both directories and symlinks to directories but only returns is symlink for symbolic links.


1 Answers

I'd use the find command.

find . -lname /particular/folder 

That will recursively search the current directory for symlinks to /particular/folder. Note that it will only find absolute symlinks. A similar command can be used to search for all symlinks pointing at objects called "folder":

find . -lname '*folder' 

From there you would need to weed out any false positives.

like image 200
skymt Avatar answered Oct 02 '22 05:10

skymt