July 22nd, 2024

Bash-Oneliners: A collection of terminal tricks for Linux

The GitHub repository compiles Bash one-liners and commands for bioinformatics and cloud computing, covering terminal tricks, variable manipulation, text processing, networking commands, and system maintenance for improved command-line proficiency.

Read original articleLink Icon
Bash-Oneliners: A collection of terminal tricks for Linux

The GitHub repository offers a compilation of useful Bash one-liners and commands tailored for bioinformatics and cloud computing tasks. It features various sections, including terminal tricks for navigation and editing, variable manipulation techniques, arithmetic operations, and text processing using tools like `grep`, `sed`, and `awk`. Additionally, it covers networking commands for checking connectivity and managing network interfaces, as well as system maintenance commands for file and process management.

Key highlights include terminal shortcuts, methods for variable substitution and length calculation, and commands for searching and transforming text files. The repository also emphasizes the use of `grep` for pattern searching, `sed` for text filtering and transformation, and `awk` for advanced text processing. Networking commands are provided for tasks such as DNS lookups and connectivity checks.

Moreover, the repository includes tips for utilizing tools like `xargs`, `find`, and `xwindow` applications, along with commands for data wrangling and system monitoring. This collection serves as a valuable resource for individuals aiming to improve their command-line proficiency and optimize their workflows in a Linux environment. Users are encouraged to explore specific commands or sections for further insights.

Link Icon 12 comments
By @boffinAudio - 4 months
I so rarely see my (oft-repeated) favourite BASH script hack - commenting ones command lines:

    $ mv -n ~/Desktop/*.pdf ~/Documents/PDF_Archive/  #pdfsync
This command, which sweeps all the PDF files off my Desktop into a PDF Archive, is easily recalled with the key-combo Ctrl-R "pdfsync" - this is very convenient because it doesn't require me to add a custom shell script anywhere, in any particular path, and can also be used to refer to combinations of commands, for example:

    $ for i in some_collection_of_git_repos/ ; do ; pushd . ; cd $i ; git fetch --all ; popd ; done #refreshgits
Ctrl-R "refreshgits", and voila: all of the repos I'm interested in get a full automatic refresh ..

Command commenting is my favourite trick to teach ops newbies, too .. right after they learn about just how important "history > some_history.txt #historylog" is as a command, as well ..

By @axkdev - 4 months
I'd like to point out that, for example, Ctrl+a is not specific to bash, it's a readline[0] keybinding. A subset of those will work in the text box in which I am typing this comment. C-f and C-b work, even C-h, but not C-w. Perhaps this key combo is reserved for closing the firefox tab on windows? Anyway, I love readline and wish it would work on literally all text inputs.

0. https://en.wikipedia.org/wiki/GNU_Readline

By @tripflag - 4 months
I can warmly recommend making your own oneliners.txt over time, especially if you hop between boxes a lot. Some of the more hyper-specific entries in my own list has saved my bacon more times than I'd like to admit... https://ocv.me/doc/unix/oneliners/
By @Sohcahtoa82 - 4 months
A guy I used to work with aliased "fuck" to "sudo" because he would frequently run commands that require sudo, but forget sudo, and being able to type "fuck !!" was far more satisfying than "sudo !!"
By @sampling - 4 months
Previous discussion (2022) with 108 comments: https://news.ycombinator.com/item?id=31250275
By @ramon156 - 4 months
I'd love to make a fish shell version of this but I'm far from advanced enough with fish, perhaps it's a good excuse to start learning professional fish(ing)
By @aquafox - 4 months
There's already commandlinefu.com
By @hifromwork - 4 months
As a fish shell user, I'd like to notice that "bash oneliners" and "terminal tricks" are not the same.

TFA mixes them freely, but makes it clear they're two different things, HN title kinda conflates them.

By @brendanfay - 4 months
Fwiw, Ctrl+l is not the same as clear. clear will exit with code 0, Ctrl+l will not exit with any code.
By @noufalibrahim - 4 months
I have a small section in my regular training for fresher developers where I teach shell. I sometimes wonder if it's needed anymore.
By @prashp - 4 months
Recently I have found that claude sonnet 3.5 is extremely good at coming up with bash one liners that do what you ask for fantastically.