Introduction
The following pages are intended to give you a solid foundation in how to use the terminal, to get the computer to do useful work for you. You won't be a Unix guru at the end but you will be well on your way and armed with the right knowledge and skills to get you there if that's what you want (which you should because that will make you even more awesome).
Here you will learn the Linux command line (Bash) with our 13 part beginners tutorial. It contains clear descriptions, command outlines, examples, shortcuts and best practice.
At first, the Linux command line may seem daunting, complex and scary. It is actually quite simple and intuitive (once you understand what is going on that is), and once you work through the following sections you will understand what is going on.
Unix likes to take the approach of giving you a set of building blocks and then letting you put them together. This allows us to build things to suit our needs. With a bit of creativity and logical thinking, mixed in with an appreciation of how the blocks work, we can assemble tools to do virtually anything we want. The aim is to be lazy. Why should we do anything we can get the computer to do for us? The only reason I can think of is that you don't know how (but after working through these pages you will know how, so then there won't be a good reason).
A question that may have crossed your mind is "Why should I bother learning the command line? The Graphical User Interface is much easier and I can already do most of what I need there." To a certain extent you would be right, and by no means am I suggesting you should ditch the GUI. Some tasks are best suited to a GUI, word processing and video editing are great examples. At the same time, some tasks are more suited to the command line, data manipulation (reporting) and file management are some good examples. Some tasks will be just as easy in either environment. Think of the command line as another tool you can add to your belt. As always, pick the best tool for the job.
Outline
This Linux tutorial is divided into 13 sections. In general I recommend you work through them in order but if you've come here just to learn about a specific topic then feel free to just go straight to that one.
You can now jump into section 1 and get started or keep reading below to learn a little more about this tutorial.
- The Command Line - What is it, how does it work and how do I get to one.
- Basic Navigation - An introduction to the Linux directory system and how to get around it.
- More About Files - Find out some interesting characteristics of files and directories in a Linux environment.
- Manual Pages - Learn how to make the most of the Linux commands you are learning.
- File Manipulation - How to make, remove, rename, copy and move files and directories.
- Vi Text Editor - Discover a powerful Linux based text editor.
- Wildcards - Also referred to as globbing, this is a means to refer to several files in one go.
- Permissions - Learn to identify and change the permissions of files and directories and what the consequences of these are.
- Filters - An introduction to various commands that allow us to mangle data in interesting and useful ways.
- Grep and Regular Expressions - Master a powerful pattern matching language that is useful for analysing and processing data.
- Piping and Redirection - Join commands together in powerful combinations.
- Process Management - See what is currently running on your Linux system and what state the system is in, learn how to kill programs that have hung and put jobs in the background.
- Scripting - Be happy. Get the computer to do tedious and repetitive tasks for you.
- Cheat Sheet - A quick reference for the main points covered in this tutorial.
Structure
The best way to learn the Linux command line is as a series of small, easy to manage steps. This tutorial is organised as such, with each section building upon the knowledge and skills learned in the previous sections. If you work through them in order, read them fully (there is a fair bit of material but it is important for getting a proper understanding) and practice on the command line as you go I believe you should have a fairly pleasant and smooth journey to Linux command line mastery.
99 times out of 100 when a student has troubles with this stuff I find that it is not that they are incapable but that they were lazy and didn't read the material fully.
Each section is structured in the following format:
- An introduction outlining what you will learn in that section.
- Detailed material including extensive examples.
- A summary of programs covered in that section and the most important concepts.
- A set of activities to help you solidify your knowledge and skills.
Think of the activities not as tutorial questions (such as you may get in a class at school) but as direction on where to explore in the Linux environment to benefit from your new knowledge and skills. Treat the activities as a starting point for exploration. The further you take it, the better you will do. (How well you do and how far you go depends on how unlazy you are.)
This site is also designed to work well on tablets. I know a lot of students like to be at their computer doing work and have their tablet next to them with reference material on it. If that is you then this site works quite well with that set up. Another good approach is to have your browser on one half of the screen of your computer and a terminal on the other half so you can try out the examples as you go.
Some general house rules:
- I'll refer to Linux in the following pages, whenever I do, assume I'm actually saying Unix/ Linux. Linux is an offshoot of Unix and behaves pretty much exactly the same.
- Whenever you see <something>, what this means is that you are to replace this with something useful. Replace the whole thing (including the < and >). If you see something such as <n> then it usually means replace this with a number.
- Whenever you see [something] this usually means that this something is optional. When you run the command you may put in the something or leave it out.
Problem Solving and Creative Thinking
If you wish to succeed with the Linux command line then there are two things you need, Problem solving and Creative thinking. Here are some basic pointers to help you along the way.
- Explore and experiment. Remember, you're learning about a set of building blocks and with them you can build almost anything. The examples you will find are intended to be an illustration of how they work, not the only thing you can do with them. I encourage you to tweak the examples and see how they behave. This will give you a much better understanding on how they work. You will have a lot of questions along the way along the lines of "What if....?" and "Can I ...?" to which I say, "Give it a go and see what happens." The worst you can really get is an error message. In which case you read the error message to understand why it didn't work, then have another go. Don't hold back!
- Read carefully and don't skip over the fine details. I can't stress this enough. The fine details are important and are often the difference between your command working and not working. If something isn't working then re-read the material carefully and re look over what you have typed in to make sure you haven't make a silly little typo.