Linux Cheat Sheet
“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 |
Install Conda
Official page: Miniconda.
Replace bash
with zsh
or others if you are using other shells.
1 | mkdir -p ~/miniconda3 |
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 | zip archive.zip filename1 filename2 filename3 |
To tar or untar a file.
1 | tar -cvzf archive.tar.gz filename1 filename2 filename3 |
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…