Terminal 101: Automate the Terminal with Bash Scripts By MacLife 08 October 2012 Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems.The shell is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts. Users typically interact with a Unix shell using a terminal emulator; however, direct operation.
Terminal
Hey

Terminal, the wonder app, can do pretty much anything. This post is going to show you how you can unzip files using Terminal. I will also show you how you can can combine commands to download and unzip files really quickly. Its really simple to complete. You may want to use Terminal since you can access extra options which you may normally be hidden away from you.
The first step is to open Terminal. Use the “cd” command to change the directory to the location where you want to unzip the zip file. For example you can use:
cd ./Desktop
The next step is to invoke the unzip command. Type the following into Terminal. This assumes you have a zip file ready to unzip.
unzip file.zip
This will unzip you file into you desktop location. If you want to change this location you can type the following.
unzip file.zip -d ~/another/folder
You can also remove all of the text that Terminal will output when you run the command by adding a modifier/option to the front of the syntax.
unzip -q file.zip
Optionally you can also add more information by adding a verbose option. This will show you all of the details of the file you unzip.
unzip -v file.zip
You can combine this command with other command so you can download and unzip a file automatically. For example if you have wget installed you can type in Terminal.
cd ~/download;wget http://www.example.com/file/zip;unzip file.zip
The different commands are separated by a semi-colon (;). The previous command will change your directory to your downloads folder. It will then grab the zip file from your website and unzip the file to your location.
The one problem with unzip command is that it creates a an extra folder called “__MACOSX” this folder would normally be hidden as it stores extra data that you don’t need to see. You can easily get rid of this by combining the delete command with the unzip command.
Bash Download Multiple Files On Terminal Mac Mojave
unzip file.zip;rm -rf __MACOSX
That will unzip the file and then delete this extra folder. You can of course combine this with the download command previously.
cd ~/download;wget http://www.example.com/file/zip;unzip file.zip;rm -rf __MACOSX
You could even take this further by moving files and folders although that would be out of the scope of this article. How quick do you reckon it would be to type that command compared to downloading a zip folder normally and then normally extracting it. You do have to type more, but it is a lot less clicking and searching in Finder.
If you want to take your skills with Terminal a bit further I recommend you check out the Terminal Category on this site. If you fancy reading a book there is a couple on Amazon that I regularly see mentioned and recommend, O’reilly Unix Geeks and Unix Under the Hood both are designed for Mac OS X and take Terminal further.
Related posts:
Where To Next?
Terminal User Guide
In Terminal, you can move and copy files locally or remotely using the mv, cp, and scp command-line tools.
Enable Bash On Mac
Tip: It’s easier to move and copy files using the Finder. See Organize files in folders.
Bash Download File From Url
Move a file or folder locally
Install Bash On Mac
In the Terminal app on your Mac, use the
mvcommand to move files or folders from one location to another on the same computer. Themvcommand moves the file or folder from its old location and puts it in the new location.For example, to move a file from your Downloads folder to a Work folder in your Documents folder:
% mv ~/Downloads/MyFile.txt ~/Documents/Work/MyFile.txtYou can also change the name of the file as it’s moved:
% mv ~/Downloads/MyFile.txt ~/Documents/Work/NewFileName.txt
See the mv command man page.
Copy a file or folder locally
In the Terminal app on your Mac, use the
cpcommand to make a copy of a file.For example, to copy a folder named Expenses in your Documents folder to another volume named Data:
% cp -R ~/Documents/Expenses /Volumes/Data/ExpensesThe
-Rflag causescpto copy the folder and its contents. Note that the folder name does not end with a slash, which would change howcpcopies the folder.
See the cp command man page.
Bash Download Multiple Files On Terminal Mac Osx
Copy a file or folder remotely
Bash Terminal Download Win 10
In the Terminal app on your Mac, use the
scpcommand to copy a file or folder to or from a remote computer.scpuses the same underlying protocols asssh.For example, to copy a compressed file from your home folder to another user’s home folder on a remote server:
% scp -E ~/ImportantPapers.tgz username@remoteserver.com:/Users/username/Desktop/ImportantPapers.tgzYou’re prompted for the user’s password.
The
-Eflag preserves extended attributes, resource forks, and ACL information.The
-rflag, which isn’t used in this example, causesscpto copy a folder and its contents.
See the scp command man page.