文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Linux常用命令及参数

Linux常用命令及参数

时间:2006-05-30  来源:linux_debian

.     代表此层目录
..    代表上层目录
~     代表自己的家目录
~user 代表到 user 这个人的家目录

  • cd

语法:

[root @test /root ]# cd [相对路径或绝对路径] 
参数说明:
路径有『相对路径』与『绝对路径』的分别,请千万小心啰!
范例:
[root @test /root]# cd ..       <==回到上一层目录
[root @test /root]# cd ../home     <==相对路径的写法
[root @test /root]# cd /var/www/html  <==绝对路径的写法
[root @test /etc]# cd         <==回到使用者的家目录
[root @test /etc]# cd ~         <==回到使用者的家目录!
[root @test /etc]# cd ~test      <==回到 test 这个使用者的家目录

  • pwd


语法:

[root @test /root ]# pwd 
范例:
[root @test root]# cd /home/test
[root @test test]# pwd 
/home/test             <==显示目前你所在的目录呦!

  • mkdir


语法:

[root @test /root ]# mkdir [-mp] [目录名称]
参数说明:
-m :设定文件的权限喔!直接设定,不需要看 umask 这个内容的脸色!
-p :帮助你直接将上面的目录递归建立起来!
范例:
[root @test /root]# cd tmp
[root @test /tmp]# mkdir test<==建立名称为 test 的目录
[root @test /tmp]# mkdir -p test1/test2/test3/test4 <==直接建立 test2...等上层目录
[root @test /tmp]# mkdir -m 711 testqq  <==建立权限为 711 的目录!
[root @test /tmp]# ll test*
drwxrwxr-x    2 test    test        4096 Feb  6 20:47 test/
drwxrwxr-x    3 test    test        4096 Feb  6 20:48 test1/
drwx--x--x    2 test    test        4096 Feb  6 20:48 testqq/

  • rmdir


语法:

