How to check the extension of a filename in a bash script?

后端 未结 9 923
不思量自难忘°
不思量自难忘° 2020-12-04 05:33

I am writing a nightly build script in bash.
Everything is fine and dandy except for one little snag:


#!/bin/bash

for file in \"$PATH_TO_SOMEWHERE\"; d         


        
9条回答
  •  时光说笑
    2020-12-04 05:51

    I wrote a bash script that looks at the type of a file then copies it to a location, I use it to look through the videos I've watched online from my firefox cache:

    #!/bin/bash
    # flvcache script
    
    CACHE=~/.mozilla/firefox/xxxxxxxx.default/Cache
    OUTPUTDIR=~/Videos/flvs
    MINFILESIZE=2M
    
    for f in `find $CACHE -size +$MINFILESIZE`
    do
        a=$(file $f | cut -f2 -d ' ')
        o=$(basename $f)
        if [ "$a" = "Macromedia" ]
            then
                cp "$f" "$OUTPUTDIR/$o"
        fi
    done
    
    nautilus  "$OUTPUTDIR"&
    

    It uses similar ideas to those presented here, hope this is helpful to someone.

提交回复
热议问题