LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Traverse the file system and Rename (xargs or sed?) (https://www.linuxquestions.org/questions/linux-general-1/traverse-the-file-system-and-rename-xargs-or-sed-880784/)

MTK358 05-15-2011 12:57 PM

Quote:

Originally Posted by EricTRA (Post 4357073)
meaning that if you run the command a second time a second .dir gets added which is not what he wants. I'm trying to figure out how to overcome that but haven't found a solution yet. Any ideas?


I already solved that: http://www.linuxquestions.org/questi...4/#post4357066

EricTRA 05-15-2011 01:03 PM

Hi,

Yes, I've noticed that but that wouldn't work if it were the first run. Say OP is running his tests in a testing environment to build a solution for his problem. After the first run .dir gets added, on the second run and the ones thereafter, if he does change the command between runs, he will not get .dir.dir and so on. But what if he wants to run this as a one command solution on another machine? Most likely OP just runs your commands to clean up his system so this doesn't apply but just thought it worth mentioning for completeness.

Kind regards,

Eric

MTK358 05-15-2011 01:06 PM

Quote:

Originally Posted by EricTRA (Post 4357079)
But what if he wants to run this as a one command solution on another machine?

What difference will that make? It simply adds ".dir" if it's not there already.

EricTRA 05-15-2011 01:11 PM

Hi,

Sorry, didn't notice you've added the -not option. My brain is on Sunday mode. Should work correctly.

Kind regards,

Eric

sahil.jammu 05-25-2011 10:15 AM

Hello Guys,

Came across another scenario, i'm struck at a point, Need your inputs to proceed further:-

------
1. Traverse entire file system, look for directories which has .git directory in it
2. Rename the immediate parent directory to <orignal_name.git>
3. Traverse this new file structure and look for all directories with <original_name>.git
4. cd to that directory and remove its contents
5. once everything inside the directory is deleted, create a file
------

Code:-
Step 1:- find * -type d -iname '.git'
Step 2:-
function rename_git_parent
{
for file in "$1"/*
do
cd .. | $(pwd) -exec mv '{}' '{}'.git ';'
done
return 1
}


//i am not too sure if its the right way of doing it, or shall i use dirname...


How shall i go about step2 and ownwards...
Appreciate the help.

Thanks.


Regards
Sahil


All times are GMT -5. The time now is 10:27 PM.