[b]
Linux命令大全:
[url]http://ss64.com/bash/[/url][/b]
unix命令:
Quick Reference: Unix Commands:
[url]http://www.washington.edu/computing/unix/unixqr.html#O[/url]
What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?
[url]http://unix.stackexchange.com/questions/4126/what-is-the-exact-difference-between-a-terminal-a-shell-a-tty-and-a-con[/url][quote]In unix terminology, the short answer is that
terminal = tty = text input/output environment
console = physical terminal
shell = command line interpreter[/quote]
[b]Common commands: [/b]
Shell scripting and more useful commands:
[url]http://docs.jboss.org/jbossaop/docs/2.0.0.GA/docs/aspect-framework/reference/en/html/pointcuts.html[/url]
[b]查看 Text files 文件内容的命令s:[/b]
[url]http://www.freemacunix.com/viewing-text-files-cat-head-tail-more-less/[/url]
[url]http://linuxfrombeginning.wordpress.com/2008/09/19/linux/[/url]
[b]文件转码、编码、encoding、charset 相关:[/b]
[b]压缩及解压缩(Compress & Decompress)相关命令:[/b]
tar 常用参数:
-x:eXtract 解压
-v:verbose
-c:create 打包成 tar 包。
-f:File ame,标识跟在这个参数后的为压缩或解压的文件的名字
-z:标识压缩成 tar.gz(即 gzip)。
-t or --file:list content,不解压,只是查看压缩包中的文件列表。
-C:指定解压到的目录。
[url]http://www.cyberciti.biz/howto/question/general/compress-file-unix-linux-cheat-sheet.php[/url]
link 相关命令:
[url]http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/[/url][quote]link分两种:hard link 和 soft link(也叫 symbolic link)。
hard link 只能为文件创建,不能为文件夹创建;[/quote]
[b]文件查找命令s:[/b] ---待完善with chrome quick note。 grep find locate
[url]http://www.vogella.com/articles/Ubuntu/article.html[/url]
[url]https://www.google.com/search?num=100&hl=en&newwindow=1&safe=off&tbo=d&site=webhp&source=hp&q=grep+find+locate&oq=grep+find+locate+&gs_l=hp.3.0.0i30j0i5i30j0i8i30.1030.8783.0.10434.29.20.7.2.2.0.118.1669.17j3.20.0.les%3B..0.0...1c.1.2.hp.apAhTOivpgc[/url]
[b]Finding all files containing a text string | 递归查找指定目录下的文件中,其内容包含指定字符串的所有文件(强大的grep):[/b]
[url]http://stackoverflow.com/questions/16956810/finding-all-files-containing-a-text-string-on-linux[/url]
[color=red][b]find:[/b][/color]
[url]http://www.grymoire.com/Unix/Find.html[/url]
7 Linux Grep OR, Grep AND, Grep NOT Operator Examples:
[b][url]http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/[/url][/b]
sed awk cut: 待完善:
sed awk grep的区别:
[url]http://stackoverflow.com/questions/7727640/differences-among-grep-awk-and-sed[/url]
cut:
[url]http://www.computerhope.com/unix/ucut.htm[/url]
[url]http://lowfatlinux.com/linux-columns-cut.html[/url]
[b]$ grep 'Bounces' 2013-02-18.log | grep 'androidlaunch' | cut -d'|' -f11 | sort -n | uniq -c | grep -v 'sohu' | less -S[/b]
[b]$ grep 'Bounces' 4939-2013-02-18.log | awk -F'|' '{print $5"|"$11}' | awk -F'@' '{print $2}' | sort | uniq -c | sort -nr | less -S[/b]
[color=red][b]awk:[/b][/color]
[url]http://www.grymoire.com/Unix/Awk.html[/url]
8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR:
[url]http://www.thegeekstuff.com/2010/01/8-powerful-awk-built-in-variables-fs-ofs-rs-ors-nr-nf-filename-fnr/[/url][quote]awk 例子:
下列文本:
[url]http://www.grymoire.com/Unix/Sed.html[/url]
Sed Explained, Part 1:
[url]http://www.linuxforu.com/2011/04/sed-explained-part-1/[/url]
Sed Explained, Part 2: Data Structures and Operators:
[url]http://www.linuxforu.com/2011/06/sed-part-2-data-structures-and-operators/[/url]
[url]http://www.gnu.org/software/sed/manual/sed.html[/url]
常用举例:
[b][url]http://www.unixguide.net/unix/sedoneliner.shtml[/url][/b]
文件的 split & merge:
[b]wget & curl:[/b]
[url]http://www.thegeekstuff.com/2012/07/wget-curl/[/url]
[b]curl & wget 比较之 download[/b][quote]
[b][url]http://blog.kyplex.com/2011/03/curl-wget-password-protected-pages.html[/url][/b]
[b]ssh & scp:[/b]
[url]http://chamibuddhika.wordpress.com/2012/03/21/ssh-tunnelling-explained/[/url]
[url]http://blog.jlank.com/2011/05/16/ssh-tunneling-with--l/[/url]
[url]http://stackoverflow.com/questions/9447226/how-to-close-this-ssh-tunnel[/url][quote]选项说明:
-f [b][color=red]=[/color][/b] fork process into background,相当于shell下的 &
-N [b][color=red]=[/color][/b] don't run any commands remotely (w/o this -f will complain。指定这个选项则登陆远程主机后不会出现命令提示符)
-L [bind_address:]port_of_bind_address:host:hostport [b][color=red]=[/color][/b] binds the port [i][u]port_of_bind_address[/u][/i] of [u][i]bind_address[/i][/u](可省略,若省略则默认为localhost) to the port [u][i]hostport[/i][/u] on host [u][i]host[/i][/u]
例子:使用 ssh forwarding 连接远程 mysql:
场景:
mysql 实例在 remote-mysql-server 上,且在本地无权限通过ssh直接登陆该主机或通过 mysql command line 连接该主机上的 mysql instance。
remote-another-server 是和 remote-mysql-server 在同一局域网的另一个远程主机(隐意是可以在该主机上通过 mysql command line 登陆 remote-mysql-server 上的 mysql instance),且本地有权限通过 ssh 登陆该远程主机。
步骤:
1. 本地启动 ssh forwarding:
[b]技巧性组合命令:[/b]
[b]用户相关命令:[/b]
[b]System Information Commands:[/b]
[b]1 df (abbreviated from disk free)[/b]: The df command displays filesystem disk space usage for all mounted partitions. "df -h" is probably the most useful - it uses megabytes (M) and gigabytes (G) instead of blocks to report. (-h means "human-readable")
[b]2 du (abbreviated from disk usage)[/b]: The du command displays the disk usage for a directory. It can either display the space used for all subdirectories or the total for the directory you run it on.-s means "Summary" and -h means "Human Readable".
[b]4 top[/b]: The top ('table of processes') command displays information on your Linux system, running processes and system resources, including CPU, RAM & swap usage and total number of tasks being run. To exit top, press "q".
[b]5 uname -a[/b]: The uname command with the -a option prints all system information, including machine name, kernel name & version, and a few other details. Most useful for checking which kernel you're using.
[b]6 lsb_release -a[/b]: The lsb_release(lsb stands for Linux Standard Base) command with the -a option prints version information for the Linux release you're running, for example:
[b]7 ip addr[/b]: reports on your system's network interfaces.
[b]8 ifconfig[/b]: (short for interface configuration) is a system administration utility in Unix-like operating systems to configure, control, and query TCP/IP network interface.
证书 ca certificate 相关命令:
[url]https://code.google.com/p/chromium/wiki/LinuxCertManagement[/url]
[url]http://blog.avirtualhome.com/adding-ssl-certificates-to-google-chrome-linux-ubuntu/[/url]
[url]http://superuser.com/a/657177/175890[/url]
[url]http://www.autistici.org/en/stuff/man_ca/linux.html[/url]
Linux DNS Lookup utilities:
1 dig(domain information groper):
[url]http://linux.die.net/man/1/dig[/url]
[url]http://www.thegeekstuff.com/2012/02/dig-command-examples/[/url]
2 host
3 nslookup
另附DNS 记录类型:
[url]http://en.wikipedia.org/wiki/List_of_DNS_record_types[/url]
linux命令中什么时候使用引号,及使用双引号还是单引号:
UNIX SHELL Quote Tutorial:
[url]http://www.grymoire.com/Unix/Quote.html[/url]
[b]一些 linux/unix 命令/缩写词 的含义:
What does {some strange unix command name} stand for?
[url]http://www.unixguide.net/unix/faq/1.3.shtml[/url][/b][quote]cli:Command Line Interface[/quote]
[b]Linux Commands Chaining(Grouping):[/b]
[url]http://sayle.net/book/basics.htm#grouping_commands[/url][quote][b]1 Semicolon 分号 [color=red];[/color] [/b]
顺序执行分号分割的多个命令,不管 ; 分割的各个命令执行结果如何。
[b]2 double ampersands [color=red]&&[/color][/b]
当且仅当 && 前的命令返回状态码为0(表示执行成功),才执行 && 后的命令
[b]3 double vertical bars [color=red]||[/color][/b]
当且仅当 || 前的命令返回状态码为非0(即执行失败),才执行 || 后的命令
The parentheses, when grouped around a command, [b]cause the command to be executed in a subshell[/b]. Any environmental changes occuring within the subshell do not persist beyond its execution; in other words, [b]all changes to the working environment of the commands issued within the parentheses do not affect the working shell. [/b]
Like parentheses, curly braces can be used to group a set of commands; however, the commands execute within the context of the current shell. And some restrict: [b]Inside the curly braces, White space precedes and follows the enclosed commands, and a semicolon terminates the last command are required.[/b]
技巧:
Disable Line Wrapping In Terminal:
[url]http://ubuntuforums.org/showthread.php?t=1066656[/url][quote]1 使用 some_command | less -S
2 [url]http://software.jessies.org/terminator/#downloads[/url][/quote]
Linux命令大全:
[url]http://ss64.com/bash/[/url][/b]
unix命令:
Quick Reference: Unix Commands:
[url]http://www.washington.edu/computing/unix/unixqr.html#O[/url]
What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?
[url]http://unix.stackexchange.com/questions/4126/what-is-the-exact-difference-between-a-terminal-a-shell-a-tty-and-a-con[/url][quote]In unix terminology, the short answer is that
terminal = tty = text input/output environment
console = physical terminal
shell = command line interpreter[/quote]
[b]Common commands: [/b]
//output the path of the current working directory. (stands for Print Working Directory, or Present Working Directory)
$ pwd
//执行上个命令
$ !!
// &: runs the whole thing in the background, giving you your prompt back immediately.
$ someCommand &
//alias of ls -la
$ ll
//list all file(except . & ..), and human readable format(-h代表human readable,会将文件和文件夹的大小用K,M,G等表示)
$ ls -lAh
//清屏
$ clear(or 快捷键ctrl+l) or reset
//查看一个命令的实际执行脚本文件
$ which sh
$ type -a sh
//To navigate into the root directory
$ cd /
//To navigate to your home directory, use
$ cd ~ (or only cd)
//To navigate up one directory level
$ cd ..
//To navigate to the previous directory (or back)
$ cd -
//查看包含‘aplus’串的进程
$ ps -ef | grep aplus
//输出环境变量 JAVA_HOME 的值
$ echo $JAVA_HOME
$ printenv JAVA_HOME
//查看当前的所有环境变量
$ env or printenv or export
//拷贝文件或目录,如果是拷贝目录必须添加参数"-r" (recursively)
cp oriFile destFile
cp -r oriDirectory destDirectory
//删除文件或目录,如欲删除目录必须加上参数"-r"
rm -fr ./aplusdev/
//将一个文件或目录移动到指定的目录
$ mv beenMovedFileOrDir destDir
//检查文件或文件夹的类型
$ file fileOrDirName
//查找当前路径下名称中含有“mysql”的文件夹/文件
find . -name "mysql"
参考:
Shell scripting and more useful commands:
[url]http://docs.jboss.org/jbossaop/docs/2.0.0.GA/docs/aspect-framework/reference/en/html/pointcuts.html[/url]
[b]查看 Text files 文件内容的命令s:[/b]
[url]http://www.freemacunix.com/viewing-text-files-cat-head-tail-more-less/[/url]
[url]http://linuxfrombeginning.wordpress.com/2008/09/19/linux/[/url]
$ cat fileName
$ less fileName
$ more fileName
$ head -显示行数 fileName
$ tail -显示行数 fileName
# tail文件,并且不管其被重建多少次(gentoo 4.3 下单独使用 -F 无效,需加 ---disable-inotify,参见 https://lists.gnu.org/archive/html/bug-coreutils/2011-08/msg00041.html)
$ tail -F ---disable-inotify data/log/logback.log
[b]文件转码、编码、encoding、charset 相关:[/b]
# 将 windows系统下导出的 gbk 编码的csv文件编码改成 utf8
$ iconv -f gbk -t utf8 fileName.csv > fileName_u8.csv
# 如果碰上无法转的字符(可能原因是原文件中某行数据在gbk下本就已经是乱码),则可以使用 ignoring (//IGNORE) or approximating (//TRANSLIT) 来处理(http://stackoverflow.com/questions/7688464/iconv-unicode-unknown-input-format, http://spin.atomicobject.com/2011/07/13/some-useful-iconv-functionality/):
$ iconv -f gbk -t utf8//IGNORE fileName.csv > fileName_u8.csv
[b]压缩及解压缩(Compress & Decompress)相关命令:[/b]
tar 常用参数:
-x:eXtract 解压
-v:verbose
-c:create 打包成 tar 包。
-f:File ame,标识跟在这个参数后的为压缩或解压的文件的名字
-z:标识压缩成 tar.gz(即 gzip)。
-t or --file:list content,不解压,只是查看压缩包中的文件列表。
-C:指定解压到的目录。
[url]http://www.cyberciti.biz/howto/question/general/compress-file-unix-linux-cheat-sheet.php[/url]
//打包 为 zip 包
$ zip 包名.zip 某文件
//查看 tar 包的内容(不解压)
$ tar -t(v)f xxx.tar
//还是不解压而只查看tar包的内容,但是不递归查看所以的内容,而只查看tar包根目录下的内容(参见 http://stackoverflow.com/questions/2700306/listing-the-content-of-a-tar-file-or-a-directory-only-down-to-some-level)
$ tar --exclude="*/*" -tf file.tar
//将tar包解压到 ~/Dev 目录
$ tar -xzf redis-2.6.3.tar.gz -C ~/Dev
//压缩为 tar.gz
$ tar -czf package_name.tar.gz .
//解压 war/jar 包可以使用 unzip 命令,另可以通过 -d 参数指定解压的目录的名字
unzip projectName-webapp-1.22-SNAPSHOT.war -d projectName
unzip -d xxx project-api-1.0-SNAPSHOT.jar
# 解压缩 rar 包 (需要安装 unrar:sudo apt-get install unrar; sudo yum install unrar)
$ unrar x abc.rar
# 解压缩 rar 包到目录 aaa
$ unrar x abc.rar aaa
link 相关命令:
[url]http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/[/url][quote]link分两种:hard link 和 soft link(也叫 symbolic link)。
#任何参数都不加,创建的是 hard link
$ ln /full/path/of/original/file /full/path/of/hard/link/file
#欲创建 soft link,请添加 -s(symbolic) 参数:
$ ln -s /full/path/of/original/file /full/path/of/soft/link/file
注意事项:
hard link 只能为文件创建,不能为文件夹创建;[/quote]
[b]文件查找命令s:[/b] ---待完善with chrome quick note。 grep find locate
[url]http://www.vogella.com/articles/Ubuntu/article.html[/url]
[url]https://www.google.com/search?num=100&hl=en&newwindow=1&safe=off&tbo=d&site=webhp&source=hp&q=grep+find+locate&oq=grep+find+locate+&gs_l=hp.3.0.0i30j0i5i30j0i8i30.1030.8783.0.10434.29.20.7.2.2.0.118.1669.17j3.20.0.les%3B..0.0...1c.1.2.hp.apAhTOivpgc[/url]
[b]Finding all files containing a text string | 递归查找指定目录下的文件中,其内容包含指定字符串的所有文件(强大的grep):[/b]
[url]http://stackoverflow.com/questions/16956810/finding-all-files-containing-a-text-string-on-linux[/url]
grep -r . -e 'pattern-of-mached-text'
[color=red][b]find:[/b][/color]
[url]http://www.grymoire.com/Unix/Find.html[/url]
#查找当前目录及其子目录下文件名包含 __init__.py 的文件;注意如果是用相对路径形式的 . 代表当前目录,则显示出的路径也是以相对路径的形式出现,如下面的第1个;如果想要文件的路径以绝对路径的形式展现,则用绝对路径表征当前目录即可,如下面的第2和3个。
$ find . -name *__init__.py*
$ find $PWD -name *__init__.py*
$ find `pwd` -name *__init__.py*
[color=red][b]grep:[/b][/color]
7 Linux Grep OR, Grep AND, Grep NOT Operator Examples:
[b][url]http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/[/url][/b]
//查询 fileName.log中包含 searchStr 的行:
$ grep 'searchStr' fileName.log | less -S
$ awk '/searchStr/' fileName.log | less -S
//查询 fileName.log中包含 searchStr 的行,并显示行号:
$ grep 'searchStr' -n fileName.log | less -S
//查询 fileName.log 中即包含 xxx,又包含 yyy 的行:
$ grep "xxx" fileName.log | grep "yyy" | less -S
$ grep -E "xxx.*yyy|yyy.*xxx" fileName.log | less -S
//查询 fileName.log 中即包含 xxx,又包含 yyy 且xxx在yyy之前的行:
$ grep -E "xxx.*yyy" fileName.log | less -S
//查询 fileName 中或包含 xxx,或包含 yyy 的行:
$ grep 'xxx\|yyy' fileName | less -S
$ grep -E 'xxx|yyy' fileName | less -S
$ egrep 'xxx|yyy' fileName | less -S
$ grep -e 'xxx' -e 'yyy' fileName | less -S
//忽略大小写查询 fileName 中 包含 filtered 的行:
$ grep -i "filtered" fileName | less -S
//查询文件中不包含 abc 的行:
$ grep -v "abc" fileName | less -S
//查询文件中既不包含 abc,也不包含 xyz 的行:
$ grep -v -E "abc|xyz" fileName | less -S
// 查询 catalina.out 中 存在 "Elapsed:[这里有四位以上数字] ms" 的行;结合 http://wuaner.iteye.com/blog/1157713 体会 BRE 和 ERE 中 对 ? + ( ) { } 六个字符处理的不同
$ grep '^.\+Elapsed:[0-9]\{4,\} ms.\+$' catalina.out | less
$ grep -E '^.+Elapsed:[0-9]{4,} ms.+$' catalina.out | less
sed awk cut: 待完善:
sed awk grep的区别:
[url]http://stackoverflow.com/questions/7727640/differences-among-grep-awk-and-sed[/url]
cut:
[url]http://www.computerhope.com/unix/ucut.htm[/url]
[url]http://lowfatlinux.com/linux-columns-cut.html[/url]
[b]$ grep 'Bounces' 2013-02-18.log | grep 'androidlaunch' | cut -d'|' -f11 | sort -n | uniq -c | grep -v 'sohu' | less -S[/b]
[b]$ grep 'Bounces' 4939-2013-02-18.log | awk -F'|' '{print $5"|"$11}' | awk -F'@' '{print $2}' | sort | uniq -c | sort -nr | less -S[/b]
[color=red][b]awk:[/b][/color]
[url]http://www.grymoire.com/Unix/Awk.html[/url]
8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR:
[url]http://www.thegeekstuff.com/2010/01/8-powerful-awk-built-in-variables-fs-ofs-rs-ors-nr-nf-filename-fnr/[/url][quote]awk 例子:
下列文本:
r1c1|r1c2|r1c3|r1c4|r1c5|r1c6|r1c7|r1c8
r2c1|r2c2|r2c3|r2c4|r2c5|r2c6|r2c7|r2c8
r3c1|r3c2|r3c3|r3c4|r3c5|r3c6|r3c7|r3c8
r4c1|r4c2|r4c3|r4c4|r4c5|r4c6|r4c7|r4c8
将由 | 分割的第 4、5、7、8 列提取出来,并且 4/5/7 列之间用 [b][color=red],[/color][/b] 分割开,7/8 列之间用 [color=red][b]|[/b][/color] 分割开。使用 awk 很简单,如下:
$ awk -F'|' '{print $4","$5","$7" "$8}' text | less
输出:
r1c4,r1c5,r1c7 r1c8
r2c4,r2c5,r2c7 r2c8
r3c4,r3c5,r3c7 r3c8
r4c4,r4c5,r4c7 r4c8
# 找出文本中所有字符个数大于 2014 的行,输出它们的行号和字符个数
$ awk 'length > 1024 {print NR" "length}' text | less
# 找出文本中字符个数最多的行,输出其行号和字符个数
$ awk 'length > max {max=length;row=NR} END {print row" "max}' text | less
[/quote]sed:[b]s[/b]tream [b]ed[/b]itor:
[url]http://www.grymoire.com/Unix/Sed.html[/url]
Sed Explained, Part 1:
[url]http://www.linuxforu.com/2011/04/sed-explained-part-1/[/url]
Sed Explained, Part 2: Data Structures and Operators:
[url]http://www.linuxforu.com/2011/06/sed-part-2-data-structures-and-operators/[/url]
[url]http://www.gnu.org/software/sed/manual/sed.html[/url]
常用举例:
[b][url]http://www.unixguide.net/unix/sedoneliner.shtml[/url][/b]
#查看文件内容
$ sed '' fileName
#使用 = 指定行号
$ sed ‘=’ fileName
#使用 G 在每行下添加空行
$ sed 'G' fileName
#同 wc -l
$ sed -n '$=' fileName
#删除首行(http://stackoverflow.com/questions/9633114/unix-script-remove-first-line-of-csv-file)
$ sed 1d test.csv | less -s (原文件中首行仍在,只是不输出首行)
$ sed -i 1d test.csv (删除原文件中的首行)
文件的 split & merge:
#将 userids_all.csv 拆分成多个小文件,每个文件 200 行,且生成的小文件名为 userids_00, userids_01, ...
$ split -d -l 200 userids_all.csv userids_
# 如果原文件很大,切分成的小文件很多,则可能会报 split: output file suffixes exhausted,这时可以使用 -a 指定后缀的长度(默认为2,故对 -d(数字后缀) 来说,其支持的最大文件数目为 100)
$ split -d -l 1000000 -a 3 4亿.csv /data/splitted/splitted_
#将 userids_0*.result 的文件们的内容合并到 result.csv 中
$ cat userids_0*.result > result.csv
[b]wget & curl:[/b]
[url]http://www.thegeekstuff.com/2012/07/wget-curl/[/url]
[b]curl & wget 比较之 download[/b][quote]
$ wget http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2
$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701
$ curl -O http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2
$ curl -o taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701
Using curl to download password-protected pages:
[b][url]http://blog.kyplex.com/2011/03/curl-wget-password-protected-pages.html[/url][/b]
$ curl --cookie 'authkit="598a1255672b90e1aa2b90d800b6171051497289XXX@gmail.com!"; path=/; domain=myaccount.critsend.com' "https://myaccount.critsend.com/logs/download?date=2013-03-21" > critsend
[/quote][b]curl & wget 比较之 POST Content-Type:application/json[/b][quote]
$ curl -X POST -H "Content-Type:application/json" -d '{"start":0,"rows":10,"keyword":"物流主管"}' http://search.xxx.com/position/search
# 使用 -v -w 查看 curl 调用详细的信息
$ curl -v -w '%{http_code}' http://x.y.m.n:8000/rootContext/controller/26182337/1,20?random=true
$ wget -qO- --header 'Content-Type:application/json' --post-data '{"start":0,"rows":10,"keyword":"物流主管"}' http://search.xxx.com/position/search
[/quote]
[b]ssh & scp:[/b]
#使用 ssh 登录远程主机(注意 ssh 指定端口号时使用的是小写 -p)
$ ssh -p 2208 remote-user@remote-ip
#使用 scp 拷贝本地文件到远程主机(注意 scp 指定端口号时使用的是大写 -P)
$ scp -P 2208 local-file remote-user@remote-ip:~
#使用 scp 拷贝远程文件到本地
$ scp -P 2208 remote-user@remote-ip:path-of-remote-file local-path
SSH forwarding:
[url]http://chamibuddhika.wordpress.com/2012/03/21/ssh-tunnelling-explained/[/url]
[url]http://blog.jlank.com/2011/05/16/ssh-tunneling-with--l/[/url]
[url]http://stackoverflow.com/questions/9447226/how-to-close-this-ssh-tunnel[/url][quote]选项说明:
-f [b][color=red]=[/color][/b] fork process into background,相当于shell下的 &
-N [b][color=red]=[/color][/b] don't run any commands remotely (w/o this -f will complain。指定这个选项则登陆远程主机后不会出现命令提示符)
-L [bind_address:]port_of_bind_address:host:hostport [b][color=red]=[/color][/b] binds the port [i][u]port_of_bind_address[/u][/i] of [u][i]bind_address[/i][/u](可省略,若省略则默认为localhost) to the port [u][i]hostport[/i][/u] on host [u][i]host[/i][/u]
例子:使用 ssh forwarding 连接远程 mysql:
场景:
mysql 实例在 remote-mysql-server 上,且在本地无权限通过ssh直接登陆该主机或通过 mysql command line 连接该主机上的 mysql instance。
remote-another-server 是和 remote-mysql-server 在同一局域网的另一个远程主机(隐意是可以在该主机上通过 mysql command line 登陆 remote-mysql-server 上的 mysql instance),且本地有权限通过 ssh 登陆该远程主机。
步骤:
1. 本地启动 ssh forwarding:
ssh -f -N -L 33060:remote-mysql-server:3306 root@remote-another-server
2. 在本地使用以下jdbc连接 remote-mysql-server 上的 mysql 数据库:
jdbc:mysql://localhost:33060/name-of-database-on-remote-mysql-server
& username、password of mysql instance on remote-mysql-server
[/quote]
[b]技巧性组合命令:[/b]
//为history命令查看到的命令历史添加时间:
$ echo 'export HISTTIMEFORMAT="%y-%m-%d %T "' >> ~/.bashrc
[b]用户相关命令:[/b]
//切换用户
$ su - userName (单独 su 是作为超级用户root登陆)
//列出当前登陆用户
$ whoami
$ id -un
//设置密码
$ passwd userName
//添加用户
$ adduser or useradd
[b]System Information Commands:[/b]
[b]1 df (abbreviated from disk free)[/b]: The df command displays filesystem disk space usage for all mounted partitions. "df -h" is probably the most useful - it uses megabytes (M) and gigabytes (G) instead of blocks to report. (-h means "human-readable")
[b]2 du (abbreviated from disk usage)[/b]: The du command displays the disk usage for a directory. It can either display the space used for all subdirectories or the total for the directory you run it on.-s means "Summary" and -h means "Human Readable".
//计算 /data 目录下所有文件的总大小 (ls -l 显示的只是目录本身的存储占用大小) (-s stands for summarize,-h stands for human readable)
$ du -sh /data
//递归计算 /data 目录(包含)下各级目录的文件大小,并按占用空间从多到少输出
$ du -h /data | sort -hr | less
[b]3 free[/b]: The free command displays the amount of free and used memory in the system. "free -m" will give the information using megabytes, which is probably most useful for current computers.
[b]4 top[/b]: The top ('table of processes') command displays information on your Linux system, running processes and system resources, including CPU, RAM & swap usage and total number of tasks being run. To exit top, press "q".
[b]5 uname -a[/b]: The uname command with the -a option prints all system information, including machine name, kernel name & version, and a few other details. Most useful for checking which kernel you're using.
[b]6 lsb_release -a[/b]: The lsb_release(lsb stands for Linux Standard Base) command with the -a option prints version information for the Linux release you're running, for example:
[b]7 ip addr[/b]: reports on your system's network interfaces.
[b]8 ifconfig[/b]: (short for interface configuration) is a system administration utility in Unix-like operating systems to configure, control, and query TCP/IP network interface.
证书 ca certificate 相关命令:
[url]https://code.google.com/p/chromium/wiki/LinuxCertManagement[/url]
[url]http://blog.avirtualhome.com/adding-ssl-certificates-to-google-chrome-linux-ubuntu/[/url]
# List all certificates
$ certutil -d sql:$HOME/.pki/nssdb -L
# import
$ certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n goagent -i '/home/lee/Apps/goagent/local/CA.crt'
# delete a certificate
$ certutil -d sql:$HOME/.pki/nssdb -D -n <certificate nickname>
# List details of a certificate
$ certutil -d sql:$HOME/.pki/nssdb -L -n <certificate nickname>
注意对 chrome / chromium 来说, 因为其的 certs store 是在 $HOME/.pki/nssdb 下单独维护的,所以只能通过上面的方式来做,而不能通过常见的导入 crt 文件到 system certificate store 的方式:
将 crt 文件放到 /usr/local/share/ca-certificates(或 /usr/share/ca-certificates)
然后 sudo update-ca-certificates
来做。参见:
[url]http://superuser.com/a/657177/175890[/url]
[url]http://www.autistici.org/en/stuff/man_ca/linux.html[/url]
Linux DNS Lookup utilities:
1 dig(domain information groper):
[url]http://linux.die.net/man/1/dig[/url]
[url]http://www.thegeekstuff.com/2012/02/dig-command-examples/[/url]
2 host
3 nslookup
另附DNS 记录类型:
[url]http://en.wikipedia.org/wiki/List_of_DNS_record_types[/url]
linux命令中什么时候使用引号,及使用双引号还是单引号:
UNIX SHELL Quote Tutorial:
[url]http://www.grymoire.com/Unix/Quote.html[/url]
[b]一些 linux/unix 命令/缩写词 的含义:
What does {some strange unix command name} stand for?
[url]http://www.unixguide.net/unix/faq/1.3.shtml[/url][/b][quote]cli:Command Line Interface[/quote]
[b]Linux Commands Chaining(Grouping):[/b]
[url]http://sayle.net/book/basics.htm#grouping_commands[/url][quote][b]1 Semicolon 分号 [color=red];[/color] [/b]
顺序执行分号分割的多个命令,不管 ; 分割的各个命令执行结果如何。
[b]2 double ampersands [color=red]&&[/color][/b]
当且仅当 && 前的命令返回状态码为0(表示执行成功),才执行 && 后的命令
[b]3 double vertical bars [color=red]||[/color][/b]
当且仅当 || 前的命令返回状态码为非0(即执行失败),才执行 || 后的命令
$ (ls -l | grep "root") || echo "No files owned by root"
[b]4 parentheses [color=red]()[/color][/b]
The parentheses, when grouped around a command, [b]cause the command to be executed in a subshell[/b]. Any environmental changes occuring within the subshell do not persist beyond its execution; in other words, [b]all changes to the working environment of the commands issued within the parentheses do not affect the working shell. [/b]
$ cd; ls
bin etc include man tmp
$ cd bin; ls; ls
bash gunzip gzip zcat
bash gunzip gzip zcat
$ cd
$ (cd bin; ls); ls
bash gunzip gzip zcat
bin etc include man tmp
[b]5 curly braces [color=red]{}[/color][/b]
Like parentheses, curly braces can be used to group a set of commands; however, the commands execute within the context of the current shell. And some restrict: [b]Inside the curly braces, White space precedes and follows the enclosed commands, and a semicolon terminates the last command are required.[/b]
$ { cd bin; ls; }; ls
[/quote]
技巧:
Disable Line Wrapping In Terminal:
[url]http://ubuntuforums.org/showthread.php?t=1066656[/url][quote]1 使用 some_command | less -S
2 [url]http://software.jessies.org/terminator/#downloads[/url][/quote]