Trim string from string

This question already has an answer here:

  • Extract filename and extension in Bash 35 answers

  • ONLY_L="${FILES##*/}"

    or

    ONLY_L="$(basename "$FILES")"

    or

    ONLY_L="$(echo "$FILES" | sed 's|.*/||')"

    does what you want


    For sed , you don't have to use /

    For instance, this works as well:

    echo $FILES | sed 's#/tmp/files/##'
    

    You should use the basename command for this. It automatically removes the path and leaves just the filename:

    basename /tmp/files/list
    

    Output:

    list
    
    链接地址: http://www.djcxy.com/p/57084.html

    上一篇: 删除文本文件bash中的文件扩展名

    下一篇: 修整字符串中的字符串