该命令列出当前路径下的目录:
ls -d */
模式*/到底做什么?
我们如何在上面的命令中给出绝对路径(例如ls -d /home/alice/Documents),只列出该路径下的目录?
该命令列出当前路径下的目录:
ls -d */
模式*/到底做什么?
我们如何在上面的命令中给出绝对路径(例如ls -d /home/alice/Documents),只列出该路径下的目录?
当前回答
显示没有/的文件夹列表:
ls -d */|sed 's|[/]||g'
其他回答
我只是把它添加到我的.bashrc文件中(如果你只需要/想要一个会话,你也可以在命令行上输入它):
alias lsd='ls -ld */'
然后lsd会产生想要的结果。
file * | grep directory
输出(在我的机器上)——
[root@rhel6 ~]# file * | grep directory
mongo-example-master: directory
nostarch: directory
scriptzz: directory
splunk: directory
testdir: directory
以上输出可以通过使用cut进行进一步细化:
file * | grep directory | cut -d':' -f1
mongo-example-master
nostarch
scriptzz
splunk
testdir
* could be replaced with any path that's permitted
file - determine file type
grep - searches for string named directory
-d - to specify a field delimiter
-f1 - denotes field 1
我使用:
ls -d */ | cut -f1 -d'/'
这将创建一个没有结尾斜杠的单列——在脚本中很有用。
使用Perl:
ls | perl -nle 'print if -d;'
如果你有空间在你的文件夹名称$9打印不工作尝试下面的命令
ls -l yourfolder/alldata/ | grep '^d' | awk '{print $9" " $10}'
输出
ls -l yourfolder/alldata/ | grep '^d' | awk '{print $9" " $10}'
testing_Data
Folder 1