Shell scripts make it easy to pass data between external commands. But shell script as a programming language lacks features like non-trivial data structures and easy, robust concurrency. These would be useful in building quick solutions to system administration and automation problems.
As others have noted,12345 Haskell is an interesting alternative for these scripting tasks. I wrote the shqq
library to make it a little easier to invoke external programs from Haskell. With the sh
quasiquoter, you write a shell command which embeds Haskell variables, execute it as an IO action, and get the command's standard output as a String
. In other words, it's a bit like the backtick operator from Perl or Ruby.
Here's a small example:
$ ghci -XQuasiQuotes
λ> import System.ShQQ
λ> let x = "/proc/uptime" in [sh| sha1sum $x |]
"337ec3fb998fb3a4650a18e0785f0992762b3cda /proc/uptime\n"
shqq
also handles escaping for you, so that the shell will not interpret special characters from Haskell variables. You can override this behavior when desired.
The big caveat is that shqq
refuses to build on GHC 7.0 or earlier, due to a Unicode-handling bug in process-1.0
. You'll need GHC 7.2 or later.
Finding duplicate files
As an example, here's a program to find duplicate files in the directory tree rooted at the current working directory.
{-# LANGUAGE QuasiQuotes, TupleSections #-}
import Control.Concurrent.Spawn -- package spawn-0.3
import Data.List.Split -- package split-0.1
import System.ShQQ -- package shqq-0.1
import System.Posix.Files
import qualified Data.Map as M
First, the computation itself. If we pair each file with a key, such as size or checksum, we can find the groups of (potentially) duplicate files.
dupes :: (Ord k) => [(FilePath,k)] -> [[FilePath]]
dupes = filter (not . null . drop 1) . M.elems
. foldr (\(v,k) -> M.insertWith (++) k [v]) M.empty
We want to examine files in parallel, but the operating system will complain if we have too many open files. We limit each pass to have at most 256 tests in progress at once.
inParallel :: (a -> IO b) -> [a] -> IO [b]
inParallel f xs = do p <- pool 256; parMapIO (p . f) xs
For efficiency, we find potential duplicates by size, and then checksum only these files. We use external shell commands for checksumming as well as the initial directory traversal. At the end we print the names of duplicated files, one per line, with a blank line after each group of duplicates.
main :: IO ()
main = do
files <- endBy "\0" `fmap` [sh| find -type f -print0 |]
let getSize f = ((f,) . fileSize) `fmap` getFileStatus f
sizeDupes <- dupes `fmap` inParallel getSize files
let getSha f = ((f,) . head . words) `fmap` [sh| sha1sum $f |]
shaDupes <- dupes `fmap` inParallel getSha (concat sizeDupes)
mapM_ (mapM_ putStrLn . (++[""])) shaDupes
And we run it like so:
$ ghc -O -threaded -rtsopts dupe.hs
$ ./dupe +RTS -N
I included type signatures for clarity, but you wouldn't need them in a one-off script. Not counting imports and the LANGUAGE
pragma, that makes 10 lines of code total. I'm pretty happy with the expressiveness of this solution, especially the use of parallel IO for an easy speedup.
Thanks to Dylan Lukes for the original idea for this library.
Where are 'pool' and 'parMapIO' defined?
ReplyDeleteAnacrolix: They're defined in the module Control.Concurrent.Spawn, from the package 'spawn'.
ReplyDelete10 lines? Of much more complex code? Plus more stuff around it?
ReplyDeleteThat would have taken one line in bash. And be nicer to the eye / simpler to read.
Something like this would probably do the trick:
find -type f | while read F; do echo "$(sha1sum "$F" | cut -c 1-40) $(stat -c %s "$F") $F"; done | uniq -d -f 3 -c # -c is optional
(Files with backslashes in their names won’t work.)
Sure, it won’t be as fast to run, but it’s just a one-off thing, and the hard disks are the speed bottleneck anyway, so the difference will be negligible.
I love me some Haskell, but *you’re doing it wrong*!
BAReFOOt:
ReplyDeleteYou seem to be missing the point. The article is about the shqq library, not about finding duplicate files. That's what we in the business like to call "an example".
Cool, the only change needed to run on OSX was to add a '.' argument after 'find'. Thanks for sharing!
ReplyDeleteمن المعلوم أن عملية نقل العفش والمتعلقات الشخصية ليست بأمر يسير، فهو شيء بالغ الصعوبة والأهمية، فجميعنا نود حماية وحفظ ممتلكاتنا دون حدوث لها أي شيء قد يترك تأثيره على شكلها وقيمتها، وهنا في مؤسسة نقل عفش بخميس نقوم بمساعدك في تقصي ذلك الشأن دون أي مشكلات ولا تلفيات لأي شيء، فنحن نعمل باستمرارٌ على راحتك وسعادتك عميلنا العزيز.
ReplyDeleteشركة نقل عفش
شركة نقل اثاث من الرياض الى قطر
شركة نقل عفش من الرياض الى قطر
شركة نقل عفش بابها
lampungservice.com
ReplyDeletetempatservicehpdibandarlampung.blogspot.com
lampungandroid.blogspot.com
http://www.google.co.id/url?q=http://www.lampungservice.com
http://www.google.com/url?q=http://www.lampungservice.com
Thanks for sharing this helpful post, hopefully you will share some more IT related post.
ReplyDeleteGet the best lead conversion services through email advertising and massive SMS messages in London, United Kingdom, with lead generation companies uk.
Bluebeam Revu Standard Crack
ReplyDeleteCracked Here is a useful place where you can easily find Activators, Patch, Full version software Free Download, License key, serial key, keygen, Activation Key and Torrents.
Get all of these by easily just on a single click.
Final Draft Crack Download is one of the most powerful scripting software in the world for writing and formatting scripts in a standard script format.finaldraftcrack
ReplyDeleteNuance Dragon Professional Individual Crack is an advanced speech recognition software that allows busy professionals to convert words / spoken words into text. dragonprofessionalindividual
ReplyDeleteGameMaker Crack Key Download is an easy-to-use game-making software that allows beginner developers to create great games using actions without programming knowledge.gamemakerstudioultimateserialkey
ReplyDeleteu-he Total Bundle Mac Crack Download: Diva captures the spirit of analog synthesizers for 50 years. Oscillators, filters, and envelopes from the great monophonic and polyphonic composers of the past have been meticulously configured for unparalleled analog sound.uhetotalbundletorrent
ReplyDeleteBig EDM PsyTrance Chakra Crack Download offers a new experience in creating music-driven music journeys.bigedmpsytrancechakrafreedownload
ReplyDeleteAshampoo Burning Studio Crack is a fast and reliable way to burn movies, music, and files to any recordable disc. Besides data backups, this burning program also extracts audio from music CDs and creates stylish covers and overlays.crackforashampooburningstudio
ReplyDeleteAOMEI Partition Assistant Crack is disk partition manager software, which has earned its reputation among users around the world.aomeipartitionassistantlicensecode
ReplyDeleteI am a regular visitor, and this post posted on this web page is truly pleasant.
ReplyDeleteLooserCrack
Lightworks Pro Crack
ReplyDeleteDownload Latest Pro Crack Software With Keys
I am very thankful for the effort put on by you, to help us, Thank you so much for the post it is very helpful, keep posting such type of Article.
This is very useful article for me Thanks for this help us in this way and provide us usful content from this website
ReplyDeleteYou can visit these article
Driver Easy Pro
Adobe Spark
This website is remarkable information and facts it’s really excellent
ReplyDeleteGrammarly Premium Crack
avira-antivirus-pro-crack
ReplyDeletevlc-media-player-crack
ezvid-video-maker-crack
adobe-photoshop-cc-crack
altercam-crack
norton-antivirus-crack
movavi-screen-recorder-crack
avast-free-antivirus-crack
winrar-crack
download unity pro full crack
ReplyDeleteI am very thankful for the effort put on by you, to help us, Thank you so much for the post it is very helpful, keep posting such type of Article. Excellent piece of work, and I am in wonder how you manage all of this content and his entry. I would like to say you have superb capabilities related to your work, and lastly, please keep it up because I am looking for the more
Here you will find free full software.
ReplyDeleteGenymotion Crack
Powtoon Crack
Radioboss Keygen
Radioboss Torrent
Readiris Pro Crack
A friend is someone who knows all about you and still loves you.
ReplyDeleteDLL File Fixer Crack
This article is one of the beat near me.
ReplyDeleteI really like this article.
adguard lifetime key
FabFilter Saturn Crack with Torrent (2021) Latest Free Download FabFilter Saturn 2 Crack latest new edition that is a top rated distortion, saturation as well as amp modeling plugin. The tool includes powerful and unique modulation options.
ReplyDeleteFabFilter Saturn Crack + License Key Full Version Download FabFilter Saturn Crack comes with a great 77 presets that utilize the plugin’s 25 saturation templates for the purpose to generate a wide range of soundtracks varies from delicate warmth to sonic annihilation.
ReplyDeleteWell, Are you looking for the Miracle Box Crack Lest Version without box configuration, then you are in the right place. Here we will share all the versions of the Miracle Box Crack Setup Full Edition. Also, the current version is 3.21. More, this tool works on most smartphones with brands such as OPPO, Vivo, Motorola, Xiaomi, and much more. So, before you install this, make sure to Turn Off any active “Antivirus Software” from your system to avoid disturbance while installing Miracle Software. So, download Miracle Box 3.14 Crack here.
ReplyDeleteMiracle Box Crack
Pianoteq 7.4.1 Crack is a sound-creating instrument. Also, Pianoteq means a brand. And not consider it a simple program. It is specially designed to provide you with full-time mental joy with its fantastic sound system. Moreover, its unique and simple features and functions make it more different from other tools. Also, nothing is much difficult in this software from the day of its release. In this advanced world, the music industry is leading nowadays. And there are millions of music-creating tools. However, Pianoteq Crack Mac download free full version is more advanced and than others. Likewise, the instrument is more flexible in its category. However, most of the applications on the internet require special tutorials as well as more deep knowledge of hardware. But, Pianoteq Mac Crack does not need such things.
ReplyDeletepianoteq crack
Nice work. am very glad to be here. thanks a lot for sharing this wonderful work. keep going and going.
ReplyDeletecrackwon
crackinfree
Adobe Spark Crack With Serial Key Free Version Download Adobe Spark Crack Create impact social graphics, web stories, and animated videos with Spark’s free graphic design app
ReplyDeletevst4free is a great shooter with polygonal graphics very similar to Minecraft.
ReplyDeleteNice post. I used to be checking constantly this blog and I am impressed! Extremely useful info particularly the ultimate section 🙂 I take care of such information a lot. I was seeking this certain information for a long time. Thank you and best of luck.
ReplyDelete9th Sanskrit Trimasik exam 2021 solution
I am very lucky to see this grateful website. I think my needed articles here. I appreciate your good work. Keep it up. I found this great website during searching my needed articles on google. Thanks for sharing us.
ReplyDeleteLightworks Pro 2022.3 Crack
AllCrackSoft Full Version Softwares Free Download
ReplyDeleteSuper-Duper site! I am Loving it!! Will come back again, Im taking your feed also, Thanks.eset-nod32-antivirus-license-key/
Microsoft office 365 Product Key is the activation key for MS office 365. It is a complete package of tools that makes your work easier. The features are classic and helpful. Yes, I want to tell you that it is offline office software and helps users do their work offline over the pc or laptop. Microsoft Office Crack
ReplyDeletegreat tips you provide us thanx for sharing keep it up.Active Data Studio crack
ReplyDeleteNetbalancer Crack is an extraordinary software that fills in as an organization analyzer, regulator, and observing device. Utilizing this device allows clients effectively to control organizations. For example, deciding the need of an application network access, restricting rate, setting up security, block access, and so on Thusly, it shows the subtleties of the organizations' utilization independently and all in (all out traffic). Additionally, NetBalancer Pro Crack empowers you to control, peruse, and do any web movement. Control web traffic with needs and rules.
ReplyDeletehttps://cracklot.com/netbalancer-crack-code/
Assassin Creed 3 Highly Compressed PC Game is a gutsy computer game loaded with activity and exciting energy. It is played from a third-individual viewpoint. This game permits you to investigate another world and show your gaming abilities. The primary plot of the computer game depends on the anecdotal history that connections back to Assassins, who took on many conflicts for their tranquility and to assume responsibility for the world.
ReplyDeletehttps://icompressedgames.com/assassin-creed-3-highly-compressed/
Thanks for sharing such a great post. Nice Post I Enjoyed!
ReplyDeleteGameMaker Studio Crack
IceCream Screen Recorder Crack
Super-Duper site! I am Loving it!! Will come back again, Im taking your feed also, Thanks.
ReplyDeleteavg-pc-tuneup-crack/
https://crackedpro.org/express-vpn-crack-with-serial-key-full/
ReplyDeleteExpress VPN Crack is the totality of several big VPN services. Because it offers a special-security entree to the Internet. This is not unsigned internet browsing. It is a pop VPN program used by millions of people to protect anonymous internet browsing and name.
https://crackedsoftpc.com/windows-10-manager-crack/
ReplyDeleteWindows 10 Manager Crack is an application that makes doubles your computer speed and checks your computer every day,
https://activatorskey.com/little-snitch-4-full-torrent-cracked/
ReplyDeleteLittle Snitch Crack helps you to see, what is invisible to you. It displays the internet connection, which you cannot see. It provides you authentic control over this internet connection
https://activatorscrack.com/icloud-remover-cracked/
ReplyDeleteiCloud Remover Crack is a very good and very famous program that can help to move your all iPhone data to your iCloud account and save it from loss. To stimulate the Find my iPhone feature on your iPhone, be sure to are logged into the Apple device with your Apple Identification and Security password,
Nice. Your work provides me a good information
ReplyDeleteGenymotion
Pixologic ZBrush 7.1 Crack software program that digitally sculpts the gadgets. It combines 3-d/2.5D modeling, texturing, and painting. There is a pixel that saves the lighting, color, material, orientation, and intensity facts for the factors generating up all gadgets on the screen. ZBrush is greater akin to conventional sculpting.
ReplyDeleteZBrush 2022 crack is the software program that develops 3-d virtual sculpting. Pixologic ZBrush has many powerful capabilities. It makes use in diverse industries.
CareUEyes Pro 2.1.7.0 Crack is the soft, computerized blue filtration device and a tip to relaxation and takes a loosen up every time. The aggregate of the 2 of those hrs can assist lower eye pressure precipitated via way of means of non-stop and extended use of computer systems. Regardless of the precise pretty grammatically un-attractive name may also recommend, CareUEyes Cracked Apk Download is a great small application created to appeal to people who make investments massive additives in their existence seated in the front of computer shows.
Many men and women struggle with drug and alcohol use does putting drugs in your anus work along with mental illness. In 2018, an estimated 9.2 million people in the U.S. struggled with co-occurring disorders like this, according to the Substance Abuse and mental Health Services Administration.
ReplyDeleteKnow how the Cash app twitches words in a detailed way.
ReplyDeleteTo understand how Cash App Twitch works and what you can do to get the best out of it, you don't have to wander. For the same purpose, the best step you can take is to read these posts thoroughly. Here, you will know all about it in a proper and hassle-free manner. Follow the provided link and get to know everything.
I love your blog. Many thanks for the shared this informative and Interesting post with us
ReplyDeleteNote Burner Sptify Music Converter with Crack
ReplyDeleteWow! very beautiful, great, nice, and very good post. I like it very much.
adobe-xd-cc
ReplyDeleteCamtasia Studio Crack
I am very happy to read this article.Thanks for giving us Amazing info. Fantastic post.
I appreciate this post. You write in such an amazing style and I really enjoy visiting your website.
hope you'll continue to write like this in the future.
Is this a paid topic or do you change it yourself?
ReplyDeleteHowever, stopping by with great quality writing, it's hard to see any good blog today.
AirMyPC Crack
iTools Crack
ReplyDeletenuance dragon professional individual crack Check-Put your voice
to work creating reports, emails, forms, and more with the new Dragon Professional Individual, v15.
Your post style is super Awesome and unique from others I am visiting the page I like your style.
ReplyDeleteYodot RAR Repair
You write in such an amazing style and I really enjoy visiting your website. I hope you'll continue to write like this in the future.
ReplyDeletehqplayer crack
I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. You can Latest Software Crack Free Download With Activation Key, Serial Key & Keygen I hope to have many more entries or so from you. Download Crack Softwares Free Download
ReplyDeletefull latest version 2022 blog.
PreSonus Notion Crack
CLA-76 Compressor Crack
Ozone Imager Crack
1Keyboard Crack
4Front TruePianos Latest VST Crack
Readiris Pro Crack
Easyworship crack
ReplyDeleteTurbotax Pro Crack
CLO Standalone Crack
Revo uninstaller Crack
Miracle Box Tools Crack is a GSM thunder edition product, relating to you for activation, here, you can easily update or crack up the software for the purpose of long time usage anonymously. The thunder edition will lead you to go slightly to awake up the complete functionality having a quick response in a short period of time. It is easy to load more solutions for your mobile devices. Let, you can enjoy the flash-up power of the device accurately.
มาเเล้ว cetecc เว็บไซต์ที่รวบรวมความน่ารักของสัตว์เลี้ยง ใครที่กำลังมองหาสัตว์เลี้ยงสักตัวไว้ดูเเล เเละเป็นเพื่อคลายเหงาเว็บไซต์ของเราก็มีมาเเนะนำ เยี่ยมชม รวมทริคการเลี้ยงสัตว์ ติดตามเรื่องราวสัตว์โลกน่ารัก ได้ที่นี้ เทคนิคที่จะช่วยให้สัตว์เลี้ยงของคุณมีสุขภาพที่ดี รวมครบจบที่นี่.
ReplyDeleteDavinci Resolve Crack
ReplyDeleteParallel Desktop Crack
Windows 10 Crack
WinZip Pro Crack
graphpad prism crack
FL Studio Crack
ccleaner pro crack
wondershare filmora crack
EaseUS Partition Master Crack
That was a fantastically written article. It's a pleasure to study under your tutelage. Maintain an active lifestyle.https://hitlicense.net/rewasd-crack/
ReplyDeleteGutt Websäit : Zonahobisaya
ReplyDeleteGutt Websäit : Zonahobisaya
Gutt Websäit : Zonahobisaya
Gutt Websäit : One Piece
Gutt Websäit : Zonahobisaya
Gutt Websäit : Biodata
Gutt Websäit : Sinopsis Film
Gutt Websäit : Sinopsis Film Terbaru
I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. axcrack.com I hope to have many more entries or so from you.
ReplyDeleteVery interesting blog.
Easeus Partition Master Crack
this is a very importent posts thanks for help
ReplyDeleteseriallink.org
NordVPN Crack
FastFolders Crack
Flip PDF Corporate Edition Crack
AnyDesk Crack
I guess I am the only one who came here to share my very own experience. Guess what
ReplyDeleteI am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues.
I do not know how to Crackadvise Free Download But thankfully, I recently visited a website named Crackadvise.Crack
Corel VideoStudio Crack
SoftPerfect Network Scanner Crack
Aeesoft Buisrnova Crack
Nero Burning ROM Crack
VMware Fusion Pro Crack
Arclab Watermark Studio Crack
I like this application. It works in a very easy way. No need to pay for these features on another application. Download Here
ReplyDeleteI enjoy your blog everytime you share. god job keep it up. also try Virtual DJ 2022 Infinity VST Crack
ReplyDeleteVery Nice Blog this excellent Software.
ReplyDeletehttps://hotpcsoft.com/ukeysoft-spotify-music-converter/
I am very impressed with your post because this post is very beneficial for me and provide a new knowledge to me
ReplyDeleteAdobe Lightroom Crack
Screenpresso Crack
Ludo Star MOD (Unlimited) Crack
Many thanks for sharing this informative and interesting post with us. cockos-reaper-crack/
ReplyDelete
ReplyDeleteI guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to Download Latest PC Cracked Softwares But thankfully, I recently visited a website named pcsoftz.net
Adobe Photoshop Lightroom Crack/
I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot.
ReplyDeleteChessBase Crack
Blue Iris Crack
Cinch Audio Recorder Crack
ReplyDeleteI guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to Download Latest PC Cracked Softwares But thankfully, I recently visited a website named pcsoftz.net
Adobe Photoshop Lightroom Crack
I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.
ReplyDeleteVery interesting blog.
Virtual Audio Cable Crack
AVG Driver Updater Crack
Reason Crack
RealVNC Enterprise Crack
ReplyDeleteHowever, stopping by with great quality writing, it's hard to see any good blog today.
https://crackpul.com/
GstarCAD Professional Crack
FontCreator Crack
AlterCam Crack
4K Video Downloader Crack
Rekordbox DJ Crack
Macro Recorder Crack
AlterPDF Pro Crack
Advanced SystemCare Pro Keygen enables you to eliminate various security threats, including viruses, spying, and ransomware
ReplyDeleteGrand Theft Auto V Offline and multiplayer modes The chief variation is can compete against others for rewards and join your friends as your opponents. The core cast of Michael, Franklin, and Trevor live in world of the early aughts concerned with the Great Recession, the meth, and the problem of getting yours in the door. They are in capitalism, each trying to their way in the world. They assemble mentors or friends as they go, all of whom are consumed in an ever-complicating story that prods corrupt government agencies, companies, and wellness.
ReplyDeletekralbet
ReplyDeletebetpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
betmatik
HT7
Downie Crack For Mac Free Download could help you download those films to your computer so you can view them with your preferred media player. It’s a great tool for downloading videos from different websites to your Mac so you can watch them later.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteFlykez is a European Award-winning creative branding & marketing agency in France that aims to drive impactful change
ReplyDelete