Find the smallest file
Bash + coreutils, 13 bytes
ls -Sar|sed q
Explanation:
ls -Sar|sed q
ls # list files
-S # sorted, biggest first
a # show hidden files
r # reversed (smallest first)
|sed q # q is quit at first line that matches given regex,
# given regex is empty so guaranteed match.
PowerShell, 30 24 21 bytes
(ls|sort le*)[0].Name
Try it online!
ls
is an alias for Get-ChildItem
. That's piped to sort-object
with the length
attribute, so the files are sorted by size. We index into that with the (...)[0]
to get the first (i.e., smallest), and then take the .Name
thereof. Output via implicit Write-Output
happens at program completion.
Saved 6 bytes since we're guaranteed that only files exist in the directory. Saved an additional 3 thanks to ConnorLSW.
Python 2 3, 94 76 74 54 bytes
-18 bytes thanks to @orlp
-2 bytes thanks to @Jonathan Allan
-20 bytes thanks to a change in challenge specs
from os import*
print(min(listdir(),key=path.getsize))