Removing last n characters from Unix Filename before the extension
问题 I have a bunch of files in Unix Directory : test_XXXXX.txt best_YYY.txt nest_ZZZZZZZZZ.txt I need to rename these files as test.txt best.txt nest.txt I am using Ksh on AIX .Please let me know how i can accomplish the above using a Single command . Thanks, 回答1: In this case, it seems you have an _ to start every section you want to remove. If that's the case, then this ought to work: for f in *.txt do g="${f%%_*}.txt" echo mv "${f}" "${g}" done Remove the echo if the output seems correct, or