Pages

22 Apr 2024

Mastering RHEL

Essential Commands and Shortcuts

Essential Commands and Shortcuts

Part 1: Navigating the File System

ls

Lists files and directories in the current directory.

cd

Changes the current directory.

pwd

Displays the current directory path.

mkdir new_directory

Creates a new directory named "new_directory".

rmdir old_directory

Removes the directory named "old_directory".

touch newfile.txt

Creates a new empty file named "newfile.txt".

cp source.txt destination.txt

Copies the contents of "source.txt" to "destination.txt".

mv oldname.txt newname.txt

Renames "oldname.txt" to "newname.txt".

rm unwantedfile.txt

Deletes the file named "unwantedfile.txt".

cat file.txt

Displays the contents of "file.txt".

Part 2: File Permissions and Ownership

chmod 755 script.sh

Changes the permissions of "script.sh" to rwxr-xr-x.

chown user:group file.txt

Changes the owner and group of "file.txt" to "user" and "group".

Part 3: Process Management

ps aux

Displays a detailed list of running processes.

top

Shows a real-time list of running processes and system resource usage.

kill PID

Sends a signal to terminate the process with the specified PID.

nohup command &

Runs a command immune to hangups, with output redirected to "nohup.out".

Part 4: Network Commands

ping example.com

Tests the connectivity to "example.com" by sending ICMP ECHO_REQUEST packets.

ifconfig

Displays information about network interfaces.

netstat -tuln

Shows network connections, routing tables, and interface statistics.

curl -I http://example.com

Fetches the HTTP headers from "http://example.com".

Part 5: System Information

uname -a

Displays detailed information about the system kernel and version.

df -h

Shows disk space usage in a human-readable format.

free -m

Displays memory usage in megabytes.

uptime

Shows how long the system has been running along with load averages.

Part 6: File Searching

find /path -name filename

Searches for files named "filename" starting from "/path".

grep 'search_term' file.txt

Searches for "search_term" in "file.txt".

Part 7: Package Management

apt-get update

Updates the package list for upgrades.

apt-get install package_name

Installs a package named "package_name".

yum update

Updates all packages to the latest version on RPM-based systems.

yum install package_name

Installs a package named "package_name" on RPM-based systems.

Part 8: Archiving and Compression

tar -cvf archive.tar file1 file2

Creates a tarball archive named "archive.tar" containing "file1" and "file2".

tar -xvf archive.tar

Extracts the contents of "archive.tar".

gzip file.txt

Compresses "file.txt" into "file.txt.gz".

gunzip file.txt.gz

Decompresses "file.txt.gz" back to "file.txt".

Part 9: Text Processing

awk '{print $1}' file.txt

Prints the first field of each line in "file.txt".

sed 's/old/new/g' file.txt

Replaces all occurrences of "old" with "new" in "file.txt".

sort file.txt

Sorts the lines in "file.txt" alphabetically.

uniq file.txt

Removes duplicate lines from "file.txt".

Part 10: System Shutdown and Reboot

shutdown now

Shuts down the system immediately.

reboot

Reboots the system.

halt

Halts the system immediately, shutting down all processes.

poweroff

Turns off the system power.

No comments:

Post a Comment