Outline. Structure of a UNIX command

Similar documents
CS4350 Unix Programming. Outline

Mills HPC Tutorial Series. Linux Basics I

CS Fundamentals of Programming II Fall Very Basic UNIX

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 Filesystem. January 26 th, 2004 Class Meeting 2

Unix Introduction to UNIX

Introduction to the Linux Command Line

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Course 144 Supplementary Materials. UNIX Fundamentals

Introduction: What is Unix?

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

Week 2 Lecture 3. Unix

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

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Linux Command Line Primer. By: Scott Marshall

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

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Introduction to Linux

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

Introduction to Linux

Introduction to the UNIX command line

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

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

Physics REU Unix Tutorial

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

Computer Systems and Architecture

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

Introduction to Linux Workshop 1

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

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]

Introduction to Linux

CS101 Linux Shell Handout

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

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

CISC 220 fall 2011, set 1: Linux basics

Computer Systems and Architecture

Chapter-3. Introduction to Unix: Fundamental Commands

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

Introduction to Linux

A Brief Introduction to Unix

Linux/Cygwin Practice Computer Architecture

Introduction To Linux

Working with Basic Linux. Daniel Balagué

Getting Started with UNIX

Exploring UNIX: Session 3

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

Std: XI CHAPTER-3 LINUX

Oxford University Computing Services. Getting Started with Unix

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

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

CS246 Spring14 Programming Paradigm Notes on Linux

Basic File Attributes

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

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

Overview of the UNIX File System

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

Essential Linux Shell Commands

Introduction to Linux Basics

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

Getting started with Hugs on Linux

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

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

Introduction to Linux. Fundamentals of Computer Science

Exercise Sheet 2. (Classifications of Operating Systems)

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

INSE Lab 1 Introduction to UNIX Fall 2017

Perl and R Scripting for Biologists

An Introduction to Unix

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

UNIX Quick Reference

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

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

commandname flags arguments

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

CHE3935. Lecture 1. Introduction to Linux

UNLV Computer Science Department CS 135 Lab Manual

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

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

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

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

Unix Tutorial Haverford Astronomy 2014/2015

Introduction to the basics of UNIX

Introduction to Unix: Fundamental Commands

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

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

Short Read Sequencing Analysis Workshop

Introduction to Linux

(a) About Unix. History

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

Overview of the UNIX File System. Navigating and Viewing Directories

Session 1: Accessing MUGrid and Command Line Basics

UNIX File Hierarchy: Structure and Commands

AN INTRODUCTION TO UNIX

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

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

Getting Started With UNIX Lab Exercises

Linux Kung-Fu. James Droste UBNetDef Fall 2016

Helpful Tips for Labs. CS140, Spring 2015

CS/CIS 249 SP18 - Intro to Information Security

Transcription:

Outline 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 commands Structure of a UNIX command $ command [ [ - ] option (s) ] [ option argument (s) ] [ command argument (s) ] Examples: $ ls $ ls -la $ ls -la m* Fall 2013 CS4350 Husain Gholoom Page 1

Utility Commands Help on UNIX o Examining System Setups whoami uname -a who hostname o Command Alias alias alias name=string Commands Obtaining Help with the man Command man [options][-s section] command-list Example : $ man printf NAME printf -- formatted output SYNOPSIS printf format [arguments...] Fall 2013 CS4350 Husain Gholoom Page 2

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. 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.. Fall 2013 CS4350 Husain Gholoom Page 3

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.. Logging On and Logging Off Text mode Local: UNIX terminal Remote: SSH Fall 2013 CS4350 Husain Gholoom Page 4

Connecting via UNIX Terminal login: your_username <Enter> password: your_password <Enter> Welcome messages. You have new mail. [yourname ~]$type_command_here Connecting via SSH Fall 2013 CS4350 Husain Gholoom Page 5

Fall 2013 CS4350 Husain Gholoom Page 6

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 Fall 2013 CS4350 Husain Gholoom Page 7

Files and File Systems Unix uses a tree structure Starts at / Directory Structure Fall 2013 CS4350 Husain Gholoom Page 8

Files and File Systems Big, always-on data structure N-ary tree instead of binary tree Unix directories contain: One parent N children (sub-directories) Files and links 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 Fall 2013 CS4350 Husain Gholoom Page 9

Absolute Paths cd /home/user3/dir1 Relative Paths cd../home/user3 Fall 2013 CS4350 Husain Gholoom Page 10

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 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 Fall 2013 CS4350 Husain Gholoom Page 11

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 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 Fall 2013 CS4350 Husain Gholoom Page 12

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 Fall 2013 CS4350 Husain Gholoom Page 13

File Create/Destroy The simple approach to create 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> 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. Fall 2013 CS4350 Husain Gholoom Page 14

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> File Editing vim emacs gedit Kwrite small, hard to learn huge, hard to learn GUI, good Fall 2013 CS4350 Husain Gholoom Page 15

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 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 chown [ R] owner[:group] file. For Example chown Jeff file1 allows jeff to be the owner of the file file1 chgrp 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 Fall 2013 CS4350 Husain Gholoom Page 16

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 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. Fall 2013 CS4350 Husain Gholoom Page 17

/usr/share : This directory contains 'shareable', architecture-independent files (docs, icons, fonts etc) /usr/man /usr/bin /usr/sbin : It once held the man pages. It has been moved to /usr/share/man. : This directory stores all binary programs distributed with the operating system not residing in /bin, /sbin : Non-essential system binaries /usr/include : Stores the development headers used throughout the system Basic Administration Important user configuration files ( when you log on ( ID- Password ), or already logged on, or history of commands entered ).bash_profile.bashrc.bash_history Important system configuration files passwd : change system password. grub.conf : Allow the user to boot one of multiple operating systems installed on a computer Fall 2013 CS4350 Husain Gholoom Page 18

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 Fall 2013 CS4350 Husain Gholoom Page 19

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). Fall 2013 CS4350 Husain Gholoom Page 20

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 newfile 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 Fall 2013 CS4350 Husain Gholoom Page 21