2017年2月19日 星期日

Handbook - Linux

Q: Kill all process related to an application
A: use 'killall' command.

Q: Where is the core dumps ?
A: [Ubuntu12.04] /var/crash/

Q: How to pause (suspend) / resume current process ?
A: To pause (suspend) current process, press CTRL+Z
To resume it, use 'fg' command.

Q: How to show time (including year) of a file ?
A: ls --full-time

Q: How to show a file's creation time ?
A: stat


Q: How to update hardware time ?
A: "ntpdate pool.ntp.org" or "date --set "5 Aug 2012 12:54 IST"
and "hwclock --systohc --localtime"
# Truncate the file in-place starting a certain line.
sed -i '50001,$ d' filename
-i means in place.
d means delete.
50001,$ means the lines from 50001 to the end.



=======================================================================
GREP
=======================================================================
Q. How to grep multiple patterns/keyworks?
A. grep -E 'pattern1|pattern2' file

# Show lines containing any one of multiple keywords in a file 'foo.txt'
grep -e keyword1 -e keyword2 foo.txt

# Show lines containing 'keyword' in a file 'foo.txt'
grep keyword foo.txt

# Full (case sensitive) match
grep -w ""

# Show X lines before and Y lines after the line containing 'keyword' in a file 'foo.txt'

grep -B X -A Y keyword foo.txt
grep -C Z keyword foo.txt #when Z=Y=X

# Special characters.
grep '\$' # dollar sign
grep -P 'Modified\t' * # Tab


# Find line number of a specific text.
A: grep -nr 04:07: top_log

grep -n -E 'WNC|null pointer' tsu_all_20210202 > tsu_all_20210202.refine1
grep -v -E 'convertWNCsignalStrengthToRIL|SIGNAL_STRENGTH' tsu_all_20210202.refine1 > tsu_all_20210202.refine2
grep -n -E 'null pointer|Data Connection ESTABLISHED' tsu_all_20210202 > tsu_all_20210202.refine3
grep -n -E 'null pointer|SIGNAL_STRENGTH' tsu_all_20210202 > tsu_all_20210202.refine4


=========================================================================================
TAR
=========================================================================================
tar zcf foo.tgz foo/ --exclude .git
tar: ais9628_20180412_tmp-glibc/work/mdm9607-oe-linux-gnueabi/tftp-server/git-r1/pseudo/pseudo.socket: socket ignored

% mkdir /work/bkup/jane
% cd /home/jane
% tar cf - . | (cd /work/bkup/jane && tar xBf -)


=========================================================================================
Screen
=========================================================================================
Q. How to grep multiple patterns/keyworks?
A. grep -E 'pattern1|pattern2' file

[Process]
     # List process of given executable
          $ pgrep

[User account, group, permission]
     # How do I find out what groups I belong to?
           $ groups []
           or
           $ id -Gn []
     # How to add a user to multiple groups?
           $ usermod -a -G ftp,sudo,example geek

[Date & Time]
     # Set date
     
     date 010100002000.00     
     #MMDDhhmmYYYY.ss Linux command to get time in milliseconds
     
     bash - Linux command to get time in milliseconds - Stack Overflow
          date +"%T.%N" returns the current time with nanoseconds.
               06:46:41.431857000
          date +"%T.%6N" returns the current time with nanoseconds rounded to the first 6 digits, which is microseconds.
               06:47:07.183172 
          date +"%T.%3N" returns the current time with nanoseconds rounded to the first 3 digits, which is milliseconds.
               06:47:42.773

沒有留言: