You are not logged in.
Pages: 1
Hi guys,
I'm thinking about this piece of command lines:
[user@host ~]$ echo "first word" > test
[user@host ~]$ cat test
first word
[user@host ~]$ { rm ./test && awk -F' ' '{ print $2,$1 }' > ./test; } < ./test
[user@host ~]$ cat test
word first
[user@host ~]$ { awk -F' ' '{ print $2,$1 }' > ./test; } < ./test
[user@host ~]$ cat test
[user@host ~]$ ls -l test
-rw-r--r-- 1 user user 0 17 apr 22.06 test
I wonder why:
{ rm ./test && awk -F' ' '{ print $2,$1 }' > ./test; } < ./test
works as I expect (the file "test" have words in reverse order), while instead:
{ awk -F' ' '{ print $2,$1 }' > ./test; } < ./test
give a file "test" empty, with size 0.
Why and how the leding "rm" make the difference?
Thanks
Mine
Only those who have the courage to take a penalty miss them. (R. Baggio)
Offline
The first example results in the inode of ./test changing, whilst the second maintains the same inode. Try ls -i
Although the file is deleted with rm, the redirect < still has a handle to the original inode and continues to read from it.
Without the rm, the redirect > overwrites the data at that inode, hence no data to process.
Last edited by zorro (2012-04-17 20:57:42)
Offline
The first example results in the inode of ./test changing, whilst the second maintains the same inode. Try ls -i
Although the file is deleted with rm, the redirect < still has a handle to the original inode and continues to read from it.
Without the rm, the redirect > overwrites the data at that inode, hence no data to process.
Thanks for this explanation. OP made me curious.
Offline
Thank you zorro, now it is more clear!
About this I find a useful link: http://backreference.org/2011/01/29/in- … -of-files/
OP made me curious.
/dev/zero, what do you mean with "OP"?
Mine
Only those who have the courage to take a penalty miss them. (R. Baggio)
Offline
:: Registered Linux User No. 223384
:: github
:: infinality-bundle+fonts: good looking fonts made easy
Offline
AHAHAH... you're very amusing.
Op has many meanings, what of the thoundas I find on internet is the meaning /dev/zero was thinking?
OP=OPerating system
OP=Original Poster
OP=Operator Access
(and so on...)
Less sarcasm (offsite) and more pragmatism, please.
Mine
Only those who have the courage to take a penalty miss them. (R. Baggio)
Offline
bohoomil wrote:AHAHAH... you're very amusing.
Op has many meanings, what of the thoundas I find on internet is the meaning /dev/zero was thinking?
OP=OPerating system
OP=Original Poster
OP=Operator Access
(and so on...)Less sarcasm (offsite) and more pragmatism, please.
http://netforbeginners.about.com/od/int … -Is-OP.htm
Happy ?
Offline
Yes, first for explanation and second for /dev/zero comment, which I can now understand.
I'm not a forums "habitue", so the question
Mine
Only those who have the courage to take a penalty miss them. (R. Baggio)
Offline
Pages: 1