I need to search for all the files that have a hyphen followed by the number 2015 in a maximum depth of 1 directory, this would be equivalent to the current directory and another within a folder without going to its sub-folders. Taking into account that I have a structure like the following:
./
- index-2015/
-- otrodir/
-- assets-2015/
-- tmp/
- contacto-2015/
- contacto/
- index/
- subdominios/
-- subd1/ <-- A partir de aquí ya no debería listar las coincidencias
--- hoja1-2015/
--- hoja2-2015/
command in use
To list all directories of the current level I'm on (with no matching sub-directories) I use:
ls | grep '\w-2015'
The problem with that is that it lists the files for me too, another solution is:
ls -d *-2015
It doesn't list me in subdirectories though. I used the following command but it didn't return any results:
find ./ -type d -regex '/\w-2015/'
The following command will use a maximum depth of 2 by using the option
-maxdepth
, that is, the folder of the path you specify and one more level:Example:
In my project I have:
It doesn't go down to the folder
migrations
. But if I use: