can relative path access more than one level?Quick path jumpingStand-alone Flash projector doesn't take relative pathsHow can I add a directory to my PATH?What would I write as a directory?How do I open file or directory in terminal without typing the full directory path?Why is there more than one command in Bash for accomplishing the same task?Custom command - one less than current brightness levelCan one change the output path of cups pdf printer dynamicallyHow to move files from subdirectories that have the same directory name to its relative upper/parent directory?Adding folders to your PATH environment variable
What's the correct term for a waitress in the Middle Ages?
How do I remove hundreds of automatically added network printers?
Do adult Russians normally hand-write Cyrillic as cursive or as block letters?
Short story written from alien perspective with this line: "It's too bright to look at, so they don't"
Traffic law UK, pedestrians
What do we gain with higher order logics?
How to split a string in two substrings of same length using bash?
Incremental Ranges!
What is the correct expression of 10/20, 20/30, 30/40 etc?
How were concentration and extermination camp guards recruited?
What are they doing to this poor rocket?
What's the most polite way to tell a manager "shut up and let me work"?
Will TSA allow me to carry a Continuous Positive Airway Pressure (CPAP) device?
Credit card offering 0.5 miles for every cent rounded up. Too good to be true?
If Boris Johnson were prosecuted and convicted of lying about Brexit, can that be used to cancel Brexit?
Avoid that star symbol is searchable with questionmark "?"
Can I ask a publisher for a paper that I need for reviewing
Is there any word or phrase for negative bearing?
Valid B1/B2 visa owner wins the DV lottery, needs to go US before the interview. Can he?
Word for a small burst of laughter that can't be held back
Responsibility for visa checking
Unconventional Opposites
Metal bar on DMM PCB
PhD student with mental health issues and bad performance
can relative path access more than one level?
Quick path jumpingStand-alone Flash projector doesn't take relative pathsHow can I add a directory to my PATH?What would I write as a directory?How do I open file or directory in terminal without typing the full directory path?Why is there more than one command in Bash for accomplishing the same task?Custom command - one less than current brightness levelCan one change the output path of cups pdf printer dynamicallyHow to move files from subdirectories that have the same directory name to its relative upper/parent directory?Adding folders to your PATH environment variable
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm new to Linux and was wondering if relative path can access more than one level.
For example:
/home/john/Desktop/Myfiles/text.txt
If i'm currently at ~/
can i jump to text.txt
without having to write Desktop/Myfiles/
in my path ?
command-line directory paths
add a comment |
I'm new to Linux and was wondering if relative path can access more than one level.
For example:
/home/john/Desktop/Myfiles/text.txt
If i'm currently at ~/
can i jump to text.txt
without having to write Desktop/Myfiles/
in my path ?
command-line directory paths
add a comment |
I'm new to Linux and was wondering if relative path can access more than one level.
For example:
/home/john/Desktop/Myfiles/text.txt
If i'm currently at ~/
can i jump to text.txt
without having to write Desktop/Myfiles/
in my path ?
command-line directory paths
I'm new to Linux and was wondering if relative path can access more than one level.
For example:
/home/john/Desktop/Myfiles/text.txt
If i'm currently at ~/
can i jump to text.txt
without having to write Desktop/Myfiles/
in my path ?
command-line directory paths
command-line directory paths
edited Apr 14 at 21:20
Sergiy Kolodyazhnyy
76.2k10161336
76.2k10161336
asked Apr 14 at 19:41
AnhtuAnhtu
1
1
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Yes, all paths can have multiple components. "Relative" paths don't begin with "/
", and start looking in the current directory. "Absolute" paths begin with "/
" and start looking at the root of the filesystem tree, also called "/
".
So, you can use paths like this:
cd $HOME
ls Desktop/MyFiles/text.txt
or:
cd $HOME/Desktop/MyFiles
ls text.txt
In either case, ls /etc/passwd
would refer to the same file.
add a comment |
Skipping parts of path cannot be done, that is you cannot do something like cd ~/.../Myfiles
. Suppose you have /home/john/Desktop/Myfiles/
and /home/john/Documents/Myfiles
. When you want to navigate to Myfiles
, which one do you mean ? One in ~/Desktop
or ~/Documents
. Essential reason is because directory structure is organized into a tree, where each preceding element has to have a parent item. Thus, the question becomes who is the parent directory of Myfiles
when there are two of them ?
However, there are several things that help navigating the long pathnames:
- save absolute path to variable. Say
myfiles=/home/john/Desktop/Myfiles
. When you start the shell, you already have$HOME
special variable or you can use tilde expansioncd ~/Desktop/Myfiles
use
pushd
andpopd
. Shell has something known as "directory stack", which can be used to record a sequence of directories. For example, if I do$ pushd /etc
/etc ~
$ pushd /sys/class/backlight/intel_backlight/
/sys/class/backlight/intel_backlight /etc ~
$ pushd .
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc ~Notice that in dirstack the very first item indicates current working directory, while the second item remains unchanged even if you
cd
elsewhere. This is whypushd .
was added. Now, if we navigate elsewhere,/sys/class/backlight/intel_backlight
will be stored on the stack and we can always return to it.# navigate elsewhere after pushd .
$ cd /var/log
$ cd /usr/share
# check what's in the stack
$ echo $DIRSTACK[@]
/usr/share /sys/class/backlight/intel_backlight /etc /home/ubuntuadmin
# go to one of the directories on the stack
$ cd $DIRSTACK[1]
$ pwd
/sys/class/backlight/intel_backlight
# remember that very first item changes, it's the current working directory
$ echo $DIRSTACK[@]
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc /home/ubuntuadminUse symlinks.Example:
$ ln -s /var/log ~/logs
$ cd ~/logsNow instead of doing
cd /var/log
you can docd ~/logs
. Trivial example, but imagine if/var/log
was something like/media/external_harddrive/someproject/subproject/data/bignumbers/calculations/
. We can just docd ~/calculations
then if we have symlink. Of course disadvantage of symlinks is that when directory is renamed or removed, symlink remains and becomes broken, but it's a simple fix - either re-create full path to symlink or remove the symlink and create new one. We can also create a symlink that points to symlink that points to actual directory, but beware that Linux kernel caps too many levels of symlinks ( and you'd get an error that says exactly that) if there are more than 40 symlinks.If the goal is to create a fast way of opening the file
text.txt
the symlink approach can help us with that$ echo 'Hello, this is a test' > ~/Documents/another_directory/file.txt
$ ln -s ~/Documents/another_directory/file.txt ~/file.symlink
$ cat ~/file.symlink
Hello, this is a test
$You can use inode numbers. This is often used to deal with difficult filenames, where quoting and special characters become a problem. For instance, if we know directory's inode
# return $HOME
$ cd
# find the inode
$ ls -id ~/Documents/things
1205421 /home/ubuntuadmin/Documents/things
# go to the directory by inode
$ cd "$(find -inum 1205421)"
$ pwd
/home/ubuntuadmin/Documents/thingsProblem with this approach - it is slow and inefficient, since recursive traversal via
find
and checking all inodes along the way requires time and a lot of syscalls.
Ah it makes sense...so no matter where i am, skipping parts of path is not possible...Thx
– Anhtu
Apr 14 at 22:33
@Anhtu Essentially yes. If you know there's no duplicate, you could docd ~/*/Myfiles
but if there's~/anotherdir/Myfiles
that approach will fail
– Sergiy Kolodyazhnyy
Apr 14 at 22:37
@Anhtu I've added another bullet point, which can be sort of "skipping" but it is slow, inefficient, and essentially is something that goes against Unix/Linux design, so it is used in only special cases - not generally
– Sergiy Kolodyazhnyy
Apr 14 at 22:48
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1133888%2fcan-relative-path-access-more-than-one-level%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes, all paths can have multiple components. "Relative" paths don't begin with "/
", and start looking in the current directory. "Absolute" paths begin with "/
" and start looking at the root of the filesystem tree, also called "/
".
So, you can use paths like this:
cd $HOME
ls Desktop/MyFiles/text.txt
or:
cd $HOME/Desktop/MyFiles
ls text.txt
In either case, ls /etc/passwd
would refer to the same file.
add a comment |
Yes, all paths can have multiple components. "Relative" paths don't begin with "/
", and start looking in the current directory. "Absolute" paths begin with "/
" and start looking at the root of the filesystem tree, also called "/
".
So, you can use paths like this:
cd $HOME
ls Desktop/MyFiles/text.txt
or:
cd $HOME/Desktop/MyFiles
ls text.txt
In either case, ls /etc/passwd
would refer to the same file.
add a comment |
Yes, all paths can have multiple components. "Relative" paths don't begin with "/
", and start looking in the current directory. "Absolute" paths begin with "/
" and start looking at the root of the filesystem tree, also called "/
".
So, you can use paths like this:
cd $HOME
ls Desktop/MyFiles/text.txt
or:
cd $HOME/Desktop/MyFiles
ls text.txt
In either case, ls /etc/passwd
would refer to the same file.
Yes, all paths can have multiple components. "Relative" paths don't begin with "/
", and start looking in the current directory. "Absolute" paths begin with "/
" and start looking at the root of the filesystem tree, also called "/
".
So, you can use paths like this:
cd $HOME
ls Desktop/MyFiles/text.txt
or:
cd $HOME/Desktop/MyFiles
ls text.txt
In either case, ls /etc/passwd
would refer to the same file.
answered Apr 14 at 19:54
waltinatorwaltinator
23.2k74272
23.2k74272
add a comment |
add a comment |
Skipping parts of path cannot be done, that is you cannot do something like cd ~/.../Myfiles
. Suppose you have /home/john/Desktop/Myfiles/
and /home/john/Documents/Myfiles
. When you want to navigate to Myfiles
, which one do you mean ? One in ~/Desktop
or ~/Documents
. Essential reason is because directory structure is organized into a tree, where each preceding element has to have a parent item. Thus, the question becomes who is the parent directory of Myfiles
when there are two of them ?
However, there are several things that help navigating the long pathnames:
- save absolute path to variable. Say
myfiles=/home/john/Desktop/Myfiles
. When you start the shell, you already have$HOME
special variable or you can use tilde expansioncd ~/Desktop/Myfiles
use
pushd
andpopd
. Shell has something known as "directory stack", which can be used to record a sequence of directories. For example, if I do$ pushd /etc
/etc ~
$ pushd /sys/class/backlight/intel_backlight/
/sys/class/backlight/intel_backlight /etc ~
$ pushd .
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc ~Notice that in dirstack the very first item indicates current working directory, while the second item remains unchanged even if you
cd
elsewhere. This is whypushd .
was added. Now, if we navigate elsewhere,/sys/class/backlight/intel_backlight
will be stored on the stack and we can always return to it.# navigate elsewhere after pushd .
$ cd /var/log
$ cd /usr/share
# check what's in the stack
$ echo $DIRSTACK[@]
/usr/share /sys/class/backlight/intel_backlight /etc /home/ubuntuadmin
# go to one of the directories on the stack
$ cd $DIRSTACK[1]
$ pwd
/sys/class/backlight/intel_backlight
# remember that very first item changes, it's the current working directory
$ echo $DIRSTACK[@]
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc /home/ubuntuadminUse symlinks.Example:
$ ln -s /var/log ~/logs
$ cd ~/logsNow instead of doing
cd /var/log
you can docd ~/logs
. Trivial example, but imagine if/var/log
was something like/media/external_harddrive/someproject/subproject/data/bignumbers/calculations/
. We can just docd ~/calculations
then if we have symlink. Of course disadvantage of symlinks is that when directory is renamed or removed, symlink remains and becomes broken, but it's a simple fix - either re-create full path to symlink or remove the symlink and create new one. We can also create a symlink that points to symlink that points to actual directory, but beware that Linux kernel caps too many levels of symlinks ( and you'd get an error that says exactly that) if there are more than 40 symlinks.If the goal is to create a fast way of opening the file
text.txt
the symlink approach can help us with that$ echo 'Hello, this is a test' > ~/Documents/another_directory/file.txt
$ ln -s ~/Documents/another_directory/file.txt ~/file.symlink
$ cat ~/file.symlink
Hello, this is a test
$You can use inode numbers. This is often used to deal with difficult filenames, where quoting and special characters become a problem. For instance, if we know directory's inode
# return $HOME
$ cd
# find the inode
$ ls -id ~/Documents/things
1205421 /home/ubuntuadmin/Documents/things
# go to the directory by inode
$ cd "$(find -inum 1205421)"
$ pwd
/home/ubuntuadmin/Documents/thingsProblem with this approach - it is slow and inefficient, since recursive traversal via
find
and checking all inodes along the way requires time and a lot of syscalls.
Ah it makes sense...so no matter where i am, skipping parts of path is not possible...Thx
– Anhtu
Apr 14 at 22:33
@Anhtu Essentially yes. If you know there's no duplicate, you could docd ~/*/Myfiles
but if there's~/anotherdir/Myfiles
that approach will fail
– Sergiy Kolodyazhnyy
Apr 14 at 22:37
@Anhtu I've added another bullet point, which can be sort of "skipping" but it is slow, inefficient, and essentially is something that goes against Unix/Linux design, so it is used in only special cases - not generally
– Sergiy Kolodyazhnyy
Apr 14 at 22:48
add a comment |
Skipping parts of path cannot be done, that is you cannot do something like cd ~/.../Myfiles
. Suppose you have /home/john/Desktop/Myfiles/
and /home/john/Documents/Myfiles
. When you want to navigate to Myfiles
, which one do you mean ? One in ~/Desktop
or ~/Documents
. Essential reason is because directory structure is organized into a tree, where each preceding element has to have a parent item. Thus, the question becomes who is the parent directory of Myfiles
when there are two of them ?
However, there are several things that help navigating the long pathnames:
- save absolute path to variable. Say
myfiles=/home/john/Desktop/Myfiles
. When you start the shell, you already have$HOME
special variable or you can use tilde expansioncd ~/Desktop/Myfiles
use
pushd
andpopd
. Shell has something known as "directory stack", which can be used to record a sequence of directories. For example, if I do$ pushd /etc
/etc ~
$ pushd /sys/class/backlight/intel_backlight/
/sys/class/backlight/intel_backlight /etc ~
$ pushd .
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc ~Notice that in dirstack the very first item indicates current working directory, while the second item remains unchanged even if you
cd
elsewhere. This is whypushd .
was added. Now, if we navigate elsewhere,/sys/class/backlight/intel_backlight
will be stored on the stack and we can always return to it.# navigate elsewhere after pushd .
$ cd /var/log
$ cd /usr/share
# check what's in the stack
$ echo $DIRSTACK[@]
/usr/share /sys/class/backlight/intel_backlight /etc /home/ubuntuadmin
# go to one of the directories on the stack
$ cd $DIRSTACK[1]
$ pwd
/sys/class/backlight/intel_backlight
# remember that very first item changes, it's the current working directory
$ echo $DIRSTACK[@]
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc /home/ubuntuadminUse symlinks.Example:
$ ln -s /var/log ~/logs
$ cd ~/logsNow instead of doing
cd /var/log
you can docd ~/logs
. Trivial example, but imagine if/var/log
was something like/media/external_harddrive/someproject/subproject/data/bignumbers/calculations/
. We can just docd ~/calculations
then if we have symlink. Of course disadvantage of symlinks is that when directory is renamed or removed, symlink remains and becomes broken, but it's a simple fix - either re-create full path to symlink or remove the symlink and create new one. We can also create a symlink that points to symlink that points to actual directory, but beware that Linux kernel caps too many levels of symlinks ( and you'd get an error that says exactly that) if there are more than 40 symlinks.If the goal is to create a fast way of opening the file
text.txt
the symlink approach can help us with that$ echo 'Hello, this is a test' > ~/Documents/another_directory/file.txt
$ ln -s ~/Documents/another_directory/file.txt ~/file.symlink
$ cat ~/file.symlink
Hello, this is a test
$You can use inode numbers. This is often used to deal with difficult filenames, where quoting and special characters become a problem. For instance, if we know directory's inode
# return $HOME
$ cd
# find the inode
$ ls -id ~/Documents/things
1205421 /home/ubuntuadmin/Documents/things
# go to the directory by inode
$ cd "$(find -inum 1205421)"
$ pwd
/home/ubuntuadmin/Documents/thingsProblem with this approach - it is slow and inefficient, since recursive traversal via
find
and checking all inodes along the way requires time and a lot of syscalls.
Ah it makes sense...so no matter where i am, skipping parts of path is not possible...Thx
– Anhtu
Apr 14 at 22:33
@Anhtu Essentially yes. If you know there's no duplicate, you could docd ~/*/Myfiles
but if there's~/anotherdir/Myfiles
that approach will fail
– Sergiy Kolodyazhnyy
Apr 14 at 22:37
@Anhtu I've added another bullet point, which can be sort of "skipping" but it is slow, inefficient, and essentially is something that goes against Unix/Linux design, so it is used in only special cases - not generally
– Sergiy Kolodyazhnyy
Apr 14 at 22:48
add a comment |
Skipping parts of path cannot be done, that is you cannot do something like cd ~/.../Myfiles
. Suppose you have /home/john/Desktop/Myfiles/
and /home/john/Documents/Myfiles
. When you want to navigate to Myfiles
, which one do you mean ? One in ~/Desktop
or ~/Documents
. Essential reason is because directory structure is organized into a tree, where each preceding element has to have a parent item. Thus, the question becomes who is the parent directory of Myfiles
when there are two of them ?
However, there are several things that help navigating the long pathnames:
- save absolute path to variable. Say
myfiles=/home/john/Desktop/Myfiles
. When you start the shell, you already have$HOME
special variable or you can use tilde expansioncd ~/Desktop/Myfiles
use
pushd
andpopd
. Shell has something known as "directory stack", which can be used to record a sequence of directories. For example, if I do$ pushd /etc
/etc ~
$ pushd /sys/class/backlight/intel_backlight/
/sys/class/backlight/intel_backlight /etc ~
$ pushd .
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc ~Notice that in dirstack the very first item indicates current working directory, while the second item remains unchanged even if you
cd
elsewhere. This is whypushd .
was added. Now, if we navigate elsewhere,/sys/class/backlight/intel_backlight
will be stored on the stack and we can always return to it.# navigate elsewhere after pushd .
$ cd /var/log
$ cd /usr/share
# check what's in the stack
$ echo $DIRSTACK[@]
/usr/share /sys/class/backlight/intel_backlight /etc /home/ubuntuadmin
# go to one of the directories on the stack
$ cd $DIRSTACK[1]
$ pwd
/sys/class/backlight/intel_backlight
# remember that very first item changes, it's the current working directory
$ echo $DIRSTACK[@]
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc /home/ubuntuadminUse symlinks.Example:
$ ln -s /var/log ~/logs
$ cd ~/logsNow instead of doing
cd /var/log
you can docd ~/logs
. Trivial example, but imagine if/var/log
was something like/media/external_harddrive/someproject/subproject/data/bignumbers/calculations/
. We can just docd ~/calculations
then if we have symlink. Of course disadvantage of symlinks is that when directory is renamed or removed, symlink remains and becomes broken, but it's a simple fix - either re-create full path to symlink or remove the symlink and create new one. We can also create a symlink that points to symlink that points to actual directory, but beware that Linux kernel caps too many levels of symlinks ( and you'd get an error that says exactly that) if there are more than 40 symlinks.If the goal is to create a fast way of opening the file
text.txt
the symlink approach can help us with that$ echo 'Hello, this is a test' > ~/Documents/another_directory/file.txt
$ ln -s ~/Documents/another_directory/file.txt ~/file.symlink
$ cat ~/file.symlink
Hello, this is a test
$You can use inode numbers. This is often used to deal with difficult filenames, where quoting and special characters become a problem. For instance, if we know directory's inode
# return $HOME
$ cd
# find the inode
$ ls -id ~/Documents/things
1205421 /home/ubuntuadmin/Documents/things
# go to the directory by inode
$ cd "$(find -inum 1205421)"
$ pwd
/home/ubuntuadmin/Documents/thingsProblem with this approach - it is slow and inefficient, since recursive traversal via
find
and checking all inodes along the way requires time and a lot of syscalls.
Skipping parts of path cannot be done, that is you cannot do something like cd ~/.../Myfiles
. Suppose you have /home/john/Desktop/Myfiles/
and /home/john/Documents/Myfiles
. When you want to navigate to Myfiles
, which one do you mean ? One in ~/Desktop
or ~/Documents
. Essential reason is because directory structure is organized into a tree, where each preceding element has to have a parent item. Thus, the question becomes who is the parent directory of Myfiles
when there are two of them ?
However, there are several things that help navigating the long pathnames:
- save absolute path to variable. Say
myfiles=/home/john/Desktop/Myfiles
. When you start the shell, you already have$HOME
special variable or you can use tilde expansioncd ~/Desktop/Myfiles
use
pushd
andpopd
. Shell has something known as "directory stack", which can be used to record a sequence of directories. For example, if I do$ pushd /etc
/etc ~
$ pushd /sys/class/backlight/intel_backlight/
/sys/class/backlight/intel_backlight /etc ~
$ pushd .
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc ~Notice that in dirstack the very first item indicates current working directory, while the second item remains unchanged even if you
cd
elsewhere. This is whypushd .
was added. Now, if we navigate elsewhere,/sys/class/backlight/intel_backlight
will be stored on the stack and we can always return to it.# navigate elsewhere after pushd .
$ cd /var/log
$ cd /usr/share
# check what's in the stack
$ echo $DIRSTACK[@]
/usr/share /sys/class/backlight/intel_backlight /etc /home/ubuntuadmin
# go to one of the directories on the stack
$ cd $DIRSTACK[1]
$ pwd
/sys/class/backlight/intel_backlight
# remember that very first item changes, it's the current working directory
$ echo $DIRSTACK[@]
/sys/class/backlight/intel_backlight /sys/class/backlight/intel_backlight /etc /home/ubuntuadminUse symlinks.Example:
$ ln -s /var/log ~/logs
$ cd ~/logsNow instead of doing
cd /var/log
you can docd ~/logs
. Trivial example, but imagine if/var/log
was something like/media/external_harddrive/someproject/subproject/data/bignumbers/calculations/
. We can just docd ~/calculations
then if we have symlink. Of course disadvantage of symlinks is that when directory is renamed or removed, symlink remains and becomes broken, but it's a simple fix - either re-create full path to symlink or remove the symlink and create new one. We can also create a symlink that points to symlink that points to actual directory, but beware that Linux kernel caps too many levels of symlinks ( and you'd get an error that says exactly that) if there are more than 40 symlinks.If the goal is to create a fast way of opening the file
text.txt
the symlink approach can help us with that$ echo 'Hello, this is a test' > ~/Documents/another_directory/file.txt
$ ln -s ~/Documents/another_directory/file.txt ~/file.symlink
$ cat ~/file.symlink
Hello, this is a test
$You can use inode numbers. This is often used to deal with difficult filenames, where quoting and special characters become a problem. For instance, if we know directory's inode
# return $HOME
$ cd
# find the inode
$ ls -id ~/Documents/things
1205421 /home/ubuntuadmin/Documents/things
# go to the directory by inode
$ cd "$(find -inum 1205421)"
$ pwd
/home/ubuntuadmin/Documents/thingsProblem with this approach - it is slow and inefficient, since recursive traversal via
find
and checking all inodes along the way requires time and a lot of syscalls.
edited Apr 14 at 22:47
answered Apr 14 at 21:17
Sergiy KolodyazhnyySergiy Kolodyazhnyy
76.2k10161336
76.2k10161336
Ah it makes sense...so no matter where i am, skipping parts of path is not possible...Thx
– Anhtu
Apr 14 at 22:33
@Anhtu Essentially yes. If you know there's no duplicate, you could docd ~/*/Myfiles
but if there's~/anotherdir/Myfiles
that approach will fail
– Sergiy Kolodyazhnyy
Apr 14 at 22:37
@Anhtu I've added another bullet point, which can be sort of "skipping" but it is slow, inefficient, and essentially is something that goes against Unix/Linux design, so it is used in only special cases - not generally
– Sergiy Kolodyazhnyy
Apr 14 at 22:48
add a comment |
Ah it makes sense...so no matter where i am, skipping parts of path is not possible...Thx
– Anhtu
Apr 14 at 22:33
@Anhtu Essentially yes. If you know there's no duplicate, you could docd ~/*/Myfiles
but if there's~/anotherdir/Myfiles
that approach will fail
– Sergiy Kolodyazhnyy
Apr 14 at 22:37
@Anhtu I've added another bullet point, which can be sort of "skipping" but it is slow, inefficient, and essentially is something that goes against Unix/Linux design, so it is used in only special cases - not generally
– Sergiy Kolodyazhnyy
Apr 14 at 22:48
Ah it makes sense...so no matter where i am, skipping parts of path is not possible...Thx
– Anhtu
Apr 14 at 22:33
Ah it makes sense...so no matter where i am, skipping parts of path is not possible...Thx
– Anhtu
Apr 14 at 22:33
@Anhtu Essentially yes. If you know there's no duplicate, you could do
cd ~/*/Myfiles
but if there's ~/anotherdir/Myfiles
that approach will fail– Sergiy Kolodyazhnyy
Apr 14 at 22:37
@Anhtu Essentially yes. If you know there's no duplicate, you could do
cd ~/*/Myfiles
but if there's ~/anotherdir/Myfiles
that approach will fail– Sergiy Kolodyazhnyy
Apr 14 at 22:37
@Anhtu I've added another bullet point, which can be sort of "skipping" but it is slow, inefficient, and essentially is something that goes against Unix/Linux design, so it is used in only special cases - not generally
– Sergiy Kolodyazhnyy
Apr 14 at 22:48
@Anhtu I've added another bullet point, which can be sort of "skipping" but it is slow, inefficient, and essentially is something that goes against Unix/Linux design, so it is used in only special cases - not generally
– Sergiy Kolodyazhnyy
Apr 14 at 22:48
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1133888%2fcan-relative-path-access-more-than-one-level%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown