Typo got in the code after I tested. NEWNAME="./NEWNAME" should be NEWNAME="./$NEWNAME" ======================================================================= #!/bin/bash # # This script simply renames files or directories to <name>-<date>[<num>] # # Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany. # # Contributor Bernard Lang # # please send bugfixes or comments to http://www.suse.de/feedback. # # # usage - tell user to use program # # Trick : put an inexistant file name as first argument if you are worried # about the possibility of files called -h or --help # usage() { echo usage: "$0" file\|dir [file\|dir ...] } if [ $# -eq 0 ] ; then usage exit fi if [ $1 = -h -o $1 = --help ] ; then echo 'Renames file or directory <name> given in argument list to <name>-<date>[<num>]' echo 'adding when necessary a suffix number <num> to avoid already used names.' exit fi DATESTRING=`date +"%Y%m%d"` for i in "$@" ; do i=${i%%/} if [ -e "$i" ] ; then NEWNAME=$i-$DATESTRING NUMBER=0 while [ -e "$NEWNAME" ] ; do NEWNAME=$i-$DATESTRING-$NUMBER let NUMBER=$NUMBER+1 done echo moving "$i" to "$NEWNAME" if [ `expr substr "$i" 1 1` = - ] ; then i="./$i" NEWNAME="./NEWNAME" fi mv "$i" "$NEWNAME" else echo "$i" does not exist. fi done ======================================================================= * Bernard Lang <Bernard.Lang@datcha.net>, le 23-02-20, a écrit:
This command should be improved or junked.
I decided to do the work, and got to correct a bug while doing it.
But where do I send that.
Code checkers are welcome.
Bernard
========================================================== #!/bin/bash
# # This script simply renames files or directories to <name>-<date>[<num>] # # Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany. # # Contributor Bernard Lang # # please send bugfixes or comments to http://www.suse.de/feedback. # ^^^ the above line seems obsolete # # # usage - tell user to use program # # Trick : put a nonexistant file name as first argument if you are worried # about the possibility of files called -h or --help #
usage() { echo usage: "$0" file\|dir [file\|dir ...] }
if [ $# -eq 0 ] ; then usage exit fi
if [ $1 = -h -o $1 = --help ] ; then echo 'Renames file or directory <name> given in argument list to <name>-<date>[<num>]' echo 'adding when necessary a suffix number <num> to avoid already used names.' exit fi
DATESTRING=`date +"%Y%m%d"`
for i in "$@" ; do i=${i%%/} if [ -e "$i" ] ; then NEWNAME=$i-$DATESTRING NUMBER=0 while [ -e "$NEWNAME" ] ; do NEWNAME=$i-$DATESTRING-$NUMBER let NUMBER=$NUMBER+1 done echo moving "$i" to "$NEWNAME" if [ `expr substr "$i" 1 1` = - ] ; then i="./$i" NEWNAME="./$NEWNAME" fi mv "$i" "$NEWNAME" else echo "$i" does not exist. fi done
==========================================================
* Bernard Lang <Bernard.Lang@datcha.net>, le 23-02-20, a écrit:
I agree
I had never heard of it ... But it does exist on my computer.
I guessed what it should do and tested in a directory created for the purpose.
A waste of time ... because the job was just half done by the author. Just having a decent --help is not hard.
This command should be improved or junked.
Bernard
* Carlos E. R. <robin.listas@telefonica.net>, le 23-02-20, a écrit:
On 22/02/2020 15.13, Luca Beltrame wrote:
Il giorno Sat, 22 Feb 2020 00:54:01 +0100 Knurpht-openSUSE <> ha scritto:
cp /etc/nsswitch.conf /etc/nsswitch,.conf.`date +%F`
Or just "old /etc/nsswitch.conf" ("old" is part of aaa_base, which means installed in almost all configurations).
cer@Telcontar:~> man old No manual entry for old cer@Telcontar:~> cer@Telcontar:~> old usage: /usr/bin/old file|dir [file|dir ...] cer@Telcontar:~> cer@Telcontar:~> old --help --help does not exist. cer@Telcontar:~>
No idea what it does...
-- Cheers / Saludos,
Carlos E. R. (from 15.1 x86_64 at Telcontar)
--
Bernard.Lang@datcha.net ,_ /\o \o/ mobile +33 6 6206 1693 http://www.datcha.net/ ^^^^^^^^^^^^^^^^^ fixe +33 1 3056 1693
-- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
--
Bernard.Lang@datcha.net ,_ /\o \o/ mobile +33 6 6206 1693 http://www.datcha.net/ ^^^^^^^^^^^^^^^^^ fixe +33 1 3056 1693
-- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
-- Bernard.Lang@datcha.net ,_ /\o \o/ mobile +33 6 6206 1693 http://www.datcha.net/ ^^^^^^^^^^^^^^^^^ fixe +33 1 3056 1693 -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org