Terminal

(added another URL)
Line 161: Line 161:
'''Want more?'''
'''Want more?'''
-
There are infinite possibilities with the terminal, I'd recommend using google if you want to find out more or look at [http://www.busybox.net/downloads/BusyBox.html Busybox commands]. 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.
+
There are infinite possibilities with the terminal, I'd recommend using google if you want to find out more or look at [http://www.busybox.net/downloads/BusyBox.html Busybox commands] or [http://linuxcommand.org/learning_the_shell.php 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.
[[Category:Users]]
[[Category:Users]]

Revision as of 19:12, 6 December 2009

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.

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.

The terminal should open with a

~ $

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

~ $ exit [enter]

Managing Files

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

~ $ ls [enter]

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

~ $ ls -l [enter]

To list hidden files and directories

~ $ ls -la [enter]

To list all mp3 files on memory card mmc1

~ $ ls -l /media/mmc1/*.mp3 [enter]

To copy files use cp, so

~ $ cp file file2 [enter]

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 [enter]

To go back a level on a directory

~/MyDocs $ cd .. [enter]

To go back two levels on a directory

~ $ cd ../.. [enter]

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

BTW, 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 [enter]

pwd stands for present working directory


To create a directory, use mkdir

mkdir mydirectory [enter]


To move files use mv

~ $ mv file2 mydirectory/file2 [enter]

moving file2 to mydirectory directory


You can also use mv to rename a file

~ $ mv file newname [enter]


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

~ $ mv mydirectory/file . [enter]


The dot at the end of the command means the current 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.


Finding files

find /media -name "*.jpg" [enter]

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]*" [enter]

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 use

<Ctrl> c [enter]


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

grep "Maemo" mydocument [enter]


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 [enter]
cd mynewdirectory/ [enter]

tar xvfz myarchive.tar.gz [enter]

This will unpack myarchive in to mynewdirectory/


Show disk usage in megabytes

~ $ du -m [enter]

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 [enter]

du -m list 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 [enter]


Show Linux Kernel messages

~ $ dmesg | more [enter]

Want more?

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.