-->
Previous Table of Contents Next


In Table 17.5, size is a number and also may be C for sizeof(char), S for sizeof(short), I for sizeof(int), or L for sizeof(long). If type is f, size may also be F for sizeof(float), D for sizeof(double), or L for sizeof(long double).


NOTE:  sizeof is a C language function that returns the number of bytes in the data structure passed as the parameter. For example, you would use the following function call to determine the number of bytes in an integer on your system, because the number of bytes in an integer is system-dependent:

sizeof( int );


radix in Table 17.3 stands for number system and is d for decimal, o for octal, x for hexadecimal, or n for none. bytes is hexadecimal with a prefix of 0x or 0X; it’s multiplied by 512 with a b suffix, by 1,024 with k, and by 1,048,576 with an m suffix. -s without a number implies 3; -w without a number implies 32. By default, od uses -A o -t d2 -w 16.

Searching for Files

If you can’t find a file by looking with the ls command, you can use the find command. The find command is an extremely powerful tool, which makes it one of the more difficult commands to use. The find command has three parts, each of which can consist of multiple subparts:

  Where to look
  What to look for
  What to do when you find it

If you know the name of a file but don’t know where in the Linux file structure it’s located, the simplest case of the find command works like this:


find / -name filename -print


CAUTION:  
Be careful when searching from the root directory; on large systems, it can take a long time to search every directory beginning with the root directory and continuing through every subdirectory and disk (and remotely mounted disk) to find what you’re looking for.

It may be more prudent to limit the search to one or two directories, at most. For example, if you know that a file is probably in the /usr or /usr2 directory, use the following command instead:


find /usr /usr2 -name filename -print

You can use many different options with find; Table 17.6 lists just a few. To see all the available options, use the man find command.

Table 17.6 A Sample of the find Command Flags

Command Description

-name file The file variable can be the name of a file or a wildcarded filename. If it’s a wildcarded filename, every file that matches the wildcards is selected for processing.
-links n Any file that has n or more links to it is selected for processing. Replace n with the number you want to check.
-size n[c] Any file that occupies n or more 512-byte blocks is selected for processing. A c appended to n means to select any file that occupies n or more characters.
-atime n Select any file that has been accessed in the past n days. Note that the act of looking for a file with find modifies the access date stamp.
-exec cmd After you select a list of files, you can run a Linux command that uses the selected files as an argument. You use two simple rules with -exec: the name of a selected file is represented by {}, and the command must be terminated by an escaped semicolon, which is represented by \;. Suppose you create a user directory while logged in as root. As a result, all the files are owned by root, but the files should be owned by the user. You would issue the following command to change the owner of all the files in /home/jack and all subdirectories from root to jack: find /home/jack -exec chown jack {} \;
-print This instruction, the most often used, simply prints the name and location of any selected files.

The find command allows you to perform many logical tests on files as well. For example, if you want to find a selection of filenames that can’t be collectively represented with wildcards, you can use the or option (-o) to obtain a list:


find /home ( -name file1 -o -name file2 ) -print

You can combine as much selection criteria as you want with the find command. Unless you specify the -o option, find assumes you mean and. For example, the command find -size 100 -atime 2 means find a file that’s at least 100 blocks in size and that was last accessed at least two days ago. You can use parentheses, as in the above example, to prevent ambiguous processing of your criteria, especially if you combine an and/or selection criteria.

Changing File Time and Date Stamps

Each Linux file maintains three time and date stamps: the date of the file’s creation, the date of the file’s last modification, and the date of the last access. The file creation date can’t be changed artificially except by deliberately copying and renaming a file. Whenever a file is read or opened by a program, the file’s access date stamp is modified. As mentioned in the preceding section, using the find command also causes the access date to be modified.

If a file is modified in any way—that is, if it’s written to, even if the file is actually not modified—the file modification and file access date stamps are updated. The date stamps on a file are useful if you need to back up selectively only files that have been modified since a given date. You can use the find command for this purpose.

If you want to modify the date stamps on a file without actually modifying the file, you can do so with the touch command. By default, touch updates the access and modification date stamps on a file with the current system date. By default, if you attempt to touch a file that doesn’t exist, touch creates the file.


Previous Table of Contents Next