Unix Tutorial CSU480. Outline  Getting Started  System Resources  Shells  Special Unix Features  Text Processing  Other Useful Commands.

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

1 Introduction to UNIX Ke Liu
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 27 th, 2009 Essential Unix Commands.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Lesson 22 – Introduction to Linux Systems Administration.
Linux+ Guide to Linux Certification, Second Edition
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
The Unix Shell. Operating System shell The shell is a command interpreter It forms the interface between a user and the operating system When you log.
Guide To UNIX Using Linux Third Edition
Introduction to Linux and Shell Scripting Jacob Chan.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
Linux Commands LINUX COMMANDS.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
Brief introduction to UNIX A. Emerson CINECA, High Performance Systems.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
Linux+ Guide to Linux Certification, Second Edition
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Λειτουργικά Συστήματα - Lab1 Γιάννης Πετράκης. The Operating System  Unix is a layered operating system  The innermost layer is the hardware that provides.
Introduction to Programming Using C An Introduction to Operating Systems.
CSC414 “Introduction to UNIX/ Linux” Lecture 5. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
Manage Directories and Files in Linux Part 2. 2 Identify File Types in the Linux System The file types in Linux referred to as normal files and directories.
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Linux Commands C151 Multi-User Operating Systems.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
The Kernel At a high level, the kernel in an operating system serves as the bridge between applications and the actual data processing of the hardware.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
The Unix File System R Bigelow. The UNIX File System The file system refers to the way in which UNIX implements files and directories. The UNIX file system.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
Learning Unix/Linux Based on slides from: Eric Bishop.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Linux Filesystem Management
Lesson 5-Exploring Utilities
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Lecture 2 Working with Files and Directories
Some Linux Commands.
C151 Multi-User Operating Systems
Shell Script Assignment 1.
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Linux Shell Script Programming
Linux Commands LINUX COMMANDS.
Presentation transcript:

Unix Tutorial CSU480

Outline  Getting Started  System Resources  Shells  Special Unix Features  Text Processing  Other Useful Commands

The Unix Operating System Kernel Kernel System calls System calls Multi-user, multi-tasking OS Multi-user, multi-tasking OS

File System FS is the focus point of Unix FS is the focus point of Unix Looks like an inverted tree Looks like an inverted tree Root directory / Root directory / Each node is either a file or a directory Each node is either a file or a directory Path name Path name Absolute path Relative path. The current directory.. The parent of current directory

Directory, File and I-node Every directory and file is listed in its parent directory Every directory and file is listed in its parent directory The root’s parent is itself The root’s parent is itself All Unix files are non-structured (bit stream) All Unix files are non-structured (bit stream) A directory is a special file: A directory is a special file:  File name  I-node number

Unix Programs Shell: between user and the kernel Shell: between user and the kernel Commands: Commands:  Built-in shell command (pwd)  Source compiled, object code file (ls)  Shell script (**.sh) $PATH=/bin:/usr/bin:/usr/local/bin, etc $PATH=/bin:/usr/bin:/usr/local/bin, etc

Getting started Logging in Logging in Linux Command Line Structure Linux Command Line Structure Control Keys Control Keys stty – terminal control stty – terminal control Getting Help Getting Help Directory Navigation and Control Directory Navigation and Control File Maintenance Commands File Maintenance Commands Display Commands Display Commands

Logging in Username & password Username & password Unux is case sensitive Unux is case sensitive Changing password Changing password  passwd Choosing an hard-to-crack password Choosing an hard-to-crack password Exiting system Exiting system  Ctrl-D

Identity username userid username userid groupname groupid groupname groupid A user can belong to more than one group A user can belong to more than one group  Primary group: /etc/passwd  Additional groups: /etc/group

Identity % id uid=1101(frank) gid=10(staff) % id uid=1101(frank) gid=10(staff) groups=10(staff),5(operator),14(sysadmin),110(uts) % groups staff sysadmin uts operator

Unix Command Line Structure Format: command [options] [arguments] Format: command [options] [arguments] Arguments: action object, usu. files Arguments: action object, usu. files Options: change the way it performs Options: change the way it performs command -[option][option][option] command -[option][option][option]  ls -alR command -option1 -option2 -option3 command -option1 -option2 -option3  ls -a -l -R

Control Keys Used to perform special functions Used to perform special functions Ctrl-Key (^-Key) Ctrl-Key (^-Key) ^-U: “line-kill” signal ^-A: go to the beginning of the line ^-E: go to the end of the line ^-K: kill until the end of the line

Getting Help man command man command % man -k password % man -k password  passwd (5) - password file  passwd (1) - change password information % man 5 passwd % man 5 passwd

Getting Help

Directory Navigation and Control

cd

mkdir & rmdir mkdir mkdir -p create the intermediate (parent) directories, as needed -m mode access permissions (SVR4). rmdir: directory must be empty rmdir: directory must be empty

