Computer users today are so attached to graphical interfaces. Sometimes it seems that people help computers to do the tasks. Can you imagine how many mouse clicks is required to do something simple. This is visible when task is cyclic like “find, sort, delete”. Sometimes you find yourself just clicking mouse and not seeing the result. What you would do half a day clicking the mouse, it can be performed with single command line. The question is how to be that smart and feel like a fish in a water in front of command prompt, shell or bash – call it how ever you want. It is a system program that accepts typed commands from used and performs tasks. If you look deeper at almost any program with graphical interface you will see that it is only a nice skin that hides same commands that run when user clicks buttons. None graphical interface can cower all features of shell commands. So if you start dealing with Linux, then start being friend to terminal.
Historically Unix computers even didn’t have graphical interface, so all tasks were performed from terminal screen. This is why bash program that handles commands is well polished, is flexible and offers many amazing features.
How to learn bash commands and write scripts for it? The answer like elsewhere is same – keep doing this and you will learn. Indeed, don’t afraid to experiment. With Raspberry Pi ir becomes even simpler, just attache network cable, run PuTTY and keep practicing. No problem if something goes wrong – in worst case scenario you could just load new image in to SD card and continue. Internet is full of tutorials and guides pick one and go.
Bare in mind that command line is not as warm as GUI, it is more designed for computer programs rather than humans. But in time you can see a pattern. Simple rules makes this obvious. Lets get warmed up with few useful commands. Probably you are familiar with sudo command. In many cases it stands in front of most commands which tells to run command as super user. In Linux systems you are not advised to run as administrator. So if you need administrator privileges add sudo. In many cases you may find typing sudo before almost every command. For this is a simple command variable -i which runs shell with super user privileges:
Most common task in any operating system is working with files and directories. When you are in terminal program you need to be aware where currently you are. After initial login to Raspberry Pi normally you are located in /home/me directory. You can check you current location by typing command
it shows current directory you are in – this is called working directory.
Once we know where we are. We probably want to know what’s inside this directory. Just type another command
it lists all the files in it. Lets say we want to navigate to another directory. For instance Desktop. For this we should use cd command with directory path. If directory is inside working directory we can type its name after command
if we need to get back, then we type
don’t forget a space after cd! If we want to go to specific directory we should type in full path to it. For instance if we want to get to usr directory we should type
Since you are logged in as user named pi, you can get any time to user directory by typing
this gets you to /home/pi directory.
Few rules must be kept in mind while working with files in Linux based systems:
- File names are case sensitive. Same file name with Upper case and lower case characters represents different files.
- Avoid using spaces in file names. It gets messy when writing complex commands. Better use underscores, dashes to combine several words in to file name.
- Everything is a file in a Linux system.
This only a scratch of the surface. We will try more interesting commands next time.