Advertisements
Home > Interview Q, Linux, Others > Basic UNIX/Linux commands for Interview Questions – Part 1

Basic UNIX/Linux commands for Interview Questions – Part 1


Some basic UNIX/Linux commands:
… from College notes !
 

Q1. Start UNIX/Linux while logging in remotely to telnet

Ans: [student@localhost student]$ telnet 192.168.0.4
 

Q2. Enter the user name as student and password as student.

Ans: [student@localhost student]$
 

Q3. Display all files starting with a dot and filename more than three characters.

Ans: [student@localhost student]$ ls .???*
 

Q4. Create files chap01,chap02,chap05,chap07,chap*,chap[0-3]

Ans: [student@localhost student]$ cat > chap01
[student@localhost student]$ cat > chap02
[student@localhost student]$ cat > chap05
[student@localhost student]$ cat > chap07
[student@localhost student]$ cat > chap0*
 

Q5. Display all files starting with an alphabet irrespective of the case.

Ans: [student@localhost student]$ ls [a-Za-z]*
 

Q6. Try the command pwd to see the present working directory

Ans: [student@localhost student]$ /home/student
 

Q7. Create files namely abc.txt ,aby.txt ,xdf ,x02,x04,ab4.

Ans: [student@localhost student]$ cat > abc.txt
[student@localhost student]$ cat > aby.txt
[student@localhost student]$ cat > xdf
[student@localhost student]$ cat > x02
[student@localhost student]$ cat > x04
[student@localhost student]$ cat > ab4
 

Q8. Display the files starting with a or t and second character b or x and length of the files should be only 3 characters.

Ans: [student@localhost student]$ ls [a,t][b,x]?
 

Q9. Create directories namely dir1,dir2,dir3

Ans: [student@localhost student]$ mkdir dir1,dir2,dir3.
 

Q10. Create three files in each of the directory.

Ans: [student@localhost student]$ cat > /home/student/dir1/file01
[student@localhost student]$ cat > /home/student/dir2/file02
[student@localhost student]$ cat > /home/student/dir3/file03
 

Q11. Copy all the files from these directories to the current directory.

Ans: [student@localhost student]$
 

Q12. Copy recursively the three directories include , bin, lib from / to directory.

Ans: [student@localhost student]$ cp –R { nitin1,nitin2,nitin3 }
/home/student/kap

 
Q13. Remove the file chap*

Ans: [student@localhost student]$ rm chap*
 

Q14. Display the file contents of file chap[0-3].

Ans: [student@localhost student]$ cat chap[0-3]
 

Q15. Create a file hello.

Ans: [student@localhost student]$ cat > hello
 

Q16. Create a hard link of the file hello name it as hai.

Ans: [student@localhost student]$ ln hello hai
 

Q17. Display the listing of both hello and hai files along either their i-node number.

Ans. [student@localhost student]$ ls –i hello hai
 

Q18. Create the symbolic link of file hello as hellohai

Ans. [student@localhost student]$ ln –s hello hai
 

Q19. Display the listing of both hello and hellohai files along with their i-node number.

Ans. [student@localhost student]$ ls –i hello hellohai
 

Q20. Display the process status of all the processes running on linux.

Ans. [student@localhost student]$ ps
 

Q21. Display the hidden files and also marked them as executable and directory.

Ans. [student@localhost student]$ ls –Fa
 

Q22. Display all the directories, sub- directories and files.

Ans. [student@localhost student]$ls -R
 

Q23. Create a file name in file at 3 to 4 line of text to it.

Ans. [student@localhost student]$cat >infile
 

Q24. Count number of lines, words and characters in the filename infile.

Ans. [student@localhost student]$wc –lwm infile
 

Q25. Count number of words in infile with and without redirection.

Ans. [student@localhost student]$wc –w<infile
 

Q26. In a single command except data as well as display contents of the file infile.

Ans. [student@localhost student]$cat infile –
 

Q27. Display all the files starting with an alphabetic irrespective of the case.

Ans. [student@localhost student]$ls [a-zA-Z]*
 

Q28. Display the number of users logged on.

Ans. [student@localhost student]$who | wc-l
 

Q29. Display the number of files present in the current directory.

Ans. [student@localhost student]$ls –l | wc-l
 

Q30. Count number of bytes of all the .c files individually present in the current directory.

Ans. [student@localhost student]$wc –c *.c
 

Q31. Count total number of bytes of all the .c files present in the current directory.

Ans. [student@localhost student]$wc –c *.c | tail -1 –
 

Q32. Display the statement as there are _ files in the current directory using command substitution.

Ans. [student@localhost student]$echo “There are `ls –l –R | wc –l` files in current dir.”
 

Q33. Try the two statement echo the average pay is $1000
echo ‘the average pay is $1000’
echo “the average pay is $1000”

Ans. [student@localhost student]$echo ‘the average pay is $1000’
the average pay is $1000
echo “the average pay is $1000”
the average pay is 000
 

Q34. Create a shell variable as work and store the present working directory in it and display the same.

Ans. [student@localhost student]$ work=`pwd`
 

Q35. Try the command cat alone without using an argument.

Ans. [student@localhost student]$cat
(With only cat command with no file name it only read standard input.)
 

Check [Part-2] for next set of Questions.
 


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: