linux shell 获取路径中指定信息

file=/home/data/hunan/hn.2015-9-11.log.bbk

file_log_name=`basename $file`  ## file_log_name 就等于 hn.2015-9-11.log.bbk

file_test=`basename $file .bbk` ## file_test 就等于 hn.2015-9-11.log

 

no_file_path=${file%/*}   ### 获取文件所在的路径  即 /home/data/hunan

city=${no_file_path##*/}   ### 获取路径的最后一个文件夹名称  即 hunan

posted @ 2015-09-11 14:45  沉下心学习  阅读(669)  评论(0编辑  收藏  举报