Last active
December 11, 2015 23:48
-
-
Save tousinn/4679043 to your computer and use it in GitHub Desktop.
How to get the File Name, Extension of the File , the File Path under shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.How to get the File Name | |
test_full_file_path="/home/doc/myfile.txt" | |
file_name=`basename ${test_full_file_path}` | |
or | |
file_name=${test_full_file_path##*/} | |
2.How to get the extension of the file | |
test_full_file_path="/home/doc/myfile.txt" | |
file_name=`basename ${test_full_file_path}` | |
extension_name=${file_name##*.} | |
3.How to get the file name without the extension | |
test_full_file_path="/home/doc/myfile.txt" | |
file_name=`basename ${test_full_file_path}` | |
file_name_without_extinsion=${file_name%.*} | |
4.How to get the File Path | |
test_full_file_path="/home/doc/myfile.txt" | |
file_path=${test_full_file_path%/*} | |
【##】:the longest string that matches the pattern from the front of the original string will be deleted | |
【%】: the shortest string that matches the pattern from the back of the original string will be deleted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment