shell command cat/find/tr/mkdir

1. cat              cat is used to read, display, or concatenate the contents of a file

cat file.txt //show the content of file.txt 显示file.txt中的内容
cat file.txt file1.txt.... //show the content of file.txt file1.txt ..... 显示多个文件file.txt file1.txt...的内容
cat file.txt | tr -s '\n' //show the content of file.txt. It will squeeze adjacent '\n' characters into a single '\n' 显示file.txt的内容,并且将连续的空行换成一个
cat -T file.txt //show the content of file.txt and highlight tab characters as ^I 显示file.txt中的内容,并且将TAB自付显示为^I
cat -n file.txt //show each line with a line number prefixed 显示文件中的内容,每一行带有行号
cat file1.txt file3.txt | xargs //show the content of file1.txt and file3.txt without any enter '\n'
cat file1.txt | xargs -n 3 //Converting single line into multiple line output and every line has 3 words (the default delimiter is space, so we could thinks it as words)

 2. find          list all the files and folders from the current directory to the descending child directories

find base_path //list all files and subfiles in base_path 
find /root/deploy_ws/ -name "testlist.*" //list all files with filename starting with testlist in /root/deploy_ws
find /root/deploy_ws/ -iname "testlist.*" //list all files with filename starting with testlist in /root/deploy_ws, the more important is to ignore case
find /root/deploy_ws \( -name "testlist.*" -or -name "*.plugin" \) -print //list all files with filename starting with testlist or ending with plugin
find /root/deploy_ws \( -name "testlist.*" -and -name "*.plugin" \) //list all files with filename starting with testlist and ending with plugin
find /root/deploy_ws -path "*BAT*" -print //list all files in /root/deploy_ws and the path for the files should match BAT*
find . -regex ".*\(\.txt\|\.sh\)$" //list all files with filename ending with txt or sh in current dir.
find . ! -name "*.txt" -print    //list files the name does not end with .txt
find . -type d -print //List only directories including descendants
find . -type f -print //List only regular files
find . -type l -print //List only symbolic links
find /usr/lib/firefox/plugins -type l -print //list symbolic links in /usr/lib/firefox/plugins
find . -type f -name "*.sh" -delete //delete all files whose type is file and filename end with .sh

 3. tr  tr [–c/d/s/t] [SET1] [SET2] 不指定options,默认是-t

  • Replace all uppercase characters to lowercase characters. (-t) 将大写字符替换为小写字符
#echo "HELLO WHO IS THIS" | tr 'A-Z' 'a-z'
hello who is this
  • -d Delete specified characters   删除指定的字符
#cat file1.txt
This is the first line inside file1.txt
# cat file1.txt | tr -d 'first'
Th  he  lne nde le1.x
  • -c Filter characters which isn't included in set1 . The example following is to delete all the characters from the input text except the ones specified in the complement set.  删除除了在列表中的其余所有的字符 -c 相当于补集的功能。
# echo hello 1 char 2 next 4 | tr -d -c '0-9 \n'   
 1  2  4
  • –s option to squeeze repeating characters from the input
# echo aaacccddd | tr -s [a-z]
acd

4. mkdir 

  • -p 
#mkdir -p /root/deploy_ws/shellTest/newDir/newDir    //ignores if any level of directory exists and creates the missing directories.

posted on 2015-06-02 13:54  karenwang  阅读(205)  评论(0编辑  收藏  举报

导航