Linux: Find all symlinks of a given 'original' file? (reverse 'readlink')

后端 未结 6 2170
遥遥无期
遥遥无期 2020-12-04 11:33

Consider the following command line snippet:

$ cd /tmp/
$ mkdir dirA
$ mkdir dirB
$ echo \"the contents of the \'original\' file\" > orig.file
$ ls -la o         


        
6条回答
  •  余生分开走
    2020-12-04 12:00

    This may be too simplistic for what you want to do, but I find it useful. it does Not answer your question literally, as it's not 'run on the original file', but it accomplishes the task. But, a lot more HDD access. And, it only works for 'soft' linked files which is majority of user linked files.

    from the root of you data storage directory or users data directories, wherever symlinked 'files' to the orig.file may reside, run the find command:

    # find -type l -ls |grep -i 'orig.file' 
    

    or

    # find /Starting/Search\ Path/ -type l -ls |grep -i '*orig*'
    

    I would Normally use part of the name eg, '*orig*' to start, because we know users will rename (prefix) a simply named file with a more descriptive one like " Jan report from London _ orig.file.2015.01.21 " or something.

    Note: I've Never gotten the -samefile option to work for me.

    clean, simple, easy to remember

    hope this helps Someone. Landis.

提交回复
热议问题