Lab No 4 Finding Files After completing this lab students wi

Lab No. 4: Finding Files After completing this lab, students will be able to: find files using wildcards use wildcards to perform bulk file operations perform simple searches in files by occurrence of character strings File Wildcards In Lab No.2 we learned how to list us), move mv), copy (cp) and remove rm and rmdir) files and directories. Wildcard characters (also known as globbing characters) allow these commands (and many others to operate on patterns. The following list contains the standard bash wildcards: Character Meaning A sequence of zero or more characters A single character List of characters Exclude list of characters List of wildcard expressions Let\'s create some files so we can see globbing in action: [you oblue mkdir wildcards you oblue cd wildcards [you@blue wildcards]$ touch dnf.sys.Log-20170212 dnf.rpm.uog-20170205 dnf.Lib.uog-20170112 maiu.err maiu. Uog maiu .com. Log-20170116 messages. rpm. [you@blue wildcards]$ us trh total 0 -rw--------- 1 you you 0 Feb 15 22:14 spooler.sys. log-20170130 -rw--------- 1 you you 0 Feb 15 22:14 secure.ssh.log-20170116 -rw------ 1 you you 0 Feb 15 22:14 messages. rpm.uog-20170116 -rw--------- 1 you you 0 Feb 15 22:14 mail. log 1 you vou 0 Feb 15 22 14 mail, err

Solution

1. Which command will list all the files that have a timestamp?
As we assumed, the digits included in the file names are dates,
we are supposed to list all the file names, that include digits in it.
So, to do that, the command is:
ls *[0-9]*

2. Which command will list all the \"dnf\" and \"mail\" files that have a timestamp?
dnf mails start with dnf, and mail files start with mail, so list all dnf, and mail files,
the command is:
ls {dnf*,mail*}
But this will list all the files. To further filter the files that are with time stamp,
now use the command:
ls {dnf*,mail*} | grep \"[0-9]\"
This will list all the dnf and mail files, and among those files, it will display only
files that have timestamps in it.

3. Which command will list all the \"dnf\" files that do not have a timestamp?
ls dnf* will list all the dnf files.
And to further filter the files that do not have a time stamp, lets use the grep command.
The grep command with -v option will list all the file names, except the names that match the pattern.
So, the command is:
ls dnf* | grep -v \"[0-9]\"

4. Execute a command that will ensure that all files in the wildcards directory can be only
be read and written by the owner. Include this command in your report.
If you are readily in wildcards directory, the command to ensure all the files have only
read and write permissions to the owner is:
chmod 600 *

 Lab No. 4: Finding Files After completing this lab, students will be able to: find files using wildcards use wildcards to perform bulk file operations perform

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site