Memo a few useful shell scripts

Source: Internet
Author: User

(1) under the shell, operate the Hadoop directory, batch name or delete, the final command sed the regular greedy replacement, look at the following script:

Java code
  1. # traverse the file name under the Hadoop directory
  2. for line in ' Hadoop fs-ls/user/d1 | Gawk ' {print $8} '
  3. Do
  4. #echo $line;
  5. #将 files in level 2 directory, move to the top level
  6. #hadoop fs-mv $line"/tmp_search_keywords_cate_stat/*" $line;
  7. #删除 level 2 Directory
  8. #hadoop fs-rm-r $line"/tmp_search_keywords_cate_stat"
  9. for line2 in ' Hadoop fs-ls $line | Gawk ' {print $8} '
  10. Do
  11. echo $line 2;
  12. #将/tmp/a/b use sed to become/tmp/a_b note the following regular formula
  13. Newname= ' echo $line 2 | Sed-e ' s/\ (. *\) \//\1_/' ;
  14. #echo $newname;
  15. Hadoop FS-MV $line 2 $newname
  16. Done
  17. Done
# traverse the name of the Hadoop directory for line in ' Hadoop fs-ls/user/d1 | Gawk ' {print $8} ' Do#echo $line;   #将2级目录下的文件, move to the previous level #hadoop FS-MV $line "/tmp_search_keywords_cate_stat/*"  $line; #删除2级目录 #hadoop FS   -rm-r  $line "/tmp_search_keywords_cate_stat" for line2 in ' Hadoop fs-ls $line  | gawk ' {print $8} '   doecho $line 2; #将/tm p/a/b use SED to become/tmp/a_b note the following regular expression newname= ' echo $line 2 | Sed-e ' s/\ (. *\) \//\1_/'; #echo $newname; Hadoop fs-mv $line 2   $newnamedonedone



(2) record the currently started process ID and suspend the operation in the background, the script example is as follows:

Java code
    1. [Search@fse4 solr]$ cat start.sh
    2. #下面的代码, record the last initiated process ID that is currently started
    3. #方便关闭时, kill.
    4. #$$ records the current process id,$! records the process ID that was last started
    5. #nohup is the background hangs the thread way to run, and the log file output to nohup.out inside, carries on the monitoring
    6. Nohup Java-jar start.jar &> nohup.out & Echo $! >pid&
    7. #echo $$ > PID
    8. [Search@fse4 solr]$
[[email protected] solr]$ cat start.sh #下面的代码, log down the process ID of the last boot that is currently started # when it is convenient to close, kill #$$ record the current process id,$! record the process that was last started Id#nohup Is the background hangs thread mode run, and the log file output to nohup.out inside, to monitor nohup Java-jar start.jar  &> nohup.out &  



(3) Under Linux, the string date is formatted as a timestamp:

Java code
    1. [Search@fsedump01sand tempshell]$ date-d ' 2015-12-01 ' +%s
    2. 1448899200

Memo a few useful shell scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.