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

Similar documents
Chapter 2 Unix Utilities for non-programmers

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Mills HPC Tutorial Series. Linux Basics I

CS4350 Unix Programming. Outline

Outline. Structure of a UNIX command

UNIX Quick Reference

COSC UNIX. Textbook. Grading Scheme

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.

CSCI 2132 Software Development. Lecture 4: Files and Directories

Chapter-3. Introduction to Unix: Fundamental Commands

Introduction to Linux Environment. Yun-Wen Chen

Linux/Cygwin Practice Computer Architecture

commandname flags arguments

Unix Introduction to UNIX

Std: XI CHAPTER-3 LINUX

CSCI 2132 Software Development. Lecture 5: File Permissions

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

Practical Session 0 Introduction to Linux

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

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

Getting started with Hugs on Linux

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

Operating Systems, Unix Files and Commands SEEM

Editors in Unix come in two general flavours:

Files and Directories

Perl and R Scripting for Biologists

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

Lecture # 2 Introduction to UNIX (Part 2)

CS Fundamentals of Programming II Fall Very Basic UNIX

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

Getting started with Hugs on Linux

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

Getting Started With UNIX Lab Exercises

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

SECTION -C. Getting Started with UNIX

CISC 220 fall 2011, set 1: Linux basics

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

Basic Unix Commands. CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang

Intro. To Unix commands. What are the machines? Very basics

Working with Basic Linux. Daniel Balagué

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

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

2) clear :- It clears the terminal screen. Syntax :- clear

CSCE 212H, Spring 2008, Matthews Lab Assignment 1: Representation of Integers Assigned: January 17 Due: January 22

Helpful Tips for Labs. CS140, Spring 2015

CS CS Tutorial 2 2 Winter 2018

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

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

Introduction to Unix: Fundamental Commands

Using the Unix system. UNIX Introduction

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

Linux & Shell Programming 2014

bash startup files Linux/Unix files stty Todd Kelley CST8207 Todd Kelley 1

Introduction. File System. Note. Achtung!

FILE MAINTENANCE COMMANDS

Getting Started with UNIX

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Introduction: What is Unix?

Short Read Sequencing Analysis Workshop

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Introduction to Linux. Fundamentals of Computer Science

Unix Tutorial. Beginner. CS Help Desk: Marc Jarvis (in spirit), Monica Ung, Corey Antoniuk 2015

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 1

Using the Zoo Workstations

AN INTRODUCTION TO UNIX

IMPORTANT: Logging Off LOGGING IN

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

RH033 Red Hat Linux Essentials

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

Course 144 Supplementary Materials. UNIX Fundamentals

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

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

A Brief Introduction to Unix

Introduction to Linux

April 2007 UNIX - An Overview No.76

CHE3935. Lecture 1. Introduction to Linux

Unix Workshop Aug 2014

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

Introduction to the Linux Command Line

Basic File Attributes

Unix basics exercise MBV-INFX410

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

Linux Command Line Primer. By: Scott Marshall

Week 2 Lecture 3. Unix

12/7/10 ATSC 212 UNIX ATSC 212 ATSC 212 UNIX

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Introduction to Linux

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

No Food or Drink in this room. Logon to Windows machine

100 SHELL PROGRAMS IN UNIX

Introduction to Linux

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

Some useful UNIX Commands written down by Razor for newbies to get a start in UNIX

Oxford University Computing Services. Getting Started with Unix

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

Transcription:

Chapter 2 Unix Utilities for non-programmers Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, 2003. Original Notes by Raj Sunderraman Converted to presentation and updated by Michael Weeks 8/20/2008 cs3320 1 Getting Started Obtain an account -OR- install Linux Logging in locally: enter username and password remotely: use the ssh/telnet utility to sign on to Upon logging on you will see a prompt (usually $ or %) which is displayed by a special kind of program called a SHELL program. To set your password, use passwd 8/20/2008 cs3320 2 Shells Popular shells: Bourne Shell Korn Shell C Shell Bash (Bourne Again SHell) All have common core functionality; some differences. Each shell has its own programming language. (Shell programming). 8/20/2008 cs3320 3 Running Utilities To run a utility, simply type the name of the utility after the prompt. Some utilities: date, man, clear, stty, passwd Utility: date [yymmddhhmm[.ss]] Utility: clear Utility: man [-s section] word man -k keyword To logout, enter CTRL-D (or exit) 8/20/2008 cs3320 4 Special Characters list meta characters with stty -a command ^ means control ^C means hold down control key (CTRL) and press the C key 8/20/2008 cs3320 5 Special Characters erase: CTRL-H erase character before cursor werase: CTRL-W erase word before cursor kill: CTRL-U erase entire line rprnt: CTRL-R reprint line To test these: type some input like one two three four at the terminal prompt move cursor around try the above characters 8/20/2008 cs3320 6

Special Characters intr: CTRL-C interrupt running program susp: CTRL-Z suspend running program stop: CTRL-S/CTRL-Q stop printing to screen eof: CTRL-D give program end of file To test these: Try a command like find * For eof, try cat > testfile then CTRL-D on new line Some common UNIX utilities pwd cat (like concatenate), more, page, head, tail ls, cd mv, cp, rm mkdir, rmdir file (determine file type), wc (word count), lp vi, pico, emacs groups, chgrp, chmod 8/20/2008 cs3320 7 8/20/2008 cs3320 8 Pathnames /home/mweeks/x.c /export/home/mweeks /Users/mweeks /usr/oracle/m01/app/oracle/product/8.0.4/bin/sqlpl us. refers to current directory (example:./a.out).. refers to parent directory (example:../p2.cpp) 8/20/2008 cs3320 9 Example of cat $ cat > letter Hi Mom, Please send me money! David ^D $ ls -l letter -rw-r--r-- 1 qcheng other 38 May 28 11:20 letter 8/20/2008 cs3320 10 List Files (ls) $ ls -algfsdr <file-spec> options a: hidden files l: long listing g: group F: put character after file name indicating executable*, link@, directory/, socket= s: num. disk blocks d: dir details not contents R: recursive listing Show File Contents (cat, more) $ cat <file-spec-list> list contents of file(s) on screen without pause $ more <file-spec-list> same as cat; pauses after each screen -more- space bar takes you to next screen; qquit enter shows next line hhelp key for more commands 8/20/2008 cs3320 11 8/20/2008 cs3320 12

Show File Contents (page, head, tail) $ page <file-spec-list> same as more; clears screen before each page quicker $ head -n <file-spec> display n lines from front of file $ tail -n <file-spec> display n lines from end of file Working with Directories $ mkdir <dname> make a new directory $ cd <dir> built-in to shell changes shell to a different directory $ pwd print working directory 8/20/2008 cs3320 13 8/20/2008 cs3320 14 Rename Files (mv) rename files (simply change labels in the file hierarchy) $ mv -i <old> <new> i for inquire (prompt if <new> already exists) $ mv -i <file-spec> <dir> $ mv -i <dir> <dir> Copy Files (cp) $ cp -i <old> <new> i for inquire (prompt if <new> already exists) $ cp -i <file-spec> <dir> $ cp -ir <file-spec> <dir> r for recursive 8/20/2008 cs3320 15 8/20/2008 cs3320 16 Removing Files (rm, rmdir) remove (delete) file $ rm -fir <file-spec> f: force; inhibits all prompts/messages i: inquire r: recursive Be careful! This is a permanent deletion! remove (delete) directory $ rmdir <dir> Line Printing Commands Print file <file-spec> to printer dest : $ lp -d dest -n copies <file-spec> also lpr Get status of jobs at printer dest $ lpstat dest Stop a print job Need job number <request-id> from above $ cancel <request-id> 8/20/2008 cs3320 17 8/20/2008 cs3320 18

Word Count word count $ wc -clw <file-spec> c counts the bytes l counts the newline characters w prints the word counts File Attributes -rwx------ 1 cscqxcx cscqxcx 3661 Jan 9 23:12 RingBufferActOutHandler.java -rwx------ : file type (first char), permissions file type (- regular, d dir, b buffered file disk drive, c unbuffered file terminal, l link, ppp pipe, s socket) 1 : hard link count cscqxcx : file owner cscqxcx : file's group 3661 : file size in bytes Jan 9 23:12 : file modification date RingBufferActOutHandler.java : file name 8/20/2008 cs3320 19 8/20/2008 cs3320 20 File Type $ file <fname> ascertains the type of file (ascii/binary etc.) example: [cscqxcx@techie BattleFieldOnFramework]$ file BFComputation.c BFComputation.c: ASCII C program text, with CRLF line terminators File Type example: [cscqxcx@techie testbed]$ file * BattleFieldOnFramework: directory BattleFieldOnFramework.09.24.tar: POSIX tar archive RingBufferActOutHandler.java: ASCII C program text Samples: directory try: ASCII text 8/20/2008 cs3320 21 8/20/2008 cs3320 22 Process Attributes When a process executes, it has a real user ID an effective user ID a real group ID an effective group ID Process Attributes When you log in, your login shell process has its real/effective user id set to your user id real/effective group id set to your group id 8/20/2008 cs3320 23 8/20/2008 cs3320 24

Process' File Permissions When a process runs, the file permissions apply as follows: If process' effective user id = owner of file; User Privilege applies If process' effective user id is not owner of file, but its effective group id = file's group id; Group Privilege applies Otherwise Other Privilege applies Real user id is used for accounting purposes only Process Access Rights Process Access Rights depends on who executes the process, NOT who owns the executable Sometimes undesirable Example: game of rogue file of best scores needs to be modified ONLY by rogue program process when player ends game; NOT by players' shells. 8/20/2008 cs3320 25 8/20/2008 cs3320 26 Process Access Rights Special feature: 2 special file permissions set user ID (s instead of x) set group ID When an executable with set user ID is executed, the effective user ID of the process becomes that of the executable, NOT of the players shell Allows process to modify best scores file Groups list the groups a particular user belongs to $ groups <userid> change the group a file belongs to $ chgrp -R <group-name> <file-spec> R stands for recursive create subshell with effective group id = group $ newgrp <group-name> 8/20/2008 cs3320 27 8/20/2008 cs3320 28 Change File Permissions change file mode; u,g,o,a r,w,x,s user, group, other, all read, write, execute, (set) plus (+) adds permissions minus (-) subtracts Also allows octal numbers Change File Permissions Examples $ chmod -R XXX <file-spec> $ chmod -R g+w <file-spec> $ chmod -R u-rw <file-spec> $ chmod -R u+w,g-r <file-spec> 8/20/2008 cs3320 29 8/20/2008 cs3320 30

Change File Permissions Example with octal numbers mweeks@carmaux:~$ ls -l example.txt -rw-r--r-- 1 mweeks mweeks 51 2007-08-23 16:06 example.txt mweeks@carmaux:~$ chmod 765 example.txt mweeks@carmaux:~$ ls -l example.txt -rwxrw-r-x 1 mweeks mweeks 51 2007-08-23 16:06 example.txt Notice: 7 = 111 (binary) r on, w on, x on 6 = 110 (binary) r on, w on, x off 5 = 101 (binary) r on, w off, x on 8/20/2008 cs3320 31 Change File Owner change owner of file $ chown <new-owner> <file-spec> only super user can do this 8/20/2008 cs3320 32 visual text editor Very common on Unix systems Created by Bill Joy in 1976 Many versions exist, including vim viimproved Command mode vs Text Entry Mode To enter text entry mode use the following commands: i,i,a,a,o,o,r to get back to command mode use ESC line ranges: 1,$ 1,..,$.,.-2 5,12.,.+12 8/20/2008 cs3320 33 8/20/2008 cs3320 34 Cursor Movement: up arrow k down arrow j left arrow h right arrow l beginning of line 0 first non-whitespace char in line ^ end of line $ 8/20/2008 cs3320 35 Cursor Movement: next word w previous word (back) b Goto line number nn :nn Go to last line :$ Arithmetic expression 1,$ 1,..,$.,-2 8/20/2008 cs3320 36

CTRL-D (down half screen) CTRL-U (up half screen) CTRL-F (forward one screen) CTRL-B (back one screen) 8/20/2008 cs3320 37 Deleting Text: delete character under cursor x delete word dw delete line dd (also D) delete many lines :<range>d Replacing text: replace char under cursor r replace word under cursor cw replace entire line cc substitute next 4 characters 4s 8/20/2008 cs3320 38 Pasting text: :<range>y (yank lines) 5yy (yank 5 lines) p P :nnp (after line nn) pu Searching: search forward /sss/ search backward?sss? Searching/Replacing: :<range>s/sss/ttt/ :<range>s/sss/ttt/g 8/20/2008 cs3320 39 8/20/2008 cs3320 40 Saving/Loading: write to file :w <fname> write again :w write :<range>w <fname> write and quit :wq edit new file :e <fname> read (insert) a file :r <fname> Misc re-draw screen CTRL-L execute a shell command :!comand Quitting: quit :q write and quit :wq quit without writing :q! exit and write if changed :x 8/20/2008 cs3320 41 8/20/2008 cs3320 42

Review Shells and Special Characters Common Utilities Working with Directories Removing Files File Attributes/Types Process Attributes File permissions, groups, and owner The vi editor 8/20/2008 cs3320 43