linux操作

  1. 1.基础命令
    1. 1. find 命令
  2. 2.关于conda
  3. 3.source in shell
  4. 4. 配置ssh公匙无密码登录
  5. 5. linux 文件系统介绍

1.基础命令

  • 查看剩余空间大小df -h
  • linux系统在后台运行命令:
nohup python chushi.py > out.dat 2>&1 & 
#即使关闭终端任务仍在进行;2>&1将错误重定向输出 &后台运行符号**`
#查看后台运行的任务:jobs
  • 在单引号里面引用变量要给变量加上单引号 ‘$i’

  • z文件 zcat .z >> a.dat

  • ls命令

    • ls -l 显示文件详细信息
    • ls -r 倒序排序
    • ls -t 按照时间排序
    • ls -a 显示隐藏文件和文件夹
  • paste 用于合并文件的列

  • 解压缩和压缩文件

    gunzip file.gz
    tar -xzvf file.tar
    tar -cf file.tar 文件名  !打包文件
    
  • 快速跳到文件的行 80gg

    dG:删除光标所在到最后一行的所有数据

    删除第9行到第200行的内容(先用200G转到第200行),使用:9,.d

  • 解压zip unzip

  • shell脚本编程引用变量用双引号“”,单引号无法引用

  • ifort -fast 报错

    cannot find -lm
    cannot find -lc

    去掉 -fast

  • **scp -P 2222 -r (文件夹)2222 infile.ucposcar liz@59.72.114.246:/work/home/liz/try/tdep/examples/c**

    **sftp -P 12580 lijx@59.72.114.93 put get**

  • ifort -o 脚本名称 fortran程序

  • **查看占用文件的进程 lsof +文件名 , 强制结束进程 kill -9 +进程id **

  • 查看后台运行的任务 ps -aux 杀掉后台运行的任务 kill +ID

  • 替换第七行内容 for i in $(seq 4 4 48);do cp cal.slurm $i;cp in.lmp $i;sed -i '7s/.*/#SBATCH --ntasks='$i'/' $i/cal.slurm;done

  • d1G删除光标所在以及前面的行

  • for i in $(seq 600 100 1000);do cd $i;sed -i ‘s/87287/70591/g’ in.lmp;sbatch cal.slurm;cd ..;done

  • free 查看内存信息 lscpu 查看cpu型号和基准频率等等

1. find 命令

搜索当前目录及其子目录下所有名为example.txt的文件

find 路径 参数 动作

find . -name "example.txt"

搜索当前目录下所有大小超过10MB的文件

find . -type f -size +10M

-type f 指定搜索文件的类型

-type d 代表目录

删除当前目录下所有.txt文件

find . -type f -name "*.txt" -delete

2.关于conda

  • which python 显示当前的python版本目录

  • conda env list 显示所有的python版本

  • conda activate ------ 切换到——python版本

  • conda deactivate 退回到默认的python版本

  • conda create -n name python 创建环境

  • **conda remove -n name --all 删除环境 **

  • conda安装错误,有可能是源的问题,.condarc

3.source in shell

https://phoenixnap.com/kb/linux-source-command

source命令用于逐行运行文件中的命令,如

Using the source command to pass a file as an argument

source用于把一些变量或者命令在当前环境中读取,而不需要重新开一个新的环境

source和 .的作用相同 ,是在当前进程下运行命令,会保留脚本内的变量

而./则是新开一个进程运行命令,运行结束进程关闭,不会保留下变量

https://medium.com/@sdbutalla/what-really-is-the-difference-between-the-source-and-dot-commands-in-bash-zshell-736896bc26a3

source 和 . 的区别

``source can be run in any directory, provided the file is in the current directory or the path is provided, whereas . looks for the file in the paths in your PATH variable; if the file is not in a directory that is in your PATH, you must provide the full path to the file.`

source可以在所有情况下适用, . 必须指定完整路径或者在环境变量下

export PATH="/work/home/liz/software/vtst/vtstscripts-972:$PATH"

添加目录到环境变量

MPI :并行用到的库,用于在不同进程间传递信息

4. 配置ssh公匙无密码登录

[快速实战派:ssh公钥登录远程服务器配置_配置公钥私钥进行远程登录-CSDN博客](https://blog.csdn.net/u011291072/article/details/119298179#:~:text=如下图,全过程有三步,第一步是输入公钥私钥的保存路径,第二步和第三步是设置私钥密码和确认密码。 如果是第一次生成公钥,则直接一路回车确认就行。,公钥和私钥会自动生成到%2FUsers%2F [用户名]%2F.ssh路径下。 默认公钥文件名为id_rsa.pub,私钥文件名为id_rsa。)

  1. ssh-keygen

    生成公钥

  2. 把.ssh/id_rsa.pub的内容cat到服务器的~/.ssh/authorized_keys

  3. 可以登录

    ssh -p **** 用户名@地址

  4. 可以在本地的.ssh内构造config 文件 ,使用用户名登陆

image-20231227224213521

https://zhuanlan.zhihu.com/p/136152982

Linux 将标准输出重定向到剪切板_linux 重定向剪贴板-CSDN博客

[Ubuntu将标准输出重定向到剪贴板_ubuntu命令输出重定向到粘贴板-CSDN博客](https://blog.csdn.net/tcliuwenwen/article/details/103752486#:~:text=那么如何将标准输出重定向到剪贴板方便我们粘贴呢? 1.更新源sudo apt update2.安装xsel或者xclipsudo apt install xselsudo apt,install xclip3.将输出通过管道重定向到剪贴板ls | xsel -ib %23 使用xsel…_ubuntu 剪切板)

5. linux 文件系统介绍

https://github.com/ByteByteGoHq/system-design-101?tab=readme-ov-file#linux-file-system-explained

img


转载请注明来源 有问题可通过github提交issue