Monday, March 1, 2021

Top 25 UNIX commands interview question and answer for SDET

 




1. How to get the current directory?

 - pwd

2. How to create a new directory?

- Mkdir folder1


3. How to change or navigate to a particular directory?

Cd folder1           --à moving to folder


4. How to Navigate to HOME directory ?

Cd ~         -à to move to home dir


5. How to move to one level up or directory up ?

Cd ..


6. How to create a new file ?

Vi ab.txt

Cat > abcd.txt


7. How to display the file content ?

Cat ab.txt


8. How to join two files (file1, file2) and stores the output in a new file (file3) ?

Cat ab.txt abcd.txt>RenameFile -----à it will merge and create new filr RenameFile


9. How to Rename a file ?

mv ab.txt abReame.txt


10. How to Lists all files and directories?

ls


11. How to list files in sub-directories?

ls-R


12. How to list hidden files?

ls-a

ls-ltr


13. How to delete a file?

rm cd.txt      --àdeleting cd.txt file


14. How to remove directory with files?

rm -rf folder1/


15. How to copy a file from one location to a new location?

Cp abRename.txt /home/swapnil358/folder1 ----

or

Cp abRename.txt ./folder1


16. How to copy contents of a folder?

Cp –R folder1/ . /folder2           --Copyig content of folder 1 to folder2


17. How do you find out all processes that are currently running?

Ps -f


18. How do you kill a process?

Kill -pid


19. What would you use to view contents of a large error log file?

tail -10 fileName


20. How do you log in to a remote Unix box ?

telnet or ssh command to login to unit box


21. How do you start a job on background?

bg%1------à1 – is job id


22. How do you know if a remote host is alive or not?

ping or telnet


23. How do you copy a file from one server to your local system?

scp -S


24. How to search a word inside a file?

grep –w this *    -àit will search this word in current dir

or

grep java book.txt    --> it will search 'java' in book.txt


25. What is “chmod” command?

Chmod -777 abRename.txt   ---àIt will give rwx(read,write and execute) permission

Chmod 400 abRename.txt -à it will give read only permission


26. Filter command

ls -d abc*   # list all files starting with abc---
ls -d *abc*  # list all files containing --abc--
ls -d *abc   # list all files ending with --abc


27. How to find the file?

1. find . -name thisfile.txt

If you need to know how to find a file in Linux called thisfile.txt, it will look for it in current and sub-directories.

2. find /home -name *.jpg

Look for all .jpg files in the /home and directories below it.

3. find . -type f -empty

Look for an empty file inside the current directory.

4. find /home -user randomperson-mtime 6 -iname ".db"

Look for all .db files (ignoring text case) that have been changed in the preceding 6 days by a user called randomperson.








No comments:

Post a Comment

How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post