Linux / Shell interview questions
1. Write a command that will look for files with anextension “c”, and has the occurrence of the string “apple” in it.
Find ./ -name “*.c” | xargs grep –i “apple”
2. Xargs 代替一堆parameters,就是把之前的参数都在这次传进来,比如你想rm一堆你你find到的文件,likethis:rm`find /path -type f`。但是这样会报错,参数太多,所以需要改成这样find/path -type f -print0 | xargs -0 rm。记住:单纯的”|”是不管用的,因为是rm sth而不是sth->命令,所以”|”没用。
3. Valid Phone Number:
cat file.txt | grep -E "^(([0-9]{3})|[0-9]{3}-)[0-9]{3}-[0-9]{4}$"
4. Let’s say you maintains a backup on regularbasis for the company you are working. The backups are maintained in Compressedfile format. You need to examine a log, two months old. What would you suggestwithout decompressing the compressed file?
5. # zcat f phpshell2.4.tar.gz
6. You need to track events on your system. Whatwill you do?
Running ‘syslogd‘ application in terminalgenerates log file at the location ‘/var/log/syslog‘. The syslogd applicationis very useful in troubleshooting Linux sytems. A sample log file looks similarto below.
7. Telnet and SSH both are communication protocolwhich are used to manage remote system. SSH is Secured, which requiresexchanging of key opposite of telnet which transmit data in plain text, whichmeans telnet is less secure than SSH.
8. You need to search for the string “Tecmint” in allthe “.txt” files in the current directory. How will you do it?
9. # find -name “*.txt” | xargs grep “Tecmint”