Renommer plusieurs fichiers sous UNIX [Résolu/Fermé]

Signaler
-
Messages postés
40805
Date d'inscription
jeudi 28 août 2003
Statut
Modérateur
Dernière intervention
10 août 2020
-
Bonjour,
J'aimerais renommer des fichiers sous UNIX (AIX) j'ai des fichiers TOTO_30025_01.zip et je veux les renommer en TOTO_30165_01.zip . J'ai essayé certaines solutions postées ici, mais j'ai eu les erreures suivantes:

pour la script:
#!/bin/bash
for file in *_30025_*; do
mv $file ${file/30025/30165}
done

${file/30025/30165}: 0403-011 The specified substitution is not valid for this command.
sachant que je ne pas le repertoire bin/bash

pour le script:
for i in *; do mv "$i" ${i/30025/30165}; done
${i/30025/30165}: 0403-011 The specified substitution is not valid for this command.

pour le script:
for i in $(ls TOTO_*30025*);do mv -v $i ${i%%_*}_30165_${i##*_};done
Usage: mv [-I] [-i | -f] [-E{force|ignore|warn}] [--] src target
or: mv [-I] [-i | -f] [-E{force|ignore|warn}] [--] src1 ... srcN directory

La fonction rename n'existe pas.
# man rename
Manual entry for rename not found or not installed.

Je pense que c'est un problème avec ma fonction mv:

# man mv

Commands Reference, Volume 3, i - m

mv Command

Purpose

Moves files.

Syntax

To Move and Rename a File

mv [ -E{force|ignore|warn} ] [ -i | -f ] [ -I ] SourceFile ... TargetFile

To Move and Rename a Directory

mv -E{force|ignore|warn} ] [ -i | -f ] [ -I ] SourceDirectory ... TargetDirectory

To Move Files or Directories to a Directory Maintaining Original File Names

mv -E{force|ignore|warn} ] [ -i | -f ] [ -I ] SourceFile/SourceDirectory TargetDirectory

Description
Attention: The mv command can overwrite many existing files unless you specify the -i flag. The -i flag prompts you to confirm
before it overwrites a file. If both the -f and -i flags are specified in combination, the last flag specified takes precedence.

The mv command moves files and directories from one directory to another or renames a file or directory. If you move a file or
directory to a new directory, it retains the base file name. When you move a file, all links to other files remain intact, except
when you move it to a different file system. When you move a directory into an existing directory, the directory and its contents
are added under the existing directory.

When you use the mv command to rename a file or directory, the TargetDirectory parameter can specify either a new file name or a new
directory path name.

If moving the file would overwrite an existing file that does not have write-permission set and if standard input is a workstation,
the mv command displays the file-permission code and reads a line from standard input. If that line begins with a y or the locale's
equivalent of a y, the mv command moves the file. If the response is anything other than a y, the mv command does nothing to that
file and continues with the next specified file. The file-permission code displayed may not fully represent the access permission if
the TargetFile is associated with an ACL. When the parent directory of the SourceFile is writable and has the sticky bit set, one or
more of the following conditions are true:
* The user must own the file.
* The user must own the directory
* The user must be a privileged user.
* The file must be writable by the user.

This warning message and prompt for input can be overridden by using the -f option.

You can use the mv command to move files within the same file system or between file systems. Whether you are working in one file
system or across file systems, the mv command copies the file to the target and deletes the original file. The mv command preserves
in the new file the time of the most recent data modification, the time of the most recent access, the user ID, the group ID, the
file mode, the extended attributes, and ACLs of the original file. For symbolic links, the mv command preserves only the owner and
group of the link itself.

If it is unable to preserve the owner and group ID, the mv command clears S_ISUID and S_ISGID bits in the target. The mv command
prints a diagnostic message to stderr if it is unable to clear these bits, though the exit code is not affected.

The mv command modifies either the source file or the destination path if the command is prematurely terminated. Note: The mv
command supports the -- (dash, dash) parameter as a delimiter that indicates the end of the flags.

Flags

Attention: The mv command can overwrite many existing files unless you specify the -i flag. The -i flag prompts you to confirm
before it overwrites a file. If both the -f and -i flags are specified in combination, the last flag specified takes
precedence.

-E
The -E option requires one of the following arguments. If you omit the -E option, warn is the default behavior.
force
Fails the mv operation on a file if the fixed extent size or space reservation of the file cannot be preserved.
ignore
Ignores any errors in preserving extent attributes.
warn
Issues a warning if the space reservation or the fixed extent size of the file cannot be preserved.
-f
Does not prompt you before overwriting an existing file.
-i
Prompts you before moving a file or directory to an existing path name by displaying the name of the file followed by a
question mark. If you answer with a line starting with y or the locale's equivalent of a y, the move continues. Any other reply
prevents the move from occurring.
-I
Suppresses the warning message during ACL conversion.

Examples
1 To rename a file, enter:

mv appendix apndx.a

This command renames appendix to apndx.a. If a file named apndx.a already exists, its old contents are replaced with those of
appendix.
2 To move a directory, enter:

mv book manual

