Linux常用命令

scp

scp account@HostName:/home/account/*[!.mp3] d:/upload/ #从服务器下载文件
scp -r [filePath] acount@HostName:[remotePath]         #本地上传文件至服务器
ssh user@host 'bash -s' < test.sh init                 #ssh运行加参数的本地脚本

ssh user@host < test.sh                                #ssh直接运行.sh脚本

ssh user@host 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub #将本地公钥id_rsa.pub传给远程主机

用户操作

useradd -d /home/[username] -m [username] //添加用户

adduser [username] 添加用户

userdel -r [username] 删除用户

usermod -G [groupname] [username] 把用户从其他组中去掉,只属于该组

usermod -a -G [groupname] [username] 把用户添加至该组,之前所属组不影响

权限操作

root用户下打开 /etc/sudoers 文件

[username] ALL=NOPASSWD: ALL 某用户不需要密码可以执行sudo

%[groupname] ALL=NOPASSWD: ALL 某组的所有用户不需要密码可执行sudo

 文件操作


chown -R bruce:bruce [filePath]                  #更改文件拥有者及组

tar
--exclude=*.mp3 -zcvf file.tar.gz [filePath] #过滤文件并压缩

tar -xzvf file.tar.gz -C [targetPath] #解压缩至指定目录

ls -lR|grep "^-"|wc -l #统计当前文件夹下文件的个数,包括子文件夹

ls -lR|grep "^d"|wc -l #统计当前文件夹下目录的个数,包括子文件夹

ls -l |grep "^-"|wc -l #统计当前文件夹下文件的个数

ls -l |grep "^d"|wc -l #统计当前文件夹下目录的个数

find -type d -empty | xargs rmdir -p #删除当前目录下所有空文件夹

find temp/*201902* -not -name *20190214* | xargs rm -rf   #删除除某种条件下的文件

ls -1 *.ts | sort -n | xargs cat > merged.ts  #按顺序合并文件到merged.ts

 磁盘操作

du -hd0           #查看当前目录下总空间大小
du -hd0 [path] #查看指定目录下总空间大小
du -hd1 #查看当前目录及各目录的总空间大小

系统操作

systemctl restart sshd.service 重启sshd
原文地址:https://www.cnblogs.com/chenzhaoyu/p/10175471.html