Terminal操作速查

2019-07-08  本文已影响0人  此方病

内容出自内部交流《Useful tips in Linux》,因为每次要用的时候都要去找这份PPT,就把内容汇总过来顺便把已经用到的部分整理一下。

Move

mv /path/to/dir_or_file /path/to/save/

Create directories/files

mkdir ./directory_name

Copy

cp /path/to/file /path/to/save/
cp –r /path/to/dir /path/to/save/

-r递归处理,将指定目录下的文件与子目录一并处理。若源文件或目录的形态,不属于目录或符号链接,则一律视为普通文件处理

例,将obama的data/misc复制一份给vsoyou:

cp -r obama/data/misc vsoyou/data

Delete

rm /path/to/file
rm –r /path/to/dir
mv /path/to/file_or_dir_to_del /path/to/trash(A more safe way)

例,递归删除save文件夹下所有内容

rm –rf *

Transmit files or directories between servers

  1. Upload file/directory from local to server:
    scp /path/to/file username@server_ip:/path/to/target
    scp –r /path/to/dir username@server_ip:/path/to/target
  2. Download file/directory from server to local:
    scp username@server_ip:/path/to/file /local/path/to/target
    scp –r username@server_ip:/path/to/dir /local/path/to/target

Check script running state

Check GPU usage

nvidia-smi
watch –n 1 nvidia-smi

Designate GPU to use

export CUDA_VISIBLE_DEVICES=GPU_ID1,GPU_ID2 ## in Linux terminal
export CUDA_VISIBLE_DEVICES= ## in Linux terminal, use CPU
import os; os.environ["CUDA_VISIBLE_DEVICES"] = ‘2’ ## in python

个人的习惯是:

CUDA_VISIBLE_DEVICES=0 python run_rnn.py

Kill

kill process_id ## kill a process

查看文件大小

Linux下查看文件和文件夹大小

查看指定目录

du -h --max-depth=1 work/testing

查看硬盘容量

df -hl

————————————待更新————————————

GPU options in Tensorflow

  1. Set GPU memory fractions to use:
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.7)
    sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
  2. Allow GPU memory growth
    gpu_options = tf.GPUOptions(allow_growth=True)
    sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

Docker basic usage

docker exec -it docker_name /bin/bash ## enter a docker container
Ctrl+d ## exit a container back to host

Run program in the background

  1. nohup some_command & ## run the ‘some_command’ in the background, output to file named nouhup
  2. tmux
    tmux new –s window_name ## create and enter a new window named ‘window_name’
    tmux a –t window_name ## enter the existing window ‘window_name’
    Ctrl+b, d ## detach from a window
    Ctrl+d ## detach from a window and close the window
    Ctrl+b, % ## inside a window, split window into 2 sub-window vertically
    Ctrl+b, “ ## inside a window, split window into 2 sub-window horizontally

unzip files

tar xvzf file.tar.gz ## to uncompress a gzip tar file (.tgz or .tar.gz)
tar xvjf file.tar.bz2 ## to uncompress a bzip2 tar file (.tbz or .tar.bz2) to extract the contents.
tar xvf file.tar ## to uncompressed tar file (.tar)
tar xvC /var/tmp -f file.tar ## to uncompress tar file (.tar) to another directory
unzip file.zip ## to uncompress *.zip

Other

wget https://ip.to.files.to_download ## download file from web
wc –l ## count number of lines in a text file
ls /path/to/dir | wc –l ## count number of files in a directory
du –lh –d 1 ## check directories’ size、
kill process_id ## kill a process

`

上一篇下一篇

猜你喜欢

热点阅读