Linux Cheatsheet
- Linux view the total size of folders and files contained in the current directory
du -sh
- Linux checks the size of the download folder in the current directory, because the set depth is 0
du -h --max-depth=0 download
- 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 *
- Linux searches for services related to specified keywords, such as main services
ps -ef|grep main
# or
ps aux|grep main
- Linux view all port occupancy information
netstat -tupln
# or
sudo netstat -tulpn | grep LISTEN
- Directly specify port query
sudo netstat -tnlp | grip :8448
- View all processes
ps aux # ps -elf
- View process resource usage ranking
top
- 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
- Linux checks the user group to which the current user belongs
groups # or specify user groups openhacking
- Increase the api file permissions to the maximum, and fix the
Permission denied
problem
chmod 777 api
- 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
- 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
- Kill the process with the specified pid
kill -9 11864
- Compress data
tar -zcvf my-folder.tar.gz my-folder
- Decompress data
tar -zxvf my-folder.tar.gz
- Linux view remaining disk space
df -h
- Keep the program running in the background, main is the Linux executable file
sudo nohup ./main &
- Print the latest record in the log file
For example, only read the last 100 lines
tail -100 stderr.log
- View Linux system architecture
Available for all linux systems
uname -a
For Debian/Ubuntu only
dpkg --print-architecture
getconf LONG_BIT
arch