Friday, March 6, 2015

Mac OS X Terminal Commands - Getting Started - Python Tutorial

Mac OS X Terminal CommandsWhen it comes to learning Python there are several other tools you will need to learn as well to make you full fledge Python programmer. In today’s tutorial we will focus on Mac OS X Terminal Commands which we will need to know since we will spend a good amount of time in the Terminal.  Some of you that were around when computers only took commands from command line maybe thinking why are we going back in history but the truth is if you are familiar with the terminal you will be able to make things happen faster and easier than the graphical interface will allow you.


What Is The Terminal?


The terminal is an application that gives you ability to command your computer to perform a certain task by typing in a short command. When using the terminal, you are giving your computer a direct command similar to what some software would do if you were using software to perform the task. The terminal application is the same as back in the day when you would have to type in the command line for certain commands to put a game on your computer or to get the computer to do a simple task. The reason why the terminal is still available in the graphical user interface era is because it is one of the most powerful tools your computer has.


How to Open The Terminal?


The terminal application is located in the applications folder > utilities > terminal. We can either open the terminal through finder or we can be quicker or lazier however you want to look at and press command + space bar which opens spotlight and then we can type in the terminal.


How to Open The Terminal? Command + Spacebar then type terminal


 


I suggest that you then pin your terminal to your dock so we can be even lazier and just click on the terminal as we go through our Python tutorials.


Entering The Terminal


Now that we have the terminal open.  You will not see much but your terminal will look a bit different than mine.


Open Terminal


Our commands start after the $ symbol.  In this tutorial, we are going show you the $ symbol in our examples since that symbol is universal but do not type it into your terminal when following along with us. Let’s get started with some basic Mac OS X terminal commands that we will be using in our Python tutorials.


Print Working Directory


pwd – Print working directory gives the location of the directory we are currently in.  This is a good way to find out where you are currently at within your files.


$ pwd
/Users/Tommy/desktop

List Information About File


ls – List information about file gives us all the files and folders in the containing folder.


$ ls
comments.py python wizardtut.py
django videos
projects web developement notes

Change Directory


cd – Change directory gives us the ability to navigate through our folders and files.


$ ls
Applications Downloads Pictures
Creative Cloud Files Library Public
Desktop Movies
Documents Music

Thomass-MBP:~ Tommy$ cd desktop

Thomass-MBP:desktop Tommy$

cd /foldername/filename – Move multiple directories at once.


$ cd desktop/python
Thomass-MBP:python Tommy$

cd .. – Move up to parent directory


python Tommy$ cd ..
Thomass-MBP:desktop Tommy$

cd ../.. – Move up to directories


Thomass-MBP:python Tommy$ cd ../..
Thomass-MBP:~ Tommy$

Create New Folder


mkdir – We can create a new folder using this command.


Thomass-MBP:desktop Tommy$ mkdir learnPython
Thomass-MBP:desktop Tommy$ cd learnPython
Thomass-MBP:learnPython Tommy$

Create File


touch – We can use this command to create a file


Thomass-MBP:desktop Tommy$ touch manage.py
Thomass-MBP:desktop Tommy$ ls
django projects web developement notes
learnPython python wizardtut.py
manage.py videos

Remove Files


rm – This command gives us the ability to remove files


Thomass-MBP:desktop Tommy$ ls
comments.py projects web developement notes
django python wizardtut.py
learnPython videos
Thomass-MBP:desktop Tommy$ rm comments.py
Thomass-MBP:desktop Tommy$ ls
django python wizardtut.py
learnPython videos
projects web developement notes
Thomass-MBP:desktop Tommy$

Remove Folder


rmdir – This command gives the ability to remove folders


Thomass-MBP:desktop Tommy$ ls
django python web developement notes
learnPython test wizardtut.py
projects videos
Thomass-MBP:desktop Tommy$ rmdir test
Thomass-MBP:desktop Tommy$ ls
django python wizardtut.py
learnPython videos
projects web developement notes

Make Computer Talk


say – This will change your text into audio.  This has nothing to do with our Python tutorials but I think it is fun and wanted to share it.


Thomass-MBP:desktop Tommy$ say "Learn Python Tutorial is the best Tutorial Site"

Conclusion of Mac OS X Terminal Commands


Now that we have covered some of the basic Mac OS X Terminal Commands we can move on with our Python tutorials.  Theses are only the basics if you want to learn more there are several resources on the internet do not forget to check them out. The commands that we covered in this tutorial will help you through the Python tutorials and if any others come up during the tutorials I will remember to share them.



No comments:

Post a Comment