- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to get info on file attributes ? Like leng...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 07:45 AM
тАО09-06-2006 07:45 AM
#########################################
Hello All,
Is there a way to determine the lenght of a file? or to get the attributes of a file ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 07:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 07:50 AM
тАО09-06-2006 07:50 AM
Re: How to get info on file attributes ? Like lenght of file
ls -al
when you say length, I am assuming you mean how many lines are in the file:
cat filename | wc -l
I wouldn't use cat on a binary file!
use file filename to determine filetype first
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 07:53 AM
тАО09-06-2006 07:53 AM
Re: How to get info on file attributes ? Like lenght of file
By file attributes, I presume that you mean things like the modification timestamp, the lastaccess timestamp, the last inode change timestamp, the size of the file in characters, for instance.
The 'ls' command offers the above information. Look at the manpages for 'ls' along with the manpages for 'stat(2)'. It's the 'stat' structure that holds these attributes.
If you mean the "type" or "kind" of file, use the 'file' command. The manpages for 'file' will enlighten you on how the "magic" [pun intended!] is performed to deduce whether a file is a "text" or a "binary" file for instance.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 08:04 AM
тАО09-06-2006 08:04 AM
Re: How to get info on file attributes ? Like lenght of file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 08:22 AM
тАО09-06-2006 08:22 AM
Re: How to get info on file attributes ? Like lenght of file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 08:37 AM
тАО09-06-2006 08:37 AM
Re: How to get info on file attributes ? Like lenght of file
In addition to using 'stat()' in a Perl script, Perl offers a plethora of file test operators to make life easy, too. These can make "asking" questions of the stat() information easy. For instance, instead of dissecting the octal mode from 'stat()' use Perl's "-u" with the file to test if the 'setuid' bit is set.
In reality, the shell 'test' operator has the same ability to determine if a file is readable, or has a size other than zero, or has the setuid bit set. See the 'test(1)' manpages.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 10:33 AM
тАО09-06-2006 10:33 AM
Re: How to get info on file attributes ? Like lenght of file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 10:40 AM
тАО09-06-2006 10:40 AM
Re: How to get info on file attributes ? Like lenght of file
An example, using Perl, to report the 'mtime' (modification timestamp) of a file would be:
# perl -le 'print scalar localtime ((stat($ARGV[0]))[8])' file
...which might look like:
# touch /tmp/me
# perl -le 'print scalar localtime ((stat($ARGV[0]))[8])' /tmp/me
Wed Sep 6 18:39:51 2006
...where my TZ=EST5EDT
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 10:47 AM
тАО09-06-2006 10:47 AM
Re: How to get info on file attributes ? Like lenght of file
...and in keeping with our running dialog, I should add this alternative:
# perl -le '$t=-M $ARGV[0];print $ARGV[0], " is ", $t*86400, " seconds old"' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 10:50 AM
тАО09-06-2006 10:50 AM
Re: How to get info on file attributes ? Like lenght of file
Yes, I know I need to read a perl book, but I'm in a rush. Thanks........... :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 11:19 AM
тАО09-06-2006 11:19 AM
Re: How to get info on file attributes ? Like lenght of file
Mother Nature abhors rushing. However, the top of this page (URL) offers you the answer and the documentation of why for 'mtime' I should have chosen the nineth and not the eight element of 'stat()' in my original example, above :-))
http://perldoc.perl.org/functions/stat.html
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 11:36 AM
тАО09-06-2006 11:36 AM
Re: How to get info on file attributes ? Like lenght of file
" size of file, in bytes ":
7 size total size of file, in bytes
####################################
but when I entered the following :
# perl -le 'print scalar size ((stat($ARGV[0]))[7])' /tmp/foo
Undefined subroutine &main::size called at -e line 1.
Seems I just do not get it. I'll take some time to review perl. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 11:47 AM
тАО09-06-2006 11:47 AM
Re: How to get info on file attributes ? Like lenght of file
# perl -le 'print ((stat($ARGV[0]))[7])' /tmp/foo
...returns the size in characters.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 11:49 AM
тАО09-06-2006 11:49 AM
Re: How to get info on file attributes ? Like lenght of file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 11:54 AM
тАО09-06-2006 11:54 AM
Re: How to get info on file attributes ? Like lenght of file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 02:10 PM
тАО09-06-2006 02:10 PM
Re: How to get info on file attributes ? Like lenght of file
I have no idea what this question means. The value representing the length of a file is in bytes and it is stored in the inode in binary format but in any event the value 694 (decimal) can be converted to whatever radix you choose including base 2 and Perl can do this as well. Now it is also possible that this lenfth doesn't mean what you think it means. Consider the case of writing a single byte at offset 0 and then doing an lseek() to offset 999,999 and writing another siggle byte and then closing the file. How big is this file? ls -l (and stat(), either the system call or the Perl function) will tell you it is 1MB but other utilities that look at the filesystem will tell you that this 1MB file is only 2 blocks (typically 1KiB) long --- and both are right --- they are simply measuring different things --- welcome to "sparse" files. When this file is read, the "missing" bytes are silently filled in with NUL's. To make it more confusing, if you copy this file, the copy will not be sparse and the file will truly be 1MB in length.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 08:16 PM
тАО09-06-2006 08:16 PM
Re: How to get info on file attributes ? Like lenght of file
ti get info about a file I use this simple ksh script:
#!/usr/bin/ksh
typeset tmp=$(head -1 $1)
typeset wcr=$(wc $1)
echo "$(basename $1): Reclen=${#tmp}, Lines=$(echo $wcr|awk '{print $1}'), Size=$(echo $wcr|awk '{print $3}'), \
Type='$(echo $(file $1)|awk -F ": " '{print $2}')'"
#eof
i.e:
finfo finfo
finfo: Reclen=14, Lines=6, Size=232, Type='commands text'
Take care that teh reclen info is valid only if all the record of your file have teh same length.
If you are interested to know info about records length just use:
awk '{printf "%2d %6i\n", NR,length($0)}' finfo
i.e:
awk '{printf "%2d %6i\n", NR,length($0)}' finfo
1 14
2 25
3 20
4 112
5 51
6 4
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2006 03:47 AM
тАО09-07-2006 03:47 AM
Re: How to get info on file attributes ? Like lenght of file
detailed, and it was not really needed. I now see the "ls" cmd delivers all the attributes I needed. I did learn other ways to obtain info needed. Thanks for putting up with me.
Your Friend.
Jerry Sims
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2006 03:56 AM
тАО09-07-2006 03:56 AM
Re: How to get info on file attributes ? Like lenght of file
As I originally noted, one hopes that 'ls' and 'stat()' return the same values! After all, 'stat()' is what 'ls' uses :-))
Regards!
..JRF...