Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 02-22-2011, 05:46 AM   #1
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
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
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.
man find

Last edited by stress_junkie; 02-22-2011 at 08:48 AM.
Old 02-22-2011, 10:31 AM   #3
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)


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} \;
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
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
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.



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 > Forums > Linux Forums > Linux - Software

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

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