简体   繁体   English

shell 脚本:我有一个包含几个其他目录的主目录,我想打印这些目录中的所有文件

[英]shell scripting : I have a main directory which contain few other directories and I want to print all files inside those directories

This script only print files from main directory but doesn't print files of an sub directory that is present in main directory.此脚本仅打印主目录中的文件,但不打印主目录中存在的子目录的文件。

If not clear what I mean is if I have a main directory and that main directory has 5 sub directories and all of them contains file.如果不清楚我的意思是如果我有一个主目录并且该主目录有 5 个子目录并且它们都包含文件。 I just want to print all of those files.我只想打印所有这些文件。

read filename
for entry in "$filename"/*
do
  echo "$entry"
done

I just want to print all of those files.我只想打印所有这些文件。

Then use find .然后使用find

find "$filename" -type f

will print all filenames.将打印所有文件名。

I have to ask: which shell?不得不问:shell是哪个? a Linux shell? Linux shell? Powershell? Powershell?

If Powershell:如果 Powershell:

    $files = Get-Childitem -Recurse

Just don't use this starting at just the C:\ .只是不要从C:\开始使用它。

But with your read and echo , it looks like Linux.但是通过您的readecho ,它看起来像 Linux。 have you tried the tree command?你试过tree命令吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将具有指定数量文件的所有目录移动到另一个目录 - Moving all directories which have a specified number of files, to another directory 如何使用根目录中存在的所有目录下特定文件夹中的Shell脚本列出所有文件? - How to list all the files using shell script present in a specific folder under all the directories those are present in the root directory? 在BASH Shell脚本中创建文件和目录 - Creating files and directories in BASH Shell Scripting 嵌套目录中的Shell脚本 - Shell scripting in nested directories 我想删除linux中的所有文件和目录 - I wanna to delete all files and directories in linux Linux:如何删除目录本身(不是子目录)内的所有文件(不是目录) - Linux: How to delete all of the files (not directories) inside a directory itself (not childs) Unix shell脚本:更新所有子目录和子文件的时间戳,包括带空格的子目录和子文件 - Unix shell script: Update timestamp on all sub-directories and sub-files, including those with spaces Linux-如何仅压缩包含特定文件的目录? - Linux - how can I tar only directories that contain specific files? 我只需要在文本文件中获取包含其他目录中文件名的那些行 - I have to get only those lines in a text file that contain the filename of the files in another directory 我将如何使用 find 来收集所有目录的路径,而不是我想要的目录中任何子目录的路径 - How would I use find to collect the paths of all directories, but not the paths of any subdirectories within the directories I want
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM