Sponsored Content
Full Discussion: unix rename
Top Forums UNIX for Dummies Questions & Answers unix rename Post 53392 by zazzybob on Wednesday 14th of July 2004 09:59:58 AM
Old 07-14-2004
Quote:
Originally posted by milhan
Is there another way to do it?
There are lots of ways of doing it, but what's wrong with the method Ygor posted? It's quick and easy.

You could write solutions in Perl, C, XYZ to do this....

e.g. in Perl
Code:
#!/usr/bin/perl

opendir(DIR,".") or die;

while( defined( $file = readdir( DIR ) ) ) {
   next if $file =~ /^\.\.?$/;  # ignore . and ..

   if ( $file =~ /\.jpg/ ) {
      ( $newname = $file ) =~ s/(.*)\.jpg/\1_LRG.jpg/g;
      rename( $file, $newname );
   }
}

closedir(DIR);

but what's the point adding unnecessary complexity?!

Cheers
ZB

Last edited by zazzybob; 07-14-2004 at 11:07 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How Do I rename a unix file contianing spacing?

How can I rename a unix file that has a spacing in in the charactyers? For example, I want to rename or move a file called "My OldFile.txt" to "MyNewFile.txt" or "My_New_file.txt" Please help (7 Replies)
Discussion started by: frankyranky
7 Replies

2. Shell Programming and Scripting

[Unix] a dos style rename wont work

Hey guys i'm creating a dos style rename script, so if a user types say q14.* as the 1st param and b14.* as the 2nd and will rename all q14 files to b14 but keep the extensions, so i've developed nearly the full script "i think", if i use echo(echo "if $1 had been renamed it would now be... (3 Replies)
Discussion started by: fblade1987
3 Replies

3. Shell Programming and Scripting

copy/rename file as date() unix/shell

File.jpg I want to copy and rename this as 2008-12-02.jpg I tried this copy File.jpg date '%y-%m-%d-%H:%M:%S'.jpg This doesnt work.... what do i do? (1 Reply)
Discussion started by: hdogg
1 Replies

4. UNIX for Advanced & Expert Users

How UNIX/AIX handles a file deep down, say it's being read while another one tries to rename it?

Hi Thinkers, On AIX 5.3, we have a monitor program that reads the log file and searching for a certain string pattern that we define(say "transactionException"), if it sees it then it will raise an alert by sending an email. Because the log file XXX.log is rolling into XXX.log.0, XXX.log.1,... (2 Replies)
Discussion started by: TheGunMan
2 Replies

5. Shell Programming and Scripting

Rename a file sequencially in UNIX

I need to be able to look for the last file in a dirctory in UNIX, the file satrt with EFT so this work file=$(ls -tr $EFT*.dat | tail -1) # Select the latest file my last file is EFT1234.dat then I need to be able to get a file that I just ftp and rename with this name EFT1234.dat but... (5 Replies)
Discussion started by: rechever
5 Replies

6. UNIX for Advanced & Expert Users

Unix Command to rename a file in a zipped folder

Hi, I am into automation work. Is there any UNIX command to rename a file in a zipped folder, without unzipping it..??? Thanks in advance.. (1 Reply)
Discussion started by: Victoria.Sam
1 Replies

7. Shell Programming and Scripting

Multiple file rename (change in filename in unix with single command

Dear All, Please help ! i ham having 300 file with E.G. PMC1_4567.arc in seq. like PMC1_4568.arc,PMC1_4569.arc ...n and so on.. i want all those file to be rename like PMC_4567.arc ,PMC_4568.arc .. mean i want to remove 1 from first file name .. pls help.. (6 Replies)
Discussion started by: moon_22
6 Replies

8. Shell Programming and Scripting

How to rename a file even when it shows permission Denied in Unix

While executing a script, I am not being able to able to create a file as the file with the same name already exists. That existing file is not getting overwritten as I am not the owner of the file. So, Neither am I able to rename the file nor delete the existing file, so as to get my file created.... (2 Replies)
Discussion started by: Haimanti
2 Replies

9. UNIX for Dummies Questions & Answers

Help with Unix file rename

Hi All, I have a unix file which is ceated with variable name, for example: FIRST_FILE_3456 and next time it will be FIRST_FILE_3457 and so on. I need to rename this file like PREV_FIRST_FILE_XXXX where XXXX is the variable part of the file FOR Example 3456 or 3457, etc. Please help to... (4 Replies)
Discussion started by: Mohammad T Khan
4 Replies

10. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies
DIRECTORY(3)						   BSD Library Functions Manual 					      DIRECTORY(3)

NAME
closedir, dirfd, opendir, readdir, readdir_r, rewinddir, seekdir, telldir -- directory operations LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <dirent.h> int closedir(DIR *dirp); int dirfd(DIR *dirp); DIR * opendir(const char *dirname); struct dirent * readdir(DIR *dirp); int readdir_r(DIR *restrict dirp, struct dirent *restrict entry, struct dirent **restrict result); void rewinddir(DIR *dirp); void seekdir(DIR *dirp, long loc); long telldir(DIR *dirp); DESCRIPTION
The opendir() function opens the directory named by dirname, associates a directory stream with it, and returns a pointer to be used to iden- tify the directory stream in subsequent operations. The pointer NULL is returned if dirname cannot be accessed or if it cannot malloc(3) enough memory to hold the whole thing. The readdir() function returns a pointer to the next directory entry. It returns NULL upon reaching the end of the directory or detecting an invalid seekdir() operation. readdir_r() provides the same functionality as readdir(), but the caller must provide a directory entry buffer to store the results in. If the read succeeds, result is pointed at the entry; upon reaching the end of the directory, result is set to NULL. readdir_r() returns 0 on success or an error number to indicate failure. The telldir() function returns the current location associated with the named directory stream. Values returned by telldir() are good only for the lifetime of the DIR pointer (e.g., dirp) from which they are derived. If the directory is closed and then reopened, prior values returned by telldir() will no longer be valid. The seekdir() function sets the position of the next readdir() operation on the directory stream. The new position reverts to the one asso- ciated with the directory stream when the telldir() operation was performed. The rewinddir() function resets the position of the named directory stream to the beginning of the directory. The closedir() function closes the named directory stream and frees the structure associated with the dirp pointer, returning 0 on success. On failure, -1 is returned and the global variable errno is set to indicate the error. The dirfd() function returns the integer file descriptor associated with the named directory stream, see open(2). Sample code which searches a directory for entry ``name'' is: len = strlen(name); dirp = opendir("."); while ((dp = readdir(dirp)) != NULL) if (dp->d_namlen == len && !strcmp(dp->d_name, name)) { (void)closedir(dirp); return FOUND; } (void)closedir(dirp); return NOT_FOUND; LEGACY SYNOPSIS
#include <sys/types.h> #include <dirent.h> <sys/types.h> is necessary for these functions. SEE ALSO
close(2), lseek(2), open(2), read(2), compat(5), dir(5) HISTORY
The closedir(), dirfd(), opendir(), readdir(), rewinddir(), seekdir(), and telldir() functions appeared in 4.2BSD. BSD
June 4, 1993 BSD
All times are GMT -4. The time now is 02:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy