shell实战命令全集

shell 实战命令全集

cat:将文件或标准输入转化为标准输出

	1、一次显示整个文件。     cat   filename
	2、创建一个文件,只能创建新文件不能编辑新文件。   cat > filename
	3、将几个文件合并为一个文件。     cat  file1  file2  > file
	退出cat    ctrl+c   或 ctrl+d        或者控制台输入 control -D        control -C

cd:切换目录

	切换目录    cd dirname
	cd   进入主目录
	cd ~  进入用户主目录
	cd -  返回进入此目录之前所在的目录
	cd .. 返回上级
	cd ../.. 返回上两级目录
	cd !$  把上个命令的参数作为cd参数使用

ls:显示文件和目录的信息

	显示文件和目录的信息
	ls 以默认方式显示当前目录文件列表
	ls -a 显示所有文件包括隐藏文件
	ls -l    或 ll    显示文件属性,包括大小,日期,符号连接,是否可读写及是否可执行
	ls -lc    列出文件的最后更改时间
	ls -lu    列出文件的最后访问时间
	ls -lh 显示文件的大小,以容易理解的格式印出文件大小 (例如 1K 234M2G)
	ls -lt 显示文件,按照修改时间排序

cp:拷贝文件

	拷贝文件
	cp source target 将文件source复制为target
	cp /root/source . 将/root下的文件source复制到当前目录
	cp –av soure_dir target_dir 将整个目录复制,两目录完全一样

rm:删除文件或目录

	删除文件或目录
	rm file 删除某一个文件
	rm -f file 删除时候不进行提示。可以于r参数配合使用
	rm -rf dir 删除当前目录下叫dir的整个目录
	rm -rf !(file1|file2|file3) 删除除file1 file2 file3 的所有文件

mv:将文件移走或改名

	将文件移走或改名
	mv source target 将文件source更名为target
	mv text.txt text.log    改名
	mv text.txt  rodger/file   移走
	命令参数:
			-b :若需覆盖文件,则覆盖前先行备份。 
			-f :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖;
			-i :若目标文件 (destination) 已经存在时,就会询问是否覆盖!
			-u :若目标文件已经存在,且 source 比较新,才会更新(update)
		    -t : --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY,即指定mv的目标目录,该选项适用于移动多个源文件到一个目录的情况,此时目标目录在前,源文件在后。

sz:下载文件 将选定的文件发送到本地机器

	下载文件   将选定的文件发送到本地机器
	sz filename 

rz:上传文件

	上传文件	  运行该命令会弹出一个文件选择窗口,从本地选择文件上传到linux服务器
	rz
	-a, –ascii  
	-b, –binary 用二进制的方式上传下载,不解释字符为 ascii
	-e, –escape 强制escape 所有控制字符,比如 Ctrl+x,DEL 等
	-ary –o-sync
	-a 表示使用ascii码格式传输文件,如果是Dos格式的文件,会转换为unix格式
	-r 使用 Crash recovery mode. 即文件传输中断会重传
	-y 表示文件已存在的时候会覆盖
	–o-sync 采用同步写模式,以处理从缓存写到磁盘时中断丢失的情况

chomd:改变用户的权限

	改变用户的权限
	chmod a+x file  将file文件设置为可运行
	chmod 666 file 将文件file设置为可读写
	chmod 750 file 将文件file设置为,所有者为完全权限,同组可以读和执行,其他无权限

