Recipe 9.13. Creating Files and Directories
9.13.1 Problem
You
want to organize your files by placing them in directories. But where
do directories come from? For that matter, how do you create a file?
9.13.2 Solution
Use mkdir and touch.
mkdir creates directories. Mind your filepaths!
This comand creates a new subdirectory in the current directory:
$ mkdir photos
This creates a new top-level directory. Only the superuser can do
this:
# mkdir /local_bins
You can set permissions when you create a directory:
# mkdir -m 755 /shared
To create a subdirectory and all of its parent directories at once,
use the -p flag:
$ mkdir -p photos/scanned/jpgs/thumbs
Most files are created by a program, such as a word processor, image
editor, or compiler. You can also create a new, empty file with
touch:
$ touch newfile.txt
9.13.3 Discussion
touch is useful in scripting, when you need the
script to create a new file. It's also useful for
creating placeholders, or for populating a directory for testing
things.
9.13.4 See Also
|