Find the answer to your Linux question:
Results 1 to 4 of 4
Hi Friends i usually do this task (i) I usually make multiple dir using -p option ex: mkdir -p dicttest/audrep/tdriver/test Now after creating this dir's i stay in current dir ...
  1. #1
    Just Joined!
    Join Date
    Apr 2010
    Posts
    12

    mkdir -p , which <> | vi

    Hi Friends i usually do this task

    (i) I usually make multiple dir using -p option

    ex: mkdir -p dicttest/audrep/tdriver/test

    Now after creating this dir's i stay in current dir instead i want to go directly to test dir how can i acheive this.

    (ii) When i execute which command as follows

    which testerm i will get the location of testterm now i want to open this file

    when i did in this way

    which testterm | vi

    The file dosent get opened how can i acheive this ?

    ex:

    linuxx86:110$ which testterm
    /view/rdl110_linuxx86/vobs_usrrdl/sc/testterm
    linuxx86:110$ which testterm| vi
    Vim: Warning: Input is not from a terminal
    Vim: Error reading input, exiting...

    Vim: Finished.
    linuxx86:110$

    (iii) I want to grep for a string in all files present in current dir excluding sub dir, sometimes including sub dir how can i acheive this i do this task on almost all platforms.

  2. #2
    Just Joined!
    Join Date
    Apr 2010
    Posts
    5
    You can add these function defs to your .profile or .bashrc

    mkdirandcd(){ mkdir -p $1;cd $1;}
    whichandvi(){ F=`which $1`;vi $F;}

    You now have 2 more commands you can use, mkdirandcd and whichandvi.

    and for the grep question I usually do something like this to show which files have my search pattern, including in subdirectories:

    grep -l pattern `find . -type f`

    Note that the quote marks in the above posting are backticks, same key on your keyboard that has the ~

  3. #3
    Just Joined!
    Join Date
    Apr 2010
    Posts
    5
    There is also a recursive grep in some linux varieties, either rgrep or use -r option. Look in the man pages about that. I didn't mention this at first because the grep and find combination works across different platforms, which you mentioned you want to do (HPUX, Solaris, Linux, OSX, etc.). You can also do a find command and use the -exec option to do the grep on each file found. Google "grep subdirectories" for some clever examples.

  4. #4
    Just Joined!
    Join Date
    Apr 2010
    Posts
    12
    Thanks friend

    And to add to grep now i am using

    grep -in <pattern> *

    its working great for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...