How can you quickly get the complete path to a file for use in terminal?
up vote
42
down vote
favorite
How can you quickly get the complete path to a file for use in terminal?
command-line files paths
add a comment |
up vote
42
down vote
favorite
How can you quickly get the complete path to a file for use in terminal?
command-line files paths
add a comment |
up vote
42
down vote
favorite
up vote
42
down vote
favorite
How can you quickly get the complete path to a file for use in terminal?
command-line files paths
How can you quickly get the complete path to a file for use in terminal?
command-line files paths
command-line files paths
edited Nov 27 at 9:32
Sergiy Kolodyazhnyy
68k9141301
68k9141301
asked Jan 26 '11 at 19:32
Olivier Lalonde
20.4k50111140
20.4k50111140
add a comment |
add a comment |
7 Answers
7
active
oldest
votes
up vote
38
down vote
readlink -f foo.bar
or (install it first)
realpath foo.bar
This answer is more accurate than one accepted.
– Kunok
Oct 4 '16 at 9:23
For the complete folder:ls | xargs realpath.
– Pablo Bianchi
May 17 '17 at 13:57
The downside ofreadlinkis that it will work even if the file doesn't exist. This can perpetuate bugs in very odd ways.
– GregRos
Jun 28 at 17:30
add a comment |
up vote
30
down vote
accepted
Just drag and drop the file in the terminal.
1
I'm putting this here so that I don't forget, let's hope it helps some of you :D
– Olivier Lalonde
Jan 26 '11 at 19:33
Returns an "smb://" prefixed path for SMB mounted shares instead of the actual mounted path.
– Kupiakos
Sep 26 '13 at 23:21
@Kupiakos: for me, gnome-terminal happily translates the dropped file path to'/home/alexcohn/.gvfs/…'
– Alex Cohn
Mar 17 '14 at 15:11
add a comment |
up vote
9
down vote
All good answers; Here is a tip for another situation.
If you are browsing your files using nautilus and you want the complete path of your current directory, then press CTRL+L. This changes the breadcrumb buttons temporarily back to the old-style address bar, allowing you to copy the path.
… but this is stillsmb://-style, so it cannot be reused in terminal.
– Alex Cohn
Mar 17 '14 at 12:36
Interesting; on my system (Ubuntu 13.10) I do not get asmb://-style path.
– Sicco
Mar 17 '14 at 13:03
Exactly what I was looking for, I mean the terminal is a great place to ls but there is those times you work in a file folder views : ' )
– edencorbin
Feb 1 '17 at 6:25
add a comment |
up vote
3
down vote
If it's an executable, then execute (in a terminal):
$ which your_executable
For example: $ which ls
This is the answer i was looking for
– Sharjeel Ahmed
Jun 15 '15 at 19:18
add a comment |
up vote
1
down vote
In addition to dragging the icon, there are a few ways to get the full path without nautilus (or thunar, konqueror, et al.). You would then triple-click or click-drag and copy, potentially saving this in your clipboard manager*, and paste it where you need.
(pastie, klipper, glippy, glipper, anamnesis)
You can use
findin a directory above your file. (If you don't know where it is, start where your shell drops you, [generally] in the top of your home directory.)find . | egrep filenameYou can use
locateto get the filename. (Runsudo updatedbif that hasn't been done recently.)
A more realistic example of using find would be something like :
$ find | egrep askubuntu | grep txt
./askubuntu-temp.txt
./drDocuments/web/meta.askubuntu.txt
./other/stuff/askubuntu.txt.iteration.1
./other/stuff/askubuntu.txt.iteration.2
[...]
To cut out the ones you don't like, e.g.:
find | egrep askubuntu | grep txt | egrep -v iteration
find | egrep askubuntu | grep txt | egrep -v 'iteration|meta|other'
locate is used much the same way, though grep is frequently more necessary:
locate myfile | egrep home | egrep -v 'mozilla|cache|local|bin|.pyc|test' | grep .py
This isn't the most efficient way to type this, but usually if I've lost a file, I do this iteratively, adding grep clauses as I go.
add a comment |
up vote
1
down vote
Easily done in python using os.realpath() function:
$ python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' ./VirtualBox VMs/
/mnt/HDD/VirtualBox VMs
From a related answer,you can also use readlink
$ readlink -e ./out.txt
/home/username/out.txt
add a comment |
up vote
0
down vote
If you simply copy a file in Nautilus, then the full path is copied.
Then paste it in the terminal.
By simply pasting you get:
file:///home/juan/2017/agenda20170101.html
If you right-click and choose "Paste filenames" then you get:
'/home/juan/2017/agenda20170101.html'
with the quotes as shown.
This differs from Windows, that copies the file content instead of its name.
add a comment |
protected by Sergiy Kolodyazhnyy Nov 27 at 9:32
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
38
down vote
readlink -f foo.bar
or (install it first)
realpath foo.bar
This answer is more accurate than one accepted.
– Kunok
Oct 4 '16 at 9:23
For the complete folder:ls | xargs realpath.
– Pablo Bianchi
May 17 '17 at 13:57
The downside ofreadlinkis that it will work even if the file doesn't exist. This can perpetuate bugs in very odd ways.
– GregRos
Jun 28 at 17:30
add a comment |
up vote
38
down vote
readlink -f foo.bar
or (install it first)
realpath foo.bar
This answer is more accurate than one accepted.
– Kunok
Oct 4 '16 at 9:23
For the complete folder:ls | xargs realpath.
– Pablo Bianchi
May 17 '17 at 13:57
The downside ofreadlinkis that it will work even if the file doesn't exist. This can perpetuate bugs in very odd ways.
– GregRos
Jun 28 at 17:30
add a comment |
up vote
38
down vote
up vote
38
down vote
readlink -f foo.bar
or (install it first)
realpath foo.bar
readlink -f foo.bar
or (install it first)
realpath foo.bar
edited Jan 4 '14 at 18:01
Avinash Raj
51.1k41165211
51.1k41165211
answered Jan 26 '11 at 20:27
spennig
53433
53433
This answer is more accurate than one accepted.
– Kunok
Oct 4 '16 at 9:23
For the complete folder:ls | xargs realpath.
– Pablo Bianchi
May 17 '17 at 13:57
The downside ofreadlinkis that it will work even if the file doesn't exist. This can perpetuate bugs in very odd ways.
– GregRos
Jun 28 at 17:30
add a comment |
This answer is more accurate than one accepted.
– Kunok
Oct 4 '16 at 9:23
For the complete folder:ls | xargs realpath.
– Pablo Bianchi
May 17 '17 at 13:57
The downside ofreadlinkis that it will work even if the file doesn't exist. This can perpetuate bugs in very odd ways.
– GregRos
Jun 28 at 17:30
This answer is more accurate than one accepted.
– Kunok
Oct 4 '16 at 9:23
This answer is more accurate than one accepted.
– Kunok
Oct 4 '16 at 9:23
For the complete folder:
ls | xargs realpath.– Pablo Bianchi
May 17 '17 at 13:57
For the complete folder:
ls | xargs realpath.– Pablo Bianchi
May 17 '17 at 13:57
The downside of
readlink is that it will work even if the file doesn't exist. This can perpetuate bugs in very odd ways.– GregRos
Jun 28 at 17:30
The downside of
readlink is that it will work even if the file doesn't exist. This can perpetuate bugs in very odd ways.– GregRos
Jun 28 at 17:30
add a comment |
up vote
30
down vote
accepted
Just drag and drop the file in the terminal.
1
I'm putting this here so that I don't forget, let's hope it helps some of you :D
– Olivier Lalonde
Jan 26 '11 at 19:33
Returns an "smb://" prefixed path for SMB mounted shares instead of the actual mounted path.
– Kupiakos
Sep 26 '13 at 23:21
@Kupiakos: for me, gnome-terminal happily translates the dropped file path to'/home/alexcohn/.gvfs/…'
– Alex Cohn
Mar 17 '14 at 15:11
add a comment |
up vote
30
down vote
accepted
Just drag and drop the file in the terminal.
1
I'm putting this here so that I don't forget, let's hope it helps some of you :D
– Olivier Lalonde
Jan 26 '11 at 19:33
Returns an "smb://" prefixed path for SMB mounted shares instead of the actual mounted path.
– Kupiakos
Sep 26 '13 at 23:21
@Kupiakos: for me, gnome-terminal happily translates the dropped file path to'/home/alexcohn/.gvfs/…'
– Alex Cohn
Mar 17 '14 at 15:11
add a comment |
up vote
30
down vote
accepted
up vote
30
down vote
accepted
Just drag and drop the file in the terminal.
Just drag and drop the file in the terminal.
answered Jan 26 '11 at 19:32
Olivier Lalonde
20.4k50111140
20.4k50111140
1
I'm putting this here so that I don't forget, let's hope it helps some of you :D
– Olivier Lalonde
Jan 26 '11 at 19:33
Returns an "smb://" prefixed path for SMB mounted shares instead of the actual mounted path.
– Kupiakos
Sep 26 '13 at 23:21
@Kupiakos: for me, gnome-terminal happily translates the dropped file path to'/home/alexcohn/.gvfs/…'
– Alex Cohn
Mar 17 '14 at 15:11
add a comment |
1
I'm putting this here so that I don't forget, let's hope it helps some of you :D
– Olivier Lalonde
Jan 26 '11 at 19:33
Returns an "smb://" prefixed path for SMB mounted shares instead of the actual mounted path.
– Kupiakos
Sep 26 '13 at 23:21
@Kupiakos: for me, gnome-terminal happily translates the dropped file path to'/home/alexcohn/.gvfs/…'
– Alex Cohn
Mar 17 '14 at 15:11
1
1
I'm putting this here so that I don't forget, let's hope it helps some of you :D
– Olivier Lalonde
Jan 26 '11 at 19:33
I'm putting this here so that I don't forget, let's hope it helps some of you :D
– Olivier Lalonde
Jan 26 '11 at 19:33
Returns an "smb://" prefixed path for SMB mounted shares instead of the actual mounted path.
– Kupiakos
Sep 26 '13 at 23:21
Returns an "smb://" prefixed path for SMB mounted shares instead of the actual mounted path.
– Kupiakos
Sep 26 '13 at 23:21
@Kupiakos: for me, gnome-terminal happily translates the dropped file path to
'/home/alexcohn/.gvfs/…'– Alex Cohn
Mar 17 '14 at 15:11
@Kupiakos: for me, gnome-terminal happily translates the dropped file path to
'/home/alexcohn/.gvfs/…'– Alex Cohn
Mar 17 '14 at 15:11
add a comment |
up vote
9
down vote
All good answers; Here is a tip for another situation.
If you are browsing your files using nautilus and you want the complete path of your current directory, then press CTRL+L. This changes the breadcrumb buttons temporarily back to the old-style address bar, allowing you to copy the path.
… but this is stillsmb://-style, so it cannot be reused in terminal.
– Alex Cohn
Mar 17 '14 at 12:36
Interesting; on my system (Ubuntu 13.10) I do not get asmb://-style path.
– Sicco
Mar 17 '14 at 13:03
Exactly what I was looking for, I mean the terminal is a great place to ls but there is those times you work in a file folder views : ' )
– edencorbin
Feb 1 '17 at 6:25
add a comment |
up vote
9
down vote
All good answers; Here is a tip for another situation.
If you are browsing your files using nautilus and you want the complete path of your current directory, then press CTRL+L. This changes the breadcrumb buttons temporarily back to the old-style address bar, allowing you to copy the path.
… but this is stillsmb://-style, so it cannot be reused in terminal.
– Alex Cohn
Mar 17 '14 at 12:36
Interesting; on my system (Ubuntu 13.10) I do not get asmb://-style path.
– Sicco
Mar 17 '14 at 13:03
Exactly what I was looking for, I mean the terminal is a great place to ls but there is those times you work in a file folder views : ' )
– edencorbin
Feb 1 '17 at 6:25
add a comment |
up vote
9
down vote
up vote
9
down vote
All good answers; Here is a tip for another situation.
If you are browsing your files using nautilus and you want the complete path of your current directory, then press CTRL+L. This changes the breadcrumb buttons temporarily back to the old-style address bar, allowing you to copy the path.
All good answers; Here is a tip for another situation.
If you are browsing your files using nautilus and you want the complete path of your current directory, then press CTRL+L. This changes the breadcrumb buttons temporarily back to the old-style address bar, allowing you to copy the path.
answered Jun 6 '12 at 20:34
Sicco
291316
291316
… but this is stillsmb://-style, so it cannot be reused in terminal.
– Alex Cohn
Mar 17 '14 at 12:36
Interesting; on my system (Ubuntu 13.10) I do not get asmb://-style path.
– Sicco
Mar 17 '14 at 13:03
Exactly what I was looking for, I mean the terminal is a great place to ls but there is those times you work in a file folder views : ' )
– edencorbin
Feb 1 '17 at 6:25
add a comment |
… but this is stillsmb://-style, so it cannot be reused in terminal.
– Alex Cohn
Mar 17 '14 at 12:36
Interesting; on my system (Ubuntu 13.10) I do not get asmb://-style path.
– Sicco
Mar 17 '14 at 13:03
Exactly what I was looking for, I mean the terminal is a great place to ls but there is those times you work in a file folder views : ' )
– edencorbin
Feb 1 '17 at 6:25
… but this is still
smb://-style, so it cannot be reused in terminal.– Alex Cohn
Mar 17 '14 at 12:36
… but this is still
smb://-style, so it cannot be reused in terminal.– Alex Cohn
Mar 17 '14 at 12:36
Interesting; on my system (Ubuntu 13.10) I do not get a
smb://-style path.– Sicco
Mar 17 '14 at 13:03
Interesting; on my system (Ubuntu 13.10) I do not get a
smb://-style path.– Sicco
Mar 17 '14 at 13:03
Exactly what I was looking for, I mean the terminal is a great place to ls but there is those times you work in a file folder views : ' )
– edencorbin
Feb 1 '17 at 6:25
Exactly what I was looking for, I mean the terminal is a great place to ls but there is those times you work in a file folder views : ' )
– edencorbin
Feb 1 '17 at 6:25
add a comment |
up vote
3
down vote
If it's an executable, then execute (in a terminal):
$ which your_executable
For example: $ which ls
This is the answer i was looking for
– Sharjeel Ahmed
Jun 15 '15 at 19:18
add a comment |
up vote
3
down vote
If it's an executable, then execute (in a terminal):
$ which your_executable
For example: $ which ls
This is the answer i was looking for
– Sharjeel Ahmed
Jun 15 '15 at 19:18
add a comment |
up vote
3
down vote
up vote
3
down vote
If it's an executable, then execute (in a terminal):
$ which your_executable
For example: $ which ls
If it's an executable, then execute (in a terminal):
$ which your_executable
For example: $ which ls
edited Oct 14 '15 at 11:04
Matthew
1074
1074
answered Jan 26 '11 at 19:52
perseo22
95096
95096
This is the answer i was looking for
– Sharjeel Ahmed
Jun 15 '15 at 19:18
add a comment |
This is the answer i was looking for
– Sharjeel Ahmed
Jun 15 '15 at 19:18
This is the answer i was looking for
– Sharjeel Ahmed
Jun 15 '15 at 19:18
This is the answer i was looking for
– Sharjeel Ahmed
Jun 15 '15 at 19:18
add a comment |
up vote
1
down vote
In addition to dragging the icon, there are a few ways to get the full path without nautilus (or thunar, konqueror, et al.). You would then triple-click or click-drag and copy, potentially saving this in your clipboard manager*, and paste it where you need.
(pastie, klipper, glippy, glipper, anamnesis)
You can use
findin a directory above your file. (If you don't know where it is, start where your shell drops you, [generally] in the top of your home directory.)find . | egrep filenameYou can use
locateto get the filename. (Runsudo updatedbif that hasn't been done recently.)
A more realistic example of using find would be something like :
$ find | egrep askubuntu | grep txt
./askubuntu-temp.txt
./drDocuments/web/meta.askubuntu.txt
./other/stuff/askubuntu.txt.iteration.1
./other/stuff/askubuntu.txt.iteration.2
[...]
To cut out the ones you don't like, e.g.:
find | egrep askubuntu | grep txt | egrep -v iteration
find | egrep askubuntu | grep txt | egrep -v 'iteration|meta|other'
locate is used much the same way, though grep is frequently more necessary:
locate myfile | egrep home | egrep -v 'mozilla|cache|local|bin|.pyc|test' | grep .py
This isn't the most efficient way to type this, but usually if I've lost a file, I do this iteratively, adding grep clauses as I go.
add a comment |
up vote
1
down vote
In addition to dragging the icon, there are a few ways to get the full path without nautilus (or thunar, konqueror, et al.). You would then triple-click or click-drag and copy, potentially saving this in your clipboard manager*, and paste it where you need.
(pastie, klipper, glippy, glipper, anamnesis)
You can use
findin a directory above your file. (If you don't know where it is, start where your shell drops you, [generally] in the top of your home directory.)find . | egrep filenameYou can use
locateto get the filename. (Runsudo updatedbif that hasn't been done recently.)
A more realistic example of using find would be something like :
$ find | egrep askubuntu | grep txt
./askubuntu-temp.txt
./drDocuments/web/meta.askubuntu.txt
./other/stuff/askubuntu.txt.iteration.1
./other/stuff/askubuntu.txt.iteration.2
[...]
To cut out the ones you don't like, e.g.:
find | egrep askubuntu | grep txt | egrep -v iteration
find | egrep askubuntu | grep txt | egrep -v 'iteration|meta|other'
locate is used much the same way, though grep is frequently more necessary:
locate myfile | egrep home | egrep -v 'mozilla|cache|local|bin|.pyc|test' | grep .py
This isn't the most efficient way to type this, but usually if I've lost a file, I do this iteratively, adding grep clauses as I go.
add a comment |
up vote
1
down vote
up vote
1
down vote
In addition to dragging the icon, there are a few ways to get the full path without nautilus (or thunar, konqueror, et al.). You would then triple-click or click-drag and copy, potentially saving this in your clipboard manager*, and paste it where you need.
(pastie, klipper, glippy, glipper, anamnesis)
You can use
findin a directory above your file. (If you don't know where it is, start where your shell drops you, [generally] in the top of your home directory.)find . | egrep filenameYou can use
locateto get the filename. (Runsudo updatedbif that hasn't been done recently.)
A more realistic example of using find would be something like :
$ find | egrep askubuntu | grep txt
./askubuntu-temp.txt
./drDocuments/web/meta.askubuntu.txt
./other/stuff/askubuntu.txt.iteration.1
./other/stuff/askubuntu.txt.iteration.2
[...]
To cut out the ones you don't like, e.g.:
find | egrep askubuntu | grep txt | egrep -v iteration
find | egrep askubuntu | grep txt | egrep -v 'iteration|meta|other'
locate is used much the same way, though grep is frequently more necessary:
locate myfile | egrep home | egrep -v 'mozilla|cache|local|bin|.pyc|test' | grep .py
This isn't the most efficient way to type this, but usually if I've lost a file, I do this iteratively, adding grep clauses as I go.
In addition to dragging the icon, there are a few ways to get the full path without nautilus (or thunar, konqueror, et al.). You would then triple-click or click-drag and copy, potentially saving this in your clipboard manager*, and paste it where you need.
(pastie, klipper, glippy, glipper, anamnesis)
You can use
findin a directory above your file. (If you don't know where it is, start where your shell drops you, [generally] in the top of your home directory.)find . | egrep filenameYou can use
locateto get the filename. (Runsudo updatedbif that hasn't been done recently.)
A more realistic example of using find would be something like :
$ find | egrep askubuntu | grep txt
./askubuntu-temp.txt
./drDocuments/web/meta.askubuntu.txt
./other/stuff/askubuntu.txt.iteration.1
./other/stuff/askubuntu.txt.iteration.2
[...]
To cut out the ones you don't like, e.g.:
find | egrep askubuntu | grep txt | egrep -v iteration
find | egrep askubuntu | grep txt | egrep -v 'iteration|meta|other'
locate is used much the same way, though grep is frequently more necessary:
locate myfile | egrep home | egrep -v 'mozilla|cache|local|bin|.pyc|test' | grep .py
This isn't the most efficient way to type this, but usually if I've lost a file, I do this iteratively, adding grep clauses as I go.
edited Jan 26 '11 at 20:23
answered Jan 26 '11 at 20:12
belacqua
15.6k1472103
15.6k1472103
add a comment |
add a comment |
up vote
1
down vote
Easily done in python using os.realpath() function:
$ python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' ./VirtualBox VMs/
/mnt/HDD/VirtualBox VMs
From a related answer,you can also use readlink
$ readlink -e ./out.txt
/home/username/out.txt
add a comment |
up vote
1
down vote
Easily done in python using os.realpath() function:
$ python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' ./VirtualBox VMs/
/mnt/HDD/VirtualBox VMs
From a related answer,you can also use readlink
$ readlink -e ./out.txt
/home/username/out.txt
add a comment |
up vote
1
down vote
up vote
1
down vote
Easily done in python using os.realpath() function:
$ python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' ./VirtualBox VMs/
/mnt/HDD/VirtualBox VMs
From a related answer,you can also use readlink
$ readlink -e ./out.txt
/home/username/out.txt
Easily done in python using os.realpath() function:
$ python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' ./VirtualBox VMs/
/mnt/HDD/VirtualBox VMs
From a related answer,you can also use readlink
$ readlink -e ./out.txt
/home/username/out.txt
edited Nov 27 at 9:35
answered Jan 13 '17 at 13:57
Sergiy Kolodyazhnyy
68k9141301
68k9141301
add a comment |
add a comment |
up vote
0
down vote
If you simply copy a file in Nautilus, then the full path is copied.
Then paste it in the terminal.
By simply pasting you get:
file:///home/juan/2017/agenda20170101.html
If you right-click and choose "Paste filenames" then you get:
'/home/juan/2017/agenda20170101.html'
with the quotes as shown.
This differs from Windows, that copies the file content instead of its name.
add a comment |
up vote
0
down vote
If you simply copy a file in Nautilus, then the full path is copied.
Then paste it in the terminal.
By simply pasting you get:
file:///home/juan/2017/agenda20170101.html
If you right-click and choose "Paste filenames" then you get:
'/home/juan/2017/agenda20170101.html'
with the quotes as shown.
This differs from Windows, that copies the file content instead of its name.
add a comment |
up vote
0
down vote
up vote
0
down vote
If you simply copy a file in Nautilus, then the full path is copied.
Then paste it in the terminal.
By simply pasting you get:
file:///home/juan/2017/agenda20170101.html
If you right-click and choose "Paste filenames" then you get:
'/home/juan/2017/agenda20170101.html'
with the quotes as shown.
This differs from Windows, that copies the file content instead of its name.
If you simply copy a file in Nautilus, then the full path is copied.
Then paste it in the terminal.
By simply pasting you get:
file:///home/juan/2017/agenda20170101.html
If you right-click and choose "Paste filenames" then you get:
'/home/juan/2017/agenda20170101.html'
with the quotes as shown.
This differs from Windows, that copies the file content instead of its name.
answered Jan 8 '17 at 14:26
Juan Lanus
16115
16115
add a comment |
add a comment |
protected by Sergiy Kolodyazhnyy Nov 27 at 9:32
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?