List of CentOS Essential Commands for beginners

CentOS Essential Commands

Share This Post

Introduction

CentOS Essential Commands: I know many of you might already familiar with all these commands, but remember, newbies are everywhere and have right to learn, so if you already know all these then pls skip and for all who want to know more, then continue. Now, are you ready to take the plunge into the world of CentOS and CentOS Essential Commands? Harness the power of this robust Linux distribution. Whether you’re a seasoned Linux user or a curious newcomer, mastering the fundamental commands is the key to unlocking CentOS’s full potential. In this comprehensive guide, we’ll explore the CentOS essential commands that every user should know, empowering you to navigate, manage, and customize your system with ease.

But before we dive into the commands, let’s address the elephant in the room – why CentOS? This community-driven operating system, derived from the sources of Red Hat Enterprise Linux (RHEL), offers exceptional stability, security, and scalability. With its widespread adoption in enterprise environments and hosting providers, CentOS has become a go-to choice for countless IT professionals and enthusiasts alike.

Usage

Now, let’s roll up our sleeves and delve into the world of CentOS commands. Brace yourselves; by the end of this article, you’ll be well on your way to becoming a CentOS command-line wizard!

Common Commands

No. 1: Navigation and File Management:

  • ls: List the contents of a directory.
  • cd: Change the current working directory.
  • pwd: Print the current working directory.
  • mkdir: Create a new directory.
  • rm: Remove files or directories.
  • cp: Copy files or directories.
  • mv: Move or rename files or directories.

No. 2: File Viewing and Editing:

  • cat: Concatenate and display file contents.
  • less or more: View file contents page by page.
  • head or tail: Display the beginning or end of a file.
  • nano or vi: Edit text files using command-line text editors.

No. 3: System Information and Monitoring:

  • uname: Display system information.
  • hostname: Show or set the system’s host name.
  • top: Display real-time information about running processes.
  • ps: List currently running processes.
  • df: Report file system disk space usage.
  • du: Estimate file space usage.

No. 4: User and Group Management:

  • useradd: Create a new user account.
  • userdel: Delete a user account.
  • groupadd: Create a new group.
  • groupdel: Delete a group.
  • passwd: Change a user’s password.
  • su: Switch to another user account.

No. 5: Package Management:

  • yum: The primary package management tool in CentOS.
  • yum install: Install a new package.
  • yum update: Update installed packages to their latest versions.
  • yum remove: Remove an installed package.
  • yum search: Search for available packages.

No. 6: Network and Connectivity:

  • ifconfig: Configure network interfaces.
  • ping: Test network connectivity by sending ICMP echo requests.
  • ssh: Secure Shell for remote login and file transfer.
  • scp: Secure Copy for transferring files between hosts.
  • wget: Retrieve files from the web.

No. 7: Process Management:

  • kill: Terminate a running process by specifying its PID.
  • killall: Terminate processes by name.
  • nice and renice: Set or adjust the priority of a process.
  • bg and fg: Move jobs between the background and foreground.

No. 8: File and Text Manipulation:

  • grep: Search for patterns in files or output.
  • sort: Sort lines of text alphabetically or numerically.
  • uniq: Report or remove repeated lines in a file.
  • cut: Extract sections from each line of a file.
  • tr: Translate or delete characters.

No. 9: Permissions and Ownership:

  • chmod: Change file or directory permissions.
  • chown: Change file or directory ownership.
  • chgrp: Change the group ownership of files or directories.

No. 10: System Administration and Maintenance:

  • systemctl: Control and manage system services.
  • journalctl: View and query system logs.
  • cron and anacron: Schedule tasks to run at specified times.
  • tar: Create, extract, and manage archive files.
  • zip and unzip: Compress and decompress ZIP archives.

Essential CentOS commands with Examples

Let’s explore some of the essential CentOS commands with examples and command-line usage:

