Determine whether the Linux system is 32-bit or 64-bit by using Shell scripts

Source: Internet
Author: User

Determine whether the Linux system is 32-bit or 64-bit by using Shell scripts

Output 32 or 64 rows.

You can use "getconf WORD_BIT" and "getconf LONG_BIT" to obtain the number of digits of word and long. In a 64-bit system, 32 and 64 are obtained respectively.

The reference code is as follows:

View source? 1 ldconfig 2 if [ $(getconf WORD_BIT) = '32' ] && [ $(getconf LONG_BIT) = '64' ] ; then 3 ln -s /usr/ local /mysql/lib/mysql /usr/lib64/mysql 4 else 5 ln -s /usr/ local /mysql/lib/mysql /usr/lib/mysql 6 fi


Other methods 1: Execute the command file/sbin/init

1 [root@localhost jianbao] # file /sbin/init 2 /sbin/init: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

In 32-bit Linux, 64-bit is displayed.

For example, the result of running on another 64-bit machine:

1 [root@edunosql ~] # file /sbin/init 2 /sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

Method 2: uname-

32-bit: Linux localhost. localdomain 2.6.32-431.17.1.el6.i686 #1 SMP Wed May 7 20:52:21 UTC 2014 i686 i686 i386 GNU/Linux

64-bit: Linux demolinux 2.6.32-431.11.2.el6.x86 _ 64 #1 SMP Tue Mar 25 19:59:55 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Method 3: Use "getconf WORD_BIT" and "getconf LONG_BIT" to obtain the number of digits of word and long. The 64-bit system should obtain 32 and 64 respectively.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.