Write a function that lists the number of ordinary files, directories, block special files, character special files, FIFOs, and symbolic links in the working directory. Do this in two different ways:
a. Use the first letter of the output of ls –l to determine a file’s type.
b. Use the file type condition tests of the [[ expression ]] syntax to determine
a file’s type.
a.
$ function ft () {
> declare -i ord=0 dir=0 blk=0 char=0 fifo=0 symlnk=0 other=0
>
> for fn in *
> do
> case $(ls -ld "$fn" | cut -b1) in
> d)
> ((dir=$dir+1))
> ;;
> b)
> ((blk=$blk+1))
> ;;
> c)
> ((char=$char+1))
> ;;
> p)
> ((fifo=$fifo+1))
> ;;
> l)
> ((symlnk=$symlnk+1))
> ;;
> a-z)
> ((other=other+1))
> ;;
> *)
> ((ord=ord+1))
> ;;
> esac
> done
>
> echo $ord ordinary
> echo $dir directory
> echo $blk block
> echo $char character
> echo $fifo FIFO
> echo $symlnk symbolic link
> echo $other other
> }
b.
$ function ft2 () {
> declare -i ord=0 dir=0 blk=0 char=0 fifo=0 symlnk=0 other=0
>
> for fn in *
> do
> if [[ -h $fn ]]
> then ((symlnk=$symlnk+1))
> elif [[ -f $fn ]]
> then ((ord=ord+1))
> elif [[ -d $fn ]]
> then ((dir=$dir+1))
> elif [[ -b $fn ]]
> then ((blk=$blk+1))
> elif [[ -c $fn ]]
> then ((char=$char+1))
> elif [[ -p $fn ]]
> then ((fifo=$fifo+1))
> else
> ((other=other+1))
> fi
> done
>
> echo $ord ordinary
> echo $dir directory
> echo $blk block
> echo $char character
> echo $fifo FIFO
> echo $symlnk symbolic link
> echo $other other
> }
You might also like to view...
To customize the elements of your chart you can use the ___________________ contextual tab(s).
A. CHART LAYOUT B. CHART TOOLS DESIGN and FORMAT C. CUSTOMIZE CHART D. CHART DESIGN and CREATION
Organizations that use design strategically are more likely to see market growth and increased demands for products and services
Indicate whether the statement is true or false
The more specific your search criteria in the Search box, the better the list of matches you will receive from the search engine.
Answer the following statement true (T) or false (F)
JavaScript is a language often used within HTML documents to trigger interactive features.
Answer the following statement true (T) or false (F)