The current directory is the directory in which a user is working at a given time. Every user is always working within a directory.
A directory in Linux or any other Unix-like operating system is a special type of file that contains a list of objects (i.e., files, directories and links) and the corresponding inodes for each of those objects. A file is a named collection of related information that appears to the user as a single, contiguous block of data and that is retained in storage (e.g., a hard disk drive or a floppy disk). An inode is data about a file including its size, the location in memory of the data it contains and when it was created but exclusive of the actual data that it contains.
There are several ways of determining what the current directory is. One is by looking at the command prompt, which is a short text message at the start of the command line (i.e., the line on which a command is typed) on an all-text mode display. The command prompt in bash, which is the default shell on Linux, contains the name of the user, the name of the computer and the name of the current directory. For example, for a user named sandra on a computer named localhost and who is working in a directory called work, the prompt might look something like [sandra@localhost work]$. A shell is a program that provides the traditional, text-only user interface in Unix-like operating systems for issuing commands and interacting with the system.
Another way to determine the current directory is to run the pwd (i.e., present working directory) command. pwd is a very simple command that is used without any arguments (i.e., file names or other input data supplied by the user) as follows:
pwd has the advantage that it shows the full path of the current directory, not just its name. The full path, also referred to as the absolute path, is the sequence of directories in the hierarchy of directories from the root directory (i.e., the directory that contains all other directories and files on the system and which is designated by a forward slash) to, and including, the current directory. Thus, for example, pwd might show that the full path of the current directory for the user sandra at the present time is /home/sandra/work.
By default, the current directory for a user after logging into the system is initially that user's home directory (i.e., the directory that serves as the repository for a user's personal files, directories and programs). The current directory can then be changed from that directory (or from any other directory) with the cd (i.e., change directory) command. For example, to change the current directory (from whatever it is) to the directory /usr/bin (which contains standard programs that are not required for booting or repairing the system), the following command would be used:
The current directory is often abbreviated by a single dot (i.e., period), and its parent directory (i.e., the directory in which it is contained) is abbreviated by two successive dots. For example, every directory on a Unix-like system contains an entry designated by a single dot and an entry designated by two dots, which represent the current directory and its parent directory, respectively. This can be easily verified by using the ls command (which by default lists the contents of the current directory) with its -a option (which tells ls to show all objects in the directory, including hidden files):
The first line returned will be a single dot and the second will be two dots. The output of ls -a is sent to the head command using a pipe (represented by the vertical bar character) in this example in order to make the output easier to read, because head by default shows only the first ten lines rather than a long list that likely would not fit on the display screen.
A single dot is also used to represent the current directory in some commands, scripts (i.e., short programs) and the PATH environmental variable. Environmental variables are used to tell the shell how to behave as a user works at the command line or in scripts. The PATH environmental variable is a list of directories that tells the system where to search for the executable files (i.e., runnable versions of programs whose names are typed in at the command line). A dot in PATH, although not included by default for safety reasons, would tell the system to also search in the current directory for the executable files.
Just as the term current directory refers to the directory in which a user is working at a specific time, the term current user refers to the person who is using a computer at a specific time. Also, the term current session refers to the login session in which a user is currently working. For example, when PATH or some other environmental variable is changed for the current session, it will revert back to its former value for subsequent sessions.
Created May 19, 2005. Updated July 12, 2007.
Copyright © 2005 - 2007 The Linux Information Project. All Rights Reserved.