Gentle introduction to the command line

From BITS wiki
Jump to: navigation, search
Go back to parent page Introduction to Linux for bioinformatics

Tutorial on core commands of the linux command line

We will first hold your hand: type over these commands below step by step, and watch what they do.

Use cd to change the current working directory (user = bits). To create your own directories use the mkdir (make directory) command.

$ cd ~
$ mkdir sequences
$ cd sequences
$ mkdir proteins
$ cd proteins
$ pwd
/home/bits/sequences/proteins
$ cd ../..
$ pwd
/home/bits

To create a new file, use the touch command:

$ cd ~/sequences/proteins/
$ touch my_sequence.txt
$ ls -l
-rw-r--r-- 1 bits users 0 Sep 19 15:56 my_sequence.txt

In the last command above, the -l (a lowercase “L”, not a “1” (one)) option was used with the ls command. The -l indicates that you want the directory contents shown in the “long listing” format.

Most commands accept options. But which options can you use? The command man helps you. Type man followed by the command name. E.g. man ls to see what options are available for the ls command. You get a the list of options. Keep pressing Space until the page stops scrolling, then enter “q” to return to the command prompt

Luckily, most tools have the --help option. (ls --help for example). These 2 methods should help you further. usually provides information. To see what options can be used with ls, enter man ls.

$ man ls

To delete a file, use the rm (remove) command:

$ cd ~/sequences/proteins/
$ ls
my_sequence.txt
$ rm my_sequence.txt
$ ls
$

To remove a directory, use the rmdir (remove directory) command. The directory needs to be empty to do this.

$ cd ~/sequences/
$ ls
proteins
$ rmdir proteins
$ ls
$

To copy a file, use the cp (copy) command:

$ cd ~/sequences
$ touch testfile1
$ ls
testfile1
$ cp testfile1 testfile2
$ ls
testfile1 testfile2

To rename a file, or to move it to another directory, use the mv (move) command:

$ cd 
$ touch testfile3
$ mv testfile3 junk
$ mkdir testdir
$ mv junk testdir
$ ls testdir
junk

To download a file, use the wget command:

$ cd ~/Downloads
$ wget http://data.bits.vib.be/pub/trainingen/Linux/sample.sam
$ ls sample.sam
$

The commands covered so far represent a small but useful subset of the many commands available on a typical Linux system.

Make a project folder structure

We assume that start from your home folder.


Go back to parent page Introduction to Linux for bioinformatics