UNIX Basic FAQ's


How to see Linux version or type?
1.cat /etc/issue
Welcome to SUSE Linux Enterprise Server 11 (x86_64) - Kernel \r (\l).
2./etc/redhat-release
3.cat /etc/*release
How to see linux/unix versions in all Unix ?
1.For Redhat Linux boxes,
    # cat /etc/redhat-release
2.For SuSe Linux boxes,
    # cat /etc/SuSe-release
3.For Solaris boxes,
    # cat /etc/release
4.For AIX boxes,
    # oslevel –g
    # oslevel –r
ISA of an UNIX machine?(How to see OS bit level ?)

1)// Solaris ---- isainfo -v

2) // for hpux and linux ----- getconf WORD_BIT

3) // for AIX ----- getconf –a | grep KERNEL_BITS (or) getconf KERNEL_BITMODE

4) bootinfo -K

5)//HP-UX - ----- getconf KERNEL_BITS

32 bit or 64 bit??(How do we know the BIT level of Processor - Hardware?)

AIX ------- bootinfo -K getconf LONG_BIT (or) getconf HARDWARE_BITMODE

SOLARIS ------ isainfo -b

HPUX ------- getconf KERNEL_BITS

LINUX --------- getconf LONG_BIT

How to see RAM usage?

Solaris :  To see RAM : /usr/sbin/prtconf
                To see free ram : vmstat
Linux :     free -m  [ or ] top  [or] # cat /proc/meminfo
memory size in MB(memory is RAM size)
And Swap is SWAP size
HP-Ux : /usr/contrib/bin/machinfo.
To see HD space in HP UX 
For disk info, use ioscan -fnkC disk command then diskinfo command will give you info about each disk.
How to work with back space and options in HP-UX ?
Option 1: Use bash_hp binary
Option 2: stty -a
intr='^c'
stty intr '^c'
Option 3 :
Run the following in command line
exec stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z"
How to see processor related details ?
Solaris  
/usr/platform/`uname -i`/sbin/prtdiag
How to increase tmp space in AIX ? 
chfs -a size=+1 /tmp

How to add new user ?
Solaris9
bash-3.00# useradd -d /export/home/kbabu -s /bin/ksh -m kbabu
64 blocks
bash-3.00# passwd kbabu
New Password:
Re-enter new Password:
passwd: password successfully changed for kbabu

How to find a word in all files in a directory ? (using grep)
1. grep root /etc/passwd  - Searches word root in passwd file and prints the line on console.
2. grep -r root /etc/ - Searches word root in all the files under /etc
3. grep -r -i root /etc/ -  Searches word root by ignoring case in all the files under /etc
4. awk '/gold/' coins.txt
5. find . -mount -type f -print0 | xargs -0 grep "something"- When there is any problem is searching words under file systems like /dev* this will help.
Reference : [1]
How to set line number in vi editor ? 
Press ESC and : set number

How to see the process and their child processes in a tree structure ? 
Linux :
 ps --forest -eaf
  and
 pstree -p
Solaris :
  ptree PID

How to delete a user in Solaris 9 ?
The userdel(1M) command is used to delete a user account. The user account is specified as a command-line argument. Only one other command-line argument is supported. This is -r, which is used to remove the home directory. The following shows deleting the user3 account:
# userdel -r user3

AIX

mkuser "pgrp=mysql" "groups=mysql" "shell=/usr/bin/ksh" "home=/opt/mysql" mysql
home dir == /opt/mysql

How to modify or create a user?
user kbabu
usermod

Command to show type of UNIX flavor?
uname –a

How to see the logged in user?
1>>$LOGNAME
2>>id

How to see running processes?
1>> top
2>> monitor
3>> prstat

How to see Virtual memory usage?
vmstat

Where is xclock installed on Soalris ?
/usr/X/bin/xclock

How to enable FTP on Solaris 10?
inetadm -e ftp
svcadm enable ftp

How to use Back space in AIX?
Shift + Backspace


Find and replace all in file in VI editor ?
 
 ESC : %s/first/second/g


How to send broad cast message to all current users of the machine?

wall hi

How to start FTP on LINUX?
Edit the file /etc/xinetd.d/wu-ftpd
changing the two lines to:
default: on
disabled = no
then run the command
etc/rc.d/init.d/xinetd restart
on RH linux AS4
# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd: [ OK ]
how to give ftp for root
Configure FTP for root logins
Edit the files /etc/vsftpd.ftpusers and /etc/vsftpd.user_list and remove the 'root' line from each file.

How to enable telnet?
Edit the file /etc/xinetd.d/telnetd

changing the two lines to:

# default: on

disabled = no

then try doing this

/etc/rc.d/init.d/xinetd restart

cat /etc/passwd

vi /etc/vsftpd/ftpusers

vi /etc/vsftpd/user_list

vi /etc/vsftpd/vsftpd.conf

service vsftpd reload


How to set current working directory at your prompt?

PS1='\w $'

How to see patch level of the OS (solaris) ?

showrev -a

showrev -a | tee /opt/kbabu/a.txt


How to use SCP? (Secure Copy)

scp user@hsot1 a.txt user@host2:/osdb/jkdj/


How to made HP-UX easy?

exec stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z"


How to empty or clear the contents of an existing UNIX file ?
The special file /dev/null can and does contain nothing. While most often used as a sink of nothingness, for example writing output to it that you don’t want to keep, it can be used as a source of nothingness, too. To replace the contents of the file XYZ.txt with nothing, you can use the command
cat /dev/null > XYZ.txt
This command makes sense as it is using standard UNIX redirection to place the contents of one file (a known empty one) to another file. Another way to do this, although a less obvious way and probably less readable in a shell script by others, is
> XYZ.txt
How to see common entries in two files?

sort file1 file2 | uniq –d

How to set time in Unix ?
  • date -s "2 OCT 2006 18:00:00"
  • date set="2 OCT 2006 18:00:00"
  •  date +%T -s "10:13:13"
 Use %p locale’s equivalent of either AM or PM, enter:
  • # date +%T%p -s "6:10:30AM"
  • # date +%T%p -s "12:10:30PM"
To sync the clock with hardware
  • # hwclock –show
  • # hwclock –systohc
How to install a package in Linux using RPM ? How do u uninstall ? how do u see the installed packages ?
Install:
rpm –ivh
Upgrade :
rpm -Uvh IBMJava2-142-ia32-SDK-1.4.2-12.0.i386.rpm
View :
nc041030:/opt/tivoli/ep/_uninst # rpm -qa | grep TIV
TIVguid-1.3.0-0
Remove :
rpm -evv TIVguid-1.3.0-0

How to install GCC on Linux ?
   1. wget ftp://mirrors.kernel.org/gnu/gcc/gcc-3.4.6/gcc-3.4.6.tar.bz2
Some how download the gcc-3.4.6.tar.bz2 or latest gcc for ur linux and place it in ur working directory.
   2. tar -jxf gcc-3.4.6.tar.bz2
   3. cd gcc-3.4.6
   4. ./configure
   5. make
   6. make install

How to mount files in Solaris 10?

mount -F nfs -o vers=3 172.22.21.2:/StarTeam /StarTeam

-----------

Mount –F/t nfs 172.22.21.2:/StarTeam /StarTeam

Sol: vi /etc/vfstab

172.22.21.2:/StarTeam - /StarTeam nfs - yes rw,hard

Li: vi /etc/fstab

172.22.21.2:/StarTeam - /StarTeam nfs - yes rw,hard




How to see IP from a host name or Host name from IP?

/usr/sbin/nslookup mercury

Server: 9.20.136.11

Address: 9.20.136.11#53




Name: mercury.hursley.ibm.com

Address: 9.180.210.217

Installing top?
pkgadd -d top-3.6.1-sol10-sparc-local

How to create NFS Sharing?
To be able to share a remote filesystem you have to share the remote filesystem.

To share the remote filesystem you need to modify
the /etc/dfs/dfstab file with
share -F nfs -o rw /filesystem
also modify the /etc/dfs/sharetab with
/filesystem nfs rw
then issue
shareall
make sure nfs daemon are running of the server
you could check by isseing
ps -ef | grep nfs
if it is not running you could start nfsd by issuing /etc/init.d/nfs.server start
on the client side, that is the side with no disk space
you need to mount the remote filesystem you could do this by issuing
mount (remote server):/usr/local /mount_point
Note:
/filesystem will be the filesytem you intend to share eg / /usr/local, /var, /export/home
so if you intend to share /usr/local your /etc/dfs/dfstab will look like
share -F nfs -o rw /usr/local
and /etc/dfs/sharetab will look like
/usr/local - nfs rw

How to add route between machines ?
To discover the Southbank Test Network you may need to add suitable routes:
A discovery from Hursley requires a route to 172.20.0.0/16 and 172.21.0.0/16 via 9.180.210.193
Note on Routing table on devtest22
A discovery from Southbank requires a route to 172.20.0.0/16 and 172.21.0.0/16 via 9.196.131.10
IP Route command examples would be:
Linux:
ip route add 172.20.0.0/16 via 9.196.131.10
Solaris:
route add 172.20.0.0/16 9.196.131.10
Windows:
route add 172.20.0.0 mask 255.255.0.0 9.196.131.10
netstat -r
route add 10.100.20.1/24 172.22.23.43
add all the agetns of range 1-24 to the gateway with the server 43
route add 10.100.20.1 172.22.23.43

How to zip a folder in UNIX using tar ?
tar -cvf netcool.tar netcool/
gzip netcool.tar
or
tar -cvzf filename.tar.gz folder-name

How to run gunzip and tar at a time ?
gunzip -c C1H53EN.tar.gz | tar xf -
tar -xvfz file.tar.gz

How to get PID of a used port ?
AIX : for i in `ps -e|awk '{print $1}'`;do echo "UR PID :$i" ;procfiles $i |grep 1521;done
Solaris :
for i in `ps -e|awk '{print $1}'`;do echo "UR PID :$i" ;pfiles $i |grep ;done
ex :
for i in `ps -e|awk '{print $1}'`;do echo "UR PID :$i" ;pfiles $i |grep 1521;done

Solaris 2.9 AIX 5.2
pflags [-r] [pid | core] procflags [-r] [pid]
pcred [pid | core] proccred [pid]
pmap [-rxIF] [pid | core] procmap [-F] [pid]
pldd [-F] [pid | core] procldd [-F] [pid]
pstack [-F] [pid | core] procstack [-F] [pid]
pfiles [-F] [pid] procfiles [-nF] [pid]
ptime command [argument] Not available

How to see the folder occupied space on the disk ?
du -sh /opt/kbabu

How to know the last rebooted time of a solaris server ?
bash-2.05$ uptime
7:18am up 47 day(s), 23:50, 4 users, load average: 0.36, 0.56, 0.35

What is UMASK ?
UMASK is a Unix environment variable which automatically sets file permissions on newly created files.
The UMASK variable can be confusing to use, because it does work as a mask. In other words, you set the permissions that you do not want in the UMASK.
To calculate permissions which will result from specific UMASK values, subtract the UMASK from 666 for files and from 777 for directories.
If you want all files created with permissions of 666, set your UMASK to 000. Alternatively, if you want all files created with permissions of 000, set your UMASK to 666.
A reasonable value for UMASK is 022, which will cause files to be created with permissions of 644 (rw-r--r--) and directories to be created with permissions of 755 (rwxr-xr-x).
A more secure value for UMASK is 066, which will cause files to be created with permissions of 600 (rw-------) and directories to be created with permissions of 700 (rwx------).
UMASK is nomally defined in the .profile or .login user startup files.
usage :
bash-2.05$ umask
022
bash-2.05$ umask 077

How to extract cpio file in UNIX ?
cpio -idmv <>

IPV6
How to check the whether IPV6 is configured on Linux machine or not ?

[ -f /proc/net/if_inet6 ] && echo 'IPv6 ready system!' || echo 'No IPv6'

simply if we see "/sbin/ipconfig -a" output we will see some thing related IPV6 which itself confirms the IPV6 configuration

How to put process running on foreground to background and viceversa?

You have a process running on Unix terminal as follows ..
bash$./launchpad
to put it in back ground
hold ctrl+ z
It will be stopped and kept in stopped jobs
If u see jobs u can see that in stopped jobs list say
to bring it back to foreground
command : fg %1
assuming in the jobs list our job no is 1.


Find command usage?
find / -name Chapter1 -type f -print
This command searches through the root filesystem ("/") for the file named "Chapter1". If it finds the file, it prints the location to the screen.

find /usr -name Chapter1 -type f -print

This command searches through the "/usr" directory for the file named "Chapter1".

find /usr -name "Chapter*" -type f -print

This command searches through the "/usr" directory for all files that begin with the letters "Chapter". The filename can end with any other combination of characters.

This will match filenames such as "Chapter", "Chapter1", "Chapter1.bad", "Chapter_in_life".

find /usr/local -name "*.html" -type f -print

This command searches through the "/usr/local" directory for files that end with the extension ".html". These file locations are then printed to the screen.

find /usr/local -name "*.html" -type f
-exec chmod 644 {} \;

This command searches through the "/usr/local" directory for files that end with the extension ".html". When these files are found, their permission is changed to mode 644 (rw-r--r--).

find htdocs cgi-bin -name "*.cgi" -type f
-exec chmod 755 {} \;

This command searches through the "htdocs" and "cgi-bin" directories for files that end with the extension ".cgi". When these files are found, their permission is changed to mode 755 (rwxr-xr-x). This example shows that the find command can easily search through multiple sub-directories (htdocs, cgi-bin) at one time.

How to find the free disk space in Solaris ?
bash-3.00$ df -k
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 32768 4824 86% 2328 64% /
/dev/hd2 1998848 63540 97% 44252 69% /usr
/dev/hd9var 360448 335100 8% 524 1% /var
/dev/hd3 1048576 1040968 1% 127 1% /tmp
/proc - - - - - /proc
/dev/hd10opt 131072 45456 66% 3163 23% /opt
/dev/fslv00 156237824 156213640 1% 4 1% /space
netapp:/vol/home/kbabu 503316480 143701960 72% 3464308 17% /home/kbabu
bash-3.00$ pwd
/space
bash-3.00$ df -k .
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/fslv00 156237824 156213640 1% 4 1% /space

Where is make command installed in Solaris 10 ?
Generally it will be in
1.export PATH=$PATH:/usr/bin:/usr/local/bin
2./usr/ccs/bin
3./usr/sfw/bin
How to reboot a AIX machine ?

shutdown -r

Download a file from a FTP server using WGET command ?

 wget https://cbrtp.tivlab.raleigh.ibm.com/brf/FB/agentsvc_1421/intel/BLD/WIN/build.out/com.ibm.tivoli.cas.agent.ismp/dist/NSaAUZPS-eQsL28dZcVTv/common_agent_1.4.2.1_201110051713_linux.tar --http-user xyz@in.ibm.com --http-passwd abc1234567
--05:28:06--  https://cbrtp.tivlab.raleigh.ibm.com/brf/FB/agentsvc_1421/intel/BLD/WIN/build.out/com.ibm.tivoli.cas.agent.ismp/dist/NSaAUZPS-eQsL28dZcVTv/common_agent_1.4.2.1_201110051713_linux.tar
           => `common_agent_1.4.2.1_201110051713_linux.tar'
Resolving cbrtp.tivlab.raleigh.ibm.com... 9.42.60.91
Connecting to cbrtp.tivlab.raleigh.ibm.com[9.42.60.91]:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 136,273,920 [application/x-tar]


5 comments to "UNIX Basic FAQ's"

  • It's really useful ..thanks for sharing

  • what is sticky bit?

  • Using Wget with no certificate options :
    wget https://rtpgsa.abc.com/projects/Media/Linux/IBM-was-8.5.0-Base-Trial-linux64.zip --http-user XYZ --http-passwd ZYX --no-check-certificate

  • How to clear bash commands history in command line ?
    run the below command
    history -c

  • I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in IBM Netcool Operations Insight 1.3, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on IBM Netcool Operations Insight 1.3. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    MaxMunus
    E-mail: nitesh@maxmunus.com
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023
    http://www.maxmunus.com/




Post a Comment

Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")

Popular Posts

Enter your email address:

Buffs ...

Tags


Powered by WidgetsForFree

Archives