5 command line tips for Raspberry Pi
New to the Raspberry Pi? If you’re looking for hints or advice to improve your skills and knowledge of the command line, you’ve come to the right place…
The Raspberry Pi is designed to introduce its users to the more practical side of computing. As such it exposes users to the command line as soon as you turn it on. New users (and even some more experienced enthusiasts) can have a rather irrational fear of the command line. Hopefully the following tips and techniques will prove that it’s actually much friendlier than you might think…
All of the tips and techniques work on the command prompt (when you first start your Raspberry Pi) and in the LXTerminal window (once you’ve logged in to your desktop by typing startx ) and assume you’re running the officially supported operating system for Raspberry Pi, Raspbian.
If you’re scratching your head wondering what tasks you’d possibly want to carry out in the command line, check out the five things to do after setting up your Raspberry Pi to get some inspiration.
You CAN copy & paste
One of the most widely overlooked command line conveniences is the fact you can actually copy and paste snippets of code or URLs into the terminal. Simply highlight the text you wish to copy, right click and select Copy. Moving over to the terminal window, all you need to do is right click inside and select Paste.
The quicker alternative would be to use the convenient Copy and Paste shortcut keys, you just need to add SHIFT into the mix.
So if you’re following a guide online and want to copy some code or a URL into the command line, all you need to do is copy at as normal, click onto the LXTerminal window and press SHIFT + CTRL + v to paste it in. Easy!
TAB completion & command history
Quite often when you’re working in the command line you need to repeat certain commands or write long strings of characters. Luckily there are two very helpful conveniences already in place to make both of these things trivial – TAB completion and command history.
TAB completion is quite an intelligent tool. If you’re mid-way through writing a command or perhaps a file or folder location you can simply tap the TAB key and your Pi will fill in the blanks for you. This only works if the terminal recognises it as a valid command or location.
If there’s more than one possible way to proceed from the segment you’ve written, then double-tapping the TAB key will reveal them all.
Command history, on the other hand, is a great way to go back and find commands you’ve previously used without having to do any typing at all. Simply tap the UP key on your keyboard you can cycle through a long history of your previously used commands. Simply press RETURN on the one you want to use again and it will carry it out as if you’ve just typed it.
Pressing DOWN on the keyboard will cycle in the opposite direction.
Install & remove software
By far the quickest and most convenient way to install software on any Linux system is via the command line. Since Raspbian is a Debian-based distribution you do this using APT (Advanced Package Tool).
Like all Linux ‘distros’, Raspbian has a repository full of thousands of amazing applications and tools. To install software from this repository all you need to do is ask APT to fetch it for you. Let’s say you wanted to edit a picture that you took with the Raspberry Pi Camera Module… to do that you’d need to install GIMP (The GNU Image Manipulation Program).
At the command line or within the LXTerminal window you just need to type:
sudo apt-get install gimp
Follow the on-screen instructions and after a short-while you’ll find it’s been installed and can be accessed via the applications menu (you’ll find it in Graphics). Some applications will even give you a desktop shortcut to click on.
But what if GIMP wasn’t the right program for you? To tidy up after yourself you’d want to remove it like this:
sudo apt-get remove gimp
It’s really easy, but only if you already know the name of the software you want to install…
Find cool software
What happens when you want a new piece of software, but have no idea what it’s called? That’s where APT’s search command comes in handy.
There are actually a couple of ways you can do this: the old fashioned apt-cache search method, or the more modern aptitude search method. You’ll get great results with both, but we personally prefer the former - it’s quicker.
Let’s say you want to find a little application to take a screenshot of your Raspberry Pi desktop. All you do is add a search term to the end of the command like this:
apt-cache search screenshot
You’ll be met with a list of results that each feature the name of application (making it easy to copy & paste into the install command) and a handy summery of what the application does.
Since there could be tens or even hundreds of results for your search term, you might find it more helpful to ‘pipe‘ the results into an easy-to-scroll window using the less command…
apt-cache search screenshot | less
You can scroll up and down through the results with ease and press ‘q‘ to quit back to the command line.
Want to see the real power of open source? Try the following command to see all the software available to your Raspberry Pi. SPOILER: There’s a lot!
apt-cache search . | less
Read the flipping manual
Quite a lot of the applications you’ll find searching through the Raspbian repository are CLI (Command Line Interface) tools. This means, while they can do any number of amazing things, you can only interact with them at the command prompt or in an LXTerminal window.
Since none of us are psychic, there needs to be a way to learn how to use them. That’s where man pages come in.
Carrying on from our example, we decided to install scrot. It’s a really simple and elegant CLI tool for taking screenshots of your Raspberry Pi desktop. It has loads of great features like being able to take pictures of different sizes, using a count-down timer to take delayed shots and so on. To find out how to use all these cool features we use the man page. It’s a built-in tool that’s short for manual.
To read scrot‘s manual you’d simply type the following: man scrot
It’ll put you in the same kind of easy-to-scroll window we saw earlier (so you just press ‘q‘ to quit back to the command line). This way it’s easy to scroll through and make a note of the commands you might want to use.
Another easy to remember alternative is --help (or simply -h ), which gives a brief, but helpful overview of the key commands on offer. The syntax would simply be: scrot --help
Did you find any of these useful? We’ll be back with another five essential command line tips soon!
If you’ve got a tip or technique you’d like to share, let us know in the comments thread below.