Unix Handouts. Shantanu N Kulkarni

Similar documents
Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

CS246 Spring14 Programming Paradigm Notes on Linux

Perl and R Scripting for Biologists

Files

System Administration

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

EECS2301. Lab 1 Winter 2016

Introduction to Cygwin Operating Environment

Unix Filesystem. January 26 th, 2004 Class Meeting 2

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

Linux & Shell Programming 2014

Introduction: What is Unix?

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

Unix System Architecture, File System, and Shell Commands

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

Linux for Beginners. Windows users should download putty or bitvise:

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

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

The UNIX operating system is a set of programs that act as a link between the computer and the user.

(a) About Unix. History

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

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

Welcome to Linux. Lecture 1.1

CS395T: Introduction to Scientific and Technical Computing

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

CSE II-Sem)

UNIX / LINUX - GETTING STARTED

CISC 220 fall 2011, set 1: Linux basics

Introduction to the UNIX command line

EE516: Embedded Software Project 1. Setting Up Environment for Projects

Chapter-3. Introduction to Unix: Fundamental Commands

Unix Introduction to UNIX

Practical 4. Linux Commands: Working with Directories

Basic Unix Command. It is used to see the manual of the various command. It helps in selecting the correct options

Self-test Linux/UNIX fundamentals

CMU MSP 36602: Intro to UNIX and Scripting: Part 1

Files and Directories

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

UNIX Concepts COMPSCI 386

Practical Computing-II. Programming in the Linux Environment. 0. An Introduction. B.W.Gore. March 20, 2015

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

Unix/Linux: History and Philosophy

Introduction to Linux

Introduction to Linux

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Basic Linux Commands. Srihari Kalgi M.Tech, CSE (KReSIT), IIT Bombay. May 5, 2009

Introduction to Linux

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

Introduction to Linux Workshop 1

Course 144 Supplementary Materials. UNIX Fundamentals

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

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

ScazLab. Linux Scripting. Core Skills That Every Roboticist Must Have. Alex Litoiu Thursday, November 14, 13

CSCI 2132 Software Development. Lecture 4: Files and Directories

Introduction to Linux

Chapter 1. Getting started with UNIX

Introduction to Linux

Introduction to Unix: Fundamental Commands

Week 2 Lecture 3. Unix

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

Common UNIX Commands. Unix. User Interfaces. Unix Commands Winter COMP 1270 Computer Usage II 9-1. Using UNIX. Unix has a command line interface

Linux Shell Script. J. K. Mandal

Introduction of Linux

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

Mills HPC Tutorial Series. Linux Basics I

Essential Linux Shell Commands

CSC209. Software Tools and Systems Programming.

Linux Systems Administration Getting Started with Linux

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

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

*nix Crash Course. Presented by: Virginia Tech Linux / Unix Users Group VTLUUG

Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~

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

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

d. Permissions 600 on directory dir and 300 on file dir/foo. c. Permissions 700 on directory dir and 200 on file dir/foo.

UNIX Basics. UNIX Basics CIS 218 Oakton Community College

Command-line interpreters

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

Introduction to Linux

Introduction to UNIX I: Command Line 1 / 21

Introduction to Linux Part I: The Filesystem Luca Heltai

UNIX Kernel. UNIX History

A Brief Introduction to Unix

Outline. Structure of a UNIX command

Multiple Choice - 58 Questions - 10 of 15%

d. 1 e. test: $a: integer expression expected

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 1

Getting started with Hugs on Linux

Working with Basic Linux. Daniel Balagué

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

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

UNIX File Hierarchy: Structure and Commands

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

CS 300. Data Structures

commandname flags arguments

Transcription:

Unix Handouts Shantanu N Kulkarni Abstract These handouts are meant to be used as a study aid during my class. They are neither complete nor sincerely accurate. The idea is that the participants should concentrate more on the session, than on writing. 1 History The timeline of Unix can be very briefly summarised as below. The key people who played a leading role in initial development of Unix were, Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, Rob Pike and Joe Ossanna. 1960s - MIT, Bell Labs GE worked on Multics 1971 - Unix, 1 st edition 1972 - Unix written in C 1975 - Unix version 4, 5 and 6 released 1983 - FSF founded by RMS 1991-386BSD (BSD on intel) and Linux released 2 Introducing the Shell The shell is a program that interprets commands and acts as an intermediary between the user and the kernel. sh (Bourne shell, S. R. Bourne) csh (C-shell, Bill Joy) tcsh (TENEX C-shell) ksh (David Korn, AT&T) bash (Bourne again shell, Brian Fox) 3 Command Syntax and Getting Help The basic syntax of a command is, command -switch arguments Unix comes with excellent help system in form of man (short for manual) pages. One invokes this system by giving at the prompt man name-of-the-command. # displays manual of the cat command $ man cat The echo command writes arguments to the standard output. The who command displays who is logged in. # Display text $ echo Hello world Hello world # Current shell $ echo $0 -bash echo $0 and echo $SHELL shows the name of the shell. The symbol indicates that a space is required. 1

5 FILE AND DIRECTORY COMMANDS $ who am i shantanu tty7 Aug 19 16:10 (:0) $ who shantanu tty7 Aug 19 16:10 (:0) charuhas pts/0 Aug 19 16:11 192.168.1.2 The date command is used to display or set date and time. $ date Fri Aug 19 17:32:37 IST 2011 $ date -u Fri Aug 19 12:02:47 UTC 2011 $ date +%d 19 $ date +%m 08 $ date +%y 11 $ date +%d%m%y 190811 4 Directory Structure / : This is the root directory. /bin : contains executable programs /sbin : like /bin, but which are usually not executed by normal users /usr : hold only sharable, read-only data /var : spool and log files /home : home directories for users are usually beneath this directory /root : home directory of root user /etc : contains configuration files /dev : special or device files, which refer to physical devices /tmp : temporary files 5 File and Directory Commands The touch command changes file access and modification times and the ls command lists directory contents. The rm command removes directory entries. $ touch foo $ touch bar car $ ls bar car foo $ rm foo $ rm -i foo rm: remove regular file foo'? $ ls -l total 0 -rw-r--r-- 1 shantanu shantanu 0 Aug 19 18:41 bar -rw-r--r-- 1 shantanu shantanu 0 Aug 19 18:41 foo $ ls -l /etc total 1588 Only the superuser may change the date.

5 FILE AND DIRECTORY COMMANDS drwxr-xr-x 5 root root 4096 Apr 29 2010 ConsoleKit -rw-r--r-- 1 root root 2964 Nov 7 2009 Muttprintrc drwxr-xr-x 2 root root 4096 Jan 21 2011 Muttrc.d... The mkdir command is used to create directories, while the rmdir command is used to delete empty directories. The cd built-in is used to change to directories and pwd command shows the present working directory. $ mkdir dir1 $ rmdir dir1 $ mkdir a/b/c mkdir: cannot create directory a/b/c': No such file or directory $ mkdir -p a/b/c $ rmdir a/ rmdir: failed to remove a': Directory not empty $ rm -r a/ $ cd dir1/ /dir1 $ $ cd.. $ cd /etc/ /etc $ cd - $ cd /usr/local/ /usr/local $ cd ~/notes/ The cp and the mv commands are used to copy and move (rename) files respectively. $ cp foo bar $ cp /etc/passwd myfile $ cp /etc/passwd./ $ cp myfile myfile2 $ cp myfile2 dir1/ # Copies entire directory $ cp -r dir1/ dir2/ $ mv bar car Commands to view file contents The cat command is used to print file contents. The more or less commands are useful to view files screen-by-screen. $ cat /etc/passwd $ more /etc/passwd $ less /etc/passwd Aliases A way to execute a command with (usually) shorter name. $ alias c=clear $ alias dnow='date +%d%m%y' $ dnow 19082011 $ alias dnow alias dnow='date +%d%m%y' $ alias alias c='clear' alias dnow='date +%d%m%y' $ unalias dnow Aliases in csh and tcsh do not use = symbol.

