Giter Site home page Giter Site logo

lg's Introduction

idiomas/idioms

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
cabal 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.

lg's People

Contributors

innaky avatar signedchar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.