- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Script help needed (easy one)
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2005 12:37 PM
тАО07-21-2005 12:37 PM
I want to take a list that is in a file and execute a chown on each entry so that the owner is the same....
OK...I didn't even understand that. Let me lay it out like this...
File 1 contains the following entries:
abc
def
I want to execute a chown on each in a way like this...
chown abc abc
Therefore making the owner the same as the name of the file.
However I have a very long list to do...I'm lazy....and scripting is not my strength. Any help is appreciated.
Solved! Go to Solution.
- Tags:
- chown
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2005 12:49 PM
тАО07-21-2005 12:49 PM
Solutiondo
chown $filename:$filename $filename
done < filelist
Thats a simple shell that changes ownership and group.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2005 03:14 PM
тАО07-21-2005 03:14 PM
Re: Script help needed (easy one)
while read line;
do
chown $line $line
done < filename
or
awk '{ print "chown "$0" "$0 }' filename | sh
hth.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2005 03:21 PM
тАО07-21-2005 03:21 PM
Re: Script help needed (easy one)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2005 03:23 PM
тАО07-21-2005 03:23 PM
Re: Script help needed (easy one)
do
chown $i $i
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2005 03:49 PM
тАО07-21-2005 03:49 PM
Re: Script help needed (easy one)
perl -pi -e 's/^(.*)/chown \$1 \$1/'
sh
hth.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-25-2005 04:48 AM
тАО07-25-2005 04:48 AM
Re: Script help needed (easy one)
Here is a one-line awk construct that can be used for your script:
# awk '{system("chown "$1":"$1" "$1)}' File1
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-25-2005 07:46 AM
тАО07-25-2005 07:46 AM
Re: Script help needed (easy one)
cat filename | xargs -i: chmod : :
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-25-2005 07:47 AM
тАО07-25-2005 07:47 AM
Re: Script help needed (easy one)
cat filename.list | xargs -i chown {} {}
You may need to escape the brackets {} depending on what shell you are using.
Things to note:
xargs is one of those small and fast swords to keep at your side. It can do great things at fast speeds in a very small package.
Another example of xargs would be change permissions of files:
cat filelist | xargs chmod 777
Or in another example, use find to pipe directly to xargs and print the cksum of each file:
find . -print | xargs cksum
And of course can be used to destroy things:
find . -print | xargs rm -f
(hehehe, DO NOT ACTUALLY DO THAT unless you want to whack all files in a directory)
Read the man page for xargs for more info.
-- Tom
- Tags:
- xargs