Skip to content
Snippets Groups Projects
Commit 2612f278 authored by alexis.dereeper_ird.fr's avatar alexis.dereeper_ird.fr
Browse files

Update bash-4-working_with_files_and_directories.md

parent f62f80ae
No related branches found
No related tags found
No related merge requests found
Pipeline #39005 passed
......@@ -150,48 +150,6 @@ Let's imagine you want your script `script1.sh` locally to run your analysis, bu
ls script
```
Before running your analysis, you may be interested to access all the fastq files present in the `data` folder.
You can use the `cp` command for all the files one by one as we have seen previously. But if you have hundred of those `fastq` files, it would be fastidious.
Well Bash does carry out a very powerful feature, the `filename expansion`, a process known as globbing! (to not confound with regular expressions).
??? tip "Course reminder about globbing/jokers"
**Here the list of globbing:**
| wildcard characters | meaning |
| :-: | :-: |
| `?` | Any single character |
| `*` | Zero or more characters |
| `[]` | Specify a range. Any character of the range or none of them by using `!` inside the bracket.|
| `{term1,term2}` | Specify a list of terms separated by commas and each term must be a name or a wildcard.|
| `{term1..term2}` | Called brace expansion, this syntax expands all the terms between term1 and term2 (Letters or Integers).|
The most important one you have to remember is `*`.
!!! question "Using `ls`, list all the fastq files available in the `data` folder (and only the fastq files!)"
??? example "Click to show the solution"
```bash
ls ../data/data?.fastq
```
This one works but if we had a file called `dataPE.fastq` it would not appear because only a single character is expected between `data` and `.fastq` while here it would be `PE`.
```bash
ls ../data/*.fastq
```
Excellent this one match all files ending in `.fastq`.
!!! question "Now copy all the fastq files using a single command thanks to the `*` filename expansion."
??? example "Click to show the solution"
```bash
cp ../data/*.fastq .
```
Very convenient isn't it?
## Renaming files/folders (mv)
......@@ -289,7 +247,53 @@ To remove links you can use `rm` like for files or the dedicated `unlink` comman
```bash
rm script script1.sh
```
## Jokers/Wildcards (*)
Before running your analysis, you may be interested to access all the fastq files present in the `data` folder.
You can use the `cp` command for all the files one by one as we have seen previously. But if you have hundred of those `fastq` files, it would be fastidious.
Well Bash does carry out a very powerful feature, the `filename expansion`, a process known as globbing! (to not confound with regular expressions).
??? tip "Course reminder about globbing/jokers"
**Here the list of globbing:**
| wildcard characters | meaning |
| :-: | :-: |
| `?` | Any single character |
| `*` | Zero or more characters |
| `[]` | Specify a range. Any character of the range or none of them by using `!` inside the bracket.|
| `{term1,term2}` | Specify a list of terms separated by commas and each term must be a name or a wildcard.|
| `{term1..term2}` | Called brace expansion, this syntax expands all the terms between term1 and term2 (Letters or Integers).|
The most important one you have to remember is `*`.
!!! question "Using `ls`, list all the fastq files available in the `data` folder (and only the fastq files!)"
??? example "Click to show the solution"
```bash
ls ../data/data?.fastq
```
This one works but if we had a file called `dataPE.fastq` it would not appear because only a single character is expected between `data` and `.fastq` while here it would be `PE`.
```bash
ls ../data/*.fastq
```
Excellent this one match all files ending in `.fastq`.
!!! question "Now copy all the fastq files using a single command thanks to the `*` filename expansion."
??? example "Click to show the solution"
```bash
cp ../data/*.fastq .
```
Very convenient isn't it?
## Commands to keep in mind
......
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