Finding your way on a Linux System part 2

Using Directories and Listing Files

Files and Directories

In this article, we will explore directories and the listing of files in Linux systems. Files contain data used by the computer system. Directories are used to create organization within a file system. Directories can contain files and other directories.

For example, we can use this command to check the directories and files you have.

$ tree

If you are on Ubuntu you can install the tree with the following command:

$ sudo apt install tree

$ sudo snap install tree
Sample output
├── --background
├── cockroach-data [error opening dir]
├── cockroach-latest.linux-amd64.tgz
├── cockroach-v21.1.11
│   └── src
│       └── github.com
│           └── cockroachdb
│               └── cockroach
│                   ├── AUTHORS
│                   ├── _bazel
│                   │   ├── bin
│                   │   ├── cockroach
│                   │   ├── out
│                   │   └── testlogs
│                   ├── build
│                   │   ├── archive
│                   │   │   ├── contents
│                   │   │   │   ├── Makefile
│                   │   │   │   └── README
│                   │   │   └── README.md
│                   │   ├── bazelbuilder
│                   │   │   ├── bazelbuild.sh
│                   │   │   ├── bazeltest.sh
│                   │   │   └── Dockerfile
│                   │   ├── bazelutil
│                   │   │   └── bazel-generate.sh

From the above, we have 492 directories and 2847 files.

File and Directory Names

In Linux, It is not advisable to use special characters or use spaces when naming files or directories. Spaces for example need escape character \ to be entered correctly. For example

$ cd Report \ schedule

Take note of the escape character \.

Navigating the Filesystem

Getting current location

In the Linux command line menu, we use pwd to know the current location. For example

$ pwd

Let’s say we are in the Documents directory and inside documents, we have a WordPress subdirectory. We can know where we are by using pwd command.

The relationship of directories is represented with a forward slash (/). WordPress is a subdirectory of documents which is a subdirectory of sang which is located in a directory called home which has a parent directory root.

Listing Directory content

Listing contents of the current directory is done with the ls command. The ls command only sees the content of the current directory.

$ ls
--background
 cockroach-data
 cockroach-latest.linux-amd64.tgz
 cockroach-v21.1.11
 cockroach-v21.1.11.linux-amd64
 Desktop
 Documents
 Downloads
 GNS3
 google-chrome-stable_current_amd64.deb
'--http-addr=localhost:8080'
 --insecure
'--join=localhost:26257,localhost:26258,localhost:26259'
'--listen-addr=localhost:26257'
 Music
 Pictures
 Postman
 Public

Changing Current Directory

Navigation in Linux is done with the changes directory command (cd).

We can still use cd to go back to the home directory.

Conclusion

We have learned how to go about Linux by using special commands such as ls, cd, and pwd. Make sure you understand how to use it because it’s necessary when navigating through Linux. Next, we will explore Creating, moving, and deleting files in Linux.

About Mason Kipward

I am a technology enthusiast who loves to share gained knowledge through offering daily tips as a way of empowering others. I am fan of Linux and all other things open source.
View all posts by Mason Kipward →

Leave a Reply

Your email address will not be published.