Navigating and listing files & directories | Linux Tutorial | RHCSA on RHEL 8



0
31

In this video tutorial of RHCSA 8, I have explained and demonstrated navigating files and directories with different options. So, let’s get started. I am here in the bash terminal of Red Hat Enterprise Linux 8. As we can see, I am logged in to the server as a standard user student. To know on which directory I am currently on, I run pwd. As we can see, I am in the student directory which is inside the home subdirectory of the top directory or root directory. Now, to understand it more precisely, I open the graphical window of the server. For this, Click on Activities and then Click on Files. The home directory of the user student is open. Type ls to list the files and directories. We can see exactly the same file and directory names as in the graphical. Now, I navigate to the directory Desktop using the command cd and the directory name Desktop. And again, listing the contents of the directory, we find nothing. This means the directory is empty. To verify, we can double click on the Desktop folder. It’s empty. Here, I create a file with touch and then the file name. The file is created and we can see it here graphically. Also, if I run ls in the linux CLI, we can see the file name. Now, let’s list contents of a directory using different options. First of all, I list the contents of the directory log using the absolute path. We can see the files and directories. Here, the names with blue are directories and names with black are files. If I run cd and hit enter, it leads me all the way back to the home directory. Run ls . . to list the parent directory of the current directory. To list a user’s home directory, type ls and then the tilde symbol. I am currently logged in as student user, so it lists the contents of the home directory of the user. Likewise, ls and /, lists the root directory. Clear the screen, I switch my current directory to /etc/ and run ls –l, it long lists the files and directories. Run ls –al to long list all the contents of the directory including the hidden. Here, files or directories starting with dot were hidden. Type and run ls –lh to long list in human readable format. Here, we can see, the size is more readable. To list with size, we can also use ls –ls. Here we can se the size in byte and kilobyte. To list in reverse order, ls –r. The contents are listed in reverse alphabetical order. To list in tree format, ls –R. Here, we can see, directories, subdirectories and files of all the directories in the current location. To list sorted by file size, run ls –S. To list in ascending alphabetical order, ls –t. And for descending alphabetical order, ls –r. We can also use ls –lr to long list in descending alphabetical order. To list or sort files by their extension, run ls –X. Run ls *.txt to list only the files with .txt extension in the current directory. Now clearing the screen, I switch to /var/tmp. Then run ls –d $PWD/* to list the files and directories with full path. Although I am in the /var/tmp directory, it lists the files and folders with full path. Okay friends, these are the various techniques of listing files and directories of a directory. That’s all for now. Thanks for watching this video, see you in the next, until then have a nice time good bye !

Published by: Network Heros Published at: 2 years ago Category: