cd、zip、unzip、文件和文件夹的操作
cd ~ #返回主目录
cd .. #上一级目录
cd /sgdata/homedata/anaconda3/bin #绝对路径
cd ./bin #当前目录下的子文件
ls #列出当前目录的内容
ls /home/bin #列出指定目录的内容
ls -l #以详细列表方式显示当前目录下的文件和目录信息
ls -a #显示所有文件,包括隐藏文件
pwd #显示当前工作目录的路径
zip archive.zip file1 file2 file3 #添加file文件到压缩包archive中
zip -r archive.zip newfile.txt #添加文件或文件夹到ZIP文件中
zip -r archive.zip folder
unzip -l archive.zip #不解压缩,显示压缩文件中的目录
unzip archive.zip #解压缩
unzip archive.zip -d /home/data #解压缩到指定文件夹
unzip -v archive.zip #详细模式显示解压缩的过程,包括文件大小、压缩比等信息
unzip archive.zip file1.txt #仅解压指定文件
unzip -p archive.zip file1.txt #解压缩到屏幕显示,但不保存
mkdir directory_name #在当前目录下创建名为directory_name的新目录
mkdir /path/to/new_directory #在指定目录下创建名为directory_name的新目录
touch file.txt #创建名为file.txt的新文件
cat file.txt #显示名为file.txt的文件内容
rm file.txt #删除名为file.txt的文件
rm -r directory #递归删除名为directory的目录及其内容
rm -f file.txt #强制删除文件,不会提示确认
cp file1.txt file2.txt #将file1.txt复制为file2.txt
cp -r directory1 directory2 #递归地将directory1复制到directory2
mv file1.txt /home/user #将file1.txt移动到指定位置
mv old_name.txt new_name.txt #将文件从old_name.txt重命名为new_name.txt
grep "pattern" file.txt #在file.txt中搜索匹配pattern的行
chmod permissions file.txt #将file.txt的权限更改为permissions
chown user:group file.txt #将file.txt的所有者更改为user,所属组更改为group
历史命令行
history #显示历史命令行
history 10 #显示最近的10个命令。
history | grep keyword #搜索包含keyword的命令。
!number #其中number是命令在历史中的编号。例如,!100将执行历史中编号为100的命令。
history -c #清除所有的命令历史记录,不会删除历史文件
隐式执行py,终端关闭继续执行
nohup python script.py & #后台执行Python脚本文件script.py
保存执行的log
#使用>;符号会覆盖目标文件,如果文件不存在则创建新文件。
#使用>>;符号会将输出追加到目标文件的末尾,如果文件不存在则创建新文件。
#nohup python script.py可替换为其余命令
nohup python script.py > output.log
#将scrip.py执行过程中的输出保存到当前目录下名为output.log的文件中
nohup python script2.py >> output.log
#将scrip2.py执行过程中的输出追加保存到当前目录下名为output.log的文件中
nohup python script.py &> output.log
python script.py > output.log 2>&1
#保存scrip.py的标准输出和标准错误输出到output.log
设置使用哪块显卡
CUDA_VISIBLE_DEVICES=0 python script.py
#只在运行script.py时使用CUDA0显卡运行
#!!!!关闭终端设置失效!!!
export CUDA_VISIBLE_DEVICES=0
#在当前终端中,仅使用CUDA=0的显卡,其他CUDA不可见
export CUDA_VISIBLE_DEVICES=0,2
#在当前终端中,仅使用CUDA=0和2的显卡,其他CUDA不可见
实时查看显卡运行
watch -n 1 -d nvidia-smi
CVS文件从UTF8编码转换到GBK编码,windows默认编码方式为GBK,Linux默认为UTF8编码
iconv -f UTF-8 -t GBK utf8_file.csv -o gbk_file.csv
chardet库,查看文件的编码
chardetect "D:\Codes\corn_information_2020Hebi.csv"
# 输出
D:\Codes\corn_information_2020Hebi.csv: utf-8 with confidence 0.99
进程
kill PID
ps aux |grep PID
ps # 当前进程