Linux Cheatsheet

  1. Linux view the total size of folders and files contained in the current directory
du -sh
  1. Linux checks the size of the download folder in the current directory, because the set depth is 0
du -h --max-depth=0 download
  1. Linux checks the size of each folder and file in the current directory, as well as subfolders and subfiles, because the set depth is 1
du -h --max-depth=1 *
  1. Linux searches for services related to specified keywords, such as main services
ps -ef|grep main
# or
ps aux|grep main
  1. Linux view all port occupancy information
netstat -tupln
# or
sudo netstat -tulpn | grep LISTEN
  1. Directly specify port query
sudo netstat -tnlp | grip :8448
  1. View all processes
ps aux # ps -elf
  1. View process resource usage ranking
top
  1. Linux checks the permissions of all files and folders in the current directory
ls -l # or specify a file or folder ls -l file.txt
  1. Linux checks the user group to which the current user belongs
groups # or specify user groups openhacking
  1. Increase the api file permissions to the maximum, and fix the Permission denied problem
chmod 777 api
  1. Linux batch modify file and folder permissions
chmod -R 777 /software/lwebapp

# The -R parameter is to recursively process all files and subfolders in the directory
# 777 is to open all permissions, which is the highest permission
  1. Linux batch modify file and folder owner
chown -R opensource:openhacking /software/lwebapp # Or directly specify the user chown -R openhacking /software/lwebapp

# Perform the same owner change on all files and subfolders in the /software/lwebapp directory, so that the owner is changed to the openhacking user of the opensource user group
  1. Kill the process with the specified pid
kill -9 11864
  1. Compress data
tar -zcvf my-folder.tar.gz my-folder
  1. Decompress data
tar -zxvf my-folder.tar.gz
  1. Linux view remaining disk space
df -h
  1. Keep the program running in the background, main is the Linux executable file
sudo nohup ./main &
  1. Print the latest record in the log file

For example, only read the last 100 lines

tail -100 stderr.log
  1. View Linux system architecture

Available for all linux systems

uname -a

For Debian/Ubuntu only

dpkg --print-architecture
getconf LONG_BIT
arch