Std: XI CHAPTER-3 LINUX

Similar documents
Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

5/8/2012. Creating and Changing Directories Chapter 7

Mills HPC Tutorial Series. Linux Basics I

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

CSCI 2132 Software Development. Lecture 4: Files and Directories

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Getting Started with UNIX

h/w m/c Kernel shell Application s/w user

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

Chapter-3. Introduction to Unix: Fundamental Commands

UNIX System Programming Lecture 3: BASH Programming

Outline. Structure of a UNIX command

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Introduction to Unix: Fundamental Commands

5/20/2007. Touring Essential Programs

Week 2 Lecture 3. Unix

Linux Command Line Primer. By: Scott Marshall

Linux Shell Script. J. K. Mandal

5/8/2012. Exploring Utilities Chapter 5

CHE3935. Lecture 1. Introduction to Linux

A Brief Introduction to the Linux Shell for Data Science

commandname flags arguments

Overview of the UNIX File System

Perl and R Scripting for Biologists

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

Overview of the UNIX File System. Navigating and Viewing Directories

Files and Directories

Introduction: What is Unix?

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Lab Working with Linux Command Line

Introduction of Linux

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

CS4350 Unix Programming. Outline

Introduction to Unix and Linux. Workshop 1: Directories and Files

Files

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Linux/Cygwin Practice Computer Architecture

Introduction to Linux Environment. Yun-Wen Chen

This is Lab Worksheet 3 - not an Assignment

Lab 2: Linux/Unix shell

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Scripting Languages Course 1. Diana Trandabăț

Full file at

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

CS246 Spring14 Programming Paradigm Notes on Linux

Introduction to Linux

Introduction to Linux Workshop 1

Introduction to the UNIX command line

FREEENGINEER.ORG. 1 of 6 11/5/15 8:31 PM. Learn UNIX in 10 minutes. Version 1.3. Preface

Introduction to Linux

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Using the Zoo Workstations

Commands are in black

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

The Unix Shell & Shell Scripts

Unix Introduction to UNIX

EECS2301. Lab 1 Winter 2016

Embedded Linux Systems. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Practical Session 0 Introduction to Linux

Introduction to Linux

Useful Unix Commands Cheat Sheet

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

Using the Unix system. UNIX Introduction

UNIX Quick Reference

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

CS Unix Tools. Lecture 2 Fall Hussam Abu-Libdeh based on slides by David Slater. September 10, 2010

Chapter 6. Linux File System

Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny.

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Oxford University Computing Services. Getting Started with Unix

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

Linux & Shell Programming 2014

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

CS Fundamentals of Programming II Fall Very Basic UNIX

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

(MCQZ-CS604 Operating Systems)

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

Linux environment. Graphical interface X-window + window manager. Text interface terminal + shell

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

LING 408/508: Computational Techniques for Linguists. Lecture 5

RH033 Red Hat Linux Essentials

A Brief Introduction to Unix

Basic File Attributes

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

(a) About Unix. History

The Unix Shell. Pipes and Filters

Getting your department account

Introduction. File System. Note. Achtung!

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

Transcription:

Commands: General format: Command Option Argument Command: ls - Lists the contents of a file. Option: Begins with minus sign (-) ls a Lists including the hidden files. Argument refers to the name of a file-.(dot). Path Name (Identifies the target file) Path for BIN {/bin- The first slash refers to the root directory} {/usr/bin} TWO TYPES OF PATH NAME Absolute path name [complete path] Relative path name Path names for job directory {/home/kumaran/personal/job}-absolute {/personal/job}-relative Identifying the path of working directory: pwd command Path of working directory Present working directory Print working directory [ilamathi@localhost ilamathi]$ pwd /home/ilamathi Changing the current directory: Current user ilamathi wants to switch over from home directory to the bin directory. The steps are [ilamathi@localhost ilamathi]$ pwd Page 1 of 12

