From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: ken Newsgroups: gmane.emacs.help Subject: Re: Changing file names with "--" to "-" recursively Date: Sun, 21 Feb 2021 08:41:07 -0500 Message-ID: <018f5831-352f-0aee-6505-010d0a4bc80e@mousecar.com> References: Reply-To: gebser@mousecar.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25656"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 21 14:42:02 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDozp-0006YZ-Uw for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 21 Feb 2021 14:42:01 +0100 Original-Received: from localhost ([::1]:55090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lDozo-00084R-U1 for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 21 Feb 2021 08:42:00 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lDoz7-00083M-J7 for help-gnu-emacs@gnu.org; Sun, 21 Feb 2021 08:41:17 -0500 Original-Received: from mout.perfora.net ([74.208.4.197]:48499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lDoz5-0004aD-NI for help-gnu-emacs@gnu.org; Sun, 21 Feb 2021 08:41:17 -0500 Original-Received: from [192.168.0.17] ([96.27.75.237]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPSA (Nemesis) id 0MNJJ1-1lBvIe1N7J-006zFJ for ; Sun, 21 Feb 2021 14:41:13 +0100 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:H2uPDLSd0wd4p0Mz67F34dJZRDP70y0H6O2dzat01cKZ1VMw+/V gDiHWcGBEgs2UEYeE6ZNMsLvewXMX16Zlpy3pF+U0oxfvgZIQuFVuRT7FT2+nv2pSYohPs6 UlkKItXwHgZs8Q89MmVUXS6ZyQDSHreGG+XboTeYBhNtGQgXpkRd/1UOAWrxRlxIKHJ9P1h enV8J15d3Bheg1eLjIpZg== X-UI-Out-Filterresults: notjunk:1;V03:K0:WS5WaFrOSPI=:Bkx3ruNPRJjAcdiDAZ9qGt ERnBwiPrPvuP2beMpZSNZXiQ5RnuC1AM01pWGJtdgUbgZLn3ChccX6L/SYohGIPzlsNldIK3W RUFQbKvM8uedSQB9JcCb+LBfxDTjkjrIBDlW6YJZhY0a0aZp9CHvZw5F2k79dUfwsb23N/guD lqKsMnHw1PR1yze8BzUC7JhZBuaNERy9sy9VUyF+pGp7OZ43ib28s3JlHcHXG30+35JsAEcXn W1Qgek2K8huYvMh4EvDv4GUyXyCkqCoVdCO1VveHYerqBea9E5MiMtpbVD2wZwSOmOlKmnIF1 Nz9OstoR2fYyLe48XPQYASFDMxt23T5RD4f++Vy5aJlHBN7h6CO4RljBRhpNpSQwBrxC7MXg0 MF+ZxywvPg8c10lx9PmIwJG0Qp+n4R7YQVcxfe4GDucRgsh/SW8H2mnONXTT/kEnOpQMXRQQr 7Whs1O0CUg== Received-SPF: none client-ip=74.208.4.197; envelope-from=gebser@mousecar.com; helo=mout.perfora.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128183 Archived-At: On 02/21/2021 01:45 AM, Jean Louis wrote: > * 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