Bash-Oneliner and GameShell Teach Unix Command Line
Written by Nikos Vaggalis   
Friday, 10 June 2022

Two great resources, one for beginners and one for intermediate users, for learning the Unix, well, Linux shell.

Many wanted the command line bashed (pun intended), deprecated or replaced by something else. Still it has never gone away and never will, especially now that it has infiltrated even Windows through WSL.

In "The PaSh Project - Advancing the Unix Philosophy One Step Further" I found that:

I remember the time when the saying was "Learn Perl so you don't have to learn the Shell and its hundreds of utilities".
Fast forward some decades and the use of shell scripts still has not been eradicated. On the contrary, their use has increased due to the rise of containers, VM's, administering the cloud, and Linux itself. 

This is due of course to the timeless Unix philosophy; taking simple, high quality, components and combining them together in smart ways to obtain a complex result. Of course, the Linux cli is not easy to master therefore any helpis very welcome. On that matter, last month I presented Dash Dash, a new website that aims to prettify the ugly that is the Man Pages making the exploration of the cli a much healthier proposition.

This month two new items are added to this category of helpful resources. Lets' start with the more straightforward one aimed at total beginners, Gameshell, a "game" to teach the Unix shell.

GameShell was devised as a tool to help students at the Université Savoie Mont Blanc to engage with a real shell in a way that encourages learning while also having fun. It is like an old text adventure RPG where instead of commands like 'get', 'talk', 'fight' you have 'cd', 'ls' or 'pwd' ! Of course, as you progress, you get more deep into the commands.

The oxymoron is that Gameshell requires writing shell commands in order to install it. Fear not though as it is as simple as loading
its dependencies with :

$ sudo apt install gettext man-db procps psmisc nano tree bsdmainutils x11-apps wget

and then the game itself:

$ wget https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh

finally running it with:

$ bash gameshell.sh

The next resource is the Bash-Oneliner, "a collection of handy Bash One-Liners and terminal tricks for data processing and Linux system maintenance". The idea of running such a collection was conceived while the author was working in the field of bioinformatics, and, in agreement with the Unix philosophy aspect that we've detailed in the Pash article, found that she was:

amazed by those single-word bash commands which are much faster than my dull scripts, time saved through learning command-line shortcuts and scripting. 

so much that she's put an effort to collect them into one huge cheat-sheet. Of course it ended up getting split into sections: 

  • Terminal Tricks
  • Variable
  • Math
  • Grep
  • Sed
  • Awk
  • Xargs
  • Find
  • Condition and Loop
  • Time
  • Download
  • Random
  • Xwindow
  • System
  • Hardware
  • Networking
  • Data Wrangling
  • Others

There's really something for everyone in there.

For instance, in the Terminal tricks section we find how to use the Ctrl keys combination in order to move around:

Ctrl + n : same as Down arrow.

Ctrl + p : same as Up arrow.
Ctrl + r : begins a backward search through command history.(keep pressing Ctrl + r to move backward)
Ctrl + s : to stop output to terminal
...
and work with History:

Run history number (e.g. 53)
!53

Run last command
!!
# run the previous command using sudo
sudo !!

Under the Variable heading, we learn how variable substitution works:
# foo=bar
echo $foo
# bar
echo "$foo"
# bar
# $foo
# single quotes within double quotes will not cancel expansion and will be part of the output
echo "'$foo'"

Of course, Grep hints are very useful :

Grep only IP address
grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
# or
grep -Po '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'

followed by Sed, Awk, Xargs and so on.

This cheat-sheet however is addressed at intermediate users who need an at-a-glancequick reference. If  you are a beginner then it is strongly recommended to start with Gameshell.  Bash-Oneliner can wait... 

More Information

Bash-Oneliner
GameShell: a "game" to teach the Unix shell

Related Articles

Dash Dash - Making Linux Documentation More Approachable

The PaSh Project - Advancing the Unix Philosophy One Step Further

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


pg_ivm - Materialised Views On Steroids
06/06/2022

pg_ivm is an extension module for PostgreSQL 14 that provides an Incremental View Maintenance (IVM) feature.That means that materialized views are updated immediately after a base table is modified.



TypeScript 4.7 Adds Node.js ECMAScript Module Support
06/06/2022

TypeScript 4.7 has been released with improvements including ECMAScript module support in Node.js, instantiation expressions, and control-flow analysis for computed properties.


More News

pythondata

 



 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Friday, 10 June 2022 )