LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-06-2010, 12:56 PM   #1
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Unexpected output from stat --format %h


Hello

stat is (generously) giving twice the expected output:
Code:
c@CW8:/tmp$ touch foo
c@CW8:/tmp$ ln foo bar
c@CW8:/tmp$ /bin/ls -l foo bar
-rw-r--r-- 2 c users 0 2010-03-07 00:17 bar
-rw-r--r-- 2 c users 0 2010-03-07 00:17 foo
c@CW8:/tmp$ stat foo --format '%h' foo
2
2
c@CW8:/tmp$ stat foo --format '%h' --terse foo
2
2
c@CW8:/tmp$ stat foo --format '%h %n' --terse foo
2 foo
2 foo
c@CW8:/tmp$ rm bar
c@CW8:/tmp$ stat foo --format '%h %n' --terse foo
2 foo
2 foo
c@CW8:/tmp$ stat foo
  File: `foo'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 807h/2055d      Inode: 442175      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/       c)   Gid: (  100/   users)
Access: 2010-03-07 00:17:48.991592829 +0530
Modify: 2010-03-07 00:17:48.991592829 +0530
Change: 2010-03-07 00:22:23.299909243 +0530
c@CW8:/tmp$ type stat
stat is hashed (/usr/bin/stat)
c@CW8:/tmp$ stat --version
stat (GNU coreutils) 7.4
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Michael Meskes.
Is this a bug or have I misunderstood how stat works?

Best

Charles
 
Old 03-07-2010, 02:35 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
You're asking for it twice so you're getting it twice. Shouldn't you just use 'stat -c '%h' /target'?
 
1 members found this post helpful.
Old 03-07-2010, 03:00 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578

Original Poster
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by unSpawn View Post
You're asking for it twice so you're getting it twice. Shouldn't you just use 'stat -c '%h' /target'?
So I am! Thanks for spotting it.
 
  


Reply

Tags
links, stat



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
understanding stat() output Aquarius_Girl Programming 5 02-23-2010 12:37 AM
[SOLVED] stat command to print permission in octal format cola Linux - General 2 10-11-2009 07:14 PM
stat=Deferred: 421 Unexpected log failure, please try later in sendmail riton71 Linux - Server 1 12-12-2007 08:12 PM
Cannot stat Input/Output error cygnus-x1 Linux - General 5 08-16-2006 09:48 AM
the format of the date in stat in wrong rhuser Programming 9 03-16-2003 12:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration