Skip to content
Snippets Groups Projects
Commit 656d8ed8 authored by jacques.dainat_ird.fr's avatar jacques.dainat_ird.fr
Browse files

update

parent e4ece8fb
No related branches found
No related tags found
No related merge requests found
Pipeline #2416 passed
Showing with 190 additions and 12 deletions
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -345,6 +345,24 @@ If your screen gets too cluttered, you can clear your terminal using the `clear`
clear
```
## Command Autocompletion
It exist a wonderful behavior in Bash called the autocompletion. What it is?
Autocompletion refers to a feature that allows you to automatically complete the names of **commands** and file paths by pressing the Tab key. This feature can significantly improve efficiency and reduce the need to type out long or complex names manually.
When you start typing a command and press the Tab key ↹, Bash will attempt to complete the command name based on the available commands.
If there is only one possible completion, it will be filled in automatically. If there are multiple possibilities, Bash will list them, and you can continue typing or press Tab again to cycle through the options.
!!! exercise
Let's try with the `history` command. Start by typing `his` and press the Tab key ↹.
What happens?
??? example "Click to show the solution"
Bash will automatically fill `history`
But is that the only command starting by history? Try to press the Tab key ↹ again.
??? example "Click to show the solution"
Apparently yes, it is the only one, othewise a list of command starting by `history` would have poped up this time.
!!! Success "Quick recap"
In this section we've learned a lot of things:
......@@ -357,3 +375,4 @@ clear
- How to set bash as shell (in case it is not your default shell)
- The existence of an history
- How to clear your terminal
- Autocompletion
......@@ -196,9 +196,22 @@ We are now in the `script` directory.
7. cd ~/data/..
9. cd /
### A final navigation tip
## File path Autocompletion
You are supposed to be in the `script` directory. Try the command `cd` without any argument. What happens? (check with `pwd`)
It exist a wonderful behavior in Bash called the autocompletion. What it is?
Autocompletion refers to a feature that allows you to automatically complete the names of commands and **file paths** by pressing the Tab key. This feature can significantly improve efficiency and reduce the need to type out long or complex names manually.
Bash can complete file paths based on what exists in the current directory or any specified path.
As you type a file or directory name and press Tab, Bash will complete the name if it's unique. If not, it will show a list of possible matches.
!!! exercise
Move to `data` directory via the absolute path using the autocompletion.
## A final navigation tip
You are supposed to be in the `data` directory now. Try the command `cd` without any argument. What happens? (check with `pwd`)
??? example "Click to show the solution"
Right you moved in the `home` directory. This command is even shorter than `cd ~`.
......
......@@ -222,15 +222,87 @@ Actually in a real world what we have done so far was not very recommended (copy
Fastq files are generaly huge. Doing a copy double the disk space used by the file, because now you have it twice. It is recommended when possible to avoid to make copies of huge files.
You may have continue to work on the `script1.sh` file located in the `script/` folder, but what if you forgot to copy the last version of it into your `analysis` directory?
There is a solution ease your life, giving you the simplicity to have a file locally (no need to think about the path) and to avoid to have a copy of the file. The **link**.
In your new bioinformatician life you will often need to acces files far away many times (e.g. input files for a local script) and you will have to deal with long path. Long paths can be annoying...
It exists the `hard link` and the `soft link`.
There is a solution to ease your life, giving you the simplicity to have a file locally (no need to think about the path), to avoid having a copy of the file and to avoid dealing with long path: The **link**!
xxxxxx
It exists two types of link: the `hard link` and the `soft link`.
## Autocompletion
### Hard link
You did realize how painfull it is to write paths? Actually bash is full of tricks and maybe you already found the `autocompletion` one. What it is and how it works?
It is kind of easy and you will use it evertime...
A file is actually a reference to an existing inode (data structure on the file system that stores information).
Making a hard link to a file is essentially setting an additional reference to the same inode.
All hard links pointing to the same inode share the same set of data blocks on the disk.
If you delete one hard link, the data is not actually removed from disk until the last hard link is deleted.
xxxx
\ No newline at end of file
![](../images/4-creation/hard_link.png){: style="height:350px"}
The hard link is made via the `ln` command.
```bash
ln existing_file [hard_link_name]
```
!!! Exercice
Create a Hard link of the `data` folder
??? example "Click to show the solution"
```ln ../data```
What do you see?
??? example "Click to show the solution"
It is actually not possible to hard link a directory
Run `ls -l` and then create a Hard link of the `data/data1.fa` file and run again `ls -l`
??? example "Click to show the solution"
```bash
ln ../data/data1.fa
```
create a Hard link of the `data/data1.fa` but with the choosen name `data1_hard.fa`
??? example "Click to show the solution"
```bash
ln ../data/data1.fa data1_hard.fa
```
Run again `ls -l`.
The second column is the number of hard links to the file. (For a directory, the number of hard links is the number of immediate subdirectories it has plus its parent directory and itself) We can see that we have currrently 3 "files" pointing to the same inode.
### Soft link
The `soft link` is also known as `symbolic link`. It is a special sort of file that points at a different file. You could think of it like a shortcut.
If you remove the original file, the link become inoperable.
![](../images/4-creation/soft_link.png){: style="height:350px"}
The solft link is made via the `ln -s` command.
```bash
ln -s existing_file [soft_link_name]
```
!!! Exercice
Create a Soft link of the `script` folder
??? example "Click to show the solution"
```ln -s ../script```
Run `ls -l`. What do you see?
??? example "Click to show the solution"
There is an extra arrow showing to what file my link point to.
Create a Hard link of the `script/script1.sh` file and run again `ls -l`
??? example "Click to show the solution"
```bash
ln -s ../data/data1.fa
ls -l
```
### Removing links
To remove links you can use `rm` like for files or the dedicated `unlink` command (the only difference is that unlink cannot remove directories).
!!! Exercice
Remove all the link we set: `data`, `data1.fa`, `data1_hard.fa`, `script`, `script1.sh`
!!! Success "Quick recap"
In this section we've learned:
- How to create files and directories
- How to move files and directories
- How to rename files and directories
- How to delete files and directories
- How to link files and directories
......@@ -109,4 +109,9 @@ Find a way print the following sentence `my value $var is 4 (interesting)` with
Bash is extraordinary powerfull, but stupid as any computer... it just applies rules. There are many characters with specific meanings and combined together it increase the complexity. That may become difficult for the user to read or understand. But bash it its side will just follow the rules!
!!! Success "Quick recap"
In this section we've learned:
- the use of single and double quotes and their behavior towards special characters.
- How to espace special characters with `\`
# Let's fo Further
# The PATH variable
The PATH environment variable (variable available by all shells) is very important, it specifies the directories to be searched to find a command absent from bash itself.
## Commands
When calling a tool, Bash will first look among commands shipped with him, then look at your current directory, and finally will look in order in all directories listed un the PATH variable.
It is how your computer access tools. There is no magic. The computer is just following some simple rules. If you call a tool unknown by Bash and not part of any path listed in $PATH, there is no way for your computer to guess where it is and will tell you `command not found`.
The only solution is to fill the full path to the tool you want to use (You must know where it is standing then).
###
1 commands, 2 coomadns etc.. pipe
save command in a variavle
var=$(pwd)
### The PATH variable
The PATH environment variable is very important, it specifies the directories to be searched to find a command.
BASH will alway try to find a
You can list the folder in which your bash is always looking at when trying to execute a command via:
```bash
......@@ -35,23 +28,12 @@ The paths are listed using the `:` separator.
which python3
```
Is that path part of $PATH?
It is how your cmputer access the tool. There is no magic. It is just following some rules. If you call a tool not part of a path listed in $PATH, there is no way for your computer to guess where it is and will tell you `command not found`.
### Autocompletion
### I/O of commmands
### Command pipes
## Scripting
## Comment
??? example "Click to show the solution"
yes
In bash, everything after the `#` special character is a comment and will be skipped.
You can check it by yourself:
!!! Success "Quick recap"
In this section we've learned:
```bash
echo # hello my command ls ; cd
```
- the PATH variable
- the logic how a command or a tool is found on the computer
When it will come the time to write scripts, you will have to use it extensively to comment your code...
\ No newline at end of file
# Commands
## Commands
###
1 commands, 2 coomadns etc.. pipe
save command results in a variavle
var=$(pwd)
### I/O of commmands
### Command pipes
# Loops
\ No newline at end of file
# Scripting
## Comment
In bash, everything after the `#` special character is a comment and will be skipped.
You can check it by yourself:
```bash
echo # hello my command ls ; cd
```
When it will come the time to write scripts, you will have to use it extensively to comment your code...
\ No newline at end of file
No preview for this file type
docs/pages/images/4-creation/hard_link.png

358 KiB

docs/pages/images/4-creation/soft_link.png

359 KiB

......@@ -96,9 +96,9 @@ nav:
- Introduction: pages/bash/bash-1-introduction.md
- The basics: pages/bash/bash-2-the-basics.md
- Navigating files and directories: pages/bash/bash-3-navigating.md
- Working with files and directories: pages/bash/bash-4-working_with_files_and_directories
- Tips: pages/bash/bash-4-tips.md
- Extra material: pages/bash/bash-5-let-us-go-futher.md
- Working with files and directories: pages/bash/bash-4-working_with_files_and_directories.md
- Quotes: pages/bash/bash-5-quotes.md
- Let us go further: pages/bash/bash-6-let-us-go-further.md
- Cheat sheet:
- Bash Cheat sheet: pages/cheat_sheet/bash/bash.md
- Interesting ressources: pages/cheat_sheet/interesting_ressources.md
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment