SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
Linux基础
Lo小能(Eric Lo)
lxneng@gmail.com
http://lxneng.com
twitter: lxneng
一切都是文件
 
man xxx
xxx --help
常用命令
文件管理
pwd, ls, cd, cp
pwd   //打印当前目录
ls       //打印目录下的文件
cd      //切换目录
ex:
cd ~
cd -
cp      //复制文件
ex:
cp /path/file/from /path/file/to
cp -R /etc ~/etc_bak
 
mv, rm
mv   //移动文件
ex:
mv /path/file/from /path/file/to
用来移动文件、文件夹和重命名
rm   //remove的简称,移除文件
ex:
rm /path/file
rm -rf /path/dir
这个命令一定要小心, 最好不使用
mkdir, rmdir
mkdir
ex:
mkdir dirname
mkdir -p 2010/12/01
-p参数用来创建目标目录的上层目录,但即使这些目录已
存在也不当作错误处理
rmdir
ex:
 rmdir dirname //删除空文件夹
 rmdir -p a/b/c //删除指定目录及其上级文件
夹    与"rmdir a/b/c a/b a'" 基本相同
ln
ln   //创建链接
ex:
 ln aaa bbb //为aaa创建一个硬链接bbb
 ln -s aaa bbb //为aaa创建一个软链接bbb
一般创建软链接就可以了 相当于创建一个快捷方式
压缩解压缩
zip, unzip, tar, gzip, gunzip
zip
 ex:
