Skip to content

Instantly share code, notes, and snippets.

@YimianDai
Last active November 6, 2019 23:19
Show Gist options
  • Save YimianDai/7f4309112d8f7d8d1c2bd8d3813ca824 to your computer and use it in GitHub Desktop.
Save YimianDai/7f4309112d8f7d8d1c2bd8d3813ca824 to your computer and use it in GitHub Desktop.
Notes on Linux

软件

  1. Linux 的 回收站 trash-cli

重命名

$ mv /home/user/oldname /home/user/newname

统计文件夹下的文件数目

  1. 统计当前目录下文件的个数(不包括目录)
$ ls -l | grep "^-" | wc -l
  1. 统计当前目录下文件的个数(包括子目录)
$ ls -lR| grep "^-" | wc -l
  1. 查看某目录下文件夹 (目录) 的个数(包括子目录)
$ ls -lR | grep "^d" | wc -l

查看系统的发行版

$ cat /etc/os-release

清空所占用的内存、显存

跑深度学习代码的时候,Ctrl + C 取消代码后显存往往还会被占用,这样别人或者自己就不能再用了,所以需要把显存都清掉

pkill -u yimian

查看文件大小

ls -l 默认的大小是 B,长长一串,可以用 ls -lh 这样显示的单位是 MB

查看当前 Shell 类型

$ ps -p $$  

ls 的各自应用

实现列文件按时间排序

时间最近的在前面

$ ls -lt 

时间从前到后

$ ls -ltr
给 Dataset 准备文件名 txt
$ ls -ltr | sort -R >> trainvaltest.txt

-R 是 Random 的意思, 然后配合 Sublime Text 的 Column Select, 在 Mac 上快捷键是 Option + 左键

nvidia-smi 实时刷新

$ watch -n 0.1 -d nvidia-smi     #每隔 0.1 秒刷新一次

如果一个文件很长, 但我只关心文件最后的内容的动态变化:

watch -n 0.1 -d "cat FCN_DENTIST_best_IoU.log | tail -n $(($LINES - 2))"

查看发行版型号

下面 3 个命令都可以, 至少在 centos 上可以

$ cat /etc/os-release
$ lsb_release -a
$ hostnamectl

查看各文件夹大小

$ du -h --max-depth=1

安装排错:

Conda: "command not found" error

在 ~/.bashrc 中添加下面内容

export PATH="<path to anaconda>bin:$PATH"

<path to anaconda> 换成安装 conda 安装的路径, 比如 /root/miniconda3/, 然后再 source ~/.bashrc 就好了

查看硬盘大小和使用情况

df -hl

nohup

nohupping backgrounded jobs is typically used to avoid terminating them when logging off from a remote SSH session

$ nohup python 3.6 sdfs.py&> result.out&
$ nohup sh script.sh &

Nohup catches the HUP signals. Nohup doesn't put the job automatically in the background. We need to tell that explicitly using &

将 视频 转换成 图像序列 using ffmpeg

ffmpeg -i input.mkv -r 0.05 image_sequence%06d.png

-r 0.05 = 0.05 Hz = 3 images per minute. It sometimes includes a few extra frames from the start though. Without -r it saves every frame.

把 0.05 改成 1 就是 1 秒 1 个

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment