![]() |
Image Source: https://www.istockphoto.com/photo/server-configuration-command-lines-on-a-monitor-gm619051530-107880303?phrase=linux |
In this blog post we have compiled 15 interview questions related to Linux commands.
1. Which command is used to remove duplicate lines in a file?
uniq command
Syntax:
uniq [options]
2. What does less command do?
Prints file contents one screen at a time.
Syntax:
less [options]
3. What does df command do?
Prints the amount of free disk space available.
4. Command to print current processes running.
ps
5. How to compress and archive files?
Single file:
gzip [options]
Multiple Files:
zip [options] <zipfile_name> <file1_name> <file2_name>
tar [options]
6. file command in Linux.
Used to identify the type of file for example is it .txt or .pdf etc.
Syntax:
file [options]
7. cut command in Linux
Removes specific sections from a file and prints them on terminal.
Syntax:
cut [options] <range_of_content_to_remove> <file_name>
8. What is inode number?
It is a unique number that the system uses to identify a file.
9. Explain hard and soft links.
Hard links create a copy of a file with another name. The new file has a different name but same inode number as the original file. Even if original file is deleted, hard link still remains. It is not recommended to use hard links.
Soft links are like shortcuts to a file. The link is a pointer to the original file. The file and link have different inode number. If the original file is deleted, soft links are broken.
Syntax for creating links is,
ln <source_file> <destination_file>
By default hard links are created using the above command.
To create soft links specify the -s option.
ln -s <source_file> <destination_file>
10. w command in Linux.
Displays details about the users that are currently logged in.
11. System calls in unix were written in which language?
C Language
12. id command in Linux.
Used to find user and group names and ids.
13. Difference between sleep and time sleep commands.
sleep command causes the terminal to wait for the specified duration of time before allowing the user to enter another command.
E.g. sleep 5
Terminal is paused for 5 s.
time sleep command pauses the terminal and also prints real, user and system times.
14. split command in Linux.
Used to split a file into multiple files as specified.
Syntax:
split [options] <file_name>
E.g. Consider a file having 50 lines named file_to_split.txt
split -l 10 file_to_split.txt
The above command creates 5 new files having 10 lines each without altering the original file.
15. paste command in Linux.
Merges lines of the specified files using the given delimiter.
Syntax:
paste [options] <"delimiter"> <"file1"> <"file2">
Comments
Post a Comment