Lecture 2 Shell environment I: - command line interface & basic commands; - directories & files; - standard I/O & file descriptors; CSE4251 The Unix Programming.

Slides:



Advertisements
Similar presentations
RH030 Linux Computing Essentials
Advertisements

1 Introduction to UNIX Ke Liu
©Colin Jamison 2004 Introduction to Linux Colin Jamison.
5 Basic utilities When a user logs in to the Linux operating system the directory that they will start in is their home directory. Most users will have.
Exploring the UNIX File System and File Security
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
Linux Linux File System.
LINUX COMMAND LINE INTERFACE Lab 3 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
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.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
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”
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.
CHAPTER 1 UNIX FOR NONPROGRAMMERS By U ğ ur Halıcı.
Linux Directory Navigation. File & Directory Commands This is a minimal list of Unix commands that you must know for file management: ls (list) mkdir.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
– 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.
Linux+ Guide to Linux Certification, Second Edition
PROGRAMMING PROJECT POLICIES AND UNIX INTRO Sal LaMarca CSCI 1302, Fall 2009.
Chapter Two Exploring the UNIX File System and File Security.
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/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Linux+ Guide to Linux Certification, Third Edition
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.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
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.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Chapter Two Exploring the UNIX File System and File Security.
1May 16, 2005 Week 2 Lab Agenda Command Line FTP Commands Review More UNIX commands to learn File name expansion - * Introduction of vi.
40 Years and Still Rocking the Terminal!
E X C E E D I N G E X P E C T A T I O N S Basic LINUX Linux System Administration Dr. Hoganson Kennesaw State University Operating Systems Directory structure:
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Introduction to Programming Using C An Introduction to Operating Systems.
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.
UNIX filesystem CS 2204 Class meeting 2 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
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.
 Last lesson, the Windows Operating System was discussed along with the Windows command shell  Unix is a computer operating system, that similarly manages.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
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).
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.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
Web Programming Essentials:
Linux 101 Training Module Linux Basics.
Andy Wang Object Oriented Programming in C++ COP 3330
Lecture 2 Working with Files and Directories
Some Linux Commands.
The Command Prompt Commands are the way to “do things” in Unix
CS314 – Section 5 Recitation 1
Using Linux Commands Lab 3.
Exploring the UNIX File System and File Security
Web Programming Essentials:
Introduction to Computer Organization & Systems
Andy Wang Object Oriented Programming in C++ COP 3330
UNIX/LINUX Commands Using BASH Copyright © 2017 – Curt Hill.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Linux Commands LINUX COMMANDS.
A shell is a user interface.
January 26th, 2004 Class Meeting 2
Presentation transcript:

Lecture 2 Shell environment I: - command line interface & basic commands; - directories & files; - standard I/O & file descriptors; CSE4251 The Unix Programming Environment 1

Recap Shell – a non-graphic user interface to access Unix-like OSes – a process – a command interpreter Log into shell – on Linux machine: open terminal via GUI (normally) – on Windows machine: run PuTTY (w/ Pageant) to connect to remote a Linux server run Linux locally via VirtualBox/VMware-Workstation 2

After you logged in... 3

user name: zhengm 4

host machine name: eta After you logged in... 5

current directory: ~ (i.e., /home/zhengm) After you logged in... 6

bash command prompt: $ After you logged in... 7

Choose your shell Check your current shell – $ echo $SHELL – $ echo $0 Check availabe shells – $ cat /etc/shells – $ chsh –l Switch to another shell – $ chsh –s /bin/dash (changing to dash) won’t take effect until next login – directly type the shell name e.g.: $ dash temporarily change current shell without re-login (may not be supported on some OSes) $ cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/tcsh /bin/csh /bin/dash 8

Customize your shell Every shell supports some customization – user prompt – shortcuts (alias) – paths Customization takes place in startup files – configurations read by the shell automatically when it starts – system-wide config. file: /etc/profile (normally don’t touch) – your config. file: ~/.bashrc 9

Customize your shell Change user prompt – E.g., add the following line to your ~/.bashrc file: export " \t : the current time in 24-hour HH:MM:SS format \u : the username of the current user \H : the hostname \w: current working directory \r : carriage return \n : newline ~]$ + 10

Customize your shell Change user prompt – E.g., add the following line to your ~/.bashrc file: export " \t : the current time in 24-hour HH:MM:SS format \u : the username of the current user \H : the hostname \w: current working directory \r : carriage return \n : newline More about customized alias and paths on later lectures ~]$ + 11

Create account & change password Create an username “joe” (usually in lower case) – $ useradd joe Sets an initial password for “joe” – $ passwd joe (optional) Create a group called “students” – $ groupadd students (optional) Add “joe” to group “students” – $ useradd –G students joe “joe” changes password after logged in using the initial password – $ passwd 12

Some commonly used commands $ ls somedir# list files in dir $ cd somedir# enter some directory $ uname –a# check your platform info $ mv oldfilename newfilename# rename a file $ cp srcfilename dstfilename# copy a file $ cat filename # display the content of a file $ tail -n filename # display the last n lines of file $ head -n filename # display the first n lines of file $ rm filename # delete file/directory $ mkdir dirname# create a directory $ rmdir dirname # delete empty directory $ man cmdname# lookup cmd usage 13

What you see via “ls” is part of a file system $ ls / 14

File system 101 A way to organize data/resource – “everything is a file” on Unix Conceptually a tree structure 15

The Structure of Directories A file cc.txt in directory bb under directory aa under the root directory can be represented as /aa/bb/cc.txt. means current directory $ cd. #still in current directory $./prog #run ‘prog’ in current dir.. means parent directory $ cd.. #change to parent directory 16

Several Important Directories / – the root directory /bin – executable/binary files /dev – device files /home – personal work directory, default place after logged in 17

Several Important Directories /etc – configuration files & some executable shell files /usr – /usr/inlcude #header files – /usr/lib #libraries – /usr/bin/ #more executables /sbin – executables which can only be executed by the super user (root) 18

Some directory-related commands $ pwd – display current full directory path $ mkdir somedir and $ rmdir somedir – create and delete a directory $ ls – list the files in a directory – -l,-t $ cd somedir – enter a directory 19

Unix is multi-users/multi-tasks Allow multiple users to log into a shell simultaneously Allow multiple programs running concurrently Need protection! – protect different users – protect different programs Basic protection: access rights of file/directory 20

Access rights for file/directory Check access rights (permissions) – $ ls –l - rw- rw- r usenix.sty_.txt drwxrwxr-x.... WinLog d: directory 21

Access rights for file/directory Check access rights (permissions) – $ ls –l - rw- rw- r usenix.sty_.txt drwxrwxr-x.... WinLog access rights (permissions) 22

Three groups of Access rights – Owner (u) – The members within a group (g) – Others (o) Access Rights Groups - rw- rw- r usenix.sty_.txt drwxrwxr-x.... WinLog u g o 23

Access rights representation Each group has permissions represented by rwx or 0-7 – r mean read – w means write – x means executable – translated to 0-7 via binary values rwxBinaryOctalpermission No read, no write, no run No read, no write, can run No read, can write, no run Can read, no write, no run Can read, can write, and can run 24

What is permission 5? – 5 in binary format is : 101 Can read No write Can run Access rights representation 5 = 101 = r-x 25

Three groups of access rights, three numbers – Owner (u) – The members within a group (g) – Others (o) 764 owner can: read, write, run group can: read, write Others: can only read Access rights representation = = = rwx rw-- r

Commands related to the access right chown: change the owner of a file – e.g., $ chown user_name file_name chgrp: change the group of a file – e.g., $ chgrp group_name file_name 27

chmod: change permissions for owner, group, or others – access groups: u, g, o, and a (all groups) – access rights: r, w, x. – e.g.: $ chmod u+rwx, g+rx, o+rx file_name $ chmod 755 file_name $ chmod o-x file_name Commands related to the access right 28

Wildcards / Metacharacters for filename abbreviation Shell understands wildcards Metacharacters: * ? [ ] ~ * matches anything $ ls *.doc # list all files ending with.doc ? matches single character $ ls ?.doc # list a.doc, b.doc, but not ab.doc 29

[…] matches any of the enclosed charactors $ ls [ab].doc # only list a.doc or b.doc $ ls *[cx].doc # list files ending with c.doc or x.doc ~ is a shortcut of your home directory $ cd ~ # change to home directory $ cd ~/music # change to /home/username/music directory Wildcards / Metacharacters for filename abbreviation 30

Programs and Standard I/O Program Standard Input (stdin) Keyboard Output from another program A file Standard Output (stdout) Screen Input to another program A file Standard Error (stderr) 31

File Descriptor A file descriptor (fd) is an abstract indicator for accessing a file. It’s an Integer in Unix IntegerName 0Standard Input (stdin) 1 Standard Output (stdout) 2Standard Error (stderr) 32