These are appendixes from the set of posts about setting up and using a Raspberry Pi.
As part of the boot process, your Pi used DHCP to get an IP address from the router. The problem with this is that it is an automated process which is invisible to you unless you log onto your router’s admin page to discover it.Â If only the Pi and your router know what its IP address is, you don’t know where to log on to your Pi.Â The easiest thing to do is change the IP settings on the Pi’s card to a static address, assigned by you.Â That way you know what it is and you know it won’t change.Â You don’t need to let the router know which address you have chosen, as the magic IPixies in the Pi sprinkle the router with their Ipixie Dust to let it know automatically.Â Well, they do for all I know; I’ve no idea how the router finds out, but it does.
You need to pick an address for your Pi – something like 192.168.1.16, but you want to pick one that is not in the range of addresses your router assigns for DHCP requests.Â If the address you choose is within the router’s DHCP address range there is a possibility that you will end up with two devices using the same address.
I’m going to leave it to you to find out what range of addresses your router assigns for DHCP and which ones are suitable for static IP addresses.Â The settings will be available somewhere in your router’s admin pages.Â If fiddling around with your router is out of the question, as a quick bodge you could try finding the IP address of your PC in order to guess a safe non-DHCP range address for your Pi.Â Copy the first 3 sets of numbers of your PC’s address and change the last number to a low one if it’s not low or a high one (maximum 254) if it is low. Â e.g.
- Your PC’s IP is 192.168.1.3 so you pick 192.168.1.250 for your Pi
- Your PC’s IP is 192.168.1.101 so you pick 192.168.1.3 for your Pi
You also need to know the gateway (the router’s IP address on the LAN) and subnet mask (which will probably be 255.255.255.0 – it usually is for home networks).
Appendix B: The Linux Filesystem
You might be used to Windows, with its lame C: drives, D: drives, random assignation of drive letters for plug-in devices, and its pathetic attempts to hide this lameness with My Documents, libraries and other rubbish. Â Linux has one hierarchical tree of files, with everything hanging off the root “/” directory.Â There are no drive letters or special places; everything – programs, user data, log files, temporary files and even devices, is placed on the same directory tree.Â There is a convention as to where different types of file are stored, but let’s have a little wander around and see for ourselves.
Take a look at the command prompt – “naich@raspberrypi ~ $”Â It contains 4 pieces of information; your name and the name of the computer you are on (with an “@” between them), the working directory (~) and the effective user ID ($).Â The “$” changes to a “#” if you are currently root – that’s all that does, but it is important to know if your powers are currently elevated to those of the godly root.Â The working directory is where you currently are in the directory tree, i.e. it is the directory that a command will take action in if you don’t actually specify which directory you want the command to do its stuff in.Â Get it?Â No?Â An example will demonstrate better than that convoluted jumble of words; type ls:
naich@raspberrypi: ~ $ ls naich@raspberrypi: ~ $
See anything?Â Nope.Â ls means list all the files in a directory.Â As you did not specify a directory it lists the files in the working directory, which is “~”, and is currently empty.Â If you tell it to list files in a different directory it will use that one instead of the working one; type ls /:
naich@raspberrypi ~ $ ls / binÂ Â devÂ homeÂ lost+foundÂ mntÂ procÂ runÂ Â selinuxÂ sysÂ usr bootÂ etcÂ libÂ Â mediaÂ Â Â Â Â Â optÂ rootÂ sbinÂ srvÂ Â Â Â Â tmpÂ var naich@raspberrypi ~ $
These are all the files and directories in the root directory “/”.Â Try ls /bin – see what is happening there?Â You are listing all the files in the “/bin” directory.Â This rule also goes for file names.Â If you want to access a file but only write a file name, the command or program will look for that file in the working directory.Â If you include the directory that the file is in, it will look there instead. This goes for any type of file – data, programs or devices.Â Think of your terminal window as psychically sitting on a branch of the directory tree, with everything you type in acting on that branch unless you explicitly specify otherwise.Â The location of that branch is the working directory.
Handy hint – Stuff shooting off the top your screen before you can read it?Â Add “ | more” to the end of your command, (e.g. ls /bin | more) to show one page of output at a time.Â Scroll to the next page with the space bar or press “Q” to quit.Â This works with all commands.Â Don’t try to understand how it works for the moment, just consider it magic.
You can move your terminal around the directory tree with the cd (change directory) command.Â Type cd / to move your working directory to the root directory and type ls again.Â Now your working directory is “/”, it lists the files there when you don’t explicitly say otherwise.Â Try moving to “/bin” and looking at the files there.Â Try moving to other places and have a good old poke around.Â Even with a basic install there are tens of thousands of files on your Pi, so there’s plenty to look at.Â When you are done, move back to your home directory by simply typing cd ~.
As well as looking at the the prompt, another way to find out the working directory is to type pwd:
naich@raspberrypi ~ $ pwd /home/naich naich@raspberrypi ~ $
Eh?Â I thought we were in “~”?Â Well, we are.Â “~” means “my home directory”, which is “/home/your_username”.Â Your home directory is where you put all your stuff and is probably the only directory you can write to.Â If you are going to start drawing Windows analogies, it is a bit like “My Documents”.Â The “~” provides a reference to where all your stuff is, so using “~/README.txt” refers to README.txt which resides in your home directory, rather than any other README.txt which might be in whatever working directory you happen to be in.
It’s all relative though.Â When you specify a directory to move to, look in, or to find a file in, the location you give is relative to where you currently are – i.e. your working directory.Â If you start the directory location off with a “/” or “~/” it doesn’t matter where you are, as the location you are specifying starts at the root or home directory.Â These are fixed absolute points on the tree, but miss off the “/” or “~/” from the start of the directory or file and it becomes relative to your working directory.Â Type cd /usr to move your working directory to the “/usr” directory.Â Do a ls to see the contents.Â See that directory called “bin”?Â It’s not the one you looked at earlier; that was a directory for general system bin(ary) programs, this one is for user-orientated bin(ary) programs.Â Type ls bin.Â The files listed are not the ones you saw earlier in “/bin” but are the ones in “/usr/bin”.Â Because the “/” is missing from the front of “bin”, the “bin” it is showing you is the one relative to your working directory, which is currently “/usr”.Â You can still see the contents of “/bin” (with the slash) by typing ls /bin (with the slash).
If you understand the concept that everything is relative to the working directory unless you say so, you are ready to know about dots – “..”, “.” and dots at the start of files.
A double dot is shorthand for “the parent directory”, i.e. the next directory down on the way to the root.Â If your working directory is “/home/naich” then typing cd .. will change your working directory to “/home”.Â Typing ls .. will list the contents of “/home” and so on.Â You can string double dots together as if they were real directories. cd ../.. will move you two directories towards root – from “/home/naich” to “/”.Â You can do daft things like cd /home/naich/../../home/naich to end up in “/home/naich”, the first “/home/naich” having been rendered pointless by the two sets of double dots moving you back down to “/” again.
A single dot means “this directory”, i.e. the current working directory.Â That might not sounds useful, seeing as how, by it’s very nature, you are already working in the working directory but it does have its uses.Â I’m not going to go in to them here, but you should know about it in case you see it later on.
Finally, there are hidden files.Â These are hidden for convenience not security and are simply files that you don’t care about in the normal scheme of things.Â Files like configuration files or log files.Â You can hide a file or directory by starting its name with a dot, e.g. “.config_file”.Â You have some in your home directory but didn’t see them earlier.Â Go home (cd ~) and have a closer look – type ls -a.
naich@raspberrypi ~ $ ls -a .Â ..Â .bash_historyÂ .bash_logoutÂ .bashrcÂ .profile naich@raspberrypi ~ $
The “-a” bit is an “option” that tells the “ls” command to show hidden files.Â Those hidden files are configuration files that are automatically generated when you create a user and control parameters about the way your terminal works.Â Most of the time you don’t need to see them, so they are hidden.Â You can also see the “.” and “..”, which show up as directories in their own right.
Appendix C: Commands
The basic format for doing things from the command line has 3 sections separated by spaces:
command [-options] [the_thing_you_are_doing_it_to]
An “option” is a way to modify what the command does.Â For example, the default thing for the ls command to do is show the files as a horizontal list, so to list all the files in the root “/” directory:
naich@raspberrypi ~ $ ls / binÂ Â devÂ homeÂ lost+foundÂ mntÂ procÂ runÂ Â selinuxÂ sysÂ usr bootÂ etcÂ libÂ Â mediaÂ Â Â Â Â Â optÂ rootÂ sbinÂ srvÂ Â Â Â Â tmpÂ var naich@raspberrypi / $
but if you add the option “-l” (minus lower case L) to the “ls” command it does this:
naich@raspberrypi ~ $ ls -l / total 84 drwxr-xr-xÂ 2 root rootÂ 4096 AugÂ 6 12:35 bin drwxr-xr-xÂ 2 root root 16384 JanÂ 1Â 1970 boot ... skip a few ... drwxr-xr-x 10 root rootÂ 4096 Jul 15 19:57 usr drwxr-xr-x 11 root rootÂ 4096 Jul 15 20:42 var naich@raspberrypi / $
The “-l” means print it in “long” format, i.e. with more information about what sort of file or directory it is (the “d” in “drwxr-xr-x” means directory, don’t worry about the rest for now), who owns it (“root”), the group they are in (root), the size of the file, date it was last modified and its name.Â You can have more than one option.Â Try ls -lh /.Â The “h” means put the file sizes in human readable units.
naich@raspberrypi ~ $ ls -lh / total 84K drwxr-xr-xÂ 2 root root 4.0K AugÂ 6 12:35 bin drwxr-xr-xÂ 2 root rootÂ 16K JanÂ 1Â 1970 boot ... and so on
You could make it show you hidden files (“-a”), in date order (“-t”), but reversed so the latest is at the bottom (“-r”) by using ls -lhatr /
naich@raspberrypi ~ $ ls -lahtr / total 92K drwxr-xr-xÂ 2 root rootÂ 16K JanÂ 1Â 1970 boot dr-xr-xr-x 68 root rootÂ Â Â 0 JanÂ 1Â 1970 proc drwxr-xr-x 12 root rootÂ Â Â 0 JanÂ 1Â 1970 sys drwxr-xr-xÂ 2 root root 4.0K JunÂ 2 10:25 mnt ... etc. ...
Note that the “Jan 1 1970” comes from boot time, when the Pi doesn’t know what time it is (no real time clock), so it defaults to the earliest time a Unix timestamp can have.
It would be pretty unreasonable to expect everyone to remember what all the options are, so most commands have help built in, accessible by using either “-h” or “–help” (that’s two dashes there, compared to the one for single letter options). Â With ls, “-h” is used for specifying human-readable units, so –help (with the two dashes) is the option to use for help.
naich@raspberrypi ~ $ ls --help Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. Mandatory arguments to long options are mandatory for short options too. Â -a, --allÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â do not ignore entries starting with . ... blah blah etc. ...
Options with two dashes and a word are called “long options”, one dash, one letter ones are “short” options.Â Obviously you can’t lump long options together behind the same dashes, so you have to use them seperately, i.e. ls --all --human-readable /.Â You can also mix them if you want, i.e. ls -la --human-readable /.
A huge amount of help is also available from the manual pages residing on your Pi, which contain more verbose instructions.Â You use these by typing “man command”, e.g. man ls or man adduser or even man man.Â While they are very detailed and available for pretty much every command you’ll use, a) you need to already know what command you want, and b) they aren’t always written in the clearest manner for a beginner.Â Don’t be afraid to google for information too – for example, putting “how do i add a user in linux” into google’s search box gives you exactly what you need to know.Â You aren’t born with knowledge of how Linux works so you need to find it somewhere.Â Start off with the manual pages but if you only understand a few of the words on them, have a google for it.