How to find directory of some command?
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 PATH
.
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 can I find a file/directory that could be anywhere on linux command line?
"Unfortunately this seems to only check the current directory, not the entire folder". Presumably you mean it doesn't look in subdirectories. To fix this, use find -name "filename"
If the file in question is not in the current working directory, you can search your entire machine via
find / -name "filename"
This also works with stuff like find / -name "*.pdf"
, etc. Sometimes I like to pipe that into a grep statement as well (since, on my machine at least, it highlights the results), so I end up with something like
find / -name "*star*wars*" | grep star
Doing this or a similar method just helps me instantly find the filename and recognize if it is in fact the file I am looking for.
Find file in directory from command line
find /root/directory/to/search -name 'filename.*'
# Directory is optional (defaults to cwd)
Standard UNIX globbing is supported. See man find
for more information.
If you're using Vim, you can use:
:e **/filename.cpp
Or :tabn
or any Vim command which accepts a filename.
how to search for a directory from the terminal in ubuntu
you can search for directory by using find
with flag -name
you should use
find /user -name "sdk" -type d
meaning find directories named sdk in or below the directory /user
or if you want to be case-insensitive
find /user -iname "sdk" -type d
Unix shell script find out which directory the script file resides?
In Bash, you should get what you need like this:
#!/usr/bin/env bash
BASEDIR=$(dirname "$0")
echo "$BASEDIR"
How to get full path of a file?
Use readlink:
readlink -f file.txt
Shell command to find files in a directory pattern
Shell Script:
find /home/*/public_html/images -iname "*php" -exec echo {} \;
You can then change the -exec command to do whatever actions you want to the returned files. In this case, we echo them, but you could easily perform other actions as well.
Related Topics
Limiting Memory Usage in R Under Linux
How to Get Position of Cursor in Terminal
How to Automatically Add User Account and Password with a Bash Script
Colour Highlighting Output Based on Regex in Shell
Linux Shell Sort File According to the Second Column
Awk - How to Delete First Column with Field Separator
How to Remove All .Svn Directories from My Application Directories
Command Output Redirect to File and Terminal
How to Grep for the Dollar Symbol ($)
Nginx: Serve Multiple Laravel Apps with Same Url But Two Different Sub Locations in Linux
How to Get Child Process from Parent Process
Self Modifying Code Always Segmentation Faults on Linux
Docker Command Can't Connect to Docker Daemon
Run Script with Rc.Local: Script Works, But Not at Boot
Where Does Eclipse Look for Eclipse.Ini Under Linux
Symbols from Convenience Library Not Getting Exported in Executable
How to Detect the Physical Connected State of a Network Cable/Connector