RSS Feed for This PostCurrent Article

Useful Unix Commands

Some side note on some Unix commands. List will grow over time…

Find new created large file for past 3 days
# find /path -type f -mtime -3 -exec ll \+ | sort -rn -k5 | head -n 10

vi

<esc>:g/^$/d

This means that all the lines that just have a carriage return on them (NO Spaces), will be removed.

Ok, so I have some of those lines too. How can I remove all of them as well?

<esc>:g/^ *$/d

NOTE: There is a space after the ‘^’ and before the ‘*’.

sed

Remove HTML tags

sed -e :a -e 's/<[^>]*>//g;
/</N;//ba'

Get number of opened sockets

 (( socketsopen=`
netstat -an|wc -l` - 
`netstat -an | 
grep -n "Active UNIX domain sockets
"|cut -d: -f1` - 2 )); 
echo $socketsopen

for HP-UX, find process by port number

# lsof -i tcp:161
# lsof -i udp:161

Download from
http://gatekeep.cs.utah.edu/
hppd/hpux/Sysadmin/lsof-4.64/

ps showing memory info

to find the system serial number

echo “map selall info;wait infolog” | cstm > /tmp/cstm.txt

UNIX95=1 ps -ef -o pid,sz,vsz,comm
ps -elf|awk ‘{print $10, $3, $4, $15, 16}’|sort -nr|more

vi references

Editing

A Append to end of current line
i Insert before cursor
I Insert at beginning of line
o Open line above cursor
O Open line below cursor
ESC End of insert mode
Ctrl-I Insert a tab
Ctrl-T Move to next tab position
Backspace Move back one character
Ctrl-U Delete current line
Ctrl-V Quote next character
Ctrl-W Move back one word
cw Change word
cc Change line
C Change from current position to end of line
dd Delete current line
ndd Delete n lines
D Delete remainer of line
dw Delete word
d} Delete rest of paragraph
d^ Delete back to start of line
c/pat Delete up to first occurance of pattern
dn Delete up to next occurance of pattern
Delete up to and including a on current line
dta Delete up to, but not including, a on current line
dL Delete up to last line on screen
dG Delete to end of file
J Join two lines
p Insert buffer after cursor
P Insert buffer before cursor
rx Replace character with x
Rtext Replace text beginning at cursor
s Substitute character
ns Substitute n characters
S Substitute entire line
u Undo last change
U Restore current line
x Delete current cursor position
X Delete back one character
nX Delete previous n characters
. Repeat last change
~ Reverse case
y Copy current line to new buffer
yy Copy current line
“xyy Copy current line into buffer x
“Xd Delete and append into buffer x
“xp Put contents of buffer x
y]] Copy up to next section heading
ye Copy to end of word

Cursor

h Left
j Down
k Up
l (or spacebar) Right
w Forward one word
b Back one word
e End of word
( Beginning of current sentence
) Beginning of next sentence
{ Beginning of current paragraph
} Beginning of next paragraph
[[ Beginning of current section
]] Beginning of next section
0 Start of current line
$ End of current line
^ First non-white character of current line
+ or RETURN First character of next line
– First character of previous line
n | character n of current line
H Top line of current screen
M Middle line of current screen
L Last line of current screen
nH n lines after top line of current screen
nL n lines before last line of current screen
Ctrl-F Forward one screen
Ctrl-B Back one screen
Ctrl-D Down half a screen
Ctrl-U Up half a screen
Ctrl-E Display another line at bottom of screen
Ctrl-Y Display another line at top of screen
z RETURN Redraw screen with cursor at top
z . Redraw screen with cursor in middle
z – Redraw screen with cursor at bottom
Ctrl-L Redraw screen without re-positioning
Ctrl-R Redraw screen without re-positioning
/text Search for text (forwards) dfa
/ Repeat forward search
?text Search for text (backwards)
? Repeat previous search backwards
n Repeat previous search
N Repeat previous search, but it opposite direction
/text/+n Go to line n after text
?text?-n Go to line n before text
% Find match of current parenthesis, brace, or bracket.
Ctrl-G Display line number of cursor
nG Move cursor to line number n
:n Move cursor to line number n
G Move to last line in file

File Handling

:w Write file
:w! Write file (ignoring warnings)
:w! file Overwrite file (ignoring warnings)
:wq Write file and quit
:q Quit
:q! Quit (even if changes not saved)
:w file Write file as file, leaving original untouched
ZZ Quit, only writing file if changed
😡 Quit, only writing file if changed
:n1,n2w file Write lines n1 to n2 to file
:n1,n2w >> file Append lines n1 to n2 to file
:e file2 Edit file2 (current file becomes alternate file)
:e! Reload file from disk (revert to previous saved version)
:e# Edit alternate file
% Display current filename
# Display alternate filename
:n Edit next file
:n! Edit next file (ignoring warnings)
:n files Specify new list of files
:r file Insert file after cursor
:r !command Run command, and insert output after current line

With top you can use:

top -d 1 -n 1024 -f /tmp/topout

The -d 1 means 1 screen, -n 1024 means up to 1024 processes shown (this is
unlimited), and -f /tmp/topout means to send the output to that file.

With glance you can use:

glance -f /tmp/gout -adviser_only -bootup -iterations 2 > /dev/null

The -f /tmp/gout means to send the output to /tmp/gout, -advisor_only and
-bootup are required to send the output to a file, and -iterations is how
many screen shots (minimum 2). You need to output to /dev/null so it won’t
try to display. There is a -syntax command line option that
tells where to look for advisor syntax. If you don’t specify anything, it
defaults to the syntax in /var/opt/perf/adviser.syntax.

See the top and glance man pages for more info.

Check for large file

#fsadm -F vxfs /mount_point

Enable large file

#fsadm -o largefiles /my/filesystem

Mounting a ISO file in HP-UX

nohup /usr/sbin/pfs_mountd&
nohup /usr/sbin/pfsd&
/usr/sbin/pfs_mount -t iso9660 -x unix /images/cd.iso /mnt

Find and grep text

find . -name “*.java” -exec grep “JSON String” {} \; -print
find . -name ‘*.java’ -mtime +7 -print | xargs grep ‘java.awt’

one liner

http://www.unixguide.net/unix/sedoneliner.shtml
http://www.catonmat.net/blog/sed-one-liners-explained-part-one/
http://sed.sourceforge.net/sed1line.txt
http://student.northpark.edu/pemente/awk/awk1line.txt
http://www.catonmat.net/blog/awk-one-liners-explained-part-one/
http://www.softpanorama.org/Tools/Awk/awk_one_liners.shtml


Trackback URL


Sorry, comments for this entry are closed at this time.