Sponsored Content
Top Forums Shell Programming and Scripting Find directories with same name and rename them Post 302552767 by DGPickett on Monday 5th of September 2011 02:05:41 PM
Old 09-05-2011
find will find directories, see man find, and mv renames/moves, see man mv, and then I get confused what you want in the end. Try adding an example.
 

10 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

bash script to rename multiple directories

Hello I have a directory structure with year in format 4 digits, e.g 2009, below which is month format 1 or 2 digits, e.g 1 or 12, blow which is day format 1 or 2 digits, e.g 1 or 31. I want to change the names of lots of directories to the be Year - 4 digits , e.g 2009 - No change here... (4 Replies)
Discussion started by: garethsays
4 Replies

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

5. Shell Programming and Scripting

Recursively rename directories

I have this directory tree under /apps/myapp/data: imageshack.us/photo/my-images/703/foldersc.png How to recursively rename ONLY directories with 5 digits (00000, 00100, 00200,..., 00007, 00107,...)? I want to add to their name two more zeros: Before: 00107 After: 0000107 Thanks in... (2 Replies)
Discussion started by: Susan_45
2 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. UNIX for Dummies Questions & Answers

Using grep command to find the pattern of text in all directories and sub-directories.

Hi all, Using grep command, i want to find the pattern of text in all directories and sub-directories. e.g: if i want to search for a pattern named "parmeter", i used the command grep -i "param" ../* is this correct? (1 Reply)
Discussion started by: vinothrajan55
1 Replies

8. UNIX for Dummies Questions & Answers

Script to rename directories

I am trying to create a script that will search for a directory named bob, and then rename that directory to peter. I do not want the directory path to change. so /folders/bob would become /folders/peter It seems to be renaming the bob folder to peter correctly, but the peter folder ends... (2 Replies)
Discussion started by: gumby456m
2 Replies

9. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: AshwaniSharma09
1 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
RENAME(2)						     Linux Programmer's Manual							 RENAME(2)

NAME
rename - change the name or location of a file SYNOPSIS
#include <stdio.h> int rename(const char *oldpath, const char *newpath); DESCRIPTION
rename renames a file, moving it between directories if required. Any other hard links to the file (as created using link(2)) are unaffected. If newpath already exists it will be atomically replaced (subject to a few conditions - see ERRORS below), so that there is no point at which another process attempting to access newpath will find it missing. If newpath exists but the operation fails for some reason rename guarantees to leave an instance of newpath in place. However, when overwriting there will probably be a window in which both oldpath and newpath refer to the file being renamed. If oldpath refers to a symbolic link the link is renamed; if newpath refers to a symbolic link the link will be overwritten. RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ERRORS
EISDIR newpath is an existing directory, but oldpath is not a directory. EXDEV oldpath and newpath are not on the same filesystem. ENOTEMPTY or EEXIST newpath is a non-empty directory, i.e., contains entries other than "." and "..". EBUSY The rename fails because oldpath or newpath is a directory that is in use by some process (perhaps as current working directory, or as root directory, or because it was open for reading) or is in use by the system (for example as mount point), while the system considers this an error. (Note that there is no requirement to return EBUSY in such cases - there is nothing wrong with doing the rename anyway - but it is allowed to return EBUSY if the system cannot otherwise handle such situations.) EINVAL The new pathname contained a path prefix of the old, or, more generally, an attempt was made to make a directory a subdirectory of itself. EMLINK oldpath already has the maximum number of links to it, or it was a directory and the directory containing newpath has the maximum number of links. ENOTDIR A component used as a directory in oldpath or newpath is not, in fact, a directory. Or, oldpath is a directory, and newpath exists but is not a directory. EFAULT oldpath or newpath points outside your accessible address space. EACCES Write access to the directory containing oldpath or newpath is not allowed for the process's effective uid, or one of the directo- ries in oldpath or newpath did not allow search (execute) permission, or oldpath was a directory and did not allow write permission (needed to update the .. entry). EPERM or EACCES The directory containing oldpath has the sticky bit set and the process's effective uid is neither that of root nor the uid of the file to be deleted nor that of the directory containing it, or newpath is an existing file and the directory containing it has the sticky bit set and the process's effective uid is neither that of root nor the uid of the file to be replaced nor that of the direc- tory containing it, or the filesystem containing pathname does not support renaming of the type requested. ENAMETOOLONG oldpath or newpath was too long. ENOENT A directory component in oldpath or newpath does not exist or is a dangling symbolic link. ENOMEM Insufficient kernel memory was available. EROFS The file is on a read-only filesystem. ELOOP Too many symbolic links were encountered in resolving oldpath or newpath. ENOSPC The device containing the file has no room for the new directory entry. CONFORMING TO
POSIX, 4.3BSD, ANSI C BUGS
On NFS filesystems, you can not assume that if the operation failed the file was not renamed. If the server does the rename operation and then crashes, the retransmitted RPC which will be processed when the server is up again causes a failure. The application is expected to deal with this. See link(2) for a similar problem. SEE ALSO
link(2), unlink(2), symlink(2), mv(1) Linux 2.0 1998-06-04 RENAME(2)
All times are GMT -4. The time now is 06:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy