cat

shell中 >/dev/null 2>&1是什么意思

浪子不回头ぞ 提交于 2019-11-30 03:37:11
原文地址: http://juke.outofmemory.cn/entry/295292 我们经常能在 shell 脚本中发现 > /dev/ null 2 >& 1 这样的语句。以前的我并没有去深入地理解这段命令的作用,照搬照用,直到上周我将这段命令不小心写成了 2 >& 1 > /dev/ null ,出了一点小问题之后,我才开始去了解这段命令背后的“玄机”。 shell重定向介绍 就像我们平时写的程序一样,一段程序会处理外部的输入,然后将运算结果输出到指定的位置。在交互式的程序中,输入来自用户的键盘和鼠标,结果输出到用户的屏幕,甚至播放设备中。而对于某些后台运行的程序,输入可能来自于外部的一些文件,运算的结果通常又写到其他的文件中。而且程序在运行的过程中,会有一些关键性的信息,比如异常堆栈,外部接口调用情况等,这些都会统统写到日志文件里。 shell脚本也一样,但是我们一般在使用shell命令的时候,更多地还是通过键盘输入,然后在屏幕上查看命令的执行结果。如果某些情况下,我们需要将shell命令的执行结果存储到文件中,那么我们就需要使用输入输出的重定向功能。 文件描述符 当执行shell命令时,会默认打开3个文件,每个文件有对应的文件描述符来方便我们使用: 类型 文件描述符 默认情况 对应文件句柄位置 标准输入(standard input) 0 从键盘获得输入 /proc

Remove First Word in text stream

雨燕双飞 提交于 2019-11-30 02:58:31
How would I remove the first word from each line of text in a stream? i.e. $cat myfile some text 1 some text 2 some text 3 what I want is $cat myfile | magiccommand text 1 text 2 text 3 How would I go about this using bash? I could use awk '{print $2 $3 $4 $5 ....}' but that's messy and would result in extra spaces for all null arguments. I was thinking that sed might be able to do this, but I could not find any examples of this. Any help is appreciated! Thanks! based on your example text, cut -d' ' -f2- yourFile should do the job. That should work: $ cat test.txt some text 1 some text 2 some

javascript 原型链污染

天大地大妈咪最大 提交于 2019-11-30 01:44:04
原理 ①javascript中构造函数就相当于类,并且可以将其实例化 ②javascript的每一个函数都有一个prototype属性,用来指向该构造函数的原型 同样的javascript的每一个实例对象也有一个__proto__方法指向该实例对象的原型,并且例如: function Cat(){ This.color='orange'; } cat =new Cat(); console.log(Cat.prototype===cat.__proto__) 结果 True 可见实例的原型和构造函数的原型相等 并且每一个函数也有一个constructor属性指向其构造函数,也就是 Cat.prototype.constructor===Cat ③在javascript中Object是位于原型链的顶端,Object.prototype===null ④javascript的继承是基于原型链的,在原型链上的任何位置设置属性都能被其访问到,原型的作用也在此, 他可以包含所有实例共享的属性和方法,例如: function Cat(){ this.color='orange'; } Cat.prototype.getcolor=function(){ console.log(this.color) } cat =new Cat(); cat.getcolor(); //orange

bash cat multiple files content in to single string without newlines

大憨熊 提交于 2019-11-30 01:25:23
问题 i got some files with name start as eg_. and only each contains one single line eg_01.txt: @china:129.00 eg_02.txt @uk:219.98 eg_03.txt @USA:341.90 ...... i am expecting to cat them in to a single line to send by URL like: @china:129.00@uk:219.98@USA:341.90 i use echo cat eg_* it give me the output look like a string, but it actually contains new line: "@china:129.00 @uk:219.98 @USA:341.90" is there any other way i can construct that string which expected and get rid of new line and even the

linux常用查看硬件配置命令

荒凉一梦 提交于 2019-11-29 23:15:24
一、查看cpu总个数 1 第一种方法:top命令法 首先执行top命令,如下图所示。 Linux 如何查看主机的cpu总个数和总内存 2 在top命令的显示界面,按数字键1,即可查看到当前系统中的总cpu数,如下图为4核的cpu。 Linux 如何查看主机的cpu总个数和总内存 3 第二种方法,通过proc文件系统,直接获取cpu总数量,具体执行如下命令: cat /proc/cpuinfo | grep processor Linux 如何查看主机的cpu总个数和总内存 END 二、查看总内存的方法 1 第一种方法:top命令法 top是一个功能很强大的命令,用它也可以总内存,如下图所示。 Linux 如何查看主机的cpu总个数和总内存 2 第二种方法:free命令法 free命令主要用于显示内存数量,如下图所示 Linux 如何查看主机的cpu总个数和总内存 3 一般使用free命令的-h参数,更人性化的显示 Linux 如何查看主机的cpu总个数和总内存 4 第三种方法:通过proc虚拟文件系统,来直接获取总内存数。 head /proc/meminfo Linux 如何查看主机的cpu总个数和总内存 查看系统版本号(centos/readhat): cat /etc/redhat-release 查看内核版本信息 [bes8@JQ-BZ-284 ~]$ uname -a

JS继承的实现方式

混江龙づ霸主 提交于 2019-11-29 19:59:16
前言 JS作为面向对象的弱类型语言,继承也是其非常强大的特性之一。那么如何在JS中实现继承呢?让我们拭目以待。 既然要实现继承,那么首先我们得有一个父类,代码如下: // 定义一个动物类 function Animal (name) { // 属性 this.name = name || 'Animal'; // 实例方法 this.sleep = function(){ console.log(this.name + '正在睡觉!'); } } // 原型方法 Animal.prototype.eat = function(food) { console.log(this.name + '正在吃:' + food); }; 1、原型链继承 核心: 将父类的实例作为子类的原型 function Cat(){ } Cat.prototype = new Animal(); Cat.prototype.name = 'cat'; // Test Code var cat = new Cat(); console.log(cat.name); console.log(cat.eat('fish')); console.log(cat.sleep()); console.log(cat instanceof Animal); //true console.log(cat

JS继承的几种方式

早过忘川 提交于 2019-11-29 19:58:42
JS作为面向对象的弱类型语言,继承也是其非常强大的特性之一。 既然要实现继承,那么我们先定义一个父类: // 定义一个动物类 function Animal (name) { // 属性 this.name = name || 'Animal'; // 实例方法 this.sleep = function(){ alert(this.name + '正在睡觉!'); } } // 原型方法 Animal.prototype.eat = function(food) { alert(this.name + '正在吃:' + food); }; 1、原型链继承 核心: 将父类的实例作为子类的原型 function Cat(){ } Cat.prototype = new Animal(); Cat.prototype.name = 'cat'; // Test Code var cat = new Cat(); alert(cat.name); alert(cat.eat('fish')); alert(cat.sleep()); alert(cat instanceof Animal); //true alert(cat instanceof Cat); //true 特点: 非常纯粹的继承关系,实例是子类的实例,也是父类的实例 父类新增原型方法/原型属性,子类都能访问到 缺点:

python学习——pandas扩展:傅里叶变换

微笑、不失礼 提交于 2019-11-29 19:09:20
导包,np 从numpy.fft导入fft、ifft 导入图片库PIL中的Image In [1]: import numpy as np #fft傅里叶转换,ifft傅里叶反转 from numpy.fft import fft,ifft #真实世界,时域 ndarray #规律,频域 高低, from PIL import Image 第一步读取数据 In [2]: cat = Image.open('cat.png') In [7]: cat Out[7]: 转换成int类型数据,int8 == 128 In [10]: cat_data = np.fromstring(cat.tobytes(),dtype=np.int8) # 之所以有负数,是因为int8<128,颜色值0~255 cat_data C:\Users\BLX\AppData\Roaming\Python\Python37\site-packages\ipykernel_launcher.py:1: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead """Entry point for

Concatenate multiple files but include filename as section headers

泪湿孤枕 提交于 2019-11-29 18:32:54
I would like to concatenate a number of text files into one large file in terminal. I know I can do this using the cat command. However, I would like the filename of each file to precede the "data dump" for that file. Anyone know how to do this? what I currently have: file1.txt = bluemoongoodbeer file2.txt = awesomepossum file3.txt = hownowbrowncow cat file1.txt file2.txt file3.txt desired output: file1 bluemoongoodbeer file2 awesomepossum file3 hownowbrowncow DS. Was looking for the same thing, and found this to suggest: tail -n +1 file1.txt file2.txt file3.txt Output: ==> file1.txt <==

PHP之Trait详解

梦想与她 提交于 2019-11-29 17:21:44
php从以前到现在一直都是单继承的语言,无法同时从两个基类中继承属性和方法,为了解决这个问题,php出了Trait这个特性 用法:通过在类中使用use 关键字,声明要组合的Trait名称,具体的Trait的声明使用Trait关键词,Trait不能实例化 如下代码实例: <?php trait Dog{ public $name="dog"; public function bark(){ echo "This is dog"; } } class Animal{ public function eat(){ echo "This is animal eat"; } } class Cat extends Animal{ use Dog; public function drive(){ echo "This is cat drive"; } } $cat = new Cat(); $cat->drive(); echo "<br/>"; $cat->eat(); echo "<br/>"; $cat->bark(); ?> 将会如下输出 再测试Trait、基类和本类对同名属性或方法的处理,如下代码 <?php trait Dog{ public $name="dog"; public function drive(){ echo "This is dog drive"; }