Skip to content
class method

FileUtils.cd

(::FileUtils::path dir, ?verbose: ::boolish) -> void
[X] (::FileUtils::path dir, ?verbose: ::boolish) { (::String) -> X } -> X
cd(dir, verbose: nil) { |dir| ... }

Changes the working directory to the given dir, which should be interpretable as a path:

With no block given, changes the current directory to the directory at dir; returns zero:

Example
FileUtils.pwd # => "/rdoc/fileutils"
FileUtils.cd('..')
FileUtils.pwd # => "/rdoc"
FileUtils.cd('fileutils')

With a block given, changes the current directory to the directory at dir, calls the block with argument dir, and restores the original current directory; returns the block’s value:

Example
FileUtils.pwd                                     # => "/rdoc/fileutils"
FileUtils.cd('..') { |arg| [arg, FileUtils.pwd] } # => ["..", "/rdoc"]
FileUtils.pwd                                     # => "/rdoc/fileutils"

Keyword arguments:

  • verbose: true - prints an equivalent command:

    Example
    FileUtils.cd('..')
    FileUtils.cd('fileutils')
    

    Output:

    cd ..
    cd fileutils

Related: FileUtils.pwd.

See also #cd .chdir .chmod also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0