This command moves all files and directories under book to the directory named manual, if manual exists. Otherwise, the
directory book is renamed manual.
3 To move a file to another directory and give it a new name, enter:

mv intro manual/chap1

This command moves intro to manual/chap1. The name intro is removed from the current directory, and the same file appears as
chap1 in the directory manual.
4 To move a file to another directory, keeping the same name, enter:

mv chap3 manual

This command moves chap3 to manual/chap3

Note: Examples 1 and 3 name two files, example 2 names two existing directories, and example 4 names a file and a directory.

5 To move several files into another directory, enter:

mv chap4 jim/chap5 /home/manual

This command moves the chap4 file to the /home/manual/chap4 file directory and the jim/chap5 file to the /home/manual/chap5
file.
6 To use the mv command with pattern-matching characters, enter:

mv manual/* .

This command moves all files in the manual directory into the current directory . (period), retaining the names they had in
manual. This move also empties manual. You must type a space between the asterisk and the period.

Note: Pattern-matching characters expand names of existing files only. For example, the command mv intro man*/chap1 does not
work if the file manual/chap1 does not exist.

Exit Status

0
All input files were moved successfully.
>0
An error occurred.

Files

/usr/bin/mv
Contains the mv command.

Related Information

The chmod command, ln command, rm command.

The rename subroutine.

Files Overview in the AIX 5L Version 5.3 System User's Guide: Operating System and Devices.

Directory Overview in AIX 5L Version 5.3 System User's Guide: Operating System and Devices.

Input and Output Redirection Overview in AIX 5L Version 5.3 System User's Guide: Operating System and Devices.

Merci pour votre aide
Amine

3 réponses

1
Merci

Quelques mots de remerciements seront grandement appréciés. Ajouter un commentaire

CCM 65492 internautes nous ont dit merci ce mois-ci

Messages postés
40805
Date d'inscription
jeudi 28 août 2003
Statut
Modérateur
Dernière intervention
10 août 2020
4 836
Salut,

T'as essayé comme ça :
 ssh$ ls -1 TO*
TOTO_30025_01.zip
TOTO_30025_02.zip
TOTO_30025_03.zip
TOTO_30025_04.zip
TOTO_30025_05.zip

 ssh$ for i in *.zip;do mv ${i} $(echo "${i}" |sed 's/30025/30165/');done

 ssh$ ls -1 TO*
TOTO_30165_01.zip
TOTO_30165_02.zip
TOTO_30165_03.zip
TOTO_30165_04.zip
TOTO_30165_05.zip

 ssh$
;-))
Messages postés
21331
Date d'inscription
jeudi 4 novembre 2004
Statut
Modérateur, Contributeur sécurité
Dernière intervention
30 octobre 2019
3 522
Salut,

Affiche le résultat de
ls TO*

Messages postés
40805
Date d'inscription
jeudi 28 août 2003
Statut
Modérateur
Dernière intervention
10 août 2020
4 836 >
Messages postés
21331
Date d'inscription
jeudi 4 novembre 2004
Statut
Modérateur, Contributeur sécurité
Dernière intervention
30 octobre 2019

Salut,

Tu y tiens vraiment ?
Messages postés
21331
Date d'inscription
jeudi 4 novembre 2004
Statut
Modérateur, Contributeur sécurité
Dernière intervention
30 octobre 2019
3 522 >
Messages postés
40805
Date d'inscription
jeudi 28 août 2003
Statut
Modérateur
Dernière intervention
10 août 2020

Re,

Oui ;-)
Messages postés
37
Date d'inscription
mercredi 8 juillet 2009
Statut
Membre
Dernière intervention
21 novembre 2011
3
Magnifique!!

Merci jipicy
Messages postés
40805
Date d'inscription
jeudi 28 août 2003
Statut
Modérateur
Dernière intervention
10 août 2020
4 836 >
Messages postés
37
Date d'inscription
mercredi 8 juillet 2009
Statut
Membre
Dernière intervention
21 novembre 2011

De rien ;-))
Messages postés
40805
Date d'inscription
jeudi 28 août 2003
Statut
Modérateur
Dernière intervention
10 août 2020
4 836
 ssh$ ls  TO*
TOTO_30165_01.zip  TOTO_30165_02.zip  TOTO_30165_03.zip  TOTO_30165_04.zip  TOTO_30165_05.zip
Messages postés
21331
Date d'inscription
jeudi 4 novembre 2004
Statut
Modérateur, Contributeur sécurité
Dernière intervention
30 octobre 2019
3 522
Re,

Ben, en fait je me suis demandé (vu que je ne peux pas testé) si echo n'ajoute un \n à la fin du nom du fichier.
Messages postés
40805
Date d'inscription
jeudi 28 août 2003
Statut
Modérateur
Dernière intervention
10 août 2020
4 836 >
Messages postés
21331
Date d'inscription
jeudi 4 novembre 2004
Statut
Modérateur, Contributeur sécurité
Dernière intervention
30 octobre 2019

Autant que le font les commandes "mv" ou "rename", mais ce n'est pas gênant, c'est sur l'affichage que ça joue, pas sur le traitement...