Unix Questions for Interview

Author: neptune | 10th-May-2022 | Views: 229

Unix Interview Questions

1. Find all the empty files inside the directory OFFICE and delete them.

$ find OFFICE/ -empty -type f -delete

2.Find the name of the directory you are currently placed.

$ pwd

3.Display the system date

$ date

4.Create three empty files in your home directory with the names file1, file2 and file3.

$ touch file1 file2 file3

5.Copy the file file1 to the sub-directory HR under the OFFICE directory.

$ cp file1 OFFICE/HR

6.Rename the file file1 to hrfile.txt.

$ mv file hrfile.txt

7.Copy the file file2 and file3 to the sub-directory BILLS under the sub-directory FINANCE under OFFICE directory


8.Rename file2 to billpaid.txt and file3 to billdue.txt.

$ mv file2 billpaid.txt

$ mv file3 billdue.txt

9.Change the permissions of the ADMIN directory as below

Owner – All permissions

Group – Read and Execute permissions

Others – Read permission

10.Copy the directory HR to another directory with name HR_new

$ cp -r HR HR_new

11.Copy the file inside the directory HR to another directory with name TEMPDIR.

$ cp -r HR/* TEMPDIR/

12.Delete the file inside the directory HR_New and then delete the directory HR_New

$ rm -r HR_New/*

$ rm -d HR_New

13.Delete the directory TEMPDIR at one go.

$ rm -d TEMPDIR/

14. List all the files in your home directory with all the attributes.

$ ls -A


$ ls -a

15.List all the text files in your home directory.

$ ls -a *.txt

16.List the users currently logged in.

$ w

17. Compare the file sample.txt inside the directory ADMIN with the file hrfile.txt inside the directory HR.

Syntax: cmp [options] file1 file2

$ cmp ADMIN/sample.txt HR/hrfile.txt

18.List the common lines between the two files mentioned in the previous question.

$ comm ADMIN/sample.txt HR/hrfile.txt

19. Display the lines which start with the word “This” in the file sample.txt inside the directory ADMIN.

$ grep “^This” sample.txt

20. Display the count of lines having the word “sample” in the file sample.txt. The search should be case-insensitive.

$ grep -ic “sample” sample.txt

21. Create a file called scores.txt in your home directory with the following content

Roll No|Name|Score






Display the name of the top 3 scorers from the data stored in the file scores.txt.

$ sort -k2,2rn -t: scores.txt | head -n 3 | cut -f1 -d:

Thanks for Reading !!!

anonymous | May 10, 2022, 1:26 a.m.


Related Blogs
Top linux commands every developer should know.
Author: neptune | 08th-May-2022 | Views: 601
We are going to explore top commands of Linux / Ubuntu that every developer should know...

How to kill multiple processes in one cmd.
Author: neptune | 11th-Dec-2022 | Views: 107
I think most of us use task manager to end/kill processes if the application doesn’t respond...

View More