Visit our Google Group Way 2 SAP BASIS

unix commands

Forum where general Basis related topics are discussed.

Moderators: BASIS24x7, Rashed

unix commands

Postby mubashir »

Download the original attachment

UNIX
Below are few useful UNIX command which can be used in your daily task. Unix commands are case sensitive and be careful while running any of these command.

Listing of files:

ls -lt | more : list of files, sort by date
ls -lR | more : list of files including sub directories (recursive mode).
ls -l | sort +4nr | more : List of files sort by size.
Space administration:

bdf . : Current file system usage.
bdf : List of the moutpoint with utilization and free space.
df -k : same as above but with more details.
df -k . : Current filesystem usage.
du -k : List of file with current utilization including sub directories.
du -k . : List of files with size in the current directory.
Create / Copy / Move / ftp files:

vi <file_name> : Edit / change the file content. And also the same command is used for creating the new file.
mv <source_file> <target_path and target_file> : move a file from one location to other or same location. Ex. (mv abc.txt pqr.txt) (mv /home/abc.txt /home/Q47/abc.txt. Be careful while running this command.
cp <source_file> <target_path and target_file> : Make a copy of a file from one location to other or same location. Ex. (cp abc.txt pqr.txt) (cp /home/abc.txt /home/Q47/abc.txt. Be careful while running this command.
ftp <host_name> : Copy local files from windows machine to Unix server. Ex. below:
ftp sapux003
Will prompted user name and password and then it will connect to the UNIX server.
bin : Enable the binary mode.
hash : Enable the (#) mode.
put <file_name>


General Commands:

last : List of the users who logged into the system, ordered by current date.
top : List of process which are using high CPU, memory etc..
date : today's date.
tail -f <file_name> : Will show the last few lines of the file, and also will update if the file is being modified.
tail -<last_line_numbers> <file_name> : same as above but will display the lines which you have mentioned in the option. Ex. tail -100 <file_name>.
pwd : show current directory.
uptime : System Uptime, from when the system is up.
ps -eaf | grep <process> : Process are running with the <text> Ex. ps -eaf | grep ora
w : currently logged on users.
whoami : Show which user you are logged in.
env : Show environment variables.
echo $<variable_name> : Show the variable output. Ex. echo $ORACLE_HOME.

Useful commands while working with SAP under UNIX:

dpmon : Work process list at OS level as SM50.
disp+work -V | more : Current version of the disp+work file.
R3trans -d <SID> : Check whether the R/3 is able to connect to the DB, the log will be generated at OS level in same directory as "trans.log".
R3trans -x <SID> : Check whether the R/3 is able to connect to the DB, the detailed log will be generated at OS level in same directory as "trans.log".
tp connect <SID> : Check whether the tp is able to connect to the DB or not.
SAPCAR -xvf <car/sar_file> : Uncar the SAR/CAR files.
Use the <SID>adm for SAP related activity.
Use the ora<SID> for oracle related activity.

General purpose utilities:
1.what is the command to get the calendar?

Cal
2.what is the command to get the date?

Date
3. Displaying the message which we had given?

Echo

4. what is the command for the calculator?

Bc

5. To record the session?

Script
6. To change the password?

Passwd
7. To get the users?

Who
8. To get the terminal characteristics?

Tty
9. displaying and setting the terminal characteristics?

Sty



File oriented commands:
what is the command to list out the contents?
Ls -l

what is the command to get the hidden files(.,..)?
Ls –a

what is the command to get the files in category wise(flagged)?
Ls –f

4. what is the command to get the directory attributes?

Ls –ld <directory name>

Eg: $ ls –ld rajesh

5 in ls -l what is the first character indicates?

drwxr-xr-x 2 mgurumur staff 1024 May 10 15:07 temp

Type of the file

file
d-directory

c-char file



6. what is the command to create a file?

Cat > file name



7. How to append the content to an existing file?

Cat >> file name



8. what is the end of file indicator?

Ctrl d

9. how to concatenate two files

Cat file1,file2>file 3.



10 . how to remove a file?

Rm <file name>

11. while removing how to get the prompt for the removal{interactive remove}

Rm –I <file1,file2,file3>

what is the command for recursive file delete?
Rm –r.

what is the difference between “ cat <filename>” and “cat > file name”
First command displays the content of the file

Second command creates the file

what is the use of “more” command
to get the contents page wise

15. what is that command to copy a file and link a file.

cp sample1 sample2 - for copying sample1 to sample2

ln sample1 sample2 - for linking sample1 and sample2
16. what is the difference between linking and copying files.

linking - links two or more files. Does not create another copy of the file. changes in one file, gets reflected in all the linked files

copy - creates separate files , changes in one is not reflected in

others.



17. How to find the total number of characters in a file

wc -c <file>
18..what is command substitution.

echo todays date is `date`

19.. How to convert case (upper case, lower case) of a file

cat <file> | tr [a-z] [A-Z]



20. How to search for core files from root and delete them

find / -name "core" -exec rm {} \;

21. what’s the command to rename a file?

Mv

22. to get the type of the file?

File

Eg: file chap01


23. comparing two files?

Cmp

Eg: $cmp file1 file2-----------prints the first mismatch(character and the line)

File1 file2 differ: char 9, line 1
24.to get the common content in two files

comm.

Eg: comm file1 file2 – prints the common content in both the files

25. to get the difference in two files and converting one file to other

diff

eg: diff file1 file2
26. to compress and uncompress the files?

Gzip and gunzip



27. to make an archive?

Tar

28. compressing and archiving together?

Zip and unzip


29.how to change the permissions of a file

chmod

30.how to give the executable permission to the group?

Chmod g+x <file name>


31.what is the meaning of the command chmod 777 {4-read,2 –write, 1-execute}

rwx for user

rwx for group

rwx for others

32.commands to transfer the files remotely

ftp,rcp,scp

33.what is the difference between rcp and scp?

Rcp-remote copy-no profound authentication

Scp-secured copy-copied in a encrypted format, rate of transit is high

34.what is the syntax for Scp?

scp [options] [[user@]host1:]filename1 ... [[user@]host2:]filename2

eg: scp file1.txt dvader@deathstar.com:somedir

35.head Output beginning of f

36 tail Output end of f



37.chmode 777 file name

38.ls –top

39.


Directory oriented commands:


what is the command to create a directory?
Mkdir <dir name>



what is the command to change the directory?
Cd <dir name>



how to move to the parent directory?
cd..



how to get the current directory?
Pwd, echo $home
how to remove the directory?
Rmdir, rm –r
what is the difference between rmdir and rm –r?
inorder to use the rmdir command the directory should be empty.

The rm –r itself deletes the subdirectories.
how to copy the entire directory structure?
Cp -R <dir1><new dir>




Process oriented and filters:


what are the basic filters available?
Grep, sed.

Grep “pattern” <file name>
2. how to count for pattern in a file

grep -c "pattern" <file>


what is sed?
Sed is used as a multipurpose filter.


3.how to increment value of a variable

a=`expr $a + 1`


4. how to check for various processes that are running on a system

ps -ef


5. How will you execute a program so that it runs in the background

progranname &


6. How to bring background process to foreground

fg



Vi editor commands:



STARTING vi

vi filename edit a file named "filename"

vi newfile create a new file named "newfile"

ENTERING TEXT

i insert text left of cursor

a append text right of cursor

MOVING THE CURSOR

h left one space

j down one line

k up one line

l right one space

BASIC EDITING

x delete character

nx delete n characters

X delete character before cursor

dw delete word

ndw delete n words

dd delete line

ndd delete n lines

D delete characters from cursor to end of line

r replace character under cursor

cw replace a word

ncw replace n words

C change text from cursor to end of line

o insert blank line below cursor

(ready for insertion)

O insert blank line above cursor

(ready for insertion)

J join succeeding line to current cursor line

nJ join n succeeding lines to current cursor line

u undo last change

U restore current line

MOVING AROUND IN A FILE

w forward word by word

b backward word by word

$ to end of line

0 (zero) to beginning of line

H to top line of screen

M to middle line of screen

L to last line of screen

G to last line of file

1G to first line of file

<Control>f scroll forward one screen

<Control>b scroll backward one screen

<Control>d scroll down one-half screen

<Control>u scroll up one-half screen

n repeat last search in same direction

N repeat last search in opposite direction

CLOSING AND SAVING A FILE

ZZ save file and then quit

:w save file

:q! discard changes and quit file

Regards,
Mubashir Ali
mubashir
 
Posts: 2

Return to General Basis Forum

Who is online

Users browsing this forum: No registered users and 1 guest

Visit our Google Group Way 2 SAP BASIS
cron