touch:修改文件时间戳或者新建一个不存在的文件

	修改文件时间戳或者新建一个不存在的文件
		-a 改变档案的读取时间记录。
	   -m 改变档案的修改时间记录。
	   -c 假如目的档案不存在,不会建立新的档案。与 --no-create 的效果一样。
	    -h ,不干扰引用 影响每个符号链接,而不是所有参考文件(只适用于系统的改变一个符号,时间戳)
	   -f 不会执行实际操作,是为了与其他 unix 系统的相容性而保留。
	   -r 使用参考档的时间记录,与 --file 的效果一样。
	   -d 设定时间与日期,可以使用各种不同的格式。
	   -t 设定档案的时间记录,格式与 date 指令相同。[[CC]YY]MMDDhhmm[.SS],CC为年数中的前两位,即”世纪数”;YY为年数的后两位,即某世纪中的年数.如果不给出CC的值,则linux中touch命令参数将把年数CCYY限定在1969--2068之内.MM为月数,DD为天将把年数CCYY限定在1969--2068之内.MM为月数,DD为天数,hh 为小时数(几点),mm为分钟数,SS为秒数.此处秒的设定范围是0--61,这样可以处理闰秒.这些数字组成的时间是环境变量TZ指定的时区中的一个时间.由于系统的限制,早于1970年1月1日的时间是错误的.
	touch file    创建file文件
	touch -t 201812262315.34 b.txt 指定时间创建文件

