renaming files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users renaming files
# 8  
Old 12-18-2008
Code:
#!/bin/ksh
find . -name \*\.c -print|while read FILENAME
do
        DIR=`dirname "${FILENAME}"`
        FILENAME_NEW="${DIR}/`basename ${FILENAME} .c`.txt"
        mv "${FILENAME}" "${FILENAME_NEW}"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. Shell Programming and Scripting

Renaming files

Hello, I am looking for a command line that will rename name files : f700_abc_o_t_MASTERID_AS_AE_20130323.csv like this f700_abc_o_t_MASTERID_AS_AE_20130324.csv The great idea could be to get the date stamp 20130323 and change any part of it, instead of just change the... (4 Replies)
Discussion started by: Aswex
4 Replies

3. Shell Programming and Scripting

renaming files

Hi, I have a list of files in a folder with the same name ending (over 1000 files) joe.jpy.jpeg joe1.jpy.jpeg joe2.jpy.jpeg jon3.jpy.jpeg jor5.jpy.jpeg .....jpy.jpeg etc. I want to change jpy to hhk So the output will be: joe.hhk.jpeg joe1.hhk.jpeg joe2.hhk.jpeg jon3.hhk.jpeg... (3 Replies)
Discussion started by: kylle345
3 Replies

4. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

5. Shell Programming and Scripting

renaming files

Hi all, using a utility image file was named starting with blank space and a blank space in between. I want to rename the files. file names are in the format " sb 12.tif"," sb 13.tif"," sb 14.tif" the files are in thousands. i want to rename as 12.tif, 13.tif, 14.tif.... thanks. (3 Replies)
Discussion started by: ahkverma
3 Replies

6. UNIX for Dummies Questions & Answers

renaming files

I have a list of files named ab_*.csv I would like to remane them all by removing the ab_ and have *.csv I did the following but I am surely missing something. /* wrong script */ for i in `ls -1 ab_*`; do mv ab_$i $i; done Thanks in advance. (1 Reply)
Discussion started by: jxh461
1 Replies

7. UNIX for Dummies Questions & Answers

Renaming files

Hello! I am not familiar with UNIX and I have this problem: I need to move files from a UNIX machine to a PC. UNIX file names contain ":" as special character which is not recognized in a PC. How can I change ":" for "_" in the name of a bunch of files in UNIX? Thanks for your help. (7 Replies)
Discussion started by: Tygoon
7 Replies

8. UNIX for Dummies Questions & Answers

renaming files

directory name = /usr/tom/1997 files - ABC_1997_ST1_BCD.SQL BCD_1997_ST1_EFG_SAB.SQL TTT_EBC_1997_ST1_A.SQL sub directory - /usr/tom/1997/jan a) I want to just rename the all files ending with '.SQL' and also its contents in the 1997 directory(excluding subdirectories eg... (3 Replies)
Discussion started by: systemsb
3 Replies

9. UNIX for Dummies Questions & Answers

renaming the files

Hi All, Today I got a small problem while handling zipped files in PROD support. There are files in this format and I had to grep them reading some contents A.B.gz.C.D where A,B,C and D stand for variables (like FIRST.NAME.gz.MIDDLE.LAST). I know that these files are zipped files and If I... (1 Reply)
Discussion started by: adurga
1 Replies

10. UNIX for Dummies Questions & Answers

renaming files

i have a set of *.lst files. now i want to change the names from "lst" to "dat". how to do it? ex.: -rw-r--r-- 1 rram group 22 Sep 21 13:10 a.lst -rw-r--r-- 1 rram group 22 Sep 21 13:09 b.lst -rw-r--r-- 1 rram group 22 Sep 21 13:10 c.lst... (4 Replies)
Discussion started by: raguramtgr
4 Replies
Login or Register to Ask a Question
RENAME(2)						      BSD System Calls Manual							 RENAME(2)

NAME
rename -- change the name of a file SYNOPSIS
#include <stdio.h> int rename(const char *old, const char *new); DESCRIPTION
The rename() system call causes the link named old to be renamed as new. If new exists, it is first removed. Both old and new must be of the same type (that is, both must be either directories or non-directories) and must reside on the same file system. The rename() system call guarantees that an instance of new will always exist, even if the system should crash in the middle of the opera- tion. If the final component of old is a symbolic link, the symbolic link is renamed, not the file or directory to which it points. CAVEATS
The system can deadlock if a loop is present in the file system graph. This loop takes the form of an entry in directory 'a', say 'a/foo', being a hard link to directory 'b', and an entry in directory 'b', say 'b/bar', being a hard link to directory 'a'. When such a loop exists and two separate processes attempt to perform 'rename a/foo b/bar' and 'rename b/bar a/foo', respectively, the system may deadlock attempting to lock both directories for modification. Whether or not hard links to directories are supported is specific to the underlying filesystem implementation. It is recommended that any hard links to directories in an underlying filesystem should be replaced by symbolic links by the system adminis- trator to avoid the possibility of deadlocks. Moving or renaming a file or directory into a directory with inheritable ACLs does not result in ACLs being set on the file or directory. Use acl(3) in conjunction with rename() to set ACLs on the file or directory. RETURN VALUES
A 0 value is returned if the operation succeeds, otherwise rename() returns -1 and the global variable errno indicates the reason for the failure. ERRORS
The rename() system call will fail and neither of the argument files will be affected if: [EACCES] A component of either path prefix denies search permission. [EACCES] The requested operation requires writing in a directory (e.g., new, new/.., or old/..) whose modes disallow this. [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. [EFAULT] Path points outside the process's allocated address space. [EINVAL] Old is a parent directory of new, or an attempt is made to rename '.' or '..'. [EIO] An I/O error occurs while making or updating a directory entry. [EISDIR] new is a directory, but old is not a directory. [ELOOP] Too many symbolic links are encountered in translating either pathname. This is taken to be indicative of a looping sym- bolic link. [ENAMETOOLONG] A component of a pathname exceeds {NAME_MAX} characters, or an entire path name exceeds {PATH_MAX} characters. [ENOENT] A component of the old path does not exist, or a path prefix of new does not exist. [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. [ENOTDIR] A component of either path prefix is not a directory. [ENOTDIR] old is a directory, but new is not a directory. [ENOTEMPTY] New is a directory and is not empty. [EPERM] The directory containing old is marked sticky, and neither the containing directory nor old are owned by the effective user ID. [EPERM] The new file exists, the directory containing new is marked sticky, and neither the containing directory nor new are owned by the effective user ID. [EROFS] The requested link requires writing in a directory on a read-only file system. [EXDEV] The link named by new and the file named by old are on different logical devices (file systems). Note that this error code will not be returned if the implementation permits cross-device links. CONFORMANCE
The restriction on renaming a directory whose permissions disallow writing is based on the fact that UFS directories contain a ".." entry. If renaming a directory would move it to another parent directory, this entry needs to be changed. This restriction has been generalized to disallow renaming of any write-disabled directory, even when this would not require a change to the ".." entry. For consistency, HFS+ directories emulate this behavior. SEE ALSO
open(2), symlink(7) STANDARDS
The rename() function conforms to IEEE Std 1003.1-1988 (``POSIX.1''). 4.2 Berkeley Distribution September 18, 2008 4.2 Berkeley Distribution