Skip to content
/ lg Public

馃敟 List greater files or lg (Free Unix-like binary command)

License

Notifications You must be signed in to change notification settings

innaky/lg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

36 Commits

Repository files navigation

idiomas/idioms

Download binary

lg x86_64

lg (Comando Linux/Unix-like)

Lista los archivos por tama帽os de mayor a menor.

El tama帽o de los directorios es equivalente a la cantidad de informaci贸n que contengan recursivamente.

El tama帽o de los directorios vac铆os es cero.

Motivaci贸n

En trabajos con servidores (GNU/Linux, BSD), ocasionalmente ten铆a que buscar los directorios o archivos de mayor tama帽o, para respaldo u otra actividad. Usualmente con unos pocos comandos es f谩cil resolverle.

Pero 驴Si tienes much铆simos directorios con un gran 谩rbol de subdirectorios, con muchos archivos? (ejemplo colapso de disco por mal empleo de logs)

Pues con algunas tuber铆as asunto resuelto...

Pero quer铆a programar un binario en Haskell para mis amistades, as铆 que tom茅 este problema, el binario lo ejecutas llamando a un directorio y obtienes los archivos o directorios de mayor tama帽o a un nivel de profundidad, sin embargo, la sumatoria es recursiva, es decir, revisa todo el 谩rbol de subdirectorios.

Construcci贸n e instalaci贸n

git clone https://github.com/innaky/lg
  • Construcci贸n:
cd lg
stack build

Tomas el binario que se encuentra bajo el directorio .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/lg

chmod 755 lg
mv lg /usr/local/bin

Listo, con estos pasos lo tendr谩s disponible en el sistema.

Uso

  • Ayuda:

lg [-h | --help]

  • Ejecuci贸n:

lg [-b] archivo | directorio

Por defecto est谩 en formato de f谩cil lectura (Kilobytes, Megabytes etc), con el par谩metro -b al inicio, la salida es en bytes.

Ejemplos

  • Salida con lectura agradable (lg directorio)
> lg /home/live/src/haskell-misc/
106K     /home/live/src/haskell-misc/.git
23K      /home/live/src/haskell-misc/learn-you-a-haskell
1K       /home/live/src/haskell-misc/LICENSE
617      /home/live/src/haskell-misc/README.md
  • Salida en bits (lg -b directorio)
> lg -b /home/live/src/haskell-misc/
108837   /home/live/src/haskell-misc/.git
24372    /home/live/src/haskell-misc/learn-you-a-haskell
1063     /home/live/src/haskell-misc/LICENSE
617      /home/live/src/haskell-misc/README.md`
  • Salida agradable de archivo (lg /ruta/archivo):
> lg /home/live/ISOS/test.iso
516M     /home/live/ISOS/test.iso
  • Salida en bytes para archivos (lg -b /ruta/archivo):
> lg -b /home/live/ISOS/test.iso
541065216        /home/live/ISOS/test.iso
  • ayuda (lg -h):
SYNOPSIS
    lg [-h | --help ]
    lg [-b] Filename | Directory

    For more information lg --help
  • Para ayuda detallada usar (lg --help)

Escalabilidad

Ya desde esta versi贸n (gracias a @echarte) es f谩cil escalar el binario, agregando una m贸dulo en /src e importandole en /app/Main.hs, s贸lo debes agregar el par谩metro en la funci贸n main :: IO ()

lg (Free Unix-like binary command)

List greater files

Return a filename and the size:

  • If the input is a file return the size.
  • if the input is a file type directory return the sum (recursively) of all of files.

Usage

lg of a directory

> lg /home/live/src/haskell-misc/
106K     /home/live/src/haskell-misc/.git
23K      /home/live/src/haskell-misc/learn-you-a-haskell
1K       /home/live/src/haskell-misc/LICENSE
617      /home/live/src/haskell-misc/README.md

lg of a file

> lg /home/live/src/haskell-misc/README.md
617      /home/live/src/haskell-misc/README.md

Shell pipes

lg /home/live/src/haskell-misc/ | head -n 2
106K     /home/live/src/haskell-misc/.git
23K      /home/live/src/haskell-misc/learn-you-a-haskell

Symbolic link management (Example)

# Input in the directory

> cd /home/live/src/haskell-misc

# List the files
> ls -l 
total 12
drwxr-xr-x 7 live live 4096 feb 17 21:40 learn-you-a-haskell
-rw-r--r-- 1 live live 1063 feb 17 21:40 LICENSE
-rw-r--r-- 1 live live  617 feb 24 18:04 README.md

# Creating directory symbolic link (DirHomeLink) and file symbolic link (MyFileLink)
> ln -s /home/live/ DirHomeLink
> ln -s /home/live/src/haskell-misc/README.md MyFileLink

# List Everything
> ls -la
total 24
drwxr-xr-x 4 live live 4096 feb 29 21:48 .
drwxr-xr-x 6 live live 4096 feb 25 04:36 ..
lrwxrwxrwx 1 live live   11 feb 29 21:47 DirHomeLink -> /home/live/
drwxr-xr-x 8 live live 4096 feb 28 21:01 .git
drwxr-xr-x 7 live live 4096 feb 17 21:40 learn-you-a-haskell
-rw-r--r-- 1 live live 1063 feb 17 21:40 LICENSE
lrwxrwxrwx 1 live live   37 feb 29 21:48 MyFileLink -> /home/live/src/haskell-misc/README.md
-rw-r--r-- 1 live live  617 feb 24 18:04 README.md

# Testing "List greater" binary (lg)
> lg .
106K     /home/live/src/haskell-misc/.git
23K      /home/live/src/haskell-misc/learn-you-a-haskell
1K       /home/live/src/haskell-misc/LICENSE
617      /home/live/src/haskell-misc/README.md
8        /home/live/src/haskell-misc/MyFileLink
0        /home/live/src/haskell-misc/DirHomeLink

for :

  • file symbolic link return the size.
  • directory symbolic link return zero.

About

馃敟 List greater files or lg (Free Unix-like binary command)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published