Sponsored Content
Top Forums Shell Programming and Scripting Copying subdirectories of a directory to some other directory and renaming them Post 302433460 by EAGL€ on Tuesday 29th of June 2010 06:19:44 PM
Old 06-29-2010
Quote:
Originally Posted by sholay
Hi,
I am a newbie in shell scripting. I have to copy a particular sub-directory (data) from a large no. of directories (all in the same folder) and paste them to another directory ( /home/hubble/data ) and then rename all the subdirectories (data) as the name of its parent directory.

please help. Its urgent. Thank you in advance.
can you provide us more info about the sub-directories and give a sample of them? And Besides how u want to rename them?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

makefiles in a directory and subdirectories

I need to develop a makefile that spans across directories. For example, let's say i have an upper level directory (main) and about 2 subdirectories. I want my .cpp files and .o files to be in one subdirectory. I want my .a files to be in the other subdirectory. The .a files are made up of the... (0 Replies)
Discussion started by: benjie_asu
0 Replies

2. Shell Programming and Scripting

How Can I Make Subdirectories In A Directory?

I cant remember how, i use to know but its been like 2 years since ive used shell can anyone help me? (7 Replies)
Discussion started by: kprescod4158
7 Replies

3. UNIX for Dummies Questions & Answers

Copying one file at a time from one directory to another directory.

Hi All i want to write a script which could copy one file at a time from one directory to another directory. Scenerio: Let's say i have 100 file in a dirctory,so i want to copy one file at a time to another directory with a sleep statement in between that of 30 secs. please help me... (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

4. Shell Programming and Scripting

search files in a directory and its subdirectories

Hello my friends, I need to write a simple shell bad file :D that search and delete a file it's name 'Microsoft.txt' in the current directory and its subdirectories? So can you help to guide me how i can write this shell, Just give me the beginning :o thank you. (1 Reply)
Discussion started by: Net-Man
1 Replies

5. UNIX for Dummies Questions & Answers

How to remove directory with subdirectories and files?

I'm trying to remove several directories which contains sun-dirs and files inside. I used the command rm -r <dirname> But, it always ask "examine file in directory <dirname> yes/no?" line by line. So, i need to write "y" for every line. How can i skip this step and remove all directories with... (9 Replies)
Discussion started by: ppa108
9 Replies

6. Shell Programming and Scripting

Find directory name while traversing subdirectories

Hi, I have a parent directory in which I have sub directories of different depth /usr/usr1/user2/671 /usr/usr1/672 /usr/user2/user1/673 /usr/user2/user3/user4/674 And I need the names of all the directories that which starts only with 6 in a file. Thanks, (12 Replies)
Discussion started by: arun_maffy
12 Replies

7. UNIX for Dummies Questions & Answers

recursive copy into a directory and all its subdirectories...

I want to copy a file from the top directory into all the sub-folders and all of the sub-folders of those sub-folder etc. Does anyone have any idea how to do this? Thanks in advance of any help you can give. (3 Replies)
Discussion started by: EinsteinMcfly
3 Replies

8. UNIX for Dummies Questions & Answers

Renaming files with part of their pathname and copying them to new directory

Hi I think this should be relatively simple but I can't figure it out. I have several files with the same name in different folders within a directory (the output of a program that I ran). Something like this: ./myAnalysis/item1/round1/myoutput.txt ./myAnalysis/item1/round2/myoutput.txt... (2 Replies)
Discussion started by: jullee
2 Replies

9. Shell Programming and Scripting

Copying files from one directory to another, renaming duplicates.

Below is the script i have but i would like simplified but still do the same job. I need a script to copy files not directories or sub-directories into a existing or new directory. The files, if have the same name but different extension; for example 01.doc 01.pdf then only copy the .doc file. ... (1 Reply)
Discussion started by: Gilljambo
1 Replies

10. Shell Programming and Scripting

Copying files to a directory, renaming it if a file with the same name already exists

Hi All, I need to copy files from one directory to another with the files to be renamed while copying if a file with the same name already exists in the target directory. THanks, Dev (2 Replies)
Discussion started by: dev.devil.1983
2 Replies
RENAME(2)						      BSD System Calls Manual							 RENAME(2)

NAME
rename -- change the name of a file SYNOPSIS
#include <stdio.h> int rename(const char *old, const char *new); DESCRIPTION
The rename() system call causes the link named old to be renamed as new. If new exists, it is first removed. Both old and new must be of the same type (that is, both must be either directories or non-directories) and must reside on the same file system. The rename() system call guarantees that an instance of new will always exist, even if the system should crash in the middle of the opera- tion. If the final component of old is a symbolic link, the symbolic link is renamed, not the file or directory to which it points. CAVEATS
The system can deadlock if a loop is present in the file system graph. This loop takes the form of an entry in directory 'a', say 'a/foo', being a hard link to directory 'b', and an entry in directory 'b', say 'b/bar', being a hard link to directory 'a'. When such a loop exists and two separate processes attempt to perform 'rename a/foo b/bar' and 'rename b/bar a/foo', respectively, the system may deadlock attempting to lock both directories for modification. Whether or not hard links to directories are supported is specific to the underlying filesystem implementation. It is recommended that any hard links to directories in an underlying filesystem should be replaced by symbolic links by the system adminis- trator to avoid the possibility of deadlocks. Moving or renaming a file or directory into a directory with inheritable ACLs does not result in ACLs being set on the file or directory. Use acl(3) in conjunction with rename() to set ACLs on the file or directory. RETURN VALUES
A 0 value is returned if the operation succeeds, otherwise rename() returns -1 and the global variable errno indicates the reason for the failure. ERRORS
The rename() system call will fail and neither of the argument files will be affected if: [EACCES] A component of either path prefix denies search permission. [EACCES] The requested operation requires writing in a directory (e.g., new, new/.., or old/..) whose modes disallow this. [EDQUOT] The directory in which the entry for the new name is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted. [EFAULT] Path points outside the process's allocated address space. [EINVAL] Old is a parent directory of new, or an attempt is made to rename '.' or '..'. [EIO] An I/O error occurs while making or updating a directory entry. [EISDIR] new is a directory, but old is not a directory. [ELOOP] Too many symbolic links are encountered in translating either pathname. This is taken to be indicative of a looping sym- bolic link. [ENAMETOOLONG] A component of a pathname exceeds {NAME_MAX} characters, or an entire path name exceeds {PATH_MAX} characters. [ENOENT] A component of the old path does not exist, or a path prefix of new does not exist. [ENOSPC] The directory in which the entry for the new name is being placed cannot be extended because there is no space left on the file system containing the directory. [ENOTDIR] A component of either path prefix is not a directory. [ENOTDIR] old is a directory, but new is not a directory. [ENOTEMPTY] New is a directory and is not empty. [EPERM] The directory containing old is marked sticky, and neither the containing directory nor old are owned by the effective user ID. [EPERM] The new file exists, the directory containing new is marked sticky, and neither the containing directory nor new are owned by the effective user ID. [EROFS] The requested link requires writing in a directory on a read-only file system. [EXDEV] The link named by new and the file named by old are on different logical devices (file systems). Note that this error code will not be returned if the implementation permits cross-device links. CONFORMANCE
The restriction on renaming a directory whose permissions disallow writing is based on the fact that UFS directories contain a ".." entry. If renaming a directory would move it to another parent directory, this entry needs to be changed. This restriction has been generalized to disallow renaming of any write-disabled directory, even when this would not require a change to the ".." entry. For consistency, HFS+ directories emulate this behavior. SEE ALSO
open(2), symlink(7) STANDARDS
The rename() function conforms to IEEE Std 1003.1-1988 (``POSIX.1''). 4.2 Berkeley Distribution September 18, 2008 4.2 Berkeley Distribution
All times are GMT -4. The time now is 11:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy