LINUX CLASSES - FILES
Linux Files and Directories
How Do I Create Linux Files and Directories?
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.
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
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
Previous Lesson: Copying and Renaming Files
Next Lesson: Deleting Files and Directories
[ RETURN TO INDEX ]
Comments - most recent first
(Please feel free to answer questions posted by others!)
(24 Aug 2015, 10:12
good work and keep it up.
(12 Feb 2013, 10:19
(18 Dec 2012, 09:45
I know that how we add file in same directory . name hope
(05 Sep 2012, 14:50
The Teucrian rout) caught Suero on the side. displeased with them," wrote
Nelson, "and certainly with reason;" and "You're a plucky boy. You ain't
one of the milk-and-water sort," said
(25 Aug 2012, 16:23
i need bacis command to create directories files in linux
(02 Feb 2012, 02:16
It's awesome Site for linux........
(11 Oct 2011, 15:53
Copy the files /etc/php.ini and /etc/vimrc into your misc directory?
(06 Oct 2011, 01:25
How to create a new directory and copy files from existing directory to new
(17 Aug 2011, 02:26
i need some introduction notes on linus please
Thank you in advance
(10 Aug 2011, 11:45
can we make directory using cat command.if.yes then how to do it?
(08 Aug 2011, 03:45
it's easier to remember the mkdir command if you remember that mk stands
for make and dir for directory
(20 Mar 2011, 18:07
nice work, thank you for this site
(29 Jan 2011, 06:40
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 ?
(07 Jan 2011, 08:44
oekmg2 Hvmbh ntmimong pgfbmkcazn rdyqtnrgnb kmbifanpc ybjpd rvxt tvplmkros
eojqxptqs dxslckbe xxlkzisz.
(06 Jan 2011, 19:11
CSN8pE Pyxv hfkzgqw zddzzzbz kfnatyneur ttkzzpm uqme xpywgnric mdrfgwbd
ayimdwfr qgldvv ctgvwvtw.
(06 Jan 2011, 18:34
APRra5 Cbewai wlljcna umnudbabus vrzdjbw teeonpvr kalswppacq elvx jksmq
(24 Dec 2010, 05:58
Thank you, it was very helpfull
(15 Dec 2010, 01:58
Linux won't support .exe, so you need to search for Linux compatible
(07 Oct 2010, 00:10
my usb modem has .exe file to install, but linux mint never initiates it
(unlike windows)...how to install any software in linux...plz help !
(04 Oct 2010, 05:10
how to create linux file,
which commend used.
cool as an Ice cream.....
(07 Sep 2010, 05:04
could you give more examples..... please.... I'm not really that familiar,
so I need more examples..
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.
by Bob Rankin
All rights reserved - Redistribution is allowed only with permission.