July 4, 2024

Linux: A Dictionary for Node Enthusiasts

In this article, I have compiled the main commands, utilities, and scripts of Linux that are actively used in the installation and monitoring of nodes. This section will be continuously updated, and I hope it will one day become a true encyclopedia.


Table of Contents


Basic Commands

Content

sudo

The sudo (SuperUser DO) command allows you to perform tasks that require administrator or root privileges. It is mainly used for installing and updating packages, starting services, and viewing logs.

sudo apt-get install git 
# command installs the git package with administrator privileges.

cd

The cd (change directory) command is used for navigating through files and directories. It is used either with the specified path to the desired directory/subdirectory or without a specified path to move to the HOME folder.

Important! The Linux shell is case-sensitive. It is necessary to enter directory names exactly.

cd /usr/bin #navigate to the subdirectory /bin in the /usr directory.

cd #go to HOME catalogue

cp

The cp (copy) command allows you to copy a file from the current directory to another directory.

cp addrbook.json /home/config 
# Creates a copy of addrbook.json from the current directory in the directory /home/config.

mv

The mv (move) command moves a file from the current directory to another directory. The mv command is similar to the cp command, except that it deletes the file in the current directory after moving it. Additionally, the mv command can be used to rename files.

mv addrbook.json /home/config
# moves addrbook.json from the current directory to the directory /home/config.

mv old_name.txt new_name.txt
# renames the file old_name.txt to new_name.txt.  

mkdir

The mkdir (make directory) command creates a new directory.

mkdir Backup
# creates a subdirectory Backup in the current directory

rm

The rm command is used to delete files. To delete directories, you need to use the recursive option -r with the rm command. Additionally, some files and directories cannot be deleted immediately due to read-only file access permissions. They need to be forcefully deleted using the -f option.

Important! Be cautious with this command and always verify which directory you are in. It deletes everything and cannot be undone.

rm addrbook.json
#deleting a file that is not write-protected

rm -f addrbook.json
#deleting a file that is write-protected
rm -r config
#deleting a directory that is not write-protected.

rm -rf config 
#deleting a directory that is write-protected

top

The top command allows you to view a list of running processes along with their CPU usage percentage, memory usage, and other useful parameters. Monitoring system resource usage is very useful. This way, you can determine which process needs to be terminated because it is consuming too many resources.

top

df

The df (disk free) command displays used and free disk space, which is very useful for monitoring "hungry" nodes.

df
#report on the used disk space in kilobytes
df -m
#report on the used disk space in megabytes

grep

grep is a command used for searching by query. It displays lines containing the requested word or phrase.

During node installation and monitoring, the grep command is primarily used to search specific logs for keywords.

sudo journalctl -u evmosd -f |grep block
#command to search for lines containing the word "block" in the logs of the Evmos node

grep peers config.toml
#command to search for lines containing the word "peers" in the file addrbook.json.   

wget

Using the wget command, you can download any file from the internet to your server. To do this, after the command, you need to enter the link to the file you want to download.

wget https://golang.org/dl/go1.17.5.linux-amd64.tar.gz
# command to download GO

tar

The tar command is used for archiving and extracting multiple files. The tar command has many features, but in 99% of cases, it is used to extract downloaded archives.

Extraction is specified with the -x key. The -f key is used to specify the filename. The -z key is used to extract files compressed with gzip (files with the extension *.tar.gz). To visually display the progress of the process, you can add the -v key. These keys can be combined.

By default, the archive is extracted into the current directory. To change the extraction location, use the -C key.

tar -xzf go1.17.5.linux-amd64.tar.gz
#extracting an archive into the current directory 
tar -C /usr/local -xzf go1.17.5.linux-amd64.tar.gz
#extracting an archive into the directory /usr/local

chmod

The chmod (change mode) command is used to change permissions for reading (r), writing (w), and executing (x and s for executing as superuser) files and directories. These permissions can be set for three categories of users: u - the file owner, g - the file's group, o - all other users.

Actions can be indicated with the symbols "+" - to enable or "-" - to disable.

chmod u+x file.sh #allow execution for the owner

chmod +x file.sh #allow execution for everyone

chmod ug+w file.sh #allow write permission for the owner and group

chmod ugo+rwx file.sh #allow all permissions for everyone

echo

The echo command outputs text to stdout (standard output). The >> operator appends stdout to a file. There is also the > operator, which will create a file if it does not exist and output text there or overwrite an existing file.

echo Nick >> nickname.txt
# appends the text "Nick" to the file nickname.txt
echo "export NICKNAME="Nick"" >> ~/.bash_profile
# adds a variable to the system environment

&&

The double ampersand && is a control operator that allows executing multiple commands sequentially.

Important! Monitor the execution of commands. The subsequent command will not execute if the preceding command terminates with an error.

sudo apt update && sudo apt install curl
#update packages and then install the curl package


Useful utilities

Content

curl

nano

apt-get

ufw

ccze


Packages

Content

make

Used for compiling and managing a set of applications and files from source code. This allows developers to use the terminal to install and build various programs. It also manages and reduces the time required for compilation. It is included in the meta-package build-essentials.

The main goal of make is to break down a large program into smaller parts and determine if it needs to be recompiled. It also provides important instructions for their recompilation. The make command is used to execute a makefile, which is a unique file containing shell commands that we write to ensure the project works.

To install the make package, use the command:

sudo apt install make

build-essential

jq

pkg-config

gcc

libssl-dev

cmake

libclang-dev


Programming languages

Content

This section provides commands for installing various programming languages commonly used by developers of crypto projects, necessary for the proper installation and operation of nodes.

GO

The Go language is a compiled statically typed programming language developed by Google.

Installation of Go, version 1.18.4:

wget https://go.dev/dl/go1.18.4.linux-amd64.tar.gz; \
rm -rv /usr/local/go; \
tar -C /usr/local -xzf go1.18.4.linux-amd64.tar.gz && \
rm -v go1.18.4.linux-amd64.tar.gz && \
echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> ~/.bash_profile && \
source ~/.bash_profile && \
go version

RUST

Rust is a multi-paradigm compiled general-purpose programming language that combines functional and procedural programming paradigms with an object system based on traits.

# installing necessary packages
sudo apt install curl build-essential gcc make -y
# downloading the Rust installation script
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Select option 1) to continue installation (default).

# activate the Rust environment for the current shell
source ~/.profile
source ~/.cargo/env
# install nightly
rustup toolchain install nightly
rustup default nightly

Running programs using screen

Content

If you need to run a program in the background, you can use screen. Screen is a utility that allows you to run applications in the background. This utility is useful because you can start any process and disconnect from the SSH session, and the process will continue to run.

Installation of screen:

sudo apt-get install screen 

To create a new session (terminal), you use the -S flag.

screen -S <programm_name> 

To detach and return to the main terminal use the key combination Ctrl+A+D

To attach to an existing session use the -x flag

screen -x <programm_name>

You can view the list of running terminals with the command

screen -ls

To stop and remove a terminal, use the combination Ctrl + D


CryptoCowboy

x.com | Discord