Terminal

(Managing Files: move some information from Xterm)
(Using the terminal: move more content from Xterm)
Line 21: Line 21:
'''Understand what a command does before you type it'''
'''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 [http://ss64.com/bash Linux commands] or [http://www.busybox.net/downloads/BusyBox.html Busybox list of Linux commands and options for each one]
+
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 <code>--help</code> to get a list of options, i.e. <code>ls --help</code>, or look up manual pages if installed, with:
-
Some example commands, all here are non-destructive.
+
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 [http://ss64.com/bash Linux commands] or [http://www.busybox.net/downloads/BusyBox.html Busybox list of Linux commands and options for each one]
 +
 
 +
=== Basics ===
 +
 
 +
Some example commands, all here are non-destructive. Press enter after each command to execute it.
The terminal should open with a  
The terminal should open with a  
Line 31: Line 37:
To exit the terminal at any time type, exit and enter, so
To exit the terminal at any time type, exit and enter, so
-
  ~ $ exit [enter]
+
  ~ $ exit
 +
 
 +
<code>echo</code> outputs/prints text to <code>stdout</code>:
 +
 
 +
~ $ echo "hello world"
 +
 
 +
hello world
 +
 
 +
Echo can also be used with variables, such as <code>USER</code>, which contains the current user’s username. Variables are prefixed with a '<code>$</code>':
 +
 
 +
~ $ echo $USER
 +
 
 +
user
 +
 
 +
Use <code>uname</code> to list the kernel version, and use the <code>-a</code> argument to output all known information:
 +
 
 +
~ $ uname -a
 +
 
 +
2.6.21-omap1
 +
 
 +
<code>cat</code> spits out an entire text file to terminal. <code>resolv.conf</code> (remember *NIX is case-sensitive) is where DNS servers are stored. The <code>#</code> hash/pound character is a [[:wikipedia:Comment (computer programming)|comment]], which means that the rest of the line is ignored.
 +
 
 +
~ $ cat /etc/resolv.conf
 +
 
 +
#nameserver 127.0.0.1
 +
 +
nameserver 192.168.1.1
 +
 +
#nameserver 4.2.2.2
 +
 
 +
Basic example of a variable:
 +
 
 +
~ $ foobar='example'; echo $foobar'''
 +
 
 +
example
 +
 
 +
Example of directing output to a file. Files stored in <code>/dev/shm</code> are stored directly in RAM and thus are deleted on shutdown:
 +
 
 +
~ $ uname -s > /dev/shm/os; cat /dev/shm/os
=== Managing Files ===
=== Managing Files ===
Line 37: Line 81:
To list files in a directory type ls and hit enter, so
To list files in a directory type ls and hit enter, so
-
  ~ $ ls [enter]
+
  ~ $ ls
-
To list files in a directory with permissions, owners, time, the use the long format with <code>ls</code>, which is <code>ls -l</code> enter
+
To list files in a directory with permissions, owners, time, the use the long format with <code>ls</code>, which is <code>ls -l</code>:
-
  ~ $ ls -l [enter]
+
  ~ $ ls -l
To list hidden files and directories
To list hidden files and directories
-
  ~ $ ls -la [enter]
+
  ~ $ ls -la
To list all mp3 files on memory card mmc1
To list all mp3 files on memory card mmc1
-
  ~ $ ls -l /media/mmc1/*.mp3 [enter]
+
  ~ $ ls -l /media/mmc1/*.mp3
To copy files use cp, so  
To copy files use cp, so  
-
  ~ $ cp file file2 [enter]
+
  ~ $ cp file file2
This would make a copy of file and call it file2. Note that "file2" can be a whole other path (like <code>/home/user/MyDocs/afolder/file2</code>).  If file2 already exists it will be overwritten.
This would make a copy of file and call it file2. Note that "file2" can be a whole other path (like <code>/home/user/MyDocs/afolder/file2</code>).  If file2 already exists it will be overwritten.
Line 59: Line 103:
To change directory use <code>cd</code>, so
To change directory use <code>cd</code>, so
-
  ~ $ cd MyDocs [enter]
+
  ~ $ cd MyDocs
To go back a level on a directory
To go back a level on a directory
-
  ~/MyDocs $ cd .. [enter]
+
  ~/MyDocs $ cd ..
To go back two levels on a directory
To go back two levels on a directory
-
  ~ $ cd ../.. [enter]
+
  ~ $ cd ../..
To go back three... I think you get the idea
To go back three... I think you get the idea
Line 73: Line 117:
By the way, the bit before the $, tells you the directory you are in. The symbol <code>~</code> means your home directory, however to find out which directory you are in
By the way, the bit before the $, tells you the directory you are in. The symbol <code>~</code> means your home directory, however to find out which directory you are in
-
  ~ $ pwd [enter]
+
  ~ $ pwd
-
pwd stands for present working directory
+
<code>pwd</code> stands for present working directory
To create a directory, use <code>mkdir</code>
To create a directory, use <code>mkdir</code>
-
  mkdir mydirectory [enter]
+
  mkdir mydirectory
To move files use <code>mv</code>
To move files use <code>mv</code>
-
  ~ $ mv file2 mydirectory/file2 [enter]
+
  ~ $ mv file2 mydirectory/file2
moving file2 to mydirectory directory
moving file2 to mydirectory directory
Line 89: Line 133:
You can also use <code>mv</code> to rename a file
You can also use <code>mv</code> to rename a file
-
  ~ $ mv file newname [enter]
+
  ~ $ 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:
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 . [enter]
+
  ~ $ mv mydirectory/file .
The dot at the end of the command means the current directory.
The dot at the end of the command means the current directory.
Line 99: Line 143:
To delete a file, use the <code>rm</code> command:
To delete a file, use the <code>rm</code> command:
-
  ~ $ rm file [enter]
+
  ~ $ rm file
To delete a directory and all of its subdirectories and files, use the recursive option with <code>rm</code>:
To delete a directory and all of its subdirectories and files, use the recursive option with <code>rm</code>:
-
  ~ $ rm -r directory [enter]
+
  ~ $ rm -r directory
=== Directory structure ===
=== Directory structure ===
Line 111: Line 155:
=== Finding files ===
=== Finding files ===
-
  find /media -name "*.jpg" [enter]
+
  find /media -name "*.jpg"
Finds all files ending with a .jpg, i.e. photo files in <code>/media</code> directory, memory card. The <code>*</code> is a wildcard.
Finds all files ending with a .jpg, i.e. photo files in <code>/media</code> directory, memory card. The <code>*</code> is a wildcard.
-
 
=== Wildcards ===
=== Wildcards ===
Line 126: Line 169:
So
So
-
  find . -name "birthday?[bg]*" [enter]
+
  find . -name "birthday?[bg]*"
Will find any files starting with birthday, followed by any one character,  then either a lowercase b or g, with <code>*</code> meaning any other characters if any.  
Will find any files starting with birthday, followed by any one character,  then either a lowercase b or g, with <code>*</code> meaning any other characters if any.  
-
If you want to stop a search, or any command for that matter use
+
If you want to stop a search, or any command for that matter press and hold Ctrl and then press c:
-
  <Ctrl> c [enter]
+
  <Ctrl> c
-
To find a word in a file you use grep. So if you want to find the word Maemo in file mydocument you type
+
To find a word in a file you use <code>grep</code>. For example, if you want to find the word Maemo in file mydocument you type
-
  grep "Maemo" mydocument [enter]
+
  grep "Maemo" mydocument
=== Opening tar.gz files ===
=== Opening tar.gz files ===
Line 142: Line 185:
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
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 [enter]
+
  mkdir mynewdirectory
-
 
+
  cd mynewdirectory/
-
  cd mynewdirectory/ [enter]
+
tar -xvfz myarchive.tar.gz
   
   
-
tar xvfz myarchive.tar.gz [enter]
+
This will unpack <code>myarchive.tar.gz</code> into <code>mynewdirectory/</code>
-
+
-
This will unpack myarchive in to mynewdirectory/
+
=== Show disk usage in megabytes ===
=== Show disk usage in megabytes ===
-
  ~ $ du -m [enter]
+
  ~ $ du -m
 +
 
 +
=== Piping ===
You can do fancy things and link commands together with what is called a pipe (this symbol: | ). Press Chr on the [[Nokia N810|N810]] or Fn on the [[Nokia N900|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.
You can do fancy things and link commands together with what is called a pipe (this symbol: | ). Press Chr on the [[Nokia N810|N810]] or Fn on the [[Nokia N900|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.
Line 158: Line 201:
So using <code>du</code> with the sort command you can list files and sort in order of megabytes,
So using <code>du</code> with the sort command you can list files and sort in order of megabytes,
-
  ~ $ du -m | sort -r -n | more [enter]
+
  ~ $ du -m | sort -r -n | more
<code>du -m</code> 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.
<code>du -m</code> 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
+
To show disk (memory cards, etc.) partitions and their space
 +
 
 +
~ $ df -h
 +
 
 +
Show Linux Kernel messages:
 +
 
 +
~ $ dmesg | more
-
~ $ df -h [enter]
+
<code>ps</code> lists running processes, you might also be interested in the interactive <code>top</code> command. Piped to <code>awk</code> which in this case says to only show the 5th column (separated by tab characters)
-
Show Linux Kernel messages
+
~ $ ps | awk '{ print $5 }'
-
  ~ $ dmesg | more [enter]
+
  /usr/bin/osso-xterm
 +
/usr/libexec/gnome-vfs-daemon
 +
bash
 +
ps
 +
awk
=== Gain root access ===
=== Gain root access ===

Revision as of 09:29, 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.

Contents

Opening the terminal

N900

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

N810

  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

Basics

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
user

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

~ $ uname -a
2.6.21-omap1

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
#nameserver 127.0.0.1

nameserver 192.168.1.1

#nameserver 4.2.2.2

Basic example of a variable:

~ $ foobar='example'; echo $foobar
example

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.

Wildcards

  • * 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...

So

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/

Show disk usage in megabytes

~ $ du -m

Piping

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 }'
/usr/bin/osso-xterm
/usr/libexec/gnome-vfs-daemon
bash
ps
awk

Gain root access

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

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.