LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-26-2011, 11:40 PM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
check file existence in your directory


In the linux server, there shoud have a file which called abc.txt under each user directory , if I want to check if all user direcory have this file , what can i do ?

Thanks.
 
Old 07-26-2011, 11:41 PM   #2
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: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
find /home/* -name abc.txt
 
Old 07-27-2011, 12:59 AM   #3
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Tinkster View Post
find /home/* -name abc.txt

Thx reply,

it is ok , but if I want to know which user do not have the file , what can i do ?

Thanks.
 
Old 07-27-2011, 01:25 AM   #4
digsecurity
Member
 
Registered: Apr 2010
Posts: 54

Rep: Reputation: 18
find /home/* -name abc.txt -user username

Try "man find" for the detail.
 
Old 07-27-2011, 02:18 AM   #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: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by ust View Post
Thx reply,

it is ok , but if I want to know which user do not have the file , what can i do ?

Thanks.
for i in /home/*; do ls $i/abc.txt ; done

Bit ugly, but does the job
 
Old 07-27-2011, 02:29 AM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,614

Rep: Reputation: 450Reputation: 450Reputation: 450Reputation: 450Reputation: 450
Code:
for FILE in /home/*; do if [[ ! -f "${FILE}/abc.txt" ]];then echo "user '${FILE////}' does not not have file abc.txt" ;fi; done
 
Old 07-27-2011, 05:12 AM   #7
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by crts View Post
Code:
for FILE in /home/*; do if [[ ! -f "${FILE}/abc.txt" ]];then echo "user '${FILE////}' does not not have file abc.txt" ;fi; done
it works . thx much.
 
  


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
[SOLVED] Need bash script to check existence of images within an HTML document thunor Programming 7 10-26-2010 10:20 AM
[bash] Remote file existence check danket Linux - Newbie 5 01-14-2008 04:39 PM
[Question] Check File existence hbinded Programming 3 12-19-2006 05:15 PM
check for file existence ignoring case sensitive rammohhan2000 Programming 3 06-13-2006 03:12 PM
check for existence of file j-me Linux - Newbie 5 07-29-2003 07:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:28 PM.

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