How to rename files without changing extension in Linux 102221.pdf to 102221_name.pdf

前端 未结 3 1285
时光取名叫无心
时光取名叫无心 2021-01-16 09:46

How to rename files without changing extension in Linux \\

102221.pdf to 102221_name.pdf

相关标签:
3条回答
  • 2021-01-16 10:11

    This is what you want I think:

    for x in *; do mv "$x" "${x%.*}_name.${x##*.}"; done
    
    • ${x%.*} will give the name of the file without extention
    • ${x##*.} will extract the extentions
    0 讨论(0)
  • 2021-01-16 10:14
    ls * | sed -r 'p;s/\.pdf$/_name\.pdf/g' | xargs -n2 mv
    

    list all the files with ls and pipe the output to sed. sed replaces .pdf with _name.pdf and outputs both the original file name and the new file name to xargs with will call mv with the 2 parameters.

    you can also use the rename command which is simpler

     rename 's/\.pdf$/_name\.pdf/g' ./*
    

    The regex pattern remains the same though

    0 讨论(0)
  • 2021-01-16 10:28

    well i am not so good in linux.. but still found a working answer for you.. hope it will solve ur purpose..

    check the given link.. you might need a light weighted tool called as jhead mainly its to get the header information about the file link created date and time and other.. you can find the information which suits you..

    Answer https://superuser.com/questions/90057/linux-rename-file-but-keep-extension

    jhead http://www.sentex.net/~mwandel/jhead/

    0 讨论(0)
提交回复
热议问题