Common Linux Commands


In the following sections, we look at a number of the basic commands you will use in the day-to-day management of your server. You can use these commands in conjunction with each other to gain quick access to detailed information on a process or an event. The output from the various commands can be piped through tools such as grep to further refine the scope of the information.

Basic Commands

A Linux server can be conceptually subdivided into three main categories. Though this subdivision is not rigorous, we have categorized the basic commands into these distinct areas of interest: system control, the filesystem, memory, and processes.

A number of these commands have been used in examples throughout this book. Table 7.1 provides a quick synopsis of the most commonly used commands, and we expand on a number of them in upcoming sections within this chapter. You can find a more detailed explanation of the various command-line parameters for each in the man and info pages.

Table 7.1. Commonly Used Linux Commands

SYSTEM CONTROL

COMMAND PURPOSE

init

Allows you to quickly change the runlevel of the system. Not commonly used. init was covered in more detail in Chapter 3, "Booting and Shutting Down the Server."

shutdown

Shuts down the system in an orderly fashion. It allows for a message to be displayed to all users and provides for a time delay in the shutdown as well as the opportunity for a reboot.

reboot

Performs a quick restart of the system. This command actually calls shutdown but does not allow for the same parameters.

FILESYSTEM

df

Returns information of the current disk utilization at the filesystem level. The -h flag returns results in "human" readable units of kilobytes, megabytes, or gigabytes.

du

Returns the disk utilization for a file or a directory. The -h flag returns results in "human" readable units of kilobytes, megabytes, or gigabytes.

find

Locates files within a directory structure.

fuser

Identifies the user and the process ID currently using a file. This command is particularly useful when you are looking for users who have a volume mounted on the system.

ln

Creates links to other files on the system. This allows for a file to be seen in more than one directory structure at a time. All pointers, however, reference the same file within the filesystem, allowing for a single version to be maintained.

lsof

Lists all currently opened files on the system.

ls

Provides a listing of the files in the target filesystem or directory. Common arguments are -l for a long format, including file sizes; -a to include all hidden files in the list as well; and -t to sort the output by date/time.

mount

Returns information on the current mount points, their underlying format (ext3, reiserfs), and their default options and permissions.

rm

Removes (deletes) files. The rmdir command is used to remove empty rmdirdirectories.

stat

Returns detailed information about a file including the dates it was created, last accessed, and last modified.

MEMORY MANAGEMENT

free

Displays the current memory utilization and swap file status.

procinfo

Reports memory utilization, although it is more of a process information tool.

PROCESS INFORMATION

ps

Processes status information. A number of parameters can be passed to extract information in a number of formats. By default, this command lists only the process table for the current user.

pstree

Provides a process list in a tree format showing which processes are children and which are their parent.

w

Lists all the processes by users.


Additional Tools

You also can use the following tools:

|

The pipe symbol allows you to control the output from one command and redirect it to the input of another. This extremely powerful tool will be used extensively throughout this book in conjunction with grep.

awk

This tool can be used to extract specific columnar information from a file or pipe based on a pattern.

cat

This tool prints the contents of a file to the display.

cut

This tool prints out only selected portions from each line of a file.

grep

This tool searches for information in a file and returns all the lines that match the provided criteria.

head

This tool displays the first 10 lines of a file. The -n parameter can be used to change the number of lines shown.

tail

This tool prints the last 10 lines of a file to the display. You can use the -n parameter to specify how many lines from the bottom of the file should be listed. This command is essential when you are reviewing large log files.

wc

By default, this command counts the number of words in a document or pipe. The parameter -l changes the default behavior to count lines instead.


The preceding certainly does not provide an exhaustive list of the available commands. As you gain experience using these commands individually, combining the pipe tool with grep, awk, or wc will become second nature.



    SUSE LINUX Enterprise Server 9 Administrator's Handbook
    SUSE LINUX Enterprise Server 9 Administrators Handbook
    ISBN: 067232735X
    EAN: 2147483647
    Year: 2003
    Pages: 134

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net