UnixInterviewQuestions


Unix interview questions:

Level: Basic

Displays contents of the file 
cat filename
----------------------------------------------------------------------------------------------------
Copy source file into the destination
cp source destination 
----------------------------------------------------------------------------------------------------
Move/rename and old name to the new name
mv old name new name 
----------------------------------------------------------------------------------------------------
Remove/delete filename
rm filename
----------------------------------------------------------------------------------------------------
Creating a new directory:
mkdir directory_name
----------------------------------------------------------------------------------------------------
Removing a directory
rmdir directory_name
----------------------------------------------------------------------------------------------------
Listing directory contents of files and directories
ls [options] [file|dir]
----------------------------------------------------------------------------------------------------
Changing the current working directory
cd or cd "path to navigate"
----------------------------------------------------------------------------------------------------
Clears the terminal screen.
clear
----------------------------------------------------------------------------------------------------
Opening file for editing it:
vi filename
----------------------------------------------------------------------------------------------------
Save changes in file and quit
:wq!
----------------------------------------------------------------------------------------------------
Find today’s date?
The command “date” use to retrieve current date.
----------------------------------------------------------------------------------------------------
Find maximum memory taking process on the server?
The command top displays the CPU usage, process id, and other details.
----------------------------------------------------------------------------------------------------
Allows normal users to run programs as superuser or root:
sudo
----------------------------------------------------------------------------------------------------
Command used to install and update packages
apt-get




Level: Intermediate
----------------------------------------------------------------------------------------------------
Search tomcat process and take the pid and kill it:
ps -ef | grep tomcat | awk '{print $2}' | xargs kill -9
----------------------------------------------------------------------------------------------------
run a process in background:
nohup node server.js &
For running a process in background use "&" in command line
For bringing it back in foreground use command "fg jobid"
and for getting job id you use command jobs,
for killing that process find PID and use kill -9 PID command.
----------------------------------------------------------------------------------------------------
History with grep:
history | grep "keyword2find"
----------------------------------------------------------------------------------------------------
How do you check how much space left in current drive ?
By using "df" command in UNIX. For example "df -h ." will list how full your current drive is.
----------------------------------------------------------------------------------------------------
What is "chmod" command? What do you understand by this line “r-- -w- --x?
user has only read permission, group members has write permissions and other people has only execute permission
----------------------------------------------------------------------------------------------------
In a file word UNIX is appearing many times? How will you count number
grep -c "Unix" filename
----------------------------------------------------------------------------------------------------
How do you find for how many days your Server is up?
By using uptime command in UNIX
----------------------------------------------------------------------------------------------------
 How to do recursive and force deletion?
rm -rf
----------------------------------------------------------------------------------------------------
What is the command to find hidden files in the current directory?
ls –lrta’ is to display hidden files in current directory.
----------------------------------------------------------------------------------------------------
What is the command to find weather system is 32 bit or 64 bit?
arch” or “uname -a” can use for this process.
----------------------------------------------------------------------------------------------------
What is called piping?
“piping” is used to combine two or more commands together. The output of the first command work as the input of the second command, and so on. Pipe character ( | ) is represent piping.
----------------------------------------------------------------------------------------------------
How is cmp command different from diff command?
cmp’ command is basically used for byte by byte comparison of two files to determine the first mismatch byte. This command does not use the directory name and displays the first encountered mismatched byte.
Whereas, ‘diff’ command’ determines the changes that are to be performed on the files in order to make the two files identical. In this case, directory names can be used.
----------------------------------------------------------------------------------------------------
What is the typical command syntax under the UNIX shell?
Command [-argument] [-argument] [–argument] [file]
----------------------------------------------------------------------------------------------------
Write a command that will find all text files in a directory such that it does not contain the word “amazing” in any form (that is, it must include the words Amazing, AMAZING, or aMAZINg)
grep –vi amazing *.txt
----------------------------------------------------------------------------------------------------
Write a command that will allow a UNIX system to shut down in 15 minutes, after which it will perform a reboot.
shutdown –r +15
----------------------------------------------------------------------------------------------------
Write a shell script that requests the user’s age and then echoes it, along with some suitable comment.
echo Hello! What\’s your age\?
read age
echo $age! I\’ll be obsolete by that age!
----------------------------------------------------------------------------------------------------
How to tails last 200 lines of any log fine?
$ tail -200f filename.txt