0% found this document useful (0 votes)
6 views

Redhat Linux Expertise Commands

Uploaded by

prajwalmv1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Redhat Linux Expertise Commands

Uploaded by

prajwalmv1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Basic Commands

1. File and Directory Management:


o ls (list): List directory contents.
o cd (change directory): Change the current directory.
o pwd (print working directory): Show the current directory.
o mkdir (make directory): Create a new directory.
o rmdir (remove directory): Delete an empty directory.
o rm (remove): Delete files or directories.
o cp (copy): Copy files or directories.
o mv (move): Move or rename files or directories.
o touch (touch): Create an empty file or update a file's timestamp.
o cat (concatenate): Display the content of a file.
o less (less): View file content one screen at a time.
o more (more): View file content with limited navigation.
o head (head): Display the first lines of a file.
o tail (tail): Display the last lines of a file.
2. File Permissions and Ownership:
o chmod (change mode): Change file permissions.
o chown (change owner): Change file owner and group.
o chgrp (change group): Change group ownership.
3. File Content Manipulation:
o echo (echo): Display a line of text.
o grep (global regular expression print): Search text using patterns.
o awk (awk): Pattern scanning and processing language.
o sed (stream editor): Stream editor for filtering and transforming text.
4. System Information:
o uname (unix name): Display system information.
o df (disk free): Show disk usage of file systems.
o du (disk usage): Estimate file space usage.
o free (free): Display memory usage.
o uptime (uptime): Show how long the system has been running.
o top (top): Display tasks and system performance.
o htop (htop): Interactive process viewer.
o ps (process status): Display information about active processes.
o who (who): Show who is logged on.
o w (w): Display who is logged on and their activity.
5. Networking:
o ping (ping): Check network connectivity.
o ifconfig (interface configuration): Configure network interfaces (deprecated
in favor of ip).
o ip (ip): Show/manipulate routing, devices, policy routing, and tunnels.
o netstat (network statistics): Print network connections, routing tables,
interface statistics.
o ss (socket statistics): Another utility to investigate sockets.
o traceroute (traceroute): Trace the route packets take to the destination.
o nslookup (name server lookup): Query internet name servers interactively.
o dig (domain information groper): DNS lookup.
Intermediate Commands

1. Archiving and Compression:


o tar (tape archive): Archive files.
o gzip (GNU zip): Compress files.
o gunzip (GNU unzip): Decompress files.
o bzip2 (bzip2): Compress files.
o bunzip2 (bunzip2): Decompress files.
o zip (zip): Package and compress files.
o unzip (unzip): Extract compressed files.
2. Text Processing:
o sort (sort): Sort lines of text files.
o uniq (unique): Report or omit repeated lines.
o tr (translate): Translate or delete characters.
o cut (cut): Remove sections from each line of files.
o paste (paste): Merge lines of files.
o wc (word count): Print newline, word, and byte counts for each file.
3. User and Group Management:
o useradd (user add): Create a new user.
o userdel (user delete): Delete a user.
o usermod (user modify): Modify a user.
o passwd (password): Update user's authentication tokens (passwords).
o groupadd (group add): Create a new group.
o groupdel (group delete): Delete a group.
o groupmod (group modify): Modify a group.
4. Disk Management:
o mount (mount): Mount a filesystem.
o umount (unmount): Unmount a filesystem.
o fdisk (format disk): Partition table manipulator for Linux.
o parted (partition editor): A partition manipulation program.
o mkfs (make filesystem): Build a Linux file system.
o fsck (file system check): Check and repair a Linux file system.

Advanced Commands

1. System Monitoring and Performance:


o iostat (I/O statistics): Report CPU and I/O statistics.
o vmstat (virtual memory statistics): Report virtual memory statistics.
o sar (system activity reporter): Collect, report, or save system activity
information.
o strace (system call trace): Trace system calls and signals.
o lsof (list open files): List open files.
2. Security and Access Control:
o iptables (IP tables): Administration tool for IPv4 packet filtering and NAT.
o firewalld (firewalld): Manage firewall with zones.
o ufw (uncomplicated firewall): Frontend for managing firewall rules.
o ssh (secure shell): OpenSSH SSH client (remote login program).
o scp (secure copy): Securely copy files between hosts.
o rsync (remote sync): Remote file and directory synchronization.
3. System Administration:
o crontab (cron table): Schedule periodic background tasks.
o at (at): Schedule a command to be run at a particular time.
o systemctl (system control): Examine and control the systemd system and
service manager.
o journalctl (journal control): Query and display messages from the journal.
4. Development and Scripting:
o gcc (GNU compiler collection): Compiler from GNU.
o make (make): Build and manage dependencies.
o git (git): Distributed version control system.
o perl (perl): Practical Extraction and Report Language.
o python (python): Python interpreter.
5. Virtualization and Containers:
o docker (docker): Docker container platform.
o docker-compose (docker-compose): Define and run multi-container Docker
applications.
o virsh (virtual shell): Manage virtual machines.
o kvm (kernel-based virtual machine): Virtualization solution for Linux.

Expert Commands

1. System Recovery and Debugging:


o rescue (rescue mode): Boot into rescue mode for system recovery.
o debugfs (debug file system): Debug the ext2/ext3/ext4 file systems.
o gdb (GNU debugger): Debugging information and symbols.
2. Kernel Management:
o modprobe (module probe): Add and remove modules from the Linux kernel.
o lsmod (list modules): Show the status of modules in the Linux kernel.
o rmmod (remove module): Remove a module from the Linux kernel.
3. Cluster Management and High Availability:
o pacemaker (pacemaker): Cluster resource manager.
o corosync (corosync): Provides cluster membership and messaging.
4. Automation and Configuration Management:
o ansible (ansible): Automation tool for configuration management.
o puppet (puppet): IT automation tool.
o chef (chef): Configuration management tool.
5. Advanced Networking:
o ipvsadm (IP virtual server administration): Admin tool for IP virtual server.
o bridge (bridge): Show/manipulate bridge addresses and devices.
o nmcli (network manager command line): Command-line client for
NetworkManager.
Advanced Run Level and Target Management Commands

1. Viewing and Changing Run Levels (SysVinit Systems)


o runlevel: Display the previous and current run level.
o init (initialize): Change the run level.

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

2. Managing Targets with systemd


o systemctl get-default: Display the default target.
o systemctl set-default [target]: Set the default target.

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

o systemctl isolate [target]: Change the current target.

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

3. Listing Available Targets and Units


o systemctl list-units --type=target: List all active targets.
o systemctl list-units --all --type=target: List all available targets,
active and inactive.
4. Creating and Modifying Targets
o Customizing and creating new systemd targets involves creating target unit
files, usually located in /etc/systemd/system/ or /lib/systemd/system/.

sh
Copy code
sudo nano /etc/systemd/system/custom.target

Example content for a custom target:

ini
Copy code
[Unit]
Description=Custom Target

[Install]
WantedBy=multi-user.target

5. Managing Services within Targets


o systemctl enable [service]: Enable a service to start at boot.
o systemctl disable [service]: Disable a service from starting at boot.
o systemctl start [service]: Start a service immediately.
o systemctl stop [service]: Stop a service immediately.
o systemctl restart [service]: Restart a service.
o systemctl status [service]: Check the status of a service.
6. Inspecting Target Dependencies
o systemctl list-dependencies [target]: List all dependencies of a target.

sh
Copy code
systemctl list-dependencies graphical.target

Advanced Topics and Concepts

1. Understanding systemd Units


o Unit files define how services, mounts, devices, sockets, targets, etc., behave
in systemd. They are typically found in /etc/systemd/system/ and
/lib/systemd/system/.
o Types of units include service, socket, device, mount, automount, swap,
target, path, timer, slice, and scope.
2. System Rescue and Recovery
o Rescue Mode: Single-user mode with minimal services, useful for
maintenance and recovery tasks.

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

3. Analyzing Boot Performance


o systemd-analyze: Analyze and debug boot-up performance.

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

4. Custom Init Scripts (SysVinit Systems)


o Custom init scripts are typically placed in /etc/init.d/ and symlinked to
/etc/rc.d/ directories corresponding to run levels.
5. Handling Orphaned Processes
o Use pstree to visualize the process tree and identify orphaned processes.

sh
Copy code
pstree -p

6. Kernel Command Line Parameters


o Modifying boot loader configurations (e.g., GRUB) to change the run level or
target at boot time.

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

