238 lines
3.7 KiB
HTML
238 lines
3.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>Exercises</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
|
REL="HOME"
|
|
TITLE="Bash Guide for Beginners"
|
|
HREF="index.html"><LINK
|
|
REL="UP"
|
|
TITLE="Regular expressions"
|
|
HREF="chap_04.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Summary"
|
|
HREF="sect_04_04.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="The GNU sed stream editor"
|
|
HREF="chap_05.html"></HEAD
|
|
><BODY
|
|
CLASS="sect1"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>Bash Guide for Beginners</TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="sect_04_04.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
>Chapter 4. Regular expressions</TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="chap_05.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="sect1"
|
|
><H1
|
|
CLASS="sect1"
|
|
><A
|
|
NAME="sect_04_05"
|
|
></A
|
|
>4.5. Exercises</H1
|
|
><P
|
|
>These exercises will help you master regular expressions.</P
|
|
><P
|
|
></P
|
|
><OL
|
|
TYPE="1"
|
|
><LI
|
|
><P
|
|
>Display a list of all the users on your system who log in with the Bash shell as a default.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>From the <TT
|
|
CLASS="filename"
|
|
>/etc/group</TT
|
|
> directory, display all lines starting with the string <SPAN
|
|
CLASS="QUOTE"
|
|
>"daemon"</SPAN
|
|
>.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Print all the lines from the same file that don't contain the string.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Display localhost information from the <TT
|
|
CLASS="filename"
|
|
>/etc/hosts</TT
|
|
> file, display the line number(s) matching the search string and count the number of occurrences of the string.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Display a list of <TT
|
|
CLASS="filename"
|
|
>/usr/share/doc</TT
|
|
> subdirectories containing information about shells.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>How many <TT
|
|
CLASS="filename"
|
|
>README</TT
|
|
> files do these subdirectories contain? Don't count anything in the form of <SPAN
|
|
CLASS="QUOTE"
|
|
>"README.a_string"</SPAN
|
|
>.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Make a list of files in your home directory that were changed less that 10 hours ago, using <B
|
|
CLASS="command"
|
|
>grep</B
|
|
>, but leave out directories.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Put these commands in a shell script that will generate comprehensible output.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Can you find an alternative for <B
|
|
CLASS="command"
|
|
>wc <TT
|
|
CLASS="option"
|
|
>-l</TT
|
|
></B
|
|
>, using <B
|
|
CLASS="command"
|
|
>grep</B
|
|
>?</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Using the file system table (<TT
|
|
CLASS="filename"
|
|
>/etc/fstab</TT
|
|
> for instance), list local disk devices.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Make a script that checks whether a user exists in <TT
|
|
CLASS="filename"
|
|
>/etc/passwd</TT
|
|
>. For now, you can specify the user name in the script, you don't have to work with arguments and conditionals at this stage.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Display configuration files in <TT
|
|
CLASS="filename"
|
|
>/etc</TT
|
|
> that contain numbers in their names.</P
|
|
></LI
|
|
></OL
|
|
></DIV
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="sect_04_04.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="index.html"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="chap_05.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Summary</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="chap_04.html"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>The GNU sed stream editor</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |