The Basics of Linux

Dolamu Oludare
Towards Data Engineering
5 min readMay 7, 2024
Photo by Gabriel Heinzer on Unsplash.

Why Linux?

The Linux operating system is an open-source and free operating system often used by developers. The operating system is known for its security, customizability, stability, and interoperability. it is often used in containerization and virtualization platforms like Docker and Kubernetes and it also has a powerful Command Line Interface (CLI) that helps users perform several tasks efficiently. In the article, I will discuss the basics of the Linux Operating system and also Permissions and Ownership in Linux.

It is important to note that all commands in Linux are case-sensitive. e.g. CD ≠ cd. One of the important things in Linux is paths, There are two types of paths generally, the relative path (The location of a file or directory relative to the user’s current directory) and the absolute path (The location of a file or directory relative to the root directory).

Some common commands used in Linux are:

  • whoami: This command prints the username currently logged in to the terminal.
  • pwd: give you the path of the current directory.
  • ls: This command shows you the list of all files and folders in the current directory. Optional arguments ls -l provides list in a vertical format with other information.

ls -a shows all the files and folders in the directory including hidden files.

ls -la shows the list of all the files in a vertical format including the hidden files.

  • cd: This allows you to navigate into a directory.
  • sudo: is used for root privileges, where permission is needed.
  • touch: is used to create a file in a directory.
  • mkdir: This command creates a new folder.
  • rmdir: This command is used to delete multiple empty folders.
  • rm: is used to delete a folder, if the folder contains a file, then you have to provide the -rf command e.g. rm -rf Docs.
  • mv: This command is used to move and rename files.
  • cp: This command is used to copy files from one directory to another. To copy folders you need to add the -r flag to copy the whole content of the folder.
  • The tab command: The tab command is very useful in Linux, it autocompletes a command or file name.
  • clear: is used to clear the screen.
  • man: provides documentation of any command in Linux.
  • cat: It shows the content of a file.
  • grep: This command is used to search for a pattern in a directory.

Linux Permissions & Ownership

The Linux file structure is simple and gives read, write, and execution access to a user(The file owner), group(The group to which the file owner belongs), and others (others). The read, write, and execution functions are represented by the alphabet r, w, and x respectively.

Let’s take a look at a sample from our directory.

Folders in a Directory.

From the image, we can see the notation for file permission. The d in the notation means that particular entity is a directory or a folder. There are three sets of rwxtext in the notation, the first one is for the user, the second set is for the group the user belongs to, and the last one is for others. From the image, we can observe that the user has read, write, and execution access, the group has only read and execution access, and others also have read and execution access.

The number 4, 2, and 1 represent the read (r), write (w), and execution (x) permissions in octal notation. so if a particular group has an octal notation of 777, it means the user, group, and others all have read, write, and execution access, which would display rwxrwxrwx on the terminal.

To change file permission in Linux, we used the chmod command. Let us give the group section of the Python_docker folder in the image write access. We would do this by running the following command.

chmod g+w Python_docker

The chmod command means change directory permission, while the g stands for group and +w means add write access, and Python_docker is the directory name. Now, we will take a look at the file permissions after running the command.

Folder After Granting Write Permission.

We can see that the Python_docker now has write permission for the group. You might as well use the sudo command in case you do not have full permission to carry out the previous command.

To change the ownership of a file, we use the chown command. Let’s see some examples:

  • To change a file’s ownership to a different user: chown username file.txt.
  • Change a file’s group to another group: chown:newgroup file.txt
  • Change both the file’s owner and its group: chown newuser:newgroup file.txt.

Firstly, let’s add a new user with the name John to our users with the following commands.

sudo adduser --force-badname John

We are using the --force-badname option to override restrictions on the NAME_REGEX variable for username patterns in the adduser.conf located in the etc folder on the Linux file system.

Adding new user.

Now that we have added a new user, Let’s go ahead and change the user of a file to John

List of files in folder.

Now the owner of the Dockerfile is dolzy. Let’s change it to John by running the following commands.

sudo chown John Dockerfile

We can see that the owner of the Dockerfile has changed to John.

Conclusion

The Linux terminal or command line runs on the Linux operating system. it allows users to run and execute tasks, navigate the file system, and manage processes. Having mastery of the concept of Linux terminal would pay off if you are looking to go into deep collaboration and open-source projects.

--

--