查找所有视频文件扩展名和文件大小的 Linux 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8015888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 07:02:24  来源:igfitidea点击:

Linux script to find all video file extensions and file sizes

linuxbashscriptingfind

提问by Lawrence

I was trying to write a couple of scripts that would do a couple of things:

我试图编写几个脚本来做几件事:

  1. Recursively list all file type in a given directory and gives me the total number of files for that file type and the total file sizes for each (i.e .doc = 300 and 450 MB, .xlsx = 543 and 516 MB, .mov = 67 and 5.4 GB, etc.)

  2. A script that would recursively find all video files on my server (.mov, .mp4, .avi, etc.) in a given directory and displays their location/path and file size sorted by file size in descending order (largest to smallest)

  1. 递归列出给定目录中的所有文件类型,并为我提供该文件类型的文件总数和每个文件的总文件大小(即 .doc = 300 和 450 MB,.xlsx = 543 和 516 MB,.mov = 67和 5.4 GB 等)

  2. 一个脚本,它将在给定目录中递归地查找我的服务器上的所有视频文件(.mov、.mp4、.avi 等),并按文件大小降序(从大到小)显示它们的位置/路径和文件大小

How would I write this?

我会怎么写这个?

回答by Adam Zalcman

Try these:

试试这些:

1.

1.

for ext in $( find . -type f | sed -e 's#.*\(\.[a-zA-Z]*\)$##' | sort | uniq ); do
    echo -n "${ext} "
    find . -type f -name "*${ext}" -ls | awk 'BEGIN { size=0; count=0 } { size+=; count++ } END { unit="B"; if (size > 1024*1024*1024) { size=size/(1024*1024*1024); unit="GB"; } else if (size > 1024*1024) { size=size/(1024*1024); unit="MB"; } else if (size > 1024) { size=size/1024; unit="kB"; } print "count: ", count, " size: ", size, unit }'
done

2.

2.

find . -type f -name '*.java' -ls | sort -k +7 -r

回答by chown

1) This script takes a directory and extension (w/o the ".") as parameters and gives the total file size for all files in that directory and all sub-directories:

1) 此脚本将目录和扩展名(不带“.”)作为参数,并给出该目录和所有子目录中所有文件的总文件大小:

#!/bin/bash
DIR=
TYPE=
TOTAL=0    
FILES=`find $DIR -type f -iname "*.$TYPE"`
for f in $FILES; do
    if [ -f $f ]; then
        SIZE=`stat -c "%s" "$f"`
        TOTAL=$(($SIZE + $TOTAL))
    fi
done    
TOTALK=$(echo "scale=2; $TOTAL / 1024" | bc -l)
TOTALM=$(echo "scale=2; $TOTALK / 1024" | bc -l)
echo "Total file size for all \"$TYPE\" files: ${TOTAL}b / ${TOTALK}Kb / ${TOTALM}Mb"

Output:

输出:

[ 18:03 jon@hozbox ~/SO/bash ]$ ./linux-script-to-find-all-video-file-extensions-and-file-sizes.sh /home/jon/SO/python py
Total file size for all "py" files: 20062b / 19.59Kb / .01Mb


2) This one was fun to figure out. It has room for optimization, but it gets the job done. The only parameter needed is a directory:

2)这个很有趣。它有优化的空间,但它完成了工作。唯一需要的参数是一个目录:

#!/bin/bash

# fill with more extensions or have it as a cmd line arg
TYPES=( mov mp4 avi )

DIR=

# Create a regex of the extensions for the find command
TYPES_RE="\("${TYPES[1]}
for t in "${TYPES[@]:1:${#TYPES[*]}}"; do
    TYPES_RE="${TYPES_RE}\|${t}"
done
TYPES_RE="${TYPES_RE}\)"

# Set the field seperator to newline instead of space
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

# Generate output from path and size using: `stat -c "%s" filepath`
OUTPUT=""
for f in `find ${DIR} -type f -regex ".*\.${TYPES_RE}"`; do
SIZE=`stat -c "%s" ${f}`
    SIZEK=`echo "scale=2; ${SIZE} / 1024" | bc -l`
    SIZEM=`echo "scale=2; ${SIZEK} / 1024" | bc -l`
    OUTPUT=`echo ${SIZE}b / ${SIZEK}Kb / ${SIZEM}Mb - ${f}`";"$OUTPUT
done

# Reset IFS
IFS=$SAVEIFS

# Reverse numeric sort the output and replace ; with \n for printing
echo $OUTPUT | tr ';' '\n' | sort -nr

Script in action:

运行中的脚本:

[ 18:10 jon@hozbox ~/SO/bash ]$ ./linux-script-to-find-all-video-file-extensions-and-file-sizes2.sh /Media/
1732419584b / 1691816.00Kb / 1652.16Mb - /Media/Movies/The Lord of the Rings - Extended Trilogy/The Return of the King.avi
1711714450b / 1671596.14Kb / 1632.41Mb - /Media/Movies/Saving Private Ryan/Saving_Private_Ryan-(1998)-QUALiTY.mov
1581664256b / 1544594.00Kb / 1508.39Mb - /Media/Movies/Buffalo Soldiers/Buffalo Soldiers.mp4
1574578176b / 1537674.00Kb / 1501.63Mb - /Media/Movies/The Next Three Days/The Next Three Days_3.avi
1534617600b / 1498650.00Kb / 1463.52Mb - /Media/Movies/The Lord of the Rings - Extended Trilogy/The Two Towers.mov
1467039744b / 1432656.00Kb / 1399.07Mb - /Media/Movies/Gladiator/Gladiator[2000][Extended.Edition]DvDrip.AC3[Eng]-aXXo.mp4
1461037056b / 1426794.00Kb / 1393.35Mb - /Media/Movies/Fear and Loathing in Las Vegas/Fear And Loathing In Las Vegas(Xvid)(Darkside_RG).avi
1428451328b / 1394972.00Kb / 1362.27Mb - /Media/Movies/The Lord of the Rings - Extended Trilogy/The Fellowship of the Ring.avi
1344398068b / 1312888.73Kb / 1282.11Mb - /Media/Movies/Xmen Trilogy/X2 - X-Men United.avi
1323552189b / 1292531.43Kb / 1262.23Mb - /Media/Movies/pi/pi.avi
1309632512b / 1278938.00Kb / 1248.96Mb - /Media/Movies/Godfather/Godfather.avi
1203953744b / 1175736.07Kb / 1148.17Mb - /Media/Movies/The Next Three Days/The Next Three Days_2.avi
1125270752b / 1098897.21Kb / 1073.14Mb - /Media/Movies/Dog Day Afternoon/Dog Day Afternoon.avi
1088729202b / 1063212.11Kb / 1038.29Mb - /Media/Movies/Hackers/Hackers.avi
1047903102b / 1023342.87Kb / 999.35Mb - /Media/Movies/Xmen Trilogy/X-men.avi
970967384b / 948210.33Kb / 925.98Mb - /Media/Movies/Red/Red.avi
945065984b / 922916.00Kb / 901.28Mb - /Media/Movies/Babel/Babel.avi
942888960b / 920790.00Kb / 899.20Mb - /Media/Movies/Munich/Munich.avi
886425600b / 865650.00Kb / 845.36Mb - /Media/Movies/Die Hard 1-2-3/Die Hard 3 Die Hard With A Vengeance 1995 Widescreen/(Die Hard 3 Die Hard With A Vengeance - Widescreen).avi
868198400b / 847850.00Kb / 827.97Mb - /Media/Movies/Blank Check/Blank Check.avi
845575252b / 825757.08Kb / 806.40Mb - /Media/Movies/Reservtheitroad Dogs/Reservtheitroad Dogs [Eng][DVDrip].avi
841349120b / 821630.00Kb / 802.37Mb - /Media/Movies/Casino Royale/Casino.Royale[2006]DvDrip[Eng]-aXXo.avi
840572928b / 820872.00Kb / 801.63Mb - /Media/Movies/The Departed/The Departed.avi
839313408b / 819642.00Kb / 800.43Mb - /Media/Movies/The Next Three Days/The Next Three Days_1.avi
838971392b / 819308.00Kb / 800.10Mb - /Media/Movies/Letters from Iwo Jima/Letters.From.Iwo.Jima[2006]DvDrip[Eng.Hard.Sub]-aXXo.avi
776615936b / 758414.00Kb / 740.63Mb - /Media/Movies/Blank Check/Blank Check [1994].avi
766049096b / 748094.82Kb / 730.56Mb - /Media/Movies/Get Smart/Get Smart.avi
741783552b / 724398.00Kb / 707.41Mb - /Media/Movies/The Terminator (All 3)/Terminator 3 - Rise Of The Machines.avi
738355200b / 721050.00Kb / 704.15Mb - /Media/Movies/Rushmore/Rushmore [XviD][DVDRip][1998].avi
736495616b / 719234.00Kb / 702.37Mb - /Media/Movies/Training Day/Training Day.avi
736169984b / 718916.00Kb / 702.06Mb - /Media/Movies/Half Baked/halfb-apl.avi
736055296b / 718804.00Kb / 701.95Mb - /Media/Movies/Pineapple Express/Pineapple Express.avi
735993856b / 718744.00Kb / 701.89Mb - /Media/Movies/Serenity/Serenity.avi
735809536b / 718564.00Kb / 701.72Mb - /Media/Movies/Flags of our Fathers/Flags.Of.Our.Fathers[2006]DvDrip[Eng]-aXXo.avi
735797248b / 718552.00Kb / 701.71Mb - /Media/Movies/Blood Diamond/Blood Diamond.DVDSCR/CD2/Blood Diamond.DVDSCR.avi
735660032b / 718418.00Kb / 701.58Mb - /Media/Movies/Xmen Trilogy/X-Men.The.Last.Stand[2006]DvDrip[Eng]-aXXo/X-Men.The.Last.Stand[2006]DvDrip[Eng]-aXXo.avi
735447040b / 718210.00Kb / 701.37Mb - /Media/Movies/A Scanner Darkly/A Scanner Darkly.avi
735350784b / 718116.00Kb / 701.28Mb - /Media/Movies/The Boondock Saints/The Boondock Saints [1999] Eng [DVDRiP] -=Flint=-.avi
735283200b / 718050.00Kb / 701.22Mb - /Media/Movies/Apocalypse Now/Apocalypse Now (1979) XviD.DVDRip.PiLFER.avi
735111168b / 717882.00Kb / 701.05Mb - /Media/Movies/Black Hawk Down/Black Hawk Down (2001) [ENG] [DVDrip] CD2.avi
735107072b / 717878.00Kb / 701.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Motorcycles.avi
735107072b / 717878.00Kb / 701.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Contruction Machines.avi
735102976b / 717874.00Kb / 701.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Cars.avi
735049728b / 717822.00Kb / 700.99Mb - /Media/Movies/Equilibrium/Equilibrium[2002]DvDrip[Eng]-Killa.avi
734885888b / 717662.00Kb / 700.84Mb - /Media/Music/Nine Ninch Nails/Halo 22 - Beside you in Time/aaf-ninbyit-cd2.avi
734777344b / 717556.00Kb / 700.73Mb - /Media/Movies/The Prestige/The.Prestige[2006]DvDrip[Eng]-aXXo.avi
734752768b / 717532.00Kb / 700.71Mb - /Media/TV/Rome/Rome - s01e11.avi
734742528b / 717522.00Kb / 700.70Mb - /Media/Movies/Star Wars - All six episodes/Star Wars II - Attack of the Clones.avi
734726144b / 717506.00Kb / 700.68Mb - /Media/Movies/Spy Game/Spy Game.avi
734689280b / 717470.00Kb / 700.65Mb - /Media/Movies/The Matrix Trilogy/The Matrix.avi
734642176b / 717424.00Kb / 700.60Mb - /Media/Movies/Syriana/Syriana.avi
734631936b / 717414.00Kb / 700.59Mb - /Media/Movies/The Matrix Trilogy/The Matrix - Reloaded.avi
734625792b / 717408.00Kb / 700.59Mb - /Media/Movies/The Matrix Trilogy/The Matrix - Revolutions.avi
734570496b / 717354.00Kb / 700.54Mb - /Media/Movies/Star Wars - All six episodes/Star Wars I - The Phantom Menace.avi
734552064b / 717336.00Kb / 700.52Mb - /Media/Movies/Donnie Darko/Donnie Darko[2001]DvDrip[Eng]-Bugz.avi
734550016b / 717334.00Kb / 700.52Mb - /Media/Movies/Star Wars - All six episodes/Star Wars VI - Return of the Jedi.avi
734535680b / 717320.00Kb / 700.50Mb - /Media/TV/Modern Marvels/Modern Marvels - Apollo 13.avi
734500864b / 717286.00Kb / 700.47Mb - /Media/Movies/The Thin Red Line/the thin red line.cd1.avi
734476288b / 717262.00Kb / 700.45Mb - /Media/Movies/Man of the Year/Man of the Year.avi
734472192b / 717258.00Kb / 700.44Mb - /Media/Movies/Waiting/Waiting.avi
734431232b / 717218.00Kb / 700.40Mb - /Media/Movies/American History X/American History X 1998 XviD DVDRip.avi
734359552b / 717148.00Kb / 700.33Mb - /Media/Movies/The Black Dahlia/The.Black.Dahlia[2006]DvDrip[Eng]-aXXo.avi
734327256b / 717116.46Kb / 700.30Mb - /Media/TV/Generation Kill/Generation Kill - 101 - Get Some.avi
734326784b / 717116.00Kb / 700.30Mb - /Media/Movies/indiana Jones/Indiana Jones And The Last Crusade 1989 Widescreen DVDRip/Indiana Jones And The Last Crusade (WS DVDRip).avi
734314496b / 717104.00Kb / 700.29Mb - /Media/Movies/Clerks 1 & 2/Clerks 2.avi
734291968b / 717082.00Kb / 700.27Mb - /Media/Movies/Taxi Driver/Taxi.Driver.XviD.jiLAiaa.avi
734279680b / 717070.00Kb / 700.26Mb - /Media/Movies/Lock Stock and Two Smokin Barrels/Lock Stock and Two Smoking Barrels.avi
734259200b / 717050.00Kb / 700.24Mb - /Media/Movies/Austin Powers - Trilogy/Austin.Powers.1997.iNTERNAL.DVDRip.XViD-vRs/Austing Powers International Man of Mistery iNTERNAL.avi
734251008b / 717042.00Kb / 700.23Mb - /Media/Movies/Burn After Reading/Burn After Reading.avi
734238720b / 717030.00Kb / 700.22Mb - /Media/Movies/Lord Of War/CD1/low-fico.cd1.avi
734232576b / 717024.00Kb / 700.21Mb - /Media/Movies/Super Troopers/SuperTroopers.DVDRip.XVID.avi
734220288b / 717012.00Kb / 700.20Mb - /Media/Movies/Old School/Old School.avi
734187520b / 716980.00Kb / 700.17Mb - /Media/Movies/Blade Runner/Blade.Runner[Remastered.Director's.Cut]DvDrip[Eng]-aXXo.avi
734181714b / 716974.33Kb / 700.17Mb - /Media/TV/Generation Kill/Generation Kill - 102 -.avi
734148608b / 716942.00Kb / 700.13Mb - /Media/Movies/Tenacious D - The Pick of Destiny/Tenacious.D-The.Pick.Of.Destiny[2006]DvDrip[Eng]-aXXo.avi
734148608b / 716942.00Kb / 700.13Mb - /Media/Movies/indiana Jones/Indiana Jones And The Raiders Of The Lost Ark 1981 Widescreen DVDRip/Indiana Jones And The Raiders Of The Lost Ark (WS DVDRip).avi
734144512b / 716938.00Kb / 700.13Mb - /Media/Movies/Grandmas Boy/Grandmas Boy Unrated [Unrated Diamond].avi
734138408b / 716932.03Kb / 700.12Mb - /Media/TV/Generation Kill/Generation Kill - 104 - Combat Hyman.avi
734121984b / 716916.00Kb / 700.11Mb - /Media/Movies/Shaun Of The Dead/Shaun Of The Dead.avi
734111510b / 716905.77Kb / 700.10Mb - /Media/Movies/Star Wars - All six episodes/Star Wars V - The Empire Strikes Back.avi
734099456b / 716894.00Kb / 700.09Mb - /Media/Movies/Lord Of War/CD2/low-fico.cd2.avi
734076928b / 716872.00Kb / 700.07Mb - /Media/Movies/Ace Ventura - Pet Detective (I & II)/Ace Ventura II - When Nature Calls (1995).avi
734064224b / 716859.59Kb / 700.05Mb - /Media/TV/Generation Kill/Generation Kill - 106 - Stay Frosty.avi
734061752b / 716857.17Kb / 700.05Mb - /Media/TV/Generation Kill/Generation Kill - 105 - A Burning Dog.avi
734060544b / 716856.00Kb / 700.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Walt Disney World.avi
734056448b / 716852.00Kb / 700.05Mb - /Media/Movies/Friday/Friday.avi
734056262b / 716851.81Kb / 700.05Mb - /Media/TV/Generation Kill/Generation Kill - E7.avi
734044160b / 716840.00Kb / 700.03Mb - /Media/Movies/Austin Powers - Trilogy/Austin.Powers.The.Spy.Who.Shagged.Me.1999.iNTERNAL.DVDRip.XviD-XviK/Austin Powers The Spy Who Shagged Me.avi
734027336b / 716823.57Kb / 700.02Mb - /Media/TV/Generation Kill/Generation Kill - 103 - Screwby.avi
733989632b / 716786.75Kb / 699.98Mb - /Media/TV/Heroes/Season 2/heroes.s02e01.hdtv.xvid-xor.avi
733976576b / 716774.00Kb / 699.97Mb - /Media/Movies/The Godfather - Part 2/disc2/THE GODFATHER - PART 2 - DISK 2.avi
733976576b / 716774.00Kb / 699.97Mb - /Media/Movies/Red Dawn/Red Dawn.avi
733937664b / 716736.00Kb / 699.93Mb - /Media/Movies/indiana Jones/Indiana Jones And The Temple Of Doom 1984 Widescreen DVDRip/Indiana Jones And The Temple Of Doom (WS DVDRip).avi
733919232b / 716718.00Kb / 699.91Mb - /Media/Movies/Star Wars - All six episodes/Star Wars IV - A New Hope.avi
733900800b / 716700.00Kb / 699.90Mb - /Media/Movies/The Terminator (All 3)/The Terminator.avi
733896704b / 716696.00Kb / 699.89Mb - /Media/Movies/Breach/Breach.2007.DvDRip.ENG-FxM.avi
733872128b / 716672.00Kb / 699.87Mb - /Media/Movies/Heat/Heat.CD1.WS.AC3.DVDRip.Xvid.BeefStew.avi
733872128b / 716672.00Kb / 699.87Mb - /Media/Movies/Apocalypto/CD1/Apocalypto.DVDSCR.XviD.CD1-iMBT.[www.torrentfive.com].avi
733818880b / 716620.00Kb / 699.82Mb - /Media/Movies/Beowulf & Grendel/Beowulf.&.Grendel[2005]DvDrip[Eng]-aXXo.avi
733763344b / 716565.76Kb / 699.77Mb - /Media/TV/Lost/season_4/Lost.S04E13-E14.HDTV.avi
733678316b / 716482.73Kb / 699.69Mb - /Media/TV/Lost/season_5/lost.s05e16-e17.hdtv.xvid-fqm.avi
733675520b / 716480.00Kb / 699.68Mb - /Media/Movies/Borat/Borat[2006]DvDrip.AC3[Eng]-aXXo.avi
733663232b / 716468.00Kb / 699.67Mb - /Media/Movies/Idiocracy/Idiocracy[2006]DvDrip.AC3[Eng]-aXXo.avi
733562880b / 716370.00Kb / 699.58Mb - /Media/Movies/3.10 to Yuma/dmd-310yuma-cd1.avi
733542400b / 716350.00Kb / 699.56Mb - /Media/Movies/Sin City/dmd-sincity-cd1.avi
733536256b / 716344.00Kb / 699.55Mb - /Media/Movies/The Thin Red Line/the thin red line.cd2.avi
733528064b / 716336.00Kb / 699.54Mb - /Media/TV/Lost/season_1/Lost - s01e24.avi
733528064b / 716336.00Kb / 699.54Mb - /Media/Movies/The Godfather - Part 2/disc1/THE GODFATHER - PART2 - DISC 1.avi
733503488b / 716312.00Kb / 699.52Mb - /Media/Movies/Black Hawk Down/Black Hawk Down (2001) [ENG] [DVDrip] CD1.avi
733499392b / 716308.00Kb / 699.51Mb - /Media/Movies/Reno 911 - Miami/Reno.911!-Miami[2007][Unrated.Edition]DvDrip.AC3[Eng]-aXXo.avi
733470720b / 716280.00Kb / 699.49Mb - /Media/Movies/Little Miss Sunshine/little miss sunshine.avi
733122560b / 715940.00Kb / 699.16Mb - /Media/Music/Nine Ninch Nails/Halo 22 - Beside you in Time/aaf-ninbyit-cd1.avi
733077504b / 715896.00Kb / 699.11Mb - /Media/Movies/Stranger Than Fiction/ogt-stf-xvid-cd2.avi
732968960b / 715790.00Kb / 699.01Mb - /Media/Movies/Stranger Than Fiction/ogt-stf-xvid-cd1.avi
732803072b / 715628.00Kb / 698.85Mb - /Media/Movies/Sin City/dmd-sincity-cd2.avi
732696092b / 715523.52Kb / 698.75Mb - /Media/Movies/Hancock/Hancock.avi
732657664b / 715486.00Kb / 698.71Mb - /Media/Movies/Heat/Heat.CD2.WS.AC3.DVDRip.Xvid.BeefStew.avi
732166144b / 715006.00Kb / 698.24Mb - /Media/TV/Lost/season_3/Lost - s03e09.avi
732164096b / 715004.00Kb / 698.24Mb - /Media/TV/Rome/Rome - s01e07.avi
732092416b / 714934.00Kb / 698.17Mb - /Media/TV/Heroes/Season 1/Heroes - 1x00 - Unaired pilot - DVDrip - tpz.avi
731932672b / 714778.00Kb / 698.02Mb - /Media/Movies/Righteous Kill/Righteous Kill [2008] DvDrip FRA.avi
731918336b / 714764.00Kb / 698.01Mb - /Media/Movies/Dumb and Dumber/dumb.and.dumber.1994.unrated.dvdrip.xvid.fragment.avi
731678720b / 714530.00Kb / 697.78Mb - /Media/TV/Rome/Rome - s01e08.avi
731432960b / 714290.00Kb / 697.54Mb - /Media/Movies/Spun/Spun 2002 DVDRip DivX.avi
731164578b / 714027.90Kb / 697.29Mb - /Media/Movies/Megamind/Megamind.avi
731117568b / 713982.00Kb / 697.24Mb - /Media/Movies/Trainspotting/Trainspotting.1996.DVDRip.XviD-NewMov.avi
730976256b / 713844.00Kb / 697.11Mb - /Media/Movies/Snatch/Snatch.2000.INTERNAL.DVDrip.XViD-DCA.[www.torrentfive.com].avi
730220544b / 713106.00Kb / 696.39Mb - /Media/Movies/Alien Trilogy/Alien.1979/Alien.1979.Theatrical.Release.WS.NTSC.DVDRip.DivX3[lowMotion].AC3.5.1ch[eng]-ViRUSMoNK.avi
729845760b / 712740.00Kb / 696.03Mb - /Media/Movies/Harsh Times/xv-harshtime.avi
729208832b / 712118.00Kb / 695.42Mb - /Media/Movies/3.10 to Yuma/dmd-310yuma-cd2.avi
729157632b / 712068.00Kb / 695.37Mb - /Media/Movies/Apocalypto/CD2/Apocalypto.DVDSCR.XviD.CD2-iMBT.[www.torrentfive.com].avi
729047040b / 711960.00Kb / 695.27Mb - /Media/Movies/Black Sheep/Black Sheep [Eng][XviD][1996].avi
728840192b / 711758.00Kb / 695.07Mb - /Media/Movies/Alien Trilogy/[3]Alien.III.1992.DVDRip.XviD.iNT-7aS/7aS.ali3.int.avi
727152640b / 710110.00Kb / 693.46Mb - /Media/Movies/Alien Trilogy/[2]Aliens.1986.DVDRip.XviD.iNT-7aS/7aS-Aliens.iNT.avi
726935552b / 709898.00Kb / 693.25Mb - /Media/Movies/Mallrats/Mallrats.avi
725692416b / 708684.00Kb / 692.07Mb - /Media/Movies/Blood Diamond/Blood Diamond.DVDSCR/CD1/Blood Diamond.DVDSCR.avi
724285440b / 707310.00Kb / 690.73Mb - /Media/Movies/Die Hard 1-2-3/Die Hard 2 Die Harder 1990 Widescreen/(Die Hard 2 Die Harder - Widescreen).avi
723839024b / 706874.04Kb / 690.30Mb - /Media/Movies/Castaway/CASTAWAY.avi
722556928b / 705622.00Kb / 689.08Mb - /Media/Movies/Dark City/Dark City.avi
719507456b / 702644.00Kb / 686.17Mb - /Media/Movies/Ace Ventura - Pet Detective (I & II)/Ace Ventura I - Pet Detective (1994).avi
716509184b / 699716.00Kb / 683.31Mb - /Media/Movies/Star Wars - All six episodes/Star Wars III - Revenge of the Sith.avi
711309312b / 694638.00Kb / 678.35Mb - /Media/Movies/The Terminator (All 3)/Terminator 2 Judgment Day.avi
701927424b / 685476.00Kb / 669.41Mb - /Media/Movies/American Psycho/American Psycho.avi
700067840b / 683660.00Kb / 667.63Mb - /Media/TV/Modern Marvels/Modern Marvels - Private Collections.avi
695296000b / 679000.00Kb / 663.08Mb - /Media/Movies/Clerks 1 & 2/Clerks.avi
691305472b / 675103.00Kb / 659.28Mb - /Media/Movies/Pulp Fiction/Pulp Fiction.avi
689162752b / 673010.50Kb / 657.23Mb - /Media/Movies/Tommy Boy/Tommy Boy.avi
654974976b / 639624.00Kb / 624.63Mb - /Media/Movies/Die Hard 1-2-3/Die Hard 1988 Widescreen/(Die Hard - Widescreen).avi
578396160b / 564840.00Kb / 551.60Mb - /Media/TV/Dexter/Season_4/Dexter.S04E04.avi
578377728b / 564822.00Kb / 551.58Mb - /Media/TV/Dexter/Season_4/Dexter.S04E12.avi
578310144b / 564756.00Kb / 551.51Mb - /Media/TV/Dexter/Season_4/Dexter.S04E09.avi
577336482b / 563805.15Kb / 550.59Mb - /Media/TV/Dexter/Season_4/Dexter.S04E10.avi
577295822b / 563765.45Kb / 550.55Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E03.HDTV.XviD-NoTV.avi
577075200b / 563550.00Kb / 550.34Mb - /Media/TV/Dexter/Season_4/Dexter.S04E08.avi
576837632b / 563318.00Kb / 550.11Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E07.HDTV.XviD-LOL.avi
576810986b / 563291.97Kb / 550.08Mb - /Media/TV/Dexter/Season_4/Dexter.S04E07.avi
576781850b / 563263.52Kb / 550.06Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E10.HDTV.XviD-0TV.avi
576743456b / 563226.03Kb / 550.02Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E09.HDTV.XviD-0TV.avi
576737360b / 563220.07Kb / 550.01Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E05.HDTV.XviD-0TV.avi
576730440b / 563213.32Kb / 550.01Mb - /Media/TV/Dexter/Season_4/Dexter.S04E02.avi
576711398b / 563194.72Kb / 549.99Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E02.HDTV.XviD-0TV.avi
576707972b / 563191.37Kb / 549.99Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E04.HDTV.XviD-0TV.[VTV].avi
576689352b / 563173.19Kb / 549.97Mb - /Media/TV/Dexter/Season_4/Dexter.S04E05.avi
576649216b / 563134.00Kb / 549.93Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E08.HDTV.XviD-LOL.avi
576608256b / 563094.00Kb / 549.89Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E06.HDTV.XviD-LOL.avi
576591872b / 563078.00Kb / 549.88Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E12.HDTV.XviD-aAF.avi
576561152b / 563048.00Kb / 549.85Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E11.HDTV.XviD-aAF.avi
575608832b / 562118.00Kb / 548.94Mb - /Media/TV/Dexter/Season_4/Dexter.S04E06.avi
574103552b / 560648.00Kb / 547.50Mb - /Media/TV/Dexter/Season_4/Dexter.S04E03.avi
573956096b / 560504.00Kb / 547.36Mb - /Media/TV/Dexter/Season_4/Dexter.S04E11.avi
561372274b / 548215.11Kb / 535.36Mb - /Media/TV/Dexter/Season_3_HD/Dexter.S03E01.DVDScr.XviD-NOTYOU.avi
442640808b / 432266.41Kb / 422.13Mb - /Media/TV/Modern Marvels/Modern Marvels - Egyptian Pyramids.avi
441226782b / 430885.52Kb / 420.78Mb - /Media/TV/Modern Marvels/Modern Marvels - Extreme Aircraft.avi
439986036b / 429673.86Kb / 419.60Mb - /Media/TV/Modern Marvels/Modern Marvels - Inviting Disaster, Kursk.avi
439608886b / 429305.55Kb / 419.24Mb - /Media/TV/Modern Marvels/Modern Marvels - Metal.avi
439260602b / 428965.43Kb / 418.91Mb - /Media/TV/Modern Marvels/Modern Marvels - Dredging.avi
439035240b / 428745.35Kb / 418.69Mb - /Media/TV/Modern Marvels/Modern Marvels - The Great Wall of China.avi
438817000b / 428532.22Kb / 418.48Mb - /Media/TV/Modern Marvels/Modern Marvels - Mountain Roads.avi
435969540b / 425751.50Kb / 415.77Mb - /Media/TV/Modern Marvels/Modern Marvels - Strategic Air Command.avi
435524214b / 425316.61Kb / 415.34Mb - /Media/TV/Modern Marvels/Modern Marvels - Inventions of War.avi
435496294b / 425289.34Kb / 415.32Mb - /Media/TV/Modern Marvels/Modern Marvels - D-Day Tech.avi
435388062b / 425183.65Kb / 415.21Mb - /Media/TV/Modern Marvels/Modern Marvels - Aswan Dam.avi
433062420b / 422912.51Kb / 413.00Mb - /Media/TV/Modern Marvels/Modern Marvels - Axes, Swords, and Knives.avi
430453082b / 420364.33Kb / 410.51Mb - /Media/TV/Modern Marvels/Modern Marvels - Machines of D-Day.avi
428136892b / 418102.43Kb / 408.30Mb - /Media/TV/Modern Marvels/Modern Marvels - Magnum.avi
408764044b / 399183.63Kb / 389.82Mb - /Media/TV/Modern Marvels/Modern Marvels - Snack Food Tech.avi
407927738b / 398366.93Kb / 389.03Mb - /Media/TV/Modern Marvels/Modern Marvels - Train Wrecks.avi
405319136b / 395819.46Kb / 386.54Mb - /Media/TV/Modern Marvels/Modern Marvels - More Snack Food Tech.avi
380031956b / 371124.95Kb / 362.42Mb - /Media/TV/Modern Marvels/Modern Marvels - Emergency Room.avi
370051072b / 361378.00Kb / 352.90Mb - /Media/TV/Heroes/Season 2/Heroes.S02E03.HDTV.XViD-HiQT.avi
369717248b / 361052.00Kb / 352.58Mb - /Media/TV/Modern Marvels/Modern Marvels - Drag Racing.avi
369561600b / 360900.00Kb / 352.44Mb - /Media/TV/Modern Marvels/Modern Marvels - Camouflage.avi
369217536b / 360564.00Kb / 352.11Mb - /Media/TV/Modern Marvels/Modern Marvels - Dangerous Cargo.avi
368844274b / 360199.48Kb / 351.75Mb - /Media/TV/Lost/season_4/Lost.S04E11.HDTV.avi
368832512b / 360188.00Kb / 351.74Mb - /Media/TV/Lost/season_2/Lost - s02e16.avi
368580608b / 359942.00Kb / 351.50Mb - /Media/TV/House MD/House MD - Season 2/House MD 215 - Clueless.avi
368568520b / 359930.19Kb / 351.49Mb - /Media/TV/Psych/Psych.S03E03.HDTV.XviD-NoTV.avi
368372278b / 359738.55Kb / 351.30Mb - /Media/TV/Mad Men/Season 3/Mad Men - S03E01 - UNKNOWN.avi
368332800b / 359700.00Kb / 351.26Mb - /Media/TV/Modern Marvels/Modern Marvels - Engineering Disasters 16.avi
368308224b / 359676.00Kb / 351.24Mb - /Media/TV/Modern Marvels/Modern Marvels - Coal Mines.avi
368290708b / 359658.89Kb / 351.22Mb - /Media/TV/Lost/season_1/Lost - s01e16.avi
368283648b / 359652.00Kb / 351.22Mb - /Media/TV/Lost/season_1/Lost - s01e08.avi
368195584b / 359566.00Kb / 351.13Mb - /Media/TV/Mad Men/Season 2/Mad Men - S02E10 - UNKNOWN.avi
368152576b / 359524.00Kb / 351.09Mb - /Media/TV/Mad Men/Season 2/Mad Men - S02E08 - UNKNOWN.avi
368128360b / 359500.35Kb / 351.07Mb - /Media/TV/Dexter/Season_2/Dexter S02E04 - See-Through.avi
368119808b / 359492.00Kb / 351.06Mb - /Media/TV/Modern Marvels/Modern Marvels - Glue.avi
368112450b / 359484.81Kb / 351.05Mb - /Media/TV/Lost/season_5/Lost.S05E07 - The Life and Death of Jeremy Bentham.avi
368111616b / 359484.00Kb / 351.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Frontline Reporting.avi
368111616b / 359484.00Kb / 351.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Bible Tech.avi
368109568b / 359482.00Kb / 351.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Surveillance Tech.avi
368107520b / 359480.00Kb / 351.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Poison.avi
368107520b / 359480.00Kb / 351.05Mb - /Media/TV/Modern Marvels/Modern Marvels - George Washington Bridge.avi
368107520b / 359480.00Kb / 351.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Arches.avi
368105472b / 359478.00Kb / 351.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Smart Bombs.avi
368105472b / 359478.00Kb / 351.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Natures Engineers 2.avi
368103424b / 359476.00Kb / 351.05Mb - /Media/TV/Modern Marvels/Modern Marvels - Engineering Disasters 9.avi
368099328b / 359472.00Kb / 351.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Sub-zero Tech.avi
368099328b / 359472.00Kb / 351.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Sears Tower.avi
368099328b / 359472.00Kb / 351.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Engineering Disasters 8.avi
368099328b / 359472.00Kb / 351.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Deadliest Weapons.avi
368097280b / 359470.00Kb / 351.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Police Guns.avi
368095232b / 359468.00Kb / 351.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Power Tools.avi
368093184b / 359466.00Kb / 351.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Worlds Longest Bridge.avi
368093184b / 359466.00Kb / 351.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Satelite.avi
368093184b / 359466.00Kb / 351.04Mb - /Media/TV/Modern Marvels/Modern Marvels - Engineering Disasters.avi
368089088b / 359462.00Kb / 351.03Mb - /Media/TV/Modern Marvels/Modern Marvels - High Tech Sex.avi
368087040b / 359460.00Kb / 351.03Mb - /Media/TV/Modern Marvels/Modern Marvels - Power Plants.avi
368087040b / 359460.00Kb / 351.03Mb - /Media/TV/Modern Marvels/Modern Marvels - Alcan Highway.avi
368078848b / 359452.00Kb / 351.02Mb - /Media/TV/Mad Men/Season 2/Mad Men - S02E13 - UNKNOWN.avi
368072704b / 359446.00Kb / 351.02Mb - /Media/TV/Modern Marvels/Modern Marvels - Nature Tech Tsunami's.avi
368066560b / 359440.00Kb / 351.01Mb - /Media/TV/Modern Marvels/Modern Marvels - Helicopters.avi
368007168b / 359382.00Kb / 350.95Mb - /Media/TV/House MD/House MD - Season 1/House MD 105 - Damned If You Do.avi
367997084b / 359372.15Kb / 350.94Mb - /Media/TV/Dexter/Season_2/Dexter S02E07 - That Night, A Forest Grew.avi
367984640b / 359360.00Kb / 350.93Mb - /Media/TV/Rome/Rome - s01e04.avi
367966208b / 359342.00Kb / 350.91Mb - /Media/TV/Modern Marvels/Modern Marvels - Magnets.avi
367964160b / 359340.00Kb / 350.91Mb - /Media/TV/Modern Marvels/Modern Marvels - Quarries.avi
367960064b / 359336.00Kb / 350.91Mb - /Media/TV/Modern Marvels/Modern marvels - The Manhatten Project.avi
367958016b / 359334.00Kb / 350.91Mb - /Media/TV/Modern Marvels/Modern Marvels - Booby Traps.avi
367955968b / 359332.00Kb / 350.91Mb - /Media/TV/House MD/House MD - Season 2/House MD 204 - TB or Not TB.avi
367927296b / 359304.00Kb / 350.88Mb - /Media/TV/Modern Marvels/Modern Marvels - Titanic Tech.avi
367927296b / 359304.00Kb / 350.88Mb - /Media/TV/Modern Marvels/Modern Marvels - Concept Cars.avi
367925248b / 359302.00Kb / 350.88Mb - /Media/TV/Modern Marvels/Modern Marvels - Cranes.avi
367910912b / 359288.00Kb / 350.86Mb - /Media/TV/Modern Marvels/Modern Marvels - Train Crashes.avi
367901086b / 359278.40Kb / 350.85Mb - /Media/TV/Lost/season_5/Lost.S05E04 - The Little Prince.avi
367894528b / 359272.00Kb / 350.85Mb - /Media/TV/Modern Marvels/Modern Marvels - Gasoline.avi
367892480b / 359270.00Kb / 350.84Mb - /Media/TV/Modern Marvels/Modern Marvels - Firefighters Extreme Conditions.avi
367888428b / 359266.04Kb / 350.84Mb - /Media/TV/House MD/House MD - Season 2/House MD 223 - Who's Your Daddy.avi
367882674b / 359260.42Kb / 350.84Mb - /Media/TV/Psych/Psych.S03E05.HDTV.XviD-NoTV.avi
367880192b / 359258.00Kb / 350.83Mb - /Media/TV/Modern Marvels/Modern Marvels - Bunkers.avi
367863808b / 359242.00Kb / 350.82Mb - /Media/TV/Modern Marvels/Modern Marvels - Muscle Cars.avi
367862124b / 359240.35Kb / 350.82Mb - /Media/TV/Lost/season_5/Lost.S05E08.HDTV.XviD-XOR.avi
367861760b / 359240.00Kb / 350.82Mb - /Media/TV/Modern Marvels/Modern Marvels - US Mints.avi
367860240b / 359238.51Kb / 350.81Mb - /Media/TV/Dexter/Season_4/Dexter.S04E01.avi
367859712b / 359238.00Kb / 350.81Mb - /Media/TV/Lost/season_3/Lost - s03e16.avi
367853568b / 359232.00Kb / 350.81Mb - /Media/TV/Modern Marvels/Modern Marvels - Desert Tech.avi

Bash Scripting Guideis one of the best resources I know of for writing bash scripts.

Bash Scripting Guide是我所知道的编写 bash 脚本的最佳资源之一。

man stat
man sort
man find
man bc
man tr

man stat
man sort
man find
man bc
man tr

回答by Armand

Here is my take on the answer:

这是我对答案的看法:

find folder -type f -print0 | xargs -0 file --media-type | egrep 'image|video' | cut -f1 -d : | tr '\n' '##代码##'

The above will locate all Videos and Images. If you refer to @Adam's example, you can then capture the output from this into a for loop to generate the information you are looking for. It's best to put all this into a script. I include the tr '\n' '\0' at the end so that you can pipe the output to xargs with the -0 argument to simplify chaining this with other commands. if you are going to use the for loop wrapper solution, then the tr is not necessary (though having it eliminates the need to deal with special characters and quoting in file name)

以上将找到所有视频和图像。如果您参考@Adam 的示例,则可以将 this 的输出捕获到 for 循环中以生成您要查找的信息。最好将所有这些都放入一个脚本中。我在末尾包含 tr '\n' '\0' 以便您可以使用 -0 参数将输出通过管道传输到 xargs 以简化将其与其他命令链接。如果您打算使用 for 循环包装器解决方案,则 tr 不是必需的(尽管使用它消除了处理特殊字符和在文件名中引用的需要)

回答by Captain Deadly

xargs -0 file --media-type

xargs -0 文件 --media-type

--mime-type

--mime 类型