Doctor Bob
Linux Topic
Search

 
TOURBUS
HOME PAGE
SAVVY
CONSUMER
FREE TECH
SUPPORT

LINUX FILES

How Do I Create Linux Files and Directories?

Creating Files

If you want to create a new file rather than copy an existing one, use the touch command:
$ touch new.file

This creates a new, empty file.

If you issue the ls -l new.file command, you can verify that the file has a size of zero bytes. It might seem silly to create an empty file, but you can use them to verify that you have permission to create files in a certain directory, and some programs insist upon a control or log file even if it's empty. (The touch command will also update the time and date stamp on an existing file.)

If you'd rather create a new file with data in it--for example, a line of text--use the echo command:

$ echo "Remember to buy oatmeal raisin cookies." > reminder

This will create a file named reminder with just one line in it (the text in quotation marks). The echo command normally just prints a line to the screen, but here we've directed the output to a file. (This command also works in DOS.)

If you want to create a multiline file, use the cat command (similar to the DOS type command):

$ cat > fox.socks
Through three cheese trees three free fleas flew.
While these fleas flew, freezy breeze blew.
Freezy breeze made these three trees freeze.
Freezy trees made these trees' cheese freeze.
That's what made these three free fleas sneeze.
^D

The first line in this example tells Linux what to name the new file (fox.socks). The typed lines that follow will become the contents of this new file. Pressing ctrl-D tells Linux that the file is done, and the cat command transfers your typing to the new file.

Creating Directories

If you have a bunch of related files scattered in your home directory, why not create a directory for them? Use the mkdir command as follows:

$ mkdir cooking

This creates a new directory named cooking in the current directory, into which you can move all those recipes for easy retrieval.

For more information on the mkdir command, see the mkdir manual.

Previous Lesson: Copying and Renaming Files
Next Lesson: Deleting Files and Directories

[ RETURN TO INDEX ]




Ask Bob Rankin - Free Tech Support
<Send This Link to a Friend>         <Help>         <Bookmark This Page>


Copyright © by Bob Rankin
All rights reserved - Redistribution is allowed only with permission.