Author: JackTian

Source: Public account “Jie Ge’s IT Journey”

ID: Jake_Internet

Please contact authorization for reprinting (wechat ID: Hc220088)

10 Linux Alternatives you didn’t know existed!

Hi, I’m Jack.

In Linux, we often use the cat command to connect multiple files and print them to standard output, compose several files into a single object file, and append several files to the object file.

I recently found a similar command on GitHub called “Bat,” which is an alternative to cat with cool features like syntax highlighting, Git integration, and automatic paging.

In this article, we will introduce how to install and use the bat command in Linux.

1, the bat

Install the bat

Arch Linux

Bat is available in the default software source for the Arch Linux operating system and can be installed directly on any ARCH-based system using the pacman command.

pacman -S bat
Copy the code

Fedora

dnf install bat
Copy the code

macOS

brew install bat
Copy the code

Ubuntu 21.10

Deb file is downloaded from the release page of bat. You can run the following command to download and install it.

sudo apt-get install wget
wget https://github.com/sharkdp/bat/releases/tag/v018.3./bat_018.3._amd64.deb
sudo dpkg -i bat_018.3._amd64.deb
Copy the code

For other systems, you may need to compile and install from a software source, or refer to other operating system installations at BAT on GitHub.

The bat command is used

The use of the bat command is very similar to that of the cat command.

Create a new file using the bat command:

bat > jiaoben1.sh
Copy the code

Run the bat command to view the file contents:

bat jiaoben1.sh
Copy the code

Use the bat command to view multiple files simultaneously:

bat jiaoben1.sh jiaoben2.sh
Copy the code

Use the bat command to combine the contents of multiple files into a single file:

bat jiaoben1.sh jiaoben2.sh > test.txt
Copy the code

The above describes how BAT creates new files, views file contents, and merges the contents of multiple files into a single file.

Next, let’s look at some of the cool features of the bat command.

The bat command supports syntax highlighting for most programming and markup languages, so let’s use cat and bat commands to show jiaoben1.sh for a sharp contrast.

As you can see, the cat command displays the contents of the file in plain text format, while the bat command shows syntax highlighting and neat text alignment.

If you want to display the line number, you can use the -n parameter. Although cat will display the line number, it is not as good as bat output.

bat -n jiaoben2.sh
Copy the code

Bat command support Git integration, you can easily view and edit files in Git repository, bat and Git connection can show changes about the index.

Bat’s support for automatic paging is also worth noting.

Support paging means that when the output of a file is beyond the screen, the bat command will automatically pass its output to the less command. You can use the enter key to view the output page by page, and use the space bar to jump directly to the last line of the text.

None of this is necessary when you use the bat command, which automatically transmits the output of files across multiple pages.

bat jiaoben3.sh
Copy the code

When you run the cat command to view the file contents of jiaoben3.sh across multiple pages, the prompt will jump directly to the last page of the file and you will not be able to see the contents at the beginning and middle of the file across multiple pages.

cat jiaoben3.sh
Copy the code

If you want to use cat to achieve the effect of bat, you need to use cat output to transmit to less so that you can view the contents page by page from the beginning.

cat jiaoben3.sh | less
Copy the code

It is also possible to use the return key to view the output page by page and the space bar to jump directly to the last line of the text.

Bat Custom theme

Currently there are 24 bat custom themes, including: Coldark-cold, GitHub, Monokai Extended Light, OneHalfDark, Solarized (Light), TwoDark, Visual Studio Dark+, Base16, Zenburn, etc.

If you don’t like the default themes, you can modify them according to your own style. Just run the: bat –list-themes command to display the themes available.

# bat --list-themes
Theme: 1337

  // Output the square of a number.
  fn print_square(num: f64) {
      let result = f64::powf(num, 2.0); println! ("The square of {:.2} is {:.2}.", num, result); }...Copy the code

For example, you have to chooseDraculaSubject, can be executed directly:Bat --theme=Dracula file name

If you want to change a theme permanently, use export BAT_THEME=”Dracula” to make the change permanent by launching the file in your shell.

You can use the –style parameter option to control the appearance of bat output. Configuration elements include line numbers, file headers, grid borders, Git modifications to show anything other than file content, and the parameter is a comma-separated list.

–style=numbers,changes You can use the BAT_STYLE environment variable to make these changes permanent by showing only Git changes and line numbers, not grid and file titles.

For more information about how to use bat, run the man bat or bat –help command.

In addition, you can also check out the GitHub library of the BAT project for more details. Once I use BAT, I won’t want to go back to CAT!

