[태그:] Tech Tips

  • Mac File Organizer: How to easily extract only files in subfolders

    Mac File Organizer: How to easily extract only files in subfolders

    When you need to collect files in subfolders separately on Mac

    When using a Mac, there are times when you need to gather files scattered across several subfolders into one place.

    Mac File Organizer: Extract Files from Subfolders
    Mac File Organizer: Extract Files from Subfolders

    Original Korean article: Mac File Organizer: How to easily extract only files in subfolders

    For example, you might have project materials, photos, downloads, and scanned documents divided into folders. At this time, if you do not need a folder structure and just want to collect files separately, you can use two methods.

    The first way is to utilize the Finder search function. The second method is to use the find command in the terminal.

    If you don't have a lot of files, Finder is convenient. If you have a lot of files or need to do repetitive tasks, the Terminal method is faster.

    First things first: copying and moving are different

    Before you start, you need to distinguish the difference between copying and moving.

    Copying is a method of leaving the original file as is and creating another identical file in a new location. Moving involves removing files from their original location and moving them to a new location.

    If it's important material, it's best not to move it in the first place. Test by copying first, check the results, and move only when necessary.

    Method 1. Collect only files through Finder search

    The easiest way is to use Finder's search function. You don't need to know the commands, and you can work while visually checking the results.

    Step 1. Open top level folder

    Open Finder and navigate to the top-level folder containing your files.

    For example, let's say you have the following structure:

    project-folder
    ├── source-files-1
    │   ├── document1.pdf
    │   └── document2.docx
    ├── source-files-2
    │   ├── image1.jpg
    │   └── image2.png
    └── references
        └── memo.txt

    The goal is to collect only the files in one place, ignoring the subfolder structure under the project folder.

    Step 2. Open Finder search bar

    With the top-level folder open, press the following shortcut key:

    Cmd(⌘) + F

    Alternatively, you can click the search icon at the top right of Finder.

    Step 3. Enter search term

    Enter the search term below in the search box.

    NOT kind:folder

    The important thing here is to type NOT in capital letters.

    This search term means “Show me only items, not folders.” This means that only files will appear in search results, and no subfolders will be included.

    Step 4. Change search scope to current folder

    At the bottom of the search bar, you have the option to select a search location.

    If the default is This Mac, your entire Mac can be searched. This may cause unwanted files to be mixed into the results.

    So you need to change the search scope to the name of the folder you are currently working in.

    For example, if you're searching within a project folder, select Project Folder, not This Mac.

    Step 5. Select all files and copy or move them

    If only files are displayed in the search results, select all with the following shortcut key.

    Cmd(⌘) + A

    To copy, follow these steps:

    Cmd(⌘) + C → move-to-target-folder → Cmd(⌘) + V

    To move, follow these steps:

    Cmd(⌘) + C → move-to-target-folder → Cmd(⌘) + Option(⌥) + V

    If you select Move, the files in their original location will disappear and be moved to the destination folder.

    When the Finder method is suitable

    The Finder method is suitable for the following situations:

    • When there are not many files
    • If you are not familiar with using commands
    • When you want to move a file while visually checking it
    • When you want to avoid accidentally making the wrong move

    However, if you have more than a few thousand files, Finder may become slow. In this case, the terminal method is more stable.

    Method 2. Copy only files using terminal command

    If you have a lot of files or complex subfolders, you might want to use the Terminal.

    In the terminal, you can only find files in subfolders with the find command. And you can copy or move the found files to any folder you want.

    Step 1. Run terminal

    Press the following shortcut key:

    Cmd(⌘) + Space

    When the Spotlight search box opens, type Terminal or Terminal and run it.

    Step 2. Create a folder to collect files

    We recommend that you first create a new folder to collect your files.

    For example, you can create a folder called Collected Files on your desktop. To create it in the terminal, enter the following command:

    mkdir ~/Desktop/collected-files

    You can also create a new folder directly in Finder.

    Command to copy files

    To copy the original files to the destination folder while leaving them intact, use the following format:

    find source-folder-path -type f -exec cp {} target-folder-path \;

    For example, to copy all files in the Downloads/Data folder to the collected files folder on the desktop, enter the following:

    find ~/Downloads/files -type f -exec cp {} ~/Desktop/collected-files \;

    Here the last \; is not an unnecessary character. This is a required marker that tells you where the find -exec command ends. In zsh/bash on a Mac terminal, if you write a semicolon as is, the shell will interpret it first, so you must precede it with a backslash \; You must enter it like this:

    This command will scan all subfolders under the Materials folder. Then, find only the files, excluding folders, and copy them to the collected files folder.

    Command to move files

    To remove a file from its original location and move it to a destination folder, use mv instead of cp.

    find source-folder-path -type f -exec mv {} target-folder-path \;

    An example can be seen like this.

    find ~/Downloads/files -type f -exec mv {} ~/Desktop/collected-files \;

    When you run this command, the files in the source folder will be moved to the destination folder. After the move, no files will remain inside the existing subfolders.

    If entering the path is difficult, use drag and drop.

    The most confusing part of the terminal is entering the folder path.

    If you find it difficult to enter the path directly, drag and drop the folder from Finder into the terminal window. The folder path will then be automatically entered.

    When moving files, the entire flow can be viewed like this:

    find [drag-source-folder] -type f -exec mv {} [drag-target-folder] \;

    The actual command will have a form similar to the following.

    find /Users/username/Downloads/files -type f -exec mv {} /Users/username/Desktop/collected-files \;

    Folder names with spaces are automatically processed when you drag and drop them, so they are safer than entering them manually.

    Be careful if there are files with the same name

    There may be files with the same name in different subfolders.

    For example, let's say you have the following files:

    Aexample/report.pdf
    Bexample/report.pdf

    If you put two files together in the same folder, the file names will conflict. In this case, existing files may be overwritten depending on the command method.

    If it is important material, test it by copying it first. It is safer to proceed after checking the results.

    Safe copy command to avoid overwriting

    If you do not want to overwrite files with the same name, you can use the cp -n option.

    find source-folder-path -type f -exec cp -n {} target-folder-path \;

    An example can be seen like this.

    find ~/Downloads/files -type f -exec cp -n {} ~/Desktop/collected-files \;

    The -n option prevents overwriting if a file with the same name already exists in the destination folder.

    If you are doing this for the first time, this method is safer.

    Which method should you choose: Finder or Terminal?

    Situation Recommended method There are a small number of files. You are not familiar with Finder commands. You want to move Finder files while visually checking them. There are a lot of Finder files. Terminal. Subfolders are very complicated. Terminal. Repeated work is required. Terminal. You want to batch process quickly. Terminal.

    If this is your first time trying it, we recommend checking it out using the Finder method. If you need to do a lot of work or the Finder is slow, you can use the terminal method.

    Checklist before work

    To collect files without mistakes, check the items below first.

    • Check that the original folder is correct.
    • Create a destination folder in advance to collect files.
    • Important material is tested by copy first.
    • Check to see if they can have the same file name.
    • Move commands are used after testing.

    Just checking these five things can significantly reduce your risk of file loss.

    organize

    There are two main ways to ignore the subfolder structure on Mac and collect files in one place.

    In Finder, you can easily pick out just the files by using the NOT kind:folder search. In the terminal, you can quickly process large files by using the find command and the -type f option.

    If you are a beginner, I recommend the Finder method. If there are many files or repetitive tasks are required, the terminal method is recommended.

    When dealing with important material, don't move it right away; test it with a copy first. In particular, since files with the same name may exist in multiple folders, it is recommended to check whether they will be overwritten.

    FAQ

    What if NOT kind:folder doesn't work properly in Finder?

    Make sure you type NOT in capital letters. Also make sure the search scope is set to the folder you're currently working in, not This Mac.

    How do I move files without copying them?

    In Finder, press Cmd + C and then Cmd + Option + V in the destination folder to move. In the terminal, you can use the mv command instead of cp.

    What happens if there are files with the same name?

    A conflict may occur if a file with the same name already exists in the destination folder. For safe copying, we recommend using the cp -n option.

    Aren't subfolders copied as is?

    Using NOT kind:folder in Finder or the -type f option in Terminal selects only files, not folders. So the subfolder structure is not copied.

    What is the best method if terminal commands are burdensome?

    If there are not many files, the Finder method is easiest. Terminal is recommended for use when large file processing or repetitive tasks are required.

    Related Reading

    FAQ

    What is this article about?

    This article is an English translation and global-reader adaptation of the Korean post “Mac File Organizer: How to easily extract only files in subfolders.” It preserves the original article’s main explanation, examples, and practical context.

    Why is it translated into English?

    The English version helps global readers access Thinknote articles through English search keywords while keeping the Korean source available as the original reference.

    Where can I read the original Korean version?

    You can read the original Korean article here: https://www.thinknote.co.kr/mac-extract-files-from-subfolders/