深度阅读

How to display the complete path of a file using the ls command in Linux?

作者
作者
2023年08月22日
更新时间
11.18 分钟
阅读时间
0
阅读量

To display the complete or absolute path of a file using the ls command in Linux, you can use the -d or -l options with the pwd command or the ${PWD} variable. Here are some examples:

  1. To display the absolute path of a single file:
ls -d "$(pwd)/file_name"

or

ls -ld "${PWD}/file_name"
  1. To display the absolute paths of all files in a directory:
ls -d "$(pwd)/*"

or

ls -ld "${PWD}/"*

Both of these commands will display the absolute path of each file in the current directory (including subdirectories, if any). The -d option tells ls to list the directory itself, rather than its contents, while the -l option provides a long listing of each file, including ownership and permission information. The $(pwd) or ${PWD} variable provides the full path of the current working directory.

Keep in mind that using ls to display file paths is not always the most efficient way, especially when dealing with large directory structures or complex filters. For more complex operations, you may need to use other commands such as find or locate.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。