FIND, GREP, PATH, and UMOUNT questions (should be easy for you)

FIND, GREP, PATH, and UMOUNT questions (should be easy for you)

Post by Green Manalish » Sat, 12 Dec 1998 04:00:00



Ok, a few questions for y'all:

1. I want to be able to make an alias that will just output the
subdirectories of a variable directory.  Similar to DOS's "dir /ad" but
I want to input the directory (command line option, $1).  I know the
find command works: " find <path> -type d -maxdepth 1 ".  Why doesn't
"find /$1 ..... work for the same argument if the executable is names
'ld ' ---> " ld usr " where <path> before was /usr?

2. I want to remove an element from my PATH environmental variable.
What file is it stored in?

3. Do I have this right.  Grep is only good if you specify ONE directory
to search for strings in a file or files?  How do I search for strings
across multiple directories?

4. My book specifies that umount applies to the device and not the mount
point.  Well my system works just the opposite.  That is, I type: "
umount /mnt/dos " where dos is a mount point.

Green

 
 
 

FIND, GREP, PATH, and UMOUNT questions (should be easy for you)

Post by John Thomps » Sat, 12 Dec 1998 04:00:00



Quote:>4. My book specifies that umount applies to the device and not the mount
>point.  Well my system works just the opposite.  That is, I type: "
>umount /mnt/dos " where dos is a mount point.

I think it will work with the mount point if the partition in
question has an entry in /etc/fstab.  If it doesn't you need to
specify the device.



 
 
 

FIND, GREP, PATH, and UMOUNT questions (should be easy for you)

Post by pe.. » Sat, 12 Dec 1998 04:00:00



> Ok, a few questions for y'all:

> 1. I want to be able to make an alias that will just output the
> subdirectories of a variable directory.  Similar to DOS's "dir /ad" but
> I want to input the directory (command line option, $1).  I know the
> find command works: " find <path> -type d -maxdepth 1 ".  Why doesn't
> "find /$1 ..... work for the same argument if the executable is names
> 'ld ' ---> " ld usr " where <path> before was /usr?

I' completely confused by this one! Maybe you should try `ls
/the/path/to/*/something or similar' (Those jokers are just great!)

Quote:> 2. I want to remove an element from my PATH environmental variable.
> What file is it stored in?

bash, sh & co: /etc/profile; csh: /etc/csh.cshrc -- but that's the global
default. To remove it from your path only, you'd have to do something like:
export PATH=`echo $PATH | sed -e s~:path/you/want/removed:~:~g`
Note: The directory has to be between other directories in the $PATH,
otherwise the expression won't match.
export PATH=`echo $PATH | sed -e s~:PYWR:~:~; s~^PYWR:~~; s~:PYWR$~~`
should fix this.

Quote:> 3. Do I have this right.  Grep is only good if you specify ONE directory
> to search for strings in a file or files?  How do I search for strings
> across multiple directories?

find <path> -type f -exec grep -l <string> {} \; -exec grep <string> {} \;

This isn't at all a good sollution: You can hardly see the filenames
(written by the first grep), grep is run twice for every file in the
tree and the searchstring has to be entered twice.

for i in `find <path> -type d` ; do grep -i <string> $i/* ; done

might be better, but it will produce a lot of error messages (`No such file
or directory' and `Is a directory')

for i in `find <path> -type d` ; do for j in $i/* ; do test -f $j && grep -i
<string> $j ; done ; done

(all in one line) fixes the error messages (a simple 2>/dev/null would have
worked also) but then you don't have filenames.

Quote:> 4. My book specifies that umount applies to the device and not the mount
> point.  Well my system works just the opposite.  That is, I type: "
> umount /mnt/dos " where dos is a mount point.

It should work both ways, i.e. whether you give umount the special file or
the mount point should not matter.

   HIH,
   Peter
--
   ---------------------------------------------------------------------

   Throughout  this  HOWTO, a  manual  entry  is simply referred to as a
   man page, regardless of actual length and without  sexist  intention.
                                              [The Linux Man-Page-Howto]

 
 
 

FIND, GREP, PATH, and UMOUNT questions (should be easy for you)

Post by Gary Johns » Wed, 16 Dec 1998 04:00:00



> 1. I want to be able to make an alias that will just output the
> subdirectories of a variable directory.  Similar to DOS's "dir /ad" but
> I want to input the directory (command line option, $1).  I know the
> find command works: " find <path> -type d -maxdepth 1 ".  Why doesn't
> "find /$1 ..... work for the same argument if the executable is names
> 'ld ' ---> " ld usr " where <path> before was /usr?

There is already an 'ld' command in /usr/bin/ld, so the problem might be
that /usr/bin is in your PATH ahead of wherever you put your 'ld'
command.

Quote:> 2. I want to remove an element from my PATH environmental variable.
> What file is it stored in?

It is usually defined first in /etc/profile.

Quote:> 3. Do I have this right.  Grep is only good if you specify ONE directory
> to search for strings in a file or files?  How do I search for strings
> across multiple directories?

Use 'find', 'xargs' and 'grep' together, like this:

    find <path> -type f -print | xargs grep <string>

You could also use 'find's -exec argument for this, but xargs is much
faster.

If you just want to search in a list of directories, rather than
traverse a directory tree as 'find' would, you could use something like
this:

    for dir in <dir1> <dir2> <dir3>
    do
        grep <string> $dir/*
    done

Gary

 
 
 

1. neb question, too easy Find File question...

I am a neb to linux.
How do I search for a utility using FIND?

I used the FIND command on the root looking for a file named "ntsysv".
The search zoomed thorugh my root folder and returned "no such file or
dir".

Then I tried to install this utility from my install disk. I used the
rpm -Uvh command to install the utility. However, Bash informed me the
utility is already loaded. So where is it? Why does the find command
not find the utility?

NOTE: I tried the find command using both several criteria including
the same file name as the one i was attempting to load
"ntsysv-1.3.5-3.i356.rpm" just to be sure. Still no good.

-nb

2. limiting user processes

3. Easy Question (grep and sed)

4. Unix Job Opportunity

5. Stupid $PATH question that I am ashamed to ask, but having no pride, I proceed

6. locate exact string?

7. Can't Alter My Path, Can't Find My Path

8. euid bug?

9. Commands to Find Common Base Path of 2 Given Paths?

10. easy easy easy one

11. Easy question on find (hopefully)

12. grep + find: how to find files which have certain strings

13. grep question New to grep