获取指定目录/usr/下所有文件夹的名称并输出:

shell代码:

  1. #!/bin/bash
  2. #方法一
  3. dir=$(ls -l /usr/ |awk '/^d/ {print $NF}')
  4. for i in $dir
  5. do
  6. echo $i
  7. done
  8. #######
  9. #方法二
  10. for dir in $(ls /usr/)
  11. do
  12. [ -d $dir ] && echo $dir
  13. done
  14. ##方法三
  15.  
  16. ls -l /usr/ |awk '/^d/ {print $NF}' ## 其实同方法一,直接就可以显示不用for循环

运行shell后会输出/usr/目录下所有的文件夹的名字:

  1. [root@localhost ~]# ./foler.sh
  2. bin
  3. etc
  4. games
  5. include
  6. lib
  7. lib64
  8. libexec
  9. local
  10. sbin
  11. share
  12. src

shell获取目录下所有文件夹的名称并输出的更多相关文章

  1. Shell获取某目录下所有文件夹的名称

    查看目录下面的所有文件: #!/bin/bash cd /目标目录 for file in $(ls *) do echo $file done 延伸的方法,查看目录下面的所有目录 #!/bin/ba ...

  2. 取CPU序列号,获取网卡,取硬盘系列号,获取目录下的文件,强制删除目录

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  3. Python开发【笔记】:获取目录下所有文件

    获取文件 import os def sub_dirs(rdir): li = os.listdir(rdir) return li def main(rdir): content = sub_dir ...

  4. PHP遍历目录下的文件夹和文件 以及遍历文件下内容

    1.遍历目录下的文件夹和文件: public function bianli1($dir) { $files = array(); if($head = opendir($dir)) { while( ...

  5. UIPath工具取得某个路径下的文件夹的名称

    UIPath工具取得某个路径下的文件夹的名称 处理的流程如下图 [Edit Code]按钮押下之后写入代码如下 Dim dir As New DirectoryInfo("C:\Users\ ...

  6. 阿里云OSS 获取目录下所有文件

    public class AliyunHandle { public static string accessKeyId = "a1uI5xxxxxxxxxrP4H"; publi ...

  7. Golang获取目录下的文件及目录信息

    一.获取当前目录下的文件或目录信息(不包含多级子目录) func main() {  pwd,_ := os.Getwd() //获取当前目录  //获取文件或目录相关信息  fileInfoList ...

  8. C/C++ 获取目录下的文件列表信息

    在C/C++编程时,需要获取目录下面的文件列表信息. 1.数据结构 struct dirent {     long d_ino;                 /* inode number 索引 ...

  9. File类 递归 获取目录下所有文件文件夹

    package com.xiwi; import java.io.*; import java.util.*; class file{ public static void main(String a ...

随机推荐

  1. HDOJ1007

    /** 最近点对问题,时间复杂度为O(n*logn*logn) */ #include <iostream> #include <cstdio> #include <cs ...

  2. intel python加速效果初探

    python3安装intel的加速库: conda config --add channels intel conda create --name intelpy intelpython3_full ...

  3. Vue--关于点击当前路由,视图无法更新的解决方案

    转自:https://juejin.im/post/593121aa0ce4630057f70d35 问题的根源: 用户点击当前高亮的路由并不会刷新view,因为vue-router会拦截你的路由,它 ...

  4. kill qz _e epi,eu,ex,exo out3

    1● epi 在~上,在~周围,在~后面   2● eu 好,优秀     3● ex 出,出去   4● exo 在外面 的,外部的    

  5. Dos命令下目录操作

    Dos命令下目录操作 1.cd 操作 显示当前目录名或改变当前目录 cd [盘符][路径]                      进入指定盘符下的目录 cd [..]               ...

  6. POJ 2896 AC自动机 or 暴力

    DESCRIPTION :大意是说.给你n个代表病毒的字符串.m个表示网站的字符串.让你计算有多少个网站被病毒感染了.被那些病毒感染了. 刚开始就想暴力.然而,忽略了条件:每个网站最多有三个病毒.于是 ...

  7. write file to stroage trigger kernel warning

    when you write large files  to extern stroage, the kernel may have as follow context: [ 4560.236385] ...

  8. Redis (一) 概念安装

    一.阿里云安装Redis 1.安装Redis yum -y install redis 2.启动Redis service redis start 或者(推荐使用) systemctl start  ...

  9. 《Python》 函数初识

    一.函数: 1.函数初识: def 关键字 函数名 # def my_len() 函数名的命名规则跟变量一样,要具有描述性. 函数的优点: 减少代码的重复率 增强代码的阅读性 函数的主要目的:封装一个 ...

  10. 基于GUI的简单聊天室03

    上一版本,客户端关闭后会出现“socket close”异常问题,这个版本用捕捉异常来解决,实际上只是把异常输出的语句改为用户退出之类,并没真正解决 服务器类 package Chat03; /** ...