LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 07-25-2013, 01:47 AM   #1
Virendra Nath
LQ Newbie
 
Registered: Jul 2013
Posts: 1

Rep: Reputation: Disabled
How I copy files with same name but in different case in same directory in linux ?


How I copy files with same name but in different case in same directory in linux ?
ex: mpcc & mpCC
 
Old 07-25-2013, 01:50 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

welcome to LQ.
Quote:
Originally Posted by Virendra Nath View Post
How I copy files with same name but in different case in same directory in linux ?
ex: mpcc & mpCC
If the case is different then the file names are different, so you would copy them the same way you would copy any other files. What methods have you tried? What problems did you encouter?

Evo2.
 
Old 07-25-2013, 02:50 AM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi Virendra,

This solution was posted to you on another forum.
**************************
Lets understand the problem.
(1) Files are too many to locate and copy one by one.
(2) You don't know whether the files will have names in uppercase, lowercase or mixed.

Well, the "find" command has an option to find files names with case insensitive. So instead of option "-name" , you have use -iname. Find also has an option called -exec that acts on each selected file.

So.
find . (or whichever directory) -iname "criterion" -exec command '{}' \;

See
http://linux.die.net/man/1/find

OK
**************************
Did you try it? Whats the result?

OK

Last edited by AnanthaP; 07-25-2013 at 02:56 AM.
 
Old 07-25-2013, 11:53 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
You should also be able to use simple globbing patterns in many cases, particularly in conjunction with a for loop, although it's also possible to use them directly in commands. Just remember that the string will expand into the full list of matched files before the command is executed.

In bash you can use the nocaseglob shell option to make the globbing matches case insensitive. But even without it it's usually relatively easy to create patterns that match all the files you want.

Code:
mv mp* targetdir            #move all files that start with lowercase "mp"

mv mp[cC][cC] targetdir     #move all files starting with lowercase "mp", followed by
                            #two c's, of either case.

shopt -s nocaseglob         #move all files named "mpcc", case insensitive.
mv [m]pcc targetdir
In the last line the brackets around the one letter are necessary to make the shell recognize it as a globbing pattern, as opposed to a simple filename.
 
  


Reply



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
Copy a directory into another directory while ignoring specific directories or files wh33t Linux - Newbie 14 05-16-2012 08:13 PM
Copying files from case-sensitive Linux to case-insensitive Windows via CIFS? SlowCoder Linux - General 4 05-07-2008 07:03 PM
How can I use Linux to copy binary files to a new directory lnx_learner Linux - Newbie 1 01-07-2008 11:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 08:49 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
Open Source Consulting | Domain Registration