No. 1: Navigation and File Management:

  • ls (list files and directories):
    • ls (list files and directories in the current directory)
    • ls -l (list files and directories with detailed information)
    • ls -a (list all files, including hidden ones)
  • cd (change directory):
    • cd /path/to/directory (navigate to a specific directory)
    • cd ~ (navigate to the current user’s home directory)
    • cd .. (navigate to the parent directory)
  • mkdir (create a new directory):
    • mkdir new_directory (create a new directory called “new_directory”)
    • mkdir -p path/to/nested/directories (create nested directories)
  • rm (remove files or directories):
    • rm file.txt (remove a file called “file.txt”)
    • rm -r directory (remove a directory and its contents recursively)

No. 2: File Viewing and Editing:

  • cat (concatenate and display file contents):
    • cat file.txt (display the contents of “file.txt”)
    • cat file1.txt file2.txt (display the contents of multiple files)
  • less (view file contents page by page):
    • less file.txt (view “file.txt” with navigation and search capabilities)
  • nano (edit text files using the nano text editor):
    • nano file.txt (open “file.txt” for editing in nano)

No. 3: System Information and Monitoring:

  • uname (display system information):
    • uname -a (display detailed system information)
  • top (display real-time information about running processes):
    • top (launch the top utility and view processes sorted by CPU usage)
  • ps (list currently running processes):
    • ps aux (display all running processes with detailed information)
  • df (report file system disk space usage):
    • df -h (display disk space usage in a human-readable format)

No. 4: User and Group Management:

  • useradd (create a new user account):
    • useradd new_user (create a new user account called “new_user”)
    • useradd -G group1,group2 new_user (add the new user to specific groups)
  • passwd (change a user’s password):
    • passwd new_user (change the password for the “new_user” account)
  • groupadd (create a new group):
    • groupadd new_group (create a new group called “new_group”)

No. 5: Package Management:

  • yum (the primary package management tool in CentOS):
    • yum install package_name (install a package called “package_name”)
    • yum update (update all installed packages to their latest versions)
    • yum remove package_name (remove an installed package called “package_name”)
    • yum search keyword (search for available packages containing “keyword”)

No. 6: Network and Connectivity:

  • ifconfig (configure network interfaces):
    • ifconfig (display information about active network interfaces)
    • ifconfig eth0 192.168.1.100 (set the IP address of the “eth0” interface)
  • ping (test network connectivity):
    • ping example.com (send ICMP echo requests to “example.com” and display the response times)
  • ssh (Secure Shell for remote login and file transfer):
    • ssh user@remote_host (establish an SSH connection to a remote host as the specified user)
    • ssh -X user@remote_host (enable X11 forwarding for graphical applications)

No. 7: Process Management:

  • kill (terminate a running process by specifying its PID):
    • kill 1234 (terminate the process with PID 1234)
    • kill -9 1234 (forcefully terminate the process with PID 1234)
  • nice and renice (set or adjust the priority of a process):
    • nice -n 10 command (run “command” with an increased nice value, lowering its priority)
    • renice -n 5 -p 1234 (change the nice value of the process with PID 1234 to 5)

Understand SUDO

Now let’s use sudo for running commands as a non-root user. Let me provide some examples where sudo is required:

No. 1: File Management:

  • sudo rm -r /path/to/system/directory (remove a system directory, which requires root permissions)
  • sudo chown -R user:group /path/to/directory (change ownership of a directory and its contents recursively)

No. 2: User and Group Management:

  • sudo useradd new_user (create a new user account, which requires root privileges)
  • sudo passwd user (change the password for the “user” account as root)

No. 3: Package Management:

  • sudo yum install package_name (install a package, which typically requires root permissions)
  • sudo yum update (update installed packages to their latest versions as root)

No. 4: System Administration and Maintenance:

  • sudo systemctl start/stop/restart service (start, stop, or restart a system service)
  • sudo journalctl -u service (view logs for a specific system service)
  • sudo crontab -e (edit the root user’s crontab file to schedule tasks)

No. 5: Network and Connectivity:

  • sudo ifconfig eth0 192.168.1.100 (configure a network interface, which requires root privileges)
  • sudo iptables -L (list the current iptables firewall rules as root)

No. 6: Process Management:

  • sudo kill 1234 (terminate a process as root, which may be required for certain system processes)
  • sudo renice -n 10 -p 1234 (adjust the priority of a process as root)

In CentOS, and most Linux distributions, the sudo command allows non-root users to run commands with superuser (root) privileges temporarily. It’s an essential tool for performing system administration tasks and making system-wide changes that require elevated permissions.

When using sudo, you’ll be prompted to enter your user account’s password (unless you’ve configured sudo to allow passwordless execution for specific users or commands). It’s important to use sudo judiciously and only when necessary, as running commands with root privileges can potentially cause system-wide changes or damage if used improperly.

Always exercise caution when running commands with sudo, double-check your command syntax, and be mindful of the potential impact on your system.

Understanding Yum Usage

Now let’s go through some common yum commands with examples:

No. 1: Installing Packages:

  • sudo yum install package_name (install a single package)
    • Example: sudo yum install nginx
  • sudo yum install package1 package2 package3 (install multiple packages)
    • Example: sudo yum install php php-fpm php-mysqlnd

No. 2: Removing Packages:

  • sudo yum remove package_name (remove a single package)
    • Example: sudo yum remove httpd
  • sudo yum remove package1 package2 (remove multiple packages)
    • Example: sudo yum remove mariadb-server mariadb-client

No. 3: Updating Packages:

  • sudo yum update (update all installed packages to their latest versions)
  • sudo yum update package_name (update a specific package)
    • Example: sudo yum update firefox

No. 4: Searching for Packages:

  • yum search keyword (search for packages containing the specified keyword)
    • Example: yum search apache
  • yum search all keyword (search package summaries and descriptions)
    • Example: yum search all php

No. 5: Listing Packages:

  • yum list installed (list all installed packages)
  • yum list available (list all available packages in the configured repositories)
  • yum list package_name (display details about a specific package)
    • Example: yum list docker

No. 6: Getting Package Information:

  • yum info package_name (display detailed information about a package)
    • Example: yum info httpd

No. 7: Cleaning Up:

  • sudo yum clean all (clean up cached package data and metadata)
  • sudo yum autoremove (remove unused dependency packages)

No. 8: Enabling and Disabling Repositories:

  • sudo yum repolist (list enabled and disabled repositories)
  • sudo yum-config-manager --enable repo_name (enable a specific repository)
    • Example: sudo yum-config-manager --enable epel
  • sudo yum-config-manager --disable repo_name (disable a specific repository)

The yum command is the primary package management tool in CentOS, and it offers a wide range of options and subcommands for installing, updating, removing, and managing packages and repositories. It’s essential to use sudo with most yum commands to gain the necessary permissions for system-wide package operations.

Remember to always exercise caution when installing or removing packages, as it can potentially impact the stability and functionality of your CentOS system. It’s a good practice to read the package descriptions, review dependencies, and ensure that you’re installing packages from trusted sources.

These examples provide a glimpse into the powerful capabilities of CentOS commands. Remember, each command often has numerous options and flags that can further enhance its functionality. Don’t hesitate to explore the man pages (man command) or online documentation for more detailed information and advanced usage examples.

This list merely scratches the surface of the vast array of commands available in CentOS. Each command is a powerful tool in its own right, with numerous options and flags that allow for even greater customization and control. As you gain experience, you’ll discover new commands and nuances that will further enhance your CentOS mastery.

But learning commands is just the beginning. To truly harness the power of CentOS, you’ll need to dive deeper into topics like shell scripting, system administration, and security best practices. Don’t worry, though; the Linux community is vast and welcoming, with countless resources available to guide you on your journey.

Remember, practice makes perfect. Set up a virtual machine or a dedicated CentOS system, and start experimenting with the commands you’ve learned. Break things, fix them, and repeat the process – that’s the best way to solidify your understanding and build confidence.

Conclusion

In conclusion, mastering the essential CentOS basic commands is a critical step towards becoming a proficient Linux user. With this guide as your foundation, you’re well-equipped to navigate, manage, and customize your CentOS system with ease. Embrace the command line, embrace the power of CentOS, and embark on an exciting journey of learning and exploration. The possibilities are endless, and the rewards are immeasurable. Happy commanding!

Share this post:

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

CentOS Essential Commands

Share This Post

Share this post:

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Do You Want To Boost Your Business?

drop us a line and keep in touch

small_c_popup.png

Share your details to letus know about your needs!

Let's have a chat