File and Directory Management
-
ls
: List files and directories in the current directory. It displays the names of files and directories present in the current directory.Example:
ls
-
pwd
: Print the full path of the current directory. It helps you know where you are in the file system.Example:
pwd
-
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
-
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
-
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.Example:
cp file.txt /home/user/documents/
(copy a file)cp -r folder1 /home/user/documents/
(copy a directory)
-
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.Example:
mv file.txt /home/user/documents/file_new.txt
(rename a file)mv folder1 /home/user/documents/
(move a directory)
-
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
-
mkdir <directory>
: Create a new directory with the specified name.Example:
mkdir new_folder
-
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
-
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) -
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
-
ps
: List the running processes. This command displays a list of processes and their corresponding Process IDs (PID).Example:
ps
-
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
-
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) -
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) -
systemctl stop <service>
: Stop the specified service. This command stops a running service.Example:
systemctl stop httpd
(stop the Apache service) -
systemctl restart <service>
: Restart the specified service. This command stops and starts the service.Example:
systemctl restart httpd
(restart the Apache service) -
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
-
yum install <package>
: Install a software package from the CentOS repository.Example:
yum install nginx
(install Nginx) -
yum update <package>
: Update the installed software package to the latest version.Example:
yum update nginx
(update Nginx) -
yum remove <package>
: Remove an installed package from the system.Example:
yum remove nginx
(remove Nginx)
Network Management
-
ifconfig
: Display information about network devices and IP addresses of the system.Example:
ifconfig
-
ip addr
: Display information about network devices and IP addresses of the system. This command is similar toifconfig
.Example:
ip addr
-
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
-
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
-
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.