m@mariachi:~/test/5/4/3/2/1$ pwd
/home/m/test/5/4/3/2/1
m@mariachi:~/test/5/4/3/2/1$ for i in {1..3}; do cd ../; done
m@mariachi:~/test/5/4$ pwd
/home/m/test/5/4
...however I don't think it will be much faster than typing cd and .. then hitting tab for each level you want to go up!! :)
All right, another really funny answer, that is really a one-liner, to go up 42 parent directories:
cd $(yes ../|head -42|tr -d \\n)
Same as gniourf_gniourf's other answer, it's cd - friendly (and it's just a couple characters longer than the shortest answer).
Replace 42 with your favorite number.
Now that you understood the amazing power of the wonderful command yes, you can join the dark side and use the evil command eval, and while we're at it we can use the terrible backticks:
eval `yes 'cd ..;'|head -42`
This is so far the shortest one-liner, but it's really bad: it uses eval, backticks and it's not cd - friendly. But hey, it works really well and it's funny!
How often do you go up more than five levels? If the answer is Not too often I suggest you place these
cd -
friendly aliases in your profile:Advantages
A funny way:
How does it work?
a
with$1
spaces.cd
where each space ina
has been replaced with../
.Use as:
to go up to forty-second parent directory.
The pro of this method is that you'll still be able to
cd -
to come back to previous directory, unlike the methods that use a loop.Absolutely worth putting in your
.bashrc
. Or not.you can use a singleline
for
loop:..replace the
3
with yourn
for example:
...however I don't think it will be much faster than typing
cd
and..
then hittingtab
for each level you want to go up!! :)I am not aware of any command that does that, but it is easy to create one yourself. For example, just add
in your
~/.bashrc
file, and after you create a new shell you can just runand you will move up by
N
directoriesAll right, another really funny answer, that is really a one-liner, to go up 42 parent directories:
Same as gniourf_gniourf's other answer, it's
cd -
friendly (and it's just a couple characters longer than the shortest answer).Replace
42
with your favorite number.Now that you understood the amazing power of the wonderful command
yes
, you can join the dark side and use the evil commandeval
, and while we're at it we can use the terrible backticks:This is so far the shortest one-liner, but it's really bad: it uses
eval
, backticks and it's notcd -
friendly. But hey, it works really well and it's funny!You sure can define a function to do that: