File and directory manipulation in bash is very easy and intuitive. These are some of the most-used commands that you need to learn.

To print out any string in your terminal, you can use the echo command. If you wish to print out “Hello world” in your terminal, use the following: You can add escape characters like \n for new lines using -e flag.

Create Files Using touch

The touch command is used to create files. You can create single or multiple files as follows. To create multiple files, append their file names one after another.

Write on Files Using nano Text Editor

You can write or modify file contents using the nano editor. To open a file in write mode, use: The above command opens a text editor in the terminal. You can write whatever you want and save the file using Ctrl + O and exit the text editor using Ctrl + X .

See Content of a File With cat

To see what is written on a file without opening it, you can use the cat command.

List Files and Directories Using ls

In the steps above, you’ve created three files: file1.txt, file2.txt and file3.txt. You can list those files using the ls command.

Create Directories With mkdir

We use the mkdir command to create directories. it is an acronym for “make directories.” You can create a “greetings” directory like this.

Change Directory With cd

You can change and navigate directories using the cd command. Go to the previous directory using the ../ path parameter. You can directly go to your home folder using the ~ path parameter.

Get to Your Working Directory Using pwd

If you want to know the working directory of any file or directory, you can use the pwd command.

Copy a File or Directory Using cp

The cp command requires two arguments. The first should be the file or directory path you want to copy, while the second is the target location path. In the following example we are copying our “file1.txt” file to the “greetings” directory.

Move and Rename a File With mv

If you want to move your file, you’ll have to use the mv command. It also needs two arguments: source file location and destination location. You can also rename a file using the mv command. The trick is to leave the source path the same, but in the destination path you’ll need to write the modified name with the same file extension.

Remove a File Using rm

You can use the rm command with the file location to remove or delete a file. If you want to delete a directory, use the -rf flag. It allows you to recursively delete all the files inside the directory.

Delete a Directory with rmdir

Add the directory path after the rmdir command to delete an empty directory. You can also delete multiple directories in a single command.

Permission Management Commands

Each file in Linux has various permissions. For instance, you may not be permitted to view or use a file. Fortunately, this list of commands allows you to change file permissions in Linux.

Modify File Permissions With chmod

You can add or remove file permissions using the chmod command. To make a file readable, add the +r flag after chmod. To make a file executable, add +x after the chmod command. In Linux, we often need to make files executable to run them. To solve this issue, you can run this command in your terminal: The executable can be run as:

Become Superuser Using su and sudo

To install new software and modify files and folders beyond your user directory, you need superuser permissions. Superuser can change anything in your operating system. There are two popular ways to temporarily become superuser in Linux. Using su, you’ll get a superuser prompt, and your commands will run as a superuser inside that prompt. You can use su like this: You can leave the superuser prompt by running the exit command. Modern Linux distributions use sudo instead of su. You can escalate your permission to superuser only by prefixing sudo in your command. After the command executes, your permission will return to normal. This is a more secure option than su .

As Linux is very popular in the server space, it comes with various tools to work with networking. Below you’ll find some commands which can give you the basic idea about networking in Linux.

Download Files Using wget

You can download files and interact with any REST APIs using the wget command. wget supports HTTP, HTTPS, FTP and FTPS protocols. You can download a file by simply adding the link of the source after the wget command. In this example, we are downloading a video using wget: wget automatically fetches the video file and downloads it.

Curl Basics

Curl is a networking utility that is used to transfer data to and from servers. It provides a number of options allowing you to resume transfers, limit the bandwidth, proxy support, user authentication etc. To download and save a file using curl, use the -O flag. If the connection drops during the download, you can resume the download by using -C flag.

Utilities Commands

These are some of the utilities you can use in your day-to-day activities. Knowing them will help you save a lot of time and become more efficient.

Date

Get today’s date using the date command. Output contains date, month, year, weekdays and your timezone.

Search With grep

grep is a very powerful searching tool that you can use to search for words and sentences in directories. You can also employ grep to find a software package of your choice. For example, if you need to install VLC player and don’t know its package name, you can combine apt and grep to search for the software package.

Find Package Installation Path Using which

You can use which to see the location where packages are installed. For example, to see the location of your bash installed binary use:

Get Previous Command via History

Sometimes we forget commands. Fortunately, you can use history to see all the previous commands you ran and refresh your memory.

Close a GUI Application Using kill

Once you’ve opened a GUI application from your terminal, you get the ID of the application. This is like a handle to that application. To close this application, you can use kill command.

Read CLI User Manual via man

You can look at the documentation of a CLI tool using the man command. The above command will give you the manual for the echo command. Here you can learn about all the available flags for the echo command. You should try different flags to customize the command to suit your needs. To exit from the manual page, hit the q button.

Clean the Terminal

If your terminal is filling with clutter, you can wipe it clean by using the clear command. You can also use the Ctrl + l shortcut the clean the terminal window.

Show Off to Your Friends

If you’d like to have some fun and print some random cool stuff on your screen just for the sake of it or to show off to your friends, you can employ a tool called cmatrix. To install cmatrix, run these commands. In your terminal, run cmatrix. The output will be like a snapshot of the matrix. You can also display a moving train using a simple bash command: sl. You can install this using the following command. Run this utility in the terminal. Image credit: Gabriel Heinzer via Unsplash. All screenshots are by Hrishikesh Pathak