Rename multiple file names in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename multiple file names in a directory
# 1  
Old 05-22-2011
Java Rename multiple file names in a directory

I hope some one can help me

I have multiple files in a directory with out extension like as below mentioned. But i want to change all the file names along .DDMMYYYYHHMISS format. And all files should have same DDMMYYYYHHMISS.

Scenario:

direcory name = /vol/best/srcfiles

files in a direcory

Payor
customer
vendor
Employee


I want the files names as below

Payor.05222011035216
customer.05222011035216
vendor.05222011035216
Employee.05222011035216


Thanks,
# 2  
Old 05-22-2011
you can try this..

for file in *
do
mv $file $file.`date +%d%m%y%H%M%S`
done
# 3  
Old 05-22-2011
Folks, use code tags.
I would also recommend using instead of
Code:
`code` with $(code)

for easier reading for code.
# 4  
Old 05-22-2011
atul9806,

i have tried as mentioned below, which is not working. Can you please guide me with sed command
# 5  
Old 05-22-2011
To match your requirement, the 'date' command should be:
Code:
date +'%d%m%Y%H%M%S'

The %Y gives a 4-digit year.

Statements like "which is not working" tell us nothing. What went wrong?

Maybe your script should be something like:

Code:
#!/bin/sh
DDMMYYYYHHMMSS=`date +'%d%m%Y%H%M%S'` # Evaluate the date once only
cd /vol/best/srcfiles
for filename in "Payor" "customer" "vendor" Employee"
do
       if [ -f "${filename} ]
       then
              mv "${filename}" "${filename}.${DDMMYYYYHHMMSS}"
       fi
done


Btw. The date format YYYYMMDD etc. is much better than DDMMYYYY etc. in filenames because the files will come out in chronogical order in a default "ls" directory list.

Last edited by methyl; 05-22-2011 at 05:50 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rename the file name from Parent directory

Hi All, Just started learning unix and stuck into below issue. Suppose i have folder structure as below. Dir1/Dir2/Dir3/File1.msg I am looking to rename the file name from File1.msg to File2.msg but from the parent Dir1 From Dir3 i can easily run the command like mv File1.msg... (2 Replies)
Discussion started by: Gurjeet Singh
2 Replies

2. 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

3. Shell Programming and Scripting

How to rename multiple file names?

Hi all, I need to rename more file name in one command or script. The files have this structure: XxY - filename.doc where X and Y are numbers and the x is the letter itself. I need to rename these files with this structure: string.S0XEY.filename.doc the string is a suffix that... (8 Replies)
Discussion started by: idro
8 Replies

4. Shell Programming and Scripting

Fetch the last two days directory names and rename them

Hi All, I have below directory structure and from these directories, I would like to fetch the last two days list of directories and append a '0' (zero) to those directories. bash-4.1$ ls -lrt total 32 drwxr-xr-x+ 6 root root 9 Sep 5 01:05 tested-597 drwxr-xr-x+ 6 root root 9 Sep 9... (3 Replies)
Discussion started by: ibad_urs
3 Replies

5. Shell Programming and Scripting

Trying to do multiple dir's and multiple file names etc.

What am I missing? find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing... (3 Replies)
Discussion started by: xgringo
3 Replies

6. Shell Programming and Scripting

changing multiple directory names

Hi guys, I have lots of files that look like: ABC.packed.dir DEF.packed.dir GHI.packed.dir etc... I would like them to have more of the usual naming convention ABC DEF GHI etc... so I was thinking that I could: (2 Replies)
Discussion started by: atjurhs
2 Replies

7. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

8. Shell Programming and Scripting

Find and rename long file names (html)

Hi Guys, I need a help. I have 1130 zip files. Each one of them has files including 1 html file with long file name (includes special charactors, Alphabetic and numbers). I have copied all 1130 zip files to my linux system and extracted using below command. Find . -name "*.zip" -exec... (7 Replies)
Discussion started by: Rajmani
7 Replies

9. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

10. OS X (Apple)

changing multiple directory names w/ sed

ive looked and couldnt find an answer... can someone tell me how i can replace spaces and characters with an "_" on multiple folders? thanx muchly. (1 Reply)
Discussion started by: RahJiggah
1 Replies
Login or Register to Ask a Question