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
.. 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:
- PATH
bash
$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。
- LD_LIBRARY_PATH
bash
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
zipandunzipare specifically for compressing and decompressing.ziparchives.taris another more versatile compression and decompression tool available in Linux.
bash
bash
bash
View GPU Information
Command:nvidia-smi
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
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
-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.
%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.
-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.
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.