Basic Linux Operations Summary

Source: Internet
Author: User

Basic Linux Operations 0.Linux shortcut keys and common operations

01. Shortcut keys

01.tab : 命令行自动补全-自动补全当前的命令行。如果启用自动补全脚本命令参数和选项也可以自动补齐。02.ctrl-l : 清屏或者clear03.ctrl-a : 把光标移动到命令行最开始的地方。04.ctrl-e : 把光标移动到命令行末尾。05.ctrl-u : 清除命令行中光标所处位置之前的所有字符。06.ctrl-k : 清除从提示符所在位置到行末尾之间的字符07.ctrl-w : 清除左边的字段08.ctrl-y : 将会贴上被ctrl-u 或者ctrl-k 或者ctrl-w清除的部分。09.ctrl-D : 关闭窗口,结束任务。10.ctrl-C :  打断,强行停止。11.ctrl-r : 将自动在命令历史缓存中增量搜索后面入的字符。

02. Skill Operation
001.

0001.shift + 打印键0002.shift + Alt + 打印键0003.打印键

002. See if a language is supported

locale -a

003. Printing

echo
1. Log Off restart shutdown

Logou, reboot, shutdown

01.logou Logoff 02.reboot Restart
001.shutdown -r now #现在立即重启002.shutdown -r +3 #三分钟后重启003.shutdown -r 1212 #三分钟后重启
03.shutdown shutdown
001.shutdown -h now #现在立即关机002.shutdown -h +3  “The System will shutdown after 3 minutes” #提示使用者将在三分钟后关机003.shutdown -h +5  #  5分钟后关机004.shutdown -h 1200  # 12点钟关机005.shutdown -c   # 取消关机操作
2. Switch Directories

Cd

01. cd # 回到当前用户的家目录02. cd - # 切换到上一次的目录03.cd /etc # 切换到etc目录

Tips

01.~  #可用于表示用户家目录02. . #当前目录03. .. #上一级目录
3. View the current work path

Pwd

4. Create a directory (folder)

Mkdir

01. mkdir 目录名     #mkdir my_dir02.mkdir- p     #参数  递归创建目录,用于同时创建多级目录    
5. Create a file

Touch

01. 改变文件或目录的时间,文件不存在时会创建一个空文件。touch file1 # file1 不存在时被创建touch -c file1 # 不创建文件02.更改文件夹的时间戳touch -r ref_file file1 更新file1.txt的时间戳和ref+file相同touch -t 201210120505.25 file1

Note: If the file starts with ".", it means that the file is a hidden file.

6. Get Help

**01. -H

    1. --help
    2. Info
    3. man**

      001.man man  # 查看man命令的手册  002.man cd 003.man pwd 004.man 5 passwd #第五章内passwd内容005.man -k passwd # 模糊查找006.man -f  passwd  
      7. Change the password

      passwd
      ```

    4. passwd #修改当前用户密码
    5. sudo passwd username #更改制定用户密码, requires permission
      ```

      8. Delete

Rm

01.rm -f file1 # 强制删除文件02.rm -r a/b/file1 # 删除指定目录及其下的所有文件和目录03.rm -rf a/b/file1 # 强制删除指定目录及其下的所有文件和目录04.rm -i #提示后删除

RM command is too dangerous and is not recommended for use

9. Move or re-order files or directories

Mv

01.mv test.log test.txt # 文件改名02.mv test1.txt dir1/ #移动文件03.mv test1.txt test2.tx test3.tx dir1/ #移动多个文件
10. Copying

Cp

01.cp -i SOURCE DEST # 如果遇到需要覆盖的情况,则提示02.cp -r dir1 dir2 #若给出的源文件是一目录文件,此时cp将递归复制该目录下所有的子目录和文件。此时目标文件必须为一个目录名03.cp -p file1 file2 #此时cp除复制源文件的内容外,还将把其修改时间和访问权限也复制到新文件中。(需要权限)04.cp -rp dir1 dir2
11. View file-related information

Stat

stat file
12. View the contents of a file

Cat

01.cat file1 #显示 file1的文件内容02.cat file1 file2 # 显示file1和file2的文件内容03.cat -n file1 # 由1开始对所有输出的行数编号04.cat -s file # 当遇到连续2行以上的空白行,只保留一行空白行
13. Reverse View file Contents

Tac

Counts the number of bytes, words, and lines in the specified file, and displays the results of the statistics output

Wc

01.-c 统计字节数。02.-l 统计行数。03.-m 统计字符数。这个标志不能与 -c 标志一起使用。04.-w 统计字数。一个字被定义为由空白、跳格或换行字符分隔的字符串
14. Sorting

Sort

选项与参数:01.-r :反向排序;02.-n :使用『纯数字』进行排序(默认是以文字型态来排序的);03.-b :忽略最前面的空格符部分;04.-t :分隔符,默认是用 [tab] 键来分隔;05.-k :以那个区间 (field) 来进行排序的意思06.-f :忽略大小写的差异,例如 A 与 a 视为编码相同;07.-u :就是 uniq ,相同的数据中,仅出现一行代表;
15. Ignore or report duplicate rows

Uniq

选项与参数:01.-i :忽略大小写字符的不同;02.-c :进行计数03.-u :只显示唯一的行
16. You can extract text columns from a text file or text stream.

Cut

选项与参数:01.-d :后面接分隔字符。与 -f 一起使用;02.-f :依据 -d 的分隔字符将一段信息分割成为数段,用 -f 取出第几段的意思;03.-c :以字符 (characters) 的单位取出固定字符区间;
17. Read the standard input data and output its contents as a file

Tee

01.cat sec.log | tee file1 # 读取sec.log ,并生成file1文件02.cat sec.log | tee - a file1 # 读取sec.log ,并追加,03.cat sec.log |tee file1 file2
18. View executed Commands

History

01.history # 显示最近1000条历史命令02.history 5 # 显示最后5条命令03.!number# number为history之后命令前的序号:执行该条命令04.!cat,!299执行最后一条以cat开头的命令,执行299条命令
19. View file contents-Start from scratch

More

查看技巧:01.空格向下翻页02.b键向上翻页03.q退出其他技巧:alt+.查看最近一次输入内容
20. View the contents of the file-starting at the end

Less

21. Output File Start department, you can specify the number of lines, the default is 10 rows

Head

head -n 5 file
View the contents of the end of a file, showing the last 10 rows by default

Tall

tail file1tail -n 5 file1tail -f file1 # 动态监控文件
See where a command is located

which

Basic Linux Operations Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.