user3398900
user3398900

Reputation: 845

how to list all files directories and sub directories in a folder using shellscript

Hi all i am trying to print all the files present in a file here for instance a folder name "WebstormProjects" when i am trying to print the files it is going only upto 2nd sub directory(as written there) only if i want to go much deep into the sub-directory(2nd level) how to go deep down recursively?? here is the tree

WebstormProjects/
|-- goutham
|   |-- goutham.js
|   |-- demo.html
|   |-- format.js
|   `-- login.html
`-- Nodejs
    |-- prototype
    |`-- app.js
    `-- requests
        `-- app.js

  4 directories, 6 files

here is the code

enter code here
#!/bin/bash
target="/home/goutham/WebstormProjects"
for f in "$target"/*
do
if [[ -d $f ]]; then
     for k in "$f"/*
 do
    echo "$k"
 done
     echo ""
 else
    echo $f
 fi
 done
 echo ""

Upvotes: 0

Views: 559

Answers (2)

Joao  Vitorino
Joao Vitorino

Reputation: 3266

You want the output as list. Use

find WebstormProjects

Or if you want in a tree like you post

tree -af

Upvotes: 0

that other guy
that other guy

Reputation: 123680

Use find:

find WebstormProjects

If you want only files and no directories:

find WebstormProjects -type f

Upvotes: 1

Related Questions