Command Line for Mac OS x
August 2015 · 3 minute read
This tutorial will explain how to use command line basics for beginners with mac os x, including examples of creating and destroying directories and files.
1. Hold down command and press space to get a spotlight search bar in the top right of your screen.
2. Type the word terminal to find your terminal and open a new window
A terminal window will tell you in the first line when your last login was and which directory you are in (dir). A terminal or unix shell is the default command line interpreter on linux and mac osx. Command line comprises of communications between the user and their computer. By executing commands (typing them out and pressing enter) you can create new folders and files, maintain your digital library and documents, and run programs.
3. To see what’s in the home dir, type ‘ls’ and press enter. This shows a list of all directories available
$ ls
4. To create a new dir (within the home dir), execute ‘mkdir TEST’
(make directory TEST, the directory name is case sensitive)
$ mkdir TEST
5. Execute ‘ls’. You should see the list of current dirs, including the new TEST dir you have just created.
$ ls
6. To move into the new dir, execute ‘cd TEST’. You will see that the bash shell dir has changed to ‘TEST’
$ cd TEST
7. To create a new text file in the TEST directory, execute ‘touch second_test.doc’.
$ touch second_test.doc
8. Execute ‘ls’ to see the contents of the TEST dir, including the new second_test.doc document file you have just created.
9. Now create a new dir called ‘ThirdTest’ (reference steps 4-5)
$ mkdir ThirdTest
10. Cd into the new dir by typing ‘cd Th’ and then pressing ‘tab’. Tab will auto complete dir and file names within your current location.
11. To iterate through previous commands, press the up arrow and execute (press enter) when you get to the one that you’re looking for. Try this method to view the contents of your current location. You’ll notice the dir is currently empty.
12. To move back to the previous dir, type ‘cd ..’
$ cd ..
13. Again, execute ‘ls’ to view the folders contents
14. To rename a file, you can type ‘mv oldfielname newfilename’. Change the name of the second_test.doc file to test2.doc by executing ‘mv second_test.doc test2.doc ‘. Execute ‘ls’ to see the file name has changed
$ mv second_test.doc test2.doc
15. To delete a file, you can type ‘rm filename’. Execute ‘rm test2’, and then ‘ls’ to see the current dir’s new contents
$ rm test2.doc
16. To delete a dir, you can type ‘rmdir dirname’. Execute ‘rmdir TestThree’, and execute ‘ls’ to see the current dir’s new contents. It should now be empty.
$ rmdir ThirdTest