Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Trivy: List of Methods to Ignore Directories & Files During Scanning

Trivy provides multiple ways to ignore directories, files, and vulnerabilities during scanning. This guide covers all correct and updated methods, including command-line options, configuration files, and post-processing techniques.


1๏ธโƒฃ Ignore Directories & Files Using Command-Line Options (Recommended for Quick Exclusions)

Trivy supports --skip-dirs and --skip-files flags to exclude directories and files while scanning.

Examples:

โœ… Ignore specific directories

trivy image --skip-dirs "/var/lib/gems/2.5.0/gems/fluent-plugin-detect-exceptions-0.0.13" \
            --skip-dirs "/var/lib/gems/2.5.0/gems/http_parser.rb-0.6.0" \
            quay.io/fluentd_elasticsearch/fluentd:v2.9.0
Code language: JavaScript (javascript)

โœ… Ignore directories when scanning a local filesystem

trivy fs --skip-dirs "./testdata/*" .
Code language: JavaScript (javascript)

โœ… Ignore Terraform-related files and directories

trivy config --skip-dirs "**/.terraform" .
Code language: JavaScript (javascript)

โœ… Ignore specific files during image scanning

trivy image --skip-files "/Gemfile.lock" --skip-files "/var/lib/gems/2.5.0/gems/http_parser.rb-0.6.0/Gemfile.lock" quay.io/fluentd_elasticsearch/fluentd:v2.9.0
Code language: JavaScript (javascript)

โœ… Ignore all foo directories in any subdirectory

trivy image --skip-files "**/foo" image:tag
Code language: JavaScript (javascript)

โœ… Use --file-patterns to ignore files based on type

trivy fs --file-patterns "dockerfile:.*.docker" --file-patterns "kubernetes:*.tpl" --file-patterns "pip:requirements-.*\.txt" .
Code language: CSS (css)

๐Ÿ“Œ Use Case: Best when you want to exclude files or directories temporarily without modifying any configuration files.


2๏ธโƒฃ Use trivy.yaml Configuration File for Persistent Directory/File Skipping

For a permanent solution, create a trivy.yaml file in the root of your project.

Example trivy.yaml

scan:
  skip-dirs:
    - "**/examples/**"
    - "**/.terraform/**"
    - "node_modules"
    - "vendor"
  skip-files:
    - "**/*.log"
    - "**/Gemfile.lock"
Code language: JavaScript (javascript)

โœ… Run Trivy with the configuration file:

trivy fs --config trivy.yaml .
Code language: CSS (css)

๐Ÿ“Œ Use Case: Best for consistent exclusions across multiple runs without needing CLI options.


3๏ธโƒฃ Ignore Specific Vulnerabilities Using .trivyignore

You can ignore specific vulnerabilities by their IDs using a .trivyignore file.

Example .trivyignore

AVD-KSV-0014
CVE-2023-1234

โœ… Run Trivy and apply .trivyignore:

trivy fs --ignorefile .trivyignore .
Code language: CSS (css)

๐Ÿ“Œ Use Case: When you want to exclude false positives or known vulnerabilities without ignoring entire files or directories.


4๏ธโƒฃ Use find to Dynamically Exclude Directories Before Running Trivy

If you don’t want to modify your Trivy configurations, you can manually exclude directories before scanning.

โœ… Find and exclude examples and node_modules directories

find . -type d \( -name "examples" -o -name "node_modules" \) -prune -o -print | trivy fs .
Code language: PHP (php)

๐Ÿ“Œ Use Case: When you cannot modify project files but need to exclude directories.


5๏ธโƒฃ Use grep -v to Filter Out Results After Scanning

If Trivy scans everything but you want to remove unwanted results from the output:

โœ… Remove results from examples/ directories

trivy fs . | grep -v "examples/"
Code language: JavaScript (javascript)

๐Ÿ“Œ Use Case: Quick fix when Trivy outputs unwanted directories but scanning time is not a concern.


Final Comparison: Best Method to Use

MethodBest ForPermanent?Performance Impact?
--skip-dirs / --skip-filesQuick exclusionsโŒ Noโœ… Improves
trivy.yaml (skip-dirs, skip-files)Persistent exclusionsโœ… Yesโœ… Improves
.trivyignore (Ignore CVEs)Ignoring vulnerabilitiesโœ… Yesโš ๏ธ No impact
find -pruneExcluding before scanningโŒ Noโœ… Improves
grep -vFiltering after scanningโŒ Noโš ๏ธ No impact

Conclusion

๐Ÿš€ Best method โ†’ Use --skip-dirs and --skip-files in the CLI for quick fixes.
โšก For permanent exclusions โ†’ Use trivy.yaml.
๐Ÿ”Ž To ignore vulnerabilities only โ†’ Use .trivyignore.
โณ If you can’t modify configurations โ†’ Use find or grep.

This is the correct, updated, and complete guide to ignoring directories and files in Trivy. โœ… Let me know if you need further clarification! ๐Ÿš€

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Top 10 Presentation Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, creating engaging and impactful presentations is more than just slides with bullet pointsโ€”itโ€™s about telling a story, conveying ideas visually, and keeping your audience…

Read More

Should A Student Use ChatGPT To Learn DevOps Instead Of Courses?

As a student looking to learn DevOps, you might be wondering if ChatGPT is a good alternative to traditional courses. While there are some benefits to using…

Read More

Top 10 Digital Signature Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, digital transformation has reshaped the way businesses manage documents, sign agreements, and engage with clients. Digital signatures have become an essential component of this…

Read More

Top 10 Graphics Design Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, graphics design tools are more essential than ever for businesses, content creators, designers, and marketers across industries. From creating brand identities and advertising materials…

Read More

How to Optimize Your headless CMS for Multilingual Websites

A multilingual site enables a company to internationalize itself to different audiences for better engagement and ultimately, international brand awareness. However, without the proper considerations with the…

Read More

Top 10 AI SEO Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI SEO tools have become indispensable for digital marketers, businesses, and content creators aiming to dominate search engine rankings. These tools leverage artificial intelligence…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x