970_90

Tuesday, 21 April 2015

Unix Commands Interview Questions and Answers for beginner

Unix Commands Interview Questions and Answers for beginner


Question: How to create shell script file?
Follow the simple steps to create first shell script file.
1. Login to putty console with your username/password.
2. Now go inside directory where you want to create the shell script files.
3. type following command to create text file.
vi test1
Now, you are in vi editor mode.
4. Type following script inside editor.
echo "Hello World"

5. Now get out of this vi editor using :wq
6. Now execute your file.
sh test1
7.It should print "Hello World" in output


Question: How can I concatenate two string variables in shell script file?
a="Hello World,"
b=" How r u?"
c=$a$b;
echo $c;#Hello World, How r u?



Question: Give me few examples of Grep command?
Example 1: Search text in file.
grep  "Hello" test.txt

"Hello" -is text, which you want to search.
test.text -It is file where u r searching.

Example 2:Search text in multiple files.
grep "Hello" test_*

"Hello" -is text, which you want to search.
test_* -It means search in all the files which start with test_

Example 3:Search text in file with insensitive.
grep -i "Hello" test.txt
"Hello" -is text, which you want to search.
test_* -It means search in all the files which start with test_

Example 4: Search text recursively in all files.
grep -r "Hello" *
-r: It is option used to search recursively in all sub folder.
"Hello" -is text, which you want to search.
* -Search in all current directory



Question: How to get all cron job for all users?
create empty text file and add following code in that file.
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done
Now, just execute the file
sh filename
It will list all the cron job for all user.


Question: What is difference between sh and bash?
Sh: Shell Command is a programming language described by the POSIX standard.
blash: In Starting, bash was also sh compatible but Now it is NOT due to in-valid POSIX shell.


Question: How can I "Reverse the order of lines" in a file?
tail -r text.txt



Question: How to download a file from SSH?
You can copy the file from server to another public directory, from there you can download with FTP/SFTP.
scp [email protected]:file.txt /path/to/dir

This command, put the file.txt to "path/to/dir", From this directory you can download.


Question: What is difference between Soft link and Hard link?
Soft Link: soft or symbolic is just a short cut to the original file. If we delete one or more soft link, nothing happens.
Hard link: It is multiple paths to the same file.


Question: How to set screen names with GNU screen?
screen -S foo



Question: How to get full path of a file?
readlink -f test.txt



Question: How to permanently set $PATH on Linux?
You need to add it to your ~/.profile file.
export PATH=$PATH:/path/to/directory



Question: How to list all the files/directory with permission?
 ls -l



Question: How to get the current folder path?
pwd



Question: How can I copy the output of a command directly into my clipboard?
cat file | xclip





No comments:

Post a Comment