Skip to main content
Below is an introduction to the commonly used essential commands:

List Files/Folders

Command: ls (list)
bash

Create/Change Paths

Create command: mkdir (make directory) Change command: cd (change working directory)
bash
Two special directories: .. and . or written as ../ and ./, where .. represents the parent directory and ./ represents the current directory.
bash

View Current Path

Command: pwd (print working directory)
bash

Rename or Move Files/Folders

Command: mv (move)
plaintext
plaintext

Copy Files/Folders

Command: cp (copy) Option: -r (the -r stands for recursive)
bash

Delete Files/Folders

Command: rm (remove) Option: -rf (the -r stands for recursive, and -f stands for force)
bash

Set Environment Variables

Command: export For setting environment variables, two common ones are PATH and LD_LIBRARY_PATH. Here’s how you can configure them:
  1. PATH
If you have installed commands that you want to use directly, you can add them to the PATH environment variable. For instance, if you have Python installed in a non-standard location, you might need to add its path to PATH to use it without specifying the full path. You can do this with the following command:
bash
This command adds the specified directory to the PATH variable, which is used by the shell to locate executable files when you type commands。The $PATH represents the current value of the PATH variable, and you should preserve it so that it doesn’t affect the use of other commands. When you type a command like python, the shell will search for the executable in the directories listed in the PATH variable, using the first one it finds。The order of the paths before and after the colon (:) is important。
  1. LD_LIBRARY_PATH
Similar to PATH, LD_LIBRARY_PATH is used to set the search path for dynamic link libraries. After installing CUDA, for example, you might need to set it like this:
bash
You can verify if the settings are successful by using the command env | grep PATH. Remember, the environment variables set with export are only valid in the current terminal session. To make them effective globally, write the export commands into the file ~/.bashrc, and then execute source ~/.bashrc to make them take effect, or simply open a new terminal.

Edit Text Files

Command: vim Advanced usage of vim can be quite complex. Please refer to other documents for learning.

Compress and Decompress

Commands: zip, unzip, tar
  • zip and unzip are specifically for compressing and decompressing .zip archives.
  • tar is another more versatile compression and decompression tool available in Linux.
Using zip and unzip:
bash
Using tar:
bash
bash

View GPU Information

Command: nvidia-smi
If you need to continuously display GPU usage information, you can use nvidia-smi -l 1 to output the information every 1 second. Alternatively, you can use watch -n 1 nvidia-smi to achieve the same effect.

View/Kill Processes

View Process Command: ps Kill Process Command: kill
bash
From the output of the ps command, you can identify the process you want to terminate based on the command name. For example, if the process ID (PID) for the last python tensorflow2.x-test.py command executed is 402, you can terminate it with the following command:
bash
The -9 option forces the process to stop immediately. After executing the kill command, you can use ps -ef again to confirm whether the process has been terminated.

View Process CPU and Memory Usage

Command: top Alternatively, you can use the instance monitoring feature provided by the platform for a more convenient view.
If there is a high load (high CPU usage), processes are generally listed at the top, and you can confirm them by their process names. The CPU usage of a process can be read from the %CPU field. Memory usage is a bit more complex, but usually looking at the RES field is sufficient. For example, the first Python process mentioned has a CPU usage rate of 101.4% and is using 1.796GB of memory (Tip: If the memory units displayed are different from those mentioned, press the e key to switch).

Redirect Logs

Command: >
bash

Scenario 1

Scenario: The program appears to have stopped, but the GPU memory is still occupied.
In general, this situation indicates that the process is seemingly dead but is actually still running. You can use the ps -ef command to check if the process is still active. If it is, you can terminate it with the kill command. Afterward, you should use nvidia-smi to verify whether the GPU memory has been freed.

Scenario 2

Scenario: You want to save a model or data from an instance to a network drive for use by other instances.
bash

Scenario 3

Scenario: A process is using more memory than the limit allows, causing it to be terminated.
You can use the top command to monitor the memory usage of processes. Check if the memory usage stabilizes at a certain value or keeps increasing. If it keeps increasing, it indicates that there might be a memory leak in the program. You can then analyze the references of variables in your Python code to optimize and resolve the issue.

Scenario 4

Scenario: You’re running a training process in a JupyterLab terminal as a daemon, and you’re concerned about not being able to see the logs after closing the web page.
You can use the log redirection feature to write the logs to a file.