0% found this document useful (0 votes)
2 views

L10_file System and Related Commands

The document provides an overview of the UNIX file system, detailing its hierarchical structure starting from the root directory and the types of files it contains, such as ordinary, directory, and device files. It explains various Linux file management commands for navigating, creating, copying, moving, and deleting files and directories, as well as managing file permissions using commands like chmod and chown. Additionally, it covers file attributes, compression methods, and the importance of file permissions in maintaining system security.

Uploaded by

realkaran07
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

L10_file System and Related Commands

The document provides an overview of the UNIX file system, detailing its hierarchical structure starting from the root directory and the types of files it contains, such as ordinary, directory, and device files. It explains various Linux file management commands for navigating, creating, copying, moving, and deleting files and directories, as well as managing file permissions using commands like chmod and chown. Additionally, it covers file attributes, compression methods, and the importance of file permissions in maintaining system security.

Uploaded by

realkaran07
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

FILE SYSTEM

• UNIX File System in general


• File system is organized in tree structure.
• File tree can be arbitrarily deep.
• File name must NOT LONGER than 256 chars.
• File system is organized as a hierarchy of directories
• It starts from a single directory called root(represented by a /).

/(root)

----------------------------------------------------------------------------------------------------------------

| | | | | |

/bin /dev /home /etc /lib /tmp /sbin /usr /var


TYPES OF FILES
 Ordinary files or regular files: : contain data as stream of characters.
 binary
• GIF, JPEG, Executable etc.
 text
• scripts, program source code, documentation
 Supports sequential and random access
 Directory Files: contain names of other files and directories. Contain 2 fields for each
file: name and identification no( inode no)
 Device File: represent all hardware devices.
• Allows programs to communicate with hardware.
LINUX FILE MANAGEMENT AND VIEWING
pwd
• Displays personal working directory, i.e.
• your current directory.
• % pwd
/home/user1
 Here is pathname a sequence of directory names separated by slashes
LINUX FILE MANAGEMENT AND VIEWING(CONT.)
• There are 2 ways for accessing any file from our current directory:
1. Absolute pathname: which uses the root directory as ultimate reference for the file.
2. Relative pathnames: which uses the current directory as point of reference and

specifies the path relative to it


The absolute path to the directory named "jon" would be:
/users/admin/jon

The relative path from the directory named "student" to the directory named "jon" in the tree
diagram would be:
../admin/jon
LINUX FILE MANAGEMENT AND VIEWING(CONT.)
cd – will change the working directory
– ex. cd no argument – return to home directory
– ex. cd .. return you up 1 level
– ex. cd / will bring you to the root level
– ex. cd ../../../../lookout/a/fred/c changes directory to specified path
Example:
$ pwd
/home/user1
$ cd progs progs must be in present dir
/home/user1/progs
Or specify full path using absolute pathname and if dir is not in present dir then specify
absolute path
LINUX FILE MANAGEMENT AND VIEWING(CONT.)
Mkdir
• Creates a directory.
• % mkdir newdir
• We can create any no of dirs using this cmd or we can create even dir tree using this cmd
eg : mkdir pis pis/progs pis/data
• But it also possible that system refuses to create a new dir. reasons for this are:
1) dir by that name already exist
2) there may be an ordinary file by that name in current dir
3) permission set for that dir don’t permit creation of files and dir by user
LINUX FILE MANAGEMENT AND VIEWING(CONT.)
rmdir
• Removes a directory.
• % rmdir dirname
• Equivalent:
– % rm -r dirname
• When deleting dir keep in mind following points
1) we can’t del any dir unless its not empty
2) we can’t del a dir unless we are there in that dir
e g: $ cd progs
$ pwd:/home/user1/pis/progs
$ rmdir . This is wrong
 $ cd..
 $ pwd : /home/user1/pis
 $ rmdir progs : cmd successful
LINUX FILE MANAGEMENT AND VIEWING(CONT.)
 Cp command
