ITS 2310 - Linux I


Chapter 8, Exploring the UNIX/Linux Utilities

Objectives:

This lesson discusses more file operations and introduces some system utilities. Objectives important to this lesson:

  1. More operating system utilities
  2. The dd utility
  3. Monitoring hard drives with df and du
  4. System status commands
  5. Processes
  6. Network utilities
Concepts:

This chapter discusses more utility programs that are included in UNIX/Linux. The first several pages list utilities according to eight types. The organization of eight tables by these types is meant to help you find the right tool for a task that suddenly appears.

File processing utilities
Display and manipulate files
System status utilities
Display and alter the status of files, directories, and system objects
Network utilities
Displays status and configure network objects, as well as make and diagnose network connections
Communications utilities
Mail and messaging tasks
Security utilities
Manage user rights on the network and manage network devices
Programming utilities
Allow users to create programs in C and related languages
Source code utilities
Manage a program development environment on the network
Miscellaneous utilities
Things that don't fit the seven categories above: we will discuss a few

The text lists and briefly describes many utilities in several tables. Mercifully, it only spends the next 25 pages discussing them. We will concentrate on a few.

File processing utilities

The dd utility is used to copy files when you need to specify parameters for the destination file that are different from the source file. The text gives us examples of converting from one character code to another (like ASCII to EBCDIC), one block size to another, one case to another, and from variable length records to fixed length records.

The df and du commands are related.

  • The df command stands for disk free. Its purpose is to tell us how much space is used and how much space is available on a file storage device. Think of df as a high level view of storage compared to du, which stands for disk usage.
  • You might think that the two commands supply the same information, but the du command can give us data not just for the disk drives, but for every folder on those drives. Use it for more detailed analysis of how a server's hard drives are being used.

Garbage files are files on a system that have no further purpose for the user or process that created them. In order to find them, however, users should be taught to name their files in reasonable ways, such as appending .test or .tmp to files that are only to be used in a test or a day's events. With names that we can trust, we can run searches for files of that we are sure should be removed from a system. Note the syntax of the command on page 410 that uses find to locate files named either a.out or core, then uses the -exec option of find to run the rm command on each filename that is found. This kind of script should be checked for errors very well before it is trusted to run.

System status utilities

On page 411, the text discusses the top command, which runs a check on the system's CPU, and returns a list of the processes that are causing the heaviest load on it, updating the list every five seconds while top is being run. top runs until you stop it by pressing q, for quit. While it is running, you can press k (for kill) to bring up an interface to kill (end) a process that should not be allowed to continue.

On page 412, the text describes the free command, which reports information about system RAM. It can be set to run continuously with the -s option. If running continuously, quitting is done by typing ctrl-c.


Managing processes

The text reminds us (if we already know) that processes running in memory are assigned process ID numbers, also called PIDs. You can see four of them in the image above for the top command. The text tells us on page 414 that we might want to run top in the background instead of running it in its normal mode, which takes over the terminal console. The command to run any process in the background is just to add an ampersand (&) to the command that starts the process.

Any program that is running may start several processes, which makes it hard to keep track of them. The text explains that we can use the ps command to list all or some of the processes that are currently running.

You already know that you can run the top command and kill a process from it. But that only gives you access to the most processor intensive processes. To kill any process, you can use the kill command (assuming you have rights to do so). To kill a process the syntax is kill PID, or kill processname. You can also use the pkill command with the name of a user to kill all processes that belong to that user.


Network utilities

On page 435, the text begins a discussion of several utilities that relate to network setting and use.

  • ifconfig - This is a lot like the ipconfig utility you may have used in Windows environments. The text gives you some background in IP addressing, and spends too little space on doing it for anyone not aware of how IP addresses work. If you are not comfortable with IP addresses, spend a few minutes reading this set of notes from NET 102. You should have the ideas down in a few minutes. Once you know what to expect from the IP settings on your computer, you can use the ifconfig command to see what they are, and make repairs if necessary.
  • ping - The ping command actually sends a signal to an IP address, typically that of a computer on your own or another network, to prove that a connection to that device can be made. If the ping fails, something is wrong with your computer, the other computer, or any part of the links that would connect the two computers.
  • traceroute - The traceroute command sends a series of signals to another device, and reports information about the various links that the signals pass through on their way to the other device.
  • netstat - The netstat command, issued by itself, will report all IP address/port assignments that this computer knows about. It effectively reports the routing table that has been collected by this computer, which means a table of connections this computer has or knows about on its network. This is not static information. It is assembled by netstat by querying the computer, which means it could change at any moment, as new connections are opened and old ones are closed. Note the -p switch that shows programs actively using connections.