LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Create a script to display file name, Inode, and size of any file. Has to be a script (https://www.linuxquestions.org/questions/linux-newbie-8/create-a-script-to-display-file-name-inode-and-size-of-any-file-has-to-be-a-script-523898/)

JaxsunApex 01-29-2007 07:05 PM

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?

unSpawn 01-29-2007 07:13 PM

"man stat" would be a good start.

macemoneta 01-29-2007 07:13 PM

How about this:

Code:

#!/bin/bash
/bin/ls -1ish "$1"


unSpawn 01-29-2007 07:21 PM

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


JaxsunApex 01-29-2007 07:22 PM

It is that simple? I did all that and it can be compiled into one line?:scratch:

macemoneta 01-29-2007 07:23 PM

'man ls' will explain the options, but yes, it's just a one line script.

JaxsunApex 01-29-2007 07:37 PM

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

unSpawn 01-29-2007 08:15 PM

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



All times are GMT -5. The time now is 05:40 PM.