linux基础02-文件系统

setup

/etc/sysconfig/network-scripts/ifcfg-eth0

 

ifconfig

-a

ifconfig eth2

ifconfig eth4 ip netmask xxx

ifconfig eth2 down

ifconfig eth2 up

ifdown eth2

ifup eth2

 

ping -c n IP

 

# cat /proc/sys/net/ipv4/icmp_echo_ignore_all

0

# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

 

/etc/hosts

IP hostname

 

/etc/resolv.conf

nameserver 114.114.114.114

nameserver 8.8.8.8

nameserver 10.1.1.254

 

route -n

route add -net 192.168.1.0/24 dev eth0

route del -net 192.168.1.0

route add -host 172.16.2.10 gw 10.1.1.254

route add default gw 10.1.1.254

route del default

 

uname -r

hostname|uname -n

 

kernel 应用程序 文件系统 shell

 

/etc:

/dev:

/root:

/home:

/var:

/tmp:

/bin:

/sbin:

/usr/bin:

/usr/sbin:

/usr/local:

/var/log:

/usr/src:

...

 

命令分类:

内部命令: man cd

shell程序(bash)自己集成的命令。

外部命令:

shell本身没有,需要执行其他程序才能实现。

 

type 命令:判断命令是外部还是内部

type command

 

# type echo

echo is a shell builtin shell内部集成 内部命令

# type shutdown

shutdown is /sbin/shutdown 调用外部程序upstart, 外部命令

# rpm -qf /sbin/shutdown

upstart-0.6.5-12.el6_4.1.x86_64

 

 

file 命令:判断文件类型

file filename

# file /dev/tty1

/dev/tty1: character special 字符设备

字符设备【输入输出】

输入:键盘、鼠标

输出:显示器、打印机

 

# file /dev/sda

/dev/sda: block special 块设备

软盘|U盘|光盘|磁带|硬盘

 

# file /dev/cdrom

/dev/cdrom: symbolic link to `sr0' 链接文件(类似windows快捷方式)

 

# file /dev/sr0

/dev/sr0: block special

 

linux下的文件类型:

-:普通文件

d:目录

s:socket文件(套接字),一般是网络程序和本地程序通讯的一种方式

p:管道文件,是进程之间通讯的一种方式

b:块设备

c:字符设备

l:链接文件

 

whatis command:简单查看命令的解释

which command:查看命令的存放路径

 

# whatis ls

ls (1) - list directory contents

ls (1p) - list directory contents

# which ls

alias ls='ls --color=auto' 别名

/bin/ls

 

基本命令:

ls:列出目录里的内容

-a:列出所有的文件包含隐藏文件 隐藏文件都是以.开头

-l:以长格式的形式列出

-h:查看大小

-m:用逗号隔开文件名列出

-t:按照时间排序,默认是升序

-rt:按照时间排序,将序排列

-R:递归列出

 

cd:更改工作路径

cd 回车 直接回到当前用户的家目录里

~:用户家目录

.:当前目录

..:上一级目录

-:上一次改变的路径

 

[root@node1 ~]#

root代表当前用户

node1代表主机命令

~ 代表当前工作路径

 

pwd 查看当前工作路径

 

touch命令:创建文件或者修改文件的时间戳

当目标文件不存在:创建一个新的空文件

touch filename

# touch file2 file3

# touch {1,2}{a,b,c}

如果文件名有特殊字符,可以使用双引号、单引号、反斜杠(转义)

# touch abc/"a b c"

# touch abc/'a b'

# touch abc/a\ b\ c\ d

 

当目标文件存在:修改文件的时间戳

 

# stat file1 查看文件的详细信息

File: `file1'

Size: 0 Blocks: 0 IO Block: 4096 regular empty file

Device: fd00h/64768d Inode: 275120 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2016-09-07 10:38:31.254889085 +0800 访问时间

Modify: 2016-09-07 10:38:31.254889085 +0800 修改时间

Change: 2016-09-07 10:38:31.254889085 +0800 属性时间

 

touch:

-a:修改文件的访问时间

-m:修改文件的修改时间

-d:修改文件的修改时间和访问时间

 

# touch -a file1 -t 201709091111

# touch -m file1 -t 202010101111

 

# stat file1

