Thursday, August 6, 2015

Some good Linux scripts

Change test in file

sed -i s/helloword/HELLOWORLD/g file.txt

Copy file from Linux server to Linux server

scp source_file_name username@destination_host:destination_folder
     or
scp [-r] [[user1@]hostname1:]file1 ... [[user2@]hostname2:]file2

Ex:
scp pluto:/home/jones/letter.doc .
copy the file letter.doc from the /home/jones directory of the remote system pluto to the working directory on the local system 

scp notice.doc pluto:/home/jones
copy the file notice.doc from current directory of the local system to the /home/jones directory of the remote system, pluto

Find file match name in a folder

cd <your-folder>
for f in *; do
        case $f in
                abc*.xml)
                        echo $f
                        ;;
               
def*.xml)
                        echo $f
                        ;;
        esac
done


Check file is open in linux

Check if file prefix by 'filename' is open by 'cp' process:

while :
do
    if [[ `lsof -c cp | grep filename*.xml` ]]
    then
    printf ".";
    sleep 0.5
       
    else
        break   
    fi
done
    echo "Done!"

No comments:

Post a Comment