May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Cd Command

News Advanced Unix filesystem navigation Recommended Links Pushd, popd and dirs


History command Regular expressions Command completion Directory favorites
ls Bash history and bang commands fc command Unix Shell Tips and Tricks Bash Tips and Tricks Tips Horror Stories Humor Etc

The road to hell is paved with good intentions

Unix cd looks like an extremely primitive, elementary command, but it is not. Because as a mean of navigation of Unix filesystem it is hopelessly outdated, and environment in which it operated is extremely complex. Both sysadmin and regular users working on command like probably type this command more then any other. most of this typing is iether unnecessary or redundant. there are better ways to navigate Unix filesystem.  See Norton Change Directory (NCD) clones and Orthodox File Managers for some ideas.

Another valuable idea is the idea of  Directory favorites and in the most  primitive form it can implemented with  Pushd, popd and dirs

An that only a start ;-). You can also try to use for simplification of navigation  cdpathRegular expressions and Command completion. Previous cd commands are available from the history, unless suppressed with special option. 

Since bash 4.0 if you set option autocd (by default it is off):

shopt -s autocd

In this case you can type the name of directory without prefixing it with it cd. If you name directories with the first upper case letter that can save you a lot keystrokes.

Now you probably syspect that cd is very complex command. And  that is true because the environment in which it operates is so complex.  See Sysadmin Horror Stories. some of them involve mistyped, or misunderstood cd command.

If you still have some doubts that cd is a non-trivial command please try to do the following experiment:

  1. Create /Fav directory
  2. Symlink /etc/sysconfig to it using for example command
    ln -s /etc/sysconfig /Fav/sysconf
  3. cd  /Fav/sysconf
  4. pwd; ls
  5. cd .. 
  6. pwd

Now compare the behaviour of the system with your expectations.  Did you expect that cd will follow symlink back?  To do so you need that command maintain some internal stack of visited directories and remember from which directory you come, because in no way /Fav is the parent directory of /etc/sysconfig.


There are several important shortcuts (see Advanced Unix filesystem navigation for details)

