Mac Terminal Search For Files



EDIT: This post have been getting very many views lately so ‘fess up in the comments if you want a part 2 with more advanced and new ways to use Mac OS X commands and wildcard characters.

In such a case, the “line” it returns is the entire file; this can dump a lot of text into your Terminal window. In the previous example, grep ran in a specific folder, checking all the files.

With the Finder active, display the Find controls by pressing Command+F (or choose File from the Finder menu and then choose Find). Mac OS X displays the controls that you see here. Click the buttons at the top of the list to specify where you want to search. You can choose This Mac (your entire system, including network volumes) or a local volume. Use Terminal to Find Files and Folders on Mac. The terminal is one of the most useful utility tools in Mac that lets us send direct commands to our system. A lot of users are not able to find any file or folder on Mac which is hidden. In this case, you can take the assistance of Terminal to view the hidden files/folders first.

This tip/post is going to be about several common Mac OS X commands and wildcard characters I have discovered, at work, that is useful to understand and know how to use. First off, wildcard characters are special characters such as * and ? that help you to find groups of filenames that have something in common.

Mac terminal find file

For example, say I have a couple of files that I want to find in my home directory. My home directory is cluttered with junk files that I never take the time to organize. But somewhere within that junk pile of files there lay 8 files I would like. Their filenames are ssw_idl.a285, ssw_idl.r391, ssw_idl.z988, ssw_idl.c293, and the other 4 files are named similarly (“ssw_idl.” followed by a letter, then 3 numbers).

Open up terminal (or something similar like X11’s xterm) and type in ls then enter. This lists all your files and folders in the current directory.
Cramming time:
cdchanges directories (directories = folders). cd .. to go up a directory and cd FOLDERNAME to go to a folder in the current directory.
rm – deletes files/folders.
mkdir – makes directories (folders).
say 'Hello!' – computer says ‘Hello!’
more textFileName – opens up a text file for viewing inside the command line/shell.

Now the actual reason I wrote up this post was to show you how to display only certain files with similar names. So we’ll go on to learn about wildcard characters (to be completely honest, I am a noob to this whole wildcard thing; I am stilling learning also), and then about how to use wildcard characters in the Mac OS X command line. Skip ahead if you already know about wildcard characters.

——– The Good Stuff ——-

* – this star means “everything”.
ls * will display all folders and all files within those folders.
? – means any character. ?? means any two characters. So basically ls ??* will only display files/folders that have filenames 2 or more characters long.
alphabet and numbers – typing in any letters or numbers means that files/folders must have those exact letters/numbers.
ls *.jpg – lists all files that are jpeg images (.jpg extension)
The “.” (backslash then dot with no space, in case you couldn’t see it well) means a literal dot. No backslash before the dot would mean just any single character except for a new line (n).
ls a* – lists files/folders starting with an “a”.
ls *.* – lists only files because folders don’t have a dot in their name.
ls [a-z] – lists only folders with a one character letter for their name.
ls frame[0-9] – lists any files/folders starting with “frame” and then any 1 number.

A very nicely made reference page for Mac OS X Commands:
http://www.ss64.com/osx/

Any comments welcome! Show me something cool & new!

No matter how much space you have on your Mac, one day, you may see “Your disk is almost full” notification. Even if it seems like there is no app or program that would take a considerable amount of storage, the large files may be hidden deep down in your Mac’s memory. Keep reading to discover how to locate such files on your Mac and delete them for good.

Scan the most obvious place

When looking for large files on their Macs, users often start scanning a bunch of folders stored on their machines. But, usually, the most common destination of all large files is the Downloads folder. You may automatically download thousands of files and forget to remove them. So, checking the Downloads folder on your Mac may help you find lots of forgotten large files and documents that you don’t need anymore.

Looking for the large items may take some time. Free tools, like CleanMyMac X, can accelerate the process by scanning your Mac’s memory and detecting large files. The only task left for you will be to remove the found files all at once.

Find large files using Finder

Another way to search for large files is by using search filters in Finder. It can help you locate the biggest files on your Mac. Here’s how to find large files using Finder:

Mac Find File By Name

  1. Open Finder.
  2. Find the Search field in the top right and click it.
  3. Click the Settings symbol and select Show Search Criteria.
  4. In the list of search filters on the left, choose Other.
  5. In the window that appears, select File Size and click OK.
  6. In the second space, select Is greater than and enter the size in the third space.
  7. Choose KB, MG, or GB in a final filter field.

Remember to select This Mac to get a full list of results. You will then see all files which size is greater than you defined. Look through the found documents and remove unnecessary items that take too much space on your Mac.

Although, this method has certain disadvantages. Finder doesn’t give you a full picture of the large files stored on your Mac. It shows only single files, excluding large folders that comprise a lot of smaller items.

It’s also unclear which files you can safely delete without risk of removing important documents. Finder neither provides any additional information about files nor shows which folder the file belongs to. So, it’s difficult to decide whether the large file is important or not.

Continue reading to discover how to find the largest files on your Mac using other methods.

Find large files using the Storage Management app

Another solution is to use the built-in Storage Management app.

  1. Choose Apple menu.
  2. Select About This Mac.
  3. In the window that appears, click Storage. Here you can see how much free storage you have and view the amount of space used by different categories.
  4. Click Manage.
  5. As the Storage Management app opens, select Documents.
  6. Browse the Large Files to delete those you don’t need.

Click any file to see its path at the bottom of the window. The Storage Management app also shows the exact size of each document as well as the date you opened it last.

Apple provides helpful recommendations at the top left to help you optimize your storage. Here you can choose to store all your files in iCloud, remove large files like movies and TV shows, turn on Empty Trash Automatically and reduce clutter.

This method is great for those who don’t have a lot of large files on their Mac. But, if you tend to keep many files on your machine, you may consider using the Storage Management app tiresome.

How to find biggest files on Mac via Terminal

Another way to locate large files on your Mac is to use Terminal. Although some users find commands complicated, if you use them correctly, you can find anything on your Mac. So, you can locate the biggest files on your device, just like that:

  1. Go to Utilities and open Terminal.
  2. Execute find command. If you want to locate all files bigger than 1G under the /home directory, for example, type find /home -size 1G.
  3. To delete the files enter
    find /home -type f -name *.avi -size +2G -exec rm {}
    This command will remove all AVI files that are greater than 2GB under the /home directory.

Mac Terminal Find Large Files

Using this command, you can also limit your search, setting size filters. Then your command will look like this: find /home -size +30M -size -100M. This command will locate all files that are greater than 30MB but less than 100MB.

Mac terminal search all files

Locate and remove large files using CleanMyMac X

If you have enough time, you can look through all data stored on your Mac using the methods described above. In case you want to speed up the process, CleanMyMac X can prove useful. Thanks to its Large & Old files feature, you can look at the bigger picture of all large files found on your Mac and delete them altogether.

Terminal

Here’s short instruction on how to find and delete large files using CleanMyMac X:

  1. Download the free version of CleanMyMac X and open the app once it’s installed.
  2. Click the Large & Old Files tab.
  3. Run a quick scan.
  4. CleanMyMac X will show you all files stored on your Mac. You can sort files based on their size, type, and access date, to see the large items that can be removed from your Mac.
  5. Check the boxes for the files you want to delete and click Remove.

Using CleanMyMac X, you can remove all unnecessary files quickly and make some space for more important documents.

Mac Terminal Search For Files Mac

So, these were some simple methods of how to view all files on Mac and delete them. You can either use Finder, the Storage Management app, or Terminal to find the biggest files on your Mac and clean up your machine of them.





Comments are closed.