Tuesday, July 17, 2018

linux essential

# copy single file to multiple files.

tee <ORIGINAL_FILE ORIGINAL_FILE2 ORIGINAL_FILE3

# checking public via cli
curl ipinfo.io/ip
#curl -s checkip.dyndns.org
#curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

# nmcli
nmcli connection add con-name 10516 ifname enp12s0 type ethernet ip4 a.b.c.d/24 gw4 a.b.c.254

# pip
apt-get install -y libav-tools
pip install --upgrade pip
pip install --upgrade youtube-dl
# eyeD3
eyeD3 --remove-comments --remove-lyrics  --remove-images --remove-all# process & port

# lsof -i
# nmap
nmap --min-parallelism 4096 -p- 8.8.8.8
# nemo cannot handle smb locations # could "smb" be any protocol?
apt install -y gvfs-backends

# useradd -r/ groupadd -r
-r: system account, The password , home directory and other settings from login.defs will not apply to this user. A shell of "/sbin/nologin" prevents anyone from logging in to a service account. Old Unix systems would typically allow daemons and services access to files as root.

#
ss -ant4 # list EST & LISTEN only?
ss -l4tn
ss -ltp # show pid, fd & process name.
ss -x src /var/run/dbus/*
ss -x src /var/run/dbus/system_bus_socket # same as above.
# kibana
hosttype: stock
hostname: stock
#
ss -nA inet
netstat -46n







###prepend
USER@56105 ~ $ cat t1
L1
L2
USER@56105 ~ $ cat t2
LL1
LL2
USER@56105 ~ $ cat t1 |(echo L0 ; cat)
L0
L1
L2

USER@56105 ~ $ cat t1 |(cat t2 ; cat)
LL1
LL2
L1
L2





#############
e530b ~ # service cups stop
Warning: Stopping cups.service, but it can still be activated by:
  cups.path
e530b ~ # ^op^art
service cups start
e530b ~ #
---------------
e530b ~ # systemctl status dhcpd
● dhcpd.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
e530b ~ # ^dhcpd^gpm
systemctl status gpm
● gpm.service - LSB: gpm sysv init script
#############


reen
right ctrl+enter or f
right ctrl+right alt+right shift+enter




Tools/Preferences. Under the Interface tab you should see the option for System Tray Icon.

rsyslog discard messages
:msg, contains, "Connection from UDP" ~

linux audio: alsa

sudo dpkg -i package_name.deb; sudo apt-get -f install
#################
pip install --upgrade pip
pip install --upgrade setuptools
pip install --upgrade youtube-dl


squid:
|perl  -pe 's/\d+/localtime($&)/e'
nmap --max-parallelism 65535 # or something else

systemd-analyze critical-chain

ll /bin/ |grep bash$
-rwxr-xr-x. 1 root root     960472 Dec  7 07:19 bash
lrwxrwxrwx. 1 root root          4 Mar 14 10:30 sh -> bash


show timestamp  prompt
export PROMPT_COMMAND="echo -n \$(date +%H%M%S)\ "

export PS1="\[\e[34m\]\t\[\e[m\]\[\e[35m\]\u\[\e[m\]\[\e[36m\]\h\[\e[m\]\[\e[31m\]\W\[\e[m\] "


pkill -kill gpm

mount   | column -t
When your typing and you enter a partial word, you can cause Vim to search for a completion by using the ^P (search for previous marching word) and ^N (search for next match).

yum install bind-utils
bind-utils is nice shit
yum provides nslookup
check which package contains nslookup
show filename only:
ls or ls -1

locate session |grep etc

locate cacti.sql
rpm -ql cacti|grep cacti.sql

find / -nouser -o -nogroup 2>/dev/null


apt install -y  remmina remmina-plugin-rdp


show specific line
sed '5!d' FILE
awk 'NR==5' FILE



 file/etc/sysctl.conf


net.ipv4.ip_forward = 1

vim /etc/hostname
NEW HOSTNAME

ip  -c a
compiles                                
apt install -y make intltool wget
bzip2 -cd nmap-7.31.tar.bz2 | tar xvf -
cd nmap-7.31
./configure
make
su root
make install




vim /etc/rsyslog.conf
RepeatedMsgReduction off    # log every message

learning crontab
crontab.guru

vim ~/.bashrc
HISTSIZE=10000
HISTFILESIZE=20000
or just keep the empty string *=

apt  install -y remmina remmina-plugin-rdp
must save the gui config so u can connect due to  unknowing auth.

yum install -y PackageKit-command-not-found

awk -F/ '{print $1}' /tmp/a|xargs apt install -y

dnf install yum utils -y
 package-cleanup --oldkernels --count=1gdebi package.deb

disable vim
line
    line
        line
:set paste vs :set nopaste


grep -A3: and above 3 line
grep -B3: and below 3 line
fsck -ycf /dev/sda1

nmtui
smb://10.1.95.110/software/
run file explorer.
click on "file"
select "connect on server"
easy peasy~
fsck
.bashrc
PS1='\[\033[1;36m\]\u\[\033[1;31m\]@\[\033[1;32m\]\h:\[\033[1;35m\]\w\[\033[1;31m\]\$\[\033[0m\] '
PS1='[\[\e[1;33m\]\u@\[\e[1;35m\]\h:\w\$\[\e[1;36m\] '

.vimrc
:syntax on
#colorscheme
:set hlsearch
:set number
(:set nu)
must systemctl stop services b4 configuring .json.

echo "alias AL=\"apt list |grep -i\"" >> ~/.bashrc
ls  --full-time
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
-r, --reverse              reverse order while sorting
-S                         sort by file size, largest first
-t                         sort by modification time, newest first
-u                         with -lt: sort by, and show, access time;




case convert:
|tr '[:upper:]' '[:lower:]'
|tr A-Z a-z

xargs exp.:
 apt list |grep zabbix|grep -v 'libzabbix-api-perl\|pgsql\|proxy'|awk -F/ '{print $1}'|xargs apt install -y


grep -c string a.txt: how many string in a.txt
-n: which line did string locate
-A2: 2 line after string
-B2: 2 line b4 string

grep -iC2 string a.txt
1st line
2nd line
string
3rd line
4th line


sort
-u: uniq
-t: specificate field(-t without space i guess...)
-k: according to which column.
i think sort -u is better then uniq -c
diff -u is better then nothing(-ruN better?)



checking M$ formate or unix formate: cat -A
dos2unix
unix2dos

grep "x\?yz" xyz
grep "x\+" xyz
grep "x\?yz" xyz
grep "x\{2\}" xyz
xxyz
yxxz



ls /e*/s*/n*/i*
ls /etc/sysconfig/network-scripts/i*check DNS


cat emp.txt |grep "\<c"
christina




cat emp.txt |grep "s\>"
chris

systemctl restart ntp
^re^
systemctl start ntp

^a^e: all a change to b

cat /etc/resolv.conf


UUID=fd1d0fad-3a4c-457f-9b5e-eed021cce3d1 /                       ext4    remount,ro        1 1
(read more about fstab dump pass...)
 find . -name "*STRING*" -exec rm -rf {} \;
mind the *


Resume a Stopped Job: fg

grep * > t1 2>&1
grep * &>t1

swapon --summary
grep SwapTotal /proc/meminfo

vim /etc/fstab
UUID=9214D18814D16FA9   /run/media/e/w/ ntfs    defaults        0       0
mount -a    # checking fstab


vim /etc/default/grub

GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
grub-mkconfig >/boot/grub/grub.cfg
vim /etc/systemd/logind.conf
HandleLidSwitch=ignore
systemctl restart systemd-logind.service

sha1sum {file}
sha1sum {file} > {file}.sha1
sha1sum -c {file}.sha1

dpkg-query
*/5    9-16  *  *  1-15

apt list |grep selinux |grep policy
apt-get install -y selinux-policy-default
vim /etc/selinux/config

sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0
vim /etc/sysctl.conf
net.ipv4.ip_forward=1

configuring timezone
dpkg-reconfigure tzdata
 /etc/init.d/ntp restart

unlink /"symbolic link"
rm -rf  /"symbolic link"

ln
Create hard  links  by  default,  symbolic  links  with  -s.   By default,  each  destination (name of new link) should not already exist. When creating hard links, each TARGET must exist.  Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.


vim /etc/ssh/ssh_config

below "Host *"
ServerAliveInterval 240                                        #depand on the device idle period
ServerAliveCountMax 2


setenforce [ Enforcing | Permissive | 1 | 0 ]

enforcing=0 or selinux=0 while boting will temporarily disable SELinux

lspci -v

nice - n -20  livestreamer "random url" source
nice - n -20  livestreamer

