Coreutils-5.2.1

The Coreutils package contains utilities for showing and setting the basic system characteristics.

Approximate build time:  0.9 SBU
Required disk space:     69 MB

Coreutils installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, Perl, Sed.

Installation of Coreutils

Normally the functionality of uname is somewhat broken, in that the -p switch always returns “unknown”. The following patch fixes this behavior for Intel architectures:

patch -Np1 -i ../coreutils-5.2.1-uname-1.patch

We do not want Coreutils to install its version of the hostname program, because it is inferior to the version provided by Net-tools. Prevent its installation by applying a patch:

patch -Np1 -i ../coreutils-5.2.1-hostname-1.patch

Now prepare Coreutils for compilation:

DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/usr

Compile the package:

make

The test suite of Coreutils makes several assumptions about the presence of files and users that aren't valid this early in the LFS build. We will therefore have to set up a few things before being able to run the tests. If you choose not to run these tests, skip down to “Install the package”.

To be able to run the full test suite, the su program needs to be installed. We didn't bother to install this little program in Chapter 5 because it requires root privileges, so do it now:

make install-root

Create a 'table of mounted filesystems' file with:

touch /etc/mtab

And create two dummy groups and a dummy user name:

echo "dummy1:x:1000" >> /etc/group
echo "dummy2:x:1001:dummy" >> /etc/group
echo "dummy:x:1000:1000:::/bin/bash" >> /etc/passwd

Now you're all set to run the test suite. First run the few tests that are meant to be run as root:

export NON_ROOT_USERNAME=dummy; make check-root

Then run the remainder of the tests as the dummy user:

su dummy -c "make RUN_EXPENSIVE_TESTS=yes check"

When you're done testing, remove the dummy user and groups:

sed -i.bak '/dummy/d' /etc/passwd /etc/group

Install the package:

make install

And move some programs to their proper locations:

mv /usr/bin/{basename,cat,chgrp,chmod,chown,cp,dd,df} /bin
mv /usr/bin/{date,echo,false,head,install,ln,ls} /bin
mv /usr/bin/{mkdir,mknod,mv,pwd,rm,rmdir,sync} /bin
mv /usr/bin/{sleep,stty,su,test,touch,true,uname} /bin
mv /usr/bin/chroot /usr/sbin

We'll be using the kill program from the Procps package (installed as /bin/kill later in the chapter). Remove the one installed by Coreutils:

rm /usr/bin/kill

Finally, create two symlinks to be FHS-compliant:

ln -s test /bin/[
ln -s ../../bin/install /usr/bin

Contents of Coreutils

Installed programs: basename, cat, chgrp, chmod, chown, chroot, cksum, comm, cp, csplit, cut, date, dd, df, dir, dircolors, dirname, du, echo, env, expand, expr, factor, false, fmt, fold, groups, head, hostid, hostname, id, install, join, link, ln, logname, ls, md5sum, mkdir, mkfifo, mknod, mv, nice, nl, nohup, od, paste, pathchk, pinky, pr, printenv, printf, ptx, pwd, readlink, rm, rmdir, seq, sha1sum, shred, sleep, sort, split, stat, stty, su, sum, sync, tac, tail, tee, test, touch, tr, true, tsort, tty, uname, unexpand, uniq, unlink, uptime, users, vdir, wc, who, whoami and yes

Short descriptions

basename strips any path and a given suffix from the given file name.

cat concatenates files to standard output.

chgrp changes the group ownership of each given file to the given group. The group can be either given a a name or a numeric ID.

chmod changes the permissions of each given file to the given mode. The mode can be either a symbolic representation of the changes to make, or an octal number representing the new permissions.

chown changes the user and/or group ownership of each given file to the given user:group pair.

chroot runs a given command with the specified directory as the / directory. The given command can be an interactive shell. On most systems only root can do this.

cksum prints the CRC (Cyclic Redundancy Check) checksum and the byte counts of each specified file.

comm compares two sorted files, outputting in three columns the lines that are unique, and the lines that are common.

cp copies files.

csplit splits a given file into several new files, separating them according to given patterns or line numbers, and outputting the byte count of each new file.

cut prints parts of lines, selecting the parts according to given fields or positions.

date displays the current time in the given format, or sets the system date.

dd copies a file using the given block size and count, while optionally performing conversions on it.

df reports the amount of disk space available (and used) on all mounted file systems, or only on the file systems holding the given files.

dir is the same as ls.

dircolors outputs commands to set the LS_COLOR environment variable, to change the color scheme used by ls.

dirname strips the non-directory suffix from a given file name.

du reports the amount of disk space used by the current directory, or by each of the given directories including all their subdirectories, or by each of the given files.

echo displays the given strings.

env runs a command in a modified environment.

expand converts tabs to spaces.

expr evaluates expressions.

factor prints the prime factors of all specified integer numbers.

false does nothing, unsuccessfully. It always exits with a status code indicating failure.

fmt reformats the paragraphs in the given files.

fold wraps the lines in the given files.

groups reports a user's group memberships.

head prints the first ten lines (or the given number of lines) of each given file.

hostid reports the numeric identifier (in hexadecimal) of the host.

hostname reports or sets the name of the host.

id reports the effective user ID, group ID, and group memberships of the current user, or of a given user.

install copies files while setting their permission modes and, if possible, their owner and group.

join joins from two files the lines that have identical join fields.

link creates a hard link with the given name to the given file.

ln makes hard links or soft links between files.

logname reports the current user's login name.

ls lists the contents of each given directory. By default it orders the files and subdirectories alphabetically.

md5sum reports or checks MD5 (Message Digest 5) checksums.

mkdir creates directories with the given names.

mkfifo creates FIFOs (First-In, First-Out, a "named pipe" in UNIX parlance) with the given names.

mknod creates device nodes with the given names. A device node is a character special file, or a block special file, or a FIFO.

mv moves or renames files or directories.

nice runs a program with modified scheduling priority.

nl numbers the lines from the given files.

nohup runs a command immune to hangups, with output redirected to a log file.

od dumps files in octal and other formats.

paste merges the given files, joining sequentially corresponding lines side by side, separated by tab characters..

pathchk checks whether file names are valid or portable.

pinky is a lightweight finger. It reports some information about the given users.

pr paginates and columnates files for printing.

printenv prints the environment.

printf prints the given arguments according to the given format -- much like the C printf function.

ptx produces from the contents of the given files a permuted index, with each keyword in its context.

pwd reports the name of the current directory.

readlink reports the value of the given symbolic link.

rm removes files or directories.

rmdir removes directories, if they are empty.

seq prints a sequence of numbers, within a given range and with a given increment.

sha1sum prints or checks 160-bit SHA1 checksums.

shred overwrites the given files repeatedly with strange patterns, to make it real hard to recover the data.

sleep pauses for the given amount of time.

sort sorts the lines from the given files.

split splits the given file into pieces, by size or by numbspliter of lines.

stty sets or reports terminal line settings.

su runs a shell with substitute user and group IDs.

sum prints checksum and block counts for each given file.

sync flushes file system buffers. It forces changed blocks to disk and updates the super block.

tac concatenates the given files in reverse.

tail prints the last ten lines (or the given number of lines) of each given file.

tee reads from standard input while writing both to standard output and to the given files.

test compares values and checks file types.

touch changes file timestamps, setting the access and modification times of the given files to the current time. Files that do not exist are created with zero length.

tr translates, squeezes, and deletes the given characters from standard input.

true does nothing, successfully. It always exits with a status code indicating success.

tsort performs a topological sort. It writes a totally ordered list according to the partial ordering in a given file.

tty reports the file name of the terminal connected to standard input.

uname reports system information.

unexpand converts spaces to tabs.

uniq discards all but one of successive identical lines.

unlink removes the given file.

uptime reports how long the system has been running, how many users are logged on, and the system load averages.

users reports the names of the users currently logged on.

vdir is the same as ls -l.

wc reports the number of lines, words, and bytes for each given file, and a total line when more than one file is given.

who reports who is logged on.

whoami reports the user name associated with the current effective user ID.

yes outputs 'y' or a given string repeatedly, until killed.