Tuesday, March 7, 2023
HomeNetworkingConstructing your private Linux cheat sheets

Constructing your private Linux cheat sheets


Linux man pages might be overwhelming to people who find themselves simply studying learn how to work on the command line, however right here we’ll have a look at a option to shortly put together a cheat sheet for a collection of instructions. These cheat sheets will inform new Linux customers sufficient to get began and know what man web page to learn once they wish to know extra.

To get began, we’ll check out collection of instructions that any Linux beginner would wish to study:

alias   cmp     export  much less    tail    whereis
apropos comm    grep    extra    tar     who
cat     dd      head    passwd  prime     whoami
chmod   df      kill    pwd     unzip   zip
chown   diff    killall kind    whatis

Subsequent, we use a collection of instructions that may present quick descriptions of those instructions. These are assist -d, whatis, and a man command that selects solely the command description from the person pages.

assist -d

The assist -d command will present a one-line description for a few of the bash built-ins.

$ assist -d pwd
pwd - Print the identify of the present working listing.

The person -f and whatis instructions

The man -f command and the whatis command produce the identical outcomes. Listed here are some examples:

$ whatis cd
cd (1) - bash built-in instructions, see bash(1)
$ man -f cd
cd (1) - bash built-in instructions, see bash(1)

Getting the 4th line from the person web page

The 4th line of every man web page accommodates a brief description of the command. The script beneath will get this by taking the highest three traces (utilizing the head command) after which solely displaying the final of them (utilizing the tail command).

Getting the outline from the person web page

To retrieve simply the quick description from a command’s man web page, you need to use a command like this:

$ man date | head -4 | tail -1
date - print or set the system date and time

Utilizing a script

To make use of every of the strategies described, you may run a script just like the one proven beneath that runs by the collection of instructions you present (listed in a file) and creates a cheat sheet utilizing every of the instructions described. This script calls the resultant recordsdata help1, help2, and help3. Be aware that it quiets any error message (e.g., when it will probably’t discover a description for a specific command) and in any other case provides a line to one of many three recordsdata.

#!/bin/bash

# empty CheatSheet recordsdata in the event that they exist
> help1; > help2; > help3
# get identify of command listing
echo -n "lisf of instructions> "
learn listing
# kind command listing
kind $listing > $listing$$
# run by command listing and gather descriptions
for cmd in `cat $listing$$
do
    assist -d $cmd 2>/dev/null >> help1
    whatis $cmd 2>/dev/null | grep ^$cmd 2>/dev/null >> help2
    man $cmd | head -4 | tail -1 2>/dev/null >> help3
achieved
# take away sorted instructions file
rm $listing$$

Outcomes

The outcomes beneath present the highest 10 traces from every of the recordsdata.

$ head -10 help1 help2 help3
==> help1 <==
alias - Outline or show aliases.
command - Execute a easy command or show details about instructions.
export - Set export attribute for shell variables.
kill - Ship a sign to a job.
pwd - Print the identify of the present working listing.

==> help2 <==
alias (1)            - bash built-in instructions, see bash(1)
apropos (1)          - search the guide web page names and descriptions
cat (1)              - concatenate recordsdata and print on the usual output
chmod (1)            - change file mode bits
chown (1)            - change file proprietor and group
cmp (1)              - evaluate two recordsdata byte by byte
comm (1)             - evaluate two sorted recordsdata line by line
dd (1)               - convert and replica a file
df (1)               - report file system disk area utilization
diff (1)             - evaluate recordsdata line by line

==> help3 <==
       bash,  :,  .,  [, alias, bg, bind, break, builtin, caller, cd, command,
       apropos - search the manual page names and descriptions
       cat - concatenate files and print on the standard output
       chmod - change file mode bits
       chown - change file owner and group
       cmp - compare two files byte by byte
       comm - compare two sorted files line by line
       dd - convert and copy a file
       df - report file system disk space usage
       diff - compare files line by line

Wrap-Up

Using the commands described in this post, you can assemble a list of commands and quickly prepare a cheat sheet that contains a brief description of each of them. Select the resultant file that works best or join them into a single cheat sheet.

Copyright © 2023 IDG Communications, Inc.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments