四川大学新能源与低碳技术研究院
高性能计算中心(以鸣计算实验室)
首页
|
联系我们
Toggle navigation
高性能计算中心
中心简介
要闻快讯
评测报告
专题课程
开放资源
仪器设备简介
实验室服务器申请
计算资源申请
线下专题课程预约
线上专题课程预约
合作产品
专题文档
专题文档库
# 第四章 Linux常用命令 [TOC] 我们经常看到为了学Linux,很多人去买很厚的Linux系统的书籍,或者很多Linux系统的资料。从使用Linux进行学科计算的角度而言,其实我们并不需要学那么多的Linux知识,只需要了解最常用的几个命令就可以了,这里介绍一下我们最常用的Linux命令和工具。 ## ls/ll命令 这个命令就相当于dos下的dir命令一样也是Linux控制台命令中最为重要几个命令之一 。它的作用就是查看当前目录下的文件和文件夹有哪些。 ``` [scudt.duyong@scu apps]$ ls admintools cp2k-9.1-build l_BaseKit_p_2022.3.0.8767_offline.sh maui-3.3.1 parallel_studio_xe_2019_update4_cluster_edition torque-6.1.2.tar.gz Anaconda3-2022.10-Linux-x86_64.sh cp2k-9.1.tar.bz2 l_HPCKit_p_2022.3.0.8751_offline.sh maui-3.3.1.tar.gz parallel_studio_xe_2019_update4_cluster_edition.tgz vasp.5.4.4 BIOVIA_2019.MaterialsStudio2019.tgz frp_0.58.0_linux_amd64.tar.gz libgfortran.so.5.0.0 msi2019.lic phonopy-2.29.1 vaspkit.1.4.1.linux.x64.tar.gz cp2k-2022.1.build Gaussian_16-A03-AVX2.tbz libstdc++.so.6.0.25 openmpi phonopy-2.29.1.tar.gz vtstscripts.tgz cp2k-2022.2.build.tar.bz2 glibc-2.18 make-4.3.tar.gz openpbs-23.06.06.tar.gz scp-compute.sh cp2k-2022.2.tar.bz2 glibc-2.18.tar.gz mathlib parallel_studio_b.lic torque-6.1.2 ``` ``` [scudt.duyong@scu apps]$ ll total 13573116 drwxr-xr-x 3 root root 4096 Oct 24 05:57 admintools -rwxr-xr-x 1 root root 773428196 Oct 14 01:23 Anaconda3-2022.10-Linux-x86_64.sh -rw-r--r-- 1 root root 1077894234 Oct 14 01:25 BIOVIA_2019.MaterialsStudio2019.tgz drwxr-xr-x 2 root root 4096 Jul 24 2022 cp2k-2022.1.build -rw-r--r-- 1 root root 488321743 Oct 14 01:25 cp2k-2022.2.build.tar.bz2 -rw-r--r-- 1 root root 64932093 Oct 14 01:25 cp2k-2022.2.tar.bz2 drwxr-xr-x 2 root root 4096 Oct 14 01:24 cp2k-9.1-build -rw-r--r-- 1 root root 64687353 Oct 14 01:24 cp2k-9.1.tar.bz2 -rw-r--r-- 1 root root 12367383 Oct 14 01:23 frp_0.58.0_linux_amd64.tar.gz -rw-r--r-- 1 root root 3618851011 Oct 14 01:25 Gaussian_16-A03-AVX2.tbz drwxrwxr-x 70 root root 4096 Oct 14 05:21 glibc-2.18 -rw-r--r-- 1 root root 23428909 Oct 14 01:23 glibc-2.18.tar.gz -rw-r--r-- 1 root root 3363322240 Oct 14 01:24 l_BaseKit_p_2022.3.0.8767_offline.sh -rw-r--r-- 1 root root 1483804801 Oct 14 01:24 l_HPCKit_p_2022.3.0.8751_offline.sh -rw-r--r-- 1 root root 2626504 Oct 14 01:23 libgfortran.so.5.0.0 -rw-r--r-- 1 root root 1661424 Oct 14 01:23 libstdc++.so.6.0.25 -rw-r--r-- 1 root root 2317073 Oct 14 01:24 make-4.3.tar.gz drwxr-xr-x 2 root root 4096 Oct 14 01:22 mathlib drwxrwxr-x 14 603 603 4096 Oct 14 06:01 maui-3.3.1 -rw-r--r-- 1 root root 901179 Oct 14 01:24 maui-3.3.1.tar.gz -rw-r--r-- 1 root root 85099 Oct 14 01:25 msi2019.lic drwxr-xr-x 3 root root 4096 Oct 14 11:10 openmpi -rw-r--r-- 1 root root 3489878 Oct 14 01:24 openpbs-23.06.06.tar.gz -rw-r--r-- 1 root root 952 Oct 14 01:24 parallel_studio_b.lic drwxr-xr-x 4 root root 4096 May 17 2019 parallel_studio_xe_2019_update4_cluster_edition -rw-r--r-- 1 root root 2832040306 Oct 14 01:25 parallel_studio_xe_2019_update4_cluster_edition.tgz drwxr-xr-x 7 root root 4096 Oct 27 03:03 phonopy-2.29.1 -rw-r--r-- 1 root root 4054184 Oct 24 23:44 phonopy-2.29.1.tar.gz -rwxr-xr-x 1 root root 104 Oct 14 04:35 scp-compute.sh drwxr-xr-x 7 1167 2010 4096 Oct 14 06:26 torque-6.1.2 -rw-r--r-- 1 root root 14197460 Oct 14 01:24 torque-6.1.2.tar.gz drwxr-xr-x 3 root root 4096 Oct 29 23:36 vasp.5.4.4 -rw-r--r-- 1 root root 65984159 Oct 14 01:25 vaspkit.1.4.1.linux.x64.tar.gz -rw-r--r-- 1 scudt.duyong scudt.duyong 345302 Oct 29 23:40 vtstscripts.tgz ``` 我们注意到,ls命令和ll命令虽然都是查看当前目录下内容的,但显示格式是不同的,ll命令显示的内容更详细些。建议多使用ll命令。 在linux中,ls/ll命令显示的蓝色表示“目录”。同时,ls/ll命令会根据文件的具体类型给文件名配色:1、白色表示普通文件;2、亮绿色表示可执行文件;3、亮红色表示压缩文件;4、蓝色表示目录;5、亮蓝色表示链接文件;6、亮黄色表示设备文件。 有些时候,我们需要查看目录下隐藏的文件或文件夹,就需要用到-a参数 ``` [scudt.duyong@scu ~]$ ll -a total 64 drwx------ 9 scudt.duyong scudt.duyong 4096 Oct 31 02:52 . drwxr-xr-x 4 root root 0 Oct 31 02:46 .. -rw------- 1 scudt.duyong scudt.duyong 3988 Oct 30 13:40 .bash_history -rw-r--r-- 1 scudt.duyong scudt.duyong 18 Aug 2 2017 .bash_logout -rw-r--r-- 1 scudt.duyong scudt.duyong 193 Aug 2 2017 .bash_profile -rw-r--r-- 1 scudt.duyong scudt.duyong 231 Aug 2 2017 .bashrc drwxrwxr-x 4 scudt.duyong scudt.duyong 4096 Oct 27 02:40 .cache drwxrwxr-x 2 scudt.duyong scudt.duyong 4096 Oct 15 13:20 cen drwxrwxr-x 3 scudt.duyong scudt.duyong 4096 Oct 14 01:30 .config -rw-r--r-- 1 scudt.duyong scudt.duyong 334 Mar 2 2017 .emacs drwxr-xr-x 4 scudt.duyong scudt.duyong 4096 Oct 14 00:15 .mozilla drwxrwxr-x 2 scudt.duyong scudt.duyong 4096 Oct 15 01:56 nie drwx------ 2 scudt.duyong scudt.duyong 4096 Oct 29 23:40 .ssh drwxrwxr-x 4 scudt.duyong scudt.duyong 4096 Oct 15 03:11 testjobs -rw------- 1 scudt.duyong scudt.duyong 4873 Oct 29 23:40 .viminfo -rw------- 1 scudt.duyong scudt.duyong 798 Oct 31 02:52 .Xauthority ``` ## cd命令 cd这个命令是用来到达指定路径目录的。Linux的目录对大小写是敏感的,大小写拼写有误,你的cd操作是成功不了的。输入cd后面不加任何东西会回到登录账号的主目录。 例如,执行`cd /home/duyong/software/hdf5-1.12.0/src`即可进入src目录下。 ## mkdir 、rmdir命令 mkdir命令用来建立新的目录。 rmdir用来删除已建立的目录。 例如: ``` mkdir test #在当前目录创建test目录 rmdir test #删除test目录 ``` ## cp命令 cp命令是拷贝文件和文件夹的常用命令。 例如:我们拷贝test.job文件到testjobs目录下: ``` cp test.job /home/duyong/testjobs/vaspjob/ ``` 这里我们要讲一下绝对路径和相对路径的概念,这也是很多人最初使用linux系统时很混乱的原因之一。 其实,理解绝对路径和相对路径也是非常简单的,就像我们说绝对距离和相对距离很类似。“绝对”是指以一个公认的原点为基准,而“相对”指以人为指定的原点为基准。在linux系统里,绝对路径是指以根目录/为原点,到达目标目录的路径;相对路径一般是以当前所在目录为原点,到达目标目录的路径。 例如: 我当前是在duyong账号用户主目录,我拷贝test.job到这个目录的下级子目录testjobs/vaspjobs/目录下。 绝对路径的cp命令是: ``` cp test.job /home/duyong/testjobs/vaspjob/ ``` 相对路径的cp命令是: ``` cp test.job testjobs/vaspjob/ ``` 绝对路径是把从根目录开始到目标目录,输入完整的路径;相对路径是从当前目录开始到目标目录的路径。特别注意,绝对路径是从/开始,所以home前是有/号的,而相对路径前面是没有/号的。 拷贝文件夹时,cp命令后面要加参数: cp –r 源文件夹 目的路径。参数 r 是指递归处理,将指定目录下的文件与子目录一并拷贝。若源文件或目录的形态,不属于目录或符号链接,则一律视为普通文件处理连同源文件中的子目录一同拷贝。 cp –rf 源文件夹 目的路径。除了r参数的功能外,强行复制文件或目录,不论目的文件或目录是否已经存在,若目标文件已存在,则会直接覆盖原文件。 ## rm命令 rm命令是用来删除文件和文件夹的命令 rm -rf 强制删除文件/目录 **特别提醒,请慎用rm命令,特别是添加了-rf参数的rm命令。** ## mv命令 mv这个命令的功能是移动目录或文件,引申的功能是给目录或文件重命名。 这个命令的移动功能类似cp命令,我们也常用这个命令重命名文件或文件夹,例如: ``` mv test.job testvasp.job ``` 我们把test.job文件重命名为testvasp.job。 ## cat/tail命令 cat命令的功能是显示文件内容。当我们想查看test.job文件的内容时,执行 ``` cat test.job ``` 就可以查看test.job文件的内容了。tail命令也是查看文件内容的命令。当我们运行计算作业,输出结果文件记录了计算过程和结果,但在计算任务没有结束之前,这个文件的内容一直是在被一直写入的。如果我们用cat命令查看,只能查看输入cat命令时结果文件的内容,并不能实时看到输出。这时,我们使用 ``` tail -f 结果文件名 ``` 当结果文件内容有增加时,会实时的输出到屏幕上。 vi命令 Linux系统中,特别是CentOS系统,命令行界面下文本编辑工具vim是最常用的工具软件。强烈建议大家学会使用。 输入vi 文件名,用vi命令打开文件。 这时文件是查看状态,并不能进行编译。 我们记住最基础的几个快捷方式: - 按键盘a或i键,进入编译模式 - 按键盘esc键,退出编辑模式; - 在查看模式下输入:wq保存退出; - 在查看模式下输入:q!不保存退出。