Linux Tips For Beginners
Linux Tips that you regret not knowing earlier...
Configure Linux password-less login
Add your public key to ~/.ssh/authorized_keys
.
To get a public key, simply execute the ssh-keygen
command, then you'll find your public key and private key in ~/.ssh
The public key is used to encrypt your data, and only the corresponding private key can decrypt that data.
Save printed text
There're two ways to accomplish this.
Use the tee
command
The tee command redirects stdout to a given file as well as print those text to the screen. usage:
ls | tee <path/to/output/file>
The |
symbol is used to redirect the output of the command before it to the command after it.
Use the >
or >>
symbol to redirect output
usage:
ls > out.txt
>
overwrites existing file, while >>
append new content to existing file.
Refresh command every 1 second
Let's say you want to refresh the nvidia-smi
command every second, you can simply type
watch -n 1 nvidia-smi
You can also change 1 to any number to increase or decrease refreshing frequency.
Release network port on Debian
First, install iptables
.
sudo apt install iptables
Let's say you want to release the 8888
port, you can simply type
iptables -I INPUT -p tcp --dport 8888 -j ACCEPT
Then save the rule that you just set.
iptables-save
Now the changes are taking effect. However, it will lost after a reboot, to actually make the changes to be persistent, you have to install iptables-persistent
sudo apt install iptables-persistent
Then save the rules persistently
netfilter-persistent save
netfilter-persistent reload
Now the port is released forever.
Check how much disk space is free
Simply type
df -h
Enable mouse support for vim
Enter :set mouse=a
in vim command mode.
This will expire after the current session is terminated.
To enable that by default, add
set mouse=a
to the ~/.vimrc
file.
评论
发表评论