Linux commands: df

A comprehensive guide to the df command: analyzing disk usage The df command is an essential tool for retrieving disk usage information on various operating systems, including Linux, macOS, and Windows Subsystem for Linux (WSL). In this article, we will explore the basic usage of the df command and its various options. Understanding the basic usage The df command, in its simplest form, provides information about the volumes mounted on your system....

Linux Commands: dirname

In this blog post, we will explore the dirname command and its usage to retrieve the directory portion of a path. Whether you are using Linux, macOS, WSL, or any UNIX environment, the dirname command is an essential tool in your repertoire. Let’s start with an example: suppose we have a file path /Users/flavio/test.txt. By running the following command: dirname /Users/flavio/test.txt We obtain the directory portion of the path, which is /Users/flavio....

Linux Commands: du - A Quick Guide to Calculating File and Directory Space Usage

The du command is a powerful tool in Linux that allows you to determine the space usage of files and directories. By using this command, you can easily find out how much disk space is being consumed by your data. To calculate the size of a directory as a whole, simply run the command du. It will display the total size of the directory in bytes. For example: du In the above example, the du command shows that the directory size is 32 bytes....

Linux Commands: Echo - A Quick Guide

The echo command is a versatile tool that is used to print the argument passed to it. In this guide, we will explore the various ways you can use the echo command in a Linux environment. To begin, let’s look at a simple example: echo "hello" When this command is executed, it will print hello to the terminal. Appending the output to a file is also possible with the echo command:...

Linux commands: env - Interacting with Environment Variables

The env command is a versatile tool used in Linux, macOS, WSL, and UNIX environments to run commands while manipulating and interacting with environment variables. Passing Environment Variables One of the main use cases for the env command is to pass environment variables to a command, without permanently setting them in the current shell. For example, if you want to run a Node.js app and set the USER variable to it, you can use the env command as follows:...

Linux Commands: Exploring the `printenv` Command for Environment Variables

The printenv command is a useful tool for printing the values of environment variables in a Linux, macOS, or UNIX environment. In this guide, we will explore how to use this command effectively. Understanding Environment Variables Environment variables play a crucial role in setting system configurations and customizing shell behaviors. They can be set by the system itself or by your own shell scripts and configuration files. Printing All Environment Variables To print all the environment variables to the terminal, simply execute the printenv command....

Linux commands: export

A comprehensive guide on the export command and its usage to export variables to child processes. The export command plays a crucial role in exporting variables to child processes. But what does this actually mean? Let’s dive deeper into it. Imagine you have a variable named TEST defined as follows: TEST="test" To check the value of this variable, you can simply use the echo $TEST command. However, if you try to define a Bash script in a file named script....

Linux Commands: fg

Learn how to use the fg command in Linux to bring background jobs to the foreground. When a command is running in the background, indicated by the & symbol at the end or by using the bg command, you can use the fg command to bring it back to the foreground. To bring the last suspended job to the foreground, simply run: fg You can also specify the job number to bring a specific job to the foreground....

Linux Commands: Find

In this blog post, we will explore the powerful find command in Linux, which is commonly used to search for files and folders on the filesystem. The find command allows you to search for files or folders based on specific criteria and can perform recursive searches. Let’s dive into some examples to understand how to use the find command effectively. To find all files with the .js extension under the current directory and print their relative paths, you can use the following command:...

Linux commands: grep - A Quick Guide to Matching Patterns in Text

The grep command is a powerful tool that can help you match patterns in text. Mastering grep will greatly enhance your productivity in your day-to-day tasks. What is grep? grep stands for global regular expression print. It allows you to search for specific patterns within files or filter the output of other commands using pipes. Searching in Files To search for occurrences of a specific pattern in a file, you can use the following command:...