@learnbyexample@programming.dev avatar

learnbyexample

@learnbyexample@programming.dev

Interests: Regular Expressions, Linux CLI one-liners, Scripting Languages and Vim

GitHub: github.com/learnbyexample

This profile is from a federated server and may be incomplete. Browse more on the original instance.

learnbyexample OP ,
@learnbyexample@programming.dev avatar

That’s great to hear and thanks for the kind feedback :)

learnbyexample ,
@learnbyexample@programming.dev avatar

<span style="color:#62a35c;">alias </span><span style="font-weight:bold;color:#795da3;">a</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">'alias'
</span><span style="color:#323232;">
</span><span style="color:#323232;">a c=</span><span style="color:#183691;">'clear'
</span><span style="color:#323232;">a p=</span><span style="color:#183691;">'pwd'
</span><span style="color:#323232;">a e=</span><span style="color:#183691;">'exit'
</span><span style="color:#323232;">a q=</span><span style="color:#183691;">'exit'
</span><span style="color:#323232;">
</span><span style="color:#323232;">a h=</span><span style="color:#183691;">'history | tail -n20'
</span><span style="font-style:italic;color:#969896;"># turn off history, use 'set -o history' to turn it on again
</span><span style="color:#323232;">a so=</span><span style="color:#183691;">'set +o history'
</span><span style="color:#323232;">
</span><span style="color:#323232;">a b1=</span><span style="color:#183691;">'cd ../'
</span><span style="color:#323232;">a b2=</span><span style="color:#183691;">'cd ../../'
</span><span style="color:#323232;">a b3=</span><span style="color:#183691;">'cd ../../../'
</span><span style="color:#323232;">a b4=</span><span style="color:#183691;">'cd ../../../../'
</span><span style="color:#323232;">a b5=</span><span style="color:#183691;">'cd ../../../../../'
</span><span style="color:#323232;">
</span><span style="color:#323232;">a ls=</span><span style="color:#183691;">'ls --color=auto'
</span><span style="color:#323232;">a l=</span><span style="color:#183691;">'ls -ltrhG'
</span><span style="color:#323232;">a la=</span><span style="color:#183691;">'l -A'
</span><span style="color:#323232;">a vi=</span><span style="color:#183691;">'gvim'
</span><span style="color:#323232;">a grep=</span><span style="color:#183691;">'grep --color=auto'
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># open and source aliases
</span><span style="color:#323232;">a oa=</span><span style="color:#183691;">'vi ~/.bash_aliases'
</span><span style="color:#323232;">a sa=</span><span style="color:#183691;">'source ~/.bash_aliases'
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># sort file/directory sizes in current directory in human readable format
</span><span style="color:#323232;">a s=</span><span style="color:#183691;">'du -sh -- * | sort -h'
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># save last command from history to a file
</span><span style="font-style:italic;color:#969896;"># tip, add a comment to end of command before saving, ex: ls --color=auto # colored ls output
</span><span style="color:#323232;">a sl=</span><span style="color:#183691;">'fc -ln -1 | sed "s/^s*//" >> ~/.saved_commands.txt'
</span><span style="font-style:italic;color:#969896;"># short-cut to grep that file
</span><span style="color:#323232;">a slg=</span><span style="color:#183691;">'&lt; ~/.saved_commands.txt grep'
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># change ascii alphabets to unicode bold characters
</span><span style="color:#323232;">a ascii2bold=</span><span style="color:#183691;">"perl -Mopen=locale -Mutf8 -pe 'tr/a-zA-Z/𝗮-𝘇𝗔-𝗭/'"
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;">### functions
</span><span style="font-style:italic;color:#969896;"># 'command help' for command name and single option - ex: ch ls -A
</span><span style="font-style:italic;color:#969896;"># see https://github.com/learnbyexample/command_help for a better script version
</span><span style="font-weight:bold;color:#795da3;">ch</span><span style="color:#323232;">() { whatis $1</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">man $1 </span><span style="font-weight:bold;color:#a71d5d;">| </span><span style="color:#323232;">sed -n </span><span style="color:#183691;">"/^s*$</span><span style="color:#323232;">2</span><span style="color:#183691;">/,/^$/p" </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># add path to filename(s)
</span><span style="font-style:italic;color:#969896;"># usage: ap file1 file2 etc
</span><span style="font-weight:bold;color:#795da3;">ap</span><span style="color:#323232;">() { </span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> f </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#183691;">"$</span><span style="color:#323232;">@</span><span style="color:#183691;">"</span><span style="font-weight:bold;color:#a71d5d;">; do </span><span style="color:#62a35c;">echo </span><span style="color:#183691;">"$</span><span style="color:#323232;">PWD</span><span style="color:#183691;">/$</span><span style="color:#323232;">f</span><span style="color:#183691;">"</span><span style="font-weight:bold;color:#a71d5d;">; done; </span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># simple case-insensitive file search based on name
</span><span style="font-style:italic;color:#969896;"># usage: fs name
</span><span style="font-style:italic;color:#969896;"># remove '-type f' if you want to match directories as well
</span><span style="font-weight:bold;color:#795da3;">fs</span><span style="color:#323232;">() { find -type f -iname </span><span style="color:#183691;">'*'"$</span><span style="color:#323232;">1</span><span style="color:#183691;">"'*' </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># open files with default application, don't print output/error messages
</span><span style="font-style:italic;color:#969896;"># useful for opening docs, pdfs, images, etc from command line
</span><span style="font-weight:bold;color:#795da3;">o</span><span style="color:#323232;">() { xdg-open </span><span style="color:#183691;">"$</span><span style="color:#323232;">@</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">;></span><span style="color:#323232;"> /dev/null </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># if unix2dos and dos2unix commands aren't available by default
</span><span style="font-weight:bold;color:#795da3;">unix2dos</span><span style="color:#323232;">() { sed -i </span><span style="color:#183691;">'s/$/r/' "$</span><span style="color:#323232;">@</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">}
</span><span style="font-weight:bold;color:#795da3;">dos2unix</span><span style="color:#323232;">() { sed -i </span><span style="color:#183691;">'s/r$//' "$</span><span style="color:#323232;">@</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">}
</span>
learnbyexample ,
@learnbyexample@programming.dev avatar

I used to use it for posting on Twitter, with some keywords (like book title) in bold.

learnbyexample OP ,
@learnbyexample@programming.dev avatar

Hope you find the book useful :)

I’d also suggest these shorter guides to get started:

learnbyexample OP ,
@learnbyexample@programming.dev avatar

Thanks a lot for the feedback on Coreutils book! It’s so nice to hear that it helped in your thesis.

Regarding the ebook versions, I use pandoc to convert GitHub style Markdown to PDF/EPUB (wrote a blog post about my process here: learnbyexample.github.io/customizing-pandoc/). I had to search through stackexchange threads to customize the few things I could. I don’t know how to fix the kind of page breaks you mentioned. But, I’ll try to find a solution. Thanks again for the feedback :)

learnbyexample OP ,
@learnbyexample@programming.dev avatar

I’ve written books on regex too, if you are interested in learning ;)

learnbyexample OP ,
@learnbyexample@programming.dev avatar

I have a book for Perl One-Liners as well, which I’m currently revising :)

learnbyexample ,
@learnbyexample@programming.dev avatar

I read three progression fantasy books in the past three days, so I’m going to take a break and get some of my actual work done :D

Card Mage: Slumdog Deckbuilder by Benedict Patrick (book 1 of a new series) was well written and a compelling read, but I’d have enjoyed it a lot more if it was lighthearted.

Overpowered Dungeon Boy by Benjamin Barreth (2 book completed series) was a lighthearted fun read. The OP main character took a while to warm up to, but many of the side characters were easy to root for.

learnbyexample ,
@learnbyexample@programming.dev avatar

See also:

Anyone know of a reverse command script or package to parse args for flags, expand them, and condense a man or help page(s) to just the relevant flags?

I have been working on my scripts for user/group permissions today. This idea has been on my back burner for awhile. I’m sure others have done this before. I just haven’t encountered them yet....

learnbyexample ,
@learnbyexample@programming.dev avatar

Inspired by explainshell, I wrote a script (github.com/learnbyexample/command_help) to be used from the terminal itself. It is a bit buggy, but works well most of the time. For example:


<span style="color:#323232;">$ ch grep -Ao
</span><span style="color:#323232;">       grep - print lines that match patterns
</span><span style="color:#323232;">
</span><span style="color:#323232;">       -A NUM, --after-context=NUM
</span><span style="color:#323232;">              Print NUM lines of trailing context after matching lines.  Places a
</span><span style="color:#323232;">              line containing a group separator (--) between contiguous groups of
</span><span style="color:#323232;">              matches.  With the -o or --only-matching option, this has no effect
</span><span style="color:#323232;">              and a warning is given.
</span><span style="color:#323232;">
</span><span style="color:#323232;">       -o, --only-matching
</span><span style="color:#323232;">              Print  only  the matched (non-empty) parts of a matching line, with
</span><span style="color:#323232;">              each such part on a separate output line.
</span>
  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • tech
  • drbboard
  • updates
  • testing
  • til
  • bitcoincash
  • programming
  • Sacramento
  • All magazines