In: Computer Science
1. Give a command using find to search from the root directory the file program.f and redirect any errors to the file myerrors.txt
2. Give a command for finding files having the letters index as the beginning of the file name and located in your home directory (provide the absolute path)
3. Give a command for finding within a directory called /mp3collection, only those mp3 files that have a size less than 5000 Kilobytes (< 5MB).
4. Give a commmand that searches for those files that are present in the directory /home/david and its subdirectories which end in .c and which have been accessed in the last 10 minutes.
5. Give a command that searches within the directory /mp3-collection for files that have their names beginning with ’Metallica’ and whose size is greater than 10000 kilobytes (> 10 MB).
6. Give a command that searches in the same directory as above case but only for files that are greater than 10MB, but they should not have ’Metallica’ as the starting of their filenames.
7. Explain what the following commands do. What is the major difference between their outputs? a) chmod -R 755 . b) chmod -R 755 *
8. Explain the output of the following command:
pr -t -n -d -o 10 group12
9. Study the cut command and describe what is its function, provide some examples including options like -c, and -f.
10. What is the output of the following command?
sort -t: -k3,3 -n /etc/group
ANSWER 7: In the event that you wish to alter your Files/Directories ownership you can utilize the chmod command. We use chmod command in order to change the authorizations of a document in Unix. In this order we can pass the record authorizations as a three-digit number.
In this number 755, first digit 7 is the authorizations given to owner, second digit 5 is the authorization of group and third digit 5 is the authorizations of all others.
Likewise the numbers 7 and 5 are produced using keeping rules:
4 = read consent
2 = compose consent
1 = execute consent
So 7 = 4 + 2 + 1 = Read + Write + Execute consent
5 = 4 + 1 = Read + Execute consent (Consent means permissions)
Part a)
In our above example chmod -R 755 means, the owner has read, write and execute consents. Group and others have read and execute authorizations only.
Also the -R means changing records and directories recursively.
Therefore, the command "chmod - R 755 myfiles" means "Recursively (- R) Change the authorizations of the directory myfiles, and all files and folders it contains, to mode 755 where User can read, write, and execute; group members and different clients can read and execute, however can't write."
Part b)
Linux enables you to utilize wild cards, shown with an indicator * to carry out an activity on a gathering of documents:
For e.g - chmod 755 *.cgi .
Here, we've advised Linux to set permissions on all records in the directory that end with .cgi
ANSWER 8: On Unix-like OS, the pr command arranges a file to make it look better when printed. pr paginates FILE(s) for printing.
ANSWER 9: The cut order separates a given number of characters or sections from a document. For cutting a specific number of sections it is essential to determine the delimiter. A delimiter determines how the sections are isolated in a book document.
syntax : cut [options] [filename]
- c (section): To cut by character utilize the - c alternative. This chooses the characters given to the - c choice. This can be a rundown of numbers isolated comma or a scope of numbers isolated by hyphen(- ). Tabs and deletes are treated as a character. It is important to determine rundown of character numbers else it gives blunder with this alternative.
e.g. => $ cut -c 5-10 file1 : This command will extract characters 5 to 10 from each line.
- f (field): - c alternative is helpful for fixed-length lines. Most unix records doesn't have fixed-length lines. To remove the valuable data you have to cut by fields as opposed to segments. Rundown of the fields number determined must be isolated by comma. Extents are not depicted with - f alternative. cut uses tab as a default field delimiter yet can likewise work with other delimiter by utilizing - d choice. Note: Space isn't considered as delimiter in UNIX.
e.g. => For delimiter separated fields, the -d option is used. The default delimiter is the tab character.
$ cut -d “,” -f 2,6 file1 : This command will extract the second and sixth field from each line, using the ‘,’ character as the delimiter.
ANSWER 10:
SORT command is utilized to sort a document, masterminding the records in a specific request. As a matter of course, the sort direction sorts document accepting the substance are ASCII. Utilizing alternatives in sort direction, it can likewise be utilized to sort numerically.
- k Option : Unix gives the component of arranging a table based on any segment number by utilizing - k alternative.
Utilize the - k alternative to sort on a specific segment. the "- k3 " to sort on the third section.
- n Option : To sort a document numerically utilized – n alternative. - n choice is likewise predefined in unix as the above alternatives seem to be. This alternative is utilized to sort the document with numeric information present inside.
/etc/group is the file path.