Saving Output to Other Files

Problem

You want to save the output with a redirect to elsewhere in the filesystem, not in the current directory.

Solution

Use more of a pathname when you redirect the output.

$ echo some more data > /tmp/echo.out

or:

$ echo some more data > ../../over.here

Discussion

The filename that appears after the redirection character (the >) is actually a path-name. If it begins with no other qualifiers, the file will be placed in the current directory.

If that filename begins with a slash (/) then this is an absolute pathname, and will be placed where it specifies in the filesystem hierarchy (i.e., tree) beginning at the root (provided all the intermediary directories exist and have permissions that allow you to traverse them). We used /tmp since it is a well-known, universally available scratch directory on virtually all Unix systems. The shell, in this example, will create the file named echo.out in the /tmp directory.

Our second example, placing the output into ../../over.here, uses a relative path-name, and the .. is the specially-named directory inside every directory that refers to the parent directory. So each reference to .. moves up a level in the filesystem tree (toward the root, not what we usually mean by up in a tree). The point here is that we can redirect our output, if we want, into a file that is far away from where we are running the command.

See Also

  • Learning the bash Shell by Cameron Newham (O’Reilly), See Also, Problem, Discussion, See Also for an introduction to files, directories, and the dot notation (i.e., . and .. )

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.218.215