What depth learning linux command do you need to know?

Original blog address

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

System Operation

df -hl  #查看磁盘剩余空间
df -h #查看每个根路径的分区大小
du -sh [目录名] #返回该目录的大小
du -sm [文件夹] #返回该文件夹总M数
# 挂载/卸载磁盘
sudo fdisk -l
mount -o rw src_dir dst_dir
umount dir

#即刻关机
sudo shutdown
#定时关机
sudo shutdown -h xx:xx
#重启
sudo reboot
sudo shutdown -r now
sudo init 6

File Operations

# 文件权限
chmod 777 dir # read,write,executable for all
chmod 777 -R dir # 递归到所有子文件夹
chmod 755 dir  # rwx for owner, rx for group
chmod 755 -R dir  

# ls文件夹下所有文件
ls dir -hl 
# ls文件夹中的前/后N个文件
ls dir | head -N
ls dir | head -n N
ls dir | tail -N
ls dir | tail -n N
# 查找文件
find dir -name "*.xxx"
find dir -name "xxx*"

# 统计文件夹下所有文件个数
ls dir -l  | grep "^-" | wc -l # 只统计一层
ls dir -l  | grep -c "^-"      # 只统计一层
ls dir -lR | gerp "^-" | wc -l # 递归统计所有子文件夹
ls dir -lR | gerp -c "^-"      # 递归统计所有子文件夹
find dir -type f | wc -l   # 递归统计所有子文件夹
find dir -maxdepth 1 -type f | wc -l # 只统计一层
########## 推荐使用find!!!############
# 统计文件夹下某后缀文件个数
ls dir -l | grep ".xxx" | wc -l  #注意不是“*.xxx”
find dir -type f -name "*.xxx" | wc -l
# copy特定后缀文件
find src_dir -type f -name "*.xxx"  | xargs -i cp {} dst_dir
find src_dir -type f -name "*.xxx"  | xargs cp -t dst_dir
# copy前/后N个特定后缀文件
find src_dir -type f -name "*.xxx" | head -n N | xargs -i cp {} dst_dir
find src_dir -type f -name "*.xxx" | head   -N | xargs -i cp {} dst_dir
find src_dir -type f -name "*.xxx" | head -n N | xargs cp -t dst_dir
find src_dir -type f -name "*.xxx" | head   -N | xargs cp -t dst_dir

find src_dir -type f -name "*.xxx" | tail -n N | xargs -i cp {} dst_dir
find src_dir -type f -name "*.xxx" | tail   -N | xargs -i cp {} dst_dir
find src_dir -type f -name "*.xxx" | tail -n N | xargs cp -t dst_dir
find src_dir -type f -name "*.xxx" | tail   -N | xargs cp -t dst_dir
# copy前N个文件,控制一下文件夹搜索的depth
find src_dir -maxdepth 1 -type f | head -N | xargs cp -t dst_dir
find src_dir -maxdepth 1 -type f -name ".xxx"| head -N | xargs cp -t dst_dir
# 随机copy N个文件
find src_dir -type f -name "*.xxx" | shuf -n N | xargs -i cp {} dst_dir
find src_dir -type f -name "*.xxx" | shuf -n N | xargs cp -t dst_dir
# 从远程服务器往本地服务器copy文件
scp <username>@<ip>:src_dir dst_dir
scp -r <username>@<ip>:src_dir dst_dir # 递归拷贝
# 从本地服务器往远程服务器copy文件
scp src_dir <username>@<ip>:dst_dir 
scp -r src_dir <username>@<ip>:dst_dir  # 递归拷贝

# 把文件夹下所有文件名字写到一个txt里
find src_dir -type f -name "*.xxx" > dst_dir/xxx.txt
# 把所有文件内容写到一个文件里
cat src_dir/xxx* >> dst_file
find src_dir -type f -name "xxx*" | sort | xargs -i cat {} >> dst_file

# 输出文件的前/后N行
head -n N xxx.xxx
head -N xxx.xxx
tail -n N xxx.xxx
tail -N xxx.xxx
# 计算文件行数
wc -l xxx.xxx
# 计算文件words数
wc -w xxx.xxx
# 输出文件中包含某种pattern的行
grep -n "some_pattern" xxx.xxx
# 输出文件中包含某种pattern的行数
grep -c "some_pattern" xxx.xxx
# 计算文件大小
du -h xxx.xxx
# 计算文件夹大小
du -sh dir
# 文件行打乱
shuf -o src_file dst_file # src_file和dst_file同名时,原地执行操作
# 文件切分
split -l N src_file out_file_prefix # 按行切分,每个文件N行,生成的文件个数 = src_file总行数 / N
split -n N src_file out_file_prefix # 指定切分N个文件,但一行可能会被切分到两个文件中

