Examining a directory, files and subdirectories in it
One of the commonest problems we deal with is finding misplaced files and sorting out mangled file hierarchies. This section will discuss tricks for examining a portion of the filesystem and presenting the contents.
Getting ready
The find
command and loops we discussed give us tools to examine and report details in a directory and its contents.
How to do it...
The next recipes show two ways to examine a directory. First we'll display the hierarchy as a tree, then we'll see how to generate a summary of files and folders under a directory.
Generating a tree view of a directory.
Sometimes it's easier to visualize a file system if it's presented graphically.
The next recipe pulls together several of the tools we discussed. It uses the find command to generate a list of all the files and sub-folders under the current folder.
The -exec
option creates a subshell which uses echo to send the filenames to the tr
command's stdin
. There are two tr
commands...