diff --git a/docs/Intro_to_Unix/Intro_to_Unix_Part_1.html b/docs/Intro_to_Unix/Intro_to_Unix_Part_1.html index 4f43156..fbd0ae9 100644 --- a/docs/Intro_to_Unix/Intro_to_Unix_Part_1.html +++ b/docs/Intro_to_Unix/Intro_to_Unix_Part_1.html @@ -324,6 +324,9 @@

Shell commands are basic instructions used to perform specific tasks.

command_name -[option(s)] [argument(s)]

Example:

+
+
ls -lah part_1
+

Here we are providing multiple options to the ls command and the directory part_1 as an argument

+
message="Hello, World"
+echo $message
Hello, World
@@ -613,6 +621,9 @@ macOS 14.4 January 9, 2021 macOS 14.4
  • You can also cycle through previously run commands using the up and down arrow keys
  • By default bash stores the last 500 commands, zsh stores the last 1000
  • +
    +
    history
    +
    @@ -660,7 +671,7 @@ What is the realative path to file1.txt if the working director

    pwd: print working directory

    -
    pwd
    +
    pwd
    @@ -674,7 +685,7 @@ What is the realative path to file1.txt if the working director

    ls: list contents of a directory

    -
    ls .
    +
    ls .
    part_1
     part_2
    @@ -687,11 +698,11 @@ unix_workshop.tar.gz
  • -h file sizes in human readable format (e.g., 1K, 2G)
  • -
    ls -lah part_1
    +
    ls -lah part_1
    total 8
    -drwx---r--@ 4 nelphick  staff   128B Nov 11 10:58 .
    -drwxr-xr-x@ 6 nelphick  staff   192B Nov 11 10:58 ..
    +drwx---r--@ 4 nelphick  staff   128B Nov 11 11:00 .
    +drwxr-xr-x@ 6 nelphick  staff   192B Nov 11 11:00 ..
     -rw-r--r--@ 1 nelphick  staff     0B Apr 11  2023 .hidden_file.txt
     -rw-r--r--@ 1 nelphick  staff    60B Apr 12  2023 list_numbers.tsv
    @@ -700,8 +711,8 @@ drwxr-xr-x@ 6 nelphick staff 192B Nov 11 10:58 ..

    cd: move to a directory

    -
    cd unix_workshop/part_1
    -ls -l
    +
    cd unix_workshop/part_1
    +ls -l
    @@ -710,14 +721,14 @@ drwxr-xr-x@ 6 nelphick staff 192B Nov 11 10:58 ..
    -
    cd ..
    -ls -l
    +
    cd ..
    +ls -l
    total 8
    -drwx---r--@ 4 nelphick  staff   128 Nov 11 10:58 part_1
    -drwxr-xr-x@ 3 nelphick  staff    96 Nov 11 10:58 part_2
    +drwx---r--@ 4 nelphick  staff   128 Nov 11 11:00 part_1
    +drwxr-xr-x@ 3 nelphick  staff    96 Nov 11 11:00 part_2
     -rw-r--r--  1 nelphick  staff  1790 Nov 11 10:43 unix_workshop.tar.gz
    @@ -755,7 +766,7 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2

    touch: create an empty file

    -
    touch new_file.txt
    +
    touch new_file.txt
    • If the file exists, it will update the time stamp
    • @@ -764,7 +775,7 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2

      mkdir: make a directory

      -
      mkdir new_directory
      +
      mkdir new_directory
      • -p make parent directories if they don’t exist
      • @@ -773,19 +784,19 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2

        mv: move a file or folder

        -
        mv new_file.txt new_directory
        +
        mv new_file.txt new_directory
        • Also used to rename files/folders
        -
        mv new_directory/new_file.txt new_directory/new_file1.txt
        +
        mv new_directory/new_file.txt new_directory/new_file1.txt

        cp: copy a file or folder

        -
        cp new_directory/new_file1.txt new_directory/new_file2.txt
        +
        cp new_directory/new_file1.txt new_directory/new_file2.txt
        • -r to copy a folder (recursive)
        • @@ -797,13 +808,13 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2
        • This command should always be used with care since the files it is used on cannot be recovered
        -
        rm new_directory/new_file2.txt
        +
        rm new_directory/new_file2.txt

        du: check the size of a file or folder

        -
        du -h */*
        +
        du -h */*
          0B    new_directory/new_file1.txt
         4.0K    part_1/list_numbers.tsv
        @@ -827,7 +838,7 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2

        nano

        -
        nano new_directory/new_file1.txt
        +
        nano new_directory/new_file1.txt
        @@ -876,7 +887,7 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2
      • curl supports multiple protocols but the most commonly used one is HTTPS
      -
      curl -o part_2/homo_sapiens.refseq.tsv.gz https://ftp.ensembl.org/pub/current_tsv/homo_sapiens/Homo_sapiens.GRCh38.115.refseq.tsv.gz
      +
      curl -o part_2/homo_sapiens.refseq.tsv.gz https://ftp.ensembl.org/pub/current_tsv/homo_sapiens/Homo_sapiens.GRCh38.115.refseq.tsv.gz
      • -o gives the output file name and location
      • @@ -892,7 +903,7 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2
    -
    scp /path/to/local/file user@remote.host:/path/to/remote/directory
    +
    scp /path/to/local/file user@remote.host:/path/to/remote/directory
    @@ -907,7 +918,7 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2
  • Regular Expressions : sequence of characters that forms a search pattern

  • -
    grep "7" part_1/list_numbers.tsv
    +
    grep "7" part_1/list_numbers.tsv
    7   8   52  13  6   42  79  1
     13  4   9   82  67  71  93  3
    @@ -935,7 +946,7 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2
    -
    grep "3$" part_1/list_numbers.tsv
    +
    grep "3$" part_1/list_numbers.tsv
    1   3   6   10  11  22  0   3
     13  4   9   82  67  71  93  3
    @@ -945,13 +956,13 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2

    head/tail: view the first or last n lines of a file

    -
    head -n 1 part_1/list_numbers.tsv
    +
    head -n 1 part_1/list_numbers.tsv
    1   3   6   10  11  22  0   3
    -
    tail -n 1 part_1/list_numbers.tsv
    +
    tail -n 1 part_1/list_numbers.tsv
    13  4   9   82  67  71  93  3
    @@ -964,7 +975,7 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2

    cat: print the contents of a file

    -
    cat part_1/list_numbers.tsv
    +
    cat part_1/list_numbers.tsv
    1   3   6   10  11  22  0   3
     7   8   52  13  6   42  79  1
    @@ -975,7 +986,7 @@ drwxr-xr-x@ 3 nelphick  staff    96 Nov 11 10:58 part_2
     

    cut: get specific columns from a file

    -
    cut -f 1-3,6 part_1/list_numbers.tsv
    +
    cut -f 1-3,6 part_1/list_numbers.tsv
    1   3   6   22
     7   8   52  42
    @@ -996,7 +1007,7 @@ drwxr-xr-x@ 3 nelphick  staff    96 Nov 11 10:58 part_2
     
  • Chaining commands allows you to do complex operations on text streams
  • -
    grep "3$" part_1/list_numbers.tsv | cut -f 1-3
    +
    grep "3$" part_1/list_numbers.tsv | cut -f 1-3
    1   3   6
     13  4   9
    @@ -1009,14 +1020,14 @@ drwxr-xr-x@ 3 nelphick staff 96 Nov 11 10:58 part_2
  • The output of any command can be written to a file with the ” > ” character
  • -
    grep "3$" part_1/list_numbers.tsv | cut -f 1-3 > part_1/subset_list_numbers.tsv
    +
    grep "3$" part_1/list_numbers.tsv | cut -f 1-3 > part_1/subset_list_numbers.tsv

    tr: translate or substitute characters

    -
    cat part_1/list_numbers.tsv | tr "\t" "," > part_1/list_numbers.csv
    -cat part_1/list_numbers.csv
    +
    cat part_1/list_numbers.tsv | tr "\t" "," > part_1/list_numbers.csv
    +cat part_1/list_numbers.csv
    1,3,6,10,11,22,0,3
     7,8,52,13,6,42,79,1
    @@ -1027,7 +1038,7 @@ drwxr-xr-x@ 3 nelphick  staff    96 Nov 11 10:58 part_2
     

    sort: sort values

    -
    cat part_1/list_numbers.csv | cut -d "," -f 1 | sort -n
    +
    cat part_1/list_numbers.csv | cut -d "," -f 1 | sort -n
    1
     7
    @@ -1038,7 +1049,7 @@ drwxr-xr-x@ 3 nelphick  staff    96 Nov 11 10:58 part_2
     
  • -n : sort numerically (default is alphabetical)
  • -
    cat part_1/list_numbers.csv | cut -d "," -f 8 | sort -nu
    +
    cat part_1/list_numbers.csv | cut -d "," -f 8 | sort -nu
    1
     3
    diff --git a/docs/Intro_to_Unix/Intro_to_Unix_Part_2.html b/docs/Intro_to_Unix/Intro_to_Unix_Part_2.html index 75232ff..3ad1266 100644 --- a/docs/Intro_to_Unix/Intro_to_Unix_Part_2.html +++ b/docs/Intro_to_Unix/Intro_to_Unix_Part_2.html @@ -306,9 +306,9 @@ ls -l
    total 16
    -drwx---r--@ 4 nelphick  staff   128 Nov 11 11:00 part_1
    --rw-r--r--  1 nelphick  staff   800 Nov 11 11:00 part_1.tar.gz
    -drwxr-xr-x@ 4 nelphick  staff   128 Nov 11 11:00 part_2
    +drwx---r--@ 4 nelphick  staff   128 Nov 11 12:31 part_1
    +-rw-r--r--  1 nelphick  staff   800 Nov 11 12:32 part_1.tar.gz
    +drwxr-xr-x@ 4 nelphick  staff   128 Nov 11 12:32 part_2
     -rw-r--r--  1 nelphick  staff  1790 Nov 11 10:43 unix_workshop.tar.gz
    @@ -473,7 +473,7 @@ ENSG00000149527 ENST00000449969 ENSP00000397289 XM_047435038 RefSeq_mRNA_pred
    ls -l part_2/example_script.sh
    -
    -rw-r--r--  1 nelphick  staff  287 Nov 11 11:00 part_2/example_script.sh
    +
    -rw-r--r--  1 nelphick  staff  287 Nov 11 12:32 part_2/example_script.sh
      @@ -483,7 +483,7 @@ ENSG00000149527 ENST00000449969 ENSP00000397289 XM_047435038 RefSeq_mRNA_pred
      chmod u+x part_2/example_script.sh
       ls -l part_2/example_script.sh
      -
      -rwxr--r--  1 nelphick  staff  287 Nov 11 11:00 part_2/example_script.sh
      +
      -rwxr--r--  1 nelphick  staff  287 Nov 11 12:32 part_2/example_script.sh
    diff --git a/intro-unix-command-line/Intro_to_Unix_Part_1.qmd b/intro-unix-command-line/Intro_to_Unix_Part_1.qmd index cc31976..fa39332 100644 --- a/intro-unix-command-line/Intro_to_Unix_Part_1.qmd +++ b/intro-unix-command-line/Intro_to_Unix_Part_1.qmd @@ -142,6 +142,7 @@ Shell commands are basic instructions used to perform specific tasks. Example: ```{bash} #| eval: false +#| echo: true ls -lah part_1 ``` @@ -151,6 +152,11 @@ Here we are providing multiple options to the `ls` command and the directory **p ## man: pull up the manual page for a command +```{bash} +#| echo: true +#| eval: false +man echo +``` ```{bash} @@ -172,6 +178,7 @@ man -P cat man | col -b - **Variables** : a named container that holds a value or data - **Strings** : sequence of characters ```{bash} +#| echo: true message="Hello, World" echo $message ``` @@ -183,6 +190,8 @@ Here, we assign the string "Hello, World!" to the variable `message` and use ech - By default bash stores the last 500 commands, zsh stores the last 1000 ```{bash} +#| echo: true +#| eval: false history ```