Overview of the UNIX File System. Navigating and Viewing Directories

Similar documents
Overview of the UNIX File System

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

CSCI 2132 Software Development. Lecture 4: Files and Directories

5/8/2012. Creating and Changing Directories Chapter 7

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

UNIX Tutorial One

Commands are in black

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

1 Getting Started with Linux.

History. Terminology. Opening a Terminal. Introduction to the Unix command line GNOME

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

The Directory Structure

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Basic Survival UNIX.

Introduction to Unix: Fundamental Commands

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Chapter-3. Introduction to Unix: Fundamental Commands

Scripting Languages Course 1. Diana Trandabăț

Std: XI CHAPTER-3 LINUX

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

Linux basics U3A in Bath. Linux Principles. by Andy Pepperdine

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

CS197U: A Hands on Introduction to Unix

You will automatically be in your user (home) directory when you login.

5/20/2007. Touring Essential Programs

Introduction to the Linux Command Line

Getting your department account

1 Installation (briefly)

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

UNIX System Programming Lecture 3: BASH Programming

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

CS/CIS 249 SP18 - Intro to Information Security

Outline. Structure of a UNIX command

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

Session 1: Accessing MUGrid and Command Line Basics

Lecture 2: The file system

Introduction to Linux

Files and Directories

Introduction of Linux

Assignment 2, due September 17

Unix Tutorial Haverford Astronomy 2014/2015

Linux Systems Administration Getting Started with Linux

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

commandname flags arguments

Week 5 Lesson 5 02/28/18

Lab #0 Getting Started Due In Your Lab, August 25, 2004

Oxford University Computing Services. Getting Started with Unix

Practical Session 0 Introduction to Linux

A Brief Introduction to Unix

h/w m/c Kernel shell Application s/w user

CS4350 Unix Programming. Outline

Shell Programming Overview

Operating System Interaction via bash

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

UNIX File Hierarchy: Structure and Commands

Essential Linux Shell Commands

Introduction to Linux

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

Filesystem Hierarchy Operating systems I800 Edmund Laugasson

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Getting Started with Linux

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

Welcome to the Bash Workshop!

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

Getting Started. Logging In and Out. Adapted from Practical Unix and Programming Hunter College

Introduction to Linux

Linux for Beginners. Windows users should download putty or bitvise:

Computer Systems and Architecture

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Linux File System and Basic Commands

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

INF322 Operating Systems

Files

CHE3935. Lecture 1. Introduction to Linux

EECS2301. Lab 1 Winter 2016

Manage Directories and Files in Linux. Objectives. Understand the Filesystem Hierarchy Standard (FHS)

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Virtual Machine. Linux flavor : Debian. Everything (except slides) preinstalled for you.

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

INTRODUCTION TO LINUX

Filesystem Hierarchy and Permissions

CS Unix Tools. Lecture 2 Fall Hussam Abu-Libdeh based on slides by David Slater. September 10, 2010

Introduction to Unix

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

CENG 334 Computer Networks. Laboratory I Linux Tutorial

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

Linux Pathnames and Directories

Filesystem Hierarchy and Permissions

Introduction to Linux

22-Sep CSCI 2132 Software Development Lecture 8: Shells, Processes, and Job Control. Faculty of Computer Science, Dalhousie University

Introduction to UNIX command-line

CSE115 Lab exercises for week 1 of recitations Spring 2011

Operating Systems. Copyleft 2005, Binnur Kurt

Transcription:

Overview of the UNIX File System Navigating and Viewing Directories Copyright 2006 Stewart Weiss

The UNIX file system The most distinguishing characteristic of the UNIX file system is the nature of its files. In UNIX, everything is a file: directories (folders), devices (like keyboards, monitors, and printers), documents, programs, network connections, and even random access memory. By making everything a file, UNIX's designers simplified the operating system, making it easy to extend and maintain. 2 CSci 132 Practical UNIX with Perl

The UNIX file system hierarchy The UNIX file system is organized into a hierarchy whose top level is called the root ("/") directory. The root directory always has certain specific sub-directories, which in turn have specific sub-directories of their own. Below are some of the directories present in every UNIX system: / root bin etc sbin usr dev lib 3 CSci 132 Practical UNIX with Perl

