Professional Documents
Culture Documents
Lecture Objectives
After this lecture, students should be able to:
identify the Linux file system, execute basic file system commands, and give permission to Linux file system.
PART I
Working with Linux Files
Linux Files
File
a collection of data a stream of characters or a "byte stream" no structure is imposed on a file by the operating system
Socket files are created when communication to a process on another machine located on a network is required.
Special Files - provide access to hardware such as hard drives, CD/DVD-ROM drives, modems, and Ethernet adapters. Other are similar to aliases or shortcuts and enables to access a single file using different names. e.g. .profile, /dev, /dev/sda
Linux Filenames
Some important facts about Linux filenames:
Should be descriptive of the content (readable) Should only use alphanumeric characters (uppercase, lowercase, number, @, _ ) Should not include embedded blanks Should not contain shell metacharacters: * ? > < / ; & ! [ ] | \ ' " ( ){} Should not begin with + or - sign Case sensitive (uppercase is different from lowercase letters) Filenames starting with a . are hidden files Maximum number of characters for a filename is 255
Linux Pathnames
Full Pathnames
A pathnames that starts from / or /root (the root directory)
Relative Pathnames
A pathnames that starts from the present working directory
Linux Pathnames
Listing Files
ls - list the files and directories stored in the current directory.
With the ls command: $ ls dir/file $ ls /home tux1 tux2 tux3 Important options
-l -a -t -R -F lists - long listing (more information) - lists all files (including hidden) - lists files sorted by change date - lists contents recursively - appends a character indicating the file type of each of the items it
Creating Directories
With the mkdir (make directory) command: $ mkdir dirname
$ mkdir /home/tux1/doc (full pathname) $ cd /home/tux1 $ mkdir doc (relative pathname)
Removing Directories
With the rmdir (remove directory) command: $ rmdir dirname
$ pwd /home/tux1 $ rmdir doc test rmdir: doc: Directory not empty
Copying Files
cp command copies files: cp source/s target
Copying one file to another:
$ cp .bashrc bashrc.old
Copying Files
cp can recursively copy directories with the -R flag $ cp -R /home/tux1/doc /tmp To prevent cp from overwriting existing files, use:
$ cp -R -i /home/tux1/doc /tmp cp: overwrite `/tmp/doc/walrus?
With the strings command: $ strings /usr/bin/passwd /lib/ld.so.1 __gmon_start__ __deregister_frame_info __register_frame_info
Removing Files
With the rm command: $ rm filename $ ls test/rob ls: rob: No such file or directory If unsure, use -i option $ rm -i test/rob rm: remove `test/rob? To remove files and directories recursively: $ rm -ir test
Splitting Files
You can split a file into smaller files with the split command $ split -b <bytes> file [prefix]
$ ls -l -rw-r--r-- 1 root root 4194304 Feb 21 13:31 large $ split -b 1024k large large. $ ls -l -rw-r--r--rw-r--r--rw-r--r--rw-r--r--rw-r--r--
1 1 1 1 1
21 21 21 21 21
PART II
Linux File Permissions
File Permission
Linux files are setup so access to them is controlled. There are three types of access:
read (r) write (w) execute (x)
Each file belongs to a specific user (u) and group (g). Access to the files is controlled by user, group, and what is called other(o). The term, other, is used to refer to someone who is not the user (owner) of the file, nor is the person a member of the group the file belongs to.
File Permission
Setting permissions for "other" users to use, it is commonly referred to as setting the world execute (x), read (r), or write (w) bit since anyone in the world will be able to perform the operation if the permission is set in the other category.
Table 3. Action
umask Command
New files should not be created with 666, to avoid this problem a permission mask exists.
Syntax: $ umask 022
When the execute bit for the group is set to "s", the set group ID bit is set and the user running the program is given access based on access permission for the group the file belongs to.
The listing below shows a listing of two files that have the group or user ID bit set.
-rws--x--x -rwxr-sr-x 1 root 1 root root mail 14024 Sep 9 1999 chfn 12072 Aug 16 1999 lockfile
Note: The files chfn and lockfile are located in the directory "/usr/bin".