rm fichier.txt
rm -r dossier
💡️On peut également utiliser -R ou --recursive à la place de -r
rm -d dossier_vide
💡️On peut également utiliser la version longue --dir à la place de -d
💡️La commande rmdir existe également.
# cd dossier;
rm *
# RETOUR :
# -bash: /bin/rm: Argument list too long
# cd dossier;
ls | xargs rm
💡️Voici une version assez agressive mais très efficace qui utilise les options -r et -f : `ls | xargs rm -rf`
# cd dossier;
ls | while read param
do
rm param
done
rm fichier_1 fichier_2;
# touch fichier_1 fichier_3 fichier_4
# denis@denis:/tmp/test $ ls
# fichier_1 fichier_3 fichier_4
rm fichier_1 fichier_2 fichier_3
# RETOUR :
# rm: impossible de supprimer 'fichier_2': Aucun fichier ou dossier de ce type
# $? vaut 1 : erreur
# Le ls retournera cela
# fichier_4
# touch fichier_1 fichier_3 fichier_4
# denis@denis:/tmp/test $ ls
# fichier_1 fichier_3 fichier_4
rm -f fichier_1 fichier_2 fichier_3
# RETOUR : vide
# $? vaut 0 : ok
# Le ls retournera toujours cela
# fichier_4
rm /etc/sudoers
# RETOUR :
# rm: supprimer '/etc/sudoers' qui est protégé en écriture ? y
# rm: impossible de supprimer '/etc/sudoers': Permission non accordée
# $? vaut 1 : erreur
rm -f /etc/sudoers
# RETOUR :
# rm: impossible de supprimer '/etc/sudoers': Permission non accordée
# $? vaut 1 : erreur
touch fichier_1 fichier_2 fichier_3
rm -i fichier_*
# RETOUR :
# rm : supprimer 'fichier_1' du type fichier vide ? n
# rm : supprimer 'fichier_2' du type fichier vide ? n
# rm : supprimer 'fichier_3' du type fichier vide ? n
💣️Les options --interactive (-i, -I) n'ont aucun effet si l'option --force (-f) est présente.
touch fichier_1 fichier_2 fichier_3 fichier_4 && mkdir dossier;
rm -rI
# RETOUR :
# rm : supprimer 5 arguments récursivement ? y
rm: impossible de supprimer 'dossier': est un dossier
rm -rf --no-preserve-root /
🧙♂️️Note : n'ayant pas de VM sous la main pour effectuer cette commande, je vous laisse découvrir son résultat ;-).
📖️️La sécurité sur le root existerait depuis 2006 sur les OS GNU : https://en.wikipedia.org/wiki/Rm_%28Unix%29#Protection_of_the_filesystem_root.
rm --version
rm (GNU coreutils) 8.28
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Paul Rubin, David MacKenzie, Richard M. Stallman,
and Jim Meyering
💣️Ne pas utiliser -v (équivalent à --verbose) pour afficher la version de rm.
Member "coreutils-9.0/ChangeLog" (24 Sep 2021, 328480 Bytes) of package /linux/misc/coreutils-9.0.tar.xz:
1615 2020-11-26 Nishant Nayan <nishant.nayan@oracle.com>
1616
1617 rm: do not skip files upon failure to remove an empty dir
1618 When removing a directory fails for some reason, and that directory
1619 is empty, the rm_fts code gets the return value of the excise call
1620 confused with the return value of its earlier call to prompt,
1621 causing fts_skip_tree to be called again and the next file
1622 that rm would otherwise have deleted to survive.
1623
1624 * src/remove.c (rm_fts): Ensure we only skip a single fts entry,
1625 when processing empty dirs. I.e. only skip the entry
1626 having successfully removed it.
1627 * tests/rm/empty-immutable-skip.sh: New root-only test.
1628 * tests/local.mk: Add it.
1629 * NEWS: Mention the bug fix.
1630 Fixes https://bugs.gnu.org/44883
4310 2018-06-21 Pádraig Brady <P@draigBrady.com>
4311
4312 tests: provide an option to relax the need for gdb
4313 * tests/rm/r-root.sh: gdb provides extra protection,
4314 but is not strictly necessary. So provide an option
4315 for maintainers to relax the requirements.
4316
4317 rm: add --preserve-root=all to protect mounts
4318 * src/remove.c (rm_fts): With the --preserve-root=all extension,
4319 reject command line arguments that are mount points.
4320 * src/remove.h (rm_options): Add preserve_all_root to store config.
4321 * src/mv.c (rm_option_init): Init preserve_all_root to false.
4322 * src/rm.c (main): Init preserve_all_root as per option.
4323 (usage): Describe the new option.
4324 * src/remove.c (rm_fts): Lookup the parent device id,
4325 and reject the cli argument if a separate file system.
4326 * tests/rm/one-file-system.sh: Add a test case.
4327 * NEWS: Mention the new feature.
7692 2016-10-04 Pádraig Brady <P@draigBrady.com>
7693
7694 rm: disallow --n alias for --no-preserve-root
7695 * src/rm.c (main): Ensure the full --no-preserve-root
7696 option is specified, rather than allowing --n etc.
7697 * tests/rm/r-root.sh: Add a test case.
7698 * NEWS: Mention the change in behavior.
7699
7700 Improved by Jim Meyering.
7701 Fixes http://bugs.gnu.org/24604
3,4 GiB [
📖️️Les commandes proviennent du stackoverflow 130802(https://unix.stackexchange.com/a/130802).
journalctl --disk-usage
Journals take up 3.4G on disk.
sudo vim /etc/systemd/journald.conf
[Journal]
#Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitIntervalSec=30s
#RateLimitBurst=10000
#SystemMaxUse=
#SystemKeepFree=
#SystemMaxFileSize=
#SystemMaxFiles=100
#RuntimeMaxUse=
#RuntimeKeepFree=
#RuntimeMaxFileSize=
#RuntimeMaxFiles=100
#MaxRetentionSec=
#MaxFileSec=1month
#ForwardToSyslog=yes
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg
#LineMax=48K
#ReadKMsg=yes
SystemMaxUse=50M
sudo systemctl kill --kill-who=main --signal=SIGUSR2 systemd-journald.service
sudo systemctl restart systemd-journald.service
du -sh /var/log/journal
# 49M /var/log/journal
journalctl --disk-usage
sudo du -sh /var/cache/apt
#AVANT:
#sudo du -sh /var/cache/apt
#490M /var/cache/apt
sudo apt-get clean
#APRES:
#sudo du -sh /var/cache/apt
#364K /var/cache/apt