Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.





Unix: everything I can tell in one hour






D. Puthier

Inserm U1090/Technologies Avancées pour le Génome et la Clinique



Press F11 for full screen


Installing Linux




Command synopsis



 
	command1 -a valueOfa -b valueOfb file      
		


Examples:


	head -n 5 refGene.txt 
	tail -n 5 refGene.txt
      

Directories and files



The cd commande


 
		cd the/Directory/Path      
		

Examples:

 
	   cd ~
	   cd ../..
	   cd ..      
		

Directories and files



The root directory



Examples:

 
	   cd / 
	   ls      
		

Directories and files



The home directory



Examples:

 
	   cd ~
	   cd $HOME
	   cd
	   ls ~
	   ls $HOME    
		

Directories and files


Absolute and relative path



 
	   cd ..
	   pwd
	   cd ../..
	   pwd 
	   cd     
		

NB: pwd stands for print working directory


Directories and files



The ls command



Examples:

 
		ls -rtl   
		

Directories and files



Creating files and directories



Examples:

 
		mkdir -p data
		ls   
		

Directories and files



The joker/wild card characters



Examples:

 
		touch file1.txt file2.txt file10.txt
		ls file*txt
		ls file?.txt
		

Directories and files



Viewing file content



Examples:

 
		cat *txt
		less myFile.txt
		

Directories and files



Copying



Examples:

 
		mv file1.txt file3.txt
		cp file3.txt file4.txt
		ls -rtlh file*txt
		

Regular expressions


A regular expression is a set of characters that specify a pattern.


Syntax Meaning
[a-z] lowercase alphabetic character (interval, ex: [u-w]).
[A-Z] uppercase alphabetic character (interval, ex: [A-E]).
[ABc] A or B or c
. Any character
[^ABab] Any letter but not A/a or B/b.
^ Beginning of a line.
$ End of a line
x* 0 or n times x.
x+ 1 or n times x.
x{n,m} x repeated n to m times.
/ Escape character

Regular expressions


Examples


Syntax Meaning
\.txt$ Any string that ends with ".txt".
^[A B] Any string that starts with uppercase character.
^.{4,6}\.txt$ Four to six characters followed by ".txt"
^[A Z].*\.txt$ A string starting with uppercase character and ending with ".txt"
[^ABab] Any letter but not A/a or B/b.
^[^0 9]*\.sh$ A string without any number that ends with ".sh"

Commands can be chained using pipes



Command that can take a stream in their standard input and send the resulting stream to ouput are called filters



Redirecting operators



Redirecting operators are used to redirect a text stream to a file or a process.



Examples

 
		cat atextfile.txt | sort | uniq > myfile.txt
		cat atextfile.txt | cut -f13 > newfile.txt
		cat atextfile.txt|grep  "^[AM]" | head -2 >> newfile.txt
		

Some useful filters



This list is not exhaustive



Sed





Awk




General usage

			awk 'condition {action}' file.txt
			cat file.txt | awk 'condition {action}' 
		
			awk 'BEGIN{something to do before reading the stream} condition {action} END{something to do at the end of the program}' file.txt
		

NB: Perl oneliner programs follows almost the same structure.


Awk




Examples:

		
			ls -l | awk 'BEGIN{FS=" "}$6 == "Feb" { sum += 1 } END { print sum }'

			echo -e  "123\t123\n456\t325" > file.txt
			
			awk 'BEGIN{FS="\t"}($1==$2){print $0}' file.txt
			
			awk 'BEGIN{FS="\t"; OFS=":"}($1==$2){print $1,$2}' file.txt

			...
		

Awk




Examples:

		
			ls -l | awk 'BEGIN{FS=" "}$6 == "Feb" { sum += 1 } END { print sum }'

			echo -e  "123\t123\n456\t325" > file.txt
			
			awk 'BEGIN{FS="\t"}($1==$2){print $0}' file.txt
			
			awk 'BEGIN{FS="\t"; OFS=":"}($1==$2){print $1,$2}' file.txt

			...
		

Merci

-->