0%

科研过程中在命令行长敲的命令

包括Win、Linux等下的

注:

(我)表示我自己的叫法,自己的理解

Win

conda

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 检测是否安装成功
conda

# packages
conda list

# 查看环境
conda env list
OR conda info --envs

# 新建Anaconda虚拟环境
# 常用Python版本3.8/3.9(SOURCE:BILIBILI VIDEO)
conda create -n pytorch python=3.8

# 安装依赖
conda install --file environment.txt

# 进入Anaconda虚拟环境
conda activate pytorch

# 退出Anaconda虚拟环境,即去掉前面的base
conda deactivate

#环境克隆
1. conda create -n 新环境名称 --clone 老环境名称
2. 由于 conda 的环境其实是以一个文件夹的形式存在于 anaconda 的安装路径下,所以也可以直接找到这个文件夹(如~/anaconda3/envs),复制一份,修改文件夹名称为新环境名即可。

# 删除掉一个环境(第一步:首先退出环境conda deactivate)
conda remove -n name_of_environment –-all

# 安装一个包
conda install some_package

# 清空缓存文件等
conda clean -a

# 帮助
conda --help

note:

通过conda安装的库都会额外存放在conda/pkgs目录下作为本地缓存

参考:

https://conda.io/projects/conda/en/latest/commands.html

pip

常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
# i->index
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple package_name

#
pip install 包名 --trusted-host pypi.org --trusted-host files.pythonhosted.org

# 更新pip
pip install --upgrade pip

# pip whl离线安装
1.conda activate xunihuanjing
2.pip install package_name(切换到whl的目录在执行这条命令)
SOURCE:https://zhuanlan.zhihu.com/p/136927881

pip install options

1
-r, --requirement <file>

Install from the given requirements file. This option can be used multiple times.

1
-i, --index-url <url>

Base URL of the Python Package Index (default https://pypi.org/simple). This should point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format.

1
-f, --find-links <url>

If a URL or path to an html file, then parse for links to archives such as sdist (.tar.gz) or wheel (.whl) files. If a local path or [file://](file:///) URL that’s a directory, then look for archives in the directory listing. Links to VCS project URLs are not supported.

参考:

https://pip.pypa.io/en/stable/cli/pip_install/

Node.js

npm, short for Node Package Manager

npm install options

1
2
3
4
5
6
7
8
9
10
11
12
-g
# globally
# Installing a package globally allows you to use the code in the package as a set of tools on your local computer.
参考:
https://docs.npmjs.com/downloading-and-installing-packages-globally

--save
# The –save option in npm install was used in older versions of npm to add a package to the dependencies section of the package.json file of your project.
When you install a package using npm install <package-name> --save, npm would download and install the specified package and also add it as a dependency in your package.json file.
However, starting from npm version 5.0.0, the –save option is no longer necessary. When you run npm install without any options, npm automatically saves the package to the dependencies section of package.json.
参考:
https://www.geeksforgeeks.org/what-is-the-save-option-for-npm-install/#

文件校验

PS下

1
2
3
4
Get-FileHash -Algorithm MD5 -Path "文件路径"
# MD5校验
参考:
https://zhuanlan.zhihu.com/p/681786595

ssh-keygen

options

1
2
3
4
5
6
7
8
9
-t
# “Type” This option specifies the type of key to be created. Commonly used values are: - rsa for RSA keys - dsa for DSA keys - ecdsa for elliptic curve DSA keys
参考:
https://www.ssh.com/academy/ssh/keygen

-C
# Provides custom key comment (which will be appended at the end of the public key).
参考:
https://en.wikipedia.org/wiki/Ssh-keygen

dotfile

In Unix-like operating systems, any file or folder that starts with a dot character (for example, /home/user/. config), commonly called a dot file or dotfile, is to be treated as hidden – that is, the ls command does not display them unless the -a or -A flags ( ls -a or ls -A ) are used.

参考:

https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory#:~:text=In Unix-like operating systems,ls -A )%20are%20used.

Windows下是配置文件

参考:
https://www.zhihu.com/question/468366149/answer/1977282851

Linux

ifconfig

short for interface config

usr folder

一种说法:

usr=Unix Software Resource

另一种说法:

/usr就是给普通用户用来存放home目录的地方。

On many systems, /usr is a directory that contains the directories of all the normal users of the system.

参考:

https://weibo.com/1659946704/5038040724539167

.bashrc file

short for bash read command

man

What do the numbers in a man page mean?

The number corresponds to what section of the manual that page is from; 1 is user commands, while 8 is sysadmin stuff. The man page for man itself (man man) explains it and lists the standard ones:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
MANUAL SECTIONS
The standard sections of the manual include:

1 User Commands
2 System Calls
3 C Library Functions
4 Devices and Special Files
5 File Formats and Conventions
6 Games et. al.
7 Miscellanea
8 System Administration tools and Daemons

Distributions customize the manual section to their specifics,
which often include additional sections.

参考:

https://unix.stackexchange.com/questions/3586/what-do-the-numbers-in-a-man-page-mean

https://www.bell-labs.com/usr/dmr/www/manintro.html

netstat

注意:使用这个命令之前需要先安装

network statistics

常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
netstat -tunlp
# 查看端口号
-t或--tcp 显示TCP传输协议的连线状况。
-u或--udp 显示UDP传输协议的连线状况。
-n或--numeric 直接使用IP地址,而不通过域名服务器。
Show numerical addresses instead of trying to determine symbolic host, port or user names.
-l或--listening 显示监控中的服务器的Socket。
Show only listening sockets. (These are omitted by default.)
-p或--programs 显示正在使用Socket的程序识别码和程序名称。
Show the PID (process identifier) and name of the program that each socket belongs.
参考:
https://www.runoob.com/linux/linux-comm-netstat.html
https://www.computerhope.com/unix/unetstat.htm#:~:text=Description,interface)%20and%20network%20protocol%20statistics.

SCP

secure copy

命令行传文件(我)

options

1
2
-r
# This option tells scp to copy directories recursively.

mv

常用命令

1
2
mv 文件 文件
# 重命名

vim

常用命令

1
2
set nu
# 显示行号

注:

Ubuntu 20版本好像不带Vim,按照命令行的提示安装即可。

ps

process status

常用命令

1
2
3
4
5
ps -ef
# -e,Select all processes. Identical to -A.
-f,Do full-format listing. This option can be combined with other Unix-style options to add additional columns. It also causes the command arguments to be printed. When used with -L, the NLWP (number of threads) and LWP (thread ID) columns are added. See the c option, the format keyword args, and the format keyword comm.
参考:
https://www.computerhope.com/unix/ups.htm#:~:text=On%20every%20UNIX%2Dlike%20operating,to%20many%20distributions%20of%20Linux.

clear

终端清屏

echo

常用命令

1
2
3
4
5
6
7
8
9
echo My name is Dave.
# 在屏幕打印“My name is Dave.”
或 echo “My name is Dave.”(会更好一点)(替换上面的命令)
# 在屏幕打印“My name is Dave.”

echo "Creating a new file." > sample.txt
echo "Adding to the file." >> sample.txt
# If we use the > redirection operator, the file is created if it does not exist. If the file does exist, the output from echo is added at the start of the file, overwriting any previous content.
If we use the >> redirection operator, the file is created if it does not exist. The output from echo is added to the end of the file and doesn't overwrite any existing content of the file.

options

1
2
3
4
5
6
-e
# Enable interpretation of backslash escape sequences
# "\u56FD\u670D"这串代码\u表示Unicode编码
# 例如Unicode就可以
参考:
https://www.computerhope.com/unix/uecho.htm

mkdir

options

1
2
3
4
5
6
7
8
-p(-parent) 
# 假设想在一个嵌套的目录结构中存储一些文件,路径如./files/images/jpg。可以使用以下命令一次性创建所有需要的目录:

mkdir -p files/images/jpg

如果files、files/images或files/images/jpg任何一个目录已经存在,该命令都会成功,并确保完整的目录路径被创建。

参考:https://blog.csdn.net/weixin_43844521/article/details/132611979

whereis

常用命令

1
2
whereis kitti2bag
# 找到kitti2bag文件路径

curl

Client for URL

options

1
2
3
4
-s,--silent
# Silent mode. Don't show progress meter or error messages. Makes curl mute. It still outputs the data you ask for, potentially even to the terminal/stdout unless you redirect it.
参考:
https://www.computerhope.com/unix/curl.htm#

更改密码

step1:
sudo su切换为root
step2:
passwd user(user为对应的用户名),输入两次新的密码即可

注:
只打passwd也进行了修改,但是没有修改king的(即我的用户名)(当我锁屏登陆时候,仍然是原来的密码)
我的密码为:qwe(20240626修改),旧密码为:123

参考:
https://blog.csdn.net/qq_43176116/article/details/88908431

rm

常用命令

1
2
rm -rf 要删除的文件名或目录
# 删除

make

代码变成可执行文件,叫做编译(compile);先编译这个,还是先编译那个(即编译的安排),叫做构建(build)。Make是最常用的构建工具。

参考:

https://www.ruanyifeng.com/blog/2015/02/make.html

options

1
2
3
4
5
6
7
-j [jobs], --jobs[=jobs]
# Specifies the number of jobs (commands) to run simultaneously. If there is more than one -j option, the last one is effective. If the -j option is given without an argument, make will not limit the number of jobs that can run simultaneously.

-f rules.txt,--file=rules.txt
# 依据rules.txt文件进行构建,而不是Makefile文件
参考:
https://www.ruanyifeng.com/blog/2015/02/make.html

wc

wc stands for word count

options

1
2
-l或--lines 
# 显示行数

ln

options

1
2
3
4
5
6
7
-s, --symbolic	
# Make symbolic links instead of hard links
软链接(符号链接)

参考:
https://www.runoob.com/linux/linux-comm-ln.html
https://www.computerhope.com/unix/uln.htm

|(管道)

前为标准输出,后为标准输入

常用命令

1
2
3
4
cat test.txt | grep -n 'test'
# cat test.txt会将test.txt的内容作为标准输出,然后利用管道,将其作为grep -n 'test'命令的标准输入。
参考:
https://murphypei.github.io/blog/2018/04/linux-redirect-pipe

>(重定向)

#!

叫做shebang或hashbang,给Linux用的,不是给Python解释器用的。

当Linux执行一个文件的时候,如果发现它是这样的格式,就会把!后面的内容提取出来拼在你的脚本文件或路径之前,当作实际执行的命令,对你这个脚本来说就是
/usr/bin/env python ./myscript.py(原代码:#!/usr/bin/env python)
/usr/bin/env可以认为是一个东西。

grep

global regular expression

常用命令

1
2
3
4
5
6
7
8
9
grep hello file.txt
# 在文件file.txt中查找字符串"hello",并打印出来

echo "hello world" | grep "hello"

cat error.log | grep "error" | wc -l
# wc是按行数计数
参考:
https://blog.csdn.net/qq_40647372/article/details/132707922

options

1
2
-n
# 显示行号

Ubuntu

apt

Advanced Packaging Tool

note:Ubuntu、Debian使用的是APT包管理系统

常用命令

1
2
3
4
5
6
7
8
9
apt update

apt upgrade
# update 命令只会获得系统上所有包的最新信息,并不会下载或者安装任何一个包。而是 apt upgrade 命令来把这些包下载和升级到最新版本。
# 这两个命令组合会升级内核。
推荐使用:
apt update

apt upgrade

options

1
2
3
4
5
-f,--fix-broken
# When used with install or remove, this option attempts to fix any broken dependencies.

-y
# Assume the answer "yes" to any prompts, proceeding with all operations if they are possible.

参考:

https://www.computerhope.com/unix/apt.htm#

dpkg

Debian Packager

常用命令

1
2
# dpkg安装deb文件 
sudo dpkg -i xxxx.deb

options

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-i, --install package-file...
Install the package. If --recursive or -R option is specified, package-file must
refer to a directory instead.

Installation consists of the following steps:

1. Extract the control files of the new package.

2. If another version of the same package was installed before the new
installation, execute prerm script of the old package.

3. Run preinst script, if provided by the package.

4. Unpack the new files, and at the same time back up the old files, so that if
something goes wrong, they can be restored.

5. If another version of the same package was installed before the new
installation, execute the postrm script of the old package. Note that this script
is executed after the preinst script of the new package, because new files are
written at the same time old files are removed.

6. Configure the package. See --configure for detailed information about how this
is done.
1
2
-?, --help
Display a brief help message.
1
2
3
-L, --listfiles package-name...
List files installed to your system from package-name.
# 使用dpkg查看linux将软件安装到了什么地方(非官方)

参考:

https://manpages.ubuntu.com/manpages/trusty/man1/dpkg.1.html#:~:text=dpkg itself is controlled entirely,dpkg-query(1).

压缩解压缩

1
2
3
4
5
6
7
8
9
10
# 解压
gzip -d filename.gz OR gunzip filename.gz# d,decompress

tar -zxvf 文件.tar.gz(解压)
-z或--gzip或--ungzip 通过gzip指令处理备份文件
-x或--extract或--get 从备份文件中还原文件
-v或--verbose 显示指令执行过程
-f<备份文件>或--file=<备份文件> 指定备份文件
(非官方)
# .tgz文件一样的解压命令

chmod

options

1
2
-R
# recursive,一般对文件夹操作加这个选项

make

个人认为make一般和makefile一起用。

1
2
make 
# To use this makefile to delete the executable file and all the object files from the directory

uname

UNIX name

options

1
2
3
-r, --kernel-release
Print the kernel release.
例:输出:6.2.0-37-generic,解释:6.2.0 - The kernel version number.,37 - The kernel's specific release or build number.,generic - Indicates the kernel flavor. The generic flavor is a common choice for regular desktop and server systems.

参考:

https://www.computerhope.com/unix/uuname.htm

wget

1
2
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz
# 下载文件使用wget

options

1
2
3
wget -O latest-hugo.zip https://github.com/gohugoio/hugo/archive/master.zip
# -O file即--output-document=file
使用-O来把下载的文件重命名

参考:

https://linuxize.com/post/wget-command-examples/

&&

&& strings commands together. Successive commands only execute if preceding ones succeed.

apt update VS upgrade

If it helps you remember:

  • apt update: updates the package cache (to know which package versions can be installed or upgraded)
  • apt upgrade: upgrades packages to the new version

参考:

https://itsfoss.com/apt-update-vs-upgrade/

apt VS apt-get

The apt-get command was the most popular of them all. It is a low-level, feature rich command. apt is a newer and simpler version of apt-get.

参考:

https://itsfoss.com/apt-update-vs-upgrade/

Centos

Nginx

常用命令

1
2
3
4
5
6
7
8
nginx -t
# 测试修改后的配置文件有没有问题

systemctl start nginx
# 启动nginx

systemctl restart nginx
# 重启nginx

错误代码

1
2
3
4
5
403
# 没有权限

404
# 没有找到文件夹

EPEL

Extra Packages for Enterprise Linux

NVIDIA

1
2
# 查看cuda版本
nvidia-smi

Python

1
2
3
4
5
6
7
8
9
10
# 查看帮助
python -h
OR python --help

# [-m mod] run library module as a script (terminates option list)
# “terminates option list”意味着“-m”之后的其它选项不起作用,在这点上它跟“-c”是一样的,都是“终极选项”。官方把它们定义为“接口选项”(Interface options),需要区别于其它的普通选项或通用选项。
python -m

# python在什么位置
where pyhton
欢迎打赏