Open-source News

The only Linux command you need to know

opensource.com - Thu, 06/02/2022 - 15:00
The only Linux command you need to know Seth Kenlon Thu, 06/02/2022 - 03:00 1 reader likes this 1 reader likes this

Information about Linux and open source abounds on the internet, but when you're entrenched in your work there's often a need for quick documentation. Since the early days of Unix, well before Linux even existed, there's been the man (short for "manual") and info commands, both of which display official project documentation about commands, configuration files, system calls, and more.

There's a debate over whether man and info pages are meant as helpful reminders for users who already know how to use a tool, or an intro for first time users. Either way, both man and info pages describe tools and how to use them, and rarely address specific tasks and how to accomplish them. It's for that very reason that the cheat command was developed.

For instance, suppose you can't remember how to unarchive a tar file. The man page provides you with all the options you require, but it leaves it up to you to translate this information into a functional command:

tar -A [OPTIONS] ARCHIVE ARCHIVE
tar -c [-f ARCHIVE] [OPTIONS] [FILE...]
tar -d [-f ARCHIVE] [OPTIONS] [FILE...]
tar -t [-f ARCHIVE] [OPTIONS] [MEMBER...]
tar -r [-f ARCHIVE] [OPTIONS] [FILE...]
tar -u [-f ARCHIVE] [OPTIONS] [FILE...]
tar -x [-f ARCHIVE] [OPTIONS] [MEMBER...]

That's exactly what some users need, but it confounds other users. The cheat sheet for tar, by contrast, provides complete common commands:

$ cheat tar

# To extract an uncompressed archive:
tar -xvf /path/to/foo.tar

# To extract a .tar in specified Directory:
tar -xvf /path/to/foo.tar -C /path/to/destination/

# To create an uncompressed archive:
tar -cvf /path/to/foo.tar /path/to/foo/

# To extract a .tgz or .tar.gz archive:
tar -xzvf /path/to/foo.tgz
tar -xzvf /path/to/foo.tar.gz
[...]

It's exactly what you need, when you need it.

More Linux resources Linux commands cheat sheet Advanced Linux commands cheat sheet Free online course: RHEL technical overview Linux networking cheat sheet SELinux cheat sheet Linux common commands cheat sheet What are Linux containers? Our latest Linux articles The Linux cheat command

The cheat command is a utility to search for and display a list of example tasks you might do with a Linux command. As with many Unix commands, there are different implementations of the same concept, including one written in Go and one, which I help maintain, written in just 100 lines of Bash.

To install the Go version, download the latest release and put it somewhere in your path, such as ~/.local/bin/ or /usr/local/bin. To install the Bash version, download the latest release and run the install-cheat.sh script:

$ sh ./install-cheat.sh

Or to configure the installation, use Autotools:

$ aclocal ; autoconf
$ automake --add-missing ; autoreconf
$ ./configure --prefix=$HOME/.local
$ make
$ make installGet cheat sheets for your Linux terminal

Cheat sheets are just plain text files containing common commands. The main collection of cheat sheets is available at Github.com/cheat/cheatsheets. The Go version of cheat downloads cheatsheets for you when you first run the command. If you're using the Bash version of cheat, the --fetch option downloads cheatsheets for you:

$ cheat --fetch

As with man pages, you can have multiple collections of cheat sheets on your system. The Go version of cheat uses a YAML config file to define where each collection is located. The Bash version defines the path during the install, and by default downloads the Github.com/cheat/cheatsheets collection as well as Opensource.com's own Gitlab.com/opensource.com/cheatsheets collection.

List cheat sheets

To list the cheat sheets on your system, use the --list option:

$ cheat --list
7z
ab
acl
alias
ansi
ansible
ansible-galaxy
ansible-vault
apk
[...]View a Linux cheat sheet

Viewing a cheat sheet is as easy as viewing a man or info page. Just provide the name of the command you need help with:

$ cheat alias

# To show a list of your current shell aliases:
alias

# To alias `ls -l` to `ll`:
alias ll='ls -l'

By default, the cheat command uses your environment's pager. Your pager is set with the PAGER environment variable. You can override that temporarily by redefining the PAGER variable before running the cheat command:

$ PAGER=most cheat less

If you just want to cat the cheat sheet into your terminal without a pager, the Bash version has a --cat option for convenience:

$ cheat --cat lessIt's not actually cheating

The cheat system cuts to the chase. You don't have to piece together clues about how to use a command. You just follow the examples. Of course, for complex commands, it's not a shortcut for a thorough study of the actual documentation, but for quick reference, it's as fast as it gets.

You can even create your own cheat sheet just by placing a file in one of the cheat sheet collections. Good news! Because the projects are open source, you can contribute your personal cheat sheets to the GitHub collection. And more good news! When there's a new Opensource.com cheat sheet release, we'll include a plain text version from now on so you can add that to your collection.

The command is called cheat, but as any Linux user will assure you, it's not actually cheating. It's working smarter, the open source way.

The Linux cheat command is a utility to search for and display a list of example tasks you might do with a command.

Image by:

Opensource.com

Linux What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Arch Linux Hits Top Linux Spot Over Ubuntu In May's Steam Survey

Phoronix - Thu, 06/02/2022 - 08:40
The Steam Survey results are in for May 2022 and while it shows Linux slightly down on a percentage basis, it shows a new top-spot for the most popular Linux distribution unseating Ubuntu LTS...

Mesa 22.1.1 Released With Many Open-Source Graphics Driver Fixes

Phoronix - Thu, 06/02/2022 - 07:58
Last month marked the debut of Mesa 22.1 as the newest quarterly release to this open-source Linux graphics driver stack. For those that prefer waiting until the first point release before upgrading, today is the day with Mesa 22.1.1 now available...

IO_uring Continues Advancing In 2022 With New Features For Pushing Linux I/O

Phoronix - Thu, 06/02/2022 - 03:00
The Kernel Recipes 2022 conference kicked off today in Paris, France. Kicking off the event was Linux block subsystem maintainer and lead IO_uring developer Jens Axboe to talk about all of the recent and ongoing work around this major advancement to Linux I/O in recent years...

Google Launches New Silicon Design Portal For Open-Source Projects

Phoronix - Thu, 06/02/2022 - 02:00
Google has been helping small open-source projects get started in chip fabrication with Google covering the costs and partnering with SkyWater Technology using their open-source process design kit (PDK). While the chip manufacturing is done on a 130nm process (SKY130), this effort has proven to be a big success for open-source hardware projects with limited funding and Google today announced a new silicon design portal...

Intel Makes Another Exciting Software Acquisition

Phoronix - Thu, 06/02/2022 - 00:12
Back in February Intel announced it was acquiring Linutronix as the folks maintaining real-time Linux (PREEMPT_RT) and other prominent Linux contributions. Today Intel announced another exciting software acquisition for bolstering their open ecosystem...

Pages