Loading...
 

Linux Basics

1. Server Connection

a. If you are using a windows machine and the SSH client application, start the SSH Client, by clicking this icon in the desktop 9jwJ2sbnqU6jwFnijESPfYmPkyXSWzzr1wYjdYgXU8-QEPkzVTLaoM5_ys0b4WxSdZVcZlwhwAAc36JW94z64O-HoFdEFGwyJ3RGzQIRuz8abtYtivCwLmVbnAEDM3tlHC0kkhsq, on a Windows Laptop. Start the Terminal in a Mac laptop.

b. Use the given IP address for the Host name. Use the username and password provided to you, along with the Hostname, to connect to the class server.

c. Your connection window would look like below or similar;

vNZdFPQVi1R64n4qheK8MqyBfzp18n0JOeiXVS8qZ59bGv-AUSbTPfZIfy5VokdbPYwSfy3HTe25fdvAFGnnHzOnOkNz8YqE0edcSUnT4K0Q3LdnBtXgSrh2kAx1JqH3IcQ03dJj


d. Use the ssh command, specifying the username and the ip address, like below, to login in to the server using the mac terminal;. AqfvLNa_NmJDclqZ3ntf_w-yOK_4J27Jt6jcD4txU0YOqhYwChUCsCIrC0XA0Sdk0XjagolSFNLFe8V9bN50wMxswW0ZdHta6Ln-QyuvGSt2929oeE32PlUT0BOERTsQmERBngt2


2. The first 5 commands - pwd,ls,mkdir,cp,cd

 

a. pwd - Print the path of the current working directory

pwd

 

b. ls - List items in the current working directory

ls

 

c. mkdir - Make/create a new directory

mkdir mydemo

 

d. cp - Copy files(s)/folder(s) from one place to another

cp ~/Desktop/unix/FoxA1_peaks.narrowPeak mydemo

 

e. cd - Change to a different directory

cd mydemo
ls -l
ls -a
ls -lh

3. The next 5 - mv,head,tail,man,rm

a. Make a copy of the original file

cp FoxA1_peaks.narrowPeak towork.txt

 

b. mv - Move/Rename file/folder

mv towork.txt peaks.txt
ls -lh

 

c. head - Show the first few /head contents of a file

head peaks.txt
head -n 2 peaks.txt
head -n 10 peaks.txt > peaks10.txt

 

d. tail - Show the last few /tail contents of a file

tail peaks.txt
tail -n 2 peaks.txt

 

e. man - Show the manual page for a command

man head

 

f. rm - Remove a file/folder

ls -l
rm peaks10.txt
ls -l

4. Useful others - more,less,grep,wc,cat

 

a. more - Displays the first few lines of a file and lets you scroll through

more peaks.txt

 

b. less - Like more, but forward and backward

less peaks.txt

 

c. grep - The powerful search command

grep chr1 peaks.txt > chr1.txt
ls -l
head chr1.txt
tail chr1.txt
grep -w chr1 peaks.txt > chr1correct.txt        #use word boundary
ls -l
head chr1correct.txt
tail chr1correct.txt
rm chr1.txt
mv chr1correct.txt chr1.txt
ls -l

 

d. wc - Counts things - letters, words, lines etc.

wc peaks.txt
wc -l peaks.txt
wc -l chr.txt

 

e.cat - Concatenate file contents

grep -w chr2 peaks.txt > chr2.txt
ls -lh
cat chr1.txt
cat chr1.txt chr2.txt > chr1and2.txt
head chr1and2.txt
tail chr1and2.txt
wc -l chr1and2.txt

5. Editor

 

a. nano or vi or vim or emacs

nano f1.txt

 

b. Enter some text and Ctrl X, to save.


QgBi42FtdW337NNMj5j99d_uPmG5Qm4We6u3xtOXSS9oZrSe4-t62eKKtyjNYkDUNt3bX9ZnK4_Wq0J2tWQAaAxkGYFQh67wY_QDn9bPIKDfzryqzivEleYziIr2ftzGrZfWc5mq

 

cat f1.txt

 

c. vi - Visual text editor

vi f2.txt

 

Press the ‘i’ key, enter some text

Press the ‘esc’ key to get out of the insert modePress :wq to write (save) and quit

FYkvPIbJmA56Y9YVQqdNp8f3_kxIEJdWjjXtrycX0IvWqNLUxXR_olJCDDjy-tSwuRLsT7xxBE-KehNGUG5v1RjWoxIpuhhEGhnx7cBpsOsolutzefmOdsFk373lAnUDHb8-H5xb

cat f2.txt
ls -lh

6. Input and Output

6.1.  STDIN,STDOUT (>,<)

 

head -n 2 peaks.txt > first2
ls -lh
cat first2
tail -n 2 peaks.txt > last2
cat last2
wc -l < peaks.txt
wc -l < last2

 

6.2. APPEND

The double greater than symbol appends/adds content to the end of a file

cat last2 >> first2
cat first2

 

6.3. PIPES

Pipes help pass the input/output between one command/program to another command/program

grep -w chr3 peaks.txt | wc -l<br>ls -l | grep chr | wc -l

7. Getting External Data

a. wget - Get data from only URL, from command line

wget hgdownload.cse.ucsc.edu/goldenPath/hg38/database/ncbiRefSeq.txt.gz
ls -l
gunzip ncbiRefSeq.txt.gz
ls -l
head ncbiRefSeq.txt