Thanks Ted (and others) I tried using your script and it worked perfectly. If I may impose on you further, how can I make this script work recursively so that it functions on any subdirectory, while ensuring that it does not enter directories above the one that it is started in? This is not something that I need urgently (or perhaps may never need) so don't lose any sleep over it. Thanks again. Eddie On Monday 26 November 2001 10:32 am, Ted Harding wrote:
On 26-Nov-01 Eddie Howson wrote:
Can some shell script guru help me with creating a scipt that takes the owners of a file and renames that file prefixing it with the owners name and an underscore? For example if the file work.txt is owned by tommy, the file is renamed tommy_work.txt. The directory holds a number of files owned by different users.
#! /bin/bash ls -l | awk ' /^total/{next} {command=sprintf("mv %s %s_%s",$9,$3,$9); system(command)}'
Hope this helps! Ted.
PS As it stands, you don't want to run this too often on the same directory, e.g. to update it when new files come in. Otherwise you'll end up with a lot of files named
tommy_tommy_tommy_tommy_tommy_tommy_...
The above script could be adapted to recognise filenames ($9) beginning with "user_" ($3_) and ignore them, if that would be useful.
E.g. you could insert the line
(index($9,$3 "_")==1){next}
above the line which composes the command.
-------------------------------------------------------------------- E-Mail: (Ted Harding)
Fax-to-email: +44 (0)870 167 1972 Date: 26-Nov-01 Time: 10:32:55 ------------------------------ XFMail ------------------------------