Linux Files and Directories
How Do I Create Linux Files and Directories?
Creating FilesIf 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
Comments - most recent first
(Please feel free to answer questions posted by others!)
Thank you in advance
nice work, thank you for this site
I used the echo command as told by you above. It does make a file in my current directory but when i open it in any text editor (i tried gedit, kate, openoffice, vim), the file seems empty. There is no text written in it. I use Ubuntu 10.10.
Can you tell me what am I doing wrong here ?
Linux won't support .exe, so you need to search for Linux compatible installer
which commend used.
thank you God bless...
I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But
don't ask me to send what you already have. :-) NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Copyright © by -
All rights reserved - Redistribution is allowed only with permission.

