Week 4 File and Directories in A UNIX System Lecture
Week 4 File and Directories in A UNIX System Lecture
Permission commands
FIND COMMAND
4
Allows you to find files and directories in a directory
hierarchy and perform subsequent operations on
them.
Syntax: $ find [pathname] [-name filename]
Example
Search for a file by pattern
$ find /home -name "*.txt"
Search for a file by specific name
$ find /home -name file.txt
SORT COMMAND
5
sorts lines contained in a group of files alphabetically
Syntax: $ sort [options] [filenames]
EXAMPLE
Example: $ wc food.txt
4 8 53
food.txt
Apple orange
Grapes banana
Pears plum
Cherries lemon
CUT COMMAND
10
Option Description
-c char_list Extract the portion of the line defined by char_list.
The list may consist of one or more comma-separated
numerical ranges.
-f field_list Extract one or more fields from the line as defined by
field_list. The list may contain one or more fields or
field ranges separated by commas.
-d delim_char When -f is specified, use delim_char as the field
delimiting character. By default, fields must be
separated by a single tab character.
--complement Extract the entire line of text, except for those
portions
specified by -c and/or -f.
CUT COMMAND: EXAMPLE
12
$ > foo.txt
$ ls -l
foo.txt
EXPLAINED
23
d A directory.
l A symbolic link. Notice that with symbolic links, the remaining file
attributes are always rwxrwxrwx and are dummy values. The real
file attributes are those of the file the symbolic link points to.
b A block special file. This file type refers to a device that handles
data in blocks, such as a hard drive or CD-ROM drive.
TYPES OF FILES - PERMISSION
We can use ls –l command to know the type of the file
Example1: ls –l /dev/ram
lrwxrwxrwx 1 root root 4 Mar 22 2020 /dev/ram -> ram1
symbolic link.
Example 2: ls –l /dev/tty
crw-rw-rw- 1 root tty 5, 0 Jan 24 11:29 /dev/tty
b or c indicates a device file
Example 4: ls –l filename
-rw------- 1 n01547728 staff 0 Jan 26 16:18 week3
- indicates a regular file
PERMISSIONS EXPLAINED
24
…
CHMOD COMMAND
(CONT’D)
25
Permission Mapping
Octal Binary File Mode
0 000 ---
1 001 --x
2 010 -w-
3 011 -wx
4 100 r--
5 101 r-x
6 110 rw-
7 111 rwx
CHMOD COMMAND
(CONT’D)
26
Example: