活动

天翼云最新优惠活动,涵盖免费试用,产品折扣等,助您降本增效!
热门活动
  • 618智算钜惠季 爆款云主机2核4G限时秒杀,88元/年起!
  • 免费体验DeepSeek,上天翼云息壤 NEW 新老用户均可免费体验2500万Tokens,限时两周
  • 云上钜惠 HOT 爆款云主机全场特惠,更有万元锦鲤券等你来领!
  • 算力套餐 HOT 让算力触手可及
  • 天翼云脑AOne NEW 连接、保护、办公,All-in-One!
  • 中小企业应用上云专场 产品组合下单即享折上9折起,助力企业快速上云
  • 息壤高校钜惠活动 NEW 天翼云息壤杯高校AI大赛,数款产品享受线上订购超值特惠
  • 天翼云电脑专场 HOT 移动办公新选择,爆款4核8G畅享1年3.5折起,快来抢购!
  • 天翼云奖励推广计划 加入成为云推官,推荐新用户注册下单得现金奖励
免费活动
  • 免费试用中心 HOT 多款云产品免费试用,快来开启云上之旅
  • 天翼云用户体验官 NEW 您的洞察,重塑科技边界

智算服务

打造统一的产品能力,实现算网调度、训练推理、技术架构、资源管理一体化智算服务
智算云(DeepSeek专区)
科研助手
  • 算力商城
  • 应用商城
  • 开发机
  • 并行计算
算力互联调度平台
  • 应用市场
  • 算力市场
  • 算力调度推荐
一站式智算服务平台
  • 模型广场
  • 体验中心
  • 服务接入
智算一体机
  • 智算一体机
大模型
  • DeepSeek-R1-昇腾版(671B)
  • DeepSeek-R1-英伟达版(671B)
  • DeepSeek-V3-昇腾版(671B)
  • DeepSeek-R1-Distill-Llama-70B
  • DeepSeek-R1-Distill-Qwen-32B
  • Qwen2-72B-Instruct
  • StableDiffusion-V2.1
  • TeleChat-12B

应用商城

天翼云精选行业优秀合作伙伴及千余款商品,提供一站式云上应用服务
进入甄选商城进入云市场创新解决方案
办公协同
  • WPS云文档
  • 安全邮箱
  • EMM手机管家
  • 智能商业平台
财务管理
  • 工资条
  • 税务风控云
企业应用
  • 翼信息化运维服务
  • 翼视频云归档解决方案
工业能源
  • 智慧工厂_生产流程管理解决方案
  • 智慧工地
建站工具
  • SSL证书
  • 新域名服务
网络工具
  • 翼云加速
灾备迁移
  • 云管家2.0
  • 翼备份
资源管理
  • 全栈混合云敏捷版(软件)
  • 全栈混合云敏捷版(一体机)
行业应用
  • 翼电子教室
  • 翼智慧显示一体化解决方案

合作伙伴

天翼云携手合作伙伴,共创云上生态,合作共赢
天翼云生态合作中心
  • 天翼云生态合作中心
天翼云渠道合作伙伴
  • 天翼云代理渠道合作伙伴
天翼云服务合作伙伴
  • 天翼云集成商交付能力认证
天翼云应用合作伙伴
  • 天翼云云市场合作伙伴
  • 天翼云甄选商城合作伙伴
天翼云技术合作伙伴
  • 天翼云OpenAPI中心
  • 天翼云EasyCoding平台
天翼云培训认证
  • 天翼云学堂
  • 天翼云市场商学院
天翼云合作计划
  • 云汇计划
天翼云东升计划
  • 适配中心
  • 东升计划
  • 适配互认证

开发者

开发者相关功能入口汇聚
技术社区
  • 专栏文章
  • 互动问答
  • 技术视频
资源与工具
  • OpenAPI中心
开放能力
  • EasyCoding敏捷开发平台
培训与认证
  • 天翼云学堂
  • 天翼云认证
魔乐社区
  • 魔乐社区

支持与服务

为您提供全方位支持与服务,全流程技术保障,助您轻松上云,安全无忧
文档与工具
  • 文档中心
  • 新手上云
  • 自助服务
  • OpenAPI中心
定价
  • 价格计算器
  • 定价策略
基础服务
  • 售前咨询
  • 在线支持
  • 在线支持
  • 工单服务
  • 建议与反馈
  • 用户体验官
  • 服务保障
  • 客户公告
  • 会员中心
