Get the List of Files and Directories Recursively in Linux
Simple bash Script to get the list of files and directories inside the specified path
Sometimes we want to get the list of files and directories recursively, but it is tedious to navigate each directory to check all the files. Here are the simple commands which will help you to check all the files and directories available in a specific path.
$ find -L "/path/to/directory" -type f
-L | Argument to take name of the files or directories to be examined. -L option follow the symbolic links as well. |
-type | File is of type, (f) regular file, (d) directory, (c) character |
If you don’t want to search in specific directory then you can also restrict your search result from below command.
Exclude specific directories
$ find -L "/path/to/directory" -type f -and -not -path "*/.git*"
In my example I have excluded .git directory from my listing criteria.
Shell Script to list files recursively
checkfile.sh
#!/bin/sh dir="" if [ -d "$1" ]; then dir=$1; else echo "Please directory path as a argument." exit 0 fi files="$(find -L "$dir" -type f -and -not -path "*/.git*")" echo "$files" | while read file; do echo "$file" done
Uses:
sh checkfile.sh /path/to/directory Few related Article https://techieroop.com/category/scripting/ https://github.com/roopendra/devops/tree/master/bash_scripting
(Visited 45 times, 1 visits today)