linux 命令几 例子,所有Linux命令例子

7c5ab77a580d3156e21195bae8ecf495.png

一旦熟悉了命令,在终端工作很容易,这就是为什么大多数Linux工作者更喜欢Linux终端而不是GUI。

本文将帮助你熟悉所有最常用的Linux命令及它用法,这些命令根据它的功能划分为15个部分。

系统相关命令

这些命令用于查看和管理Linux系统。2. cat /etc/redhat_release : Shows which version of redhat installed

5. last reboot : Shows system reboot history

8. w : Displays who is logged on and what they are doing

10. finger user : Displays information about user

11. reboot : Reboots the system

硬件相关命令

这些命令用于查看和管理Linux机器的硬件。14. cat /proc/cpuinfo : Displays information about processes and CPUs of the system

15. cat /proc/meminfo : Displays details on hardware memory

16. cat /proc/interrupts : Lists the number of interrupts per CPU per I/O device

17. lshw : Displays information on hardware configuration of the system. But this command must be run as super user or it will only report partial information

18. lsblk : Displays block device related information of the machine. With -a you can view all block devices

19. free -m : Shows used and free memory (-m for MB)

20. lspci -tv : Shows information on PCI buses devices

21. lsusb -tv : Shows information on USB devices

23. hdparm -i /dev/sda : Shows info about disk sda

hdparm -tT /dev/sda : Performs a read speed test on disk sda

24. badblocks -s /dev/sda : Tests for unreadable blocks on disk sda

统计相关命令

这些命令集用于查看Linux系统的各种状态25. mpstat 1 : Displays processors related statistics

26. vmstat 2 : Displays virtual memory statistics

27. iostat 2 : Displays I/O statistics

28. tail -n 500 /var/log/messages : Displays the last 500 kernel/syslog messages

29. tcpdump -i eth1 : Captures all packets flow on interface eth1. With -w switch you can specify a file where you can direct the output to

tcpdump -i eth0 'port 80' : Monitors all traffic on port 80 on interface eth0

30. lsof : Lists all open files belonging to all active processes

lsof -u testuser : Lists files opened by a specific user

31. free -m : Shows RAM memory details

32. watch df -h : Watches changeable disk usage continuously

用户相关命令

这些命令用于管理Linux用户33. id : Shows the active user and group information. With -G switch you can view the IDs of groups

34. last : Shows a list of last logins on the system. Using -a switch you can add the hostname to the last column of the output

35. who : Shows who is logged on the system

36. groupadd admin : Adds the group"admin"

37. useradd -c"Sam Tomshi" -g admin -m sam : Creates user"sam" and adds to group"admin"

38. userdel sam : Deletes user sam

39. adduser sam : Adds user"sam"

40. usermod : Modifies user information

41. passwd user1: Changes the password of user1

文件相关命令

这些命令用于处理文件和目录42. ls -al : Displays all information about files/directories. This includes displaying all hidden files as well

43. pwd : Shows current directory path

44. mkdir directory-name : Creates a directory

45. rm file-name : Deletes file

rm -r directory-name : Deletes directory recursively

rm -f file-name : Forcefully removes file

rm -rf directory-name : Forcefully removes directory recursively

46. cp file1 file2 : Copies linux files, here file1 to file2

cp -r dir1 dir2 : Copies dir1 to dir2, creates dir2 if it doesn't exist

47. mv file1 file2 : Moves files from one place to another/renames file1 to file2

48. ln -s /path/to/target-directory-name link-dir : Creates a symbolic link to link-dir

49. touch file : Creates empty file

50. cat file : Prints the file content in terminal

51. more file : Display the contents of file

52. head file : Display the first 10 lines of file

53. tail file : Outputs the last 10 lines of file

tail -f file : Outputs the contents of file as it grows starting with the last 10 lines

54. gpg -c file : Encrypts file

gpg file.gpg : Decrypts file

55. cksum file : View the checksum of the file

56. diff file1 file2 : View the differences between contents of file1 and file2

57. ln -s target-file link-file: Create a soft link named link-file to target-file

58. sort: Sorts files in alphabetical order

59. uniq: Compares adjacent lines in a file and removes/reports any duplicate lines

60. wc: Counts number of words/lines

61. dir: Lists the content of the directory

62. tee: Command for chaining and redirection

63. tr: Command for translating characters

处理相关命令

这些命令用于处理Linux进程64. ps : Displays your currently active processes

