LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-29-2007, 07:05 PM   #1
JaxsunApex
LQ Newbie
 
Registered: Jan 2007
Posts: 5

Rep: Reputation: 0
Create a script to display file name, Inode, and size of any file. Has to be a script


This is what I have so far:

FILE="$1"
if [ $# -eq 0 ]; then
echo "$(The filename is: $0) - file-name"
exit 1
fi

set temp = `ls -l $fileName`
set size = $temp[4]

if (! -d $file)
set temp = `ls-l $file`
bytes = $bytes + $temp[4]
fi
echo "Total size = $bytes bytes."


textArray[0]="" # hold text
c=0 # counter
# read whole file in loop
while read line
do
textArray[c]=$line # store line
c=$(expr $c + 1) # increase counter by 1
done < $FILE
# get length of array
len=$(expr $c - 1 )

# use for loop to reverse the array
for (( i=$len; i>=0; i-- ));
do
echo ${textArray[$i]}
done

I created this in VI. I want to be able to display the filename, size, and Inode. Can anyone direct me?
 
Old 01-29-2007, 07:13 PM   #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
"man stat" would be a good start.
 
Old 01-29-2007, 07:13 PM   #3
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
How about this:

Code:
#!/bin/bash
/bin/ls -1ish "$1"
 
Old 01-29-2007, 07:21 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
or

Code:
#!/bin/sh
if [ -f "$1" ]; then file=`readlink -f "$1"`
 attrib=`stat -c "inode:%i size:%s" "${file}"` 
 echo "file:${file:=ERROR} ${attrib:=ERROR}"
else echo "This is soo bad, its a crime."; fi
exit 0
 
Old 01-29-2007, 07:22 PM   #5
JaxsunApex
LQ Newbie
 
Registered: Jan 2007
Posts: 5

Original Poster
Rep: Reputation: 0
It is that simple? I did all that and it can be compiled into one line?
 
Old 01-29-2007, 07:23 PM   #6
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
'man ls' will explain the options, but yes, it's just a one line script.
 
Old 01-29-2007, 07:37 PM   #7
JaxsunApex
LQ Newbie
 
Registered: Jan 2007
Posts: 5

Original Poster
Rep: Reputation: 0
I ran this code, but didn't get any file information:

#!/bin/sh
if [ -f "$1" ]; then file=`readlink -f "$1"`
attrib=`stat -c "inode:%i size:%s" "${file}"`
echo "file:${file:=ERROR} ${attrib:=ERROR}"
else echo "This is soo bad, its a crime."; fi
exit 0
 
Old 01-29-2007, 08:15 PM   #8
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 have to supply a /path/to/file as argument:
Code:
sh /tmp/script.sh /tmp/adore.o
file:/tmp/adore.o inode:20666 size:9321
 
  


Reply



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
File size using BASH script cb951303 Programming 16 11-07-2012 07:45 AM
File Size Shell Script BlackLabel Programming 7 11-27-2007 07:48 PM
Can you write a script to display file name, Inode, and size of any file? JaxsunApex Linux - Newbie 3 01-30-2007 08:39 AM
Help with file size script jpc82 Programming 10 04-01-2004 04:55 AM
Need script to check file size. _TK_ Linux - General 1 08-06-2001 08:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:21 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