TranslateProject/sources/tech/20190104 Search, Study And Practice Linux Commands On The Fly.md

10 KiB
Raw Blame History

Search, Study And Practice Linux Commands On The Fly!

The title may look like sketchy and click bait. Allow me to explain what I am about to explain in this tutorial. Let us say you want to download an archive file, extract it and move the file from one location to another from command line. As per the above scenario, we may need at least three Linux commands, one for downloading the file, one for extracting the downloaded file and one for moving the file. If youre intermediate or advanced Linux user, you could do this easily with an one-liner command or a script in few seconds/minutes. But, if you are a noob who dont know much about Linux commands, you might need little help.

Of course, a quick google search may yield many results. Or, you could use man pages. But some man pages are really long, comprehensive and lack in useful example. You might need to scroll down for quite a long time when youre looking for a particular information on the specific flags/options. Thankfully, there are some good alternatives to man pages, which are focused on mostly practical commands. One such good alternative is TLDR pages. Using TLDR pages, we can quickly and easily learn a Linux command with practical examples. To access the TLDR pages, we require a TLDR client. There are many clients available. Today, we are going to learn about one such client named “Tldr++”.

Tldr++ is a fast and interactive tldr client written with Go programming language. Unlike the other Tldr clients, it is fully interactive. That means, you can pick a command, read all examples , and immediately run any command without having to retype or copy/paste each command in the Terminal. Still dont get it? No problem. Read on to learn and practice Linux commands on the fly.

Install Tldr++

Installing Tldr++ is very simple. Download tldr++ latest version from the releases page. Extract it and move the tldr++ binary to your $PATH.

$ wget https://github.com/isacikgoz/tldr/releases/download/v0.5.0/tldr_0.5.0_linux_amd64.tar.gz

$ tar xzf tldr_0.5.0_linux_amd64.tar.gz

$ sudo mv tldr /usr/local/bin

$ sudo chmod +x /usr/local/bin/tldr

Now, run tldr binary to populate the tldr pages in your local system.

$ tldr

Sample output:

Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Compressing objects: 100% (6/6), done.
Total 18157 (delta 0), reused 3 (delta 0), pack-reused 18151
Successfully cloned into: /home/sk/.local/share/tldr

Tldr++ is available in AUR. If youre on Arch Linux, you can install it using any AUR helper, for example YaY. Make sure you have removed any existing tldr client from your system and run the following command to install tldr++.

$ yay -S tldr++

Alternatively, you can build from source as described below. Since Tldr++ is written using Go language, make sure you have installed it on your Linux box. If it isnt installed yet, refer the following guide.

After installing Go, run the following command to install Tldr++.

$ go get -u github.com/isacikgoz/tldr

This command will download the contents of tldr repository in a folder named go in the current working directory.

Now run the tldr binary to populate all tldr pages in your local system using command:

$ go/bin/tldr

Sample output:

Finally, copy the tldr binary to your PATH.

$ sudo mv tldr /usr/local/bin

It is time to see some examples.

Tldr++ Usage

Type tldr command without any options to display all command examples in alphabetical order.

Use the UP/DOWN arrows to navigate through the commands, type any letters to search or type a command name to view the examples of that respective command. Press ? for more and Ctrl+c to return/exit.

To display the example commands of a specific command, for example apt , simply do:

$ tldr apt

Choose any example command from the list and hit ENTER. You will see a *** symbol** before the selected command. For example, I choose the first command i.e sudo apt update. Now, it will ask you whether to continue or not. If the command is correct, just type y to continue and type your sudo password to run the selected command.

See? You dont need to copy/paste or type the actual command in the Terminal. Just choose it from the list and run on the fly!

There are hundreds of Linux command examples are available in Tldr pages. You can choose one or two commands per day and learn them thoroughly. And keep this practice everyday to learn as much as you can.

Learn And Practice Linux Commands On The Fly Using Tldr++

Now think of the scenario that I mentioned in the first paragraph. You want to download a file, extract it and move it to different location and make it executable. Let us see how to do it interactively using Tldr++ client.

Step 1 Download a file from Internet

To download a file from command line, we mostly use curl or wget commands. Let me use wget to download the file. To open tldr page of wget command, just run:

$ tldr wget

Here is the examples of wget command.

You can use UP/DOWN arrows to go through the list of commands. Once you choose the command of your choice, press ENTER. Here I chose the first command.

Now, enter the path of the file to download.

You will then be asked to confirm if it is the correct command or not. If the command is correct, simply type yes or y to start downloading the file.

We have downloaded the file. Let us go ahead and extract this file.

Step 2 Extract downloaded archive

We downloaded the tar.gz file. So I am going to open the tar tldr page.

$ tldr tar

You will see the list of example commands. Go through the examples and find which command is suitable to extract tar.gz(gzipped archive) file and hit ENTER key. In our case, it is the third command.

Now, you will be prompted to enter the path of the tar.gz file. Just type the path and hit ENTER key. Tldr++ supports smart file suggestions. That means it will suggest the file name automatically as you type. Just press TAB key for auto-completion.

If you downloaded the file to some other location, just type the full path, for example /home/sk/Downloads/tldr_0.5.0_linux_amd64.tar.gz.

Once you enter the path of the file to extract, press ENTER and then, type y to confirm.

Step 3 Move file from one location to another

We extracted the archive. Now we need to move the file to another location. To move the files from one location to another, we use mv command. So, let me open the tldr page for mv command.

$ tldr mv

Choose the correct command to move the files from one location to another. In our case, the first command will work, so let me choose it.

Type the path of the file that you want to move and enter the destination path and hit ENTER key.

Note: Type y! or yes! to run command with sudo privileges.

As you see in the above screenshot, I moved the file named tldr to /usr/local/bin/ location.

For more details, refer the projects GitHub page given at the end.

Conclusion

Dont get me wrong. Man pages are great! There is no doubt about it. But, as I already said, many man pages are comprehensive and doesnt have useful examples. There is no way I could memorize all lengthy commands with tricky flags. Some times I spent much time on man pages and remained clueless. The Tldr pages helped me to find what I need within few minutes. Also, we use some commands once in a while and then we forget them completely. Tldr pages on the other hand actually helps when it comes to using commands we rarely use. Tldr++ client makes this task much easier with smart user interaction. Give it a go and let us know what you think about this tool in the comment section below.

And, thats all. More good stuffs to come. Stay tuned!

Good luck!


via: https://www.ostechnix.com/search-study-and-practice-linux-commands-on-the-fly/

作者:SK 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出