/home/ilamathi [ilamathi@localhost ilamathi]$ cd/usr/bin [ilamathi@localhost ilamathi]$ pwd /usr/bin To change from current directory to parent directory give (cd..) command at the $ prompt. [ilamathi@localhost bin]$ cd.. [ilamathi@localhost/usr]$ pwd /usr NOTE: The cd command without any path name will always take the user to his /her home Directory The Tilde Sign (~) (Substitute for home directory) 1. Kumaran is currently in the directory /usr/bin wants to go to his personal directory.the easiest way to achieve this is the use of tilde sign and /personal. [kumaran@localhost bin]$ ~/personal /home/kumaran/personal [kumaran@localhost personal]$ cd ~ [kumaran@localhost kumaran]$ pwd /home/kumaran 2. Kumaran is in personal directory and he wants to go to his health directory [kumaran@localhost personal]$ cd.. /health [kumaran@localhost health]$ pwd /home/kumaran/health. Subdirectory- Directory under another directory Creating a Directory(mkdir): [kumaran@localhost health]$ mkdir insurance A new directory named insurance is created Removing a Directory (rmdir): [kumaran@localhost health]$ rmdir insurance A directory named insurance is removed Conditions for removing a directory The directory should be empty Should not be the working directory Page 2 of 12

Listing the contents of a directory: Kumaran wants to know the names of files and subdirectories of /home/kumaran [kumaran@localhost kumaran]$ ls /home/kumaran Health cprogramming c++programming personal [kumaran@localhost kumaran]$ ls F. Health/c programming/c++ programming/personal/. F adds slash at the end of the directories and subdirectories. l gives information about the files. Other Commands: The clear command clears the screen The same thing is done by tput clear command also The command tput cup 20 20 will position the cursor at row 20,column 20 Extracting the Help: Use of man command will lead us to know about the particular command $ man ls {help for ls command} The Echo Command: Displays a message to the user $ echo n Please enter your name.-n places the cursor in same line. File Commands: Cat-displays the contents of a file If the file is too lengthy, more command is used to show one page at a time Press f to move forward and b to move backward The tee command does double the work of cat command. It is just like Tpipe It takes the input from standard input and displays the contents on screen Stores the same in the file specified The LINUX files are arranged in a continuous stream of bytes Input data stream-standard input Output data stream-standard output Input: $ cat file 1 Output: contents of file 1 Input: $ more file 1 Output: contents of file 1 page by page Page 3 of 12

Redirection and Piping: 1. $ cat file 1 > file 2: copies the contents of file 1into file 2 where file 2 is empty If file 2 exists then its destroys file 2 and copies the contents of file 1 2. $ cat file 1 > file 1: copies file 1 into file 1 since file 1 exists and the right hand side is executed first, file 1 is destroyed. Then, left hand side is executed. Noclobber: Prevents overwriting an existing file by redirection operation Append (>>): To overcome the difficulty of overwriting the existing file, append operator is used. Example: $ cat file 1 >> file 2: appends the contents of file 1 to file 2 without overwriting. Standard Input: Commands receive data from the standard input. It is either connected to device or to file. By default, it is connected to the device KEYBOARD. The characters typed into the keyboard are taken to the standard input and then directed to the command. $ cat (without any argument): This command expects data from the standard input KEYBOARD. Ctrl + D: End of file work. $ cat > file (standard input redirection operator) Message Ctrl + D $ cat > file 3: The typed in material will be redirected to the cat command through the standard input and this is sent to the file after the > symbol. Input Redirection Operator (<): $ cat < file 3 In order to make the cat command to get data from the file 3 (not from keyboard), the command used is $ cat < file 3. Since there is no > symbol, the message is sent to the screen. If the standard input is to be redirected to receive its data from file 3 and the standard output is to be redirected to place the data in file 4, the command used is, $ cat < file 3 > file 4. Piping ( ): Page 4 of 12

Redirection operator works only on files. If you want to send the output of one command to another command, pipe is the only command used. Godown -> Carpenter -> Painter -> Godown Wood -> Chairs -> Painter chairs -> Godown Here, the chairs are taken to the painter through conveyor belts. And then to godowns through lorries. The action of conveyor belt is piping and that of lorry is redirection File is storage medium to store data. Command is a program or set of instructions. You can save data into or retrieve data from a file. A command may read from or save data into a file but command itself cannot store the data. Redirection simply places the output in a file but piping sends the output to another command. 1. $ cat file 3 lpr: The cat command gets the contents of the file 3 and sends it to the standard output. The output is piped to the lpr (line print). The lpr takes the standard output as the input and sends it to the printer. Thus pipes receive data from the command placed before the pipe and send it to the command placed after pipe. 2. $ cat n file 3 lpr: The cat command with n option sends the contents of file 3 to the standard output after numbering each line 3. $ cat file 3 more: Used if the length of the contents is large 4. $ cat file 1 file 2 file 3 more: displays the contents of more than one file with the line numbers. Each file is separated by a space and no comma is used. Sort Command This command sorts each line of the given file alphabetically and sends the sorted version to the standard output $ sort file 3 more $ sort file 3 cat - more $ sort file 3 cat n lpr $ sort file 5 tee file 6 : copies file 5 to file 6 but also displays the contents of file 5 on screen. $ sort file 5 tee s file 5 : sorted contents of file 5 can be copied into another file and displayed on screen. Here, s file 5 is the sorted file of file 5. The sorted file s file 5 is displayed on screen $ sort file 5 tee s file 5 lpr : sort - copy print Copying file: $ cp [options] < source file < destination > Page 5 of 12

$ cp file 1 file 6: copies the contents of file 1 to file 6. Option I in the above command is used for getting a warning from the system before over writing so that you can stop copying process. Input: $ cp i file 1 file 2 Output: overwrite file 2? n $ $ cp r alpha alpha 1 Copy a directory recursively using cp command with the r option -s option creates a symbolic link -v explains in detail what is being done. Removing file: $ rm file 1 file 2: file1, file 2 are removed in current directory $ rm r alpha : removes alpha 1 directory along with sub directories. Wild Cards: $ ls : all files $ ls *.c: list on files only with extn.c $ ls doc[12]: list files that start with doc and end with either 1 or 2 $ ls char? :? fixes number of characters. $ doc [1-5] doc [1-g] : specifies ranges. Edit Commands: Edit command line with the help of Left arrow (ctrl + B) Right arrow (ctrl + F) Back space (ctrl + H) Delete (Erase a char) Deletes a line (ctrl + U) Can enter more than one command in a same line but separate them by a semicolon. Moving and renaming files: mv [option] <source> <destination> Move mv command is used to move or rename a file $ mv temp temporary: Renames temp as temporary. Viewing system date and time: Refer page 155, 156. File Systems Mount and Unmount: Page 6 of 12

Establishing the connection between file system on a storage device and your main directory tree is calling mounting the device. This is done by Mount command. Here the command line prompt changes from $ to # Mount has two parameters. Storage device and Directory Device is a special device file that connects your system to the hardware device. Syntax: # mount device destination. E.g. for mount: # mount /dev/fd0/destination Device files are located in the /dev directories Fd0: first floppy disk drive Fd1: Second floppy disk drive Hda1: hard disk drive, first partition on the first hard drive. E.g. for Unmount: # unmount/dev/fd0 Unmount floppy disk mounted to the /destination directory Note: You can never unmount file system that you are currently working in. Mounting and formatting floppy disk: Mount: # mount/dev/fd0/mnt/floppy # unmount/dev/fd0 (or) #unmount/mnt/floppy, #mount/mnt/floppy Mkfs: makes formatting, commands (formats a floppy) Mounting- CD ROMs # mount/mnt/cdrom # unmount/mnt/cdrom # mount/dev/hdc/destination Vi Editor: Editors are used for creating, deleting and editing the files. The two types of editors are Ed (line editors) and VI (visual editors). Editors use keyboard for two main purposes. 1. To specify editing commands 2. To receive character input. Page 7 of 12

