2024. április 19., péntek

Gyorskeresés

Linux parancsgyűjteményem 2

Írta: |

[ ÚJ BEJEGYZÉS ]

1. Get Internal IP Address(es) on Linux Shell / Command Line

1.1 Get Single IP Address by Interface

Returns plain IP address.
## Example usage ##
/sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
10.20.10.1

Create simple bash function (example int-ip) with following command.

function int-ip { /sbin/ifconfig $1 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'; }

## Example usage ##
int-ip eth0
10.20.10.1

1.2 Get Every Interfaces IP Address

Returns every interface and IP address pairs.

/sbin/ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }'

## Example output ##
eth0: 10.20.10.1
eth1: 10.20.1.168
lo: 127.0.0.1

Create simple bash function (example int-ips) with following command.

function int-ips { /sbin/ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }'; }

## Example usage ##
int-ips
eth0: 10.20.10.1
eth1: 10.20.1.168
lo: 127.0.0.1

2. Get External IP Address on Linux Shell / Command Line

I use here whatismyip.org service.
2.1 Get External IP Address Using Lynx

Returns plain IP address.

lynx --dump http://ipecho.net/plain

## Example output ##
80.10.10.80

Create simple bash function (example ext-ip) with following command.

function ext-ip () { lynx --dump http://ipecho.net/plain; }

## Example usage ##
ext-ip
80.10.10.80

2.2 Get External IP Address Using Curl

Returns plain IP address.

curl http://ipecho.net/plain; echo

## Example output ##
80.10.10.80

Create simple bash function (example ext-ip) with following command.

function ext-ip () { curl http://ipecho.net/plain; echo; }

## Example usage ##
ext-ip
80.10.10.80
-----------------------------------------------------------------------------------------------------------------

Red Hat / CentOS: Swap / Change Ethernet Aliases

One file is the udev rule for network devices which is located here:

/etc/udev/rules.d/70-persistent-net.rules
Set your ethX number
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:50:56:b2:23:e0″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

Open each interfaces configuration file:

/etc/sysconfig/network-scripts/ifcfg-eth0 - eth0 configuration file
/etc/sysconfig/network-scripts/ifcfg-eth1 - eth1 configuration file

And set the right Device identifier.
# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Copper)
DEVICE=eth0

-----------------------------------------------------------------------------------------------------------------

/etc/group

It stores group information or defines the user groups i.e. it defines the groups to which users belong. There is one entry per line, and each line has the following format (all fields are separated by a colon (:)
cdrom:x:24:vivek,student13,raj
_____ _ _ _____
| | | |
| | | |
1 2 3 4

1. group_name: It is the name of group. If you run ls -l command, you will see this name printed in the group field.
2. Password: Generally password is not used, hence it is empty/blank. It can store encrypted password. This is useful to implement privileged groups.
3. Group ID (GID): Each user must be assigned a group ID. You can see this number in your /etc/passwd file.
4. Group List: It is a list of user names of users who are members of the group. The user names, must be separated by commas.

View Current Groups Settings
$ less /etc/group

Find Out the Groups a User Is In
$ groups {username}
$ groups
$ groups sonar

Print user / group Identity
$ id -g
$ id -g user

$ id -gn sonar

Display only the group ID and the supplementary groups, enter:
$ id -G
$ id -G user
$ id -Gn sonar

-----------------------------------------------------------------------------------------------------------------

dmesg

A dmesg parancs a kernel által loggolt dolgokat adja vissza.
Láthatjuk, hogy milyen hadware-ket ismert fel a kernel, milyen modulok lettek betöltve...

dmesg | less
Nyomd meg a / gombot és tudsz keresni listázott szövegben.
Illetve a kurzorokkal tudunk scrollozni.
A dmesg | grep kombóval is lehetöség van a szurésre
dmesg | grep -i USB
megkeresi az USB-s eszközökre vonatkozó bejegyzéseket.

dmesg -w
dmesg --follow
real time-ban látjuk a bejegyzéseket
-----------------------------------------------------------------------------------------------------------------

tar

Egy filet másolunk ki, módositjuk majd vissza csomagoljuk
gunzip test.tar.gz
tar --extract --file=test.tar etc/cron.hourly/rsync-dt
#delete it from the tar
tar --delete -f test.tar etc/cron.hourly/rsync-dt
# change the file as you see fit
tar --update --file=test.tar etc/cron.hourly/rsync-dt
gzip test.tar

-----------------------------------------------------------------------------------------------------------------

regex

grep ^a - azokat keresi amik 'a'-val kezdődnek
grep b$ - azokat keresi amik b-re végződnek
grep ...b$ - b-re végződik és legalább 4 karakteres szavak
grep ^[a-c]*s$ - elso betu a-tol c-ig és s-re végződik
grep ^[^a-y]y - első betű kívül esik a-tól y-ig tartományon (tehát z) és a második betű y
-----------------------------------------------------------------------------------------------------------------

multiple commands

./configure;make;make install - egy sorba irva pontosvesszővel elválasztva futtathatunk parancsokat egymás után. Hátránya ha a mondjuk a make elbukik valahol a make install-t akkor is megpróbálja lefuttatni
./configure && make && make install - && egy logikai operátor, egész pontosan ha a ./configure futása sikeres volt csak akkor indul el a make, majd ha az is sikeresen lefutott akkor a make install
command1 || command2 - itt a || azt jelenti, hogy a command2 akkor fog lefutni ha a command1 hibára futott. Ez amolyan ELSE ágnak tekinthető.
-----------------------------------------------------------------------------------------------------------------

samba user without shell access

less /etc/shells - a gépen elérhető shell-ek listája
useradd -s /bin/nologin r2d2 - user hozzáadása a megfelelő shellel
smbpasswd -L -a r2d2 - samba-hoz is hozzáadjuk
smbpasswd -L -e r2d2 - engedélyezzük a samba hozzáférést
nano /etc/samba/smb.conf - megszerkesztjük a shareket, ha kell
-----------------------------------------------------------------------------------------------------------------

share the terminal session

Lehetőség van arra, hogy mások is kövessék amit a terminálban ügyködünk. Ehhez a srceen programra van szükségünk.
sudo apt-get install screen - install
screen -S screen-name - készítünk egy "sharet"
screen -x screen-name - így tudnak csatlakozni a sessionunkhoz. Fontos, hogy ugyanazzal az accounttal lépjenek be!

Copyright © 2000-2024 PROHARDVER Informatikai Kft.