ps aux | grep 'telnet' : Displays all process ids related to telnet process

65. pmap : Display Memory map of process

66. top : Display all running processes and cpu/memory usage

67. kill pid : Kills process with mentioned pid

68. killall proc : Kills all processes named proc

69. pkill processname : Sends kill signal to a process with its name

70. bg : Resumes suspended jobs without bringing them to foreground

71. fg : Brings the most recent job to foreground

fg n : Brings job n to the foreground

文件权限相关命令

这些命令用于更改文件的权限72. chmod octal file-name : Changes the permissions of file to octal

chmod 777 /data/test.c : Sets rwx permission for owner , group and others

chmod 755 /data/test.c : Sets rwx permission for owner and rx for group and others

73. chown owner-user file : Changes owner of the file

chown owner-user:owner-group file-name : Changes owner and group owner of the file

chown owner-user:owner-group directory : Changes owner and group owner of the directory

74. chgrp group1 file : Changes the group ownership of the file to group1

网络相关命令

这些命令用于查看和编辑系统的相关方面的网络配置75. ifconfig -a : Displays all network interface and set ip address

76. ifconfig eth0 : Displays eth0 ethernet port ip address and details

77. ip addr show : Display all network interfaces and ip addresses

78. ip address add 192.168.0.1 dev eth0 : Sets ip address of eth0 device

79. ethtool eth0 : Linux tool to show ethernet status

80. mii-tool eth0 : Linux tool to show eth0 status

81. ping host : Sends echo requests to the host to test ipv4 connection

82. whois domain : Gets who is information for domain

83. dig domain : Gets DNS nameserver information for domain

dig -x host : Reverse lookup host

84. host google.com : Lookup DNS ip address for the name

85. hostname -i : Lookup local ip address

86. wget file : Downloads file

87. netstat -tupl : Lists all active listening ports

88. nslookup : Resolves domain names to IP addresses

压缩/存档相关命令

这些命令用于压缩和解压文件89. tar cf home.tar home : Creates a tar named home.tar containing home/

tar xf file.tar : Extracts the files from file.tar

tar czf file.tar.gz files : Creates a tar with gzip compression

90. gzip file : Compresses file and renames it to file.gz

91. bzip2 -z file : Compresses file and renames it to file.bz2

bzip2 -d file.bz2 : Decompress the file

软件包安装相关命令

这些命令用于管理Linux包92. rpm -i pkgname.rpm : Installs rpm based package

rpm -e pkgname : Removes package

93. make : Install from source file

搜索相关命令

这些命令用于搜索文件和模式94. grep pattern files : Searches for pattern in files

grep -r pattern dir : Searches recursively for pattern in dir

95. locate file : Finds all instances of file

96. find /home/tom -name 'index*' : Finds file names that start with"index" inside /home/tom directory

find /home -size +10000k : Finds files larger than 10000k in /home

登录相关命令

这些命令用于登录到另一个主机Securely connect to a host as user

98. telnet host : Connects to the system using telnet port

文件传输相关命令

这些命令用于将文件从一个系统复制到另一个系统99. scp file.txt server2:/tmp : Secure copy file.txt to remote host /tmp folder

scp [email protected]:/www/*.html /www/tmp : Copies *.html files from remote host to current host /www/tmp folder

scp -r [email protected]:/www /www/tmp : Copies all files and folders recursively from remote server to the current system /www/tmp folder

100. rsync -a /home/apps /backup/ : Synchronizes source to destination

rsync -avz /home/apps $ [email protected]:/backup : Synchronize files/directories between the local and remote system with compression enabled

磁盘使用相关命令

这些命令用于查看磁盘统计信息101. df -h : Shows free space on mounted filesystems

df -i : Shows free inodes on mounted filesystems

102. fdisk -l : Shows disks partitions sizes and types

103. du -ah : Displays disk usage in human readable form

du -sh : Displays total disk usage on the current directory

104. findmnt : Displays target mount point for all filesystems

105. mount device-path mount-point : Mounts a device to the device-path

目录遍历相关命令

这些命令用于更改目录106. cd .. : Goes up one level of the directory tree

cd : Goes to $HOME directory

cd /test : Changes to /test directory

结束语

在这个教程中,我们学习了几乎所有的linux命令,本文只关注对日常活动有用的最常见的命令,如果需要这些命令的更多信息,可以在linux上使用man命令。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值