Sign in to follow this  
AplexTM

Bash Scripting Count only files we own

Recommended Posts

#!/bin/bash
# Counting the number of lines in a list of files
# for loop over arguments
# count only those files I am owner of

if [ $# -lt 1 ]
then
 echo "Usage: $0 file ..."
 exit 1
fi

echo "$0 counts the lines of code" 
l=0
n=0
s=0
for f in $*
do
 if [ -O $f ] # checks whether file owner is running the script
 then 
     l=`wc -l $f | sed 's/^\([0-9]*\).*$/\1/'`
     echo "$f: $l"
     n=$[ $n + 1 ]
     s=$[ $s + $l ]
 else
     continue
 fi
done

echo "$n files in total, with $s lines in total"

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this