Traverse the file system and Rename (xargs or sed?)
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.