{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# First steps on Linux\n",
    "\n",
    "Commands for *moving around the file system* and *manipulating files/folders*\n",
    "\n",
    "<img style=\"float: left;\" width=\"800\" height=\"800\"  src=\"https://upload.wikimedia.org/wikipedia/commons/f/f3/Standard-unix-filesystem-hierarchy.svg\">\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Linux command syntax\n",
    "\n",
    "command [ -options] [ arguments ]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Your first command _pwd_\n",
    "\n",
    "**pwd** print the name of the curent directory (the full path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/christine/Documents/2023-Formation/transmittingScience/trainingts/2-JB/DAY1-2\n"
     ]
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img style=\"float: center;\" width=\"100%\" src=\"./tree.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2nd command _ls_\n",
    "\n",
    "* without argument : list all the files in the current directory (by default)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2nd command + option _ls -l_\n",
    "\n",
    "ls -l : _list files with more information about each file_ (long)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ls -l"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2nd command + argument\n",
    "\n",
    "with argument <=> directory path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ls PUT_HERE_DIRECTORY_NAME"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"http://vibepictures.com/wp-content/uploads/2014/02/avatar-tux-jedi-star-wars-linux-acatos1.png\"> \n",
    "\n",
    "        * list the content of the directory REF\n",
    "        \n",
    "<img style=\"float: center;\" width=\"100%\" src=\"./tree.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# A few Basic Commands\n",
    "\n",
    "How to get help about one command\n",
    "\n",
    "* with the ’option --help ou -h     \n",
    "* with the command man       "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# A few Basic Commands\n",
    "\n",
    "\n",
    "| |    |\n",
    "|------|------|\n",
    "|   pwd  | Display the full path of the current directory|\n",
    "|   ls  | List all files/directories|\n",
    "|   ls -l  | Display all files (Long listing)|\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# The file tree - file system\n",
    "\n",
    "*  Directory structure starts at the root directory called “/” (slash) \n",
    "\n",
    "<img style=\"float: center;\" width=\"500\" height=\"500\"  src=\"https://tranchant.github.io/TransmittingScience/img/arbo3.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"http://vibepictures.com/wp-content/uploads/2014/02/avatar-tux-jedi-star-wars-linux-acatos1.png\"> \n",
    "\n",
    "### It's your turn !\n",
    "\n",
    "\n",
    "        * list the content of the root directory"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# The file tree - Main directories\n",
    "\n",
    "<img style=\"float: center;\" width=\"500\" height=\"500\"  src=\"https://tranchant.github.io/TransmittingScience/img/arbo4.png\">\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Path of a file\n",
    "\n",
    "* Path =  location to a file/directory in the file system\n",
    "\n",
    "* On linux filetree, you can use absolute or relative path \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"https://i.pinimg.com/236x/a8/cc/00/a8cc00c8b1b3aa8d37749fd3e00eaa25--page-blogspot-com.jpg\"> \n",
    "        * What is the difference between the absolute and relative path ?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# In brief\n",
    "\n",
    "* Path =  location to a file/directory in the file system\n",
    "\n",
    "| ABSOLUTE  | RELATIVE   |\n",
    "|:------|:------|\n",
    "|  Complete path of a file <br />starting from the root directory /  | Path related to the present working directory <br /> (where the user is working) \n",
    "|\n",
    "|   starts always with / | Never starts with / |\n",
    "|   always good wherever user is working | Depends on where the user is working| \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Absolute Path \n",
    "\n",
    "* Always start with / (root directory)\n",
    "\n",
    "* Always works wherever user is working on the server or vm\n",
    "\n",
    "<img style=\"float: center;\" width=\"500\" height=\"500\"  src=\"https://tranchant.github.io/TransmittingScience/img/absolute1.png\">\n",
    "\n",
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"https://i.pinimg.com/236x/a8/cc/00/a8cc00c8b1b3aa8d37749fd3e00eaa25--page-blogspot-com.jpg\"> \n",
    "        * What is the absolute path of the file sequence.fasta ?\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Absolute Path \n",
    "\n",
    "* Always start with / (root directory)\n",
    "\n",
    "* Always works wherever user is working on the server or vm\n",
    "\n",
    "<img style=\"float: center;\" width=\"500\" height=\"500\"  src=\"https://tranchant.github.io/TransmittingScience/img/absolute2.png\">\n",
    "\n",
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"https://i.pinimg.com/236x/a8/cc/00/a8cc00c8b1b3aa8d37749fd3e00eaa25--page-blogspot-com.jpg\"> \n",
    "        * What is the absolute path of the  directory script ?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Relative Path \n",
    "\n",
    "* Path related to the present working directory\n",
    "\n",
    "* Never starts with /\n",
    "\n",
    "<img style=\"float: center;\" width=\"500\" height=\"500\"  src=\"https://tranchant.github.io/TransmittingScience/img/relative1.png\">\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"https://i.pinimg.com/236x/a8/cc/00/a8cc00c8b1b3aa8d37749fd3e00eaa25--page-blogspot-com.jpg\"> \n",
    "        * What is the relative path of the file sequence.fasta ?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Relative Path \n",
    "\n",
    "* Path related to the present working directory\n",
    "\n",
    "* Never starts with /\n",
    "\n",
    "<img style=\"float: center;\" width=\"500\" height=\"500\"  src=\"https://tranchant.github.io/TransmittingScience/img/relative2.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"https://i.pinimg.com/236x/a8/cc/00/a8cc00c8b1b3aa8d37749fd3e00eaa25--page-blogspot-com.jpg\"> \n",
    "        * What is the relative path of the  directory fasta ?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Rules for naming file and directory names\n",
    "\n",
    "* linux is case sensitive\n",
    "* Only ROMAN letters, numbers and _ -\n",
    "* No space, accent or special symbol\n",
    "* No need to use filename extension (.txt), just to improve readability of filenames. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Command _cd_\n",
    "\n",
    "* cd as Change Directory\n",
    "    \n",
    "* Move from the current directory into a new directory\n",
    "\n",
    "_cd DIRECTORY NAME (absolute or relative path)__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"https://i.pinimg.com/236x/a8/cc/00/a8cc00c8b1b3aa8d37749fd3e00eaa25--page-blogspot-com.jpg\"> \n",
    "        \n",
    "Move into the REF directory (absolute path)\n",
    "        \n",
    "<img style=\"float: center;\" width=\"100%\" src=\"./tree.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "PUT THE COMMAND"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"https://i.pinimg.com/236x/a8/cc/00/a8cc00c8b1b3aa8d37749fd3e00eaa25--page-blogspot-com.jpg\"> \n",
    "\n",
    "* Move into the SV_DATA directory (absolute path)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "PUT THE COMMAND"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img style=\"float: left;\" width=\"100\" height=\"100\"  src=\"https://i.pinimg.com/236x/a8/cc/00/a8cc00c8b1b3aa8d37749fd3e00eaa25--page-blogspot-com.jpg\"> \n",
    "\n",
    "* Move into the SHORT_READS directory (relative path)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "PUT THE COMMAND"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Some Commands\n",
    "\n",
    "\n",
    "| |    |\n",
    "|:------|:------|\n",
    "|   pwd  | Display the full path of the current directory|\n",
    "|   ls  | List all files/directories|\n",
    "|   cd DIR_NAME| Change the working directory|\n",
    "| rm nom_fichier | Remove a directory\n",
    "| cp file1 file2 | Make a copy of file1 and calls it file2 |\n",
    "| cp FILE_NAME DIR_NAME | Copy the file FILE_NAME in the directory DIR_NAME |\n",
    "| cp FILE DIR/NEW_FILE | Mix of 2 |\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# command cat\n",
    "\n",
    "cat nom_fichier \n",
    "Displays the content of a file on the screen\n",
    "(Don’t use it with big files!!)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cat _PUT_THE_CORRECT_PATH_TO_ASSEMBLIES/assembly-stats.txt_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# command wc\n",
    "\n",
    "* `wc -l`  : Displays the nomber of lines in a file\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "wc -l PUT_THE_CORRECT_PATH_TO_REF/GCA_002220235.1_ASM222023v1_genomic.gff"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# command head\n",
    "\n",
    "* `head nom_fichier`  : writes the first ten lines of a file to the screen\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "head PUT_THE_CORRECT_PATH_TO_ASSEMBLIES/GCA_002220235.1_ASM222023v1_genomic.gff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "head -n 20 PUT_THE_CORRECT_PATH_TO_ASSEMBLIES/GCA_002220235.1_ASM222023v1_genomic.gff"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# command tail\n",
    "\n",
    "* `tail nom_fichier`  : writes the last ten lines of a file to the screen\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tail PUT_THE_CORRECT_PATH_TO_ASSEMBLIES/GCA_002220235.1_ASM222023v1_genomic.gff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Download additional notebooks for practicing linux applied to bioinformatics analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Go into the correct directory to download notebook - cd command\n",
    "cd /home/jovyan/NOTEBOOK/DAY1-2 \n",
    "wget https://itrop.ird.fr/trainingts/notebook/DAY1-2/Day2_Linux_Exercice1.ipynb --no-check-certificate"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Format de la Cellule Texte Brut",
  "kernelspec": {
   "display_name": "Bash",
   "language": "bash",
   "name": "bash"
  },
  "language_info": {
   "codemirror_mode": "shell",
   "file_extension": ".sh",
   "mimetype": "text/x-sh",
   "name": "bash"
  },
  "rise": {
   "enable_chalkboard": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
