- How to show the full path of a file or directory in the terminal?
- 3 Answers 3
- How to get full path name of a Linux command
- 5 Answers 5
- Navigating Your File System in Linux
- This chapter is from the book
- This chapter is from the book
- This chapter is from the book
- List Files and Folders
- In linux, how to get the full path of a command I am using?
- 3 Answers 3
- Not the answer you’re looking for? Browse other questions tagged linux path or ask your own question.
- Related
- Hot Network Questions
- Subscribe to RSS
- How can I generate a list of files with their absolute path in Linux?
- 26 Answers 26
How to show the full path of a file or directory in the terminal?
I need to know how the directory name in order to type it out in the terminal. How do I access the names of directories?
Windows Explorer used to have a title bar with the full path. Can someone please help me figure out how to see the full path of a certain file?
3 Answers 3
If you are using nautilus to browse your files, you can toggle the navigation bar by pressing Ctrl + L .
If you are using the terminal, just use pwd to know the absolute path of your current location.
To display the full path of a file in the terminal just drag the file’s icon into the terminal, and the full path of the file will be displayed enclosed by two apostrophes (single quotation mark characters). It’s that simple.
In Ubuntu 20.04 and later drag and drop of files or directories doesn’t work from the desktop, but does work in other locations including dragging from the desktop in Files file manager.
find can do this quite handily from the terminal. Here’s an example in which I’m looking for the full path of the file Taxes-2013.pdf:
sudo find / -name Taxes-2013.pdf
Provides the output:
I’m using sudo so that I can avoid all the permission denied output that I would otherwise get with find when searching from the root of the tree.
If you just want the pathname and want the filename stripped off you can use
sudo find / -name Taxes-2013.pdf | xargs -n1 dirname
Note: If you are in the habit of putting spaces in names this is relevant to you.
Источник
How to get full path name of a Linux command
I want to find out the file path of commands in Linux e.g., ls has file path as /bin/ls . How can I find out the exact path of some commands?
5 Answers 5
As pointed out, which
would do it. You could also try:
This will list all the paths that contains progName . I.e whereis -b gcc on my machine returns:
you can use which , it give you path of command:
you can use type :
You can use the which command. In case of a command in your $PATH it will show you the full path:
And it will also show details about aliases:
Yes you can find it with which command
You did not specify, which shell you are going to use, but I strongly recommend using which , as it does not necessarily do, what you expect. Here two examples, where the result possibly is not what you expect:
(1) Example with bash, and the command echo :
would output /usr/bin/echo , but if you use the echo command in your bash script, /usr/bin/echo is not executed. Instead, the builtin command echo is executed, which is similar, but not identical in behaviour.
(2) Example with zsh, and the command which :
would output the message which: shell built-in command (which is correct, but certainly not a file path, as you requested), while
would output the file path /usr/bin/which , but (as in the bash example) this is not what’s getting executed when you just type which .
There are cases, when you know for sure (because you know your application), that which will produce the right result, but beware that as soon as builtin-commands, aliases and shell functions are involved, you need first to decide how you want to handle those cases, and then choose the appropriate tools depending on the kind of shell which you are using.
Источник
Navigating Your File System in Linux
This chapter is from the book
This chapter is from the book
This chapter is from the book
This chapter introduces the basic commands you’ll find yourself using several times every day. Think of these as the hammer, screwdriver, and pliers that a carpenter keeps in the top of his toolbox. After you learn these commands, you can start controlling your shell and finding out all sorts of interesting things about your files, folders, data, and environment. In particular, you’ll be learning about some of the metadata—the data describing your data—that Linux has to keep track of, and it may just surprise you how much there is.
When I updated this book for its second edition, I removed the section about mkdir -v (which shows you what mkdir is doing as it does it) and rm -v (which does the same thing, but for rm). You can find the original text on my website, www.granneman.com/linux-redactions.
Also, I took the sections on touch, mkdir, cp, mv, rm, and rmdir and used them to create a new Chapter 3 titled “Creation and Destruction” (which of course renumbered everything after it!). Finally, the section on su was moved to Chapter 8, “Ownership and Permissions,” which makes a lot more sense.
List Files and Folders
The ls command is probably the one that people find themselves using the most. After all, before you can manipulate and use files in a directory (remember, file and directory are interchangeable), you first have to know what files are available. That’s where ls comes in, as it lists the files and subdirectories found in a directory.
The ls command might sound simple—just show me the files!—but there are a surprising number of permutations to this amazingly pliable command, as you’ll see.
Typing ls lists the contents of the directory in which you’re currently working. When you first log in to your shell, you’ll find yourself in your home directory. Enter ls, and you might see something like the following:
Источник
In linux, how to get the full path of a command I am using?
How to get the full path of a command I am using?
for example, I have installed jdk into /opt/Oracle/jdk1.7.0_25 , and my PATH looks like this:
I want to get /opt/Oracle/jdk1.7.0_25/bin/java from java .
3 Answers 3
should give you the complete path.
This also works for any other command in Linux, just use which command_name .
It depends on your distribution, in debian and debian-based distros you have update-alternatives
And for your java you do for instance:
update-alternatives —install «/usr/bin/java» «java» «/opt/Oracle/jdk1.7.0_25/bin/java» 3
If you’re in bash:
type is a built-in, which is usually a separate executable:
Not the answer you’re looking for? Browse other questions tagged linux path or ask your own question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.8.40416
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
How can I generate a list of files with their absolute path in Linux?
I am writing a shell script that takes file paths as input.
For this reason, I need to generate recursive file listings with full paths. For example, the file bar has the path:
but, as far as I can see, both ls and find only give relative path listings:
It seems like an obvious requirement, but I can’t see anything in the find or ls man pages.
How can I generate a list of files in the shell including their absolute paths?
26 Answers 26
If you give find an absolute path to start with, it will print absolute paths. For instance, to find all .htaccess files in the current directory:
or if your shell expands $PWD to the current directory:
find simply prepends the path it was given to a relative path to the file from that path.
Greg Hewgill also suggested using pwd -P if you want to resolve symlinks in your current directory.
gives the full absolute path. but if the file is a symlink, u’ll get the final resolved name.
Use this for dirs (the / after ** is needed in bash to limit it to directories):
this for files and directories directly under the current directory, whose names contain a . :
this for everything:
In bash, ** is recursive if you enable shopt -s globstar .
This looks only in the current directory. It quotes «$PWD» in case it contains spaces.
Command: ls -1 -d «$PWD/»*
This will give the absolute paths of the file like below.
The $PWD is a good option by Matthew above. If you want find to only print files then you can also add the -type f option to search only normal files. Other options are «d» for directories only etc. So in your case it would be (if i want to search only for files with .c ext):
or if you want all files:
Note: You can’t make an alias for the above command, because $PWD gets auto-completed to your home directory when the alias is being set by bash.
If you give the find command an absolute path, it will spit the results out with an absolute path. So, from the Ken directory if you were to type:
(instead of the relative path find . -name bar -print )
Therefore, if you want an ls -l and have it return the absolute path, you can just tell the find command to execute an ls -l on whatever it finds.
NOTE: There is a space between <> and ;
You’ll get something like this:
If you aren’t sure where the file is, you can always change the search location. As long as the search path starts with «/», you will get an absolute path in return. If you are searching a location (like /) where you are going to get a lot of permission denied errors, then I would recommend redirecting standard error so you can actually see the find results:
( 2> is the syntax for the Borne and Bash shells, but will not work with the C shell. It may work in other shells too, but I only know for sure that it works in Bourne and Bash).
Источник