Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 17 of 17
I am running the script on a BSD machine. The stat "switches" are not the same on an BSD machine. When I run this code I am getting the error ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Just Joined!
    Join Date
    Dec 2013
    Posts
    10

    I am running the script on a BSD machine. The stat "switches" are not the
    same on an BSD machine.

    When I run this code I am getting the error messages:
    stat: illegal option -- c
    usage: stat [-FLnq] [-f format | -l | -r | -s | -x] [-t timefmt] [file ...]
    If I use the code
    Code:
    while read -r s f
    do 
    	echo "$f"
    	ts+=$s
    done < <(stat -f '%N %z' ~/Desktop/1/*)
    I get the ouput:
    243
    271
    3385
    271
    271
    718
    441
    194
    649
    149
    124
    73
    15243
    15243
    3469
    475
    271
    2795
    242
    is empty.sh 131

  2. #12
    Just Joined!
    Join Date
    Dec 2013
    Posts
    10
    This code works on my OS:
    Code:
    while read -r s f
    do 
    	echo "$f"
    	ts+=$s
    	echo "$s"
    done < <(stat -f '%z %N' ~/Desktop/1/*)
    Output:
    /usr/home/flit/Desktop/1/1.sh
    243
    /usr/home/flit/Desktop/1/11
    271
    /usr/home/flit/Desktop/1/2.sh
    3385
    /usr/home/flit/Desktop/1/3.sh
    271
    /usr/home/flit/Desktop/1/4.sh
    271
    /usr/home/flit/Desktop/1/44.sh
    718
    /usr/home/flit/Desktop/1/444
    441
    /usr/home/flit/Desktop/1/a.sh
    194
    /usr/home/flit/Desktop/1/b.sh
    73
    /usr/home/flit/Desktop/1/index.html
    15243
    /usr/home/flit/Desktop/1/index.html.1
    15243
    /usr/home/flit/Desktop/1/script_menu.sh
    3469
    /usr/home/flit/Desktop/1/statout.sh
    2795
    /usr/home/flit/Desktop/1/test.sh
    242
    /usr/home/flit/Desktop/1/variable is empty.sh
    131
    Last edited by flit; 12-08-2013 at 06:32 PM.

  3. #13
    Just Joined!
    Join Date
    Dec 2013
    Posts
    10
    List of stat "switches" and output on BSD:
    stat -f "%N" 1.sh Output: 1.sh
    stat -f "%Mp" 1.sh Output: 0
    stat -f "%Lp" 1.sh Output: 700
    stat -f "%Sp" 1.sh Output: -rwx------
    stat -f "%Mp%Lp/%Sp" 1.sh Output: 0700/-rwx------
    stat -f "%5u" 1.sh Output: 1001
    stat -f "%8Su" 1.sh Output: flit
    stat -f "%-15z" 1.sh Output: 243
    stat -f "%5g" 1.sh Output: 1001
    stat -f "%8Sg" 1.sh Output: flit
    stat -f "%Sa%n" 1.sh Output: Dec 6 09:19:18 2013 Access
    stat -f "%Sm%n" 1.sh Output: Nov 17 23:48:08 2013 Modify
    stat -f "%Sc%n" 1.sh Output: Dec 8 05:50:56 2013 Change
    stat -f "%SB" 1.sh Output: Nov 17 23:48:08 2013 Birth
    stat -f "%z" 1.sh Output: 243

  4. #14
    Just Joined!
    Join Date
    Dec 2013
    Posts
    10
    Code:
    while read -r s f
    do 
      echo "$f"
      ts+=($s)
    done < <(stat -f '%N %z' ~/Desktop/1/*)
    I tried this code and I got the following output:

    243
    271
    3385
    271
    271
    718
    441
    194
    649
    149
    124
    73
    15243
    15243
    3469
    475
    271
    2795
    2795
    242
    is empty.sh 131
    Correction: It works I should have changed %N %z to %z %N to match s f
    Last edited by flit; 12-08-2013 at 07:23 PM.

  5. #15
    Just Joined!
    Join Date
    Dec 2013
    Posts
    10
    Code:
    while read -r s f; do echo "$f"; ts+=$s; done < <(stat -c '%s %n' ~/Desktop/1/*-*)
    Can anyone tell me why I can't use
    Code:
    <(stat -c '%s %n' ~/Desktop/1/*-*)
    Instead of
    Code:
    < <(stat -c '%s %n' ~/Desktop/1/*-*)
    What is the meaning of the extra <?
    Last edited by flit; 12-08-2013 at 09:29 PM.

  6. #16
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    211
    process substitution (`<(...)`) sends its output to a file descriptor, which is a file.
    like any other file, fd's content needs to be redirected to the command that reads it.

  7. #17
    Just Joined!
    Join Date
    Dec 2013
    Posts
    10
    Thank you very much.

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •