You are on page 1of 12

4) How to copy a file within box?

Unix Commands:–– Ans: cp <file1> <file2>  copy file1 to file 2 within the directory.
cp <file1> /tmp  copy file1 to /tmp directory with same name.
1) top: this command is used to know the cpu utilization in Linux .
cp <file1> ~raj  copy file1 to Home directory of raj.
Ans: 5) How to copy a file from one unix box to another unix box?
Ans: scp <filename1> <username>@<ip address or hostname>:<path where to copy>
Eg: scp sample.txt rajkumar@192.168.32.64:/root/Desktop/raj
Copy file sample.txt to 192.168.32.64 box /root/Desktop/raj directory.
6) How to to copy a file from unix to windows?
Ans : ftp <ip address>
ftp> <username>
ftp> <password>
ftp>cd ../../../..(move to particular directory to copy file)
ftp> put <filename> /dir  put is used to copy a file to unix box a particular directry
ftp> mput <file1> <file2> …<file n> /dirput multiple files to unix box a particular dir.
ftp> get <filename>  get a file from unix box to windows.
ftp> mget <file1> <file2> ..<file n>  get multiple file from unix box to windows
ftp> quit  used to quit from unix box.
7) How to copy a file from winsdows to unix?
Ans : WINSCP
2) How to list top ‘5’ cpu utilization processes? X–Manager
Ans : Reflection –X…. etc.
ps –auxf | sort –nr –k 3 | head –5
ps u | sort –k 1 –r | head –5 8) List all the files and directories in a directory?
Ans : ls  to list all the files and directories in within directory
 how to list last ‘5’ cpu utilization processes?
ps –auxf | sort –nr –k 3 | tail –5
ps u | sort –k 1 –r | tail –5
3) How to replace a string in a file?
Ans: sed –i “s/<old string>/<new String>/g” <filename>
Eg: sed –i “s/unix/linux/g” /root/Desktop/language.txt
0 1
9) List all the hidden files in a directory?
Ans : ls –a.
11) How to list all the running java processes?
Ans : ps –ef | grep java
12) How to list all the listening ports ?
Ans : netstat –a
13) How to know the port number based on process id<PID>?
Ans : netstat –antp | grep <pid>
14) How to know the processed id <PID> based on port number?
Ans: netstat –antp | grep <port>
10) How to list all the files in ling list format? Know the service running in a port – Linux
Ans : ls –ltr
It gives the files and directories list with permissions, In our previous article we explained the steps for windows. Here you can find the steps to
first character ‘–‘ indicates files, ‘d’ indicates directory. identify the service running in a port on linux . Here we used commands “fuser” and “PS”. I am
using apache2 web server on port 80. Replace your port number with 80 (my example with port
80 )
Run following command to find the Process ID from port number
root@server:~ # fuser -n tcp 80
2 3
Now you can see the Process IDs associated with this service 5 =1+4 means executable and read
80/tcp: 2584 15941 15943 15944 15945 16332 16333 16880 16881 16882 16899 6 = 4+2 means read and write
Run the following command to find the service name from process ID 7 = 1+2+3 means read write and executable
root@server:~ # ps -ef | grep 2584 We can give maximum value as 7. (1–7).
root 2584 1 0 Apr01 ? 00:00:08 /usr/sbin/apache2 -k start
Eg: What indicates chmod 723 f1.txt?
 User can have the permissions to read, write and execute the file f1.txt.
Group users only have the permission to write the file f1.txt.
Others can have the permissions to read and write the file f1.txt.
16) What is the use of sticky bit?
Ans : The owner or Super User only can delete and rename the file, If you enable a sticky bit on
a file, group users and Others only can read, write and execute that file but can’t delete
15) How to change the file permissions?
Ans: chmod 777 <filename> Ex : chmod +t <file name>  To enable the sticky bit.
chmod –t <file name>  To disable the sticky bit.
17) Command to go to previous directory?
Ans : cd –
18) Command to go to root User directory?
Ans : cd ~
pwd <enter>
o/p: /home/<user name>
19) Command to check ip address?
20 = 1 indicates  executable (x) Ans : ifconfig  to find the ipaddress.
21 = 2 indicates  write(w) 20) Command to check free disk space?
22 = 4 indicates  read(r) Ans : df –m /<dir name>  to find the free disk space,(-m for MB ,-k for KB).
3 =1+2 means write and executable 21) Command to find free memory?
4 5
Ans: free –m  to find the free memory,(-m for MB ,-k for KB). 32) What is the difference between ‘diff’ and ‘cmp’ commands?
22) How to change ownership of a file? Ans : cmp  it compares two files and gives the output like “Line no. and Byte” which
indicates the first difference.
Ans: chown <user name> <file name>
Syn: cmp
23) How to find how many users are logged in that unix box?
diff  it compares two files or directories and gives the output which words
Ans : users (or) who are different when comparing the files, which files are different when comparing the
24) How to find with which user name is logged in? directories.
33) What is the difference between tail and head commands?
Ans : whoami , who am i .
Ans : head  list the top files.
25) How to find the given OS is 32 bit or 64 bit?
Eg: - head -5 <filename>
Ans : arch (or) uname –m
tail  list the last files.
26) How to find the given os version?
Eg: - tail -5 <filename>
Ans : more /etc/*release
34) How to add a new user?
Ans : useradd <user name>
27) I want to execute a script, everyday at 5:00pm. Write a crontab syntax to achieve that?
35) How to change the password?
Ans : <min> <Hours> <day of the month> <month> <day of the week> <path of script>
Ans : passwd <new password>
* 17 * * * <path of script>
36) How to check the connectivity between two unix boxes?
28) How to list the crontabs?
Ans : ping <ip address>
Ans : crontab – l
Eg: ping 192.168.64.128
29) What is the difference between kill –3, kill –9 and kill –15?
37) What is the difference between find and grep command?
Ans: kill –3 <PID>  to generate the “Thread dumps”
Ans : find  to search the word recursively in a particular file.
kill –9 <PID>  to kill the process forcibly
Syn: find /<dir-name> -name “<filename>”
kill –15 <PID>  it will wait to kill the process until the child processes are killed.
Eg: find /root/Desktop -name “abc.txt”
30) What is the command to make a tar file?
i) find . –name “<filename>”  search goes in current directory.
Ans : tar –cvf <filename>.tar <path of the desired folder> ii) find / -name “<filename>”  search goes all the directories in file system.
iii) find ~/ -name “<filename>”  search goes the root directory.
31) Command to extract a tar file?
Ans : tar –xvf <filename>.tar /<directory to extract> grep  to search the word in a particular file. But it is not recursive.
6 7
Syn: grep “<string>” <filename>. atime – File Access Time
Access time shows the last time the data from a file was accessed – read by one of the Unix
Eg:- grep “rajkumar” /root/Desktop/abc.txt
processes directly or through commands and scripts.
38) How to list running java processes?
ctime – File Change Time
Ans : ps –ef | grep java
ctime also changes when you change file's ownership or access permissions. It will also naturally
39) How to check Webserver is running or not? highlight the last time file had its contents updated.
Ans : ps aux | grep httpd (or) ps auxf | grep httpd mtime – File Modify Time
40) How to run a process in the back ground? Last modification time shows time of the last change to file's contents. It does not change with
owner or permission changes, and is therefore used for tracking the actual changes to data of
Ans : Put “& “ at the end of the command. the file itself.
Syn : - <complete command> & 46) Command to find recent modified files?
41) How to bring the process to fore ground? Ans : ls –lrt
Ans : fg <pid> 47) What is the use of umask and what is the default umask value?
42) What is the default telnet and ssh port numbers? Ans : The umask specifies the permissions you do not want given by default to newly created files
and directories.
Ans : 22  for ssh and 23  for telnet.
To reset the values. Default umask value is 022.
43) How to find and replace a string in a file?
i) How to set umask ?
Ans : sed – i “s/<old string>/<new string>/g” <file name>
Ans : umask 022
44) How to rename a file?
48) How to mount a file system?
Ans : mv <old file name> <new file name>
Ans : mount <file system name> <where to mount>
Eg : mv /root/Desktop/abc.txt /root/Desktop/rajkumar.txt
Eg: mount /dev/cdrom /mnt/cdrom
45) Command to find files which are older than 15 days?
Mount: A file system can be "mounted" on your Linux system interactively or automatically at
Ans : find <directory path> –atime +15 (–mtime also will work as same)
startup. Then the file system is just as accessible as any other file system on your computer.
The command to "attach" a file or directory ismount, and the command to "detach" a
[syn : find {directory to search in} –atime {+,–, } {number of days}
mounted file or directory is umount (see UNIX man (manual) pages for the commands mount
and umount for more information). Users should detach from the file system when the
(+) means greater than, (–) means less than and without anything means exactly equal to.]
resource is no longer needed.
Note :
49) Command to find top 8 processes which consumes high cpu utilization?
[Three times tracked for each file in Unix are these:
• access time – atime Ans : ps auxf | sort –nr –k 3| head –8
• change time – ctime
• modify time – mtime 50) Command to find top 8 files which consumes high disk usage?
8 9
Ans : du –sm *|sort –nr | head –8 58) Command to display number of lines in a file?
Here ‘s’ summarizes all the reports, ‘m’ indicates size in MB. Ans: - wc -l <filemname>  it gives no of lines in a file.
51) What is the command to find the files size more than 100 MB? wc -m <filename>  it gives no of characters in a file.
Ans : find . –size +100M wc -w <filename>  it gives no of words in a file.
find /<dirname> –size +100M wc <file name>  it gives no of lines ,no of words, no of bytes in given file.
Note : ‘.’ Indicates current directory. 59) Command to list number of files in a directory?
Eg : find . –size +100M Ans: - ls -1 /root/Desktop/RPM | wc -l
52) What is the use of lsof command? 60) How to set java path in Linux/Unix?
Ans : lsof stands for list the open files, which will list all the open files in the system. The open
Ans : - Setting java path(In Temporary way)
files include network connection, devices and directories.
Syn : lsof | more JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk
export $JAVA_HOME
53) more  it is used to display or read a file page by page. For next page press enter.
Syn : more <file name> Setting java path (In Permanent way)
Edit ~/ .bashrc and place below two lines in that file and save the file.
54) What is the difference between softlink and hardlink? Vi ~/.bashrc
JAVA_HOME = /usr/lib/jvm/jre-1.6.0 -openjdk
Ans : Softlink  It create a separate inode for linked file. We should not delete
export $JAVA_HOME
the original file to access the softlink.
hardlink  It doesn’t have a separate inode. Hard link file will be deleted Note :- Please note that the file ~/.bashrc is similar, with the exception that ~/.bash_profile
when we delete the original file. runs only for Bash login shells and .bashrc runs for every new Bash shell.
55) Command to list the processes which are currently running?
Ans : netstat –antp
56) What are different run levels in Linux?
Ans :- Run Level 0: Halt System (To shutdown the system)
Run Level 1: Single user mode
VI-EDITOR Commands:
Run Level 2: Basic multi user mode without NFS
Run Level 3: Full multi user mode (text based) j  move cursor to one line down
Run Level 4: unused
Run Level 5: Multi user mode with Graphical User Interface
k move cursor to one line up
Run Level 6: Reboot System h move cursor left to one character
l  move cursor right to one character
57) Command to fine HOSTNAME of system? 0(zero)  move the cursor to staring of current line
Ans: hostname $  move cursor to end of end of current line
10 11
w  move cursor to beginning of next word
b  move cursor to beginning of previous word
u  undo
G  move cursor to end of the File
1G  move cursor the starting of the file In the above output example, the 11567230 is the size of the file. For a more user friendly
3G  move cursor to the 3rd line of the file. (nG  for nth line). output, use the du command as shown below.
dd  delete entire line from current cursor position, without blank line. du -h log.txt
cc  deletes entire line from current cursor position with auto edit of blank line.
This command would display the output "12M log.txt"
D  Deletes the right side portion of the cursor position.
o (small oh)  to insert a blank line below the cursor (current line).
O(capital oh)  to insert a blank line above the cursor (current line).
i  to edit.
:q  after saving only it will quit otherwise it won’t quit from editor.
:q!c  quit without save.
WebSphere
WEBSPHERE ADMINISTRATION AND MUCH MORE
:wq  save and quit. Showing posts with label UNIX. Show all posts
61) Ho to set line numbers in vi editor? 5/26/10
Ans : press esc  :set nu press enter.
uptime
uptime is a measure of the time a machine has up been.
62) How to delete blank lines in a file?
Ans : - vi <filename> This is pretty useful command.
Press esc  : g/^$/d  press enter To know since when the system is up one can do like this at the terminal prompt
$uptime
63) How to delete 50 lines from a file? 11:10:27 up 9 mins, 2 users, Load average: 0.02, 0.24, 0.18
Ans : vi <filename>
DETERMINING SYSTEM UPTIME IN WINDOWS -
Press esc  50D
Deletes 50 lines from current cursor position. 1.
C:\> systeminfo | find "Time:"
64) How to delete 50th Line form a file?
System Up Time: 0 Days, 8 Hours, 7 Minutes, 19 Seconds
Ans: sed '50d' <fileName.txt>
65) How to find the size of the file or folder? Note: Windows Vista Business 64-bit and Windows 7 do not return a "System Up Time" but "System
Ans: ls -l log.txt Boot Time" instead.
Performing the above command would list output similar to the below information.
-rw-r----- 1 comphope www 49746 Nov 24 01:12 log.txt
2.
12 13
C:\> net statistics server | find "since" Java(TM) 2 Runtime Environment, Standard Edition (IBM build 1.5.0_06-erdist-20060404 20060511)
Server Statistics for \\COMPUTERNAME Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_06-erdist-20060404, mixed mode)
IBM Java ORB build orb50-20060511a (SR2)
Statistics since 8/31/2009 8:52:29 PM XML build XSLT4J Java 2.7.4
XML build IBM JAXP 1.3.5
remove directory
XML build XML4J 4.4.5
If you need to remove a directory, or files and or folders under a directory, in say, Solaris you do like this,
say to remove cache under wstemp
This is a machine which has WAS 32bit
rm -r wstemp/*
$ ./java -d64 -version
which removes files folders under wstemp recursively.
execv(): No such file or directory
rm test.txt
Error trying to exec /software/opt/IBM/WebSphere/AppServer/java/jre/bin/sparcv9/java.
deletes test.txt file
Check if file exists and permissions are set correctly.
rm -i wstemp/*
Failed to start a 64-bit JVM process from a 32-bit JVM.
inquires and prompts yes or no for each file
Verify all necessary J2SE components have been installed.
In Linux
(Solaris SPARC 64-bit components must be installed after 32-bit components.)
rm -f - force removes a file
rm -fr - force removes directory
So acid Test is -
goto App Server javahome
In DOS -
/path/to/washome/java/jre/bin
rmdir is the command to remove a directory.
./java -d64 -version
rmdir dSample
removes if dSample dir is empty.
if it is 64 bit, it returns with version info.
To force remove
otherwise returns with no such file or directory.
rmdir /S dSample
removes dSample directory but inquires Also we can check for the setup cd or inside the setup fule
rmdir /S /Q dSample
removes dSample directory and its sub directories quietly.
64 bit or 32 bit JVM?
POSTED BY AT 8/20/2009 09:26:00 PM 1 COMMENTS
How to know your WAS version is 32 bit or 64 bit? LABELS: JAVA, SOLARIS, UNIX, WAS
This is a machine which has WAS 64 bit While using df
$ ./java -d64 -version Solaris
java version "1.5.0_06" df -h is the command to display available disk free space in bytes
14 15
e.g., used. Under certain exceptional conditions, such as when a file system is being modified while
$df -h the df command is running, the statistics displayed by the df command might not be accurate.
Filesystem size used avail capacity Mounted on
Note:
/dev/md/dsk/d84 3.9G 136M 3.8G 4% /var
Some remote file systems, such as the Network File System (NFS), do not provide all the information that
swap 6.6G 992K 6.6G 1% /tmp
the df command needs. The df command prints blanks for statistics that the server does not provide.
/dev/md/dsk/d101 20G 7.8G 12G 41% /software
The df command does not fully support NFSv4 filesystems. Use the nfs4cl command to extract block and
Equivalent df in AIX
space information.
df -g
AIX df command Flags
Displays statistics in units of GB blocks. The output values for the file system statistics
DF COMMAND -g
would be in floating point numbers as value of each unit in bytes is significantly high.
Purpose -i
Displays the number of used inodes and the percentage of inodes in use for the file
system. This output is the default when the specified file system is mounted.
Reports information about space on file systems. This document describes the AIX dfcommand as well as Displays information on the total number of blocks, the used space, the free space, the
-I
percentage of used space, and the mount point for the file system.
the System V version of df.
-k Displays statistics in units of 1024-byte blocks.
Displays statistics in units of MB blocks. The output values for the file system
Syntax
-m statistics would be in floating point numbers as value of each unit in bytes is
significantly high.
df [ [ -P ] | [ -I | -M | -i | -t | -v ] ] [ -k ] [ -m ] [ -g ] [ -s ] [FileSystem ... | File... ] -M Displays the mount point information for the file system in the second column.
Displays information on the file system in POSIX portable format.
Description
When the -P flag is specified, the header line appears similar to:
The df command displays information about total space and available space on a file system.
Filesystem 512-blocks Used Available Capacity Mounted on\n
The FileSystem parameter specifies the name of the device on which the file system resides, the directory
on which the file system is mounted, or the relative path name of a file system. The File parameter -P If the -k, -m or -g flag is specified in addition to the -P flag, the column heading 512-
specifies a file or a directory that is not a mount point. If the Fileparameter is specified, the df command
blocks is replaced by the respective units, depending on which of these flags is used
with the -P flag.
displays information for the file system on which the file or directory resides. If you do not specify
the FileSystem or File parameter, the dfcommand displays information for all currently mounted file File system statistics are displayed on one line in the following order:
systems. File system statistics are displayed in units of 512-byte blocks by default.
FileSystem, TotalSpace, UsedSpace, FreeSpace, UsedPercentage, MountPoint
Displays statistics on unmounted JFS or Enhanced JFS file systems by the command
The df command gets file system space statistics from the statfs system call. However, specifying the - line arguments. If there are no arguments specified, the -s flag has no effect. If the file
s flag gets the statistics from the virtual file system (VFS) specific file system helper. If you do not specify systems specified by the argument are currently mounted or an argument is a file, the -
-s
s flag has no effect for that particular argument. To collect statistics on unmounted file
arguments with the -s flag and the helper fails to get the statistics, the statfs system call statistics are
systems, an argument must be a JFS or Enhanced JFS file system mount point or
device, the file system must be listed in/etc/filesystems, and the user must have read
16 17
access to the device. df -m /test
-t Includes figures for total allocated space in the output.
Filesystem MB blocks Free %Used Iused %Iused Mounted on
-v Displays all information for the specified file system.
/dev/lv11 16.00 15.46 4% 18 1% /tmp/ravi1
The values of the output parameters with the flags -m and -g would be rounded off to nearest second
This displays file system statistics in MB disk blocks rounded off to nearest 2nd decimal digit.
decimal digit. If all or any two of the -k, -m and -g flags are specified, the last one specified takes effect.
4. To display information about the /test file system in GB blocks, enter:
Exit Status
df -g /test
This command returns the following exit values:
Filesystem GB blocks Free %Used Iused %Iused Mounted on
0 Successful completion. /dev/lv11 0.02 0.02 0% 18 1% /tmp/ravi1
>0 An error occurred.
This displays file system statistics in GB disk blocks rounded off to nearest 2nd decimal digit.
Examples
5. To display available space on the file system in which your current directory resides, enter:
1. To display information about all mounted file systems, enter:
cd/
df
df .
If your system has the /, /usr, /site, and /usr/venus file systems mounted, the output from
The output from this command resembles the following:
the df command resembles the following:
Device 512-blocks free %used iused %iused Mounted on
Filesystem 512-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 19368 9976 48% 4714 5% /
/dev/hd0 19368 9976 48% 4714 5% /
Files
/dev/hd1 24212 4808 80% 5031 19% /usr
/dev/hd2 9744 9352 4% 1900 4% /site /etc/filesystems Lists the known file systems and defines their characteristics.
/dev/hd3 3868 3856 0% 986 0% /usr/venus /etc/vfs Contains descriptions of virtual file system types.
Solaris df, du, ls commands
2. To display information about /test file system in 1024-byte blocks, enter: Solaris df command
df -k /test
New df, du, and ls Options
Filesystem 1024 blocks Free %Used Iused %Iused Mounted on
/dev/lv11 16384 15824 4% 18 1% /tmp/ravi1
The df, du, and ls commands have a new h option for displaying disk usage and file or file system sizes
that are easy to understand.
This displays the file system statistics in 1024-byte disk blocks.
3. To display information about /test file system in MB blocks, enter: The default form of the df command displays file system size in blocks (512 bytes). The df output, in
18 19
kilobytes, follows: The default form of the ls -l command displays file size in bytes. Use the ls -lh command to display file size
in powers of 1024:
$ df -k / /usr
Filesystem kbytes used avail capacity Mounted on % ls -lh k
/dev/dsk/c0t0d0s0 192056 94788 78063 55% / -r-xr-xr-x 1 root bin 49K Nov 30 03:32 kadmin
/dev/dsk/c0t0d0s6 1982988 829966 1093533 44% /usr -r-xr-xr-x 1 root bin 49K Nov 30 03:32 kadmin.local
-r-xr-xr-x 1 root bin 49K Nov 30 03:32 kdb5_util
The same file system sizes displayed in powers of 1024 follows: -r-xr-xr-x 1 root sys 44K Nov 25 04:37 keyserv
-r-xr-xr-x 1 root bin 4.3K Nov 25 04:36 killall
$ df -h / /usr
AIX Command Tips
Filesystem size used avail capacity Mounted on
Displaying top CPU_consuming processes:
/dev/dsk/c0t0d0s0 188M 93M 76M 55% /
#ps aux | head -1; ps aux | sort -rn +2 | head -10
/dev/dsk/c0t0d0s6 1.9G 811M 1.0G 44% /usr
Displaying top 10 memory-consuming processes:
#ps aux | head -1; ps aux | sort -rn +3 | head
The default form of the du command displays disk space in blocks (512 bytes). The du output, in blocks,
Displaying process in order of being penalized:
follows:
#ps -eakl | head -1; ps -eakl | sort -rn +5
Displaying process in order of priority:
% du -s k*
#ps -eakl | sort -n +6 | head
100 kadmin
Displaying process in order of nice value
98 kadmin.local
#ps -eakl | sort -n +7
98 kdb5_util
Displaying the process in order of time
90 keyserv
#ps vx | head -1;ps vx | grep -v PID | sort -rn +3 | head -10
10 killall
Displaying the process in order of real memory use
#ps vx | head -1; ps vx | grep -v PID | sort -rn +6 | head -10
The same disk space displayed in powers of 1024 follows:
Displaying the process in order of I/O
#ps vx | head -1; ps vx | grep -v PID | sort -rn +4 | head -10
% du -h k*
Displaying WLM classes
50K kadmin
#ps -a -o pid, user, class, pcpu, pmem, args
49K kadmin.local
Determinimg process ID of wait processes:
49K kdb5_util
#ps vg | head -1; ps vg | grep -w wait
45K keyserv
Wait process bound to CPU
5K killall
#ps -mo THREAD -p
Cpu usage with priority levels
20 21
#topas -P
#svmon -Put 10 will give the memory mapping for the
top ten memory consuming processes.
#top
Remember, some commands needs you to be root. So, you switch to su to root.
Two important things here -
1. from ur profile, if u say
$su root
takes you to root with current shell. Means that, though u r root, u still carry ur .profile and ur env
variables.
2. if u want to have root's env variables -
su - root or
su root
after getting into root
. ./.profile
22

You might also like