logo NodeSeekbeta

震惊!微软要把linux命令全部移植到windows上!

123
  • @wengby #20 发布于6/4/2026, 3:20:35 PM
    @sv6cr #15
    那么多 alias 感觉记别名都要记很久
    而且我要用的话 肯定会在输systemctl的时候以为是s
    还是AI好用的多 xhj015

    不用记啊,这都是我自己选择的别名,因为命令用的多了不想每次打太多字所以我就会选择一个短的别名拿来用,好叭,虽然是自己选的,也是需要稍稍记一丢丢的

    我以前闲着没事喜欢用以下命令筛选出我常用的需要打很多字的命令:

    awk '{c[$1]++}END{for(s in c)print c[s],s}' ~/.bash_history | sort -rn | less
    awk '{c[$1" "$2]++}END{for(s in c)print c[s],s}' ~/.bash_history | sort -rn | less
    awk '{c[$1" "$2" "$3]++}END{for(s in c)print c[s],s}' ~/.bash_history | sort -rn | less
    

    然后我会选择一个短的别名,我的别名选择逻辑是尽量短,首先先选择第一个字母,例如sudo我选择了s,若是第一个字母的别名被用了,我会选择两个字母的,例如systemctl我选择了sy,两个字母的别名有时我喜欢选择头两个字母,有时我喜欢选择两个音节或单词的首字母,以此类推会有3个字母甚至更多字母的别名,因为有时候2个字母的别名也被占用了,我脚本的命名逻辑也大差不离,当然古早时期我并不遵循这个逻辑,就会有些比较长名字的别名和脚本

    某种意义上我是一半活在终端里的人,很多软件我都只用cli命令行或TUI终端界面而不是GUI图形界面,比如我的纯文本编辑器是neovim是TUI,邮箱客户端是neomutt是TUI,我一般不用文件管理器而是用cd和zoxide都是cli但偶尔会用lf是TUI,密码管理器是pass是cli,词典是sdcv是cli,日历是remind是cli,音乐播放器是mpv是cli,视频播放器是mpv是伪GUI,计算器是bc是cli,单位/货币转换是units是cli,多媒体格式转换是ffmpeg是cli,文档格式转换是pandoc是cli,资源管理器是htop-vim是TUI,天气预报用我的wtr脚本是cli,等等等

  • @sv6cr #9 发布于2026/6/4 20:33:53,编辑于2026/6/4 21:06:11

    @陌生人 #8 发布于6/4/2026, 12:27:31 PM
    windows我才不高兴敲命令,敲命令那是linux上的事,当然,linux上现在也都不大敲了,用ai了

    每次用shell四剑客find, grep, sed, awk时,我都在后悔为何没有早接触shell,如此强大优雅而简洁,每次使用的时候我都感觉我在作弊,别的语言数行甚至十数行的能做到的,shell一行就行,而且太帅了好叭,尤其是awk,当我第一次使用awk '!a[$0]++'去重的时候,我就爱死了awk爱死了shell。还有shell的管道|,不像其他语言那样用类似函数function()的方式,管道|写起脚本来爽爆了,有的时候一个脚本可以从开始到结束全部用多个管道串起来从头一直管道到尾,而且性能还强,因为这玩意是一行一行并行处理,我不知道我这么解释/理解对不对,反正感觉其他语言想实现管道的这种并行还是要麻烦一丢丢的,起码得来个循环不是?而且而且,咱多线程不会但可以多进程啊,直接上&wait,原地无敌。还有还有,虽然POSIX shell当初设计的时候的一些思想后来被认为是不够好的,比如只有字符串一种数据结构/类型,甚至没有数组,比如追求写脚本/程序尽量少打字导致可读性很差(同样的见awk的awk '!a[$0]++'),但在命令行这个环境下,我认为依旧是最好的设计,只有字符串一种数据结构也意味着非常简单非常好上手,用户可以直接跳过不用学任何数据结构/类型,追求少打字也是极好的,对于活在命令行里的人来说,能只打一个字符绝不会多打俩个,见https://www.nodeseek.com/post-720799-1#1:

    康康我的bash别名设置,.bashrc见https://git.flylightning.xyz/config_local_arch/tree/home/xyz/.bashrc?id=38d0de3c0bff59a381aa0c389f62b0e6dffa8921

    # https://github.com/LukeSmithxyz/voidrice/blob/master/.config/shell/aliasrc
    for cmd in hardcode-fixer ventoy units_cur fbgrab powertop nft rpi-imager fdisk dmesg; do
    	alias $cmd="sudo $cmd"
    done
    for cmd in pacdiff visudo; do
    	alias $cmd="sudo -E $cmd"
    done
    for cmd in loop o 'watch -c'; do
    	alias ${cmd%% *}="$cmd "
    done
    unset cmd
    
    # note: the following code pipe to while read will not work, because pipe create subshell
    #git -C "$HOME/programs/config_local_arch" branch | awk '{print ($1=="*")?$2:$1}' | grep -v master | while read -r branch; do
    # `man bash`: "Each command in a multi-command pipeline, where pipes are created, is executed in a subshell, which is a separate process."
    # https://stackoverflow.com/questions/56327528/bash-aliases-set-in-while-loop-not-persisting
    # can be tested via $BASHPID, note $$ will not work, because $$ does not show subshell pid
    # another way is: echo "$(exec sh -c 'echo "$PPID"')"
    # `man bash`:
    # > BASHPIP Expands to the process ID of the current bash process. This differs from $$ under certain circumstances, such as subshells that  do not  require bash to be re-initialized.
    # > $ Expands to the process ID of the shell. In a subshell, it expands to the process ID of the current shell, not the subshell.
    # https://unix.stackexchange.com/questions/484442/how-can-i-get-the-pid-of-a-subshell
    for branch in $(git -C "$HOME/programs/config_local_arch" branch | awk '{print ($1=="*")?$2:$1}' | grep -v master); do
    	case "$branch" in
    		master|pp) ;;
    		*) alias "s$branch"="ssh $branch";;
    	esac
    done
    unset branch
    
    # different name
    alias a=alarm
    # /dev/ttyACM0 can be in config file, or as environmantal variable, see /usr/share/doc/adafruit-ampy/README.md
    #alias ap='ampy -p /dev/ttyACM0'
    alias b='lsblk -o NAME,FSTYPE,FSVER,LABEL,UUID,FSAVAIL,FSUSED,FSUSE%,MOUNTPOINTS'
    alias c=cfg
    #alias cr=curl
    alias cri='curl -Is'
    alias crig='curl -Is www.google.com'
    alias d='sdcv --color'
    # Using '"$PAGER"' will cause complete-alias unable to complete "e <tab>" and
    # "e --<tab>". I don't know why alias v='"$EDITOR"' does not have this issue, I
    # guess maybe it is related to less has some fzf completion? see `complete -p
    # less` output is "complete -F _fzf_path_completion less". Temporary ignore
    # shellcheck warnings about this if not met any issues.
    alias e="$PAGER"
    # https://superuser.com/a/1202867
    alias fdu="find . -maxdepth 1 -execdir du -sh '{}' \+ | sort -h"
    alias g=git
    alias gcd='git clone --depth=1'
    alias gr='grep --color=auto -i'
    alias grr='grep --color=auto -iIR'
    alias h=htop
    alias i=nsxiv
    alias j=journalctl
    alias ju='journalctl --user'
    alias l='ls --color=auto -A --group-directories-first'
    alias ll='ls --color=auto -lAh --group-directories-first'
    #alias lo=loop
    alias lop='loop ping'
    alias lopd='loop ping 9.9.9.9'
    alias m=man
    alias mpf='mpra -c "$HOME/programs/repos/fly/any/fsh-git"; sudo pacman -Sy fsh-git --noconfirm'
    alias p=pacman
    # Pacman Qqne Redirect
    alias pqr='pacman -Qqne > "$XDG_CONFIG_HOME/myconf/pacman_Qqne"; pacman -Qqme > "$XDG_CONFIG_HOME/myconf/pacman_Qqme"'
    alias pt=pactree
    alias pu=paru
    alias qre='qrencode -t utf8i -m 1'
    alias r='rem -cu+2 -@'
    # https://askubuntu.com/a/22043
    alias s='sudo '
    alias sa='ssh-add -l || ssh-add'
    alias se='sudo -E '
    alias sp='ssh pp'
    alias spd='speedtest; librespeed-cli'
    # can test this mess with `alias tt='echo "\$haha \"lala\""'`
    alias sun='printf "set \$Longitude \"120.95\"\nset \$Latitude \"31.38\"\nrem [sunrise()] msg sunrise\nrem [sunset()] msg sunset" | remind -n -'
    # another way:
    # can test this mess with `alias tt="echo '\$haha \"lala\"'"`
    #alias sun="printf 'set \$Longitude \"-121.89\"\nset \$Latitude \"37.34\"\nrem [sunrise()] msg sunrise\nrem [sunset()] msg sunset' | remind -n -"
    alias sv=sudoedit
    alias y=systemctl
    alias yd='systemctl list-dependencies --all'
    alias ydr='systemctl list-dependencies --all --reverse'
    alias ye='systemctl list-unit-files --state=enabled'
    # sYstemctl Enabled Redirect
    alias yer='systemctl list-unit-files --state=enabled > "$XDG_CONFIG_HOME/myconf/sye"; systemctl --user list-unit-files --state=enabled > "$XDG_CONFIG_HOME/myconf/syue"'
    alias yr='systemctl restart'
    alias ys='systemctl status'
    alias yu='systemctl --user'
    alias yue='systemctl --user list-unit-files --state=enabled'
    alias yus='systemctl --user status'
    alias v='"$EDITOR"'
    alias va='"$EDITOR" "$XDG_DOCUMENTS_DIR/notes/computer/arch_install.md"'
    alias vc='"$EDITOR" "$XDG_DOCUMENTS_DIR/notes/computer/cli_notes.md"'
    alias vd='vidir'
    alias vd2='vidir2 --linktargets'
    alias vq='"$EDITOR" "$XDG_DOCUMENTS_DIR/notes/others/questions_ideas_tips.md"'
    alias vn='"$EDITOR" "$(find "$XDG_DOCUMENTS_DIR/notes" -mindepth 1 -path "*/\.git" -prune -o -type f -print | fzf)"'
    alias vni='"$EDITOR" -ni NONE'
    alias vr='"$EDITOR" "$DOTREMINDERS"'
    alias vrc='"$EDITOR" +e\ \$MYVIMRC'
    alias vrm='"$EDITOR" "$XDG_DOCUMENTS_DIR/notes/others/recurring_maintenance.md"'
    alias vt='"$EDITOR" "$XDG_DOCUMENTS_DIR/notes/others/tmp_mobile_notes.md"'
    alias xmr='monero-wallet-cli --config-file="$HOME/.bitmonero/monero-wallet-cli.conf"'
    alias xmrds='monerod status; monerod print_net_stats'
    alias xr='xset r rate 250 30'
    alias za='zoxide add'
    #alias zq='zoxide query'
    #alias zqi='zoxide query -i'
    
    # same name
    alias absolutely-proprietary='echo n | absolutely-proprietary -f'
    alias alsamixer='alsamixer -V all'
    # I can't find a quick and easy way to temperory disable cloc config file except to change config file. Using an alias can disable --vcs with just \cloc.
    alias cloc='cloc --vcs auto'
    alias diff='diff --color=auto'
    alias glmark2='glmark2 --fullscreen --annotate'
    alias grep='grep --color=auto'
    #alias info='info --vi-keys'
    alias ls='ls --color=auto'
    alias radeontop='radeontop -c'
    alias rem='rem -@'
    alias remind='remind -@'
    alias rm='rm -I'
    alias sdcv='sdcv --color'
    alias shellcheck='shellcheck -x'
    alias tree='tree -aC -I .git | "$PAGER"'
    alias uname='uname -a'
    alias vkmark='vkmark --fullscreen'
    
    # deprecated
    # all green color, no auto turn off color when pipe to nvim
    #alias pactree='pactree -c'
    

    我还有一个目标呢!见https://forum.archlinuxcn.org/t/topic/13854/9

    我的目标是24个英文字母每个都对应一个alias,目前进度:

    • a alarm
    • b lsblk
    • c cfg
    • d sdcv
    • e less
    • f
    • g git
      • gr grep
    • h htop
    • i nsxiv
    • j journalctl
    • k
    • l ls
    • m man
    • n
    • o o
    • p pacman
      • pu paru
    • q
    • r rem
    • s sudo
    • t
    • u u
    • v nvim
    • w w
    • x
    • y systemctl
    • z zoxide

    有些alias的是自己的脚本

    但与git相关的更多的是我的脚本,见:

    收藏备用

  • xhj003

123

你好啊,陌生人!

我的朋友,看起来你是新来的,如果想参与到讨论中,点击下面的按钮!

📈用户数目📈

目前论坛共有59800位seeker

🎉欢迎新用户🎉