old-www/LDP/GNU-Linux-Tools-Summary/html/finding-information.html

806 lines
12 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Finding information about the system</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="GNU/Linux Command-Line Tools Summary"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Mass Rename/copy/link Tools"
HREF="mass-rename.html"><LINK
REL="NEXT"
TITLE="Date/Time/Calendars"
HREF="date-time-calendars.html"></HEAD
><BODY
CLASS="CHAPTER"
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"
>GNU/Linux Command-Line Tools Summary</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="mass-rename.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="date-time-calendars.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="FINDING-INFORMATION"
></A
>Chapter 8. Finding information about the system</H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
>8.1. <A
HREF="date-time-calendars.html"
>Date/Time/Calendars</A
></DT
><DT
>8.2. <A
HREF="hard-disk-partition-info.html"
>Finding information about partitions</A
></DT
></DL
></DIV
><P
></P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>time</DT
><DD
><P
>If you are looking for how to change the time please refer to <EM
>date</EM
> here: <A
HREF="date-time-calendars.html"
>Section 8.1</A
>. </P
><P
><EM
>time </EM
>is a utility to measure the amount of time it takes a program to execute. It also measures CPU usage and displays statistics.</P
><P
>Use<EM
> time -v </EM
>(verbose mode) to display even more detailed statistics about the particular program.</P
><P
>Example usage:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>time program_name options</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>/proc</DT
><DD
><P
>The files under the /proc (process information pseudo file-system) show various information about the system. Consider it a window to the information that the kernel uses. </P
><P
>For example:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>cat /proc/cpuinfo</PRE
></FONT
></TD
></TR
></TABLE
><P
>Displays information about the <SPAN
CLASS="ACRONYM"
>CPU</SPAN
>. </P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>less /proc/modules<EM
> </EM
></PRE
></FONT
></TD
></TR
></TABLE
><P
>Use the above command to view information about what kernel-modules are loaded on your system.</P
></DD
><DT
>dmesg</DT
><DD
><P
><EM
>dmesg</EM
> can be used to print (or control) the &#8220; kernel ring buffer&#8221;. <EM
>dmesg</EM
> is generally used to print the contents of your bootup messages displayed by the kernel. This is often useful when debugging problems.</P
><P
>Simply type:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>dmesg</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>df</DT
><DD
><P
>Displays information about the space on mounted file-systems. Use the<EM
> -h </EM
> option to have <EM
>df</EM
> list the space in a 'human readable' format. ie. if there are 1024 kilobytes left (approximately) then <EM
>df</EM
> will say there is 1MB left.</P
><P
>Command syntax:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>df -options /dev/hdx</PRE
></FONT
></TD
></TR
></TABLE
><P
>The latter part is optional, you can simply use <EM
>df</EM
> with or without options to list space on all file-systems.</P
><P
></P
></DD
><DT
>who</DT
><DD
><P
>Displays information on which users are logged into the system including the time they logged in. </P
><P
>Command syntax:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>who</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>w</DT
><DD
><P
>Displays information on who is logged into the system and what they are doing (ie. the processes they are running). It's similar to <EM
>who</EM
> but displays slightly different information.</P
><P
>Command syntax:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>w</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>users</DT
><DD
><P
>Very similar to <EM
>who</EM
> except it only prints out the user names who are currently logged in. (Doesn't need or take any options).</P
><P
>Command syntax:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>users </PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>last</DT
><DD
><P
>Displays records of when various users have logged in or out. This includes information on when the computer was rebooted.</P
><P
>To execute this simply type:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>last</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>lastlog</DT
><DD
><P
>Displays a list of users and what day/time they logged into the system. </P
><P
>Simply type:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>lastlog</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>whoami</DT
><DD
><P
>Tells the user who they are currently logged in as, this is normally the usename they logged in with but can be changed with commands like su). <EM
>whoami</EM
> does not need or take any options. </P
><P
>Simply type:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>whoami</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>free</DT
><DD
><P
>Displays memory statistics (total, free, used, cached, swap). Use the<EM
> -t </EM
> option to display totals of everything and use the<EM
> -m </EM
>to display memory in megabytes. </P
><P
>Example:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>free -tm</PRE
></FONT
></TD
></TR
></TABLE
><P
>This will display the memory usage including totals in megabytes.</P
></DD
><DT
>uptime</DT
><DD
><P
>Print how long the computer has been &#8220;up&#8221;, how long the computer has been running. It also displays the number of users and the processor load (how hard the <SPAN
CLASS="ACRONYM"
>CPU</SPAN
> has been working...). </P
><DIV
CLASS="TIP"
><P
></P
><TABLE
CLASS="TIP"
WIDTH="90%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>The w command</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The <EM
>w</EM
> command displays the output of the uptime command when you run this command. You could use the <EM
>w</EM
> command instead of uptime.</P
></TD
></TR
></TABLE
></DIV
></DD
><DT
>uname<EM
></EM
></DT
><DD
><P
>uname is used to print information on the system such as OS type, kernel version et cetera.</P
><P
>Some <EM
>uname</EM
> options:</P
><P
></P
><UL
><LI
><P
><EM
>-a</EM
> --- print all the available information.</P
></LI
><LI
><P
><EM
>-m</EM
> --- print only information related to the machine itself. </P
></LI
><LI
><P
><EM
>-n</EM
> --- print only the machine hostname. </P
></LI
><LI
><P
><EM
>-r</EM
> --- print the release number of the current kernel. </P
></LI
><LI
><P
><EM
>-s</EM
> --- print the operating system name </P
></LI
><LI
><P
><EM
>-p</EM
> --- print the processor type. </P
></LI
></UL
><P
>Command syntax:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>uname -options</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>xargs</DT
><DD
><P
>Note that <EM
>xargs</EM
> is an advanced, confusing, yet powerful command. <EM
>xargs</EM
> is a command used to run other commands as many times as necessary, this way it prevents any kind of overload... When you run a command then add a<EM
> &#8220;| xargs command2</EM
>&#8221;. The results of command1 will be passed to command2, possibly on a line-by-line basis or something similar. </P
><P
>Understanding <EM
>xargs</EM
> tends to be very difficult and my explanation is not the best. Refer to the examples below or try [6] of the <A
HREF="references.html"
><I
>Bibliography</I
></A
> for another <EM
>xargs</EM
> tutorial.</P
><DIV
CLASS="NOTE"
><P
></P
><TABLE
CLASS="NOTE"
WIDTH="90%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Alternatives to using xargs</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Please note that the below explanation of <EM
>xargs</EM
> is not the strongest (at the time of writing I could not find anything better :()).</P
><P
>Alternatives may include writing a simple bash script to do the job which is not the most difficult task in the world.</P
></TD
></TR
></TABLE
></DIV
><P
>Examples:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>ls | xargs grep work</PRE
></FONT
></TD
></TR
></TABLE
><P
>The first command is obvious, it will list the files in the current directory. For each line of output of <EM
>ls</EM
>, <EM
>xargs</EM
> will run <EM
>grep</EM
> on that particular line and look for the string &#8220;work&#8221;. The output have the each time <EM
>grep</EM
> is executed on a new line, the output would look like:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>file_name: results_of_grep </PRE
></FONT
></TD
></TR
></TABLE
><P
>If <EM
>grep</EM
> didn't find the word then there would be no output if it had an error then it will output the error. Obviously this isn't very useful (you could just do:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>grep 'word' *</PRE
></FONT
></TD
></TR
></TABLE
><P
><EM
></EM
> This is just a simple example...</P
><P
><EM
>xargs </EM
>also takes various options:</P
><P
></P
><UL
><LI
><P
><EM
>-nx</EM
> --- will group the first x commands together</P
></LI
><LI
><P
><EM
>-lx</EM
> --- xargs will execute the command for every x number of lines of input</P
></LI
><LI
><P
><EM
>-p</EM
> --- prompt whether or not to execute this particular string</P
></LI
><LI
><P
><EM
>-t</EM
> --- (tell) be verbose, echo each command before performing it</P
></LI
><LI
><P
><EM
>-i</EM
> --- will use substitution similar to find's -exec option, it will execute certain commands on something.</P
></LI
></UL
><P
>Example:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>ls dir1 | xargs -i mv dir1/'{}' dir2/'{}'</PRE
></FONT
></TD
></TR
></TABLE
><P
>The {} would be substituted for the current input (in this example the current file/directory) listed within the directory. The above command would move every file listed in dir1 to dir2. Obviously this command won't be too useful, it would be easier to go to dir1 and type <EM
> mv * ../dir2</EM
></P
><P
>Here is a more useful example: </P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>\ls *.wav | xargs -i lame -h '{}' '{}'.mp3</PRE
></FONT
></TD
></TR
></TABLE
><P
>This would find all wave files within the current directory and convert them to mp3 files (encoded with lame) and append a &#8220;.mp3&#8221; to the end of the filename, unfortunately it doesn't remove the .wav and so its not too useful...but it works.</P
></DD
></DL
></DIV
></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="mass-rename.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="date-time-calendars.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Mass Rename/copy/link Tools</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Date/Time/Calendars</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>