LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-25-2019, 08:10 PM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 421

Rep: Reputation: 0
rename utility reports error, running from Mobaxterm


Hey Guys,

Performing an exercise to rename all files/directories where there is a space in the file name or directory.

Here is the snippet:
Code:
find -name "* *" -type d | rename 's/ /_/g'
find -name "* *" -type f | rename 's/ /_/g'
And there are files are directories with spaces, please refer to the below:
Code:
find -name "* *" -type d
./online/online/Maven Jenkins
./Lynda.com - Learning Azure DevOps (2)
./Lynda.com - Learning Azure DevOps (2)/Lynda.com - Learning Azure DevOps
./Lynda.com - Learning Azure DevOps (2)/Lynda.com - Learning Azure DevOps/0 - Introduction
./Lynda.com - Learning Azure DevOps (2)/Lynda.com - Learning Azure DevOps/1 - 1. Azure Boards
./Lynda.com - Learning Azure DevOps (2)/Lynda.com - Learning Azure DevOps/2 - 2. Azure Repos

find -name "* *" -type f | head -5
./'Hacking With Experts.pdf'.pdf
./-Linux Command.pdf
./1 - Creating a Web Server Deployment - Outline.zip
./2000+ udemy coupons 100% off Latest.docx
./2019_0114-STG_Slide-Deck (2).pdf
When I run the find command piped with rename it reports the error below:

Code:
+ find -name '* *' -type d
+ rename 's/ /_/g'
rename: not enough arguments

Usage:
 rename [options] <expression> <replacement> <file>...

Options:
 -v, --verbose    explain what is being done
 -s, --symlink    act on the target of symlinks

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see rename(1).
+ find -name '* *' -type f
+ rename 's/ /_/g'
rename: not enough arguments
What is the issue and how to fix it?
 
Old 04-25-2019, 08:25 PM   #2
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 2,889

Rep: Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001
Quote:
Originally Posted by sysmicuser View Post

What is the issue and how to fix it?
Code:
Usage:
 rename [options] <expression> <replacement> <file>...
...so rename followed by options followed by an expression, a replacement, and a filename pattern.
Your command has only the expression.

Use the --verbose option to see what's going on.
Have you read man 1 rename as suggested?
Also review man find, as you can exec the command within find...I don't think the pipe is doing what you want it to. Something like:
Code:
find -name "* *" -type f -exec ls -l ##to test
find -name "* *" -type f -exec rename 's/ /_/g' {} \;  #but I'm not sure of my syntax
Give how unforgiving rename is when it works, search for more information on find and -exec
 
1 members found this post helpful.
Old 04-25-2019, 11:31 PM   #3
sysmicuser
Member
 
Registered: Mar 2010
Posts: 421

Original Poster
Rep: Reputation: 0
Thanks Sean, will try out and see how it goes. Thank you again.
 
Old 04-26-2019, 12:26 AM   #4
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 2,975

Rep: Reputation: 771Reputation: 771Reputation: 771Reputation: 771Reputation: 771Reputation: 771Reputation: 771
I believe that there are several versions of rename with different options, depending on the distro. If in doubt, use the man page and/or rename --help.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello, this is my first post! Seems I have a fix for MobaXterm's apt-cyg/apt-get cpqlinux LinuxQuestions.org Member Intro 2 05-10-2018 11:11 AM
MobaXterm not Installing git danielvolk Linux - Newbie 3 05-04-2018 03:12 PM
MobaXterm connect to host port 22: Connection timed out redhatwannabe General 0 11-07-2012 07:41 PM
Rename network interface (Rename ppp0 ...) Nicolas1390 Linux - Newbie 2 08-08-2011 02:14 AM
Rename/VI/Awstats Reports Usage nistelrooy Linux - General 7 07-16-2005 09:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration