I'm trying to organize my image files in a directory for a photo manager that only supports certain formats. Some of these files are missing extensions, so I need a way to see all the different types of files in that folder. Does anyone know how I can generate a list of all file types in a directory, including hidden files, recursively?
5 Answers
You can use a combination of the `find` and `file` commands to list the file types in your directory. Try running this command from the parent folder:
```bash
find thefoldername/ -type f -exec file {} +
```
This will look through all files in the specified folder and return their types, even without file extensions. If you want a quick check just in the current directory (without subfolders), you can simplify it to:
```bash
file *
```
You can also try using `imagemagick` if it's installed. Here's a command that might help:
```bash
find . -type f -exec bash -c 'echo -e "$(basename "$1") $(identify -format "%m" "$1[0]")"' _ {} ;
```
This will list the file name along with its type, which can be super handy! Just remember to adjust it based on your setup.
Just a quick note: Linux doesn’t rely solely on file extensions. The `file` command is great for identifying file types regardless of their names. Running `file *` in your directory will give you a list of all your files and their types. It'll handle hidden files too if you include them by using `.*`. Just make sure you check that way if you have any hidden ones you're curious about!
If you're just looking to list file types, it's worth mentioning that you can escape a lot of hassle using a graphical file manager. Something like Midnight Commander can give you a neat overview of files and their types without diving into the command line.
Another good command for this is:
```bash
ls -1 | while IFS= read -r f; do [ -f "$f" ] && echo "$(file -b --mime-type "$f") $f"; done
```
This one lists each file along with its MIME type. Just make sure you're in the correct directory when you run this. It does a nice job of preserving spaces in filenames, too!

That's smart! I didn't know about `-b --mime-type` for the `file` command. Makes it easier to understand the output.