Sponsored Content
Full Discussion: Listing files with full path
Top Forums UNIX for Dummies Questions & Answers Listing files with full path Post 302325377 by praving5 on Monday 15th of June 2009 02:56:26 AM
Old 06-15-2009
Hi Guys,
I did something good today:

My situation:
-----------

I had 2 servers say server A and server B. Server A had got millions of files and directories. I had to keep the same ownership and group ownership in server B as in Server A. For this I did below:

1. Get to know the file ownerships in server A and put it in a file

find . -type f | sed "s#^.#$(pwd)#" | xargs ls -l | tr -s " " " " | cut -f3,4,9 -d\ > perm.conf

find . -type d | sed "s#^.#$(pwd)#" | xargs ls -ld | tr -s " " " " | cut -f3,4,9 -d\ >> perm.conf

2. copy the perm.conf on the server B under the same hierachy as in server A.

3. Then I wrote a script:

#!/bin/sh

k=`wc -l perm.conf | cut -f1 -d\ `
i=1
RECORD=""
OWNER=""
GROUP=""
FILE=""
while [ $k -ne $i ]
do
RECORD=`head -$i perm.conf | tail -1`
OWNER=`echo $RECORD | cut -f1 -d\ `
GROUP=`echo $RECORD | cut -f2 -d\ `
FILE=`echo $RECORD | cut -f3 -d\ `
chown $OWNER:$GROUP $FILE 2>> logfile
i=`expr $i + 1`
done

and I was done...

Hope this help someone...

Thanks and regards,
Pravin Goyal
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

list all files with full path of the file

How can i list every single file on a sun solaris server running 2.8 starting from '/' with the full path included in it? example. / ... ... ... /etc/inetd.conf /etc/passwd /etc/shadow ... ... ... /var/adm/messages /var/adm/messages.0 /var/adm/messages.1 ... ... ...... (4 Replies)
Discussion started by: Sowser
4 Replies

2. Shell Programming and Scripting

List files with full path

Hi all, How to save file full name to a file. I tried the following but don't know to include path name. $ ls -l | awk '{print $9}' > outputfile.dat $ cat outputfile.dat fifth.txt first.txt fourth.txt second.txt third.txt My wanted result is ie: ... (3 Replies)
Discussion started by: mr_bold
3 Replies

3. Red Hat

ls command to give full path to files

How can i perform a ls or other command to list the full paths of files from a ls? Looked through the man page for ls, no luck $ cd /tmp/ $ ls -l total 6 drwx------ 2 root root 4096 Nov 7 2008 keyring-7b5rMv drwx------ 2 bcr bcr 4096 Dec 7 2007 keyring-cGhir8 $ I'd be looking for... (1 Reply)
Discussion started by: brendan76
1 Replies

4. Shell Programming and Scripting

Help with listing given files in a given directory path

hello every one, i'm a novice in the field of Linux, so please help me out with this problem. a text file with the following syntax is given: file1 file2 file3 file4 file5 a script is to be written to list all d file names and tar the files with the filename... (3 Replies)
Discussion started by: Amruthesh C
3 Replies

5. Windows & DOS: Issues & Discussions

DOS Dir - listing of full path and timestamp

Hi, (Apologies, I'm sure I'm not the first person to raise this question but so far in my searches haven't found a good answer). I would like to output a listing per line of filename (including full path) and 'last updated' timestamp. e.g: Z:\dir1\file1.txt 01/02/2010 10:43... (5 Replies)
Discussion started by: GM_AIX
5 Replies

6. Shell Programming and Scripting

How to extract strings from full path when full path is not fixed

/Path/snowbird9/nrfCompMgrRave1230100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird6/nrfCompMgrRave1220100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird14/nrfCompMgrRave920100920.log.gz:09/20/2010 06:14:51 ERROR Error Message.... (0 Replies)
Discussion started by: Shirisha
0 Replies

7. Shell Programming and Scripting

listing the files without cd to the path

Hi all, I want to check the list of all directories and links in a particular directory and here, i have the list of the directories/links which i need to print on screen. I used the below command to check the dir/links, cd path1 ; ls -ltd `cat dir_links_list` But here, i don't want to... (3 Replies)
Discussion started by: raghu.iv85
3 Replies

8. Shell Programming and Scripting

How to list all Subdirectories and files with its full path in a parent directory?

How to list all Subdirectories and files with its full path in a parent directory? (1 Reply)
Discussion started by: johnveslin
1 Replies

9. Shell Programming and Scripting

Find and replace the path value in files, pattern is not full known.

Hi, I need to do find and replace, but the pattern is not full known. for example, my file has /proj/app-d1/sun or /data/site-d1/conf here app-d1 and site-d1 is not constant. It may be different in different files. common part is /proj/xx/sun and /data/xxx/conf i want to find where ever... (6 Replies)
Discussion started by: rbalaj16
6 Replies

10. UNIX for Beginners Questions & Answers

30 days old files with full path

my requirement is 30 days old files along with size and pull path of the file (file should be listed in descending by size). output: 12345 /app/testing/file1 12341 /app/testing/file2 (5 Replies)
Discussion started by: Rajesh123
5 Replies
CHOWN(1)                                                           User Commands                                                          CHOWN(1)

NAME
chown - change file owner and group SYNOPSIS
chown [OPTION]... [OWNER][:[GROUP]] FILE... chown [OPTION]... --reference=RFILE FILE... DESCRIPTION
This manual page documents the GNU version of chown. chown changes the user and/or group ownership of each given file. If only an owner (a user name or numeric user ID) is given, that user is made the owner of each given file, and the files' group is not changed. If the owner is followed by a colon and a group name (or numeric group ID), with no spaces between them, the group ownership of the files is changed as well. If a colon but no group name follows the user name, that user is made the owner of the files and the group of the files is changed to that user's login group. If the colon and group are given, but the owner is omitted, only the group of the files is changed; in this case, chown performs the same function as chgrp. If only a colon is given, or if the entire operand is empty, neither the owner nor the group is changed. OPTIONS
Change the owner and/or group of each FILE to OWNER and/or GROUP. With --reference, change the owner and group of each FILE to those of RFILE. -c, --changes like verbose but report only when a change is made -f, --silent, --quiet suppress most error messages -v, --verbose output a diagnostic for every file processed --dereference affect the referent of each symbolic link (this is the default), rather than the symbolic link itself -h, --no-dereference affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink) --from=CURRENT_OWNER:CURRENT_GROUP change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omit- ted, in which case a match is not required for the omitted attribute --no-preserve-root do not treat '/' specially (the default) --preserve-root fail to operate recursively on '/' --reference=RFILE use RFILE's owner and group rather than specifying OWNER:GROUP values -R, --recursive operate on files and directories recursively The following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one takes effect. -H if a command line argument is a symbolic link to a directory, traverse it -L traverse every symbolic link to a directory encountered -P do not traverse any symbolic links (default) --help display this help and exit --version output version information and exit Owner is unchanged if missing. Group is unchanged if missing, but changed to login group if implied by a ':' following a symbolic OWNER. OWNER and GROUP may be numeric as well as symbolic. EXAMPLES
chown root /u Change the owner of /u to "root". chown root:staff /u Likewise, but also change its group to "staff". chown -hR root /u Change the owner of /u and subfiles to "root". AUTHOR
Written by David MacKenzie and Jim Meyering. REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report chown translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
chown(2) Full documentation at: <http://www.gnu.org/software/coreutils/chown> or available locally via: info '(coreutils) chown invocation' GNU coreutils 8.28 January 2018 CHOWN(1)
All times are GMT -4. The time now is 06:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy