Linux / UNIX Tech Support Forum
This is a discussion on Shell script to change folder directory owner after restore within the Shell scripting forums, part of the Development/Scripting category; Hello, Recently I had to backup my data because the hard drives were failing. When I restored the accounts, all ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hello,
Recently I had to backup my data because the hard drives were failing. When I restored the accounts, all folders (users) in /home had the same owner (a3u3). Here's an example: Quote:
Can anyone help me a script which will change the ownership of each directory? This is how it's supposed to look like: Quote:
I guess this should be easy to make for someone who knows scripting....Can anyone help me please? I have over 1000 accounts and doing this manually will take ages. The script should execute chown -R user.group directory... Thanks, Marin |
| Sponsored Links | ||
|
|
|
||||
|
Try
Code:
#!/bin/bash
HOMED="/home"
DIRS=$(ls -l $HOMED | grep ^d | awk '{ print $8}')
for d in $DIRS
do
echo "chown -R $d.$d $HOMED/$d"
done
Code:
echo "chown -R $d.$d $HOMED/$d" Code:
chown -R $d.$d $HOMED/$d
__________________
Vivek Gite Linux Evangelist |
|
|||
|
Thanks for the quick reply! This is what I get:
root@voyager [~]# ./home chown -R 08:23.08:23 /home/08:23 chown -R 08:23.08:23 /home/08:23 chown -R 08:23.08:23 /home/08:23 chown -R 08:23.08:23 /home/08:23 chown -R 08:23.08:23 /home/08:23 chown -R 08:24.08:24 /home/08:24 chown -R 08:34.08:34 /home/08:34 chown -R 08:24.08:24 /home/08:24 chown -R 08:34.08:34 /home/08:34 chown -R 08:24.08:24 /home/08:24 chown -R 08:24.08:24 /home/08:24 Is it normal? |
|
||||
|
Is this a Linux box? Just count output using ls -l and select correct col $8 is for dir. Try $9 and run script again
__________________
Vivek Gite Linux Evangelist |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell Delete Directory | chimu | Slackware | 2 | 31-05-2008 03:36 PM |
| A script for Removing all the files inside a folder and its sub folder | vivekv | Shell scripting | 1 | 25-10-2007 01:44 PM |
| i need a script to delete one folder with files on my ftp | silver_ch | Shell scripting | 1 | 27-03-2007 10:15 AM |
| How to change the login shell for Linux user | chimu | Getting started tutorials | 0 | 26-01-2007 07:20 PM |
| error shell script no such file or directory /bin/sh | Linux software | 1 | 08-01-2006 08:34 PM | |