6 FINDING FILES Links An inode stores all the information about a regular file, directory, or other file system object, except its data and name. A file s inode number can be found using the ls -i command. The ln command is used to make hard and symbolic links to files. # makes a hard link $ ln foo foo2 $ ls -li foo foo2 459486 -rw-r--r-- 2 shantanu shantanu 2322 Aug 20 19:17 foo 459486 -rw-r--r-- 2 shantanu shantanu 2322 Aug 20 19:17 foo2 # makes a soft links $ ln -s foo foo3 $ ls -li foo foo2 foo3 459486 -rw-r--r-- 2 shantanu shantanu 2322 Aug 20 19:17 foo 459486 -rw-r--r-- 2 shantanu shantanu 2322 Aug 20 19:17 foo2 459513 lrwxrwxrwx 1 shantanu shantanu 3 Aug 20 19:19 foo3 -> foo File Owerships and Permissions The chown command is used to change file ownership.the chmod command is used to change file permissions. u=user(owner), g=group, o=others, a=all three r=read, w=write, x=execute -rw-r--r-- 2 shantanu shantanu 0 Aug 19 17:34 foo $ chmod u+x foo -rwxr--r-- 2 shantanu shantanu 0 Aug 19 17:34 foo $ chmod g+w foo -rwxrw-r-- 2 shantanu shantanu 0 Aug 19 17:34 foo $ chmod ug-wx foo -r--r--r-- 2 shantanu shantanu 0 Aug 19 17:34 foo $ chmod ugo+r foo $ chmod a+r foo $ chmod 644 foo -rw-r--r-- 2 shantanu shantanu 0 Aug 19 17:34 foo $ chmod 123 foo ---x-w--wx 2 shantanu shantanu 0 Aug 19 17:34 foo 6 Finding Files The syntax of find command is, find path(s) expression(s) On many Unix systems only the superuser may use the chown command.

7 FILTERS # Find by name find./ -name 'passwd' find./ -name 'hosts*' # By type find./ -type d find./ -type f -a -name 'hosts*' # by size find./ -size +10000c find./ -size +10000c -o type d # by time find./ -mtime +7 find./ -newer sample 7 Filters Filters in Unix are those commands which show specific parts of the file (or input). The basic filters include, head and tail The head and tail utilities show by default first ten and last ten lines of a given file respectively. $ cat sample.txt $ head -n 2 sample.txt $ tail -n 2 sample.txt cut The cut utility selects portions of each line vertically. -d delim : use delim as delimiter $ cut -d ',' -f1 sample.txt archis shantanu anil $ cut -d ',' -f1,3 sample.txt archis,python shantanu,python anil,perl -f list : show fields specified in list $ cut -d ',' -f1-3 sample.txt archis,shell,python shantanu,shell,python anil,php,perl $ cut -d ',' -f3- sample.txt python,c,198 python,make,234 perl,make,789 sort The sort utility sorts text files by lines. -r : reverse sort -t char : use char as field separator $ sort sample.txt -n : numeric sort -k pos : sort by key position $ sort -t ',' -k2 sample.txt

8 VI EDITOR $ sort -t ',' -r -k2 sample.txt $ sort -t ',' -n -k5 sample.txt grep The grep utility searches any given input files, selecting lines that match one or more patterns. -c : count of selected lines -i : case insensitive matching -v : not matching lines $ grep 'python' sample.txt $ grep -v 'python ' sample.txt $ grep -c 'python' sas mple.txt 2 8 VI Editor The VI editor is a screen-oriented text editor. The first thing to note about the VI editor is that it has two modes: command and insert. The command mode allows the entry of commands to manipulate text and the insert mode puts anything typed on the keyboard into the current file. To leave insert mode, one has to press the ESCAPE key. Basic survival commands are given below. Open and Close vi new.txt edit new.txt :w/:wq save/save and quit :w new2.txt save as new2.txt :q! quit do not save Cursor Movements h/j/k/l left,down,up,right w/b word forward/backward ^/$ start/end of line ng n th line Cut-Copy-Put x delete char dw/yw delete/copy word dd/yy delete/copy line p put (paste)