Sponsored Content
Top Forums Shell Programming and Scripting How to Rename List of files in a directory Post 302635783 by knip on Sunday 6th of May 2012 08:19:10 AM
Old 05-06-2012
sorry

scenario

for ex in a directory i have 3 files with names as
oldfile111.txt
oldfile222.txt
oldfile333.txt

i want this to be renames to
newfile111.txt
newfile222.txt
newfile333.txt

Thanks in advance...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

copy and rename list of files

Hi all, I am a newbie in writng unix..I am using ksh shell..Does anyone know how to copy a list o files from directory A to directory B with differnt names? i.e in Dir A, I have RPT101.555.TXT RPT102.666.TXT and I want to copy those files to dir B with new naming convention.. in Dir B,... (7 Replies)
Discussion started by: kinmak
7 Replies

2. Shell Programming and Scripting

Rename many files in a directory

Hi, I have around 100 xml file in a directory. I need to rename the files from .xml to .xml1. So i tried using the following command: mv *.xml *.xml1 but i am getting the following error mv: when moving multiple files, last argument must be a directory Try `mv --help' for more... (8 Replies)
Discussion started by: ananthi_ku
8 Replies

3. UNIX for Dummies Questions & Answers

rename files based on their respective directory name

I have a number of files in directories labeled like this: /Data/tr_gray/tr_DTI/dti_FA.nii.gz (the brackets here represent a range of number that the files are labeled with) I need to rename each dti_FA.nii.gz file according to the name of the folder it resides in. For example, the file ... (3 Replies)
Discussion started by: tk0034
3 Replies

4. UNIX for Dummies Questions & Answers

Bash script to rename files in a directory

Dear friends, I have created a script to rename all files in a directory by appending the file name with username (who created the file), the date it was created. For example, "apple.doc" should be renamed to "johnFeb23apple.doc" where "john" is the owner and "Feb23" is file created date. It... (4 Replies)
Discussion started by: djsnifer
4 Replies

5. Shell Programming and Scripting

How do I rename list of files with dateformat

Hello, I have a list of files like -rw-rw-r-- 1 rails rails 8463005 Jul 27 04:02 find_or.log.3.gz -rw-rw-r-- 1 rails rails 33786339 Jul 27 04:02 pro.log.10.gz -rw-rw-r-- 1 rails rails 44815467 Aug 3 04:02 pro.log.9.gz -rw-rw-r-- 1 rails rails 81562896 Aug 4 04:02 pro.log.8.gz... (7 Replies)
Discussion started by: ashokvpp
7 Replies

6. UNIX for Dummies Questions & Answers

Rename files in a directory and move them

I have a directory e2e_ms_xfer/cent01 this contains the multiple files some of which will be named below with unique date time stamps e2e_ms_edd_nom_CCYYMMDD_HHMM.csv What I want to do is in a loop 1) Get the oldest file 2) Rename 3) Move it up one level from e2e_ms_xfer/cent01 to... (1 Reply)
Discussion started by: andymay
1 Replies

7. Shell Programming and Scripting

Rename Files in remote directory

Hi All, I am creating a script which will connect to remote server with ssh and perfom below. - Search in a directory - Search for a pattern - Check the size if greater than the size_limit rename the file. Below is the code i have written. ssh user@host <<EOF find /tmp... (5 Replies)
Discussion started by: Girish19
5 Replies

8. UNIX for Dummies Questions & Answers

Rename files based on a list

Hi, I have a directory with a lot of files like this: a.bam b.bam c.bam I like to rename these files based on a list where the name of the files in the first column will be replasced by the names in the second column. Here is my list which is a tab-delimited text file: a x b y c ... (4 Replies)
Discussion started by: a_bahreini
4 Replies

9. Shell Programming and Scripting

How to rename (move) most recent files in directory?

I'm using cygwin32 on Windows. DN is an environment variable pointed at my download directory. This command works to move the single most recent file in my download directory to my current directory: mv "`perl -e '$p = $ARGV; opendir $h, $p or die "cannot opendir $p: $!"; @f = sort { -M $a... (2 Replies)
Discussion started by: siegfried
2 Replies

10. Shell Programming and Scripting

Rename files from multiple directories along with directory indicator

Hi, Friends, i have a requirement where i need to rename my files residing in multiple sub directories and move them to one different directory along with some kind of directory indicator. For eg: test--is my parent directory and it has many files such as a1.txt a2.txt a3.txt ... (5 Replies)
Discussion started by: gnnsprapa
5 Replies
mv(1)							      General Commands Manual							     mv(1)

