|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to empty file contents w/o rm and touch
Hi all,
Can any one tell me how to empty the contents of a file in unix without using the following sequence : rm <file> ; touch <file> is there any command in unix?? is it possible through shell scripting? If so, how? -krishna |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Code:
echo "" > file cp /dev/null file dd if=/dev/zero of=output.file bs=1 count=1 |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Code:
cat /dev/null > your_file lorcan |
|
#4
|
|||
|
|||
|
and this, Code:
>filename |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
does this really work??? where and how to use this at the shell prompt?? |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
I think this works only with ksh/bash shell not in csh. you just have to enter the command in your prompt.
|
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Here are other ways not mentioned yet: Code:
: > file cat file > file ## Gives error message in ksh, but it works. head file > file tail file > file Last edited by Shell_Life; 07-18-2007 at 08:47 AM.. Reason: Display comment of error message in 'cat' |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| search for the contents in many file and print that file using shell script | cdfd123 | Shell Programming and Scripting | 3 | 10-07-2007 10:17 PM |
| File is not empty? | lesstjm | Shell Programming and Scripting | 7 | 07-12-2007 10:21 AM |
| empty file in hp-ux | Mizi | UNIX for Advanced & Expert Users | 2 | 08-09-2006 06:29 AM |
| Creating file contents using contents of another file | ReV | Shell Programming and Scripting | 21 | 02-24-2006 09:25 AM |
| command 'touch -c file/dir' | zp523444 | UNIX for Advanced & Expert Users | 1 | 11-20-2005 01:11 PM |
|
|