Lab Assignment_5-Solution (5)
Lab Assignment_5-Solution (5)
Module 1 :
2. Search in your current directory for a file using its name (select a name of your choice, use a
default search). What do your remark ?
Solution.
find gx
We remark that the search is performed only in the current directory (i.e., in the first level of
the path).
3. Modify the previous command by adding the appropriate option, so that you avoid the default
search of find.
Solution.
find -name gx
As we search in the root ‘/’, we observe that in some parts we have no access right to display
the file, and this is quite logic as we are not the root user, and also you are not navigating in our
home directory (in which we have the full access rights).
10. Search for ordinary files only in all directories, without displaying access rights errors, in which
their name starts with ‘pass’, their size is more than 1K and less than 4K, they are with 664
permissions and you are the owner.
Solution.
find / -type f -name ‘pass*’ –size +1k –size -4K -perm 664 -user user01 2>/dev/null
11. Repeat the previous command, so that you list only files and avoid all directories.
Solution.
find / ! -type d -name ‘pass*’ –size +1k –size -4K -perm 664 -user user01 2>/dev/null
12. Run ls -l command on all ‘*.c’ files in all directories to get extended information.
Solution.
Find / -name ‘*.c’ –type f –exec ls -l {} \;
13. Change the access rights of your files to 666 and your directories to 777 in your home directory.
Solution.
find . \(-type f-exec chmod 664 {} \; \) , \( -type d -exec chmod 775 {} \; \)
14. Exit out the script. Save the output file so you can continue with Module 2.
Solution.
exit
Module 2 :
1. Start script again and append to the existing output file of step 14.
Solution.
script -a lab5
2. Search for a given string of characters, such as games in your home directory. Modify the
command so that you figure out the line number.
Solution.
grep -r games ~
grep -rc games ~
3. In what follows, perform pattern research within /etc/passwd file :
Search for a given pattern, such as sshd.
Solution.
grep sshd /etc/passwd