Monday, October 3, 2022

Unix Interview Preparation

 

Unix Interview Q&A -Part 1

1.Describe the usage and functionality of the command “rm –r *” in UNIX?

Answer: The command “rm –r *” is a single line command to erase all files in a directory with its subdirectories.

  • “rm” — command for deleting files.
  • “-r” — command to delete directories and subdirectories with files within.
  • “*” — indicates all entries.

2. What is the behavioral difference between “cmp” and “diff” commands?

Answer: Both commands are used for file comparison.

  • Cmp — Compare given two files with byte by byte and display the first mismatch.
  • Diff — Display changes that need to do to make both files identical.

3. What are the duties of the following commands: chmod, chown, chgrp?

Answer:

  • chmod — Change the permission set of the file.
  • chown — Change ownership of the file.
  • chgrp — Change group of the file.

4. What is the purpose of the following command?

5. Describe the zip/unzip command using gzip?

Answer: gzip command creates a zip file using the given filename in the same directory.

6. How to display the last line of a file?

Answer: This can be performed using either “tail” or “sed” commands. The easiest way is to use the “tail” command.

7. What are the various IDs in UNIX processes?

Answer: Process ID is a unique integer that UNIX uses to identify each process. The process executes to initiate other processes is called parent process and its ID is defined as PPID (Parent Process ID).

  • getpid() — Retrieve process id
  • getuid() — Retrieve user-id
  • geteuid() — Retrieve effective user-id

8. How to Kill a process in UNIX?

Answer: The kill command accepts process ID (PID) as a parameter. This is applicable only for the processes owned by the command executor.

9. What is the command to find maximum memory taking process on the server?

Answer: Top command displays the CPU usage, process id, and other details.

10.What is the command to find hidden files in the current directory?

Answer: ‘ls –lrta’ command is used to display hidden files in the current directory.

11.Explain ‘nohup’ in UNIX?

Answer: “nohup” is a special command that is available to run a process in the background. The process starts with ‘nohup’ command and does not terminate even the user started to log off from the system.

12.What is the method to edit a large file without opening it in UNIX?

Answer: The “sed” command is available for this process ‘.sed’ stands for a team editor.

  • -v: prints line that does not match the pattern.
  • -n: print matched line and line number.
  • -l: print file names with matching lines.
  • -c: prints only count the matching lines.
  • -i: matches either uppercase or lowercase.

13.How to remove the duplicate from file in unix

sort command: arranges lines of text alphabetically or numerically.

sort authors.txt | uniq
Chaucer
Orwell
Larkin

14.How to show a count of the number of times a line occurred

To output the number of occurrences of a line use the -c option in conjunction with uniq. This prepends a number value to the output of each line.

uniq -c authors.txt
2 Chaucer
2 Larkin
1 Orwell

15.How to only show repeated lines

To only show repeated lines pass the -d option to uniq. This will output only lines that occur more than once and write the result to standard output.

uniq -d authors.txt
Chaucer
Larkin

16.How to only show lines that are not repeated

To only show lines that are not repeated pass the -u option to uniq. This will output only lines that are not repeated and write the result to standard output.

uniq -u authors.txt
Orwell

17. Delete Files older Than 30 Days

find /opt/backup -type f -mtime +30find /opt/backup -type f -mtime +30 -delete

18. Delete Old Directory Recursively

find /var/log -type d -mtime +30 -exec rm -rf {} \;

No comments:

Post a Comment

Spark- Window Function

  Window functions in Spark ================================================ -> Spark Window functions operate on a group of rows like pa...