1 thought on “remove file ending bash”

  1. That doesn’t do that. Consider, you’d have a file named “foo.cfg.bz2”. Your command would move that file to “foo.bz2”.

    You’re looking for %.

    Remove matching suffix pattern.


    ask@ewzw032:~/tmp$ f=foo.cfg
    ask@ewzw032:~/tmp$ echo ${f} ${f%.cfg}
    foo.cfg foo

    ask@ewzw032:~/tmp$ f2=foo.cfg.bz2
    ask@ewzw032:~/tmp$ echo ${f2} ${f2%.cfg} ${f2/.cfg/}
    foo.cfg.bz2 foo.cfg.bz2 foo.bz2


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.