- You can create and remove your own directories, as well as change your working directory, with the mkdir, rmdir, and cd commands
- Each of these commands can take as its argument the pathname for a directory
- The pwd command displays the absolute pathname of your working directory
- In addition to these commands, the special characters represented by a single dot, a double dot, and a tilde can be used to reference the working directory, the parent of the working directory, and the home directory, respectively
- You can create one directory inside another directory, move from one directory to another, and use pathnames to reference any of your directories
Creating and Deleting Directories
- You create and remove directories with the mkdir and rmdir commands
- In either case, you can also use pathnames for the directories
- In the following example, the user creates the directory named as bank
Example: mkdir bank
- In the following example user creates the directory krithika using a pathname
Example: mkdir /home/vish/krithika
- You can remove a directory with the rmdir command followed by the directory name
- In the next example, the user removes the directory bank with the rmdir command
Example: rmdir bank
- To remove a directory and all its subdirectories, you use the rm command with the -r option
- This is a very powerful command and can easily be used to erase all your files
- If your rm command is aliased as rm -i (interactive mode), you will be prompted for each file
- To simply remove all files and subdirectories without prompts, add the -f option
- In the following example user deletes the bank directory and all its subdirectories
Example: rm -rf bank
Displaying Directory Contents
- Use different switches of ls to display the contents of the directory
- Even you can display the contents of a subdirectory without actually going there . You can use the path
- In the following example user displays the content of directory which is the subdirectory of mgm1 and mgm1 is the subdirectory of mgm
Example: ls mgm/mgm1/mgm2
Moving Through Directories
- The cd command takes as its argument the name of the directory to which you want to change
- The name of the directory can be the name of a subdirectory in your working directory or the full pathname of any directory on the system
- If you want to change back to your home directory, you only need to enter the cd command by itself, without a filename argument
- In the following example user changes to the directory named suvarni from the current directory
Example: cd suvarni
Linux: Printing of Files << Previous
Next>> Linux: Listing of files
Our aim is to provide information to the knowledge
seekers.