Redhat Linux Expertise Commands
Redhat Linux Expertise Commands
Advanced Commands
Expert Commands
sh
Copy code
sudo init 3 # Change to run level 3 (multi-user mode without
GUI)
sudo init 5 # Change to run level 5 (multi-user mode with
GUI)
sudo init 0 # Halt the system
sh
Copy code
sudo systemctl set-default multi-user.target # Set default
to multi-user mode without GUI
sudo systemctl set-default graphical.target # Set default
to graphical mode with GUI
sh
Copy code
sudo systemctl isolate multi-user.target # Switch to multi-
user mode without GUI
sudo systemctl isolate graphical.target # Switch to
graphical mode with GUI
sudo systemctl isolate rescue.target # Switch to rescue
mode
sh
Copy code
sudo nano /etc/systemd/system/custom.target
ini
Copy code
[Unit]
Description=Custom Target
[Install]
WantedBy=multi-user.target
sh
Copy code
systemctl list-dependencies graphical.target
sh
Copy code
sudo systemctl isolate rescue.target
o Emergency Mode: Even more minimal than rescue mode, requiring root
password for access.
sh
Copy code
sudo systemctl isolate emergency.target
sh
Copy code
systemd-analyze
systemd-analyze blame # Show time taken by each service
systemd-analyze critical-chain # Show the critical chain of
services during boot
sh
Copy code
pstree -p
sh
Copy code
sudo nano /etc/default/grub
# Add or modify the GRUB_CMDLINE_LINUX_DEFAULT line
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash systemd.unit=multi-
user.target"
sudo update-grub # Update GRUB configuration.
7. Debugging Services and Units
o journalctl: View logs to debug services and units.
sh
Copy code
journalctl -u [service]
journalctl -b # View logs from the current boot
sh
Copy code
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
sh
Copy code
sudo grub2-install /dev/sda
sh
Copy code
systemd-cgls
sh
Copy code
systemd-cgtop
3. Service Management:
o systemctl mask: Prevent a service from being started manually or
automatically.
sh
Copy code
sudo systemctl mask [service]
sh
Copy code
sudo systemctl unmask [service]
4. Power Management:
o systemctl suspend: Suspend the system.
sh
Copy code
sudo systemctl suspend
sh
Copy code
sudo systemctl hibernate
sh
Copy code
sudo systemctl hybrid-sleep
sh
Copy code
sudo systemctl default
sh
Copy code
networkctl status
networkctl list
sh
Copy code
sudo systemd-analyze verify /etc/systemd/system/[unit].service
8. Service Configuration:
o systemctl edit: Edit a service's unit file or override file.
sh
Copy code
sudo systemctl edit [service]
Additional Topics and Concepts
sh
Copy code
sudo dracut --force
sh
Copy code
sudo grub2-setpassword
sh
Copy code
sudo swapon /dev/sdX
sh
Copy code
sudo swapoff /dev/sdX
sh
Copy code
systemctl list-timers
5. Kernel Management:
o uname -r: Display the current kernel version.
sh
Copy code
uname -r
o kexec: Load a new kernel for rebooting without going through the bootloader.
sh
Copy code
sudo kexec -l /boot/vmlinuz-<version> --
initrd=/boot/initrd.img-<version> --reuse-cmdline
sudo kexec -e
6. Inspecting Systemd Journal:
o journalctl -f: Follow (tail) the journal log.
sh
Copy code
journalctl -f
sh
Copy code
journalctl --disk-usage
sh
Copy code
sudo journalctl --vacuum-size=1G
sh
Copy code
sudo btrfs filesystem df /mnt
sudo btrfs balance start /mnt
sh
Copy code
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
9. LVM Management:
o lvcreate, lvremove, lvextend, lvresize: Commands to manage Logical
Volumes.
sh
Copy code
sudo lvcreate -L 10G -n lvname vgname
sudo lvextend -L +5G /dev/vgname/lvname
sudo lvresize -r -L 15G /dev/vgname/lvname
sudo lvremove /dev/vgname/lvname
10. Advanced Disk Management:
o xfs_growfs: Grow an XFS filesystem.
sh
Copy code
sudo xfs_growfs /mount/point
sh
Copy code
sudo resize2fs /dev/sdX
Advanced Commands
sh
Copy code
sudo blkid
sh
Copy code
sudo partprobe
sh
Copy code
sudo cryptsetup luksFormat /dev/sdX
sudo cryptsetup luksOpen /dev/sdX my_encrypted_volume
2. Advanced Networking:
o ethtool: Display or change Ethernet device settings.
sh
Copy code
sudo ethtool eth0
sh
Copy code
sudo ifenslave bond0 eth0 eth1
sh
Copy code
sudo ipset create myset hash:ip
sudo ipset add myset 192.168.1.1
3. Kernel Modules:
o modinfo: Show information about a kernel module.
sh
Copy code
modinfo [module_name]
sh
Copy code
ulimit -a # Show all limits
ulimit -n 4096 # Set the number of open files limit
sh
Copy code
dmesg | grep -i error
sh
Copy code
sudo sysctl -w net.ipv4.ip_forward=1
sh
Copy code
expect myscript.exp
7. Hardware Management:
o lshw: List hardware configuration.
sh
Copy code
sudo lshw -short
sh
Copy code
sudo hdparm -Tt /dev/sdX
8. Advanced Backup and Restore:
o dd: Convert and copy a file.
sh
Copy code
sudo dd if=/dev/sdX of=/path/to/backup.img bs=4M
sh
Copy code
sudo rsnapshot configtest
sudo rsnapshot daily
Advanced Topics
sh
Copy code
getenforce
sudo setenforce 1 # Enforce mode
sudo setenforce 0 # Permissive mode
sh
Copy code
sudo semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
sudo restorecon -Rv /web
sudo chcon -R -t httpd_sys_content_t /web
sh
Copy code
sudo systemctl restart rsyslog
sudo nano /etc/rsyslog.conf
sh
Copy code
sudo logrotate -f /etc/logrotate.conf
3. Containerization and Orchestration:
o podman: Manage containers without a daemon.
sh
Copy code
podman run -it --rm fedora bash
sh
Copy code
kubectl get pods
kubectl apply -f myapp.yaml
sh
Copy code
terraform init
terraform apply
sh
Copy code
sudo systemctl start jenkins
sudo systemctl enable jenkins
sh
Copy code
ansible-playbook site.yml
sh
Copy code
man [command]
1. Filesystem Management:
o XFS Tools:
▪ xfs_info: Display information about an XFS filesystem.
sh
Copy code
sudo xfs_info /mount/point
sh
Copy code
sudo xfs_repair /dev/sdX
o Btrfs Tools:
▪ btrfs scrub: Verify and correct errors in a Btrfs filesystem.
sh
Copy code
sudo btrfs scrub start /mnt
sh
Copy code
sudo btrfs balance start /mnt
sh
Copy code
sudo ip link add link eth0 name eth0.100 type vlan id 100
o Bridging:
▪ brctl: Manage Ethernet bridges.
sh
Copy code
sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo brctl stp br0 on
3. Security and Auditing:
o Auditd:
▪ auditctl: Configure audit rules.
sh
Copy code
sudo auditctl -w /etc/passwd -p wa -k passwd_changes
sh
Copy code
sudo ausearch -k passwd_changes
sh
Copy code
sudo aureport -k
o AppArmor:
▪ aa-status: Display the current AppArmor status.
sh
Copy code
sudo aa-status
sh
Copy code
sudo aa-complain /etc/apparmor.d/usr.sbin.mysqld
4. Container Management:
o Docker:
▪ docker-compose: Define and run multi-container Docker applications.
sh
Copy code
docker-compose up -d
o Kubernetes:
▪ minikube: Run Kubernetes locally.
sh
Copy code
minikube start
sh
Copy code
helm install mychart ./mychart
5. Performance Tuning:
o CPU and Memory Tuning:
▪ cpulimit: Limit the CPU usage of a process.
sh
Copy code
sudo cpulimit -l 50 -p 1234
sh
Copy code
sudo numactl --membind=0 --cpunodebind=0 myprogram
sh
Copy code
sudo ionice -c3 -p 1234
sh
Copy code
iostat -xz 1
6. Virtualization:
o KVM (Kernel-based Virtual Machine):
▪ virsh: Manage KVM-based virtual machines.
sh
Copy code
virsh list --all
virsh start myvm
virsh shutdown myvm
o QEMU:
▪ qemu-system-x86_64: Emulate a full system.
sh
Copy code
qemu-system-x86_64 -hda /path/to/disk.img -boot d -cdrom
/path/to/cd.iso
sh
Copy code
sudo netdata
Prometheus and Grafana:
sh
Copy code
prometheus --config.file=prometheus.yml
grafana-server --config=/etc/grafana/grafana.ini