In this articles we gonna see some useful commands while working on files and directory in a Linux system.
Directory:
The directory is the place where files and subdirectories are created. While coming in GUI we call a directory as a folder. A directory can hold more sub-directories or sub-folders inside it.
In Linux the / is known as the root directory where everything on your Linux system is located under this directory.
Creating directory:
To create a directory use mkdir command,
user@ljunix:/home$ mkdir Dir1
user@ljunix:/home$ mkdir Dir2
The above commands creates two directories as Dir1 and Dir2,
Creating Consecutive directory:
To create consecutive directory use -p command with mkdir, this allows you to create sub-directory inside a directory.
The above command creates all subdirectories in a single command.
Toggling between Directories:
Use cd command to change from active directories, Let us assume you are creating the above directories in /home directory. Now you want to enter into Dir1. The command to change your current working directory is,
user@ljunix:/home$ cd Dir1
user@ljunix:/home/Dir1$ cd /home/Dir2
user@ljunix:/home/Dir2$
To move to the previous directory use cd -
user@ljunix:/home/Dir2$ cd -
user@ljunix:/home/Dir1$
To move one directory back use ..with cd
user@ljunix:/home/Dir1$ cd ..
user@ljunix:/home$
To move two directory back use ../.. with cd
user@ljunix:/home/Dir1$ cd ../..
user@ljunix:/$
cd command will get you back to the root directory.
user@ljunix:/$ cd
user@ljunix:~$
user@ljunix:~$ cd
Knowing the current working directory:
To print the current working directory use pwd
user@ljunix:~$ pwd
user@ljunix:~$ /home/user
Deleting a Directory:
The command use to delete a directory is rm -rf, This command will delete all the subdirectories inside the directory. Beware of using rm -rf command since it will never ask for a confirmation.
Comments