Re: rename and move
From: jpd (read_the_sig_at_do.not.spam.it)
Date: 07/20/04
- Next message: David Lord: "Re: 5.2.1 Freezes while creating new root filesystem (during sysinstall) WRITE_DMA WARNING"
- Previous message: jpd: "Re: FreeBSD boot message...critical, or..?"
- In reply to: Marshall McCabe: "rename and move"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 20 Jul 2004 05:12:14 +0000 (UTC)
On 2004-07-20, Marshall McCabe <mccabe@omsc.net> wrote:
> Is there a way to rename and move a file by executing a script?
Yes. Have the script execute a mv(1) on the file. You can also do
it directly, without a script but from the command line.
> We
> need to shorten long file names and them move the newly named file to
> a different directory. An example of the current names is:
>
> MB4010A1835FFP.20040716.115956.1548
>
> we would like to nename to 20040716.115956
>
> All of the files have the same characters until the date (20040716)
Of course you can do that. I'd write an one-liner but for the sake of
readability I'll provide something script-like:
#!/bin/sh
for file in MB4010A1835FFP.*
# strip off the first bit
newfile="${file##MB4010A1835FFP.}"
# strip off the last dot and four digits
newfile=`echo $newfile|sed 's/\.[0-9][0-9][0-9][0-9]$//'`
# if there were more files with the same date and subsecond
# suffix, only the last will survive
mv "$file" "$newfile"
end
You could delete the first step and integrate it into the sed statement.
You could rewrite the sed statement to use esed and/or a repeat count.
This will not work for subdirectories, but you could use find(1) in a
variety of ways to compensate for that. To move files to a new directory,
insert the directory in the apropriate place.
If you need to do this kind of thing more often, I'd suggest getting
a book on shell programming and the use of sed and regexpen. This is
a fairly basic question for anyone familiar with un*x.
-- j p d (at) d s b (dot) t u d e l f t (dot) n l .
- Next message: David Lord: "Re: 5.2.1 Freezes while creating new root filesystem (during sysinstall) WRITE_DMA WARNING"
- Previous message: jpd: "Re: FreeBSD boot message...critical, or..?"
- In reply to: Marshall McCabe: "rename and move"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|