Lab Exercises for Lesson 09 Intro: The lab for this lesson will cover finding files. To begin the lab, please use the s

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Lab Exercises for Lesson 09 Intro: The lab for this lesson will cover finding files. To begin the lab, please use the s

Post by answerhappygod »

Lab Exercises for Lesson 09Intro:The lab for this lesson will cover finding files. To begin the lab,please use the script command to record your session. Activity 1: whichThe which command can be used to determine what programwill actually be executed when more than one utility exists withthe same name or when commands have been aliased. To begin, runthe which command on the ls command, firstspecifying the fully qualified path name, then just ls:$ which /bin/ls$ which lsNotice how the second entry is different from the first. Dependingon your setup, the ls command may be giving you colorizedoutput, even when you are not specifyingthe --color option. On some systems,the ls command has been aliased so that any time a usertypes "ls" the system replaces that with "ls --color=tty" instead.We'll cover aliases in a future lesson. For now, look at how tooverride this behavior by simply invoking ls with thefull path. For example, run the following commands and notice thedifference (if any):$ ls -l$ /bin/ls -lActivity 2: whereisThe whereis command searches a series of directorieslooking for matching files. For example, to find out where theapropos command is located, let's try:$ whereis aproposThe data that comes back will consist of the file were aresearching for (apropos) followed by the location of the executable(/usr/bin/apropos) and the location of the man pages(/usr/share/man/man1/apropos.1.gz). Some utilities may havemultiple man pages, in which case whereis will return allappropriate data. Let's try a whereis search forthe chmod command, which we'll cover in a laterlesson:$ whereis chmodThe manual system divides things up into several sections. See the"man pages" entry in chapter two of your text for moreinformation.
NOTE: Your reading assignment for this lesson includes thefollowing: "The whereis utility looks through a list of standarddirectories and works independently of your search path." This isnot a true statement. For example, I have a directory called bin inmy home directory, and it includes the executable file counter.pl.If my $PATH variable includes ~/bin/ , then whereis WILL find thisfile. If my $PATH variable does NOT include ~/bin/, this file willNOT be found by whereis.Activity 3: locateThe locate utility provides a similar functionalityto whereis, but is more robust. However, it relies on adatabase of filenames that may or may not be updated frequently. Tobegin, let's search for "robots" (I'll include the output from thiscommand):$ locate robots/opt/anaconda3/lib/python3.7/site-packages/notebook/static/robots.txt/opt/anaconda3/lib/python3.7/site-packages/tornado/test/static/robots.txt/opt/anaconda3/pkgs/notebook-5.6.0-py37_0/lib/python3.7/site-packages/notebook/static/robots.txt/opt/anaconda3/pkgs/tornado-5.1-py37h14c3975_0/lib/python3.7/site-packages/tornado/test/static/robots.txt/usr/share/cups/www/robots.txt/usr/share/vim/vim74/syntax/robots.vimThe system found several matches, including files fromthe anaconda,python, cups and vim entries. If you have afile who's name contains the word "robots" in your userdirectory, it may or may not find it, depending on how long it'sbeen since you created one. Look up the man pagefor locate and run the command that will output thenumber of files "robots" matches rather than the list.Activity 4: findSimilar to the locate command, the find commandalso looks for full or partially matching files, but unlikethe locate command, find does not search apre-compiled database, but rather searches for the named files atruntime. The find command can take several arguments, butwe'll begin with the most common one (output included in examplebelow.)$ find ~ -name "the_raven*"/home/staff/metcalf/the_raven.txtThe command options above tells find to begin searchingin our user directory (identified by a single tilde: ~), and thenlook for files whose name (-name) matches the pattern "the_raven*"(note that the entire phrase the_raven* must be enclosed in quoteson some systems, so it's best to get in the habit of doing this allthe time.) If we wanted to search other directories, we could do soby adjusting the options. For example, let's find all executablefiles associated with the MySQL database system:$ find /usr/bin -name "mysql*"Several other options exist for the find command. Usingthe man page, we notice that several options are available under"TESTS." For example, we can discover how to look in our userdirectory and see if there are any empty files:$ touch ~/blankfile.txt$ find ~ -empty
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply