command to read file name and size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting command to read file name and size
# 1  
Old 01-09-2009
command to read file name and size

hi all,
there is any command or anything we can use to read the file name and size. thanks
# 2  
Old 01-09-2009
ls -l

If that's not the command you were looking for, then post a better question.
# 3  
Old 01-09-2009
okkk....sorry i ask u bit wrong question....

here is what i want to do..
i wanna read only file name and size from ls -l out put (-rwxr-xr-x 1 root root 220 Jan 7 09:15 filmon) and also i wanna store them in variables. Thanks.
# 4  
Old 01-09-2009
Quote:
Originally Posted by s_linux
i wanna read only file name and size from ls -l out put (-rwxr-xr-x 1 root root 220 Jan 7 09:15 filmon) and also i wanna store them in variables.

Code:
set -f
set -- $( ls -l filmon )
size=$5
filename=$9

# 5  
Old 01-10-2009
Code:
fname=`stat -c '%n' file`
fsize=`stat -c '%s' file`

# 6  
Old 01-10-2009
for file name use this command
export file_name=`ls -l | awk '{print $9}'`
echo $file_name to display
for size file_size=`ls -l | awk '{print $5}'`
echo $file_size to display
# 7  
Old 01-10-2009
Quote:
Originally Posted by agn
Code:
fname=`stat -c '%n' file`
fsize=`stat -c '%s' file`


The stat command is not standard, and neither is its syntax on those systems that do have it:

Code:
$ fname=`stat -c '%n' file`
stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]

The -c option works with the GNU version of stat, but it is only necessary to call it once:

Code:
eval "$( stat -c 'fname="%n" fsize="%s"' "$FILE"' )

The *BSD syntax is:

Code:
eval "$( stat -f 'fname="%N" fsize="%z"' "$FILE"' )

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

2. HP-UX

find command to display size and date of a file

Hi, The blow code does not yeild any output. find . -name "*.jar" -o -name "*.ksh" -o -name "*.properties" -name "*.war" -o -name "*.ear" -o -name "*.sh" -o -name "*.cfg" -exec ls -l {} \; I wish to print the filename filesize filedate in HP-UX. Can anyone help ? (9 Replies)
Discussion started by: mohtashims
9 Replies

3. HP-UX

Performance issue with 'grep' command for huge file size

I have 2 files; one file (say, details.txt) contains the details of employees and another file (say, emp.txt) has some selected employee names. I am extracting employee details from details.txt by using emp.txt and the corresponding code is: while read line do emp_name=`echo $line` grep -e... (7 Replies)
Discussion started by: arb_1984
7 Replies

4. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

5. Shell Programming and Scripting

command to reduce size of file/directory???

Hello, I want to compress any given file or directory. I used 1)gzip 2)zip But when I do "ls -l". I found that the zipped file is in fact greater in size than the original file. Can you please tell me the commands which will show me the difference in its size. (2 Replies)
Discussion started by: nsharath
2 Replies

6. HP-UX

command to list file size

I'm new to HP-UX and am looking for the command that will allow to me determine the total size of listed files. I'm being told that my backup selection is exceeding my tape drive size and need to determine how much information is being backed up. Help? (3 Replies)
Discussion started by: rgordon
3 Replies

7. UNIX for Dummies Questions & Answers

Command to get file size..

Hi, Apart from ll -s, is there any way to check the file size. I am working on a script to send a alert when the file size nears the ulimit. So need the command that will show just the size in bytes. Also clear my another doubt.When ulimit -a shows the following time(seconds) ... (5 Replies)
Discussion started by: preethgideon
5 Replies

8. UNIX for Dummies Questions & Answers

Extracting only file size of the ls -ltr command.

All, I only need to get the file size when I do an ls -ltr filename.txt Could you give me the exact syntax. Thanks KOP (6 Replies)
Discussion started by: kingofprussia
6 Replies

9. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

10. Shell Programming and Scripting

File size limitation of unix sort command.

hi , iam trying to sort millions of records which is delimited and i cant able to use sort command more than 60 million..if i try to do so i got an message stating that "File size limit exceeded",Is there any file size limit for using sort command.. How can i solve this problem. thanks ... (7 Replies)
Discussion started by: cskumar
7 Replies
Login or Register to Ask a Question