Skip to content

3badguys/Linux_tips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Some tips for Linux Users.

Software Management

# Install package
sudo apt install <software>

sudo dpkg -i <xxx.deb>
# If there are dependency problems, may run:
sudo apt -f install

Text Editor

Emacs

I like Emacs, and it is the best editor in the world. Configuration: 3badguys’s Emacs configuration

Vim

Vim is just an alternative choice and I don’t really like it.

PDF Viewer

Zathura

Zathura is a highly customizable and functional document viewer with vi-styled keybindings. It provides a minimalistic and space saving interface as well as an easy usage that mainly focuses on keyboard interaction. Different file formats are supported through plugins. Support is available for PDF, PS, DjVu and CB files.

Installation

sudo apt install zathura zathura-djvu zathura-ps zathura-cb

Key Binding(Default)

ShortcutDescription
TabShow index and switch to index mode
:Enter command
EscapeAbort
qQuit
dToggle dual page view
/, ?Search for text
n, NSearch for the next or previous result
o, OOpen ducument
ggGo to the first
GGo to the last
nGGo to the nth page
h, LeftScroll to the left
k, DownScroll to the down
j, UpScroll to the up
l, RightScroll to the right
C-fScroll page down
C-bScroll page up
C-dScroll half a page down
C-uScroll half a page up
rRotate the page
RReload the document
C-rRecolor(grayscale and invert colors)
aAdjust window in best-fit mode
sAdjust window in width mode
+Zoom in
-Zoom out
=Zoom to original size
C-mToggle inputbar
C-nToggle statusbar
fFollow links
FDisplay link target

Configuration

emacs ~/.config/zathura/zathurarc

set incremental-search true
set show-v-scrollbar true
set selection-clipboard clipboard

Keyborad

Test

showkey -a
sudo showkey -k

Recommendation

  • Kinesis Advantage2 BROWN
  • X-Bows Nature RED
  • Cherry G80-3000/3494 RED
  • DasKeyborad Model S GREEN

xmodmap

xmodmap is a utility for modifying keymaps and pointer button mappings in Xorg.

# When you restart, the .Xmodmap will run automatically.
xmodmap ~/.Xmodmap

.Xmodmap

Code Lines Count

### Install cloc
git clone https://github.com/3badguys/cloc.git
cd cloc
sudo ln -s `pwd`/cloc /usr/local/bin/cloc  # `pwd` get the current path

### Use cloc
cd <code_path>
cloc .

Terminal

PS1

export PS1="\[\033[01;36m\][\u\[\033[01;35m\]@\[\033[01;36m\]\h \[\033[01;34m\]\w \[\033[01;37m\]\$?\[\033[01;36m\] ]\$\[\033[00m\] "

dircolors

Run ls on a folder with directories that have a 777 permission, then these directories’s color is unreadable.

dircolors -p > ~/.dircolors
# change .dircolors's OTHER_WRITABLE option from 34;42 to 30;42
eval $(dircolors ~/.dircolors)

rxvt-unicode(urxvt)

URxvt is a customizable terminal emulator forked from rxvt. Features of rxvt-unicode include international language support through Unicode, transparency, the ability to display multiple font types and support for Perl extensions. URxvt is one of the most popular terminal emulator in UNIX world, especially on Unixporn. It’s well known for being lightweight and riceable. But just like any other software in UNIX world, it’s ugly out of the box. So, we should configure it before we use it. URxvt configurations is commonly placed in ~/.Xresources file.

Installation

sudo apt install rxvt-unicode
xrdb ~/.Xresources # make the configuration work

Configuration

.Xresources

lilyterm

LilyTerm is a terminal emulator based off of libvte that aims to be fast and lightweight, Licensed under GPLv3.

Installation

sudo apt install libvte-dev

git clone https://github.com/Tetralet/LilyTerm.git
cd LilyTerm
./configure
make
sudo make install

Configuration

default.conf

tmux

tmux is a terminal multiplexer for Unix-like operating systems. It allows multiple terminal sessions to be accessed simultaneously in a single window. It is useful for running more than one command-line program at the same time. It can also be used to detach processes from their controlling terminals, allowing SSH sessions to remain active without being visible.

Installation

sudo apt install tmux

# cygwin copy to system clipborad
# use tmux-yank plugin
git clone https://github.com/tmux-plugins/tmux-yank
# cygutils contain getclip/putclip
apt-cyg install cygutils-extra

Configuration

.tmux.conf

CheatSheet

tmux_cheat_sheet

mintty

If you use git-bash or cygwin in windows system, you may consider to config your mintty terminal through .minttyrc:

#
# dotfiles/.minttyrc - Configuration file for mintty terminal
#

BoldAsFont=no
Font=Consolas
FontHeight=11
Rows=45
Term=xterm-256color

ForegroundColour=131,148,150
BackgroundColour=0,43,54
CursorColour=220,50,47

Black=7,54,66
BoldBlack=0,43,54
Red=220,50,47
BoldRed=203,75,22
Green=133,153,0
BoldGreen=88,110,117
Yellow=181,137,0
BoldYellow=101,123,131
Blue=38,139,210
BoldBlue=131,148,150
Magenta=211,54,130
BoldMagenta=108,113,196
Cyan=42,161,152
BoldCyan=147,161,161
White=238,232,213
BoldWhite=253,246,227

