Curious about getting into Raspberry Pi or just Linux in general but you're not sure where to start? This post is for you. It's not intended to be a comprehensive guide, rather a gentle intro into the Linux world. I'm not a Linux expert, but I know from experience that it can be an intimidating platform to get started in. I want this post to show you what you need to know to get started with Linux.
My dad bought us our first PC in around 1990. We'd had a Commodore 64 before that, but this was our first Windows based machine. I loved it, but I'm pretty sure I made Dad nervous with how fearlessly I clicked and navigated around everything. I was curious to learn about this thing and I wasn't afraid to tweak settings or click on something I probably shouldn't have. A whole new world had been opened to me and I wanted to "drink from the firehose" and learn as much as I could. I've been using Windows on a daily basis ever since. Needless to say, I've been a Windows user a long time.
Eventually I got into programming. My experience with Windows continued to serve me well for a long time, but every now and again I'd have to deal with a bit of Linux. And, I have to be brutally honest here, it terrified me. I couldn't even fathom using a command line for copying a simple file, let alone installing an application server and deploying a web app! It continued to terrify me for years, but each and every time I used it a tiny little bit of me got more comfortable with it. A few years later and I started to realize: "hey, this ain't so bad, I actually kinda like this"!
Around that point I decided that I'd like to learn a bit more about Linux, and that was one of the motivating factors for deciding to get into programming and building projects with the Raspberry Pi. About a month ago when I decided to build and launch this blog I took an even bigger step: I installed Debian Jessie on my Dell Studio XPS. Now I'm a full time Linux user on my personal projects and I'm really enjoying it. Granted, it'll take years for me to reach the level of proficiency that I am at with Windows, but it's a skill that looks great on a resume and anything that keeps me learning new things about computing is a Great Thing™ in my book.
So I decided to put together a quick guide/cheat sheet for those of you who may be new to Linux (maybe you're just getting into Raspberry Pi yourself). There are plenty of cheat sheets out there, and most may be more comprehensive and detailed, but I hope this guide will get you familiar with Linux at a basic, bare bones level. Some of the definitions I use may not be textbook, but I intend to use easy to understand (and commonly used/accepted) definitions for some terms. Feel free to offer corrections and I'll keep the post updated if I've made any glaring mistakes.
Different "versions" of the Linux operating system are called distributions (or "distros"). There are lots of them. The Raspberry Pi uses a distribution called Raspbian which is based on one of earliest distros called Debian. You've heard of the Android OS for mobile phones, right? Android is a Linux distribution. The wireless router in your house right now is running some flavor of Linux. If you're a fan of Mr. Robot, you've probably heard of Kali Linux, a popular distro used for digital forensics and penetration testing.
In the Linux world, the "terminal" is the equivalent of the Windows command prompt. It's a textual interface to enter commands, navigate the file system and perform tasks on the Linux machine. You'll probably end up using the terminal a lot to install software on your Linux machine. There are several different "package managers" used on Linux - "yum" and "apt-get" are ones you'll probably see and hear of quite often. Sometimes people use different words for the terminal like 'console', or 'shell' - this is a good explanation of all those different terms. There are many different versions of terminals depending on your distribution or personal preference, but all of them will allow you to perform the same tasks. When in a terminal session, CTRL+C will break out of most running processes.
sudoers
file - see man sudoers
) you can execute a command with elevated privileges by putting sudo
before your command. Read more about sudo here. If you're wondering, sudo originally stood for 'superuser do'. Another option you may need to invoke is "switch user" or just su
by calling sudo su
or just su
. The difference between sudo
and su
is that sudo
allows you to perform the action as your own user, with your own password while su
grants you the permission of another user (typically the 'root' user) and requires the superuser password. Read more on the difference if you're interested here.The Linux command man
is used to get a 'manual' (or user guide) for a specific piece of software. Many programs and Linux commands have detailed user guides accessible by typing man [command name]
in a terminal window. Most man pages use more
(reference) or less
(reference) to view the manual page. In more or less you navigate through a file using SPACE to move forward one page or 'b' to move backwards one page. Hit 'q' to quit. To learn more about more and less, try man more
or man less
. Whew, that's a mouthful.
SSH (Secure Shell) is the term most commonly used for "remoting in" to a Linux machine and manipulating/performing tasks via the command line. You can SSH into a machine with a username and password, or via a private key file. To SSH into a machine, you must have an SSH compatible client. On Linux, any terminal window will do. Same goes with any terminal in OS X. Windows (pre version 10) has no built in support for SSH, but there are several third party programs that'll do the trick. Check out PuTTY and Cygwin if you need a good Windows SSH client.
This section is going to be a rapid fire dump of some commonly used commands. If you're brand new to the command line you can use this as a quick reference or intro to some of the things you can do. Many commands have 'switches' or arguments that you can pass to them to alter the task performed in some way. Arguments are passed after the command and preceded by a dash "-a" or two dashes "--all". To learn more about a command, always remember that man
exists to help you out.
ls
command. Commonly used arguments are "-la", the "-l" switch uses a "long" (detailed) list format, the "-a" switch includes hidden files (those beginning with a ".").
Use cd
(change directory) and enter the path to the directory you would like to move to. Paths that begin with a forward slash ("/" - the Linux path delimiter) are absolute paths. That means they begin from the top of the directory tree. Paths that don't have a leading forward slash are relative - they begin at the folder you're currently in. You can pass a full path instead of stepping through one level at a time. If you're in /home
and you want to go to a folder three levels deeper you'd use something like cd projects/scratch/foo
.
pwd
(present working directory) will tell you where you're at.mkdir [dirname]
will create a new subdirectory in the current directory.
touch [filename.extension]
will create a new file in the current directory.chown
(change owner), chgrp
(change group) and chmod
(change permissions) are the three commands to remember when it comes to changing file/folder permissions and ownershipt. Managing file permissions via Terminal can be a tricky thing to wrap your head around and I could spend a full blog post explaining them, but for now you should know that these commands exist and you should spend time learning about file permissions. If all else fails you can manager permissions (to an extent) via the GUI in your desktop environment by right clicking on a file/folder and selecting Properties - Permissions.
There are several built in text editors that can be used within a terminal session. My favorite is nano (launched by typing nano [filename]
). It has simple controls that are listed on the bottom of the editor. Hardcore nerds prefer Vim (launched with the command vi
). I just entered Vim while writing this blog post and it took me about 2 minutes to simply exit Vim. That's why I don't use Vim.
mv [source] [destination]
can be used to move a file from one directory to another. If the destination directory is the same as the source then the file will be renamed. cp [source] [destination]
is used to copy a file from a source to a destination.rm [filename]
(remove) will delete a file.
rm -rf [directory]
will remove a directory (the -r switch is for 'recursive' and the -f switch is to 'force' the deletion and not ask for confirmation).
This might be getting into a bit more advanced territory, but I think it's worth noting in a beginners guide that grep
exists. It's best illustrated via example, so imagine a directory structure like so:
drwxr-xr-x 2 toddsharp toddsharp 4096 Mar 18 18:19 .
drwxr-xr-x 4 toddsharp toddsharp 4096 Mar 18 17:52 ..
-rw-r--r-- 1 root root 0 Mar 18 18:19 bar.txt
-rw-r--r-- 1 root root 0 Mar 18 18:19 food.txt
-rw-r--r-- 1 root root 0 Mar 18 18:19 foo.txt
Let's say I wanted to find all the files in this directory that begin with the string "foo". One way of doing this would be to "pipe" the result of the ls
command to grep
and pass a "regular expression" that I want to search for. In Linux, to redirect the result of a command you use the "pipe" character |
which is why you'll often hear "pipe" used in this context.
ls -la | grep 'foo*'
Would result in:
-rw-r--r-- 1 root root 0 Mar 18 18:19 food.txt
-rw-r--r-- 1 root root 0 Mar 18 18:19 foo.txt
Read more on grep
here.
Of course! You can use find
. Here's a thorough article for more details, but find
is another way to search for a file like the previous grep
example. The first argument passed to find is the path at which to start looking. A dot (".") is the current directory, while "/" would search from root. The next argument is the name of the file, but find requires us to "escape" the wildcard (*) so to reproduce the previous example we'd do:
find . -name foo\*
scp
is a bit beyond the scope of a beginner article, but know it exists and read more on it when you need to. You can use scp
to copy from/to Linux machines, but to use Windows to copy to/from a Linux machine you need PuTTY or WinSCP.One of the cooler things about the Spark Java framework is built in websocket support thanks to the embedded Jetty server. I've long been fascinated...
I published a post last week showing how to use Grails to create a website on the Raspberry Pi. After some feedback and conversations about whether...
In this post we'll create and deploy a simple website on the Raspberry Pi. There are a few prerequisites that I've covered in some previous posts...