LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   making the file containing large data empty (https://www.linuxquestions.org/questions/linux-newbie-8/making-the-file-containing-large-data-empty-711959/)

chetanpatel 03-16-2009 08:49 AM

making the file containing large data empty
 
Hi all
I want to make a file empty which contain some data.
I am trying as follows
echo "" > filename.
but it is not working.
Please help

JaksoDebr 03-16-2009 09:12 AM

This depends on what you mean by empty. An empty file is usually a file with zero-byte length. Sometimes a file containing any number of zero-bytes is also called empty. A file with some specific file file type, like a TIFF image, that contains the file structure, but no image at all, can also be called empty.

Your attempt with 'echo "" > filename' only gives a zero-length file - obviously not what you want.

To create a file containing NULL bytes you can use the 'dd' command by using /dev/null as the input (something like 'dd if=/dev/null of=your.file', but read the man page first).

To keep a specific file format, but removing custom content data, you still have to keep the file format intact. An empty OpenOffice document, for example, is one that doesn't contain custom text - the same as a newly created document.

JD

Linux Archive

malekmustaq 03-16-2009 11:27 AM

Quote:

Originally Posted by chetanpatel (Post 3477031)
Hi all
I want to make a file empty which contain some data.
I am trying as follows
echo "" > filename.
but it is not working.
Please help

==========================

chetanpatel:

You said: "I want to make a file empty which contain some data."

Answer 1: If you truly mean CREATING (make) "file" that contains nothing do this:

$ touch <filename>

this creates an empty file. Check if it is there: ls -l <filename>

Answer 2: But if you mean a "folder" (since folder is considered file) do this:

$ cd <folder> (that's to get inside the folder)
$ rm -rf * (that deletes all files inside it and subfolders as well)

==>Notabene: This rm -fr is dangerous, be certain what you are doing. Also it cannot delete files/folders that you did not create: to overcome this you must login as root first then cd to the directory folder the contents of which you wanted to delete. Sometimes you need to own them first by chown if the UID that created it belonged somewhere from other galaxy; do this:

# chown root:root *

then you can execute the verdict above.

[The multitude of my answers sprang out not from my loquacity but from my sincere inclination to help despite your very "vague" question. I understand that we in this forum came from several languages and our English just vary from all sides. For this you may pardon my long answer to a short question.]

Anyway, I hope this helps.

Be careful. Goodluck.

palisetty_suman 03-16-2009 12:00 PM

Hi
 
Thanks malek

H_TeXMeX_H 03-16-2009 12:15 PM

There's also:

Code:

cat /dev/null > file


All times are GMT -5. The time now is 06:07 AM.