Home  >  Article  >  Operation and Maintenance  >  Detailed explanation of how to obtain the names of all folders in a certain directory using Shell under Linux

Detailed explanation of how to obtain the names of all folders in a certain directory using Shell under Linux

黄舟
黄舟Original
2017-05-28 11:38:194759browse

This article mainly introduces linux Shell to obtain the names of all folders in a directory. Friends who need it can refer to

to view all files under the directory:

#!/bin/bash
cd /目标目录
for file in $(ls *)
do
  echo $file
done

Extension method, view all directories under the directory

#!/bin/bash
cd /export/bak/original_document
for dir in $(ls split*)
do
  [ -d $dir ] && echo $dir #先判断是否是目录,然后再输出
done

The above is the detailed content of Detailed explanation of how to obtain the names of all folders in a certain directory using Shell under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn