Shell 基础命令

Basic commonds:

1. Give the authority for execution

chmod +x filename.sh

2. Look the content

cat filename.sh

3. Create a new file and edit the content

vi filename    # e.g., vi Bo0001.sh

4. Create a new folder

mkdir filename

5. Rename file

mv filename1 filename2  # rename file1 as file2

6. Delete or remove (rm) the file

rm filename  

7. Delete the folder

rmdir filename 

8. Copy

cp path1/filename path2    # copy the file from path1 to path2.

9. Replace the content

sed -i '4s/name1/name2/' filename    # Replace name1 as name2 at the 4th line of the file
sed -i 's/name1/name2/g' filename    # Replace name1 as name2 at every possible place in the file

10. Give a parameter to a program 

 An example (input a value "0.2299" to the program ./voroData.out using pipe):

echo 0.2299 | ./voroData.out   
11.Disk usage enquires:
du -sh --max-depth=1   #查看当前目录下所有一级子目录文件夹大小
du -d1 -h # ubuntu
du -h --max-depth=1 |sort  #查看当前目录下所有一级子目录文件夹大小并排序

12. See the current path:

pwd

 13. 查找包含某个内容的文件目录

find | xargs grep -l particle_input.dat

 

================================================

Example 1 - Running jobs 

#!/bin/bash

./a.out>>output

sleep 10

if [ -f jobfinished ]; then
exit 0
elif [ -f jobError ]; then
exit 0
else 
qsub Bo00802
fi

Example 2 - Replace contents in a file

#! /bin/bash

cd /short/v71/ywu565/settling/quenching/0JUN/NP6500/Bo00013
sed -i '4s/2400 /1500/' hopp3d.inp

 

posted @ 2017-12-08 12:02  YWU  阅读(190)  评论(0)    收藏  举报