Red Hat Linux Commands Cheat Sheet

Advertisement

Red Hat Linux Commands Cheat Sheet

Red Hat Linux is one of the most popular Linux distributions, widely used in enterprise environments due to its stability, security, and support. For users and administrators alike, becoming proficient in using the command line interface (CLI) is essential for effective system management and troubleshooting. This article serves as a comprehensive cheat sheet for Red Hat Linux commands, covering various aspects including file management, system monitoring, user management, and networking.

File Management Commands



File management is a fundamental aspect of using any operating system. In Red Hat Linux, the following commands are essential for navigating and manipulating files and directories.

Basic File Commands



1. ls - List directory contents.
- Syntax: `ls [options] [file|directory]`
- Common options:
- `-l`: Long listing format
- `-a`: Include hidden files
- `-h`: Human-readable sizes

2. cd - Change the current directory.
- Syntax: `cd [directory]`
- Example: `cd /var/log`

3. pwd - Print the current working directory.
- Syntax: `pwd`

4. mkdir - Create a new directory.
- Syntax: `mkdir [directory_name]`
- Example: `mkdir new_folder`

5. rmdir - Remove an empty directory.
- Syntax: `rmdir [directory_name]`

6. rm - Remove files or directories.
- Syntax: `rm [options] [file|directory]`
- Common options:
- `-r`: Remove directories and their contents recursively
- `-f`: Force removal without prompt

7. cp - Copy files and directories.
- Syntax: `cp [options] source destination`
- Common options:
- `-r`: Copy directories recursively
- `-i`: Prompt before overwrite

8. mv - Move or rename files and directories.
- Syntax: `mv [options] source destination`
- Example: `mv file.txt /home/user/documents/`

9. touch - Create an empty file or update the timestamp of an existing file.
- Syntax: `touch [file_name]`

File Viewing and Editing Commands



1. cat - Concatenate and display file content.
- Syntax: `cat [file_name]`

2. less - View file content one screen at a time.
- Syntax: `less [file_name]`

3. more - View file content with pagination.
- Syntax: `more [file_name]`

4. nano - Open a simple text editor in the terminal.
- Syntax: `nano [file_name]`

5. vi - Open the advanced text editor.
- Syntax: `vi [file_name]`
- Basic commands:
- `i`: Enter insert mode
- `Esc`: Exit insert mode
- `:w`: Save changes
- `:q`: Quit

System Monitoring Commands



Monitoring system performance and resource usage is crucial for maintaining a healthy Red Hat Linux environment. The following commands are useful for system administrators.

Process Management



1. ps - Report a snapshot of current processes.
- Syntax: `ps [options]`
- Common options:
- `-aux`: Show all processes in detail

2. top - Display real-time system processes and resource usage.
- Syntax: `top`

3. htop - An enhanced version of `top` with a more user-friendly interface (may need to install).
- Syntax: `htop`

4. kill - Terminate a process by its PID.
- Syntax: `kill [PID]`

5. pkill - Kill processes by name.
- Syntax: `pkill [process_name]`

6. jobs - List active jobs in the current session.
- Syntax: `jobs`

Disk Usage and System Information



1. df - Display disk space usage.
- Syntax: `df [options]`
- Common options:
- `-h`: Human-readable format

2. du - Estimate file and directory space usage.
- Syntax: `du [options] [directory]`
- Common options:
- `-h`: Human-readable format
- `-s`: Summarize total space used

3. free - Display memory usage.
- Syntax: `free [options]`
- Common options:
- `-h`: Human-readable format

4. uname - Display kernel and system information.
- Syntax: `uname [options]`
- Common options:
- `-a`: Show all available system information

User Management Commands



Managing users and groups is another critical task in system administration. The following commands will help you handle user accounts effectively.

User Commands



1. useradd - Create a new user.
- Syntax: `useradd [options] [username]`
- Example: `useradd -m newuser`

2. passwd - Change a user's password.
- Syntax: `passwd [username]`

3. usermod - Modify a user's account.
- Syntax: `usermod [options] [username]`
- Common options:
- `-aG [group]`: Add user to a group

4. userdel - Delete a user account.
- Syntax: `userdel [options] [username]`

Group Commands



1. groupadd - Create a new group.
- Syntax: `groupadd [group_name]`

2. groupdel - Delete a group.
- Syntax: `groupdel [group_name]`

3. groups - Display the groups a user belongs to.
- Syntax: `groups [username]`

Networking Commands



Networking is fundamental to system administration, and Red Hat Linux provides various commands to manage and troubleshoot networks.

Network Configuration



1. ip - Show and manipulate routing, devices, policy routing, and tunnels.
- Syntax: `ip [options]`
- Example: `ip addr show`

2. ifconfig - Configure a network interface (deprecated in favor of `ip`).
- Syntax: `ifconfig [interface] [options]`

3. ping - Check connectivity to a host.
- Syntax: `ping [hostname|IP]`

4. netstat - Display network connections, routing tables, interface statistics, and more.
- Syntax: `netstat [options]`
- Common options:
- `-tuln`: Show listening ports

5. traceroute - Trace the route packets take to a network host.
- Syntax: `traceroute [hostname|IP]`

6. nslookup - Query DNS to obtain domain name or IP address mapping.
- Syntax: `nslookup [domain]`

Package Management Commands



One of the strengths of Red Hat Linux is its package management system, which simplifies software installation and updates.

YUM/DNF Commands



1. yum - Package management utility for installing, updating, and removing software.
- Common commands:
- `yum install [package]`: Install a package
- `yum update`: Update all packages
- `yum remove [package]`: Remove a package

2. dnf - The next-generation package manager, used in newer versions of Red Hat.
- Common commands:
- `dnf install [package]`
- `dnf update`
- `dnf remove [package]`

Conclusion



Mastering the command line is an essential skill for anyone working with Red Hat Linux. This cheat sheet provides a quick reference to the most commonly used commands, helping users navigate file systems, monitor system performance, manage users, troubleshoot networks, and manage software packages. Familiarity with these commands will significantly enhance your ability to operate effectively within the Red Hat Linux environment. As you gain experience, you can explore more advanced commands and scripting to automate tasks and improve efficiency.

Frequently Asked Questions


What is the purpose of the 'yum' command in Red Hat Linux?

The 'yum' command is used for package management in Red Hat Linux, allowing users to install, update, and remove software packages from the system.

How do you check the current version of Red Hat Linux?

You can check the current version of Red Hat Linux by running the command 'cat /etc/redhat-release' in the terminal.

What command is used to start, stop, or restart services in Red Hat Linux?

The 'systemctl' command is used to manage services. For example, 'systemctl start <service_name>' to start a service.

How can you view the disk usage of a specific directory?

You can view the disk usage of a specific directory using the command 'du -sh <directory_path>'.

What is the command to display network configuration in Red Hat Linux?

The command 'ip addr' or 'ifconfig' can be used to display the network configuration in Red Hat Linux.

How do you find and kill a process by name in Red Hat Linux?

You can find and kill a process by name using 'pkill <process_name>', which will terminate all processes matching the name.