[root @test /root ]# rmdir [-p] [目录名称]
参数说明:
-p :将上层的目录也删除吧!
范例:
[root @test /root]# rmdir test<==删除名称为 test 的目录
[root @test tmp]# ll
drwxrwxr-x    3 test    test        4096 Feb  6 20:48 test1/
[root @test tmp]# rmdir test1
rmdir: `test1': Directory not empty
[root @test tmp]# rmdir -p test1/test2/test3/test4
[root @test tmp]$ ll

  • 环境变量 PATH

[root@test root]# echo $PATH
/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin

  ls
语法:

[root @test /root ]# ls [-ailS]
参数说明:
-a       :全部的文件都列出(连同隐藏档)
-i       :印出 inode 的值
-l       :长的列出,连同文件大小的数据等等
-S       :以文件大小排序
--color=never     :不要显示颜色
--color=always    :均显示颜色
--color=auto      :由系统自行判断!
范例:
[root @test /root]# ls -al
total 48
drwxr-x---    4 root     root         4096 Mar 10 00:37 .
drwxr-xr-x   21 root     root         4096 Mar 10 20:16 ..
-rw-------    1 root     root          524 Mar 10 00:40 .bash_history
-rw-r--r--    1 root     root           24 Jun 11  2000 .bash_logout
-rw-r--r--    1 root     root          266 Jun 11  2000 .bash_profile
-rw-r--r--    1 root     root          249 Mar  6 20:50 .bashrc
-rw-r--r--    1 root     root          210 Jun 11  2000 .cshrc
drwx------    2 root     root         4096 Mar  9 11:06 .gnupg
-rw-------    1 root     root          524 Jan 16 14:37 .mysql_history
drwx------    2 root     root         4096 Mar  9 11:06 .ssh
-rw-r--r--    1 root     root          196 Jul 11  2000 .tcshrc
-rw-r--r--    1 root     root         1126 Aug 24  1995 .Xresources
[root @test /]# ls
bin   dev    etc   lib         misc  opt   root  tftpboot  usr
boot  disk1  home  lost+found  mnt   proc  sbin  tmp       var
[root @test /]# ls --color=never
bin   dev    etc   lib         misc  opt   root  tftpboot  usr
boot  disk1  home  lost+found  mnt   proc  sbin  tmp       var
[root @test /]# ls -al|more

  cp
语法:

[root @test /root ]# cp [-drsu] [来源档] [目的檔]
参数说明:
-d     :在进行 copy 的时候,如果是 copy 到 link 文件,若不加任何参数,则预设情况中会将 link 到的源文件
       copy 到目的地,若加 -d 时,则 link 文件可原封不动的将 link 这个快捷方式其拷贝到目的地!
-r     :可以进行目录的 copy 呦!
-s          :做成连结档,而不 copy 之意!与 ln 指令相同功能!
-u, --update:如果来源档比较新,或者是没有目的档,那么才会进行 copy 的动作!可用于备份的动作中!
范例:
[root @test /root]# cp    .bashrc bashrc      <==将 .bashrc 拷贝成 bashrc 这个文件!
[root @test /root]# cp -r /bin /tmp/bin        <==这个功能就好玩啦!这是用来 copy 整个目录的参数!
[root @test /root]# cp -s .bashrc bashrc         <==将 .bashrc 建立一个连结档,档名为 bashrc
[root @test /root]# cp -u /home/.bashrc .bashrc  <==先检查 /home/.bashrc 是否与 .bashrc 不同,如果不同的话就开始 copy 一份!如果相同则不做任何动作!

  rm
语法:

[root @test /root ]# rm [-fir] [檔名]
参数说明:
-i     :提供使用者确认(这是默认值)
-r     :循环,就是一直杀掉,直到没有东西为止的意思
-f     :force ,就是强力杀掉啦!
范例:
[root @test /root]# cp .bashrc bashrc<==建立一个新文件, bashrc
[root @test /root]# rm bashrc           <==会显示如下的提示:
rm: remove `bashrc'?
[root @test /root]# mkdir testing
[root @test /root]# cp .bashrc testing
[root @test /root]# rmdir testing
rmdir: `testing': Directory not empty   <==由于 testing 里面有 .bashrc ,所以砍不掉!
[root @test /root]# rm -rf testing      <==持续删除该目录下的所有文件与目录

  mv
语法:

[root @test /root ]# mv [-u] [来源档] [目的檔]
参数说明:
-u   :同样的,为 update 的简写,当来源档比目的档还新的时后才会动作!
范例:
[root @test /root]# cp .bashrc bashrc
[root @test /root]# mv bashrc bashrc.old
[root @test /root]# mv bashrc bashrc2 /tmp<==将 bashrc 与 bashrc2 移动到 /tmp 这个目录下!请注意,最后一个才是最终的目标,其它的都是 SOURCE

  basename
语法:

[root @test /root ]# basename [目录]
参数说明:
范例:
[root @test /root]# basename /usr/local/etc
etc
这个指令会将后面的[目录]仅撷取出最后面的那个目录或文件,
以上面的例子来看, /usr/local/etc 不论 etc 是目录或文件,
他都会被撷取出来,因为他是最后一个出现的咚咚!

  dirname
语法:

[root @test /root ]# dirname [目录]
参数说明:
范例:
[root @test /root]# dirname /usr/local/etc
/usr/local
恰恰与 basename 相反,他仅是秀出来前面的『目录』部分喔!

  cat
语法:

[root @test /root ]# cat [-nAE]
参数说明:
-n:   显示时,连行号印出屏幕上。
-A:   将 DOS 下的 <tab> 与断行字符都列出来!
-E:   将 DOS 编辑的文件中,仅列出 断行字符出来!
范例:
[root @test /root]# cat ~/.bashrc         <==显示 .bashrc 这个文件
# .bashrc

# User specific aliases and functions
PATH="/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH"
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ll='ls -l --color=never'

[root @test /root]# cat ~/.bashrc -n      <==显示 .bashrc 并且加上行号!
     1  # .bashrc
     2
     3  # User specific aliases and functions
     4  PATH="/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH"
     6  alias rm='rm -i'
     7  alias cp='cp -i'
     8  alias mv='mv -i'
     9  alias ll='ls -l --color=never'

[root @test /root]# cat -A regexp.txt
This is a cat, however, I need a dog.^M$
I want to "Happy" and <Happy> and /Happy/ here.^M$
OK! ^Ieverythins is OK^M$
Now, I will eat my food^M$
are you ^Ifinished your work^M$
what do you 123 goto where^M$
显示出 DOS 文件的几个特殊符号,以上面文件为例,
可发现 ^M 为断行符号,而每行的 $ 为行尾符号,
至于 ^I 则是 <tab> 按键啦! 

  more
语法:

[root @test /root ]# more [檔名]
参数说明:
范例:
[root @test /root]# more ~/.bashrc  <==一页一页的显示文件内容
[root @test /]# ls -al | more  <==一页一页的将 ls 的内容显示出来

  less
语法:

[root @test /root ]# less [檔名] 
参数说明: 
范例: 
[root @test /root]# less ~/.bashrc 

  head
语法:

[root @test /root ]# head [-n number] [檔名]
参数说明:
-n :显示 number 行
范例:
[root @test /root]# head ~/.bashrc  <==预设情况下,显示头十行
[root @test /root]# head -n 20 ~/.bashrc<==显示头二十行!

  tail
语法:

[root @test /root ]# tail [-n number] [檔名]
参数说明:
-n :显示 number 行
范例:
[root @test /root]# tail ~/.bashrc
[root @test /root]# tail -n 5 ~/.bashrc <==只显示最后面五行!

语法:

[root @test /root ]# ln [-s] [来源档] [目的檔]
参数说明:
-s   :提供连结档的连结!如果直接以 ln 不加任何参数的话,那么就属于 hard link 啰!
范例:
[root @test /root]# mkdir test
[root @test /root]# cd test
[root @test /test]# cp /usr/bin/passwd .

0. 原本的信息:
[root @test /test]# ll 
-rw-r--r-- 1 root     root        13476 Jun 26 11:31 passwd
[root @test /test]# du -k <==查看该目录下的占用硬盘空间
20

1. Hard Link 信息:
[root @test /test]# ln passwd passwd-hard
[root @test /test]# ll
total 32
-rw-r--r-- 2 root     root        13476 Jun 26 11:31 passwd
-rw-r--r-- 2 root     root        13476 Jun 26 11:31 passwd-hard
注意看,上面那个数字变成 2 啰!这就是占用掉 inodes 啰!
[root @test /test]# du -k
20  <==注意看,容量并没有变大!因为是 link 文件呀!

2. Symbolic Link 信息:
[root @test /test]# ln -s passwd passwd-soft; ll
-rw-r--r--    2 root     root        13476 Jun 26 11:31 passwd
-rw-r--r--    2 root     root        13476 Jun 26 11:31 passwd-hard
lrwxrwxrwx    1 root     root            6 Jun 26 11:37 passwd-sofe -> passwd
注意啰!该 Symbolic Link 的文件是有容量的呦!
注意啰, passwd-soft 会指到另外一个文件去,而且,最前面属性显示 l ,
此外,他是一个独立的文件!先杀掉 passwd 后,我们分别 more 一下内容:

3. 用 more 来试试看是怎样?! 
[root @test test]# rm passwd
rm: remove regular file `passwd'? y
[root @test test]# more passwd-hard
………(正常显示)
[root @test test]# more passwd-soft
passwd-soft: No such file or directory

  • chown


