Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我得到这个时,我试图找到文件数,
通过终端:
ls | wc -l
给了我总共58925 个文件
并通过 Python 的 os 模块:
len(os.listdir('/home/cloud_user/notebooks/Zain/Data/Images/'))
给了我总共58926 个文件
为什么这两者之间有区别?哪一个是正确的?
在 Linux/UNIX 中,除非您指定该选项,否则ls隐藏以点开头的文件名,因此很明显,您在以开头的目录中有一个文件,它可以解释但不会。.-aImages.os.listdirls
ls
.
-a
Images
os.listdir