Linux 常用小技巧

1.cp -r:递归复制目录下的内容

2.改变文件夹权限:chown username:group directory,不要轻易使用-R

参考:command line - Change folder permissions and ownership - Ask Ubuntu

3.使用lsof /path/to/file查看打开文件的程序

参考:How to determine which process is creating a file? - Unix & Linux Stack Exchange

4.删除文件夹及文件夹中的所有内容:rm -rf /Directory

5.如果想永久的保存alias,修改文件

nano ~/.bashrc

参考:How do I create a permanent Bash alias? - Ask Ubuntu

6.永久修改环境变量

nano /etc/environment

参考:Setting proxy for apt from terminal - Ask Ubuntu

7.显示shell实际运行的命令

参考:bash - How can I see what command was actually run in the shell, through an alias or function - Unix & Linux Stack Exchange

set -x
ls
set +x

8.查找文件

find / -name "index.html"

9.查找文件内容:

grep --recursive  "string" /

10.显示开放的端口和使用的程序:

-> # netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      439/sshd                  
.............

参考:Get a list of Open Ports in Linux - Super User

11.linux改变shell的hostname

参考:bash - How to show the host name in Linux commandline prompt - Unix & Linux Stack Exchange

-> # PS1="test$"
test$

12.删除特殊字符开头的文件

参考:shell - How do I delete a file whose name begins with “-” (hyphen a.k.a. dash or minus)? - Unix & Linux Stack Exchange
比如一个文件名为--help的文件,删除方法如下:

rm -- --help

13.空文件是可执行的

这是一个很坑的点,空文件是可以运行的:

-> # touch test
-> # chmod +x test
-> # ./test
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值