有用的Linux命令整理(不断积累中)
2017-12-22 09:12
302 查看
System
1. man command —— show the manual for command$ man whereis
2. whereis app —— show possible locations of app$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/share/man/man1/gcc.1.gz
3. which app —— show which app will be run by default$ which gcc
/usr/bin/gcc
4. whoami —— show your username (who you are logged in as)$ whoami
airobot
File/Directory Basics
5. pwd —— show the present working directory$ pwd
/home/airobot/Desktop/dev
6. cdcd dir —— change directory to dircd .. —— go up one directorycd / —— go to the root directorycd ~ —— go to your home directorycd - —— go to the last directory you were just in
File Viewing
7. cat —— output the contents of file
8. head —— output the first 10 lines of file
9. tail —— output the last 10 lines of file
10. nl —— number lines
File Properties/Permissions
11. file —— identify file types12. stat —— display file attributes
13. chmod ugo file —— change permissions of file to ugo, where u is the user's permission, g is the group's permissions, and o is the everyone else's permission. The walues of u, g, and o can bu any number between 0 and 7. (4: read, 2: write, 1: execute)e.g.
chmod 777: read, write, execute for all (参考上图中给出的例子)
chmod 755: rwx for owner, everyone else can rxchmod 600: you can read and writechmod 644: you can read and wirte, and everyone else can only read
14. chgrp —— change file group15. chown —— change file owner
IO Redirection16. cat > file —— places standard input to file
例如,在下图中,我们首先在命令上输入 cat > my_file,然后系统会自动在当前文件夹下创建一个名为my_file的文件,然后我们在Terminal上输入的文字将被写入my_file中,直到我们在键盘上输入CTRL + d 时返回。这时我们打开my_file文件,可以发现之前的内容已经被成功写入了。
17. cmd > file —— Standard output (stdout) of cmd to file
18. cmd >> file —— Append stdout to file
Process Management
19. ps —— show snapshot of processes
ps命令用于报告当前系统的进程状态。可以搭配kill指令随时中断、删除不必要的程序。ps命令是最基本同时也是非常强大的进程查看命令,使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等,总之大部分信息都是可以通过执行该命令得到的。
20. top —— show real time processes
top命令可以实时动态地查看系统的整体运行情况,是一个综合了多方信息监测系统性能和运行信息的实用工具。通过top命令所提供的互动式界面,用热键可以管理。
21. kill pid —— kill process with id pid22. pkill name —— kill process with name name
23. killall name —— kill all processes with names beginning name
Searching24. locate file —— find all instances of file using indexed database built from the updatedb command. Much faster than find
25. grep pattern files —— search for pattern in filesgrep -i : case insensitive searchgrep -o : only show matched part of file
26. grep -r pattern dir —— search recursively for pattern in dir
27. grep -rn pattern dir —— search recursively for pattern in dir and show the line number found
28. command | grep pattern —— search for pattern in the output of command
Pipes and Command Lists
29. cmd1 | cmd2 —— stdout of cmd1 to cmd2
30. cmd1 |& cmd2 —— stderr of cmd1 to cmd2
31. cmd1 ; cmd2 —— run cmd1 then cmd2
32. cmd1 && cmd2 —— run cmd2 if cmd1 is successful
33. cmd1 || cmd2 —— run cmd2 if cmd1 is unsuccessfull
ShortcutsCTRL+c —— stop current command
CTRL+w —— erases one word in the current line
CTRL+u —— erases the whole line
CTRL+a —— move cursor to the beginning of lineCTRL+e —— move cursor to the end of line
CTRL+b —— move cursor backward one character
CTRL+f —— move cursor forward one character
ALT+b —— move cursor backward one word
ALT+f —— move cursor forward one word
参考http://gnulinux.guru/bash_cheatsheet.pdfhttp://man.linuxde.net/
1. man command —— show the manual for command$ man whereis
2. whereis app —— show possible locations of app$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/share/man/man1/gcc.1.gz
3. which app —— show which app will be run by default$ which gcc
/usr/bin/gcc
4. whoami —— show your username (who you are logged in as)$ whoami
airobot
File/Directory Basics
5. pwd —— show the present working directory$ pwd
/home/airobot/Desktop/dev
6. cdcd dir —— change directory to dircd .. —— go up one directorycd / —— go to the root directorycd ~ —— go to your home directorycd - —— go to the last directory you were just in
File Viewing
7. cat —— output the contents of file
8. head —— output the first 10 lines of file
9. tail —— output the last 10 lines of file
10. nl —— number lines
File Properties/Permissions
11. file —— identify file types12. stat —— display file attributes
13. chmod ugo file —— change permissions of file to ugo, where u is the user's permission, g is the group's permissions, and o is the everyone else's permission. The walues of u, g, and o can bu any number between 0 and 7. (4: read, 2: write, 1: execute)e.g.
chmod 777: read, write, execute for all (参考上图中给出的例子)
chmod 755: rwx for owner, everyone else can rxchmod 600: you can read and writechmod 644: you can read and wirte, and everyone else can only read
14. chgrp —— change file group15. chown —— change file owner
IO Redirection16. cat > file —— places standard input to file
例如,在下图中,我们首先在命令上输入 cat > my_file,然后系统会自动在当前文件夹下创建一个名为my_file的文件,然后我们在Terminal上输入的文字将被写入my_file中,直到我们在键盘上输入CTRL + d 时返回。这时我们打开my_file文件,可以发现之前的内容已经被成功写入了。
17. cmd > file —— Standard output (stdout) of cmd to file
18. cmd >> file —— Append stdout to file
Process Management
19. ps —— show snapshot of processes
ps命令用于报告当前系统的进程状态。可以搭配kill指令随时中断、删除不必要的程序。ps命令是最基本同时也是非常强大的进程查看命令,使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等,总之大部分信息都是可以通过执行该命令得到的。
20. top —— show real time processes
top命令可以实时动态地查看系统的整体运行情况,是一个综合了多方信息监测系统性能和运行信息的实用工具。通过top命令所提供的互动式界面,用热键可以管理。
21. kill pid —— kill process with id pid22. pkill name —— kill process with name name
23. killall name —— kill all processes with names beginning name
Searching24. locate file —— find all instances of file using indexed database built from the updatedb command. Much faster than find
25. grep pattern files —— search for pattern in filesgrep -i : case insensitive searchgrep -o : only show matched part of file
26. grep -r pattern dir —— search recursively for pattern in dir
27. grep -rn pattern dir —— search recursively for pattern in dir and show the line number found
28. command | grep pattern —— search for pattern in the output of command
Pipes and Command Lists
29. cmd1 | cmd2 —— stdout of cmd1 to cmd2
30. cmd1 |& cmd2 —— stderr of cmd1 to cmd2
31. cmd1 ; cmd2 —— run cmd1 then cmd2
32. cmd1 && cmd2 —— run cmd2 if cmd1 is successful
33. cmd1 || cmd2 —— run cmd2 if cmd1 is unsuccessfull
ShortcutsCTRL+c —— stop current command
CTRL+w —— erases one word in the current line
CTRL+u —— erases the whole line
CTRL+a —— move cursor to the beginning of lineCTRL+e —— move cursor to the end of line
CTRL+b —— move cursor backward one character
CTRL+f —— move cursor forward one character
ALT+b —— move cursor backward one word
ALT+f —— move cursor forward one word
参考http://gnulinux.guru/bash_cheatsheet.pdfhttp://man.linuxde.net/
相关文章推荐
- Windows命令模式(DOS)下几个比较有用的命令(不断更新整理)
- 有用的Linux命令总结(不断更新中)
- Linux命令整理(不断更新中)
- 一些有用的mysql语句(不断积累更新)
- [整理]有用的SQL语句(不断增加)
- 平时整理的非常实用的linux命令
- 【FastReport】问题整理(不断更新)
- eclipse最有用快捷键整理
- 整理:对开发者有用的英文网站合集
- java有用代码段整理
- 有用资源的整理集合
- 整理的40个有用的jQuery技术和教程
- 不断学习,每天进步一点点【图像,计算机视觉,机器学习,学习积累】
- [原创] QTP 小技巧不断积累更新(…
- 一些有用的linux命令和技巧
- 我自己常用的linux命令及使用技巧(不断完善中)
- Linux命令整理
- 记录css样式及html标签属性!不断积累
- 关于js中date用法(不断整理)
- Java开发中最常用的Linux命令整理