学习Linux,Shell

TECH``linux``shell``posts

Shell技巧

  • 识别当前运行的是哪种shell

    1.$ echo $02.-zsh

终端里删字符

  • backspace
  • delete
  • ctrl+h
  • ctrl+w 删除一个单词
  • ctrl+u 删除行

搜索命令

1.$ apropos keyword

识别文件内容

1.$ file 100k.jpg2.100k.jpg: JPEG image data, JFIF standard 1.02

mtr: unable to get raw sockets

TECH``posts``Mac``homebrew``mtr 用homebrew安装mtr 后有段提示:mtr requires root privileges so you will need to run sudo mtr. You should be certain that you trust any software you grant root privileges. 所以要吧mtr改成root属主并且激活suid位

1.  $ sudo chown root:wheel /usr/local/Cellar/mtr/0.86/sbin/mtr2.  $ sudo chmod u+s /usr/local/Cellar/mtr/0.86/sbin/mtr

  1. yum install python-setuptools python-pip
  2. pip install supervisor
  3. echo_supervisord_conf > /etc/supervisord.conf
  4. create init script in : /usr/lib/systemd/system/supervisord.service
    \[Unit\] Description=supervisord - Supervisor process control system for UNIX Documentation=http://supervisord.org After=network.target \[Service\] Type=forking ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf ExecReload=/usr/bin/supervisorctl reload ExecStop=/usr/bin/supervisorctl shutdown User=root</li> </ol> \[Install\] WantedBy=multi-user.target <pre><code>

假设我们有一大批数据(GB或TB量级)需要处理,处理过程可能分为好几个步骤,每个步骤必须由不同的二进制文件(程序)来处理 - 或者可以假设我们正在执行一系列的map-reduce任务!由于输入数据量很大,读取和写入数据的效率决定了运行时间。因此,不会使用随机读写,而是对数据进行流式读取,一旦处理完成,再通过流式写入将数据刷新到磁盘。通过这种方式,我们可以分摊磁盘I / O成本 。不需要磁盘寻道,直接连续的向前写入。 有序字符串表(Sorted String Table)是包含一组任意有序键 - 值对的文件,可以很好的处理重复键,不需要额外的空间来填充(padding)键或值,并且键值可以是任意的东西。顺序的读取整个文件,就可以获得一个有序的索引。如果文件非常大,可以在前面追加或创建独立的key:offset索引来加速访问。这就是SSTable,一个非常简单却非常有用的交换大量有序数据片段的方式。 来源: 图灵社区 : 阅读 : SSTable和日志结构化存储:LevelDB

This document describes the Cassandra Query Language (CQL) version 3. CQL v3 is not backward compatible with CQL v2 and differs from it in numerous ways. Note that this document describes the last version of the languages. However, the changes section provides the diff between the different versions of CQL v3. CQL v3 offers a model very close to SQL in the sense that data is put in tables containing rows of columns. For that reason, when used in this document, these terms (tables, rows and columns) have the same definition than they have in SQL. But please note that as such, they do not refer to the concept of rows and columns found in the internal implementation of Cassandra and in the thrift and CQL v2 API. 来源: CQL

Virtual Environments A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable. For example, you can work on a project which requires Django 1.3 while also maintaining a project which requires Django 1.0. virtualenv virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need. Install virtualenv via pip: $ pip install virtualenv Basic Usage

  1. Create a virtual environment for a project:

$ cd my_project_folder $ virtualenv venv virtualenv venv will create a folder in the current directory which will contain the Python executable files, and a copy of the pip library which you can use to install other packages. The name of the virtual environment (in this case, it was venv) can be anything; omitting the name will place the files in the current directory instead. This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named venv. You can also use a Python interpreter of your choice. $ virtualenv -p /usr/bin/python2.7 venv This will use the Python interpreter in /usr/bin/python2.7

  1. To begin using the virtual environment, it needs to be activated:

