Skip to content
EntityQ283438· pop 32· linked from 323 articles

Also known as CHDIR(), change directory, A Quick Introduction to Unix/Changing Directories

command of Unix, DOS, OS/2, AmigaOS, Windows, and Linux operating systems

Key facts

Developers
AT&T Bell Laboratories , MetaComCo , Microsoft , IBM , DR , Novell , HP , JP Software , ReactOS Contributors
Operating system
Unix , Unix-like , V , DOS , MSX-DOS , FlexOS , OS/2 , TRIPOS , Windows , MPE/iX , Plan 9 , Inferno , ReactOS , KolibriOS , SymbOS
Platform
Cross-platform
Type
Command

via Wikipedia infobox

Described at

5. Starting with the first pathname in the -separated pathnames of CDPATH (see the ENVIRONMENT VARIABLES section) if the pathname is non-null, test if the concatenation of that pathname, a character if that pathname did not end with a character, and the directory operand names a directory. If the pathname is null, test if the concatenation of dot, a character, and the operand names a directory. In either case, if the resulting string names an existing directory, set curpath to that string and proceed to step 7. Otherwise, repeat this step with the next pathname in CDPATH until all pathnames have been tested. 1. Dot components and any characters that separate them from the next component shall be deleted. 2. The preceding component, all characters separating the preceding component from dot-dot, dot-dot, and all characters separating dot-dot from the following component (if any) shall be deleted. 9. If curpath is longer than {PATH MAX} bytes (including the terminating null) and the directory operand was not longer than {PATH MAX} bytes (including the terminating null), then curpath shall be converted from an absolute pathname to an equivalent relative pathname if possible. This conversion shall always be considered possible if the value of PWD, with a trailing added if it does not already have one, is an initial substring of curpath . Whether or not it is considered possible under other circumstances is unspecified. Implementations may also apply this conversion if curpath is not longer than {PATH MAX} bytes or the directory operand was longer than {PATH MAX} bytes. If, during the execution of the above steps, the PWD environment variable is set, the OLDPWD environment variable shall also be set to the value of the old working directory (that is the current working directory immediately prior to the call to cd ). Handle the operand dot-dot logically; symbolic link components shall not be resolved before dot-dot components are processed (see steps 8. and 9. in the DESCRIPTION). Handle the operand dot-dot physically; symbolic link components shall be resolved before dot-dot components are processed (see step 7. in the DESCRIPTION). which changes to the previous working directory and then writes its name. The name of the directory, used when no directory operand is specified. Provide a default value for the internationalization variables that are unset or null. (See XBD Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) If set to a non-empty string value, override the values of all the other internationalization variables. Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. [XSI) ] ![[Option Start]]( Determine the location of message catalogs for the processing of LC MESSAGES. ![[Option End]]( The use of the CDPATH was introduced in the System V shell. Its use is analogous to the use of the PATH variable in the shell. The BSD C shell used a shell parameter cdpath for this purpose. This behavior is now the default. It is not consistent with the definition of dot-dot in most historical practice; that is, while this behavior has been optionally available in the KornShell, other shells have historically not supported this functionality. The logical pathname is stored in the PWD environment variable when the cd utility completes and this value is used to construct the next directory name if cd is invoked with the -L option. The -L and -P options are added to align with the IEEE P1003.2b draft standard. This also includes the introduction of a new description to include the effect of these options. IEEE Std 1003.1-2001/Cor 1-2002, item XCU/TC1/D6/14 is applied, changing the SYNOPSIS to make it clear that the -L and -P options are mutually-exclusive. Austin Group Interpretation 1003.1-2001 199 is applied, clarifying how the cd utility handles concatenation of two pa

Excerpt from a page describing this subject · 15,734 chars · not written by Vinony

Wikidata facts

Image
Cd command.png
Show 4 more facts
Sources (5)

via Wikidata · CC0

Article · 日本語

cd(シーディー、change directory)は、シェル等の(プロセスの)現在のワーキングディレクトリ(カレントディレクトリ)を変更するコマンドである。chdir という名前だったりそのような別名があることもある。原理的に外部コマンドとして実装することが不可能であり、かならずシェル等の内部コマンド(ビルトインコマンド、en:Shell builtin)として実装される。 ディレクトリはファイルシステム中の論理的な区分であり、ファイルを保持するために使われる。ディレクトリは他のディレクトリをも含めることができる。cdコマンドはサブディレクトリ(子ディレクトリ)に移動したり、親ディレクトリに移動したり、ルートディレクトリ(すべてのディレクトリの祖先ディレクトリ)に一気に移動したり、ある与えられたディレクトリに移動したりすることができる。 次の図は何らかのファイルシステムの一部分を示している。1つのファイル ("text.txt")と3つのサブディレクトリを含むユーザのホームディレクトリ(~で表している)が示されている。 もしカレントディレクトリがホームディレクトリ(~)であれば、「cd games」というコマンドを実行した後で「ls」と実行すると、例えば次のような結果が得られる。 me@host:~$ lsworkreports games encyclopedia text.txtme@host:~$ cd gamesme@host:games$ ユーザはこの時点で"games"ディレクトリにいる。似たようなことをMS-DOSで実行すると次のようになる。MS-DOSにはバージョンによってホームディレクトリの概念が存在しないこともある。 C:\>dirworkreports Wed Oct 9th 9:01games Tue Oct 8th 14:32encyclopedia Mon Oct 1st 10:05text txt 1903 Thu Oct10th 12:43C:\>cd gamesC:\games> cdに引数を与えずに実行した場合、システムによって異なる振る舞いをする。例えばMS-DOSやWindowsではカレントドライブとそのカレントディレクトリが、その絶対パスの文字列で表示される(Unixのpwdに類似)。Unixではシェル変数 $HOME に設定されたディレクトリ(通常はユーザのホームディレクトリがログイン時に環境変数として設定されている)に移動する。 バッチファイルやシェルスクリプト内でcdが実行された場合の効果もシステムによって異なる、というように考える者がいるようだが、シングルタスクのMS-DOSで学習した結果、根本的にプロセスの概念をわかっていないと、そのような把握になるものと思われる。すなわち、MS-DOSのバッチファイルはサブプロセスとして実行されるのではなく、そのシェル自身の入力を一時的に切替えるだけのものであるため、バッチファイル内でのcdコマンドはそのシェル自身に影響する。Unixのシェルでは普通、シェルスクリプトをそのシェル自身に対するコマンド列として実行するか( source あるいは . コマンド)、サブプロセスとして実行されるシェル(サブシェル)で実行するか(通常の外部コマンドのようにして実行した場合)を選べるため、結果はそれに応じて異なる。

Abstract from DBpedia / Wikipedia · CC BY-SA

cd · Vinony