The UNIX file system hierarchy Every directory is either empty, or it has other directories or non-directory files. This is a fragment of a fictitious file system: / bin etc home usr dev lib faculty gradstud bin share local stewart tbw asia man doc courses lib 4 CSci 132 Practical UNIX with Perl

Special directories The top level sub-directories keep UNIX organized. Some contain executable programs, some contain administrative files, some contain special library files, and others contain device drivers. Some contain important data. Every UNIX system uses these directories in the same way, no matter what "flavor" of UNIX it is. Ordinary users cannot modify any of the files in these special directories. Following are descriptions of a few of these directories. 5 CSci 132 Practical UNIX with Perl

The /bin subdirectory Originally UNIX was small enough that all programs could be placed into a single directory, /bin. Programs are executable files, consisting not of words and letters, but sequences of binary digits (i.e., bits), 0 and 1. They are called executables, because they are executed (run) by the computer. Executables are also called binaries. bin is short for binaries. In UNIX all words were abbreviated, to make it compact and faster. 6 CSci 132 Practical UNIX with Perl

The /etc subdirectory The /etc directory was created as a place to store configuration and administrative files. The type of stuff you'd find in a Windows registry or in the Mac's System folder is found in /etc. So much is stored in /etc these days that it has many subdirectories of its own. 7 CSci 132 Practical UNIX with Perl

The /dev subdirectory The /dev directory is a marvel to behold. It embodies the ingenuity of UNIX's creators. Every file in /dev represents some physical or logical device. Each actually contains a device driver; i.e., an executable program. The interesting part is that you never "run" these files. Instead you read from them or write to them as if they were ordinary text files. We will visit this directory in future lessons. 8 CSci 132 Practical UNIX with Perl

Other important top-level directories /usr /var /lib /tmp /boot /home /proc usually contains executables more administrative files library files temporary work space for programs start up files usually the top level of user home directories images of running programs 9 CSci 132 Practical UNIX with Perl

Identifying files by pathnames In UNIX, files are referred to by pathnames. A pathname specifies the location of the file in the file system by its position in the hierarchy. In UNIX, a forward slash "/" separates successive directory and file names in the pathname. This is the pathname from the root of the file system to the directory named courses in the directory named stewart in the directory named faculty in the directory named home: /home/faculty/stewart/courses 10 CSci 132 Practical UNIX with Perl

Absolute pathnames There are two kinds of pathnames: absolute pathnames, and relative pathnames. The absolute pathname is the unique name for the file that starts at the root of the file system. It always starts with a forward slash. The next slide illustrates. 11 CSci 132 Practical UNIX with Perl

Example of absolute pathname / bin etc home usr dev lib faculty gradstud bin share local stewart tbw asia man doc courses The absolute pathname of the courses directory is /home/faculty/stewart/courses 12 CSci 132 Practical UNIX with Perl