Scrollbar=none

CursorType=block
CursorBlinks=no

Change host-name

Modify the following config files:

  • /etc/hostname
  • /etc/hosts

Git

Installation

sudo apt install git
git --version

Generate SSH Public Key

ssh-keygen -o
cat ~/.ssh/id_rsa.pub

Completion

The function of completion just like git bash.

git clone https://github.com/git/git.git
cp git/contrib/completion/git-completion.bash ~/.git-completion.bash
# Add the next line to ~/.bashrc
source ~/.git-completion.bash

Frequently-used command

# create a git repository in current dir
git init
# clone a project
git clone <repo-url>

# work with git repo without cd into the dir
git --git-dir=<project-dir>/.git/ status

# show current status
git status

git log
# show last 3 commits
git log -3
# show diff of last changes
git log -p -3

# show what revision and author last modified each line of a file
git blame <file-name>

# Summarize git log output
git shortlog -sn

# diff working dir vs staging area
git diff
git diff --stat
# diff staging area vs the specific commit
git diff --staged <commit-id>
# diff working dir vs the specific commit
git diff <commit-id>

# show all local branches
git branch
# show all remote branches
git branch -r
# show all local and remote branches
git branch -a
# show branches and their commits
git show-branch
# create a branch
git branch <new-branch> <from-branch>
# switch to the specific branch
git checkout <branch-name>
# rename the specific branch
git branch -m <old_branch> <new-branch>
# rename the specific branch, even if there already exists new branch
git branch -M <old_branch> <new-branch>
# delete the specific local branch(the branch must be merged first)
git branch -d <branch-name>
# delete the specific local branch
git branch -D <branch-name>
# delete the specific remote branch
git push origin --delete <branch-name>

# upstream repository
git remote -v
git remote add origin <remote-url>

# merge upstream to local
git remote add upstream <upstream-url>
git fetch upstream
git merge upstream/master

# config file is ~/.gitconfig
git config --list
git config --global user.name <user-name>
git config --global user.email <user-email>
git config --global core.editor emacs
# avoid to input username and password
git config --global credential.helper store
# run git command in eshell, to avoid `WARNING: terminal is not fully functional`
git config --global core.pager '`test "$TERM" = "dumb" && echo cat || echo less`'
# make git always use color in diff
git config --global color.ui true
# ignore file mode
git config core.filemode false

# revert file
git checkout -- <file-name>
# revert file to the specific commit
git checkout <commit-id> -- file_name
# reset to the specific commit, but keep your changes
git reset <commit-id> --soft
# reset to the specific commit
git reset <commit-id> --hard

# show the commit id the current HEAD points to
cd <project-dir>; cat .git/HEAD # sample output: ref: refs/heads/master
cat .git/refs/heads/master

# create a branch a switch to it
git checkout -b <local-branch> <remote-branch>

# including new or deleted file/dir
git add -A .
# commit a change
git add .
git commit -m "commit-massage"
git push origin <remote-branch>

# remove file in remote, but keep in local
git rm --cached <file-name>
# remove directory in remote, but keep in local
git rm -r --cached <directory>

# update last commit change
git commit --amend
git commit --amend --author="Author Name <email@address.com>"
git push orgin <remote-branch>

git rebase -i HEAD~2
git push -f origin <remote-branch>

git checkout <master_branch>
git pull
git checkout <develop_branch>
git rebase <master_branch>
git push -f origin <develop_branch>

# handle conflicts
# method 1. by cherry-pick
git checkout <master_branch>
git branch -D <develop_branch> # record develop_branch's newest commit-id as <new_commit_id>
git pull
git checkout -b <develop_branch>
git cherry-pick <new_commit_id>
# after handle conflicts, continue to cherry-pick
git cherry-pick --continue
git push -f origin <develop_branch>
# method 2. by rebase
git checkout <master_branch>
git pull
git checkout <develop_branch>
git rebase <master_branch>
# after handle confilcts, continue to rebase
git rebase --continue
git push -f origin <develop_branch>

# delete a remote branch
git push origin --delete <remote-branch>
# Alternative: push a empty local branch to remote
git push origin :<remote-branch>

# save a stash
git stash save
git stash save "stash_message"
# list stash
git stash list
# show the last stash
git stash show
# show the specific stash
git stash show stash@{index}
# apply the last stash
git stash apply
# apply the specific stash
git stash apply stash@{index}
# drop the last stash
git stash drop
# drop the special stash
git stash drop stash@{index}
# apply the last stash and drop it
git stash pop
# apply the specific stash and drop it
git stash pop stash@{index}
# clear all stash
git stash clear

git submodule

Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.

# Add a submodule, .gitmodules will be changed
git submodule add {remote_url} {local_path}

# After clone a project contain submodules
git submodule init
git submodule update
# Alternative
git submodule update --init --recursive

# fetch and update submodules
git submodule update --remote

# Delete a submodule
rm -rf {local_path}
emacs .gitmodules
emacs .git/config
rm -rf .git/modules/{local_path}

