4 Useful Terminal Commands for Awkward Finder Tasks (Bite-size Article)

Introduction

Today’s article is a short one, but I’d like to share four useful Terminal commands I recently learned for Finder-related tasks (Mac).

Until not long ago, I used to check these things manually, but doing them in Terminal is much faster, so I’ve been using these commands a lot lately. I decided to write this article partly as a memo for myself, and also to share them with people who may not know them yet. Much of this is fairly basic, so some of you may already know these, but if you’re interested, I hope you’ll give it a quick read.

1. Show Only Recently Updated Files

find . -type f -mtime -7

This command lists files that have been updated recently under the current directory and its subdirectories.

Finder does have a “Recent” section in the sidebar, but in my case—perhaps because of my own PC—it can sometimes take time to load, or miss files I expect to see. So this feels like a more reliable method.

The -7 part represents the number of days in the past, so it’s convenient that you can change it to any value you want.

2. Count Files

First, here is the simplest version as a basic way to count files.

find . -type f | wc -l

This command counts the number of files under the current directory (excluding folders).

If you want to include folders as well, you can use:

find . | wc -l

Note: In this form, the starting point . itself is also counted as one item. If you do not want to include it, use find . -mindepth 1 | wc -l instead.

Next, based on these commands, here is an example of excluding a specific folder.

find . -type f ! -path '*/node_modules/*' | wc -l

This counts files while excluding node_modules. In this case, the added condition is “exclude this folder.”

If you want to count only files that contain a specific string in their filename, you can change it like this:

find . -type f -name '*test*' | wc -l

This counts only files whose names contain test.

Here, the added condition is “filter by name.”

Finder already shows the number of items in a directory at the bottom by default, but by combining commands like these, you can investigate with much more specific conditions, which makes them very useful.

3. Find Empty Folders

find . -type d -empty

This command lists only empty directories.

Sometimes you create a folder during work and forget to put anything in it, or empty folders remain after reorganizing files. It is possible to look for them in Finder, but it becomes quite troublesome once the folder hierarchy gets deep.

In those situations, this command is convenient because it lets you check unnecessary empty folders all at once. It is a small thing, but quite useful when cleaning up a project.

4. Quickly See Which Folders Are Heavy

du -sh ./* | sort -h

This command displays the sizes of files and folders directly under the current directory in an easy-to-read order.

du -sh ./* shows the size of each item, and sort -h arranges them in order by size. Because of that, it is useful when you want to get a rough idea of which folders are taking up the most space.

In Finder, you can check information for individual items with Command + I, but comparing multiple folders in a list is a bit inconvenient. When you want to identify unused large data and delete it, it can be very productive to go to a suspicious directory first and run this command.

Note: In this example, hidden files and hidden folders whose names begin with a dot are not included.

Conclusion

Today I introduced four Finder-related Terminal commands that I have been using a lot recently.

Personally, many of these tasks could already be checked manually, so for a long time I never really had the idea of looking into whether there was a faster way to do them. However, once I started using them in real work, I found them extremely convenient, and I feel that they noticeably improve the speed of small verification tasks, even if only in subtle ways.

Finder can already do many things quite well, but when you want to check things with more specific conditions, Terminal still feels more useful. If I come across more commands like these, I’d like to keep sharing them here as notes for myself as well.

Thank you very much for reading!

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

VCs are betting billions on AI’s next wave, so why is OpenAI killing Sora?

Next Post

Memory chip giant SK hynix could help end ‘RAMmageddon’ with blockbuster US IPO

Related Posts
arkui-x平台差异化

ArkUI-X平台差异化

跨平台使用场景是一套ArkTS代码运行在多个终端设备上,如Android、iOS、OpenHarmony(含基于OpenHarmony发行的商业版,如HarmonyOS Next)。当不同平台业务逻辑不同,或使用了不支持跨平台的API,就需要根据平台不同进行一定代码差异化适配。当前仅支持在代码运行态进行差异化,接下来详细介绍场景及如何差异化适配。 使用场景 平台差异化适用于以下两种典型场景: 1.自身业务逻辑不同平台本来就有差异; 2.在OpenHarmony上调用了不支持跨平台的API,这就需要在OpenHarmony上仍然调用对应API,其他平台通过Bridge桥接机制进行差异化处理; 判断平台类型 可以通过let osName: string = deviceInfo.osFullName;获取对应OS名字,该接口已支持跨平台,不同平台上其返回值如下: OpenHarmony上,osName等于OpenHarmony-XXX Android上,osName等于Android XXX iOS上,osName等于iOS XXX 示例如下:…
Read More