UNIX Questions with Answers
1. What are the key features of the UNIX operating system?
- Multi-user, multitasking, portability, hierarchical file system, built-in networking, and robust security.
2. Explain the file structure in UNIX. How is it organized?
- It is a hierarchical tree structure starting with the root (/). Directories branch off to organize files logically.
3. What is the difference between an absolute path and a relative path?
- Absolute path: Specifies the complete path from the root (e.g.,
/home/user/file
). - Relative path: Specifies the path from the current directory (e.g.,
../file
).
4. How do you change file permissions using chmod?
- Command:
chmod 755 file
- Gives the owner read, write, execute permissions, and others read and execute permissions.
5. What is the difference between chown and chmod?
- chown: Changes the owner of a file.
- chmod: Changes the file’s permissions.
6. How do you view hidden files in UNIX?
- Command:
ls -a
7. What is the purpose of the grep command? Provide an example.
- Searches for patterns in a file.
- Example:
grep "error" logfile.txt
8. How do you check disk usage in UNIX?
- Command:
df -h
9. What is the difference between > and >> in file redirection?
>
: Overwrites the file.>>
: Appends to the file.
10. How do you display the first 10 lines of a file?
- Command:
head filename
11. What is the purpose of the tail command?
- Displays the last 10 lines of a file.
- Example:
tail logfile.txt
12. How do you copy a file in UNIX?
- Command:
cp sourcefile destinationfile
13. What is the purpose of the find command?
- Finds files and directories.
- Example:
find /path-name -name "filename"
14. How do you kill a process in UNIX?
- Command:
kill -9 PID
15. What is the difference between a soft link and a hard link?
- Soft Link: Points to a file path; breaks if the file is deleted.
- Hard Link: Points to the file’s inode; doesn’t break if the file is deleted.
16. How can you check currently running processes?
- Commands:
ps
ortop
- Example:
ps -ef
17. What does the awk command do?
- Used for pattern scanning and text processing.
- Example:
awk '{print $1}' filename
18. How do you schedule tasks in UNIX?
- Command:
crontab -e
19. What is the difference between df and du?
- df: Shows disk space usage of filesystems.
- du: Shows disk usage of directories/files.
20. How do you compress files in UNIX?
- Command:
gzip filename
21. What is the difference between vi and nano editors?
- vi: A powerful, mode-based editor.
- nano: Simpler and user-friendly.
22. How do you list only directories in UNIX?
- Command:
ls -d */
23. How do you display the current working directory?
- Command:
pwd
24. What is the purpose of the cut command?
- Extracts specific columns or fields from a file.
- Example:
cut -d',' -f1 filename
25. How do you display a file’s contents page by page?
- Commands:
more
orless
- Example:
more filename
26. How do you find out the shell you’re using?
- Command:
echo $SHELL
27. How can you view a file’s permissions?
- Command:
ls -l
28. What is the purpose of the env command?
- Displays environment variables.
29. How do you terminate all processes owned by a specific user?
- Command:
pkill -u username
30. What does the nohup command do?
- Runs a command immune to hang-ups.
- Example:
nohup ./script.sh &
SQL Questions with Answers
1. What is a primary key?
- A unique identifier for each row in a table, ensuring no duplicate values.
2. What is a foreign key?
- A column that references the primary key of another table to establish a relationship.
3. What is the difference between WHERE and HAVING?
- WHERE: Filters rows before grouping.
- HAVING: Filters groups after grouping.
4. Explain normalization and its benefits.
- Organizes data to reduce redundancy and improve consistency.
- Examples: 1NF, 2NF, 3NF.
5. What is the purpose of JOIN in SQL?
- Combines rows from two or more tables.
- Types: INNER, LEFT, RIGHT, FULL.
6. What is the difference between DELETE and TRUNCATE?
- DELETE: Removes specific rows; can have a WHERE clause.
- TRUNCATE: Removes all rows; faster and cannot be rolled back.
7. What are aggregate functions?
- Functions like SUM, AVG, MAX, MIN, and COUNT perform calculations on a set of rows.
8. What is the difference between CHAR and VARCHAR?
- CHAR: Fixed-length storage.
- VARCHAR: Variable-length storage.
9. How do you retrieve unique values from a column?
- Command:
SELECT DISTINCT column_name FROM table_name;
10. What is a subquery?
- A query inside another query.
- Example:
SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
11. What is the difference between UNION and UNION ALL?
- UNION: Removes duplicates.
- UNION ALL: Keeps duplicates.
12. What is indexing in SQL?
- Improves query performance by allowing faster data retrieval.
13. How do you create a view in SQL?
- Command:
CREATE VIEW view_name AS SELECT column1, column2 FROM table_name;
14. What is a stored procedure?
- A reusable block of SQL code stored in the database.
15. What is the difference between GROUP BY and ORDER BY?
- GROUP BY: Groups rows based on a column.
- ORDER BY: Sorts rows in ascending or descending order.
16. What is a transaction in SQL?
- A sequence of operations performed as a single unit, ensuring ACID properties.
17. How do you handle NULL values in SQL?
- Use functions like
IS NULL
,IS NOT NULL
, orCOALESCE
.
18. What is the use of CASE in SQL?
- Implements conditional logic in a query.
- Example:
SELECT column, CASE WHEN condition THEN result END FROM table;
19. What is a self-join?
- A table joined with itself.
- Example:
SELECT A.column, B.column FROM table A, table B WHERE A.id = B.parent_id;