Command Line Interface (CLI) for Deep Learning Applications

Vitor dos Santos
6 min readApr 27, 2022

Hello, everyone!

I bet that you have already seen in movies the IT guy hacking a system by writing commands inside a black window and thought “How cool is that!”. Well, in reality, things are not that easy to hack but we do have some basic commands that can help interact with the computer, which is called command-line interface (CLI).

The command-line interface is a program on your computer that allows you to create and delete files, run programs, and navigate through folders and files. On a Mac and Linux Systems, it’s called Terminal, and on Windows, it’s Command Prompt.

CLI is not just a fancy method to interact with your computer. It can also provide a simple and faster way to perform commands, mainly when considering working with a lot of data, which is the case when developing Deep Learning applications.

In this article, I am going to walk you through some of the commonly used command-line commands. Next, I will focus on commands for accessing and interacting with a remote network. The commands described in this article will be related to Unix systems.

Basic commands

To test these commands, you have to open a terminal on your Linux computer.

  1. ls (List): lists all files and folders in the current directory.
Figure 1: ls command.

In this case, there are 8 folders in my current directory.

For some commands, you can type some optional commands to show more information. In this command, for example, you can type ls -a to include showing hidden files.

2. cd(Change Directory): changes the current directory to another specific one. You only have to write the name of the new folder.

Consider you want to enter the Documents folder shown in the Figure above. You can type cd Documents .

Figure 2: cd command.

The new directory will be shown before the $ symbol, which means that you successfully entered the folder. If there’s another folder that you want to enter, you can keep entering the folder’s name followed by a slash /.

3. mkdir (Make a Directory): Creates a new folder in the current directory.

Figure 3: mkdir command.

In the Figure above, we created a new folder called NewFolder using the command mkdir NewFolder .

By using the ls command, it is possible to see the new folder created after using the mkdir command.

4. touch (Create File):

After writing the touch command, you must enter the filename that you want to create.

Figure 4: touch command.

In the sequence of commands shown in the Figure above, we entered the NewFolder folder, created a new file called newfile.txt, and showed the contents of the folder using the ls command.

5. rm(Remove File):

After writing the rm command, you must enter the filename that you want to remove.

Figure 5: rm command.

In the sequence shown above, there was a file named newfile.txt and after the rm command, this file was removed.

6. cp (Copy File):

This command takes two arguments separated by spaces. The first argument represents the file or folder that you want to copy from and the second argument represents the destiny folder that you want to insert the file.

Figure 6: cp command.

In the Figure above, we created a new folder called TestFolder, created a new file called newfile.txt, copied this new file into the new folder, changed the directory to the new folder, and then listed the contents of this new folder, where it is possible to see the that it contains the newfile.

Remote Network

Developing, training, and evaluating Convolutional Neural Networks (most used in Deep Learning applications) is usually computationally expensive and time-consuming.

When working with Deep Learning applications in companies, it is common to have a dedicated computer or servers to train and evaluate a neural network, which usually is expensive and time-consuming. In this context, SSH can be used to remotely access the server, providing IT and information security professionals with a secure mechanism to manage SSH clients remotely.

There are ways to perform a SSH connection via GUI. However, some processing and operations can take too much time, mainly when working with folders with high storage or many images (which is common in Deep Learning applications).

For example, the image below shows the remaining time to copy an entire folder of 4.2 GB to another location using a SSH connection with Ubuntu’s GUI.

Figure 7: Remaining time to complete the operation.

It will take approximately 17 hours to complete this operation!

The same operation was performed using the cp command via CLI, as shown in the Figure below, where the date command informs the date and current hour.

Figure 8: Copying files using CLI command.

Comparing both dates commands, which were taken immediately before and after the command, it is possible to see that it took 19 seconds to copy the same entire folder! That is really nice time reduction, isn’t it?

Opening folders with many files in GUI via ssh can also be troublesome. If you only want to know the number of files inside a specific folder, you can use the command ls FOLDER_NAME | wc -l , as shown in the Figure below.

Figure 9: command to get the number of files inside a folder.

In this case, the folder letras has 34103 images.

Suppose now that you want to know some metadata related to only one image, such as its resolution. Instead of using GUI, entering the folder, opening the image, and getting its properties (which would take time in this case), you can use the file command informing only the file.

Figure 10: file command.

This particular image, called 0_cA.jpg, has a 20x20 pixels resolution and only 1 component, meaning that it is a grayscale image. I had already needed to know this information before training a new neural network, and this command sure saved me some time.

These are just a few examples that show the importance of using CLI. I am sure that you will find other benefits when using it.

Finally, in order to access a remote network via ssh using CLI, you just need the username, the IP address of the network, and the port (if it is not the default one) following the syntax below:

ssh username@ip_address -p port_number

Usually, there is a password related to the username. If the connection is successful, the password will be requested.

Afterward, you can use the CLI commands as you need.

So, that’s all for today, folks! I hope that this article helped you in any way!

Conclusion

In this article, I presented some basic commands that can help interact with a computer using Linux Terminals, such as listing files, creating new folders and files, accessing folders, and creating, copying, and removing files.

After, I presented some benefits of using CLI commands, mainly when working with remote networks, where the processing time to access or copy some files is greatly reduced.

Finally, I showed how to connect to a network via ssh, where information such as username, IP address, port, and password are required.

References

--

--

Vitor dos Santos

PhD student on Computer Science at Dublin City University. Interested on Computer Vision, Deep Learning and Data Science.