File: `file1'

Size: 12 Blocks: 8 IO Block: 4096 regular file

Device: fd00h/64768d Inode: 275120 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2017-09-09 11:11:00.000000000 +0800

Modify: 2020-10-10 11:11:00.000000000 +0800

Change: 2016-09-07 10:51:37.613888218 +0800

 

 

# touch -d 20181212 file3

# touch -d 11:11 file3

# touch -d "20091212 11:11" file3

 

mkdir命令:创建目录(文件夹)

 

# mkdir dir1

# mkdir dir2 dir3

# mkdir dir1/dd{1..5}.dir

 

# mkdir dir2/uplooking/redhat/test

mkdir: cannot create directory `dir2/uplooking/redhat/test': No such file or directory

 

# mkdir dir2/uplooking/redhat/test -p

-p:级联创建

 

rm和rmdir命令:删除文件或者目录

 

rm filename 删除一个文件

-f:强制删除,不提示

-r:递归删除 删除一个目录

-i:交互式删除

 

rmdir 删除空的目录

rm -rf dir1

 

rm -f file*

 

mv命令:移动或者重命名

# mv file2 test2 重命名

# mv /home/test1 /home/file1 重命名

 

# mv ./test2 dir2/ 移动

# mv file1 ./dir2/uplooking/redhat/test/test1 移动并重命名

 

# mv file* dir2/uplooking/

 

cp和scp命令:本地拷贝和远程拷贝(复制)

本地拷贝:cp

cp 要拷贝的文件(源文件) 拷贝的路径(目标路径)

# pwd

/home/dir2/uplooking

# cp file1 ../../

 

# cp file2 ../test2 拷贝过程中重命名

cp: overwrite `../test2'? y 如果目标路径下有相同的文件,会提示是否覆盖

 

# \cp file3 ../test2 目标目录下有相同的文件直接覆盖不提示 \cp

 

需要拷贝文件的属性信息:

-p

 

拷贝目录:

-r:递归拷贝

-rp

cp -rp dir1 /home

-a:拷贝所有信息(目录和文件)

cp -a dir1 /home

 

scp:远程拷贝

scp 本地文件 目标主机

scp file1 10.1.1.1:/tmp 将本地文件file1远程拷贝到10.1.1.1的/tmp里

scp 10.1.1.1:/tmp/test1 . 将远程服务器10.1.1.1的/tmp里的test1文件拷贝到本地当前目录

 

# scp file3 10.1.1.12:/tmp

root@10.1.1.12's password:

file3 100% 7 0.0KB/s 00:00

$ scp 10.1.1.12:/tmp/file3 /home/zhangsan

user01@10.1.1.12's password:

 

# scp user01@10.1.1.12:/tmp/file3 /home/zhangsan

user01@10.1.1.12's password:

file3 100% 7 0.0KB/s 00:00

 

查看文件的相关命令:

cat:查看小文件,将文件内容从第一行到最后一行列出

tac:查看小文件,从最后一行到第一行列出

 

more:查看大文件 q退出 /serach 搜索关键字

less:查看大文件 q退出 /serach 搜索关键字

 

head:默认查看文件的前10行

head -n file:查看文件的前n行

tail:默认查看文件的后10行

tail -n file:查看文件的后n行

tail -f file:动态实时查看日志情况

 

ldd:查看非普通的文件 二进制命令

 

alias:定义别名

alias 查看当前系统的别名

 

# alias kk='ls -l' 临时定义别名(只在当前终端当前用户生效)

# unalias kk 取消别名定义

 

永久定义别名:

只针对某个用户生效(局部):

# su - user01

$ vim ~/.bashrc

alias kk='ls -l'

...

 

$ kk

-bash: kk: command not found

马上生效:重新读取文件

$ source .bashrc

或者

$ . .bashrc

 

针对所有用户所有终端生效(全局):

# vim /etc/bashrc

...

alias cc='hostname'

 

# source .bashrc

 

说明:

局部和全局冲突,那么一般情况以局部为准

 

history:查看历史记录

-w:将历史记录保存到当前用户的家目录里的.bash_history

-c:清空历史记录

 

.bash_history:存放用户的历史记录

.bash_logout:用户退出时读取文件

.bash_profile:用户的环境变量

.bashrc:用户的别名或者默认掩码

 

bash 标准I/O输入输出

标准输入(stdin):键盘上的输入 文件描述符(0)

标准输出(stdout):屏幕上输出的正确结果 文件描述符(1)

标准错误(stderr):屏幕上输出的错误的结果 文件描述符(2)

 

重定向:将屏幕上输出的内容(正确和错误)保存到另一个文件中。

>:重定向

>>:追加

&:不在屏幕上显示

<:输入

 

 

/dev/null 空设备,无底洞

 

# ./test.sh

Wed Sep 7 14:54:59 CST 2016

node1.uplook.com

./test.sh: line 3: you: command not found

# ./test.sh 1>/tmp/log1

./test.sh: line 3: you: command not found

# ./test.sh 2>/tmp/log1

Wed Sep 7 14:56:51 CST 2016

node1.uplook.com

# ./test.sh > /dev/null 2>&1

# ./test.sh &>/dev/null

 

echo命令:输出,将输入的字符打印到屏幕,默认打印一个换行符

-n:不打印换行符

-e:解释转义字符

-E:不解释转义字符

 

# echo -e "a\tb\tc"

 

# echo 8888 > file2

# >file2

 

# cat >file3

1111111

2222222

uplooking

ctrl+d结束输入

 

# cat > file4 </etc/hosts

# cat </etc/fstab >file5

 

# cat >> file3 <<END 往file3文件里追加内容,遇到END结束输入

> 33333

> 4444

> 5555

> END

 

Linux怎么获取帮助:

help 简约帮助

man 文档

info 软件信息

 

内部命令:

help command

# help echo

外部命令:

command --help(-h)

# useradd --help

 

man 文档:

man man

MANUAL SECTIONS

The standard sections of the manual include:

 

1 User Commands 用户命令

 

2 System Calls 系统调用

 

3 C Library Functions 库文件和函数

 

4 Devices and Special Files 特殊文件和设备

 

5 File Formats and Conventions 文档说明(配置文件)

 

6 Games et. Al. 游戏相关

 

7 Miscellanea 杂项

 

8 System Administration tools and Deamons 系统管理员工具及程序

 

程序员:23468

运维:158

 

man 1 ls

man command

man 5 file.conf|command

 

-f:精确匹配

-k:模糊匹配

 

# man -f passwd

passwd (1) - update user's authentication tokens

passwd (5) - password file

passwd [sslpasswd] (1ssl) - compute password hashes

 

# man -k shut

....

shutdown (2) - shut down part of a full-duplex connection

shutdown (3p) - shut down socket send and receive operations

shutdown (8) - bring the system down

 

q:退出man文档

/:搜索关键字

 

# info /usr/share/doc/yum-3.2.29/INSTALL

 

/usr/share/doc/ 系统软件说明手册

 

总结:

遇到陌生命令,怎么办?

type——>内部|外部——>whatis xxx——>help command|command --help——>man(非常详细)——>google|百度|必应

 

练习:

1、在/home目录下创建uplook/redhat/test目录,然后在uplook目录下创建5个文件file1~file5;并且修改file1的日期为20200708,修改file2的修改时间为12:12:12

# mkdir /home/uplook/redhat/test -p

# touch /home/uplook/file{1..5}

# cd /home/uplook/

# touch -d 20200708 file1

# touch -d 12:12:12 file2

# touch -m file2 -t "201609071212"

 

2、将/home/uplook下的file1~file5文件移动到redhat/test目录下,并且重命名为test1~test5

# mv file* redhat/test/

# rename file test file?

 

3、将/home/uplook/redhat/下的test目录远程拷贝到10.1.1.254的/tmp/0905目录里,并且重命名成自己的名字zhagnsan;【user01/123】

# scp -r ./test user01@10.1.1.254:/tmp/0905/zhangsan

The authenticity of host '10.1.1.254 (10.1.1.254)' can't be established.

RSA key fingerprint is 86:2d:7e:c2:95:8c:2a:ea:69:25:13:3a:2a:1d:7e:c5.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '10.1.1.254' (RSA) to the list of known hosts.

user01@10.1.1.254's password:

test3 100% 0 0.0KB/s 00:00

test1 100% 0 0.0KB/s 00:00

test4 100% 0 0.0KB/s 00:00

test2 100% 0 0.0KB/s 00:00

test5 100% 0 0.0KB/s 00:00

4、删除/home/uplook目录下的所有文件

# rm -rf /home/uplook/*

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值