ls

File Maintenance Commands

cp –r: recursively copy a directory cp –r: recursively copy a directory mv: Actually all you’ve done is to update the directory table entry to give the file a new name. The contents of the file remain where they were. mv: Actually all you’ve done is to update the directory table entry to give the file a new name. The contents of the file remain where they were. rm: Actually, all you’ve done is to remove the directory table entry and mark the inode as unused. The file contents are still on the disk, but the system now has no way of identifying those data blocks with a file name. rm: Actually, all you’ve done is to remove the directory table entry and mark the inode as unused. The file contents are still on the disk, but the system now has no way of identifying those data blocks with a file name. -r: recursively -f: force

chmod u – user g – group o – other read=4, write=2, execute=1 or read=r, write=w, execute=x + add permissions - remove permissions = set permissions

chmod chmod 755 file1 or chmod u=rwx,go=rx file1 chmod 755 file1 or chmod u=rwx,go=rx file1 As for directory: As for directory: r: can read the content of the directory w: can create/delete files of the directory x: can “go through” the directory

chown chown new_user:new_group file chown new_user:new_group file Note: On most versions of Unix this can only be done by the super-user, i.e. a normal user can’t give away ownership of their files. Note: On most versions of Unix this can only be done by the super-user, i.e. a normal user can’t give away ownership of their files.

Display Commands

echo

more, less, & pg

System Resources

df df is used to report the number of disk blocks and inodes used and free for each file system. df is used to report the number of disk blocks and inodes used and free for each file system. Options: Options: -l local file systems only (SVR4) -k report in kilobytes (SVR4)

du du reports the amount of disk space in use for the files or directories you specify. du reports the amount of disk space in use for the files or directories you specify. Options: Options: -a display disk usage for each file, not just subdirectories -s display a summary total only -k report in kilobytes (SVR4)

ps ps is used to report on processes currently running on the system. ps is used to report on processes currently running on the system. Options: Options: -e Select all processes. -f does full-format listing.

kill

who who reports who is logged in at the present time. who reports who is logged in at the present time. Syntax Syntax who [am i]

whereis

which which will report the name of the file that is be executed when the command is invoked. This will be the full path name or the alias that’s found first in your path. which will report the name of the file that is be executed when the command is invoked. This will be the full path name or the alias that’s found first in your path. Syntax Syntax which command(s)

hostname/uname hostname (uname -n on SysV) reports the host name of the machine the user is logged into hostname (uname -n on SysV) reports the host name of the machine the user is logged into uname has additional options to print information about system hardware type and software version. uname has additional options to print information about system hardware type and software version.

script script creates a script of your session input and output. Using the script command, you can capture all the data transmission from and to your terminal screen until you exit the script program. This can be useful during the programming-and-debugging process, to document the combination of things you have tried, or to get a printed copy of it all for later perusal. script creates a script of your session input and output. Using the script command, you can capture all the data transmission from and to your terminal screen until you exit the script program. This can be useful during the programming-and-debugging process, to document the combination of things you have tried, or to get a printed copy of it all for later perusal. Syntax Syntax script [-a] [file] exit

date date displays the current data and time. A superuser can set the date and time. date displays the current data and time. A superuser can set the date and time. Syntax Syntax date [options] [+format]

Shells The shell sits between you and the operating system, acting as a command interpreter. The shell sits between you and the operating system, acting as a command interpreter. cat /etc/shells cat /etc/shells/bin/sh/bin/bash/sbin/nologin/bin/ash/bin/bsh/bin/ksh/usr/bin/ksh/usr/bin/pdksh/bin/tcsh/bin/csh/bin/zsh

Shells sh: Bourne shell (not suited for interactive) sh: Bourne shell (not suited for interactive) csh: uses C type syntax (job control) csh: uses C type syntax (job control) ksh: Korn shell ksh: Korn shell bash: Bourne Again Shell (GNU) bash: Bourne Again Shell (GNU) tcsh: T-C shell tcsh: T-C shell cshe: extended C shell cshe: extended C shell

Built-in Commands These commands are executed directly in the shell and don’t have to call another program to be run. These commands are executed directly in the shell and don’t have to call another program to be run.

Environment Variables Environmental variables are used to provide information to the programs you use. Environmental variables are used to provide information to the programs you use. Global environment variables are set by your login shell and new programs and shells inherit the environment of their parent shell. Global environment variables are set by your login shell and new programs and shells inherit the environment of their parent shell. Local shell variables are used only by that shell and are not passed on to other processes. Local shell variables are used only by that shell and are not passed on to other processes.

Environment Variables

Shell profile Global: Global:/etc/profile User: User:/home/duanjj/.bash_profile

profile #: comments $PATH: separated by a colon : and dot. represents current directory A variable set in.profile is set only in the login shell unless you "export" it or source.profile from another shell. umask 0022