# 文件批量重命名
for file in "*.xxx"; do mv "$file" "${file/.xxx/_123.xxx}";done # a.xxx -> a_123.xxx

# zip包的压缩和解压
zip -r dst_zip_file src_dir
unzip zip_file
# tar包的压缩和解压
tar -cvf dst.tar src_dir/  # 压缩
tar -xvf tar_file  # 解压
# 

GPU

# 查看gpu使用情况及进程号
sudo nvidia-smi
# 每N秒查看一次gpu使用情况及进程号
watch -n N nvidia-smi
# 查看cuda版本
nvcc -V
# 查看使用gpu的进程
sudo fuser -v /dev/nvidia*
# 关闭gpu进程
sudo kill -9 xxx

jupyter notebook

# 配置jupyter notebook可远程访问
jupyter-notebook --generate-config
jupyter-notebook password # 输入密码并确认,这就是以后的登陆密码
vi /home/username/.jupyter/jupyter_notebook_config.json # 复制里面的sha1码
vi /home/username/.jupyter/jupyter_notebook_config.py
 # 在jupyter_notebook_config.py 文件填入下面配置:
 # 设置默认目录
c.NotebookApp.notebook_dir = u'/home/username/jupyterdata'
 # 允许通过任意绑定服务器的ip访问
c.NotebookApp.ip = '*'
 # 用于访问的端口
c.NotebookApp.port = 8888
 # 不自动打开浏览器
c.NotebookApp.open_browser = False
 # 设置登录密码
c.NotebookApp.password = u'sha1:xxxxxxxxxxxxxxxx' # 上面复制的sha1码

# 使用
 # 在远程服务器输入:
jupyter notebook
 # 打开本地浏览器,输入:
192.168.x.xxx:8888

Install samba

#step1:
sudo apt install samba
sudo apt install smbclient
#step2:
sudo vim /etc/samba/smb.conf
 # 在smb.conf文件的行尾添加:
[xxx] # xxx为samba的共享文件夹
comment = Share Folder require password
browseable = yes
path = /home/xxx
create mask = 0777
directory mask = 0777
valid users = xxx
public = yes
writable = yes
available = yes
:wq
#step3:
sudo /etc/init.d/damba restart 
#step4:
cd /home
sudo mkdir xxx
sudo chmod 777 xxx
#step5:
 # 添加账户
sudo groupadd xxx -g 6000
sudo useradd xxx -g 6000 -d /home/xxx
sudo passwd xxx
sudo usermod -aG users xxx
sudo smbpasswd -a xxx
#step6:
 # 转到windows电脑,添加一个网络位置
\\ip_address\xxx  # ip_address为创建samba的ubuntu电脑的本地ip

Anaconda build deep learning environment

# 查看conda环境
conda info -e # 查看所有安装的conda环境
conda info  # 查看当前环境的信息
conda list # 查看当前环境安装了哪些包
# 创建conda环境
conda create -n env_name #创建conda环境
conda create -n env_name python=3.5.2  #创建基于python3.5.2的conda环境,并且安装依赖包。
# 切换conda环境
activate env_name #切换到新环境
activate root  #切换到root环境
deactivate      #退出当前环境
# 删除conda环境
conda remove -n env_name --all
# 一个例子
conda create -n tensorflow python=3.5.2
activate tensorflow
   #Tensorflow based on GPU
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl 
(tensorflow)C:> conda install scipy #在当前环境下安装scipy,keras需要
(tensorflow)C:> conda install jupyter #
(tensorflow)C:> conda install pandas  #
(tensorflow)C:> conda install scikit-learn
(tensorflow)C:> conda install seaborn
(tensorflow)C:> pip install keras
(tensorflow)C:> jupyter notebook

Clean up space

# 查看apt缓存
sudo du -sh /var/cache/apt
# 清理apt缓存
sudo apt clean
# 查看缩略图缓存
du -sh ~/.cache/thumbnails
#清理缩略图缓存
rm -rf ~/.cache/thumbnails/*
Published 102 original articles · won praise 117 · views 330 000 +

Guess you like

Origin blog.csdn.net/pursuit_zhangyu/article/details/94161033