增值服务
  • 红心服务
  • 首保服务
  • 客户支持计划
  • 专家技术服务
  • 备案管家

了解天翼云

天翼云秉承央企使命,致力于成为数字经济主力军,投身科技强国伟大事业,为用户提供安全、普惠云服务
品牌介绍
  • 关于天翼云
  • 智算云
  • 天翼云4.0
  • 新闻资讯
  • 天翼云APP
基础设施
  • 全球基础设施
  • 信任中心
最佳实践
  • 精选案例
  • 超级探访
  • 云杂志
  • 分析师和白皮书
  • 天翼云·创新直播间
市场活动
  • 2025智能云生态大会
  • 2024智算云生态大会
  • 2023云生态大会
  • 2022云生态大会
  • 天翼云中国行
天翼云
  • 活动
  • 智算服务
  • 产品
  • 解决方案
  • 应用商城
  • 合作伙伴
  • 开发者
  • 支持与服务
  • 了解天翼云
      • 文档
      • 控制中心
      • 备案
      • 管理中心
      文档中心

      科研助手

      科研助手

        • 产品动态
        • 产品介绍
        • 产品公告
        • Comfyui安全风险通告
        • Pytorch安全风险通告
        • 什么是科研助手
        • 产品特性
        • 产品优势
        • 应用场景
        • 术语解释
        • 约束与限制
        • 科研助手2.0
        • 计费说明
        • 计费概述
        • 计费项
        • 计费方式
        • 套餐包
        • 包周期
        • 欠费说明
        • 快速入门
        • 准备工作
        • 创建开发机
        • 免费体验包
        • 用户指南
        • 总览
        • 开发机
        • 创建开发机
        • 查询开发机
        • 启动开发机
        • 打开开发机
        • VNC介绍
        • 在线IDE介绍
        • 停止开发机
        • 变更开发机规格
        • 保存自定义镜像
        • 变更镜像
        • 删除开发机
        • 查看开发机详情
        • 并行计算
        • 作业管理
        • 作业类型
        • 创建作业
        • 查看作业详情
        • 暂停和恢复作业
        • 终止作业
        • 删除作业
        • 作业监控
        • 模板管理
        • 创建作业模板
        • 通过作业模板创建作业
        • 管理作业模板
        • 创建任务模板
        • 通过任务模板创建作业
        • 管理任务模板
        • 科研服务
        • 服务部署
        • 部署新服务
        • 启动服务
        • 查看服务
        • 停止服务
        • 删除服务
        • 数据存储
        • 存储网络
        • 创建存储网络
        • 查看存储网络
        • 存储源管理
        • 创建存储源
        • 查看存储源
        • 删除存储源
        • 自建NFS存储安全配置
        • 数据集管理
        • 创建数据集
        • 查看数据集列表
        • 查看数据集详情
        • 删除数据集
        • 网盘数据集
        • 在开发环机引用数据集
        • 科研文件管理
        • 创建科研文件
        • 查看科研文件
        • 删除科研文件
        • 镜像管理
        • 查看开发机镜像
        • 分享开发机镜像
        • 删除开发机镜像
        • 资源配额
        • 资源池管理
        • 共享资源池
        • 创建共享集群
        • 管理共享集群
        • 队列管理
        • 创建队列
        • 编辑队列
        • 查看队列列表
        • 查看队列详情
        • 删除队列
        • 科研版
        • 开发机
        • 创建开发机
        • 查询开发机
        • 启动开发机
        • 打开开发机
        • 在线IDE介绍
        • VNC介绍
        • 停止开发机
        • 变更开发机规格
        • 保存自定义镜像
        • 变更镜像
        • 删除开发机
        • 查看开发机详情
        • 并行计算
        • 创建并行计算
        • 查看并行计算
        • 停止并行计算
        • 删除并行计算
        • 并行计算模板
        • 数据存储
        • 数据集管理
        • 创建数据集
        • 查看数据集
        • 删除数据集
        • 上传/下载数据
        • 网盘数据集
        • 在开发机中引用数据集
        • 科研文件管理
        • 创建科研文件
        • 查看科研文件
        • 删除科研文件
        • 自定义镜像
        • 查看开发机镜像
        • 分享开发机镜像
        • 删除开发机镜像
        • CTIAM已上线权限点及说明
        • 最佳实践
        • 开发机快照实例
        • 在科研助手上使用Qwen3进行科研服务
        • 钢筋计数模型训练教学与实践
        • Linux系统基础命令实验
        • MySQL教学与实践
        • 使用科研文件存放和加载专属Conda环境
        • 在科研助手上使用OpenManus快速生成应用
        • 科研助手解锁 OWL 智能体,启动任务 “开挂” 模式
        • 适用于科研教育的主子账号及预警配额设置
        • 在科研助手上使用并行计算训练模型
        • 在科研助手上使用Dify搭建DeepSeek知识库
        • 在科研助手上使用AnythingLLM搭建DeepSeek知识库
        • 在科研助手上使用DeepSeek进行科研服务
        • 在科研助手上使用SD-Trainer进行模型微调
        • 在科研助手上使用Stable Diffusion进行图像生成
        • 在科研助手上使用LangChain-ChatChat-基于本地知识库的问答应用
        • 在科研助手上使用LLaMA Factory进行模型LLMs微调
        • 在科研助手上使用Open WebUI对LLM模型推理
        • 在科研助手上使用ComfyUI进行复杂图像生成
        • 科研助手并行计算使用外部镜像仓库
        • 常见问题
        • 应用类
        • 计费类
        • 功能类
        • 技术运维类
        • API参考
        • API概览
        • 文档下载
        • 操作手册
        • 相关协议
        • 科研助手服务协议
        • 科研助手服务等级协议
        • 科研助手计费协议
        • 社区镜像用户服务协议
        • 科研助手服务条款
        • 科研助手SSH服务使用协议
          无相关产品

          本页目录

          帮助中心科研助手最佳实践Linux系统基础命令实验
          Linux系统基础命令实验
          更新时间 2025-04-01 21:53:37
          • 新浪微博
          • 微信
            扫码分享
          • 复制链接
          最近更新时间: 2025-04-01 21:53:37
          分享文章
          • 新浪微博
          • 微信
            扫码分享
          • 复制链接
          本实验基于科研助手环境,主要介绍Linux的基本命令,帮助大家了解并掌握基本的Linux命令。

          实验概述

          实验背景

          Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和Unix的多用户、多任务、支持多线程和多CPU的操作系统。它能运行主要的Unix工具软件、应用程序和网络协议。它支持32位和64位硬件。Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。**

          实验介绍

          本实验基于科研助手环境,主要介绍Linux的基本命令,帮助大家了解并掌握基本的Linux命令。

          实验环境

          1、进入科研助手控制台-应用商城页面,选择【类型】为“教学与实践”,“Linux系统教学与实践"镜像,点击“使用此镜像”

          1.png

          2、进入开发机购买页面,资源可以选择CPU,CPU: 4核 内存: 16GB即可满足教学环境。框架版本为预置的jupyter-mysqltraining。

          2.png

          3、购买完成后,回到开发机列表,点击【打开】进入开发机。

          4.png

          4、跳转至jupyter环境,点击【终端】可直接进入实验环境。

          3.png

          前置说明

          实验手册的文件名以及目录仅供参考,大家可设置为自己便于操作的文件名或者目录,或者加上唯一标识,比如名字缩写。

          命令实操

          查看文件夹

          以当前所在目录为/home为例:

          步骤1 查看当前文件夹信息

          输入:

          ls
          

          输出:

          batchcom  dataset-bc-pub
          

          使用ls命令,查看当前目录下的所有文件及文件夹。

          输入命令ls --help 查看ls命令详情。

          输入:

          ls --help
          

          输出:

          Usage: ls [OPTION]... [FILE]...
          List information about the FILEs (the current directory by default).
          Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
          
          Mandatory arguments to long options are mandatory for short options too.
          -a, --all                  do not ignore entries starting with .
          -A, --almost-all           do not list implied . and ..
             --author               with -l, print the author of each file
          
          ...
          ...
          GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
          For complete documentation, run: info coreutils 'ls invocation'
          

          ls的命令参数有很多,本实验将一些经常使用的参数进行一一列举,帮助大家去了解ls命令。

          步骤2 列表方式查看当前文件夹信息

          输入:

          ls -l
          

          输出:

          total 8
          -rw-r--r-- 1 batchcom batchcom 7637 Apr  1 10:44 Mysql教学.ipynb
          drwxr-x--- 1 batchcom batchcom   70 Apr  1 10:02 batchcom
          drwxrwxrwx 8 root     root      168 Mar 15 22:46 dataset-bc-pub
          

          ls -l 按照列表的形式,输出当前目录的所有信息。

          一般关注文件的类型、文件的权限、文件所属的用户及用户组、文件的创建时间和文件的名称,对于文件的硬链接数本实验暂不关注。

          这里的信息可以分为8个部分。

          参数选项 描述 备注
          - d 描述当前文件类型
          rw-rw-r-- 描述当前文件的权限,三个为一组 第一组对应的为该文件用户的权限 第二组为文件所属用户组的权限 第三组为其他用户组的权限 r:可读 w:可写 x:可执行 -:无权限
          1 1 8
          batchcom 当前文件的所属的用户 文件属于batchcom用户创建
          batchcom 当前文件所属的用户组 文件归属于batchcom用户组
          7637 70 168
          Apr 1 10:44 文件的创建时间
          Mysql教学.ipynb 文件的名称

          ls -l 在Linux使用中也会简写为 ll 。

          步骤3 查看文件夹中所有信息

          输入:

          ls -a
          

          输出:

          .  ..  .ipynb_checkpoints  Mysql教学.ipynb  batchcom  dataset-bc-pub
          

          ls -a 把当前目录的所有信息都列举出来,同时包含隐藏文件。

          在Linux系统中 . 开头的文件一般是隐藏文件。

          . 表示当前文件夹。

          .. 表示父目录。

          步骤4 按文件大小查看文件夹信息

          输入:

          ls -lS
          

          输出:

          total 56
          -rw-r--r-- 1 batchcom batchcom 55611 Apr  1 10:53 Mysql教学.ipynb
          drwxrwxrwx 8 root     root       168 Mar 15 22:46 dataset-bc-pub
          drwxr-x--- 1 batchcom batchcom    70 Apr  1 10:02 batchcom
          

          参数S使得ls的输出项按照文件大小从大到小排序。

          -lS ls命令支持多个参数项拼凑在一起生效。这里表示ls的输出项按照文件大小从大到小以文件列表的形式展示输出项。也可以分开来生效,即 ls -l -S。

          步骤5 列表方式查看其他目录

          输入:

          ls -l /
          

          输出:

          total 4
          lrwxrwxrwx    1 root root    7 Jan 26 10:05 bin -> usr/bin
          drwxr-xr-x    2 root root    6 Apr 18  2022 boot
          drwxr-xr-x    5 root root  440 Apr  1 10:50 dev
          drwxr-xr-x    1 root root 4096 Apr  1 10:52 etc
          drwxrwxrwx    1 root root   47 Apr  1 10:53 home
          lrwxrwxrwx    1 root root    7 Jan 26 10:05 lib -> usr/lib
          lrwxrwxrwx    1 root root    9 Jan 26 10:05 lib32 -> usr/lib32
          lrwxrwxrwx    1 root root    9 Jan 26 10:05 lib64 -> usr/lib64
          lrwxrwxrwx    1 root root   10 Jan 26 10:05 libx32 -> usr/libx32
          drwxr-xr-x    2 root root    6 Jan 26 10:05 media
          drwxr-xr-x    2 root root    6 Jan 26 10:05 mnt
          drwxr-xr-x    1 root root   35 Apr  1 09:59 opt
          dr-xr-xr-x 1420 root root    0 Apr  1 10:50 proc
          drwx------    2 root root   37 Jan 26 10:13 root
          drwxr-xr-x    1 root root   20 Apr  1 10:51 run
          lrwxrwxrwx    1 root root    8 Jan 26 10:05 sbin -> usr/sbin
          drwxr-xr-x    2 root root    6 Jan 26 10:05 srv
          dr-xr-xr-x   13 root root    0 Mar 17 00:26 sys
          drwxrwxrwt    1 root root   28 Apr  1 10:52 tmp
          drwxr-xr-x    1 root root   53 Jan 26 10:05 usr
          drwxr-xr-x    1 root root   41 Jan 26 10:13 var
          

          ls 一般默认是查看当前目录下的文件信息,也支持查看其他文件夹的信息。在命令最后紧跟一个绝对路径或者相对路径,可以查看输入的path下的目录信息。

          查看当前目录的绝对路径

          步骤1 查看当前目录的绝对路径

          输入:

          pwd
          

          输出:

          /home
          

          表示当前路径的绝对路径。

          在Linux操作中,需要通过pwd命令查看当前路径的绝对路径,避免因为手写错误或者记忆错误造成文件路径写错,减少可预见的错误操作。

          在Linux操作过程中,Shell客户端界面只会显示当前父目录的名称,而不会显示全部的目录地址。

          切换目录

          步骤1 切换至根目录

          输入:

          cd /
          

          输入:

          ls
          

          输出:

          bin   dev  home  lib32  libx32  mnt  proc  run   srv  tmp  var
          boot  etc  lib   lib64  media   opt  root  sbin  sys  usr
          

          通过Shell的客户端界面可以看到,当前目录从~切换到了/,也就是根目录下,同时查看根目录下的文件信息,进行核实。

          ~ 波浪线代表的目录地址为当前用户的主目录。

          输入:

          cd ~
          

          输入:

          pwd
          

          输出:

          /home/batchcom
          

          输入:

          ls
          

          输出:

          log
          

          可以看到通过切换路径为~,可以直接切换到当前用户的用户主目录。

          创建目录

          步骤1 创建新目录

          输入:

          cd /home
          mkdir ./mkdir_test
          

          输入:

          ll
          

          输出:

          total 56
          -rw-r--r-- 1 batchcom batchcom 55611 Apr  1 10:53 Mysql教学.ipynb
          drwxr-x--- 1 batchcom batchcom    70 Apr  1 10:56 batchcom
          drwxrwxrwx 8 root     root       168 Mar 15 22:46 dataset-bc-pub
          drwxr-xr-x 2 batchcom batchcom     6 Apr  1 10:58 mkdir_test
          

          在用户目录下创建一个文件夹,命名为mkdir_test。

          mkdir 创建目录默认在当前目录下创建指定的文件夹,也可以紧跟对应的路径。

          输入:

          mkdir --help
          

          步骤2 创建多级目录

          输入:

          mkdir -p /home/dir1/dir2/dir3
          

          输入:

          ls -R /home/dir1
          

          输出:

          /home/dir1:
          dir2
          
          /home/dir1/dir2:
          dir3
          
          /home/dir1/dir2/dir3:
          

          mkdir默认只能在目录下创建子目录,无法在不存在的子目录下创建孙子目录。因此通过-p参数,递归地创建目录,避免因为目录不存在而造成目录创建失败。

          如果不加-p参数。

          输入:

          mkdir ~/dir11/dir2/dir3
          

          输出:

          mkdir: cannot create directory ‘/home/batchcom/dir11/dir2/dir3’: No such file or directory
          

          用户无法创建目录dir3,因为不存在目录/root/dir11/dir2。

          删除目录

          步骤1 删除一个目录

          输入:

          rmdir /home/dir1
          

          输出:

          rmdir: failed to remove '/home/dir1': Directory not empty
          

          rmdir在删除目录的时候需要目录内为空,即不存在文件和文件夹。

          可以通过rmdir --help查看命令使用。

          输入:

          rmdir --help
          

          步骤2 删除多级目录

          如果需要删除多个文件夹,需要添加-rf参数。

          输入:

          rm -rf /home/dir1
          

          输入:

          ll
          

          输出:

          total 24
          drwxrwxrwx 1 root     root       109 Apr  1 13:00 ./
          drwxr-xr-x 1 root     root        51 Apr  1 11:46 ../
          drwxr-xr-x 1 batchcom batchcom    42 Apr  1 10:44 .ipynb_checkpoints/
          -rw-r--r-- 1 batchcom batchcom 16749 Apr  1 11:50 Mysql教学.ipynb
          drwxr-x--- 1 batchcom batchcom   109 Apr  1 12:57 batchcom/
          drwxrwxrwx 5 root     root        71 Mar 26 15:42 dataset-assist-0/
          drwxrwxrwx 4 root     root      4096 Feb 26 16:59 dataset-bc-pub/
          drwxrwxrwx 3 root     root        83 Mar 20 18:10 dataset-fs-0/
          drwxr-xr-x 2 batchcom batchcom     6 Apr  1 12:57 mkdir_test/
          

          创建文件

          步骤1 创建空白文件

          输入:

          cd ~
          

          输入:

          touch file1
          

          输入:

          ls
          

          输出:

          file1  log  mkdir_test
          

          创建一个名叫file1的空白文件。

          输入:

          touch --help
          

          步骤2 创建指定时间戳的文件

          输入:

          touch -t 202504011230 file2
          

          输入:

          ll
          

          输出:

          total 20
          drwxr-x--- 1 batchcom batchcom  135 Apr  1 13:02 ./
          drwxrwxrwx 1 root     root      109 Apr  1 13:00 ../
          -rw------- 1 batchcom batchcom 1203 Apr  1 11:48 .bash_history
          -rw-r--r-- 1 batchcom batchcom  220 Jan  7  2022 .bash_logout
          -rw-r--r-- 1 batchcom batchcom 4240 Mar 11 15:02 .bashrc
          drwxr-xr-x 3 batchcom batchcom   17 Apr  1 10:02 .cache/
          drwxr-xr-x 1 batchcom batchcom   29 Apr  1 10:44 .ipython/
          drwxr-xr-x 1 batchcom batchcom   33 Apr  1 10:44 .jupyter/
          drwxr-xr-x 1 batchcom batchcom   19 Apr  1 09:59 .local/
          -rw-r--r-- 1 batchcom batchcom  807 Jan  7  2022 .profile
          drwxr-xr-x 1 batchcom batchcom   29 Apr  1 09:59 .supervisor-pid/
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 13:01 file1
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 12:30 file2
          drwxr-xr-x 1 batchcom batchcom   24 Apr  1 09:59 log/
          drwxr-xr-x 2 batchcom batchcom    6 Apr  1 12:57 mkdir_test/
          

          使用-t参数创建了一个指定的时间戳202504011230的文件file2。

          -t参数后面紧跟的时间戳格式为[[CC]YY]MMDDhhmm[.ss]。

          步骤3 更新文件时间戳

          输入:

          touch -r file1 file2
          

          输入:

          ls -l
          

          输出:

          total 20
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 13:01 file1
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 13:01 file2
          drwxr-xr-x 1 batchcom batchcom   24 Apr  1 09:59 log/
          drwxr-xr-x 2 batchcom batchcom    6 Apr  1 12:57 mkdir_test/
          

          使用-r参数,指定file1文件的时间戳作为file2文件的时间戳。使得file2文件的时间戳得到了更新。

          步骤4 创建多个文件

          输入:

          touch file3 file4
          

          输入:

          ls
          

          输出:

          file1  file2  file3  file4  log  mkdir_test
          

          touch命令后紧跟多个文件名称,会自动创建多个文件。

          文件复制

          步骤1 文件复制

          输入:

          cp file1 file1_cp
          

          输入:

          ls
          

          输出:

          file1  file1_cp  file2  file3  file4  log  mkdir_test
          

          通过cp命令复制file1文件,并命名为file1_cp。这里是重新创建了一个文件。

          可以通过输入cp --help查看使用规则:

          cp --help
          

          cp的命令虽然参数很多,但常用的参数比较少,一般都是直接复制文件即可。cp后面紧跟的就是两个文件的路径。

          步骤2 保留文件属性复制

          使用-a参数复制文件保留文件属性

          输入:

          cp -a file1 file1_cp_a
          

          输入:

          ls -l
          

          输出:

          total 20
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 13:01 file1
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 13:04 file1_cp
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 13:01 file1_cp_a
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 13:01 file2
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 13:04 file3
          -rw-r--r-- 1 batchcom batchcom    0 Apr  1 13:04 file4
          drwxr-xr-x 1 batchcom batchcom   24 Apr  1 09:59 log/
          drwxr-xr-x 2 batchcom batchcom    6 Apr  1 12:57 mkdir_test/
          

          file1_cp_a文件的所有属性与file1保持一致。

          步骤3 文件夹复制

          创建一个新的文件夹dir1之后使用-r参数复制文件夹。

          输入:

          mkdir dir1
          

          输入:

          cp -r dir1 dir1_cp
          

          输入:

          ls -l
          

          输出:

          total 0
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 13:06 dir1
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 13:07 dir1_cp
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:01 file1
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file1_cp
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:01 file1_cp_a
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:01 file2
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file3
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file4
          drwxr-xr-x 1 batchcom batchcom 24 Apr  1 09:59 log
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 12:57 mkdir_test
          

          通过-r参数可以复制文件夹,也可以添加-a参数来复制文件夹的所有属性。

          输入:

          cp -a -r dir1 dir1_cp_a
          

          输入:

          ls -l
          

          输出:

          total 0
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 13:06 dir1
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 13:07 dir1_cp
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 13:06 dir1_cp_a
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:01 file1
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file1_cp
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:01 file1_cp_a
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:01 file2
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file3
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file4
          drwxr-xr-x 1 batchcom batchcom 24 Apr  1 09:59 log
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 12:57 mkdir_test
          

          文件移动

          文件移动命令mv,通过mv移动文件,类似于Windows的剪切,同时做剪切过程中也可以进行文件的重命名。

          可以使用mv -help查看使用规则,输入:

          mv --help
          

          步骤1 文件移动

          将文件file1移动至文件夹dir1中。

          输入:

          mv file1 dir1/
          

          输入:

          ll dir1/
          

          输出:

          total 0
          drwxr-xr-x 2 batchcom batchcom  19 Apr  1 13:09 ./
          drwxr-x--- 1 batchcom batchcom 226 Apr  1 13:09 ../
          -rw-r--r-- 1 batchcom batchcom   0 Apr  1 13:01 file1
          

          mv的第一个参数为对应的文件路径,第二个参数为目标路径。如果第二个参数为目录路径,那么移动之后的文件名称保持一致;如果第二个参数为文件路径,那么移动之后的文件名称会自动重命名。

          输入:

          mv file1_cp dir1/file1_cp_mv
          

          输入:

          ll dir1
          

          输出:

          total 0
          drwxr-xr-x 2 batchcom batchcom  38 Apr  1 13:10 ./
          drwxr-x--- 1 batchcom batchcom 210 Apr  1 13:10 ../
          -rw-r--r-- 1 batchcom batchcom   0 Apr  1 13:01 file1
          -rw-r--r-- 1 batchcom batchcom   0 Apr  1 13:04 file1_cp_mv
          

          移动完成之后原来的文件就会消失。

          输入:

          ll
          

          输出:

          total 0
          drwxr-xr-x 2 batchcom batchcom 38 Apr  1 13:10 dir1
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 13:07 dir1_cp
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 13:06 dir1_cp_a
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:01 file1_cp_a
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:01 file2
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file3
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file4
          drwxr-xr-x 1 batchcom batchcom 24 Apr  1 09:59 log
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 12:57 mkdir_test
          

          步骤2 文件夹移动

          将文件夹dir1_cp移动至dir1。

          输入:

          mv dir1_cp dir1
          

          输入:

          ll dir1
          

          输出:

          total 0
          drwxr-xr-x 3 batchcom batchcom  53 Apr  1 13:11 ./
          drwxr-x--- 1 batchcom batchcom 195 Apr  1 13:11 ../
          drwxr-xr-x 2 batchcom batchcom   6 Apr  1 13:07 dir1_cp/
          -rw-r--r-- 1 batchcom batchcom   0 Apr  1 13:01 file1
          -rw-r--r-- 1 batchcom batchcom   0 Apr  1 13:04 file1_cp_mv
          

          文件夹的移动与文件移动是一样的。是否会自动重命名看第二个参数是什么路径。如果是目录路径则不重命名,如果不是则会自动重命名。

          步骤3 移动文件夹内某些文件

          移动dir1中的file开头的文件至文件夹dir1_cp_a中。

          输入:

          mv dir1/file* dir1_cp_a
          

          输入:

          ll dir1
          

          输出:

          total 0
          drwxr-xr-x 3 batchcom batchcom  21 Apr  1 13:11 ./
          drwxr-x--- 1 batchcom batchcom 195 Apr  1 13:11 ../
          drwxr-xr-x 2 batchcom batchcom   6 Apr  1 13:07 dir1_cp/
          

          输入:

          ll dir1_cp_a
          

          输出:

          total 0
          drwxr-xr-x 2 batchcom batchcom  38 Apr  1 13:11 ./
          drwxr-x--- 1 batchcom batchcom 195 Apr  1 13:11 ../
          -rw-r--r-- 1 batchcom batchcom   0 Apr  1 13:01 file1
          -rw-r--r-- 1 batchcom batchcom   0 Apr  1 13:04 file1_cp_mv
          

          通过name*的方式去匹配文件夹中以name为开头的文件。

          文件删除

          通过命令rm做文件删除操作。

          可以通过rm --help查看使用规则,输入:

          rm --help
          

          步骤1 删除文件

          删除文件file2

          输入:

          rm file2
          

          输入:

          ls -l
          

          输出:

          total 0
          drwxr-xr-x 3 batchcom batchcom 21 Apr  1 13:11 dir1
          drwxr-xr-x 2 batchcom batchcom 38 Apr  1 13:11 dir1_cp_a
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:01 file1_cp_a
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file3
          -rw-r--r-- 1 batchcom batchcom  0 Apr  1 13:04 file4
          drwxr-xr-x 1 batchcom batchcom 24 Apr  1 09:59 log
          drwxr-xr-x 2 batchcom batchcom  6 Apr  1 12:57 mkdir_test
          

          rm命令紧跟文件的路径,表示删除对应该路径下的文件。

          步骤2 删除多个文件

          删除文件file3 file4

          输入:

          rm file3 file4
          

          输入:

          ls
          

          输出:

          dir1  dir1_cp_a  file1_cp_a  log  mkdir_test
          

          rm 后面紧跟多个文件可以删除多个文件。如果文件有规律,也可以使用通配符*的方式来匹配。

          rm file*
          

          步骤3 删除文件夹

          删除文件夹dir1。

          输入:

          rm -r dir1
          

          输入:

          ls
          

          输出:

          dir1_cp_a  file1_cp_a  log  mkdir_test
          

          rm默认只能删除文件,通过参数-r可以删除文件夹。

          rm 删除操作之后文件就丢失了,因此在操作过程中做删除操作的时候需要多多注意待删除的目标文件或者文件夹的路径是否正确。

          rm -r也支持删除多个文件夹。需要在后面紧跟多个文件夹,也可以使用通配符来匹配。

          文件查看

          文件查看的命令主要介绍三个,一个是cat,一个是head,一个是tail。

          cat命令主要是查看文件的所有内容;head用作查看文件的头部内容;tail用作查看文件的末尾内容。

          步骤1 cat查看文件

          查看系统环境变量文件/etc/profile。

          输入:

          cat /etc/profile
          

          输出:

          # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
          # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
          
          if [ "${PS1-}" ]; then
            if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
              # The file bash.bashrc already sets the default PS1.
              # PS1='\h:\w\$ '
              if [ -f /etc/bash.bashrc ]; then
                . /etc/bash.bashrc
              fi
            else
              if [ "$(id -u)" -eq 0 ]; then
                PS1='# '
              else
                PS1='$ '
              fi
            fi
          fi
          
          if [ -d /etc/profile.d ]; then
            for i in /etc/profile.d/*.sh; do
              if [ -r $i ]; then
                . $i
              fi
            done
            unset i
          fi
          

          cat命令紧跟需要查看的文件路径,这个路径可以是绝对路径也可以是相对路径。

          cat 详细参数:

          输入:

          cat --help
          

          步骤2 head查看文件

          查看环境变量文件/etc/profile前5行的信息。

          输入:

          head -5 /etc/profile
          

          输出:

          # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
          # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
          
          if [ "${PS1-}" ]; then
            if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
          

          通过-5的方式来指定需要查看多少行的数据(不指定参数默认查看前10行的数据)。

          head命令参数详情:

          输入:

          head --help
          

          步骤3 tail查看文件

          查看环境变量文件/etc/profile末尾5行的信息。

          输入:

          tail -5 /etc/profile
          

          输出:

               . $i
              fi
            done
            unset i
          fi
          

          通过-5的方式来指定需要查看末尾多少行的数据(不指定参数默认查看末尾10行的数据)。

          tail命令参数详情:

          输入:

          tail --help
          

          tail 还有一个比较常用的操作是使用参数-f,可以实时监控查看的文件,文件一旦新增了内容就会将新增的内容显示出来。

          实验小结

          本次实验通过敲击一些常用的Linux命令来辅助学习Linux的基础操作,主要有浏览文件、创建文件、文件操作,为后续的Linux高阶语法奠定基础。

          文档反馈

          建议您登录后反馈,可在建议与反馈里查看问题处理进度

          鼠标选中文档,精准反馈问题

          选中存在疑惑的内容,即可快速反馈问题,我们会跟进处理

          知道了

          上一篇 :  钢筋计数模型训练教学与实践
          下一篇 :  MySQL教学与实践
          搜索 关闭
          ©2025 天翼云科技有限公司版权所有 增值电信业务经营许可证A2.B1.B2-20090001
          公司地址:北京市东城区青龙胡同甲1号、3号2幢2层205-32室
          备案 京公网安备11010802043424号 京ICP备 2021034386号
          ©2025天翼云科技有限公司版权所有
          京ICP备 2021034386号
          备案 京公网安备11010802043424号
          增值电信业务经营许可证A2.B1.B2-20090001
          用户协议 隐私政策 法律声明