FLOSS Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Terminal

Terminal: BasicCommands

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 might find useful. Most people find that it is best not to try to learn all of them at once. You might choose a few to learn about and practice, and come back for more after you are comfortable with the first few.

  • ls Directory listing
  • cd Change directory
  • mkdir Make directory
  • rmdir Remove directory (Dangerous)
  • pwd Print working directory, that is, the currently active directory location.
  • mv Move files
  • rm Remove (erase) files (Dangerous)
  • cp Copy files
  • ping Check whether a site is reachable
  • less Display a file in a scrollable window; similar to more
  • date Display or set date and time
  • cat Join or copy files
  • top Display information on running programs

So, let's 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 a note warns you about that.

ls

The ls command is the List command. You can use this to list the contents of the directory you are in, or you can give it the path to any other directory. Try typing this command by itself 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 you type the following:
ls -l

Then you are 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" parameter for ls:

ls --help

For the ls command you should 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" you could type:

cd me.txt
This gives 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" you 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 is because either you don't have permissions to enter the directory, you misspelled the directory name, or the directory simply doesn't exist.

If you have navigated to some distant directory, you can get back to your home directory with the command

 cd

without any path.

mkdir

This is the command you used to create a directory.  It is short for Make Directory. To use this, simply type the name of the directory you want to create after the mkdir command:
mkdir bleep
The above command creates a directory called "bleep" in the current directory. If a directory with this name already exists, you get an error but fortunately the computer doesn'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 tells you where you are. pwd means Print Working Directory - this command gives you the location or absolute path of where you are. For example, if you are in your olpc home directory, the output of the pwd command is:
/home/olpc
Experiment with changing directories with cd then typing pwd to see where you are.

mv

This command is short for Move. It 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 you wanted to move a file "me.txt" from your current directory to the "bleep" subdirectory in the current directory you would type the following:

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

mv me.txt bleep/you.txt
If you just wanted to rename the file and not move it you 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 there is already a file named "you.txt" in the example above, is it overwritten with the data from "me.txt".

rm

rm is 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

In this example "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 they could cripple your operating system, possibly requiring reinstallation.

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 it's handy if you need to know if you are online. ping sends a request to any computer on the network. If that computer gets the request it responds. Type ping followed by a URL that you know, for example it might be a good idea to try the following:

ping cnn.com

If that computer gets the request you get some information coming back through the terminal... this keeps scrolling so to stop it type ctrl + 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.

less

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

If you used this in your 1000 file directory you get one page at a time of output and pressing the spacebar shows the next page. You can move to the previous page display with up arrow. What do you think down arrow does? Pressing q quits less. 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 it's 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. Read the help to find out how to set the date and time.

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 you want to see the contents of the file "README" you would type:

cat README

If that file is too big to have its contents displayed in the terminal you might use it in combination with the less command like this:

cat README | less

 The cat utility was originally created for combining text files, a function called concatenation by some, and catenation by those who detest unnecessary syllables.

top

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


There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.