在Linux系统中 第一块网卡的名称为eth0
第二块网卡的名称为eth1
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:19:D1:83:A3:DD
inet addr:192.168.12.93 Bcast:192.168.12.255 Mask:255.255.255.0
inet6 addr: fe80::219:d1ff:fe83:a3dd/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:404422135 errors:0 dropped:0 overruns:0 frame:0
TX packets:287192081 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:611426610 (583.1 MiB) TX bytes:3485490838 (3.2 GiB)
Base address:0xecc0 Memory:dfde0000-dfe00000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:93899704 errors:0 dropped:0 overruns:0 frame:0
TX packets:93899704 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1908943876 (1.7 GiB) TX bytes:1908943876 (1.7 GiB)
lo:0 Link encap:Local Loopback
inet addr:192.168.12.202 Mask:255.255.255.255
UP LOOPBACK RUNNING MTU:16436 Metric:1
gedit 为linux下的一个文本编辑器,
通过rpm -q 命令查询gedit是否安装
[root@localhost ~]# rpm -q gedit
gedit-2.16.0-5.el5
/
/root 超级管理员的宿主(家)目录
/bin 在linux系统中,登录时,分为超级管理员和普通用户权限,此目录存放的是普通用户能执行的命令,为二进制文件
/boot 存放系统启动文件和内核文件
/dev 存放一切设备文件 sda 第一块硬盘 /dev/sda
/etc 类似于windows中的注册表,配置文件都放在此目录中
/var 存放的为日志文件
/lib 存放动态库文件
/usr 存放第三方程序
/media 存放临时设备文件
root@localhost ~]# iduid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)[root@localhost ~]# id portaluid=500(portal) gid=500(portal) groups=500(portal)[portal@localhost ~]$ su posterftp¿ÚÁ[posterftp@localhost portal]$ iduid=506(posterftp) gid=506(posterftp) groups=506(posterftp)
id + 用户名 作用:查看用户信息
以上"#"代表以管理员的账号登录
[root@localhost ~]# su - portal[portal@localhost ~]$ iduid=500(portal) gid=500(portal) groups=500(portal)如果id后面不跟任何用户名,则代表查看当前用户信息
以上“$“ 代表当前登录的是普通用户
[root@localhost ~]# uname --help用法: uname [选项]...Print certain system information. With no OPTION, same as -s.-a, --all print all information, in the following order, except omit -p and -i if unknown: -s, --kernel-name print the kernel name -n, --nodename print the network node hostname -r, --kernel-release print the kernel release -v, --kernel-version print the kernel version -m, --machine print the machine hardware name -p, --processor print the processor type or "unknown" -i, --hardware-platform print the hardware platform or "unknown" -o, --operating-system print the operating system --help 显示此帮助信息并推出 --version 输出版本信息并推出
[root@localhost ~]# uname -aLinux localhost.localdomain 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:02 EDT 2007 i686 i686 i386 GNU/Linux[root@localhost ~]# uname -sLinux[root@localhost ~]# uname -nlocalhost.localdomain[root@localhost ~]# uname -r2.6.18-53.el5[root@localhost ~]# uname -v#1 SMP Wed Oct 10 16:34:02 EDT 2007[root@localhost ~]# uname -mi686[root@localhost ~]# uname -pi686[root@localhost ~]# uname -ii386[root@localhost ~]# uname -oGNU/Linuxhostname 查看计算机的主机名称
[root@localhost ~]# hostnamelocalhost.localdomain计算机名称 所在域的名称
ifconfig 查看网络信息
[root@localhost ~]# ifconfig eth0eth0 Link encap:Ethernet HWaddr 00:19:D1:83:A3:DD inet addr:192.168.12.93 Bcast:192.168.12.255 Mask:255.255.255.0 inet6 addr: fe80::219:d1ff:fe83:a3dd/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:404433260 errors:0 dropped:0 overruns:0 frame:0 TX packets:287196844 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:613335905 (584.9 MiB) TX bytes:3486391094 (3.2 GiB) Base address:0xecc0 Memory:dfde0000-dfe00000 [root@localhost ~]# ifconfigeth0 Link encap:Ethernet HWaddr 00:19:D1:83:A3:DD inet addr:192.168.12.93 Bcast:192.168.12.255 Mask:255.255.255.0 inet6 addr: fe80::219:d1ff:fe83:a3dd/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:404434038 errors:0 dropped:0 overruns:0 frame:0 TX packets:287197141 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:613445293 (585.0 MiB) TX bytes:3486464992 (3.2 GiB) Base address:0xecc0 Memory:dfde0000-dfe00000lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:94028091 errors:0 dropped:0 overruns:0 frame:0 TX packets:94028091 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2949724985 (2.7 GiB) TX bytes:2949724985 (2.7 GiB)
lo:0 Link encap:Local Loopback inet addr:192.168.12.202 Mask:255.255.255.255 UP LOOPBACK RUNNING MTU:16436 Metric:1
lo 网络回环地址通常用来测试网卡是否损坏
[root@localhost ~]# ip addr show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet 192.168.12.202/32 brd 192.168.12.202 scope global lo:0 inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 100 link/ether 00:19:d1:83:a3:dd brd ff:ff:ff:ff:ff:ff inet 192.168.12.93/24 brd 192.168.12.255 scope global eth0 inet6 fe80::219:d1ff:fe83:a3dd/64 scope link valid_lft forever preferred_lft forever3: sit0: <NOARP> mtu 1480 qdisc noop link/sit 0.0.0.0 brd 0.0.0.0[root@localhost ~]#ip addr show 查看计算机的ip地址[可查看虚拟IP]
区别
ifconfig 查看物理的ip地址,网卡上有ip地址 vip 虚拟ip地址通过此命令显示不出来,只能通过ip addr show显示
[root@localhost ~]# cat /proc/cpuinfo //查看cpu信息 processor : 0vendor_id : GenuineIntelcpu family : 15model : 6model name : Intel(R) Pentium(R) D CPU 3.00GHzstepping : 5cpu MHz : 2992.656cache size : 2048 KB
查看内存信息
[root@localhost ~]# cat /proc/meminfo
MemTotal: 2065848 kB
MemFree: 88728 kB
Buffers: 138308 kB
Cached: 225556 kB
查看内存使用情况
[root@localhost ~]# free --help
free: invalid option -- -
usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
-b,-k,-m,-g show output in bytes, KB, MB, or GB
-l show detailed low and high memory statistics
-o use old format (no -/+buffers/cache line)
-t display total for RAM + swap
-s update every [delay] seconds
-c update [count] times
-V display version information and exit
[root@localhost ~]# free -m -l
total used free shared buffers cached
Mem: 2017 1930 87 0 134 219
Low: 875 820 54
High: 1142 1109 33
-/+ buffers/cache: 1576 441
Swap: 1983 55 1928
[root@localhost ~]# free -m -o
total used free shared buffers cached
Mem: 2017 1930 87 0 134 219
Swap: 1983 55 1928
[root@localhost ~]# free -m -t
total used free shared buffers cached
Mem: 2017 1964 53 0 134 252
-/+ buffers/cache: 1576 441
Swap: 1983 55 1928
Total: 4001 2019 1981
[root@localhost ~]# free -m -s 1
total used free shared buffers cached
Mem: 2017 1930 86 0 134 219
-/+ buffers/cache: 1576 441
Swap: 1983 55 1928
total used free shared buffers cached
Mem: 2017 1930 86 0 134 219
-/+ buffers/cache: 1576 441
Swap: 1983 55 1928
total used free shared buffers cached
Mem: 2017 1930 86 0 134 219
-/+ buffers/cache: 1576 441
Swap: 1983 55 1928
[root@localhost ~]# free -m -c 1
total used free shared buffers cached
Mem: 2017 1961 55 0 134 250
-/+ buffers/cache: 1576 441
Swap: 1983 55 1928
[root@localhost ~]# free -m total used free shared buffers cachedMem: 2017 1965 52 0 135 254-/+ buffers/cache: 1575 441Swap: 1983 55 1928
shutdown -h now
poweroff 关机的同时关闭电源,需要主板支持
命令和选项之间必须用空格隔开,选项和参数也是如此,区分大小写
shutdown、reboot 重启
[root@localhost ~]# shutdown -r +15 'The system will be shutdown!'
Broadcast message from root (pts/1) (Sat Sep 15 00:39:35 2012):
The system will be shutdown!
The system is going DOWN for reboot in 15 minutes!
Shutdown cancelled.
ctrl +c 取消重启
shutdown -c 取消重启
命令的执行依赖于解释器程序(例如:/bin/bash)
内部命令 系统启动直接存放在内存中[系统本身存在,在任何目录中执行时,都不需要输入命令的绝对路径]
外部命令 存放在硬盘中[如windows 中的 QQ]
命令字 [选项] [参数]
选项:用于调节命令的具体功能
以”-“引导短格式选项(单个字符)
以"--"引导长格式选项
ls -l 查看目录下又哪些文件,以及文件的详细信息
Tab 键可以为命令和目录自动补齐
反斜杠”\“为强制换行
[root@localhost ~]# \
>
快捷键
ctrl+u 当前光标清空至行首
ctrl+k 当前光标清空至行尾[有疑问]
ctrl+l 清屏clear
ctrl+c 取消本次命令编辑
命令的"--help"选项
ls --help 查看帮助
man ls
man 查看命令的手册页
man ls | col -b > lshelp/txt
>输出重定向[会覆盖原有文件中的内容]
>>追加
查看及切换目录
pwd 查看当前目录
cd 【从/开始的路径称为绝对路径,从当前所在的路径开始的路径称为相对路径】
cd .. 返回上一级
cd - 【返回到上一次所用到的目录】
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd /home/portal/
[root@localhost portal]# cd ..
[root@localhost home]# pwd
/home
[root@localhost home]# cd -
/home/portal
[root@localhost portal]# cd /home/portal/henan/
[root@localhost henan]# cd -
/home/portal
[root@localhost portal]# pwd
/home/portal
[root@localhost portal]# cd /tmp/
[root@localhost tmp]# cd -
/home/portal
[root@localhost portal]# cd /etc/
[root@localhost etc]# cd -
/home/portal
cd ~
cd
返回到用户的宿主(家)目录
[root@localhost portal]# cd
[root@localhost ~]# cd ~
ls
[root@localhost ~]# ls -l /tmp
总计 12
drwx------ 2 root root 4096 2007-11-30 keyring-cwMrip
srwxr-xr-x 1 root root 0 2007-11-30 mapping-root
srwxrwxrwx 1 root root 0 08-26 22:28 mongodb-27017.sock
srwxr-xr-x 1 root root 0 2007-11-30 scim-bridge-0.3.0.socket-0@localhost:0.0
srw------- 1 root root 0 2007-11-30 scim-helper-manager-socket-root
srw------- 1 root root 0 2007-11-30 scim-panel-socket:0-root
srw------- 1 root root 0 2007-11-30 scim-socket-frontend-root
drwxr-xr-x 2 root root 4096 09-06 13:37 test
drwxrwxr-x 3 test1 test1 4096 09-06 13:42 test1
-rw-r--r-- 1 lijian portal 0 09-08 17:03 testAq.log
[root@localhost ~]# ls -ld /tmp
drwxrwxrwt 8 root root 36864 09-15 01:02 /tmp
[root@localhost ~]# ls -a /tmp
. mapping-root test
.. mongodb-27017.sock test1
.font-unix scim-bridge-0.3.0.socket-0@localhost:0.0 testAq.log
.gdm_socket scim-helper-manager-socket-root .X0-lock
.ICE-unix scim-panel-socket:0-root .X11-unix
keyring-cwMrip scim-socket-frontend-root
[root@localhost ~]# ls -A /tmp
.font-unix mongodb-27017.sock test
.gdm_socket scim-bridge-0.3.0.socket-0@localhost:0.0 test1
.ICE-unix scim-helper-manager-socket-root testAq.log
keyring-cwMrip scim-panel-socket:0-root .X0-lock
mapping-root scim-socket-frontend-root .X11-unix
[root@localhost ~]#
ls -l
ls -ld 查看目录的详细信息
ls -a 查看指定目录下的所有文件[包括隐藏文件 隐藏文件以.开始 , ..代表上一级目录]
ls -A 不显示.和..
软链接 快捷方式[源文件删除,此链接不能使用,链接中文件内容修改,源文件也发生变化,ln -s]
硬链接 文件拷贝[源文件删除,此链接文件变为一个普通文件,不需要加-s直接创建]
查看目录及每个文件的大小
du -h 以简单明了的方式显示
du -sh 目录[统计目录所占用的空间]
[root@localhost ~]# du -h /tmp
4.0K /tmp/.X11-unix
8.0K /tmp/test1/.kde/Autostart
12K /tmp/test1/.kde
40K /tmp/test1
4.0K /tmp/test
4.0K /tmp/.font-unix
4.0K /tmp/keyring-cwMrip
4.0K /tmp/.ICE-unix
104K /tmp
[root@localhost ~]# du -sh /tmp
104K /tmp
mkdir test 创建目录
mkdir -p test1/test2 创建递归的目录
rm -rf test1 强制删除递归目录
touch test.txt 此命令可以创建多个文件
file test.txt 查看文件属性
[root@localhost tmp]# touch test1.txt
[root@localhost tmp]# file test1
test1/ test1.txt
[root@localhost tmp]# file test1
test1/ test1.txt
[root@localhost tmp]# file test1.txt
test1.txt: empty
ls -t
ls -R 递归显示内容
ls -lh 显示单位大小
s 开头代表为socket文件 接口文件
--color
ls install.log*
* 代表一个字符
?代表一个数字字母或者符号
??? 代表后面只有三个数字字母符号
创建隐藏目录 mkdir .text
alias 定义别名
mv -i 修改前会有交互信息输出
alias qq='ls -a' //执行qq就代表执行ls -a
unalias qq
df 查看系统分区使用情况
//创建软连接[快捷方式,源文件删除,此链接不能使用,软链接中文件内容修改,源文件也发生变化]
[root@localhost tmp]# echo "123" > sourceFile 新建一个内容为123的文件,文件名称为sourceFile
[root@localhost tmp]# ln -s sourceFile softlink 创建软链接
源文件
[root@localhost tmp]# ll
总计 8
drwx------ 2 root root 4096 2007-11-30 keyring-cwMrip
srwxr-xr-x 1 root root 0 2007-11-30 mapping-root
srwxrwxrwx 1 root root 0 08-26 22:28 mongodb-27017.sock
srwxr-xr-x 1 root root 0 2007-11-30 scim-bridge-0.3.0.socket-0@localhost:0.0
srw------- 1 root root 0 2007-11-30 scim-helper-manager-socket-root
srw------- 1 root root 0 2007-11-30 scim-panel-socket:0-root
srw------- 1 root root 0 2007-11-30 scim-socket-frontend-root
lrwxrwxrwx 1 root root 10 09-15 23:20 softlink -> sourceFile //已创建的软链接
-rw-r--r-- 1 root root 4 09-15 23:17 sourceFile //源文件
[root@localhost tmp]# cat softlink //查看软链接中的内容和源文件中的内容一致
123
[root@localhost tmp]# cat sourceFile //查看源文件中的内容
123
[root@localhost tmp]# echo "1234" >> softlink //修改软链接文件中的内容
[root@localhost tmp]# cat softlink //查看软链接文件中的内容
123
1234
[root@localhost tmp]# cat sourceFile //查看源文件中的内容
123
1234
//由此可见,当修改软链接中的内容时,源文件的内容页发生变化
[root@localhost tmp]# echo "12345" >> sourceFile //修改源文件中的内容
[root@localhost tmp]# cat sourceFile
123
1234
12345
[root@localhost tmp]# cat softlink
123
1234
12345
//修改源文件中的内容,软链接中的内容页发生变化
[root@localhost tmp]# rm -rf sourceFile
当删除了源文件时,软链接文件则无法访问
//创建硬连接[文件拷贝,源文件删除,此链接文件变为一个普通文件]
[root@localhost tmp]# echo "123456" > sourceFile
[root@localhost tmp]# ll
总计 8
drwx------ 2 root root 4096 2007-11-30 keyring-cwMrip
srwxr-xr-x 1 root root 0 2007-11-30 mapping-root
srwxrwxrwx 1 root root 0 08-26 22:28 mongodb-27017.sock
srwxr-xr-x 1 root root 0 2007-11-30 scim-bridge-0.3.0.socket-0@localhost:0.0
srw------- 1 root root 0 2007-11-30 scim-helper-manager-socket-root
srw------- 1 root root 0 2007-11-30 scim-panel-socket:0-root
srw------- 1 root root 0 2007-11-30 scim-socket-frontend-root
-rw-r--r-- 1 root root 7 09-15 23:50 sourceFile
[root@localhost tmp]# cat sourceFile
123456
[root@localhost tmp]# ln sourceFile hardLink
[root@localhost tmp]# ll
总计 12
-rw-r--r-- 2 root root 7 09-15 23:50 hardLink
drwx------ 2 root root 4096 2007-11-30 keyring-cwMrip
srwxr-xr-x 1 root root 0 2007-11-30 mapping-root
srwxrwxrwx 1 root root 0 08-26 22:28 mongodb-27017.sock
srwxr-xr-x 1 root root 0 2007-11-30 scim-bridge-0.3.0.socket-0@localhost:0.0
srw------- 1 root root 0 2007-11-30 scim-helper-manager-socket-root
srw------- 1 root root 0 2007-11-30 scim-panel-socket:0-root
srw------- 1 root root 0 2007-11-30 scim-socket-frontend-root
-rw-r--r-- 2 root root 7 09-15 23:50 sourceFile
[root@localhost tmp]# cat hardLink
123456
[root@localhost tmp]# echo "1234567" >> sourceFile
[root@localhost tmp]# cat hardLink
123456
1234567
[root@localhost tmp]# echo "1234567" >> hardLink
[root@localhost tmp]# cat hardLink
123456
1234567
1234567
[root@localhost tmp]# cat sourceFile
123456
1234567
1234567
[root@localhost tmp]# rm -rf sourceFile
[root@localhost tmp]# cat hardLink
123456
1234567
1234567
[root@localhost tmp]#
总结,不管修改软链接文件还是硬链接文件,都会影响源文件内容,区别是
软链接将源文件删除后,链接文件不能访问
硬链接将源文件删除后,链接文件依然可以访问
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options
too.
-a, --archive
same as -dpR
--backup[=CONTROL]
make a backup of each existing destination file
-b like --backup but does not accept an argument
--copy-contents
copy contents of special files when recursive
-d same as --no-dereference --preserve=link
-f, --force
if an existing destination file cannot be opened, remove it and
try again
-i, --interactive
prompt before overwrite
-H follow command-line symbolic links
-l, --link
link files instead of copying
-L, --dereference
always follow symbolic links
-P, --no-dereference
never follow symbolic links
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,owner-
ship,timestamps) and security contexts, if possible additional
attributes: links, all
--no-preserve=ATTR_LIST
don¡¯t preserve the specified attributes
--parents
use full source file name under DIRECTORY
-R, -r, --recursive
copy directories recursively
--remove-destination
remove each existing destination file before attempting to open
it (contrast with --force)
--sparse=WHEN
control creation of sparse files
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-s, --symbolic-link
make symbolic links instead of copying
-S, --suffix=SUFFIX
override the usual backup suffix
-t, --target-directory=DIRECTORY
copy all SOURCE arguments into DIRECTORY
-T, --no-target-directory
treat DEST as a normal file
-u, --update
copy only when the SOURCE file is newer than the destination
file or when the destination file is missing
-v, --verbose
explain what is being done
-x, --one-file-system
stay on this file system
--help display this help and exit
-Z, --context=CONTEXT
set security context of copy to CONTEXT
--version
output version information and exit
[root@localhost tmp]# touch cptest
[root@localhost tmp]# ll
总计 8
-rw-r--r-- 1 root root 0 09-16 00:16 cptest
[root@localhost tmp]# ls -lh /root/ |grep cptest
-rw-r--r-- 1 root root 0 09-16 00:17 cptest
[root@localhost tmp]# cp -i cptest /root
cp 是否覆盖 root/cptest¡±? yes
[root@localhost tmp]# ls -lh /root/ |grep cptest
-rw-r--r-- 1 root root 0 09-16 00:18 cptest
[root@localhost tmp]# ls -p /root/ |grep cptest
cptest
[root@localhost tmp]# ls -lh /root/ |grep cptest
-rw-r--r-- 1 root root 0 09-16 00:18 cptest
[root@localhost tmp]# cp -i cptest /root
cp是否覆盖/root/cptest¡±? yes
[root@localhost tmp]# ls -lh /root/ |grep cptest
-rw-r--r-- 1 root root 0 09-16 00:19 cptest
[root@localhost tmp]# cp -fp cptest /root
cp是否覆盖/root/cptest¡±? yes
[root@localhost tmp]# ls -lh /root/ |grep cptest
-rw-r--r-- 1 root root 0 09-16 00:16 cptest
[root@localhost tmp]# cp -i -p cptest /root
cp是否覆盖/root/cptest¡±? yes
[root@localhost tmp]# cp -f -p cptest /root
cp是否覆盖/root/cptest¡±? yes
[root@localhost tmp]#
-p 保存文件原有属性 same as --preserve = mode ,ownship,timestamps
-f 强制覆盖 提醒 if an existint destination file cannot be opened,remove it and try angin
-i 强制覆盖 提醒 prompt before overwrite
mv 移动文件或者更改名称
which 主要用于查找命令的绝对路径
[root@localhost tmp]# which ls
alias ls='ls --color=tty'
/bin/ls
[root@localhost tmp]# which vsftpd
/usr/sbin/vsftpd
[root@localhost tmp]# echo $PATH
/usr/java/jdk1.6.0_24/bin:/usr/java/jdk1.6.0_24/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/bin/gcc
find
-name
-size
-user
-type
-exec 将查找到的结果给exec后面的命令去执行
-ok
/etc/resolv.conf 中存放DNS的IP地址
[root@localhost tmp]# find /boot type d //在/boot文件中查找类型为目录的文件
/boot
/boot/grub
/boot/grub/grub.conf
/boot/grub/device.map
/boot/grub/e2fs_stage1_5
/boot/grub/vstafs_stage1_5
/boot/grub/stage2
/boot/grub/minix_stage1_5
/boot/grub/menu.lst
/boot/grub/fat_stage1_5
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option or the
-follow option is in effect, unless the symbolic link is
broken. If you want to search for symbolic links when -L
is in effect, use -xtype.
s socket
D door (Solaris)
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option or the
-follow option is in effect, unless the symbolic link is
broken. If you want to search for symbolic links when -L
is in effect, use -xtype.
s socket
D door (Solaris)
[root@localhost ~]# find /boot -size +1024k -a -name "vmlinuz*" //此处-a代表and
/boot/vmlinuz-2.6.18-53.el5
[root@localhost ~]# find /boot -size +1024k
/boot/vmlinuz-2.6.18-53.el5
/boot/initrd-2.6.18-53.el5.img
[root@localhost ~]# find /boot -size +1024k -o -name "vmlinuz*" //此处-o代表or
/boot/vmlinuz-2.6.18-53.el5
/boot/initrd-2.6.18-53.el5.img
[root@localhost ~]# find $HOME -print //$HOME代表用户主目录
[root@localhost ~]# find ~ -name "*.txt"/root/test1.txt
/root/text.txt
/root/456.txt
[root@localhost ~]# find ~ -name "[A-Z]*.txt"
/root/tomcat6_jdk6/RUNNING.txt
/root/tomcat6_jdk6/webapps/docs/RUNNING.txt
查找etc下passwd*文件中是否有nobody这个用户
[root@localhost ~]# find /etc -name "passwd*" -exec grep "nobody" {} \;
nobody:x:99:99:Nobody:/:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
[root@localhost ~]# find /etc -name "*conf" -mtime +5
/etc/avahi/avahi-daemon.conf
/etc/X11/xinit/xinput.d/none.conf
/etc/X11/xinit/xinput.d/scim.conf
/etc/X11/xinit/xinput.d/xim.conf
目录和文件管理
[root@localhost ~]# cat /etc/passwd [仅仅用来查看文件内容比较少的文件]
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@localhost ~]# more /etc/passwd[用来查看文件内容比较多的文件]
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
less /etc/passwd
[root@localhost ~]# head -2 /etc/passwd //查看文件前2行的内容
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@localhost ~]# tail /etc/passwd [默认显示后10行的内容]
[root@localhost ~]# tail -2 /etc/passwd 【显示后2行的内容】
test1:x:10004:10004::/tmp/test1:/bin/bash
test2:x:10005:10004::/tmp/test1:/bin/bash
wc 统计文件中的单词数量
[root@localhost ~]# wc /etc/hosts
4 23 185 /etc/hosts
行 单词 字节
[root@localhost ~]# wc -l /etc/passwd [仅仅统计行数]
60 /etc/passwd
-l 行数
-w 统计单词个数
grep -i 忽略大小写
-v 反转查找,输出与查找条件不相符的行
"^" 开头
“$” 结尾
"^$" 空行
[root@localhost ~]# cat /etc/vsftpd/vsftpd.conf |grep ^# //查找以#号开头的文本
# Example config file /etc/vsftpd/vsftpd.conf
#
[root@localhost ~]# cat /etc/vsftpd/vsftpd.conf |grep -v ^# //过滤掉以#好开头的文件
anonymous_enable=NO
local_enable=YES
write_enable=YES
gzip [-9] 文件名
bzip2 [-9] 文件名
以上只能压缩文件不能压缩目录
解压缩 gzip -d .gz格式的压缩文件
解压缩 bzip2 -d *.bz2格式的压缩文件
-9 表示高压缩比
-d 用于解压缩已经压缩过的文件
tar 命令 压缩目录
tar 制作归档文件 释放归档文件
tar [选项] 归档文件名 源文件名
[选项] 归档文件名
-c 创建
-x 解压
-v 输出响应信息
-f 表示使用归档文件
-p 保留文件属性
-t 查看文件内容
[root@localhost tmp]# dd if=/dev/zero of=test.dat1 count=2 bs=2M;
2+0 records in
2+0 records out
4194304 bytes (4.2 MB) copied, 0.011399 seconds, 368 MB/s
[root@localhost tmp]# ls -lh|grep test.dat1
-rw-r--r-- 1 root root 4.0M 09-20 23:44 test.dat1
linux 系统不区分扩展名称
tar -xzvf clvn.tar.gz 解压缩
tar -czvf clvn.tar.gz clvn
tar -jxvf 用来解压bz格式文件
[root@localhost tmp]# ls -lh|grep test.data*
-rw-r--r-- 1 root root 2.0M 09-18 21:07 test.dat
-rw-r--r-- 1 root root 4.0M 09-20 23:44 test.dat1
[root@localhost tmp]# tar -czvf test.tar.gz test.dat test.dat1
test.dat
test.dat1
[root@localhost tmp]# ls -lh|grep test
-rw-r--r-- 1 root root 0 09-16 00:16 cptest
-rw-r--r-- 1 lijian portal 0 09-16 17:03 testAq.log
-rw-r--r-- 1 root root 2.0M 09-18 21:07 test.dat
-rw-r--r-- 1 root root 4.0M 09-20 23:44 test.dat1
-rw-r--r-- 1 root root 6.2K 09-20 23:47 test.tar.gz
[root@localhost tmp]# mkdir test
[root@localhost tmp]# tar -xzvf test.tar.gz -C test //[将test.tar.gz解压到/test目录中]
test.dat
test.dat1
[root@localhost tmp]# ls -lh ./test
×Ü¼Æ 6.1M
-rw-r--r-- 1 root root 2.0M 09-18 21:07 test.dat
-rw-r--r-- 1 root root 4.0M 09-20 23:44 test.dat1
[root@localhost tmp]#
命令模式
输入模式
末行模式