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).If you are not using the Xfce desktop environment, bash will be launched when you log in.
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
Post a Comment