Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Exclude a Specific Directory in NCDU Command

How do I exclude a directory from ncdu scanning?

I can't found the information in man ncdu page.

When doing ncdu -x / it scanned my /home/tmp directory for almost an hour.

like image 571
Drunken M Avatar asked Aug 09 '19 15:08

Drunken M


People also ask

How do you exclude a directory?

To exclude multiple directories, OR them between parentheses. And, to exclude directories with a specific name at any level, use the -name primary instead of -path .

How do I exclude a directory in Find command?

We can exclude directories by using the help of “path“, “prune“, “o” and “print” switches with find command. The directory “bit” will be excluded from the find search!

How do you exclude a directory in LS?

without directories — and here it is. Adding -ls or -exec ls -l {} \; would make it like ls -l without directories. find .


Video Answer


2 Answers

ncdu has the same command line options as the du command, so to exclude a directory simply use:

--exclude /dir/path

For example: ncdu -x / --exclude /home/tmp

To exclude multiple directories: ncdu -x / --exclude /home/tmp --exclude /var/log

etc.

Note that you should avoid a trailing slash (use /home/tmp NOT /home/tmp/) otherwise it will fail to actually exclude the directory.

like image 174
Drunken M Avatar answered Oct 22 '22 16:10

Drunken M


NCDU - ncdu (NCurses Disk Usage) is a curses-based version of the well-known 'du', and provides a fast way to see what directories are using your disk space.

As part of the scan options, you can be more accurate and save time by excluding directory or directories by this formula:

ncdu <pathToScan> --exclude=<excludeDirA> --exclude=<excludeDirB> --exclude=<excludeDirC>

for example:

sudo ncdu / --exclude=/dev --exclude=/Applications

For more options ,attaching ncdu scan documentation:

 Scan Options

These options affect the scanning progress, and have no effect when 
importing directory information from a file.


-x  Do not cross filesystem boundaries, i.e. only count files and directories on the same filesystem as the
           directory being scanned.

   --exclude PATTERN
       Exclude files that match PATTERN. The files will still be displayed by default, but are not counted
       towards the disk usage statistics. This argument can be added multiple times to add more patterns.

   -X FILE, --exclude-from FILE
       Exclude files that match any pattern in FILE. Patterns should be separated by a newline.

   --exclude-caches
       Exclude directories containing CACHEDIR.TAG.  The directories will still be displayed, but not their
       content, and they are not counted towards the disk usage statistics.  See
       http://www.brynosaurus.com/cachedir/

   -L, --follow-symlinks
       Follow symlinks and count the size of the file they point to. As of ncdu 1.14, this option will not follow
       symlinks to directories and will count each symlinked file as a unique file (i.e. unlike how hard links
       are handled). This is subject to change in later versions.
like image 33
avivamg Avatar answered Oct 22 '22 16:10

avivamg