DEV Community

loading...
Cover image for Important Linux Commands | Operating System - M01 P06

Important Linux Commands | Operating System - M01 P06

rahulmishra05 profile image Rahul Mishra Originally published at programmingport.hashnode.dev ・3 min read

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 note

  1. chmod a -rw
  2. chmod go + r note
  3. chmod ugo = r note
  4. u+r, g+r, o-x note

Answer: (iii.) chmod ugo = r note

Explanation:

  • If we want to give any permission to any directory or file then we use chmod command, it means change mode

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.

Question 2: chmod ugo+rw note command can be replaced in octal notation as.

  1. chmod 555 note
  2. chmod 666 note
  3. chmod 333 note
  4. chmod 444 note

Answer: (ii.) chmod 666 note

Explanation:

  • 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 note is 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 note which 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

Here lseek is used two times sequentially

lseek (n, 10,SEEK_CUR)

lseek (n,5,SEEK_SET)

After applying lseek command two times what will be the position of R/W (read/write) head? (Index starts from 0)

  1. 0
  2. 5
  3. 10
  4. 15

Answer: 5

Explanation:

  • First of all remember one thing that lseek is a system call. There are many more important system calls such as fork, read and write etc.
  • lseek command 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.

📱 Contact Me

Twitter
LinkedIn
Telegram
Instagram

📧 Write a mail

rahulmishra102000@gmail.com

🚀 Other links

GitHub
HackerRank

Discussion

pic
Editor guide