User Tools

Site Tools


ubuntu:bash_-_scripts:kind

Ubuntu - Bash - Scripts - kind

Displays the names of all files in the specified directory with the specified type.

If you do not specify any type it defaults to text files.


Usage

kind [-a] [-d] [-t] [-x] [file...]

Code

#!/bin/bash
#
# @(#) kind v1.0   Prints files of the same kind
#
 
if [ $# -gt 0 ]
then if [ `echo $1 | cut -c1` = "-" ]
  then case #1 in
    -a)   KIND='archive'
          shift;;
    -d)   KIND='data'
          shift;;
    -t)   KIND='text'
          shift;;
    -x)   KIND='executable'
          shift;;
     *)   echo "kind: arg error"                           >&2
          echo "usage: kind [-a] [-d] [-t] [-x] [file...]" >&2
          echo "       -a  archive"                        >&2
          echo "       -d  data"                           >&2
          echo "       -t  text, default"                  >&2
          echo "       -x  executable"                     >&2
          echo "       if no args, reads stdin"            >&2
          exit 1;;
    esac
    fi
  fi
 
: ${KIND:='text'}
 
case $# in
  0)   while read FILE
       do
           file $FILE | fgrep $KIND | cut -d: -f1
       done;;
  *)   file $@ | fgrep $KIND | cut -d: -f1;;
esac

FILE contains the file names as they are read from stdin (Standard input).

KIND contains the text string that defines the type of file.


Examples

Display all text files in the directory /etc.

more `kind /etc/*`

That is actually hatched a list of all data files.


And if I have done the following sequence of commands cd /etc and kind -d *.

kind -d /etc/*

Possible result:

/etc/mnttab
/etc/utmp
/etc/wtmp

od `kind -d /etc/*`

ll `sh -x kind -a /lib/*` | m

find / -print | kind -x | while read FILE
     > do
     >        ll $FILE
     > done > /tmp/filelist
ubuntu/bash_-_scripts/kind.txt · Last modified: 2020/07/15 10:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki