2024年4月19日发(作者:)

linux常用命令整理:

命令行自动补全工具

yum install bash-completion -y

重启系统生效/或者断开xshell重新连接即可使用

输入输出

ls file1 file2 2>/dev/null

将输出到重定向的文件:

ls file1 file2 &>file3

追加输出:

ls file1 file2 $>>file3

管道

管道使用 | 符号来表示:把上一个命令的输出作为第二个命令的输入。

cat /etd/passwd | tail -3 查看文件内容的后三行

tail -5 /etc/passwd | head -1 找文件的倒数第5行

head -4 /etc/passwd | head -1 找文件的正数第4行

vi编辑器

linux上最常用的编辑器就是vi。

vim编辑器主要有三种模式:

命令模式 dd u yy p

扩展命令模式

编辑模式 i o

扩展命令模式主要实现文件的关键字查找、替换、保存、退出等操作。

:w 保存修改

:q 不保存退出

:wq或者:x或者ZZ: 保存退出

:q! 当修改了文件,不需要保存,使用强制退出。

:set number 临时为每行加上行号

:set nonumber 去掉行号

关闭selinux“

全称 security enhanced linux,为linux增加了很多安全权限,初学者建议管理。

vi /etc/selinux/config

将文档中 SELINUX=enforcing 改成disable

保存后退出,

然后reboot重启,才能够生效。

文件的链接

软硬链接

软链接相当于(symbolic link)类似于windows的快捷方式:

[root@centosnode5 ~]# ll /etc/

lrwxrwxrwx. 1 root root 22 11月 29 03:34 /etc/ ->

../boot/grub2/ #l开头的是软连接

使用md5sum命令查看一个文件的md5值。

[root@centosnode5 bin]# cd /

[root@centosnode5 /]# cd test

[root@centosnode5 test]# mkdir aaa

[root@centosnode5 test]# ln -s aaa bbb

[root@centosnode5 test]# ll

总用量 4

-rw-r--r--. 1 root root 0 3月 16 15:19 123

drwxr-xr-x 2 root root 6 3月 16 16:05 aaa

lrwxrwxrwx 1 root root 3 3月 16 16:05 bbb -> aaa

-rw-r--r--. 1 root root 0 3月 16 14:44 file1

-rw-r--r--. 1 root root 57 3月 16 14:46 file3

[root@centosnode5 test]# touch aaa/1

[root@centosnode5 test]# ls bbb/

1

[root@centosnode5 test]# vi aaa/1

[root@centosnode5 test]# cat bbb/1

aabbbccc

用ll -i 查看inode。

硬链接:是两个inode一致的不同名文件。不可以跨分区。不可以手动对目录做硬链接,但系统默认存

放目录的硬链接。

ll -di /var/mail/

ll -di /var/spool/mail/