$ source venv/bin/activate The name of the current virtual environment will now appear on the left of the prompt (e.g. (venv)Your-Computer:your_project UserName$) to let you know that it’s active. From now on, any package that you install using pip will be placed in the venv folder, isolated from the global Python installation. Install packages as usual, for example: $ pip install requests

  1. If you are done working in the virtual environment for the moment, you can deactivate it:

$ deactivate This puts you back to the system’s default Python interpreter with all its installed libraries. To delete a virtual environment, just delete its folder. (In this case, it would be rm -rf venv.) After a while, though, you might end up with a lot of virtual environments littered across your system, and its possible you’ll forget their names or where they were placed. Other Notes Running virtualenv with the option <b–<no-site-packages will not include the packages that are installed globally. This can be useful for keeping the package list clean in case it needs to be accessed later. [This is the default behavior for virtualenv 1.7 and later.] In order to keep your environment consistent, it’s a good idea to “freeze” the current state of the environment packages. To do this, run $ pip freeze > requirements.txt This will create a requirements.txt file, which contains a simple list of all the packages in the current environment, and their respective versions. You can see the list of installed packages without the requirements format using “pip list”. Later it will be easier for a different developer (or you, if you need to re-create the environment) to install the same packages using the same versions: $ pip install -r requirements.txt This can help ensure consistency across installations, across deployments, and across developers. Lastly, remember to exclude the virtual environment folder from source control by adding it to the ignore list. virtualenvwrapper virtualenvwrapper provides a set of commands which makes working with virtual environments much more pleasant. It also places all your virtual environments in one place. To install (make sure virtualenv is already installed): $ pip install virtualenvwrapper $ export WORKON_HOME=~/Envs $ source /usr/local/bin/virtualenvwrapper.sh (Full virtualenvwrapper install instructions.) For Windows, you can use the virtualenvwrapper-win. To install (make sure virtualenv is already installed): $ pip install virtualenvwrapper-win In Windows, the default path for WORKON_HOME is %USERPROFILE%Envs Basic Usage

  1. Create a virtual environment:

$ mkvirtualenv venv This creates the venv folder inside ~/Envs.

  1. Work on a virtual environment:

$ workon venv Alternatively, you can make a project, which creates the virtual environment, and also a project directory inside $PROJECT_HOME, which is cd -ed into when you workon myproject. $ mkproject myproject virtualenvwrapper provides tab-completion on environment names. It really helps when you have a lot of environments and have trouble remembering their names. workon also deactivates whatever environment you are currently in, so you can quickly switch between environments.

  1. Deactivating is still the same:

$ deactivate

  1. To delete:

$ rmvirtualenv venv Other useful commands lsvirtualenv List all of the environments. cdvirtualenv Navigate into the directory of the currently activated virtual environment, so you can browse its site-packages, for example. cdsitepackages Like the above, but directly into site-packages directory. lssitepackages Shows contents of site-packages directory. Full list of virtualenvwrapper commands. virtualenv-burrito With virtualenv-burrito, you can have a working virtualenv + virtualenvwrapper environment in a single command. autoenv When you cd into a directory containing a .env, autoenv automagically activates the environment. Install it on Mac OS X using brew: $ brew install autoenv And on Linux: $ git clone git://github.com/kennethreitz/autoenv.git ~/.autoenv $ echo ‘source ~/.autoenv/activate.sh’ >> ~/.bashrc

[bash] #取消对文件的修改。还原到最近的版本,废弃本地做的修改。 git checkout – <file> #取消已经暂存的文件。即,撤销先前"git add"的操作 git reset HEAD <file>… #修改最后一次提交。用于修改上一次的提交信息,或漏提交文件等情况。 git commit --amend #回退所有内容到上一个版本 git reset HEAD^ #回退a.py这个文件的版本到上一个版本 git reset HEAD^ a.py #向前回退到第3个版本 git reset –soft HEAD~3 #将本地的状态回退到和远程的一样 git reset –hard origin/master #回退到某个版本 git reset 057d #回退到上一次提交的状态,按照某一次的commit完全反向的进行一次commit.(代码回滚到上个版本,并提交git) git revert HEAD [/bash]

来源: Dart

0%