zip xxx.zip xxx/*  压缩xxx文件夹下面的文件到xxx.
zip
unzip
 ex:
unzip xxx.zip
tar
ex:
tar -xjvf xxx.tar.bz2
tar -zxvf xxx.tar.gz -C /tmp
tar -zcvf xxx.tar.gz xxx
gzip
gunzip
文件内容相关
cat, more, less, head, tail
cat  //从第一行开始显示文件内容, 而tac则是反过来
ex
cat xxx
 tac xxx
more//一页一页的显示文件的内容
less  //和more类似,他可以往前翻
head//将文件内容的头10 行显示
tail  //将文件内容的尾部开始显示
ex:
tail -f production.log
-f 参数即时输出文件变化后追加的数据
权限相关
chmod, chown
r-w-x = 4-2-1 [所有者][组][其他用户]
chmod //改变文件权限
ex:
chmod 755 /path/file
chmod 755 -R /path/dirname
chown //改变文件的所有者或组
ex:
chown root /path/file
chown root:root /path/file
chown root:root -hR /path/dirname //将dirname下面
的所有文件的owner和group改为root
重定向和管道
>  |
>  //重定向
ex:
cat xxx > yyy
将标准输出stdout重定向到文件或其他
|  //管道
 ex:
ps -aux|grep ruby //ps -aux的输出通过管道用grep去
匹配出含有ruby的进程
搜索文件
find, which, whereis, locate
find      //查找文件
ex:
find ~/workspace/NetBeansProjects/ -name '*.yml'
which   //查找可执行文件的位置
ex:
which mysql
whereis //查找文件的位置(binary, source, and manual
page files) 
ex:
whereis mysql
locate   //从系统数据库中查找文件
ex:
locate mysql
用户管理
adduser, deluser, addgroup, delgroup
adduser
ex:
adduser user1 //添加新用户user1
adduser user1 sudo //将user1添加到sudo组
deluser
ex:
deluser user1
addgroup
ex: 
addgroup xxx
delgroup
ex:
delgroup xxx
用户管理
passwd
passwd
ex
passwd //改变当前用户的密码
passwd username //改变username的密码
passwd -l username //锁定(lock)
passwd -u username //解锁(unlock)
系统管理
shutdown, halt, poweroff, reboot
shutdown
ex:
shutdown 16:33
shutdown +5
shutdown now
shutdown -r  // ==reboot
halt //关闭系统
poweroff //关闭系统并切断系统电源
reboot //重新启动
ps, kill, killall, free, df
ps   //查看进程
ex:
ps -aux
kill
ex:
kill -9 3232 //杀死3232这个进程
killall
ex:
killall -9 ruby
free //查看内存的使用情况
df //硬盘的使用情况 
ex:
df -h
top, uptime,&
top 
显示任务
uptime
看负载
& 
后台工作
ex:
ruby script/server & //后台执行
文本编辑
nano, vim
nano
ex:
nano xxxx
vim
ex:
vim xxx
其他命令
 who, w, whoami, uname
who         //显示谁登陆了
w             //显示谁登陆了 并且在干什么
whoami    //显示用户名
uname      //输出一组系统信息
ex
uname -a
Linux eric-desktop 2.6.35-23-generic #41-Ubuntu
SMP Wed Nov 24 10:18:49 UTC 2010 i686 GNU/Linux
其他命令
cron, ping, route, ifconfig
cron     //作业调度
ex:
crontab -e //编辑系统的crontab文件
 00 4 * * * sh /home/eric/rsync_db.sh //表示每日4点
去执行这个rsync_db.sh脚本
 # m h  dom mon dow   command // 分钟,小时,天
(1-31), 月份(1-12),星期几(1-7), 命令
ping    //ping 8.8.8.8
route   //内核 IP 路由表
ifconfig//网络接口配置
远程访问与文件传输
ssh, scp
ssh
服务器端需要有sshd server
openssh-server
apt-get install openssh-server
config file: /etc/ssh/ssh_config  
客户端机器默认有ssh client
ssh username@jkydjk.com
config_file:vim ~/.ssh/config
scp 远程文件传输
 scp xxx eric@lxneng.com:/tmp
 scp eric@lxneng.com:/tmp/text.txt ./
下载
wget, curl
wget
ex:
wget wget http://www.google.
com/intl/en_ALL/images/srpr/logo1w.png //写到
logo1w.png
wget -mk http://google.com  //镜像
wget -O google.htm http://google.com //写到
google.html
curl
 ex:
curl http://google.com //标准输出
curl -o xxx http://google.com //写到xxx
curl -I http://google.com  //看head信息
The End!~
 

Weitere ähnliche Inhalte

Was ist angesagt?

Effective linux.2.(tools)
Effective linux.2.(tools)Effective linux.2.(tools)
Effective linux.2.(tools)wang hongjiang
 
Linux基础
Linux基础Linux基础
Linux基础zhuqling
 
Linux command tutorial
Linux command tutorialLinux command tutorial
Linux command tutorial朋 陈
 
如何学习Bash Shell
如何学习Bash Shell如何学习Bash Shell
如何学习Bash ShellLI Daobing
 
Mysql展示功能与源码对应
Mysql展示功能与源码对应Mysql展示功能与源码对应
Mysql展示功能与源码对应zhaolinjnu
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)wang hongjiang
 
網路組-Ubuntu介紹
網路組-Ubuntu介紹網路組-Ubuntu介紹
網路組-Ubuntu介紹maryqute520
 
Linux常用命令
Linux常用命令Linux常用命令
Linux常用命令Tony Deng
 
Introduce to Linux command line
Introduce to Linux command lineIntroduce to Linux command line
Introduce to Linux command lineWen Liao
 
Virtual file system (VFS)
Virtual file system (VFS)Virtual file system (VFS)
Virtual file system (VFS)Waylin Ch
 
Ruby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for MacRuby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for MacMarsZ Chen
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuMarsZ Chen
 
Mac os Terminal 常用指令與小技巧
Mac os Terminal 常用指令與小技巧Mac os Terminal 常用指令與小技巧
Mac os Terminal 常用指令與小技巧Chen Liwei
 
Diff and Patch command Manual
Diff and Patch command ManualDiff and Patch command Manual
Diff and Patch command Manualtag taglife
 
1, shell intro
1, shell intro1, shell intro
1, shell introted-xu
 
淺談Debian套件打包
淺談Debian套件打包淺談Debian套件打包
淺談Debian套件打包Wen Liao
 
常用Mac/Linux命令分享
常用Mac/Linux命令分享常用Mac/Linux命令分享
常用Mac/Linux命令分享Yihua Huang
 

Was ist angesagt? (20)

Effective linux.2.(tools)
Effective linux.2.(tools)Effective linux.2.(tools)
Effective linux.2.(tools)
 
Linux基础
Linux基础Linux基础
Linux基础
 
Linux command tutorial
Linux command tutorialLinux command tutorial
Linux command tutorial
 
如何学习Bash Shell
如何学习Bash Shell如何学习Bash Shell
如何学习Bash Shell
 
Mysql展示功能与源码对应
Mysql展示功能与源码对应Mysql展示功能与源码对应
Mysql展示功能与源码对应
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)
 
網路組-Ubuntu介紹
網路組-Ubuntu介紹網路組-Ubuntu介紹
網路組-Ubuntu介紹
 
Linux常用命令
Linux常用命令Linux常用命令
Linux常用命令
 
Cent os
Cent osCent os
Cent os
 
Introduce to Linux command line
Introduce to Linux command lineIntroduce to Linux command line
Introduce to Linux command line
 
Virtual file system (VFS)
Virtual file system (VFS)Virtual file system (VFS)
Virtual file system (VFS)
 
Ruby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for MacRuby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for Mac
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for Ubuntu
 
Mac os Terminal 常用指令與小技巧
Mac os Terminal 常用指令與小技巧Mac os Terminal 常用指令與小技巧
Mac os Terminal 常用指令與小技巧
 
Diff and Patch command Manual
Diff and Patch command ManualDiff and Patch command Manual
Diff and Patch command Manual
 
1, shell intro
1, shell intro1, shell intro
1, shell intro
 
Cvs
CvsCvs
Cvs
 
MySQL aio
MySQL aioMySQL aio
MySQL aio
 
淺談Debian套件打包
淺談Debian套件打包淺談Debian套件打包
淺談Debian套件打包
 
常用Mac/Linux命令分享
常用Mac/Linux命令分享常用Mac/Linux命令分享
常用Mac/Linux命令分享
 

Ähnlich wie Linux基础

Linux安全配置终极指南
Linux安全配置终极指南Linux安全配置终极指南
Linux安全配置终极指南wensheng wei
 
Unix常用命令 1
Unix常用命令 1Unix常用命令 1
Unix常用命令 1tony2yy_fish
 
5, system admin
5, system admin5, system admin
5, system adminted-xu
 
4, files & folders
4, files & folders4, files & folders
4, files & foldersted-xu
 
unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版Jie Bao
 
linux安装以及LAMP 环境安装详细
linux安装以及LAMP 环境安装详细linux安装以及LAMP 环境安装详细
linux安装以及LAMP 环境安装详细colderboy17
 
makefile20141121
makefile20141121makefile20141121
makefile20141121Kevin Wu
 
Linux必学的60个命令
Linux必学的60个命令Linux必学的60个命令
Linux必学的60个命令yiditushe
 
Linux常用命令与工具简介
Linux常用命令与工具简介Linux常用命令与工具简介
Linux常用命令与工具简介weihe
 
Unixtoolbox zh cn
Unixtoolbox zh cnUnixtoolbox zh cn
Unixtoolbox zh cnxdboy2006
 
Debian 套件打包教學指南 v0.19 - 繁體中文翻譯
Debian 套件打包教學指南 v0.19 - 繁體中文翻譯Debian 套件打包教學指南 v0.19 - 繁體中文翻譯
Debian 套件打包教學指南 v0.19 - 繁體中文翻譯SZ Lin
 
CentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 ZendCentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 Zendwensheng wei
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结Yiwei Ma
 
Lamp安全全攻略
Lamp安全全攻略Lamp安全全攻略
Lamp安全全攻略Da Zhao
 

Ähnlich wie Linux基础 (20)

Linux安全配置终极指南
Linux安全配置终极指南Linux安全配置终极指南
Linux安全配置终极指南
 
Linuxcommand
LinuxcommandLinuxcommand
Linuxcommand
 
Unix常用命令 1
Unix常用命令 1Unix常用命令 1
Unix常用命令 1
 
5, system admin
5, system admin5, system admin
5, system admin
 
4, files & folders
4, files & folders4, files & folders
4, files & folders
 
unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版
 
linux安装以及LAMP 环境安装详细
linux安装以及LAMP 环境安装详细linux安装以及LAMP 环境安装详细
linux安装以及LAMP 环境安装详细
 
makefile20141121
makefile20141121makefile20141121
makefile20141121
 
Linux必学的60个命令
Linux必学的60个命令Linux必学的60个命令
Linux必学的60个命令
 
Linux常用命令与工具简介
Linux常用命令与工具简介Linux常用命令与工具简介
Linux常用命令与工具简介
 
Linuxguide4f2e
Linuxguide4f2eLinuxguide4f2e
Linuxguide4f2e
 
LinuxGuide4F2E
LinuxGuide4F2ELinuxGuide4F2E
LinuxGuide4F2E
 
Unixtoolbox zh cn
Unixtoolbox zh cnUnixtoolbox zh cn
Unixtoolbox zh cn
 
unixtoolbox_zh_CN
unixtoolbox_zh_CNunixtoolbox_zh_CN
unixtoolbox_zh_CN
 
Unix常用命令
Unix常用命令Unix常用命令
Unix常用命令
 
Debian 套件打包教學指南 v0.19 - 繁體中文翻譯
Debian 套件打包教學指南 v0.19 - 繁體中文翻譯Debian 套件打包教學指南 v0.19 - 繁體中文翻譯
Debian 套件打包教學指南 v0.19 - 繁體中文翻譯
 
Asm+aix
Asm+aixAsm+aix
Asm+aix
 
CentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 ZendCentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 Zend
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结
 
Lamp安全全攻略
Lamp安全全攻略Lamp安全全攻略
Lamp安全全攻略
 

Linux基础

  • 4. 文件管理 pwd, ls, cd, cp pwd   //打印当前目录 ls       //打印目录下的文件 cd      //切换目录 ex: cd ~ cd - cp      //复制文件 ex: cp /path/file/from /path/file/to cp -R /etc ~/etc_bak  
  • 5. mv, rm mv   //移动文件 ex: mv /path/file/from /path/file/to 用来移动文件、文件夹和重命名 rm   //remove的简称,移除文件 ex: rm /path/file rm -rf /path/dir 这个命令一定要小心, 最好不使用
  • 6. mkdir, rmdir mkdir ex: mkdir dirname mkdir -p 2010/12/01 -p参数用来创建目标目录的上层目录,但即使这些目录已 存在也不当作错误处理 rmdir ex:  rmdir dirname //删除空文件夹  rmdir -p a/b/c //删除指定目录及其上级文件 夹    与"rmdir a/b/c a/b a'" 基本相同
  • 7. ln ln   //创建链接 ex:  ln aaa bbb //为aaa创建一个硬链接bbb  ln -s aaa bbb //为aaa创建一个软链接bbb 一般创建软链接就可以了 相当于创建一个快捷方式
  • 8. 压缩解压缩 zip, unzip, tar, gzip, gunzip zip  ex: zip xxx.zip xxx/*  压缩xxx文件夹下面的文件到xxx. zip unzip  ex: unzip xxx.zip tar ex: tar -xjvf xxx.tar.bz2 tar -zxvf xxx.tar.gz -C /tmp tar -zcvf xxx.tar.gz xxx gzip gunzip
  • 9. 文件内容相关 cat, more, less, head, tail cat  //从第一行开始显示文件内容, 而tac则是反过来 ex cat xxx  tac xxx more//一页一页的显示文件的内容 less  //和more类似,他可以往前翻 head//将文件内容的头10 行显示 tail  //将文件内容的尾部开始显示 ex: tail -f production.log -f 参数即时输出文件变化后追加的数据
  • 10. 权限相关 chmod, chown r-w-x = 4-2-1 [所有者][组][其他用户] chmod //改变文件权限 ex: chmod 755 /path/file chmod 755 -R /path/dirname chown //改变文件的所有者或组 ex: chown root /path/file chown root:root /path/file chown root:root -hR /path/dirname //将dirname下面 的所有文件的owner和group改为root
  • 11. 重定向和管道 >  | >  //重定向 ex: cat xxx > yyy 将标准输出stdout重定向到文件或其他 |  //管道  ex: ps -aux|grep ruby //ps -aux的输出通过管道用grep去 匹配出含有ruby的进程
  • 12. 搜索文件 find, which, whereis, locate find      //查找文件 ex: find ~/workspace/NetBeansProjects/ -name '*.yml' which   //查找可执行文件的位置 ex: which mysql whereis //查找文件的位置(binary, source, and manual page files)  ex: whereis mysql locate   //从系统数据库中查找文件 ex: locate mysql
  • 13. 用户管理 adduser, deluser, addgroup, delgroup adduser ex: adduser user1 //添加新用户user1 adduser user1 sudo //将user1添加到sudo组 deluser ex: deluser user1 addgroup ex:  addgroup xxx delgroup ex: delgroup xxx
  • 14. 用户管理 passwd passwd ex passwd //改变当前用户的密码 passwd username //改变username的密码 passwd -l username //锁定(lock) passwd -u username //解锁(unlock)
  • 15. 系统管理 shutdown, halt, poweroff, reboot shutdown ex: shutdown 16:33 shutdown +5 shutdown now shutdown -r  // ==reboot halt //关闭系统 poweroff //关闭系统并切断系统电源 reboot //重新启动
  • 16. ps, kill, killall, free, df ps   //查看进程 ex: ps -aux kill ex: kill -9 3232 //杀死3232这个进程 killall ex: killall -9 ruby free //查看内存的使用情况 df //硬盘的使用情况  ex: df -h
  • 19. 其他命令  who, w, whoami, uname who         //显示谁登陆了 w             //显示谁登陆了 并且在干什么 whoami    //显示用户名 uname      //输出一组系统信息 ex uname -a Linux eric-desktop 2.6.35-23-generic #41-Ubuntu SMP Wed Nov 24 10:18:49 UTC 2010 i686 GNU/Linux
  • 20. 其他命令 cron, ping, route, ifconfig cron     //作业调度 ex: crontab -e //编辑系统的crontab文件  00 4 * * * sh /home/eric/rsync_db.sh //表示每日4点 去执行这个rsync_db.sh脚本  # m h  dom mon dow   command // 分钟,小时,天 (1-31), 月份(1-12),星期几(1-7), 命令 ping    //ping 8.8.8.8 route   //内核 IP 路由表 ifconfig//网络接口配置
  • 21. 远程访问与文件传输 ssh, scp ssh 服务器端需要有sshd server openssh-server apt-get install openssh-server config file: /etc/ssh/ssh_config   客户端机器默认有ssh client ssh username@jkydjk.com config_file:vim ~/.ssh/config scp 远程文件传输  scp xxx eric@lxneng.com:/tmp  scp eric@lxneng.com:/tmp/text.txt ./
  • 22. 下载 wget, curl wget ex: wget wget http://www.google. com/intl/en_ALL/images/srpr/logo1w.png //写到 logo1w.png wget -mk http://google.com  //镜像 wget -O google.htm http://google.com //写到 google.html curl  ex: curl http://google.com //标准输出 curl -o xxx http://google.com //写到xxx curl -I http://google.com  //看head信息