常用基础命令
ls -l | wc -l
ls > xxx.txt
which
whereis
updatedb
locate
dpkg -l | grep '^rc'
sudo dpkg -P <package-name>
dpkg -l | awk '/^rc/{print $2}' | sudo xargs dpkg -P
scp <local_path> <user_name>@<adress_ip>:<remot_path>
scp <user_name>@<adress_ip>:<remot_path> <local_path>
sftp <user_name>@<adress_ip>
put <local_path> <remot_path>
get <remot_path> <local_path>
ssh-keygen -t rsa -C "xxx@xxx.com"
ssh-copy-id -i ~/.ssh/id_rsa.pub <username>@<ip_address>
使用 screen 和 rsync 后台拷贝文件与目录
screen
screen -ls
Ctrl + A + D
screen -r xxx
rsync -ah --preallocate --info=progress2 [xxx] [xxx]
防火墙 ufw
ufw allow ssh
ufw enable
ufw status
ufw allow 9090
ufw delete allow 9090
磁盘命令
df -h
du -sh *
fdisk -l
fdisk /dev/xxx
mkfs -t ext4 -c /dev/xxx
blkid /dev/xxx
vi /etc/fstab
sudo mount -a
sudo hdparm -S 120 /dev/xxx
hdparm -C /dev/xxx
hdparm -I /dev/xxx
apt install smartmontools
smartctl --info /dev/xxx
smartctl -a /dev/xxx
badblocks -s -v /dev/xxx
sudo e4defrag -c /mnt/xxx
e4defrag /mnt/xxx
系统服务
lsb_release -a
systemctl edit xxx.service --full --force
systemctl start <httpd.service>
systemctl restart <httpd.service>
systemctl stop <httpd.service>
systemctl reload <httpd.service>
systemctl status <httpd.service>
systemctl is-enable <httpd.service>
systemctl enable <httpd.service>
systemctl disable <httpd.service>
systemd-analyze blame
netstat -nultp
sudo netstat -anp | grep <port>
清理缓存
sync
sh -c "echo 1 > /proc/sys/vm/drop_caches"
sh -c "echo 2 > /proc/sys/vm/drop_caches"
sh -c "echo 3 > /proc/sys/vm/drop_caches"
压缩、解压文件 tar
tar –zcvf <name>.tar.gz <path>
tar –zxvf <name>.tar.gz
软件安装
./configure --enable-optimizations
make
make install
make clean
make distclean
update-alternatives --display python
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives –remove python /usr/bin/python2.7
update-alternatives --config python
用户与权限
Linux 中,每个文件拥有以下三种权限
- 目录必须拥有 "x" 权限才可查看其内容。 很多时候,执行权限 "x" 对于目录而言也叫浏览权限。仅有 "r" 权限是无法查看目录内容的(因为连访问都做不到)。
| 权限 | 对文件的影响 | 对目录的影响 |
|---|
| r(读取) | 可读取文件内容 | 可列出目录内容 |
| w(写入) | 可以修改文件内容 | 可在目录创建、删除文件 |
| x(执行) | 可以作为命令执行 | 可访问目录内容 |
UGO模型的权限
- 第1位是文件类型描述符,"d"表示目录,"-"表示文件
- 第2-4位"rwx"是U模型权限,可读可写可执行
- 第5-7位"r-x"是G模型权限,可读可执行,不可写
- 第8-10位"r-x"是O模型权限
useradd -m <username>
useradd -m -G <group_name> <username>
usermod -s /bin/bash <username>
passwd <username>
su <username>
userdel -r haha
compgen -u
cat /etc/passwd
/etc/group
vi /etc/sudoers
yuchuan ALL=(ALL) ALL
$ groups
$ chown <username> <filename>
$ chgrp <groupname> <filename>
$ chmod <mode> <filename>
$ chmod go-w ./log