Linux常用命令(一)
linux常用命令(一)
1 touch命令1.1 命令参数-a change only the access time -c,--no-create do not create any files -d,--date=STRING parse STRING and use it instead of current time -f (ignored) -h,--no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink) -m change only the modification time -r,--reference=FILE use this file‘s times instead of current time -t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time --time=WORD change the specified time: WORD is access,atime,or use: equivalent to -a WORD is modify or mtime: equivalent to -m --help display this help and exit --version output version information and exit 1.2 命令实例touch file 创建一个名字为file的文件 [[email?protected] shenwei]# touch file [[email?protected] shenwei]# ls file touch file{1..10} 创建file1—file10共10个文件 [[email?protected] shenwei]# touch file{1..10} [[email?protected] shenwei]# ls file file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 2 mv命令2.1 命令参数-b :若需覆盖文件,则覆盖前先行备份。 -f :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖; -i :若目标文件 (destination) 已经存在时,就会询问是否覆盖! -u :若目标文件已经存在,且 source 比较新,才会更新(update) -t : --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY,即指定mv的目标目录,该选项适用于移动多个源文件到一个目录的情况,此时目标目录在前,源文件在后。 2.2 命令实例1.修改文件名称 [[email?protected] shenwei]# ls test.txt [[email?protected] shenwei]# mv test.txt test.log [[email?protected] shenwei]# ls test.log 2.将多个文件移动到指定的目录中。 **note:目标目录要放置在前面** [[email?protected] /]# cd shen [[email?protected] shen]# ls file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 [[email?protected] shen]# mv -t /shenwei file* [[email?protected] shen]# ls [[email?protected] shen]# cd .. [[email?protected] /]# cd shenwei [[email?protected] shenwei]# ls file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 3.将文件file1改名为file2,如果file2已经存在,增加参数 i 可以进行提示,省略也可以 **note:-i 可以省去不写** [[email?protected] shen]# cd /shenwei [[email?protected] shenwei]# ls file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 test.log [[email?protected] shenwei]# cd /shen [[email?protected] shen]# mv -i file1 /shenwei mv: overwrite `/shenwei/file1‘? yes [[email?protected] shen]# ls file2 [[email?protected] shen]# cd /shenwei [[email?protected] shenwei]# ls file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 test.log 4.将文件file1改名为file2,如果file2已经存在,则强制覆盖,增加参数 -f [[email?protected] shenwei]# cd /shen [[email?protected] shen]# ls file2 [[email?protected] shen]# cd /shenwei [[email?protected] shenwei]# ls file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 test.log [[email?protected] shenwei]# cd /shen [[email?protected] shen]# mv -f file2 /shenwei [[email?protected] shen]# cd /shenwei [[email?protected] shenwei]# ls file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 test.log [[email?protected] shenwei]# [[email?protected] shenwei]# cd /shen [[email?protected] shen]# ls 3 cp命令该命令的功能是将给出的文件或目录拷贝到另一文件或目录中 3.1 语法语法: cp [选项] [源文件或目录 目标文件或目录] 3.2 命令参数-a 该选项通常在拷贝目录时使用。他保留连接、文件属性,并且递归地拷贝目录,其作用等于后面的dpr选项的组合 -d 拷贝时保留连接 -f 删除已经存在的目标文件并且不进行提示 -i 和f相反,在覆盖文件之前将给出提示要求用户确认。回答y时目标文件将被覆盖,是交互式拷贝。 此参数可以时cp命令安全,建议用户在拷贝的时候增加。 -p 除了复制源文件中的内容之外,还将其修改时间和访问权限也复制到新文件中。 -r 递归复制目中的文件 -l 不做拷贝,只做链接文件 -v —— 带有 -v (verbose)选项,cp命令将告诉用户正在做什么。很多Linux命令都带有具有相同意义的 -v 选项。 3.3 命令实例1.将文档 file 复制成 file1 . –i为提示确认 note:这个与mv的区别,mv是重命名,而cp是进行复制文件 [[email?protected] shenwei]# cd /shen [[email?protected] shen]# ls file file4 [[email?protected] shen]# cp -i file file1 [[email?protected] shen]# ls file file1 file4 2.将文档 file 复制到目录shemwei下,文件名仍为 file [[email?protected] shenwei]# ls file1 file10 file11 file2 file3 file4 file5 file6 file7 file8 file9 test.log [[email?protected] shenwei]# cd /shen [[email?protected] shen]# ls file file1 file4 [[email?protected] shen]# cp file /shenwei [[email?protected] shen]# cd /shenwei [[email?protected] shenwei]# ls file file1 file10 file11 file2 file3 file4 file5 file6 file7 file8 file9 test.log [[email?protected] shenwei]# 4.递归复制目录 note:如果目标文件不存在则新建文件夹并将文件复制到其中,倘若文件夹存在则在将源文件夹及其包含的内容复制到其中。 [[email?protected] /]# ls bin boot dev etc home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var [[email?protected] /]# mkdir shen [[email?protected] /]# ls bin boot dev etc home lib lib64 lost+found media mnt opt proc root sbin selinux shen srv sys tmp usr var [[email?protected] /]# cd shen [[email?protected] shen]# mkdir shen{1..10} [[email?protected] shen]# ls shen1 shen10 shen2 shen3 shen4 shen5 shen6 shen7 shen8 shen9 [[email?protected] shen]# cd .. [[email?protected] /]# cp -r shen shenwei [[email?protected] /]# ls bin boot dev etc home lib lib64 lost+found media mnt opt proc root sbin selinux shen shenwei srv sys tmp usr var [[email?protected] /]# cd shenwei [[email?protected] shenwei]# ls shen1 shen10 shen2 shen3 shen4 shen5 shen6 shen7 shen8 shen9 [[email?protected] shenwei]# cd .. [[email?protected] /]# cp -r shen shenwei [[email?protected] /]# cd shenwei [[email?protected] shenwei]# ls shen shen1 shen10 shen2 shen3 shen4 shen5 shen6 shen7 shen8 shen9 [[email?protected] shenwei]# cd shen [[email?protected] shen]# ls shen1 shen10 shen2 shen3 shen4 shen5 shen6 shen7 shen8 shen9 [[email?protected] shen]# 4 cat命令cat命令常用来查看文件内容,并且可以跟几个文件一起连接起来显示,可以跟重定向命令(后续会讲到)一起使用为文件输入或追加内容。 cat主要有三大功能: 1. 一次显示整个文件:cat filename 2. 从键盘创建一个文件:cat > filename 只能创建新文件,不能编辑已有文件. 3. 将几个文件合并为一个文件:cat file1 file2 > file 4.1 语法语法cat [选项] [文件]... 4.2 命令参数-A,--show-all 等价于 -vET -b,--number-nonblank 对非空输出行编号 -e 等价于 -vE -E,--show-ends 在每行结束处显示 $ -n,--number 对输出的所有行编号,由1开始对所有输出的行数编号 -s,--squeeze-blank 有连续两行以上的空白行,就代换为一行的空白行 -t 与 -vT 等价 -T,--show-tabs 将跳格字符显示为 ^I -u (被忽略) -v,--show-nonprinting 使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外 4.3 命令实例
说明:tac 是将 cat 反写过来,所以他的功能就跟 cat 相反, cat 是由第一行到最后一行连续显示在萤幕上,而 tac 则是由最后一行到第一行反向在萤幕上显示出来! 5 head命令用来显示文件开头的内容,如果不指定参数,则默认显示前10行 5.1 语法语法:head[参数][文件] 5.2 命令参数-q 隐藏文件名 -v 显示文件名 -c<字节> 显示字节数 -n<行数> 显示的行数 5.3 命令实例
6 tail命令tail 命令从指定点开始将文件写到标准输出,如果不指定参数,则默认显示后10行 6.1 语法语法:tail[参数][文件] 6.2 命令参数-f 循环读取 -q 不显示处理信息 -v 显示详细的处理信息 -c<数目> 显示的字节数 -n<行数> 显示行数 -s,--sleep-interval=S 与-f合用,表示在每次反复的间隔休眠S秒 note:使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的文件内容. 6.3 命令实例
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |