Linux Command

User & Password

We have below users and their password:

  • root

  • ryan (sudoer)

  • grace
    Login as ryan:

  • check password expiration

    1
    chage -1 ryan	# number 1
  • change password

    1
    passwd			# for user self
  • login as root

    1
    su - root
  • change password for grace

    1
    passwd grace
  • login as grace

    1
    su grace
  • become root

    1
    sudo su - root
  • set password never expire, must done by root

    1
    2
    3
    4
    5
    6
    7
    8
    chage ryan

    Minimum password age:0
    Maximum password age:99999
    Last password change: enter
    Expiration warning: enter
    Password Inactive: enter
    Account expiration date: -1

File & Directory

  • check directory size
    1
    du -sh <path>
  • monitor log
    1
    tail -100f <file>
  • monitor log and catch specific content
    1
    tail -100f <file> | grep "<content>"
  • change file modified time
    1
    touch  -d 20170101 <file>
  • delete files that mtime > 7
    1
    find $dir -type f -mtime +7 -name '*.txt' -execdir rm -- '{}' \;
    1209-16:32 will delete files before 1201-16:32. Completed data for 7 days from 1202 to 1208
  • copy and move
    1
    2
    [cp / scp / mv] <originFile> <targetFile> / <targetDir>
    scp ryan@IP:~/test.txt ~
  • create file
    1
    touch <file>
  • remove
    1
    2
    rm <file>
    rm -r <dir> # delete all the files and dirs in this dir (include)
  • count number of files
    1
    fileNumber=`ls -1R <dir> | wc -l`
  • zip and unzip
    1
    2
    gzip <file>
    gunzip *.gz
  • permission
    1
    chmod 755 <file>

Run Program

  • nohup
    1
    2
    cd ~/myApp
    nohup ./runApp.sh &
    -1- runApp will be kept running at the background
    -2- the output like echo will be put into ~/myApp/nohup.out
  • job process id
    1
    jobPid="$(ps -ef | grep ksh | grep runApp.sh | awk '{print $2}')"
  • kill job
    1
    kill -9 <jobPid>
  • pass parameter
    1
    runApp.sh xyz	# so in runApp.sh, $1="xyz"

Operation

  • if else
    1
    2
    3
    4
    5
    if [""=""]; then
    action
    else
    action
    fi

Compile / Build Java Program

1
2
3
4
5
6
7
8
9
10
releasePath=~/myApp
buildPath=$releasePath/application
~/apache-ant/bin/ant -Dreleasepath=$releasePath -Dbuildpath=$buildPath -Dant.project=<appName> -Dlibpath=$releasePath/lib

status=$?
if [$status -eq 0]; then
echo "compilation is successful.."
else
echo "compilation is unsuccessful.."
fi

Others

  • press to continue
    1
    2
    echo "Press to continue.."
    read q