Important Linux Commands | Operating System - M01 P06
This is a multipart blog article series, and in this series I am going to explain you the concepts of operating system. This article series is divided into multiple modules and this is the first module which consists of 12 articles.
In this article we will see some question on Linux commands, and try to understand important Linux commands. Mainly we are going to discuss about system call commands, in this article.
Question 1: Which command is used to assign only read permission to all three categories of file named
chmod a -rw
chmod go + r note
chmod ugo = r note
u+r, g+r, o-x note
chmod ugo = r note
- If we want to give any permission to any directory or file then we use
chmodcommand, it means
There are in total three categories in every file user, group and other. On the other hand there are three types of permissions, which can be given to a file, and they are read, write and execute.
Read means that a user can read the data of the file, write means that a user can write/update that file and execute means that user can execute that file (e.g. User can execute a code file.)
chmod ugo = r note is the correct answer, because here we are giving read permissions to user, group and other for the file note.
chmod ugo+rw note command can be replaced in octal notation as.
chmod 555 note
chmod 666 note
chmod 333 note
chmod 444 note
chmod 666 note
- Every command can be denoted by a specific number in octal notation. Read is denoted by 4, write is denoted by 2 and execute is denoted by 1.
- So, if you want to give read and write permission to any user, you have to write 6 because
4 (read) + 2 (write) = 6. Similarly, write and execute will be written as 3 and read and execute will be written as 5 and if you want to give read write and execute permission it will be written as 7.
chmod 666 noteis correct answer because, this command means that we are giving 6 to user, 6 to group and 6 to other, where 6 means read and write permissions, and on the other hand question is asking for the octal notation of the command
ugo+rw notewhich means giving permissions of read and write to user group and other on the file named note.
Question 3: Suppose you have a file whose content are 1234567890abcdefghij
lseek is used two times sequentially
lseek (n, 10,SEEK_CUR)
lseek command two times what will be the position of R/W (read/write) head? (Index starts from 0)
- First of all remember one thing that
lseekis a system call. There are many more important system calls such as fork, read and write etc.
lseekcommand is used to move the read/write head, by default the read/write head is on first position (index 0).
- n means
file descriptor, first command means that the read/write head will be moved to 10th position by default. If you want to set the read/write head to a particular position then we use
SEEK_SET, so after we execute second command then the read/write head will be sent to 5th position.
- So, now after executing the above commands the position of read/write head will be on 5. Hence answer of this question is 5.
Hope you learn something from this article, and if you have any doubt, question or want to share something then, please feel free to contact me.