a='hello world
hello world
hello world
hello world
hello world ad a a t t hello'
n=0
> result.txt
for word in $a
do
wcount=$(echo $a| grep -o $word | wc -l)
echo "$word : $wcount" >> result.txt
done
cat result.txt | uniq
Tag: linux
recover files in linux using xfs_undelete and dd
yum install expect tcl tcllib
dd if=/dev/sda | ssh USERNAME@IP_ADDR dd of=sda.iso
xfs_undelete sda.iso
More :
https://github.com/ianka/xfs_undelete
https://unix.stackexchange.com/questions/132797/how-to-dd-a-remote-disk-using-ssh-on-local-machine-and-save-to-a-local-disk
Open port using NC command in linux
Open port using NC:
nc 8888
Listen port:
nc localhost 8888
Send packet using bash:
echo -n "hello" >/dev/tcp/localhost/8888
Mount cifs/samba share inside container
#Dockerfile
FROM ubuntu
RUN apt update -y
RUN apt install cifs-utils -y
docker build -t cifs .
docker run -it --cap-add SYS_ADMIN --cap-add DAC_READ_SEARCH -cap-add NET_BIND_SERVICE cifs bash
#centos with privileged (working)
docker run --privileged -it --cap-add SYS_ADMIN --cap-add DAC_READ_SEARCH --cap-add NET_BIND_SERVICE centos bash
mount -t cifs -o username=a,password=a //192.168.0.228/public /mnt
mount -t cifs -o username=a,password=a //192.168.0.228/public /mnt
mount -t cifs -o username=a,password=a,ro,domain=WORKGROUP //192.168.0.228/public /a -v
Tmux , Screen, Nohup, – Run command in background
Why?
– Run process in background
– Run database backup in background
Tmux:
#List
tmux ls
#Start session
tmux new -s mysession
#Reconnect
tmux a -t session_name
#Disconnect
ctrl + b + D
#Reconnect to 0 session
tmux a -t 0
More : https://tmuxcheatsheet.com
Screen :
#List
screen -ls
#Named session
screen -A -m -d -S session_name command
#Reconnect to named session
screen -r session_name
#Disconnect
CTRL + a + d
https://gist.github.com/jctosta/af918e1618682638aa82
Nohup:
Nohup command &
It’s create nohup.out
file in same directory with all command logs
Jobs:
jobs
fg
bg
Strings command in linux
strings /lib64/libc.so.6 |grep GLIBC
strings /bin/ls
Usage: strings [option(s)] [file(s)]
Display printable strings in [file(s)] (stdin by default)
The options are:
-a - --all Scan the entire file, not just the data section [default]
-d --data Only scan the data sections in the file
-f --print-file-name Print the name of the file before each string
-n --bytes=[number] Locate & print any NUL-terminated sequence of at
-<number> least [number] characters (default 4).
-t --radix={o,d,x} Print the location of the string in base 8, 10 or 16
-w --include-all-whitespace Include all whitespace as valid string characters
-o An alias for --radix=o
-T --target=<BFDNAME> Specify the binary file format
-e --encoding={s,S,b,l,B,L} Select character size and endianness:
s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit
-s --output-separator=<string> String used to separate strings in output.
@<file> Read options from <file>
-h --help Display this information
-v -V --version Print the program's version number
strings: supported targets: elf64-x86-64 elf32-i386 elf32-iamcu elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big pe-x86-64 pe-bigobj-x86-64 pe-i386 plugin srec symbolsrec verilog tekhex binary ihex
create bootable usb using dd
dd bs=4M if=/home/input.iso of=/dev/sd[?] conv=fdatasync status=progress
[?] = Run lsblk
and find your USB
connect to wifi using terminal in ubuntu
1.Create file and add wifi name and creds (vi /etc/wpa_supplicant.conf)
network={
ssid="ssid_name"
psk="password"
}
2.Connect
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D wext
sudo dhclient wlan0
More : https://askubuntu.com/questions/138472/how-do-i-connect-to-a-wpa-wifi-network-using-the-command-line
https://askubuntu.com/questions/294257/connect-to-wifi-network-through-ubuntu-terminal
sftp setup to restrict user to some /path
WHY?
– Secure access
– Secure path
adduser kool -s /sbin/nologin
#edit /etc/ssh/sshd_config and ADD
Subsystem sftp internal-sftp
Match User kool
ChrootDirectory /opt/dir1/dir2
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no
chown root:root -R /opt/dir1/dir2
chmod 755 -R /opt/dir1/dir2
chown kool:kool /opt/dir1/dir2/kool
chmod 700 /opt/dir1/dir2/kool
iptables port allow/block
//Block port 8080
iptables -A INPUT -p tcp --dport 8080 -j DROP
//Allow port 8080
iptables -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
//Delete rule from same command(-D)
iptables -D INPUT -p tcp --dport 8080 -j DROP
//Delete iptable rule for 8080 as per line number
iptables -L --line-numbers
iptables -D INPUT 1
//List rules
iptables -S
iptables -S TCP
iptables -L INPUT
iptables -L INPUT -v
#save
service iptables save