find -
modified > 3 days : find . -mtime +3
modified <>2 & < >
find only in current dir, exclude sub-dir: find . \( ! -name . -prune \) \( -name "xyz.dat*" -o -name "abc*" \)
find in all sub-dirs: find . -type d -print
find only in 1st level sub-dirs: find . \( ! -name . -prune \) -type d -print
find only in 1st level sub-dirs, folder names matching: find . \( ! -name . -prune \) \( -type d -a \( -name "5AA00" -o -name "5X[0789]00" \) \)
more - http://www.unix.com/answers-frequently-asked-questions/13863-advanced-complex-uses-find-command.html
Grab file records by line #
awk '{if (NR>=11895 && NR<=11905) print $0}' xxx > yyy
awk 'NR==11895, NR==11905' xxx > yyy
awk '{if (NR==11895 || NR==11905) print $0}' xxx > yyy
Get E
64 ways to get Environment variables: http://rosettacode.org/wiki/Environment_variables
awk 'BEGIN{print "HOME:"ENVIRON["HOME"],"USER:"ENVIRON["USER"]}'
print N records after some pattern:
awk 'c&&c--;/pattern/{c=N}' file
groups - find user groups
find groups a user belongs to: groups user1 user2...
find users in a group: lsgroup -f group
(file: /etc/group)
IFS - change field delimiter
see current value:
$echo "$IFS" | od -b
0000000 040 011 012 012
0000004
$echo "$IFS" | od -c
0000000 \t \n \n
0000004
changing IFS to ","
IFS_SAV=$IFS
IFS=,
line='a,,b,c,d'
for x in $line
do
echo $x
done
ls - get file date time stamp
ls -l = modification time
ls -lu = access time
ls -l = creation time
port -
AIX - This file shows the usage of ports -
lsof -i :port#
proctree -
proctree (-a) PID
procfiles -
procfiles (-n) PID
ps -
for user xxx
>> ps -fuxxx
>> ps -fl -uxxx
all jobs by xxx sort by cpu
>> ps -fuxxx | sort +3
all jobs related to PID ??????
>> ps -fL ??????
display environment of another process:
ps eww PID | tr ' ' '\n' | grep ORACLE_SID
check process priority:
ps -eo pid,state,nice,args | less -Sps -lef
change priority:
nice/renice
read -
(break fields on a record/line into variables)
>>move 1st field of each line to end of line (xx=1st field, yy=rest of fields)
while read -r xx yy
do
print printf "%s %s/n" $yy $xx
done <>> To read a line and split it into fields, and use "enter ur name:" as a prompt
read word1?"enter ur name: " word2 word3 word4....
>> read more than 1 values into a variable (reak up the list by using for)
$ read x y z; echo $x; echo $y; echo $z
one two three four
$one
$two
$three four
>> show the oldest file
: ls -tr| read xxx; echo $xxx
: ls -tr |&
read -p $xxx
echo $xxx
>> read from a file into variables
exec 3<>
sed -
print a line with a pattern & the next line
search string = APPSTVCH.BI120-3
sed -n '
/APPSTVCH.BI120-3/ {
N
/\n.*1/ p
}' APPSTVCH_703295.log
Handy one-liners for SED: http://www.catonmat.net/blog/sed-one-liners-explained-part-two/
(great site with a # of one-liners-explained http://www.catonmat.net/)
# print 1 line of context before and after regexp, with line number
# indicating where the regexp occurred
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
sort -
>> sort by column 4-14 of 1st field:
sort -k 1.4,1.14
>> sort by numeric, 3rd field, delimited by ':'
sort -n -t ':' +2 /etc/passwd
>> second field as the sort key
sort -k 2,2 infile # new style
sort +1 -2 infile # old style
>> reverse sort, contents of infile1 and infile2, placing the output in outfile and using the second character of the second field as the sort key (assuming that the first character of the second field is the field separator):
sort -r -o outfile -k 2.2,2.2 infile1 infile2 # new style key definition used
sort -r -o outfile +1.1 -1.2 infile1 infile2 # old style key definition used
>> sorts the contents of infile1 and infile2 using the second non-blank character of the second field as the sort key:
sort -k 2.2b,2.2b infile1 infile2
sort +1.1b -1.2b infile1 infile2
>> prints the passwd(4) file (user database) sorted by the numeric user ID (the third colon-separated field):
sort -t ':' -k 3,3n /etc/passwd
sort -t ':' +2 -3n /etc/passwd
sort -n -t ':' -k 3,3 /etc/passwd
>> imitate uniq using sort: either of the following commands prints the lines of the already sorted file infile, suppressing all but one occurrence of lines having the same third field:
sort -um -k 3.1,3.0 infile
sort -um +2.0 -3.0 infile
The -n option informs sort to compare the specified field as numbers, not ASCII characters. The r option reverses the order of the sort.
sort -t: +5 -6 +0 -1 /etc/passwd # The output is now sorted by field 6, then by field 1 if necessary.
- using TAB as delimiter, sort on 5th field: sort -t "`/bin/echo '\t'" +6 xx
touch -
- change DTTM stamp
03:04:55 a.m. on Jan 2, 1985
>>touch -t 198501020304.55 program.c
use the time stamp of another file
>>touch -r file1 program.c
avoid creating a new file, enter
>>touch -c program