LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-22-2019, 07:40 AM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Rep: Reputation: 56
Changing directories - any Shortcuts available?


Hello

Assuming I have two directory structures:
1. /one/two/three/four/five/six/seven/eight
2. /one/two/three/aaa/bbb/ccc/ddd/eee

If my present working directory is eight and I want to go to directory eee. Then is there any other way to do this?

Code:
cd ../../../../../aaa/bbb/ccc/ddd/eee
Is there any possibility of shortening the relative path pattern "../" which is 5 times? No absolute path though.

Thanks
 
Old 01-22-2019, 07:54 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by ddenial View Post
Hello

Assuming I have two directory structures:
1. /one/two/three/four/five/six/seven/eight
2. /one/two/three/aaa/bbb/ccc/ddd/eee

If my present working directory is eight and I want to go to directory eee. Then is there any other way to do this?

Code:
cd ../../../../../aaa/bbb/ccc/ddd/eee
Is there any possibility of shortening the relative path pattern "../" which is 5 times? No absolute path though.

Thanks
Why can't you use the absolute path?
Code:
cd /one/two/three/aaa/bbb/ccc/ddd/eee

Last edited by TenTenths; 01-22-2019 at 07:55 AM.
 
1 members found this post helpful.
Old 01-22-2019, 08:07 AM   #3
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
If you need to go to /one/two/three/aaa/bbb/ccc/ddd/eee very often, you can create an alias:
Code:
alias cdeee='cd /one/two/three/aaa/bbb/ccc/ddd/eee'
Next times you can simply type:
Code:
cdeee
 
1 members found this post helpful.
Old 01-22-2019, 08:12 AM   #4
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by TenTenths View Post
Why can't you use the absolute path?
Code:
cd /one/two/three/aaa/bbb/ccc/ddd/eee
Yes, I can. But I'm curious in knowing is there another way to shortcut relative path. Like this one for renaming filenames.
 
Old 01-22-2019, 08:17 AM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by ddenial View Post

Is there any possibility of shortening the relative path pattern "../" which is 5 times? No absolute path though.
I can't imagine a reason for not using absolute paths. Except perhaps an exam question.

You can set CDPATH to /one/two/three/aaa/bbb/ccc/ddd. Then, a simple cd eee does the trick. Or you set a symbolic link, or even a bind mount.
 
1 members found this post helpful.
Old 01-22-2019, 09:37 AM   #6
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
You might like autojump.

Also available in many distros via package management

Last edited by joe_2000; 01-22-2019 at 09:38 AM. Reason: added further info
 
1 members found this post helpful.
Old 01-22-2019, 09:53 AM   #7
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by joe_2000 View Post
You might like autojump.

Also available in many distros via package management
I was looking at CDPATH and alias as explained in this website, but this looks interesting.

Thanks.
 
Old 01-22-2019, 10:00 AM   #8
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by ddenial View Post
Is there any possibility of shortening the relative path pattern "../" which is 5 times?
You already got pointed to the CDPATH variable, in which you can specify directories to look in for the cd command. I use
Code:
.:~:..:../..:../../..:../../../..:../../../../..:/mnt
which will look in current and 5 directories up (plus my home and /mnt for USB sticks),
but maybe something like wcd (a Norton CD fork) waterlan.home.xs4all.nl/ is something for you? It works by creating a database of your directories and then allowing short versions of their names to cd to them.
 
1 members found this post helpful.
Old 01-22-2019, 10:19 AM   #9
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by ehartman View Post
You already got pointed to the CDPATH variable, in which you can specify directories to look in for the cd command. I use
Code:
.:~:..:../..:../../..:../../../..:../../../../..:/mnt
which will look in current and 5 directories up (plus my home and /mnt for USB sticks),
but maybe something like wcd (a Norton CD fork) waterlan.home.xs4all.nl/ is something for you? It works by creating a database of your directories and then allowing short versions of their names to cd to them.
Thanks. But how to use it. I'm confused.
Code:
$ mkdir -p one/two/three/four/five/six/seven/eight
$ mkdir -p one/two/three/aaa/bbb/ccc/ddd/eee
$ export CDPATH=.:~:..:../..:../../..:../../../..:../../../../..
$ cd one/two/three/four/five/six/seven/eight

$ pwd
/home/alex/one/two/three/four/five/six/seven/eight

$ cd ../eee
-bash: cd: ../eee: No such file or directory

$ cd eee
-bash: cd: eee: No such file or directory

$ cd ddd
-bash: cd: ddd: No such file or directory

$ cd ..eee
-bash: cd: ..eee: No such file or directory

$ cd .eee
-bash: cd: .eee: No such file or directory
How to use this?
 
Old 01-22-2019, 10:31 AM   #10
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
^ Configured like that, I think only the following should work in your situation (from pwd=/home/alex/one/two/three/four/five/six/seven/eight):
Code:
cd aaa
Right?

Last edited by l0f4r0; 01-22-2019 at 10:32 AM.
 
1 members found this post helpful.
Old 01-22-2019, 10:39 AM   #11
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by l0f4r0 View Post
^ Configured like that, I think only the following should work in your situation (from pwd=/home/alex/one/two/three/four/five/six/seven/eight):
Code:
cd aaa
Right?
Oh! Now I understand, I need to add some more '../'s.

Thanks. Working great.
 
Old 01-22-2019, 10:48 AM   #12
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
^ Yes, so for your specific need, you will have to do:
Code:
cd aaa/bbb/ccc/ddd/eee
Here, the benefit is so-so compared to:
Code:
cd /one/two/three/aaa/bbb/ccc/ddd/eee

Last edited by l0f4r0; 01-22-2019 at 10:51 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Any command available to find out the number of inodes available in the system? Marty21 Linux - Newbie 3 01-09-2009 07:31 PM
Shortcuts for changing encoding in Konqueror Mogaba Linux - Newbie 0 02-04-2008 01:16 PM
Can't create shortcuts to directories on the Desktop! lma10110 Linux - Newbie 1 09-23-2005 02:15 PM
Changing icons for shortcuts and adding applications to KDE panel linuxRunner Linux - Newbie 5 07-31-2004 12:36 PM
Changing keyboard menu shortcuts in KDE/Gnome apps? kkant Linux - Software 3 10-07-2003 09:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration