InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

Menu
  • Home
  • Sitemap

Python Programming Language Best Tutorials and Code Examples

Learn Python Right Now!
Home
Bash
Finding Files Irrespective of Case in bash
Bash

Finding Files Irrespective of Case in bash

InfinityCoder February 20, 2017

Some of your MP3 files end with .MP3 rather than .mp3. How do you find those?

Use the -iname predicate (if your version of find supports it) to run a case-insensitive search, rather than just -name.

For example:

1
$ find . -follow -iname '*.mp3' -print0 | xargs -i -0 mv '{}' ~/songs

Sometimes you care about the case of the filename and sometimes you don’t.

Use the-iname option when you don’t care, in situations like this, where .mp3 or .MP3 both indicate that the file is probably an MP3 file.

(We say probably because on Unix-like systems you can name a file anything that you want.

It isn’t forced to have a particular extension.)
One of the most common places where you’ll see the upper- and lowercase issue is when dealing with Microsoft Windows-compatible filesystems, especially older or “lowest common denominator” filesystems.

A digital camera that we use stores its files with filenames like PICT001.JPG, incrementing the number with each picture.

If you were to try:

1
$ find . -name '*.jpg' -print

you wouldn’t find many pictures. In this case you could also try:

1
$ find . -name '*.[Jj][Pp][Gg]' -print

since that regular expression will match either letter in brackets, but that isn’t as easy to type, especially if the pattern that you want to match is much longer.

In practice, -iname is an easier choice. The catch is that not every version of find supports the -iname predicate.

If your system doesn’t support it, you could try tricky regular expressions as shown above, use multiple -name options with the case variations you expect, or install the GNU version of find.

Share
Tweet
Email
Prev Article
Next Article

Related Articles

Setting Your $CDPATH in bash
You want to make it easier to switch between several …

Setting Your $CDPATH in bash

Using Array Variables in bash
There have been plenty of scripts so far with variables, …

Using Array Variables in bash

About The Author

InfinityCoder
InfinityCoder

Leave a Reply

Cancel reply

Recent Tutorials InfinityQuest

  • Adding New Features to bash Using Loadable Built-ins in bash
    Adding New Features to bash Using Loadable …
    June 27, 2017 0
  • Getting to the Bottom of Things in bash
    Getting to the Bottom of Things in …
    June 27, 2017 0

Recent Comments

  • fer on Turning a Dictionary into XML in Python
  • mahesh on Turning a Dictionary into XML in Python

Categories

  • Bash
  • PHP
  • Python
  • Uncategorized

InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

About Us

Start learning your desired programming language with InfinityQuest.com.

On our website you can access any tutorial that you want with video and code examples.

We are very happy and honored that InfinityQuest.com has been listed as a recommended learning website for students.

Popular Tags

binary data python CIDR convert string into datetime python create xml from dict python dictionary into xml python how to create xml with dict in Python how to write binary data in Python IP Address read binary data python tutorial string as date object python string to datetime python

Archives

  • June 2017
  • April 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
Copyright © 2021 InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more
Programming Tutorials | Sitemap