10 Minute Linux Crash Course - Everything You Need to Get Started Now
Some of us grew up clicking around in MS Paint on Windows. Others may enjoyed the luxurious interface afforded by Mac OS. Still others may have been stuck with nothing more than a cell phone, or even just a TI-84 calculator.
Regardless of your humble beginnings, I want to congratulate you on taking things to the next level by jumping headfirst into the world of Linux. Whatever your reason for dipping your toes in these waters, I'm sure you won't regret it! Anyone involved with computers will almost certainly encounter Linux at some point in their career, so now is the time for you to get ahead of things and figure out how to use the dang thing!
All you'll need is a little patience and about 10 minutes to get started! Read on.
Disclaimer: the video is 10 minutes, but the article may be a bit more verbose. :)
Making Moves (Navigating the System)One of the first things you need to know how to do when you're learning to use the computer is how to move around. For Windows or Mac, everything is graphical. Some Linux distributions have a Graphical User Interface (GUI) as well, but Real Linux happens on the command line. From now on, we're throwing off the GUI security blanket and diving straight into the command-line!
ls
ls
By far, the most common command on Linux is
, which
i
ts the files in the current directory. Instead of opening a window and seeing a folder's files there, you'll instead be in a terminal window whose current working directory is set to some folder on your hard drive.
shows you everything in that folder.
Here is an example of what using
may look like:
steve@surface01:folder$ lsfile1.txt file2.txt image.jpgsteve@surface01:folder$
In the above, you can see that we typed
and hit enter, showing the contents of our current folder. As it turns out, the folder contains three files:
,
, and
.
The
command on its own hides files that start with a "
". To really see all the files, you can use
:
steve@surface01:folder$ ls -a. .. file1.txt file2.txt image.jpgsteve@surface01:folder$
You can view extra information about the files with the long version of the command,
:
steve@surface01:folder$ ls -ltotal 0-rw-r--r-- 1 steve steve 0 Nov 28 14:11 file1.txt-rw-r--r-- 1 steve steve 0 Nov 28 14:11 file2.txt-rw-r--r-- 1 steve steve 0 Nov 28 14:11 image.jpgsteve@surface01:folder$
You can use them together with
(or
):
steve@surface01:folder$ ls -altotal 8drwxr-xr-x 2 steve steve 4096 Nov 28 14:11 .drwxr-xr-x 28 steve steve 4096 Nov 28 12:38 ..-rw-r--r-- 1 steve steve 0 Nov 28 14:11 file1.txt-rw-r--r-- 1 steve steve 0 Nov 28 14:11 file2.txt-rw-r--r-- 1 steve steve 0 Nov 28 14:11 image.jpgsteve@surface01:folder$
cd
cd
What if there's nothing in this folder that we're particularly interested in? Are we out of luck?
No! The
command, or current directory, will come to the rescue! We use this command to change the current working directory to somewhere else on the system.
For example, say I need a break from work. In that case, I'll head over to my games folder:
steve@surface01:games$ cd /home/steve/gamessteve@surface01:games$ lscod.sh minecraft.shsteve@surface01:games$
As you can see, typing
again now shows the files inside the games folder in my home directory. If the path
isn't a real folder on your computer, you'll get an error:
steve@surface01:folder$ cd /home/steve/does_not_exist-bash: cd: /home/steve/does_not_exist: No such file or directorysteve@surface01:folder$
Notice how the path above begins with a slash ("
"). When you see this in Linux, it's called an absolute path. This means that you're giving the exact path to a file or folder on your system. The alternative is to use a relative path, which we'll talk about below.
pwd
pwd
In case you get completely turned around, you can use the
command, or print working directory, to tell you exactly where you are on the computer.
After running the
command in the above example, this is the output of the
command:
steve@surface01:folder$ cd /home/steve/gamessteve@surface01:games$ pwd/home/steve/gamessteve@surface01:games$
Relative PathsThere are two special directories you'll want to worry about:
and
. Yes, you read that right - they're called "dot" and "dot dot". What the heck does that mean?
The single dot,
, stands for the current directory. The double dot,
, stands for the parent directory. Anything that uses one of these two special folders, or that does not begin with a slash, is considered a relative path.
Say that we're back in my
folder, and I want to move up a folder into the
directory. One way to do this would be to type the whole path in the command, as
. However, you might as well save your fingers some work! Just type
and it will do the same job.
steve@surface01:games$ pwd/home/steve/gamessteve@surface01:games$ cd ..steve@surface01:~$ pwd/home/stevesteve@surface01:~$steve@surface01:~$ cd gamessteve@surface01:games$ pwd/home/steve/gamessteve@surface01:games$
It may not seem like a big deal, but paths can get quite long. When you're 20 folders deep, you definitely won't want to type the entire path out to move up a folder!
Another powerful part of this is that you can chain the dot-folders. To move up two directories instead of one, it's as easy as:
steve@surface01:games$ pwd/home/steve/gamessteve@surface01:games$ cd ../..steve@surface01:home$ pwd/homesteve@surface01:home$
Notice that I moved from
all the way up to
. Much quicker!
Now that you now know the basics of moving around, let's get our hands dirty and mess with some files.
Get Organized! (File Manipulation)cat
cat
The fluffiest of all Linux commands,
is also one of the most useful. It's job is not to eat all of your kibble or crawl on your keyboard, but instead to output the contents of any file on your computer. This is handy if you want to check what's inside of something without popping open a text editor, but it's also priceless when using piping, discussed below.
It's incredibly simple to use. Just type
. Here's an example - say that I keep my dog's name is a text file in case I forget it:
steve@surface01:folder$ lsdog_name.txtsteve@surface01:folder$ cat dog_name.txtDoggosteve@surface01:folder$
As you can see, we've printed the contents of
to the terminal for all the world to see!
touch
touch
If you need to create an empty file, maybe as a placeholder or just to prove that you have permission to do it, you can use the touch command.
steve@surface01:folder$ lssteve@surface01:folder$ touch my_file.txtsteve@surface01:folder$ lsmy_file.txtsteve@surface01:folder$ cat my_file.txtsteve@surface01:folder$
There it is!
mkdir
mkdir
The
command lets you make a directory. Check it out:
steve@surface01:folder$ lsmy_file.txtsteve@surface01:folder$ mkdir folder1steve@surface01:folder$ lsfolder1 my_file.txtsteve@surface01:folder$ touch folder1/other_file.txtsteve@surface01:folder$ cd folder1/steve@surface01:folder1$ lsother_file.txtsteve@surface01:folder1$ cd ..steve@surface01:folder$ lsfolder1 my_file.txtsteve@surface01:folder$
If you need to make multiple nested directories all at once, you'll have to use
.
steve@surface01:folder$ mkdir lots/of/nested/foldersmkdir: cannot create directory ‘lots/of/nested/folders’: No such file or directorysteve@surface01:folder$ mkdir -p lots/of/nested/folderssteve@surface01:folder$ lslotssteve@surface01:folder$ du -a4 ./lots/of/nested/folders8 ./lots/of/nested12 ./lots/of16 ./lots20 .steve@surface01:folder$ find .../lots./lots/of./lots/of/nested./lots/of/nested/folderssteve@surface01:folder$
Notice that we used the
command to see all of the folders. While
stands for disk utilization, it can also be helpful to show an entire folder structure rather than a single directory. Another option to perform the same task is
.
rmdir
rmdir
If you want to remove a directory,
is the way to go.
steve@surface01:folder$ mkdir imgsteve@surface01:folder$ lsimgsteve@surface01:folder$ rmdir imgsteve@surface01:folder$ lssteve@surface01:folder$
It doesn't always work though. What if the directory has something in it?
steve@surface01:folder$ lssteve@surface01:folder$ mkdir testdirsteve@surface01:folder$ touch testdir/testfile.txtsteve@surface01:folder$ find .../testdir./testdir/testfile.txtsteve@surface01:folder$ rmdir testdirrmdir: failed to remove 'testdir': Directory not emptysteve@surface01:folder$ lstestdirsteve@surface01:folder$
In order to delete a directory with something in it, we'll have to use the
command, explained below.
mv
mv
The
command serves two purposes. You can move a file, and you can also rename a file. If you think about it, this is pretty much the same thing anyway. If you rename a file, it's a lot like you're moving it to a new path in the same directory.
steve@surface01:folder$ touch myfile.txtsteve@surface01:folder$ lsmyfile.txtsteve@surface01:folder$ mv myfile.txt not_my_file.txtsteve@surface01:folder$ lsnot_my_file.txtsteve@surface01:folder$
rm
rm
Sadly, we have to let some of our files go sometimes. When that time comes,
lets you remove files.
steve@surface01:folder$ lsnot_my_file.txtsteve@surface01:folder$ rm not_my_file.txtrm: remove regular empty file 'not_my_file.txt'? ysteve@surface01:folder$ lssteve@surface01:folder$
So long!
What if you want to remove a directory? You'll have to use
instead. The
stands for recursive.
steve@surface01:folder$ lssteve@surface01:folder$ mkdir testdirsteve@surface01:folder$ touch testdir/testfile.txtsteve@surface01:folder$ find .../testdir./testdir/testfile.txtsteve@surface01:folder$ rm -r testdirrm: descend into directory 'testdir'? yrm: remove regular empty file 'testdir/testfile.txt'? yrm: remove directory 'testdir'? ysteve@surface01:folder$ lssteve@surface01:folder$
Notice how it asks you for every single file. If you're deleting a directory with thousands of files, this is not going to work. To force it to delete the files without asking, add
to the command:
steve@surface01:folder$ lssteve@surface01:folder$ mkdir testdirsteve@surface01:folder$ touch testdir/testfile.txtsteve@surface01:folder$ find .../testdir./testdir/testfile.txtsteve@surface01:folder$ rm -rf testdirsteve@surface01:folder$ lssteve@surface01:folder$
Be careful with this one, as you can damage your system beyond repair. Never run anything like
as you will delete everything (assuming you have permission) and brick your system. It's like deleting system32 on Windows - anyone telling you to run this command does not have good intentions!
Wrap UpWell done - you now know the basics of navigating around a Linux system.
If you enjoyed this article, please subscribe to our mailing list using the form below. Thanks for reading!