Additional Advanced Commands

1. Boot Management and Configuration:


o grub2-mkconfig: Generate a GRUB configuration file.

sh
Copy code
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

o grub2-install: Install GRUB to a device.

sh
Copy code
sudo grub2-install /dev/sda

2. Advanced Process Management:


o systemd-cgls: Show control group process tree.

sh
Copy code
systemd-cgls

o systemd-cgtop: Show top control groups by resource usage.

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]

o systemctl unmask: Remove the mask from a service.

sh
Copy code
sudo systemctl unmask [service]
4. Power Management:
o systemctl suspend: Suspend the system.

sh
Copy code
sudo systemctl suspend

o systemctl hibernate: Hibernate the system.

sh
Copy code
sudo systemctl hibernate

o systemctl hybrid-sleep: Hybrid sleep (suspend to both RAM and disk).

sh
Copy code
sudo systemctl hybrid-sleep

5. Emergency and Rescue Mode Commands:


o systemctl default: Return to the default target from rescue or emergency
mode.

sh
Copy code
sudo systemctl default

6. Network Management with systemd:


o networkctl: Query and manage network settings.

sh
Copy code
networkctl status
networkctl list

7. Analyzing and Debugging:


o systemd-analyze verify: Check unit files for errors.

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

1. Customizing the Initramfs:


o dracut: Used for creating and managing initramfs images.

sh
Copy code
sudo dracut --force

2. Securing System Boot:


o Configuring GRUB password to protect boot settings.

sh
Copy code
sudo grub2-setpassword

3. Managing and Configuring Swap:


o swapon: Enable swap space.

sh
Copy code
sudo swapon /dev/sdX

o swapoff: Disable swap space.

sh
Copy code
sudo swapoff /dev/sdX

4. Handling Systemd Timers:


o systemctl list-timers: List active timers.

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

o journalctl --disk-usage: Show disk usage of journal logs.

sh
Copy code
journalctl --disk-usage

o journalctl --vacuum-size=1G: Reduce journal size to 1GB.

sh
Copy code
sudo journalctl --vacuum-size=1G

7. Using Btrfs Filesystem:


o btrfs: Manage Btrfs file systems.

sh
Copy code
sudo btrfs filesystem df /mnt
sudo btrfs balance start /mnt

8. Advanced Firewall Configuration:


o firewalld commands:

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

o resize2fs: Resize ext2/ext3/ext4 file systems.

sh
Copy code
sudo resize2fs /dev/sdX

Advanced Commands

1. Advanced File System and Disk Management:


o blkid: Locate/print block device attributes.

sh
Copy code
sudo blkid

o partprobe: Inform the OS of partition table changes.

sh
Copy code
sudo partprobe

o cryptsetup: Manage encrypted volumes.

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

o bonding: Configure bonded interfaces.

sh
Copy code
sudo ifenslave bond0 eth0 eth1

o ipset: Manage IP sets for iptables.

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]

4. System Resource Limits:


o ulimit: Control user process resource limits.

sh
Copy code
ulimit -a # Show all limits
ulimit -n 4096 # Set the number of open files limit

5. Troubleshooting and Diagnostics:


o dmesg: Print or control the kernel ring buffer.

sh
Copy code
dmesg | grep -i error

o sysctl: Modify kernel parameters at runtime.

sh
Copy code
sudo sysctl -w net.ipv4.ip_forward=1

6. Automation and Scripting:


o expect: Automate interactive applications.

sh
Copy code
expect myscript.exp

7. Hardware Management:
o lshw: List hardware configuration.

sh
Copy code
sudo lshw -short

o hdparm: Get/set SATA/IDE device parameters.

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

o rsnapshot: Filesystem snapshot utility.

sh
Copy code
sudo rsnapshot configtest
sudo rsnapshot daily

Advanced Topics

1. Understanding and Managing SELinux:


o getenforce and setenforce: Get and set SELinux mode.

sh
Copy code
getenforce
sudo setenforce 1 # Enforce mode
sudo setenforce 0 # Permissive mode

o semanage, restorecon, and chcon: Manage SELinux policies and contexts.

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

2. Advanced Logging and Monitoring:


o rsyslog: Advanced logging system.

sh
Copy code
sudo systemctl restart rsyslog
sudo nano /etc/rsyslog.conf

o logrotate: Manages log file rotation and compression.

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

o kubernetes: Container orchestration platform.

sh
Copy code
kubectl get pods
kubectl apply -f myapp.yaml

4. Cloud Infrastructure Management:


o terraform: Infrastructure as code tool.

sh
Copy code
terraform init
terraform apply

5. DevOps and CI/CD Tools:


o jenkins: Automation server.

sh
Copy code
sudo systemctl start jenkins
sudo systemctl enable jenkins

o ansible-playbook: Run Ansible playbooks for configuration management.

sh
Copy code
ansible-playbook site.yml

Tips for Continuous Learning

1. Documentation and Manuals:


o Always refer to the man pages and official documentation for detailed
information.

sh
Copy code
man [command]

o Check /usr/share/doc for additional documentation.


Additional Commands and Topics for Expertise

1. Filesystem Management:
o XFS Tools:
▪ xfs_info: Display information about an XFS filesystem.

sh
Copy code
sudo xfs_info /mount/point

▪ xfs_repair: Repair an XFS filesystem.

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

▪ btrfs balance: Balance chunks across devices in a Btrfs filesystem.

sh
Copy code
sudo btrfs balance start /mnt

2. Advanced Network Configuration:


o VLANs:
▪ ip link add link eth0 name eth0.100 type vlan id 100:
Create a VLAN.

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

▪ ausearch: Search audit logs.

sh
Copy code
sudo ausearch -k passwd_changes

▪ aureport: Generate audit reports.

sh
Copy code
sudo aureport -k

o AppArmor:
▪ aa-status: Display the current AppArmor status.

sh
Copy code
sudo aa-status

▪ aa-complain: Set a profile to complain mode.

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

▪ helm: Kubernetes package manager.

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

▪ numactl: Control NUMA policy for processes or shared memory.

sh
Copy code
sudo numactl --membind=0 --cpunodebind=0 myprogram

o Disk I/O Tuning:


▪ ionice: Set or get the I/O scheduling class and priority.

sh
Copy code
sudo ionice -c3 -p 1234

▪ iostat: Report CPU and I/O statistics.

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

7. Advanced System Monitoring:


o Netdata:
▪ Real-time performance monitoring.

sh
Copy code
sudo netdata
Prometheus and Grafana:

▪ Monitor and visualize metrics.

sh
Copy code
prometheus --config.file=prometheus.yml
grafana-server --config=/etc/grafana/grafana.ini

Summary of Advanced Linux Commands and Topics

1. Run Level and Target Management:


o SysVinit: runlevel, init
o systemd: systemctl get-default, systemctl set-default, systemctl
isolate, systemctl list-units
2. File System and Disk Management:
o Commands: blkid, partprobe, cryptsetup, xfs_info, xfs_repair, btrfs
scrub, btrfs balance
3. Network Configuration:
o Commands: ip link add link, brctl, ethtool, bonding, ipset,
networkctl
4. Security and Auditing:
o Tools: auditctl, ausearch, aureport, aa-status, aa-complain
o SELinux: getenforce, setenforce, semanage, restorecon, chcon
5. Service and Process Management:
o Commands: systemctl mask, systemctl unmask, systemctl edit,
ulimit, pstree, systemd-cgls, systemd-cgtop, journalctl
6. Containerization and Orchestration:
o Tools: podman, docker-compose, minikube, helm, kubernetes, ansible-
playbook
7. Virtualization:
o Tools: virsh, qemu-system-x86_64
8. Performance Tuning and Monitoring:
o Commands: cpulimit, numactl, ionice, iostat, systemd-analyze
o Tools: netdata, Prometheus, Grafana
9. Backup and Restore:
o Tools: dd, rsnapshot
10. Advanced Logging and Monitoring:
o Tools: rsyslog, logrotate, journalctl
11. Kernel Management:
o Commands: uname -r, kexec, modinfo, sysctl
12. Automation and Scripting:
o Tool: expect
13. Hardware Management:
o Commands: lshw, hdparm
14. DevOps and CI/CD Tools:
o Tools: terraform, jenkins
15. Boot Management and Configuration:
o Commands: grub2-mkconfig, grub2-install, dracut

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy