Course 144 Supplementary Materials. UNIX Fundamentals

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

Mills HPC Tutorial Series. Linux Basics I

Unix Introduction to UNIX

Outline. Structure of a UNIX command

Introduction to Linux

Unix Filesystem. January 26 th, 2004 Class Meeting 2

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

Files

Linux Command Line Primer. By: Scott Marshall

Introduction to the UNIX command line

A Brief Introduction to Unix

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

LAB #7 Linux Tutorial

CS4350 Unix Programming. Outline

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

Linux Essentials Objectives Topics:

Chapter-3. Introduction to Unix: Fundamental Commands

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

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Introduction to the Linux Command Line

Linux Kung-Fu. James Droste UBNetDef Fall 2016

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

Introduction to remote command line Linux. Research Computing Team University of Birmingham

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

Week 2 Lecture 3. Unix

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

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

commandname flags arguments

CISC 220 fall 2011, set 1: Linux basics

acmteam/unix.pdf How to manage your account (user ID, password, shell); How to compile C, C++, and Java programs;

Introduction to Linux

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

CS/CIS 249 SP18 - Intro to Information Security

UNIX. Basic UNIX Command

Computer Systems and Architecture

Unix Handouts. Shantanu N Kulkarni

Introduction to Unix May 24, 2008

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: ~

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.

Open up a terminal, make sure you are in your home directory, and run the command.

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Commands are in black

Introduction to Linux

Computer Systems and Architecture

Chapter 8: Security under Linux

Essential Linux Shell Commands

Getting your department account

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

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]

Operating Systems Lab 1 (Users, Groups, and Security)

Lab Working with Linux Command Line

NETW 110 Lab 5 Creating and Assigning Users and Groups Page 1

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

CS246 Spring14 Programming Paradigm Notes on Linux

Physics REU Unix Tutorial

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

[ Terminal ] [ Users management ] Alt +F6 = Terminal switcher. useradd [option] JohnG

UNIX File Hierarchy: Structure and Commands

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Working with Basic Linux. Daniel Balagué

Lab 2A> ADDING USERS in Linux

Introduction: What is Unix?

Exercise Sheet 2. (Classifications of Operating Systems)

Introduction to Linux

CS Fundamentals of Programming II Fall Very Basic UNIX

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

Files and Directories

Presented by Bill Genske Gary Jackson

CSCI 2132 Software Development. Lecture 5: File Permissions

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

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

Linux/Cygwin Practice Computer Architecture

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

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 of Linux

CST8207: GNU/Linux Operating Systems I Lab Seven Linux User and Group Management. Linux User and Group Management

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

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

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

CS197U: A Hands on Introduction to Unix

Hitchhiker s Guide to VLSI Design with Cadence & Synopsys

CENG 334 Computer Networks. Laboratory I Linux Tutorial

SECTION -C. Getting Started with UNIX

INTRODUCTION TO LINUX

5/20/2007. Touring Essential Programs

CSE 390a Lecture 3. Multi-user systems; remote login; editors; users/groups; permissions

LOG ON TO LINUX AND LOG OFF

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

Chapter 1 - Introduction. September 8, 2016

The kernel is the low-level software that manages hardware, multitasks programs, etc.

Introduction to Linux

Linux Kung Fu. Ross Ventresca UBNetDef, Fall 2017

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

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

CHE3935. Lecture 1. Introduction to Linux

M.C.A. (Sem.-lll) (CBCS) Examination November CCA-3003 Operating System and LinuxlUnix programming

Command-line interpreters

CSCI 2132 Software Development. Lecture 4: Files and Directories

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

Transcription:

Course 144 Supplementary Materials UNIX Fundamentals 1

Background to UNIX Command Fundamentals This appendix provides a overview of critical commands and concepts Prerequisite knowledge attendees should already have Some (but not all!) of the most important commands for users Attendees of this course should already know the commands and concepts discussed on all pages in this appendix, except for the final three titled System Administration Either Course 143 or Course 428 would provide the needed background As a UNIX/Linux system administrator, it is your responsibility to first be a skilled UNIX/Linux user Use the man command to learn about commands List of commands by topic: man k topicname Details on one command: man commandname 143 428 UNIX documentation uses italics to indicate variable parts of examples, as in the above Polish your skill by using the commands! 2

Editing Text Files Almost all UNIX/Linux configuration is done with text files. This means that you must be able to accurately and efficiently modify these files with a standard UNIX/Linux text editor. The only interactive editor you can count on having available is the vi editor. Newer versions of vi, actually vim (for VI Improved ), may support use of the special keys on the keypad to the right of the main keyboard: the arrow keys, <Page Up>, <Page Down>, <Delete>, and <Insert>. However, those keys will not function at all times! If you are going to be a system administrator, you may be called upon to edit text files when those keys do not function. You must be able to use the standard vi commands for cursor motion (h, j, k, l, w, b, ^D, ^U, etc.), entry into and exit from insertion mode (i, a, o, O, Escape, etc.), and deletion (x, dw, dd, etc.). 3

Filename Wildcards * Matches any string, including an empty string "foo*" matches "foo", "foot", and "football"? Matches any one character "foo?" matches "food" and "foot", but not "football" [...] Matches any single character from the list "foo[ldt]" Matches any one of "food", "fool", or "foot" "foo[a-c]" Matches any one of "fooa", "foob", or "fooc" "foo[a-cx-z]" Matches any one of "fooa", "foob", "fooc", "foox", "fooy", or "fooz" "[a-cmnx-z]" Matches any one of "a", "b", "c", "m", "n", "x", "y", or "z" Be careful! "foo[d,t]ball" Matches any one of "foodball", "foo,ball", or "football"! 4

Shell Fundamentals: I/O myprog Run the program myprog and allow standard output and standard error to print on the terminal screen myprog > saveit Send standard output to a file named saveit. This overwrites saveit if it exists! myprog >> saveit Append standard output to saveit. Any data in saveit is preserved, and the new output is added to the end. myprog > saveit 2> oops Send standard output to saveit and standard error (I/O stream #2) to oops myprog > saveit 2>&1 Send standard output to saveit, and also send standard error there myprog otherprog Build a pipeline the output of myprog is used as the input of otherprog 5

Shell Fundamentals: Running Programs You do not need to be in any particular directory to run a program, so long as: 1: The program is in a directory listed in your PATH environment variable, or 2: You specify the full path to the program Reasonable PATH for users includes these directories: /bin, /usr/bin, /usr/x11r6/bin, /usr/local/bin Reasonable PATH for root adds these directories: /sbin, /usr/sbin, /usr/local/sbin If the /usr/local hierarchy is not carefully controlled, leave /usr/local/*bin out of PATH for root! Any I/O redirection is relative to your current working directory Scenario: You have data files in the directory /var/log/something. You want to process them with the program /usr/local/sbin/analyzer, which uses its command-line arguments as sources of input. Finally, you want to save the output in a file named analysis in the current directory. Just do this: /usr/local/sbin/analyzer /var/log/something/* > analysis 6

Listing Files ls List the names of the files (remember, directories are just a special type of file) ls -a List all the files, even those with names starting with. ls -l Long listing of the files and their attributes ls -d List just the directory itself, not its contents Combine these to do something like: List the attributes of just those files (but not their contents if they are directories) with names starting with capital letters: ls ld [A-Z]* Reading the output of ls -l: drwxr-xr-x 3 juser bigproject 1024 Aug 13 08:14 Data -rw-r--r-- 1 juser bigproject 16192 Aug 22 20:41 README File type d Directory l Symbolic link b Block device c Character device - Regular file Owner Group Size in bytes Modification timestamp Filename Permissions: First 3 for owner (juser in this example) Second 3 for members of the group (bigproject in this example) Last 3 for everyone else r = read, w = write, x = execute (or search in the case of directories) s = set-user-id or set-group-id t = sticky bit (you cannot remove other user s files from this directory) 7

Manipulating Files and Directories cp foo bar mv foo bar mkdir foo rmdir foo touch foo ln s foo bar rm foo rm r foo rm rf foo Copy file foo to bar. If bar is a directory, create the file bar/foo. Otherwise, bar will be a file that is a copy of foo. Move file foo to bar. If bar is a directory, create the file bar/foo. Otherwise, foo will be renamed bar. Create a directory named foo Remove a directory named foo If foo exists, change its modification timestamp. If it does not exist, create it as an empty file. Create a symbolic link named foo pointing to bar Remove foo Recursively remove the directory foo and its contents Recursively remove the directory foo and its contents and force it to happen. (Do not bother me with warning messages!) 8

Examining File Contents more foo cat foo cmp foo bar diff foo bar grep blah foo View the contents of foo one screen at a time. Press <Spacebar> to move forward one screen, <b> to move back one screen, and <q> to quit. Print all the contents of foo to the screen Compare answer the question, Are foo and bar identical? Show the differences between foo and bar Print just those lines of foo containing the literal string blah grep i blah foo grep w blah foo grep iw blah foo grep v blah foo...except ignore the case of the letters in blah...only when blah appears as an isolated word...as an isolated word and ignoring case...only the lines that do not contain the string blah 9

Dealing With Lots of Data myprog more myprog less Run the program myprog and display its standard output one screen at a time with more The program less is like more except with more features less lets you back up a page at a time with <b> myprog grep i blah less Run the program myprog, displaying only the lines containing the string blah (in any case), displaying the result one page at a time 10

Changing File Permissions chmod 700 mydata Change the permissions of the file mydata to mode 700 chmod o-w mydata chmod R o-w mydata Remove the permission for others to write the file mydata, but leave the other permissions alone Apply that change recursively to the directory mydata and its contents Permissions can be specified in octal. Use one of these bit patterns for each of user, group and other, in that order: 7 rwx 6 rw- 5 r-x 4 r-- 1 --x 0 --- u user (owner) g group o other Permissions can be specified symbolically: [ugo][+-][rwxs] + add - remove r read w write x execute s set-uid or set-gid 11

Who Am I and Where Am I? id pwd hostname ifconfig -a List your credentials user ID, primary group ID, other groups Print the current working directory Print the computer s host name Display the computer s IP address(es) 12

Controlling Processes ps axuw kill HUP 123 List many details about all running processes. On Solaris, you must provide the full path: /usr/ucb/ps axuw Send a HUP signal to the process with PID 123. Many daemons interpret a HUP signal to mean Keep running, but re-read your configuration file. kill TERM 123 Send a TERM signal to the process with PID 123. A well-written process is given a chance to shut down cleanly. kill KILL 123 Send a KILL signal to the process with PID 123. Does not allow a clean shutdown like TERM, but sometimes a blunt weapon is needed! pkill HUP xinetd Like kill, except you can specify processes by program name, not PID 13

System Administration: Controlling System State Shut UNIX down cleanly and halt init 0 Solaris and Linux halt BSD Shut UNIX down cleanly and reboot init 6 Solaris and Linux reboot BSD Go to single-user mode (maintenance mode, root on the console) init 1 Solaris and Linux kill s TERM 1 BSD Go to full multi-user mode init 3 init 3 init 5 ^D Solaris Linux (for a text-only environment) Linux (for a graphical environment) On BSD, exit from the single-user mode shell 14

System Administration: Managing Users and Groups useradd m fred userdel fred passwd fred Create a user named fred and create the home directory /home/fred based on the contents of /etc/skel Delete the user fred (home directory and all files remain) Assign a password to the user fred groupadd g 100 wheel Create a group named wheel with group ID 100 User accounts are defined in: /etc/passwd /etc/shadow Login, UID, primary GID, real name ( GECOS field ), home directory, shell Login, hashed password, account and password aging control Groups are defined in /etc/group: Group name, GID, list of members 15

System Administration: Changing File Owner and Group chown fred mydata chgrp sys mydata chown root:sys mydata chown -R root:sys foo Change the owner of the file mydata to the user fred Change the group of the file mydata to the group sys Change the owner of the file mydata to the user root, and change the group to sys Apply that user:group change recursively to the directory foo and its contents 16