DS_Store and MACOSX folder are the files that help to store the custom attributes of the folder. Many of the Mac users have the problem that, when they compress a folder in the archived folder contains .DS_Store and _MACOSX folders. They used to share the archived file in the online for download, but windows users are trying to search the file in the _MACOSX folder.
Here I gonna tell you how to compress your folders on Mac without using the .DS_Store and _MACOSX folders on Mac.
How to compress folders on Mac without DS_Store
- Open “Terminal” using spotlight search.
- Move the folder which you need to compress. For example, if you need to compress a folder which is on the desktop then move to the desktop by using the command cd Desktop and click “Enter”.
- To zip the folder use the command zip -r my-folder.zip my-folder -x “*.DS_Store and click “Enter”.
- You need to replace the “my folder” with its actual name of the folder.
- To get a clean zip file you need to do the above steps.
Shell Script to remove DS_Store Files While Compressing
- It is very difficult to remember the commands. So that, we used to create a shell script. A shell script is a collection of commands that are stored in a file.
- Create a new file called twd_clean_zip.sh.
- Add the code in the file zip -r $1 -x “*.DS_Store.
- You can check the path under echo $PATH in the terminal.
- Open a new terminal window and execute the command sudo ano.bash_profile.
- The above command will open the new file in that file you need to define the custom path.
- Copy and the text which is given in the file and paste it in the terminal.
- Make sure that you need to replace /Users/twd/shell_scripts with your own custom path.
- Enter the code export PATH=”$PATH:/Users/twd/shell_scripts.
- Press “Control + X” key to exit file editing on the terminal.
- Just press “y” key to save changes and “return” key to save the changes.
- Move the script file by giving the command twd_clean_zip.sh under the custom path.
- You can simply copy paste the file or else use the terminal to move the file.
- Go to the “custom path directory” and type the command chmod +x twd_clean_zip.sh and execute it.
- You can now able to cleanly zip files using a simple command sudo twdd-clean_zip.sh my-folder.
Creating a shell script is optional. But it is very useful for those who don’t able to remember anything.
Note: To make our script globally accessible, we need to add this file to one of the global paths.
Hope this article is useful for your problem. If you find this article is as useful for you kindly share your opinion via the comments.