If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Clearing ocntents of file but retain permissions

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-20-04, 16:21
Armando Soto Armando Soto is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
Exclamation Clearing ocntents of file but retain permissions

Is there a way to clear the contents of a file without removing any of the permissions?

Currently I use the rm filename to removed the entire file but then I always have to go back in and rest the permissions.

Can anyone help me with a script that will clear the contents but leave the permissions intact?


Any help is greatly appreciated.

Thanks in advance..
Armando
Reply With Quote
  #2 (permalink)  
Old 12-20-04, 17:06
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
> /path2file
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 12-21-04, 03:26
srsjc srsjc is offline
Registered User
 
Join Date: Jun 2004
Posts: 20
sed -e '/^/d' Inputfile >tempfile
mv tempfile Inoutfile
Reply With Quote
  #4 (permalink)  
Old 12-21-04, 09:55
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Code:
echo /dev/null>/path2file
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #5 (permalink)  
Old 12-21-04, 10:01
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
Quote:
Originally Posted by LKBrwn_DBA
Code:
echo /dev/null>/path2file
'/path2file' will containg '/dev/null'
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #6 (permalink)  
Old 12-21-04, 13:50
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Thumbs down

Ooops, yes, it should be cat instead of echo!
Code:
 cat /dev/null>/path2file
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #7 (permalink)  
Old 12-21-04, 14:41
Armando Soto Armando Soto is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
Quote:
Originally Posted by LKBrwn_DBA
Ooops, yes, it should be cat instead of echo!
Code:
 cat /dev/null>/path2file
I tried this and it still took the permissions from the file. Any other ideas?
Reply With Quote
  #8 (permalink)  
Old 12-21-04, 15:54
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Question

Quote:
Originally Posted by Armando Soto
I tried this and it still took the permissions from the file. Any other ideas?
Which operating system?
I tested on Solaris and the permissions were not changed!
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On