2, duf

In Linux, we know that the df command is used to display the available disk space on the disk partition. The default display unit is KB. You can also use this command to obtain information such as how much disk space has been used and how much space is left.

# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda3       18439940 4943264  12559972  29% /
tmpfs             506176      76    506100   1% /dev/shm
/dev/sda1          99150   30003     64027  32% /boot
/dev/sr0         4363088 4363088         0 100% /media/CentOS_6. 5_Final
Copy the code

In addition, the du command is also used to check the space used, but different from the df command, the Linux du command is used to check the space used by files and directory disks. There are some differences with the df command.

# du
4    ./.abrt
8    ./.dbus/session-bus
12    ./.dbus
4    ./.nautilus
40    ./.local/share/gvfs-metadata
24    ./.local/share/applications
68    ./.local/share
72    ./.local
Copy the code

Here’s a terminal tool that you can think of as a combination of the traditional Linux commands df and du — duf.

Duf is a cross-platform disk usage tool written in Golang that allows you to easily check the available disk space, categorize the output, and present it in a user-friendly manner. It is suitable for Linux, Windows, macOS, Android, FreeBSD, etc. Duf is a cross-platform disk usage tool written in Golang that allows you to easily check the available disk space, categorize the output, and present it in a user-friendly manner.

Ubuntu installation mode:

$ sudo apt install gdebi
# if an error, Failed to fetch HTTP: / / http://security.ubuntu.com...
# sudo apt-get update

$ sudo gdebi duf_0. 5. 0_linux_amd64.deb
# in the first download duf_0. 5.0 _linux_amd64. Deb, download address is: https://github.com/muesli/duf/releases/download/v0.5.0/duf_0.5.0_linux_amd64.deb
Copy the code

MacOS Installation:

Install Homebrew and follow the instructions.
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

# installation duf
brew install duf

# or
sudo port selfupdate && sudo port install duf
Copy the code

Windows installation mode:

choco install duf

# or

scoop install duf
Copy the code

Once installed, duF can be used directly, and the method is very simple.

If no parameter is added, details about all local devices, mounted cloud storage devices, and other special devices (including temporary storage locations) are displayed.

$ duf
Copy the code

If you only want to view the details of the locally connected device, do:

$ duf --only local
Copy the code

If you just want to sort the output by size in a particular order, you can execute:

$ duf --sort size
Copy the code

More parameters:

Duf /home/some/file Based on arguments, duF will only list specific devices and installation points duf --allDuf --hide-network Hide network file system, Inodes duf -- Output MountPoint,size, Usage -- Hide-fuse --hide-special --hide-loops -- Hide-Sharing duf --inodes Mountpoint, size, used, Avail, usage, inodes, inodes_used, inodes_avail, inodes_usage,type, filesystem) duf --json Output in JSON format DUf --theme light If the DUF cannot detect the terminal color correctly, you can set a theme duf --helpView all available duF commandsCopy the code

3, TLDR

For beginners to learn Linux, the most common problem is that there are endless commands and the use of various parameters in the Linux operating system. In fact, you don’t need to memorize it by rote. When you use it, you can find relevant information or view relevant documents through the MAN command. For a command with many parameters, the man manual is also very difficult to read.

This time, WE will introduce a tool: TLDR, its full name is: Too Long, Don’t Read, Chinese meaning: Too Long to see the meaning.

In fact, the result of the man command is basically too long to see, TLDR this tool you can understand as a simplification of the man command help document, the Linux command is most commonly used some command usage listed, very easy to understand.

TLDR also includes clients written in many languages, such as C, Go, iOS, Python, nodeJS, etc. You can use different clients to install TLDR.

My environment is Ubuntu, so I need to install Node.js first, and then follow the following installation methods:

sudo apt-get install nodejs

sudo apt-get install npm

sudo npm install -g tldr
Copy the code

After the preceding three commands are executed, you need to run the TLDR –update command to update the TLDR to the latest status. Then you can directly use the TLDR command.

tldr --update
Copy the code

Use of TLDR:

TLDR command is also very simple to use, just TLDR + you want to query the command can;

4, htop

The most common tool for displaying process status information on Linux is the familiar top, which is a good helper for every system administrator.

Htop is a perfect substitute for the top, so to speak, it is written in C, is a cross-platform interactive process monitoring tools, has better visual effect, the status of the be clear at a glance is easier to understand the current system, allows the vertical and horizontal scroll process list to view their full command line and related information, such as memory and CPU consumption. System-wide information, such as load average or switching usage, is also displayed.

The information displayed can be configured through graphical Settings and can be interactively sorted and filtered, and process-related tasks (such as termination and reprocessing) can be completed without entering their PID.

Installation is also very simple, just execute the command: apt install htop to complete.

Compared with TOP, HTOP has obvious advantages. In addition to more perfect functions, its color collocation is also very rich, and it is more friendly to use on the whole.

5, glances

Glances is a cross-platform monitoring tool written in Python designed to present large amounts of system monitoring information through Curses or a Web-based interface, dynamically adjusted to the size of the user interface. Is a top/ HTOP replacement for GNU/Linux, BSD, Mac OS, and Windows operating systems.

It can work in client/server mode, remote monitoring can be done through terminals, Web interfaces, or apis (XML-RPC and RESTful), and statistics can also be exported to files or external time/value databases.

In addition to listing all the processes and their CPU and memory usage, it can also display other information about the system, such as:

  • Network and disk usage
  • Used space and total space of the file system
  • Data from different sensors, such as batteries
  • And a list of processes that have recently consumed too many resources

6, exa

Referred to the ls command, everyone not unfamiliar, in Linux environment, its main role: lists the current directory contains files and subdirectories, if the current directory files too much, use the command ls is not very good, because the output of the results failed to agree with all you have to find the file, the first: the need for secondary filter to find, Second: too many files, the terminal output is slow;

EXA is a modern LS replacement for the command line programs that ship with Unix and Linux operating systems, giving it more features and better defaults. It uses color to distinguish between file types and metadata. It understands symbolic links, extended properties, and Git. It is small, fast, and has only one binary file.

How is EXA different from LS?

  • Terminal screens are no longer a bottleneck: ExA is powerful, friendlier than LS, and produces faster results;
  • Color: EXA makes extensive use of color;
  • Does not conflict with the ls command

The characteristics of the EXA

  • Color: list of file types and how to distinguish files
  • Grid view: Displays files in a grid the same size as the terminal window;
  • Long term: display files and their metadata in tables
  • Tree view: Displays files and their descendants in a tree.
  • Git integration: Check the Git status of a file while in the repository.
  • Filter: Hide files in the list, show invisible files, and sort the output;
  • Xattrs: Lists the extended attributes of the file;

To install Ubuntu 21.10, simply run the command apt install exa.

Display options

  • -1, –oneline: displays one entry per line
  • -g, –grid: Displays entries as grids (default)
  • -l, –long: displays extension details and attributes
  • -r, –recurse: recurse to the directory
  • -t, –tree: recurses to the directory as a tree
  • -x, –across: Sorts the grid, not down
  • -f, –classify: Displays type indicators by file name
  • –colo[u]r: When to use terminal color
  • Colo [u]r-scale: Clearly highlight the level of file size
  • — ICONS: display ICONS
  • –no-icons: do not display ICONS (always overwrite — ICONS)

Filtering options

  • -a, –all: Displays hidden and dotted files
  • -d, –list-dirs: Lists directories like normal files
  • -l, –level=(depth) : limits the recursion depth
  • -r, –reverse: reverses the sorting order
  • -s, –sort=(field) : Sort by field
  • –group-directories-first: Lists directories before other files
  • -d, –only-dirs: lists only directories
  • –git-ignore: ignore the file mentioned in
  • -i, –ignore-glob=(globs) : Global mode for files to be ignored (pipe separation)

Pass the –all option twice to display simultaneously. And.. Directory.

EXA is an open source alternative to LS and you deserve it!

7, fd

Fd is a program that finds items in a file system. It is a simple, fast, and user-friendly alternative to the find command. Fd is not intended to replace all that the find command provides, but rather to provide reasonable defaults in most use cases, which can be very useful in some cases.

The fd output is colored, similar to some LS modes. It is recursive, and when searching for source files in directories containing Git repositories, FD automatically excludes hidden files and directories, including. In general, searches are faster and provide more relevant results the first time around.

By default, fd performs a case-insensitive pattern search in the current directory, but if your search pattern contains a uppercase letter, FD will perform it in case-sensitive mode. Of course, it is possible to override the defaults, but in many cases it is beneficial. The same search using find requires you to provide additional command-line arguments.

Fd is available on many Linux distributions and can be installed in Ubuntu using the standard repository by executing the following command:

sudo apt install fd-find
Copy the code

In Ubuntu, the command is fdfind to avoid conflicts with other existing utility names. If you want it to be fd, you can set an alias:

