Linux的简单介绍和基础命令使用
这篇文章主要介绍"Linux的简单介绍和基础命令使用",在日常操作中,相信很多人在Linux的简单介绍和基础命令使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"Linux的简单介绍和基础命令使用"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
一、Linux简要介绍
Linux命令基础
Linux命令帮助
目录与文件基本操作
Linux家族
Redhat 红帽 三个认证 (开源但是不免费)---》社区(系统开发者)---》Centos(服务器端)
Ubuntu 最好的客户端系统,开源纯免费(软件开发人群)
Debian ---》kali Linux(专用工具资源占用很少) 树莓派
suse Linux---》ISP(电信,移动,联通) 定制版
shell--Linux系统的一种特殊程序--"翻译官"
用户登录Linux系统时就自动加载一个shell程序,Bash是Linux系统中默认使用的shell程序
Linux的内核是由C语言开发出来的(面向过程的语言),应用程序是用c++开发
编译器-- gcc gcc-c++ jdk(Java的编译器)Python的编译器就是Python2/3
源码文件---》(编译器)--》执行文件
Linux命令的分类
内部命令
外部命令
通用的命令行使用格式:
命令字 [选项] [参数] (对应于操作、功能、操作对象)
-单个字符的组合
-- 单词
对root@localhost ~]# 的介绍
root --当前用户
@ --分隔符
localhost --主机名字
~ --当前目录位置
#--管理员
$ --普通用户
路径简介
绝对路径:例如--/etc/sysconfig/network-scripts/
相对路径(以当前所在位置的路径):例如--sysconfig/
家目录:管理员(/root) 普通用户(/home)
根目录: /
二、Linux命令集(结合实例)
cd:切换工作目录
pwd:查看当前所在的绝对目录路径
[root@lokott ~]# cd /etc/sysconfig/network-scripts/ //进入绝对路径下的文件夹[root@lokott network-scripts]# pwd //显示当前所在的目录的绝对路径/etc/sysconfig/network-scripts[root@lokott network-scripts]# cd - //返回上次进入的目录命令,即cd /etc/sysconfig/network-scripts//root[root@lokott ~]# cd -/etc/sysconfig/network-scripts[root@lokott network-scripts]# cd .. //返回上层目录 [root@lokott sysconfig]# cd ../../ //返回上两层目录 [root@lokott /]#
ls:显示当前目录的内容
-l 显示文件详细信息
-a 查看隐藏文件
-A 查看除了. .. 的隐藏文件
-d 显示本目录的信息
-h 友好形式显示带有单位的信息
-R 递归显示
-- color 以颜色区分文件类型
黑色(数据文件)
蓝色(目录)
红色(压缩包)
绿色(执行文件/命令文件/脚本)
天蓝色(链接文件)
黄的(设备文件/磁盘文件)
[root@lokott ~]# lsanaconda-ks.cfg initial-setup-ks.cfg note shell 公共 模板 视频 图片 文档 下载 音乐 桌面[root@lokott ~]# cd shell/[root@lokott shell]# ls 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello[root@lokott shell]# ls -a. .. 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello[root@lokott shell]# ls -A1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello[root@lokott shell]# ls -l总用量 24-rwxr-xr-x. 1 root root 111 10月 25 19:10 1.sh-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh-rwxr-xr-x. 1 root root 26 10月 25 19:37 6.shdrwxr-xr-x. 2 root root 18 10月 30 13:53 hello[root@lokott shell]# ls -R.:1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello./hello:0.sh[root@lokott shell]# ls -d.[root@lokott shell]# ls -ah. .. 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello[root@lokott shell]# ls -lR.:总用量 24-rwxr-xr-x. 1 root root 111 10月 25 19:10 1.sh-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh-rwxr-xr-x. 1 root root 26 10月 25 19:37 6.shdrwxr-xr-x. 2 root root 18 10月 30 13:53 hello./hello:总用量 0-rwxrwxrwx. 1 root root 0 10月 30 13:53 0.sh[root@lokott shell]#
alias:给命令取一个别名
du:统计目录及文件空间占用情况
-a
-h 友好显示
-s
which: 查找命令存放目录
搜索范围由环境变量PATH决定
mkdir:创建目录
-p递归嵌套创建
touch:创建文件
[root@lokott shell]# alias c='clear' //clear是表示清屏相当于Ctrl+l的操作[root@lokott shell]# which c alias c='clear' /usr/bin/clear[root@lokott shell]# which clear/usr/bin/clear[root@lokott shell]# mkdir linux[root@lokott shell]# ls1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello linux[root@lokott shell]# touch 0.sh[root@lokott shell]# ls0.sh 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello linux[root@lokott shell]# du -ah4.0K ./1.sh4.0K ./2.sh4.0K ./3.sh4.0K ./4.sh4.0K ./5.sh4.0K ./6.sh0 ./hello/0.sh0 ./hello0 ./linux0 ./0.sh24K .[root@lokott shell]# du -sh24K .[root@lokott shell]# du -as //不可以设置选项为-as(h)du: 不能既显示总用量,同时又显示每个项目Try 'du --help' for more information.[root@lokott shell]# [root@lokott shell]# mkdir -p /2019/2018/2017 //连续创建文件夹[root@lokott shell]# cd /2019/2018/2017/[root@lokott 2017]# touch {1..10}.txt //..表示创建连续10个名为1-10的txt文件[root@lokott 2017]# ls10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
下面的操作过程中会出现文件节点(inode值):文件在磁盘中存储的标识序列
ln:创建链接文件(类似于Windows系统的快捷方式)
软链接:相当于快捷方式 -s
硬链接:给文件取别名(无法创建硬链接文件夹)
[root@lokott shell]# ln -s 1.sh 8.sh[root@lokott shell]# ln 1.sh 10.sh[root@lokott shell]# ls -l总用量 28-rwxrwxrwx. 1 root root 0 10月 30 13:59 0.sh-rwxr-xr-x. 2 root root 111 10月 25 19:10 10.sh //硬链接-rwxr-xr-x. 2 root root 111 10月 25 19:10 1.sh-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh-rwxr-xr-x. 1 root root 26 10月 25 19:37 6.shlrwxrwxrwx. 1 root root 4 10月 30 14:07 8.sh -> 1.sh //软链接drwxr-xr-x. 2 root root 18 10月 30 13:53 hellodrwxr-xr-x. 2 root root 6 10月 30 13:59 linux[root@lokott shell]# ls -ih //显示文件节点值的大小19397655 0.sh 20564913 10.sh 20564913 1.sh 20564915 2.sh 20564917 3.sh 20564916 4.sh 20564918 5.sh 20564919 6.sh 19134334 8.sh 20565286 hello 35183604 linux//上面文件左边的就是该文件的文件节点(inode值)软链接与源文件的文件节点是非一致的,而硬链接的文件节点与源文件是一致的
cp :复制文件或目录 源|目标
-f 不询问
-i 询问是否覆盖原有
-p 保持源文件的用户权限不变,权限高用户使用
-r 递归复制
rm:删除
-i:默认提醒
-rf :强制递归删除
mv:移动文件或目录
[root@lokott shell]# cd hello/[root@lokott hello]# ls0.sh[root@lokott hello]# cp ../5.sh .[root@lokott hello]# ls0.sh 5.sh[root@lokott hello]# cp -i ../5.sh .cp:是否覆盖"./5.sh"? yes[root@lokott hello]# cp -f ../5.sh . //猜测被alias了cp:是否覆盖"./5.sh"? y[root@lokott hello]# [root@lokott hello]# which cp //查看cp命令果然是被alias更改了alias cp='cp -i' /usr/bin/cp[root@lokott hello]# cp -r ../linux/ . //递归复制上层路径linux文件夹的所有内容到当前路径(目前无内容)[root@lokott hello]# ls0.sh 5.sh linux[root@lokott hello]# cd linux/[root@lokott linux]# ls[root@lokott linux]# mkdir 2020 //创建文件夹[root@lokott linux]# ls2020[root@lokott linux]# cd 2020/[root@lokott 2020]# touch 2.txt //创建文件[root@lokott 2020]# cd ../../[root@lokott hello]# ls0.sh 5.sh linux[root@lokott hello]# mv linux/ ../ //移动文件夹mv:是否覆盖"../linux"? y[root@lokott hello]# cd ..[root@lokott shell]# ls0.sh 10.sh 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh 8.sh hello linux[root@lokott shell]# ls -l linux/总用量 0drwxr-xr-x. 2 root root 19 10月 30 14:15 2020[root@lokott shell]# cp -r linux/ hello/ //递归复制linux文件夹的所有内容到hello文件夹中[root@lokott shell]# cd hello/[root@lokott hello]# ls0.sh 5.sh linux[root@lokott hello]# ls -l linux/总用量 0drwxr-xr-x. 2 root root 19 10月 30 14:16 2020[root@lokott hello]# ls -lR linux/ //递归查看拷贝过来的文件夹的信息linux/:总用量 0drwxr-xr-x. 2 root root 19 10月 30 14:16 2020linux/2020:总用量 0-rw-r--r--. 1 root root 0 10月 30 14:16 2.txt
通配符
?表示一个
*表示多个
find:查找文件或目录
find 【查找范围】【选项】[表达式]
-name:根据目标名字查找
-type:根据文件类型查找
-size:根据大小查找
-user:根据文件的用户所有者查找
[root@lokott hello]# find . -name "*.sh" //*号表示通配符./0.sh./5.sh[root@lokott hello]# find . -type f./0.sh./5.sh./linux/2020/2.txt[root@lokott hello]# find . -size -10k../0.sh./5.sh./linux./linux/2020./linux/2020/2.txt./ifcfg-ens33[root@lokott hello]# find . -size -10k | du -ah0 ./0.sh4.0K ./5.sh0 ./linux/2020/2.txt0 ./linux/20200 ./linux4.0K ./ifcfg-ens338.0K .
centos7系统启动的命令清单
1. init 0 关机2. init 1 单用户模式(系统维护,破解密码)3. init 2 多用户模式无网络4. init 3 多用户模式有网络 *5. init 4 保留6. init 5多用户模式图形化界面有网络7. init 6 重启 (reboot)
到此,关于"Linux的简单介绍和基础命令使用"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!