CentOS Command Line: Common Commands and Detailed Explanations

File and Directory Management

  1. ls: List files and directories in the current directory. It displays the names of files and directories present in the current directory.

    Example: ls

  2. pwd: Print the full path of the current directory. It helps you know where you are in the file system.

    Example: pwd

  3. cd <directory>: Change to the specified directory. By using this command, you can navigate between directories in your file system.

    Example: cd /home/user/documents

  4. touch <filename>: Create a new file or update the modification time of an existing file. If the file already exists, it will update the modification time.

    Example: touch newfile.txt

  5. cp <source> <destination>: Copy a file or directory from the source location to the destination location. You can copy multiple files or directories by specifying multiple sources.


    • cp file.txt /home/user/documents/ (copy a file)
    • cp -r folder1 /home/user/documents/ (copy a directory)
  6. mv <source> <destination>: Move or rename a file or directory from the source location to the destination location. If the destination is a new name, it will rename; if it is a new path, it will move.


    • mv file.txt /home/user/documents/file_new.txt (rename a file)
    • mv folder1 /home/user/documents/ (move a directory)
  7. rm <file>: Remove a file. Note that this command will delete the file without any confirmation, so use it with caution.

    Example: rm file.txt

  8. mkdir <directory>: Create a new directory with the specified name.

    Example: mkdir new_folder

  9. rmdir <directory>: Remove an empty directory. Note that you can only remove an empty directory using this command.

    Example: rmdir empty_folder

File and Directory Permission Management

  1. chmod <permissions> <file/directory>: Change the access permissions of a file or directory according to the specified permissions. Common permissions include "r" (read), "w" (write), and "x" (execute).

    Example: chmod u+rwx file.txt (add read, write, execute permissions for the owner)

  2. chown <user>:<group> <file/directory>: Change the owner of a file or directory to the specified user and group.

    Example: chown user1:group1 file.txt (set the owner and group for file.txt)

Process and Service Management

  1. ps: List the running processes. This command displays a list of processes and their corresponding Process IDs (PID).

    Example: ps

  2. top: Display the running processes and system resources. This command provides an interactive interface to view running processes and monitor system resources such as CPU, RAM.

    Example: top

  3. kill <PID>: Terminate the process with the specified Process ID (PID). This command sends a signal to stop the process, allowing it to exit or shut down.

    Example: kill 1234 (terminate the process with PID 1234)

  4. systemctl start <service>: Start the specified service. A service is a program that runs in the background of the system, and this command starts it.

    Example: systemctl start httpd (start the Apache service)

  5. systemctl stop <service>: Stop the specified service. This command stops a running service.

    Example: systemctl stop httpd (stop the Apache service)

  6. systemctl restart <service>: Restart the specified service. This command stops and starts the service.

    Example: systemctl restart httpd (restart the Apache service)

  7. systemctl status <service>: Display the status of the specified service. This command shows whether the service is running or not, and its status.

    Example: systemctl status httpd (show the status of the Apache service)

Package Management

  1. yum install <package>: Install a software package from the CentOS repository.

    Example: yum install nginx (install Nginx)

  2. yum update <package>: Update the installed software package to the latest version.

    Example: yum update nginx (update Nginx)

  3. yum remove <package>: Remove an installed package from the system.

    Example: yum remove nginx (remove Nginx)

Network Management

  1. ifconfig: Display information about network devices and IP addresses of the system.

    Example: ifconfig

  2. ip addr: Display information about network devices and IP addresses of the system. This command is similar to ifconfig.

    Example: ip addr

  3. ping <hostname/IP>: Check network connectivity to a specified IP address or domain name by sending packets and waiting for a response.

    Example: ping google.com

  4. curl <URL>: Fetch content from a URL. This command is often used to download data from websites and display the results on the command line.

    Example: curl https://www.example.com

Command History Management

  1. history: Display the history of previously executed commands. This command lists the commands executed in the current session.

    Example: history


These are some of the common and useful command line commands in CentOS. Depending on your needs and purposes, you can use these commands to manage your system and perform basic tasks.