Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

Lab 2 - Linux Permissions CIE 302 - Operating systems

and Redirection
What is an operating system?
Main objective of the OS:
1. It provides the programmers a set of abstract resources of hardware.
2. It manages the hardware resources according to the usage of the programs.
Linux Basics
General commands:
 whoami : prints the current user
 who : display a list of all users
 uptime : display the duration
 date : display the current date and time
 man <command> : manual of the linux
commands
Linux Basics
Path and Directory commands:
 pwd : print working directory
 cd : change directory
 cd .. it goes to a single file above the
current directory

 cd absolute path it goes to the given


path directory

 cd relative path it goes to the given


path directory
Linux Basics
Path and Directory
commands:
 cd - it represent the last directory.

cd ~ it is the same as cd, which


direct the current directory to the
home directory
Linux Basics
Listing and display
 echo : it prints anything after it
 ls : Listing command
ls it lists all files / directories within the current
directory

ls path it lists all files / directories within a certain


directory without going to that directory
Linux Basics
Listing and display
ls –l it lists all files / directories with detailed information
Linux Basics
Listing and display
ls –lh it lists all files / directories with a readable size format
Linux Basics
Listing and display
ls –a it lists all files / directories including the hidden files
ls –la it lists all files / directories including the hidden files, with detailed information
Linux Basics
Directory / file creation and manipulation
 mkdir : make new
directories

 mkdir –p : creates
multiple subdirectories
at the same time
Linux Basics
Directory / file creation and manipulation
 rmdir : remove directory

 rm –rf : remove directory recursively


Linux Basics
Directory / file creation and manipulation
 touch : create a new empty
file

 rm : removes files /
directories

 rm –i : removes file /
directory by prompting
Linux Basics
Directory / file creation and manipulation
 cp : copy file / directory
 cp –r : recursive copy, which is
used to copy directories

 cp <file_name> <path> : it
copies a file to a certain
directory
Linux Basics
Directory / file creation and manipulation
 cp <file_name>
<another_name> : it copies the
file with a new name in the same
directory
mv : move or rename file /
directory
Linux Basics
More linux commands:
 pipe ( | ) : it is used as an inter process communication, to join multiple commands.
 grep : it is used to search for a certain pattern in a file

 ls –l | grep file this command is used to list all files / directories, where the file /
directory name contains “file”.
Linux Basics
More linux commands:
 grep –i : it searches for lines that contain a certain pattern

 grep –n : it searches and display the number of the lines that contain a certain
pattern
Linux Basics
More linux commands:
 grep ^string : it searches for the lines that start with a certain pattern
 grep string$ : it searches for the lines that end with a certain pattern

 cat : it concatenates the file to the standard output


Linux Basics
More linux commands:
 > : input
 < : output
 >> : append
Linux permissions and users
Types of users in Linux
 Root user:
Administrator of the system, has full control of the system

 Sudo user:
A normal user with root privileges
It has permission to control, read and execute every file on
the system

 Normal user:
Any user that isn’t a root user
It has a limited control on the files
Linux permissions and users
 Each user has its own username, password, and permissions.
 All users have a user ID (UID) and a group ID (GID).
 Group is set of users that has permission to access special files (read, write,
execute) and that owner and the root can manage level of accesses to them.
 Every user must belong to at least one group
 Every file and directory is marked with a UID and GID
Linux permissions and users
The SU command:
 su : switch user, it is used to switch to the home directory of different users
 This command changes the UID and GID of the existing user
The sudo command:
 It gives to the certain users only a few superuser permissions.
 it enables the user to issue some commands that only the root can issue
 The sudo command caches the password for 5 minutes
Linux permissions and users
Root user
UID 0 (zero)
Can access any file, regardless of UID or GID
 To set the root password:

To exit the root user, # exit


Linux permissions and users
Root user
groupadd : it adds a group to the system

useradd : user add command to add users into the system


 useradd –c : it adds comments to the created user
 useradd –m : it adds a default home directory to the user
 useradd –g : it adds this user to a group
Linux permissions and users
Root user
usermod : modify a user, this command changes the user’s parameters
 usermod –d : it modifies the home directory
 usermod –g : it modifies the group ID

 userdel –r : it deletes the user along with its home directory


 groupdel : it deletes a group
Linux permissions and users
Permissions:
Linux permissions and users
Permissions:
 ls –l : this command lists all directories and files along with their permissions
Linux permissions and users
Permissions:
Linux permissions and users
Permissions:
 chmod : command is used to change the permissions of a file or directory.
chmod UGO =/+/- filename
Linux permissions and users
Permissions:
 chmod : command is used to change the permissions of a file or directory.
rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- --- = 111 000 000
and so on... rwx = 111 in binary = 7 rw- = 110 in binary = 6 r-x = 101 in binary = 5 r-- = 100 in
binary = 4
Linux permissions and users
Value Meaning
(rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable
777
setting.
(rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute
755
the file. This setting is common for programs that are used by all users.
(rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This
700
setting is useful for programs that only the owner may use and must be kept private from others.
666 (rw-rw-rw-) All users may read and write the file.
(rw-r--r--) The owner may read and write a file, while all others may only read the file. A common
644
setting for data files that everybody may read, but only the owner may change.
(rw-------) The owner may read and write a file. All others have no rights. A common setting for data
600
files that the owner wants to keep private.
Linux permissions and users

You might also like