I'm an admirer of this page, i hope I find my answer here.
So, i wanted to check disk usage in particular file system for all directories excluding few directories(which i have in a file stored, gets created dynamically with some requirements).
But what i observed was when i hardcoded the values directly in exclude command, it was way fast and results were accurate. But when i was passing though commands inside exclude command. It was way more time consuming and yielded wrong results. I dont want to hardcode always, please suggest
Harcoded version (a, b are subdirectories) -- gave correct results
du -sh --exclude={a,b} filesystem/*
Command version
Assuming i have a file(directory_list.txt) with a and b directory names in it.
du -sh --exclude={`cat directory_list.txt`} /filesystem/*
Another thing which comes to my mind is as exclude is not yielding me accurate and timely results, i will select directories directly which i want
as below
ls filesystem/ | grep -v $(cat directory_list.txt) > selected.txt --
excluding directories and selecting only needed
du -sh $(cat selected.txt)
But please suggest better way and how can i make my command in exclude command work Thanks Mohammed
directory_list.txt. The syntax is--exclude=PATTERN, so you must make sure that{$(cat directory_list)}results in a valid pattern.duversion offer the-X, --exclude-from=FILE exclude files that match any pattern in FILEoption?directory_list.txtcontains one directory per line, doesdu -sh $(ls filesystem|fgrep -v -f directory_list.txt)do what you want? Note that command substitution$( ... )has some pitfalls. It will not work if there are directory names that contain spaces or other special characters.