Sponsored Content
Top Forums Shell Programming and Scripting Traverse file structure from top and rename the immediate parent Post 302525067 by Peasant on Wednesday 25th of May 2011 03:33:15 PM
Old 05-25-2011
Something like this ?
Code:
find $PWD -name '.git' -type d | while read line
do echo "mv $line $(dirname $line).git"
done

You can apply similar to next actions executing rm $line/* and touch $line/file on find results with different working directory and other options.
Hope it helped since i didn't understand requirment so well Smilie
This User Gave Thanks to Peasant For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Copying a Directory Structure to a new structure

Hi all Is it possible to copy a structure of a directory only. e.g. I have a file with the following entries that is a result of a find :- /dir1/dir2/file.dbf /dir1/dir2/dir3/file1.dbf /dir1/file.dbf I want to copy these to a directory and keep the structure however starting at a new dir... (8 Replies)
Discussion started by: jhansrod
8 Replies

2. UNIX for Dummies Questions & Answers

Using File Descriptors, traverse a list

I have written this code, and according to my research it SHOULD be going down the list until it is finished, but I am getting blank feedback. Nothing is being output as far as I can tell. #!/bin/sh while echo Enter to start traversing read enter do read list <&3 echo $list done any... (2 Replies)
Discussion started by: MaestroRage
2 Replies

3. Programming

Search attributes in one structure using the values from another structure

Hello Groups I am trying to find out ways of comparing a value from a 'c' structure to a value in another 'C' structure. the 'C' structure can be a List or liked list as it contains lot many records. if we loop it in both the structures it is going to consume time. I am looking for a simple... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

4. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies

5. Shell Programming and Scripting

Rename a file after the name of its parent dir

Started a thread in beginners but I thought someone from this forum may have an idea as well. Thanks! EDITED BY REBORG (3 Replies)
Discussion started by: robotsbite
3 Replies

6. Shell Programming and Scripting

How to traverse directory structure and sum size of files?

How do I write a bash or ruby or perl or groovy script to print all the files in my directory tree that are one-to-two years old, the size of each file, and the sum of file sizes and then delete them? I was using find . -atime +365 -exec rm '{}' \; but the problem was that I could not... (5 Replies)
Discussion started by: siegfried
5 Replies

7. AIX

Parent directory seems to disappear if child fails rename

If I have a file/folder that a user does not have permission to and I try to rename it, it removes the entire parent folder. At that point it is only visible in a ls. (Not a ls -l, file, more, cd). It happens on every filesystem. This is Aix 5.3 $ cd test $ ls -la total 0 drwxr-xr-x 2 root ... (4 Replies)
Discussion started by: scriptr2be
4 Replies

8. Shell Programming and Scripting

Rename last directory in a file structure

I have to write a script to rename the every last sub-directory in a directory structure if the last sub-directory name doesn't contain "submitted". eg: given directory path:/u01/home/somedir somedir can have many subdirectories and each subdirectory inturn has many subdirectories. somedir... (3 Replies)
Discussion started by: ramse8pc
3 Replies

9. Shell Programming and Scripting

How to get top level parent directory

Hi All, I have a directory like this: /u01/app/oracle/11gSE1/11gR203 How do i get the top level directory /u01 from this? Tried dirname and basename but dint help. I can this using echo $ORACLE_HOME | awk -F"/" '{print "/"$2}'. But I am trying to find out if there is a better way of doing it... (4 Replies)
Discussion started by: nilayasundar
4 Replies

10. 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
RENAME(2)							System Calls Manual							 RENAME(2)

NAME
rename - change the name of a file SYNOPSIS
#include <stdio.h> int rename(const char *from, const char *to) DESCRIPTION
Rename causes the link named from to be renamed as to. If to exists, then it is first removed. Both from and to must be of the same type (that is, both directories or both non-directories), and must reside on the same file system. Rename guarantees that an instance of to will always exist, even if the system should crash in the middle of the operation. If the final component of from is a symbolic link, the symbolic link is renamed, not the file or directory to which it points. RETURN VALUE
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
Rename will fail and neither of the argument files will be affected if any of the following are true: [ENAMETOOLONG] A path name exceeds PATH_MAX characters. [ENOENT] A component of the from path does not exist, or a path prefix of to does not exist. [EACCES] A component of either path prefix denies search permission. [EACCES] The requested link requires writing in a directory with a mode that denies write permission. [EPERM] The directory containing from is marked sticky, and neither the containing directory nor from are owned by the effective user ID. [EPERM] The to file exists, the directory containing to is marked sticky, and neither the containing directory nor to are owned by the effective user ID. [ELOOP] Too many symbolic links were encountered in translating either pathname. (Minix-vmd) [ENOTDIR] A component of either path prefix is not a directory. [ENOTDIR] From is a directory, but to is not a directory. [EISDIR] To is a directory, but from is not a directory. [EXDEV] The link named by to and the file named by from are on different logical devices (file systems). [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. [EIO] An I/O error occurred while making or updating a directory entry. [EROFS] The requested link requires writing in a directory on a read-only file system. [EFAULT] Path points outside the process's allocated address space. [EINVAL] From is a parent directory of to, or an attempt is made to rename ``.'' or ``..''. [ENOTEMPTY] To is a directory and is not empty. SEE ALSO
open(2) 4.2 Berkeley Distribution May 22, 1986 RENAME(2)
All times are GMT -4. The time now is 09:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy