10 Open Source Alternatives to Linux

Under the Linux operating system, we often use the cat command to concatenate multiple files and print to standard output, synthesize several files into one object file, and append several files to the object file.

Recently I found a similar command on GitHub called " Bat", which is a replacement for the cat command with some really cool features like syntax highlighting, Git integration, and automatic pagination.

In this article, I will show you how to install and use the bat command in Linux.

01 bat

install bat

Arch Linux

bat is available in the default repositories of the Arch Linux operating system and can be installed directly on any Arch based system using the pacman command.

pacman -S bat

Fedora

dnf install bat

macOS

brew install bat

Ubuntu 21.10

I installed bat in the Ubuntu environment, downloaded the .deb file from the bat release page, and executed the following commands to download and install.

sudo apt-get install wget
wget https://github.com/sharkdp/bat/releases/tag/v0.18.3/bat_0.18.3_amd64.deb
sudo dpkg -i bat_0.18.3_amd64.deb

For other systems, you may need to compile and install from the software source, or refer to bat on GitHub for other operating system installation methods.

Use of the bat command

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

Create a new file using the bat command:

bat > jiaoben1.sh

Use the bat command to view the contents of the file:

bat jiaoben1.sh

Use the bat command to view multiple files at the same time:

bat jiaoben1.sh jiaoben2.sh

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

bat jiaoben1.sh jiaoben2.sh > test.txt

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 take a look at some very cool features of the bat command.

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

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

From the output of the bat command above, it can be seen that there is a table line. If you only want to display the line number (without the table), you can use the -n parameter to achieve it. Although the cat execution will also display the line number, there is still no bat execution. The output effect is beautiful.

bat -n jiaoben2.sh

The bat command supports Git integration, making it easy to view and edit files in Git repositories, and the bat connection to Git displays changes to the index.

bat supports automatic paging, this feature is also worth noting.

Support paging means that when the output content of the file exceeds the screen display, the bat command will automatically pass its output content to the less command, you will be able to use the Enter key to view the output content page by page, use The space bar can jump directly to the last line at the end of the text.

These are unnecessary when you use the bat command, which will automatically transfer the output of files that span multiple pages.

bat jiaoben3.sh

Compared with the cat command, when viewing the contents of jiaoben3.sh across multiple pages, the prompt will directly jump to the last page of the file, and you will not be able to see the content at the beginning and middle of the file across multiple pages.

cat jiaoben3.sh

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

cat jiaoben3.sh | less

In the same way, 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 at the end of the text.

bat custom theme

There are currently 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 theme, you can also modify it according to your own style, just execute the : bat --list-themescommand to display the available themes.

# 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);
  }

......

For example, if you want to choose the Dracula theme, you can directly execute: bat --theme=Draculafile name

If you want to permanently change a theme, use export BAT_THEME="Dracula"the startup file in your shell to make the changes permanent.

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

--style=numbers,changesIt is possible to set the BAT_STYLE environment variable to make these changes permanent using only the Git modifications and line numbers, but not the grid and file titles.

More about the use of bat can be executed by command man bator bat --help.

In addition to this, more details can also be viewed through the GitHub repository of the bat project. After using bat, I will not want to use cat again!

02 dull

In the Linux environment, 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 get how much space is occupied by the hard disk, how much space is left, etc. information.

# 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

In addition, the du command also checks the space used, but unlike the df command, the Linux du command checks the space used by the file and directory disk, which is somewhat different from 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

Next, I will introduce a terminal tool, which you can understand as the traditional Linux command df and du integrated version - duf.

duf is a cross-platform disk usage tool written in Golang that lets you easily check free disk space, categorize output, and present it in a user-friendly way, for Linux, Windows, macOS, Android, FreeBSD;

Ubuntu installation method:

$ sudo apt install gdebi
#如果报错,Failed to fetch http://security.ubuntu.com......
# sudo apt-get update

$ sudo gdebi duf_0.5.0_linux_amd64.deb
#要先在下载duf_0.5.0_linux_amd64.deb,下载地址为:https://github.com/muesli/duf/releases/download/v0.5.0/duf_0.5.0_linux_amd64.deb

MacOS installation method:

#先安装Homebrew,按照提示安装即可。
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

#安装duf
brew install duf

#或者
sudo port selfupdate && sudo port install duf

Windows installation method:

choco install duf

#或者

scoop install duf

After the installation is complete, you can use duf directly, and the method is very simple.

Without adding any parameters, it will output the details of all local devices, any cloud storage devices that have been mounted, and any other special devices (including temporary storage locations, etc.);

$ duf

If you only want to see the details of the locally connected device and nothing else, execute:

$ duf --only local

If you just want to sort the output in a specific order based on size, execute:

$ duf --sort size

More parameters to use:

duf /home /some/file 根据参数,则 duf 将仅列出特定的设备和安装点
duf --all 列出所有内容
duf --hide-network 隐藏网络文件系统,与之对应的 --hide-fuse --hide-special --hide-loops --hide-binds
duf --inodes 列出inodes
duf --output mountpoint,size,usage 指定输出的格式 对应的还有(mountpoint, size, used, avail, usage, inodes, inodes_used, inodes_avail, inodes_usage, type, filesystem)
duf --json 以json格式输出
duf --theme light 如果 duf 无法正确检测终端的颜色,可以设置一个主题
duf --help 查看所有 duf 的可用命令

03 tldr

For beginners to learn Linux, the most common problem is that under the Linux operating system, there are endless commands and how to use various parameters. In fact, you don't need to memorize it at all, and find it when you use it. Related information or view related documents through the man command, the man manual outputs a lot of information, and for commands with many parameters, it is also very difficult to read the man manual.

This time, I will introduce a tool: tldr, its full name is: Too Long, Don't Read,Chinese meaning: too long to read.

In fact, the result of the man command is basically too long to read. You can understand tldr as a tool that simplifies the help documentation of the man command, and lists some of the most commonly used command usages of Linux commands, which is very easy to understand.

At the same time, tldr includes clients written in many languages, such as: C, Go, iOS, Python, nodejs, etc. You can use different clients to install;

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

sudo apt-get install nodejs

sudo apt-get install npm

sudo npm install -g tldr

After executing the above three commands, you need to execute tldr --update again to update tldr to the latest state, and then you can use it directly;

tldr --update

Use of tldr:

The use of the tldr command is also very simple, just tldr + the command you want to query;

04 htop

The most commonly used tool to display process running status information on Linux operating system is the familiar top, which is a good helper for every system administrator.

htop can be said to be an excellent alternative to top, it is written in C, it is a cross-platform interactive process monitoring tool, with better visual effects, it is easier to understand the current system status at a glance, allowing vertical and horizontal Scroll through the list of processes to see their full command line and related information such as memory and CPU consumption. System-wide information such as load average or swap usage is also displayed.

The information displayed is configurable through graphical settings, and can be interactively sorted and filtered, and process-related tasks such as termination and reprocessing can be done without entering its PID.

Installation is also very simple, just execute the command: and apt install htopyou are done.

Compared with top, htop has obvious advantages. In addition to more complete functions, its color matching is also very rich, and it is more friendly to use on the whole.

05 glances

Glances is a cross-platform monitoring tool written in Python, designed to present a large amount of system monitoring information through curses or a web-based interface. The information is dynamically adjusted according to the size of the user interface. It is GNU/Linux, BSD, Mac OS and Windows operation System top/htop replacement.

It can work in client/server mode, remote monitoring can be done via terminal, web interface or API (XML-RPC and RESTful), statistics can also be exported to files or external time/value databases.

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

  • Network and Disk Usage

  • Filesystem used and total space

  • Data from different sensors (e.g. battery)

  • and a list of processes that have recently consumed excessive resources

06 exa

Everyone is familiar with the ls command. In the Linux environment, its main function is to list the files and subdirectories contained in the current directory. If there are too many files in the current directory, it is not very good to use the command ls, because this The output result is not consistent with the file you are looking for. First: you need to perform a secondary filter search; second: when there are too many files, the terminal output results are slow;

EXA is a modern replacement for the ls command-line program that comes with Unix and Linux operating systems, giving it more features and better defaults. It uses color to distinguish file types and metadata. It understands symbolic links, extended attributes, and Git. It's small, fast, and has only one binary file.

How is EXA different from LS?

  • The terminal screen is no longer the bottleneck: exa is more powerful and friendlier than ls, and the output will be faster;

  • Color: exa uses color extensively;

  • Does not conflict with the ls command

Features of EXA

  • Colors: 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 a table;

  • Tree View: Displays files and their descendants in a tree;

  • Git integration: view the Git status of files while in the repository;

  • Filter: hide files in the list, show invisible files, and sort the output;

  • Xattrs: List extended attributes of files;

Ubuntu 21.10 installation is just a matter of executing the command: apt install exa.

Show options

  • -1, --oneline: display one entry per line

  • -G, --grid: show entries as grid (default)

  • -l, --long: show extended details and attributes

  • -R, --recurse: recurse into directories

  • -T, --tree: recurse into directories as tree

  • -x, --across: sort the grid, not down

  • -F, --classify: show type indicator by filename

  • --colo[u]r: when to use terminal colors

  • --colo[u]r-scale : clearly highlight the level of file size

  • --icons : show icons

  • --no-icons : don't show icons (always override --icons)

filter options

  • -a, --all: show hidden and "dot" files

  • -d, --list-dirs: list directories like normal files

  • -L, --level=(depth): limit recursion depth

  • -r, --reverse: reverse the sort order

  • -s, --sort=(field): which field to sort by

  • --group-directories-first: List directories before other files

  • -D, --only-dirs: list only directories

  • --git-ignore: ignore files mentioned in .gitignore

  • -I, --ignore-glob=(globs): glob pattern of files to ignore (pipe separated)

Pass the --all option twice to display both the . and .. directories.

07 fd

fd is a program that finds entries in the filesystem. It is a simple, fast, and user-friendly replacement for the find command. The purpose of fd is not to replace all the functionality provided by the find command, but to provide reasonable Default value, useful in some cases.

fd output is colored, similar to some ls modes, it's recursive, and when searching for source code files in directories containing Git repositories, fd automatically excludes hidden files and directories, including ., .git directories, and Ignore patterns in .gitignore files. Generally, searches are faster and provide more relevant results on the first search.

By default, fd performs a case-insensitive pattern search in the current directory, however, if your search pattern contains an uppercase letter, fd will perform it in case-sensitive mode. Of course, the default can also be overridden, but it is still advantageous in many cases. Also doing the same search with find requires you to provide additional command line arguments.

fd is available for many Linux distributions and can be installed in Ubuntu using the standard repositories by executing the following command:

sudo apt install fd-find

In Ubuntu OS, the command is fdfind, to avoid name conflicts with other existing utilities, if you want it to be fd, you can set an alias:

alias fd=fdfind

To make the alias persist across reboots, put it in the “.bashrc”or “.bash_aliases”file.

Using fd without parameter options is similar to ls, except that it also lists files in subdirectories by default.

fd
bat_0.18.3_amd64.deb
fd_8.3.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

To search for all markdown files (.md or .MD) in the current directory, the find command is as follows:

find . -iname "*.md"
./test.md

Do the same search with fd:

fd *.md
test.md

In some cases, fd requires additional options; for example, if you want to include hidden files and directories, you must use the option -H, which is not needed in find, about the use of fd more command-line parameter options method, available on the fd GitHub repository.

08 ag

ack and ag are two text search tools that are much easier to use than the built-in grep.

When searching for text in a specified directory, you don't need to specify various command-line options like grep, and the output will also include file names and line numbers, and the search keywords will be highlighted.

ag is a recursive search for file content faster than grep and ack.

Ubuntu 21.10 install ag and ack

apt-get install silversearcher-ag
apt install ack

ag command common parameters

  • ag -g (filename): similar to find . -name (filename)

  • ag -i sed: search text containing sed regardless of case

  • ag -A sed: Search for text containing sed and display n lines of text after the match

  • ag -B sed: search for text containing sed and display n lines of text before the match

  • ag -C sed: search for text containing sed, and display the matching content and the content of n lines of text before and after it at the same time

  • ag -w sed: full match search, only search for text that exactly matches the searched content

  • ag --java sed: search for text containing sed in java files

  • ag --xml sed: search for text containing sed in XML files

Use of the ag command

To search for the corresponding file according to the file name, you can use the -g parameter option.

ag -g jiaoben
jiaoben2.sh
jiaoben1.sh
jiaoben3.sh

Search the current directory for text about sed keywords.

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

More parameter options, you can use it according to your actual scene.

09 axel

axel is a command-line multi-threaded download tool that can replace curl and wget when downloading files.

Ubuntu 21.10 install axel

apt-get install axel

axel parameter options

  • -n: specifies the number of threads

  • -o: Specifies to save 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

It can be seen that we can also download the ls-lR.gz file to the /tmp directory normally through axel.

10 pydf

Under Linux system, we can use the df command to display disk related information.

# df
文件系统          1K-块     已用    可用 已用% 挂载点
tmpfs            199180     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

Ubuntu 21.10 install pydf

apt install pydf

pydf is arguably a replacement for df that displays disk usage status in a more compact way.

refer to

bat:https://github.com/sharkdp/bat duf:https://github.com/muesli/duf tldr:https://github.com/tldr-pages/tldr htop:https://github.com/htop-dev/htop glances:https://github.com/nicolargo/glances exa:https://github.com/ogham/exa fd:https://github.com/sharkdp/fd/

finally

Although most of us still use the default basic command tool in our daily work, when you replace it with the 10 alternative tools described above, I believe it is still very useful in many scenarios. Of course, there may be more Linux command line alternatives, and you are welcome to add them in the comment area below.

开源前哨Daily sharing of popular, interesting and useful open source projects. Participate in the maintenance of 100,000+ Star open source technology resource libraries, including: Python, Java, C/C++, Go, JS, CSS, Node.js, PHP, .NET, etc.

Guess you like

Origin blog.csdn.net/osfront/article/details/122267802