语法:

[root @test /root ]# chown [-R] user:group [目录名称]
参数说明:
-R    :循环的将该目录下的所有文件都改成 user 与 group 的名称!
范例:
[root @test /root]# mkdir /home/test/testing  <==在 /home/test 这个家目录中建立一个名为 testint 的子目录
[root @test /root]# cp * /home/test/testing
[root @test /root]# chown test /home/test/testing
[root @test /root]# chown -R test:test /home/test/testing<==将该目录下的所有目录或文件均变为 test 拥有

  • chmod


语法:

[root @test /root ]# chmod [-R] [parameter] [目录名称]
参数说明:
-R   :循环的一直将该目录的文件均改变之!
范例:
[root @test /root]# chmod 777 .bashrc 

  • umask


[root@vbird test]# umask
0002
[root@vbird test]# touch test1
[root@vbird test]# mkdir test2
[root@vbird test]# ls -l
-rw-rw-r--    1 root     root            0 Oct 22 00:00 test1
drwxrwxr-x    2 root     root         4096 Oct 22 00:00 test2/
发现了什么?呵呵! Test1 的属性为 666-002 = 664 !正确吗?是的!正确!
而 test2 这个目录呢?就是 777-002 = 775 !也正确!

[root@vbird test]# umask 003
[root@vbird test]# touch test3
[root@vbird test]# mkdir test4
[root@vbird test]# ll
-rw-rw-r--    1 root     root            0 Oct 22 00:03 test3
drwxrwxr--    2 root     root         4096 Oct 22 00:03 test4/
嘿!属性又跟刚刚的不一样啰!仔细推敲一下为什么呦!test3 666-003 =663,这是怎么一回事?! 663 应该是 -rw-rw--wx 才对啊!怎么会是上面的属性!呵呵!这里就要特别的给他强调了!『尽量不要以数字相加减啦!』容易造成类似上面的问题!你应该要这样想(-rw-rw-rw-) - (--------wx)=-rw-rw-r--这样就对啦!了解了吗?不要用十进制的数字喔!够能力的话,用二进制来算,不晓得的话,用 rwx 来算喔! ^_^

  • chattr


语法:

[root @test /root ]# chattr [+-=][ASacdistu] [文件或目录名称]
参数说明:
+-= :分别为 [+ 增加] [- 减少] [= 设定] 属性的意思
A  :当设定了 A 这个属性时,这个文件(或目录)的存取时间 atime (access) 将不可被修改,
    可避免例如手提式计算机容易有磁盘 I/O 错误的情况发生!
