天天看点

Linux命令总结(重制版)

linux command

  • ​​创建一个新用户,并且分配home目录​​
  • ​​删除文件夹中所有文件除了某几个文件或文件夹​​
  • ​​查看文件夹占用空间​​
  • ​​查看硬盘空间​​
  • ​​find和vim联合使用,find查找某个文件后vim直接打开​​
  • ​​nohup​​
  • ​​sed command​​
  • ​​查找文件和文件夹​​
  • ​​list the installed apps​​
  • ​​查找大于某个尺寸的文件​​
  • ​​列出详细信息​​
  • ​​从终端打开文件管理器​​
  • ​​查找进程​​
  • ​​杀死进程​​
  • ​​set proxy​​
  • ​​文件夹和文件设置权限​​
  • ​​find a pid process using a special port​​
  • ​​copy a folder to a remote machine​​

创建一个新用户,并且分配home目录

sudo useradd -m your_user_name
# as root user
passwd      

删除文件夹中所有文件除了某几个文件或文件夹

rm -rf -v !("filename"|"foldername")      

查看文件夹占用空间

du -h /logs   # -h stands for human, which is more readable for human.      

查看硬盘空间

df      

find和vim联合使用,find查找某个文件后vim直接打开

find . -name hello.md -exec vi {} \;
# or
# vi $(find . -name hello.md)      

nohup

​​How to use Nohup in Linux​​

sed command

​​Sed Command in Linux/Unix with examples​​

查找文件和文件夹

find {path} -iname {filename}
eg. find . -iname "server"
e.g.  find . -iname "*kuka*"
# -iname 模糊查找

find {path} -name {filename}
eg. find . -name server
# or find . -type f -name server
# -name 精准查找

# find directory

find . -type d -name ".git"      

list the installed apps

apt list --installed      

查找大于某个尺寸的文件

find {目录}  -type f -size +100k
e.g.  find .      

列出详细信息

ll      

从终端打开文件管理器

nautilus .   # .代表当前目录      

查找进程

ps aux | grep {pid name}
e.g.  ps aux | grep v2ray

# or      

杀死进程

kill pid_num
# kill from name 
pkill      

set proxy

alias setproxy="export ALL_PROXY=socks5://127.0.0.1:1089" 
alias unsetproxy="unset ALL_PROXY"      

文件夹和文件设置权限

文件夹一共有三种权限类型:

  • read
  • write
  • execute

通过使用数字来指定对应的权限:

  • read - 4
  • write - 2
  • execute - 1

使用chmod命令来修改权限,格式为​

​chmod xyz <file or directory>​

​ 其中:

  • x - 代表用户的所有权限的合
  • y - 用户组所有权限的和
  • z - 剩余用户和用户组所有权限的和

比如:

chmod      

代表dell和dell的group拥有对文件夹/home/dell读和写的权限,其他用户组只有读的权限,​

​-R​

​代表递归的对所有文件夹设置权限。

chmod      

find a pid process using a special port

sudo netstat -nlp | grep      

copy a folder to a remote machine

scp      

继续阅读