Need to empty


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to empty
# 1  
Old 03-19-2009
Need to empty

Hi,

How can I empty the files of *.txt.... in one command.
# 2  
Old 03-19-2009
empty ? you mean remove or size 0?
# 3  
Old 03-19-2009
not to remove, the size to 0...
# 4  
Old 03-19-2009
in one command you cant unless its just one file:
Code:
ant:/home/vbe $ ll file.txt
-rw-rw-rw-   1 vbe        bin           1010 Mar 19 19:50 file.txt
ant:/home/vbe $ >file.txt
ant:/home/vbe $ r ll
ll file.txt
-rw-rw-rw-   1 vbe        bin              0 Mar 19 19:51 file.txt
ant:/home/vbe $

# 5  
Old 03-19-2009
With some shells you can run a loop like this:
Code:
for f in *.txt; do > "$f";done

With others (Z shell with its mult_ios):

Code:
:>*.txt

# 6  
Old 03-19-2009
Thank you for your help, but I am trying to empty a set of txt files under one path, and not for a single one... there stands by doubt....

Thank you in advance.
# 7  
Old 03-19-2009
Thank you for your update, this script [ for f in *.txt; do > "$f";done ] worked out ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

if/else with an empty file...

Hi there, I'm just starting out with shell scripting and I'm trying to make a test where the script will basically run yum check-update to find out if the server has any available and if it does it e-mails me but if not it will just stop there. I have it working if there are actually... (7 Replies)
Discussion started by: Imnewtothis
7 Replies

2. Shell Programming and Scripting

Need help If empty - perl

Hi, I need help if I list all the file that determined by user input and if program cannot find file it will display " there no file that you looking for " here is my code but it not working #!/usr/bin/perl -w print "Enter Advance Search Function: "; chomp ($func = <STDIN>); my @func1 =... (2 Replies)
Discussion started by: guidely
2 Replies

3. Shell Programming and Scripting

Empty out the file

Hi All, I have a piece of perl code in which I DON'T want to delete a file rather empty out the contents, here is the code - if ( unlink("$opt_b") == 1 ) { print_log( "$opt_b deleted", 1 ); }else { print_log( "Could not delete $opt_b:$!", 1 ); ... (5 Replies)
Discussion started by: jacki
5 Replies

4. Shell Programming and Scripting

To empty the files

Hi, Using the shell script, how can I empty the files that are under a dir. -Siva (2 Replies)
Discussion started by: gsiva
2 Replies

5. Shell Programming and Scripting

empty crontab

how to create empty crontab using shell script? (7 Replies)
Discussion started by: crackthehit007
7 Replies

6. Shell Programming and Scripting

while file is empty

how can i use while loop ? while file is empty do.... if not empty do ..... in bash (1 Reply)
Discussion started by: Trump
1 Replies

7. Shell Programming and Scripting

while var not empty

Hi! How can I run a cicle while one var is not empty? Or better saying how can I see if the var has something? thanks (1 Reply)
Discussion started by: ruben.rodrigues
1 Replies

8. UNIX for Dummies Questions & Answers

Getting same exit status for empty and non empty file

Hi All, I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both. The value of $? is coming 0 in if part also and else part too. #!/bin/ksh if ]; then echo "data" # exit 0 echo "$?" else... (4 Replies)
Discussion started by: mavesum
4 Replies

9. UNIX for Dummies Questions & Answers

how to find empty folders without using -empty

hi all: my solaris FIND does not support find myFolder -type d -empty how can i find the empty folders? thanks! (7 Replies)
Discussion started by: lasse
7 Replies

10. UNIX for Advanced & Expert Users

empty file in hp-ux

Hi, I need your help. How can I create an empty filename with a specific size, in hp-ux? Regards, Mizi (2 Replies)
Discussion started by: Mizi
2 Replies
Login or Register to Ask a Question