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
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.
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
We can see that files and folders like
.config etc. are listed with the help of
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
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 /
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
Go Given Path
We can go to the log directory
$ cd /var/log
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.
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.
Move Files and Directories
We can use mv command to move files and directories
$ mv mycommand yourcommand $ mv output/ output2