简体   繁体   English

在bash中不知道其名称的情况下进入目录

[英]cd into a directory without knowing its name in bash

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? 如果我知道目录中会有一个文件夹,但我不知道它的名字,bash中有一个简单的方法可以进入它吗? If I wanted to do a check to make sure a folder exists within the current directory, can that be done? 如果我想检查以确保当前目录中存在文件夹,可以这样做吗?

If there is only one sub-directory inside your current path then you can use this glob pattern to do cd : 如果当前路径中只有一个子目录,则可以使用此glob模式执行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. 模式*/匹配当前路径中的所有子目录,因为只有一个,所以这个cd只会将目录更改为单个子目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM