Fundamental Terminal Commands for the Linux/Unix Dummy

  • Posted on: 24 February 2013
  • By: jimusik

I've been dabbling with the terminal for about 10 years now ever since I built my first linux box.  I remember watching technicians use the terminal to do all sorts of cool things that I could never understand.  I still catch myself having to review some of the basic elements so I thought I'd create a very simple blog post listing key commands to get you going.  

Terminal - 

What is the terminal you might ask?  Think of it as the fundimental text based interaction with a computer.  It allows you to navigate the system, launch services and programs and create, move, copy and delete fundimental files.  

How Does It Work - 

Whether your sitting in front of a server, or working on your Mac or Linux Distribution, the terminal works the same. It gives you a prompt where you type instructions that the system then attempts to execute. If you are already inside a graphic user interface (GUI) you can easily launch a separate terminal window. In OSX just spotlight for "terminal" and launch the application. In Ubuntu, Fedora or other favorite Linux distro, similarly just search for terminal or find it in the applications menu. 

The Prompt -

The leading text before the location of the cursor when you get into a terminal will vary depending on the operation system and the type of shell being used. This gets very complicated and can vary the commands you must enter. I'm assuming that you are probably going to be using a terminal emulator that gives you a Bash prompt since its the most popular. 

Some prompts give you lots of information including what computer you are connected to and your username. For example in the image at the start of this post you can see that I'm connected to James's iMac 21.5 and my username is jimusik of course. 

Jim's Most Used Commands -

  1. ls - this will list the contents of the directory you are in
  2. pwd - this will give you the location of the directory you are in
  3. cd - takes you to a directory you list after "cd"
  4. mkdir - creates a directory that you name after "mkdir"
  5. mv - Moves a file or renames it
  6. cp - Copy a file
  7. rm - delete a file
  8. ifconfig - this is a tool to give you information about the network connections
  9. tar - this is a standard compression and extraction for multiple files
  10. nano - this is a text based editor so you can edit or create files
  11. vi - this is another text based editor so you can edit or create files
  12. chmod - this will change permissions on a file
  13. chown - this will change the ownership of a file
  14. ssh - this allows you to log into another computer that has SSH enabled, giving you terminal access through the computer you are on
  15. mysqldump - this is a great way to backup a MySQL database from the terminal
  16. su - Switch to Root...must have root password

Navigation -

  • pwd - As noted above tells you where you are
  • ls - lists the contents of your location
  • "cd .." - will take you one segment backwards
    • For Example:
    • In this bash prompt on OSX you can see the name of my system: Jamess-iMac-213: and the name before the $ is my current username jimusik$
    • pwd shows us we are in /Users/jimusik which is my home folder
    • ls shows us what you would expect to be in my home folder
    • cd .. now moves us back one segment of the tree into the Users folder
  • the dots ".." move you backward but to move foward, you need the name of the folder.  If in the above example I typed cd jimusik I would move back into my home folder.
  • The key with cd is that you either list a folder within your current location or you give the full location: i.e. cd /Users/jimusik would take me to my home folder no matter where pwd told me I was