You are not logged in.
Pages: 1
Could someone help me to create a script (or oneliner) that will perform this operation for a directory of files?
mv "first file.ext" "first file(word).exe"
(where the "word" part can vary)
In other words, I need to rename a file to a similarly named file that has another word in parentheses at the end (but before the extension). That word varies depending on when the file was created, so I can't just do something like "mv file.ext file(new).ext", unforunately. These filenames also have spaces.
Thanks in advance for any help!
dvdtube - download all uploads from a YouTube user and then optionally create a DVD.
(Regular version AUR link / SVN version AUR link)
Offline
cd into your dir and do the following:
ADD_TEXT="add this text"
EXT=.asdf
for file in *$EXT;
do mv "$file" "$(basename "$file" $EXT)${ADD_TEXT}${EXT}"; done
☃ Snowman ☃
Offline
mmv is perfect for this job
mmv '*.*' '#1newtext.#2' would do I believe.
EDIT: forgot the dot in the second argument
Last edited by Procyon (2008-11-26 16:31:08)
Offline
mmv ??
Where do I find that? ('which mmv' yields zilch - and it's not a packet or group)
Offline
You can find it in AUR.
Offline
Check out the rename command too. May not be useful here, though...
Offline
i've fallin in love with rename; i'm not sure i fully understand what you're going for but maybe this'll get you in the right direction
$ ls
file1.exe file2.exe file3.exe
$ rename .exe \(word\).exe *.exe
$ ls
file1(word).exe file2(word).exe file3(word).exe
$
EDIT: now i see what you going for...
as per here:
linux does not *normally* store creation dates/times... there's a myriad of ways to find 'last-modified' type information which could be passed to a variable within your script.
i'd try this, can't test right now so you'll have to tweak i'm sure...
# usage commandname [directory to act on]
if [ -z $1 ];then
echo Give target directory;
exit 0;
fi
find "$1" -name '*.exe' | while read file ; do
mod=[command to get your "word" variable] $file
newname=$(echo "$file" | sed s/.exe/\("$mod"\).exe/g)
mv $file $newname
echo ""$file" changed to -> "$newname"" # for debugging
done
exit 0
Last edited by brisbin33 (2008-11-26 17:53:51)
//github/
Offline
If it doesn't have to be command line based... Have a look at KRename...
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Ah.. Thanks, everyone. basename and krename were the missing links!
dvdtube - download all uploads from a YouTube user and then optionally create a DVD.
(Regular version AUR link / SVN version AUR link)
Offline
Pages: 1