How can I find all of the distinct file extensions in a folder hierarchy?

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for How can I find all of the distinct file extensions in a folder hierarchy?

📂 How to Find All Distinct File Extensions in a Folder Hierarchy 📂

Are you tired of manually searching through countless file extensions in your folder hierarchy? 🤔 Don't worry, I've got you covered! In this blog post, I'll walk you through some easy solutions to find all the distinct file extensions on your Linux machine using the command line. Get ready to level up your file management game! 💪

🐧 Solution - Embrace the Power of Shell! 🐧

When it comes to efficiently navigating through folders and files in Linux, the shell is your best friend! Let's dive into a few methods that will help you find those elusive distinct file extensions:

Method 1: 'find' Command with 'cut' and 'sort'

One way to achieve this is by using the trusty 'find' command along with 'cut' and 'sort'. Here's the step-by-step breakdown:

  1. Open up your terminal and navigate to the root folder of your folder hierarchy.

  2. Run the following command:

find . -type f | rev | cut -d . -f 1 | rev | sort -u

Let's break it down:

  • find . -type f returns a list of all files in the current directory and its subdirectories.

  • rev reverses the order of characters in each line.

  • cut -d . -f 1 extracts the portion of each line before the first dot, effectively giving us the file extension.

  • sort -u sorts the file extensions in alphabetical order and removes duplicates.

Method 2: 'tree' Command with 'grep', 'sed', and 'tr'

If you prefer a more visual representation of your folder hierarchy, the 'tree' command can be quite handy. Here's how you can use it to find distinct file extensions:

  1. Open your terminal and navigate to the root folder of your folder hierarchy.

  2. Run the following command:

tree -afi . | grep -Eo '\.[^.]+$' | sed 's/\.//g' | tr '[:upper:]' '[:lower:]' | sort -u

Here's what each component does:

  • tree -afi . prints the folder hierarchy, including all files.

  • grep -Eo '\.[^.]+$' extracts the file extensions using regular expressions.

  • sed 's/\.//g' removes the leading dot from each file extension.

  • tr '[:upper:]' '[:lower:]' converts all uppercase letters to lowercase for consistency.

  • sort -u sorts the file extensions in alphabetical order and removes duplicates.

🎉 Engage and Share! 🎉

Now you know how to find all the distinct file extensions in a folder hierarchy with just a few simple commands! 🚀 Share this post with your friends who need a little extra help in their file management adventures. Let's make everyone's tech life easier together! 😊

Have you come across any other cool tricks or methods? Share them in the comments below and let's learn from each other! 👇

Happy file extension hunting! 👀✨

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my