LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   How I copy files with same name but in different case in same directory in linux ? (https://www.linuxquestions.org/questions/red-hat-31/how-i-copy-files-with-same-name-but-in-different-case-in-same-directory-in-linux-4175470835/)

Virendra Nath 07-25-2013 01:47 AM

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

evo2 07-25-2013 01:50 AM

Hi,

welcome to LQ.
Quote:

Originally Posted by Virendra Nath (Post 4996370)
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.

AnanthaP 07-25-2013 02:50 AM

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

David the H. 07-25-2013 11:53 AM

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.


All times are GMT -5. The time now is 06:56 PM.