Shell - How to find directory of some command?
how to find directory in linux
how to find a file in linux in all directories
linux find directory recursive
linux find command
linux find file
how to check directory
I know that when you are on shell, the only commands that can be used are the ones that can be found on some directory set on PATH. Even I don't know how to see what dirs are on my PATH variable (and this is another good question that could be answered), what I'd like to know is:
I come to shell and write:
I want to know a command on shell that can tell me WHERE this command is located. In other words, where this "executable file" is located?
$ location lshw /usr/bin
If you're using Bash or zsh, use this:
type -a lshw
This will show whether the target is a builtin, a function, an alias or an external executable. If the latter, it will show each place it appears in your
bash$ type -a lshw lshw is /usr/bin/lshw bash$ type -a ls ls is aliased to `ls --color=auto' ls is /bin/ls bash$ zsh zsh% type -a which which is a shell builtin which is /usr/bin/which
In Bash, for functions
type -a will also display the function definition. You can use
declare -f functionname to do the same thing (you have to use that for zsh, since
type -a doesn't).
How to Find Files and Folders in Linux Using the Command Line, What is the command to find a directory in Linux? How to find a directory on Linux. The find command syntax is: find /where/to/look/up criteria action OR find /dir/path/look/up criteria action OR find /dir/path/look/up -name "dir-name-here" OR find /dir/path/look/up -name "pattern" OR find /dir/path/look/up -name "dir-name-here" -print OR find /dir/path/look/up -name "dir-name-here" OR
To see all of the commands that match in your path:
which -a lshw
Where are my commands stored?, in /sbin, and you can't ran it as normal user, only as root (either log in as root, or use su or sudo). In the TENEX C Shell, tcsh, one can list a command's location (s), or if it is a built-in command, using the where command e.g.: tcsh% where python /usr/local/bin/python /usr/bin/python tcsh% where cd cd is a shell built-in /usr/bin/cd
PATH is an environment variable, and can be displayed with the echo command:
It's a list of paths separated by the colon character '
which command tells you which file gets executed when you run a command:
sometimes what you get is a path to a symlink; if you want to trace that link to where the actual executable lives, you can use
readlink and feed it the output of
readlink -f $(which lshw)
-f parameter instructs
readlink to keep following the symlink recursively.
Here's an example from my machine:
$ which firefox /usr/bin/firefox $ readlink -f $(which firefox) /usr/lib/firefox-3.6.3/firefox.sh
Linux / UNIX List Just Directories Or Directory Names, Finding a directory To find a directory called apt in / (root) file system, enter: Alert: When searching / (root) file system, you need to run the find command as root user. What follows is a list of some of the more commonly found directories in the Linux file system (all directories are not included on all systems): / is the root directory. /bin/ and /usr/bin/ store user commands. /boot/ contains files used for system startup including the kernel. /dev/ contains device files.
~$ echo $PATH /home/jack/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games ~$ whereis lshw lshw: /usr/bin/lshw /usr/share/man/man1/lshw.1.gz
How To Find a Directory On Linux Based System, How do I find files and folders in Linux using the bash command line? What is the command to find a folder in Linux? You can use find and locate All modern Linux distributions support the find command from the shell. To access the shell (sometimes called the terminal window), click the relevant icon or press Ctrl+Alt+T. (That command might not work on some Linux distributions.) Derek Abella / Lifewire
In the TENEX C Shell, tcsh, one can list a command's location(s), or if it is a built-in command, using the
where command e.g.:
tcsh% where python /usr/local/bin/python /usr/bin/python tcsh% where cd cd is a shell built-in /usr/bin/cd
How to find a folder in Linux using the command line, this command should get you what you are looking for: find / -type d -name httpdocs. that will search from the root of your server for directories with the name of Edit in response to @Notorious comment: Since Powershell 3.0 this is much easier, since switches -Directory and -File were added to Get-ChildItem. So if you want it short you've got: ls c:\test *key* -Recurse -Directory With command alias and tab-completion for switches it's a snap. I just missed that the first time.
How to find a directory on linux?, However, there are several ways to use the command line to find files in Linux, no matter The dot after “find” indicates the current directory. If, for example, you knew that the file had bob somewhere in the file, you would type: dir *bob*.* /s. The above example uses wildcards (the asterisks ). Also, it uses the /s command switch to tell the dir command to search the current directory, and all its subdirectories.
Ways to Use 'find' Command to Search Directories More Efficiently, There are several different means and utilities used for searching for files on the command line such as find, locate and which. However, the The find command will begin looking in the /dir/to/search/ and proceed to search through all accessible subdirectories. The filename is usually specified by the -name option. You can use other matching criteria too: -name file-name – Search for given file-name.
Find Files in Linux, Using the Command Line, Use the Find command from the Linux command line to locate files in a file Use find to search for a file or directory on your file system. which should be escaped ( \; ) to avoid interpretation by the shell. This may alleviate security concerns and produce more desirable performance for some operations. When you try to run a program or command from the terminal window, the shell (usually, Bash on modern distributions) has to find that command and launch it. Some commands, such as cd , history , and pwd , are built into the shell, so Bash doesn’t have to work too hard to find these.
- Thank everybody who answered, but this answer was the most exciting! Thank you! I was thinking that I'm crazy, because I defined (a long time ago) a way to do this: 'update', and this has been doing 'apt-get update; apt-get dist-upgrade' for me. But for now, I was trying to find some update.sh file somewhere, and I couldn't find it. That's why I started this question. But now, using 'type -a update' I found that this was just an alias defined on my .bashrc located on my ~home. Really thank you.
- @Gabriel: If you're not familiar with
locateit can help find files. It uses a database that's maintained by
updatedbwhich is run from a cron job. Since
locatesearches a database rather than the whole filesystem it's much faster than
find(which could be used as a last resort).
- Thank you. I'll study this tool, and see how updatedb is scheduled to run on Ubuntu's cronjob.
type -acan be confusing. e.g. in case of
nvmwhich is a bash function I needed to do:
type -a nvm | head -n1to find out what exactly is
- @MarinosAn: For functions,
type -aoutputs the function definition as well as the type of executable. The risk with using
headis that in the case of names with more than one type, the additional types wouldn't be output. You might want to look at
- also which -a lshw to see all of the commands that match in your path.
- I believe this only works with commands (executables on the $PATH), not functions.
whichis problematic because there are multiple implementations, many of which do entirely the wrong thing, and others of which seem to work fine, but have odd surprises. You should prefer
- Doesn't work for aliases and bash functions. At least on ubuntu. Better use
type -a lshw
- In ksh,
whence -ais similar to Bash's