NAME
mv - move or rename files and directories SYNOPSIS
extarg] file1 new-file extarg] file1 [file2 ]... dest-directory extarg] directory1 [directory2 ]... dest-directory DESCRIPTION
The command moves: o One file (file1) to a new or existing file (new-file). o One or more files (file1, [file2, ...]) to an existing directory (dest-directory). o One or more directory subtrees (directory1, [directory2, ...]) to a new or existing directory (dest-directory). Moving file1 to new-file is used to rename a file within a directory or to relocate a file within a file system or across different file systems. When the destination is a directory, one or more files are moved into that directory. If two or more files are moved, the desti- nation must be a directory. When moving a single file to a new file, if new-file exists, its contents are destroyed. If the access permissions of the destination dest-directory or existing destination file new-file forbid writing, asks permission to over- write the file. This is done by printing the mode (see chmod(2) and Access Control Lists below), followed by the first letters of the words yes and no in the language of the current locale, prompting for a response, and reading one line from the standard input. If the response is affirmative and the action is permissible, the operation occurs; if not, the command proceeds to the next source file, if any. If file1 is a file and new-file is a link to another file with other links, the other links remain and new-file becomes a new file. If file1 is a file with links or a link to a file, the existing file or link remains intact, but the name is changed to new-file which may or may not be in the directory where file1 resided, depending on directory path names used in the command. The last access and modification times of the file or files being moved remain unchanged. Options recognizes the following options: Perform commands without prompting for permission. This option is assumed when the standard input is not a terminal. Causes to write a prompt to standard output before moving a file that would overwrite an existing file. If the response from the standard input is affirmative, the file is moved if permissions allow the move. Specifies the handling of any extent attributes of the files(s) to be moved. extarg can be one of the following values: Issue a warning message if extent attributes cannot be preserved, but move the file anyway. Do not preserve extent attributes. Do not move the file if the extent attributes cannot be preserved. If multiple source files are specified with a single target directory, will move the files that either do not have extent attributes or that have extent attributes that can be preserved. will not move the files if it cannot preserve their extent attributes. Extent attributes cannot be preserved if the files are being moved to a file system that does not support extent attributes or if that file system has a different block size than the original. If is not specified, the default value for extarg is Access Control Lists (ACLs) If optional ACL entries are associated with new-file, displays a plus sign after the access mode when asking permission to overwrite the file. If new-file is a new file, it inherits the access control list of file1, altered to reflect any difference in ownership between the two files (see acl(5) and aclv(5)). In JFS file systems, new files created by do not inherit their parent directory's default ACL entries (if any), but instead retain their original ACLs. When moving files from a JFS file system to an HFS file system or vice versa, optional ACL entries are lost. EXTERNAL INFLUENCES
Environment Variables determines the interpretation of text as single byte and/or multibyte characters. and determine the local language equivalent of y (for yes/no queries). determines the language in which messages are displayed. If is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty vari- able. If is not specified or is set to the empty string, a default of (see lang(5)) is used instead of If any internationalization vari- able contains an invalid setting, behaves as if all internationalization variables are set to See environ(5). International Code Set Support Single character and multibyte character code sets are supported. EXAMPLES
Rename a file in the current directory: Rename a directory in the current directory: Rename a file in the current directory whose name starts with a nonprinting control character or a character that is special to the shell, such as and (extra care may be required depending on the situation): Move directory and its contents to a new location in the file system (upon completion, a subdirectory named resides in directory Move all files and directories (including links) in the current directory to a new location underneath Move all files and directories (including links) in to a new location underneath and are in separate directory paths): WARNINGS
If file1 and new-file exist on different file systems, copies the file and deletes the original. In this case the mover becomes the owner and any linking relationship with other files is lost. cannot carry hard links across file systems. If file1 is a directory, copies the entire directory structure onto the destination file system and deletes the original. cannot be used to perform the following operations: o Rename either the current working directory or its parent directory using the or notation. o Rename a directory to a new name identical to the name of a file contained in the same parent directory. DEPENDENCIES
NFS Access control lists of networked files are summarized (as returned in st_mode by stat(2)), but not copied to the new file. When using on such files, a is not printed after the mode value when asking for permission to overwrite a file. AUTHOR
was developed by AT&T, the University of California, Berkeley and HP. SEE ALSO
cp(1), cpio(1), ln(1), rm(1), link(1M), lstat(2), readlink(2), stat(2), symlink(2), symlink(4), acl(5), aclv(5). STANDARDS CONFORMANCE
mv(1)
All times are GMT -4. The time now is 01:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy