Given a scenario where the file, say file_A, locate in directory dir_A is required to rename into this format pattern <file>_yyyymmdd.txt. I’m require to write a bash script to accomplish this task. In addition to this, dir_A sometimes may contain multiple files, the script must be able to handle such situation.
Here is my work:
... ... for XFILE in `ls ${DIR_A} | grep -v "\."` do mv ${XFILE} ${XFILE}_`date +%Y%m%d`.txt doneSurprise me! It just take 4 lines of code.
No comments:
Post a Comment