Date:2022-08-15

指定运行级别

:::info 0:关机
1:单用户【找回丢失密码】
2:多用户状态没有网络服务
3:多用户状态有网络服务
4:系统为使用保留给用户
5:图形界面
6:系统重启 :::

常用运行级别是35,也可以指定默认运行级别

  1. init 0
  2. init 1
  3. //....
  4. //获取当前运行级别
  5. systemctl get-default
  6. //设置默认运行级别 reboot后生效
  7. systemctl set-default multi-user.target
  8. systemctl set-default graphical.target

找回root密码

  1. reboot
  2. 找到以 Linux16开头内容所在的行数,在行的最后输入
  3. init=/bin/sh
  4. 然后按ctrl + x进入单用户模式
  5. 在光标闪烁的位置输入:mount -o remount,rw /
  6. 输入 passwd
  7. 输入两次密码
  8. touch /.autorelabel
  9. exec /sbin/init (此过程略长,请等待)

帮助指令

man + ls help 在linux下是以 . 开头的

  1. cp code.txt copy
  2. cp sub_dir/file copy
  3. cp sub_dir/sub_dir_1/now /nobody
  4. mv code.txt temp
  5. mv code_1.txt temp/sub_dir_1
  6. mv temp/code.txt /nobody/sub_dir/code.txt
  7. mv ./target ./des/
  8. mv ./sub_dir_1/sub_dir ./sub_dir_2/
  9. mv ./sub_dir_1/temp .
  10. rm code.txt
  11. rm sub_dir/code.txt
  12. rm sub_dir_1/sub_dir_1_1/code.txt
  13. pwd
  14. cd sub_dir
  15. pwd
  16. cd ..
  17. pwd
  18. cd sub_dir/sub_dir_2
  19. cd ..
  20. cd ../sub_dir_1/sub_dir_1_1
  21. ls
  22. ls -a
  23. ls -l
  24. diff file1 file2
  25. diff -i file1 file4
  26. diff -b file1 file3
  27. df
  28. df -a
  29. df -T
  30. name='Jack'
  31. echo name
  32. echo $name
  33. stat temp1
  34. stat -f temp1
  35. stat *
  36. cat file1
  37. awk '{print $1,$4}' file1
  38. cat file2
  39. awk -F, '{print $1,$4}' file2
  40. grep test file1
  41. ##########
  42. grep test file*
  43. ##########
  44. grep -c test file*
  45. cat main.c
  46. grep test *.c
  47. grep -A1 test *.c
  48. grep -B1 test *.c
  49. cat file1
  50. ##########
  51. cat file2
  52. ##########
  53. comm file1 file2
  54. ##########
  55. comm file2 file1
  56. a=1,b=2
  57. let a=1,b=2
  58. let c=a+b
  59. let a++
  60. echo $a $b $c
  61. fold temp
  62. fold -w 12 temp
  63. fold -s -w 12 temp
  64. ls -l
  65. ln temp.txt h-temp.txt
  66. ls -l
  67. ln -s /nobody/tmp /nobody/create-link-here/s-tmp
  68. find -iname "apple*"
  69. find -type f ! -size 0
  70. find sub_dir -type f -size 0 > file
  71. nl file
  72. nl file | sed '2,5c these are 2-5 contents of file'
  73. nl file | sed -n '5,70p'
  74. nl file
  75. sed 88d file
  76. nl file | sed 88,99d
  77. nl file
  78. sed 88a'Hello world!' file
  79. sed 99i'Hello world!' file
  80. nl file
  81. echo $PATH
  82. which echo
  83. which du
  84. echo "Hello world!"
  85. ##########
  86. echo '"Hello world!"'
  87. ##########
  88. echo "Hello\nworld!"
  89. ##########
  90. echo -e "Hello\nworld!"
  91. cat file
  92. ##########
  93. od -c file
  94. ##########
  95. od -t d1 file
  96. cat file
  97. ##########
  98. od file
  99. ##########
  100. od -d file
  101. ##########
  102. od -x file
  103. ##########
  104. od -A n file
  105. ls -l
  106. ##########
  107. ln -s temp.txt s-temp.txt
  108. ##########
  109. ls -l
  110. ##########
  111. ln -sb temp2.txt s-temp.txt
  112. cut -b 4 temp.txt
  113. ##########
  114. cut -b 1,2,3 temp.txt
  115. ##########
  116. cut -c 2 temp.txt
  117. ##########
  118. cut -d @ -f 1 temp.txt
  119. less file1
  120. ##########
  121. less file2
  122. ##########
  123. cmp file1 file2
  124. id
  125. ##########
  126. id -un
  127. ##########
  128. id -ur
  129. whoami
  130. id -un
  131. id -gn
  132. cut -b 4 temp.txt
  133. ##########
  134. cut -b 1,2,3 temp.txt
  135. ##########
  136. cut -c 2 temp.txt
  137. ##########
  138. cut -d @ -f 1 temp.txt
  139. comm file1 file2 -2 -3
  140. ##########
  141. comm file1 file2 -2
  142. ##########
  143. comm file1 file2 -1 -2

LintCode-Linux合集