惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
IT之家
IT之家
V
V2EX
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI
B
Blog
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Linux Tips and Tricks -- s1
2019-08-09 · via jdhao's digital space

In this post, I list some of the often-used Linux command in my daily life.

Find all files under current folder with extension jpg or txt?#

find . -type f \( -iname "*.jpg" -o -iname "*.txt" \) -print

Ref:

Got “argument list too long error” while deleting files#

When I delete files directly using rm some_dir/*, I get the error that argument list is too long. We can use find to delete files instead:

find . -type f -name "*.jpg" -delete

Ref:

Add a prefix to each line of a file#

It is trival to do this via sed:

sed -i.bak -e 's/^/<Pattern>/' test.txt

i.bak means to back up original file and create a new file.

Ref:

How to use scp to transfer files between local and remote#

Transfer remote file to local#

scp -P <PORT> USER@remote_IP:/path/to/remote/file /local/directory

Transfer local file to remote#

scp -P <PORT> /path/to/local/file  USER@remote_IP:/path/to/remote_dir

You can rename the transfered file if you give a complete path to the file instead of just a remote directory.

Transfer remote folder to local#

scp -P <PORT> -r USER@remote_IP:/path/to/remote/dir /path/to/local/dir

Transfer local folder to remote#

scp -P <PORT> -r /path/to/local/folder USER@remote_IP:/path/to/remote/folder

When transferring folder from local to remote/from remote local, if the remote/local folder exists, the folder will be put as a child directory, otherwise, a new folder will be created with the name you give.

Download file using curl and rename#

curl -o new_name -L file_link

-L tells curl to redirect.

How to show system reboot time?#

Use last reboot to show system reboot time. who -b can also show the system last reboot time.

Ref:

Compress (using tar) files from text file?#

The files we want to compress are written in a text file, e.g, img_list.txt. Each line in img_list.txt represents a file path. How to compress all these files to a single tar ball?

We can use the -T option for tar:

-T, --files-from=FILE
       get names to extract or create from FILE

The command is:

tar zcvf images.tgz -T img_List.txt

Ref:

Only search a pattern in certain filetypes?#

Suppose we want to search PATTERN in certain filetypes, for example, *.py files.

Use grep#

grep -r -i PATTERN --include \*.py

Use ripgrep#

Ripgrep is a fast searching tool, commonly referred to as rg. Using rg, it is easier to do this:

Ref:

Randomly select N files from a folder?#

First use find to find the certain files you want to select from, then use shuf to randomly select the files.

find . -type f -name "*.jpg" -print | shuf -n 100

Ref: