Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Introduction to UNIX / Linux Dr. Jerry Shiao, Silicon Valley University Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Course Description Overview of Operating Systems. UNIX/Linux Software Architecture. UNIX Shells (Bourne, C, BASH). Editor (vi, emacs) and Electronic Mail. Files and File System Structure. File Security. Advanced File Processing. File Sharing. Redirection and Piping. Process and Job Control. Networking and Internetworking. Bourne Shell Programming. C Shell Progamming. File System Backup. Hands-On Lab Redhat Linux Host Development System. Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 2 Course Description Class Evaluation. 30 %: Midterm. First half material. 30 %: Final. Second half material. 30 %: Homework. 10 %: Attendance. Participtation. Lab Evaluation. No late Homework. 12 Lab Assignments. References: UNIX, The Textbook 2nd Edition, Syed Mansoor Sarwar A Practical Guide to Linux, Mark G. Sobell http://class.svuca.edu/~sau/class/CS206/ Homework Assignments. Lab Assignments. Lecture Slide. Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 3 Course Description Lab Assignments Assignment 1: Quick Start Into UNIX. Overview of OS. Assignment 2: UNIX Software Architecture. UNIX Shell. Assignment 3: UNIX Editors. Editing Text Files. Assignment 4: UNIX File System. UNIX File Security. Assignment 5: Basic File Processing. Advanced File Processing. Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 4 Course Description Assignment 6: File Sharing. File Redirection and Piping. Assignment 7: Processes. UNIX Networking and Internetworking. Assignment 8: Bourne Shell Programming. Advanced Bourne Shell Programming. Assignment 9: C Shell Programming. Advanced C Shell Programming. Assignment 10: File System Backup. Assignment 11: UNIX Tools. Assignment 12: UNIX GUI Basics. Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 5 Course Description http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Binaries The latest release version (beta 0.63). This will generally be a version I think is reasonably likely to work well. If you have a problem with the release version, it might be worth trying out the latest development snapshot (below) to see if I've already fixed the bug, before reporting it to me. For Windows on Intel x86 PuTTY: putty.exe (or by FTP) (RSA sig) (DSA sig) ... Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 6 Course Description Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 7 Course Description MAC OS X: In the “Applications/Utilities” folder, open “Terminal”. In the upper-right corner of the MAC main window, there is also a “Search” area. Type in “Terminal”. ssh <User Name>@<Server IP Address> ssh [email protected] Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 8 Introduction UNIX/Linux Course Outline Section 1 UNIX/Linux Introduction QuickStart into UNIX Operating System UNIX User Interface: Predominant interaction is text-based. Connect and Log On to UNIX Operating System. Maintain and Organize Files. Online Help for UNIX Commands. Common Utility Commands. UNIX At the Beginning Overview of Operating Systems. Computer Systems Software. UNIX Family History. UNIX Software Architecture UNIX Kernel and Device Driver. UNIX System Call Interface and Library. UNIX or Linux? File Maintenance Commands Utility Commands Aliases Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 9 Section 1 UNIX/Linux Introduction Computer System: What is an Operating System? Primary purpose is to faciliate: Easy, Efficient, Fair, Orderly and Secure use of hardware and software resources through Application Software (MSWord, Excel). Bottom-Up Operating System View: Consists of hardware and software resources. Software that allocates and de-allocates system resources (Resource Manager) in an efficient, fair, orderly, and secure manner. Memory allocated to process, Printer accesses one file, CPU scheduled between processes. Top-Down Operating System View: Software isolates users from hardware resources. User does not know physical location of file on disk, structure and size of the disk, and number or name of the drive on the system. Application Programmer’s Interface ( API ): System Calls Abstraction layer (Virtual File System) allows common interface to hardware resources. Simple User Interfaces (CLI). Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 10 Section 1 UNIX/Linux Introduction Layered View of a Computer System Application programs (word processors, spreadsheets, games, graphing tools, picture processing tools, Web browsers) Unix Shell, File Operation Commands Keyboard, Display Screen, RAM, disk drive, modem, CPU. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 11 Section 1 UNIX/Linux Introduction Operating System Services Services allow execution of user and system application efficiently and securely. Services designed to execute software (Application Programs): Input and Output operations performed by programs: System Logs Manipulation of all types of files Linux Message Queues, Semaphores, Shared Memory Error Detection and Reporting Hides details of underlying I/O hardware: stdin, stdout, stderr, pipe Communication between processes same/different computer Provides environment: Memory allocation, multi-processing, scheduling Secondary Storage Management: cp, mv,rm, mkdir Management of users and security Login Access Control, Password Management Control Security-Enhanced Linux (SELinux) Access Control Policy Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 12 Section 1 UNIX/Linux Introduction Character Versus Graphic User Interface Using Computer System require user to provide commands to the Operating System. Character User Interface (CUI) Keyboard issue command to the Operating System. DOS, UNIX UNIX primary input device. Maximum flexibility: Run commands directly: Minimal layer between user and system process. Graphical User Interface (GUI) Mouse (point-and-click device) issue command to the Operating System. MacOS, Microsoft Windows UNIX runs X Window System based GUI (RunLevel 5). Minimal flexibility: Extra layer Graphical process between user and the system process, causing delay in execution. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 13 Section 1 UNIX/Linux Introduction Types of Operating Systems Single-User, Single-Process System Single-User, Multiprocess System Multiple user use simultaneously and each user can run multiple processes. CPU resource multiplexed – process performing I/O while another process use CPU. Time-Sharing System: Scheduler context switches between concurrently executing processes, appear to be single user. UNIX, LINUX, WindowsNT Server, MVS, VM/CMS. Interactive Operating System One user at a time and user runs multiple processes simultaneously. OS/2, Windows XP Workstations. Multiuser, Multiprocess System One user at a time and user runs only one process at a time. CPU resource left idle while process performing I/O. MacOS, DOS, Windows 3.1. UNIX, LINUX, DOS, Windows, etc. Batch Operating System VMS running payroll programs. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 14 Section 1 UNIX/Linux Introduction Summary Operating System manage system’s hardware and software resources. Services provided include: Program Execution, I/O Operations, communication between processes, error detection and reporting, and file manipulation. Operating System categorized: Single-User Single-Process, Single-User Multi-processes, and Multi-User Multi-Processes. Multiuser and Multiprocess are Time-Sharing Systems: Increase utilitzation of system resources by switching them among concurrently executing processes. Character User Interface; Command entered directly to Operating System. Graphical User Interface: Command entered through point-andclick device. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 15 Section 1 UNIX/Linux Introduction Evolution of Linux: Developed in Response to need of heterogenous Community of Computer Uses. Open Software System: Evolution Shaped by a Populist Mindset. UNIX/Linux Community Diverse Audience MULTICS: 1965 Multiuser Operating System Source Code FREELY Distributed among Community of Users. Not Dominated by a Corporation of Institution Entity: Contributions by different User Groups and broad range of topics. Complexity in Software and Hardware to support multiple users. UNIX: 1969 Bell Laboratories early Inception as Laboratory Research Tool … Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 16 Section 1 UNIX/Linux Introduction AT&T Bell Labs: Ken Thompson and Dennis Ritchie C Source Code Multi-User, Multi-processor. Bell Labs Bourne Shell 1969 Microsoft created Xenix from UNIX System V. BSD Version 1-6 1980 System III Xenix C Shell Microsoft teams with IBM OS/2 and transferred ownership to Santa Cruz Operations (SCO). 1 BSD 4 BSD Korn Shell SUN OS System V 1990 UNIXware Linux System V and BSD Open Source 2000 Copyright @2005 Pearson Addison-Wesley. SCO UNIX Novell SCO acquires UNIXware Solaris Solaris 2 POSIX Portable Operating System Interface SILICON VALLEY UNIVERSITY CONFIDENTIAL 4.4 BSD FreeBSD 17 Section 1 UNIX/Linux Introduction UNIX Operating System Development in Bell Laboratories UNIX System developed and written in C language, small subset tailored to target processor. Releases distributed in C Source Code: UNIX did NOT follow other Operating System development: Most Operating System programs written in an assembly language, specifically tailored to the architecture of the processor. Easily modified and improved upon to add functionality by users of Operating System. Multiple processes able to execute concurrently and connected through streams. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 18 Section 1 UNIX/Linux Introduction Computer System Hardware and Software Components (Resources) Computer System Hardware Several Subsystems: Main/Primary Memory, CPU(s), Secondary Storage (Flash, Hard Disk Drives) and Input/Output Devices (CDROM, Keyboard, Scanner, Printer, and Mouse). Main/Primary Storage Storage location addressed by Byte. Store executing processes and data currently in use. Kernel space separated from user space. Volatile storage, loses content when powered off. Central Processing Unit (CPU) Control Unit Executes programs by fetching instructions from the RAM. Each processor has its own instruction set. Interacts with device controllers ( memory, keyboard, disk, monitor). Arithmetic and Logic Unit (ALU) executes instruction fetched by the Control Unit. Registers used as temporary storage locations. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 19 Section 1 UNIX/Linux Introduction Computer System Hardware Disk (Desktop) or Flash (Embedded Systems) Highest Latency in Computer System (Head Seek Time). Contains all of the Computer System’s programs and applications (Kernel, user applications). Nonvolatile storage, retains content when powered off. Bus Parallel wiring carry information from one subsystem to another. System Bus: Data Bus – carry data from one subsystem to another (i.e. program code from main memory to CPU). Address Bus – Address of main memory location to read/write. Control Bus – Control Information (i.e. read/write from CPU to main memory). I/O Devices Allows user to run commands and apps, supply inputs, capture outputs (i.e. keyboard, mouse, monitor, printer). Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 20 Section 1 UNIX/Linux Introduction Computer System Hardware Machine Cycle – CPU / System Bus CPU Control Unit: 1) Fetches program instruction. 2) Decodes and checks for valid instruction. 3) Executes the instruction., CPU Execution Unit System Bus Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 21 Section 1 UNIX/Linux Introduction Computer System Hardware System Bus Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 22 Section 1 UNIX/Linux Introduction UNIX Software Architecture Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 23 Section 1 UNIX/Linux Introduction UNIX Software Architecture Application User’s Interface ( AUI ) Applications: Contains all applications (Tools, Commands, and Utilities) available to Users. Filesystem: cp, mv, rm, mkdir, mkfifo, ls, cd. Text Processing: vi/vim, emacs, more, less, diff. Programming: make. User Environment: su, uname, who, whoami Application manipulates system resources by invoking kernel code through library functions or system calls. UNIX Shell: Program that starts running when logon and interprets the commands that are entered. echo, expr, sleep, test, tee. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 24 Section 1 UNIX/Linux Introduction UNIX Software Architecture Application Programmer’s Interface ( API ) Library and system call interfaces are Application Programming Interfaces (API) used by user programs to invoke kernel code. System Call Interface: Entry points into the Kernel. All system resources managed by the Kernel: UNIX provides access to Kernel code through function (system) calls. Manipulate processes, Files, and other System Resources (allocate/deallocate memory, access printer). Language Libraries: C, C++, Java, FORTRAN, etc. Set of prewritten functions available to programmers to use during software development., C Language Libraries: printf, memcpy, strcmp, memcmp. C Language Math Library: Functions for mathematical operations. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 25 Section 1 UNIX/Linux Introduction UNIX Kernel: UNIX Operating System Kernel Process Management: Creates, Suspends, Terminates, Schedules, Communicate, and maintain States. Provides communication between processes: Same Computer System or through Network between Computer Systems. Primary Inter-Process Communication (IPC) Mechanisms. Pipe: Temporary channel residing in main memory used by two or more related processes. Named Pipe ( FIFO ): Permanent communication channel on disk and used as IPC between two or more related processes. BSD Socket: Temporary channel allows two or more processes to communicate through network ( Internet ) or same computer. Client-Server Applications (BSD): Web Browsers, Electronic Mail, Telnet, SSH, FTP. Distributed Network Architecture (BSD): P2P Napster, BitTorrent, uTorrent Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 26 Section 1 UNIX/Linux Introduction UNIX Software Architecture UNIX Kernel (Cont) Disk Management: Main Memory Management: Disk scheduling Algorithm (multiple requests). Keeps status of physical memory, either allocated or free. How memory is allocated to processes: Contiguous Allocation, Paged Allocation, Segmented Allocation. Process Address Space: Allocates space to a process and prevents user memory space volation. File Management: File creation/removal. Directory creation/removal. File and directory attribute maintenance. Device Drivers: Executes on behalf of the UNIX kernel when a user command or application needs to perform hardware-related operations. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 27 Section 1 UNIX/Linux Introduction UNIX Usage UNIX System: Is a Multi-process, Multi-user, and Interactive Computing Environment. Designed for Multi-User computing environment (sharing the Computer System). Portability is major trademark of UNIX. UNIX Basic Connections: Local area network Connection Terminal connected to a computer server through LAN to the UNIX computer system. Internet Connection PC running Telnet or ssh software connecting through Internet to the UNIX computer system. Stand-alone Connection User logged on to UNIX computer system (Desktop UNIX). Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 28 Section 1 UNIX/Linux Introduction UNIX Usage UNIX Basic Connections: Local area network Connection Compute Server Connection to a Local or Wide Area Network RS-232 Serial Ports Modem Connection. Copyright @2005 Pearson Addison-Wesley. Terminal Server connects to Network Interface SILICON VALLEY UNIVERSITY CONFIDENTIAL 29 Section 1 UNIX/Linux Introduction UNIX Usage UNIX Basic Connections: Standalone Connection RS-232 Serial Ports Modem Connection. Copyright @2005 Pearson Addison-Wesley. Connection to a Local or Wide Area Network Terminal Server connects to Network Interface SILICON VALLEY UNIVERSITY CONFIDENTIAL 30 Section 1 UNIX/Linux Introduction UNIX Usage UNIX Basic Connections: Internet Connection Connection to a Local or Wide Area Network PC running Telnet or ssh software connecting through Internet to the UNIX computer system. Modem Connection. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 31 Section 1 UNIX/Linux Introduction Logging On Logging Out: <Ctrl> <D> Bash Shell Login: /etc/profile Login: Script searched in the following order, Shell: Started in Terminal Emulator or GUI (xterm). 1) $HOME/.bash_profile, 2) $HOME/.bash_login, 3) $HOME/.profile $HOME/.bashrc Logout: $HOME/.bash_logout Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 32 Section 1 UNIX/Linux Introduction UNIX Command Shell Environment Console: Properties and appearance. Shell session: User Interaction with the system requires information compiled by the shell to determine its behavior and access to system resources. Shell Variables or local symbols are contained exclusively in the shell in which they are defined (local session). Variable = Setting Variable is a Shell Variable. Setting is the value of the Shell Variable. Shell Environment Variables or global symbols are settings for its local session and spawned child sessions. export Variable = Setting The Environment Variable for all subsequent child sessions must be placed in Configuration Files (i.e. /etc/profile, /etc/bashrc, ~/.bash_profile, ~/.bashrc). Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 33 Section 1 UNIX/Linux Introduction UNIX Command Shell Environment Global Environment ~/.bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH User Local Environment ~/.bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # User specific aliases and functions export PATH=$PATH:$HOME/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihfraspbian/bin Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 34 Section 1 UNIX/Linux Introduction UNIX Command $ command [ [ - ] option (s) ] [ option argument (s) ] [ command argument (s) ] $: Shell prompt from the computer. [..]: Enclosed is not always needed. Command: Name of the valid UNIX command for the shell. [-option(s)]: Command modifier that change behavior of command. [option argument(s)]: option modifier that changes behavior of -option. [command argument(s)]: Command parameter(s) are objects that are affected by command. NOTES: Space separates command, option, option arguments, and command arguments. Space optional between multiple options or multiple option arguments. Order of multiple options or option arguments irrelevant. Space optional between option and option argument. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 35 Section 1 UNIX/Linux Introduction UNIX Command $ ls $ ls -la $ Command (ls) and two options (l and a). ls -la m* $ Only command. Command (ls), two options (l and a) and command argument (m*). lpr -Pspr -n 3 proposal.ps Command (lpr), two options (P and n), two option arguments (spr and 3), and command argument (proposal.ps). Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 36 Section 1 UNIX/Linux Introduction Microsoft Windows PuTTY Connection User on PC running Windows OS start the PuTTY program to connect to the remote server through the remote server’s host name or IP address. Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 37 Section 1 UNIX/Linux Introduction Microsoft Windows Command Dialogue Box Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 38 Section 1 UNIX/Linux Introduction PuTTY Connection Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 39 Section 1 UNIX/Linux Introduction History Linux File System derived from Minix File System (later Xia File System). Linux implemented Extended File System (ext, ext2, ext3, and ext4). Max file system size Max file size Max file name size Minix File System 64 MBytes 64 MBytes 16 Bytes Block file System. Extended File System 2 GBytes 2GByte 255 Bytes Block File System. Second Extended File System 32 TBytes 2 TBytes 255 Bytes Block File System. Third Extended File System 32 TBytes 2 TBytes 255 Bytes Journaling File System. Fourth Extended File System 10**6 TBytes 16 Tbytes 255 Bytes Journaling File System or Block File System. Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 40 Section 1 UNIX/Linux Introduction History Virtual File System (VFS) provide level of abstraction between user and different file systems. Using a common set of API functions, a large variety of file systems can be supported on a large variety of storage devices. Summer 2015 Read function unaware of system types (i.e. ext2, ext3, ext4, or NFS) and unaware of storage medium file system is mounted. SILICON VALLEY UNIVERSITY CONFIDENTIAL 41 Section 1 UNIX/Linux Introduction Linux Directory Structure /boot – Linux bootup files (i.e. Linux Kernel) /etc – Linux system configuration files. vmlinux boot / root etc bin usr sbin var dev mnt home /etc/inittab – Processes started at bootup (i.e. Runlevel) inittab fstab mount Summer 2015 /etc/passwd – Users are defined and user accounts. /bin – Linux system binaries. /sbin/init – Process runned during boot process. bin grep /usr/bin – Applications for the users. /lib – The shared libraries for dynamically linked modules. init /var – Data changes when the Linux system is running. log /var/log – The running Linux system updated log files. tty0 /dev – Devices that are available to Linux system. Devices are treated like files and devices can be read/written as files. cdrom /mnt – Storage devices (i.e. hard disk, CD-ROMs) must be attached to some directory before accessing. Directores are the mount points. student1 lib proc /etc/fstab – File systems and mount points. passwd /home – Each users have own directory and only place normal users are allowed to write. /proc – Special directory containing information about the kernel. devices /proc/devices – List of devices configured into current kernel. SILICON VALLEY UNIVERSITY CONFIDENTIAL 42 Section 1 Unix/Linux Introduction File Maintenance Home Directory: User Login to /home/<username> in shell. Current Working Directory (CWD): Directory shell currently in. Only one current working directory active at one time. Pathname: Textual designation of directory or file. Organize group of files into “bins” or directories, for example, according to the file contents subject matter or dates of creation. Parent of / home /home/sau/myfile2 /home/sau/first/… /home/sau/myfile1 CWD. CWD = sau Children of CWD. sau myfile2 first myfile1 ... Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 43 Section 1 UNIX/Linux Introduction File Maintenance Commands Viewing / Creating / Deleting / Managing Files cat, more, cp, mv, rm, ls / home $ cat > myfile1 Use the cat to add plain text. sau <Ctrl-D> $ more myfile1 myfile2 first myfile1 Use the cat to add plain text. $ cp myfile1 myfile2 $ mv myfile2 renamed_file renamed _file $ mv “latest revisions” late.txt mv: cannot stat `latest revision': No such file or directory $ rm renamed_file $ ls myfile1 $ Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 44 Section 1 UNIX/Linux Introduction File Maintenance Commands List Files and Directories Properties Options: -F (“/”=Directory, “*”=Binary, “<“=Executables, “@”=Symbolic Link), -a (All files, including hidden files), -i (Inode numbers), -l (File Access Mode, Link Count, Owner, Group, File Size, Mod Time). Column 1: Type of file, “d” directory, “l” ls -la symbolic link, “-” ordinary or drwx------ 37 drwxr-xr-x 8 drwxrwxr-x 9 -rw-rw-r-- 1 Column 2: Number of links to the file. Column 3: Username of owner. Copyright @2005 Pearson Addison-Wesley. regular file. Access mode for pi pi 4096 2014-09-03 16:57 . file. root root 4096 2014-01-14 18:53 .. pi pi 4096 2014-07-18 01:06 raspi pi pi 275 2014-03-14 03:15 minicom.log Column 5: Number of bytes of the file. Column 4: Group name of file. SILICON VALLEY UNIVERSITY CONFIDENTIAL 45 Section 1 UNIX/Linux Introduction File Maintenance Commands Creating / Deleting / Managing Directories mkdir, cd, pwd, rmdir $ mkdir first $ cd first $ pwd /home/sau/first $ cd $ pwd /home/sau $ cp myfile myfile2 $ ls my* myfile myfile2 $ mv myfile2 first $ rmdir first rmdir: first: Directory not empty $ rm –r first Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL home sau first myfile 46 Section 1 UNIX/Linux Introduction UNIX Help (man Command) Obtaining Help with “man” Command UNIX Reference Manual pages has 8 Sections Section 1 most users. Section 2 most software developers. Name: Synopsis: Description: List Of Files: Related Info: Errors: Warnings: Known Bugs Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 47 Section 1 UNIX/Linux Introduction UNIX Help (man Command) man [options][-s section] command-list $ man ls LS(1) FreeBSD General Commands Manual LS(1) NAME ls - list directory contents SYNOPSIS ls [-ABCFGHLPRTWZabcdfghiklmnopqrstuwx1] [file ...] DESCRIPTION For each operand that names a file of a type other than directory, ls displays its name as well as any requested, associated information. For each operand that names a file of type directory, ls displays the names of files contained within that directory, as well as any requested, associated information. If no operands are given, the contents of the current directory are displayed. If more than one operand is given, nondirectory operands are displayed first; directory and nondirectory operands are sorted separately and in lexicographical order. The following options are available: Press <SPACE> to continue, or q to quit q $ man -s2 read Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 48 Section 1 UNIX/Linux Introduction UNIX Help (man Command) man [options][-s section] command-list $ man –s2 read READ(2) NAME Linux Programmer’s Manual READ(2) read - read from a file descriptor SYNOPSIS #include <unistd.h> ssize_t read(int fd, void *buf, size_t count); DESCRIPTION read() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf. If count is zero, read() returns zero and has no other results. If count is greater than SSIZE_MAX, the result is unspecified. RETURN VALUE On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number. It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we : q Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 49 Section 1 UNIX/Linux Introduction UNIX Help (man Command) man [options][-s section] command-list $ man –k passwd [pi@sau (Fri Sep 05 - 02:43:18)$ man -k passwd chpasswd (8) - update passwords in batch mode fgetpwent_r [getpwent_r] (3) - get passwd file entry reentrantly getpwent_r (3) - get passwd file entry reentrantly gpasswd (1) - administer the /etc/group file hesiod_free_passwd [hesiod_getpwnam] (3)-Hesiod functions for retrieving passwd … hesiod_getpwnam (3) - Hesiod functions for retrieving passwd information hesiod_getpwuid [hesiod_getpwnam] (3) - Hesiod functions for retrieving passwd … htpasswd (1) - Manage user files for basic authentication ldappasswd (1) - change the password of an LDAP entry lpasswd (1) - Change group or user password lppasswd (1) - add, change, or delete digest passwords pam_localuser (8) - require users to be listed in /etc/passwd pam_passwdqc (8) - Password quality-control PAM module pam_passwdqc (rpm) - Pluggable password quality-control module. passwd (1) - update a user's authentication tokens(s) passwd2des [xcrypt] (3) - RFS password encryption passwd (5) - password file . . . Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 50 Section 1 UNIX/Linux Introduction UNIX Help man -f <keyword> whatis <keyword> Search the whatis database for abbreviated descriptions of each “keyword” and print a one-line description. $ whatis login set setenv login(1) -sign on set(1) -set runtime parameters for session setenv (1) -change or add an environment variable $ Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 51 Section 1 UNIX/Linux Introduction UNIX Utility Commands Examining System Setups whereis, whoami $ whoami sau $ whereis mkdir mkdir: /usr/bin/mkdir General Utility Commands lpr, cal $ lpr –Pspr order.eps Communication Commands write, who, mesg y, mesg n Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 52 Section 1 UNIX/Linux Introduction UNIX Utility Commands: write student1 pts/2 [student1@sau (Fri Sep 05 - 18:01:38)$ mesg y [student1@sau (Fri Sep 05 - 18:01:41)$ who pi pts/1 2014-09-05 17:51 (:0.0) student1 pts/2 2014-09-05 17:56 (10.1.110.198) student2 pts/3 2014-09-05 17:59 (10.1.110.198) [student1@sau (Fri Sep 05 - 18:01:43)$ [student1@sau (Fri Sep 05 - 18:02:52)$ write student2 pts/3 Hello student2 [student1@sau (Fri Sep 05 - 18:04:20)$ Message from [email protected] on pts/3 at 18:04 ... I am fine. Where are you? EOF student2 pts/3 [student1@sau (Fri Sep 05 - 18:01:38)$ mesg y [student2@sau (Fri Sep 05 - 18:10:50)$ who pi pts/1 2014-09-05 17:51 (:0.0) student1 pts/2 2014-09-05 17:56 (10.1.110.198) student2 pts/3 2014-09-05 17:59 (10.1.110.198) [student2@sau (Fri Sep 05 - 17:59:49)$ Message from [email protected] on pts/2 at 18:03 ... Hello student2 EOF [student2@sau (Fri Sep 05 - 18:04:30)$ write student1 pts/2 I am fine. Where are you? Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 53 Section 1 UNIX/Linux Introduction UNIX Command Alias The alias command can be used to create pseudonyms (nicknames) for commands Syntax for the alias command is: alias [name [ = string ] …] Bourne, Korn, Bash shells alias [name [ string ] ] Create aliases in term profile (i.e. .login) or shell startup script (i.e. Bash in .bashrc file). C shell Create aliases in term profile (i.e. .login) or from command line or shell startup script (i.e. .cshrc). Useful Aliases Bash shell C shell alias dir=“ls -la” alias rename=“mv” alias ll=“ls –ltr” alias dir “ls -la \!*” alias rename=“mv \!*” alias ll=“ls –ltr \!*” function foo() { mv “$@”; } Alias rename=foo Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 54 Section 1 UNIX/Linux Introduction UNIX Useful Commands Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 55 Section 1 UNIX/Linux Introduction UNIX Useful Commands Copyright @2005 Pearson Addison-Wesley. SILICON VALLEY UNIVERSITY CONFIDENTIAL 56