4. The shell: BASH is running
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
5. Unix keeps files arranged in a
hierarchical structure
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
8. $ programname ( options ) ( f i l e s )
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
9. Navigation
where am I ?
$ pwd
Go to directory dir1
$ cd d i r 1
Go to directory dir1/dir2
$ cd d i r 1 / d i r 2
Go upper directory
$ cd . .
Go upper directory and then go to dir4
$ cd . . / d i r 4
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
10. Navigation
Go to the root
$ cd /
Go to my home
$ cd ˜
Go to my previous directory
$ cd /
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
12. CASE matters
$ cd d i r 1
$ cd DIR1
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
13. Regular Expression.
’?’ : The question mark indicates there is zero or one of the
preceding element. For example, colou?r matches both ”color” and
”colour”.
’*’ : The asterisk indicates there is zero or more of the preceding
element. For example, ab*c matches ”ac”, ”abc”, ”abbc”,
”abbbc”, and so on.
’+’ : The plus sign indicates there is one or more of the preceding
element. For example, ab+c matches ”abc”, ”abbc”, ”abbbc”,
and so on, but not ”ac”.
(a—b)* denotes the set of all strings.
: A bracket expression. Matches a single character that is
contained within the brackets.
ˆMatches the starting position within the string.
$ Matches the ending position of the string or the position just
before a string-ending newline.
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
15. Shell shortcuts.
Arrow-up/down: prev/next in history.
Ctr-R : Search history.
Ctr-A : Begin line.
Ctr-E : End line.
Ctr-K : Cut line.
Ctr-D and tab : insert tabulation.
Ctr-D and tab : insert tabulation.
Ctr-D (in pipeline): EOF (End Of File).
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
16. whitespaces matter
$ cd my r e s u l t s
bash : cd : my: No such f i l e or d i r e c t o r y
$ cd ”my r e s u l t s ”
$ cd my r e s u l t s
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
17. man
$ man man
MAN(1)
NAME
man − an i n t e r f a c e to the on−l i n e
r e f e r e n c e
SYNOPSIS
man [−C f i l e ] [−d ] [−D] [−−
warnings[=wa
[−−names−only ] [−a ] [−u ] [−−no−subpages
] [−P
[−X[ dpi ] ] [−Z] [ [ s e c t i o n ] page . . . ] . . .
man −k [ apropos options ] regexp . . .
man −K [−w|−W] [−S l i s t ] [− i |− I ] [−−
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
18. apropos
$ apropos apropos
apropos (1) − search the manual page
names and
$ apropos pdf
pdfcrop (1) − crop pdf f i l e s to t h e i r
minimal
a2ping (1) − − convert between PS ,
EPS and PD
d v i p d f (1) − Convert TeX DVI f i l e to
PDF u s i n
dvipdfm (1) − Produce PDF f i l e s
d i r e c t l y from
d v i p d f t (1) − c r e a t e thumbnail images
for use
e 2 p a l l (1) − convert a l l EPS f i l e s
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
19. pwd
$ pwd
/home/ l i n d e n b / s r c / courses / about . l i n u x
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
20. mkdir
$ mkdir DIR1
$ mkdir DIR1/DIR2
$ mkdir −p DIR1/DIR3/DIR3
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
21. ls
$ l s
$ l s −l
$ l s −l a
$ l s −l a /home/
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
23. Redirection
$ echo ” Hello ” > f i l e 1 . t x t
$ echo ” Hello ” > f i l e 1 . t x t
$ echo ” Hello ” > f i l e 1 . t x t
$ cat f i l e 1 . t x t
Hello
$ echo ” Hello ” >> f i l e 2 . t x t
$ echo ” Hello ” >> f i l e 2 . t x t
$ echo ” Hello ” >> f i l e 2 . t x t
$ cat f i l e 2 . t x t
Hello
Hello
Hello
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
24. Reading
$ grep Hello << BARBAPAPA
> Hello
> Hello
> world
> BARBAPAPA
Hello
Hello
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
25. Pipe
$ gunzip −c input . vcf . gz | grep −v ’#’ | cut −
f 1 ,2 ,3 | t r ” t ” ”.” | sed ’ s / chr // ’ |
s o r t −t ’ . ’ −k2 ,2 rn | uniq | cat −n
1 1.871334. rs4072383
2 1.870903. rs13303094
3 1.866511. rs71576583
4 1.866319. rs9988021
5 1.861630. rs2879816
6 1.861008. rs28521172
7 1.762273. rs3115849
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
26. echo
$ echo ”ABCD”
$ echo −n ”ABCD”
$ echo −e ”AtBnCD”
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
27. ’file’
Determine what type of data is
within a file.
$ f i l e ˜/ j e t e r . vcf . gz ˜/Documents/2011028. odp
/home/ l i n d e n b / j e t e r . vcf . gz : gzip
compressed data , e x t r a f i e l d
/home/ l i n d e n b /Documents /2011028. odp :
OpenDocument P r e s e n t a t i on
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
28. ’tr’
translate or delete characters.
$ echo ”AAAAAAABCD” | t r ”A” ”a”
aaaaaaaBCD
$ echo ”AAAAAAABCD” | t r −s ”A”
ABCD
$ echo ”AAAAAAABCD” | t r −d ”A”
BCD
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
29. rm
$ rm f i l e 1 . t x t f i l e 2 . t x t
$ rm −r DIR1/ f i l e 1 . t x t
$ rm −i DIR1/ f i l e 1 . t x t
$ rm −f DIR1/ f i l e 1 . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
31. mv
$ mv DIR1/ f i l e 1 . t x t DIR2/
$ mv olname . t x t newname . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
32. cp
$ cp olname . t x t newname . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
33. more
$ more f i l e 1 . t x t f i l e 2 . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
34. cat
$ cat f i l e 1 . t x t f i l e 2 . t x t
$ cat −n f i l e 1 . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
35. head
output the first part of files.
$ head f i l e 1 . t x t
$ head −n 100 f i l e 1 . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
36. tail
output the last part of files.
$ head f i l e 1 . t x t
$ head −n 100 f i l e 1 . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
37. grep
$ grep Gene1 genes . t x t
$ grep −v Gene1 genes . t x t
$ grep −i Gene1 genes . t x t
$ grep −E ’( Gene1 | Protein1 ) ’ genes . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
38. cut
$ cut −d ’ ’ −f1 ,2 ,4 −10 f i l e 1
$ cut −c1−10 f i l e 1
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
39. sort
$ s o r t f i l e
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
41. uniq
$ s o r t f i l e | uniq
$ s o r t f i l e | uniq −u
$ s o r t f i l e | uniq −d
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
42. wc
$ wc f i l e
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
43. awk for filtering
awk −F ’ ’ ’( $1==” chr1 ” && i n t ( $2 )>10 && i n t (
$2 ) <100) ’ f i l e . vcf
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
44. awk for printing
$ echo −e ” chr1 t20 t30 nchr1 t10 t20 ” |
awk −F ’ t ’ ’{ p r i n t f ( ”%s:%s−%dn” , $1 , $2 −1 ,
$3 + 4) ; } ’
chr1 :19−34
chr1 :9−24
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
45. join
$ j o i n −t ’ ’ −1 1 −2 1 f i l e 1 . t x t f i l e 2 . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
46. comm
$ comm f i l e 1 . t x t f i l e 2 . t x t
$ comm −12 f i l e 1 . t x t f i l e 2 . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
47. gzip , gunzip
$ gzip f i l e 1 . t x t
$ gunzip −c f i l e 1 . t x t . gz
$ gunzip f i l e 1 . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
48. sed
Usage:
sed ’ s /PATTERN/REPLACEBY/MODIFIER ’
Examples:
$ echo ” chr1 chr2 chr3 ” | sed ’ s / chr /CHROM / ’
CHROM 1 chr2 chr3
$ echo ” chr1 chr2 chr3 ” | sed ’ s / chr /CHROM /g ’
CHROM 1 CHROM 2 CHROM 3
$ echo ” chr1 chr2 chr3 ” | sed ’ s /Chr/CHROM / gi
’
CHROM 1 CHROM 2 CHROM 3
$ echo ” chr1 chr2 chr3 ” | sed ’ s / chr /CHROM /2 ’
chr1 CHROM 2 chr3
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
49. cmp
$ cmp f i l e 1 f i l e 2
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
50. diff
$ d i f f f i l e 1 f i l e 2
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
51. find
$ f i n d /path1 / path2 / d i r 2 −name ” ∗. vcf . gz”
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
52. paste
$ paste f i l e 1 f i l e 2 f i l e 3 f i l e 4
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
53. curl
$ c u r l ” f t p :// f t p .1000 genomes . e b i . ac . uk/ vol1 /
f t p / r e l e a s e /20110521/ ALL . wgs .
p h a s e 1 r e l e a s e v 3 .20101123. s n p s i n d e l s s v .
s i t e s . vcf . gz” |
gunzip −c | head
##f i l e f o r m a t=VCFv4 .1
##INFO=<ID=LDAF, Number=1,Type=Float ,
D e s c r i p t i on =”MLE A l l e l e Frequency
Accounting f o r LD”>
##INFO=<ID=AVGPOST, Number=1,Type=Float ,
D e s c r i p t i on =”Average p o s t e r i o r p r o b a b i l i t y
from MaCH/Thunder”>
##INFO=<ID=RSQ, Number=1,Type=Float , D e s c r i p t i on
=”Genotype imputation q u a l i t y from MaCH/
Thunder”>
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
54. curl + NCBI
$ c u r l −sg ’ http ://www. ncbi . nlm . nih . gov/ e n t r e z
/ e u t i l s / esearch . f c g i ?db=pubmed&term=watson [
AU]+ c r i c k [AU]+1953[ Date+−+P u b l i c a t i on ] ’
<?xml v e r s i o n=” 1.0 ” encoding=”UTF−8”?>
<eSearchResult >
<Count>3</Count>
<RetMax>3</RetMax>
<RetStart >0</RetStart >
<I d L i s t >
<Id >13063483</Id>
<Id >13054692</Id>
<Id >13168976</Id>
</I d L i s t >
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
55. curl + NCBI
$ c u r l −sg ’ http ://www. ncbi . nlm . nih . gov/ e n t r e z
/ e u t i l s / e f e t c h . f c g i ?db=pubmed&id
=13063483 ,13054692 ,13168976& retmode=xml ’ |
grep A r t i c l e T i t l e
<A r t i c l e T i t l e >G e n e t i c a l i m p l i c a t i o n s of the
s t r u c t u r e of d e o x y r i b o n u c l e i c acid .</
A r t i c l e T i t l e >
<A r t i c l e T i t l e >Molecular s t r u c t u r e of n u c l e i c
a c i d s ; a s t r u c t u r e for d e ox y r i b os e n u c l e i c
acid .</ A r t i c l e T i t l e >
<A r t i c l e T i t l e >The s t r u c t u r e of DNA.</
A r t i c l e T i t l e >
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
56. script
$ s c r i p t m y f i l e . t x t
S c r i p t started , f i l e i s m y f i l e . t x t
$ echo ” Hello ”
Hello
$ exit
S c r i p t done , f i l e i s m y f i l e . t x t
$ cat m y f i l e . t x t
> S c r i p t s t a r t e d on Thu 25 Jun 2015 11:50:43
AM CEST
> $ echo ” Hello ”
> Hello
> $ exit
> S c r i p t done on Thu 25 Jun 2015 11:50:52 AM
CEST
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
57. bc
$ echo ” (13.3∗2) /2.3 ” | bc
11
$ echo ” (13.3∗2) /2.3 ” | bc −l
11.56521739130434782608
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
58. chown/chmod/chgrp
chown p i e r r e f i l e . t x t
chgrp b i o i n f o r m a t i c s f i l e . t x t
chmod u+rw f i l e . t x t
chmod g+r f i l e . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
59. sqlite3
$ s q l i t e 3 test . s q l i t e 3
SQLite v e r s i o n 3. 7. 9 2011−11−01 00:52:41
Enter ” . help ” for i n s t r u c t i o n s
Enter SQL statements terminated with a ” ; ”
s q l i t e > c r e a t e t a b l e Person (name t e x t ) ;
s q l i t e > i n s e r t i n t o Person (name) v a l u e s ( ’
Pierre ’ ) ;
s q l i t e > i n s e r t i n t o Person (name) v a l u e s ( ’ Paul
’ ) ;
s q l i t e > i n s e r t i n t o Person (name) v a l u e s ( ’
Jacques ’ ) ;
s q l i t e > select name from Person ;
P i e r r e
Paul
Jacques
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
60. mysql
$ mysql −−user=genome −−host=genome−mysql . cse .
ucsc . edu −D hg19 −e ’ select chrom ,
chromStart , chromEnd , Observed from snp141
where name=” rs25 ” ’
+−−−−−−−+−−−−−−−−−−−−+−−−−−−−−−−+−−−−−−−−−−+
| chrom | chromStart | chromEnd | Observed |
+−−−−−−−+−−−−−−−−−−−−+−−−−−−−−−−+−−−−−−−−−−+
| chr7 | 11584141 | 11584142 | A/G |
+−−−−−−−+−−−−−−−−−−−−+−−−−−−−−−−+−−−−−−−−−−+
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
61. R
SampleID Dye C on c e n t r a t i on 1l Concentration2
rapp Qt AS Vol
E1−4 Cy5 3 ,52 203 ,79 2 ,25 6 ,1 17 ,3 4 ,05
E1−5 Cy3 3 ,14 174 ,16 2 ,22 5 ,2 18 4 ,74
E2−4 Cy3 1 ,64 101 ,18 2 ,25 3 16 ,2 8 ,15
E2−5 Cy3 3 ,41 213 ,74 2 ,26 6 ,4 16 3 ,86
E3−4 Cy3 3 ,11 184 ,15 2 ,22 5 ,5 16 ,9 4 ,48
E3−5 Cy5 3 ,58 189 ,31 2 ,24 5 ,7 18 ,9 4 ,36
mean( samples$Concentration2 )
samples <− read . table ( ” samples2 . t x t ” ,
dec=” , ” ,
header=TRUE)
mean( samples$ Concentration2 )
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
62. ’git’
mkdir t e s t
cd t e s t
g i t i n i t
I n i t i a l i z e d empty Git r e p o s i t o r y i n t e s t /. g i t /
$ g i t add f i l e . t x t
$ g i t commit −m ”Added one f i l e ”
[ master ( root−commit) 4954 d33 ] Added one f i l e
$ echo ”World ” >> f i l e . t x t
$ g i t d i f f
d i f f −−g i t a/ f i l e . t x t b/ f i l e . t x t
@@ −1 +1,2 @@
H e l l o
+World
$ g i t add f i l e . t x t
$ g i t commit −m ” added h e l l o ”
$ g i t log f i l e . t x t
( . . . )
$ g i t rm f i l e . t x t
$ g i t checkout f i l e . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
64. Install a program
c u r l −kL −o bwa −0.7.12. z i p −L ” https :// github .
com/ lh3 /bwa/ a r c h i v e / 0 . 7 . 1 2 . z i p ”
unzip bwa −0.7.12. z i p
make −C bwa −0.7.12/
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
67. bash script
#!/ bin /bash
echo ” Hello ” > h e l l o . t x t
echo ”World” > world . t x t
cat h e l l o . t x t world . t x t > h e l l od w or l d . t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
68. make
#!/ bin /bash
function q u i t {
exit
}
function e {
echo $1
}
e Hello
e World
q u i t
echo foo
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
69. Simple math
echo $((1+1) )
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
70. Simple loop
#!/ bin /bash
for i in 1 2 3 4 5 6; do
echo item : $i
done
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
71. While read
#!/ bin /bash
cat f i l e . t x t | while read L ; do
echo $L
done
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux
73. make
a l l : h e l l od w or l d . t x t
cat $<
h e l l od w or l d . t x t : h e l l o . t x t world . t x t
cat $ˆ > $@
h e l l o . t x t :
echo ” Hello ” > $@
world . t x t :
echo ”World” > $@
clean :
rm −f h e l l od w or l d . t x t h e l l o . t x t world
. t x t
@yokofakunhttp://plindenbaum.blogspot.comUMR 1087 - Institut du Thorax. Nantes. FranceIntroduction to Linux