Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 19 of 19
Like Tree1Likes
Have a look at Webminal for an online terminal you can use to practice...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,559

    Have a look at Webminal for an online terminal you can use to practice
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

  2. #12
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19
    @elija

    I'll give that a try. Hopefully, it will answer my question below:
    Let's say I am currently in food/fruit/apple/seeds directory. For the start-dir, if I used fruit, it will automatically know I meant the folder to be outside of my current directory?

  3. #13
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,559
    Typically paths are relative to where you are so you could either specifiy the full path from / or use the parent dir twice (../../fruit)
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

  4. #14
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,557
    Read the man page. The command to do that is "man find". It will tell you exactly what all of the options do. In any case, if you are in fruit/nuts/flakes and want to search all of fruit for files named like apple-something, then you would do this: find ../.. -type f -iname '*apple*'
    That says, go up two directories and find the file (-type f) with apple, Apple, APPLE, etc in the name (-iname is for non-case-sensitive searches). If you used the option -name instead of -iname, then it would only find things with apple (no caps) in the name.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #15
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19
    @elija
    @Rubberman

    Thanks for the help.

  6. #16
    Just Joined!
    Join Date
    Oct 2012
    Location
    USA, Great Northwet
    Posts
    2

    locate, slocate, mlocate

    Depending on your distro, you can use one of the "locate" commands: locate, slocate, or mlocate - and the companion program updatedb.

    You use updatedb to create and maintain a database of all of the files and directories in your filesystem. You must have root privs to use updatedb, but not the "locate" command.

    Then you use one of the "locate" commands to query the database to find the file. The syntax is the same for any of the "locate" programs. For example, to find all instances of index.php in your filesystem

    [admin admin]$ slocate index.php

    You can use a fragment of the filename, e.g., "dex.p" is a fragment of "index.php"

    On one of my systems, to find all instances of index.php, I could use

    [admin admin]$ slocate dex.p

    That gives a long list that scrolls by really fast. I can pipe the output through less to manage the scrolling

    I can make a more focused list, e.g., only those index.php used in my bbp website, by piping through grep

    [admin admin]$ slocate dex.p | grep -i bbp
    /home/.sites/28/site1/web/bbp/index.php
    /home/.sites/28/site1/web/bbp/reports/index.php
    /home/backups/archives/20111209/bbp/index.php
    /home/backups/archives/20111209/bbp/reports/index.php
    /home/backups/current/bbp/index.php
    /home/backups/current/bbp/reports/index.php

    To find only those index.php used in my site6 website
    mlocate dex.php | grep -i site6 | less
    /home/.sites/148/site6/.users/47/jcharg/web/teacher/wp-content/index.php
    /home/.sites/148/site6/.users/47/jcharg/web/teacher/wp-content/themes-not-used/classic/index.php
    /home/.sites/148/site6/.users/47/jcharg/web/teacher/wp-content/themes-not-used/default/index.php
    /home/.sites/148/site6/.users/119/wbankke/web/randomthoughts/index.php
    /home/.sites/148/site6/.users/119/wbankke/web/randomthoughts/wp-admin/index.php
    /home/.sites/148/site6/.users/119/wbankke/web/randomthoughts/wp-content/themes/rounded-transparent-10/index.php

    or try

    [admin admin]$ slocate dex.p | grep -i bbp
    /home/.sites/28/site1/web/bbp/index.php
    /home/.sites/28/site1/web/bbp/reports/index.php
    /home/backups/archives/20111209/bbp/index.php
    /home/backups/archives/20111209/bbp/reports/index.php
    /home/backups/current/bbp/index.php
    /home/backups/current/bbp/reports/index.php

    More info:

    locate --help (or slocate --help or mlocate --help)

    man locate (or man slocate or man mlocate)

    It's up to you to learn pipes, grep, and less. It's also up to you to figure out which "locate" command your system uses. Try the "find" command that others in this thread use.

    Make sure your PATH includes the directory where the "locate" and updatedb commands reside.

    "locate" / updatedb work on any linux system - desktop or server

    Don't forget to keep your db updated by running sudo updatedb frequently (set up a cron job)

    Buena suerte.
    rokytnji likes this.

  7. #17
    Just Joined!
    Join Date
    Oct 2012
    Posts
    3
    Hello Dalawh,


    you are asking for
    to find a directory
    find start-dir -type d -name 'dirname'
    # to find a file
    find start-dir -type f -name 'filename'
    # to find anything with 'foo' in the name
    find start-dir -iname '*foo*'

    and

    What is "-type"? Is that that options?
    What is "d" or "f"?
    What is "-name"?
    What is "-iname"?

    *****************************************

    I have given the explanation with example for that

    find start-dir -type d -name 'dirname'

    where find is command name, start-dir : means path from where you want to start search, -type : is parameter indicate which type of content you want to search
    ex. d: directory, f: file etc,
    -name: parameter indicate you want to match name of file /directory and 'dirname: is name of file/directory to be search


    Example:

    # find /home/linus -type d -name 'xyz'

    # find /home/linus -type f -name 'abc.txt'


    Hope this will help you

  8. #18
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19
    Quote Originally Posted by sandybeach2000 View Post
    Depending on your distro, you can use one of the "locate" commands: locate, slocate, or mlocate - and the companion program updatedb.

    You use updatedb to create and maintain a database of all of the files and directories in your filesystem. You must have root privs to use updatedb, but not the "locate" command.

    Then you use one of the "locate" commands to query the database to find the file. The syntax is the same for any of the "locate" programs. For example, to find all instances of index.php in your filesystem

    [admin admin]$ slocate index.php

    You can use a fragment of the filename, e.g., "dex.p" is a fragment of "index.php"

    On one of my systems, to find all instances of index.php, I could use

    [admin admin]$ slocate dex.p

    That gives a long list that scrolls by really fast. I can pipe the output through less to manage the scrolling

    I can make a more focused list, e.g., only those index.php used in my bbp website, by piping through grep

    [admin admin]$ slocate dex.p | grep -i bbp
    /home/.sites/28/site1/web/bbp/index.php
    /home/.sites/28/site1/web/bbp/reports/index.php
    /home/backups/archives/20111209/bbp/index.php
    /home/backups/archives/20111209/bbp/reports/index.php
    /home/backups/current/bbp/index.php
    /home/backups/current/bbp/reports/index.php

    To find only those index.php used in my site6 website
    mlocate dex.php | grep -i site6 | less
    /home/.sites/148/site6/.users/47/jcharg/web/teacher/wp-content/index.php
    /home/.sites/148/site6/.users/47/jcharg/web/teacher/wp-content/themes-not-used/classic/index.php
    /home/.sites/148/site6/.users/47/jcharg/web/teacher/wp-content/themes-not-used/default/index.php
    /home/.sites/148/site6/.users/119/wbankke/web/randomthoughts/index.php
    /home/.sites/148/site6/.users/119/wbankke/web/randomthoughts/wp-admin/index.php
    /home/.sites/148/site6/.users/119/wbankke/web/randomthoughts/wp-content/themes/rounded-transparent-10/index.php

    or try

    [admin admin]$ slocate dex.p | grep -i bbp
    /home/.sites/28/site1/web/bbp/index.php
    /home/.sites/28/site1/web/bbp/reports/index.php
    /home/backups/archives/20111209/bbp/index.php
    /home/backups/archives/20111209/bbp/reports/index.php
    /home/backups/current/bbp/index.php
    /home/backups/current/bbp/reports/index.php

    More info:

    locate --help (or slocate --help or mlocate --help)

    man locate (or man slocate or man mlocate)

    It's up to you to learn pipes, grep, and less. It's also up to you to figure out which "locate" command your system uses. Try the "find" command that others in this thread use.

    Make sure your PATH includes the directory where the "locate" and updatedb commands reside.

    "locate" / updatedb work on any linux system - desktop or server

    Don't forget to keep your db updated by running sudo updatedb frequently (set up a cron job)

    Buena suerte.
    Thanks for introducing me to updatedb and "locate".

  9. #19
    Just Joined! Vampire5's Avatar
    Join Date
    Jan 2012
    Posts
    22
    Look, the main commands you need to use to navigate through directories to view your files is 'cd', 'ls' and 'pwd'. ls shows all the files and directories in your current directory (which, at the beginning, will most likely be your home directory). cd allows you to move from directory to directory; you use it like this:
    Code:
    # cd directory
    Finally, pwd allows you to see which directory you're in, for example:
    Code:
    # pwd
    /home/username/

Page 2 of 2 FirstFirst 1 2

Posting Permissions

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