S  :这个功能有点类似 sync 的功能!就是会将数据同步写入磁盘当中!可以有效的避免数据流失!
a  :当设定 a 之后,这个文件将只能增加数据,而不能删除,只有 root 才能设定这个属性。
c  :这个属性设定之后,将会自动的将此文件『压缩』,在读取的时候将会自动解压缩出来!
    但是在储存的时候,将会先进行压缩之后再储存(看来对于大文件似乎蛮有用的!)
d  :当 dump (备份)程序被执行的时候,设定 d 属性将可使该文件(或目录)具有 dump 功效!
i  :这个 i 可就很厉害了!他可以让一个文件『不能被删除、改名、设定连结也无法写入或新增数据!』
    对于系统安全性有相当大的帮助!
j  :当使用 ext3 这个文件系统格式时,设定 j 属性将会使文件在写入时先记录在 journal 中!
    但是当 filesystem 设定参数为 data=journalled 时,由于已经设定了日志了,所以这个属性无效!
s  :当文件设定了 s 参数时,他将会被完全的移除出这个硬盘空间。
u  :与 s 相反的,当使用 u 来设定文件时,则数据内容其实还存在磁盘中,可以使用来 undeletion.
范例:
[root @test /root]# chattr +i /etc/shadow<==呵呵!如此则无法更动这个文件啰!
[root @test /root]# chattr -i /etc/shadow <==解除该属性!

  • lsattr


语法:

[root @test /root ]# lsattr [-aR]
参数说明:
-a :将隐藏文件的属性也秀出来;
-R :连同子目录的数据也一并列出来!
范例:
[root @test /root]# chattr +i .bash_logout
[root @test /root]# lsattr -a 
-------------- ./.
-------------- ./..
---i---------- ./.bash_logout
-------------- ./.bash_profile
-------------- ./.bashrc
-------------- ./.emacs
-------------- ./.screenrc

  which
语法:

[root @test /root ]# which  [文件名称]
参数说明:
范例:
[root @test /root]# which passwd
/usr/bin/passwd

  whereis
语法:

[root @test /root ]# whereis [-bmsu] [目录名称]
参数说明:
-b    :只找 binary 的文件
-m    :只找在说明文件 manual 路径下的文件
-s    :只找 source 来源文件
-u    :没有说明档的文件!
范例:
[root @test /root]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.bz2
将 passwd 相关字眼的文件或目录都列出来!

[root @test /root]# whereis -b passwd
passwd: /usr/bin/passwd /etc/passwd
仅列出binary 文件!

[root @test /root]# whereis -m passwd
passwd: /usr/share/man/man1/passwd.1.bz2
仅搜寻 man page 所在的目录!

  locate
语法:

[root @test /root ]# locate [目录名称]
参数说明:
范例:
[root @test /root]# locate root
……一大堆跟 root 有关字眼的文件都出来了 @_@

[root @test /root]# updatedb        <==立刻更新数据库

  find
语法:

[root @test /root ]# find [路径] [参数]
参数说明:
1. 时间:
   -atime n    :在 n*24 小时内被 access 即存取过的文件列出来!
   -ctime n    :在 n*24 小时内被 changed 即改变、新增的文件或目录印出
   -mtime n    :在 n*24 小时内被 modified 即修改过的文件印出
   -newer file :比 file 还要新的文件就列出来!
2. 使用名称:
   -gid n      :寻找 群组 ID 为 n 的文件
   -group name :寻找群组名称为 name 的文件
   -uid n      :寻找拥有者 ID 为 n 的文件
   -user name  :寻找使用者名称为 name 的文件
   -name file  :寻找档名为 file 的文件名称(可以使用万用字符)
   -type type  :寻找文件属性为 type 的文件,type 包含了 b, c, d, p, l, s,
                这些与前一章的属性相同!例如 l 为 Link 而 d 为路径之意!
范例:
[root @test /root]# find / -name testing            <==寻找档名为 testing 
[root @test /root]# find / -name 'test*'       <==寻找档名包含 test 的!
[root @test /root]# find . -ctime 1                 <==寻找目前目录下一天内新增的目录或文件
[root @test /root]# find /home/test -newer .bashrc  <==寻找 /home/test 目录下比 .bashrc 还要新的文件
[root @test /root]# find /home -user test       <==寻找 /home 底下拥有者为 test 的文件
[root @test /root]# find /dev -type b               <==寻找 /dev 这个目录下,文件属性为 b 的文件



相关阅读 更多 +
排行榜 更多 +
子午线157第2章

子午线157第2章

冒险解谜 下载
冲破牢笼手机版

冲破牢笼手机版

飞行射击 下载
冲突2西线安卓版

冲突2西线安卓版

飞行射击 下载