- Current directory
- Windows current directory
- MS-DOS and Windows command line current directory
- Show the current directory in Linux and Unix
- How to list files in the current directory
- Linux what is current directory
- Unix / Linux — Directory Management
- Home Directory
- Absolute/Relative Pathnames
- Listing Directories
- Creating Directories
- Creating Parent Directories
- Removing Directories
- Changing Directories
- Renaming Directories
- The directories . (dot) and .. (dot dot)
- How to change directory in Linux terminal
- How to change directory in Linux terminal
- How to use the Linux command line to change directory or folder
- How to print the current working directory in Linux
- cd command in Linux termianl
- Absolute vs Relative pathname
- Understanding . and .. directories
- How can I return directly to my home directory when using the Linux terminal?
- How do I change directories in the Linux terminal and return to the previous directory?
- A note about symbolic links and cd command
- Linux cd command cheat sheet
- Conclusion
Current directory
Alternatively referred to as the working directory or current working directory (CWD), the current directory is the directory or folder where you are currently working. The following sections contain some common use examples involving the current working directory.
Windows current directory
While in Windows Explorer, the current working directory is shown at the top of the Explorer window in a file address bar. For example, if you were in the System32 folder, you would see «C:\Windows\System32» or «Computer > C:>Windows\System32» depending on your version of Windows. In this example, System32 is the current directory.
While in Windows a directory is more properly referred to as a folder and not a directory.
MS-DOS and Windows command line current directory
In the MS-DOS or Windows command line, the current working directory is displayed as the prompt. For example, if the prompt was «C:\Windows\System32>» the «System32» directory is the current directory, «Windows» is the parent directory, and «C:\» is the drive (root directory). To list the files in the current directory use the dir command, and if you want to change the current directory, use the cd command.
You can use the chdir command by itself to print the current directory in MS-DOS and the Windows command line.
Show the current directory in Linux and Unix
Depending on your Linux or Unix variant and its shell, the current directory may be shown as the prompt or when using the pwd (print working directory) command.
How to list files in the current directory
To list the files and directories in the current directory depends on your operating system. If you’re using Microsoft Windows or MS-DOS, you can use the dir command to list the files and directories in the current directory. If you’re using Linux, you can use the ls command to list the files and directories in the current directory.
Источник
Linux what is current directory
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.
Источник
Unix / Linux — Directory Management
In this chapter, we will discuss in detail about directory management in Unix.
A directory is a file the solo job of which is to store the file names and the related information. All the files, whether ordinary, special, or directory, are contained in directories.
Unix uses a hierarchical structure for organizing files and directories. This structure is often referred to as a directory tree. The tree has a single root node, the slash character (/), and all other directories are contained below it.
Home Directory
The directory in which you find yourself when you first login is called your home directory.
You will be doing much of your work in your home directory and subdirectories that you’ll be creating to organize your files.
You can go in your home directory anytime using the following command −
indicates the home directory. Suppose you have to go in any other user’s home directory, use the following command −
To go in your last directory, you can use the following command −
Absolute/Relative Pathnames
Directories are arranged in a hierarchy with root (/) at the top. The position of any file within the hierarchy is described by its pathname.
Elements of a pathname are separated by a /. A pathname is absolute, if it is described in relation to root, thus absolute pathnames always begin with a /.
Following are some examples of absolute filenames.
A pathname can also be relative to your current working directory. Relative pathnames never begin with /. Relative to user amrood’s home directory, some pathnames might look like this −
To determine where you are within the filesystem hierarchy at any time, enter the command pwd to print the current working directory −
Listing Directories
To list the files in a directory, you can use the following syntax −
Following is the example to list all the files contained in /usr/local directory −
Creating Directories
We will now understand how to create directories. Directories are created by the following command −
Here, directory is the absolute or relative pathname of the directory you want to create. For example, the command −
Creates the directory mydir in the current directory. Here is another example −
This command creates the directory test-dir in the /tmp directory. The mkdir command produces no output if it successfully creates the requested directory.
If you give more than one directory on the command line, mkdir creates each of the directories. For example, −
Creates the directories docs and pub under the current directory.
Creating Parent Directories
We will now understand how to create parent directories. Sometimes when you want to create a directory, its parent directory or directories might not exist. In this case, mkdir issues an error message as follows −
In such cases, you can specify the -p option to the mkdir command. It creates all the necessary directories for you. For example −
The above command creates all the required parent directories.
Removing Directories
Directories can be deleted using the rmdir command as follows −
Note − To remove a directory, make sure it is empty which means there should not be any file or sub-directory inside this directory.
You can remove multiple directories at a time as follows −
The above command removes the directories dirname1, dirname2, and dirname3, if they are empty. The rmdir command produces no output if it is successful.
Changing Directories
You can use the cd command to do more than just change to a home directory. You can use it to change to any directory by specifying a valid absolute or relative path. The syntax is as given below −
Here, dirname is the name of the directory that you want to change to. For example, the command −
Changes to the directory /usr/local/bin. From this directory, you can cd to the directory /usr/home/amrood using the following relative path −
Renaming Directories
The mv (move) command can also be used to rename a directory. The syntax is as follows −
You can rename a directory mydir to yourdir as follows −
The directories . (dot) and .. (dot dot)
The filename . (dot) represents the current working directory; and the filename .. (dot dot) represents the directory one level above the current working directory, often referred to as the parent directory.
If we enter the command to show a listing of the current working directories/files and use the -a option to list all the files and the -l option to provide the long listing, we will receive the following result.
Источник
How to change directory in Linux terminal
M y Dell Laptop came preinstalled with Ubuntu Linux, and I am a new Linux desktop user. How do I change directories in the Linux terminal?
Introduction – On Linux the cd command allows you to change directories when using the terminal application. This page shows how to change directory in Linux terminal using the cd command.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | No |
Requirements | Linux terminal |
Est. reading time | 3 minutes |
How to change directory in Linux terminal
- To return to the home directory immediately, use cd
OR cd
Let us see all examples and usage for terminal in details.
How to use the Linux command line to change directory or folder
The directory in which the user is currently working is called the current working directory (CDW).
How to print the current working directory in Linux
To display the name of the current/working directory, type the following pwd command:
pwd
cd command in Linux termianl
The syntax is:
cd
cd ..
cd /path/to/dir
When cd command used without stipulating any directory name, cd command returns to the home directory. Let us change the directory to /usr/sbin/, run:
cd /usr/sbin/
Verify it:
pwd
Want to list the files in the /usb/sbin/ directory? Try the ls command:
ls
ls -l
Let us go back to user’s home directory, run:
cd
Again verify it:
pwd
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Absolute vs Relative pathname
The cd command changes the current directory when a directory name provided by the user. The name can be written as an absolute pathname (e.g. cd /etc/httpd/ ) or as local pathname relative to the root directory (e.g. cd conf.d/ ). For example:
cd /etc/httpd/
pwd
ls
cd conf.d/
pwd
ls
The absolute vs. relative pathname for cd command in Linux
Understanding . and .. directories
On Linux the current directory is represented by a single dot ( . ) and two consecutive dots represent its parent directory ( .. ). Thus, to change to the parent of the current directory, run cd . .. For example:
ls
pwd
cd ..
pwd
ls
How can I return directly to my home directory when using the Linux terminal?
How do I change directories in the Linux terminal and return to the previous directory?
Simply pass the — option to the cd:
cd —
Verify it:
pwd
A note about symbolic links and cd command
The -P option instructs cd to use the physical directory structure instead of following symbolic links:
cd -P LinkDir
pwd
The -L option forces cd to follow symbolic links:
cd -L LinkDir
pwd
Linux cd command cheat sheet
Command | Description |
---|---|
cd | Returns you to your login directory |
cd |
tom
Conclusion
The cd command is used to change the current directory in both Linux and other Unix-like systems. See Cd command wiki page.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник