文章目录
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实际运行的命令
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