CS4350 Unix Programming. Outline

Similar documents
Outline. Structure of a UNIX command

CS Fundamentals of Programming II Fall Very Basic UNIX

Unix Introduction to UNIX

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

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

Mills HPC Tutorial Series. Linux Basics I

Introduction: What is Unix?

Introduction to the Linux Command Line

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

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

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

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

Unix Filesystem. January 26 th, 2004 Class Meeting 2

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

Introduction to Linux

CISC 220 fall 2011, set 1: Linux basics

Week 2 Lecture 3. Unix

Introduction to Linux Workshop 1

History. Terminology. Opening a Terminal. Introduction to the Unix command line GNOME

Introduction to the UNIX command line

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Introduction to Linux

Linux Command Line Primer. By: Scott Marshall

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

Linux/Cygwin Practice Computer Architecture

Course 144 Supplementary Materials. UNIX Fundamentals

Chapter-3. Introduction to Unix: Fundamental Commands

Computer Systems and Architecture

Introduction to Linux

Getting started with Hugs on Linux

CSCI 2132 Software Development. Lecture 4: Files and Directories

Computer Systems and Architecture

A Brief Introduction to Unix

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

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

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

Working with Basic Linux. Daniel Balagué

Introduction to Linux

Physics REU Unix Tutorial

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

Getting Started with UNIX

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

INSE Lab 1 Introduction to UNIX Fall 2017

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Oxford University Computing Services. Getting Started with Unix

CS101 Linux Shell Handout

Introduction To Linux

Lecture # 2 Introduction to UNIX (Part 2)

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

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

Overview of the UNIX File System

Perl and R Scripting for Biologists

Connecting to ICS Server, Shell, Vim CS238P Operating Systems fall 18

Introduction to Unix: Fundamental Commands

Exploring UNIX: Session 3

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]

Basic File Attributes

CS246 Spring14 Programming Paradigm Notes on Linux

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

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

Std: XI CHAPTER-3 LINUX

National University of Computer and Emerging Sciences Operating System Lab - 02 Lab Manual

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

Files

Session 1: Accessing MUGrid and Command Line Basics

UNLV Computer Science Department CS 135 Lab Manual

Introduction to Linux. Fundamentals of Computer Science

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

Introduction to Linux Environment. Yun-Wen Chen

Getting started with Hugs on Linux

Short Read Sequencing Analysis Workshop

Linux at the Command Line Don Johnson of BU IS&T

commandname flags arguments

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

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

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

CHE3935. Lecture 1. Introduction to Linux

Unix Tutorial Haverford Astronomy 2014/2015

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

Overview of the UNIX File System. Navigating and Viewing Directories

UNIX Quick Reference

Introduction to the basics of UNIX

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

Using the Zoo Workstations

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.

Introduction to Linux (Part II) BUPT/QMUL 2018/03/21

The Unix Shell & Shell Scripts

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

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

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

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

INF322 Operating Systems

Editors in Unix come in two general flavours:

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

Exercise Sheet 2. (Classifications of Operating Systems)

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

CS/CIS 249 SP18 - Intro to Information Security

Linux Shell Script. J. K. Mandal

Operating Systems. Copyleft 2005, Binnur Kurt

Transcription:

Outline Unix Management Files and file systems Structure of Unix Commands Command help (man) Log on (terminal vs. graphical) System information (utility) File and directory structure (path) Permission (owner, group, rwx) File and directory management (link) Disk, process and memory System and user files vi and emacs commands Spring 2019 Husain Gholoom Lecturer in Computer Science Page 1

Unix Management Three every day managements: Manage files Manage users Manage processes Other managements: Manage hardware Spring 2019 Husain Gholoom Lecturer in Computer Science Page 2

Files and File Systems In UNIX, all files are organized in a single directory tree, regardless of where they are stored physically. There are two main types of files: Plain files (containing data). Directories ( folders ), containing both plain files (optionally) and other directories. Unix directories contain: One parent. N children (sub-directories). Files and links. Each file in a directory is identified by its name and has a number of attributes: Name Type Owner Group (each file belongs to one group, even if the owner belongs to multiple groups) Access rights Access dates Spring 2019 Husain Gholoom Lecturer in Computer Science Page 3

Files in the directory trees are described by pathname. Pathnames consist of file names, separated by slashes (/) Spring 2019 Husain Gholoom Lecturer in Computer Science Page 4

Directory Structure Spring 2019 Husain Gholoom Lecturer in Computer Science Page 5

