- relative path names
- the '.' notation refers to the current directory.
what is the difference between pwd and cd ?
조회 수: 18 (최근 30일)
이전 댓글 표시
what is the difference between pwd and cd ? I get the same folder when I tyoe command in MATLAB.
댓글 수: 0
답변 (3개)
Stephen23
2016년 3월 21일
편집: Stephen23
2016년 3월 21일
Actually pwd just calls cd internally, so there is no real difference.
However I would suggest using pwd: Changing directories is a very slow way to write code (it is much faster to pass relative/absolute paths to any functions that access files of any kind), so using pwd has the advantage that it stylistically make it clear "this does NOT change the directory, we just need the path...".
In other words, using pwd encourages better programming habits.
Some faster alternatives to cd / pwd:
댓글 수: 0
Nina
2025년 7월 10일
pwd stands for "Print Working Directory", while cd stands for "Change Directory". Use pwd to see what folder you are currently in and use cd to go to a different folder. For example use cd .. to go up one folder or cd Desktop/ to go to your desktop.
댓글 수: 2
Walter Roberson
2025년 7월 10일
편집: Walter Roberson
2025년 7월 10일
cd Desktop/
will attempt to switch directories to the directory named Desktop underneath the current directory.
For MacOS and Linux,
cd ~/Desktop
which change directories to your desktop
As far as I know, there is no Windows equivalent to the ~ shortcut.
Walter Roberson
2025년 7월 10일
편집: Walter Roberson
2025년 7월 10일
if ispc()
cd( fullfile(getenv('userprofile'), 'Desktop'))
else
cd ~/Desktop
end
Walter Roberson
2025년 7월 10일
Both cd and pwd come from Unix.
Historically cd in Unix was used to change directories, and had no ability to return the name of the current directory. Historically cd in Unix with no parameters changed directories to the "home" directory.
Historically pwd in Unix was used to return the name of the current directory.
As implemented in MATLAB, cd is primarily used to change directories, and primarily returns the old directory, but cd with no parameters returns the current directory.
As implemented in MATLAB, pwd returns the current directory, with no option for changing directory.
Functionally, in MATLAB, you can use cd with no parameters interchangeably with pwd with no parameters. The reason pwd still exists is a convenience
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!