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?
Asked
Active
Viewed 4,716 times
1 Answers
18
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.

anubhava
- 761,203
- 64
- 569
- 643
-
3PS: If there are more than one directory then `cd */` will change to first sub-directory. – anubhava Mar 11 '15 at 07:16