List of commands that I often use
path=$(dirname "$(readlink -f "$0")")
sudo mount -t cifs -o username=swiftd.adm //<server name>/<dir> <path to dir to mount>
nmcli con add con-name "static-ens32" ifname ens32 type ethernet ip4 xxx.xxx.120.44/24 gw4 xxx.xxx.120.1
nmcli con mod "static-ens32" ipv4.dns "xxx.xxx.120.1,8.8.8.8"
nmcli con up "static-ens32" iface ens32
nmcli con show
nmcli con del ens32
if sudo grep -q /etc/dhcp/dhclient.conf -e 'inerface "ens160" {\n\tsend host-name = gethostname();\n\tsend dhcp-requested-address 192.168.10.101;\n}';
then
sudo dhclient -r -v && sudo dhclient -4 -d -v -cf /etc/dhcp/dhclient.conf ens16- && sudo reboot;
else
sudo echo 'inerface "ens160" {\n\tsend host-name = gethostname();\n\tsend dhcp-requested-address 192.168.10.101;\n}' >> /etc/dhcp/dhclient.conf;
sudo dhclient -r -v && sudo dhclient -4 -d -v -cf /etc/dhcp/dhclient.conf ens16- && sudo reboot;
fi
or
if ! sudo grep -q /etc/dhcp/dhclient.conf -e 'inerface "ens160" {\n\tsend host-name = gethostname();\n\tsend dhcp-requested-address 192.168.10.101;\n}';
then
sudo echo 'inerface "ens160" {\n\tsend host-name = gethostname();\n\tsend dhcp-requested-address 192.168.10.101;\n}' >> /etc/dhcp/dhclient.conf;
fi
sudo dhclient -r -v && sudo dhclient -4 -d -v -cf /etc/dhcp/dhclient.conf ens16- && sudo reboot;
systemctl commands:
- enable: enables on boot
- status: gets status
- restart
- start
- reload
journalctl -u service-name.service
journalctl -u service-name.service -b
journalctl -u service-name
Just use the journalctl command, as in:
journalctl -u service-name.service
Or, to see only log messages for the current boot:
journalctl -u service-name.service -b
For things named .service, you can actually just use , as in:
journalctl -u service-name
journalctl -u swag -n 100 --no-pager
Run a command in the background and disown
ctrl-z
bg
disown
grep -rnw <dir> -e 'pattern'
find [where to start searching from] [expression determines what to find] [-options] [what to find]
find <dir to search from> -name:option for file name 'pattern'
find ./ -name 'example.txt'
sudo chown -R user:group <dir>
-R - recursive
import re
with open("U_CAN_Ubuntu_20-04_LTS_STIG_V1R1_Manual-xccdf.xml") as fin, open('output', 'w') as fout:
for line in fin:
matches = re.findall('idref=\"V-\d\d\d\d\d\d', line)
fout.writelines(match + '\n' for match in matches)
ssh-keygen -b 4096
ssh-keygen -lf <path_to_public_key_file>