LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-22-2011, 05:46 AM   #1
mohanan.sandeep
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Rep: Reputation: 0
Unhappy Find command for no login user files


Hi there,

How to find files owned by a user who does not have an interactive shell on the system and copy them to a different location. For Eg : Files owned by UID : 86 in /sbin/nologin needs to be located.
 
Old 02-22-2011, 08:43 AM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Code:
find /sbin/nologin -type f -uid 86 -exec cp {} /destination/directory \;
In the example /destination/directory is the path to the location that you want to create the copies.

The example will not copy directories because I added the -type f parameter. You could change that if you want directories to be copied. Since we are specifying individual files it seemed inappropriate to me to copy a directory.

More information is available in the manual page for the find utility.
Code:
man find

Last edited by stress_junkie; 02-22-2011 at 08:48 AM.
 
Old 02-22-2011, 10:31 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
If the ultimate goal is to write some sort of maintenance script (like a cron job), you can combine this with stress_junkie's command:

(just an example)
Code:
#!/bin/sh

SOURCE=/source/directory
DESTINATION=/destination/directory

awk '{ FS = ":" } { print $3, $7 }' /etc/passwd | while read userid loginshell ; do
  echo "userid: ${userid} -- ${loginshell}"
  if [ "${loginshell}" = "/bin/false" ] ; then
    echo "find ${SOURCE} -type f -uid ${userid} -exec cp {} ${DESTINATION} \;"
#    find ${SOURCE} -type f -uid ${userid} -exec cp {} ${DESTINATION} \;
  fi
done
Now, before anybody runs that, obviously it needs to be customized (e.g. SOURCE and DESTINATION variables) and comparing ${loginshell} to "/bin/false" may not be the right test for your setup. Uncomment the find command only after you are satisfied that everything else works as expected.
 
Old 02-23-2011, 08:51 AM   #4
mohanan.sandeep
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Unhappy That worked parcially

Thanks for the update guys[Stress_junkie and Dark_helmet] But i am not able to find the files in the destination directory to which i copied.
 
Old 02-23-2011, 04:25 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913
Note: if the destination directory didn't previously exist you are
creating (and overwriting) the same file w/ each copy process.



Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find the user not login elainelaw Linux - Newbie 4 06-04-2010 12:14 AM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 06:55 PM
where I can find the user login record vaaub Linux - Newbie 4 03-19-2009 07:35 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 05:45 PM
How to find files and copy the found files to the floppy in one command justmehere Linux - Newbie 11 05-05-2008 12:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration