3.linux管理

Linux系统管理
文件目录管理
文件权限管理
软件管理
磁盘管理
网络管理
进程服务管理
Linux优势
更适用于服务器
       开源(open source)特性
        最大化发挥硬件性能(cpu 内存)
Linux结构
内核(kernel)+外部程序
发行版本 Release
RHEL,CentOs,Fedora,SUSE,AASlorias,Ubunru
linux 目录结构
/ 根目录
/bin,/sbin,/user/sbin,/usr/sbin,/usr/local/bin,/usr/local/sbin    可执行程序,命令
/boot   启动分区
/dev        device设备文件(硬盘, 磁盘分区, 光盘, U盘)
/etc        各应用程序的配置文件
/home       普通用户的宿主目录/家目录 
                userA-------/home/userA
/root       root管理员的宿主目录/家目录
  1. 查看系统内核版本
student@student-VirtualBox:~/supervisor_demo$ uname -r
3.13.0-32-generic

student@student-VirtualBox:~/supervisor_demo$ uname -a
Linux student-VirtualBox 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:51:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
  1. 查看系统发型版本
student@student-VirtualBox:~/supervisor_demo$ cat /etc/issue
Ubuntu 12.04.5 LTS \n \l
  1. 查看计算机名字
student@student-VirtualBox:~/supervisor_demo$ uname -n
student-VirtualBox
student@student-VirtualBox:~/supervisor_demo$ hostname
student-VirtualBox
student@student-VirtualBox:~/supervisor_demo$ 

4.修改计算机名字(临时修改)

student@student-VirtualBox:~/supervisor_demo$ sudo hostname a
[sudo] password for student: 
student@student-VirtualBox:~/supervisor_demo$ hostname
a

5.显示日期时间

student@student-VirtualBox:~$ date
2017年 09月 16日 星期六 11:59:44 CST
student@student-VirtualBox:~$ date +%T
11:59:47
student@student-VirtualBox:~$ date +%F
2017-09-16
student@student-VirtualBox:~$ date +%F-%T
2017-09-16-11:59:58
student@student-VirtualBox:~$ date +%F~%T
2017-09-16~12:00:03
  1. 查看命令帮助文档
man COMMAND

Linux 文件目录管理

  1. 查看当前目录名称
student@student-VirtualBox:~$ pwd
/home/student
  1. 切换目录
cd DIRECTORY
  1. 查看目录下的文件
ls [option] [DIRECTORY|FILE]
student@student-VirtualBox:/tmp$ ls /tmp
at-spi2                                 ssh-OYvhKCUa1849
keyring-yqnPcX                          supervisord.log
newsite-stdout---supervisor-lFodCG.log  supervisord.pid
pulse-2L9K88eMlGn7                      supervisor.sock
pulse-PKdhtXMmr18n                      unity_support_test.1
pulse-yzpFdpwwz10v

option选项
-F     所有目录名称后会带有/
student@student-VirtualBox:~/new1$ ls -F
new2/
-a    查看隐藏文件(以点开头文件)
-R  层次显示目录下的文件 
student@student-VirtualBox:~$ ls -R new1
new1:
new2

new1/new2:

-l   以详细信息的方式列出文件
student@student-VirtualBox:~$ ls -l
总用量 260
-rw-r--r--  1 student student  8445  6月 29 16:50 examples.desktop
-rw-r--r--  1 root    root     1384  9月 15 10:00 html
-rw-rw-r--  1 student student     0  8月  3 10:54 index2
-rw-rw-r--  1 student student     0  8月  3 10:56 index234
-rw-rw-r--  1 student student     0  8月  3 10:55 index23.html
-rw-rw-r--  1 student student 89482  8月 31 21:25 java_error_in_PYCHARM_2366.log
-rw-rw-r--  1 student student 91576  9月  1 12:30 java_error_in_PYCHARM_3360.log
drwxrwxr-x  3 student student  4096  8月  3 14:39 new1

-h      带有可读性的单位K,M,G
student@student-VirtualBox:~$ ls -lh
总用量 260K
-rw-r--r--  1 student student 8.3K  6月 29 16:50 examples.desktop
-rw-r--r--  1 root    root    1.4K  9月 15 10:00 html
-rw-rw-r--  1 student student    0  8月  3 10:54 index2
-rw-rw-r--  1 student student    0  8月  3 10:56 index234
-rw-rw-r--  1 student student    0  8月  3 10:55 index23.html
-rw-rw-r--  1 student student  88K  8月 31 21:25 java_error_in_PYCHARM_2366.log
-rw-rw-r--  1 student student  90K  9月  1 12:30 java_error_in_PYCHARM_3360.log
drwxrwxr-x  3 student student 4.0K  8月  3 14:39 new1

查看/etc/passwd文件权限 
student@student-VirtualBox:~$ ls -lh /etc/passwd

