(Using the terminal: move shell function information from Xterm)
(Opening tar.gz files: move starting application section from Xterm)
Line 190: Line 190:
This will unpack <code>myarchive.tar.gz</code> into <code>mynewdirectory/</code>
This will unpack <code>myarchive.tar.gz</code> into <code>mynewdirectory/</code>
=== Starting a GUI application ===
Everything is run from a terminal in *NIX. A GUI program is a running instance of a terminal process. Therefore the camera program can be launched. The <code>&</code> (ampersand) tells the shell to run the command as a [[:wikipedia:Job control (Unix)#Unix shell|background job]]:
~ $ /usr/bin/camera &
=== Show disk usage in megabytes ===
=== Show disk usage in megabytes ===

Revision as of 10:04, 28 June 2010

This page is for beginners to Linux that would like to try the terminal. Below are some basic commands you can use in the terminal app to get you started.


Opening the terminal


  1. Navigate to the application menu
  2. Navigate to ‘More...’
  3. Tap ‘X Terminal’


  1. Click the command button on the main page
  2. Select ‘Utilities’
  3. Select ‘X Terminal’

Using the terminal

Before you start, backup your data So long as your data is backed up, then you can start to try out the terminal without any fears of losing any data. This page does not cover gaining 'root' on your device so you should come to no harm. If you are gaining root, then it would best to not only have a backup before you start tinkering, but also to familiarise yourself with how to reflash your device in extreme cases where you need to get back to where you started.

Understand what a command does before you type it Fundamentally you should understand what a command does before typing it in and pressing enter. If you have a linux desktop distribution, like Ubuntu, you can normally type the command with the parameter --help to get a list of options, i.e. ls --help, or look up manual pages if installed, with:

man ls [enter]

to find out what the commands are and their options. However you can't do this on the tablets though as the tablets use cut down embedded commands, (BusyBox - I think?), so look at Linux commands or Busybox list of Linux commands and options for each one


Some example commands, all here are non-destructive. Press enter after each command to execute it.

The terminal should open with a

~ $

To exit the terminal at any time type, exit and enter, so

~ $ exit

echo outputs/prints text to stdout:

~ $ echo "hello world"
hello world

Echo can also be used with variables, such as USER, which contains the current user’s username. Variables are prefixed with a '$':

~ $ echo $USER

Use uname to list the kernel version, and use the -a argument to output all known information:

~ $ uname -a

cat spits out an entire text file to terminal. resolv.conf (remember *NIX is case-sensitive) is where DNS servers are stored. The # hash/pound character is a comment, which means that the rest of the line is ignored.

~ $ cat /etc/resolv.conf



Basic example of a variable:

~ $ foobar='example'; echo $foobar

Example of directing output to a file. Files stored in /dev/shm are stored directly in RAM and thus are deleted on shutdown:

~ $ uname -s > /dev/shm/os; cat /dev/shm/os

Managing Files

To list files in a directory type ls and hit enter, so

~ $ ls

To list files in a directory with permissions, owners, time, the use the long format with ls, which is ls -l:

~ $ ls -l

To list hidden files and directories

~ $ ls -la

To list all mp3 files on memory card mmc1

~ $ ls -l /media/mmc1/*.mp3

To copy files use cp, so

~ $ cp file file2

This would make a copy of file and call it file2. Note that "file2" can be a whole other path (like /home/user/MyDocs/afolder/file2). If file2 already exists it will be overwritten.

To change directory use cd, so

~ $ cd MyDocs

To go back a level on a directory

~/MyDocs $ cd ..

To go back two levels on a directory

~ $ cd ../..

To go back three... I think you get the idea

By the way, the bit before the $, tells you the directory you are in. The symbol ~ means your home directory, however to find out which directory you are in

~ $ pwd

pwd stands for present working directory

To create a directory, use mkdir

mkdir mydirectory

To move files use mv

~ $ mv file2 mydirectory/file2

moving file2 to mydirectory directory

You can also use mv to rename a file

~ $ mv file newname

But what happens if I want to copy stuff into the directory I am already in do I have to type out the whole directory tree again. Well you can but it is much simpler to do the following:

~ $ mv mydirectory/file .

The dot at the end of the command means the current directory.

To delete a file, use the rm command:

~ $ rm file

To delete a directory and all of its subdirectories and files, use the recursive option with rm:

~ $ rm -r directory

Directory structure

One thing to note is the directory structure on a Maemo device. When you open the terminal on the device you are in the directory /home/user Equivalent to MyDocuments in Windows. The top level directory like C: drive on Windows is a / known as a root directory. Try and stay in the /home/user directory at first, or look at your memory cards which is in the directory /media. Further information about filesystem can be found at an article named N900 filesystem.

Finding files

find /media -name "*.jpg"

Finds all files ending with a .jpg, i.e. photo files in /media directory, memory card. The * is a wildcard.


  • * means any number (zero or more) of characters
  • ? means exactly one character
  • [a-d] means exactly one character from the range 'a' to 'd' (ie 'a', 'b', 'c' or 'd')
  • [xyz] means exactly one character from the set 'x', 'y' and 'z'
  • [a-ckp1-3] means one of 'a', 'b', 'c', 'k', 'p', '1', '2' or '3' and so on...


find . -name "birthday?[bg]*"

Will find any files starting with birthday, followed by any one character, then either a lowercase b or g, with * meaning any other characters if any.

If you want to stop a search, or any command for that matter press and hold Ctrl and then press c:

<Ctrl> c

To find a word in a file you use grep. For example, if you want to find the word Maemo in file mydocument you type

grep "Maemo" mydocument

Opening tar.gz files

To open a tar.gz you need to unpack it, it is an archive file, like zip files. I recommend creating a new directory before unpacking, so

mkdir mynewdirectory
cd mynewdirectory/
tar -xvfz myarchive.tar.gz

This will unpack myarchive.tar.gz into mynewdirectory/

Starting a GUI application

Everything is run from a terminal in *NIX. A GUI program is a running instance of a terminal process. Therefore the camera program can be launched. The & (ampersand) tells the shell to run the command as a background job:

~ $ /usr/bin/camera &

Show disk usage in megabytes

~ $ du -m


You can do fancy things and link commands together with what is called a pipe (this symbol: | ). Press Chr on the N810 or Fn on the N900 to find the pipe | symbol. You can program the terminal to show the pipe symbol, by going to tools->settings and entering bar as a toolbar shortcut. What the pipe does is that it takes one program's output and gives it to another as input.

So using du with the sort command you can list files and sort in order of megabytes,

~ $ du -m | sort -r -n | more

du -m lists files in megabytes then pipes it to sort to sort it in order of megabytes, largest first, then the more command shows you one page of the screen at a time, pressing enter to show more pages.

To show disk (memory cards, etc.) partitions and their space

~ $ df -h

Show Linux Kernel messages:

~ $ dmesg | more

ps lists running processes, you might also be interested in the interactive top command. Piped to awk which in this case says to only show the 5th column (separated by tab characters)

~ $ ps | awk '{ print $5 }'

Writing a shell function

A simple shell function that uses a variable and if/then/else logic:

~ $ minute() { foo=`date +%S`; echo $foo; if [ "$foo" -lt "30" ]; then echo "under half"; else echo "over half"; fi; }
~ $ minute
under half

Using the shell function we just wrote, outputs the current time in seconds (only the seconds part) and whether it is closer to the last minute or next minute. Shell functions are only available for the terminal session. Save in .bashrc or .profile to be persistent.

Gain root access

You might need root access in order to make some advanced changes.

Debian package management

Search repositories for packages by keyword

~ $ apt-cache search nano
nano-tiny - free Pico clone
traceroute-nanog - Determine route of packets
nano - nano editor

Install the nano package (an easy to use CLI text editor).

~ $ apt-get install nano

Instead of using the repos, use wget to download a .deb package from a website:

~ $ wget http://nitstuff.appspot.com/dists/chinook/user/binary-armel/nano_2.0.6_armel.deb

Install a locally-stored Debian package:

~ $ dpkg -i nano_2.0.6_armel.deb

Further reading

There are infinite possibilities with the terminal, I'd recommend using google if you want to find out more or look at Busybox commands or learning the shell. Again to reiterate please make sure you backup your data before tinkering and when you want to try a new command, make sure you understand what it does first.