how to rename a file in linux
hello,
I am trying to rename the file by adding .txt extension and also before renaming, I want to replace . in file with _ right now file looks like this mdm.201504021628 after execution of my script file name should be mdm_201504021628.txt #!bin/bash //reading all files from directory files=$(hadoop fs -ls /dl/data/landing/hivedb/lnd_attunity_kpi_db_backup/auth_master | awk '!/^d/ {print $8}') for f in $files; do //using sed to replace . with _ and then feeding to hadoop fs command sed 's/./\_/g' $f | hadoop fs -mv $f $f.txt done Thanks for your help in advance. |
Use the rename command, it will rename a file based on a template, check the manpage for details.
|
In routine cases, the mv (move) command will do the job. See
Code:
man mv |
If you just want to rename files, you can do something simple like this
Code:
for i in $files; do echo mv "$i" "$(echo $files | sed 's/\./_/g' ).txt" ; done If the for loop is giving you the results you are asking, run the script again without the echo part. |
All times are GMT -5. The time now is 03:00 AM. |