在bash中仅使用l列出目录:检查
本文翻译自:Listing only directories using ls in bash: An examination
This command lists directories in the current path: ls -d */
此命令列出当前路径中的目录: ls -d */
What exactly does the pattern */
do? */
模式到底是做什么的?
And how can we give the absolute path in the above command (eg ls -d /home/alice/Documents
) for listing only directories in that path? 以及如何在上述命令中给出绝对路径(例如ls -d /home/alice/Documents
)以仅列出该路径中的目录?
#1楼
参考:https://stackoom.com/question/yDgY/在bash中仅使用l列出目录-检查
#2楼
*/
is a pattern that matches all of the subdirectories in the current directory ( *
would match all files and subdirectories; the /
restricts it to directories). */
是与当前目录中所有子目录匹配的模式( *
将与所有文件和子目录匹配; /
将其限制为目录)。 Similarly, to list all subdirectories under /home/alice/Documents, use ls -d /home/alice/Documents/*/
同样,要列出/ home / alice / Documents下的所有子目录,请使用ls -d /home/alice/Documents/*/
#3楼
Four ways to get this done, each with a different output format 完成此操作的四种方法,每种方法具有不同的输出格式
1. Using echo
1.使用echo
Example: echo */
, echo */*/
示例: echo */
, echo */*/
Here is what I got: 这是我得到的:
cs/ draft/ files/ hacks/ masters/ static/
cs/code/ files/images/ static/images/ static/stylesheets/
2. Using ls
only 2.仅使用ls
Example: ls -d */
示例: ls -d */
Here is exactly what I got: 这正是我得到的:
cs/ files/ masters/
draft/ hacks/ static/
Or as list (with detail info): ls -dl */
或作为列表(包含详细信息): ls -dl */
3. Using ls
and grep
3.使用ls
和grep
Example: ls -l | grep "^d"
示例: ls -l | grep "^d"
ls -l | grep "^d"
Here is what I got: ls -l | grep "^d"
这是我得到的:
drwxr-xr-x 24 h staff 816 Jun 8 10:55 cs
drwxr-xr-x 6 h staff 204 Jun 8 10:55 draft
drwxr-xr-x 9 h staff 306 Jun 8 10:55 files
drwxr-xr-x 2 h staff 68 Jun 9 13:19 hacks
drwxr-xr-x 6 h staff 204 Jun 8 10:55 masters
drwxr-xr-x 4 h staff 136 Jun 8 10:55 static
4. Bash Script (Not recommended for filename containing spaces) 4. Bash脚本(不建议将文件名包含空格)
Example: for i in $(ls -d */); do echo ${i%%/}; done
示例: for i in $(ls -d */); do echo ${i%%/}; done
for i in $(ls -d */); do echo ${i%%/}; done
Here is what I got: 这是我得到的:
cs
draft
files
hacks
masters
static
If you like to have '/' as ending character, the command will be: for i in $(ls -d */); do echo ${i}; done
如果您希望以'/'作为结束字符,则命令将为: for i in $(ls -d */); do echo ${i}; done
for i in $(ls -d */); do echo ${i}; done
cs/
draft/
files/
hacks/
masters/
static/
#4楼
I use: 我用:
ls -d */ | cut -f1 -d'/'
This creates a single column with no trailing slash - useful in scripts. 这将创建不带斜杠的单列-在脚本中很有用。
My two cents. 我的两分钱。
#5楼
I partially solved with : 我部分解决了:
cd "/path/to/pricipal/folder"for i in $(ls -d .*/); do sudo ln -s "$PWD"/${i%%/} /home/inukaze/${i%%/}; doneln: «/home/inukaze/./.»: can't overwrite a directory
ln: «/home/inukaze/../..»: can't overwrite a directory
ln: accesing to «/home/inukaze/.config»: too much symbolics links levels
ln: accesing to «/home/inukaze/.disruptive»: too much symbolics links levels
ln: accesing to «/home/inukaze/innovations»: too much symbolics links levels
ln: accesing to «/home/inukaze/sarl»: too much symbolics links levels
ln: accesing to «/home/inukaze/.e_old»: too much symbolics links levels
ln: accesing to «/home/inukaze/.gnome2_private»: too much symbolics links levels
ln: accesing to «/home/inukaze/.gvfs»: too much symbolics links levels
ln: accesing to «/home/inukaze/.kde»: too much symbolics links levels
ln: accesing to «/home/inukaze/.local»: too much symbolics links levels
ln: accesing to «/home/inukaze/.xVideoServiceThief»: too much symbolics links levels
Well , this reduce to me , the mayor part :) 好吧,这减少了我,市长的一部分:)
#6楼
One-liner to list directories only from "here". 一线式仅从“这里”列出目录。
With file count. 随着文件数。
for i in `ls -d */`; do g=`find ./$i -type f -print| wc -l`; echo "Directory $i contains $g files."; done
在bash中仅使用l列出目录:检查相关推荐
- Bash中的标准输入、标准输出和标准错误输出
原理 每个程序在运行后,都会至少打开三个文件描述符,分别是0:标准输入:1:标准输出:2:标准错误. 例如,对于test.sh脚本,我们通过下面的步骤看到它至少打开了三个文件描述符: ./test.s ...
- linux 文件大小_整理 | Linux下列出目录内容命令
IT服务圈儿 有温度.有态度的IT自媒体平台 来源:良许Linux(ID:liangxuxiansheng) 在 Linux 中,有非常多的命令可以让我们用来执行各种各样的任务.当我们想要像使用文件浏 ...
- Python 列出目录中的文件
在本文中,我们将了解如何在 Python 中列出目录中的所有文件.有多种方法可以列出目录的文件.在本文中,我们将使用以下 四种方法. os.listdir('dir_path'):返回指定目录路径中存 ...
- php删除树结构文件,树型结构列出目录中所有文件的php代码
以树型结构列出指定目录里的所有文件,这样的话,目录下的所有文件便结构清晰的呈现在你的面前,有什么文件你一看便知,很方便的哦. 示例, php; auto-links:false;"> ...
- 如何在Bash中加入数组元素?
如果我在Bash中有这样的数组: FOO=( a b c ) 如何用逗号将元素加入? 例如,产生a,b,c . #1楼 重复使用@无关紧要的解决方案,但是通过避免$ {:1}的替换和避免中间变量的使用 ...
- linux相等路径,关于linux:如何检查Bash中两条路径是否相等?
在Bash中检查两条路径是否相等的最佳方法是什么? 例如,给定目录结构 ~/ Desktop/ Downloads/ (symlink to ~/Downloads) Downloads/ photo ...
- Linux Shell 只列出目录的方法
在实际应用中,我们有时需要仅列出目录,下面是 4 种不同的方法. 1. 利用 ls 命令的 -d 选项: $ ls -d */ Desktop/ pic/ shell/ src/ 2. 利用 ls 命 ...
- 在windows上的git bash中安装tree 和 linux tree命令使用
在windows上的git bash中安装tree 和 linux tree命令使用 文章目录: 1 在windows上的git bash中安装tree 1.1 下载windows版本的tree 1. ...
- Bash 中的特殊字符大全
Linux下无论如何都是要用到shell命令的,在Shell的实际使用中,有编程经验的很容易上手,但稍微有难度的是shell里面的那些个符号,各种特殊的符号在我们编写Shell脚本的时候如果能够用的好 ...
最新文章
- java 加载jar_java手动加载jar
- ASP.NET - 截取固定长度字符串显示在页面,多余部分显示为省略号
- oracle 迁移用户信息,Oracle备份一个用户并迁移
- 商品规格表设计_400㎡美容院装修设计,为什么说无中式不贵气?
- 初识Zookeeper
- BZOJ2329: [HNOI2011]括号修复(Splay)
- EasyDarwin开源手机直播方案:EasyPusher手机直播推送,EasyDarwin流媒体服务器,EasyPlayer手机播放器...
- xampp启动Apache报错 1、Error: Apache shutdown unexpectedly. 2、Unclean shutdown of previous Apache run?
- 解决java无法切分字符串,.split()无效
- mysql出现error 2003_mysql启动时出现ERROR 2003 (HY000)问题的解决方法
- IOS的四种数据存储方式及优劣
- Android:Json数据转换成Map
- 基础平面设计(文字排版篇)
- ios设备管理 iMazing官方免费激活电脑版下载v2.11.6.0
- 巨潮网站爬虫程序修改
- 今天脚被蜈蚣“啃”了
- edp协议 netty_使用esp8266 arduino 通过EDP协议 将数据传递到onenet平台
- Git命令详解及工作实用流程
- certbot安装https证书
- po是什么意思java_在Java中VO , PO , BO , QO, DAO ,POJO是什么意思
热门文章
- LABjs异步加载组件
- pace.js – 加载进度条插件
- (翻译)正确实施DevOps-The Lay of the Land
- .NET程序的代码混淆、加壳与脱壳
- InstallShield 2012 Spring新功能试用(6): InstallScript工程支持64位组件(Components)...
- 第 7 章 使用filter过滤请求
- Web项目之Flask框架
- Cobalt Strike 3.13的新功能
- 请问spfa+stack 和spfa+queue 是什么原理
- (转载)valgrind,好东西,一般人我不告诉他~~ 选项