Grab the filename in Unix out of full path
问题 I am trying to get "abc.txt" out of /this/is/could/be/any/path/abc.txt using Unix command. Note that /this/is/could/be/any/path is dynamic. Any idea? 回答1: In bash : path=/this/is/could/be/any/path/abc.txt If your path has spaces in it, wrap it in " path="/this/is/could/be/any/path/a b c.txt" Then to extract the path, use the basename function file=$(basename "$path") or file=${path##*/} 回答2: basename path gives the file name at the end of path Edit: It is probably worth adding that a common