thelinuxCommandLine学习笔记--mysql命令行导入sql文件到指定数据库的方法
thelinuxCommandLine学习笔记--mysql命令行导入sql文件到指定数据库的方法
中英文资料:http://billie66.github.io/TLCL/book/chap01.html
the graphical user interface (GUI) 图形界面The Command Line 命令行
Linux 是以 Unix 家族的操作系统为模型写成的。
第二章 什么是 Shell:
bash 是 shell 的一种,来自于 GNU 项目。“bash”是“Bourne Again SHell”的首字母缩写,
所指的是这样一个事实,bash 是 sh 的增强版,sh 是最初 Unix 的 shell 程序,
由 Steve Bourne 写成。
KDE 用的是 konsole 程序, 而 GNOME 则使用 gnome-terminal。
还有其他一些终端仿真器可供 Linux 使用,但基本上,它们都是为了完成同样的事情,
让我们能访问 shell
[me@linuxbox ~]$
“$" 普通用户
a pound sign (“#”),提示符的最后一个字符是“#”, 而不是“$”, 那么这个终端会话就有超级用户权限。命令历史
查看以往的输入的命令,向上箭头
显示系统当前时间和日期
[root@AY130410135131135089 ~]# date
Tue Nov 26 23:38:14 CST 2013
默认显示当前月份的日历
[root@AY130410135131135089 ~]# cal
November 2013
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
查看磁盘剩余空间(free space on your disk drives)的数量,输入 df:
[root@AY130410135131135089 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 20469760 7366592 13103168 36% /
tmpfs 1960828 0 1960828 0% /dev/shm
同样地,显示空闲内存的数量(the amount of free memory),输入命令 free。
[root@AY130410135131135089 ~]# free
total used free shared buffers cached
Mem: 3921656 2141516 1780140 0 656 168692
-/+ buffers/cache: 1972168 1949488
Swap: 490488 2348 488140
结束终端会话,也即退出终端
[root@AY130410135131135089 ~]# exit
logout
第三章:
pwd - 打印当前所在目录的名称 cd - 改变目录 ls - 打印目录的内容[root@AY130410135131135089 ~]# pwd
/root
Understanding The File System Tree理解文件系统树
文件系统中的第一级目录称为根目录
The Current Working Directory当前工作目录
[root@AY130410135131135089 ~]# pwd
/root
Listing The Contents Of A Directory列出目录内容
[root@AY130410135131135089 usr]# ls
bin etc games include lib lib64 libexec local sbin share src tmp
Changing The Current Working Directory更改当前工作目录
从根目录(用开头的“/”表示)开始,有一个叫 “usr” 的 目录包含了目录 “bin”。
[root@AY130410135131135089 local]# cd /usr/bin/
符号 ”.” 指的是工作目录,”..” 指的是工作目录的父目录。
经常使用 cd .. 返回上级目录
cd ..
cd ../../..
cd 更改工作目录到主目录。
cd - 更改工作目录到先前的工作目录。
cd ~user_name 更改工作目录到用户主目录。例如, cd ~bob 会更改工作目录到用户“bob”的主目录
第四章:
ls 有一些我们常用的参数, 比如我们要知道当前目录的所有内容, 包括隐藏文件夹和文件和所有属性, 例
[root@AY130410135131135089 logs]# ls
boot2013-06.log
使用 ls 命令的“-l”选项,则结果以长模式输出:
[root@AY130410135131135089 logs]# ls -l
total 8
-rw-rw-rw- 1 root root 5975 Jun 15 17:34 boot2013-06.log
显示隐藏文件:
[root@AY130410135131135089 logs]# ls -a
. .. boot2013-06.log
命令 选项 参数
command -options arguments
下面这个例子,ls 命令有两个选项, “l” 选项产生长格式输出,“t”选项按文件修改时间的先后来排序。
[me@linuxbox ~]$ ls -lt
确定一个文件什么文件类型我们用 file, 使用方法如下
[root@AY130410135131135089 logs]# file boot2013-06.log
boot2013-06.log: ASCII text
[root@AY130410135131135089 assets]# file world.swf
world.swf: Macromedia Flash data (compressed), version 10
用 less 浏览文件内容
[me@linuxbox ~]$ less /etc/passwd
TODO 表 4-3: less 命令 需要截图哦。
小提示:记得复制和粘贴技巧!如果你正在使用鼠标,双击文件名,来复制它,然后按下鼠标中键,粘贴文件名到命令行中。
Symbolic Links符号链接
Hard Links硬链接
第五章:操作文件和目录
cp — 复制文件和目录 mv — 移动/重命名文件和目录 mkdir — 创建目录 rm — 删除文件和目录
ln — 创建硬链接和符号链接 TODO没搞懂 和Window快捷键的区别联系 点击打开链接
cp — 复制文件和目录
jiangge@localhost:~$ cp item1 item2 # 把item复制到directory目录
jiangge@localhost:~$ cp file1 file2 # 复制file1到file2
jiangge@localhost:~$ cp -i file1 file2 # 复制过程中如果有这个文件提示是否覆盖
jiangge@localhost:~$ cp dir1/* dir2 # 复制目录下所有文件或目录到目标目录
jiangge@localhost:~$ cp -r dir1 dir2 # 递归复制
mkdir — 创建目录
jiangge@localhost:~$ mkdir dir
jiangge@localhost:~$ mkdir dir1 dir2 dir3 # 创建多个文件夹
jiangge@localhost:~$ mkdir -p /dir1/dir2/dir3 # 递归创建文件夹
mv — 移动/重命名文件和目录
jiangge@localhost:~$ mv file1 file2 # 重命名
jiangge@localhost:~$ mv -i file1 file2 # 如果存在提示是否写入
jiangge@localhost:~$ mv file1 file2 dir1 # 移动 file1 file2 至 dir1
jiangge@localhost:~$ mv dir1 dir2 # 移动 dir1 至 dir2
rm — 删除文件和目录
jiangge@localhost:~$ rm file1
jiangge@localhost:~$ rm file1 dir1
jiangge@localhost:~$ rm -r dir1 #删除文件夹, 递归删除
jiangge@localhost:~$ rm -rf dir1 强制删除
表5-3:通配符范例 模式 匹配对象 * 所有文件 g* 文件名以“g”开头的文件 b*.txt 以"b"开头,中间有零个或任意多个字符,并以".txt"结尾的文件 Data??? 以“Data”开头,其后紧接着3个字符的文件 [abc]* 文件名以"a","b",或"c"开头的文件 BACKUP.[0-9][0-9][0-9] 以"BACKUP."开头,并紧接着3个数字的文件 [[:upper:]]* 以大写字母开头的文件 [![:digit:]]* 不以数字开头的文件 *[[:lower:]123] 文件名以小写字母结尾,或以 “1”,“2”,或 “3” 结尾的文件
表5-4:cp 选项 选项 意义 -a, --archive 复制文件和目录,以及它们的属性,包括所有权和权限。 通常,复本具有用户所操作文件的默认属性。 -i, --interactive 在重写已存在文件之前,提示用户确认。如果这个选项不指定, cp 命令会默认重写文件。 -r, --recursive 递归地复制目录及目录中的内容。当复制目录时, 需要这个选项(或者-a 选项)。 -u, --update 当把文件从一个目录复制到另一个目录时,仅复制 目标目录中不存在的文件,或者是文件内容新于目标目录中已经存在的文件。 -v, --verbose 显示翔实的命令操作信息
表 5—5: cp 实例 命令 运行结果 cp file1 file2 复制文件 file1内容到文件 file2。如果 file2已经存在,file2的内容会被 file1的 内容重写。如果 file2不存在,则会创建 file2。 cp -i file1 file2 这条命令和上面的命令一样,除了如果文件 file2存在的话,在文件 file2被重写之前, 会提示用户确认信息。 cp file1 file2 dir1 复制文件 file1和文件 file2到目录 dir1。目录 dir1必须存在。 cp dir1/* dir2 使用一个通配符,在目录 dir1中的所有文件都被复制到目录 dir2中。 dir2必须已经存在。 cp -r dir1 dir2 复制目录 dir1中的内容到目录 dir2。如果目录 dir2不存在, 创建目录 dir2,操作完成后,目录 dir2中的内容和 dir1中的一样。 如果目录 dir2存在,则目录 dir1(和目录中的内容)将会被复制到 dir2中。
第六章:点击打开链接
type - 解读一个命令 which - 显示哪些是可执行程序,which 确定一个可执行程序的位置 man - 显示命令手册 apropos - 显示一个合适的命令列表 info - 显示一个命令信息 whatis - 显示非常简短的描述一个命令 alias - 为命令创建一个别名
[shijiangge@localhost test]$ type type type is a shell builtin
[shijiangge@localhost test]$ type ls ls is aliased to `ls --color=tty'
[shijiangge@localhost test]$ type cp cp is hashed (/bin/cp)
[shijiangge@localhost test]$ which ls #which 确定一个可执行程序的位置 alias ls='ls --color=tty' /bin/ls
[shijiangge@localhost test]$ which vim /usr/bin/vim
help 获得帮助信息, 在每个shell命令的后面加上--help参数, 如
[shijiangge@localhost test]$ ls --help Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort.
[shijiangge@localhost test]$ help cd cd: cd [-L|-P] [dir] Change the current directory to DIR. The variable $HOME is the default DIR.
注意表示法:出现在命令语法说明中的方括号,表示可选的项目。一个竖杠字符 表示互斥选项。在上面 cd 命令的例子中:
cd [-L|-P] [dir]
这种表示法说明,cd 命令可能有一个”-L”选项或者”-P”选项,进一步,可能有参数”dir”。
man 获得命令指南
[shijiangge@localhost test]$ man ls
whatis 显示一个简短的描述
[shijiangge@localhost test]$ whatis ls ls (1) - list directory contents ls (1p) - list directory contents
[shijiangge@localhost test]$ whatis vim vim (1) - Vi IMproved, a programmers text editor
用别名(alias)创建你自己的命令
shijiangge@localhost:~$ type test test is a shell builtin shijiangge@localhost:~$ type foo /bin/bash: line 0: type: foo: not found # 什么都没有 shijiangge@localhost:~$ alias foo='cd /usr; ls; cd -' shijiangge@localhost:~$ alias name='string' shijiangge@localhost:~$ alias # 创建de自定义命令都打印出来 alias foo='cd /usr; ls; cd -' alias name='string' shijiangge@localhost:~$ foo bin include lib local man sbin share src /home/shijiangge shijiangge@localhost:~$ type foo foo is aliased to 'cd /usr; ls; cd -' shijiangge@localhost:~$ unalias foo # 销毁foo shijiangge@localhost:~$ alias # 只剩下name了 alia name='string' shijiangge@localhost:~$ type foo # 什么都没有 /bin/bash: foo: command not found shijiangge@localhost:~$ unalias name # 销毁nameTODO第七章
==========================================
Lunix 调整时间,就是将服务器时间调快或调慢,线上一般不要调整时间,本地为了测试在调整服务器时间的。
date -s 07/09/2013
date -s 17:05:00
==========================================
mysql命令行导入sql文件到指定数据库的方法
mysql命令行导入的方式。
以下是各步骤:
1、先将数据库通过ftp上传至服务器内
或者使用 rz -y 进行上传
2、登陆mysql数据库:
mysql -u root -p
3、选择数据库:
use mydbname;
4、导入文件:
[win下] source e:\newdb.sql;
[linux下] source /root/newdb.sql;
导入成功!
==============================================
再来一个导出的吧(不用在mysql命令行):
mysqldump -uroot -p dbname table1 table2 > foo.sql
mysqldump -uroot -p huo > /usr/local/jiangge/foo.sql
压缩:
zip -r webgames.zip webgames
===================================================
FTP--ftp 启动命令:
service vsftpd start
----------------------------------------------------------------------------------
评论暂时关闭