Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

INTERNATIONAL WORKSHOP IN

THE AREA OF
“BIOINFORMATICS, GENOMICS,
TEXT MINING AND NGS DATA
ANALYSIS"
SEPTEMBER 12 - 30, 2022
LINUX AND COMMAND LINE
INTERFACE (CLI)

DR. SURENDRA VIKRAM


What is an Operating system
(OS)?
It’s a “suite” of programs which make the
computer to work. It is a stable, multi-
user, multi-tasking system for servers,
desktops and laptops.

UNIX is an operating system

Unix is written in “C” and “assembly


language”

Developed in the 1960s (at Bell Labs) and


has been under constant development ever
since.

UNIX systems also have a graphical user


interface (GUI) similar to Microsoft
Windows.
WHAT IS LINUX?

• Linux is a Unix clone written from scratch by


Linus Torvalds with assistance from a loosely-knit
team of hackers across the net.

• Linux and Unix strive to be portable operating


system interface (posix) compliant.

• 64% of the world’s servers run some variant of


Unix or Linux.

• The android phones and the kindle run Linux


kernel.
ADVANTAGES OF LINUX?
• It is multi-user, multitasking, multiprocessor,
multithreading
• Has the X Windows GUI
• Co-exists with other Operating Systems
• It runs on multiple platforms
• Includes the Source Code
• Most versions of Linux are free of cost
OPEN-SOURCE SOFTWARE
PEOPLE IMPROVE IT, PEOPLE ADAPT IT, PEOPLE FIX BUGS. AND THIS CAN
HAPPEN AT A SPEED THAT, COMPARED TO CONVENTIONAL SOFTWARE
DEVELOPMENT, SEEMS ASTONISHING.
WINDOWS SUBSYSTEM FOR LINUX

• RUN GNU/LINUX ENVIRONMENT INCLUDING CLI, UTILITIES AND APPLICATIONS DIRECTLY ON


WINDOWS
• DOCUMENTATION LINK TO INSTALL WSL: HTTPS://DOCS.MICROSOFT.COM/EN-
US/WINDOWS/WSL/INSTALL
INSTALL LINUX AS A SUBSYSTEM

• DOWNLOAD LINUX OF YOUR CHOICE FOR EXAMPLE: UBUNTU


(HTTPS://UBUNTU.COM/DOWNLOAD/DESKTOP)
• CREATE BOOTABLE FLASH DISK USING RUFUS
(HTTPS://GITHUB.COM/PBATARD/RUFUS/RELEASES/DOWNLOAD/V3.18/RUFUS-3.18.EXE) OR
BALENAETCHER (HTTPS://WWW.BALENA.IO/ETCHER/)
• YOU CAN FOLLOW THIS TUTORIAL TO INSTALL THE LINUX ALONGSIDE THE WINDOWS.
(HTTPS://MEDIUM.COM/LINUXFOREVERYONE/HOW-TO-INSTALL-UBUNTU-20-04-AND-DUAL-
BOOT-ALONGSIDE-WINDOWS-10-323A85271A73)
DIRECTORY STRUCTURE IN LINUX

/bin (binary) commands and


programs used by all the
users of the system
/boot files required by the
boot loader
/dev CD/DVD-ROM, floppy
drives, USB devices,
eaternal HDD, etc.
/etc System configuration
files
/home User(s) data files

Caution: Do not
alter/modify/delete any system
file/directory.
LINUX COMMAND LINE INTERFACE (CLI)
Terminal can be accessed from search menu on Ubuntu Linux
LINUX COMMAND LINE INTERFACE (CLI);
TERMINAL

In Linux we use the


file names without
spaces because
space is also a
character which is
recognized by the
operating system.
• To execute a command, type its name and arguments at the command line

ls -l /etc Argument

Command Option/ flag


IMPORTANT LINUX COMMANDS
“ls” command
ls command lists the contents of the current working directory
“ls -a” to see the hidden files in your home directory.
“ls -l” to see the output on list format with size and time stamp
“chmod”

Octal Symbolic
Permission
Notation Representation
0 No Permission ---
1 Execute Permission Only --x
2 Write Permission Only -w-
Write and Execute
3 -wx
Permissions (1+2)=3
4 Read Permission Only r--
Read and Execute
5 r-x
Permissions (1+4)=5
Read and Write The next nine characters represent the file
6 rw- permissions, three triplets of three characters
Permissions (2+4)=6
each. The first triplet shows the owner
Read, Write and Execute permissions, the second one group permissions, and
the last triplet shows everybody else permissions.
7 Permissions, Means Full rwx The permissions can have a different meaning
Permissions (1+2+4)=7 depending on the file type.

“chmod 744 filename” to change the


permission of the file
LINUX COMMANDS
• “man name_of_command” to see the related manual for the command

• “touch filename”

• “mkdir docs” to create a new directory named “docs”

• “cd” is a command to “change the directory”

• “cd .” to the current directory

• “cd /path_to_directory/” to any directory for the given path

• “cd ..” one directory up in the directory structure.

• “pwd” to see the present working directory

• tilde (~) can be used to represent the user’s directory in the home
MORE COMMANDS

• “cp /source/file/path/file /destination/file/path”

• “mv source/file/path/file destination/file/path”

• “mv” command can be also used to rename the files

• “mv file_old_name file_new_name”

• “less filename” read the content of any file on terminal.


MORE COMMANDS
• “>” symbol to redirect the output to a file.

• “cat file1 > file2”

• “>>” symbol to append (add) at the end of the file

• “cat file3 >> file2”

• “echo “Print this on terminal”

• wild card (*) ?

• “ls * ” command lists all files and directories in the current


directory

• “echo *”
MORE COMMANDS

• “rm filename” to delete a file in the


present working directory
• “rm -r” deletes all the files and directory
content
• “rm -f” forced deletion of files (If files
are write protect)
COMMAND: CUT
• Cut command is used to select the columns from the file. The
selection can be based on delimiter, byte position and character
• “cut OPTION... [FILE]...”
• “cut –f 1,2,3 sra_accession.txt
• “cut –f 1-5 sra_accession.txt
• “cut –f 1-5,8-10 sra_accession.txt
• “cut –f 1-5,8-10 --complement sra_accession.txt
• “cut –d ‘,’ –f 1-5,8-10 --complement sra_accession.txt
• cut -d ',' -f 1-5,6,7 --output-delimiter=$'\t'
sra_accession_comma.txt
COMMAND: SORT
• The Sort command is a simple command that can be used to
rearrange the contents of text files line by line.
• Numbers are sorted to be ahead of letters.
• Lowercase letters are sorted to be ahead of uppercase letters.
• “sort -u -k 1 -v sra_accession.txt”
• “sort -u -k 1 -V sra_accession.txt | less ”
• “sort -u -k 1 -V sra_accession.txt | less”
• “cut –f 2 sra_accession.txt | sort –u –V “
COMMAND: HEAD & TAIL

• To quickly see the content of a file.


• Head command selects the top lines from a file. Tail command
selects the lines from the bottom of a file. Default output is to
show 10 lines, but it can be change.
• “head sra_accession.txt”
• “tail sra_accession.txt”
• “head –n 5 sra_accession.txt”
• “tail –n 5 sra_accession.txt”
COMMAND: WC (WORD COUNT)
• “wc sra_accession.txt”
• The output will be in the four columns. First column shows the
number of lines in the file, second column shows the number of
words, third column shows the number of characters present in the
file and fourth column shows the input file name.
• “wc -l sra_accession.txt”
• Only shows the number of lines in the file.
• “wc –w sra_accession.txt”
• Only shows the number of words.
• “wc –c sra_accession.txt”
• Only shows the number of characters.
COMMAND: PASTE AND CAT
• “Paste command” is used to join files horizontally (parallel
merging) by outputting lines consisting of lines from each file
specified, separated by tab as delimiter, to the standard output.
• “Cat command” reads data from the file and gives their content as
output. It helps us to create, view, concatenate files.
• “paste sra_accession.txt file.txt”
• “paste –d ‘,’ sra_accession_comma.txt file.txt”
• “paste –s sra_accession_comma.txt file.txt”
• “cat file.txt”
• “cat file.txt > file_1.txt”
• “cat sra_accession_comma.txt file.txt > combined_file.txt”
COMMAND: GREP
• “grep [options] pattern [files]”
Options Description
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
with each such part on a separate output line.
“grep -n “paired” sra_accession.txt (search the pattern and
display the output with line number)
“grep -c “paired” sra_accession.txt (search the pattern and output
the number of lines occurrences)
“grep -i “Fastq” sra_accession.txt (search the pattern as a case
sensitive string)
“grep –w “Fastq” sra_accession.txt (search the whole word
occurrence in the file)
“grep –o “Fastq” sra_accession.txt (Displaying only the matched
pattern from the file)
“grep –l “Fastq” * (Display the file names that matches the
pattern)

You might also like