Unix File System
Unix File System
File System
Unix Overview
1
File System
The file system has the following qualities:
• Made for power and flexibility
• Navigation is cryptic
• Single root directory
– The root directory is designated /
• Everything in Unix is a file
File System
Directories are special files:
• Hold names of files or directories
• Looks like a hierarchical tree
• Similar to DOS
• Unix uses forward slashes (/)
• DOS uses backslashes (\)
Unix Overview
2
Unix File System
File Attributes
File Attributes
File Name:
• String of characters
• No relevance to periods or other
characters
• Some programs can expect specific
type of file names
– Compilers can expect file extensions
Unix Overview
3
File Attributes
File Path:
• Full path specifies all directories
-> /usr/aci/class02/temp
• Filename used when in current
directory
File Attributes
/
“/” represents the root directory
aci
class02
tempfile
/aci/class02/tempfile
Unix Overview
4
File Attributes
File Permissions:
• Each file has permissions for owner,
group, and others access
• Read, write, and execute are the
permissions
• Permissions can be set different for
owner, group, and others usage
• Permissions apply to directories as well
as files
Unix File System
File Types
Unix Overview
5
File Types
Unix has four file types:
• Ordinary files
• Directory
• Device
• Link
File Types
Ordinary files:
• Text files - ASCI
-> program source code
• Binary files
-> Compiled objects
• Hidden files – profiles or configuration
files
-> Begin with a period
-> Are not displayed when listing files
unless the “all” option is used
Unix Overview
6
File Types
Directory files:
• A directory is considered to be a file
since it also contains information
about its contents, such as file names,
file sizes, and last modification time
File Types
Device files:
• Physical devices are represented as
files the same read() and write()
functions that work on files also work
on devices
Unix Overview
7
File Types
Link files:
• A link file is an alias to an existing file
• Both names use the same physical file
• If the link is removed, the file still
exists
• If the file name is removed with a link
to it, the file remains but uses the link
name
File Types
Example of file types
Unix Overview
8
Unix File System
Working With Directories
Working With Directories
Know where you are to work effectively!
• To change directories
• To manipulate files
• To run processes
Know the directory you are in!!!
Unix Overview
9
Working With Directories
Unix has a command to identify the
current working directory.
• Print Working Directory
– pwd
Working With Directories
pwd Command
Unix Overview
10
Working With Directories
Two other useful commands to know:
• clear
-> clears the screen
• history
-> Displays a list of previous commands
Working With Directories
history Command
Unix Overview
11
Working With Directories
Before clear Command exectues
Working With Directories
After clear Command exectues
Unix Overview
12
Working With Directories
Common Directory Commands:
• Make a directory
-> mkdir <directory name>
• Remove a directory
-> rmdir <directory name>
• Change directories
-> cd <options>
Working With Directories
• When making or removing directories,
remember that Unix is case sensitive.
• However the directory name is typed
will be the only way to reference the
directory name correctly!
Unix Overview
13
Working With Directories
The following commands,
mkdir sourceCode
rmdir SourceCode
are accessing different directories since
the spelling contains different upper
and lower case letters
Working With Directories
•
Unix Overview
When using the mkdir command, the
file created will have the owner’s
permissions
14
Working With Directories
•
When using the rmdir command, the
write permissions must be set
accordingly to allow the removal of
the file and the directory must be
empty:
– rmdir emptyDirectoryName
Working With Directories
•
To remove a directory that is not
empty use the rm command with the
-r command:
– rm –r directoryName
Unix Overview
15
Working With Directories
The change directory command has a
number of variations:
• cd
• cd /directory name/directory name/…
• cd ..
• cd ./directory name/directory name/…
Working With Directories
• Every Unix user should be assigned a
home directory where the user is
place upon completion of logon
• The cd command by itself will return
the user to their home directory
Unix Overview
16
Working With Directories
cd
Working With Directories
• To change from one directory to another
directory, the change directory
command can be used with a complete
directory path starting at the root
directory ( / )
Unix Overview
17
Working With Directories
cd /directory name/ …
Working With Directories
• To return to the previous directory use
the change directory command and
two periods
• Separate change directory command
and the two periods with a space
Unix Overview
18
Working With Directories
cd ..
Working With Directories
• To change from one directory to another
that is more than one directory from the
current directory, use the change
directory command with the current
directory option ( ./)
cd ./next directory/next directory/…
Unix Overview
19
Working With Directories
To display the contents of a directory
use the list command. Depending on
what information you wish to display will
determine what options to include
• List contents of a directory command
– ls <options>
• Options are included by using a space
and a hyphen followed by the list of
options
Working With Directories
The list command has a number of options:
• No options returns a file list
• -a -> include all files (hidden files too)
• -l -> see file information
• -r -> list in reverse order
• -t -> sort by modification
Unix Overview
20
Working With Directories
When using ls –l option, the file information is
read from right to left and includes:
• The file name
• The last modification date and time
• The file size in bytes
• The group of the file owner
• The owner of the file
• The number of links to the file
• The file permissions
Working With Directories
Examples of the ls command
Unix Overview
21
Working With Directories
Examples of the ls command
Unix File System
File Permissions
Unix Overview
22
File Permissions
• Unix has several users and groups
• A user can belong to multiple groups, but
•
•
can be active in only a single group at a
time
Users are assigned a primary group and
can assume the privileges of secondary
groups
Files have user, group, and others
permissions
File Permissions
File permissions are defined for
three levels of access:
• u -> owner/user
• g -> group
• o -> others
When changing permissions by
groups to the same setting, you
can use the all group level:
• a -> all
Unix Overview
23
File Permissions
File permissions define what actions
may be taken on a file in Unix:
• r -> Read
• w -> Write
• x -> Execute
File Permissions
• Read permissions control whether
•
•
Unix Overview
someone can view a file
Write permissions allows or disallows
changes to be made to a file such as
update or delete
Execute permissions control whether
a file can be run
24
File Permissions
The permissions on a file are displayed when
a long list command (ls -l) is performed.
The right-most 10 characters displayed:
• Positon 1 is the file type
• Postions 2-4 are the owner permissions
• Postions 5-7 are the group permissions
• Postions 8-10 are the others permissions
File Permissions
051o:/db01/pmdev/r051o>ls
total 240
drwxrwxr-x
3 pmdev
drwxrwxr-x
3 pmdev
drwxrwxr-x
3 pmdev
drwxrwxr-x
3 pmdev
drwxrwxr-x
4 pmdev
drwxrwxr-x
3 pmdev
drwxrwxr-x
2 pmdev
drwxrwxr-x
2 pmdev
drwxr-xr-x
2 pmdev
drwxr-xr-x 10 pmdev
-rw-r--r-1 pmdev
•
•
•
•
Unix Overview
File Type
User Permissions
Group Permissions
World Permissions
-lrt
pmdev
pmdev
pmdev
pmdev
pmdev
pmdev
pmdev
pmdev
pmdev
pmdev
pmdev
96
96
96
96
96
96
16384
8192
8192
8192
45
Column
Columns
Columns
Columns
May
May
May
May
May
May
May
May
May
Jun
Jun
4
4
4
4
4
4
9
13
19
22
27
2005
2005
2005
2005
2005
2005
2005
2005
2005
2005
2005
fh
hm
ip
mc
sz
vs
dcllib
testdata
script
PMJournalFeed
afiedt.buf
1
2-4
5-7
8-10
25