Files and Directories in UNIX The first file in UNIX file system is “root” or “/”

Slides:



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

Introduction to UNIX CSE 2031 Fall May 2015.
Links Learning Objectives: 1. To understand the basics of links & its usage 2. To learn the construction / removal of different types of links 3. To distinguish.
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.
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Links Learning Objectives: 1. To understand the basics of links & its usage 2. To learn the construction / removal of different types of links 3. To distinguish.
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.
Links Software Tools. Lecture 4 / Slide 2 Links l A link is a pointer to a file. l In fact, in UNIX all filenames are just links to a file. Most files.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
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.
Learning basic Unix command IT 325 operating system.
Chapter 4: UNIX File Processing Input and Output.
File Systems Sources and Resources: 1. A Students Guide to UNIX, by Hahn 2. Paula Davidson’s Handout on UNIXHandout on UNIX.
1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID COSC 513 Operating System.
The file structure and related utilities CS240 Computer Science II.
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.
Introducing UNIX EMBnet slide 1 Introducing the UNIX Operating System.
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 environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
3 File Processing Mauro Jaskelioff. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash.
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.
June 1, 1999Using The C-Shell1 Introduction to UNIX F. Using C Shell Features.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
June 1, 1999UNIX File System1 Introduction to UNIX D. UNIX File Structure.
Regular expressions Used by several different UNIX commands, including ed, sed, awk, grep A period ‘.’ matches any single characters.X. matches any X.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
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.
Lesson 2 1.Commands 2.Filename Substitution 3.I/O Redirection 4.Command Grouping 5.Shell Responisibilites Review of the Basics.
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.
I/O and Redirection. Standard I/O u Standard Output (stdout) –default place to which programs write u Standard Input (stdin) –default place from which.
Managing Files. Module 5 Managing Files ♦ Introduction “On a Linux system, everything is a file; if something is not a file, it is a process.” ♦ Topics.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Introduction to UNIX. 2 Unix File System zDirectory Organization zHierarchy of Files & Directories.
Chapter 4: File Security & Permissions Also: Hard and Soft Links, see p77-80 &
Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links.
Introduction to Programming Using C An Introduction to Operating Systems.
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
Linux Commands C151 Multi-User Operating Systems.
File Systems, telnet and ftp Sources and Resources: 1. A Students Guide to UNIX, by Hahn 2. Paula Davidson’s Handout on UNIXHandout on UNIX.
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
 Last lesson, the Windows Operating System was discussed along with the Windows command shell  Unix is a computer operating system, that similarly manages.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
Learning basic Unix command It 325 operating 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).
Chapter 2: Exploring the UNIX File System (For Tuesday Section) File and File Systems.
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.
Introducing the UNIX Operating System.
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.
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Andy Wang Object Oriented Programming in C++ COP 3330
Lecture 2 Working with Files and Directories
Some Linux Commands.
The Unix File System.
The Linux Command Line Chapter 4
Module 6 Working with Files and Directories
January 26th, 2004 Class Meeting 2
The Linux Command Line Chapter 4
Presentation transcript:

Files and Directories in UNIX The first file in UNIX file system is “root” or “/”

Files and Directories in UNIX (continue.) Home directory (could be named differently) has subdirectory per user called “User Home Directory” Directories can have more subdirectory and files A file or a directory can be referred to by Relative path name [a.doc if you are at Documents] Absolute path name [/home/abuzneid/UNIX/Documents/a.doc}\] File and directory names are case sensitive

Files and Directories in UNIX (continue.) To display working directory $ pwd /home/abuzneid/UNIX $ $ ls -l total 8 drwxr-xr-x 2 abuzneid Oct 8 13:40 Documents drwxr-xr-x 2 abuzneid Oct 8 13:43 mail drwxr-xr-x 2 abuzneid Oct 8 13:53 memos drwxr-xr-x 2 abuzneid Oct 8 13:53 personal $ cd Documents $ pwd /home/abuzneid/UNIX/Documents $  cd command to change directory

Files and Directories in UNIX (continue.) $ pwd /home/abuzneid/UNIX $ ls -l total 8 drwxr-xr-x 2 abuzneid Oct 8 13:40 Documents drwxr-xr-x 2 abuzneid Oct 8 13:43 mail drwxr-xr-x 2 abuzneid Oct 8 13:53 memos drwxr-xr-x 2 abuzneid Oct 8 13:53 personal $ cd Documents $ pwd /home/abuzneid/UNIX/Documents $ cd.. $ pwd /home/abuzneid/UNIX $

Files and Directories in UNIX (continue.) $ cd / $ pwd / $ cd /home/abuzneid/UNIX/Documents $ pwd /home/abuzneid/UNIX/Documents $ cd../.. $ pwd /home/abuzneid $ cd $ pwd /home/abuzneid $

