L10_file System and Related Commands
L10_file System and Related Commands
/(root)
----------------------------------------------------------------------------------------------------------------
| | | | | |
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
- r w x r w - r - -
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