Your current working directory Whenever you are logged into a UNIX system, you have a unique, special directory called your current or present working directory (PWD for short). The present working directory is where you "are" in the file system at the moment, i.e., the directory that you feel like you are currently "in". UNIX keeps track of your PWD as you move about the file system. (We'll see how soon.) 13 CSci 132 Practical UNIX with Perl

Your current working directory (2) Many commands operate on the PWD if you do not give them an argument. We say that the PWD is their default argument. (Defaults are fall-backs what happens when you don't do something.) For example, when you enter the "ls" command (list files) without an argument, it displays the contents of your PWD. The dot "." is the name of the PWD: ls. and ls both display the files in the PWD. 14 CSci 132 Practical UNIX with Perl

Relative pathnames A relative pathname is a pathname to a file relative to the PWD. It never starts with a slash! When I login, my PWD is my home directory, /home/faculty/stewart. The relative pathname of courses is just courses or./courses. If I change my PWD (with the cd command) to /home/ faculty, the relative pathname of courses is stewart/courses (or./stewart/courses.) The pathname of courses relative to /home is faculty/stewart/courses. 15 CSci 132 Practical UNIX with Perl

The home directory When you first login, your present working directory is set to your home directory. Your home directory is a directory created for you by the system administrator. It is the top level of the part of the file system that belongs to you. You can create files and directories within your home directory, but usually nowhere else. Usually your home directory's name is the same as your username. 16 CSci 132 Practical UNIX with Perl

The home directory's names The home directory can be referred to by the tilde ~ (located above the backquote ` on the keyboard). For example, ls ~ means list the files in your home directory. Every user's home directory can be referenced using the form, ~username, where username is the person's login name, as in cd ~sweiss which is the same as cd ~ 17 CSci 132 Practical UNIX with Perl

What is a directory, anyway? How do directories "contain" files? A directory is a file with a specific structure: it is a table with as many rows as the number of files it contains. Each row represents a file and is called a directory entry. The entry has two parts: the name of the file and an index number that UNIX uses to find the file's contents on the disk: name of file index number UNIX uses to find file 18 CSci 132 Practical UNIX with Perl

Example Part of the root directory might look like this: / bin 120 usr 127 etc 63 dev 89 Notice that each name has a unique index number. The numbers above are fictitious. 19 CSci 132 Practical UNIX with Perl

Displaying the files in a directory In UNIX the ls command displays the files within a directory (like the dir command does in DOS.) For example, if a directory named stuff looked like this: pictures 120 letters 127 private 63 school 89 typing ls stuff would display letters pictures private school 20 CSci 132 Practical UNIX with Perl

Hidden files in UNIX A file is called a hidden file in UNIX if its name begins with a dot "." because the ls command by default does not display files whose names start with ".". You can request ls to display them by giving it the "-a" option. In the next slide the first use of ls display files whose names do not start with a dot. Then with -a it displays the ones that start with a dot. 21 CSci 132 Practical UNIX with Perl

How ls "hides" Files $ ls courses lib research temp $ $ ls a....bash_history.bash_profile.bashrc courses.dir_colors lib research $ 22 CSci 132 Practical UNIX with Perl

Why hide files? In Windows, user-specific data and customizations are kept in a central place, the Documents and Settings folder, and in the registry. All applications create files there. In UNIX, all user-specific data are kept in files in the user's home directory. These files are hidden because usually the user does not need to see them. Every shell creates a hidden file called something like.cshrc or.bashrc or.profile that stores your customizations of the shell. 23 CSci 132 Practical UNIX with Perl

Configuration files Many applications create hidden directories in your home directory, where they store many files related to how they are configured for you. Mozilla does this, for example. You will see directory named.mozilla in your home directory if firefox has been installed properly. SSH installs.ssh. In general, the files in these directories configure the application to work the way you like (sometimes.) 24 CSci 132 Practical UNIX with Perl

Two entries in every directory Did you notice that the example directory had two files named "." and ".."? (pronounced dot and dot-dot) Every directory has these two entries, even if it has no other files. Each of them is a directory. Dot is a shorthand name for the directory in which it occurs. It means "the current directory." 25 CSci 132 Practical UNIX with Perl

The. directory If my PWD is /home/faculty/stewart and I type ls./courses I will see the same files as if I typed ls courses Wherever I am in the file system, "." means "here". 26 CSci 132 Practical UNIX with Perl

The.. directory Dot-dot is a shorthand name for the parent directory. The parent directory is the one in which the directory is contained. It is the one that is one level up in the file hierarchy. If my PWD is currently /home/cs132/data, then../projects/project1 is the directory /home/projects/project1 and../../usr/share is the directory /usr/share. 27 CSci 132 Practical UNIX with Perl

More about.. entries You can use multiple.. references in a relative pathname. If my PWD is /usr/share/man/man1, then../man2 is /usr/share/man/man2 since.. is /usr/share/man, and../../../local is /usr/local since../.. is /usr/share and../../.. is /usr 28 CSci 132 Practical UNIX with Perl

Useful related commands: cd To change your PWD, use the cd command. $ cd.. changes the PWD to the parent directory $ cd / makes the PWD the root directory. The cd command with no argument $ cd changes your PWD to be your home directory 29 CSci 132 Practical UNIX with Perl

Useful related commands: pwd To display the absolute pathname of your PWD, use the pwd command. $ pwd /home/faculty/stewart Notice that pwd is a command but PWD is not. With pwd you can not get lost in the file system you always know where you are. 30 CSci 132 Practical UNIX with Perl

Creating directories: mkdir UNIX provides a single command to create a new directory: mkdir pronounced "make dir" which has a single argument: mkdir my_newdir will create a new directory named my_newdir in the PWD. Directory names can have almost any character in them, including spaces and newlines, but it is best to avoid using any characters other than letters, digits, and punctuation marks. 31 CSci 132 Practical UNIX with Perl

More about mkdir If you type a name but the directory already exists, mkdir will not replace it. It will warn you instead. mkdir can be given any pathname for an argument, either relative or absolute, and it will create the directory in the place you specify in the pathname. For example, mkdir /tmp/mydir will create the directory mydir in the /tmp directory. We will learn more about the mkdir command in Lesson 7. 32 CSci 132 Practical UNIX with Perl

Output redirection All commands in UNIX display their output, i.e., their results, on your terminal. You do not have to do anything special for this to happen. For example, when you type ls, it displays the list of files in your terminal window. UNIX provides a way to redirect that output to a file instead. (In fact, so does DOS, and the method is the same most likely because DOS borrowed this from UNIX when it was designed.) 33 CSci 132 Practical UNIX with Perl

The output redirection operator To force a command's standard output (the output ordinarily written to the screen) to be written into a file named gotcha, in the PWD you append the following to the end of the command: >./gotcha For example, $ last >./gotcha puts the output of last into a file named gotcha in the PWD. (Type last and see what it outputs.) In general, the form is $ command > filename 34 CSci 132 Practical UNIX with Perl

Creating files Using > It should be obvious that this is a convenient way to create small files, especially with the echo command. Assuming that the file file1 does not exist in the PWD, $ echo 'This is a test.' > file1 puts the text 'This is a test.' in file1 (without the quotes): $ cat file1 This is a test. $ 35 CSci 132 Practical UNIX with Perl

Your environment UNIX keeps track of your actions by saving various items of information about you in specially named variables called environment variables. A variable is just like a mathematical variable it is a symbol that can have a single value at any time. In UNIX, variables are named using ordinary words; environment variables are usually in all UPPERCASE. The collection of environment variables and their values is called your environment. 36 CSci 132 Practical UNIX with Perl

Viewing your environment There are several commands to display the current "state" of your environment. Without arguments, the safest to use are: env printenv 37 CSci 132 Practical UNIX with Perl

Using printenv The output of printenv may be many lines long and contain many variables whose purpose is unclear. Ignore them for now. Here is a fragment of what it could look like: USER=sweiss LOGNAME=sweiss HOME=/data/biocs/b/cshome/sweiss PWD=/data/biocs/b/cshome/sweiss SHELL=/bin/bash PATH=/bin:/usr/local/bin:/usr/bin: 38 CSci 132 Practical UNIX with Perl

Basic environment variables USER LOGNAME HOME PWD SHELL PATH User's username User's username also User's login (home) directory The present working directory The file name of the user's shell. A sequence of directories searched by shells and some other programs when you enter a command (and sometimes when you do other things too.) 39 CSci 132 Practical UNIX with Perl

Other ways to view variables When you put a '$' in front of any variable in a command, it replaces the variable by its value. ($ is called a substitution operator.) To see how this works, let me introduce a new command: echo. The echo command displays its argument on standard output: $ echo hello hello $ echo "hello to you." hello to you. $ 40 CSci 132 Practical UNIX with Perl

Echoing environment variables If you give echo an argument with the $ operator, it does the substitution first, and then it echoes: $ echo $HOME /data/biocs/b/cshome/sweiss So echo is another way to view the value of an environment variable. 41 CSci 132 Practical UNIX with Perl

Things to try Use the cd and pwd commands to explore the file hierarchy. Use printenv to see what the values of your environment variables are. Each time you change directory with cd, type printenv PWD Read the man page for the ls command and see what the -l,i,t, and m options do. 42 CSci 132 Practical UNIX with Perl