批量替换所有文件内容中的字符串
find -name '要查找的文件名' | xargs perl -pi -e 's|被替换的字符串|替换后的字符串|g'
批量将文件重命名成自增序号模式
ls -v | cat -n | while read n f; do mv -n "$f" "$n.ext"; done
https://stackoverflow.com/questions/3211595/renaming-files-in-a-folder-to-s2equential-numbers
使用rename命令
将一堆gter(\d)格式的文件,去掉gter。(实际上可以直接gter//)
rename -n ``'s/gter(\d)/$1/'` `*
注意使用单引号,否则$1无法识别
将一个文件按照空行分割:
awk 'BEGIN{file="content"++i".txt"} !NF{file="content"++i".txt";next} {print > file}' yourfile
修改文件夹的owner
chown -R /home/user
# 最后不要加/
pip升级所有的包:
pip3 freeze --local | grep -v '^-e' | cut -d = -f 1 | xargs -n1 pip3 install -U
rsync 同步命令
一般只需要acv a递归模式,v详细信息 c check校验 z压缩
rsync -acvz from to
# 指定特殊的端口
rsync -e 'ssh -p 34778' [email protected]:SourceFile DestFile
https://superuser.com/questions/153176/how-to-rsync-a-large-file-with-as-little-cpu-and-bandwidth-expense-as-possible 文件太大时:
rsync -vhz --partial --inplace <file/server stuff> .
v 详细信息 h 人类 z compress --partial
imagemagic 工具包即convert命令,将jpg转换成pgm格式
convert infile.jp2 -compress none outfile.pgm
转换svg为png
inkscap比convert好用很多
inkscape -z -d 128 -e out.png in.svg
利用compare命令比较图片的质量RMSE
compare -metric RMSE ./test.data/output/image_out.pgm ./test.data/output/image_out_2.pgm null > tmp.log 2> tmp.err
# 或者输出到终端
compare -metric RMSE ./test.data/output/image_out.pgm ./test.data/output/image_out_2.pgm null:
输出是类似:
4632.57 (0.0706886)
的结果。第一个数是RMSE值,第二个是标准化的值,上面的结果表示两个图片有7%的RMSE错误。
https://www.imagemagick.org/discourse-server/viewtopic.php?t=17284
7z压缩
全压缩:
7zr a -t7z temp.7z ziptest/
排除bbb目录,所有的,任何目录下的bbb目录:
7zr a -t7z temp.7z ziptest/ -xr\!bbb
排除bbb文件,所有的,任何目录下的bbb文件:
7zr a -t7z temp.7z ziptest/ -x\!bbb
排除.svn目录:
7zr a -t7z temp.7z ziptest -xr\!.svn
7zip排除目录的路径里不能用当前目录 . ,如 -xr!./.svn,会过滤失败, .svn 还会压缩进去。
也可以把要排除的目录路径写入文件,例如:
ziptest_x.txt:
\------------------------------
ziptest/.svn
ziptest/bbb
\------------------------------
7zr a -t7z temp.7z ziptest/ [email protected]_x.txt
注意-x
和-xr
是有很大区别的。参考7 zip - 7Zip - Command Line : Exclude folder(s) by wildcard pattern? - Super User
如果是排除的是文件,把要排除的各个文件名写入一个文件,用 [email protected]_fn.txt 就可以排除所写文件。
-pPassword
参数可以使用密码加密压缩包,默认压缩包依旧可以打开且看到文件名,-mhe=on
参数可以加密文件名。
运行下面的命令你可以解压它并使它包含全部路径:
7za x <archive name>
7z 使用插件处理格式文件。 7za 是独立可执行的。 7za 可以不需要其它任何插件的处理较少格式而不像 7z。 7zr 是独立可执行的。 7zr 可以不需要其它任何插件的处理较少格式而不像 7z。 7zr是一个轻量级的 7za 只用来解压7z 格式的文件。
注意!7z压缩无法保存文件的owner和group信息,如果需要这些信息,要先用tar把文件打包一下。
- to backup a directory :
tar cf - directory | 7za a -si directory.tar.7z
- to restore your backup :
7za x -so directory.tar.7z | tar xf -
journalctl 太大导致打开很慢
journalctl --vacuum-size=500M
更换gcc版本
系统里已经安装了gcc8和9,
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 8
# 或者
sudo update-alternatives --config gcc
重定向stdout和stderr到文件
command >out 2>&1
ll 按照文件大小排序
ll -Sh
从命令行直接复制到剪贴板
在bashrc里可以alias
alias xclips="xargs echo -n | xclip -sel clip"
在使用的时候,比如
realpath ./vectorAdd | xclips
同时,realpath
可以打印文件的全路径。xargs可以去掉最后的换行符。
https://zhuanlan.zhihu.com/p/73286091
关闭chrome的稍后阅读并打开特定的用户
可以设置快捷键的命令如下
/usr/bin/google-chrome-stable %U --disable-features=ReadLater --profile-directory=Default
地址栏输入chrome://version/
可以看到当前用户对应的个人资料路径,其最后一个文件夹的名字即为要设置的profile-directory
值。
通过设置不同的值,可以指定不同的快捷键来打开不同的用户。
命令行连接wifi
network manager有命令行模式nmcli
。
- To see list of saved connections, use (
<SavedWiFiConn>
)
nmcli c
- To see list of available WiFi hotspots (
<WiFiSSID>
)
nmcli d wifi list
连接热点PrettyFlyForAWiFi,使用密码12345678,
nmcli d wifi connect PrettyFlyForAWiFi password 12345678
but maybe run unset HISTFILE
beforehand, so that your WiFi password isn't saved to your ~/.bash_history
file.
把当前目录所有文件按照大小排序
du -h --max-depth=1 ./ | sort -rh
删除tmp目录下两天以前name为a100开头的文件
find /tmp -maxdepth 1 -mtime -2 -type f -name "a100*" -delete
-print
是打印出来
修改时区
ls -l /etc/localtime
查看当前时区
timedatectl list-timezones
列出所有时区名字
sudo timedatectl set-timezone America/New_York
设置时区
xrdp
滚动screen命令的屏幕
To scroll up within a screen window, use this command:
CTRL+a then ESC, #Press CTRL KEY and 'A' KEY together and then hit the ESC KEY #to scroll using the arrow keys hit ESC again to exit.
how-to-use-the-screen-command-in-linux
用另一个用户的身份执行命令
runuser -l username -c 'command'
- -l user_login_name : Make the shell a login shell, uses runuser-l PAM file instead of default one.
- -g group : Specify the primary group.
- -G group : Specify a supplemental group.
- -c COMMAND : Pass a single COMMAND to the shell with -c.
- --session-command=COMMAND : Pass a single COMMAND to the shell with -c and do not create a new session.
- -m : Do not reset environment variables.
- -u username : Run command as given username to get around ‘su -‘ or ‘sudo’ limit.
找到当前目录及其子目录下最大的文件
find /path/to/folder -type f -ls | awk '{print $7/1024/1024 "MB", $11}' | sort -nr | head -n 1
使用dconf-editor 修改gnome快捷键
org.gnome.desktop.wm.keybindings
Reference
7 zip - 7Zip - Command Line : Exclude folder(s) by wildcard pattern? - Super User
https://askubuntu.com/questions/461825/how-to-connect-to-wifi-from-the-command-line
https://unix.stackexchange.com/questions/302011/finding-and-deleting-files-with-a-specific-date
https://www.groovypost.com/howto/set-the-time-zone-in-linux/
https://stackoverflow.com/questions/7927750/specify-an-ssh-key-for-git-push-for-a-given-domain
https://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/
Comments