Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with find command in linux

Posted on 2014-09-11
10
Medium Priority
?
677 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 500 total points
ID: 40318315
Have you tried instead:

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

Accepted Solution

by:
woolmilkporc earned 1000 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
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!

 

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 1000 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 500 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

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!

Question has a verified solution.

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

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

722 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