Skip to content
hero

TP 2.1: Files and directories

Goal: Move inside tree structure.

The purpose of this practice is to put you in situation: You have launched some calculations on work space and must organize and store results inside your personal save space. In the save space, fasta files will be stored into data directory and blast files will be stored into blast directory.

Reminder

Current state of your directories:

  • /home/<username> : configuration files
  • /save/user/<username> : backup space, empty
  • /work/user/<username> : working space, files resulting from analysis

Prerequisite

Before starting this practice, please type the following command:

cp -r /home/formation/save/tp_linux/data/* ~/work

Create a project directory

Question

In you save space, create a folder called tp_linux, and go in this folder.

/home/<username>
├── save              <- go there 
│   └── tp_linux
└── work
Solution

# Go to home directory (replace &lt;username&gt; by your username)cd ~/save/# Create the directory tp_linuxmkdir tp_linux# Go into the new directorycd tp_linux

Structure the projet

Question

Create the sub-directories data and blast_result in tp_linux.

/home/<username>
├── save
│   └── tp_linux
│       ├── blast_result
│       └── data
└── work
Solution

mkdir datamkdir blast_result

or in one line

mkdir data blast_result

Visualize the content of your working directory

Question

List all the files inside the work directory.

Solution

Many possibilities (not exaustive):

  • by going inside the directory

cdcd workls

  • by using the absolute path

ls /work/user/<username>

  • by passing by the home directory shortcut.

ls /home/<username>/work

  • the same, but using the shortcut ~ that go to the home directory.

ls ~/work

Organize data

Question

  1. Move the files *.fasta inside directory tp_linux/data; check that none exists in work directory.
  2. Copy blast result files (*.blast) inside directory tp_linux/blast_result.
Before
/home/<username>
├── save
│   └── tp_linux
│       ├── blast_result
│       └── data
└── work
    ├── *.blast
    └── *.fasta
After
/home/<username>
├── save
│   └── tp_linux
│       ├── blast_result
│       │   └── *.blast
│       └── data
│           └── *.fasta
└── work
    └── *.blast
Solution
  • For 1:

cd /home/<username>/workmv *.fasta ~/save/tp_linux/datals

  • For 2:

cp *.blast ~/save/tp_linux/blast_result

Question

In order to avoid multiple copies of a file, a good practice is to use symbolic link (shortcut) pointing on this file.

Go in the directory ~/work and create a symbolic link that points to the file ~/save/tp_linux/data/ab005233.fasta.

/home/<username>
├── save
│   └── tp_linux
│       ├── blast_result
│       │   └── *.blast
│       └── data
│           ├── ab005233.fasta
│           └── *.fasta      ^
└── work                     │
    ├── ab005233.fasta  -----/ link
    └── *.blast

List in detailled manner the files inside your space work.

Solution

One solution

cd ~/workln -s ~/save/tp_linux/data/ab005233.fastals -l

or an equivalent solution

ln -s ~/save/tp_linux/data/ab005233.fasta ~/workcd ~/workls -l