Solved

Problem with find command in linux

Posted on 2014-09-11
10
632 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
10 Comments
 
LVL 4

Assisted Solution

by:exploitedj
exploitedj earned 125 total points
Comment Utility
Have you tried instead:

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

Accepted Solution

by:
woolmilkporc earned 250 total points
Comment Utility
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
Comment Utility
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
 

Author Comment

by:TIMFOX123
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:TIMFOX123
Comment Utility
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
Comment Utility
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
Comment Utility
No need for ls either
du -ks /!(proc|dev)
0
 
LVL 68

Expert Comment

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

Thx, ozo!
0
 

Author Closing Comment

by:TIMFOX123
Comment Utility
Thank you all

great job
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now