Home >Operation and Maintenance >CentOS >A complete collection of commonly used basic commands for CentOS
This article answers your questions regarding crucial CentOS commands, covering file management, network troubleshooting, and system administration.
This section details a selection of fundamental CentOS commands, categorized for clarity. Remember that the full power of the shell comes from combining these commands with redirection and piping.
File and Directory Management:
ls
(list): Displays the contents of a directory. Use options like -l
(long listing, showing permissions, size, etc.), -a
(show hidden files), and -h
(human-readable sizes). Example: ls -l /etc
cd
(change directory): Navigates to a different directory. Example: cd /home/user
mkdir
(make directory): Creates a new directory. Example: mkdir new_directory
rmdir
(remove directory): Removes an empty directory. Example: rmdir empty_directory
rm
(remove): Deletes files or directories. Use with caution! rm -r
recursively deletes directories and their contents. rm -f
forces removal without prompting. Example: rm file.txt
cp
(copy): Copies files or directories. Example: cp file.txt backup.txt
mv
(move): Moves or renames files or directories. Example: mv file.txt new_file.txt
touch
: Creates an empty file or updates a file's timestamp. Example: touch new_file.txt
cat
(concatenate): Displays the contents of a file. Example: cat file.txt
less
: Displays the contents of a file page by page. Use spacebar to scroll down, 'b' to scroll up, and 'q' to quit. Example: less file.txt
head
: Displays the first few lines of a file. Example: head file.txt
tail
: Displays the last few lines of a file. Useful for monitoring log files. Example: tail -f log.txt
(the -f
option follows the file as it grows)find
: Searches for files and directories based on various criteria. Example: find /home -name "*.txt"
System Information and Processes:
uname -a
: Shows system information (kernel version, hostname, etc.).df -h
: Displays disk space usage in a human-readable format.du -sh *
: Shows disk usage of files and directories in the current directory.top
: Displays real-time system processes.ps aux
: Shows a snapshot of currently running processes.kill <PID>
: Terminates a process (replace <PID>
with the process ID).This is not an exhaustive list, but it covers many essential commands for everyday use.
The essential CentOS commands for managing files and directories are those listed in the previous section under "File and Directory Management." These commands allow you to create, delete, move, copy, rename, view, and search for files and directories. Mastering these commands is fundamental to effective system administration in CentOS. Pay close attention to the options available for each command, as they significantly enhance functionality and control. For instance, understanding the -r
(recursive) option for rm
is crucial to avoid accidental data loss.
Troubleshooting network connectivity often involves a combination of commands. Here are some key ones:
The above is the detailed content of A complete collection of commonly used basic commands for CentOS. For more information, please follow other related articles on the PHP Chinese website!