Simon The Pi Man bookstore
Mmmm Raspberry Pi
Simon the Pi Man
To Infinity (probably) and beyond
(A beginners Resource for the Raspberry Pi computer using the Debian distro)
since June 2012

If you are looking for info on the Raspberry Pi computer stay on this site
If you are looking for a good cafe in Rye in East Sussex try "Simon the Pie man" near the church.

Beginners Guide to Unix - part 1 -  really really basic stuff logging in and files

If you are interested in programming the Raspberry Pi you probably ought to have an understanding of the Unix operating system.

Ok so to start with we will assume you already have a unix user account(username) and password. Please note that the coloured items are what you will normally see on the screen, the red coloured items are those you enter, and the items in green are keys on the keyboard.

In the example below we will be using a user=pi password=raspberry and the server is your Raspberry Pi(raspberry) so the starting point is usually a prompt

your response is to type in your username(pi) and press [Return or Enter]
the prompt will change to the following
pi@raspberry's password:
your response is to type in your password(raspberry) and press [Return or Enter]
if you have managed to put in the correct username and password the prompt will now show.
In actual fact what this means is that you have logged in (as pi) to a server called() and you are now in your home directory() this is usually known as your shell - ok so now what can you do ?

On a PC to list files in a command prompt you would type "dir" - on a unix box the equivalent command is "ls"(list files) - so to start we will list all the files in the root folder, in our examples a space is usually important - so type
pi@raspberrypi:~$  ls /[Return or Enter]
this instructs the operating system to list all the files in the root directory(a bit like c:\ on windows) note the unix directory slash is the opposite to the windows one.
The screen should display something like the display below

backup etc            lib        mnt     sbin       tmp     vmlinuz.old
bin    home           lib64      opt     selinux    usr
boot   initrd.img     lost+found proc    srv        var
dev    initrd.img.old media      root    sys        vmlinuz

This is a horizontal listing of all the files and directories in the root of the filesystem - please note unix files do not have to have file extensions as windows does so a program will look the same as a directory using this command. As you can see the unix display shows the equivalent of a windows "dir /w". As with pretty much all unix commands the ls command takes flags - these are options for the program which make it behave differently. So we will now add the -l flag to the basic command which will provide (-long listing) with more details.
pi@raspberrypi:~$  ls -l /[Return or Enter]
This will list the files like the windows "dir" command but shows more details.

lrwxrwxrwx 1   root
root 22    2011-02-16 15:39 backup -> /home/pi/dbbackup
drwxr-xr-x 2   root root 4096  2011-12-22 01:00 bin
drwxr-xr-x 3   root root 4096  2011-12-22 01:00 boot
drwxr-xr-x 13  root root 3260  2011-11-30 17:32 dev
drwxr-xr-x 105 root root 4096  2012-01-05 01:00 etc
drwxr-xr-x 3   root root 4096  2011-01-29 13:07 home
lrwxrwxrwx 1   root root 32    2011-12-22 01:00 initrd.img -> boot/initrd.img-2.6.32-37-server
lrwxrwxrwx 1   root root 32    2011-12-08 01:01 initrd.img.old -> boot/initrd.img-2.6.32-36-server
drwxr-xr-x 12  root root 12288 2011-12-22 01:00 lib
lrwxrwxrwx 1   root root 4     2011-01-29 12:55 lib64 -> /lib
drwx------ 2   root root 16384 2010-05-06 09:07 lost+found
drwxr-xr-x 2   root root 4096  2010-05-05 16:37 media
drwxr-xr-x 2   root root 4096  2010-04-23 11:23 mnt
drwxr-xr-x 2   root root 4096  2010-05-05 16:37 opt
dr-xr-xr-x 89  root root 0     2011-11-30 17:32 proc
drwx------ 10  root root 20480 2012-01-07 09:59 root
drwxr-xr-x 2   root root 4096  2011-12-01 01:00 sbin
drwxr-xr-x 2   root root 4096  2009-12-05 22:25 selinux
drwxr-xr-x 2   root root 4096  2010-05-05 16:37 srv
drwxr-xr-x 13  root root 0     2011-11-30 17:32 sys
drwxrwxrwt 4   root root 16384 2012-01-07 12:15 tmp
drwxr-xr-x 10  root root 4096  2010-05-05 16:37 usr
drwxr-xr-x 14  root root 4096  2011-03-31 11:56 var
lrwxrwxrwx 1   root root 29    2011-12-22 01:00 vmlinuz -> boot/vmlinuz-2.6.32-37-server
lrwxrwxrwx 1   root root 29    2011-12-08 01:01 vmlinuz.old -> boot/vmlinuz-2.6.32-36-server

OK now the above shows information in columns so lets look at in more detail

Now to try and decipher the above listing - so we need to look at the listing in columns

The 1st column shows the file permissions this is broken down into 4 pieces the
first character shows whether the file is a directory(d) or a file(-) or a symbolic link(l) (shortcut in windows) the
2nd,3rd and fourth  are the permissions for the owner(3rd column) the
5th,6th and 7th are the permissions for the group(4th column) and the
8th,9th and 10th are the permissions for the rest of the users on the server.
These sets of 3 characters in order can be r(read) or -(not read)
w (write) or -(not write) and x(executable) or -(not executable)
So as an example from above

drwx------ 10  root root    20480 2012-01-07 09:59 root

This shows that the file called root is a directory which is owned by a user called root(root is the main unix administrator account - god) who is the only user on the system who can access it (This is actually root's home folder).

The 2nd column shows the number of hard links to the file(IGNORE until you become a senior sysadmin - then still ignore)

The 3rd column shows the account that owns the file

The 4th column shows the group that you need to be in to view the file

The 5th column is the filesize in bytes of the file

The 6th column is the file date

The 7th column is the file time

The 8th column is the filename

For further details of the ls command try the Wikipedia ls entry.

Useful things that you may have missed above
  ls for listing files
  ls -l for detailed listing of files
  and file permissions

© 2012->2023

hosted by VillageNetThe Raspberry Pi Foundation is a UK registered charity which exists to promote the study of computer science and related topics, especially at school level, and to put the fun back into learning computing.

Please Note:- any mention of the Raspberry Pi computer on these pages refers to the Raspberry Pi Foundation's product, who also have trademark rights to the term 'Raspberry Pi'.