Basic Commands

The Terminal Activity is the most powerful method of interacting with Sugar.  However if you are not used to it then knowing some basics can help. The best strategy is to start using some simple commands. Don't attempt to do all your work from the command line straight away. Learn a few commands, use them and add to your understanding of what they can do over time.

Below are some basic commands that you could try starting with. Don't try and learn all of these at once. Just choose a few and practice them.

  • ls
  • cd
  • mkdir
  • mv
  • rm
  • ping
  • cp
  • pwd
  • more
  • date
  • top
  • cat

So, lets have a look at each. Feel free to experiment with these commands. Be a little careful as it is possible to do some damage to your computer if you are too casual. If there is a possibility one of the commands can accidentally create havoc then I will make a note to warn you.

ls

the ls command is the 'list' command. You can use this to list the contents of any directory you are in. Try typing this command in a terminal window and see what you get. Now, one feature of  commands is that you can add various parameters to them. This is quite a simple thing to do, and refines the way you use the command. Usually these parameters are added to the command by typing a ' - ' directly after the command and then the parameter names or abbreviations. For example if I type the following:
ls -l

Then I am passing the l parameter to the ls command. The l parameter is short for 'long list'. This format gives more information than just typing the ls command by itself... Try the two out and compare the difference.

You might well ask 'how do I know what the parameters are for each command?' This information can be found by using the help command for 'ls' :

ls --help

For the ls command I suggest you get familiar with the formats using ls by itself, as well as ls -al, and ls -l

cd

cd is the most common command used to navigate the file-system on your computer. cd stands for Change Directory. Try it out by typing ls to get a list of all the files and folders in the directory you are currently in. Now try typing cd followed by the name of one of the files in the list, for example if there was a file called 'me.txt' I could type:

cd me.txt
This will give an error! Why? Because you can't change to a directory if it is a file. It's good to try this so that you understand that you can't do any damage by making a mistake with cd. To change to a directory you type cd followed by the name of a directory you want to navigate to. If there was a directory called src we would type:
cd src

If that was successful then the terminal won't throw up an error. Try it with a real directory on your computer. If you fail it will be because either you don't have permissions to enter the directory, you misspelled the directory name, or the directory simply doesn't exist.

mkdir

This is the command you used to create a directory and is short for Make Directory. To use this, simply type the name of the directory you want to create after the mkdir command as so:
mkdir bleep
The above command will create a directory in the current directory called bleep. If a directory with this name already existed,  we will get an error but fortunately the computer won't overwrite the existing directory.

pwd

If you get lost and don't know where you are in the file system you can always type pwd and it will tell you where you are. p-w-d means 'present-working-directory' - this command gives you the location or absolute path of where you are. For example, if I am in my adam home directory, the output of the pwd command will be:
/home/adam
Experiment with changing directories with cd then typing pwd to see where you are.

mv

This command is short for Move. It is as it sounds in that mv allows you to move files around on the computer. To use mv you must first type the command, followed by the file you want to move and then the place where you want to move the file to. For example, if I wanted to move a file "me.txt" from my current directory to the "/usr/bin" directory I would type the following :

mv me.txt /usr/bin
Note: I don't have to type the filename in the path name where I want to move the file unless I also wish to change the name of the file. If for example while I was moving 'me.txt' I wanted to change the filename to "you.txt" I would type:

mv me.txt /usr/bin/you.txt
If I just wanted to rename the file and not move it I could use mv by typing this:
mv me.txt you.txt
Note that when you use mv you are moving the file not copying it. Be a bit careful because you can overwrite files accidentally, if for example I moved one file to an existing file with the same name, then target file wll be overwritten.

rm

rm a command you should be very careful about using. rm is short for Remove, and is the command you use to delete a file or directory. To use this command type rm followed by the name of the file you wish to destroy for good. To remove a directory you can use the same command with the parameter -R like so:
rm -R directoryname

Where directoryname is the name of the directory you wish to delete. You can also use rmdir for this. Be EXTREMELY careful when using these commands, if used unwisely it could be the end of your operating system.

cp

This is short for copy. Use it like mv , the only difference is that it leaves the original file where it was while also creating a copy.

ping

Not usually included in the top 10 commands you need to know but its handy if you need to know if you are online. ping sends a request to any computer on the net, if that computer gets the request it will respond. Type ping followed by a URL that you know, for example it might be a good idea to try the following:

ping www.cnn.com

If that computer gets the request you will get some information coming back through the terminal... this will keep scrolling so to stop it type ctrl and c.

If you get no response from ping then you are probably offline. However, some machines online don't answer ping requests for security and other reasons, so make sure you really know that the machine you are pinging does reply to these requests. Some internet connections won't allow ping.

more

more is used if you want to control the overly verbose output of any command to the terminal. If for example, I am in a directory which contains 1000 files and I type ls the output of the command won't fit nicely into my little terminal window so it will go scrolling past faster than is useful. To slow it down so I can read the output try this :
ls | more

If I used this in my 1000 file directory I get one page at a time of output and pressing the space-bar shows the next page. Pressing q quits more. Ok, so you might be wondering what the funny straight line is in the above command... well, this is known as the pipe command.

Pipe allows you to combine commands together to control the kind of output you get, usually its used to refine a command (which is what the command parameters also do). So, when you get really fluent with these commands you can write things that look more like equations but are really efficient ways of using standard commands... pipe will be central to enhancing your efficiency.

date

This command tells you the time and date as it is set on your computer.

cat

Cat displays the contents of files in your terminal window. You must type the name of the file you wish to display after 'cat'. For example if I want to see the contents of the file 'README' I would type :

cat README

If that file is too big to have its contents diaplsyed in the terminal I might use it in combination with the 'more' command like this :

cat | more

top

The 'top' command tells you what operations on your computer are using memory and your cpu. Its really only useful if you wish to see if there is an Activity or command using slowing down your computer. The output of 'top' will continue running until you press 'q'.