ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Is this old? I'm running a 64bit version of RHEL 4 Update 6.
I think '-execdir' was implemented in 4.2.x or so. So your find won't do. If you can not upgrade it, here is a small script that worked with subdirectories:
Code:
#!/bin/bash
count=$(find dir -depth -type d \! -iregex '.*/\..*' -name "*:2F*" | wc -l )
#echo $count
for n in $(seq 1 $count); do
find /path/to/searchdir -type d \! -iregex '.*/\..*' -name "*:2F*" -exec rename 's/:2F/-/g' '{}' \; -quit
done
Notice that this one does not have the -depth option and the -quit comes after -exec.
[EDIT]
There might be a smarter way to implement the loop condition, e.g. a while that breaks when 'find' does not find any folders to change. However, this was not my focus here.
I think '-execdir' was implemented in 4.2.x or so. So your find won't do. If you can not upgrade it, here is a small script that worked with subdirectories:
Code:
#!/bin/bash
count=$(find dir -depth -type d \! -iregex '.*/\..*' -name "*:2F*" | wc -l )
#echo $count
for n in $(seq 1 $count); do
find /path/to/searchdir -type d \! -iregex '.*/\..*' -name "*:2F*" -exec rename 's/:2F/-/g' '{}' \; -quit
done
Notice that this one does not have the -depth option and the -quit comes after -exec.
[EDIT]
There might be a smarter way to implement the loop condition, e.g. a while that breaks when 'find' does not find any folders to change. However, this was not my focus here.
I'm beginning to feel rather bad about all this ...
If I run as you posted (but I assume that the dir for the count variable, was meant to be the search path ...
Code:
#!/bin/bash
count=$(find /MFData/Restore/IKEATEST01/ -depth -type d \! -iregex '.*/\..*' -name "*:2F*" | wc -l )
for n in $(seq 1 $count); do
find /MFData/Restore/IKEATEST01/ -type d \! -iregex '.*/\..*' -name "*:2F*" -exec rename 's/:2F/-/g' '{}' \; -quit
done
I'm beginning to feel rather bad about all this ...
If I run as you posted (but I assume that the dir for the count variable, was meant to be the search path ...
Yes, sorry for the typo.
Quote:
And if I took -quit out of the script, it would run, but it hadn't renamed the directories.
Apparently your find does not support this option, too. Well, I have one more - nasty and ugly - solution which worked.
Code:
#!/bin/bash
count=$(find /MFData/Restore/IKEATEST01/ -type d \! -iregex '.*/\..*' -name "*:2F*" | wc -l )
#echo $count
for n in $(seq 1 $count); do
find /MFData/Restore/IKEATEST01/ -type d \! -iregex '.*/\..*' -name "*:2F*" -exec rename 's/:2F/-/g' '{}' \;
done
It will spit out a lot of 'No such file or directory' errors but it will hopefully do the job anyway - i.e. if your 'find' supports at least the '-exec' option. Otherwise we might have to make the solution even 'uglier'.
[EDIT]
Oops, I just saw that you already tried it without '-quit'. Thinking about it...
Apparently your find does not support this option, too. Well, I have one more - nasty and ugly - solution which worked.
Code:
#!/bin/bash
count=$(find /MFData/Restore/IKEATEST01/ -type d \! -iregex '.*/\..*' -name "*:2F*" | wc -l )
#echo $count
for n in $(seq 1 $count); do
find /MFData/Restore/IKEATEST01/ -type d \! -iregex '.*/\..*' -name "*:2F*" -exec rename 's/:2F/-/g' '{}' \;
done
It will spit out a lot of 'No such file or directory' errors but it will hopefully do the job anyway - i.e. if your 'find' supports at least the '-exec' option. Otherwise we might have to make the solution even 'uglier'.
[EDIT]
Oops, I just saw that you already tried it without '-quit'. Thinking about it...
Mate, I'm unbelievably grateful for your help here ... but sadly still not working.
Just to make sure I didn't do something silly, here's my full script:
Code:
#!/bin/bash
count=$(find /MFData/Restore/IKEATEST01/ -depth -type d \! -iregex '.*/\..*' -name "*:2F*" | wc -l )
#echo $count
for n in $(seq 1 $count); do
find /MFData/Restore/IKEATEST01/ -type d \! -iregex '.*/\..*' -name "*:2F*" -exec rename 's/:2F/-/g' '{}' \;
done
And FYI, just in case useful, version of rename running is ...
Quote:
rename from util-linux-2.12a
Oh, there were no error messages this time, just ran (very) quickly, but no change to directory names.
Ok, here is one that needs two scripts
First script:
Code:
#!/bin/bash
# script.sh
count=$(find /MFData/Restore/IKEATEST01/ -depth -type d \! -iregex '.*/\..*' -name "*:2F*" | wc -l )
#echo $count
for n in $(seq 1 $count); do
find /MFData/Restore/IKEATEST01/ -type d \! -iregex '.*/\..*' -name "*:2F*" -exec ./sscript.sh '{}' \;
done
Second script (called sscript.sh):
Code:
#!/bin/bash
newname=$(echo "$1" | sed -e 's/:2F/-/g')
mv "$1" "$newname"
However, I am beginning to suspect that the ':2F' might not be really there. It could be just the representation of an unprintable character. As you said, this are mac names that probably contain '/' in their names. To verify this please do
Ok, here is one that needs two scripts
First script:
Code:
#!/bin/bash
# script.sh
count=$(find /MFData/Restore/IKEATEST01/ -depth -type d \! -iregex '.*/\..*' -name "*:2F*" | wc -l )
#echo $count
for n in $(seq 1 $count); do
find /MFData/Restore/IKEATEST01/ -type d \! -iregex '.*/\..*' -name "*:2F*" -exec ./sscript.sh '{}' \;
done
Second script (called sscript.sh):
Code:
#!/bin/bash
newname=$(echo "$1" | sed -e 's/:2F/-/g')
mv "$1" "$newname"
However, I am beginning to suspect that the ':2F' might not be really there. It could be just the representation of an unprintable character. As you said, this are mac names that probably contain '/' in their names. To verify this please do
Now run the suggested solution for /path/to/dummydir and let us know if it works. You can skip the solutions that need -exec and -quit.
[EDIT]
I just found out that my distro has a perl implementation of 'rename' which might work differently then your 'rename'.
Mate, your blood's worth bottling! Success at long last.
I did get following output when script(/s) ran:
Quote:
find: /MFData/Restore/IKEATEST01/IKEAP0642 Perth_2/WIP/offlines 5:2F12:2F07: No such file or directory
find: /MFData/Restore/IKEATEST01/IKEAP0730 Xmas_thought_of_you/WIP/Edits/Offlines_1:2F11:2F07: No such file or directory
find: /MFData/Restore/IKEATEST01/IKEAP0730 Xmas_thought_of_you/WIP/Edits/Offlines_30:2F10:2F07: No such file or directory
find: /MFData/Restore/IKEATEST01/IKEASA0028 Light:2FBalls:2FKey Launch: No such file or directory
find: /MFData/Restore/IKEATEST01/IKEASA0141 Key:2FBalls end frame change: No such file or directory
But, curiously, the directories were renamed.
I'll try your mkdir request shortly (I did want to let you know of your success first though), but out of interest I started cp of one directory to see how it would resolve the directory name, and it did so thus ...
Quote:
IKEASA0028\ Light\:2FBalls\:2FKey\ Launch/
I'm not exactly sure, but it is escaping the : is it not (ie., that the : actually exists)???
Is there a reason why we can't just use the simple version we presented earlier?
Code:
while read dir
do
mv "$dir" "${dir%:2F*}"
done< <(find /Data/ -type d -name '*:2F*')
I created the structure you presented and this worked for me. I did also alter the find as wasn't sure the necessity of the regex portion??
The OP said that none of the solutions have worked so far. Also, when I tried this there were problems if more than one subdirectory had the pattern in its name. The parent directory would be renamed and then the subdirectory could no longer be found.
Sorry, but this thread looks too much like a soap opera. I.e. replacing three characters and renaming a directory is trivial in any programming language.
Sorry, but this thread looks too much like a soap opera. I.e. replacing three characters and renaming a directory is trivial in any programming language.
No offense mate, but its not trivial to me, or to the organisation I work for.
I stated clearly at start that I'm a gumby at this - I'm learning bash as quickly, and as in-depth, as I can.
Sorry, but this thread looks too much like a soap opera. I.e. replacing three characters and renaming a directory is trivial in any programming language.
So you're a soap opera fan, otherwise you wouldn't have read it to the end.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.