Introduction to the line. Sabry Razick (RCS Nov 2015) What is a terminal

● The terminal is an interface in you can and execute text based commands. ● It can be much faster to complete some tasks using a Terminal than with graphical applications and menus. ● Allowing access to many commands and scripts. ● When making your own program, it is easier and faster to design it to work on the terminal than with the mouse. ● More transparency on what is going on ● More control on what you do ● …….

How to access the terminal

based systems (Redhat, Ubuntu….Mac OS) it is there as a program already. ● Windows - Windows command line (cmd) can not do the thing Unix terminal do. So you need a Virtual environment or get access a Unix machine ● Virtual environment ○ Oracle Virtual Machine - www.oracle.com/us/technologies/virtualization/oraclevm/ ○ Cygwin - https://www.cygwin.com/ ○ Boot with a live /Falsh drive ● Access a Unix machine ○ Putty - http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Windows

● abel.uio.no ● freebee.abel.uio.no ● Use UIO username and password Unix

the terminal The shell

● Shell provides an interface between you and the of the computer ● Use the keyboard to tell the computer what you want of it ● Where is my home ○ $HOME ● Go to my home ○ cd $HOME ● What files or folders have in my home ○ ● Give me more details about the files ○ ls -lh The shell

out more about a command ○ man ○ e.g. man ls ● List them in sorted ○ ls -lhrt (list oldest first) ○ ls -lh --=size ● Set permissions ○ a+r .txt ○ chmod g+r test.txt ○ chmod u+x test.txt ○ chmod +x test.txt The shell

● Create a rcs2015 ● Changed to that directory ○ cd rcs2015 ● I am not sure where I am ○ ● Create test.txt ○ echo “some text” > test2.txt ○ nano test3.txt (Ctrl + o -- Save, Ctrl -x to get out) ● list the files that ends with txt ○ ls -lh *txt Path

● Path specifies a position in the directory . There are two kinds of paths. ○ absolute ○ relative ● Absolute path always starts at the of the tree (at the root directory), for example “/home/username”. The absolute path always starts with a “/” (root). ● The relative path is the path to the destination from your current position and it does not start with a “/”.

The shell ● Delete a file ○ test2.txt ● Delete a directory ○ mkdir tmp ○ rm -r tmp ○ tmdir tmp ● Create another directory and copy the file test.txt ○ mkdir $HOME/rcs2 ○ test.txt $HOME/rcs2 ○ cd $HOME/rcs2 ○ cp ../rcs2/test.txt . ○ cp /test.txt / ● Move a file (keep the copy delete the original, rename) ○ test2.txt mv test_new.txt The shell

● Which machine am I in ○ hostname ● else is logged in ○ who ● How am I logged in ○ who am i ● What are the things running at the moment ○ top ● What are the thing I am running ○ top -u ● Do I have internet connection ○ ping uio.no FIles

● Create a new file and add a content ○ nano filetest.txt ○ AAAACCTTGCCGGTCCC… ○ Ctrl + o, Ctrl +x ● Display the content ○ filetest.txt ○ less filetest.txt | more ○ filetest.txt ● Find whether there is a specific string in the file ○ “AA” filestest.txt ● Find out the file with the name filetest.txt ○ cd .. ○ find -name filetest.txt Files

● Find the file containing the string AAA, look everywhere starting from current directory ○ grep -Rni “AA” ○ grep -RH --include='*txt "AA" . ● Peak ○ test.txt ○ test.txt ● nano table.txt A B C D E A1 B1 C1 D1 E1 A2 B2 C2 D2 E2 A2 B3 C2 D3 E3 A4 B4 C2 D4 E4 , sort, ,

● Print the first column ○ awk '{print $1}' table.txt ● Create a new file by shifting column one and two ○ awk '{print $2"\t"$1"\t"$3"\t"$4}' table.txt > table2.txt ● Display unique values on first column ○ cat table.txt |awk '{print $1}'| sort | uniq ● Collapse raws ○ tr '\n' ';' < emails.txt Programs

● Where the program is installed ○ which ls ● Create a small program ○ echo "hi \$1" > p1.sh ● it executable ○ chmod +x p1.sh ● Run it ○ ./p1.sh AAA ● Add it to path so you can run it from anywhere ○ echo $PATH ○ export PATH=$PATH:$HOME/rcs2015/ Extra

○ sed -n '2,3p' table.txt ● Processes ○ -ef | grep bash ● Replace a string in a file (no undo !) ○ find . -type f -name "3.txt*" -exec sed -i "s/A/B/g" {} + Extract 2 columns and them with a . (column separated with a space) file: ProjectID PID@104555 SentrixBarcode SentrixPo 000388 1045550292122 4515597045 R01C01 000388 1045550667913 4515597045 R02C01 000388 1045550442282 4535791163 R01C01 000388 1045550660020 4535791163 R01C0 command cat Sentrix_104555_Case_3642_.txt | awk -F' ' '{print $3,".", $4}'| sed -e 's/ //g'