Basic Terminal Commands

Here are a few common Terminal Commands I found to be useful for OSX/Unix newcomers like myself.
Introduction:

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.

Preparation:

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!
[Alexander-Mclean-IIIs-Computer:~] alex%

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.

Commands:

1) cd

Cd is short for change directory. This will change the current directory to the directory specified. To access the “Desktop” directory, type:

cd Desktop

Hit return to execute the command (do this every time to execute each command line).

To return to your home directory, type:

cd ~

But for now let’s keep the path to the “Desktop” (cd Desktop).


2) mkdir

Mkdir is short for make directory (make folder). To make a test directory, type:

mkdir test

3) pwd

Pwd displays the path of the current directory. Type:

pwd

will display something like this:

/Users/alex/Desktop


4) cp

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).

5) ls

Ls is short for list. Ls will list files in a directory. Type:

ls

will output.

test2.txt

6) mv

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.

7) rm

Rm is short for remove (delete). To remove the “test3.txt” file inside the current directory type:

rm test3.txt

Or remove a folder with or without items in side

sudo rm -rf /path/folder_name

8) man

Man is short for manual. For example to display the manual for “rm” type:

man rm

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.

27 Responses

  1. bangi

    Very helpful for new mac user Thank you

  2. api

    cannot find continue, may i kindly ask to write more?

    a

  3. api

    vv – okey, it’s fine, i found it…

  4. kranthi

    thank you for giving me required information

  5. Dave

    How does one display the contents of a file (ie text) within Terminal? I thought it was ty (ie, type) but this is wrong.

  6. Mark

    Thanks for the basics, bookmarking this page until i’ve memorised them. :)

  7. Oru

    Hi. I’m not an Mac user, my system is Linux, but the terminal commands are almost the same. A friend have a problem with an apparently wrong installed program and I need to know how to get rid of it because he can’t uninstall it. Maybe from the terminal I can do it, but I need to know exactly how before a try. Thanks for any advice on the matter. :)

  8. Michelle

    Hello,

    I like your tutorial but I am having a hard time with a remote server.

    I have a file (it is html – should it be txt?) on my desktop an I need it to go to a remote server for streaming.

    usr/local/MediaServer/content/rtmp.stream (is the path of the folder)

    Thank you,
    Michelle

  9. sampath

    thanks for this…………

  10. Joe

    Thank you SO much!!!

  11. Pingback: Diving In: The Hard Way » Learn to code already! (and learn about data while you're at it)

  12. Alrescha

    I think it’s pretty irresponsible (and unnecessary) to mention the sudo command on a page of ‘basic’ terminal commands. Newbies looking for their first help with the terminal shouldn’t be told about sudo.

    A.

  13. vicky

    very useful for new user like me :)

  14. Alex

    I’m just new to Mac and to the Terminal app, and this has helped nicely, thank you.

  15. Dana

    Thanks so much! Great beginning resource. Very clear.

  16. Govi

    no offense or anything but DO NOT use a sudo command to remove empty folders… use rmdir instead because it’s a lot less risky.
    Govi

  17. someone

    when i open terminal, it’s totally blank
    HELP!!

    P.S. IT ALSO WONT DO ANYTHING WHEN I HIT ENTER!

    HELP!!!!!!!!!

  18. James

    Likewise… I open terminal.. tyoe in sudo -s, get password prompt and end of story! cannot type and when I quit terminal and restart its totally blank… as is XTerm!

  19. Dante

    Hi, what is the terminal help equivalent of –help in mac terminal?

  20. Pingback: iFound: a Terminal Commands for Linux resource | The Retail Detail

  21. Pingback: Obedience Training - How to Make Your Dog Obey You | Puppydogbyte.com

  22. Pingback: SCAN TO SMB ON MAC OS X LION | COPIERNETEYE

  23. Pingback: CONNECT MAC OS X LION (10.7) TO SMB SHARE | COPIERNETEYE

  24. kaylangan ganito agad di’bah pweding ganun muna???

  25. kay langan ganito agad??
    di’bah pweding ganun muna??

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Next Post » »