cd ~  # cd to home directory
cd    # same thing
cd -  # change to previous directory (see also pushd and popd directory stack commands)
cd /etc # change to absolute path 


  1. You can create an alias for cd that prints your current directory name after you have changed directory:
    alias cdp `cd \!* && pwd'
  2. Often you cd directory and ls it. You can do it with one command
    alias cdl `cd \!* && ls'

    Relative path and CDPATH

    cd mypath # change to relative path. 
    If CDPATH environment variable is defined, then all directories in that path will be searched for the subdirectory when a relative cd is executed:
    > export CDPATH=~/docs > cd a_doc_subdir # will work even when not in ~/docs 
    You can also use regular expressions in specifying the directory, for example
    cd /usr/l*/b* 
    Standard Wildcards (globbing patterns, see Regular expresstion for details)

    Standard wildcards (also known as globbing patterns) are used by various command line utilities to work with multiple files. For more information on standard wildcards (globbing patterns) refer to the manual page by typing:

    man 7 glob
    ? (question mark)
    this can represent any single character. If you specified something at the command line like "hd?" GNU/Linux would look for hda, hdb, hdc and every other letter/number between a-z, 0-9.
    * (asterisk)
    this can represent any number of characters (including zero, in other words, zero or more characters). If you specified a "cd*" it would use "cda", "cdrom", "cdrecord" and anything that starts with "cd" also including "cd" itself. "m*l" could by mill, mull, ml, and anything that starts with an m and ends with an l.
    [ ] (square brackets)
    specifies a range. If you did m[a,o,u]m it can become: mam, mum, mom if you did: m[a-d]m it can become anything that starts and ends with m and has any character a to d in-between. For example, these would work: mam, mbm, mcm, mdm. This kind of wildcard specifies an "or" relationship (you only need one to match).
    { } (curly brackets)
    terms are separated by commas and each term must be the name of something or a wildcard. This wildcard will copy anything that matches either wildcard(s), or exact name(s) (an "or" relationship, one or the other).

    For example, this would be valid:

    cp {*.doc,*.pdf} ~

    This will copy anything ending with .doc or .pdf to the users home directory. Note that spaces are not allowed after the commas (or anywhere else).

    This construct is similar to the [ ] construct, except rather than matching any characters inside the brackets, it'll match any character, as long as it is not listed between the [ and ]. This is a logical NOT. For example rm myfile[!9] will remove all myfiles* (ie. myfiles1, myfiles2 etc) but won't remove a file with the number 9 anywhere within it's name.
    \ (backslash)
    is used as an "escape" character, i.e. to protect a subsequent special character. Thus, "\\" searches for a backslash. Note you may need to use quotation marks and backslash(es).

    The pwd Command

    The name of the current directory in which you are working is probably the most basic piece of information about your current environment. You can use the pwd (print current directory) command to show the name of your current (working) directory.

    On a UNIX system, files are stored in various directories. At any given time, just one of these directories is your current working directory. And your shell commands affect the files and subdirectories in this working area. When you log on to the system, the current directory is your home directory, where you have full rights to do whatever you want to the files and subdirectories there. You can move from directory to directory using the cd command, discussed in a later section in this chapter. It is generally a good idea to make sure that you have landed in the desired directory before you start executing other commands.

    Because UNIX filenames are case sensitive, it is possible--although not a good idea--to have one directory called Projects and another called projects. It is an easy mistake to move to the projects directory when you really want the Projects directory. Therefore, it is good practice to use the pwd command to verify that you are in the right directory before you start deleting any files. Better yet, establish a naming convention for your directories. For example, some people use uppercase letters for directory names and lowercase letters for all regular filenames.

    Immediately after logging in, you're placed in your home directory. Let's say that your home directory is /usr/home/genuser. If you execute the pwd command immediately after logging in, then /usr/home/genuser is displayed:

    % pwd

    TIP: To help identify the directory you are currently in, you can modify your shell prompt to include the current directory name. For example, in C shell:

    % set prompt="pwd %"

    includes the name of your working directory as part of the shell prompt, and the prompt looks something like this:

    /usr/home/peter %

    SEE "Shell Variables," p. 163

    The cd Command

    The cd (change directory) command changes the current working directory to the named directory. For example:

    % pwd
    % cd /usr/home/sally
    % pwd

    If you are familiar with DOS, you will find the cd command works exactly the same way in UNIX with two exceptions. In DOS, if you don't specify a directory name when you give the cd command, the current working directory's name is displayed (just like the UNIX pwd command). However, in UNIX, if you don't specify a directory name when you give the cd command, the new directory will be your home directory. The other exception is the use of slash ("/") versus backslash ("\") in the directory path as explained in the following Note.

    NOTE: You will no doubt notice by now that UNIX directory paths are specified using the forward slash ("/") rather than the backslash ("\") you're so accustomed to in DOS. Don't use the backslash lightly because backslashes in UNIX have special meaning. A backslash stops the shell from giving a special character (known as a metacharacter), such as "*", its special meaning (wildcard, in this case). See the "Special Characters" section later in this chapter for more information.

    TIP: You can create an alias for cd that prints your current directory name after you have changed directory. Place the command:

    alias cd `cd \!*;pwd'

    in the .cshrc file, if you are using the C shell. If the UNIX shell you are using doesn't support aliases, you can create a shell script instead.

    The pathname argument to cd may be either an absolute pathname (as shown in the preceding example) or a relative pathname, which is shown in the following example:

    % pwd
    % cd ../peter
    % pwd
    % cd Projects/UNIX.Book
    % pwd

    The double dots ("..", a pseudonym for the parent directory) in the first cd command moves the working directory "up one level" and then "down" to a child directory called peter; you can move up multiple levels in the directory tree by specifying multiple ".." in the pathname (for example, cd ../.. moves you up two levels). The second cd command makes the current directory the child directory named UNIX.Book of the child directory named Projects. Note that the second cd path starts where the first one finished.

    NOTE: Although ".." is the pseudonym for the parent directory, "." is the pseudonym for the current directory. You may already be familiar with them from using DOS--DOS "borrowed" this naming convention from UNIX.

    Top Visited
    Past week
    Past month


    Old News ;-)

    Oracle - The UNIX cd command - navigating directory structure

    The UNIX change directory (cd) command is very useful for navigating in your Oracle directory structure. The cd command without any arguments takes you to the location of your UNIX home directory. The UNIX home directory is specified in the /etc/passwd file and defines where you will be immediately after a UNIX logon.



    When you give cd a directory location, you are transferred to that location. In this example, we transfer to the $ORACLE_HOME/rdbms/admin directory:

    >cd $ORACLE_HOME/rdbms/admin


    UNIX also has a very handy cd argument for switching back-and-forth between two directories. In this example, we use the cd command to bounce back-and-forth from the pfile directory and the /etc directory:

    >cd /etc

    >cd -

    >cd -


    You can also use the cd .. command to go up one level in your directory tree. In this example, we navigate from the pfile directory where the init.ora file is located to the bdump directory where the Oracle alert log is located (Figure 1-4).

    Figure 4: The OFA Tree and cd navigation

    >cd ../bdump




    Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy


    War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes


    Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law


    Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

    Classic books:

    The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haters Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

    Most popular humor pages:

    Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

    The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D

    Copyright 1996-2021 by Softpanorama Society. was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

    FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

    This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

    You can use PayPal to to buy a cup of coffee for authors of this site


    The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

    Last modified: March 12, 2019