小总结Linux操作系统核心命令

1.Linux中的路径
/ 表示根目录,是绝对路径
./ 表示当前目录,是相对路径
…/ 表示上一级目录,是相对路径
/root 用户的主目录
/home/username 存放普通用户的个人配置文件
/bin 存放Linux系统中常用的命令
/boot 存放系启动时要用到的文件
/dev 存放Linux的外部设备
/etc 存放系统管理时用到的配置文件和子目录
/sbin 存放管理员的系统管理程序
/lib 存放系统动态链接共享库
/lost+found 系统运行异常时产生错误,会将遗失的片段放在这里。
/mnt 可临时将别的外部设备挂接在此目录下
/proc 存放系统内存中的信息
/usr 用户应用程序和文件都存放在这个目录下
/tmp 存放临时文件的目录

2.VI编辑器或者VIM编辑器
vi filename 生成新文件或者编辑查看文件filename
i或者a 从命令模式进入编辑模式,i为插入文本,a为追加文本
Esc 从编辑模式进入命令模式
:w 保存文本
:wq 保持并退出文本
:wq! 保持并强制退出
:q 退出
:q! 强制退出
o 添加一行
0 在光标所在行的上方添加一行
dd 删除一行文字
D 删除从当前光标到行尾的内容
x 删除一个字符
s 删除一个字符并切换到编辑模式
S 删除一行字符并切换到编辑模式
:n 光标移动至文本第n行
$ 光标移动到文本的行尾
A 光标移动到文本的行尾,并切换到编辑模式。
^ 光标移动到本行的行首
G 光标移动到本文的末尾
gg 光标移动到本文的首行
/字符串 查找某个字符串
n 在查找模式中,继续查找。
:u 撤销(同标准编辑器中的Ctrl + Z)
:redo 重做(同标准编辑器中的Ctrl + Y)

3.Linux的启动级别
文件/etc/inittab 设置默认启动级别
0 代表halt,关机操作,不能设置,否则机器不能启动
1 代表单用户模式,
2 代表多用户模式
3 代表命令行界面,即文本界面
4 系统预留,该级别目前还没有使用
5 代表图形界面
6 代表重启模式,也不能设置。

4.系统关机与重启
reboot 重启
shutdown -r now 现在立刻重启shu
shutdown -r 11:30 等到11:30重启
shutdown -r +1 等一分钟后重启
halt 关机
shutdown -h now 立刻关闭系统
shutdown -h 11:30 等到11:30关机

5.文件操作
文件创建

  • vi /opt/learn/hello.txt 在目录/opt/learn下创建hello.txt并进行vi编辑界面
  • touch /opt/learn/test 在目录/opt/learn/下创建test空白文件
  • cat /opt/learn/catfile 创建文件catfile并在屏幕上输入内容,最后按Ctrl + D退出

文件查看

  • vi /etc/passwd 在vi编辑器中输出文本内容
  • cat /etc/passwd 在屏幕上输出文本内容
  • more /etc/passwd 分屏输出文本内容
  • head -n 10 /etc/passwd 只输出文件的头10行
  • tail -n 20 /etc/passwd 只输出文件尾的20行

文件操作

  • cp hello.txt /opt/test 把文件hello.txt复制到文件/opt/test下
  • cp hello.txt /opt/test/hello.cp 把文件hello.txt复制到文件夹hello.txt /opt/test下并重命名成hello.cp
  • mv hello.txt /opt/test 将文件hello.txt剪切到文件夹opt/test下
  • mv hello.txt /opt/test/hello.mv 将文件hello.txt剪切到文件夹opt/test下,并重命名为hello.mv
  • mv hello.txt hello2.txt 将文件hello.txt重命名为hello2.txt
  • rm /opt/test/hello.cp 删除文件
  • rm -f /opt/test/hello.cp 强制删除文件,不会有提示信息。
  • du -sk hello.txt 查看文件hello.txt的大小(以K为单位)

链接

  • ln -s hello.txt shello 为hello.txt文件创建一个名为shello的软链接(类似于快捷方式)
  • ln -d hello.txt dhello 为hello.txt文件创建一个名为dhello的硬链接,硬链接只要所有文件中更改任意一个,其他文件的所有属性会跟着变化,如大小,更新时间,权限等。

6.文件夹操作
ls/tree

  • ls [option] [file/directory] 显示指定目录下的所有文件或文件夹
  • ls 显示当前目录的内容
  • ls -l 显示当前目录的详细内容
  • ls -a 显示当前目录下的所有文件,包括隐藏文件
  • ls *.txt 显示目录下所有以.txt为后缀名的文件
  • ls /opt/training 显示目录/opt/training下的内容
  • ls -R /opt/ 列出所有/opt以及其子目录的内容
  • tree /opt 用树状结构显示目录及文件

pwd

  • pwd 显示当前所在目录

cd

  • cd directory 切换到指定目录
  • cd 切换到当前用户所有的主目录
  • cd … 回退到当前目录的上一级目录
  • cd /opt/learn 用绝对路径切换到/opt/learn目录下

mkdir

  • mkdir /opt/learn/other 在目录/opt/learn下创建目录other
  • mkdir dir2 dir3 dir4 同时创建 dir2 dir3 dir4 三个目录
  • mkdir -p /dir1/dir2/dir3/dir4 同时创建一个四层目录

rmdir

  • rmdir dir1 删除一个空目录

其他操作

  • cp -r dir2 /opt/learn /opt/learn2 拷贝文件夹
  • mv /opt/learn2 /opt/learn3 重命名文件夹
  • rm -rf /opt/learn3 强制删除文件夹

7.权限操作
用户组

  • groupadd testing 添加一个新的用户组testing
  • cat /etc/group 查看组是否被新增成功
  • groupmod -n test testing 给testing重命名为test
  • groupdel test 删除组test
  • groups root 查看用户root所在的所有组

useradd

  • useradd qiang 新增一个用户qiang(默认时新增一个对应的名为qiang组)
  • useradd -g test denny 新增一个用户denny添加到test组

usermod

  • usermod -g dev qiang 将用户qiang换到dev组
  • usermod -G 502 qiang 将用户qiang附加到gid为502的这个 组
  • usermod -d /home/mary /home/temp/mary 将mary的主目录从/home/mary改为/home/temp/mary

userdel

  • userdel qiang 删除用户qiang
  • userdel -f qiang 强制删除用户qiang(即使该用户已经登录)
  • userdel -r qiang 删除用户qiang并删除其主目录

chmod

  • chmod [权限] [文件或目录] 更改文件或目录的权限
  • chmod u+x hello.txt 为hello.txt 文件所有者添加可执行权限
  • chmod u-w hello.txt 为hello.txt 文件所有者去除可执行权限
  • chmod g-r hello.txt 为hello.txt 文件所在组去除可读权限
  • chmod o+x hello.txt 为hello.txt 文件所在组的其他组添加可执行权限
  • chmod a+x hello.txt 为所有三种角色添加可写权限
  • chmod 777 将hello.txt权限设置为rwxrwxrwx
  • chmod 763 将hello.txt权限设置rwxrw-wx-

chown

  • chown mary hello.txt 将hello.txt的文件所有者改为mary

chgrp

  • chgrp test hello.txt 将hello.txt所在组改为test

passwd

  • passwd passwd mary 修改mary的密码

文件查找
find

  • find 起始目录 查找类型 查找条件 查找起始目录及所有子目录下的文件及文件夹
  • find . -name “hello.txt” 查找当前目录下文件名为 hello.txt的文件或文件夹
  • find . -name “* hello *” 查找当前目录下包含hello的文件或者文件夹
  • find /home -name “* hello *” 查找/home目录下包含hello的文件或者文件夹
  • find -name “*” 查找当前目录下所有文件或者文件夹

grep

  • grep [选项]匹配模式 目标文件 基于行对目标文件的内容进行查找
  • grep “root” /etc/passwd 查找/etc/passwd文件中包含root的行
  • grep -n “root” /etc/passwd 查找/etc/passwd文件中包含root的行,并输出行号

归档压缩及其它
tar/gzip

  • tar -cvf hello.tar hello.txt 将helllo.txt归档并命名成hello.tar
  • tar -cvf hello.tar /opt/test 将/opt/test归档并命名成test.tar
  • tar -tf test.tar 将test.tar中的文件显示出来
  • tar -xvf test.tar 提取归档文件中的内容
  • gzip hello.tar 将归档文件hello.tar 压缩成hello.tar.gz
  • gzip -d hello.tar.gz 解压缩文件成hello.tar

zip

  • zip hello.zip hello.txt 将hello.txt 压缩并命名为hello.zip
  • zip -r test.zip /opt/test 将/opt/test 目录压缩
  • unzip -v hello.zip 查看压缩文件hell.zip 中的文件信息
  • unzip hello.zip 解压缩hello.zip

su

  • su -root 从当前用户切换到root用户(然后使用root的环境变量)
  • su root 从当前用户切换到root用户(然后使用当前用户的环境变量)

ps

  • ps 查看当前终端正在运行的进程
  • ps -ef 查看系统正在运行的所有进程
  • ps -ef | grep bash 查看系统正在运行的进程名包含bash的进程

kill

  • kill pid 根据进程号终止进程的运行
  • kill -9 pid 强制终止
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值