Utility small scripts.
Reading directories using wildcards
for file in /home/user/*
if [ -d "$file" ]
echo "$file is a directory"
elif [ -f "$file" ]
echo "$file is a file"
echo "$file is neither a file nor a directory"
Observe that in the checks $file is enclosed in double quotes since the names can also contain spaces and in that case we would want the whole name to be treated as one element for the FOR loop.
Reading and displaying the contents of the passwd file in some meaningful format.
Now the passwd file contains lines of records in the following format, denoting the information about each of the users(both visible and system)
We would like to present each user's information in a tree-like structure, that makes things more readable. Yes, you can write them to a file for future readability.
for line in `cat /etc/passwd`
echo "Values: $line"
for field in $line
echo " Field: $field"