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:
Open up your terminal and navigate to the root folder of your folder hierarchy.
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:
Open your terminal and navigate to the root folder of your folder hierarchy.
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.
