Skip main navigation

Command Line Basics

basic Linux commands
7.6
Hello, I’m Martin Aslett. In this video, I will show you some of the most important and frequently used commands in Linux. These will enable you to navigate and view the file system. For these purposes, I’m using Ubuntu 20.04, but it’s running on a MacBook Pro using software called VirtualBox. To start, I will open the terminal using the icon here. And then I will maximise the terminal here. The first command I will show you is called pwd. This stands for present working directory and shows us where in the file system our prompt currently is To run it, simply type pwd. This shows us where in the file system we currently are. In this case, we’re in a directory called /home/manager.
64.9
The next thing to show you is how to move around the directory structure. To do this, we use a command called cd which stands for change directory. Before running cd, I will run a command called ls, which stands for list, which shows the contents of the current directory. I’ll go into the details of ls later in this video. Running ls, we can see that there’s a directory called course_data. To go into course_data we simply type cd course_data.
100
We can now see that we’re in the course_data directory. I’ll type ls to show the contents of this directory. One important thing to know is that wherever you are in the directory structure, typing cd with nothing afterwards will take you back to your home directory. Here I type cd, and then pwd to show we’re back in /home/manager. cd can also be used to tap the full path of the directory rather than just the relative path as we saw earlier. To get to the course_data directory with the full path, I would type cd /home/manager/course_data.
148.8
Then type pwd. This shows that this does the same as just typing cd course_data did earlier when we were in the home directory. Lastly for cd, by convention typing two dots after the cd command takes you back up one directory in the directory tree. Hence, from /home/manager/course_data, if I type cd . .
180.6
We are now in /home/manager.
186
Probably go on. Sometimes your terminal can become very cluttered and a little bit confusing. If you wish to clear this, simply type the command clear. At this point your prompt will show, but none of the previous output will. At this point, we will return to the command ls, which stands for list, and lists the contents of a directory. At its most basic, simply type ls. This shows all of the contents. Before moving on with ls, I’ll briefly explain what command line options are. An option follows the command, usually started with a minus sign, and then a single letter. This gives the command an instruction to do something slightly more detailed than just its basic purpose.
238.6
For example, with ls, I can type ls space -l.
245.3
This lists the contents of the directory in its longer form. You can see things like dates. These are the dates when the files were created or modified. We get the owner of the file, the size, the d here actually indicates that everything is a directory. The -l option stands for long. In other words, a more detailed listing. Other options can be useful. One of these is -t, which sorts files by time. Options can be combined by listing them successively after the minus sign. So if I type ls -lt, it shows the files sorted by time. We may wish to reverse this list, in which case we add in the -r option. So I can type ls -ltr.
301.3
You’ll notice that now the course_data directory is showing at the bottom of this list because it was the last to be modified. At this point I will clear my screen. Sometimes in Unix, there are files called hidden files. These, by convention, start with a full stop with no letters beforehand. By convention they also aren’t shown up in ls by default. To list these, include the -a option. If I do this in my Home directory, do ls -al you can see there are several files, such as .bash_history which start with the dots. Those weren’t being listed previously. In addition to options, Unix commands can also take arguments. Arguments are the items on which the command is to be run.
356.5
We’ve already used arguments when we cd’d into the course_data directory in which course_data was the argument. Within ls, this can be a directory, which you want to list the content of. For example, I can type ls -l course_data.
377.6
This lists the content of the course_data directory along with file sizes, date of creation of files, owner of files, et cetera. Next, we will look at how to move files around and copy them, and also how to create directories and delete files and directories. To demonstrate these things, I will first cd into the course_data directory and then clear my screen. When I do ls, you’ll notice there are many files in this directory. We may therefore want to sort them into subdirectories. If you notice, there’s a file called test_Session1.vcf. I’ll make a directory called VCF. I do this using the command mkdir and then just typing the name of the directory I want. VCF in capitals.
434.6
By running ls -l, I can show that there is a new subdirectory called VCF.
444.5
I want to move the VCF file test_Session1.vcf into the directory VCF. I have two choices. Doing it the long hand way, I can use the command cp, or copy, and then copy test_Session1.vcf into VCF.
470.3
Running ls -l on VCF shows that test_Session1.vcf is in there. Running ls -l on the current directory shows that it is also still in the current directory. If I decide I want to delete test_Session1.vcf, I can simply type rm for remove, and then test_Session1.vcf and delete it. When I run ls -l test_Session1.vcf is no longer present. The same process can be done more concisely using the command mv, which stands for move. This means you don’t have to copy the file and then delete it. You can just use one single command, mv. I’ll actually do the process in reverse. To move test_Session1.vcf out of the VCF directory and into the current directory, which is course_data.
534.4
So I type mv VCF/test_Session1.vcf and then dot. The dot stands for the current directory. It’s a shorthand notation. I’ll then do ls -l.
559.6
You can see that test_Session1.vcf is back in this directory. To tidy things up, I remove the VCF directory. This can be done by using the command rm, which you’ve seen before, but with the -r option, which stands for recursive. rm -r VCF. And again if I do ls -l, the VCF directory is no longer there. You’ve now learned several of the basic commands for Linux. How do you find out more about them? One thing that Linux has is a command called man, which stands for manual. Most commands have a manual page which give you details of how you use them and the options that they have available. For example, I will type man ls this shows the manual.
614.7
Tells you the ls list directory contents, gives a brief synopsis, and then a description which includes all of the options. -a, -c, -g, there are many options.
631
If I scroll through with the spacebar you get an idea of all of them. And then I can press Q to quit man. Thank you for watching this video. I hope you enjoyed it. Please leave any questions and comments in the comments section.

In this video, Martin is presenting basic Linux commands pwd, cd, ls, rm, mv, mkdir, man.

You are welcome to type along, but please beware that you can permanently delete files using some of these commands !

This article is from the free online

Bioinformatics for Biologists: An Introduction to Linux, Bash Scripting, and R

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now