Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cd into a directory without knowing its name in bash

Tags:

bash

cd

If I know there will be a single folder inside a directory, but I do not know it's name, is there a simple way in bash to go into it? If I wanted to do a check to make sure a folder exists within the current directory, can that be done?

like image 544
user3475234 Avatar asked Mar 11 '15 06:03

user3475234


1 Answers

If there is only one sub-directory inside your current path then you can use this glob pattern to do cd:

cd */

Pattern */ matches all the sub-directories from current path and since there is only one so this cd will just change directory to single sub-directory.

like image 66
anubhava Avatar answered Sep 30 '22 19:09

anubhava