查找文件|文件夹并进入目录命令:cd $()
[root@localhost /]# cd $(dirname "`find / -name 'ifcfg-ens33'`") //查找ifcfg-ens33文件并进入该文件所在目录
[root@localhost network-scripts]#
[root@localhost /]# mkdir -p /etc/sysconfig/network-scripts/kings-dev
[root@localhost ~]# cd $(dirname "`find / -name 'kings-dev'`") //查找kings-dev文件夹并进入该文件夹上层目录
[root@localhost network-scripts]#
[root@localhost ~]# cd $(find / -name 'kings-dev') //查找kings-dev文件夹并进入该文件夹目录
[root@localhost kings-dev]#
[root@localhost src]# du -alh
1.9M ./redis-5.0.5.tar.gz
1.9M .
[root@localhost src]# cd $(dirname `tar -zxvf redis-5.0.5.tar.gz`) //解压redis-5.0.5.tar.gz进入解压目录
[root@localhost redis-5.0.5]#
总结
cd $(dirname "`find / -name '*file or dirname'`") //查找xxxx文件并进入该文件所在目录或文件夹并进入该文件夹上层目录
cd $(find / -name 'dirname') //查找xxxx文件夹并进入该文件夹目录
cd $(dirname "`tar -zxvf xxxx.tar.gz`") //方式1:解压源文件进入解压目录通用
cd $(dirname `tar -zxvf xxxx.tar.gz`) //方式2:解压源文件进入解压目录通用
cd $(dirname "$(tar -zxvf xxxx.tar.gz)") //方式1-2:解压源文件进入解压目录通用
cd $(dirname $(tar -zxvf xxxxtar.gz)) //方式2-2:解压源文件进入解压目录通用
[root@localhost src]# cd $(dirname "`tar -zxvf apache-tomcat-8.5.46.tar.gz`")
[root@localhost conf]# pwd
/usr/local/src/apache-tomcat-8.5.46/conf
[root@localhost src]# cd $(dirname `tar -zxvf apache-tomcat-8.5.46.tar.gz`)
[root@localhost apache-tomcat-8.5.46]# pwd
/usr/local/src/apache-tomcat-8.5.46
[root@localhost src]# cd $(dirname "`tar -zxvf redis-5.0.5.tar.gz`")
[root@localhost redis-5.0.5]# pwd
/usr/local/src/redis-5.0.5
[root@localhost src]# cd $(dirname "`tar -zxvf nginx-1.17.3.tar.gz`")
[root@localhost nginx-1.17.3]# pwd
/usr/local/src/nginx-1.17.3
[root@localhost src]# cd $(dirname "`tar -zxvf libzip-1.5.2.tar.gz`")
[root@localhost libzip-1.5.2]# pwd
/usr/local/src/libzip-1.5.2
[root@localhost src]# tar -zxvf nginx-1.17.3.tar.gz ;cd `basename -s .tar.gz nginx-1.17.3.tar.gz`
[root@localhost nginx-1.17.3]# pwd
/usr/local/src/nginx-1.17.3
[root@localhost src]# cd $(dirname "$(tar -zxvf apache-tomcat-8.5.46.tar.gz)")
[root@localhost conf]# pwd
/usr/local/src/apache-tomcat-8.5.46/conf
[root@localhost src]# cd $(dirname "$(tar -zxvf redis-5.0.5.tar.gz)")
[root@localhost redis-5.0.5]# pwd
/usr/local/src/redis-5.0.5
[root@localhost src]# cd $(dirname $(tar -zxvf apache-tomcat-8.5.46.tar.gz))
[root@localhost apache-tomcat-8.5.46]# pwd
/usr/local/src/apache-tomcat-8.5.46