Simple Usual Commands

Every day we learn commands that allow us to perform certain tasks at work, so as not to forget any of these commands that served, create a list as a memory aid.

Check OS Install Date

1# First option
2$ ls -lct /etc | tail -1 | awk '{print $6, $7, $8}'
3# Second option
4$ ls -lct --time-style=+"%d-%m-%Y %H:%M:%S" /etc | tail -1 | awk '{print $6, $7, $8}'
5# Simple Option
6$ ls -lAhF /etc/hostname

Identify the Name of a Service Based on the Port

1# We identify the process ID
2$ fuser -n tcp 7070
3# We look for the process name based on the ID
4$ ps aux | grep ID_PROCESS

Identificar Detalle de Hardware

 1$ inxi -Fxz
 2# Common: lsblk, lsusb, lsscsi, lspci, lscpu
 3$ hwinfo --short
 4$ free -m
 5$ cat /proc/partitions
 6$ sudo hdparm -i /dev/sda # Can change sda
 7$ ls /sys/class/net/
 8$ ls /sys/class/net/enp0s25 # You can change enp0s25
 9$ cat /sys/class/net/enp0s25/carrier
10$ cat /sys/class/net/enp0s25/operstate
11$ lspci -v | grep "VGA" -A 12
12$ df -h
13$ pydf
14$ sudo fdisk -l
15$ mount | column -t
16$ cat /proc/cpuinfo
17$ cat /proc/meminfo
18$ cat /proc/scsi/scsi
19$ cat /proc/version

List Open Ports

1# With netstat
2$ netstat -vatn # netstat -tlpn
3# With ss
4$ ss -tlpn

For Debian OS and Derivatives, Language and Time Zone Settings

1# vim /etc/environment
2LC_ALL="es_BO.UTF-8"
3# Timezone configuration
4$ timedatectl set-timezone America/La_Paz

DNF Commands Tested on Fedora

 1# Remove Old Fedora Kernel:
 2$ dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
 3
 4# Remove Old CentOS Kernel:
 5$ package-cleanup --oldkernels --count=2
 6
 7# RPM Commands:
 8$ rpm -qa kernel\* | sort -V
 9
10# Configuration file:
11## You must edit the /etc/yum.conf file for CentOS and /etc/dnf/dnf.conf 
12## for Fedora and set installonly_limit:
13$ installonly_limit=2
14
15# Regenerate Kernel Modules
16$ dracut --regenerate-all --force

Gnome Settings with Gsettings

1# Gnome Shell Customization to normal:
2$ gsettings set org.gnome.shell.extensions.dash-to-dock extend-height false
3$ gsettings set org.gnome.shell.extensions.dash-to-dock transparency-mode 'FIXED'
4$ gsettings set org.gnome.shell.extensions.dash-to-dock background-opacity 0.0

SSH Commands

 1# SSH Tunneling
 2$ ssh -L 2228:hostname.IP_DOMAIN_PUBLIC:22 user@IP_DOMAIN_PRIVATE
 3$ ssh -f user@IP_DOMAIN_PRIVATE -L 2229:hostname.IP_DOMAIN_PRIVATE:22 -N
 4$ ssh -L 2229:hostname.IP_DOMAIN_PUBLIC:22 user@IP_DOMAIN_PRIVATE
 5
 6# Examples
 7$ ssh -i .ssh/PUB_KEY -f user@IP_DOMAIN_PUBLIC -L 2228:IP_DOMAIN_PRIVATE:22 -N
 8$ ssh -i .ssh/PUB_KEY user@localhost -p2228
 9
10# SSH Agent TTY
11$ eval $(ssh-agent -s)
12$ ssh-add ~/.ssh/name_priv_key
13
14# List of users with accepted SSH Login
15$ sudo cat /var/log/auth* | grep Accepted

Useful Commands

 1# OpenWRT Package Manager
 2$ opkg list-upgradable | cut -f 1 -d ' ' | xargs opkg upgrade 
 3
 4# Update font cache
 5$ fc-cache -f -v
 6
 7# Remount Linux Device
 8$ mount -o remount,rw -t ext4 /dev/sdb /media/device
 9
10# Set all subfolders of a folder to 755:
11$ find . -type d -exec chmod 755 {} \;
12
13# All files to 644:
14$ find . -type f -exec chmod 644 {} \;
15
16# Set only files ending with .php to 644:
17$ find . -name \*\.php -exec chmod 644 {} \;

SELinux and Firewall CMD

 1$ journalctl -t setroubleshoot
 2$ dmesg | grep -i -e tipo = 1300 -e tipo = 1400
 3$ semodule -DB
 4$ emodule -B
 5$ sealert -l "*"
 6
 7# NGINX - Selinux
 8$ ps auZ | grep nginx
 9$ semanage permissive -a httpd_t (SELinux Disable Temporary)
10$ sudo chcon -R -t httpd_sys_content_t /var/www/html
11$ sudo chcon -R -t httpd_sys_rw_content_t /var/www/html
12
13# Firewall
14$ sudo firewall-cmd --permanent --zone=public --add-service=http
15$ sudo firewall-cmd --permanent --zone=public --add-service=https
16$ sudo firewall-cmd --reload
1$ whiptail --yesno "Did you already know whiptail?" 40 150

Delete File with No Possibility to Recover

1$ shred -u file.txt

MOC Configuration on Fedora

1# vim ~/.moc/config
2TiMidity_Config = /etc/timidity.cfg
3Theme = transparent-background 
4XTermTheme = transparent-background
5# Privilegios
6$ chmod 644 config

Create file with CAT

1$ cat <<EOF >> shell.sh
2#!/bin/bash
3echo "Template"
4sed -e
5df -h
6EOF

Disable Cloud Init on Ubuntu Server

1# First option
2$ sudo touch /etc/cloud/cloud-init.disabled
3$ sudo vim /etc/cloud/cloud-init.disabled
4cloud-init=disabled
5# Second option
6$ sudo systemctl disable cloud-init.service
7$ sudo systemctl stop cloud-init.service

Referencias

Translations: