Count files and directories using shell script

后端 未结 5 653
悲&欢浪女
悲&欢浪女 2021-01-01 18:49

I\'m learning bash scripting and have written a script to count the files and directories in the directory that is supplied as argument. I have it working one way which seem

5条回答
  •  不思量自难忘°
    2021-01-01 19:42

    You're not iterating over the list of files inside the given directory; add /* after $LOCATION. Your script should look like:

    ...
    for item in $LOCATION/*
    do
    ...
    

    As pointed by dogbane, just adding /* will count only files that does not begin with .; for doing so, you shall do the following:

    ...
    for item in $LOCATION/* $LOCATION/.*
    do
    ...
    

提交回复
热议问题