List Files ls command is used to list files and directories ls –l displays more information about every file and directory file type d for directory - for file b, c, p for special file access made for the owner, group and others number of links owner of the file Size last modification file name

List Files (continue.) $ pwd /home/abuzneid/UNIX/Documents $ ls a.doc c.doc $ ls -l total 4 -rw-r--r-- 1 abuzneid Oct 8 13:37 a.doc -rw-r--r-- 1 abuzneid Oct 8 13:38 c.doc $ cd $ pwd /home/abuneid $ ls UNIX Documents mail memos personal $

List Files (continue.) $ ls -a... Documents mail Memos personal $

Creating a Directory: the mkdir command mkdir command $ pwd /home/abuzneid/UNIX $ mkdir test $ ls Documents mail Memos personal test $ cd test $ pwd /home/abuzneid/UNIX/test $

Copying file from directory to another $ cp UNIX/personal/p1 UNIX/Documents/p11 $ ls UNIX/Documents a.doc c.doc p11 $ cp UNIX/personal/p1 UNIX/Documents $ ls UNIX/Documents a.doc c.doc p1 p11 $ cd UNIX/personal $ pwd /home/abuzneid/UNIX/personal $ ls p1 p2 $ cp p1 p2 /home/abuzneid/UNIX/mail $

Moving Files between Directories $ cd /home/abuzneid/UNIX/personal $ ls -l total 4 -rw-r--r-- 1 abuzneid Oct 10 21:46 p1 -rw-r--r-- 1 abuzneid Oct 10 21:49 p2 $ mv p1 p2 /home/abuzneid/UNIX/Memos $ cd /home/abuzneid/UNIX/Memos $ ls p1 p2 $

Rename File or Directory mv is used to rename a file of a directory $ ls -l total 14 drwxr-xr-x 2 abuzneid Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid Oct 8 13:43 mail drwxr-xr-x 2 abuzneid Oct 10 21:54 Memos drwxr-xr-x 2 abuzneid Oct 8 23:42 memos drwxr-xr-x 2 abuzneid Oct 10 21:54 personal drwxr-xr-x 2 abuzneid Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid Oct 10 21:39 test $ mv Memos memos $

Rename File or Directory (continue.) Memos renamed to memos $ ls -l total 12 drwxr-xr-x 2 abuzneid Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid Oct 8 13:43 mail drwxr-xr-x 3 abuzneid Oct 10 21:57 memos drwxr-xr-x 2 abuzneid Oct 10 21:54 personal drwxr-xr-x 2 abuzneid Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid Oct 10 21:39 test $

Removing a directory: the rmdir command To remove a directory: rmdir if the directory is empty rm –r if it’s not empty

Removing a directory: the rmdir command (continue.) $ rmdir /home/abuzneid/UNIX/memos rmdir: directory "/home/abuzneid/UNIX/memos": Directory not empty ALL SUBDIRECTORIES AND FILES IN memos MUST BE DELETED FIRST $ cd /home/abuzneid/UNIX/memos $ ls -l total 4 -rw-r--r-- 1 abuzneid Oct 8 23:23 p1 -rw-r--r-- 1 abuzneid Oct 8 23:29 p2 $ rm * $ ls $ cd.. $ rmdir memos $ ls -l total 10 drwxr-xr-x 2 abuzneid Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid Oct 8 13:43 mail drwxr-xr-x 2 abuzneid Oct 10 21:54 personal drwxr-xr-x 2 abuzneid Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid Oct 10 21:39 test $

Linking Files: the ln command To have two copies of any file, you can use: cp to copy it to another file, or ln to link the file to another file The disadvantages of cp Consumes twice as much disk space Both files always has to be changed if any of them is updated to keep them identical Number of links to a file is, normally 1 for non- linked, non-directory files More than one link to a file is possible Most often, ln is used to link files between directories

Linking Files: the ln command (continue.) There is two types of links Hard diskSoft link ln “to” can be file or directory “to” and “from” must resides on the same file system “to” and “from” may resides on different file system “to” and “from” will have the same size “to” will have a size of link (pointer) to “from” If “to” is deleted “from” will work fine and vice versa If “from” is deleted, “to” will not work

Linking Files: the ln command (continue.) $ cat aaa Bridgeport Massashusets New Hampshire Vermont $ ls -l total 12 -rw-r--r-- 1 abuzneid Oct 10 23:14 aaa -rw-r--r-- 1 abuzneid Oct 10 23:12 bbb drwxr-xr-x 2 abuzneid Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid Oct 8 13:43 mail drwxr-xr-x 2 abuzneid Oct 10 21:54 personal drwxr-xr-x 2 abuzneid Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid Oct 10 21:39 test $

Linking Files: the ln command (continue.) $ ln aaa bbb $ ls -l total 14 -rw-r--r-- 2 abuzneid Oct 10 23:14 aaa -rw-r--r-- 2 abuzneid Oct 10 23:14 bbb drwxr-xr-x 2 abuzneid Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid Oct 8 13:43 mail drwxr-xr-x 2 abuzneid Oct 10 21:54 personal drwxr-xr-x 2 abuzneid Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid Oct 10 21:39 test $ cat bbb Bridgeport Massashusets New Hampshire Vermont $

Linking Files: the ln command (continue.) $ echo one more line >> aaa $ cat aaa Bridgeport Massashusets New Hampshire Vermont one more line $ cat bbb Bridgeport Massashusets New Hampshire Vermont one more line $ rm aaa $ cat bbb Bridgeport Massashusets New Hampshire Vermont one more line $

Linking Files: the ln command (continue.) $ cp bbb ccc $ ln -s ccc ddd $ ls -l total 16 -rw-r--r-- 1 abuzneid Oct 10 23:20 bbb -rw-r--r-- 1 abuzneid Oct 10 23:25 ccc lrwxrwxrwx 1 abuzneid Oct 10 23:26 ddd -> ccc drwxr-xr-x 2 abuzneid Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid Oct 8 13:43 mail drwxr-xr-x 2 abuzneid Oct 10 21:54 personal drwxr-xr-x 2 abuzneid Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid Oct 10 21:39 test $ rm ccc $ cat ddd cat: cannot open ddd $

File Name Substitution $ ls bbb ddd Documents mail personal TEST test $ echo * Documents TEST bbb ddd mail personal test $ echo *.* *.* $ echo a* a* $ echo m* mail $ echo *a* mail personal $ The asterisk ”*”: substitutes zero or more characters

File Name Substitution (continue.) “?” matches single character $ ls bbb ddd Documents mail personal TEST test $ echo ??? bbb ddd $

File Name Substitution (continue.) Matching a single character using square brackets [] [abc] matches one letter [!a-z] matches any character except a lower case letter *[!X] matches any file that doesn't end with the upper case X

Standard Input/Output Standard input is the terminal (keyboard) Standard output is the terminal (display) command standard input standard output

Standard Input/Output (continue.) If a sort command is executed without a file name argument, then the command will take its input from standard input who skantty01 Jan 07 07:56 wiemtty52 Jan 07 06:15 samirtty03 Jan 07 09:26

Standard Input/Output (continue.) Example: $ sort nouha mahdi malek issam salwa issam mahdi malek nouha salwa $

Standard Input/Output (continue.) sort skan wiem samir skan wiem samir

Output Redirection Output directed to a file instead of standard output command > ofiledirects output to the file ofile command >> ofile appends output to the file ofile > ofilecreates an empty file “ofile”

Output Redirection (continue.) Example: $ who > users $ cat users bgeorge pts/16 Oct 5 15:01 ( ) abakshi pts/7 Oct 10 22:56 ( ) abuzneid pts/9 Oct 10 19:29 (avicenna in-addr.arpa) xiafeng pts/10 Oct 10 23:16 (Shiva-RAS-Pool-13.uhmc.sunysb.edu) $ echo add one more line >> users $ cat users bgeorge pts/16 Oct 5 15:01 ( ) abakshi pts/7 Oct 10 22:56 ( ) abuzneid pts/9 Oct 10 19:29 (avicenna in-addr.arpa) xiafeng pts/20 Oct 10 22:11 (Shiva-RAS-Pool-53.uhmc.sunysb.edu) xiafeng pts/21 Oct 10 22:15 (Shiva-RAS-Pool-55.uhmc.sunysb.edu) xiafeng pts/10 Oct 10 23:16 (Shiva-RAS-Pool-13.uhmc.sunysb.edu) add one more line $ > users $ cat users $

Input Redirection Input of a file is redirected from a file command < infileget the input from the file infile Example: $ who > users $ wc -l users 15 users $ wc -l < users 15 $

Pipes Connects the output of one command to the input of another command Example: $ who | wc -l 14 $ ls | wc -l 8 $

Pipes (continue.) wc -l 5 who

Filters Any program that can take input from standard input, perform some operation on that input, and write the results to standard output Example: cat and sort are filters

Standard Errors Terminal is the standard error In most cases, you never know the difference between standard output and standard error command 2> efile directs the error to the file efile

Standard Errors (continue.) Examples: $ ls n* n*: No such file or directory $ ls n* > foo n*: No such file or directory $ ls 2> foo bbb Documents mail TEST users ddd foo personal test $ cat foo

References UNIX SHELLS BY EXAMPLE BY ELLIE QUIGLEY UNIX FOR PROGRAMMERS AND USERS BY G. GLASS AND K ABLES UNIX SHELL PROGRAMMING BY S. KOCHAN AND P. WOOD