Job control &: put jobs into the background Ctrl-Z: suspend a job bg: put jobs into the background fg: bring jobs back to the foreground jobs: list your background jobs

Job control Background jobs can’t read from keyboard, but they can write onto the terminal, interspersing with whatever else is typed or displayed by your current job. Solution: You may want to redirect I/O to or from files for the job you intend to background. Your keyboard is connected only to the current, foreground, job.

Changing your shell chsh chsh /etc/shells /etc/shells

Working With Files

cmp reports the location of the first difference reports the location of the first difference can deal with both binary and ASCII file comparisons. can deal with both binary and ASCII file comparisons. does a byte-by-byte comparison does a byte-by-byte comparison

diff compares two files, directories, etc, and reports all differences between the two. compares two files, directories, etc, and reports all differences between the two. deals only with ASCII files. deals only with ASCII files. It’s output format is designed to report the changes necessary to convert the first file into the second. It’s output format is designed to report the changes necessary to convert the first file into the second.

cut allows a portion of a file to be extracted for another use. allows a portion of a file to be extracted for another use.

cut File: users File: users cut -f 1,2 users cut -f 1,2 users cut -c 1-4 users cut -c 1-4 users

paste allows two files to be combined side-by-side. allows two files to be combined side-by-side. The default delimiter between the columns in a paste is a tab The default delimiter between the columns in a paste is a tab A hyphen (-) in place of a file name is used to indicate that field should come from standard input. A hyphen (-) in place of a file name is used to indicate that field should come from standard input.

paste users + phone users + phone method 1: method 1:  cut –f 2 phone > temp.file  paste users temp.file > listing method 2: method 2:  cut -f2 phone | paste users - > listing

touch used to create a new (empty) file used to create a new (empty) file or to update the last access date/time on an existing file or to update the last access date/time on an existing file

wc – word count Options: Options: -c count bytes -c count bytes -l count lines -l count lines -w count words -w count words % wc users % wc users

ln – link to another file Syntax ln [options] source [target] Options -s make a symbolic link  hard link  symbolic link

Hard link Only on the same “file system” Only on the same “file system” Can’ link to a directory Can’ link to a directory creates a new directory entry pointing to the same inode as the original file. creates a new directory entry pointing to the same inode as the original file. The file linked to must exist before the hard link can be created. The file linked to must exist before the hard link can be created. The file will not be deleted until all the hard links to it are removed The file will not be deleted until all the hard links to it are removed

Symbolic link Used to create a new path to another file or directory. Used to create a new path to another file or directory. Can traverse file systems Can traverse file systems Permissions are open to all Permissions are open to all

sort - used to order the lines of a file.

example File : users File : users % sort users % sort users % sort +2 users: % sort +2 users: % sort -r users: % sort -r users: who | cut -d " " -f 1 | sort -u | wc -l who | cut -d " " -f 1 | sort -u | wc -l

tee – copy command output sends standard in to specified files and also to standard out. sends standard in to specified files and also to standard out. often used in command pipelines. often used in command pipelines. % who | tee users.file % who | tee users.file % who | tee users| wc -l % who | tee users| wc -l

uniq filters duplicate adjacent lines from a file. filters duplicate adjacent lines from a file.

find recursively search the indicated directory tree to find files matching a type or pattern you specify recursively search the indicated directory tree to find files matching a type or pattern you specify then list the files or execute arbitrary commands based on the results. then list the files or execute arbitrary commands based on the results.Syntax find directory [search options] [actions] Common Options For the time search options the notation in days, n is: +n more than n days n exactly n days n exactly n days -n less than n days

find % find. -newer library -print % find. -newer library -print % find /usr/include “stdio.h” -print % find /usr/include “stdio.h” -print

File compression gzip, gunzip gzip, gunzip bzip2, bunzip2 bzip2, bunzip2

tar – archive files combines files into one device or filename for archiving purposes. combines files into one device or filename for archiving purposes. does not compress the files; does not compress the files; merely makes a large quantity of files more manageable. merely makes a large quantity of files more manageable. accept its options either with or without a preceding hyphen (-). accept its options either with or without a preceding hyphen (-).

tar Options: Options: c create an archive (begin writting at the start of the file) t table of contents list x extract from an archive v verbose f archive file name b archive block size

od dumps a file to stdout in different formats, including octal, decimal, floating point, hex, and character format. dumps a file to stdout in different formats, including octal, decimal, floating point, hex, and character format. -b octal dump -d|-D decimal (-d) or long decimal (-D) dump -s|-S signed decimal (-s) and signed long decimal (-S) dump -f|-F floating point (-f) or long (double) floating point (-F) dump -x|-X hex (-x) or long hex (-X) dump -c|-C character (single byte) or long character dump (single or multi- byte characters, as determined by locale settings) dump -v verbose mode

Thanks