Grab the filename in Unix out of full path

后端 未结 4 2009
离开以前
离开以前 2020-12-29 17:42

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 d

4条回答
  •  一生所求
    2020-12-29 18:21

    basename path gives the file name at the end of path

    Edit:

    It is probably worth adding that a common pattern is to use back quotes around commands e.g. `basename ...`, so UNIX shells will execute the command and return its textual value.

    So to assign the result of basename to a variable, use

    x=`basename ...path...`
    

    and $x will be the file name.

提交回复
热议问题