Section 3.17. Creating a Directory: mkdir


[Page 58 (continued)]

3.17. Creating a Directory: mkdir

Rather than clog up my home directory with the many versions of "heart," I decided to create a subdirectory called "lyrics" in which to keep them all. To do this, I used the mkdir utility, as described in Figure 3-20.

Figure 3-20. Description of the mkdir command.

Utility: mkdir [-p] newDirectoryName

The mkdir utility creates a directory. The -p option creates any parent directories in the newDirectoryName pathname that do not already exist. If newDirectoryName already exists, an error message is displayed and the existing file is not altered in any way.



[Page 59]

Here's how I did it:

$ mkdir lyrics         ...create a directory called "lyrics". $ ls -lFG              ...confirm. -rw-r--r--  1  glass   106   Jan 30  23:28   heart.ver1 drwxr-xr-x  2  glass   512   Jan 30  19:49   lyrics/ $ _ 


The letter "d" at the start of the permission flags of "lyrics" indicates that it's a directory file.

In general, you should keep related files in their own separate directory. If you name your directories sensibly, it'll make it easy to track down files weeks, or even years, after you create them.

Once the "lyrics" directory was created, the next step was to move the "heart.ver1" into its new location. To do this, I used mv, and confirmed the operation using ls:

$ mv heart.ver1 lyrics  ...move into "lyrics" $ ls                    ...list the current directory. lyrics/                 ..."heart.ver1" has gone. $ ls lyrics             ...list the "lyrics" directory. heart.ver1              ..."heart.ver1" has moved. $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net