-rw-r--r-- 1 root root 1.9K  9月 15 19:43 /etc/password
-d      显示目录的属性信息
student@student-VirtualBox:~$ ls -ldh /etc/
drwxr-xr-x 135 root root 12K  9月 16 11:26 /etc/


-t      按文件修改时间降序排列 
student@student-VirtualBox:~$ ls -lt
总用量 260
drwxrwxr-x  3 student student  4096  9月 16 11:31 supervisor_demo
drwxr-xr-x  7 student student  4096  9月 15 14:44 桌面
-rw-r--r--  1 root    root     1384  9月 15 10:00 html
drwxrwxr-x 12 student student  4096  9月 15 09:41 project
-rw-rw-r--  1 student student 91576  9月  1 12:30 java_error_in_PYCHARM_3360.log
-rw-rw-r--  1 student student 89482  8月 31 21:25 java_error_in_PYCHARM_2366.log
drwxrwxr-x  5 student student  4096  8月 29 11:38 new_2
drwxrwxr-x  6 student student  4096  8月 29 11:33 new_p
drwxr-xr-x  2 student student  4096  8月 23 10:59 下载
-rw-rw-r--  1 student student   183  8月  3 18:35 shi.text

-S      按文件大小降序排列 
student@student-VirtualBox:~$ ls -lhS
总用量 260K
-rw-rw-r--  1 student student  90K  9月  1 12:30 java_error_in_PYCHARM_3360.log
-rw-rw-r--  1 student student  88K  8月 31 21:25 java_error_in_PYCHARM_2366.log
-rw-r--r--  1 student student 8.3K  6月 29 16:50 examples.desktop
drwxrwxr-x  3 student student 4.0K  8月  3 14:39 new1
drwxrwxr-x  5 student student 4.0K  8月 29 11:38 new_2
drwxrwxr-x  6 student student 4.0K  8月 29 11:33 new_p
4. 统计文件目录大小
student@student-VirtualBox:~$ du -sh /etc/fstab
4.0K    /etc/fstab
student@student-VirtualBox:~$ sudo du -sh /etc
14M /etc

student@student-VirtualBox:~$ du -ah /etc/
  1. 统计文件行数
student@student-VirtualBox:~$ wc -l /etc/passwd
39 /etc/passwd

student@student-VirtualBox:~$ wc /etc/passwd
  39   63 1933 /etc/passwd

6.6 创建目录

mkdir [option] DIRECTORY

student@student-VirtualBox:~$ mkdir newtest

option选项:
-p  递归创建  -v 显示过程
student@student-VirtualBox:~/newtest$ mkdir -pv mysite/you
mkdir: 已创建目录 "mysite"
mkdir: 已创建目录 "mysite/you"

7.创建空白文件

touch FILE
student@student-VirtualBox:~/newtest$ touch 1.text
student@student-VirtualBox:~/newtest$ ls
1.text  mysite

花括号展开
student@student-VirtualBox:~/newtest$ touch test{1..10}.txt
student@student-VirtualBox:~/newtest$ ls
1.text  test10.txt  test2.txt  test4.txt  test6.txt  test8.txt
mysite  test1.txt   test3.txt  test5.txt  test7.txt  test9.txt

student@student-VirtualBox:~/newtest$ touch test{1,3,5,7}.jpg
student@student-VirtualBox:~/newtest$ ls
1.text      test1.jpg  test3.jpg  test5.jpg  test7.jpg  test9.txt
mysite      test1.txt  test3.txt  test5.txt  test7.txt
test10.txt  test2.txt  test4.txt  test6.txt  test8.txt

命令展开
反引号`COMMAND`
$(COMMAND)
student@student-VirtualBox:~/newtest$ touch /company/web_log_`date +%T`
student@student-VirtualBox:~/newtest$ touch /company/web_log_$(date +%

8.删除文件目录

rm [option] FILE
option选项:
-r      用于删除目录
-f      强制删除

9 复制文件目录

cp [option] SRC_FILE DST_FILE
-r      用于复制目录
-a      保留文件的权限属性信息
  1. 移动文件目录
mv SRC_FILE DST_FILE

在同目录下移动文件,相当于重命名 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,457评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,837评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,696评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,183评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,057评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,105评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,520评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,211评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,482评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,574评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,353评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,897评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,489评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,683评论 2 335

推荐阅读更多精彩内容

  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 12,112评论 2 34
  • Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音。了解发音是有意...
    萤火虫de梦阅读 99,016评论 9 467
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,497评论 18 139
  • 网络虚拟,信息繁杂,一天到晚的信息流量数以万记。就像毛爷爷那句话说的’坐地不动日行八万里。坐在家里电脑前,轻轻点击...
    穹涯阅读 1,251评论 8 6
  • 晚上打水,大爷大妈们在水房外说笑,“张大姐,你来跳跳,俺可不会,嘿嘿嘿嘿嘿”,“快点,让你跳舞呢”,他们每天起早贪...
    呜呼啦呼变阅读 230评论 0 0