“I like to do all the talking myself. It saves time, and prevents arguments.”

— Oscar Wilde

Prologue

This is a collection of useful Linux commands that, you don’t need them often, but will go search for every time. So, just as a memo to save the time. 😏

This article will be updated from time to time as I use and explore Linux.

You may also like: Docker Cheat Sheet
You may also like: Git Cheat Sheet


User Related

Change password

1
passwd

Create sudo-enabled user

See Create sudo-Enabled User on Linux.


Quick Installation

Install Java

1
apt install openjdk-17-jdk openjdk-17-jre

Switch Java version

1
sudo update-alternatives --config java

Conda Installation & Usage

Official page: Miniconda.

Replace bash with zsh or others if you are using other shells.

1
2
3
4
5
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
~/miniconda3/bin/conda init bash

Basic usage. -n is short for --name. Replace myenv with your environment name.

1
2
3
4
5
conda env list  # List all environments
conda create -n myenv python=3.8 # Create an environment
conda activate myenv # Activate an environment
conda deactivate # Deactivate the current environment
conda remove -n myenv --all # Remove an environment

Utilities

Count all files under current directory

1
ls -1 | wc -l

Count all files with certain extension

1
find . -type f -name "*.ext" | wc -l

Count total line numbers of all files

1
find . -type f -name "*.ext" -print0 | xargs -0 wc -l

Show file size

1
ls -lh

Create Link

Symbolic link

1
ln -s /path/to/file /path/to/link

Hard link

1
ln /path/to/file /path/to/link

Zip/Unzip

I like Zip.

1
2
3
4
zip archive.zip filename1 filename2 filename3
zip -r archive.zip directory_name1 directory_name2 file1 file1

unzip archive.zip -d /path/to/directory

To tar or untar a file.

1
2
3
4
5
6
tar -cvzf archive.tar.gz filename1 filename2 filename3
tar -cvzf archive.tar.gz directory_name1 directory_name2 file1 file1

tar -xvf foo.tar
tar -xvzf foo.tar.gz
tar -xvjf foo.tar.bz2

Remote Connection

Perhaps this is for Windows.

Connect via SSH

1
ssh user@host

Some times the server may prompt password every time. In this case, you can send your public key to the server. First, generate key pair using ssh-keygen. This command exists on both Windows and Linux. It will generate id_rsa and id_rsa.pub under .ssh. The filename may vary.

1
ssh-keygen

Then, for Linux, you can do this using ssh-copy-id.

1
ssh-copy-id id_rsa.pub user@host

For Windows, there’s a equivalent command composition.

1
type id_rsa.pub | ssh user@host "cat >> .ssh/authorized_keys"

Epilogue

To be continued…