[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ A ] [ B ] [ C ] [ D ] [ next ]
Debian includes many tools for locating files. This chapter describes the tools for:
Searching for files and text.
Viewing files and text.
Comparing files.
From the desktop, you can search with most common options and view files. However, you need to use the command line for:
Advanced searching, especially for text.
Selected viewing of parts of files.
Comparing files.
First, however, you need to know something about how the Linux directory structure.
Linux treats everything on your hard drives and disks as a file. In practice, however, Linux uses three main types of object to store information:
Files: Containers of information. Files that start a program are called executables or binaries. Binaries are often stored in a / bin directory (short for binary), or in an /sbin directory (short for system binaries).
Links: Pointers to another file. Links are useful for saving space when you need a file in more than one place.
Directories: Collections of files, links and/or other directories. A directory within a directory is called a sub-directory.
[Note]
Strictly speaking, links and directories are specialized files. You can copy them or change their permissions exactly as you would with any other file.
The names of Linux files, links and directories follow certain rules:
Their names cannot be longer than 256 characters, and the complete path cannot be longer than 4096.
They are case sensitive, distinguishing between lower and upper case letters. Jsmith , jsmith , and JSMITH could all be files in the same directory.
They can use any letter or number. However, to avoid potential problems, do not include characters used metacharacters, or for some other purpose, such as the hash mark( # ) that indicates a comment.
They use a forward slash ( / ) at the start to indicate a directory. Windows, by contrast, uses a backward slash ( ).
[Note]
A forward slash by itself is shorthand for the root directory. You can use this shorthand on both the command line and the desktop.
Extensions are file name suffixes that start with a period. Usually, they are two or three letters long.
Linux can read many file extensions used by other platforms, such as
jpg for a graphic file, or .html for a web file. It can also use
them for mime types. However, Linux does not always use extensions to identify file types.
Often, the directory where a file is placed is a better indication of what type of file it is. See Using Directories to Find Files, Section 8.2.1.
However, Linux does use a few regular extensions.
Extensions Used in Linux +-------------------------------------------------------------------+ |Extension| File Type | |---------+---------------------------------------------------------| |.bz2 |A file compressed using bzip2 . | |---------+---------------------------------------------------------| |.c |A file written in the C programming language. | |---------+---------------------------------------------------------| |.conf |A configuration file. In some cases, "conf" is used in a | | |file name, but not as an extension. | |---------+---------------------------------------------------------| |.deb |A Debian package for installing software. | |---------+---------------------------------------------------------| |.lock |A lock file that prevents the use of another file. | |---------+---------------------------------------------------------| | |A Red Hat package file. Although you can sometimes use | |.rpm |.rpm s in Debian, doing so can have unexpected | | |results and is not generally recommended. You can also | | |convert packages using the alien utility . | |---------+---------------------------------------------------------| |.so |A shared object (a library or module). | |---------+---------------------------------------------------------| |.src |A source code file. Written in plain text, a source file | | |must be compiled to be used. | |---------+---------------------------------------------------------| |.tar |A single file made of a collection of files archived | | |using the tar command. | |---------+---------------------------------------------------------| | |A single file made of a collection of files archived | |.tar.gz |using the tar command, then compressed used the gzip | | |command. | |---------+---------------------------------------------------------| | |A single file made of a collection of files archived | |.tgz |using the tar command, then compressed used the gzip | | |command. | |---------+---------------------------------------------------------| |.gz |A file compressed using the gzip command. | +-------------------------------------------------------------------+
Linux's directory structure is based on unix 's. Like other operating systems, Linux arranges directories in a tree-like hierarchy, in which any directory may contain other-directories or files.
However, Linux's directory structure has several differences from those in other popular operating systems:
Linux systems are deeper. That is, Linux tends to have more sub-directories.
Linux systems all start with the root directory. The root directory is denoted by a forward slash (/), All other directories, even those on other partitions, are sub-directories of the root directory.
[Note]
Do not confuse the root directory (/) with the root user, the root user's home directory(/root), or the root partition (the hard drive partition which the root directory is on).
You cannot always tell from a directory's position whether it is on a separate partition from the root directory. For example, the /usr directory could be on the same partition as the root directory. It could just as easily be on another hard drive altogether.
[Note]
To see which directory a partition is mounted on, view /etc/fstab in a text editor. On each line, the first column is the partition, and the second column is its mount point.
The advantage of this system is that you can position a partition almost anywhere on the system.
Linux directories are consistent in their contents. The result is that a file's directory is usually a clue to what type of file it is.
For example, if you are looking for an executable program, it is probably in a /bin (short for "binary)" if it is a general or third party application or /usr/bin ("system binary") if it is a program that is an essential part of the operating system, or a maintenance utility.
The following table shows the directories where certain types of files are likely to be located. This structure is very similar in all Linux distributions, although small differences exist.
The Linux Directory Structure +-------------------------------------------------------------------+ |Directory | What's In It | |----------+--------------------------------------------------------| | |The root directory. Contains all other files and | | |directories. | |/ | | | |The complete or absolute path to other directories | | |starts from the root directory. | |----------+--------------------------------------------------------| | |Binary or executable files that can be used by both the | | |root user and normal user. | |/bin | | | |Look in other /bin directories for other executable | | |files. | |----------+--------------------------------------------------------| | |Files needed to start Linux, including the kernel. Most | |/boot |files in /boot generally cannot be configured using a | | |text editor. | |----------+--------------------------------------------------------| | |The usual mount point for the cd drive. If the system | |/cdrom |has a second cd drive, its mount point is usually / | | |cdrom2. | |----------+--------------------------------------------------------| | |Definitions for drives, partitions, and other devices. /| |/dev |dev also includes the makedev tool to create new | | |devices. | |----------+--------------------------------------------------------| | |Most of the system's configuration files. Including /etc| |/etc |/X11 for the X Window system and /etc/opt for third | | |party applications. | |----------+--------------------------------------------------------| | |The usual mount point for the first floppy drive. If the| |/floppy |system has a second floppy drive, its mount point is | | |usually /floppy2. | |----------+--------------------------------------------------------| | |Home directories for all regular users. The root user's | | |home directory is /root. | | | | | |Subdirectories of /home are named for the user name of | |/home |each account. | | | | | |Personal configuration files that start with a . (a | | |period) are in each home directory. These configuration | | |files are not displayed by many commands unless you | | |select an option to display them. | |----------+--------------------------------------------------------| |/initrd |Files for Linux's ram disk. | |----------+--------------------------------------------------------| | |Programming libraries needed to start the system and run| | |basic commands. | |/lib | | | |Look for other lib directories scattered throughout the | | |system. | |----------+--------------------------------------------------------| |/ |Files recovered when a check is run on a damaged file | |lost+found|system. | |----------+--------------------------------------------------------| | |A folder for other mount points, usually other | | |partitions not used directly by Linux, including those | | |for other operating systems. | |/mnt | | | |On some Linux distributions, /mnt includes /cdrom and / | | |floppy directories, but this is not standard Debian | | |practice. | |----------+--------------------------------------------------------| | |Process and system information. | | | | |/proc |Be extremely careful of changes to /proc while you are | | |logged in as the root user, because they can easily | | |bring the system down. | |----------+--------------------------------------------------------| | |The home directory for the root user. | |/root | | | |Home directories for other users are generally | | |sub-directories of /home. | |----------+--------------------------------------------------------| | |Executable files that are used only by the root user, | |/sbin |including general management and networking commands. | | | | | |Other executables are in /bin. | |----------+--------------------------------------------------------| | |Programs and system files that are shared by all users. | | | | |/usr |A common location for free software or for third-party | | |software. Important sub-directories include /usr/local | | |and /usr/share. | |----------+--------------------------------------------------------| |/var |Data files whose content changes frequently, such as | | |caches, spools, log files and user mailbox files. | |----------+--------------------------------------------------------| |/var/lock |Lock files that prevent another user from opening or | | |saving particular files. | |----------+--------------------------------------------------------| |/var/log |Log files for different programs. These logs are | | |invaluable for solving problems. | +-------------------------------------------------------------------+
A file path is a list of the directories above the file, ending with the file name.
Linux uses two types of paths: absolute and relative paths:
An absolute path always starts with the root directory. It includes all directories and sub-directories above the file. For example, the absolute path to a file in a sub-directory in a user's home directory might be /home/kchong/ToDo/january.txt . This path can take a long time to type, but is completely clear.
A relative path starts in your present working directory. For example, if you were in the /home/kchong directory, the relative path to a file in a sub-directory might be ToDo/ january.tx t. You can display your present working directory by using the pwd ("present working directory") command.
In addition, ./ indicates the present working directory and the path to your home directory.
You can search for files or text from the desktop using:
The gnome search tool (gsearchtool): A graphical interface for the find and locate commands that includes the most common options for the commands.
The gnome Midnight Commander: Useful for simple searches.
If you want a more elaborate search, See Searching From the Command Line, Section 8.4.
The find command is a tool for locating files. It can also do basic searches using strings and regular expressions.
At a command line, type: gsearchtool. The gnome search tool opens, with the Full find (find) tab selected.
Enter the directory in which to start the search. You can type the directory, choose it from the drop-down list of recent choices, or use the browse button to make a selection.
Choose the options to use from the drop-down list beside the Add button. These
options correspond to the most common ones in the find command. img/Finding-3.png
The default choice is the File name. Select the option. When it displays, select the Add button to display the option in the window. You can disable an option temporarily by de-selecting the Enable button beside it or remove it from the display by selecting the Remove button.
When you have chosen the options to use, enter any information needed to use each option.
If you want, select the Show Command button to see what the command would look like at the command line.
Select the Start button to search. Search results display in a separate window.
[Note]
This window stays open so that the results of other searches can be added to it.
From the Search Results window, you can:
Select a result to open the file in gedit .
Clear the window of results.
Save the results to a file.
The locate command searches a database of file names and prints results that match the string that is entered for a command.
At a command line, type: gsearchtool. The gnome search tool opens, with the Full find (find) tab selected.
Select the Quick Find (locate tab).
Enter a string, with or without metacharacters.
Select the Start button to search. Search results display in a separate window. This window stays open so that the results of other searches can be added to it.
From the Search Results window, you can:
Select a result to open the file in gedit .
Clear the window of results.
Save the results to a file.
Open the gnome Midnight Commander. Do one of the following:
From the workspace, select the Home directory launcher.
From the menu, select Programs > File Manager. In both cases, the gnome
Midnight Commander opens, displaying your home directory. img/Finding-7.png
From the gnome Midnight Commander menu, select Commands > Find File. The Find File window displays.
In the Start at field, type the directory from which to start the search. The default is the current directory.
In the Filename field, type the file name to search for. You can use wild cards.
In the Content field, type a text string to search for. This field is optional.
Start the search. Select the ok button. The search results display in a
separate window. They may take some time to display. img/Finding-9.png
[Note]
You can only search for results in directories in which you have read permission.
Using the buttons in the results window, you can:
Select a result and change to its directory.
Start a new search.
Close the search tool.
The Linux command line includes many tools for locating files or information in them. These tools can be divided into two main categories:
File-Locating Tool: find , locate .
Text-Locating Tools: grep , egrep , and fgrep .
Some of these commands, including grep , egrep and find can use variable text patterns (metacharacters or regular expressions) to extend their search abilities. See Using Metacharacters or Wild Cards, Section 5.3.6.
The basic tool for finding files is find . The find command is useful for locating files by their attributes or by their position in the directory tree.
You can search by a wide variety of criteria, including:
When the file was last accessed.
When the file was last changed.
The file's owner or the owner's group.
A text string, including one that uses metacharacters. See Using Metacharacters or Wild Cards, Section 5.3.6.
The type of file.
The file's age relative to another file.
The file's permissions.
Usually, find starts with the current directory, then searches its sub-directories. However, you can specify the starting directory.
You can also specify how many levels of sub-directories down to search.
Type: find directory options argument .
The find Command +-------------------------------------------------------------------+ | Option | Action | Comments | |-----------+----------------------+--------------------------------| | | |Arguments include: | | | | | | |Searches by minutes | * +number: More than the given| |-amin |since files were | number of minutes ago. | |argument |accessed. | * -number: Less than the given| | | | number of minutes ago. | | | | * number: Exactly the given | | | | number of minutes ago. | |-----------+----------------------+--------------------------------| | | |Arguments are: | | | | | | | | * +number: More than the given| |-atime |Searches by days since| number of days ago. | |argument |files were accessed. | * - number: Less than the | | | | given number of days ago. | | | | * number: Exactly the number | | | | of days ago. | |-----------+----------------------+--------------------------------| | | |Arguments include: | | | | | | |Searches by minutes | * +number: More than the given| |-cmin |since files were | number of minutes ago, | |argument |changed. | * -number: Less than the given| | | | number of minutes ago. | | | | * number: Exactly the given | | | | number of minutes ago. | |-----------+----------------------+--------------------------------| | | |Arguments are: | | | | | | | | * +number: More than the given| | |Searches by the number| number of days ago. | |-ctime |of days since file | * -number: Less than the given| |argument |attributes were | number of days ago. | | |changed. | * number: Exactly the number | | | | of days ago. | | | | | | | | | |-----------+----------------------+--------------------------------| |-follow |Traces symbolic links | | | |to original files. | | |-----------+----------------------+--------------------------------| | | |The group can be identified by | | |Searches for files |name or by group id . | |-group |that belong to a | | |group |particular group of |This option is best used as root| | |users. |user. Otherwise, you can only | | | |find files to which you have | | | |read permission. | |-----------+----------------------+--------------------------------| |-maxdepth |Sets the maximum level| | |number |of sub-directories to | | | |search. | | |-----------+----------------------+--------------------------------| |-mindepth |Sets the minimum level| | |number |of sub-directories to | | | |search. | | |-----------+----------------------+--------------------------------| |-name |Searches for files |Put a string in quotation marks | |string |that match the string.|to use shell metacharacters. | |-----------+----------------------+--------------------------------| | |Finds files newer than| | |-newer file|one included in the |. | | |command. | | |-----------+----------------------+--------------------------------| |-perm |Searches with | | |permissions|permissions in | | | |absolute mode. | | |-----------+----------------------+--------------------------------| | | |Arguments include: | |-type |Searches for types of | | |argument |files. | * d: Directory. | | | | * l: Symbolic link. | | | | * f: Regular file. | |-----------+----------------------+--------------------------------| | | |Users can be identified by | | |Searches for files |account name or by user id. | | |that belong to the | | |-user user |user included in the |This option is best used as root| | |command. |user. Otherwise, you can only | | | |find files for which you have | | | |read permission. | +-------------------------------------------------------------------+
The locate command searches a database for files. It is often the quickest way to find a file.
Type: locate string . If you want to specify the database, add the -d path or --database = path option.
[Note]
You may want to install slocate ("secure locate"), a replacement for locate .
Linux uses the grep command line tools to search for text in files. This family of tools contains three commands:
grep : A general purpose search tool that uses text strings, sometimes with metacharacters. The grep command contains most of the functionality of the other tools, but has fewer options for customizing the search.
fgrep : A specialized search tool for locating literal text strings - that is, text strings without metacharacters. Because fgrep uses literal text strings, it does not require you to remember any special characters in your search.
egrep : A specialized search tool that uses metacharacters. The command uses more metacharacters than grep . In addition, the egrep command is often said to be the fastest of the three tools.
All three commands use a similar format. Type:
grep options string files .
egrep options string files .
fgrep options string files .
[Note]
To use grep or egrep as fully as possible, you should familiarize yourself with metacharacters. See Using Metacharacters With grep Commands, Section 8.4.4.
[Note]
To save or print search results, use redirection operators. See Redirecting Input and Output for Commands, Section 5.5.6.
The grep, egrep, and fgrep Commands (Find Text) +-------------------------------------------------------------------+ | Option | Action | Comment | |-------------------------+------------------+----------------------| | |Treats the string |Used only with grep . | |-E |as an extended |Similar to using egrep| | |regular |. | | |expression. | | |-------------------------+------------------+----------------------| | |Treats strings as |Used only with grep . | |-F |regular text. |Similar to using fgrep| | | |. | |-------------------------+------------------+----------------------| | |Searches using a | | | * -f file |text file |Strings must be listed| | * --file= file |containing a list |one per line in the | | |of patterns to |file. | | |match. | | |-------------------------+------------------+----------------------| | |Ignores the |If this option is not | | * -i |distinction |used, lower case | | * --ignore-case |between upper and |letters are | | |lower case |distinguished from | | |letters. |upper case ones. | |-------------------------+------------------+----------------------| | * -l |Lists files with |Individual lines are | | * --files-with-matches |matches. |not listed. | |-------------------------+------------------+----------------------| | * -L |Searches for files| | | * --files-without-match|that do not match | | | |the string. | | |-------------------------+------------------+----------------------| | * -n |Displays lines | | | * --line-number |numbered. | | |-------------------------+------------------+----------------------| | |Sets the number of| | |-number |lines to display |Sometimes referred to | | |before and after |as "context." | | |each match. | | |-------------------------+------------------+----------------------| | * -q |Stops at the first|Whether other matches | | * --quiet |match. |are available is not | | | |listed. | |-------------------------+------------------+----------------------| | * -r |Searches | | | * --recursive |sub-directories. | | |-------------------------+------------------+----------------------| | * -v |Searches for lines| | | * --invert-match |that do not match | | | |the string. | | |-------------------------+------------------+----------------------| | * -x |Displays lines | | | * --line-regexp |that match the | | | |entire string. | | +-------------------------------------------------------------------+
Metacharacters are characters that can be used to set special conditions for searching. They are also known as wild cards. See Using Special Symbols, Section 5.5.5.1.
Metacharacters are added to a text string. A text string that includes metacharacters is called a regular expression. Regular expressions are useful for finding variations in wording or in the positioning of the string on a line.
Metacharacters can be used with both grep and egrep . However, grep can use fewer metacharacters than egrep . Whenever you want to use metacharacters, egrep is usually the tool to use.
If you do not want to use any metacharacters at all, or do not have the characters memorized for use, use fgrep .
Metacharacters can be extremely powerful, especially when used in combination. However, when you are using search tools, little is likely to go wrong unless you combine a grep command with another one that makes changes to files.
[Note]
If you want to search for a character that is usually used as a metacharacter, place a backward slash ( ) in front of it. For example, ? searches for a question mark, instead of any character.
Metacharacters are especially powerful when used together. For example:
^contacts$ searches for matches in which contacts is the only word on a line.
[Cc]ontacts matches Contacts or contacts .
^...$ searches for any line of three characters.
compan (y|ies) searches for company or companies .
[A-Za-z] searches for any upper or lowercase letter. Similarly, [0-9A-Za-z] searches for any number or any letter.
The desktop offers only limited choices for viewing files. For selective viewing of parts of files, use the command line instead. See Viewing Files From the Command Line, Section 8.6.
To view a file from the desktop:
Open the gnome Midnight Commander. Do one of the following:
From the workspace, select the Home directory launcher.
From the menu, select Programs > File Manager. In both cases, the gnome
Midnight Commander opens, displaying your home directory. img/Finding-10.png
Use the directory tree and the Back, Up, and Forward icons to display the directory you want.
Right click on the icon for the file that you want. A pop-up menu appears.
Select Open or Open With from the menu. One of two things happens:
If the file's type is associated with a program, selecting Open displays the file. See Adding MIME Types, Section 7.8.1. or
If the file's type is not associated, selecting Open or Open With displays a window to choose a viewer from.
If you are choosing a viewer, do one of three things:
Select an application from the directory tree. or
Use the Browse button to find a viewer. or
Type the path of a viewer. If the chosen browser is capable of displaying the file, then the file displays.
Linux includes so many tools for viewing files from the command line that some are widely considered obsolete.
For example, cat is less commonly used than it once was, probably because it has few options and does not allow scrolling. However, cat is still useful for a quick, no-frills view of a short file.
Similarly, although more is still a functional tool, for most people it has been replaced by less , whose name is a play on the saying that "less is more."
In general, less is the standard tool for viewing files. However, specialized commands also exist:
tac : Displays files from the end backwards.
head : Displays the first lines of a file.
tail : Displays the last lines of a file.
The cat command is useful for viewing files that are less than a screen in length. For longer files that you want to scroll back and forth in, use less instead.
Type: cat options file.
The cat Command (View) +-------------------------------------------------------------------+ | Option | Action | Comments | |----------------------+-----------------------+--------------------| | * -E |Displays line ends. |Line ends are marked| | * --show-ends | |with $. | |----------------------+-----------------------+--------------------| | * -b |Displays line numbers. | | | * --number-nonblank | | | |----------------------+-----------------------+--------------------| | * -T |Displays tabs. |Tabs are marked with| | * --show-tabs | |^I. | |----------------------+-----------------------+--------------------| | * -v |Displays non-printing | | | * --show-nonprinting|characters. | | +-------------------------------------------------------------------+
The less command is the most common tool for viewing files from the command line. In this category, it replaces cat and more , offering more options than either.
The less command displays the designated file one screen at a time. In addition to displaying files, less can also be used for simple searches.
However, for most searches, you probably want to use one of the search commands. See Searching from the Desktop, Section 8.3 See Searching From the Command Line.
Type: less options file .
The less Command (View) +-------------------------------------------------------------------+ |Option| Topic | Comments | |------+-----------------------------+------------------------------| |-h |Sets maximum number of lines | | |number|to scroll back at one time. | | |------+-----------------------------+------------------------------| | |Ignores the distinction |If this command is not used, | |-i |between upper and lower case |lower case letters are | | |letters when a string is |distinguished from upper case | | |used. |ones. | |------+-----------------------------+------------------------------| |-p |Displays file starting with | | |string|the first occurrence of the | | | |string. | | |------+-----------------------------+------------------------------| |-s |Prints multiple blank lines | | | |as a single blanks line. | | |------+-----------------------------+------------------------------| |-y |Sets the maximum number of | | |number|lines to scroll forward at | | | |one time. | | +-------------------------------------------------------------------+
The tac command's name comes from the fact that it was intended as the opposite of cat . However, tac remains useful after less has replaced cat .
Type: tac file.
Although a few options exist, they are not often used.
head has a companion tool called tail , which views the end of files. The options for both tools are similar, but have some important differences.
For example, head ordinarily displays the name of the file, while tail has more options.
Type: head options file .
The head Command (View) +-------------------------------------------------------------------+ | Option | Action | Comments | |------------+---------------------------------------+--------------| | | |Units are: | | |Sets the size of the display, and, | | | |optionally, the units. | * b : | |-c number | | Blocks. | |units |If no unit is specified, the size is in| * k : | | |bytes. | Kilobyes. | | | | * m : | | | | Megabytes.| |------------+---------------------------------------+--------------| | * -n | | | | number | | | | * --lines |Sets the number of lines to display. |The default is| | number | |10. | | | | | | | | | |------------+---------------------------------------+--------------| | * -q |Prevents display of the file name | | | * --quiet |header. | | +-------------------------------------------------------------------+
tail has a companion tool called head , which views the start of files. The options for both tools are similar, but have some important differences.
For example, tail has more options, while head ordinarily displays the name of the file.
Type: tail options file .
The tail Command (View) +-------------------------------------------------------------------+ | Option | Action | Comments | |-----------+-----------------------+-------------------------------| | |Sets the size of the | | | |display, and, |Units are: | |-c number |optionally, the units. | | |unit | | * b : blocks | | |If no unit is | * k: Kilobyes | | |specified, the size is | * m: megabytes | | |shown in bytes. | | |-----------+-----------------------+-------------------------------| | | |Press Ctrl-C to end. | | |Continues to display | | |-f |the last lines of a |This option is especially | | |file as it grows. |useful if you have a log file | | | |open as you try to debug. | |-----------+-----------------------+-------------------------------| | * -n |Sets lines to display, | | | number |measured from the end |The default is 10. | | * --lines|of the file. | | | number | | | |-----------+-----------------------+-------------------------------| | * -q |Prevents the display of| | | * --quiet|the file name header. | | |-----------+-----------------------+-------------------------------| | | |Arguments are: | |-number |Sets how much displays,| | |argument |measured from the end | * l: Lines. | | |of the file. | * b: Blocks. | | | | * c: Characters. | |-----------+-----------------------+-------------------------------| | | |Arguments are: | |+number |Sets how much displays,| | |argument |measured from the start| * l: Lines. | | |of the file. | * b: Blocks. | | | | * c: Characters. | +-------------------------------------------------------------------+
Linux includes three tools for comparing files automatically:
comm : Displays similar and different lines in two text files.
diff : Displays differences between files or directories, with a wide variety of options.
diff3 : Reports on three files, telling which ones are different.
[Note]
To save the results of a comparison to a file, or to print a copy, use redirection pipes. See Redirecting Input and Output for Commands, Section 5.5.6
Use the comm command for a basic comparison of text files. For more advanced comparisons, use diff .
Type: comm options 1st_file 2nd_file .
The results are printed in three columns. From left to right, they are:
Lines unique to the first file.
Lines unique to the second file.
Lines common to both files.
Use the - number option to keep a column from displaying. Arguments are 1 , 2 or 3 .
If you want to block two columns, enter them without any comma or space between them. For example, if you want to display only lines common to both files, enter -12 .
The comm command has no other options.
Use the diff command if you want to:
Compare two directories, including their sub-directories.
Show lines before and after differences.
Use metacharacters.
Type: diff options 1st_ file 2nd_file .
In the results, text from the first file is marked with a lesser-than symbol ( < ), while text from the second file is marked with a greater-than symbol ( > ).
The diff Command (Comparing) +-------------------------------------------------------------------+ | Option | Action | Comments | |---------------------------+--------------------+------------------| | |Ignores changes in | | | * -b |the amount of empty | | | |space. | | |---------------------------+--------------------+------------------| | * -B |Ignores blank lines.| | | * --ignore-blank-lines | | | |---------------------------+--------------------+------------------| | |Ignores the |If this command is| | |distinction between |not used, lower | |-i |upper and lower case|case letters are | | |letters when a |distinguished from| | |string is used. |upper case ones. | |---------------------------+--------------------+------------------| | |When comparing | | | * -x string |directories, |Metacharacters can| | * --exclude string |excludes directories|be used. | | |that match the | | | |string. | | |---------------------------+--------------------+------------------| | |When comparing | | | |directories, | | | * -X file |excludes files and | | | * --exclude-from = file |directories that | | | |match the pattern | | | |listed in file . | | |---------------------------+--------------------+------------------| | |Displays 3 lines | | |-c |before or after each| | | |result. | | |---------------------------+--------------------+------------------| | * -y |Displays results in | | | * --side-by-side |two columns. | | |---------------------------+--------------------+------------------| | |Includes | | | * -r |sub-directories when| | | * --recursive |comparing | | | |directories. | | |---------------------------+--------------------+------------------| | * -q |Only displays | | | * --brief |whether files | | | |differ. | | |---------------------------+--------------------+------------------| | * -s file |Only displays when | | | * --report-identical-file|files do not differ.| | +-------------------------------------------------------------------+
The diff3 command compares three files, and reports on the differences between them. It does not give detailed information about the differences, the way that diff does. diff3 can also be used to merge files using a simple script (see the man pages for more detail).
Type: diff3 options 1st_ file 2nd_file 3rd_file.
Two results may display:
=== All three files differ
=== file is different
The diff3 Command (Comparing and Merging) +-------------------------------------------------------------------+ | Option | Topic | Comments | |-----------+----------------------------+--------------------------| |-a |Compares binary files |Binary files are treated | | | |as text files. | |-----------+----------------------------+--------------------------| | * -m |Displays merged differences |Output can also be | | * --merge|on the screen. |redirected to a file | +-------------------------------------------------------------------+
[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ A ] [ B ] [ C ] [ D ] [ next ]
User's Guide (Obsolete Documentation) (Obsolete Documentation)
Version: 1.00p00, 2009.07.21-11:14