📜 ⬆️ ⬇️

Command line art



For a week now, the English version of the art of command line has been hanging in the trending section on Github. For myself, I found this material incredibly useful and decided to help the community with its translation into Russian. There are probably several flaws in the translation, so you are welcome to send pull-requests to me here or to the author of the original work Joshua Levy here . (If PR is sent to me, then after reviewing the changes I will send them to Josh's master brunch). Special thanks to jtraub for help and typos.



')
( tss, in the read more readable )

Description


Main:



Notes:



The basics



Daily use



find . -name '*.py' | xargs grep some_function cat hosts | xargs -I{} ssh root@{} hostname 


  # do something in current dir (cd /some/other/dir && other-command) # continue in original dir 


 diff /etc/hosts <(ssh somehost cat /etc/hosts) 


 TCPKeepAlive=yes ServerAliveInterval=15 ServerAliveCountMax=6 Compression=yes ControlMaster auto ControlPath /tmp/%r@%h:%p ControlPersist yes 


  stat -c '%A %a %n' /etc/timezone 


File and Information Processing



  perl -pi.bak -e 's/old-string/new-string/g' my-files-*.txt 

To rename many files at once by a template, use rename . For complex renames, repren can help:


 #    foo.bak  foo: rename 's/\.bak$//' *.bak #    ,      foo  bar. repren --full --preserve-case --from foo --to bar . 


  uconv -f utf-8 -t utf-8 -x '::Any-Lower; ::Any-NFD; [:Nonspacing Mark:] >; ::Any-NFC; ' < input.txt > output.txt 


System debugging



One line


Let's put it all together and write a few commands:



 cat ab | sort | uniq > c # c is a union b cat ab | sort | uniq -d > c # c is a intersect b cat abb | sort | uniq -u > c # c is set difference a - b 


  awk '{ x += $3 } END { print x }' myfile 


 find . -type f -ls 

This is almost like recursive ls -l , but more readable than ls -lR :



 find . -name '*.py' | xargs grep some_function cat hosts | xargs -I{} ssh root@{} hostname 


  cat access.log | egrep -o 'acct_id=[0-9]+' | cut -d= -f2 | sort | uniq -c | sort -rn 


  function taocl() { curl -s https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README-ru.md | pandoc -f markdown -t html | xmlstarlet fo --html --dropdtd | xmlstarlet sel -t -v "(html/body/ul/li[count(p)>0])[$RANDOM mod last()+1]" | xmlstarlet unesc | fmt -80 } 

Difficult but useful



MacOS only


Some things are relevant only for Mac.



More information on the topic




Disclaimer


With a few exceptions, all the code is written so that others can read it.


To whom much is given, much is asked. The fact that something can be written in Bash does not mean that it should be written there. ;)



License


Creative Commons License


Translated with the help of friends from Canada .

The original work and translation into Russian is distributed under the Creative Commons Attribution-ShareAlike 4.0 International License .



️ bootstrap.build

Source: https://habr.com/ru/post/262127/


All Articles