我试着让一个例子发挥作用:
以下是我要做的事:
( a)文件夹中有7个文件,文件的名称和时间戳都是附加的。
例如:Windows_<timestamp>.csv和Linux_<timestamp>.csv等等。
我想首先将将要重新命名的文件移到新文件夹中,然后重命名当前文件。
我试过看Rename multiple files by replacing a particular pattern in the filenames using a shell script,但这个脚本对我不起作用。我认为我必须修改里面的一些东西,但我似乎不能让它工作。
有人能帮帮我吗?我真的被困在这里了。
谢谢!
发布于 2014-11-03 19:19:26
#!/bin/bash
# find all the files that are created today and end with an extension.
# a) First find all the files created today, and filter only the files we care about.
# b) Move all these files into a new folder.
# c) Iterate all the files in this new folder.
# d) Re-name all the files in the destination folder by replacing the _
sourceFolderName="/home/abhididdigi/Desktop/TADDM"
targetFolderName="/home/abhididdigi/Desktop/TADDM_ServiceNow/"
#find all the files created today and only the CSV ones.
find $sourceFolderName -type f -mtime 0 -name '*.csv'|
while read filename
do
# TODO: Find only those files that we care about
cp $filename $targetFolderName
done
#targetFileName=${filename%_*}|sed 's#.*/##';
#Rename the files now, removing the timestamp from underscore, so that it is ready to consume.
for filename in $targetFolderName*; do
mv -v "${filename}" ${filename%_*}.`echo "${filename}" | awk -F. '{print $2}'`
donehttps://stackoverflow.com/questions/26716638
复制相似问题