Structure of a UNIX command $ command [ [ - ] option (s) ] [ option argument (s) ] [ command argument (s) ] Examples: $ whoami Help on UNIX The UNIX Programmer s Manual ( man pages ) Traditionally available on every UNIX system, quite terse Usage: man [section] <command> Sections (may differ by UNIX favor): 1. User commands 2. System calls 3. C library routines 4. Device drivers and network interfaces 5. File formats 6. Games and demos 7. Misc. (ASCII, macro packages, tables, etc) 8. Commands for system administration 9. Locally installed manual pages. (i.e. X11) man -k <term> gives you a list of pages relevant to <term> To leave the man program (or rather the pager it uses), hit q Spring 2019 Husain Gholoom Lecturer in Computer Science Page 6

man [options][-s section] command-list Example : $ man printf NAME printf -- formatted output SYNOPSIS printf format [arguments...] DESCRIPTION The printf utility formats and prints its arguments, after the first, under control of the format. The format is a character string which contains three types of objects: plain characters, which are simply copied to standard output, character escape sequences which are converted and copied to the standard output, and format specifications, each of which causes printing of the next successive argument. The arguments after the first are treated as strings if the corresponding format is either c, b or s; otherwise it is evaluated as a C constant, with the following extensions: A leading plus or minus sign is allowed. If the leading character is a single or double quote, the value is the ASCII code of the next character. The format string is reused as often as necessary to satisfy the arguments. Any extra format specifications are evaluated with zero or the null string. If the leading character is a single or double quote, the value is the ASCII code of the next character. Spring 2019 Husain Gholoom Lecturer in Computer Science Page 7

Character escape sequences are in backslash notation as defined in the ANSI X3.159-1989 (``ANSI C89''), with extensions. The characters and their meanings are as follows: \a Write a <bell> character. \b Write a <backspace> character. \c Ignore remaining characters in this string. \f Write a <form-feed> character. \n Write a <new-line> character. \r Write a <carriage return> character. \t Write a <tab> character. \v Write a <vertical tab> character. \' Write a <single quote> character. More Help on UNIX Commands whatis, which, whereis, info Google $ whatis login setenv login(1) -sign on setenv (1) -change or add an environment variable $ which mkdir /usr/bin/mkdir $ whereis mkdir mkdir: /usr/bin/mkdir $ info File: dir Node: Top This is the top of the INFO tree This (the Directory node) gives a menu of major topics. Typing "q" exits, "?" lists all Info commands, "d" returns here, "h" gives a primer for first-timers, "memacs<return>" visits the Emacs topic, etc.. Spring 2019 Husain Gholoom Lecturer in Computer Science Page 8

Logging On and Logging Off Text mode Local: UNIX terminal Remote: SSH Connecting via UNIX Terminal login: your_username <Enter> password: your_password <Enter> [yourname ~]$type_command_here Where's UNIX Linux Red Hat, SUSE, Debian, etc Windows Cygwin (www.cygwin.com) Solaris, AIX, HP UX Sun, IBM, HP Mac OS X FreeBSD Spring 2019 Husain Gholoom Lecturer in Computer Science Page 9

Secure Shell on a Windows PC You can download the Secure Shell client (or putty) from the CS departmental download server http://downloads.cs.txstate.edu Select os then windows then remote access, then SSHSecureShellClient-3.2.9.exe (then install it). To run: double click on Secure Shell Client icon Click Quick Connect and enter a host machine: hercules.cs.txstate.edu Enter username and password. Spring 2019 Husain Gholoom Lecturer in Computer Science Page 10

Navigating Unix So you log in Where am I in the tree? pwd Present Working Directory How do I go up and down the tree? cd Change Directory cd.. Up one directory cd ~ Your home directory cd ~<user> Home directory of <user> cd <path> Go to <path> Paths /home/user3/dir1 Spring 2019 Husain Gholoom Lecturer in Computer Science Page 11

Absolute Paths cd /home/user3/dir1 Relative Paths cd../home/user3 Spring 2019 Husain Gholoom Lecturer in Computer Science Page 12

Navigating Unix What files are here? ls Lists the names of files in your default directory, in alphabetical order. ls a ls l List ALL files. Including those files that begin with a period (i.e., hidden files). List files AND details. In addition to the file name, the long listing shows protection information, file owner, number of characters in file, and the date and time of the last change to the file. Generally, - enables switches You can combine switches ls la List ALL files AND details Spring 2019 Husain Gholoom Lecturer in Computer Science Page 13

Permissions drwxr--r-- directory -rwxr--r-- file -rwxr--r-- link ( hard ) drwxr--r-- rwx - read - write - execute 1st three - Owner (usually creator) 2nd three - Group (your friends) 3rd three Everyone Examples Files -rw------- Only owner can read and write -rwxrwxrwx Everyone can read, write and execute -rw-r--r-- Everyone can read, only owner can write Spring 2019 Husain Gholoom Lecturer in Computer Science Page 14

Examples Directories drwx------ Only owner can view, cd into, and delete drwxrwx--- Owner and group can view, write, etc. drwxr-xr-x Everyone can cd into but only owner can modify chmod Change Mode Change mode for who? ugoa user, group, others, or all Grant or deny access? + grant access - deny access Change which mode? rwx same as before Spring 2019 Husain Gholoom Lecturer in Computer Science Page 15

Examples : Add read access to "myfile" for group chmod g+r myfile Add write access to "myfile" for group chmod g+w myfile Deny read access for others chmod o-r myfile Add read and write access for user chmod u+rw myfile Give full group read/write access to directory "mydir" chmod g+rwx mydir Permissions Common mistake Directory without x enabled Program without x enabled File without r enabled File without w enabled Security Directory and files with rw enabled for others Spring 2019 Husain Gholoom Lecturer in Computer Science Page 16

File Create/Destroy The simple approach to create a file touch creates a file of size 0. For example : touch newfile.txt Creates a file known as "newfile.txt", if the file does not already exist. If the file already exists the accessed and modification time is updated for the file newfile.txt To delete one or multiple files rm <file> deletes the file. You will be asked to confirm that you really want to delete the file. Type y or n as appropriate and press Return. rm file1.* delete all files that starts with with file1 such as file1.txt, file1.html etc To avoid to answer yes for every file: rm f <file> Spring 2019 Husain Gholoom Lecturer in Computer Science Page 17

File Viewing Quick cat <file> Short for concatenate, it just displays the file to the screen. more <file> Like cat, this shows the entire contents of a file, but prompts you for more? between each page. Hit the space bar to go to the next page, or use the up and down arrows. Hit q to quit. less <file> This is another pager like more, i.e. it shows one page at a time. Slow emacs vim File Copy and Move Copy source to destination cp <source> <destination> Move source to destination mv <source> <destination> rename a file To recursively copy or move cp/mv R <source> <destination> Spring 2019 Husain Gholoom Lecturer in Computer Science Page 18

File Editing vim emacs gedit Kwrite small, hard to learn huge, hard to learn GUI, good Directory Maintenance Creating, Deleting and Managing Directories mkdir, cd, pwd, rm, rmdir, mv, cp $ mkdir mydir $ cd mydir $ pwd Print Working Directory the pwd command displays the name of the current working directory. $ cp r mydir mydir2 $ mv r mydir mydir2 $ rm rf mydir $ rmdir mydir Spring 2019 Husain Gholoom Lecturer in Computer Science Page 19

Link a Shortcut to a File Hard link : Creates a link to a file. ln <source> <linkname> Symbolic link ln s <source> <linkname> What will happen if the source is deleted? User and Group Change owner and group chown o chown [ R] owner[:group] file. For Example chown Jeff file1 allows jeff to be the owner of the file file1 chgrp o chgrp [ R] group file For Example chgrp -R staff proposals change the group ownership of the directory named proposals, and of all the files and subdirectories under it, to staff Spring 2019 Husain Gholoom Lecturer in Computer Science Page 20

Process and Signal Show process information ps : Show the Active Process ps A : Show all Processes Kill a process kill <pid> kill s <pid> : signal number like -9 Disk and Memory Disk space information Disk space usage of the system df [-k] Disk space usage of a file or a directory du [-k] <filename> Memory and process information top Spring 2019 Husain Gholoom Lecturer in Computer Science Page 21

Important system directories /etc : Network file /bin : Commands and Utilities /dev : Device and their uses /lib : System libraries, Kernel Modules /sbin : Contains fundamental utilities, such as init, usually needed to start, maintain and recover the system. /usr/share : This directory contains 'shareable', architecture-independent files (docs, icons, fonts etc) /usr/man : It once held the man pages. It has been moved to /usr/share/man. /usr/bin : This directory stores all binary programs distributed with the operating system not residing in /bin, /sbin /usr/sbin : Non-essential system binaries /usr/include : Stores the development headers used throughout the system Important system configuration files passwd : change system password. Spring 2019 Husain Gholoom Lecturer in Computer Science Page 22

Other Commands 1. Ends the processes with the ID you gave: kill PID 2. Shows the current date and time: date 3. Show a calendar of the current month: cal 4. Show a calendar of specific month / year: cal 10 2018 5. Counts lines, words, and characters in its inputs: wc test2.sh 6. Displays the first 10 lines of its input: head test2.sh 7. Displays the last 10 lines of its input: tail test2.h 8. Display the current jobs running in the backgroup: jobs Spring 2019 Husain Gholoom Lecturer in Computer Science Page 23

VI Editor Commands Starting vi To start using vi, at the Unix prompt type vi followed by a file name. If you wish to edit an existing file, type in its name; if you are creating a new file, type in the name you wish to give to the new file. $ vi filename Then hit Return. You will see a screen similar to the one below which shows blank lines with tildes and the name and status of the file. ~ ~ "myfile" [New file] vi's Modes and Moods vi has two modes: the command mode and the insert mode. It is essential that you know which mode you are in at any given point in time. When you are in command mode, letters of the keyboard will be interpreted as commands. When you are in insert mode the same letters of the keyboard will type or edit text. vi always starts out in command mode. When you wish to move between the two modes, keep these things in mind. You can type i to enter the insert mode. If you wish to leave insert mode and return to the command mode, hit the ESC key. If you're not sure where you are, hit ESC a couple of times and that should put you back in command mode. Entering Text To begin entering text in an empty file, you must first change from the command mode to the insert mode. To do this, type the letter i. When you start typing, anything you type will be entered into the file. Type a few short lines and hit Return at the end of each of line Spring 2019 Husain Gholoom Lecturer in Computer Science Page 24

Spring 2019 Husain Gholoom Lecturer in Computer Science Page 25

Moving One Character at a Time Try using your direction keys to move up, down, left and right in your file. Sometimes, you may find that the direction keys don't work. If that is the case, to move the cursor one character at the time, you may use the h, j, k, and l keys. These keys move you in the following directions: h left one space l right one space j down one space k up one space If you move the cursor as far as you can in any direction, you may see a screen flash or hear a beep. Moving among Words and Lines While these four keys (or your direction keys) can move you just about anywhere you want to go in your file, there are some shortcut keys that you can use to move a little more quickly through a document. To move more quickly among words, you might use the following: w moves the cursor forward one word b moves the cursor backward one word (if in the middle of a word, b will move you to the beginning of the current word). e moves to the end of a word. ( move to beginning of current block ) move to the end of current block Screen Movement To move the cursor to a line within your current screen use the following keys: H moves the cursor to the top line of the screen. M moves the cursor to the middle line of the screen. L moves the cursor to the last line of the screen. To scroll through the file and see other screens use: ctrl-f scrolls down one screen ctrl-b scrolls up one screen ctrl-u scrolls up a half a screen ctrl-d scrolls down a half a screen Two other useful commands for moving quickly from one end to the other of a document are G to move to the end of the file and 1G to move to the beginning of the file. If you precede G with a number, you can move to a specific line in the document (e.g. 15G would move you to line 15). Spring 2019 Husain Gholoom Lecturer in Computer Science Page 26

Deleting (or Cutting) Characters, Words, and Lines To delete a character, first place your cursor on that character. Then, you may use any of the following commands: x X dw dd D deletes the character under the cursor. deletes the character to the left of your cursor. deletes from the character selected to the end of the word. deletes all the current line. deletes from the current character to the end of the line. Entering the Insert Mode: i I a A o/o ESC Begin inserting text at current cursor location Begin inserting text at the beginning of the current line Begin appending text, one character to the right of current cursor location Begin appending text at the end of the current line Begin entering text one line below\above current line Exit insertion mode and return to command mode Exiting and Entering VI ZZ save file and exit VI :wq same as above :e! return to last saved version of current file :q quit without save, (Note :q! is required if changes have been made) :w write without exit (:w! to force write) Fancy Stuff: :1,10w file :340,$w >> file :sh ^d :![command] write lines 1 through 10 to file new file write lines 340 through the end of the file and append to file newfile escape temporarily to a shell return from shell to VI execute UNIX command without leaving VI Spring 2019 Husain Gholoom Lecturer in Computer Science Page 27

Spring 2019 Husain Gholoom Lecturer in Computer Science Page 28

Emacs Emacs is non-modal, normal keys always insert the corresponding letter Commands are typed by using [CRTL] or [ALT] in combination with normal keys. For example [C-a] or [M-a] to denote [a] pressed with[crtl] or [ALT] (M for meta). [C-h t] is [C-h] followed by plain [t]. Spring 2019 Husain Gholoom Lecturer in Computer Science Page 29