I need snapshots of these exercises Unix/Linux Exercises A. The whereis command
ID: 3690852 • Letter: I
Question
I need snapshots of these exercises
Unix/Linux Exercises
A. The whereis command
The whereis command searches a list of standard linux places and displays the name of the program and its absolute directory, the source file (if available), and the manual page (if available) for the command.
Exercise 1:
Enter the following:
$whereis ls
Write down the answer
B. The which command
The which command shows full path of commands (as long as it is executable). It will show the FIRST path of the command typed. Which takes a series of program names, and prints out the full pathname of the program that the shell would call to execute it. Which only searches the PATH.
PATH is an environment variable that contains a group of directories. These directories have the executable files of various commands such as man, whereis, cd, etc. PATH tells the operating system where to look for those executables.
Exercise 2:
Check the PATH value by entering the following command:
$echo $PATH
Write down the output
Exercise 3: Enter the following:
$cd ~ (Note: ~ symbol means your home directory)
$which whereis
Write down the output
Exercise 4:
Enter the set of commands below:
$PATH=~/bin:$PATH
$which whereis
Write down the output.
Exercise 5:
Explain the difference in the output from the three whereis commands (from exercises 2 to 4).
Exercise 6:
Check the PATH value again:
$echo $PATH
Is the output the same as in exercise 1? Explain why.
C. The find command
The find command searches the directory tree for a given file name by evaluating the given expression from left to right. It has a large number of options that you can read about on its man page. For now you just need to know its basic version:
find directory_to_search_from -name filename_searched_for -print
Exercise 7: Create a file on your home directory called testingfind.txt
Enter the following:
$find /space1 -name testingfind.txt –print
Write the output and explain
Exercise 8:
Enter the following:
$find /etc -name s* -print
Understand the output, and write down the output.
Exercise 9:
Write the find command to locate a file called protocols anywhere on your machine.
D. The grep command
The grep command searches the named input files (or standard input when no files are named, or the file name - is given) for lines containing a match to the given pattern. By default, grep prints the matching lines.
Exercise 10:
Enter the following command: 3
$grep www /etc/mail
Write down the output and explain the information provided.
Exercise 11:
Create a file called “data”, which contains some text content and numerical value content. Then write two grep commands to find and print all the lines in this “data” file that contain at least one non-alphabetic character:
grep '[^A-Za-z]' data
What command would you use to find all the lines that do not contain even a single alphabetic character?
Explanation / Answer
Exercise 1:
$whereis ls
Ans: ls: /bin/ls /usr/bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz
Exercise 2:
$echo $PATH
Ans: /usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin/:/usr/sbin:/sbin:/opt/java/jdk/bin:/opt/java/jboss/bin
Exercise 3:
$cd ~
$which whereis
Ans: /usr/bin/whereis
Exercise 4:
$PATH=~/bin:$PATH
$which whereis
Ans: /usr/bin/whereis
Exercise 5:
Ans: each whereis is pointing to different locationsn
Exercise 6:
Ans: No, in Exercise 4, we added the bin folder to the PATH variable(PATH=~/bin:$PATH)
Exercise 7:
$find /space1 -name testingfind.txt –print
Ans: find: '/space1' : No such file or directory
It is because we are searching under the directory space1 on root directory, which is not present in the system
Exercise 8:
$find /etc -name s* -print
Ans: It will search for the files starting with character s in the directory /etc
Exercise 9:
Ans: find / -name protocols*
Exercise 10:
$grep www /etc/mail
Ans: It will search for www in the /etc/mail directory