UNIX
File System
fdmgroup.com
Module objectives
After completing this module you will be able to:
• Describe the structure of a typical UNIX File System
• Navigate around a UNIX File System
• Manage files and directories within your home directory
• List attributes of a UNIX file
• Use wildcards to perform tasks on multiple files
• Explain how UNIX controls access to files and directories
fdmgroup.com
File System
File System
Files and Directories
Wildcards
Permissions
fdmgroup.com
File System
• Typical UNIX File System structure
/ - root
bin dev etc home usr
User1 – the home directory of
user 1 ~
User2
file1 file2 directory1
fdmgroup.com
File System
File System
Files and Directories
Wildcards
Permissions
fdmgroup.com
Files and Directories
• There are three types of files
Regular files
• Contain data, text or program instructions
Directories
• Stores special and regular files
Special files
• Provide access to hardware. For example printers, hard
disks and other devices
fdmgroup.com
Files and Directories
• Directories
Home Directory ~
• holds users files
/home/judy.marshall
Current Directory - current location
• can be displayed using pwd
• can be referenced by . in commands
Parent Directory - directory above the current directory
• can be referenced by .. in commands
fdmgroup.com
Files and Directories
• Absolute and relative paths
Absolute path
• specifies the path of a file or directory regardless of the
current location
/var/log/mail
Relative path
• specifies the path of a file or directory which is relative to
the current location
statistics
./statistics
../mail/statistics
fdmgroup.com
Files and Directories
• Directories
ls /var or ls –l /var/mail or tree /var/tmp
mkdir dirname or mkdir dir2 dir3
mkdir -p dira/dirb
cd dirname or cd .. or cd ~
rmdir dirname (empty directories only)
rm -r dir2
fdmgroup.com
Files and Directories
• Files
touch filename
cat /etc/passwd
more /etc/passwd or less /etc/passwd
head /etc/passwd or tail /etc/passwd
fdmgroup.com
Files and Directories
• Files
cp filename newfilename
mv salesFile dir3/2019Sales
mv file1 file2 file3 dira
rm filename
wc /etc/passwd
file /etc/passwd or file /bin/ls
fdmgroup.com
Files and Directories
• All Files including hidden files
ls -a
• Reverse order
ls -r
• Recursive list
ls -R
fdmgroup.com
Files and Directories
• Files - inode
ls –i
inode holds information on files such as:
• User and group ownership
• File size
• Access mode (read, write and execute)
• Access times
• Position on disk
• Type of file (regular files, directories)
• Files – long format
ls –l
fdmgroup.com
Files and Directories
• inode and Long format
ls –il /examples
User
Group Name
Size
411365 drwxrwxr-x 2 root root 4096 Mar 4 2013 dir1
411369 -rwxrwxr-x 1 root root 385 Mar 4 2013 englishMonarchs
393238 -rw-r--r-- 1 root root 123 Mar 8 2013 file1
411364 -rwxrwxr-x 1 root root 428 Mar 4 2013 lionsInTheStreet
393236 lrwxrwxrwx 1 root root 5 Mar 8 2013 lname -> file1
411368 -rw-r--r-- 2 root root 112 Mar 8 2013 name1
411368 -rw-r--r-- 2 root root 112 Mar 8 2013 name2
Hard Links Symbolic Link
inode Number Date last modified
fdmgroup.com
File System
File System
Files and Directories
Wildcards
Permissions
fdmgroup.com
Wildcards (Globbing)
• What is globbing?
• Globbing refers to file and directory pattern expansion
• The shell will interpret wildcards and expand them with
matching files before running the command
• Useful to perform a command on several files with similar
names
fdmgroup.com
Wildcards (Globbing)
• Metacharacters in globbing
* Match zero or more characters
? Match one character
[] Match anything in the [ ] for 1 character position
[a-e] The – is a range separator. This will match a to e
[!0-9] ! = negate. This will match anything except 0 to 9
\ Escape the metacharacter and treat them as a literal
ls .*rc or wc /etc/pa*
ls /dev/tty[0-9] or ls /dev/tty*[0-9]
fdmgroup.com
File System
File System
Files and Directories
Wildcards
Permissions
fdmgroup.com
Permissions
• Every file in UNIX has access permissions
Read - r
• read, print and copy
Write - w
• write
Execute - x
• executes files or change into a directory
fdmgroup.com
Permissions
• Permissions are defined for three types of users
User – owner of the file
Group – users in the same group
Other – the rest of the world
fdmgroup.com
Permissions
• Permissions are defined for three types of users
ls -l
drwxr-xr-x 2 trainee users 4096 2011-10-25 12:38 dir3
drwxr-xr-x file type: (d) means directory
dash (-)
means regular file
file t
drwxr-xr-x user (owner) permissions
drwxr-xr-x group permissions
drwxr-xr-x others permissions
A dash (-) means no permission for that function
fdmgroup.com
Permissions
• There are two ways of changing permissions
• Symbolic or Octal mode
• Both use the chmod command Reference Meaning
u Owner
g Group
o Other
a all
chmod u+x dir3/filename
chmod o-r dir3
fdmgroup.com
Permissions
Octal Text Meaning
• There are two ways of changing permissions 4 r Read
• Symbolic or Octal mode
2 w Write
• Both use the chmod command
1 x Execute
0 No
Permissions
6 rw- Read and
(4+2) write
chmod 751 dir3/filename
chmod 750 dir3
fdmgroup.com
Questions?
fdmgroup.com
Module objectives
Now you completed this module you should be able to:
• Describe the structure of a typical UNIX File System
• Navigate around a UNIX File System
• Manage files and directories within your home directory
• List 4 attributes of a UNIX file
• Explain how UNIX controls access to files and directories
• Use wildcards to perform tasks on multiple files
fdmgroup.com