(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
- # traverse the file name under the Hadoop directory
- for line in ' Hadoop fs-ls/user/d1 | Gawk ' {print $8} '
- Do
- #echo $line;
- #将 files in level 2 directory, move to the top level
- #hadoop fs-mv $line"/tmp_search_keywords_cate_stat/*" $line;
- #删除 level 2 Directory
- #hadoop fs-rm-r $line"/tmp_search_keywords_cate_stat"
- for line2 in ' Hadoop fs-ls $line | Gawk ' {print $8} '
- Do
- echo $line 2;
- #将/tmp/a/b use sed to become/tmp/a_b note the following regular formula
- Newname= ' echo $line 2 | Sed-e ' s/\ (. *\) \//\1_/' ;
- #echo $newname;
- Hadoop FS-MV $line 2 $newname
- Done
- 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
- [Search@fse4 solr]$ cat start.sh
- #下面的代码, record the last initiated process ID that is currently started
- #方便关闭时, kill.
- #$$ records the current process id,$! records the process ID that was last started
- #nohup is the background hangs the thread way to run, and the log file output to nohup.out inside, carries on the monitoring
- Nohup Java-jar start.jar &> nohup.out & Echo $! >pid&
- #echo $$ > PID
- [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
- [Search@fsedump01sand tempshell]$ date-d ' 2015-12-01 ' +%s
- 1448899200
Memo a few useful shell scripts