Space in volumes and permissions

Volume sizes and disk space

When we deal with analyzing valuable data we should consider different problems:

Check the size of a file with :

ls -lh Escherichia_coli_bl21_gold_de3_plyss_ag_.ASM2366v1.pep.all.fa 

Get a summary of the disk usage size of a directory:

du -sh my_beautiful_folder/

3.5K	my_beautiful_folder/

Display disk usage of all the files and directories:

du -ah my_beautiful_folder/
# compress files using gzip:
gzip Escherichia_coli_bl21_gold_de3_plyss_ag_.ASM2366v1.pep.all.fa

# show the content of a gzipped file without uncompressing it:
zcat SRR6466185_1.fastq.gz | head
gunzip -c SRR6466185_1.fastq.gz | head

# link files instead of copying them:

mkdir test_links
cd test_links

# ln for linking, -s for symbolic link: first comes the file to link, then where to link it!
ln -s ../SRR6466185_1.fastq.gz .
# give the copy of the file another name:
ln -s ../SRR6466185_2.fastq.gz ./sample1_read2.fastq.gz

cd ..

Show the system disk space statistics (file system disk space usage):

df -h

Filesystem                              Size  Used Avail Use% Mounted on
/dev/sda3                                20G  8.1G   11G  44% /
devtmpfs                                 63G     0   63G   0% /dev
tmpfs                                    63G     0   63G   0% /dev/shm
...

Permissions

Create a small file:

echo "my file" > test.txt

ls -l shows those permissions:

ls -l test.txt
-rw-r--r-- 1 sbonnin Bioinformatics_Unit 5 Mar 14 16:29 test.txt

Here is the owner is sbonnin and the group it belongs to is Bioinformatics_Unit.

The first field here contains 10 ticks:

Owner Group Any user
rw- r– r–



chmod [who][+,-,=][permissions] filename
User letter
owner u
group g
users not in the group o
all users a


chmod g+w test.txt

ls -l test.txt

-rw-rw-r-- 1 sbonnin Bioinformatics_Unit 5 Mar 14 16:29 test.txt
chmod o+w test.txt 

ls -l test.txt

-rw-rw-rw- 1 sbonnin Bioinformatics_Unit 5 Mar 14 16:29 test.txt
chmod og-w test.txt 

ls -l test.txt

-rw-r--r-- 1 sbonnin Bioinformatics_Unit 5 Mar 14 16:29 test.txt
chmod og-rw test.txt

-rw------- 1 sbonnin Bioinformatics_Unit 5 Mar 14 16:29 test.txt
chmod a-w test.txt 

-r-------- 1 sbonnin Bioinformatics_Unit 5 Mar 14 16:29 test.txt

# Try to overwrite the content of test.txt:

echo "test" > test.txt
-bash: test.txt: Permission denied

# Try to remove test.txt:

rm test.txt
rm: remove write-protected regular file ‘test.txt’?
chmod -x my_ugly_folder/

# try to enter the folder:
cd my_ugly_folder/
-bash: cd: my_ugly_folder/: Permission denied
chmod -R +x my_ugly_folder/

Use octal notation for file permissions

Each tick can be replaced by 0 (does not have that permission) or 1 (has that permission): this creates a binary number at each user type, that can be converted into an octal number.

Hence, each octal number represents a set of permissions:

Binary Octal Permission
000 0 - - -
001 1 - - x
010 2 - w -
011 3 - w x
100 4 r - -
101 5 r - x
110 6 r w -
111 7 r w x


chmod 760 my_expression.txt
# 7 for the owner
# 6 for the group
# 0 for other users

Next Session

Variables and “For” Loops