mtime — updated when the file contents change. This is the "default" file time in most cases.
ctime — updated when the file or its metadata (owner, permissions) change
atime — updated when the file is read

/var/spool/cron/"user crontab location"

/etc/systemd/logind.conf

youtube-dl -x --audio-format best --audio-quality 0  https://www.youtube.com/watch?v=JwkC8WaN5T4

dnf grouplist hidden
dnf grouplist -v hidden

find iname: ignore cases
find -perm 666: exact rwrwrw permission
find -perm -666: at least wrwrwr permissions find -perm /666: at least wrwrwr permissions

ln
Create hard  links  by  default,  symbolic  links  with  --symbolic.   By default,  each  destination (name of new link) should not already exist.  When creating hard links, each TARGET must exist.

dnf history rollback

vim /etc/sudoers
someone ALL =(ALL) ALL

lscpu
cat /proc/cpuinfo

[root@localhost etc]# cat /etc/sysconfig/desktop
PREFERRED=/usr/bin/cinnamon-session
DISPLAYMANAGER=/usr/sbin/lightdm
[root@localhost etc]# vim /etc/lightdm/lightdm.conf

a leading "-" is not required for tar
p: preserve the permissions
c: creat an archive
t: list contents
x: extract
f: file name
z: gzip
gzip>xz>bzip2
compress exp.: tar czf source destination
extract exp.: tar xzf file.tar.gz
extract tar: tar xf file.tar

iptables -I INPUT -p tcp --dport 51413 -j ACCEPT

uuidgen eth0

http://li.nux.ro/download/nux/dextop/el7/x86_64/

release swap:
swapoff -a
swapon -a


Ctrl+a: jump to beginning of the command line
Ctrl+e: jump to end of the command line
Ctrl+u: clean from cursor to beginning
Ctrl+k: clean from cursor to end.
Ctrl+r: search from history
Ctrl+Left Arrow  Jump to the beginning of the previous word on the command li ne.
Ctrl+Right Arrow  Jump to the beg inning of the next word on the command line.

sed remove line if pattern matched
sed -i '/pattern/d' file

[root@4 e]# date +%R
09:57
[root@4 e]# date +%x
05/12/2016
tar -xf file -c /path

echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger

Adding timestamps to terminal prompts
echo export PROMPT_COMMAND="echo -n \[\$(date +%H:%M:%S)\]\ "  > ~/.bashrc
export PROMPT_COMMAND="echo -n \[\$(date +%H:%M:%S)\]\ "


Device eth0 does not seem to be present, delaying initialization.
cat /proc/net/dev
vim /etc/udev/rules.d/70-persistent-net.rules
or delete above and reboot

grep file foo | while read line ; do echo "$line" ; done
grep file foo | while read  ; do echo "$line" ; done

nmap
-O: check os
-sL: check hostname
-Pn: assume the host is up
-A: aggressive
-FT4: fastscan

find . -delete -name "*.php"
find . -name "*.php" | xargs /bin/rm -rf
find / -name *zabbix*  | xargs /bin/rm -rf grep -r --exclude-dir=proc  eee --exclude-dir=sys --exclude-dir=dev  --exclude-dir=mnt  --exclude-dir=media  --exclude-dir=tmp

sort -k3

du -h --max-depth=1
df -h
lsblk

ls
-t mtime
-S size
-r reverse

find string in the file
grep  /tmp  -re "repo"

send mail via postfix
echo "This is a test." | mail -s "test message" user@example.net

sort with column

 cat /etc/shadow |sort -t: -k 2
-t = separate with " ", "-", ":" or ";"
-k column

"systemctl restart" command starts a service plus it also starts the dependent services
"systemctl start" command starts the service but it does not starts the dependent services What

enter single user mode
kernel /vmlinuz-2.6.15-27-386 root=/dev/mapper/Ubuntu-root rw init=/bin/bash
                                                                                                rw single

logrotate
vim /etc/logrotate.conf
rotate 48
daily
weekly
monthly
yearly

size 100k
size 100M
size 100G

config timezone in Debian
dpkg-reconfigure tzdata

find modified file past 1 min
find /target_directory -type f -mmin -1

install without NB power option
"Tab" while boot
nofb apm=off acpi=off pci=noacpi

mkdir create directory recursively
mkdir -p folder1/folder2/folder3

No comments:

Post a Comment