Maker Pro
Linux

How to Use the Linux Shell/Terminal for Raspberry Pi

March 21, 2018 by Zac Jackson
Share
banner

This UNIX program allows users to interact with an operating system, converting binary into an easier to read format.

What is Linux Shell?

A shell is a term for a UNIX program that allows users to interact with an operating system (Linux and Macintosh are UNIX-based operating systems). Computers work by sending ON and OFF signals through logic gates. These ON and OFF signals are communicated through binary as 0's and 1's, each digit is a bit of data. Reading a program in binary would be incredibly tedious for a person, so we use an interface to convert the binary into something easier to read.

In this tutorial, you will learn how to use the Linux shell for Raspberry Pi and some basic commands. Let's fire up our Raspberry Pis and get started!

Using your mouse or touch screen with the Raspberry Pi's graphical user interface, you can navigate to different folders, run different software and apps, copy files from one folder to other, rename files and folders, and many other things using few mouse clicks. But what if you need to copy a hundred files with the letter ‘k’ in their name present inside a folder with 500 files? In this case, it’s almost impossible to hand-pick files with letter ‘k’ in their name and copy them to other folders. The Linux shell shines for complex commands like this.

Take a look at the command below to see how easy a command like the one mentioned above is when you use the shell.

cp *k* /myFolder

The command above will copy all files with letter ‘k’ in their name to a destination folder named myFolder.

This is one of the many magical powers of Linux shell. There are a number of scenarios where the graphical user interface is limited, here the help of the shell comes into play.

Opening Linux Terminal

Terminal, Shell, Linux shell are all the same thing. Since Raspberry Pi is a Linux-based operating system, it also provides a full-fledged Linux Terminal. Below is a screenshot of the Linux terminal in Raspberry Pi.

To open the terminal in Raspberry Pi, click on the 4th icon to the left on the top bar.

Type “help” in the shell and you will see a list of commands printed onto the screen.

These are all commands that are supported by Raspberry Pi Terminal. You can find a more in-depth explanation of basic Linux commands in this tutorial.

Basics of Linux Terminal

When you open the terminal in Raspberry Pi, you will see a cursor blinking after some strange written text.

pi@raspberry:~ $

The text above can be broken into sections so you can see what it means:

  • pi: The username of the current user
  • raspberry: the hostname
  • ~: Represents the current directory. In Linux, the ~(tilde) represents the directory /home/pi
  • $: The prompt symbol. After this symbol user can enter commands.

Some Linux Commands to Play With

  • In terminal enter “ls”, it will show the files and folders in your current directory
  • You can use options with every command. For example “ls –l” shows a long listing and “ls –a” shows all the files in a directory including hidden ones. Hidden files in Linux start with a period “.”)
  • You can combine different options like “ls –l –a” or “ls –la” and both will work the same.
  • The command “cd” is for the current directory.

Example Program

Let's say that James wants to create a file (abc.txt) with that displays the text “Hello I’m James” in a folder named “James” on the desktop and he wants to do it without a single click. The sequence below will allow him to do that.

  • Power up your Raspberry Pi
  • Open terminal
  • Enter “cd Desktop
  • Enter “mkdir James
  • Enter “cd James
  • Enter “sudo nano abc.txt
  • A screen will open, enter your desired text in it
  • Nano is a Terminal-based text editor
  • Press CTRL+O to write contents to the file.
  • And you're done!

If you want to know how a specific command works just enter “command -?” or “cd -?”

Once you start using the terminal, you'll pick it up faster than you'd think!

Related Content

Categories

Comments


You May Also Like