Linux Commands For Devops Interview Questions
Commands | Stand For | Description |
---|---|---|
ls | List | Lists directory contents. |
cd | Change Directory | Changes the current directory. |
pwd | Print Working Directory | Prints the current working directory. |
cp | Copy | Copies files or directories. |
mv | Move | Moves files or directories. |
rm | Remove | Removes files or directories. |
touch | Touch | Creates an empty file or updates file timestamps. |
mkdir | Make Directory | Creates a new directory. |
chmod | Change Mode | Changes file permissions. |
chown | Change Owner | Changes file ownership. |
grep | Global Regular Expression Print | Searches for patterns in files. |
find | Find | Searches for files and directories. |
tail | Tail | Outputs the last part of files. |
head | Head | Outputs the first part of files. |
cat | Concatenate | Concatenates files and prints on the standard output. |
less | Less is More | Views file contents interactively. |
more | More | Views file contents page by page. |
kill | Kill | Terminates processes by ID or name. |
ps | Process Status | Displays information about running processes. |
top | Table of Processes | Displays dynamic real-time system information. |
df | Disk Free | Shows disk space usage. |
du | Disk Usage | Shows directory space usage. |
zip | Zip | Compresses files into a zip archive. |
unzip | Unzip | Extracts files from a zip archive. |
tar | Tape Archive | Creates, views, or extracts files from an archive. |
curl | Client URL | Transfers data from or to a server. |
wget | Web Get | Downloads files from the internet. |
ssh | Secure Shell | Connects to a remote machine securely. |
scp | Secure Copy | Copies files securely between hosts. |
rsync | Remote Sync | Synchronizes files and directories between two locations. |
a) Navigation
1. Switch folders
How do I move between different folders in Linux?
Answer: To navigate between folders in Linux, you can use the cd
command followed by the directory path you want to switch to. For example, to move to a directory named “Documents” within your current location, you would type cd Documents
.
2. List contents
How can I see what files are inside a folder?
Answer: You can use the ls
command to list the contents of a folder. Simply type ls
followed by the directory path if you want to list the contents of a specific folder. For example, ls /path/to/directory
.
3. Current location
Where am I right now in the file system?
Answer: To see your current location within the file system, you can use the pwd
command. Type pwd
in the terminal will display the full path of your current working directory.
b) File Management
1. Copy a file
How do I make a copy of a file and put it somewhere else?
Answer: You can use the cp
command to copy a file. Simply type cp
followed by the name of the file you want to copy and then the destination where you want to place the copy. For example, cp file.txt /path/to/destination
.
2. Move a file
How can I move a file to a different folder?
Answer: You can use the mv
command to move a file to a different folder. Type mv
followed by the name of the file you want to move and then the destination where you want to move it. For example, mv file.txt /path/to/destination
.
3. Delete a file
How do I permanently remove a file?
Answer: To delete a file, you can use the rm
command followed by the name of the file you want to delete. For example, rm file.txt
. Be careful, as this action is irreversible and the file will be permanently deleted.
4. Create an empty file
How can I make a new file with nothing in it?
Answer: You can create an empty file using the touch
command followed by the name of the file you want to create. For example, touch newfile.txt
.
5. Make a new folder
How do I create a new folder to organize files?
Answer: To create a new folder, you can use the mkdir
command followed by the name of the folder you want to create. For example, mkdir new_folder
.
6. Delete a folder
How can I remove a folder and everything inside it?
Answer: You can use the rm
command with the -r
option to remove a folder and its contents recursively. For example, rm -r folder_name
.
c) Permissions and Ownership
1. Control access
How can I decide who can see and change files/folders?
Answer: You can use the chmod
command to change the permissions of files and folders in Linux. By modifying the permissions, you can control who can read, write, or execute a file or folder.
2. Change ownership
How do I transfer ownership of a file/folder to someone else?
Answer: You can use the chown
command to change the ownership of a file or folder in Linux. This allows you to transfer ownership to another user or group.
d) Viewing and Searching
1. See last lines
How can I quickly look at the end of a file?
Answer: You can use the tail
command followed by the filename to view the last few lines of a file. For example, tail filename.txt
will display the last 10 lines of the file by default.
2. Find a file
How do I search for a specific file on my computer?
Answer: You can use the find
command to search for files on your computer. For example, find /path/to/search -name filename
will search for a file named “filename” in the specified directory.
e) Processes and Networking
1. Stop a program
How do I close a program that’s running?
Answer: You can use the kill
command followed by the process ID (PID) of the program to stop it. First, you need to find the PID using the ps
command, then use kill PID
to terminate the program.
2. Create a shortcut
How can I make a quick way to access a file or folder?
Answer: In Linux, you can create shortcuts called symbolic links using the ln
command. For example, ln -s /path/to/original /path/to/link
will create a symbolic link named “link” that points to the original file or folder.
3. Hard vs. symbolic links
What’s the difference between these two types of shortcuts?
Answer: A hard link is a direct reference to the file’s inode, while a symbolic link is a separate file that contains the path to the original file. Hard links cannot cross file systems, while symbolic links can.
4. Search within a file
How do I find specific words or patterns inside a file?
Answer: You can use the grep
command followed by the pattern you want to search for and the filename. For example, grep "pattern" filename.txt
will search for the specified pattern within the file.
5. Find files
What can the “find” command do to search for files?
Answer: The find
command is used to search for files and directories based on various criteria such as name, size, or type. It allows you to perform complex searches and execute actions on the found files.
6. Compress/uncompress files
How do I zip and unzip files in Linux?
Answer: You can use the zip
command to compress files into a zip archive and the unzip
command to extract files from a zip archive. For example, zip archive.zip file1 file2
will create a zip archive containing file1 and file2.
f) Network Management
1. See network settings
How do I view my current network setup?
Answer: You can use the ifconfig
command to view your current network configuration in Linux. It displays information about network interfaces, IP addresses, and other network settings.
2. Manually configure network
How can I set up my network connection myself?
Answer: You can manually configure your network connection by editing configuration files such as /etc/network/interfaces
or using tools like ifconfig
and ip
commands to set IP addresses, routes, and other network parameters.
3. Check internet connection
How do I make sure I’m connected to the internet?
Answer: You can use commands like ping
or curl
to check your internet connection. For example
ping google.com
will send packets to Google’s servers to check connectivity.curl http://example.com
will attempt to retrieve a webpage.
4. Data flow
How can I see where my computer sends and receives data?
Answer: You can use network monitoring tools like netstat
or tcpdump
to view network connections and data transfer on your computer. These tools provide detailed information about network activity.
5. Open ports
How do I check which programs are using the internet?
Answer: You can use the netstat
command to display active network connections and listening ports. This helps you identify which programs are using the internet and which ports they are using.
g) System Monitoring and Management
1. Monitor performance
How can I keep track of how well my computer is running?
Answer: You can use tools like top
, htop
, or vmstat
to monitor system performance in Linux. These tools display information about CPU, memory, disk, and network usage in real-time.
2. What is crontab
What can I do with the “crontab” command?
Answer: crontab
is a command-line utility in Linux used to schedule recurring tasks (cron jobs). It allows users to automate tasks by specifying commands or scripts to run at specified intervals.
3. Edit a file
How can I change the contents of a file directly in the terminal?
Answer: You can use text editors like nano
, vi
, or vim
to edit files directly in the terminal. Simply open the file with one of these editors, make your changes, and then save and exit.
4. curl vs wget
What are the differences between these two downloading tools?
Answer: curl
and wget
are both command-line tools used for downloading files from the internet, but they have different features and capabilities.
curl
supports various protocols and is more versatile.wget
is better suited for recursive downloads and mirroring websites.
5. Manage code with git
How do I use the “git” command to work on code projects?
Answer: git
is a version control system used for tracking changes in code projects. You can use commands like git clone
, git add
, git commit
, and git push
to manage and collaborate on code repositories.
6. What is awk
What can the “awk” command do for processing data?
Answer: awk
is a powerful text-processing tool in Linux used for pattern scanning and processing. It allows you to extract and manipulate data from files, perform calculations, and generate reports.
7. Search with awk
How can I use “awk” to find specific information in a file?
Answer: You can use awk
with pattern matching to search for specific information in a file. For example, awk '/pattern/' filename
will print lines containing the specified pattern.
8. Awk scripts
What are the basic parts of an “awk” script?
Answer: An awk
script consists of one or more patterns and actions enclosed in curly braces {}
. The pattern specifies when the action should be performed, and the action defines what should be done when the pattern is matched.
9. Calculations with awk
How can I use “awk” to perform math with data in a file?
Answer: awk
can perform arithmetic operations on data in a file using mathematical expressions within the script. For example, awk '{sum += $1} END {print sum}' filename
will calculate the sum of numbers in the first column of the file.
10. Format with awk
How can I use “awk” to make the output of a file look better?
Answer: awk
can be used to format the output of a file by specifying the field separators, field widths, and other formatting options within the script. This allows you to align columns and customize the appearance of the output.
FAQ’S (Linux Commands For Devops Interview Questions)
Q: What is the most common Linux command for DevOps?
ls
, which is used to list directory contents. It’s essential for navigating and understanding the structure of files and directories in Linux systems, a fundamental task in DevOps operations.Q: How Linux is used in DevOps?
Q: How to crack a DevOps interview?
Q: What is the most important command in Linux?
cd
, which stands for “change directory.” It allows users to navigate between different directories in the file system, a fundamental operation in Linux and essential for various tasks in system administration, development, and DevOps.