Linux shell basic2 cat find tr

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

mtiem: 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.

时间: 2024-12-27 07:27:24

Linux shell basic2 cat find tr的相关文章

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

1,$$:显示当前的进程id号 [email protected]:~/linux/shell/how_to_use_var$ cat show_pid.sh #!/bin/bash echo $$ sleep 3000 [email protected]:~/linux/shell/how_to_use_var$ bash show_pid.sh & [1] 9401 [email protected]:~/linux/shell/how_to_use_var$ 9401 [email pro

Linux Shell脚本编程while语句案例

1,每隔3秒,打印一次系统负载 #!/bin/bash while true do uptime sleep 3 done 2,把监控结果保存到文件,在后台执行,然后用tail -f监控文件变化 [email protected]:~/linux/shell/flow_control$ sh while.sh & [1] 12867 #!/bin/bash while true do uptime >> log.txt sleep 3 done [email protected]:~/

Linux Shell脚本编程while语句

Linux Shell脚本编程while语句案例 1,每隔3秒,打印一次系统负载 #!/bin/bash while truedo    uptime    sleep 3done 2,把监控结果保存到文件,在后台执行,然后用tail -f监控文件变化[email protected]:~/linux/shell/flow_control$ sh while.sh &[1] 12867 #!/bin/bash while truedo    uptime >> log.txt    s

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

什么是Here Document Here Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下 cmd << delimiter   Here Document Content delimiter 它的作用就是将两个 delimiter 之间的内容(Here Document Content 部分) 传递给cmd 作为输入参数. 比如在终端中输入cat << EOF ,系统会提示继续进行输入,输入多行信息再输入EOF,中间输入的信息将会显示在

Linux Shell 文本处理工具集锦

本文将介绍Linux下使用Shell处理文本时最常用的工具: find.grep.xargs.sort.uniq.tr.cut.paste.wc.sed.awk: 提供的例子和参数都是最常用和最为实用的: 我对shell脚本使用的原则是命令单行书写,尽量不要超过2行: 如果有更为复杂的任务需求,还是考虑python吧: find 文件查找 查找txt和pdf文件 find . ( -name "*.txt" -o -name "*.pdf" ) -print 正则方

Linux基础练习题(ls,tr,useradd,usermod)

0729练习题 1.将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中.      [[email protected] ~]# tr 'a-z' 'A-Z' < /etc/issue >/tmp/issue.out [[email protected] ~]# cat /tmp/issue.out \S KERNEL \R ON AN \M 2.一个linux用户给root发邮件,要求邮件标题为"help",邮件正文如下: Hello,

Linux Shell脚本编程学习笔记和实战

http://www.1987.name/141.html shell基础 终端打印.算术运算.常用变量 Linux下搜索指定目录下特定字符串并高亮显示匹配关键词 从键盘或文件中获取标准输入 [read命令] 文件的描述符和重定向 数组.关联数组和别名使用 函数的定义.执行.传参和递归函数 条件测试操作与流程控制语句 获取时间日期格式和延时 [date.sleep命令] 内部字段分隔符IFS和脚本的调试DEBUG 显示.读取或拼接文件内容 [cat命令] 文件查找与打印文件列表 [find命令]

LINUX SHELL脚本攻略笔记[速查]

Linux Shell脚本攻略笔记[速查] 资源 shell script run shell script echo printf 环境变量和变量 pgrep shell数学运算 命令状态 文件描述符和重定向 cat 数组和关联数组 alias date 调试脚本 函数和参数 管道 读取命令输出 read 字段分隔符和迭代器 循环 比较和测试 find xargs tr md5sum sha1sum 对目录进行校验 sort uniq tempfile split bash变量匹配切分 exp

Requirement-Driven Linux Shell Programming

*/--> Requirement-Driven Linux Shell Programming Table of Contents 1. Where can I find the basic Material about Linux Shell Programming? 2. How to time a function/program(Get the execution time of a program)? 3. How to pass parameters to a function?