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

推荐订阅源

博客园_首页
H
Help Net Security
腾讯CDC
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
爱范儿
爱范儿
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MyScale Blog
MyScale Blog
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
D
Docker
V
V2EX
Last Week in AI
Last Week in AI
G
Google Developers Blog
IT之家
IT之家
C
Check Point Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东

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 -- s2
2020-07-23 · via jdhao's digital space

A list of Linux command for common operations.

Generate fixed width numbers with leading zeros#

We can use seq command to generate number of fixed width (padded with leading zeros). For example, to generate number 1 to 999, with width 4 and padded with leading zeros, we can use the following command:

Ref:

Split large files into fixed size part#

We can use split command to split large files into fixed size parts:

split [options] zip_file prefix

For example, to split test.zip into smaller size with each part exactly 4000m, we can use the following command:

split -d -b 4000m test.zip test

The -d option will ensure that numeric indexing is used for the split parts, test is the prefix we use for each part. The generated files are like:

test00, test01, test02, ..., test10, ...

Ref:

Copy a directory to another directory and show progress#

During copy of large files, it is nice to show the progress of copying., we can use rsync to copy a directory to another directory and show progress:

rsync -ah --progress src dest

Since rsync version 3.1.0, we can also use the following options:

rsync -ah --info=progress2 src dest

The progress shown is not the overall progress, it is just the progress for a single file. Nonetheless, it is better than nothing and shows that something is being copied.

Note in the above, there is not slash / after src, which makes sure that src is copied as dest/src with all its structures. If you want to copy all files and folders under src to dest and do not create src directory under dest, you can add a slash after src:

rsync -ah --progress src/ dest

Ref:

Move all files and subdirectories to a directory except one#

Suppose I am at a certain directory and want to move all the files and sub-directories to a directory except one file (test.jpg). We can use the following command to achieve what we want:

\ls | \grep -v test.jpg |xargs -I{} mv {} other_directory/

Note that in the above command we use backslashed version of ls and grep command to avoid any command alias, because the command alias may cause the failure of the above command.

Ref:

zip all files under a directory without the directory itself?#

If we have a test folder under which there are a lot of files and directories. If we use the following zip command to compress the directory:

this will add one more level of folder structures. We get the following:

--> test
    --> test
        --> all files and folders under original test folder

The original test folder is also included in the zipped file. To avoid this, we can use the following command:

cd test && zip -r ../test.zip .

If there are no directories under test or we do not care about directory structure under test, we can also use the -j option:

The above command will flatten all files under test recursively into one directory, which may not be what you want, especally when there are same name filder under different child directories.

Ref: