Unix and Vi

Unix

./ <file name> runs file
cat <file name> viewer
cd Change directory
env shows environment set up
id Shows id of logged on user
kill <PID> <PID> etc Kills process, PID found from ls _l
ls list
ls –l shows properties, including PID (l for long)
ls –la As for ls – l, bit includes hidden files that start with ‘.’
ls -lct | head <number(optional)> Orders content with latest at top. Default is 10
ps Shows processes
ps -ef | grep –i <process name> or <user name> Shows all processes running regardless of user
ps -fu <user name> Shows process run per user
pwd Shows current directory
su – <new login> use this to change log ins
su – changes log into Root
vi <file name> opens Vi with specified file.
tail –f <file name> Tails log (-f automatic update)
man <command> Syntax and usage notes for commandNote q exits synopsis. Also try <command> -h or —
uptime Shows how long session has been open
chmod o+r <name> Read approval to the others
chmod g+r <name> Read approval to the group
rm <name> Deletes a file
rm <name> – i As for rm but is (i)nteractive
Mv <source> <new name> Moves file giving new name
Cp <source> <destination> Copies a file to a new destination
pushd Marks the current directory
Popd Returns you to the previous popd directory
mkdir <name> Makes new directory
Touch <name> Makes new empty file
find . -type <d or f> D for directory, f for files
grep –i <string> * Searches all the files in the current directory, -I makes it case insensitive, * wildcard for this directory
| Pipe; feeds out of a previous command in to the second, “<” does a similar role
~ Tilde; in a path takes you to home cd ~
/ Root   ie cd /
cat `grep -i <word> * | awk -F”:” ‘{print $1}’` The ` & ` return the value of the call as a stringAwk –F “:” defines the break point{print $1} instead of echo as it does not force a new line break
time Time < command> times command
Command –h
su root -c “command here” Exercise a command as root
Chown owner:group name Change the ownership of the file
du -sk * Shows disk useage
df   -k Shows disk useage
cat <file1> | dos2unix > <new file name> Removes ^M from scripts
nslookup To find names for IP addresses and vica versa
Netstat -a To find out what ports are used for whatCan be helpful to grep out the port you want
> /dev/null
psrinfo -v Show machine config
prtconf|grep -i mem Show more comfit
perl -pi -e ‘s/\/\/[^\n]*//g’ foo To fix the comments in a file called foo
diff -u ./old file ./new file > one.patch Diff –u old_file new_file >output
Tar –cvf new_name.tar input_file To compress file
find . -type f -exec grep word {} \; -print Find a word in the files in a directory
for i in *log; do > $i; done Clear logs
/usr/platform/`uname -i`/sbin/prtdiag -v Get all the config information for a box
find . -mtime -3 Find files in the current directory (or subdirectories) that have been modified within the last 3 days.
find . -type f -mtime -3 find FILES ONLY (not directories, devices, etc) that have been modified within the last 3 days.
find . -mtime +5 find files that have not been modified for 5 days.
ls -t list files, sorted by modification time (oldest first)
ls -rt list files, sorted by modification time (newest first)
psradm Used to change the number of CPUs available on a multi CPU box use man to get usage and mpstat to verify
find . -type f | xargs grep -l <name>find . -type f | xargs grep -l tbotteri Finds word in a file
last Shows who was logged on a box
Kill –stop <PID> Stops a process
Kill –cont <PID> Restarts the process

Vi

Love it or hate it. If you are going to work on a UNIX box at some point you will have to use VI

Some of the basic commands

To Open a File

Vi <Filename>

To enter command mode, press <esc>

To edit a document
I          To insert text at the beginning of a line
i          To insert text at the cursor
a         Append text after the cursor
A        Append text at the end of a line
cw      Change word
dw     Delete word
D       Delete Current to end of Line
dd      Delete line
dd      Deletes the number of lines
yy       Copy line
dd      Copy number of lines

To exit
zz       save and quit
:wq!  save and quit
:q!     quit without saving

http://en.wikipedia.org/wiki/Vi

Leave a Reply

Your email address will not be published. Required fields are marked *