Skip to main content

Beginning Raspbian Commands

LXTerminal

LXTerminal is the default terminal emulator that is included with Xfce. LXTerminal allows you to run console applications inside the graphical environment of Xfce and acts as a bridge between you and your Raspberry Pi, similar to what Xfce does. We will discuss using LXTerminal in more detail in the following...

Multiple instances of LXTerminal can be run, which allow you to run several terminal applications at the same time. These instances can be in their own windows or in a tab.
Raspbian LXTerminal

The Console

Behind the pretty graphical interfaces of a Linux-based operating system such as Raspbian, is the console.

The console is the most basic way of communicating with the innards of the Raspbian operating system. The console's history started at the very beginning of computing where the interface to a computer was a keyboard and a teletype machine. At that time, operators would type a command and the result would be printed in front of them.

Fortunately, with the development of computer monitors, we no longer need a typewriter to communicate with our computer and there are many different ways in which this can be done. You already learned how to use the Raspberry Pi's graphical user interface Xfce, and this chapter will run you through how you can use the built-in console terminal application called bash.

Bash

The Bourne again shell (bash) is a console shell developed by the GNU project that was released in 1989. Originally written by Brian Fox, it has become the de facto standard and is used by default in almost all Linux operating systems, OS X, Novell NetWare, Android, as well as on Windows. The bash was inspired by the sh shell, which was extremely popular around the time bash was created.

The bash shell was written as an open source replacement to the Bourne shell that was the default command-line interpreter for Unix. The bash supports many features, including the autocompletion of commands and filename wildcards.

Launching the bash command
interpreter

The bash command interpreter is made available to us in the Xfce environment through the LXTerminal application. Other terminal clients such as Yakuake can be installed using apt-get. If you have configured Raspbian to not start the Xfce desktop environment, bash will be automatically started after you log in.

You can launch LXTerminal by double-clicking on its icon on the desktop.

You can launch and run as many instances of LXTerminal as you like, but don't forget that your Raspberry Pi doesn't have unlimited resources.

If you are not using the Xfce desktop environment, bash will be launched when you log in.

The first thing that you will notice is that you have Command Prompt. By default, this Command Prompt will show you the current directory that you are working in, your Raspberry Pi's hostname (by default raspberrypi), and your username (by default this is pi).

As you move around the filesystem, you will see the name of the directory that you are in.

To run a command using the bash command interpreter, simply type the command and press the Enter key. The command will run and the results will be displayed. While a command is running, you won't be able to run other commands until it is finished.

If you wish to let a command run in the background, all you need to do is add an & operator to the end of the command. This will let the command run in the background.

Linux is a full multiprocessing system and you can run as many instances of LXTerminal as you want. To see which processing commands are running in the background on your Raspberry Pi, simply run ps –a.

Basic bash commands

The best way to start learning bash is to start using it. Remember that if you really make a mess of things, all you need to do is reimage your SD card and away you go!

It is easy to get more information about any of the commands that are referred to in this post. You can do this using the man command.

The man command launches the built-in documentation system for Linux. Almost every command available has documentation in the man system.

For example, to find out more information about the ls command, simply run the following command:
man ls

This will launch the man program and display every bit of information that you need to know about the ls program.
The man ls command
To move around the man program, you can use the arrow keys on your keyboard. If you wish to skip the whole page, you can press the spacebar key. When you have finished reading the information, you can exit by pressing the q key.

😨Don't forget that Linux is a case-sensitive operating system and it is extremely important that you use the correct case when you are running the command.

The autocompletion of commands

One of the most useful features of bash is its ability to autocomplete the name of the command that you are typing. This is as easy as pressing the Tab key.

For example, if you want to run the command nano in order to launch the nano text editor, simply type the following command:
nan
Now press the Tab key. The bash will automatically autocomplete the command and display this:
nano

This can be a real timesaver. If there is more than one possible combination of autocompletion, you will need to press the Tab key twice. This will cause bash to list all the different possibilities.

You can use Up and Down arrows of your keyboard to get previously used commands... But if you switch to another user you can't access previous commands by this method.

Running commands as root

Linux is an inherently secure operating system. Every part of the operating system has been configured to be secure by default. Every file is owned by a particular user, and that user is able to allocate permissions to that file in order to restrict other users and groups from accessing the file.

By default, all commands that are run in bash are run as the current user. The current user is normally the Pi user. This user is a standard user, and this means that you will not be able to run any commands that can affect other users, such as installing software or changing the network configuration of your Raspberry Pi.

Fortunately, it is easy to run commands as the root or superuser. This user has unlimited access to every part of the operating system and must be used with caution.

To run a command as the superuser, you can use use the sudo utility. The sudo utility lets you run a command as a different user from what you are logged in as.

In order to use the sudo utility to run a command as root, all you need to do is prepend the command that you want to run with sudo.

Take an example of the following command:
sudo apt-get moo
It will run the apt-get application as root. This particular command will invoke apt-get Easter egg, proving that computer programmers sometimes do have a sense of humor!
Running command as root that can make your Raspberry Pi moo!

Comments

Popular posts from this blog

8051 Simple Programs

Sum of 8-bit Numbers Stored in Memory Here  we will discuss about 8051 programs but we can't discuss about all of the 8051 instructions. For programming 8051 we should know about assembler directives as well as instruction set. Click  here to download Atmel c51 user guide that will discuss about 8051(c51 family microcontroller) instruction set, assembler directives, c51 cross assembler from Atmel.  Program ORG 00H MOV R0,#50H   ; get memory location in memory pointer R0 MOV R1,#51H   ; get memory location on memory pointer register R1 MOV A,@R0       ; get content of memory location 50H to accumulator ADD A,@R1        ; add content of A with content of memory location 51H and store result in A MOV R0,#52H    ; get 52H to memory pointer R0 MOV@R0,A         ; copy content of A to memory location 52H END Add 16-bit Numbers Program ORG 00H MOV DPTR,#2040H   ; get 2040H into DPTR MOV A,#2BH              ; get lower byte of second 16-bit number on accumulator MO

Introduction to 8051 embedded C

For 8051 we need to include the file reg51.h. This file contains the all the definitions of 8051 registers. With this information C compiler produces hex file that can be downloaded into the ROM of the microcontroller. It is important to note that the size of the hex file produced by the assembly language is much larger than the hex file produced by C compiler. Apart from this fact, there is many reasons for writing programs in C instead of assembly: ●It is much easier and less time consuming to write programs in C assembly. ●C is more flexible; it is easier to modify and update. ●Programming in C allows to use code available in function libraries. ●Program written inC for one microcontroller is portable to other microcontrollers with little or no modifications. Data Types in 8051 Embedded C The table shown below lists the data types that are available in typical C51 compiler. The gives information about the size of the data variable and it's value range. Data type

8051 Keyboard Interfacing

Keyboards are organized in a matrix of rows and columns. The CPU accesses both rows and columns through ports. Therefore, with two 8-bit ports, an 8 x 8 matrix of keys can be connected to a microprocessor. When a key is pressed, a row and a column make a contact. Otherwise, there is no connection between rows and columns. In IBM PC keyboards, a single microcontroller takes care of hardware and software interfacing. A 4x4 matrix connected to two ports. The rows are connected to an output port and the columns are connected to an input port. Grounding Rows and reading Columns:- 8051 keyboard interfacing It is the function of the microcontroller to scan the keyboard continuously to detect and identify the key pressed. To detect a pressed key, the microcontroller grounds all rows by providing 0 to the output latch, then it reads the columns. If the data read from columns is D3 – D0 =1111, no key has been pressed and the process continues till key press is detected. If one of t