Trainings 2019 – Linux For Dummies – Practice

Description Hands On Lab Exercises for Linux
Authors Christine Tranchant-Dubreuil (
Creation Date 26/02/2018
Last Modified Date 19/03/2019
Modified by Gautier Sarah (
Modified by Christine Tranchant (



Getting connected to a Linux servers from Windows with SSH (Secure Shell) protocol
Platform Software Description url
mobaXterm An enhanced terminal for Windows with an X11 server and a tabbed SSH client More
Transferring and copying files from your computer to a Linux servers with SFTP (SSH File Transfer Protocol) protocol
Platform Software Description url
filezilla FTP and SFTP client Download
Viewing and editing files on your computer before transferring on the linux server or directly on the distant server
Type Software url
Distant, consol mode nano Tutorial
Distant, consol mode vi Tutorial
Distant, graphic mode komodo edit Download
Linux & windows based editor Notepad++ Download

Practice 1 : Transferring files with filezilla sftp

Download and install FileZilla
Open FileZilla and save the cluster adress into the site manager

In the FileZilla menu, go to File > Site Manager. Then go through these 5 steps:

  1. Click New Site.
  2. Add a CUSTOM NAME for this site such as IRD_HPC or AGAP_HPC.
  3. Add the HOSTNAME (see table below).
  4. Set the Logon Type to "Normal" and insert your username and password used to connect on the IRD/CIRAD HPC
  5. Press the "Connect" button.
Cluster HPC hostname
Transferring files

  1. From your computer to the cluster : click and drag an text file item from the left local colum to the right remote column
  2. From the cluster to your computer : click and drag an text file item from he right remote column to the left local column

Practice 2 : Get Connecting on a linux server by ssh

In mobaXterm:

  1. Click the session button, then click SSH.
    • In the remote host text box, type: HOSTNAME (see table below)
    • Check the specify username box and enter your user name
  2. In the console, enter the password when prompted.
    Once you are successfully logged in, you will use this console for the rest of the lecture.
Cluster HPC hostname

Practice 3 : First steps : prompt & pwd

  • What is the current/working directory just by looking the prompt?
  • Check the name of your working directory with pwd command?
  • On the console, type your 2 first linux commands to get data necessary for the next (we will explain the two commands latter):
# get the file on the web

# decompress the gzip file
tar -xzvf LINUX-TP.tar.gz
  • Check through filezilla the content of your home directory on the server now (cf. filetree just below)
  • Delete through filezilla the file LINUX-TP.tar.gz on the server

Practice 4 : List the files using ls command

  • List the content of your home directory
  • List the content of the directory Fasta by using its absolute path in first then its relative path - ls command
  • List the content of the directory Data with the lscommand and the option -R
  • List the content of the directory Bank with the lscommand and the option -al or -a -l

Practice 5 : List the files using MARKDOWN_HASH44ba5ca65651b4f36f1927576dd35436MARKDOWNHASH command and metacharacter *_

  • List the content of the directory T-coffee. Are there only fasta files ? - ls command
  • List only the files starting by sample (in the directory T-coffee ) - MARKDOWN_HASH44ba5ca65651b4f36f1927576dd35436MARKDOWNHASH command & *_
  • List only the files with the fasta extension (in the directory T-coffee ) - MARKDOWN_HASH44ba5ca65651b4f36f1927576dd35436MARKDOWNHASH command & *_

Practice 6 : Moving into file system using cdand ls command

  • Go to the directory Script and check in the prompt you have changed correctly your working directory (pwd).
  • List the dir content with ls.
  • Go to the Fasta directory using ../
  • Go to the Fastq directory . From this directory, and without any change in your working dir, list what's in samBam directory
  • List vcfdirectory using -R option. What is there in this dir ?
  • Come back to the home directory.

Practice 7 : Manipulating Files and Folders

We will prepare our blast analysis performed after by creating directory and moving files as showing in the image just below :

  • Create a directory called BlastAnalysis with mkdircommand.
  • Move transcritsAssembly.fasta into this new directory with mv command.
  • List the content of LINUX-TPand BlastAnalysis with ls command.
  • Copy AllEst.fasta in Bank directory with cp command.
  • List the content of LINUX-TPand Bank directories. What are the differences between mv and cp?
  • Remove the file AllEst.fasta in LINUX-TP directory with rm command.
  • Copy the whole directory T-coffee with the name T -coffee-copyinto LINUX-TPdirectory.
  • After checking the content of LINUX-TPdirectory, remove the directory T-coffee-copy. How to remove a directory ?
  • Remove all the files into the directory T-coffee-copy with rm * command.
  • Remove the directory T-coffee-copy.

Practice 8 : Searching with grep

wget gff_url
  • After checking the content of your current directory, what have you done with the $wgetcommand?
  • Displays the firsts and lasts lines of the gff file
  • Prints the number of lines with the word genes in the gff file
  • Counts the number of genes
  • Searchs for the nbs-lrr genes
  • Removes the lines with putative word

Practice 9 : Blast analysis

Creating a custom database with makeblastdb

As we use a custom database for the first time, If we have a fasta format file of these sequences we have to create a database from our fasta format file AllEst.fasta with the makeblastdb command.

  • Go into the bank directory and create a nucleotide database by typing:

    module load bioinfo/ncbi-blast/2.6.0
    makeblastdb -in AllEst.fasta -dbtype nucl -parse_seqids
  • List the content of the directory to check if the database has been indexed

BLASTing against our remote database
  • Go into the blastAnalysis directory
  • Run the blast by typing the following command with the outfmt equals to 6 :
blastn –query fastaFile -db databaseFile –outfmt [0-11]  -out resultFile
  • Output formats
The flag for the output format is -outfmt followed by a number which denotes the format request :

0 = pairwise,
1 = query-anchored showing identities,
2 = query-anchored no identities,
3 = flat query-anchored, show identities,
4 = flat query-anchored, no identities,
5 = XML Blast output,
6 = tabular,
7 = tabular with comment lines,
8 = Text ASN.1,
9 = Binary ASN.1,
10 = Comma-separated values,
11 = BLAST archive format (ASN.1)
  • Output tabular format (6 or 7): one line per results splitted in 12 fields.
1. query id
2. subject id
3. percent identity
4. alignment length
5. number of mismatche-
6. number of gap openings
7. query start
8. query end
9. subject start
10. subject end
11. expect value
12. bit score
Parsing the results file
  • Display the first 10 lines of the file - head
  • Display the first 15 lines of the file - head
  • Display it last 15 lines - tail
  • Count the number of line - wc
  • Sort the lines using the second field (subject id) by alphabetical order, ascending then descending - sort
  • Sort lines by e‐value (ascending) and by “alignment length” (descending) - sort
  • Extract the first 4 fields - cut
  • Extract query id, subject id, evalue, alignment length cut

Practice 11 : Redirecting a command output to a File with >

  • Extract all ESTs identifiers and print them in the file ESTs_accession.list - cut >

Practice 12 : Sending data from one command to another (piping) with |

  • How many sequences have a homology with EST sequences ? (TIPs: cut command with sort -u (uniq) or uniq command ))
  • Extract ESTs sequences from database with blastdbcmd by typing :
blastdbcmd -entry_batch hits.txt -db bank -out hits.fasta 
 -entry_batch is the file containing the sequence names 
  • Count the number of sequences extracted - grep ">" c
  • Get the help of infoseq program - infoseq --h
  • Run infoseq program on your fasta file created just before
    infoseq -sequence FASTA_FILE | head
  • Display only accession, length and pgc column either with cut command or directly with infosee
  • What is the shorthest sequence (Accession and length)?
  • What is the longuest sequence (Accession and length)?

Practice 12 : Dealing with vcf Files

  • List the content of the directory /scratch/VCF_LINUX
  • Before creating your directory /scratch/VCF_LINUX_FORMATIONX, displays the amount of disk space available on the file system with the command df
  • Create your directory the directory /scratch/VCF_LINUX_FORMATIONXand go into it.
  • Create a shortcut of the different vcf file in the directory /scratch/VCF_LINUX with the command ln -s source_file myfile

For example


Thus, OgOb-all-MSU7-CHR6.GATKVARIANTFILTRATION.LINK.vcf is the name of the new file containing the reference to the file named OgOb-all-MSU7-CHR6.GATKVARIANTFILTRATION.vcf.

  • Repeat the same operation with the other vcf files
  • List the content of the directory VCF_LINUX_FORMATIONX with ls -l
  • Display the size of each vcf files in the directory /scratch/VCF_LINUX then in your directory /scratch/VCF_LINUX_FORMATIONX - du
  • Display the size of the directory /scratch/VCF_LINUX and the directory /scratch/VCF_LINUX_FORMATIONX - du
  • Displays the first lines of the vcf files - headcommand
  • Displays the last lines of the vcf files - tail command
  • Count the lines of the vcf files - wc -l command

Practice 13 : Filtering VCF files | - grep

To get some basics stats of the output VCF files, let's use linux command!

  • How many polymorphisms were detected (Displaying all the lines which does not start with # / header lines) in the different vcf files ?
  • How many polymorphisms were considered "good" after filtering steps by GATK VARIANTFILTRATION (ie marked PASS)?
  • How many polyporphisms were considered "bad" and filtered out (Displaying all the lines without the PASS tag )?
  • Save only the "good" polymorphisms detected that were considered "good" in a new file called OgOb-all-MSU7-CHR6.GATKVARIANTFILTRATION.GOOD.vcf
  • Display the size of this new vcf files

Practice 14 : Getting basic stats

  • Go into the directory LINUX-TP/Data/fastq/pairedTwoIndividusGzippedIrigin - cd
  • List the directory content
  • Run fastq-stats program ( more to get stats about the fastq file irigin1_1.fastq.gz
    fastq-stats -D irigin1_1.fastq.gz
  • BONUS :
    Use a for loop to run fastq-stats with every fastq file in the directory

    for file in *fastq; do 
    fastq-stats -D $file > $file.fastq-stats ; 


How to convert between Unix and Windows text files?

The format of Windows and Unix text files differs slightly. In Windows, lines end with both the line feed and carriage return ASCII characters, but Unix uses only a line feed. As a consequence, some Windows applications will not show the line breaks in Unix-format files. Likewise, Unix programs may display the carriage returns in Windows text files with Ctrl-m (^M) characters at the end of each line.

There are many ways to solve this problem as using text file compatible, unix2dos / dos2unix command or vi to do the conversion. To use the two last ones, the files to convert must be on a Linux computer.

use notepad as file editor on windows

When using Unix files on Windows, it is useful to convert the line endings to display text files correclty in other Windows-based or linux-based editors.

In Notepad++: Edit > EOL Conversion > Windows Format

unix2dos & dos2unix

# Checking if my fileformat is dos
[tranchant@master0 ~]$ cat -v test.txt

# Converting from dos to linux format
[tranchant@master0 ~]$ dos2unix test.txt
dos2unix: converting file test.txt to Unix format ...
[tranchant@master0 ~]$ cat -v test.txt

# Converting from linux to dos format
[tranchant@master0 ~]$ unix2dos test.txt
unix2dos: converting file test.txt to DOS format ...
[tranchant@master0 ~]$ cat -v test.txt
[tranchant@master0 ~]$
  • In vi, you can remove carriage return ^M characters with the following command: :1,$s/^M//g
  • To input the ^M character, press Ctrl-v, and then press Enter or return.
  • In vim, use :set ff=unix to convert to Unix; use :set ff=dos to convert to Windows.

How to open and read a file through a text editor on a distant linux server?




Komodo Edit

After installing Komodo Edit, open it and click on Edit –> Preferences

Select Servers from the left and enter sftp account information, then save it.

To edit a distant content, click on File –> Open –> Remote File

Getting Help on any command-line

with the option --help

Virtually all commands understand the -h (or --help) option, which produces a short usage description of the command and its options.

[tranchant@master0 ~]$ ls --help
Utilisation : ls [OPTION]... [FILE]...
Afficher des renseignements sur les FILEs (du répertoire actuel par défaut).
Trier les entrées alphabétiquement si aucune des options -cftuvSUX ou --sort
ne sont utilisées.

Les arguments obligatoires pour les options longues le sont aussi pour les
options courtes.
  -a, --all                  ne pas ignorer les entrées débutant par .
  -A, --almost-all           ne pas inclure . ou .. dans la liste
      --author               avec -l, afficher l'auteur de chaque fichier
  -b, --escape               afficher les caractères non graphiques avec des
                               protections selon le style C
      --block-size=SIZE      convertir les tailles en SIZE avant de les
                               afficher. Par exemple, « --block-size=M » affiche
                               les tailles en unités de 1 048 576 octets ;
                               consultez le format SIZE ci-dessous
  -B, --ignore-backups       ne pas inclure les entrées se terminant par ~ dans
                               la liste
  -c                         avec -lt : afficher et trier selon ctime (date de
                               dernière modification provenant des informations
                               d'état du fichier) ;
                               avec -l : afficher ctime et trier selon le nom ;
                               autrement : trier selon ctime
  -C                         afficher les noms en colonnes
      --color[=WHEN]         colorier la sortie ; par défaut, WHEN peut être
                               « never » (jamais), « auto » (automatique) ou
                               « always » (toujours, valeur par défaut) ; des
                               renseignements complémentaires sont ci-dessous
  -d, --directory            afficher les noms de répertoires, pas leur contenu

with the man command

Every command and nearly every application in Linux has a man (manual) file, so finding such a file is as simple as typing man command to bring up a longer manual entry for the specified command.

# Type man ls to display the related manual

LS(1)                                      Manuel de l'utilisateur Linux                                      LS(1)

       ls, dir, vdir - Afficher le contenu d'un répertoire

       ls [options] [fichier...]
       dir [fichier...]
       vdir [fichier...]

       Options POSIX : [-CFRacdilqrtu1] [--]

       Options  GNU  (forme  courte)  :  [-1abcdfgiklmnopqrstuvwxABCDFGHLNQRSUX]  [-w  cols]  [-T  cols] [-I motif]
       [--full-time]  [--show-control-chars]   [--block-size=taille]   [--format={long,verbose,commas,across,verti‐
       cal,single-column}]       [--sort={none,time,size,extension}]       [--time={atime,access,use,ctime,status}]
       [--color[={none,auto,always}]] [--help] [--version] [--]

       La commande ls affiche tout d'abord l'ensemble de ses arguments fichiers autres que des répertoires. Puis ls
       affiche  l'ensemble  des  fichiers  contenus  dans chaque répertoire indiqué. Si aucun argument autre qu'une
       option n'est fourni, l'argument « . » (répertoire en cours) est pris  par  défaut.  Avec  l'option  -d,  les
       répertoires  fournis  en argument ne sont pas considérés comme des répertoires (on affiche leurs noms et pas
       leurs contenus). Un fichier n'est affiché que si son nom ne commence pas par un point, ou si l'option -a est

       Chacune  des  listes  de fichiers (fichiers autres que des répertoires, et contenu de chaque répertoire) est
       triée séparément en fonction de la séquence d'ordre de la localisation en cours.  Lorsque  l'option  -l  est

Some helpful tips for using the man command :

  • Arrow keys: Move up and down the man file by using the arrow keys.
  • q: Quit back to the command prompt by typing q.



The resource material is licensed under the Creative Commons Attribution 4.0 International License (here).