Sample Header Ad - 728x90

bash count files and directory, summary size and EXCLUDE folders that are fuse|sshfs

1 vote
3 answers
1015 views
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 will run some commands to get information about the **file/directory** count and **file/directory** size, but I want to exclude the directory mysshfs. My bash commands that work: 1. Get the full size of workdir | **no fuse/sshfs in use** $ du -hs workdir 2. Get the full size of workdir, excluding mysshfs | **fuse/sshfs in use** $ du -hs --exclude=mysshf workdir 3. Count files in workdir | **no fuse/sshfs in use** $ find workdir -type f | wc -l 4. Count folders in workdir | **no fuse/sshfs in use** $ find workdir -type d | wc -l 5. Count files in workdir, excluding mysshfs | **no fuse/sshfs in use** $ find workdir -type f -not -path "*mysshfs*" | wc -l 6. Count folders in workdir, excluding mysshfs | **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.
Asked by ReflectYourCharacter (8185 rep)
Feb 22, 2022, 11:25 AM
Last activity: Mar 24, 2025, 07:31 PM