vim:文本编辑器

	文本编辑器,有三种模式,相互切换如下
				命令模式——>编辑模式:“i a o I A O”
				编辑模式——>命令模式:“ESC”
				命令模式——>末行模式:“: /  ?”(:与/用于搜索
	命令模式:
			复制:yy——复制一行,nyy——复制n行
			剪切/删除:dd——删除/剪切一行,ndd——删除/剪切n行
			删除一个字符:x
			替换:r——替换一个字符(如r a表示把r替换为a),R——持续替换
			粘贴:p
			撤销一个操作:u
			移动光标到文件末尾:G
			移动光标到文件首行:gg
			移动光标到文件第n行:nG或:n
			不能同时在两个终端用vim命令打开同一个文件,需将打开的一个vi命令文件关闭后才能打开另一个,否则另一个文件保存不了。

	编辑模式:
			i :在当前光标前面插入数据
			a :在当前光标之后插入数据
			I :在当前光标行头开始插入数据
			A :在当前光标行末开始插入数据
			o :在当前光标所在下一行增加一个新行
			O :在当前光标所在上一行增加一个新行(空行)

	末尾模式:
			保存文件不退出vi :          ":w"
			保存文件并退出 :        “:wq”
			退出 :                    ":q"
			不保存退出:                “:q!"
			显示行号:                   “:set nu”
			 取消行号:                  “:set nonu”
			跳转到第n行:              “:n”

less :分屏查看文件内容

	分屏查看文件内容
	语法  less [参数] 文件
		参数:
				-b <缓冲区大小> 设置缓冲区的大小
				-e  当文件显示结束后,自动离开
				-f  强迫打开特殊文件,例如外围设备代号、目录和二进制文件
				-g  只标志最后搜索的关键词
				-i  忽略搜索时的大小写
				-m  显示类似more命令的百分比
				-N  显示每行的行号
				-o <文件名> 将less 输出的内容在指定文件中保存起来
				-Q  不使用警告音
				-s  显示连续空行为一行
				-S  行过长时间将超出部分舍弃
				-x <数字> 将“tab”键显示为规定的数字空格
	
	退出:  q 或 Q  或 ZZ
	
	常用操作 :
		1、/字符串   :向下搜索"字符串"
		2、?字符串   :向上搜索"字符串"
		3、n        	:重复前一个搜索
		4、N         :向上重复前一个搜索
		5、b         :向后翻一页
		6、空格       :滚动一页
		7、回车       :滚动一行
		8、pageDown	:向下翻一页
		9、pageUp	:向上翻一页
		10、G		:移到最后一行
		11、g         :移到第一行

stat :显示文件的详细信息

	显示文件的详细信息,包括inode 、 atime 、mtime 、ctime
	stat  [参数]  文件或目录
	参数 :  
		-f     显示文件系统的信息
		-t     以简洁的方式输出
		Access	访问时间
		Modify	修改时间
		Change  状态修改时间

more:查看文件内容

	查看文件内容,一页一页的显示
	参数 :
		-num 一次显示的行数 
		-d 提示使用者,在画面下方显示 [Press space to continue, 'q' to quit.] ,如果使用者按错键,则会显示 [Press 'h' for instructions.] 而不是 '哔' 声 
		-l 取消遇见特殊字元 ^L(送纸字元)时会暂停的功能 
		-f 计算行数时,以实际上的行数,而非自动换行过后的行数(有些单行字数太长的会被扩展为两行或两行以上) 
		-p 不以卷动的方式显示每一页,而是先清除萤幕后再显示内容 
		-c 跟 -p 相似,不同的是先显示内容再清除其他旧资料 
		-s 当遇到有连续两行以上的空白行,就代换为一行的空白行 
		-u 不显示下引号 (根据环境变数 TERM 指定的 terminal 而有所不同) 
		+/ 在每个档案显示前搜寻该字串(pattern),然后从该字串之后开始显示 
		+num 从第 num 行开始显示 
	操作:
		空格下一页
		b  上一页
		G  最后一行
		h  显示帮助

pwd:打印当前工作目录名

	打印当前工作目录名

read:用于从标准输入读取数值

	用于从标准输入读取数值
	语法 :read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
	-a 后跟一个变量,该变量会被认为是个数组,然后给其赋值,默认是以空格为分割符。
	-d 后面跟一个标志符,其实只有其后的第一个字符有用,作为结束的标志。
	-p 后面跟提示信息,即在输入前打印提示信息。
	-e 在输入的时候可以使用命令补全功能。
	-n 后跟一个数字,定义输入文本的长度,很实用。
	-r 屏蔽\,如果没有该选项,则\作为一个转义字符,有的话 \就是个正常的字符了。
	-s 安静模式,在输入字符时不再屏幕上显示,例如login时输入密码。
	-t 后面跟秒数,定义输入字符的等待时间。
	-u 后面跟fd,从文件描述符中读入,该文件描述符可以是exec新开启的。

sed :一种流编辑器,它是文本处理中非常有用的工具,可以完美配合正则表达式使用。

	sed是一种流编辑器,它是文本处理中非常有用的工具,可以完美配合正则表达式使用。
	格式: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

		  -n, --quiet, --silent
		                 suppress automatic printing of pattern space   (不显示自动输出内容)
		  -e script, --expression=script
		                 add the script to the commands to be executed  (将脚本添加到要执行的命令中)
		  -f script-file, --file=script-file
		                 add the contents of script-file to the commands to be executed (添加脚本文件内容到要执行的命令中)
		  --follow-symlinks
		                 follow symlinks when processing in place       (处理到位时遵循符号链接)
		  -i[SUFFIX], --in-place[=SUFFIX]
		                 edit files in place (makes backup if SUFFIX supplied)     (就地编辑文件,如果提供后缀则进行备份)
		  -l N, --line-length=N
		                 specify the desired line-wrap length for the `l' command   (为 'l' 命令指定所需的换行长度)
		  --posix
		                 disable all GNU extensions.   (禁用所有GNU拓展)
		  -r, --regexp-extended
		                 use extended regular expressions in the script.  (在脚本中使用拓展正则表达式)
		  -s, --separate
		                 consider files as separate rather than as a single continuous long stream.     (将文件视为单独的而不是一连串的长流)
		  -u, --unbuffered
		                 load minimal amounts of data from the input files and flush the output buffers more often    (从输入文件加载最小数量的数据并刷新输出缓冲区)
		  -z, --null-data
		                 separate lines by NUL characters      (按数字字符分隔行)
		  --help     display this help and exit
		  --version  output version information and exit
	If no -e, --expression, -f, or --file option is given, then the first                如果没有指定 -e 或者 -f 选项,则第一个非选项参数被视作要解释的seq脚本,其他剩余参数作为输入文件的名字
	non-option argument is taken as the sed script to interpret.  all                    如果没有指定输入文件,会读取标准输入
	remaining arguments are names of input files; if no input files are
	specified, then the standard input is read.
	eg:
			1、组合多个表达式
				sed '表达式' | sed '表达式'
				等价于
				sed '表达式; 表达式'
			2、引用
				sed表达式可以使用单引号来引用,但是如果表达式内部包含变量字符串,就需要使用双引号。
			3、替换字符串
				sed -i 's/需要替换的字符串/替代字符串/' filename         会替换所有匹配的字符串
			4、替换行
				sed -i '/匹配行/c 新内容' filename
				eg: sed -i '/aba/c  11111'  a.txt     将a.txt中包含aba字符的行替换为 11111

file:确定文件类型

	 确定文件类型
	 Usage: file [OPTION...] [FILE...]
			Determine type of FILEs.
			      --help                 display this help and exit
			  
			  -v, --version              output version information and exit 							(输出版本信息并退出)

			  -m, --magic-file LIST      use LIST as a colon-separated list of magic number files        (使用LIST给magic number 文件以冒号分隔)

			  -z, --uncompress           try to look inside compressed files 							 (尝试查看压缩文件)

			  -b, --brief                do not prepend filenames to output lines
			  
			  -c, --checking-printout    print the parsed form of the magic file, use in                (输出magic文件的解析格式,用于和-m一起在安装新的magic文件前先调试它)
			                               conjunction with -m to debug a new magic file
			                               before installing it
			  
			  -e, --exclude TEST         exclude TEST from the list of test to be                       (从要对文件执行的测试列表中排除测试
			                               performed for file. Valid tests are:							  有效的测试是:apptype,ascii,cdf,compress,elf,encoding,soft,tar,text,tokens)
			                               apptype, ascii, cdf, compress, elf, encoding,
			                               soft, tar, text, tokens
			  -f, --files-from FILE      read the filenames to be examined from FILE

			  -F, --separator STRING     use string as separator instead of `:'
			  
			  -i, --mime                 output MIME type strings (--mime-type and
			                               --mime-encoding)
			      --apple                output the Apple CREATOR/TYPE
			  
			      --mime-type            output the MIME type
			  
			      --mime-encoding        output the MIME encoding
			  
			  -k, --keep-going           don't stop at the first match                (不在第一次匹配就停下来)
			  
			  -l, --list                 list magic strength							(列出magic强度)
			  
			  -L, --dereference          follow symlinks (default if POSIXLY_CORRECT is set)          (遵循符号链接,未设置则默认为POSIXLY_CORRECT)
			  
			  -h, --no-dereference       don't follow symlinks (default if POSIXLY_CORRECT is not set) 	(不遵循符号链接,未设置则默认为POSIXLY_CORRECT)
			  
			  -n, --no-buffer            do not buffer output											(不缓冲输出)
			  
			  -N, --no-pad               do not pad output												(不覆盖输出)
			  
			  -0, --print0               terminate filenames with ASCII NUL           					 (用 ASCII NUL 终止文件名)
			  
			  -p, --preserve-date        preserve access times on files
			  
			  -P, --parameter            set file engine parameter limits
			                               indir        15 recursion limit for indirection
			                               name         30 use limit for name/use magic
			                               elf_notes   256 max ELF notes processed
			                               elf_phnum   128 max ELF prog sections processed
			                               elf_shnum 32768 max ELF sections processed
			  
			  -r, --raw                  don't translate unprintable chars to \ooo             (不将无法打印的字符转化为\ooo)
			  
			  -s, --special-files        treat special (block/char devices) files as ordinary ones  (对特殊(块字符设备)文件视为一般文件)
			  
			  -C, --compile              compile file specified by -m                              (编译由-m指定的文件)
			  
			  -d, --debug                print debugging messages                                  (打印调试信息)

head:查看文件开头内容

	查看文件开头内容
	Usage: head [OPTION]... [FILE]...
	Print the first 10 lines of each FILE to standard output.                                    打印每个文件的前十行到标准输出
	With more than one FILE, precede each with a header giving the file name.					 超过一个文件,在每一个文件前加上文件名的头
	With no FILE, or when FILE is -, read standard input.										 如果没有文件,或者文件是-,读入标准输入

	Mandatory arguments to long options are mandatory for short options too.                     规定的长参数和短参数的是一样的
	  -c, --bytes=[-]K         print the first K bytes of each file;						     打印每个文件开头k字节的内容
	                             with the leading '-', print all but the last					 使用引导符-,打印除了最后k字节的所有内容
	                             K bytes of each file
	  -n, --lines=[-]K         print the first K lines instead of the first 10;                  打印每个文件开头K行的内容
	                             with the leading '-', print all but the last					 使用引导符-,打印除了最后k行的所有内容
	                             K lines of each file
	  -q, --quiet, --silent    never print headers giving file names                             不打印文件名
	  -v, --verbose            always print headers giving file names                            打印文件名
	      --help     display this help and exit           										 显示这个帮助并退出
	      --version  output version information and exit                                         输出版本信息并退出
	K may have a multiplier suffix:
	b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,                                           k可以有多种后缀名
	GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

tail:查看文件末尾内容

	查看文件末尾内容
	Usage: tail [OPTION]... [FILE]...
	Print the last 10 lines of each FILE to standard output.                                    打印每个文件的最后1-行到标准输出
	With more than one FILE, precede each with a header giving the file name.					超过一个文件,在每一个文件前加上文件名的头
	With no FILE, or when FILE is -, read standard input.										如果没有文件,或者文件是-,读入标准输入

	Mandatory arguments to long options are mandatory for short options too.
	  -c, --bytes=K            output the last K bytes; alternatively, use -c +K                输出最后k字节,
	                           to output bytes starting with the Kth of each file               使用-c +K 从每个文件的第K个开始输出字节
	  -f, --follow[={name|descriptor}]
	                           output appended data as the file grows;                          随着文件增长输出附加数据
	                           -f, --follow, and --follow=descriptor are
	                           equivalent
	  -F                       same as --follow=name --retry                                    与 --follow=name --retry 相同                                    
	  -n, --lines=K            output the last K lines, instead of the last 10;                 输出后 K行, 使用-n +K 输出从第K开始的行
	                           or use -n +K to output lines starting with the Kth
	      --max-unchanged-stats=N
	                           with --follow=name, reopen a FILE which has not                  使用 --follow=name 在N次(默认5次)迭代后重新打开一个未更改大小的文件,查看它是否已被
	                           changed size after N (default 5) iterations						取消链接或重命名
	                           to see if it has been unlinked or renamed
	                           (this is the usual case of rotated log files).
	                           With inotify, this option is rarely useful.
	      --pid=PID            with -f, terminate after process ID, PID dies                    使用-f,在进程ID,PID结束后终止
	  -q, --quiet, --silent    never output headers giving file names                           不在输出头上打印文件名
	      --retry              keep trying to open a file even when it is or                    即使文件变得不可访问或变得不可访问也继续尝试打开该文件
	                             becomes inaccessible; useful when following by
	                             name, i.e., with --follow=name
	  -s, --sleep-interval=N   with -f, sleep for approximately N seconds                       使用-f在迭代之间睡眠大约N秒(默认为1.0),使用inotify 和 --pid=P,每隔N秒至少检查进程P一次
	                             (default 1.0) between iterations.
	                             With inotify and --pid=P, check process P at
	                             least once every N seconds.
	  -v, --verbose            always output headers giving file names                          输出带文件名
	      --help     display this help and exit
	      --version  output version information and exit

	If the first character of K (the number of bytes or lines) is a '+',
	print beginning with the Kth item from the start of each file, otherwise,
	print the last K items in the file.  K may have a multiplier suffix:
	b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
	GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

	With --follow (-f), tail defaults to following the file descriptor, which
	means that even if a tail'ed file is renamed, tail will continue to track
	its end.  This default behavior is not desirable when you really want to
	track the actual name of the file, not the file descriptor (e.g., log
	rotation).  Use --follow=name in that case.  That causes tail to track the
	named file in a way that accommodates renaming, removal and creation.

date: 显示系统当前时间和日期

	显示系统当前时间和日期

cal:显示当前月份的日历

	显示当前月份的日历

df:查看磁盘剩余空间的数量

	查看磁盘剩余空间的数量

free:显示空闲内存的数量

	显示空闲内存的数量

exit:结束终端会话

	结束终端会话

zip :

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rodger_snow

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值