Comprehensive Guide to Common Linux Commands

1. Nginx Related Commands

  • Check Nginx Status
ps -ef|grep nginx
  • Start Nginx
cd /usr/local/nginx/sbin/
./nginx
  • Restart Nginx After Modifying Configuration File
cd /usr/local/nginx/sbin/./nginx -s reload

2. Common Docker Commands

  • View All Containers, Including Running and Stopped
docker ps -a
  • View All Running Containers
docker ps
  • Start a Stopped Container
docker start ContainerNameOrID
  • Restart a Container
docker restart ContainerNameOrID
  • Enter the Corresponding Container
docker exec -it ContainerNameOrID bash
  • Stop a Running Container
docker stop ContainerNameOrID
  • View Images
docker images
  • Package a Docker Image
docker save -o TargetFileName.tar ImageName
  • Load a Packaged Docker Image
docker load -i PathToTargetFile
  • Mount a Directory from the Host to the Image
docker run -it -v /home/ocr/training/:/home/ocr/training ImageName /bin/bash
# Use -v parameter, the path before the colon is the host directory, must be an absolute path, the path after the colon is the mount path inside the image
  • Create a Container from an Image
docker run --name ImageName ContainerName

3. Common Commands for Viewing Logs

  • Use tail to View Real-Time Logs
tail -f LogFileName
  • Use cat to View Logs Near a Keyword
cat -n LogFileName|grep "Keyword"

4. Basic Linux Operations

  • View Current Processes
top
  • Filter Specific Processes, e.g., Java Processes
ps -ef | grep java
  • Kill a Process
kill ProcessID
  • Change to a Specific Directory
cd Path
  • Go Back to the Parent Directory
cd ..
  • View File Information in the Current Directory
# View detailed information of files in the current directory
ll
# View files in the current directory
ls
  • Create a Folder
mkdir FolderName
  • Create a File aa.txt
touch aa.txt
  • Delete File aa.txt
rm -f aa.txt
  • Delete a Folder
rm -rf FolderName
  • Copy Files or Directories
# Copy file
cp SourceFile CopyFile
# Copy directory
cp -r SourceDirectory CopyDirectory
  • Move/Rename Files or Directories
mv OldName NewName
  • View Current System Time
date
  • Show Current Path
pwd
  • Search for Files in a Specified Path
# Search for files by name
find SpecifiedPath -name FileName
# Search for files by type
find SpecifiedPath -type f -name FileName
find SpecifiedPath -type d -name FolderName
  • Change File Permissions
chmod xxx FilePath
  • Archive Related Commands
# Compress
tar -cvf archive.tar Filename
# Decompress
tar -xvf archive.tar Filename

5. View Resource Usage

  • top to View Real-Time System Process Activity
top

You can see CPU usage, memory usage, process list, and detailed information of each process.

  • df to View Disk Space Usage of the File System
# Disk space usage
df -h
# File system type
df -T
# inode usage
df -i
  • free to View Memory Usage
# Display memory usage.
free -h
# Display memory usage in MB.
free -m
# Display memory usage in GB.
free -g

6. View Port Usage

  • lsof to View Port Usage
# xxxx is the port number
lsof -i:xxxx

Conclusion

The above is a summary of some commonly used Linux commands. If you find the content helpful, don’t hesitate to give a thumbs up; your support is the biggest motivation for the author to update!

See you in the next article~

Leave a Comment