Wednesday, April 6, 2016

Linux Bash Shell Script Recursive Directory Traversal and Print All File Contents Inside


How the code below works:

The code recursively traverse the Directories and Print the file contents inside those directories. The "deletefolder" named argument is passed as the first parameter of the traverseDirectory function. All the contents inside this folder is traversed recursively. If it is a directory then it is traversed recursively otherwise if it is a file then all the content inside those files are shown in terminal.

Code To Match Time Interval:

Save the code in a file named "RecursiveDirectoryFilePrintContent.sh".

Running the Code:

Just type the code below in terminal. Make sure to cd into that directory if you have not opened the terminal in that directory. Also make sure to create some a directory named "deletefolder", inside that create more directories and inside those directories some text files with some dummy data.

bash RecursiveDirectoryFilePrintContent.sh

No comments: