Linux Directory and File Operations – POFTUT

Linux Directory and File Operations


Most basic Linux usage starts with Linux file and directory operations. We will look at these operations to cover basics. In this tutorial, we will learn commands like ls , cd , mv .

List Directories and Files

Start of the navigation in the file system starts with listing the directories and files. We will use the ls command which will list current working directory files and folders.

$ ls
List Directories and Files
List Directories and Files

List Hidden Files and Directories

All operating systems have hidden files to hide them from use. It is not a security-related feature. It related to operation and reliability. Showing configuration files in the home directory have no benefits. So by default hiding them is better.

$ ls -a
List Hidden Files and Directories
List Hidden Files and Directories

We can see that files and folders like .cpan, .npm, .config etc. are listed with the help of -a option.

List Files and Folders Recursively

We can all child files and directories by providing the recursive option. We will provide the -R option which will list files and folders recursively.

$ ls -R
List Files and Folders Recursively
List Files and Folders Recursively

Change Directory

cd or change directory command can be used to change to the different directories. We can provide just the relative or complete path to the cd command.

$ cd /
Change Directory
Change Directory

Go User Home Directory

We can go to the home directory by using ~ tilde which means current user home.

$ cd ~

Go Upper/Parent Directory

We can go to the upper directory with double point .. which means parent directory

$cd ..

Go Given Path

We can go to the log directory

$ cd /var/log
Go Given Path
Go Given Path

Show Working Directory

We can work different systems and directories in day to day operation. We may not remember the current directory of the shell. We can get the current working directory with pwd command.

$ pwd
Show Working Directory
Show Working Directory

Delete File and Directory

We may need to delete a file or folder. rm and rmdir are commands used to delete file and directories.

$ rmdir output/ 
rmdir: failed to remove 'output/': Directory not empty

I can not delete the directory because there are files or directories in it. We can force for deletion

$ rm -Rf output
  • -Rf option will make deletion recursive and forcibly.
LEARN MORE  How To Remove Symbolic Links In Linux?

Move Files and Directories

We can use mv command to move files and directories

$ mv mycommand yourcommand

$ mv output/ output2

Leave a Comment