• Copies files / directories.
• % cp [options] <source> <destination>
• % cp file1 file2
• % cp file1 [file2] … /directory
• Useful option: -i to prevent overwriting existing files and prompt the user to confirm
LINUX FILE MANAGEMENT AND VIEWING(CONT.)
 rm – removes file/s in pwd
– ex. rm ch1 will remove file ch1 in pwd
– ex. rm ch* will remove any file beginning with ch in pwd
– ex. rm * will remove all files in pwd
• We can del more than 1 file with single command
• $ rm chap01 chap02 chap03
• Using –i we can make this interactive
chap01?y
chap02?n
chap03?n
MV COMMAND
• Moves or renames files/directories.
• % mv <source> <destination>
– The <source> gets removed
• % mv file1 dir/
• % mv file1 file2
– rename
• % mv file1 file2 dir/
TOUCH CMD
• By touching a file you either create it if it did not exists (with 0 length).
• Or you update it’s last modification and access times.
• There are options to override the default behaviour.
• % touch file
• When touch is used without options both time set to current time
COMPRESSION OF FILES
• Compress and gzip work with multiple files and remove original one after compression
• Zip has also original one
• Degree of compression depends upon the type of file we use
• To compress all files in present dir we use compress *
• When use compress then decompressed using uncompress filename
• A compressed gzip file has extension .gz
• Decompressed by gunzip eg
• gzip sale1 compressed to sale1.gz
• gunzip sale1.gz
• Unzip is used to decompress a file compressed by zip
FILE ATTRIBUTES
• For listing file attributes we use cmd $ ls –l
total no of blocks(block size 512 or 1024 byte)
-rw-r--r-- 1 henry metal 19514 may 08 11:11 chap01
-rwxrw-r-- 2 steve metal 4174 may 11 10:30 chap02
-rw-r--rw- 1 steve metal 9156 may 12 11:10 progs

permissions links owner Grup size Last modify filename


ownr time
FILE ATTRIBUTES(CONT.)
• St of file’s permissions string

- r w x r w - r - -

Type of file Owner permission Group permission Other’s permission

Type of file may be ordinary, device or directory. For example For ordinary file
here will be – at first col. For directory files there will be d
FILE PERMISSIONS
 File permission are part of Linux security system
 Protect the system resource from users
 Against malicious or unintentional error
 Protect each user from others
 Permission
 Reading a file
 Writing a file
 Executing a file
 Three user categories
 The file’s owner
 The file’s group
 All other users
FILE PERMISSIONS(CONT)
Chmod and chown cmd used for this
CHMOD: by default for any file permissions are: for owner rw-
for group r--
for others r—
We can change any file permissions with chmod command.this sets a file’s permissions
chmod category operation permission file(s)
category- user(owner, group, others)
Operation – assign or remove permission
Permission- read write or execute
FILE PERMISSIONS(CONT)
• For example :

chmod u + x filename

command category
operation permissions
FILE PERMISSIONS(CONT)
• There are three methods by which we can assign permissions to these categories
1) using operators like +,-
---- We can add same permission for all category at the same time by command
$ chmod ugo+x filename
$ chmod a+x filename a used for ugo
$ chmod +x filename
2) We can assign permissions using absolute assignments
• Absolute assignment is done by = operator
• This assign only permissions specified by = and remove other commands
FILE PERMISSIONS(CONT)
3) Using octal notation: in this we assign a no to each permission
read - 4
write - 2
execute- 1
• If we want to assign permissions to any category we use these nos
• Example user is assigned read and write permission, read for group and others for that
we have command
$ chmod 644 filename
• Highest possible no is 7 and lowest is 0 for permissions
FILE ATTRIBUTES(CONT.)
• chown Change owner.
Ex: chown <owner1> <filename> : Change ownership of a file to
owner1.
• First creator was owner 2.give ownership to owner 1.so now
• $ chown <owner2> <filename> not allowed
• chgrp Change group.
Ex: chgrp <group1> <filename> : Change group of a file to group1.
If group 2 was group owner then group1 can again give group ownership
to group1 which surrendered by group2 previously

You might also like