只列出当前目录和子目录方法一
1、编辑脚本[root@iZbp171r05i3piseee5kuaZ tmp]# vim /root/filelist.py
#!/usr/bin/env python
import os
for root,dirs,files in os.walk('/tmp'):
print root
2、执行脚本和确认[root@iZbp171r05i3piseee5kuaZ tmp]# python /root/filelist.py
/tmp
/tmp/gxmdir
/tmp/gxmdir/ddd
/tmp/csdir
/tmp/.ICE-unix
[root@iZbp171r05i3piseee5kuaZ tmp]# tree -d
.
├── csdir
└── gxmdir
└── ddd
3 directories
只列出当前目录和子目录方法二
1、编辑脚本[root@iZbp171r05i3piseee5kuaZ tmp]# vim /root/filelist.py
#!/usr/bin/env python
import os
for root,dirs,files in os.walk('/tmp'):
print root
print dirs
2、执行脚本和确认([]里面表示子目录)[root@iZbp171r05i3piseee5kuaZ tmp]# python /root/filelist.py
/tmp
['gxmdir', 'csdir', '.ICE-u