简体   繁体   English

获取递归包含在目录中的文件列表的最快方法是什么?

[英]What is the fastest way to get the list of files recursively contained in a directory?

I have a directory that contains millions of files spread out in a hierarchy of folders. 我有一个目录,其中包含分布在文件夹层次结构中的数百万个文件。 This directory is stored on a large remote NFS filesystem. 该目录存储在大型远程NFS文件系统中。 I'd like to retrieve the list of these files as fast as possible. 我想尽快检索这些文件的列表。

Is it possible to go faster than find . > list.txt 是否有可能比find . > list.txt更快find . > list.txt find . > list.txt ? find . > list.txt What factors affect speed? 哪些因素影响速度? I'm using python, but any solution will go as long as it's fast . 我正在使用python,但只要速度快 ,任何解决方案都会使用。

On linux, this was the fastest for me. 在linux上,这对我来说是最快的。 Use (bash) globbing and printf like this: 像这样使用(bash)globbing和printf:

printf "%s\n" directory/**/file
printf "%s\x00" directory/**/filename-with-special-characters | xargs -0 command

Seems to be a lot faster than 似乎要快得多

find directory -name file

or 要么

ls -1R directory | grep file

or even, surprisingly, 甚至,令人惊讶的是,

ls directory/**/file

This was a local file system though: x86_64 system, ext4 filesystem on an SSD, in a directory structure of over 600,000 directories with multiple files in them. 这是一个本地文件系统:x86_64系统,SSD上的ext4文件系统,目录结构超过600,000个目录,其中包含多个文件。

Depending what do you want in the output. 根据您在输出中的要求。 I recommend using 我推荐使用

ls -R | grep ":$" | sed -e 's/:$//' -e 's/^/   /' -e 's/-/|/'

for the complete path to all the files recursively in the current directory. 用于当前目录中递归的所有文件的完整路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 计算目录中大量文件的最快/最简单的方法是什么(在 Linux 中)? - What is the fastest / easiest way to count large number of files in a directory (in Linux)? 在 Python 中,在具有特定扩展名的目录中构建文件列表的最快方法 - In Python, fastest way to build a list of files in a directory with a certain extension 递归列出Bash中给定目录中的文件 - Recursively list files from a given directory in Bash 删除包含数千个文件的大目录的最佳和最快的方法是什么(在 ubuntu 中) - What is the best and the fastest way to delete large directory containing thousands of files (in ubuntu) 递归列出目录中的所有文件,包括符号链接目录中的文件 - Recursively list all files in a directory including files in symlink directories 计算目录中包含的文件 - Counting files contained in a directory 在 shell 中获取上一条命令的最快方法是什么? - What is the fastest way to get the previous command in shell? 计算目录(包括子目录)中文件数的最快方法 - The fastest way to count the number of files in a directory (including subdirectories) 如何递归查找并列出具有子目录和时间的目录中的最新修改文件 - How to recursively find and list the latest modified files in a directory with subdirectories and times 在 Linux CLI 中使用相对于当前目录的路径递归列出文件 - List files recursively in Linux CLI with path relative to the current directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM