开发者

Basic Shell scripting with control structures. Counting the number of directories and files and whether they are readable writeable and executable

write a shell script that calculates the following information for the contents of a given directory. The directory is to be specified as a single command line argument to your script. You do not need to account for any contents of nested subdirectories -- just the direct contents of the specified directory.

The total number of directories that are in the given directory (note that these are subdirectories). The total number of files in the given directory. The number of items (files/directories) in the current directory that are readable. The number of items (files/directo开发者_如何学Cries) in the current directory that are writable. The number of items (files/directories) in the current directory that are executable.

I tried :

if [ -d $file ] then counter=expr $counter + 1 echo "Number of directories :" $counter fi


I won't write the script for you, but one way to obtain the answer is to use ls -l an association with grep -c, using grep to parse out the appropriate filesystem flags (the drwxrwxrwx column) that ls -l will give you. The key is knowing how to parse this column with grep.

It may not be the most efficient (as we're doing ls multiple times, but it will give you what you're looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