The keys used are the alphabetic character keys, function keys and control keys. Editors in linux use minimum number of keys. They are the alphabetic characters, control characters, ESC key and Enter key. The modes of VI editor are command mode and input mode. Command mode: The key (x) acts as delete key and erases a character where the cursor is on. Input mode: The same key (x) simply adds x to file. ESC keys help to check in which mode we are working. If already in command mode, no beep sound is heard. Beep sound indicates that we are in command mode at present but before in input mode. Creating, editing, saving, and quitting a file in VI: $ vi filename: edit/create a new file with the given filename If the file exists, the contents of file is listed page by page, otherwise empty screen is screen. Press a, I, or o: You will be taken to the input mode. After entering data, press ESC key. It will take you to command mode. Press upper case ZZ which saves your file and then exits vi editor. Press ESC key to change the command mode and press : to go to the line editing mode. Press w. This action saves the file and returns to command mode. The command :w (filename) is equivalent to save as in other word processors. $ vi (Creates a file without name) :w some name will save the file untitled 1. [contents of the buffer are copied into some name file] Clash of file name will not be tolerated. If a file exists already, the name will be rejected. We have to try with another name. Quit vi editor: q [takes to the shell] q! [out of vi editor without saving the saves] Moving keys: h - Left arrow j- Down arrow l- Right arrow k- up arrow Ctrl + F - moves the screen forward Ctrl + B - moves the screen backward Line number G: (Some line number) G: Takes you to the particular line. Simply G moves to the end of a file. Page 8 of 12

Word wrap: : set wm=col no.: Sets word wrap margin. Std: XI CHAPTER-3 LINUX Commands for inserting text: The lower case (a) key enters text input mode and appends the text after the cursor. The lower case (i) key enters text input mode and appends the text after the cursor. The lower case (o) key enters text input mode by opening a new line immediately below the current line Commands for Deleting text: x- deletes the current character dd- delete the current line nx- delete n characters from current position ndd- deletes n lines starting from the line where the cursor is on or erased. undo: press n (Undo last modification) Break a line: Press Enter key into the input mofe Press upper case (J) key to join two lines Moving: ndd delete n nos of lines p- insert deleted line (paste) Copying: yy- copies a line nyy- copies n lines fom the cursor into the buffer p- Similar to (xv paste) Searching: /-allows to search the pattern forward?.. allows to search the pattern backward. Changing: cc change entire contents of a line r - replace the current character R allows you to overwrite text cw- allows to change a word dw- allows to delte a word. Page 9 of 12

Shell Script: It is a text file that contains linux commands. A shell script is handy as you need to enter the command only once. Shell script allows input/output operations and manipulation of variables. Executing shell script when you logon to the linux system, you get a copy of the shell to work with. This shell is known as login shell. Default shell is BASH shell. It has the capabilities of the programming languages. Creating a shell: By giving sh command in the command prompt, a new shell is created. This new shell is known a sub shell or child shell of the current shell, which can be used to execute a shell script. You will have read and write privileges but execute permission is not granted immediately. Execute/Run a shell program: $ sh file name $. file name If you want to run a shell script directly at $ prompt, you can change FAP ( File access permission) by granting execute permission. This is done using chmod command $ chmod u + x edufile $ edufile +x with chmod gives the execute permission to any user u + x : Owner of file gets the execute permission Variables: They are place holders to store values. All linux variables are treated as character strings. Mathematical operations can be done using expr and let commands. Rules for creating variables: refer page 173 Syntax for creating variables: <variable _name> = <value> Name = Ezhil Name = Ezhil Name =Ezhil (The quotes are optional) Referencing Variables: $ symbol is need to refer the contents of a variable Page 10 of 12

var1=${var2}, var1, var2 are memory locations ${var2} command extracts the value found in that location Concatenation: If you want to concatenate the contents of one variable with another value, the braces are essential $ son1=$ {father} son, where father =john; add son to john. Store the result in son1. Reading a value into variable: echo Please enter your name -> prints string on screen Expressions: expr, let commands $ expr 21 + 51 displays 72 on screen $ let <value1><operator><value2> $% let pr = 5*10 echo The product of $pr Output: The product is 50 Command Substitution: $ date - Access current date of the system. echo Today s date is date + %D, mm/dd/yy Command substitution can also be used to store the output of a command in a variable: cfiles= ls*.c\wc-l cfiles Variables contains the no of files in the current directory where names end with.c Output to be stored in variable using command substitution: $ var1=5 $ var1= expr $var1 + 20 assigns 25 to var1 Page 11 of 12

. Page 12 of 12