shell获取目录下所有文件夹的名称并输出
获取指定目录/usr/下所有文件夹的名称并输出:
shell代码:
#!/bin/bash
#方法一
dir=$(ls -l /usr/ |awk '/^d/ {print $NF}')
for i in $dir
do
echo $i
done
#######
#方法二
for dir in $(ls /usr/)
do
[ -d $dir ] && echo $dir
done
##方法三 ls -l /usr/ |awk '/^d/ {print $NF}' ## 其实同方法一,直接就可以显示不用for循环
运行shell后会输出/usr/目录下所有的文件夹的名字:
[root@localhost ~]# ./foler.sh
bin
etc
games
include
lib
lib64
libexec
local
sbin
share
src
shell获取目录下所有文件夹的名称并输出的更多相关文章
- Shell获取某目录下所有文件夹的名称
查看目录下面的所有文件: #!/bin/bash cd /目标目录 for file in $(ls *) do echo $file done 延伸的方法,查看目录下面的所有目录 #!/bin/ba ...
- 取CPU序列号,获取网卡,取硬盘系列号,获取目录下的文件,强制删除目录
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- Python开发【笔记】:获取目录下所有文件
获取文件 import os def sub_dirs(rdir): li = os.listdir(rdir) return li def main(rdir): content = sub_dir ...
- PHP遍历目录下的文件夹和文件 以及遍历文件下内容
1.遍历目录下的文件夹和文件: public function bianli1($dir) { $files = array(); if($head = opendir($dir)) { while( ...
- UIPath工具取得某个路径下的文件夹的名称
UIPath工具取得某个路径下的文件夹的名称 处理的流程如下图 [Edit Code]按钮押下之后写入代码如下 Dim dir As New DirectoryInfo("C:\Users\ ...
- 阿里云OSS 获取目录下所有文件
public class AliyunHandle { public static string accessKeyId = "a1uI5xxxxxxxxxrP4H"; publi ...
- Golang获取目录下的文件及目录信息
一.获取当前目录下的文件或目录信息(不包含多级子目录) func main() { pwd,_ := os.Getwd() //获取当前目录 //获取文件或目录相关信息 fileInfoList ...
- C/C++ 获取目录下的文件列表信息
在C/C++编程时,需要获取目录下面的文件列表信息. 1.数据结构 struct dirent { long d_ino; /* inode number 索引 ...
- File类 递归 获取目录下所有文件文件夹
package com.xiwi; import java.io.*; import java.util.*; class file{ public static void main(String a ...
随机推荐
- OC Foundation框架—字符串
一.Foundation框架中一些常用的类 字符串型: NSString:不可变字符串 NSMutableString:可变字符串 集合型: 1) NSArray:OC不可变数组 NSMutableA ...
- spark streaming 入门例子
spark streaming 入门例子: spark shell import org.apache.spark._ import org.apache.spark.streaming._ sc.g ...
- win7下安装node及出现的npm问题
按照官网下载安装,选择 Windows Installer (.msi):,一直next安装,默认安装在C:\Program Files\nodejs下,环境变量会自动添加 如果安装后,打开cmd输入 ...
- 上传xslx文件设置accept的MIME 类型
.dotx:application/vnd.openxmlformats-officedocument.wordprocessingml.template.docx:application/vnd.o ...
- sgu 129 Inheritance 凸包,线段交点,计算几何 难度:2
129. Inheritance time limit per test: 0.25 sec. memory limit per test: 4096 KB The old King decided ...
- JS之Fetch
细节叙述见以下链接:https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch 1 基本概念: WindowOrWo ...
- Oracle 固定执行计划-使用SPM(Sql Plan Management)固定执行计划
固定执行计划-使用SPM(Sql Plan Management)固定执行计划 转载自:http://www.lunar2013.com/2016/01/固定执行计划-使用spm%EF%BC%88sq ...
- (转载)Java 自动装箱与拆箱、equals和==的比较
什么是自动装箱拆箱 基本数据类型的自动装箱(autoboxing).拆箱(unboxing)是自J2SE 5.0开始提供的功能. 一般我们要创建一个类的对象实例的时候,我们会这样: Class a = ...
- wavepicking
http://www.seismology.harvard.edu/research/wavePicking.html
- L240
Giant rocks from space are falling from the sky more than they used to, but don't worry. For the pas ...