I need help for a bash script that counts files and folders in a specified directory on a Linux system (Debian), but I want to exclude a specified folder.
I have a main directory named workdir
with different script files and folders. Inside workdir
, I have a directory named mysshfs
. I use fuse/sshfs to mount an external folder in the mysshfs
folder.
Now I start some commands to get information about file/directory count and file/directory size, but I want to exclude the directoy mysshfs
.
My bash commands that work:
get the full size of
workdir
| no fuse/sshfs in use$ du -hs workdir
get the full size of
workdir
, excludingmysshfs
| fuse/sshfs in use$ du -hs --exclude=mysshf workdir
count files in
workdir
| no fuse/sshfs in use$ find workdir -type f | wc -l
count folders in
workdir
| no fuse/sshfs in use$ find workdir -type d | wc -l
count files in
workdir
, excludingmysshfs
| no fuse/sshfs in use$ find workdir -type f -not -path "*mysshfs*" | wc -l
count folders in
workdir
, excludingmysshfs
| no fuse/sshfs in use$ find workdir -type d -not -path "*mysshfs*" | wc -l
When I use commands 5 & 6 and the remote directory is mounted under the mysshfs
directory, the commands hang.
The commands eventually works and show the correct output, but it looks like the commands are still looking inside the excluded directory even though they shouldn't be, so it takes a long time to display the result.
Where is my error or did I forget something in my commands 5 & 6? Or can I use other commands for my results?
I need to count files and directories using 2 separate commands and exclude a specified folder that is mounted over fuse/sshfs to get a fast result.