LinuxQuestions.org
Visit Jeremy's Blog.
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 03-13-2014, 02:50 PM   #16
jefro
Moderator
 
Registered: Mar 2008
Posts: 16,489

Rep: Reputation: 2412Reputation: 2412Reputation: 2412Reputation: 2412Reputation: 2412Reputation: 2412Reputation: 2412Reputation: 2412Reputation: 2412Reputation: 2412Reputation: 2412

I like to call them dot and dot dot.
 
Old 03-13-2014, 10:34 PM   #17
Zaheen Abbas
LQ Newbie
 
Registered: Jan 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Question is why Linux is executing something um-necessarily?
 
Old 03-13-2014, 10:38 PM   #18
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,484

Rep: Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089
Because you told it to
 
2 members found this post helpful.
Old 03-13-2014, 10:54 PM   #19
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 664

Rep: Reputation: 81
@OP: the answer should be:

"cd" has this in its definition to toggle to parameter's location if it is a directory. thats it the code fo cd ends there.

As far as dot is concerned it is linux's definition that dot would represent current directory and double dot has the source to the current directory and cd has nothing to do with this, it is doing what it is told..
 
Old 03-14-2014, 02:30 AM   #20
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,349

Rep: Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748
Quote:
Originally Posted by Zaheen Abbas View Post
Question is why Linux is executing something um-necessarily?
Do you think linux should know what is necessary and what is something unnecessary? Do you think linux should display:
"Hey guy, it has no meaning, I won't do that for you!"
Or what do you expect? As I told you already checking is much more expensive than simply executing the command itself without guessing its necessity.
From the other hand cd . is not a noop, but it will check some permissions, therefore in some cases there can be a reason to execute it and the result is not unambiguous.
 
1 members found this post helpful.
Old 03-14-2014, 03:03 AM   #21
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,329
Blog Entries: 1

Rep: Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327
If you drove your car around the block and returned to the starting point, would you expect the car to refuse to follow such an unnecessary path and give you a warning, "Sorry Dave, I am not able to do that..."?
 
Old 03-15-2014, 01:26 AM   #22
Zaheen Abbas
LQ Newbie
 
Registered: Jan 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
I think, people out here are more in telling me the stories and giving me waste examples. This was a question asked in an interview by Red Hat only. I hope now this question may make sense to you. Please do not reply with the other car type examples. The question he asked was forcing to reply why it executes which certainly takes time, process, memory etc....
 
Old 03-15-2014, 01:37 AM   #23
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,329
Blog Entries: 1

Rep: Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327
Quote:
Originally Posted by Zaheen Abbas View Post
I think, people out here are more in telling me the stories and giving me waste examples. This was a question asked in an interview by Red Hat only. I hope now this question may make sense to you. Please do not reply with the other car type examples. The question he asked was forcing to reply why it executes which certainly takes time, process, memory etc....
Oh, well, if RED HAT asked the question in an interview, then certainly we must all be mistaken! Why didn't you say so? That changes everything!

I saw no waste examples and I just went back and read the whole thread again thinking that I had missed or mis-read something. All I see are people trying to help you understand how this works, and is intended to work in a GNU/Linux system. The examples were intended to help you understand by analogy, as mine was intended. I am sorry if you thought our help was a waste, apparently the real waste was of our time...

Last edited by astrogeek; 03-15-2014 at 01:56 AM.
 
2 members found this post helpful.
Old 03-15-2014, 03:48 AM   #24
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 664

Rep: Reputation: 81
Arrow

Quote:
Originally Posted by Zaheen Abbas View Post
The question he asked was forcing to reply why it executes which certainly takes time, process, memory etc....
If this is the question asked, my answer would be:
i cant see any use of executing it apart from just to check what cd does when a current directory call initiates!!, and guess what i can see is "cd" is doing its job and dot(.) is proving what it is meant for, there is nothing more into it.


I did saw some of the excellent information shared on this thread for an explanation on dot and double dot.

@Astrogeeks: your example was good enough to let any newbie know why it happened.


i would appreciate any other member correct me if i mistaken somewhere

Last edited by SAbhi; 03-15-2014 at 03:50 AM.
 
Old 03-15-2014, 04:49 AM   #25
nigelc
Member
 
Registered: Oct 2004
Location: Sydney, Australia
Distribution: Mageia 4
Posts: 347
Blog Entries: 4

Rep: Reputation: 63
Quote:
Originally Posted by Zaheen Abbas View Post
I think, people out here are more in telling me the stories and giving me waste examples. This was a question asked in an interview by Red Hat only. I hope now this question may make sense to you. Please do not reply with the other car type examples. The question he asked was forcing to reply why it executes which certainly takes time, process, memory etc....
If you can't answer this question, then you shouldn't be at the interview at all.
 
Old 03-15-2014, 07:49 AM   #26
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 823

Rep: Reputation: 237Reputation: 237Reputation: 237
One thought on the performance question. It's obviously a quite theoretical discussion as the performance hit is obviously minimal, but I think the performance hit of checking for this special case in every call to cd would be even less desirable...

Last edited by joe_2000; 03-15-2014 at 01:06 PM. Reason: typo
 
Old 03-15-2014, 09:54 AM   #27
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,696

Rep: Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261
Not that theoretical.

I use it during debugging scripts where the script expects to move to a working directory for operation...

during debuggging I don't want it to move - it may be a configuration item, in which case the directory changes.

During debugging I don't want it to change.
 
Old 03-15-2014, 09:59 AM   #28
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,436

Rep: Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507
How would you know that the shell didn't silently ignore your extraneous "cd ." command? There is no error message because doing that is not an error, but did the shell actually do anything (or, did someone actually put in the wasteful and truly pointless code to check for that special case)?
 
Old 03-15-2014, 12:58 PM   #29
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 664

Rep: Reputation: 81
@Jpollard: but the questn why cd . has been executed ???
should have one answer that cd has done what it is told.

Last edited by SAbhi; 03-15-2014 at 01:00 PM.
 
Old 03-15-2014, 02:02 PM   #30
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,349

Rep: Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748
Code:
mkdir -p /tmp/aaa/bbb
cd /tmp/aaa/bbb
sudo chown root /tmp/aaa
sudo chmod 700 /tmp/aaa
cd .
cd $PWD
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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




All times are GMT -5. The time now is 10:28 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration