30 GNU/Linux questions and answers | PART 1


In this article I have compiled 30 GNU/Linux questions and answers from my ongoing Udemy Linux LPIC-1 Certification Exam 101-102, which I'm enrolled now for over two months. Questions covered in here will include terminal screen shoot from each question involving command. If case you notice certain technical error regarding the questions and answers, feel free to comment in sections down bellow and I will fix the error.

1. Explain in short Linux boot process.

Once machine is booted, BIOS launch a POST (Power On Self Test) which probes hardware. Once a POST is completed, you will hear a short beep sound which tells you that hardware is fine and boot continues on. BIOS than search for MBR (Master Boot Record), a 512 byte code located on a first cylinder of your /dev/sda1 which than searches for GRUB boot loader (GRand Unified Bootloader) which loads the initrd kernel image into memory and mounts temporary root file system. Afterwards, kernel searches and executes /sbin/init, the first program executed by a kernel which has PID=1. Until temporary root file system is mounted, kernel waits for Linux distribution to enter the init level 5(graphical mode) and unloads the initrd image out of memory. Afterwards, real root file system is being mounted and login prompt appears, asking for user password. Than you're good to go. This is how Linux boot process looks like. (NOTE: If you have spotted any technical error describing the boot process, please write down in comments bellow). 

2. Where would you find GRUB configuration file? Write full location as if on command line.

# boot/grub/grub.cfg 

Above is a grub.cfg file opened on my machine using vim text editor. 

3. What does /bin directory contain?

It contains executable commands such as ls, cp, mkdir, cd, tail, head, cat and etc.

4. What is bash?

BASH is Bourne Again Shell, currently default shell on most Linux distribution. 

5. What is kernel space?

The kernel space is where all of the system level processes are happening; it is also a place where kernel reside. 

6. By default, how many entries does HISTORY file store? 

The history can store maximum 1000 entries. You can type the following command.

# echo $HISTSIZE

7. Where would you find all commands previously typed? 

It's a .bash_history file

8. Which command would you use to create a file in Linux?

It's touch command. 

9. Which command and switch would you use to copy all the files and directories inside a parent directory? Write answer as if on command line.

# cp -R  /home/amar/data  /home/amar/Desktop

- data is a directory inside a /home directory 

- R switch is a recursive switch which tells a cp command to copy all the files within /data directory

- /home/amar/Desktop - is copy location 

10. Which command is a bash built-in command?

It's echo command.

11. Which command would you use to read a file in Linux?

It's a cat command. Check figure down bellow.

12. Which command and switch would you use to display the size of a directory in Linux? Write the answer as if on command line.

# du  -h  DATA

-h will display memory size in human readable format such as KB, MB, GB and etc.

13. Which command would you use to list only directory on Desktop? Write the answer as if on command line.

# ls  -l  |  grep  '^d'

Note on left side, there are d characters which tell us that the grep command has list only directories on my Desktop.

14. How would you redirect output of /etc directory into a file etcout.txt instead of standard output? Write the answer as if on command line.

# ls /etc > /home/amar/etcout.txt 

- > it is redirection sign which tells the ls command to save the content of /etc directory in a etcout.txt and not display the content in terminal. 

15. Which command will display the last 10 lines of a file? 

It's a tail command. 

16. Which command will display first 10 lines of a file?

It's a head command. 

17. How many primary partitions can you have on a hard disk?

It's 4.

18. What is /proc file system?

A proc file system is a virtual file system created on a fly when system boots up and it is dissolved upon system shut down. In simple words, it contains useful information on a processes, memory, cpu, dma channels, kernel and etc. 

19. Which key would you use to enter the vim text editor, insert mode?

You need to press the 'i' key on keyboard. 

20. Which command would you use to save and quit the vim text editor?

# :wq 

21. Which switch would you use to save the file edited using sed command? Write a answer as if on command line.

# sed -i  '/2/d'  stream.txt

In above figure, to sed command, I have passed '-i' character to save the changes permanently, and I have remove the second line from a file stream.txt by adding to sed command '/2/d', where 2 is second line and 'd' is a delete command. 

22.  What is sed command?

It's a stream editor for filtering and transforming text. 

23. What is PATH?

PATH is a environment variable containing list of a directories system should look for in order to execute a command. 

24. How would you read the BASH variable in a terminal? Write the answer as if on a command line? 

# echo  $BASH

Each environment variable is written with capital letters; it is read via echo command by passing the dollar sign ($) and the name of the variable, in above case the BASH. As you can see, it has printed the current default BASH on my Linux distribution. 

25. Which file would you edit in order to add your /home/apps directory permanently into the PATH?

It's a .bashrc file which must be edited using any text editor with sudo rights. 

26. What is PS1 in Linux?

The PS1 is a environment variable which is used for a bash prompt configuration; it displays your username, hostname, /home directory, and user type in terminal. 

27. Which command would you use to display your user name out of /etc/passwd file? Write the answer as if on command line.

# grep  amar  /etc/passwd

28. Which command would you use to list a permissions of a file? Write the answer as if on command line.

# ls  -l  stream.txt 

29. Which command will keep the file attributes during a copy? Write the answer as if on command line. 

# cp -R --preserve=all  kings1.txt  kings

30. Which command would you use to change file owner? 

It's chown command. 

Nema komentara:

Objavi komentar