362 lines
5.1 KiB
HTML
362 lines
5.1 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="Introduction to Linux"
|
|
HREF="index.html"><LINK
|
|
REL="UP"
|
|
TITLE="I/O redirection"
|
|
HREF="chap_05.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Summary"
|
|
HREF="sect_05_04.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="Text editors"
|
|
HREF="chap_06.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"
|
|
>Introduction to Linux: </TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="sect_05_04.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
>Chapter 5. I/O redirection</TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="chap_06.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="sect1"
|
|
><H1
|
|
CLASS="sect1"
|
|
><A
|
|
NAME="sect_05_05"
|
|
></A
|
|
>5.5. Exercises</H1
|
|
><P
|
|
>These exercises give more examples on how to combine commands. The main goal is to try and use the <B
|
|
CLASS="keycap"
|
|
>Enter</B
|
|
> key as little as possible.</P
|
|
><P
|
|
>All exercises are done using a normal user ID, so as to generate some errors. While you're at it, don't forget to read those man pages!</P
|
|
><P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
>Use the <B
|
|
CLASS="command"
|
|
>cut</B
|
|
> command on the output of a long directory listing in order to display only the file permissions. Then pipe this output to <B
|
|
CLASS="command"
|
|
>sort</B
|
|
> and <B
|
|
CLASS="command"
|
|
>uniq</B
|
|
> to filter out any double lines. Then use the <B
|
|
CLASS="command"
|
|
>wc</B
|
|
> to count the different permission types in this directory.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Put the output of <B
|
|
CLASS="command"
|
|
>date</B
|
|
> in a file. Append the output of <B
|
|
CLASS="command"
|
|
>ls</B
|
|
> to this file. Send this file to your local mailbox (don't specify anything <TT
|
|
CLASS="email"
|
|
><<A
|
|
HREF="mailto:@domain"
|
|
>@domain</A
|
|
>></TT
|
|
>, just the user name will do). When using Bash, you will see a new mail notice upon success.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>List the devices in <TT
|
|
CLASS="filename"
|
|
>/dev</TT
|
|
> which are currently used by your UID. Pipe through <B
|
|
CLASS="command"
|
|
>less</B
|
|
> to view them properly.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Issue the following commands as a non-privileged user. Determine standard input, output and error for each command.</P
|
|
><P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
><P
|
|
><B
|
|
CLASS="command"
|
|
>cat <TT
|
|
CLASS="filename"
|
|
>nonexistentfile</TT
|
|
></B
|
|
> </P
|
|
></P
|
|
></LI
|
|
><LI
|
|
><P
|
|
><P
|
|
><B
|
|
CLASS="command"
|
|
>file <TT
|
|
CLASS="filename"
|
|
>/sbin/ifconfig</TT
|
|
></B
|
|
> </P
|
|
></P
|
|
></LI
|
|
><LI
|
|
><P
|
|
><P
|
|
><B
|
|
CLASS="command"
|
|
>grep <TT
|
|
CLASS="parameter"
|
|
><I
|
|
>root</I
|
|
></TT
|
|
> <TT
|
|
CLASS="filename"
|
|
>/etc/passwd /etc/nofiles</TT
|
|
> > <TT
|
|
CLASS="filename"
|
|
>grepresults</TT
|
|
></B
|
|
> </P
|
|
></P
|
|
></LI
|
|
><LI
|
|
><P
|
|
><P
|
|
><B
|
|
CLASS="command"
|
|
>/etc/init.d/sshd <TT
|
|
CLASS="parameter"
|
|
><I
|
|
>start</I
|
|
></TT
|
|
> > <TT
|
|
CLASS="filename"
|
|
>/var/tmp/output</TT
|
|
></B
|
|
> </P
|
|
></P
|
|
></LI
|
|
><LI
|
|
><P
|
|
><P
|
|
><B
|
|
CLASS="command"
|
|
>/etc/init.d/crond <TT
|
|
CLASS="parameter"
|
|
><I
|
|
>start</I
|
|
></TT
|
|
> > <TT
|
|
CLASS="filename"
|
|
>/var/tmp/output</TT
|
|
> 2>&1</B
|
|
> </P
|
|
></P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Now check your results by issuing the commands again, now redirecting standardoutput to the file <TT
|
|
CLASS="filename"
|
|
>/var/tmp/output</TT
|
|
> and standard error to the file <TT
|
|
CLASS="filename"
|
|
>/var/tmp/error</TT
|
|
>.</P
|
|
></LI
|
|
></UL
|
|
></LI
|
|
><LI
|
|
><P
|
|
>How many processes are you currently running?</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>How many invisible files are in your home directory?</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Use <B
|
|
CLASS="command"
|
|
>locate</B
|
|
> to find documentation about the kernel.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Find out which file contains the following entry:</P
|
|
><TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
> root:x:0:0:root:/root:/bin/bash
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><P
|
|
>And this one:</P
|
|
><TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
> system: root
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
></LI
|
|
><LI
|
|
><P
|
|
>See what happens upon issuing this command:</P
|
|
><P
|
|
><B
|
|
CLASS="command"
|
|
>> time; date >> time; cat < time</B
|
|
> </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>What command would you use to check which script in <TT
|
|
CLASS="filename"
|
|
>/etc/init.d</TT
|
|
> starts a given process?</P
|
|
></LI
|
|
></UL
|
|
></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_05_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_06.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_05.html"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>Text editors</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |