Skip to content

Basic Commands

Sure, please provide the text that you would like me to translate.

Here is an introduction to basic commands for operating a Linux server.

Most commands can be viewed with detailed explanations by adding the --help parameter.

<command> --help

File System

File List

List all files and folders in the current directory.

ls

ls -lh

  • The first column starting with drw: represents the permission settings of the file (Todo)
  • The second column 13: number of links
  • The third column ubuntu: user who owns the file
  • The fourth column ubuntu: group that owns the file
  • The fifth column 4.0K: size of the file
  • The sixth column Feb 19 15:35: last modified time
  • The seventh column docs: file name

List all files and folders in the specified path.

ls <dir>

Moving between Paths

Move to the docs folder in the current path.

cd docs

Move to the parent folder.

cd ..

Move to the specified path.

cd /home/ubuntu/example/docs

Creating Folders

mkdir <directory_name>

Copying and Moving

Copy a file.

cp <source> <destination>

Copy a folder.

cp -r <source> <destination>

Move a file or folder.

mv <source> <destination>

Deleting

Delete a file.

rm file.txt

Delete all files in the current path with the .txt extension.

rm *.txt

Delete a folder.

rm -rf <directory>

Checking Disk Space Usage

df -ah
du -sh <folder>

Managing Applications

Listing Processes

ps -ajxf

  • The second column 2197748: PID
  • The last column: process name (and the relationship between processes)
ps -ajxf | grep <search>

Monitoring Resource Usage

htop

Clicking on the various headers (such as VIRT, CPU%) allows you to sort and view them.

Cpu

Please do not use all threads, and keep at least some threads available for other users to perform basic computing tasks. Unless necessary, do not use more than ⅔ of the maximum number of threads.

Memory

When using multiple processes (mainly for Python users), please limit the number of processes to avoid memory overflow. Memory overflow can lead to server crashes and other serious consequences.

Idle

When not in use for a long time, please close threads in a timely manner to release memory for other users to use. If you find that there is insufficient memory during use and other users are occupying a large amount of memory, please contact the user or coordinate with WenZhi Ding.

For checking Swap usage, please refer to this page.

Terminating Processes

Obtain the process ID (PID) from the ps command or the htop command above.

kill -9 <PID>
sudo killall -u <username> -9

Text Operations

Configuration files in Linux are typically in the form of text (even if the file extension is not .txt or there is no file extension at all). The easiest way to edit these files is to download them to your local machine via SFTP, edit them, and then upload them back to their original location.

However, for browsing and simple editing, you can do it directly in the SSH terminal. For example, for the config.ini file:

vim config.ini

The operation of Vim is different from traditional text editors. You can learn it from this tutorial.


Last update: September 16, 2023