Cat stands for concatenate.

Case 1.

When the text files have more blank lines, we want to remove them.

We can use regex \s+ '\n'.

cat file.txt | tr \s '\n'

cat -T file.txt # show tabs as ^.

cat -n file.txt # show line numbers

. Specifies current directory and .. Specifies the parent directory. This convention is followed throughout the Unix file system.

find . -iname "*.txt"

i means ignore the case.

find . \( -name "*.txt" -o -name "*.pdf" \) -print

./text.pdf

./new.txt

find . -iregex ".*\(\.py\|\.sh\)$"

./test.py

./new.PY

find . ! -name "*.txt" -print

Files not end with .txt.

find . -maxdepth 1 -type f -print

Just show file and not traverse the sub folder.

find . -type d

Just show the directory

Type :

f : file

d: directory

l: link

Print all the files that were accessed within the last 7 days as follows:

$ find . -type f -atime -7 -print

atime: access time

mtime: modify time

-ctime:change time

n order to print all the files that are having access time older than seven minutes, use the

following command:

$ find . -type f -amin +7 -print

For example, find all the files that are having a modification time greater than that of the

modification time of a given file.txtfile as follows:

$ find . -type f -newer file.txt -print

Search based on file size

Based on the file sizes of the files, a search can be performed as follows:

$ find . -type f -size +2k

# Files having size greater than 2 kilobytes

Instead of kwe can use different size units as the following:

b– 512 byte blocks

c– bytes

w– two byte words

k– Kilobyte

M– Megabyte

G– Gigabyte

find . -type f -name "*.c" -exec cat {} \;>all_c_files.txt

$ cat example.txt # Example file

1 2 3 4 5 6

7 8 9 10

11 12

$ cat example.txt | xargs

1 2 3 4 5 6 7 8 9 10 11 12

$ cat example.txt | xargs -n 3

1 2 3

4 5 6

7 8 9

10 11 12

echo "hello linux" | tr 'a-z' 'A-Z'

HELLO LINUX

echo "Hello 123 world 456" | tr -d '0-9'

Hello world

echo hello 1 char 2 next 4 | tr -d -c '0-9 \n'

1 2 4

echo "I am your friends?" | tr -s ' '

I am your friends?

find -type f | xargs md5sum

e8bc686b2c380b9ad56c024a03384150 ./sub/java.txt

a5bf231497e5d503172bfd39a387b197 ./all_txt_files.txt

e827b6437257f24b9e5fbba44fd98f5c ./num.txt

b6d9275e7e16b154059677fac91baa79 ./test.txt

b6d9275e7e16b154059677fac91baa79 ./mul_bank.txt

sort -r : sort in reverse order

Split can used to split file to specify size.

Linux shell basic2 cat find tr的更多相关文章

  1. Linux Shell脚本编程while语句案例

    1,每隔3秒,打印一次系统负载 #!/bin/bash while true do uptime done 2,把监控结果保存到文件,在后台执行,然后用tail -f监控文件变化 ghostwu@de ...

  2. linux shell脚本之-变量极速入门与进阶(2)

    1,$$:显示当前的进程id号 ghostwu@dev:~/linux/shell/how_to_use_var$ cat show_pid.sh #!/bin/bash echo $$ ghostw ...

  3. linux shell脚本之-变量极速入门与进阶(1)

    1,如果创建shell脚本? 使用任意文本编辑软件,一般为vim,创建.sh结尾的文件,在文件的最开头用 #!/bin/bash 注明shell的类型 如: ghostwu@dev:~/linux/s ...

  4. Linux Shell脚本编程while语句

    Linux Shell脚本编程while语句案例 1,每隔3秒,打印一次系统负载 #!/bin/bash while truedo    uptime    sleep 3done 2,把监控结果保存 ...

  5. Linux Shell 文本处理工具集锦--Awk―sed―cut(row-based, column-based),find、grep、xargs、sort、uniq、tr、cut、paste、wc

    本文将介绍Linux下使用Shell处理文本时最常用的工具:find.grep.xargs.sort.uniq.tr.cut.paste.wc.sed.awk:提供的例子和参数都是最常用和最为实用的: ...

  6. Linux shell tr 命令详解

    该随笔摘自 https://www.jb51.net/article/103892.htm Linux shell tr 命令详解 1. 用途 tr,translate的简写,主要用于压缩重复字符,删 ...

  7. linux shell的here document用法(cat << EOF)

    什么是Here Document?Here Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下cmd << delimiter  Here Docu ...

  8. (转)linux shell 的here document 用法 (cat << EOF)

    什么是Here Documen: Here Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下 cmd << delimiter Here Docu ...

  9. Linux SHELL 命令入门题目答案(一)

    1.如何使用shell 打印 “Hello World!” (1)如果你希望打印 !,那就不要将其放入双引号中,或者你可以通过转义字符转义(2)echo 'hello world!' 使用单引号ech ...

随机推荐

  1. 获取 Windows Phone 手机系统信息

    wpf: <phone:PhoneApplicationPage x:Class="ABSystemInfo.MainPage" xmlns="http://sch ...

  2. Azure开发者任务之七:在Azure托管服务中托管WCF服务角色

    在一个托管服务中托管一个WCF服务角色和托管一个ASP.Net Web Role基本类似. 在上一篇文章中,我们学习了如何使用WCF Service Web Role. 在本文中,我会对上一篇文章进行 ...

  3. SQL Server 性能调优(一)——从等待状态判断系统资源瓶颈【转】

    转载自:http://blog.csdn.net/dba_huangzj/article/details/7607844#comments 通过DMV查看当时SQL SERVER所有任务的状态(sle ...

  4. 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传

    [源码下载] 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后台任务 后台 ...

  5. Java集合框架之Collection接口

    Java是一门面向对象的语言,那么我们写程序的时候最经常操作的便是对象了,为此,Java提供了一些专门用来处理对象的类库,这些类库的集合我们称之为集合框架.Java集合工具包位于Java.util包下 ...

  6. Linux Shell系列教程之(十七) Shell文件包含

    本文是Linux Shell系列教程的第(十七)篇,更多Linux Shell教程请看:Linux Shell系列教程 通过文件包含,可以引用其他文件的内容,也可以将复杂内容分开,使程序结构更加清晰. ...

  7. ValueStack值栈和ActionContext

    Struts2在OGNL之上提供的最大附加特性就是支持值栈(ValueStack),在OGNL上下文中只能有一个根对象,Struts2的值栈则允许存在许多虚拟对象. 一:值栈(ValueStack) ...

  8. PHP遍历目录四种方法

    学习SPL的时候,遇到了DirectoryIterator这个目录类,谢了一下遍历目录的方法.于是总结一下遍历目录的四种写法 如下: <?php /* * 方法一:利用SPL的目录类,这个很简单 ...

  9. jquery TypeError: 'undefined' is not a function (evaluating 'elem.nodeName.toLowerCase()') [jquery.js:1904]错误原因

    今天,某个环境报了个js错误,TypeError: 'undefined' is not a function (evaluating 'elem.nodeName.toLowerCase()') [ ...

  10. 解决SQL Server 2008 64位系统无法导入Access/Excel的问题 2012/08/01

    操作系统Windows Server 2008 X64,数据库SQL Server 2008 X64,Office 2007(好像只有32位),在存储过程执行OpenDatasource导入Acces ...