Ques.26. What is the purpose of 'touch' command?
Ans. Touch command serve two purpose in Linux-
Ques.27. What is the difference between 'cp' and 'mv' command?
Ans. The 'cp' command is used to copy content of one file to another. Whereas, 'mv' command moves a file from one location to another, deleting the source file. 'mv' command is also used for renaming files. Usage-
Ques.28. Explain the usage of 'head' and 'tail' commands.
Ans. Head command is used to display first few lines(default 10) of a file. Whereas, tail is used to display last few lines(default 10) of a file. Usage-
Ques.29. What is 'sed' in Linux?
Ans. Sed stands for Stream Editor. It is used to edit a file or input from a pipeline. Example-
Ques.30. How to print content of line 5 to 10 from one file to another?
Ans. Using 'sed'
Ques.31. What is 'awk'?
Ans. AWK named after the initials of its authors "Aho, Weinberger, and Kernighan", is an interpreted programming language for text processing. Usage-
Ques.32. How to count the number of words, lines and characters in a file?
Ans. Using wc command (word count)-
Ques.33. How to combine the content of multiple files into a single file?
Ans. Using 'cat' and redirection-
Ques.34. What is use of 'tac' command?
Ans. Tac command as the name suggests, is the reverse of 'cat' command. It displays the content of file in reverse order - line by line, displaying the last line first and moving up till the first line.
Ques.35. What is difference between 'more' and 'less' command?
Ans. Both more and less commands are used for viewing large files page wise. Unlike any editor like vi, using these commands for opening a file does not load the whole file in memory. One limitation of more command is, we can only scroll down but not up. Whereas, using less command, we can scroll both upwards and downwards in a file.
Ques.36. How can we find the top 3 space consuming file or directories within a directory?
Ans. Using du(disk usage) command, we can find the disk usage of all directories and sub-directories. Using du with -a option, will list the disk usage of all files as well, along with the directories. The '-h' option displays the size in human readable form. Later, we can use this command along with sort and head command, to first sort the files/directories by size and then fetch the required number of files.
Ques.37. How to create aliases in Linux?
Ans. Aliases are used to create aliases or some abbreviated short-name for a command or a group of commands.
Ques.38. What is the use of shred utility? How it is different from rm command?
Ans. Shred utility is used for deleting the content of file in a such a way that the content cannot be recovered using some data recovery tools/utilities. Whereas, when we delete a file using rm command, the space taken by the file is marked available for other files, hence there is possibility to recover the content of the file. Thus, shred is better for deleting files with sensitive data.
Ques.39. What is the difference between find and locate command?
Ans. Both find and locate commands are used for searching files on Linux. The 'find' command searches file in real time and thus take longer time to return the search result in case there are too many files to scan through. Whereas, 'locate' command is much faster than find as instead of real time search it looks up in a database - updatedb. Since, the updatedb takes snapshot of the file system only once a day output of locate is not always accurate or updated.
Ques.40. How can we introduce wait time in scripts?
Ans. Sleep command can be used to introduce wait time in scripts. We can specify wait in terms of seconds, minutes, hours and days.
Ques.41. How to compress and decompress files in Linux?
Ans. Using 'zip' and 'unzip' commands, we can compress and decompress files in Linux.
Ques.42. What are the different file permissions or access modes in Linux?
Ans. Each file and directory in Linux can have following 3 permissions, represented by a three digit octal number-
Ques.43. Explain the meaning of the permission mode "drwxr-x--x".
Ans. The 10 characters of permission mode provides information about the permission to the user, group and other users.
So, the permission mode "drwxr-xr-x", means a directory for which the user have all the read-write-excute permission, group has read and execute permission and other users can only execute the file.
Ques.44. How can we grant or remove access to a file in Linux?
Ans. The 'chmod' command is used to grant permission to a file or directory in Linux. There are two modes to grant or remove permission using chmod-
Ques.45. Explain the octal number representation for different permission types in Linux.
Ans. The absolute permission of chmod uses an octal number. The different octal numbers for different permission types are-
|Octal number||Permission granted|
|0||No permission (---) i.e. 0+0+0=0|
|1||Execute (--x) i.e. 0+0+1=1|
|2||Write (-w-) i.e. 0+2+0=2|
|3||Write and execute (-wx) i.e. 0+2+1=3|
|4||Read (r--) i.e. 4+0+0=4|
|5||Read and execute (r-x) i.e. 4+0+1=5|
|6||Read and write (rw-) i.e. 4+2+0=6|
|7||Read, write and execute (rwx) i.e. 4+2+1=7|
Ques.46. How can we change ownership and group ownership of a file in Linux?
Ans. The 'chown' command (change owner) is used to change the ownership of a file.
The 'chgrp' command is used to change the group ownership of a file.
Ques.47. How to sort the contents of a file?
Ans. Sort command can be used to sort the elements of a file line wise.
Ques.48. How can we remove the duplicates in a file?
Ans. Using 'uniq' utility with 'sort' command.
Ques.49. What are soft links in Linux? What are its advantage over cp command?
Ans. Soft links are also known as symbolic links or symlinks. These are used to create a symbolic links or pointers to a file. In Linux, soft links are created using 'ln' command with '-s' option.
It has got advantage over cp command (which creates a new copy of the file) in the sense that in order to change the permission to the files, with links only the permission of the original file need to be changed. Whereas, with cp command, the permission to all the copies of the file need to be changed.
Ques.50. What are hard links in Linux? How it is different from soft link?
Ans. Hard links are like another name for an existing file. Instead of pointing to a name(like soft link), hard links point to the content of the file directly(point to inode - a table containing metadata about a file).
It is different from soft link in the sense that in case the original files gets deleted its symbolic link will not point to anything and thus lead to "No such file or directory" error. Whereas, the hard link will still point to the content of the original file even if the file gets deleted.