Accéder au contenu principal

Un script Bash pour retrouver les fichiers volumineux

Qu'est-ce qu'un fichier volumineux ?

Personne n'a une définition précise.. Mais chacun de nous, selon les cas, peut définir un fichier volumineux selon sa taille et selon l'espace disponible sur son disque dur.

L'idée de ce script est simple : permettre à l'utilisateur de choisir une taille précise à partir de laquelle les fichiers seront considérés comme volumineux. Pour moi, j'ai choisi d'exprimer cette taille en Méga-Octets. Il est possible de le modifier pour considérer d'autres ordres de grandeurs.

L'utilisation est simple aussi : il faut indiquer un répertoire et puis la taille minimale et hop ! le script demande le mot de passe root (pour pouvoir accéder à tout les fichiers, mais on peut aussi modifier ça)

Voici une capture d'écran :


enfin voici le code :


#!/bin/bash


if [[ $1 = -h ]]
then 
echo "Usage : showlargefiles "
echo "Written by Zarathoustra : http://lovermet1984.blogspot.com"
echo "lovermet1984@gmail.com | www.facebook.com/lovermet1984"
echo "Note : Requires Root password (will be prompted)"
echo "This script uses the xmessage, find and su commands. These"
echo "commands could generate warnings and errors unhandled by"
echo "the script." 
exit
else
if [[ -n $2 ]]
then
su -c "find $1 -type f -size +${2}M -exec ls -gGhl {} \;"
if [[ $? != 0 ]]
then exit
fi
else
echo "use -h for help"
exit
fi
fi
if [ -x /usr/bin/xmessage ]
then 

echo We are Done !! Thanks for using this script
fi


PS : je viens d'enlever l'utilisation de la commande xmessage à la place du dernier "echo" pour plus de simplicité.

Commentaires

Hamdi Kadri a dit…
version en mode utilisateur, ne demande pas un mot de passe root.

#---------script----------

#!/bin/bash

if [[ $1 = -h ]]
then
echo "Usage : showlargefiles "
echo "Written by Zarathoustra : http://lovermet1984.blogspot.com"
echo "lovermet1984@gmail.com | www.facebook.com/lovermet1984"
echo "Note : Requires Root password (will be prompted)"
echo "This script uses the xmessage, find and su commands. These"
echo "commands could generate warnings and errors unhandled by"
echo "the script."
exit
else
if [[ -n $2 ]]
then
exec "find $1 -type f -size +${2}M -exec ls -gGhl {} \;"
if [[ $? != 0 ]]
then exit
fi
else
echo "use -h for help"
exit
fi
fi

echo We are Done !! Thanks for using this script

Posts les plus consultés de ce blog

GNS3 on Manjaro/Arch Linux: How to create virbr0 for NAT to work

Problem: You can't add a NAT connection to your GNS3 simulation, and you get the error : "ERROR template_manager:226 Error while creating node from template: NAT interface virbr0 is missing, please install libvirt" Steps to resolve: 1- Create a file named /tmp/default.xml 2- Paste this content and save: <network>   <name>default</name>   <bridge name="virbr0"/>   <forward mode="nat"/>   <ip address="192.168.123.1" netmask="255.255.255.0">     <dhcp>       <range start="192.168.123.2" end="192.168.123.254"/>     </dhcp>   </ip> </network> 3- Execute the following commands in your shell : virsh net-define /tmp/default.xml sudo virsh net-start default sudo virsh net-autostart default  

GNS3: Simulating a 100% opensource site2site VPN using Wireguard, VyOS and OpenVSwitch

 This is something I had in mind but didn't find the time to accomplish before. It just took a very cold day to convince me that I have to play with Wireguard on VyOS. I used GNS3 of course, on my personal Linux laptop to create this setup. Of course the performance was not that great since it is just a simulation.  In real life, I am using Wireguard on a 10 years old Raspberry Pi Model B and amazingly with just a 700MHz single core ARM CPU and less than 512 MB of RAM I had a decent and stable permanent Wireguard tunnel. (My bandwidth would reach 24 Mbps without issue) Back to my simulation, this is what it looks like : Quick explanation: the VYOS routers labeled IPERF1 and IPERF2 are only used for an iperf3 test, which was able to reach about 50 to 60 Mbps each time. It ain't much but it was honest (and free) secure bandwidth! I won't get into the details of this setup but I will just post the two most important configurations : R-East and R-West : #### VYOS WireGuard Site

AutoWG: a simple Bash script to connect two devices with Wireguard

 I made today a quite simple BASH script that allows to connect two devices running Wireguard (tested with Debian Linux 12, but should work with any device) You can check it out (and fork it if you want) in this Gitlab Page This is the source code as of now, but I could modify it later (any suggestions are welcome) : #!/bin/bash # # AUTOWG written by Hamdi KADRI  # No copyright in any form or kind # This script is intended to create configurations for  # a point-to-point Wireguard connection between a server # and a client (/30 network) # # Step zero: declare configurations as variables servercfg="[Interface] Address = <serverwgIP> SaveConfig = true ListenPort = <port> PrivateKey = <server-privatekey> [Peer] PublicKey = <client-pubkey> AllowedIPs = <clientwgIP> " clientcfg="[Interface] PrivateKey = <client-privatekey> Address = <clientwgIP> [Peer] PublicKey = <server-pubkey> AllowedIPs = 0.0.0.0/0 EndPoint = <serverIP>