Sponsored Content
Top Forums Shell Programming and Scripting Rename the files in all the directories and sub-directories Post 302807953 by AshwaniSharma09 on Wednesday 15th of May 2013 04:40:08 PM
Old 05-15-2013
Rename the files in all the directories and sub-directories

Hi all,

I have more than 12000 files in 46 different directories and each directory has 2 sub-directories named “dat” or “gridded”. Dat sub-directories have files with extension “jpg.dat” and gridded sub-directories have files with extension “.jpg”.

I need to rename all the files (some parts to be replaced or removed and most of the parts to be rearranged) in all the directories and sundirectories.

Code:
Example name of the files:  
 Old names:

 (an example file from gridded subdirectories)
 gridded_yihF-b3861-DNA433-c1-384-20110301-Tp32-CmKan-Sel2-384-MMS-32C-set1-plate1.jpg 

 (an example file from dat subdirectories)
 yihF-b3861-DNA433-c1-384-20110301-Tp32-CmKan-Sel2-384-MMS-32C-set1-plate1.jpg.dat 

 New names:

 tom_dm-MMS_yihF-b3861_1_[1-4]_DNA433-20110301.jpg

 tom_dm-MMS_yihF-b3861_1_[1-4]_DNA433-20110301.jpg.dat

In the new name, words come in this order with these changes:

(1) “gridded” needs to be replaced with “tom” (in all the files from all the gridded subdirectories).
(2) “MMS” needs to come just after “tom” and it can also be “RM” instead of “MMS”
(3) “yihF-b3861” word will be different in every file
(4) “plate1” will be replaced with “1”. It can be “plate2” which needs to be replaced by “2”
(5) “set1” needs to be replaced with “[1-4]”. It can be set2, set3 or set4 and needs to be changed [2-4], [3-4] or [4-4] respectively.
(6) “ DNA433-c1-384-20110301” part will different in each file. It needs to be renamed to “ DNA433-20110301” but the “c1-384” which needs to be removed, is same in every file.
(7) File extensions “.jpg” or “.jpg.dat” remains the same.

Remaining part of the old name (i. e. -Tp32-CmKan-Sel2-384-) will be left out or deleted.

Thanks in advance. I appreciate your time.

Last edited by Scott; 05-15-2013 at 05:41 PM.. Reason: Code tags, not Icode tags
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename files/directories based on their name

i have hundreds of directories that have to be renamed. the directory structure is fairly uniform which makes the scripting a little simpler. suppose i have many directories like this */*/*/*abc* (in other words i have similar directory names 3 dirs deep that all contain the pattern abc in... (8 Replies)
Discussion started by: quantumechanix
8 Replies

2. Shell Programming and Scripting

Rename files recursivly in specified directories

Hi, This is what I would like to do. 1. Find all directories named "ByHost" in a specified directory 2. Rename all .plist files inside "ByHost" directories This is the way I have been able to do it so far. #!/bin/sh # # Rename ByHost files # # Thomas Berglund, 13.07.08 # Get the... (2 Replies)
Discussion started by: Thomas Berglund
2 Replies

3. Shell Programming and Scripting

Rename files and directories with special characters

Hello guys, I was looking for a shell script that removes all the special characters from the files and the subdirectories recursively. I could not locate it any more. Dose any body have a similar script that dose that? Thanks for the help. AV (0 Replies)
Discussion started by: avatar_007
0 Replies

4. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

5. Shell Programming and Scripting

How to store files/directories in different directories!!

Hi legends, I am writing a script, in that my requirement is, if all the fill types stored in one directory from that we need to separate different different directories based on the file types. for example in a directory(anish). 5 different types files 1- directory 2- .txt files 2- .sh... (1 Reply)
Discussion started by: anishkumarv
1 Replies

6. Shell Programming and Scripting

Rename files in sub directories with sequential numbers

I can rename a file with sequential numbers from 1 to N with this script: num=1 for file in *.dat;do mv "$file" "$(printf "%u" $num).txt" let num=num+1 done The script begins with renaming a some.dat file to 1.dat.txt and goes on sequentially renaming other DAT files to... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

7. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

8. Shell Programming and Scripting

Archiving and moving files into directories, creating directories, etc.

how can i move "dataName".sql.gz into a folder called 'database' and then move "$fileName".tar.gz * .htaccess into a folder called 'www' with the entire gzipped file being "$fileName".tar.gz? Is this doable or overly complex. so mydemo--2015-03-23-1500.tar.gz > database -... (5 Replies)
Discussion started by: wyclef
5 Replies

9. 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
SYSTEMD-TMPFILES(8)						 systemd-tmpfiles					       SYSTEMD-TMPFILES(8)

NAME
systemd-tmpfiles - Creates, deletes and cleans up volatile and temporary files and directories. SYNOPSIS
systemd-tmpfiles [OPTIONS...] [CONFIGURATION FILE...] DESCRIPTION
systemd-tmpfiles creates, deletes and cleans up volatile and temporary files and directories, based on the configuration from /etc/tmpfiles.d/. See tmpfiles.d(5) for more details on these files. If invoked with no arguments applies all directives from all configuration files in /etc/tmpfiles.d/*.conf. If one or more absolute file names are passed on the command line only the directives in these files are applied. OPTIONS
The following options are understood: --create If this option is passed all files and directories marked with f, F, d, D in the configuration files are created. Files and directories marked with z, Z have their ownership, access mode and security labels set. --clean If this option is passed all files and directories with an age parameter configured will be cleaned up. --remove If this option is passed all files and directories marked with r, R in the configuration files are removed. --prefix=PATH Only apply rules that apply to paths with the specified prefix. --help Prints a short help text and exits. It is possible to combine --create, --clean, and --remove in one invocation. For example, during boot the following command line is executed to ensure that all temporary and volatile directories are removed and created according to the configuration file: systemd-tmpfiles --remove --create EXIT STATUS
On success 0 is returned, a non-zero failure code otherwise. SEE ALSO
systemd(1), tmpfiles.d(5), tmpwatch(8) AUTHOR
Lennart Poettering <lennart@poettering.net> Developer systemd 10/07/2013 SYSTEMD-TMPFILES(8)
All times are GMT -4. The time now is 04:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy