LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   General enquery abt the path in linux server. (https://www.linuxquestions.org/questions/linux-newbie-8/general-enquery-abt-the-path-in-linux-server-4175459756/)

linishjacob88 04-27-2013 02:30 AM

General enquery abt the path in linux server.
 
hi,

Is there any method to go to the path without entering the CD command in linux.

Eg:/]# bin :like this
/bin]#


without entering cd bin

shivaa 04-27-2013 03:39 AM

Why? What's purpose of doing this? The cd command stands for change directory and is build for purpose of changing the directory.

linishjacob88 04-27-2013 04:00 AM

hi,

my intention that, we can change the path very easily. no need to enter the whole path,
were the file is existin
i saw somewhere that, without enterin the cd/whole path they changed the path

is there any scriptin for that?

can we switch from one t other without usin cd/whole command..?

like====cd home/bin/crbt/cfg

can we go to cfg directly without using all these ??

unSpawn 04-27-2013 04:17 AM

See 'man bash' about "CDPATH" ?

Madhu Desai 04-27-2013 04:26 AM

I use alias for quick directory change. following lines i have inserted in '/etc/profile' and '/etc/bashrc'
Code:

alias cdkvm="cd /var/lib/libvirt/images"
alias cdftp="cd /var/ftp/pub"
alias cdwww="cd /var/www/html"
alias cdrep="cd /etc/yum.repos.d"
alias cdnet="cd /etc/sysconfig/network-scripts"

At terminal, you can also use following command to toggle between the last two directories
Code:

$ cd -

unSpawn 04-27-2013 04:59 AM

Quote:

Originally Posted by mddesai (Post 4939828)
I use alias for quick directory change.

Doesn't beat using CDPATH IMHO. Try it.

Madhu Desai 04-27-2013 05:29 AM

Quote:

Originally Posted by unSpawn (Post 4939839)
Doesn't beat using CDPATH IMHO. Try it.

Tutorial: How to set and use the Linux CDPATH variable with bash
Code:

[root@srv ~]# export CDPATH=$CDPATH:/etc:/var

[root@srv ~]# echo $CDPATH
:/etc:/var

[root@srv ~]# pwd
/root

[root@srv ~]# cd images
bash: cd: images: No such file or directory

[root@srv ~]# cd pub
bash: cd: pub: No such file or directory

[root@srv ~]# cd html
bash: cd: html: No such file or directory

[root@srv ~]# cd yum.repos.d
/etc/yum.repos.d

[root@srv yum.repos.d]# cd network-scripts
bash: cd: network-scripts: No such file or directory

Path for leaf directories are as stated in post #5. What i'm doing wrong...? :scratch:

Thanks.

Madhu Desai 04-27-2013 06:27 AM

OK. I resolved the problem.

The problem was
Code:

[root@srv]# find /var /etc -type d -name images -print 2>/dev/null | wc -l
15
[root@srv]# find /var /etc -type d -name html -print 2>/dev/null | wc -l
2

so i changed path, its working fine now

Code:

export CDPATH=$CDPATH:/var/lib/libvirt:/var/ftp:/var/www:/etc/yum.repos.d:/etc/sysconfig
@unSpawn Thanks very much. Its really a cooool command.

shivaa 04-27-2013 07:42 AM

@linishjacob88:
In addition to setting CDPATH variable, you can also learn about types of paths i.e. absolute and relative paths (see here).
Code:

~$ pwd
/home/user
~$ cd ./some_directory    ## Use of relative path i.e. equivalent to /home/user/some_directory

Also you can:
Code:

~$ cd /home/user
~$ cd ~  ## Same as /home/user


linishjacob88 04-27-2013 11:31 PM

Hi,

Thanks all for your valued information.@unSpawn,@mddesai,@shivaa....Let me try..


All times are GMT -5. The time now is 08:02 AM.