Basic Linux Guide

From Pandora Wiki
Revision as of 04:12, 16 May 2011 by Esn (talk | contribs) (Common directories: a few more important notes...)
Jump to: navigation, search

New to the wonderful world of Linux? No problem! You don't need mad terminal skills to open a web browser, but it can be nice to know what you're doing once in a while.

The structure of the file system

If you're used to the file system of e.g. MS Windows, you will find that a Linux file system is rather different from what you're used to. In this section, we will go through everything you have to know in order to feel comfortable with using the Pandora's file system.

Basic philosophy

In Windows, you have multiple file system roots, called "drives", that are labeled with different letters, like "C:" or "D:". In Linux, there aren't multiple root directories, but rather just one root directory, called "/". All other directories are inside of this directory, including other drives.

Common directories

Inside of the root directory ("/") are quite a lot of other directories. Here are the most important ones:

Folder Comment
/media/* External media such as SD cards, flash drives and HDDs show up in here as folders. You can think of these folders as shortcuts to the devices.
/usr/ Here is where you'll find programs and files installed on the Pandora itself. Core applications such as the web browser, media player, and other applications that are available the first time you start your Pandora are stored here inside the "/share" folder. If you decide to install anything via the "ipkg" command (covered later), this is where the files needed by those installations will end up.
/etc System-wide configuration. Should only be touched by power-users.
/home This is where all of the files that are owned by all users are stored. Users do not generally have write-access to anything outside of this directory. This directory is on the NAND and has limited space, as are all directories except for /media
/home/username Here are the personal files of user "username". In this directory, you will find a directory called "Documents", "Pictures", "Desktop" etc. that correspond to that users personal directories. This directory is also called "username"'s home directory, and can be abbreviated with "~/" (if you're currently logged in as username) or "~username/".
/tmp Home of temporary files. On the Pandora, you'll find several files here with .out extensions. If a program crashes, the developers may ask you to find its .out file and copy+paste the content, so they can see what went wrong.
/boot This is the directory where the Linux kernel is stored, and other files that are needed at boot time can be accessed. Do not touch this directory (You can't even do it if you wanted to)!
/bin
/lib
System binaries and libraries are stored here. Most of the terminal commands mentioned below can be found inside of "/bin". You should generally never have to touch this directory, either.
/mnt/utmp Often, programs will ask you to save to their folders in this directory. Anything "saved" here is actually saved at the analogous location in your "/media/pandora/appdata" directory.

Don't worry if this doesn't make any sense; It was thought up by bearded engineers back in the seventies. They liked the idea that everything would be in a predictable place, but this is no longer completely the case.

Basic Terminal Commands

Note: Linux is case sensitive. This applies to filenames and directories too. "/home/me/stuff" is a different folder than "/home/me/STUFF", you can actually have both. You can have "/home/me/Stuff" too if you like, and all three are separately recognised directories.

If you are in Terminal you can send commands to your shell (here it is BASH)

Navigation

In the terminal, you are always in some folder. Think of it like being in a file manager: you can see the contents of the directory you're in, you can do things with those files, or you may decide to go to some other folder and continue your work there.

There are a few essential commands that are used to navigate around your system via the terminal:

Command Comment
pwd Print the current working directory (will print e.g. "/home/user")
ls List directory contents (similar to "Dir" in Dos, and the Linux command "dir" will actually emulate the DOS command if you want to!)
cd <directory name> Change to a different directory, eg. "cd music" or "cd /home/me/music"
cd .. Go up one directory level (similar to "cd.." in Dos)
cd Go back to your home directory (similar to My Documents in Windows)
cd - Go back to the previous directory you were in (handy if you forget)

Controlling Running Apps

Command Comment
top View running processes (like the Task Manager in Windows) press "q" to quit
killall [program name] Stops running process (use with care)

File Manipulation

Command Comment
rm <filename> Remove a file, eg. "rm somefile.txt" or "rm /home/me/randomfiles/somefile.txt"
rmdir <directory> Will remove a directory, but **only** if it is empty!
rm -r <directory> Will remove a directory and its contents ("-r" means recursive)
rm -rf <directory> Will remove a directory, all of its contents, without asking you first. Use with extreme care. ("-f" means force)
mv <original filename> <new filename> Moves a file to a new place, also used for renaming, eg. "mv somefile.txt somefile_backup.txt" will rename it, but "mv somefile.txt /home/me/backup/somefile.txt" will move it. This will also work for directories.
cp <file to copy> <new filename> Copy a file, eg. "cp twoweeks.txt twomonths.txt" copies into current directory, while "cp twomonths.txt /home/me/ihaveadream/twoweeks.txt" copies to another directory.
cp -r <directory to copy> <new directory name> Copy a directory and all of its contents to another location.
touch <new file name> Makes a new (empty) file
mkdir <new directory name> Makes a directory

Misc.

Command Comment
cat <filename> Prints the contents of a file, eg. "cat hellolo.txt"
clear Clears screen, terminal input begins at the top again
date Your friend, the terminal will tell you the date
cal [month] [year] Makes a pretty calendar, eg. "cal 12 2009" or "cal * 2010" or "cal 1 2010 > fingers_crossed.txt" sends output to file
history Gives a list of the recent commands you have run. Running !number (e.g. !15) will rerun that numbered command in the history list
vi <filename> Opens the file for editing in vi [1]

Bash tips

History Search: Press CTRL-R. As you type, BASH will try and find the command in your recent history that most closely matches what you are typing. To get back to the prompt, press CTRL-C.

Autocompletion: Press TAB. The terminal (also called the shell) will attempt to intelligently figure out what you're trying to type. It needs something to work with however, so try pressing TAB half way through a command or location.

eg. "cd /home/me/pandora_suc" *TAB* will complete it as "cd /home/me/pandora_success" or with a filename "cat /home/me/letters/i_want_the_pandora_to_fa" *TAB* will turn into "cat /home/me/letters/i_want_the_pandora_to_fall_into_my_hands"

Directory aliases: There are some special directory names you can use to refer to a directory that would be too long to type otherwise, or that you simply don't know the name of.

  • "~" - Refers to your home directory e.g. "/home/user".
  • "~seconduser" - Refers to someone else's home directory.
  • "." - Refers to the current directory, or the "same directory" in a path. What this means, is that if you type "cd .", nothing will happen since you already are in ".", and if you type "cd somedir/././././././.", you will simply go to "somedir", since the "."-directories that come after it are the "same directory" as the one before them.
  • ".." - Refers to the directory in which the current directory is, or the "parent directory" in a path. If you type "cd .." you will come to the parent directory of your current directory, and if you type "cd s1/s2/s3/../../..", nothing will happen, since the path you specified cancels itself out.

See also