0
- #!/usr/bin/env python
- # coding=utf-8
- import os
- pathname = '.'
- for root,dirs,files in os.walk(pathname):
- for name in dirs:
- print name
0
本帖最后由 balich 于 2015-12-26 13:05 编辑
- #!/bin/bash
- #2015-12-26
- #
- #
- for d in `ls`
- do
- if [ -d $d ];then
- echo $d
- fi
- done
0
- #!/bin/env python
- import os
- from os import path
- dirs=os.listdir('./')
- for f in dirs:
- if path.isdir(f):
- print f, 'is a directory'
0
本帖最后由 soul 于 2016-1-27 14:14 编辑
#!/bin/bash
c=`/usr/bin/id -u`
if [ $c -eq 0 ]
then
read -p "输入查询的绝对路径:" a
for b in `ls $a`
do
if [ -d $b ]
then
echo $b
else
continue
fi
done
else
read -p "输入查询的绝对路径(由于权限问题您可能查不到个别的路径):" a
for b in `ls $a`
do
if [ -d $b ]
then
echo $b
else
continue
fi
done
fi
循环部分运用不是很熟练,而且发现一个BUG,不能在子目录下查询父目录
#!/bin/bash
c=`/usr/bin/id -u`
if [ $c -eq 0 ]
then
read -p "输入查询的绝对路径:" a
for b in `ls $a`
do
if [ -d $b ]
then
echo $b
else
continue
fi
done
else
read -p "输入查询的绝对路径(由于权限问题您可能查不到个别的路径):" a
for b in `ls $a`
do
if [ -d $b ]
then
echo $b
else
continue
fi
done
fi
循环部分运用不是很熟练,而且发现一个BUG,不能在子目录下查询父目录
0
#!/bin/bash
#author:changjun
#function:把当前目录下的目录(只需要一级)列出来。
p=`pwd`
for d in `ls $p`
do
if [ -d $p/$d ]
then
echo "$p/$d"
fi
done
#author:changjun
#function:把当前目录下的目录(只需要一级)列出来。
p=`pwd`
for d in `ls $p`
do
if [ -d $p/$d ]
then
echo "$p/$d"
fi
done
0
本帖最后由 wsw13640218682 于 2016-2-2 12:07 编辑
[root@nz ~]# tree test/shell/
test/shell/
└── 2
├── 3
│ ├── a
│ ├── b
│ └── c
├── a
├── b
└── c
2 directories, 6 files
[root@nz ~]# cat a.sh
#!/bin/bash
a=/root/test/shell/
for file in `find $a -maxdepth 1 -type d -print `
do
echo $file
done
或者
[root@nz shell]# cp /root/a.sh .
[root@nz shell]# cat a.sh
#!/bin/bash
a=`pwd`
for file in `find $a -maxdepth 1 -type d -print `
do
echo $file
done
[root@nz shell]# ./a.sh
/root/test/shell
/root/test/shell/2
[root@nz ~]# tree test/shell/
test/shell/
└── 2
├── 3
│ ├── a
│ ├── b
│ └── c
├── a
├── b
└── c
2 directories, 6 files
[root@nz ~]# cat a.sh
#!/bin/bash
a=/root/test/shell/
for file in `find $a -maxdepth 1 -type d -print `
do
echo $file
done
或者
[root@nz shell]# cp /root/a.sh .
[root@nz shell]# cat a.sh
#!/bin/bash
a=`pwd`
for file in `find $a -maxdepth 1 -type d -print `
do
echo $file
done
[root@nz shell]# ./a.sh
/root/test/shell
/root/test/shell/2
编辑回复