Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open all files in a directory and subdirectories using bash terminal command?

Tags:

bash

terminal

zsh

I have an alias where I can do open file1.type file2.type or open *.type

What I want is to be able to use this on all subdirectories of my current location. So if I'm in the parent directory and there are two child directories, running the command will be the same as running open file1.type file2.type child1/file1.type child2/file1.type

So something like open -? *.type is what I'm looking for.

like image 804
o_O Avatar asked Dec 24 '22 21:12

o_O


2 Answers

If running zsh or bash 4.x with the globstar option set, ** will match all directories recursively.

#!/bin/zsh
open **/*.type

...

#!/bin/bash
shopt -s globstar
open **/*.type
like image 99
Ignacio Vazquez-Abrams Avatar answered Jan 05 '23 15:01

Ignacio Vazquez-Abrams


find works for this sort of functionality. Something like this:

find . -type f -name \*.type -exec open {} \;

Or in this case, since open is an alias, you have to run the shell as the command:

find . -type f -name \*.type -exec bash -c open {} \;
like image 21
Paul Hicks Avatar answered Jan 05 '23 16:01

Paul Hicks