分类目录归档:Linux shell

Speed up grep searches with LC_ALL=C

Ever try to run a grep search on a large file, and wish there was a way to speed things up?

After some late night Googling, I ran across a proposed method of significantly speeding up a grep search from dogbane over on StackOverflow.

I went ahead and dug deeper with research and even setup a little test to try things out and understand what’s going on.

As someone that’s used grep for nearly a decade, I’m a bit embarassed to say I’d never heard of this.

If you care to skip over my extensive research on this and are just curious in the actual testing results, I won’t get offended, much.

speed up grep search

继续阅读

GNU Bourne-Again SHell Manpage

BASH

Section: User Commands (1)
Updated: 2006 September 28
IndexReturn to Main Contents


 

NAME

bash – GNU Bourne-Again SHell  

SYNOPSIS

bash [options] [file]  

COPYRIGHT

Bash is Copyright (C) 1989-2005 by the Free Software Foundation, Inc.  

DESCRIPTION

Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh). 继续阅读

Advanced Bash-Scripting Guide

Advanced Bash-Scripting Guide

An in-depth exploration of the art of shell scripting

Mendel Cooper

6.2

17 March 2010

Revision History
Revision 6.0 23 Mar 2009 Revised by: mc
‘THIMBLEBERRY’ release: Major Update.
Revision 6.1 30 Sep 2009 Revised by: mc
‘BUFFALOBERRY’ release: Minor Update.
Revision 6.2 17 Mar 2010 Revised by: mc
‘ROWANBERRY’ release

This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward an intermediate/advanced level of instruction . . . all the while sneaking in little nuggets of UNIX® wisdom and lore. It serves as a textbook, a manual for self-study, and a reference and source of knowledge on shell scripting techniques. The exercises and heavily-commented examples invite active reader participation, under the premise that the only way to really learn scripting is to write scripts.

This book is suitable for classroom use as a general introduction to programming concepts.


继续阅读

Using ctags in Vim

Using ctags and Vim is a lethal combination, especially when doing bigger projects.

Using them gives you the following features:

  • Impressive class/function/method search
  • Ability to go to the definition of a function with one click (even in dynamic languages like Python)
  • Better overview by a module browser (where you can see classes and members)

Getting started with Taglist

Tag list opens a left window where you can browse the current file. It gives a nice overview. Here is an example (click for a bigger picture):

taglist_small

继续阅读

Bash Reference Manual

Table of Contents

  • 1 Introduction
    • 1.1 What is Bash?
    • 1.2 What is a shell?
  • 2 Definitions
  • 3 Basic Shell Features
    • 3.1 Shell Syntax
      • 3.1.1 Shell Operation
      • 3.1.2 Quoting
        • 3.1.2.1 Escape Character
        • 3.1.2.2 Single Quotes
        • 3.1.2.3 Double Quotes
        • 3.1.2.4 ANSI-C Quoting
        • 3.1.2.5 Locale-Specific Translation
      • 3.1.3 Comments
    • 3.2 Shell Commands
      • 3.2.1 Simple Commands
      • 3.2.2 Pipelines
      • 3.2.3 Lists of Commands
      • 3.2.4 Compound Commands
        • 3.2.4.1 Looping Constructs
        • 3.2.4.2 Conditional Constructs
        • 3.2.4.3 Grouping Commands

        继续阅读

Linux 技巧:让进程在后台可靠运行的几种方法

想让进程在断开连接后依然保持运行?如果该进程已经开始运行了该如何补救? 如果有大量这类需求如何简化操作?

我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败。如何让命令提交后不受本地关闭终端窗口/网络断开连接的干扰呢?下面举了一些例子, 您可以针对不同的场景选择不同的方式来处理这个问题。 继续阅读

Linux 技巧:重定向 stderr 和 stdout 输出到 gdb 窗口

 

简介

本文介绍了一个实用 gdb 调试技巧。 它结合实际例子,一步一步示意如何重定向 stderr 和 stdout 到 gdb窗口,使得查看应用程序的输出信息更为方便,从而提高调试者的工作效率。 继续阅读

Linux 技巧: Bash 测试和比较函数

test、[、[[、((、和 if-then-else 解密

您是否为 Bash shell 中大量的测试和比较选项而困惑呢?这个技巧可以帮助您解密不同类型的文件、算术和字符串测试,这样您就能够知道什么时候使用 test[ ][[ ]](( ))if-then-else 了。
继续阅读

Linux 技巧: Bash 参数和参数扩展

在脚本中传递和分析参数

您是否有时想知道如何对脚本使用参数,以及如何将参数传递给内部函数或其他脚本?是否需要对参数或选项做一些简单的有效性测试?或者对参数字符串执行一些简单的析取和替换操作?本文将向您介绍参数的用法和 bash shell 中的各种参数扩展。

现在,很多 Linux® 和 UNIX® 系统上都有 bash shell,它是 Linux 上常见的默认 shell。通过本文,您将了解到如何在 bash 脚本中处理参数和选项,以及如何使用 shell 的参数扩展检查或修改参数。本文重点介绍 bash,文中的示例都是在以 bash 为 shell 的 Linux 系统上运行。但是,很多其他的 shell 中也有这些扩展,比如 ksh、ash 或 dash,您可以在其他 UNIX 系统或者甚至是 Cygwin 之类的环境中使用这些 shell 和扩展。早前的一篇文章 Linux 技巧:Bash 测试和比较函数 已经对本文中的构建工具进行了介绍。 本文中的某些材料摘录自 developerWorks 教程 LPI 102 考试准备,主题 109: Shell、脚本、编程和编译,该教程介绍了很多基本的脚本编程技术。 继续阅读

Bash 实例

第一部分

Bourne again shell (bash) 基本编程

Daniel Robbins (drobbins@gentoo.org), 总裁兼 CEO, Gentoo Technologies, Inc.

 

简介: 通过学习如何使用 bash 脚本语言编程,将使 Linux 的日常交互更有趣和有生产力,同时还可以利用那些已熟悉和喜爱的标准 UNIX 概念(如管道和重定向)。在此三部分系列中,Daniel Robbins 将以示例指导您如何用 bash 编程。他将讲述非常基本的知识(这使此系列十分适合初学者),并在后续系列中逐步引入更高级特性。

继续阅读