1a) How to find out the number of hard links to a regular file? In your answer,
ID: 3880954 • Letter: 1
Question
1a) How to find out the number of hard links to a regular file? In your answer, clearly state the command needed for this task and how this command should be used here. State where you can find the number of hard links in the output of this command.
1b) Using only the following UNIX commands: grep, ls, cat and wc, develop a single command line (regular expressions) to perform the task required. You dont need to use all commands List all the files in /usr/bin whose filenames contain lowercase English alphabet characters only and also contain the word file as a (contiguous) substring. For example, file and nsrfile are such files, but grub2-file is not.
Explanation / Answer
Hi,
Ans 1a) The command used to see and count the number of hard links to a file is -
ls -l file_name
ls is used for listing the files. The option -l is used to count the number of links found for the file. The output gives us a number which is actually the link-count of the file, when referring to a file, or the number of contained directory entries,
Ans 1b) Below is the code which involves a pattern matching-
ls /usr/bin | grep '^[a-z]*file$'
the grep comand is used to search if the string contains only alplabets from is used to indicate'a' to 'z'
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.