Info
Place to archive and snapshot the incredible command or pipe command with Linux OS platform such as Debian, Ubuntu, CentOS, β¦
In-house Commands
echo
command
Decode string with specify unicode-escaped with -e
flag, read more at: StackOverFlow - How to convert \uXXXX unicode to UTF-8 using console tools in *nix
Note
You can use
uni2ascii
for instead if you want to integrate with 3rd party
journalctl
command
Documentation: How To Use Journalctl to View and Manipulate Systemd Logs
Capture and logged full events of service
To see only log messages for the current boot
Find your boots in list
See the error log with command
Info
You can exchange -p option with pram
- 0: emerg
- 1: alert
- 2: crit
- 3: err
- 4: warning
- 5: notice
- 6: info
- 7: debug
grep
command
Use grep with exclude by -v
flag
To grep include multiple word
Info
Use
-i
flag to execute that. Especially add with\|
symbol between two words. Read more at: How to Grep for Multiple Strings, Patterns or Words, extending with multiple situations (HELPFUL)
awk
command
Skip first line Usually header when you use awk
to print column variables
Get the last param when seperate by /
or any symbol, you can use F
and $NF
to get the result
tree
command
Print the sub-directory of folder with configuration level
Print the sub file and folder with filter not include smt with -I
option. Explore at StackOverFlow - tree command for multiple includes and excludes
Print tree with combine full path, include and exclude pattern
find
command
Find the folder with find base on the regex format
Find directory in current location but expose that in format ls
Find the file or directory to provide you last in path of file and directory
iptables
command
Learn more about iptables
commands from links down below
- Github - iptables cheatsheet
- Prompt generate Iptables
- Hacktricks - Suricata & Iptables cheatsheet
- How to list all iptables rules with line numbers on Linux
- How can I remove specific rules from iptables?
Allow only traffic from external IP to host via port
Block all traffic to specify port in host
List all rule and table rule
Delete rule in iptables
tr
command
Use tr
to delete with -d
flag
Use tr
to change space to colon,
β :
ssh
command
Use tunneling mode of ssh
to reverse shell from remote to your local host
Info
Command below to port-forward from port
127.0.0.1:8080
from remote host and send the traffic to port:8080
inside your host
jq
command
List of articles relate jq
with helpful solution
You can use jq
to select multiple variable
You can use jq
to select multiple variable and concat that to one string
You can use jq
with variable to pass through from command or define to your jq
jq
support for another arg like json
, you can try to concat object this one with your existence object. Explore more at Add an object to existing JSON using jq and Append JSON Objects using jq
Convert json to string for multiple purpose
Get first keys in list object with jq
Select the keys if value of a field is βautoβ. Explore at Select the keys if value of a field is βautoβ
du
command
You can use du
command for list all size inside your directory
lsblk
command
If you want to take the look with your storage device like HDD or SSD, you can use lsblk
to see what format of those devices
File System | Supported File Size | Compatibility | Ideal Usage |
FAT32 | up to 4 GB | Windows, Mac, Linux | For maximum compatibility |
NTFS | 16 EiB β 1 KB | Windows, Mac (read-only), most Linux distributions | For internal drives and Windows system file |
Ext4 | 16 GiB β 16 TiB | Windows, Mac, Linux (requires extra drivers to access) | For files larger than 4 GB |
mkfs
command
You can use mkfs
command to formatting your device. Read more at How to Use the mkfs Command on Linux
fdisk
command
Documentation: What is FDISK and how does it work?
Use fdisk
when you want to hangout with your hard dkkkkkkkkkkkkkisk drive, like integrate multiple way for formatting or partitioning aΒ hard disk drive, or to delete different portions of it. FDISK is an external utility. It is most commonly used to prepare andΒ partitionΒ a hard drive
And when you want to hit to interaction mode you can try with
And when you hit keyboard with m
, you can see the helper
scp
command
Documentation: SCP Command in Linux {13 Examples}
scp
is protocol which permit use copy and transfer file from remote and local machine with bi-direction, or cp from remote to remote
In some special case, you can integrate with option with your scp command to specific
Different Port: Usually scp
use SSH (Port 22) to mediate help you secure transfer data through that port, but in other situation SSH not work in Port 22, you can use -p
to specific
Recursive: To copy whole folder, usually we use recursive mode and scp
does have with -r
sed
command
Documentation: Sed cheatsheet and How to Use Sed to Find and Replace a String in a File
To replace a string in file with sed
, you can use command with format
To replace in the string, you can control action with
Cheatsheet
Re run the previous command
You can use previous command with !!
on your shell, for example
Also you can reuse the previous command arguments, for example
Use environment variables from .env
file
Info
Read more about topic in
Stackoverflow
: Set environment variables from file of key/value pairs
Use export with except #
line in .env
file
When you want to work with script, you can use -o allexport
Update Ubuntu new version
You can use integration tool inside ubuntu
to update new version, that will pull and update packages inside host, do that easily with command
Warning
In this situation you update
ubuntu
, it will update your kernel so please remember make a big-changes can gain different harden to control, so do know before you doing
Follow some methodology to upgrade new version of kernel, such as
- How to Update Linux Kernel In Ubuntu
- CαΊp nhαΊt Linux Kernel trΓͺn Ubuntu 20.04 (Vietnamese)
- How to Update/Upgrade Linux Kernel in Ubuntu
- Ubuntu Linux Upgrade Linux Kernel Command
Depend on those articles, you can update kernel
of Ubuntu via
- Update OS version (e.g. 20.04 β 22.04)
- Update package of OS dependencies
- Manually Update
When you choose manually update, you can use some following tools
- Mainline
- ubuntu-mainline-kernel.sh
- Directly download use
curl
orwget
and installing from pkgs.org
If you see this one from via kubewekend
series, I prefer to use update Ubuntu version or use secondly optional via apt
like
Update alternative version
Quote
When you have multiple version of tools, package or moreover, like
python
java jdk
shell
, you need to switch between of them that why you need the topic
For change and update the configuration between different of tools, debian
core offer us the command call update-alternatives
. Let digest to its
You can find the manual of the command with --help
flag
When you want to take a look how the version we have, such as java
you can call with --list
flag and name, example
And when you have decision, on my situation java
on my machine on 11
but I want to switch to 18
, you can perform this command
Relate documentation
- Switch between multiple java versions
- What exactly does
update-alternatives
do? - The update-alternatives Command in Linux
Comment note in Shell Bash
Info
2 ways for writing the comment to shell bash.
Example and troubleshooting via Link to details
Using the #
character for comment
Info
In Bash, a comment starts with the hash symbol (#). Anything after # on that line is considered a comment and is ignored by the Bash interpreter
Using the doctype Here Document
for comment multiple line
Info
Bash doesnβt have a specific syntax for multi-line comments like some other languages, but you can use a trick with the : command and a βhere documentβ to achieve the same effect.
Reconfiguration for curl template output
Note
Reference: Timing Page Responses With Curl
Templates format to output via curl
command
To reference the documentation for the time based variables is as follows.
- time_appconnectΒ - The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed.
- time_connectΒ - The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
- time_namelookupΒ - The time, in seconds, it took from the start until the name resolving was completed.
- time_pretransferΒ - The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.
- time_redirectΒ - The time, in seconds, it took for all redirection steps including name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections.
- time_starttransferΒ - The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.
- time_totalΒ -Β Β The total time, in seconds, that the full operation lasted.
How to use
Find the PATH which including the curl-formatter.txt
file with cd
or pwd
, Use this with curl
command
Redirect Output and Error
Note
Reference βΆοΈ βΆοΈ βΆοΈ How to Redirect Output and Error to /dev/null in Linux
Some thing about the output of linux
- In the linux machine,
/dev/null
that will location where you can return null for your shell likecommand 2>&1 /dev/null
- There will have 3 three type of output which linux has
- Standard input (stdin) is designated with 0
- Standard output (stdout) is designated with 1
- Standard error (stderr) is designated with 2
Redirect output to /dev/null in Linux
For example: You run apt install curl
but you want your shell not return anything you can redirect output
into /dev/null
. It will be like
Usage: Used it when you donβt want stdout
go to your shell, just removing the odd things and keep the important output
Redirect error to /dev/null in Linux
For example: You run find /
but you run with non root, so somecase you will have some permission error output to your shell. You can use /dev/null
for removing this messing stuff
Combine stdout
and stderror
into one with this character &
Sometime you can use version
2
of combiningTheΒ
2>&1
Β part means βredirect the error stream into the output streamβ, so when you redirect the output stream, error stream gets redirected as well. Even if your program writes toΒstderr
Β now, that output would be discarded as well. (Sergey Kalinichenko)
Find this problem βΆοΈ βΆοΈ What is /dev/null 2>&1?
User Management in Linux
Info
With User and Group configuration in Linux become potential to managing, and enhance your security, user connection and moreover. Following some situation to keep some command that be useful for us when manipulate this stuff inside Linux
Some articles can be good for us when practicing with those stuff around
- Ubuntu Doc - User management
- User Management in Linux
- How to Manage Users in Linux
- Introduction to usermod command
Change Password
If you want to change password of current user, you can use command
Add and Delete user
In this situation, you have multiple command to handle it, such as adduser
, useradd
, deluser
and userdel
. With the graduation introduce by Ubuntu Doc, I will choose adduser
and deluser
to handle this case
Add and Delete user out of group
There is many way to handle this work, but I prefer to use it with usermod
command
Helpful usermod
command
Change your user with new name, but you need do it on another user with kill that shell, because if you access to your old account, I will be attached by process
Change the shell of user, you can switch to user to use chsh
but this can be done remotely
Move the content of userβs home directory using usermod
command
External Commands
Caddy server
Use the documentation to get valid command to handling Caddy Server
To reload configuration use reload
command. Doc: caddy reload
To check and validate configuration from caddyfile
use validate
command. Doc: caddy validate
Note
With
Caddy V2
, mostlywebsocket
automatically serve and do not need to configuration likev1
. Check about that in Caddy Proxy
Vagrant
If you have problems when vagrant
canβt authentication for ssh
. You will need concern to add this setting. Read more at: Vagrant ssh authentication failure
Swap mode in Ubuntu
You can swap mode in Ubuntu from desktop mode to server mode, by use key combining
- Ctrl + Alt + F1 : To use desktop mode
- Ctrl + Alt + F3: To use shell or server mode
Pip command of Python3
With Python3 from version 3.12, there isnβt gonna easy for us to install package, so if you want to force install with python3-pip
, you can add the optional --break-system-packages
after the pip command
With read from file, we can do same way