Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Linux
  3. look for symlinks pointing at the contents of directory?

look for symlinks pointing at the contents of directory?

Scheduled Pinned Locked Moved Linux
linux
8 Posts 6 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L This user is from outside of this forum
    L This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #1

    I want to move a directory with a bunch of subdirectories and files. But I have the feeling there might be some symlinks to a few of them elsewhere on the file system. (As in the directory contains the targets of symlinks.)

    How do I search all files for symlinks pointing to them?

    Some combination of find, stat, ls, realpath, readlink and maybe xargs? I can't quite figure it out.

    isokiero@sopuli.xyzI B C ? 4 Replies Last reply
    0
    • System shared this topic on
    • L [email protected]

      I want to move a directory with a bunch of subdirectories and files. But I have the feeling there might be some symlinks to a few of them elsewhere on the file system. (As in the directory contains the targets of symlinks.)

      How do I search all files for symlinks pointing to them?

      Some combination of find, stat, ls, realpath, readlink and maybe xargs? I can't quite figure it out.

      isokiero@sopuli.xyzI This user is from outside of this forum
      isokiero@sopuli.xyzI This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #2

      I think it's easier the other way round, find all symlinks and grep the directory you want to move from results.

      Something like 'find /home/user -type -l -exec ls -l {} ; | grep yourdirectory' and work from there. I don't think there's an easy way to list which symlinks point to any actual file.

      M 1 Reply Last reply
      0
      • isokiero@sopuli.xyzI [email protected]

        I think it's easier the other way round, find all symlinks and grep the directory you want to move from results.

        Something like 'find /home/user -type -l -exec ls -l {} ; | grep yourdirectory' and work from there. I don't think there's an easy way to list which symlinks point to any actual file.

        M This user is from outside of this forum
        M This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #3

        You want readlink -f rather than ls -l.

        L 1 Reply Last reply
        0
        • M [email protected]

          You want readlink -f rather than ls -l.

          L This user is from outside of this forum
          L This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #4

          because zsh I swapped out ~ -> $HOME. In addition to some permission denied that you always get finding over the home dir, I get these weird hits:

          find "$HOME" -type l -exec /bin/sh /path/to/the/script "/path/to/target/dir" {} +
          /home/user/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/lib64/libatomic.so
          /home/user/.mozilla/firefox/xxx000xx.someprofile/chrome/dir/file.css
          

          lib atomic is something I've heard of vaguely but certainly not anything I use. I couldn't identify any way this file was doing anything outside the ~/.konan dir.

          the CSS files there were a few different ones in a couple different Firefox profiles. it's the user customization. But I don't think it should have anything to do with the directory I was asking for.

          If I give it a bit more of a hint, telling to look in ~/.config specifically, now I get some (but not all) the links I expect.

          find "$HOME/.config" -type l -exec /bin/sh /path/to/the/script "/path/to/target/dir" {} +
          /home/user/.config/dir02
          /home/user/.config/dir01/subdir/file
          /home/user/.config/dir01/subdir2/file2
          

          And suggesting it searches in the .konan dir where it found lib atomimc, it now doesn't find anything.

          find "$HOME/.konan" -type l -exec /bin/sh /path/to/the/script "/path/to/target/dir" {} +
          

          Could be all kinds of things getting the way. Different versions of relevant tools, filesystems/setups, permissions...

          M 1 Reply Last reply
          0
          • L [email protected]

            I want to move a directory with a bunch of subdirectories and files. But I have the feeling there might be some symlinks to a few of them elsewhere on the file system. (As in the directory contains the targets of symlinks.)

            How do I search all files for symlinks pointing to them?

            Some combination of find, stat, ls, realpath, readlink and maybe xargs? I can't quite figure it out.

            B This user is from outside of this forum
            B This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #5

            find / -type l -lname '/path/you/are/looking/for/*'

            Note that the -lname option is a GNU find extension and may not work with other find implementations.

            1 Reply Last reply
            0
            • L [email protected]

              I want to move a directory with a bunch of subdirectories and files. But I have the feeling there might be some symlinks to a few of them elsewhere on the file system. (As in the directory contains the targets of symlinks.)

              How do I search all files for symlinks pointing to them?

              Some combination of find, stat, ls, realpath, readlink and maybe xargs? I can't quite figure it out.

              C This user is from outside of this forum
              C This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #6

              You could just move the dir and leave a symlink in its place. It doesn't solve the actual problem, but it's much easier and will keep everything working just fine.

              1 Reply Last reply
              0
              • L [email protected]

                I want to move a directory with a bunch of subdirectories and files. But I have the feeling there might be some symlinks to a few of them elsewhere on the file system. (As in the directory contains the targets of symlinks.)

                How do I search all files for symlinks pointing to them?

                Some combination of find, stat, ls, realpath, readlink and maybe xargs? I can't quite figure it out.

                ? Offline
                ? Offline
                Guest
                wrote on last edited by
                #7

                If you just rename the dir, and then find all broken symlinks in your system?

                find . -xtype l

                1 Reply Last reply
                0
                • L [email protected]

                  because zsh I swapped out ~ -> $HOME. In addition to some permission denied that you always get finding over the home dir, I get these weird hits:

                  find "$HOME" -type l -exec /bin/sh /path/to/the/script "/path/to/target/dir" {} +
                  /home/user/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/lib64/libatomic.so
                  /home/user/.mozilla/firefox/xxx000xx.someprofile/chrome/dir/file.css
                  

                  lib atomic is something I've heard of vaguely but certainly not anything I use. I couldn't identify any way this file was doing anything outside the ~/.konan dir.

                  the CSS files there were a few different ones in a couple different Firefox profiles. it's the user customization. But I don't think it should have anything to do with the directory I was asking for.

                  If I give it a bit more of a hint, telling to look in ~/.config specifically, now I get some (but not all) the links I expect.

                  find "$HOME/.config" -type l -exec /bin/sh /path/to/the/script "/path/to/target/dir" {} +
                  /home/user/.config/dir02
                  /home/user/.config/dir01/subdir/file
                  /home/user/.config/dir01/subdir2/file2
                  

                  And suggesting it searches in the .konan dir where it found lib atomimc, it now doesn't find anything.

                  find "$HOME/.konan" -type l -exec /bin/sh /path/to/the/script "/path/to/target/dir" {} +
                  

                  Could be all kinds of things getting the way. Different versions of relevant tools, filesystems/setups, permissions...

                  M This user is from outside of this forum
                  M This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #8

                  You could pass $1 and $got through $(realpath -P -- ...) to make sure all the path are in canonical form. Though now that I’m thinking about it, stat is probably a better option anyway:

                  want=/path/to/target/dir
                  pattern=$(stat -c^%d:%i: -- "$want")
                  find "$HOME" -type l -exec stat -Lc%d:%i:%n {} + | grep "$pattern"
                  
                  1 Reply Last reply
                  0
                  • System shared this topic on
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups