深度阅读

How to list only files of a certain type, such as PDF or MP3, using the ls command in Linux?

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

To list only files of a certain type (e.g. PDF or MP3) in a directory using the ls command in Linux, you can use the wildcard * character combined with the file extension. Here are some examples:

To list all PDF files in the current directory:

ls *.pdf

To list all MP3 files in a subdirectory called “Music”:

ls Music/*.mp3

To list all files of a certain type in all subdirectories of the current directory, you can use the recursive -R option with the wildcard character. For example, to list all PDF files in all subdirectories:

ls -R *.pdf

Note that these commands will only list files with the specified extension, and not directories or other types of files. If you want to include other types of files in your listing, you can combine the above commands with other options such as -l and -a.

Alternatively, you can use the find command to search for files with a specific extension in a directory and its subdirectories. Here is an example command to find all PDF files in the current directory and its subdirectories:

find . -name '*.pdf' -type f

This will display a list of all PDF files in the current directory and its subdirectories, including the full path to each file.

相关标签

博客作者

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