alias fd=fdfind
Copy the code

To keep the alias unchanged and still available after a restart, place it in the “.bashrc “or”.bash_aliases “file.

Fd with no parameter options is similar to ls, except that it also lists files in subdirectories by default.

fd
bat_018.3._amd64.deb
fd_83.. 0_amd64.deb
jiaoben1.sh
jiaoben2.sh
jiaoben3.sh
snap
snap/firefox
snap/firefox/631
snap/firefox/731
snap/firefox/common
snap/firefox/current
snap/snap-store
snap/snap-store/557
snap/snap-store/558
snap/snap-store/common
snap/snap-store/current
test.md
Copy the code

Search the current directory for all markdown files (.md or. MD), find command as follows:

find . -iname "*.md"
./test.md
Copy the code

Use fd for the same search:

fd *.md
test.md
Copy the code

In some cases, fd requires additional options; For example, if you want to include hidden files and directories, you must use the -h option, which is not required in find. For more information on how to use fd command-line options, see the FD GitHub repository.

8 ag.

Ack and AG are two text search tools that are much better than grep.

When searching for text in a specified directory, you do not need to specify various command-line options like grep. The output also contains the file name and line number, and the search keyword is highlighted.

Ag is a faster recursive search for file contents than grep and ACK.

Ubuntu 21.10 Install AG and ACK

apt-get install silversearcher-ag
apt install ack
Copy the code

Common parameters of the ag command

  • Ag-g: similar to find.-name (filename)
  • Ag-i sed: searches for sed text regardless of case
  • Ag-a sed: searches for sed text and displays n lines of text following the matched content
  • Ag-b sed: searches for sed text and displays n lines of text before the matching content
  • Ag-c sed: searches for sed text and displays the matched content and n lines of text before and after it
  • Ag-w sed: searches only the text that exactly matches the content
  • Ag — Java sed: Searches Java files for text containing sed
  • Ag — XML sed: Searches XML files for text containing sed

Use of the ag command

To search for a file based on the file name, use the -g option.

ag -g jiaoben
jiaoben2.sh
jiaoben1.sh
jiaoben3.sh
Copy the code

Search for sed keyword text in the current directory.

ag -w sed
jiaoben1.sh
10:                sed -i '2d' "$new_filename"
Copy the code

More parameter options, you can use according to their own actual scenarios.

9, axel

Axel is a command line multithreaded download tool that can replace curl and wget when downloading files.

Install Axel for Ubuntu 21.10

apt-get install axel
Copy the code

Axel parameter option

  • -n: Specifies the number of threads
  • -o: saves as a directory
  • -s: specifies the maximum number of bits per second
  • -q: silent mode

case

# axel -n 10 -o /tmp/ http://mirrors.163.com/ubuntu/ls-lR.gz
# exa /tmp/ls-lR.gz
/tmp/ls-lR.gz
Copy the code

/ TMP/ls-lr.gz/TMP/ls-lr.gz/TMP/ls-lr.gz

10, pydf

On Linux, you can use the df command to display information about disks.

# dfFile system 1K- Block used Available Used % mount point TMPFS199180     1660  197520    1% /run
/dev/sda3      19946096 10317864 8589692   55% /
tmpfs            995884        0  995884    0% /dev/shm
tmpfs              5120        4    5116    1% /run/lock
/dev/sda2        524252     5344  518908    2% /boot/efi
tmpfs            199176      100  199076    1% /run/user/1000
/dev/sr0        3043440  3043440       0  100% /media/jacktian/Ubuntu 21.10 amd64
tmpfs            199176       60  199116    1% /run/user/0
Copy the code

Install PyDF for Ubuntu 21.10

apt install pydf
Copy the code

Pydf is an alternative to DF in that it shows disk usage in a more concise way.

reference

  • bat:github.com/sharkdp/bat
  • duf:github.com/muesli/duf
  • Tldr:github.com/tldr-pages/…
  • Htop:github.com/htop-dev/ht…
  • Glances:github.com/nicolargo/g…
  • exa:github.com/ogham/exa
  • fd:github.com/sharkdp/fd/

The last

Although most of us still use the default basic command tool in our daily work, it can be very useful in many scenarios if you replace it with the 10 alternatives described above. Of course, there are probably more Linux command-line alternatives, and you are welcome to add them in the comments section below.

And that’s all for today.

If you think this article is useful to you, please like it, leave a comment or forward it, so that more friends can see it, because this will be my strongest motivation to continue to output more high-quality articles!