* Changing file names with "--" to "-"
@ 2021-02-21 3:06 wael-zwaiter
2021-02-21 3:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: wael-zwaiter @ 2021-02-21 3:06 UTC (permalink / raw)
To: Help Gnu Emacs
I have a lot of files and want to change "--" to "-".
Am using
rename 's/--/-/g' *
on the current directory.
How can I recursively go through all sub directories and do the
changes for files only.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Changing file names with "--" to "-"
2021-02-21 3:06 Changing file names with "--" to "-" wael-zwaiter
@ 2021-02-21 3:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-21 6:45 ` Changing file names with "--" to "-" recursively Jean Louis
2021-02-22 4:42 ` Changing file names with "--" to "-" Robert Thorpe
2 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-21 3:33 UTC (permalink / raw)
To: help-gnu-emacs
wael-zwaiter wrote:
> I have a lot of files and want to change "--" to "-".
>
> Am using
>
> rename 's/--/-/g' *
>
> on the current directory.
>
> How can I recursively go through all sub directories and do
> the changes for files only.
In zsh you can use **/* to get recursion, then exclude
directories from the match with the glob qualifier (.), i.e.
**/*(.)
So try
$ rename 's/--/-/g' **/*(.)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Changing file names with "--" to "-" recursively
2021-02-21 3:06 Changing file names with "--" to "-" wael-zwaiter
2021-02-21 3:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-21 6:45 ` Jean Louis
2021-02-21 7:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
` (2 more replies)
2021-02-22 4:42 ` Changing file names with "--" to "-" Robert Thorpe
2 siblings, 3 replies; 8+ messages in thread
From: Jean Louis @ 2021-02-21 6:45 UTC (permalink / raw)
To: wael-zwaiter; +Cc: Help Gnu Emacs
* wael-zwaiter@gmx.com <wael-zwaiter@gmx.com> [2021-02-21 06:07]:
>
> I have a lot of files and want to change "--" to "-".
>
> Am using
>
> rename 's/--/-/g' *
>
> on the current directory.
>
> How can I recursively go through all sub directories and do the
> changes for files only.
The command:
$ rename 's/--/-/g' *
does not work on my side as it works on yours, maybe it is different
software.
You do as following in the top directory:
for i in $(find . -type f -iname "*--*"); do mv $i $(echo $i | sed -e "s/--/-/"); done
You may alias the command to:
alias renamedashes='for i in $(find . -type f -name "*--*"); do mv $i $(echo $i | sed -e "s/--/-/"); done'
and invoke it with
$ renamedashes
in future.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Changing file names with "--" to "-" recursively
2021-02-21 6:45 ` Changing file names with "--" to "-" recursively Jean Louis
@ 2021-02-21 7:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-21 12:42 ` Jean Louis
2021-02-21 13:41 ` ken
2021-02-22 6:36 ` David Masterson
2 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-21 7:46 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis wrote:
> The command:
>
> $ rename 's/--/-/g' *
>
> does not work on my side as it works on yours, maybe it is
> different software.
Works here!
$ rename --version
/bin/rename using File::Rename version 1.13,
File::Rename::Options version 1.10
By Larry Wall, I read in rename(1p), from the "User
Contributed Perl Documentation". You gotta love it :)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Changing file names with "--" to "-" recursively
2021-02-21 7:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-21 12:42 ` Jean Louis
0 siblings, 0 replies; 8+ messages in thread
From: Jean Louis @ 2021-02-21 12:42 UTC (permalink / raw)
To: help-gnu-emacs
* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-02-21 10:47]:
> Jean Louis wrote:
>
> > The command:
> >
> > $ rename 's/--/-/g' *
> >
> > does not work on my side as it works on yours, maybe it is
> > different software.
>
> Works here!
>
> $ rename --version
>
> /bin/rename using File::Rename version 1.13,
> File::Rename::Options version 1.10
>
> By Larry Wall, I read in rename(1p), from the "User
> Contributed Perl Documentation". You gotta love it :)
Sure, I remember that one.
My command is from from util-linux 2.29.2
But it does not matter, the iteration that was proposed replaces both
of them.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Changing file names with "--" to "-" recursively
2021-02-21 6:45 ` Changing file names with "--" to "-" recursively Jean Louis
2021-02-21 7:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-21 13:41 ` ken
2021-02-22 6:36 ` David Masterson
2 siblings, 0 replies; 8+ messages in thread
From: ken @ 2021-02-21 13:41 UTC (permalink / raw)
To: help-gnu-emacs
On 02/21/2021 01:45 AM, Jean Louis wrote:
> * wael-zwaiter@gmx.com <wael-zwaiter@gmx.com> [2021-02-21 06:07]:
>> I have a lot of files and want to change "--" to "-".
>>
>> Am using
>>
>> rename 's/--/-/g' *
>>
>> on the current directory.
>>
>> How can I recursively go through all sub directories and do the
>> changes for files only.
> The command:
>
> $ rename 's/--/-/g' *
>
> does not work on my side as it works on yours, maybe it is different
> software.
>
> You do as following in the top directory:
>
> for i in $(find . -type f -iname "*--*"); do mv $i $(echo $i | sed -e "s/--/-/"); done
>
> You may alias the command to:
>
> alias renamedashes='for i in $(find . -type f -name "*--*"); do mv $i $(echo $i | sed -e "s/--/-/"); done'
>
> and invoke it with
>
> $ renamedashes
>
> in future.
>
This is very good, especially making it into an alias. Two small
improvements perhaps:
First, check to see if a file with the new name doesn't already exist...
for if it does, it would be overwritten and lost. Changing "mv" to "mv
-i" would also notify the user of such events.
Secondly, unfortunately some filenames may contain whitespace. In such
a case the mv command will give unexpected results. So the arguments to
mv should be quoted.
hth
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Changing file names with "--" to "-" recursively
2021-02-21 6:45 ` Changing file names with "--" to "-" recursively Jean Louis
2021-02-21 7:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-21 13:41 ` ken
@ 2021-02-22 6:36 ` David Masterson
2 siblings, 0 replies; 8+ messages in thread
From: David Masterson @ 2021-02-22 6:36 UTC (permalink / raw)
To: wael-zwaiter; +Cc: Help Gnu Emacs
Jean Louis <bugs@gnu.support> writes:
> * wael-zwaiter@gmx.com <wael-zwaiter@gmx.com> [2021-02-21 06:07]:
>>
>> I have a lot of files and want to change "--" to "-".
>>
>> Am using
>>
>> rename 's/--/-/g' *
>>
>> on the current directory.
>>
>> How can I recursively go through all sub directories and do the
>> changes for files only.
>
> The command:
>
> $ rename 's/--/-/g' *
>
> does not work on my side as it works on yours, maybe it is different
> software.
>
> You do as following in the top directory:
>
> for i in $(find . -type f -iname "*--*"); do mv $i $(echo $i | sed -e "s/--/-/"); done
>
That should be "s/--/-/g" to handle files like "aaa--bbb--ccc"
>
> You may alias the command to:
>
> alias renamedashes='for i in $(find . -type f -name "*--*"); do mv $i $(echo $i | sed -e "s/--/-/"); done'
>
> and invoke it with
>
> $ renamedashes
>
> in future.
>
--
David Masterson
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Changing file names with "--" to "-"
2021-02-21 3:06 Changing file names with "--" to "-" wael-zwaiter
2021-02-21 3:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-21 6:45 ` Changing file names with "--" to "-" recursively Jean Louis
@ 2021-02-22 4:42 ` Robert Thorpe
2 siblings, 0 replies; 8+ messages in thread
From: Robert Thorpe @ 2021-02-22 4:42 UTC (permalink / raw)
To: wael-zwaiter; +Cc: help-gnu-emacs
wael-zwaiter@gmx.com writes:
> I have a lot of files and want to change "--" to "-".
>
> Am using
>
> rename 's/--/-/g' *
>
> on the current directory.
>
> How can I recursively go through all sub directories and do the
> changes for files only.
People have provided lots of good suggestions for doing this with the
shell. You can also do this with Emacs. I would tend to do it with
Emacs myself.
Firstly do "M-x find-name-dired". You can type "M-x f-n-d" then press
tab. Since Emacs has separate expansion for each word these days, that
will auto complete.
Then fill in the directory to start from. After that it will prompt you
"Find name (file wildcard): ". Just put in "*". That will find all
files in the directory and every subdirectory.
Wait until find has finished (see it's mode line indicator). Then
you'll have a dired buffer containing every file and sub-directory in
that directory.
Now, enable writeable dired with "C-x C-q". Now you can treat the dired
buffer as a normal buffer. Then use normal search-and-replace. You can
use "M-%" to replace "--" with "-". You can use query-replace or
replace all using "a". Then if everything is ok press "C-c C-c" to make
the actual changes. If things are wrong then press "C-c ESC". Emacs
will then spend a while doing the renames.
The contents of the buffer will disappear at this point. That's a
little disconcerting, but anyway, you're finished. All of the files are
renamed. To view them do "M-x find-name-dired" again.
This method will also rename *sub-directories* containing "--", which
might not be what you want. Using query-replace and checking everything
is a way to avoid that.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-02-22 6:36 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-21 3:06 Changing file names with "--" to "-" wael-zwaiter
2021-02-21 3:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-21 6:45 ` Changing file names with "--" to "-" recursively Jean Louis
2021-02-21 7:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-21 12:42 ` Jean Louis
2021-02-21 13:41 ` ken
2021-02-22 6:36 ` David Masterson
2021-02-22 4:42 ` Changing file names with "--" to "-" Robert Thorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).