On unix there two important questions to ask before to do anything:
- who am I ?
- where am I ?
where am I ?
- somewhere on the file system !
do you already know a tree structure in biology?
pwd
(for print working directory)This is my map!
how to move?
cd
(changing directory)cd location
how to specify a location?
- give absolute position of your destination
- give relative path
abolute path to file abc_mouse.fa
cd
to explore the file systems.so we need to upgrade our location vocabulary:
- where a I am : .
- one level up : ..
exercise: use command cd
to explore the file systems using relative path.
cd
or cd ~
cd ~foobar
cd -
tab
to display the path completion.what are there in a this directory?
ls
(list directory contents)some useful options:
ls -l
: use a long listing format
ls -a
: do not ignore entries starting with . (ls -al)
ls -d
: list directory entries instead of contents
ls -t
: sort by modification time
ls -r
: reverse order while sorting
ls -lrt
: what does it mean?
Go in /pasteur/projets/policy01/unix_training/DataBio
, explore the subtree.
When a user want to execute a command on several files with similar names, or if he don't know the exact names, he can use jockers:
cd /pasteur/projets/policy01/unix_training/DataBio
ls -l Sequences/Nucleique/*.fasta
ls -l Sequences/Proteique/*.fasta
ls -l Sequences/Proteique/*.fasta
ls -l Sequences/*/
ls -l Sequences/*/q?1.*
how to get the listing of all files like abcd2_mouse.fa or abcd3_human.sp but NOT abcd_result.txt?
exercise:
sandbox
, and in this directory 2 directories data
, results
you can use option -p to preserve rights (owner, group, last acces and modification date)
exercise:
copy hmm files (ending with .hmm) in /pasteur/projets/policy01/unix_training/DataBio/HMM/ in data directory you just make.
you can specifies several src like mv src1 src2 src2 ... dest
The mv command has not the same effect according src and dest are directories or files
src type | dest type | action |
---|---|---|
one file | file | the src file is rename into dest file beware if dest file already exists it's lost |
several file | file | all src files are lost only the last one is rename as dest |
file | dir | all src files are moved in dest directory dest directory must exists. If not it is consider as file |
dir | dir | all src directories are moved in dest directory the dest directory must already exists |
mv files blast2 report in /pasteur/projets/policy01/unix_training/DataBio/ in sandbox/results
Warning
by default the user is not asked before to delete a file or not. You are big guy, you know what you do.
if you are unsure you can add -i option. In this case you will prompt before deleting an item.
remove all sandbox subtree
lrwxrwxrwx 1 bneron bneron 27 Oct 15 13:34 file1 -> /home/bneron/very_big_fasta
The command establishing this link is:
ln -s /home/bneron/very_big_fasta file1
We can create a link toward a directory
all this features are managed by the permissions (or right access)
$ ls -l
total 1176
drwxr-xr-x 4 bneron CIB 4096 Mar 4 2014 Alignment
-rw-r--r-- 1 bneron CIB 220196 Mar 4 2014 CIP-55-138_A.b_A06_037.ab1
drwxr-xr-x 3 bneron bneron 4096 Jun 4 14:51 HMM
file | directory | ||
---|---|---|---|
r | 4 | read | allow to list |
w | 2 | write | allow to create and delete file and directories |
x | 1 | the file is executable | allow to enter and pass trhough the directory |
Permisions are based on your identity and the groups to wich you belong.
whoami => give you the login you logged with
id <login> => give the id and the groups to which the login blong (login is optional)
bneron@bic-t2a:~$id
uid=2896(bneron) gid=3044(CIB) groups=3044(CIB),87(biok),110(sis),547(mobyle),990(gensoft),3160(vpn-ssl-users),20000(bioweb)
uid is my login
gid is my primary group
groups is the list of all groups to which I belongs (max 16 groups).
chmod [ugo] [+-] [rwx] <target>
chmod [ugo] [+-] [rwx] <target>
drwxr-xr-x 4 bneron CIB 4096 Mar 4 2014 Alignment
chmod g+w Alignment
drwxrwxr-x 4 bneron CIB 4096 Mar 4 2014 Alignment
chmod o-rx Alignment
drwxrwx--- 4 bneron CIB 4096 Mar 4 2014 Alignment
chmod g-wo+x Alignment
chmod: invalid mode: 'g-wo+x'
chmod go +rx Alignment
drwxrwxr-x 4 bneron CIB 4096 Mar 4 2014 Alignment
you can use -R option to apply permision to a directory and recursively to its contents.
chmod num_value <target>
-rw-r--r-- 1 bneron sis 0 Oct 16 13:59 file1
chmod 755 file1
-rwxr-xr-x 1 bneron sis 0 Oct 16 13:59 file1
chmod 640 file1
-rw-r----- 1 bneron sis 0 Oct 16 13:59 file1
Symbolic Notation | Octal Notation | English |
---|---|---|
---------- | 000 | no permissions |
---x--x--x | 111 | execute |
--w--w--w- | 222 | write |
--wx-wx-wx | 333 | write & execute |
-r--r--r-- | 444 | read |
-r-xr-xr-x | 555 | read & execute |
-rw-rw-rw- | 666 | read & write |
-rwxrwxrwx | 777 | read, write & execute |
exercises:
To controls the file/dir's permissions at their creation.
Octal digit in umask command | Allows on directory | allows on file |
---|---|---|
0 | read, write,execute | read, write |
1 | read and write | read, write |
2 | read and execute | read |
3 | read only | read |
4 | write and execute | write |
5 | write only | write |
6 | execute only | no permissions |
7 | no permissions | no permissions |
umask 001
umask -S
u=rwx,g=rx,o=rx
umask -S o+w
u=rwx,g=rx,o=rwx
exercise:
ls -l
To set x on file you need to use chmod.
chown command (for change ow ner)
the ownership of a file may only be altered by a super-user
Warning