Need help with a Bash shell script

Hi new to the forums looking for some help with some Linux scripting.
:wall::wall::wall:
currently working on a script that calculates user information, and i am trying to find out how i would go about getting the amount of regular files, the amount of hidden files, the amount of regular directories, the amount of hidden directories, and the amount of other types of files(AKA links).

I�ve already managed to figure out how many normal files i have using a function that uses the out put of a variable.
this is the code i used

##this is the variable
files=$(ls -a $HOME)

##this is the function
filesfunc(){
files=$#
for hidden in $#
do
if [ "$hidden" = "." ]
then
$hidden=$(expr $hidden - $files)
fi
done
echo -e "Contains:\t$files regular file(s), and $hidden hidden"
}

##calling it like so
filesfunc $files

that code will get me the correct amount of files but it just shows me the same for hidden.

the output i am looking for is

contains:  ## regular files, and ## hidden
                 ## directories, and ## hidden
                 ## other types of files.

thank you in advanced for your help and time
:slight_smile:

you can do it in find command itself

regular file

find . -type f | wc -l

regular directory

find . -type d | wc -l

hidden file

find . -type f -name "\.[a-zA-Z0-9]*"  | wc -l

hidden directory

find . -type d -name "\.[a-zA-Z0-9]*"  | wc -l
1 Like

You've got a LONG way to go my friend!

The variable '$#' returns how many positional parameters the function has (a numerical value).

You-re setting the variable 'files' to the output of ls -a $HOME , and then resetting it inside the function to '$#'

for hidden in $# , will NEVER return a value of "." it's numerical! So your [ test ] will not produce a TRUE result.

Do you want regular files that are not hidden?
Directories are still regular files.
What about hidden directories?

Even after correcting the above,

Is wrong, because hidden_files are also files, so it should be $files - $hidden

1 Like

yah i am still pretty fresh to linux scripting. thanks for your help tho i really appreciated it :smiley:

the output that i want is all the files in home and then all that are hidden
so regular files is basicly total files and the hidden are just the hidden files from the total