Unix Commands
Unix Commands
csv
8. How to replace the n-th line in a file with a new line in Unix?
sed -i'' '10 d' filename # d stands for delete
sed -i'' '10 i new inserted line' filename # i stands for insert
11. How will you find which operating system your system is running on in UNIX?
uname -a
The 'history' command can be used to get the list of commands that we are
executed.
By default, the head command displays the first 10 lines from a file. If we
change the option of head, then we can display as many lines as we want.
head -20 filename
The tail command can be used to display the last lines from a file.
tail -1 filename
16. How do you check how much space left in current drive ?
By using "df" command in UNIX. For example "df -h ."
Process size must be less than or equal to the available main memory.
It is easier to implementation and overhead to the system.
Swapping systems does not handle the memory more flexibly as compared to the
paging systems.
Paging:
Only the required memory pages are moved to main memory from the swap device
for execution.
Process size does not matter. Gives the concept of the virtual memory.
It provides greater flexibility in mapping the virtual address space into the
physical memory of the machine.
Allows more number of processes to fit in the main memory simultaneously.
Allows the greater process size than the available physical memory.
Demand paging systems handle the memory more flexibly.
18. How do you find how many cpu are in your system and there details?
By looking into file /etc/cpuinfo for example you can use below command:
cat /proc/cpuinfo
20. What is Zombie process in UNIX? How do you find Zombie process in UNIX?
When a program forks and the child finishes before the parent, the kernel
still keeps some of its information about the child in case the parent might need
it - for example, the parent may need to check the child's exit status.
To be able to get this information, the parent calls 'wait()'; In the
interval between the child terminating and the parent calling 'wait()', the child
is said to be a 'zombie' (If you do 'ps', the child will have a 'Z' in its status
field to indicate this.)
Zombie : The process is dead but have not been removed from the process
table.
21. What is "chmod" command? What do you understand by this line �r-- -w- --x?
chmod command is used to change permission of a file or directory in UNIX.
The line you see shows the permission for three different set of people :
user, group and others.
User is the currently logged in user, while group is for all other member
which are part of certain group and others means anyone other than user and group
member.
Each group has three permissions rwx stands for read, write and execute and
they are written as user_group_others.
So in above line, user has only read permission, group members has write
permissions and other people has only execute permission.
If it is a directory then you need execute permission to go inside that
directory.
See here for more detailed answer.
22. How will you run a process in background? How will you bring that into
foreground and how will you kill that process?
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.
This is indeed a good Unix Command interview questions because many of
programmer not familiar with background process in UNIX.
23. How do you find how many cpu are in your system and there details?
By looking into file /etc/cpuinfo for example you can use below command:
cat /proc/cpuinfo
http://javarevisited.blogspot.in/2011/05/unix-command-interview-questions.html
https://career.guru99.com/top-50-unix-interview-questions/
http://www.folkstalk.com/2011/12/101-examples-of-using-find-command-in.html
###################################################################################
###############################
The cmp command tells you if two files are different and where the first difference
appears.
Here's an example comparing text files:
###################################################################################
###############################
For most of us, this use of diff is probably not something we'd do very often.
If you only want to know if the files are different, you can try a simpler
approach.
###################################################################################
###############################
The diff3 command works a lot like diff, but allows you to compare three files
instead of only two.
However, this command doesn't have all the options that the diff has and, no,
there's no diff4, diff5, etc.
Comparing files two at a time with your favorite comparison tool is probably a
better strategy most of the time.
$ diff3 file1 file2 file3
###################################################################################
###############################
cksum:
Checksums can also tell you if files are different.
While this might not be advantageous when the files are on the same system,
it can help a lot when they're on different systems.
By running the cksum command on each of the two systems,
you can determine if they're the same without having to move either of the files to
the other system or share a file system or directory.
Note that the cksum command is often used to verify the integrity of system files.
###################################################################################
###############################
The comm command will display the differences in text files in a different format.
In the example below, you can probably see that we're looking at three separate
columns of output.
The first and second represent the first and second files.
The third shows the lines which are the same in both of the two files.
###################################################################################
###############################
For most of us, this use of diff is probably not something we'd do very often.
If you only want to know if the files are different, you can try a simpler
approach.
mkdir
Make Directory - ie. Create a directory.
rmdir
Remove Directory - ie. Delete a directory.
touch
Create a blank file.
cp
Copy - ie. Copy a file or directory.
mv
Move - ie. Move a file or directory (can also be used to rename).
rm
Remove - ie. Delete a file.
###################################################################################
###############################