Linux is a powerful operating system that provides many commonly used command line tools that can help us manage files, directories, processes, networks, and system configurations. Here are some commonly used Linux commands:
1. ls: List files and subdirectories in the current directory
ls
2. pwd: displays the path of the current working directory
pwd
3. cd: switch working directory
cd /path/to/directory
4. mkdir: Create a new directory
mkdir directory_name
5. rmdir: delete empty directories
rmdir directory_name
6. rm: delete files or directories
rm file_name
rm -r directory_name # 递归删除目录及其内容
7. cp: copy files or directories
cp source_file destination
cp -r source_directory destination # 递归复制目录及其内容
8. mv: move or rename files or directories
mv old_name new_name
9. touch: Create an empty file or update the timestamp of a file
touch file_name
10. cat: concatenate and display file contents
cat file_name
11. more/less: Display text file content page by page
more file_name
less file_name
12. head/tail: Display the first or last few lines of the file
head -n 10 file_name # 显示文件的前10行
tail -n 20 file_name # 显示文件的后20行
13. grep: Search for specified text in a file
grep search_term file_name
14. ps: Display currently running processes
ps aux
15. kill: terminate the process
kill process_id
16. ifconfig/ip: View and configure network interface information
ifconfig
ip addr show
17. ping: Test connectivity to the host
ping host_name_or_ip
18. wget/curl: Download files from the network
wget URL
curl -O URL
19. chmod: Modify the permissions of a file or directory
chmod permissions file_name
20. chown: Modify the owner of a file or directory
chown owner:group file_name
21. tar: used to compress and decompress files and directories
tar -czvf archive.tar.gz directory_name # 压缩目录
tar -xzvf archive.tar.gz # 解压文件
22. df/du: Display disk usage
df -h # 显示磁盘空间使用情况
du -h directory_name # 显示目录的磁盘使用情况
The output is:
(wzk_base) wangzhenkuan@pc-System-Product-Name:~$ df -h
文件系统 大小 已用 可用 已用% 挂载点
tmpfs 6.2G 2.9M 6.2G 1% /run
/dev/nvme0n1p3 861G 288G 530G 36% /
tmpfs 31G 0 31G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/nvme0n1p1 511M 6.1M 505M 2% /boot/efi
/dev/sda 1.8T 1.2T 521G 71% /home
tmpfs 6.2G 112K 6.2G 1% /run/user/1000
tmpfs 6.2G 68K 6.2G 1% /run/user/1001
tmpfs 6.2G 68K 6.2G 1% /run/user/1003
tmpfs 6.2G 68K 6.2G 1% /run/user/1008
tmpfs 6.2G 68K 6.2G 1% /run/user/1006
tmpfs 6.2G 72K 6.2G 1% /run/user/1005
23. mount/umount: Mount and unmount file systems
mount /dev/sdX1 /mnt # 挂载分区到指定目录
umount /mnt # 卸载挂载的文件系统
24. psql/mysql: Command line tool for interacting with PostgreSQL or MySQL databases
psql -U username -d database_name # 连接到PostgreSQL数据库
mysql -u username -p # 连接到MySQL数据库
25. top/htop: Displays real-time usage of system resources and process information
top
htop
26. ssh: remote login to other computers
ssh username@remote_host
27. scp: securely copy files from local to remote host, or from remote host to local
scp local_file remote_user@remote_host:/remote/directory
28. find: Find files and directories in the file system
find /path/to/search -name "file_pattern"
29. grep: Search for matching lines in text and can use regular expressions for advanced searches
grep -r "pattern" /path/to/search
30. sed: stream editor for text processing and replacement
sed 's/old_text/new_text/' file_name
31. awk: Text processing tool for text processing and data extraction
awk '{print $1}' file_name # 提取文件中的第一列数据
32. ssh-keygen: Generate SSH key pairs for authenticating to remote servers
ssh-keygen -t rsa
33. date: Display or set the system date and time
date
34. echo: Output text to standard output
echo "Hello, World!"
35. ln: Create a hard link or symbolic link
ln source_file link_name # 创建硬链接
ln -s source_file link_name # 创建符号链接
36. uname: display system information
uname -a
37. shutdown/reboot: shut down or restart the system
shutdown -h now # 立即关闭系统
reboot # 重新启动系统
38. who/w: displays the currently logged in user information
who
w
39. curl: used to interact with network resources and supports various protocols
curl -X GET http://example.com
40. zip/unzip: used to compress and decompress ZIP files
zip archive.zip file1 file2 # 压缩文件
unzip archive.zip # 解压ZIP文件
41. chmod/chown: Modify the permissions and owners of files or directories
chmod permissions file_name # 修改文件权限
chown owner:group file_name # 修改文件所有者
42. useradd/userdel: used to add and delete user accounts
useradd new_user # 添加用户
userdel username # 删除用户
43. passwd: change user password
passwd username
44. cron: scheduled task manager, used to automatically execute scheduled tasks
crontab -e # 编辑用户的定时任务
45. uptime: Displays the running time and load of the system
uptime
46. hostname: Display or set the host name of the computer
hostname # 显示主机名
47. iptables/ufw: used to configure firewall rules
iptables -A INPUT -p tcp --dport 80 -j ACCEPT # 允许HTTP流量
ufw enable # 启用Uncomplicated Firewall
48. netstat/ss: Display network connection information
netstat -tuln # 显示所有TCP和UDP端口
ss -tuln # 使用Socket Stat查看网络连接
49. ps/top/htop: Display process information and system resource usage
ps aux # 显示所有进程
top # 实时监视系统资源
htop # 更友好的进程监视器
50. history: View command history
history
51. free: Display system memory usage
free -m # 以MB为单位显示内存使用情况
52. lsblk/fdisk: View disk partition information and manage disks
lsblk # 显示块设备信息
fdisk /dev/sdX # 打开磁盘分区工具
53. nc: used for network connection testing and data transmission
nc -vz host_name_or_ip port # 测试主机的端口是否可达
54. stat: Display detailed information of a file or directory
stat file_or_directory
55. nmcli: Command line tool for managing network connections
nmcli connection show # 显示网络连接信息
56. tailf: real-time tracking of the end of the file, similar to tail -f
tailf file_name
57. scp: Safely copy files from local to remote host, or from remote host to local
scp local_file remote_user@remote_host:/remote/directory # 从本地到远程
scp remote_user@remote_host:/remote/file local_directory # 从远程到本地
58. rsync: used to synchronize files and directories between local and remote systems
rsync -avz source_directory/ remote_user@remote_host:/remote/directory/
59. dd: used to copy and convert files
dd if=input_file of=output_file bs=block_size
60. sudo: Run commands with superuser privileges
sudo command_to_run_as_superuser
The sudo command allows ordinary users to execute commands that require superuser privileges, provided they have the corresponding permissions in the sudoers file. This is a critical tool to ensure system security and should be used with caution.