Linux 学习笔记,linux学习笔记
Linux 学习笔记,linux学习笔记
Linux学习笔记
1. 常用命令
命令存放,哪些命令可以执行?
root: |
/sbin /usr/sbin |
all users:
|
/bin /usr/bin |
bin--binary 二进制文件 Linux所有都是文件,都是二进制文件 usr—user sbin—super binary |
文件处理命令 |
|
||||
1 |
ls |
英文原意是list 功能:显示目录文件 属性可以连着写,比如ls -ld |
Eg |
含义 |
|
-a all |
显示所有文件,包括隐藏文件 |
ls -a / |
|
||
-l long |
详细信息显示 |
[root@localhost ~]# ls -l total 68 -rw------- 1 root root 1211 Feb 14 04:02 anaconda-ks.cfg drwxr-xr-x 3 root root 4096 Feb 14 11:20 Desktop -rw-r--r-- 1 root root 31736 Feb 14 04:02 install.log -rw-r--r-- 1 root root 0 Feb 14 03:16 install.log.syslog drwxr-xr-x 2 root root 4096 Feb 14 17:36 test |
drwxr-xr-x 2 root root 4096 Feb 14 11:20 每三个表示权限 表示硬连接数 所有者 所属组 文件大小 创建时间 数据块 block 512字节 第一个字符表示如下: d 目录directory - 二进制文件 l 软链接文件 每三个分配如下: r—read 读 w—write写 x—execute执行 rwx r-x r-x 所有者u 所属组g 其他人o user group others |
||
-d |
查看目录属性 |
[root@localhost ~]# ls -ld /test drwxr-xr-x 3 root root 4096 Feb 14 17:42 /test |
|
||
2 |
cd |
切换目录 |
|
|
|
Cd / |
进入根目录 |
|
|
||
Cd [目录] |
|
|
|
||
Cd .. |
返回父级目录 |
|
|
||
3 |
pwd |
英文:print working directory |
查看当前目录 |
[root@localhost ~]# pwd /root |
|
4 |
touch |
创建空文件 |
|
[root@localhost test]# touch testfile [root@localhost test]# ls -l testfile -rw-r--r-- 1 root root 0 Feb 14 18:51 testfile
|
|
5 |
mkdir |
英文:make directories |
创建空目录 |
[root@localhost ~]# mkdir test |
|
6 |
cp |
英文:copy |
复制文件 -R 复制目录 |
copy [源文件,可多个] [目的目录] [root@localhost test]# cp /etc/inittab /etc/services /test [root@localhost test]# ls /test abc.txt inittab lost+found samlee services testfile
将etc拷贝到test下 [root@localhost test]# cp -R /etc /test
|
/etc 主要是配置文件,很重要,记得备份 命令停止快捷键:Ctrl+c |
7. |
mv |
英文:move |
移动文件,改名 |
[root@localhost test]# ls /test abc.txt etc inittab lost+found samlee services testfile 改名: [root@localhost test]# mv services service [root@localhost test]# ls /test abc.txt etc inittab lost+found samlee service testfile 移动: [root@localhost test]# mv /test/inittab /tmp/ [root@localhost test]# ls /test abc.txt etc lost+found samlee service testfile 改名+移动: [root@localhost test]# mv /test/testfile /tmp/file.test [root@localhost test]# ls /tmp file.test scim-panel-socket:0-root gconfd-root scim-socket-frontend-root inittab ssh-yoUWCY4180 keyring-z1fmdW virtual-root.IYU2ep mapping-root vmware-config0 orbit-root VMwareDnD scim-bridge-0.3.0.lockfile-0@localhost:0.0 vmware-root scim-bridge-0.3.0.socket-0@localhost:0.0 vmware-root-592157060 scim-helper-manager-socket-root
|
|
8 |
rm |
remove |
删除 |
[root@localhost test]# ls /test abc.txt etc lost+found samlee service 删除service [root@localhost test]# rm service rm: remove regular file `service'? y [root@localhost test]# ls /test abc.txt etc lost+found samlee 删除不询问: [root@localhost test]# touch testfile [root@localhost test]# ls abc.txt etc lost+found samlee testfile [root@localhost test]# rm -f testfile [root@localhost test]# ls abc.txt etc lost+found samlee
|
rm –f 目录名称 不提示,强制删除,在写脚本的时候用,因为没有yes交互 |
9 |
cat |
concatenate and display files |
查看 |
[root@localhost test]# cat /etc/issue CentOS release 5.5 (Final) Kernel \r on an \m
|
适合查看文件小,因为多的话会把前面的覆盖,不能翻页。 比如cat /etc/services |
10 |
more |
(空格)或f 显示下一页 (enter)显示下一行 q或Q 退出 |
分页查看 |
[root@localhost test]# more /etc/services
|
|
11 |
head |
-num 文件名 |
查看文件前num行 |
[root@localhost test]# head -5 /etc/services # /etc/services: # $Id: services,v 1.42 2006/02/23 13:09:23 pknirsch Exp $ # # Network services, Internet style #
|
|
12 |
tail |
-num 文件名 -f 文件名 |
查看文件尾num行 动态查看文件尾部信息 |
[root@localhost test]# tail -5 /etc/services com-bardac-dw 48556/tcp # com-bardac-dw com-bardac-dw 48556/udp # com-bardac-dw iqobject 48619/tcp # iqobject iqobject 48619/udp # iqobject # Local services [root@localhost test]# tail -f /etc/services
|
tail –f 为了监视日志文件,默认显示10行 |
13 |
ln |
英文:link ln 文件名 目的目录 ln –s 文件名 目的目录 -s soft软连接 |
创建硬链接 创建软链接 |
[root@localhost test]# ln -s /etc/issue /issue.soft [root@localhost test]# ls -l /etc/issue /issue.soft -rw-r--r-- 1 root root 47 Apr 26 2010 /etc/issue lrwxrwxrwx 1 root root 10 Feb 14 16:51 /issue.soft -> /etc/issue
硬链接: [root@localhost test]# ln /etc/issue /issue.hard [root@localhost test]# ls -l /etc/issue /issue.hard -rw-r--r-- 2 root root 47 Apr 26 2010 /etc/issue -rw-r--r-- 2 root root 47 Apr 26 2010 /issue.hard
拷贝: [root@localhost test]# cp /etc/issue /test/issue [root@localhost test]# ls -l /etc/issue /test/issue -rw-r--r-- 2 root root 47 Apr 26 2010 /etc/issue -rw-r--r-- 1 root root 47 Feb 14 20:31 /test/issue
拷贝并且不改变时间,比如某些备份 [root@localhost test]# cp -p /etc/issue /test/issue cp: overwrite `/test/issue'? y [root@localhost test]# ls -l /etc/issue /test/issue -rw-r--r-- 2 root root 47 Apr 26 2010 /etc/issue -rw-r--r-- 1 root root 47 Apr 26 2010 /test/issue
|
软连接文件类型是l 软连接所有人都有权限,但能不能访问取决于源文件 软连接时间值 是创建软连接的时间 相当于快捷方式
类似于copy,文件大小相同 不同于copy的是,它是同步更新的。
还有一个不同的是,拷贝的时间是不同,时间是创建的时间
|
评论暂时关闭