04-07-2008
rename
hi,
im doin an assignment which requires you to build a shell script to do the MS DOS style equivilant (sp?) of the rename function. What i have to do is a loop which checks the following rules and output messages (same):
Can't have anything after target
Can't have more than one dot
Can't have more than one asterisk
Doesn't exist
Must have a dot
No target
Targets consist of three parts: a dot, an asterisk and a string of filename characters. The dot is the middle one of the three. I have not started anything of yet as im stick on this first part and have little idea on how to do it. I an wondering if someone could give me a idea on how i would approach this. I have been told that a loop would be best.
Thanks
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi all
how can can remove the underscore from this number in this series
_1234567.abc
_1234567.abcd
I was trying mv _1234567* 1234567
but did not work ?
thanks
s (2 Replies)
Discussion started by: simon2000
2 Replies
2. UNIX for Dummies Questions & Answers
I have a file named -^, I want to look at it, rename, etc. Any help out there?? (5 Replies)
Discussion started by: nj78
5 Replies
3. Shell Programming and Scripting
hi friends,
I writing a script to psot dataset to ceratin server.....while doing ftp I have to rename the file while which is in present server like
present :test server
filename data.097878.
ftp server: it sholu be renamed as data.097878.zip
thanks,
The thing is that while... (1 Reply)
Discussion started by: Nagabhushan
1 Replies
4. UNIX for Dummies Questions & Answers
Hi, I've already search for this issue but I found different scripts for rename files, but I don't know how to customize it for my needs.
Here's what I want to do:
I have a lot of files inside many directories, like this:
/aa/01.txt
/aa/02.txt
/ab/01.txt
/ab/02.txt
I want all those files... (2 Replies)
Discussion started by: piltrafa
2 Replies
5. UNIX for Dummies Questions & Answers
hi guys i am writing a script to change the filename which is enterered as input to lower case letter even if one letter is upper case i have to change it to lower case
i get the input and use
sed comand should i use like that
sed/s/a-z/A-Z/d
will it be like that can u please help me (8 Replies)
Discussion started by: farhan_t49
8 Replies
6. Shell Programming and Scripting
Hi,
I am new to Unix and i have a requirement where i need to write a shell script where i have to loop through various files present in a directory and rename them based on below criteria.
Files in the folder are in the following format. _YYYYMMDD.dat]
SDL_V1_20100530.dat... (6 Replies)
Discussion started by: bishoo
6 Replies
7. UNIX for Dummies Questions & Answers
how to rename a file if I don't know file location ?
Can we below command :
$ find / | mv file1.txt
I am not sure........can any1 help me out ?
Thanks,
Tushar Joshi:mad: (1 Reply)
Discussion started by: tusharjoshi
1 Replies
8. Shell Programming and Scripting
hello, all
I have following files:
file_1 file_2 file_3 ... file_9
Now I want to rename them as:
file_001 file_002 file_003 ... file_009
how to use function 'rename' to accomplish this task? (2 Replies)
Discussion started by: littlewenwen
2 Replies
9. UNIX for Dummies Questions & Answers
I want to rename files
Files show like this
1977SSD_rsdtst.pdf
1976SDP_rstdtsr.pdf
1943FDT_rstdsrt.pdf
1996DFF_stdstrd.pdf
I want to introduce _ after the year, and move the characters to the end
to get
1977_rsdtst_SSD.pdf
1976_rstdtsr_SDP.pdf
1943_rstdsrt_FDT.pdf... (4 Replies)
Discussion started by: kristinu
4 Replies
10. Shell Programming and Scripting
Renaming files using rename on the following files
rename 's/.99999/.99999.sac.pzs/g' *.99999
sac_pzs_iv_esml_hhz__2013.074.10.18.23.0000_2599.365.23.59.59.99999
sac_pzs_iv_favr_hhe__2010.187.00.00.00.0000_2599.365.23.59.59.99999... (1 Reply)
Discussion started by: kristinu
1 Replies
LEARN ABOUT ULTRIX
rename
rename(2) System Calls Manual rename(2)
Name
rename - change the name of a file
Syntax
rename(from, to)
char *from, *to;
Description
The system call causes the link named from to be renamed to. If to exists, then it is first removed. Both from and to must be of the same
type (that is, both directories or both nondirectories) and must reside on the same file system.
The system call guarantees that an instance of to will always exist, even if the system should crash in the middle of the operation.
Return Values
A zero (0) value is returned if the operation succeeds. Otherwise returns -1, and the global variable errno indicates the reason for the
failure.
Restrictions
The system can deadlock if a loop in the file system graph is present.and two processes issue the call at the same time. For example, sup-
pose a directory, contains a file, Suppose that file is hard-linked to a directory, and the directory contains a file, If is hard-linked to
a loop exists. Now suppose one process issues the following call:
rename (dirname/filename secondir/secondfile)
At the same time, another process issues the following call:
rename (secondir/secondfile dirname/filename)
In this case, the system can deadlock. The system administrator should replace hard links to directories with symbolic links.
Diagnostics
The system call fails and neither of the argument files are affected under the following conditions:
[ENOTDIR] A component of either path prefix is not a directory.
[ENOENT] A component of the from path does not exist, or a path prefix of to does not exist.
[ENOENT] Either from or to points to an empty string and the environment defined is POSIX or SYSTEM_FIVE.
[EACCES] A component of either path prefix denies search permission.
[EPERM] The to file exists, the directory containing from is marked sticky, and neither the containing directory nor the to direc-
tory is owned by the effective user ID.
[EPERM] The directory containing from is marked sticky, and neither the containing directory nor the from directory is owned by the
effective user ID.
[EXDEV] The link named by to and the file named by from are on different logical devices (file systems). Note that this error code
is not returned if the implementation permits cross-device links.
[EACCES] The requested link requires writing in a directory with a mode that denies write permission.
[EROFS] The requested link requires writing in a directory on a read-only file system.
[EFAULT] The path points outside the process's allocated address space.
[EINVAL] The from is a parent directory of to, or an attempt is made to rename dot (.) or dot-dot (..).
[ENAMETOOLONG] A component of either pathname exceeded 255 characters, or the entire length of either pathname exceeded 1023 characters.
[ELOOP] Too many symbolic links were encountered in translating either pathname.
[ENOTDIR] The from is a directory, but to is not a directory.
[EISDIR] The to is a directory, but from is not a directory.
[ENOSPC] The directory in which the entry for the new name is being placed cannot be extended, because there is no space left on the
file system containing the directory.
[EDQUOT] The directory in which the entry for the new name is being placed cannot be extended, because the user's quota of disk
blocks on the file system containing the directory has been exhausted.
[EIO] An I/O error occurred while making or updating a directory entry.
[ENOTEMPTY] The to is a directory and is not empty.
[EBUSY] The directory named by from or to is a mount point.
See Also
open(2)
rename(2)