How to View the Contents of a Folder in Terminal

How to View the Contents of a Folder in Terminal

In the previous section, we have learned about Terminal Display, Directory Structure, and Users. Next we will learn about files, folders and directory structures in Linux by using command line interface.

As we have seen in the previous section, when we first enter Terminal we will be directed to the Home directory of the user which we use.

But in the previous section we have not seen the contents of a Home directory, in this section we will learn how to view the contents of a folder.

On the GUI (Graphic User Interface) or by using file exploreryou can easily see the contents of a folder by opening it or clicking on the folder.

On command line interfaceyou can view the contents of a folder by using the command ls.

For example — because we are currently in the Home directory — you can view the contents of the Home directory by using the command:

ls

Then it will appear output the contents of the Home directory as shown in the following image:

Viewing the Contents of a Folder - ls
Viewing the Contents of a Folder – ls

As you can see in the image above, the command ls will display the contents of a folder, either in the form of a file or a file sub folders.

In the image above, file names are marked in white, while folder names are marked in blue. On Terminal emulator that you use, may not be the exact same, but there is definitely a difference between files and folders.

In the example above, the command ls displays the contents of the folder where you are currently.

If you want to display content sub folders from a folder, for example in the Home directory there is a folder called “Downloads”, you can view its contents by adding a name sub folders it’s in front of the command ls as follows:

ls Downloads

Then all the contents of the “Downloads” folder will appear as shown in the image below:

Viewing the Contents of a Sub Folder - ls
Viewing the Contents of a Sub Folder – ls

Furthermore, if you want to see a sub folder of the “Downloads” folder named “Pictures”, while currently you are still in the Home directory, you can do so by using the command:

ls Download/Pictures

The same is true if you want to see sub folders from the “Pictures” folder onwards, just add a name sub folders and separate them using a slash or a slash “/” as follows:

ls Download/pictures/png/720p

Parameters in the ls command

Order ls can also be used using parameter addition. There are many parameter which can be used in commands lsOne of which is “-a”. “a” is an abbreviation of the word all.

This parameter serves to display the entire contents of a folder including hidden files and folders or what is usually called hidden files.

For example, if you want to see all files or folders in the Home directory, you can do this by using the following command:

ls -a

Then all the contents of the Home folder will appear, including hidden files and folders, as shown below:

Show All Contents of a Folder - ls -a
Show All Contents of a Folder – ls -a

Hidden files and folders on Linux are marked with a file name that starts with a period at the beginning.

You can prove it by comparing the command results ls which uses the parameter “-a” with those who don’t use it, as follows:

Comparison of ls Commands With and Without Parameters -a
Comparison of ls Commands With and Without Parameters -a

In the image above, using the parameter “-a”order ls will show more files and folders, because this command will also show hidden files and folders.

Apart from parameters “-a”another parameter that is often used in ls are parameters “-l”. Parameter “-l” will display the contents of a folder with more specific details, such as file size, permissions, date created and so on.

For example, if you want to display the contents of the Home folder with more complete details, you can do this by using the following command:

ls -l

Then the contents of the Home folder will appear with more complete details as shown below:

Viewing Folder Contents with Details - ls -l
Viewing Folder Contents with Details – ls -l

Apart from these two parameters, there are other parameters in the command lsbut these two parameters are the ones that will be used the most and are needed.

You can use more than one parameter at the same time, for example you want to use parameter “-a” and parameters “-l” on command lsyou can use it together with writing formats like the following:

ls -la

The same applies to other parameters that you can use.

That’s the tutorial Learn Terminal this time about How to View the Contents of a Folder. In the next tutorial we will learn how to move from a directory.

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *