Compress Folders on a Mac Without DS_Store or __MACOSX Folder


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

  1. Open “Terminal” using spotlight search.
  2. 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”.
  3. To zip the folder use the command zip -r my-folder.zip my-folder -x “*.DS_Store and click “Enter”.
  4. You need to replace the “my folder” with its actual name of the folder.
  5. To get a clean zip file you need to do the above steps.

Shell Script to remove DS_Store Files While Compressing

  1. 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.
  2. Create a new file called twd_clean_zip.sh.
  3. Add the code in the file zip -r $1 -x “*.DS_Store.
  4. You can check the path under echo $PATH in the terminal.
  5. Open a new terminal window and execute the command sudo ano.bash_profile.
  6. The above command will open the new file in that file you need to define the custom path.
  7. Copy and the text which is given in the file and paste it in the terminal.
  8. Make sure that you need to replace /Users/twd/shell_scripts with your own custom path.
  9. Enter the code export PATH=”$PATH:/Users/twd/shell_scripts.
  10. Press “Control + X” key to exit file editing on the terminal.
  11. Just press “y” key to save changes and “return” key to save the changes.
  12. Move the script file by giving the command twd_clean_zip.sh under the custom path.
  13. You can simply copy paste the file or else use the terminal to move the file.
  14. Go to the “custom path directory” and type the command chmod +x twd_clean_zip.sh and execute it.
  15. 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.

10:24 am

Leave a Reply