码迷,mamicode.com
首页 > 系统相关 > 详细

Linux shell basic2 cat find tr

时间:2015-02-15 21:51:16      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

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.

Linux shell basic2 cat find tr

标签:

原文地址:http://www.cnblogs.com/huaxiaoyao/p/4293493.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!