The shell gets the names of all the folders under the directory and outputs

Source: Internet
Author: User

Gets the names of all the folders under the specified directory/usr/and outputs:

Shell code:

1#!/bin/Bash2 #方法一3 dir=$(ls-l/usr/|awk '/^d/{print $NF}')4  forIinch$dir5  Do6     Echo$i7  Done   8 #######9 #方法二Ten  for dir inch$(ls/usr/) One  Do A[-D $dir] &&Echo$dir -  Done         - # #方法三 the   - ls-l/usr/|awk '/^d/{print $NF}'# # In fact the same method one, directly can be displayed without for loop

Running the shell will output the names of all the folders in the/usr/directory:

  1  [[email protected] ~]#./foler. sh   bin   3  etc   4  games   include   lib   7  lib64   8  libexec   local    sbin  11  share  12  src 

The shell gets the names of all the folders under the directory and outputs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.