Universal Ctags

Universal Ctags (abbreviated as u-ctags) is a maintained implementation of ctags. ctags generates an index (or tag) file of language objects found in source files for programming languages. This index makes it easy for text editors and other tools to locate the indexed items.

Installation

git clone https://github.com/universal-ctags/ctags.git
cd ctags
./autogen.sh
./configure --prefix=/where/you/want # defaults to /usr/local
make
sudo make install

Latex Environment

texmaker

# Install texlive and texmaker
sudo apt install texlive-full
sudo apt install texmaker

# Copy fonts from windows system
sudo mkdir /usr/share/fonts/opentype/windows_font
sudo cp -R /media/<win_user>/win7/Windows/Fonts/* /usr/share/fonts/opentype/windows_font/
sudo fc-cache -f -v

Shell Command

date, time and time-zone

date
date -R

# Asia -> China -> Beijing Time
tzselect
# Add to '.bashrc' or '.profile' in your home directory
TZ='Asia/Shanghai'; export TZ
# To make this change permanent
source ~/.bashrc

timedatectl status
timedatectl list-timezones
timedatectl set-timezone {ZONE e.g. Asia/Shanghai}

sshpass

Noninteractive ssh password provider.

Installation

sudo apt install sshpass

Usage

# Copy remote server's file to local
sshpass -p {password} scp {remote_user}@{remote_IP}:{remote_FILE} {local_DIR}

# Copy local file to remote server
sshpass -p {password} scp {local_FILE} {remote_user}@{remote_IP}:{remote_DIR}

# Run command in remote server
sshpass -p {password} ssh {remote_user}@{remote_IP}
# Disable strict host key checking
sshpass -p {password} ssh -o StrictHostKeyChecking=no {remote_user}@{remote_IP}

# Example
for i in $(seq 168 269); do sshpass -p {password} scp root@{remote_IP}:/root/code_proj/GTM/GTM$i* ./; done

FIGlet

FIGlet is a program for making large letters out of ordinary text.

Installation

sudo apt install figlet

Usage

figlet "FIGlet"
# Output:
#  ___ ___ ___ _     _
# | __|_ _/ __| |___| |_
# | _| | | (_ | / -_)  _|
# |_| |___\___|_\___|\__|

ip commands

ip command is somewhat similar to ifconfig command but it’s much more powerful with much more functionalities attached to it.

# view network statistics
ip -s link

# show information of network interface
ip addr show {iface_name}
ip a s {iface_name}

# enable & disable network interface
ip link set {iface_name} up
ip link set {iface_name} down

# assign IP address to network interface
ip addr add {ip_addr}/{netmask} dev {iface_name}

# remove IP address from network interface
ip addr del {ip_addr}/{netmask_len} dev {iface_name}
ip addr flush dev {iface_name}

# check network routing information
ip route show
ip route get {ip_addr}

# view entries in ARP cache
ip neigh

# delete ARP entry
ip neigh del {ip_addr} dev {iface_name}

# help
ip help

dd

On Unix-like operating systems, the dd command copies a file, converting the format of the data in the process.

# Example:
dd bs=4M if=xxx.img of=/dev/sdx status=progress

proxychains

ProxyChains is a UNIX program, that hooks network-related libc functions in DYNAMICALLY LINKED programs via a preloaded DLL (dlsym(), LD_PRELOAD) and redirects the connections through SOCKS4a/5 or HTTP proxies. It supports TCP only (no UDP/ICMP etc).

git clone https://github.com/rofl0r/proxychains-ng.git
cd proxychains-ng
./configure && make && sudo make install && sudo make install-config

# change config of proxychains.conf, e.g. socks5 127.0.0.1 1080
sudo emacs /usr/local/etc/proxychains.conf

# Usage
proxychains4 <command, e.g. git clone ???>

WSL2

Portproxy in windows

# if proxyport is in used, try to find the PID and kill it
netstat -ano | findstr 0.0.0.0:667

netsh interface portproxy add v4tov4 listenport=667 listenaddress=0.0.0.0 connectport=667 connectaddress=127.0.0.1

Allow WSL access windows

New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

Update proxychains config

WSL_VERSION=$(uname -r | grep WSL2 > /dev/null && echo "WSL2" || echo "WSL1")
if [ "$WSL_VERSION" == 'WSL2' ]; then
    WINDOWS_IP=$(grep nameserver /etc/resolv.conf | awk '{print $2}' | head -1)
else
    WINDOWS_IP="127.0.0.1"
fi
WINDOWS_PROXY_PORT=667
function update_proxychains_conf() {
    sed -i '/\[ProxyList\]/,$d' ~/.config/proxychains4/proxychains.conf
    echo "[ProxyList]" | tee -a ~/.config/proxychains4/proxychains.conf > /dev/null
    echo "socks5 ${WINDOWS_IP} ${WINDOWS_PROXY_PORT}" | tee -a ~/.config/proxychains4/proxychains.conf > /dev/null
}
update_proxychains_conf
alias proxychains4='proxychains4 -f ~/.config/proxychains4/proxychains.conf'

About

Some tips for linux.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages