Solved

Problem with find command in linux

Posted on 2014-09-11
10
655 Views
Last Modified: 2014-09-12
I am trying to the root directory and the directories immediately below that directory.
Also I need to exclude some directories such as /proc

Here is my attempt to get this to work  

for i  in `find /   ! -path /proc\*   -maxdepth 1  ` 
do
echo $i
done

If I put -maxdepth 1 first I do not exclude /proc
If I put  ! -path /proc\* first I do not get the maxdepth of just 1

Redhat Linux 5   
0
Comment
Question by:TIMFOX123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 4

Assisted Solution

by:exploitedj
exploitedj earned 125 total points
ID: 40318315
Have you tried instead:

find / -maxdepth 1 ! -wholename "/proc"
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 40318335
How about

shopt -s extglob
for i in `ls -d /!(proc)`
do
  echo $i
done

To exclude e. g. /proc, /tmp and /sys use

ls -d /!(proc|sys|tmp)
0
 

Author Comment

by:TIMFOX123
ID: 40318395
Here is what I am going to try tomorrow

 for J in `find / -maxdepth 1 -mindepth 1  ! -wholename "/proc" ! -wholename "/dev"`
 do
 du -ks $J
 done

I will try to close this then and thank you both very much
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:TIMFOX123
ID: 40318420
Hello Porky

you know I think you are a real brain and you give great answers.

I tried to run this and it did not seem to run correctly.  I just pasted it in to bash as root  

Could you try running it again pls

shopt -s extglob
 for i in `ls -d /!(proc)`
 do
   echo $i
 done
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 40318810
Hi again Foxy,

"It works for me".

Could you please try step by step?

shopt -s extglob
shopt extglob


You should see

extglob    on

Now try

ls -d /!(proc|dev)

You should see a multi column list of your top level directories, with the exceptions of "/proc" and "/dev".

If extended globbing doesn't work for you for some strange reason you can always try

ls -d /* | grep -Ev "/proc|/dev"

By the way, your "find" command (with maxdepth coming first) works just fine for me, too!

wmp
0
 

Author Comment

by:TIMFOX123
ID: 40318917
Hello wmp

you were right and I do not know what I did wrong the first time.  

Thank you for you patience.

you always make me a better admin so double thanks
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40318951
You're always welcome!

Seems you want to run "du -ks" against the selected top level directories? No need for a loop then:

shopt -s extglob
du -ks $(ls -d /!(proc|dev))

will do the trick. You can add a "sort" to bring the biggest directories to the bottom/top of the list.

Bottom:
du -ks $(ls -d /!(proc|dev)) | sort -n

Top:
du -ks $(ls -d /!(proc|dev)) | sort -nr

wmp
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 125 total points
ID: 40319034
No need for ls either
du -ks /!(proc|dev)
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40319064
Yes, I always forget that extglob would work for more things than just "ls"  ...

Thx, ozo!
0
 

Author Closing Comment

by:TIMFOX123
ID: 40320394
Thank you all

great job
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
parallel rsync issues with Ubuntu 1 50
Unix Help with:  mailx -s 17 65
how to write and save a unix script 12 39
phpmyadmin memory error 55 96
In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question