Linux Basic Interview Questions
Linux
1 . How do you list files in a directory?
ls - list directory contents
ls -l (-l use a long listing format)
2 . How do you list all files in a directory, including the hidden files?
ls -a (-a, do not hide entries starting with .)
3 . How do you find out all processes that are currently running?
ps -f (-f does full-format listing.)
4 . How do you find out the processes that are currently running or a particular user?
ps -au Myname (-u by effective user ID (supports names)) (a - all users)
5 . How do you kill a process?
kill -9 8 (process_id 8) or kill -9 %7 (job number 7)
kill -9 -1 (Kill all processes you can kill.)
killall - kill processes by name most (useful - killall java)
6 . What would you use to view contents of the file?
less filename
cat filename
pg filename
pr filename
more filename
most useful is command: tail file_name - you can see the end of the log file.
7 . What would you use to edit contents of the file?
vi screen editor or jedit, nedit or ex line editor
8 . What would you use to view contents of a large error log file?
tail -10 file_name ( last 10 rows)
9 . How do you log in to a remote Unix box?
Using telnet server_name or ssh -l ( ssh - OpenSSH SSH client (remote login program))
10 . How do you get help on a UNIX terminal?
man command_name
info command_name (more information)
11 . How do you list contents of a directory including all of its subdirectories, providing full details and sorted by modification time?
ls -lac
-a all entries
-c by time
12 . How do you create a symbolic link to a file (give some reasons of doing so)?
ln /../file1 Link_name
Links create pointers to the actual files, without duplicating the contents of
the files. That is, a link is a way of providing another name to the same file.
There are two types of links to a file:Hard link, Symbolic (or soft) link;
13 . What is a filesystem?
Sum of all directories called file system.
A file system is the primary means of file storage in UNIX.
File systems are made of inodes and superblocks.
14 . How do you get its usage (a filesystem)?
By storing and manipulate files.
15 . How do you check the sizes of all users� home directories (one command)?
du -s
df
The du command summarizes disk usage by directory. It recurses through all subdirectories and shows disk usage by each subdirectory with a final total at the end.
Q. in current directory
A. ls -ps (p- directory; s - size)
16 . How do you check for processes started by user 'pat'?
ps -fu pat (-f -full_format u -user_name )
17 . How do you start a job on background?
bg %4 (job 4)
18 . What utility would you use to replace a string '2001' for '2002' in a text file?
Grep, Kde( works on Linux and Unix)
19 . What utility would you use to cut off the first column in a text file?
awk, kde
20 . How to copy file into directory?
cp /tmp/file_name . (dot mean in the current directory)
21 . How to remove directory with files?
rm -rf directory_name
22 . What is the difference between internal and external commands?
Internal commands are stored in the; same level as the operating system while external
commands are stored on the hard disk among the other utility programs.
23 . List the three main parts of an operating system command:
The three main parts are the command, options and arguments.
24 . What is the difference between an argument and an option (or switch)?
An argument is what the command should act on: it could be a filename,
directory or name. An option is specified when you want to request additional
information over and above the basic information each command supplies.
25 . What is the purpose of online help?
Online help provides information on each operating system command, the
syntax, the options, the arguments with descriptive information.
26 . Name two forms of security.
Two forms of security are Passwords and File Security with permissions specified.
27 . What command do you type to find help about the command who?
$ man who
28 . What is the difference between home directory and working directory?
Home directory is the directory you begin at when you log into the
system. Working directory can be anywhere on the system and it is where you are currently
working.
29 . Which directory is closer to the top of the file system tree, parent directory or current directory?
The parent directory is above the current directory, so it is closer to
the root or top of the
file system.
30 . Given the following pathname: $ /business/acctg/payable/supplier/april a) If you were in the directory called acctg, what would be the relative pathname name for the file called april? b) What would be the absolute pathname for april?
a) $ payable/supplier/april
b) $ /business/acctg/payable/supplier/april
31 . Suppose your directory had the following files: help. 1 help.2 help.3 help.4 help.O1 help.O2 aid.O1 aid.O2 aid.O3 back. 1 back.2 back.3 a) What is the command to list all files ending in 2? b) What is the command to list all files starting in aid? c) What is the command to list all "help" files with one character extension?
a) ls *2
b) ls aid.*
c) ls help.?
32 . What are two subtle differences in using the more and the pg commands?
With the more command you display another screenful by pressing
the spacebar, with pg you press the return key.
The more command returns you automatically to the UNIX
shell when completed, while pg waits until you press return.
33 . When is it better to use the more command rather than cat command?
It is sometimes better to use the more command when you are viewing
a file that will display over one screen.
34 . What are two functions the move mv command can carry out?
The mv command moves files and can also be used to rename a file or directory.
35 . Name two methods you could use to rename a file.
Two methods that could be used:
a. use the mv command
b. copy the file and give it a new name and then remove the original file if no longer needed.
36 . The soccer league consists of boy and girl teams. The boy file names begin with B, the girl teams begin with G. All of these files are in one directory called "soccer", which is your current directory: Bteam.abc Bteam.OOl Bteam.OO2 Bteam.OO4 Gteam.win Gteam.OOl Gteam.OO2 Gteam.OO3 Write the commands to do the following: a) rename the file Bteam.abc to Bteam.OO3. b) erase the file Gteam. win after you have viewed the contents of the file c) make a directory for the boy team files called "boys", and one for the girl team files called" girls" d) move all the boy teams into the "boys" directory e) move all the girl teams into the "girls" directory f) make a new file called Gteam.OO4 that is identical to Gteam.OOl g) make a new file called Gteam.OO5 that is identical to Bteam.OO2
a) mv Bteam.abc Bteam.OO3.
b) cat Gteam.win -or- more Gteam.win
rm Gteam. win
c) mkdir boys
mkdir girls
d) mv Bteam* boys
e) mv Gteam* girls
f) cd girls
cp Gteam.OO1 Gteam.OO4
g) There are several ways to do this. Remember that we are currently in the directory
/soccer/girls.
cp ../boys/Bteam.OO2 Gteam.OO5
or
cd ../boys
cp Bteam.OO2 ../girls/Gteam.OO5
37 . What metacharacter is used to do the following: 1.1 Move up one level higher in the directory tree structure 1.2 Specify all the files ending in .txt 1.3 Specify one character 1.4 Redirect input from a file 1.5 Redirect the output and append it to a file
1. 1.1 double-dot or ..
1.2 asterisk or *
1.3 question or ?
1.4 double greater than sign: >>
1.5 the less than sign or <
38 . List all the files beginning with A
To list all the files beginning with A command: ls A*
39 . Which of the quoting or escape characters allows the dollar sign ($) to retain its special meaning?
The double quote (") allows the dollar sign ($) to retain its special meaning.
Both the backslash (\) and single quote (') would remove the special meaning of the dollar sign.
40 . What is a faster way to do the same command? mv fileO.txt newdir mv filel.txt newdir mv file2.txt newdir mv file3.txt newdir
A shortcut method would be: mv file?.txt newdir
41 . List two ways to create a new file:
a. Copy a file to make a new file.
b. Use the output operator e.g. ls -l > newfile.txt
42 . What is the difference between > and >> operators?
The operator > either overwrites the existing file (WITHOUT WARNING) or creates a new file.
The operator >> either adds the new contents to the end of an existing file or creates a new file.
43 . Write the command to do the following: 1. Redirect the output from the directory listing to a printer. 2. Add the file efg.txt to the end of the file abc.txt. 3. The file testdata feeds information into the file called program 4. Observe the contents of the file called xyz.txt using MORE. 5. Observe a directory listing that is four screens long.
1. ls > lpr
2. cat efg.txt >> abc.txt
3. program < testdata
4. more < xyz.txt
5. ls > dirsave | more
44 . How do you estimate file space usage
Use du command (Summarize disk usage of each FILE, recursively for
directories.) Good to use arguments du -hs
(-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
(-s, --summarize display only a total for each argument)
45 . How can you see all mounted drives?
mount -l
46 . How can you find a path to the file in the system?
locate file_name (locate - list files in databases that match a pattern)
47 . What Linux HotKeys do you know?
Ctrl-Alt-F1 Exit to command prompt
Ctrl-Alt-F7 or F8 Takes you back to KDE desktop from command prompt
Crtl-Alt-Backspace Restart XWindows
Ctrl-Alt-D Show desktop
48 . What can you tell about the tar Command?
The tar program is an immensely useful archiving utility. It can combine
an entire directory tree into one large file suitable for transferring or
compression.
49 . What types of files you know?
Files come in eight flavors:
Normal files
Directories
Hard links
Symbolic links
Sockets
Named pipes
Character devices
Block devices
50 . How to copy files from on PC to another on the same network
Use the following command:scp yur_file you_login@your_IP
example: copy .conf file from your PC to king computer-
scp /etc/X11/xorg.conf king@10.0.3.156:
51 . Please describe information below: -rw-rw-r-- 1 dotpc dotpc 102 Jul 18 2003 file.buf drwxr-xr-x 9 dotpc dotpc 4096 Oct 21 09:34 bin lrwxrwxrwx 1 dotpc dotpc 20 Mar 21 15:00 client -> client-2.9.5 drwxrwxr-x 11 dotpc dotpc 4096 Sep 2 2005 client-2.8.9 drwxrwxr-x 7 dotpc dotpc 4096 Dec 14 12:13 data drwxr-xr-x 12 dotpc dotpc 4096 Oct 21 09:41 docs drwxr-xr-x 5 dotpc dotpc 4096 Dec 7 14:22 etc drwxr-xr-x 11 dotpc dotpc 4096 Mar 21 15:54 client-2.9.5 -rw-r--r-- 1 dotpc dotpc 644836 Mar 22 09:53 client-2.9.5.tar.gz
This is a result of command $ls -l
we have two files, 6 directories and one link to client-2.9.5 directory.
There is number of files in every directory, size and data of last change.
52 . If you would like to run two commands in sequence what operators you can use?
; or && the difference is:
if you separate commands with ; second command will be run automatically.
if you separate commands with && second command will be run only in the case
the first was run successfully.
53 . How you will uncompress the file?
Use tar command (The GNU version of the tar archiving utility):
tar -zxvf file_name.tar.gz
54 . How do you execute a program or script, my_script in your current directoty?
./my_script
55 . How to find current time configuration in the file my_new.cfg
grep time my_new.cfg
Grep searches the named input files (or standard input if
no files are named, or the file name - is given) for lines
containing a match to the given pattern.
56 . What does grep() stand for?
General Regular Expression Parser.
57 . What does the top command display?
Top provides an ongoing look at processor activity in real
time. It displays a listing of the most CPU-intensive
tasks on the system, and can provide an interactive inter
face for manipulating processes. (q is to quit)
58 . How can you find configuration on linux?
by using /sin/ifconfig
If no arguments are given, ifconfig displays the status of the cur-
rently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argu-
ment is given, it displays the status of all interfaces, even those
that are down. Otherwise, it configures an interface.
59 . How to find difference in two configuration files on the same server?
Use diff command that is compare files line by line
diff -u /usr/home/my_project1/etc/ABC.conf /usr/home/my_project2/etc/ABC.conf
60 . What is the best way to see the end of a logfile.log file?
Use tail command - output the last part of files
tail -n file_name ( the last N lines, instead of the last 10 as default)
61 . Please write a loop for removing all files in the current directory that contains a word 'log'
for i in *log*; do rm $i; done
62 . How to switch to a previously used directory?
cd -
63 . How many VI editor modes do you know?
Three modes -
Command mode: letters or sequence of letters interactively command vi.
Insert mode: Text is inserted.
Command line mode: enter this mode by typing ":" and entry command line at the foot of the screen.
64 . How can you terminate VI session?
Use command: ZZ that is save changes and quit.
Use command line: ":wq" that is write changes and quit.
Use command line: ":q!" to ignore changes and quit.
65 . How can you copy lines into the buffer in command mode?
yy - copy a single line defined by current cursor position
3yy - copy 3 lines. Current line and two lines below it.
1 . How do you list files in a directory?
ls - list directory contents
ls -l (-l use a long listing format)
2 . How do you list all files in a directory, including the hidden files?
ls -a (-a, do not hide entries starting with .)
3 . How do you find out all processes that are currently running?
ps -f (-f does full-format listing.)
4 . How do you find out the processes that are currently running or a particular user?
ps -au Myname (-u by effective user ID (supports names)) (a - all users)
5 . How do you kill a process?
kill -9 8 (process_id 8) or kill -9 %7 (job number 7)
kill -9 -1 (Kill all processes you can kill.)
killall - kill processes by name most (useful - killall java)
6 . What would you use to view contents of the file?
less filename
cat filename
pg filename
pr filename
more filename
most useful is command: tail file_name - you can see the end of the log file.
7 . What would you use to edit contents of the file?
vi screen editor or jedit, nedit or ex line editor
8 . What would you use to view contents of a large error log file?
tail -10 file_name ( last 10 rows)
9 . How do you log in to a remote Unix box?
Using telnet server_name or ssh -l ( ssh - OpenSSH SSH client (remote login program))
10 . How do you get help on a UNIX terminal?
man command_name
info command_name (more information)
11 . How do you list contents of a directory including all of its subdirectories, providing full details and sorted by modification time?
ls -lac
-a all entries
-c by time
12 . How do you create a symbolic link to a file (give some reasons of doing so)?
ln /../file1 Link_name
Links create pointers to the actual files, without duplicating the contents of
the files. That is, a link is a way of providing another name to the same file.
There are two types of links to a file:Hard link, Symbolic (or soft) link;
13 . What is a filesystem?
Sum of all directories called file system.
A file system is the primary means of file storage in UNIX.
File systems are made of inodes and superblocks.
14 . How do you get its usage (a filesystem)?
By storing and manipulate files.
15 . How do you check the sizes of all users� home directories (one command)?
du -s
df
The du command summarizes disk usage by directory. It recurses through all subdirectories and shows disk usage by each subdirectory with a final total at the end.
Q. in current directory
A. ls -ps (p- directory; s - size)
16 . How do you check for processes started by user 'pat'?
ps -fu pat (-f -full_format u -user_name )
17 . How do you start a job on background?
bg %4 (job 4)
18 . What utility would you use to replace a string '2001' for '2002' in a text file?
Grep, Kde( works on Linux and Unix)
19 . What utility would you use to cut off the first column in a text file?
awk, kde
20 . How to copy file into directory?
cp /tmp/file_name . (dot mean in the current directory)
21 . How to remove directory with files?
rm -rf directory_name
22 . What is the difference between internal and external commands?
Internal commands are stored in the; same level as the operating system while external
commands are stored on the hard disk among the other utility programs.
23 . List the three main parts of an operating system command:
The three main parts are the command, options and arguments.
24 . What is the difference between an argument and an option (or switch)?
An argument is what the command should act on: it could be a filename,
directory or name. An option is specified when you want to request additional
information over and above the basic information each command supplies.
25 . What is the purpose of online help?
Online help provides information on each operating system command, the
syntax, the options, the arguments with descriptive information.
26 . Name two forms of security.
Two forms of security are Passwords and File Security with permissions specified.
27 . What command do you type to find help about the command who?
$ man who
28 . What is the difference between home directory and working directory?
Home directory is the directory you begin at when you log into the
system. Working directory can be anywhere on the system and it is where you are currently
working.
29 . Which directory is closer to the top of the file system tree, parent directory or current directory?
The parent directory is above the current directory, so it is closer to
the root or top of the
file system.
30 . Given the following pathname: $ /business/acctg/payable/supplier/april a) If you were in the directory called acctg, what would be the relative pathname name for the file called april? b) What would be the absolute pathname for april?
a) $ payable/supplier/april
b) $ /business/acctg/payable/supplier/april
31 . Suppose your directory had the following files: help. 1 help.2 help.3 help.4 help.O1 help.O2 aid.O1 aid.O2 aid.O3 back. 1 back.2 back.3 a) What is the command to list all files ending in 2? b) What is the command to list all files starting in aid? c) What is the command to list all "help" files with one character extension?
a) ls *2
b) ls aid.*
c) ls help.?
32 . What are two subtle differences in using the more and the pg commands?
With the more command you display another screenful by pressing
the spacebar, with pg you press the return key.
The more command returns you automatically to the UNIX
shell when completed, while pg waits until you press return.
33 . When is it better to use the more command rather than cat command?
It is sometimes better to use the more command when you are viewing
a file that will display over one screen.
34 . What are two functions the move mv command can carry out?
The mv command moves files and can also be used to rename a file or directory.
35 . Name two methods you could use to rename a file.
Two methods that could be used:
a. use the mv command
b. copy the file and give it a new name and then remove the original file if no longer needed.
36 . The soccer league consists of boy and girl teams. The boy file names begin with B, the girl teams begin with G. All of these files are in one directory called "soccer", which is your current directory: Bteam.abc Bteam.OOl Bteam.OO2 Bteam.OO4 Gteam.win Gteam.OOl Gteam.OO2 Gteam.OO3 Write the commands to do the following: a) rename the file Bteam.abc to Bteam.OO3. b) erase the file Gteam. win after you have viewed the contents of the file c) make a directory for the boy team files called "boys", and one for the girl team files called" girls" d) move all the boy teams into the "boys" directory e) move all the girl teams into the "girls" directory f) make a new file called Gteam.OO4 that is identical to Gteam.OOl g) make a new file called Gteam.OO5 that is identical to Bteam.OO2
a) mv Bteam.abc Bteam.OO3.
b) cat Gteam.win -or- more Gteam.win
rm Gteam. win
c) mkdir boys
mkdir girls
d) mv Bteam* boys
e) mv Gteam* girls
f) cd girls
cp Gteam.OO1 Gteam.OO4
g) There are several ways to do this. Remember that we are currently in the directory
/soccer/girls.
cp ../boys/Bteam.OO2 Gteam.OO5
or
cd ../boys
cp Bteam.OO2 ../girls/Gteam.OO5
37 . What metacharacter is used to do the following: 1.1 Move up one level higher in the directory tree structure 1.2 Specify all the files ending in .txt 1.3 Specify one character 1.4 Redirect input from a file 1.5 Redirect the output and append it to a file
1. 1.1 double-dot or ..
1.2 asterisk or *
1.3 question or ?
1.4 double greater than sign: >>
1.5 the less than sign or <
38 . List all the files beginning with A
To list all the files beginning with A command: ls A*
39 . Which of the quoting or escape characters allows the dollar sign ($) to retain its special meaning?
The double quote (") allows the dollar sign ($) to retain its special meaning.
Both the backslash (\) and single quote (') would remove the special meaning of the dollar sign.
40 . What is a faster way to do the same command? mv fileO.txt newdir mv filel.txt newdir mv file2.txt newdir mv file3.txt newdir
A shortcut method would be: mv file?.txt newdir
41 . List two ways to create a new file:
a. Copy a file to make a new file.
b. Use the output operator e.g. ls -l > newfile.txt
42 . What is the difference between > and >> operators?
The operator > either overwrites the existing file (WITHOUT WARNING) or creates a new file.
The operator >> either adds the new contents to the end of an existing file or creates a new file.
43 . Write the command to do the following: 1. Redirect the output from the directory listing to a printer. 2. Add the file efg.txt to the end of the file abc.txt. 3. The file testdata feeds information into the file called program 4. Observe the contents of the file called xyz.txt using MORE. 5. Observe a directory listing that is four screens long.
1. ls > lpr
2. cat efg.txt >> abc.txt
3. program < testdata
4. more < xyz.txt
5. ls > dirsave | more
44 . How do you estimate file space usage
Use du command (Summarize disk usage of each FILE, recursively for
directories.) Good to use arguments du -hs
(-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
(-s, --summarize display only a total for each argument)
45 . How can you see all mounted drives?
mount -l
46 . How can you find a path to the file in the system?
locate file_name (locate - list files in databases that match a pattern)
47 . What Linux HotKeys do you know?
Ctrl-Alt-F1 Exit to command prompt
Ctrl-Alt-F7 or F8 Takes you back to KDE desktop from command prompt
Crtl-Alt-Backspace Restart XWindows
Ctrl-Alt-D Show desktop
48 . What can you tell about the tar Command?
The tar program is an immensely useful archiving utility. It can combine
an entire directory tree into one large file suitable for transferring or
compression.
49 . What types of files you know?
Files come in eight flavors:
Normal files
Directories
Hard links
Symbolic links
Sockets
Named pipes
Character devices
Block devices
50 . How to copy files from on PC to another on the same network
Use the following command:scp yur_file you_login@your_IP
example: copy .conf file from your PC to king computer-
scp /etc/X11/xorg.conf king@10.0.3.156:
51 . Please describe information below: -rw-rw-r-- 1 dotpc dotpc 102 Jul 18 2003 file.buf drwxr-xr-x 9 dotpc dotpc 4096 Oct 21 09:34 bin lrwxrwxrwx 1 dotpc dotpc 20 Mar 21 15:00 client -> client-2.9.5 drwxrwxr-x 11 dotpc dotpc 4096 Sep 2 2005 client-2.8.9 drwxrwxr-x 7 dotpc dotpc 4096 Dec 14 12:13 data drwxr-xr-x 12 dotpc dotpc 4096 Oct 21 09:41 docs drwxr-xr-x 5 dotpc dotpc 4096 Dec 7 14:22 etc drwxr-xr-x 11 dotpc dotpc 4096 Mar 21 15:54 client-2.9.5 -rw-r--r-- 1 dotpc dotpc 644836 Mar 22 09:53 client-2.9.5.tar.gz
This is a result of command $ls -l
we have two files, 6 directories and one link to client-2.9.5 directory.
There is number of files in every directory, size and data of last change.
52 . If you would like to run two commands in sequence what operators you can use?
; or && the difference is:
if you separate commands with ; second command will be run automatically.
if you separate commands with && second command will be run only in the case
the first was run successfully.
53 . How you will uncompress the file?
Use tar command (The GNU version of the tar archiving utility):
tar -zxvf file_name.tar.gz
54 . How do you execute a program or script, my_script in your current directoty?
./my_script
55 . How to find current time configuration in the file my_new.cfg
grep time my_new.cfg
Grep searches the named input files (or standard input if
no files are named, or the file name - is given) for lines
containing a match to the given pattern.
56 . What does grep() stand for?
General Regular Expression Parser.
57 . What does the top command display?
Top provides an ongoing look at processor activity in real
time. It displays a listing of the most CPU-intensive
tasks on the system, and can provide an interactive inter
face for manipulating processes. (q is to quit)
58 . How can you find configuration on linux?
by using /sin/ifconfig
If no arguments are given, ifconfig displays the status of the cur-
rently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argu-
ment is given, it displays the status of all interfaces, even those
that are down. Otherwise, it configures an interface.
59 . How to find difference in two configuration files on the same server?
Use diff command that is compare files line by line
diff -u /usr/home/my_project1/etc/ABC.conf /usr/home/my_project2/etc/ABC.conf
60 . What is the best way to see the end of a logfile.log file?
Use tail command - output the last part of files
tail -n file_name ( the last N lines, instead of the last 10 as default)
61 . Please write a loop for removing all files in the current directory that contains a word 'log'
for i in *log*; do rm $i; done
62 . How to switch to a previously used directory?
cd -
63 . How many VI editor modes do you know?
Three modes -
Command mode: letters or sequence of letters interactively command vi.
Insert mode: Text is inserted.
Command line mode: enter this mode by typing ":" and entry command line at the foot of the screen.
64 . How can you terminate VI session?
Use command: ZZ that is save changes and quit.
Use command line: ":wq" that is write changes and quit.
Use command line: ":q!" to ignore changes and quit.
65 . How can you copy lines into the buffer in command mode?
yy - copy a single line defined by current cursor position
3yy - copy 3 lines. Current line and two lines below it.
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন