python实现简单的find命令

python实现简单的find命令

#!/usr/bin/env python
import os
def dirList(path):
    flist = os.listdir(path)
    for file in flist:
        fpath = os.path.join(path,file)
        if os.path.isdir(fpath):
            dirList(fpath)
        print fpath
dirList('/usr/local')
[root@test ~]# python dir.py
/usr/local/src
/usr/local/bin/mysql
/usr/local/bin/mysqld_safe
/usr/local/bin/mysqladmin
/usr/local/bin
/usr/local/sbin
/usr/local/etc
/usr/local/lib64
/usr/local/share/man/man2
[root@test ~]# find /usr/local/*
/usr/local/bin
/usr/local/bin/mysql
/usr/local/bin/mysqld_safe
/usr/local/bin/mysqladmin
/usr/local/etc
/usr/local/games
/usr/local/include
/usr/local/lib
/usr/local/lib/mysql
/usr/local/lib64
/usr/local/libexec
/usr/local/sbin
/usr/local/share
/usr/local/share/man
/usr/local/share/man/man2


你可能感兴趣的:(python,find)