Linux configurations
Tuyen D. Le August 31, 2023 [Server] #LinuxBasic setup
Changing colors for user, host, directory information in terminal
# https://askubuntu.com/a/123306/613914
#force_color_prompt=yes >> force_color_prompt=yes
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u\[\033[01;30m\]@\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
For loop
for; do
done
Ping show timeout
# [1566958425.967709] 64 bytes from 2404::8b: icmp_seq=23 ttl=49 time=84.6 ms
# [1566958427.820728] no answer yet for icmp_seq=24
# [1566958427.993347] 64 bytes from 2404::8b: icmp_seq=25 ttl=49 time=81.9 ms
Danish characters input
Answered from stackOverflow If you map CapsLock to the Compose key (you can do it through Settings → Keyboard → Layouts → Options, look for "Position of Compose key"), they will be accessible through Composeaa (å), Composeae (æ), and Composeo/ (ø). Note those are three keypresses in a sequence, not a combination to press at once. Use uppercase letters to get the uppercase variant.
Show all process
|
# Long line output, no wrap
|
Install Open SSH
Disable auto sleep 16.04
Good calculator
Change Timezone time/date
# List timezone
|
# Change time/date setting to USA
Find, grep, search
# >> find
# Find file have changed in 10 minute
# Smaller than 4G
# c for bytes
# w for two-byte words
# k for Kilobytes
# M for Megabytes
# G for Gigabytes
# Ignore case sensitive
# >> ag
# >> grep
# Use grep --exclude/--include syntax to not grep through certain files
# -r, --recursive
# -n, --line-number
# extract the text between, let's say, bbb and ddd.
View CSV Data from the Command Line
| | |
Redirect output to file
How do I save terminal output to a file?
|| visible in terminal || visible in file || existing
Syntax || StdOut | StdErr || StdOut | StdErr || file
==========++==========+==========++==========+==========++===========
> || no | yes || yes | no || overwrite
>> || no | yes || yes | no || append
|| | || | ||
2> || yes | no || no | yes || overwrite
2>> || yes | no || no | yes || append
|| | || | ||
&> || no | no || yes | yes || overwrite
&>> || no | no || yes | yes || append
|| | || | ||
| tee || yes | yes || yes | no || overwrite
| tee -a || yes | yes || yes | no || append
|| | || | ||
n.e. (*) || yes | yes || no | yes || overwrite
n.e. (*) || yes | yes || no | yes || append
|| | || | ||
|& tee || yes | yes || yes | yes || overwrite
|& tee -a || yes | yes || yes | yes || append
E.g:
command > output.txt
command &> output.txt &
What do the fields in ls -al output mean
-rwxrw-r-- 10 root root 2048 Jan 13 07:11 afile.exe
?UUUGGGOOOS 00 UUUUUU GGGGGG #### ^-- date stamp and file name are obvious ;-)
^ ^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | | \--- File Size
| | | | | | | \-------- Group Name (for example, Users, Administrators, etc)
| | | | | | \--------------- Owner Acct
| | | | | \---------------------- Link count (what constitutes a "link" here varies)
| | | | \--------------------------- Alternative Access (blank means none defined, anything else varies)
| \--\--\----------------------------- Read, Write and Special access modes for [U]ser, [G]roup, and [O]thers (everyone else)
\------------------------------------- File type flag
User, group
# Adding/Remove a user to a group:
# list all users with their UID
# Add user with specific user ID
# Add user without user ID
# Create default home directory for existing user in terminal
Vim
if
if )
else
Grub
# Start from 0
GRUB_DEFAULT=3
GRUB_TIMEOUT=3
nginx
Enable IP forwarding between interfaces
# Enable IP Forwarding on the fly
#---------------------------------------
# OR
# Permanent setting using /etc/sysctl.conf
#---------------------------------------
KVM
- Install
- Enable remote desktop via SSH
# Window > Install Xming from: http://sourceforge.net/projects/xming.
# Enable Remote/X11 forwarding
# SecureCRT: Session Option > Port Forwarding > Remote/X11
# Checked Forwarded X11 Packet and Enfore X11 Authen
- List all KVM
- Clone a machine
- Correct way to move kvm vm
# copy the VM's disks to the same dir on dest host
# copy this xml to the dest host
# copy xml file and import configuration on the dest host
# If the disk location differs, you need to edit the xml's devices/disk node
# to point to the image on the destination host
# If the VM is attached to custom defined networks,
# you'll need to either edit them out of the xml on the destination host
# or redefine them as well
-
Share network on kvm
-
br0
work as a swith -
eno1
is only physical port -
any machine which use
br0
network will seeeno1
+---------+ +---------+
| VM1 | | VM2 |
| | | |
| | | |
+----+----+ +---+-----+
| |
+----------------------------------------+
| | | |
| | | Host machine|
| | | |
| +--+-------------+----------+ |
| |br0 (switch) | |
| +---------------------------+ |
| |---| |
+----------------------------------------+
|
|eno1
|
+
# >> On boot
# >> Manually
# https://help.ubuntu.com/community/NetworkConnectionBridge
# enx00e04c68014a Link encap:Ethernet HWaddr 00:e0:4c:ff:ff:ff
# inet addr:192.168.0.17 Bcast:192.168.0.255 Mask:255.255.255.0
# inet6 addr: fe80::e782:ffff:ffff:ffff/64 Scope:Link
Fast copy, copy certain file extension, file size, capacity
| |
| | (; )
Java, JRE, JDK
&& &&
Remove PPA (Linux repo list)
Alternately, as ppas are stored in /etc/apt/sources.list.d you can find the one you want to remove by entering:
Then when you have noted the name of that offending ppa (e.g. myppa.list), you can enter:
# For example:
inkscape
screen GNU
# >> sending text input to a detached screen
# https://unix.stackexchange.com/a/13961/265821
# /scripts/sync_code.sh
Rename
# Rename all *.txt to *.text
for; do
done
# Rename old string to new string
for; do ; done
curl
# https://www.keycdn.com/support/popular-curl-examples
# 5) Generating Additional Information
tcpdump
# • unreachable: 1
# • too-big: 2
# • time-exceeded: 3
# • echo-request: 128
# • echo-reply: 129
# • router-solicitation: 133
# • router-advertisement: 134
# • neighbor-solicitation: 135
# • neighbor-advertisement: 136
# filter vlan 100
## Show full packet
coredump
# >> The core dump is written in the current directory of the process
# >> at the time of the crash.
# to enable core dumps
# where $pid is the process ID of the process.
# That link will point to the current working directory of that process.
python
# find python package command installed by pip
regx
# Find string between two string
# https://regexr.com/397dr
# href="/uploads/file/PDF Week 1 Day 1a.pdf" align
=
Resize image keep ratio
# https://askubuntu.com/a/135489
# 1654x is width pixel
# need to install
# you can maintain the filename by using -set option. Ex:
Crop, cut image to one center part
# https://stackoverflow.com/a/41403898
image to pdf
# Need to install
# Reduce quality if the output file is too big
# Keep same image size
# https://unix.stackexchange.com/a/74976
# convert images to pdf: How to make PDF Pages same size
# https://unix.stackexchange.com/a/20057
i=150;
# Fix error: convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
<policy domain="coder" rights="read | write" pattern="PDF" </policymap>
Remove pdf secure (password)
https://superuser.com/a/584710
Assuming it's simply a 'rights' (owner) password that restricts things like editing, printing, and copying (i.e. the password does not need to be entered to open the file) the following will remove the restrictions:
- Grab https://github.com/qpdf/qpdf/releases
- Unzip/Install and navigate to the bin folder that holds qpdf.exe (or similar for your platform)
- Place the PDF you wish to work on in the same folder
- Run:
qpdf --decrypt InputFile.pdf OutputFile.pdf
(use "s if the file name has spaces). - Do what you like with the OutputFile.
If your PDF file is user password protected, change step 4 to qpdf --decrypt --password=yourpassword InputFile OutputFile
Shrinkpdf: shrink PDF files with Ghostscript (reduce pdf size)
How can I reduce the file size of a scanned PDF file?
Method 1:
# 150 dpi
# 120 dpi
Method 2:
How to resize page to fit drawing contents in Open office/Libre Office Draw
- Press
Ctrl-A
to select everything. - Under
Format>Position and Size
you can see the exact size of the selection. It's helpful to copy the value of Width and Height to an editor (or a piece of paper). Click Cancel. - Open
Format>Page
: Set Width and Height according to the size of the selection. Set all Margins to zero. Click OK. - Open
Format>Position and Size
again: Set both Position X an Position Y to zero. - Click OK.
Edit pdf on Linux
> Open > PDF
)
extract-img-from-pdf
# https://stackoverflow.com/a/47877930
# need to install library
# pip3 install --upgrade pip
# pip3 install PyMuPDF
# python3 extract-img-from-pdf.py
=
=
=
# this is GRAY or RGB
# CMYK: convert to RGB first
=
= None
= None
Merge / convert multiple PDF files into one PDF
# https://stackoverflow.com/a/19358402
# size(output) = size(file1) + size(file2)
Remove pdf title, file metadate
# https://askubuntu.com/a/391142
Split one pdf page into two pages
E.g.
# https://askubuntu.com/a/698307
Make a sound once process is complete
;
NPM
# https://github.com/nodesource/distributions
# install Node.js v10.x:
# Using Ubuntu
|
# Using Debian, as root
|
#clean slate install.
Find USB version is using on some port
How to download all dependencies and packages to directory
# Khong phu thuoc vao viec package da duoc cai tren he thong hay chua
# aptitude va synaptic thi phu thuoc vao package he thong nen se cho et qua khong dung
Find package Ubuntu and Othes Linux Distribute
Script to ignore unknow package
# Source: https://superuser.com/questions/1112525/ignore-apt-get-download-errors/1137335#1137335
#
# Run: ./getdepends.sh [package name]
#!/bin/bash
export MAXPARAMETERS=255
function array_contains_find_index() {
local n=$#
local i=0
local value=${!n}
for (( i=1; i < n; i++ )) {
if [ "${!i}" == "${value}" ]; then
echo "REMOVING $i: ${!i} = ${value}"
return $i
fi
}
return $MAXPARAMETERS
}
LIST=( $( apt-rdepends $1 | grep -v "^ " ) )
echo ${LIST[*]}
read -n1 -r -p "... Packages that will be downloaded (Continue or CTRL+C) ..."
RESULTS=( $( apt-get download ${LIST[*]} |& cut -d' ' -f 8 ) )
LISTLEN=${#LIST[@]}
while [ ${#RESULTS[@]} -gt 0 ]; do
for (( i=0; i < $LISTLEN; i++ )); do
array_contains_find_index ${RESULTS[@]} ${LIST[$i]}
ret=$?
if (( $ret != $MAXPARAMETERS )); then
unset LIST[$i]
fi
done
FULLRESULTS=$( apt-get download ${LIST[*]} 2>&1 )
RESULTS=( $( echo $FULLRESULTS |& cut -d' ' -f 11 | sed -r "s/'(.*?):(.*$)/\1/g" ) )
done
apt-get download ${LIST[*]}