Introduction to UNIX Don Bahls user consultant (907) 450-8674.

Slides:



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

CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
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.
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
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.
Lecture 01CS311 – Operating Systems 1 1 CS311 – Lecture 01 Outline Course introduction Setting up your system Logging onto the servers at OSU with ssh.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.
Introduction to Linux/UNIX. History UNIX beginnings in 1969 (Linus Torvalds is born!) AT & T Bell Laboratories (Ken Thompson & Dennis Richie) Working.
“Linux at the Command Line” Don Johnson of BU IS&T.
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
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.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
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”
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Essential Unix at ACEnet Joey Bernard, Computational Research Consultant.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Unix Basics Chapter 4.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Introduction to Computer Organization & Systems Topics: Intro to UNIX COMP John Barr.
CS 2061 Shells Also known as: Unix Command Interpreter.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Introduction to Linux Azzam Mourad COEN 346.
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
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.
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
Unix Commands PowerPoint Presentation developed for LS 560 Information Technology online class - University of Alabama by Debey Sklenar TENacious Cohort.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
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.
Getting Started UNIX InKwan Yu Topics Unix Commands Unix System calls C function calls.
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.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
Learning basic Unix command It 325 operating system.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Introduction to the Linux Command Line Interface Research Computing Systems Bob Torgerson July 19, 2016.
Andy Wang Object Oriented Programming in C++ COP 3330
Some Linux Commands.
C151 Multi-User Operating Systems
The Linux Operating System
CSE 303 Concepts and Tools for Software Development
Basic UNIX OLC Training.
Introduction to UNIX.
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
Introduction to Linux/UNIX
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Chapter 3 The UNIX Shells
Linux Commands LINUX COMMANDS.
LPI Linux Certification
Presentation transcript:

Introduction to UNIX Don Bahls user consultant (907)

Overview The shell Common Commands File System Organization Permissions Environment Variables I/O Redirection and Pipes Shell Special Characters

The shell A UNIX shell is a program which lets you interact with a system. It lets you: –run programs. –interact with files, directories and devices on the system. –“see” what those programs are doing. –send signals to other programs running on the system. –and more, such as setting environment variables, setting limits, etc…

Some common shells sh - bourne shell ksh - korn shell bash - bourne-again shell csh - C shell tcsh - tenex C shell (a.k.a turbo C) The basic functionality of all of these is fairly similar.

What shell should you use? tcsh and bash are probably the easiest to learn for beginners, however ksh is the default at ARSC for historical reasons. With tcsh and bash : –command history (i.e. previously run commands) can be accessed using the up and down arrow keys. –the tab key tells the shell to try to perform filename completion. –there’s a lot more, but this will get you started.

How do you change your shell? Can always just type the shell name to run the shell this once. On many systems the chsh command will let you change your default shell. At ARSC a consultant has to change your shell for most UNIX systems (except Macs).

Common Commands File Related ls cd mkdir rmdir rm pwd Access Related chmod chgrp groups Process Related ps kill General Purpose more grep Documentation man

Common Commands - continued We won’t cover all of these commands, but by the end of this talk you’ll know where to find more information on all of them. Almost all of the aforementioned commands are separate executables (however cd is a built-in shell command in many shells). NOTE: Most UNIX environments are case sensitive, so “ ps ” is not the same as “ PS ”,“ Ps ” or “ pS ”!

man - on-line manuals man pages are available for most system commands in UNIX LS(1) User Commands LS(1) NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuSUX nor --sort. Mandatory arguments to long options are mandatory for short options too.

man - on-line manuals View the man page for ls man ls The “ -k ” flag lets you search for a term in all man pages. man -k color If there isn’t a man page, try using the “ -h ” or “ --help ” options with the command: ls --help

man - on-line manuals Let’s look at a real man page... A few tips: –press the “spacebar” key to move to the next page. –press the “enter” key to move to the next line. –press “/” to get into search mode. Then type a string to search for. The “n” key will find next occurrences of the string. –press “q” to quit

The ls command shows information about a file or directory. Basic Command ls - list directory contents % ls bin % ls -l /usr/bin/g++ -rwxr-xr-x 4 root root May /usr/bin/g++ Long Listing

ls - list directory contents Show long listing of all files % ls -la ~ total 72 drwxr-xr-x 3 user staff 4096 May 11 17:42. drwxr-xr-x 5 root root 4096 May 11 17:41.. -rw-r--r-- 1 user staff 24 May 11 17:41.bash_logout -rw-r--r-- 1 user staff 191 May 11 17:41.bash_profile -rw-r--r-- 1 user staff 124 May 11 17:41.bashrc drwxrwxr-x 2 user staff 4096 May 11 17:42 bin -rw user staff 67 May 11 17:41.Xauthority

ls - list directory contents Notice files beginning with “.” are now included in the output now. Also notice the special directories –“. ” the current working directory –“.. ” the parent directory Another special directory –“ ~ ” refers your home directory

cd - change directory cd lets you change the working directory of the shell. cd with no parameters returns you to your home directory. Examples cd cd /usr/bin cd.. Can you think of another way to get to your home directory?

mkdir - make directory mkdir creates a new directory % mkdir../../new_dir mkdir: cannot create directory `../../new_dir': Permission denied sometimes commands fail. % mkdir new_dir you must have permissions to write and remove files and directories (more in the Permissions section)

rmdir - remove directory rmdir removes a directory. The directory must be empty to be removed rmdir new_dir

rm - remove files or directories rm removes a file or directory. there’s no way to undo a rm ! be careful! remove file rm filename recursively remove a directory. rm -r new_dir

pwd - print working directory prints the directory the shell is in. % pwd /home/user

more - paging filter more lets you display files to screen one page (i.e. screen full) at a time. % more ~/.bashrc #.bashrc # User specific aliases and functions # Source global definitions if [ -f /etc/bashrc ]; then. /etc/bashrc fi

more - paging filter more also lets you view output from another program one page at a time. ls -l /usr/bin | more The “ | ” symbol is called a pipe. A pipe lets you connect the output from one program to the input of another program (more in the I/O section).

File system Organization The directory “ / ” is called the root directory in UNIX. All other directories are located in this directory. Some of these directories have actual files in them others provide access to hardware devices and other system information.

ps - process status Every running process (i.e. program) has an associated process id. % ps PID TTY TIME CMD 2779 pts/1 00:00:00 bash 2810 pts/1 00:00:00 ps The default output for ps show only child processes of the shell. Try “ ps -elf ” or “ ps -aux ” to get all processes

%./loop.sh & [1] 3039 % ps PID TTY TIME CMD 2779 pts/1 00:00:00 bash 3039 pts/1 00:00:00 loop.sh 3041 pts/1 00:00:00 sleep 3042 pts/1 00:00:00 ps % kill 3039 % ps PID TTY TIME CMD 2779 pts/1 00:00:00 bash 3055 pts/1 00:00:00 ps The “&” puts the process in the background. kill - terminate a process The kill command lets you send a signal to a process id. The process id for loop.sh is The sleep process was started by loop.sh and will be killed when loop.sh is killed The processes are gone Kill process 3039.

Related Shell Operations Pressing CTRL+C sends a signal to the current running process, just like kill. Pressing CTRL+Z sends a suspend signal. “ bg ” and “ fg ” let you put suspended process in the background and foreground. %./loop.sh [1]+ Stopped./loop.sh % bg [1]+./loop.sh & % CTRL+Z suspends the process. bg puts the process in the background so you can use the shell again

kill - continued Kill can send a number of different signals. Sometimes processes might not respond to a particular signal. If all else fails, “ kill -9 ” (a.k.a. “ kill -KILL ”) should work: kill NOTE: you should only use “ kill -9” if other signals don’t work!

Common Locations /bin - executables /usr - executables, include files, man pages, libraries and more. /etc - system settings files /home, /Users, /u1, /u2 - home directories can be in a lot of different locations depends on the OS and the admin that is running the machine.

Where’s my home directory? % cd % pwd /home/user % cd ~ % pwd /home/user

Permissions UNIX uses permissions to control access to files and directories. There are three categories of permissions –user permissions –group permissions –other permissions

Permissions - continued Each permissions category has three attributes. –read –write –execute

An Example % ls -l /usr/bin/g++ -rwxr-xr-x 4 root root May /usr/bin/g++ - (this is a regular file) rwx root (permissions and file owner) r-x root (group permissions and group) r-x (other permissions) “root” owns this file, and can read, write and execute. the “root” group can read and execute this file. everyone else can read and execute this file too.

Another Example % ls -l ~ drwxr-x--- 4 fred staff May bin d (this is a directory) rwx fred (permissions and directory owner) r-x staff (group permissions and group) --- (other permissions) “fred” owns this directory, and can read, write and execute. the “staff” group can read and execute this directory. no one else can access this directory.

Permissions Commands The “ groups ” command shows which groups you are in. The “ chmod ” command lets you change permissions. % chmod g+rx ~/bin % chmod 750 ~/bin Add group read and execute permissions to ~/bin (bin directory in ~) Set user read, write, and execute permissions. Also set group read and execute permissions. 4 = Read 2 = Write 1 = Execute r w x (u)ser permissions = 7 (g)roup permissions = 5 (o)ther permissions = 0

Security It’s a bad idea to give world (i.e. other) write permissions. Anyone with access to the system could change the file on you! (ARSC doesn’t permit world write permissions). Some dot files/directories contain sensitive information. Be careful who you give access to.

Environment Variables Environment variables store short strings of information that can be read by child processes. Some important variables: –PATH : Where the shell looks for executables. This lets you enter “ ls ” instead of “ /usr/bin/ls ”. –HOME : Set to the path to your home directory.

Environment Variables - Continued The “ env ” command show all of the environment variable that are set. You can also show an individual environment variable using the “ echo ” command: % echo $PATH /bin:/usr/bin:/usr/local/bin

PATH The order of directories in the PATH is important. The shell searches for executables in the order they are found in the PATH environment variable. The current directory (i.e. “. ”) is typically not in the PATH for security purposes.

“.” To run an executable in the current directory, you need to include the “. ” To run “myprog” in the current directory:./myprog or include the full path to the executable: /home/user/myprog

Setting an Environment Variable Appending a directory to the PATH –csh / tcsh syntax setenv PATH ${PATH}:${HOME}/bin –ksh / bash syntax export PATH $PATH:$HOME/bin Setting an environment variable –csh / tcsh syntax setenv FRED “hello” –ksh / bash syntax export FRED=“hello”

I/O Redirection and Pipes UNIX programs have three forms of standard I/O –stdin: input, normally from the keyboard –stdout: output, normally to the screen –stderr: error output, normally to the screen However, I/O can be redirected.

Redirecting I/O Redirecting stdout to a new file ls > ls.out Redirecting stdout appending to a file ls >> ls.out Sending a file to stdin./myprog < input Stderr redirection depends on the shell we won’t cover it here.

Using Pipes Using pipes programs using stdin and stdout can be tied together so that the input from one command comes from the output of another. more myfile | wc -l cat people | sort -u | uniq

Shell Special Characters Some characters are interpreted in special ways by the shell. –“ * ” matches anything ls /usr/bin/g* –“ ? ” matches a single character ls /usr/bin/g?? –“ & ” puts a process in the background so you can continue to use the terminal. ls -l /usr/bin > ls.output &

Shell Special Characters Some other special characters that we’ve already seen. –“ > ” stdout redirection –“ < ” stdin redirection

Parting words Don’t forget about the man command! A web search may be helpful - or find a local expert Exercises: –

Appendix A - Command Reference Kerberos Commands kshell kinit krlogin krcp kftp Openssh ssh sftp scp Compilers/Interpretors gcc / cc c99 g++ / c++ / CC f90 / f95 / ftn / pgf90 python perl ruby ld

Appendix A Utilities awk cat cut find head gawk grep gunzip gzip ld ldd less egrep sed sort tail tar uniq wc which Text Editors emacs gedit nano / pico nedit vi vim / gvim

Appendix B - Shell Reference tcsh dot files are all located in the home directory of the user. –The.login is read on login. –The.tcshrc (or.cshrc ) is read when each new shell is spawned. –The.logout is read on logout.

Appendix B bash dot files are all located in the home directory of the user. –The.bash_login or.bash_profile or.profile is read on login. –The.bashrc is read when each new shell is spawned. –The.bash_logout is read on logout.