How can I generate a list of files with their absolute path in Linux?

后端 未结 21 2245
天涯浪人
天涯浪人 2020-11-28 16:56

I am writing a shell script that takes file paths as input.

For this reason, I need to generate recursive file listings with full paths. For example, the file

21条回答
  •  囚心锁ツ
    2020-11-28 17:40

    If you give find an absolute path to start with, it will print absolute paths. For instance, to find all .htaccess files in the current directory:

    find "$(pwd)" -name .htaccess
    

    or if your shell expands $PWD to the current directory:

    find "$PWD" -name .htaccess
    

    find simply prepends the path it was given to a relative path to the file from that path.

    Greg Hewgill also suggested using pwd -P if you want to resolve symlinks in your current directory.

提交回复
热议问题