Title: Directory Commands
1Chapter 4
2Overview
-
- The disk partitioning scheme will be explained
- Will learn to manage files in the GUI (using the
Nautilus file manager) and from the command line
3Overview
-
- Will learn how to create, change, rename, and
eliminate directories - Will learn how to navigate in the directory
structure using cd and dat addressing techniques
4Overview
-
- The power of and danger of removing directories
recursively will be discussed - Will view and manipulate environmental variables
5Hierarchical Filing System or Tree-structured
Directories
- Directories and subdirectories are the means of
locating and logically grouping files
6Hierarchical Filing System or Tree-structured
Directories
- The hard disks major purpose is to store and
retrieve data
7Hierarchical Filing System or Tree-structured
Directories
- A disk is divided into partitions
- Each partition
- accessed as if it were a separate disk
- must have a file system installed on it
8Hierarchical Filing System or Tree-structured
Directories Figure 4.1 Total Disk Space p. 177
9Hierarchical Filing System or Tree-structured
Directories
- Partition table states
- Where partition begins and ends
- Whether partition is/is not active
- Partition type
10Hierarchical Filing System or Tree-structured
DirectoriesFigure 4.2 Typical Computer with
Windows p. 177
11Hierarchical Filing System or Tree-structured
Directories Figure 4.3 Dual Booting System p.
178
12Hierarchical Filing System or Tree-structured
DirectoriesTable 4.1 Linux Partition-naming
Scheme p. 178
13Hierarchical Filing System or Tree-structured
Directories
- Each physical disk divided into a maximum of
four primary partitions - One partition type may be set to be extended
(extended partition)
14Hierarchical Filing System or Tree-structured
DirectoriesFig 4.4 Windows Linux Using
Extended Partition p. 179
15Hierarchical Filing System or Tree-structured
Directories
- In Linux
- Partitions identified by device names
- Peripheral devices are also named
16Hierarchical Filing System or Tree-structured
Directories
- Each partition forms part of storage necessary to
support a single set of files and directories
17Hierarchical Filing System or Tree-structured
Directories
- Associate partition with a directory through
mounting - Mount partition, make files and directories
available starting at mount point
18Hierarchical Filing System or Tree-structured
Directories
- Linux provides a single hierarchy for all
directories that includes every mounted partition
and mounted peripheral device
19Hierarchical Filing System or Tree-structured
DirectoriesFigure 4.5 A Directory is Like a
Family Tree p. 180
20Hierarchical Filing System or Tree-structured
DirectoriesFigure 4.6 Hierarchical Structure of
a Directory p. 180
21Hierarchical Filing System or Tree-structured
DirectoriesFigure 4.7 Directories as Rooms p. 181
22Hierarchical Filing System or Tree-structured
DirectoriesFigure 4.8 Files in Subdirectories p.
182
23Managing Files and Directories
- Organization and structure of a disk is dependent
on the file system used by the operating system
24Viewing Files and Directories
- Can view files/directories in various sequences
25Activity Viewing Files and Directories
- KEY CONCEPTS
- Can sort files using Nautilus or command line
- Files sorted by name, size, type., modification
date, emblem, ascending/descending order - typenot sorting by extension but by Type of
name given to file - -X used by ls to sort in file extension order
- Can combine two options
- -r is reverse order
- Defined terms emblem and links
-
26Creating Directories
- Subdirectory
- Setting up storage area for files
- Need write permission in parent directory
- Can be created using
- Nautilus File Manager
- mkdir command at command line
- Syntax mkdir options directoryname
27Creating DirectoriesTable 4.2 mkdir Options p.
188
28Activity How to Create Directories
- KEY CONCEPTS
- Nautilus is GUI file manager
- Typing replaces selection
- File menuwhere new folder created
- Uppercase letters come before lowercase
- Linux retains case chosen
- Can create directory from terminal window
- Can identify directories
29Activity How to Create Directories
- KEY CONCEPTS
- ls command
- displays contents (directories) of disk
- Directories are in a different color
- Syntaxls OPTIONFILE
- On same line separate commands with a semicolon
- Every directory (except root always has two
names directories (dot and double dot)
30The Current Directory
- The current/default directory
- Is kept track of by the operating system
- Can be changed
31The Current Directory
- Purpose of the cd command
- Return to home directory
- cd with no parameters
- Change default directory
- Syntax is cd dir
32Activity Changing Directories
- KEY CONCEPTS
- Determined which directory was the
current/default directory - Prompt displays current directorynot the entire
path name - When a command is used it always assumes the
default directory unless another drive and/or
subdirectory is specified
33Building a Structure
- Create additional subdirectories using
- Nautilus File Manager
- mkdir command in terminal window
- Directory structure built from top down
34Building a Structure
- mkdir command
- Allows creation of structure with a single
command - -p option used to create parent directories
- Syntax mkdir optionsdirectory
35Building a Structure
- Absolute path
- Complete hierarchical structure
- Always correct
- Relative path
- Location relative to where you are
36Building a StructureFigure 4.9 Directory with
Subdirectories p.194
37Activity Creating More Subdirectories
- KEY CONCEPTS
- Created directories using
- absolute pathalways correct
- relative pathrelative to where you are
- First / is root directory
- Every other slash is a delimiter
- Compared the following two commands
- mkdir /mexicomkdir /floppy/mexico
- mkdir ../mexicols
- At command line can create intervening parent
directories if they do not exist (use -p)
38The dot (.) and double-dot (..)Dot Addressing
- Dot Addressing is method of using dots to
refer to directories - Single dot (.)
- Specific name of current directory
- Double dot (..)
- Specific name of parent directory of current
directory - No spaces between dots
39The dot (.) and double-dot (..)Dot Addressing
- Can use .. as shorthand version of parent
directory name to move up the directory tree - Cannot use .. as a shortcut symbol to move down
the hierarchy
40Activity Using the Double-dot
- KEY CONCEPTS
- Using the up arrow is equivalent to using dot
dot in the Nautilus file manager - Reviewed when and why you use the relative path,
the absolute path - Used dot addressing techniques
41Changing the Names of Directories
- Can change the names of directories
- In Nautilus file manager
- At the command line
- Syntax mv option source test
42Changing the Names of DirectoriesTable 4.3 mv
Options p. 202
43Activity Renaming Directories
- KEY CONCEPTS
- A directory is also a file
- Typing replaces selection
- May rename a file with the right-click menu
44Removing Directories
- Removing directories accomplished
- Using the Nautilus file manager
- At the command linetwo step process
- rm command to remove files
- rmdir command to remove empty directories
- Note Can remove directories only if they are
empty and contain no hidden/or system files
45Removing Directories
- rmdir command
- Cannot be used with wildcards
- Default path used if path designator not
included - Syntax rmdir options directories
46Removing Directories
- When using Nautilus file manager or rmdir
cannot remove - Directory you are currently in (default)
- Root directory
47Removing DirectoriesTable 4.4 rmdir Options p.
204
48Activity Removing Directories
- KEY CONCEPTS
- Until trash is emptied can recover what
files/folders are in the trash - Cannot remove a directory you are in nor can you
remove the default directory - Create directory from top-down
- Remove directories from bottom up
49Removing Directories Recursively-Using rm rmdir
- Can remove directories recursively
- Using Nautilus file manager
- Using rm and rmdir at the command line
50Removing Directories Recursively-Using rm rmdir
- At command line
- Can delete directory structure only if
directories are empty of files - rmdir -p deletes empty parent directories
51Removing Directories Recursively-Using rm rmdir
- At command line
- rm used to remove files in parent directories
- Syntax rmoptions files
- -r (recursive) option
- If file is name of directory will remove entire
directory structure and all its contents - Useful but dangerous (very fast)
- -f optionwill delete even read-only files
without prompting
52Removing Directories RecursivelyUsing rm
rmdirTable 4.5 rm Options p. 207
53Activity Removing Directories
- KEY CONCEPTS
- Used -v option to see what is occurring
- Used - p option to delete directory and its
parent - Used -r option to remove directory tree
(remember this option is fast and dangerous) - Used -f option which forces deletion
54 Variables
- Can recognize default directory
- Operating system in a terminal window displays
current location in the prompt - Bash shell give information by use of
environmental variables
55 Variables
- Variables
- Value that can change with conditions or
information passed to the program - Symbol/name used to represent a value
- Shell variables
- Controls functionality of the shell
- Created at command line or in shell script
56 Variables
- Shell Script
- Text file containing sequence of commands
- Provides ease in transferring values from one
command to another - Shell has ability to store data
- Takes form of two strings
- Name of variable
- Value of variable
57 Variables
- Environmental variables
- Name (UPPERCASE) assigned to string (value) of
data - displays contents rather than name
- Examples
- HOME
- PATH
- PS1
58 The PROMPT Variable
- Configuration of prompt determines how prompt
looks. - Environmental variables (PS1 and PS2) contain
text displayed in terminal window
59 The PROMPT Variable
- Environmental variable has special characters
- Will return a specified value
- Preceded by a \ and followed by a character
indicating what is to be displayed
60 The PROMPT VariableTable 4.6 Formatting
Characters for Prompt p. 211
61 The PROMPT VariableTable 4.6 Formatting
Characters for Prompt p. 211
62 The PROMPT Variable
- The default Red Hat prompt is \u_at_h \W
63Activity Changing the Prompt
- KEY CONCEPTS
- printenv command prints all or part of what is
in the environment - set command
- With no arguments/options prints all values of
all variable known to the shell - Options can be enabled/disabled
- To display value of any environmental variable
use echo, the dollar sign, and then variable name
64Activity Changing the Prompt
- KEY CONCEPTS
- Compared \w with \W
- (tilde)
- Shorthand for directory or currently logged in
user - Can be used as shorthand for home directory
65Activity Changing the PromptTable 4.7 Red Hat
Linux/Bash Configuration Files p. 214
66Understanding the PATH Variable
- Executable files (commands) stored in
directories. - Common Linux/Unix command directories
- /bin
- /usr/bin
67Understanding the PATH Variable
- PATH variable specifies directories to search
and order in which to search for a commandan
executable program - Colons separate directories in the PATH
- Operating system executes the first program
match found in the path
68Activity Using the PATH Variable
- KEY CONCEPTS
- For each command keyed in directories searched
will be ones listed in order from left to right - Delimiter used to separate one directory name
from another is the colon - Can add permanent directory to search path by
changing configuration file - Can add a temporary directory to search path
lasts only as long as you are in a work session
69Understanding the CDPATH Variable
- CDPATH
- List of directories separated by colons
- Set by user
- Allows shell search without entering entire path
name - Lasts until terminal session ends
70Activity Using the CDPATH Variable
- KEY CONCEPTS
- Set search path for directories
- (tilde)shorthand notation for home directory
- Colon used to separate directories
- Values for CDPATH lasts until terminal session
ends