Software testing – Questions and Answers – Linix / Unix
Q. How do you list files in a directory?
ls – list directory contents
Q. How do you list all files in a directory, including the hidden files?
ls -a (-a, do not hide entries starting with.)
Q. How do you find out all processes that are currently running?
ps -f (-f does full-format listing.)
Q. How to copy file into directory?
cp /tmp/file_name . (dot mean in the current directory)
Q. How to remove directory with files?
Q. 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)
Q. How do you kill a process?
The syntax for kill is
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)
Q. What would you use to view contents of the file?
The head Command
The head command displays the beginning of a file. The format of the head command is:
By default, you can only read the first ten lines of a file. You can change the number of lines displayed by specifying a number option.
head -20 <filename>
The above command would display the first 20 lines of a file named <filename>.
The tail Command
The reverse of head is tail. Using tail, you can view the last ten lines of a file. This can be useful for viewing the last ten lines of a log file for important system messages. You can also use tail to watch log files as they are updated. Using the -f option, tail automatically prints new messages from an open file to the screen in real-time. For example, to actively watch /var/log/messages, enter the folowing at a shell prompt (as the root user):
tail -f /var/log/messages
Press [Ctrl]-[C] when you are finished.
The more Command
The more command is a “pager” utility used to view text in the terminal window one page or screen at a time. The [Space] bar moves forward one page and [Q] quits.
Viewing Files with less
The format of the less command is:
The main difference between more and less is that less allows backward and single-line movement using the same navigation as man pages: press the [Space] bar to go down one page, the [B] to go back one page, the directional (or “arrow”) keys to move one line at a time, and [Q] to quit.
To search the output of a text file using less, press [/] and enter the keyword to search for within the file.
The above command would search through the file for all instances of “stuff” and highlight them in the text.
Viewing and creating files with cat
The cat command is a versatile utility. It can be used to view text, to create text files, and to join files. Its name is short for concatenate, which means to combine files.
Using cat alone echoes on the screen any text you enter. It will continue to do so until you exit with the [Ctrl]-[D] keystroke.
Entering the cat command followed by a file name displays the entire contents of the file on the screen. If the file is long, the contents scroll off the screen. You can control this by using the redirection techiniques that are discussed in Section 4.9 Manipulating Information from the Shell.
The grep Command
The grep command is useful for finding specific character strings in a file. For example, to find every reference made to “pattern” in the file <filename>, enter:
grep pattern <filename>
Each line in the file that includes the pattern “pattern” is located and displayed on the screen
Q. What would you use to edit contents of the file?
vi screen editor, gEditor, Nano Editor, Emacs Editor,
Q. What would you use to view contents of a large error log file?
tail -10 file_name ( last 10 rows)
Q. How do you log in to a remote Unix box?
Using telnet server_name or ssh -l ( ssh – OpenSSH SSH client (remote login program))
Q. How do you get help on a Linux terminal?
-h or –help
If you’re not sure how to use a specific command, run the command with the -h or –helpswitches. You’ll see usage information and a list of options you can use with the command. For example, if you want to know how to use the wget command, type wget –help or wget -h.
Q. How do you list contents of a directory including all of its subdirectories, providing full details and sorted by modification time?
-a all entries
-c by time
Q. 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.
Q. How do you get its usage (a filesystem)?
By storing and manipulate files.
Q. How do you check for processes started by user ‘pat’?
ps -fu pat (-f -full_format u -user_name )
Q: Which command to remove or delete a file in your directory?
rm command is used to remove or delete a file in your directory.
Q: How do you add a user?
“adduser newuser” command will create a new general user called “newuser” on your system, and to assign a password for the newuser account use “passwd newuser”.
Q. How do you start a job on background?
bg command is used to run the background job.
#bg%1 (job 1)
#bg%2 (job 2)
#bg%n (job n)
Note: In the same way fg command is used to run the foreground job
Q. 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.
Q. List the three main parts of an operating system command:
The three main parts are the command, options and arguments.