Here are a few common Terminal Commands I found to be useful for OSX/Unix newcomers like myself.
There are times that you’ll need to use the Terminal Command-Line Interface (CLI), especially when troubleshooting.
Here are a few common Terminal Commands I found to be useful for OS X/Unix newcomers like myself.
Before we start, open the application called TextEdit in the Applications directory. Change the format to “Make Plain Text” from the “Format” menu (note that this tutorial works with the “Make Rich Text” format as well with a “.rtf” extension; however, I prefer the “.txt” extension because it is the universal cross platform extension for plain text files). Then save the file with the name “test.txt” to your Desktop
Now open the Terminal application in the Applications directory. The start up screen will look something like this:
Last login: Sun Jan 5 12:51:58 on ttyp1
Welcome to Darwin!
Unlike the Mac OS X’s nice Aqua interface, the Terminal will display the file data and directory structure in a raw black and white format. The Terminal usually starts off in your home directory. (user%) So let’s get started with a command-line to change the directory to the “Desktop” directory.
Cd is short for change directory. This will change the current directory to the directory specified. To access the “Desktop” directory, type:
Hit return to execute the command (do this every time to execute each command line).
To return to your home directory, type:
But for now let’s keep the path to the “Desktop” (cd Desktop).
Mkdir is short for make directory (make folder). To make a test directory, type:
Pwd displays the path of the current directory. Type:
will display something like this:
Cp is short for copy. To copy the “test.txt” file inside of the “test” directory on the “Desktop”, type:
cp /Users/alex/Desktop/test.txt test/test2.txt
This placed a copy of the “test.txt” file inside the “test” directory and named it “test2.txt”.
Notice after the command “cp” we type “pathdir+old name” space, than “dir+new name”.
Change (cd) directory to the “test” directory (see above for help).
Ls is short for list. Ls will list files in a directory. Type:
Mv will change the name of a file. From the test directory type:
mv test2.txt test3.txt
Notice after the command “mv” we type “old name” space, than “new name”. Type “ls” to check if it worked.
Rm is short for remove (delete). To remove the “test3.txt” file inside the current directory type:
Or remove a folder with or without items in side
sudo rm -rf /path/folder_name
Man is short for manual. For example to display the manual for “rm” type:
This will display information about the “rm” command. You can type any command after “man” to access additional information on that topic.
9) “Q” key
Q is short for quit. To escape the manual screen, hit the “Q” key:
If you have any questions, please search or post a question to the forum.