Common Linux Basic commands

Source: Internet
Author: User
Tags root access

Allow non-root users to use "sudo"

Root login system, execute "visudo", add a new rule according to the example (remember the password entered is the current user password, not the root password)

#不需要密码执行sudo命令

Hadoop all= (All) Nopasswd:all

Date

Time Stamp to date

Date-d ' 1970-01-01 UTC 1312438633.724 seconds ' + "%y-%m-%d%T"

#显示现在日期

Echo ' date-d now +%y%m%d '

#显示昨天日期

Echo ' date-d yesterday +%y%m%d '

#加减时间

Date +%y%m%d–date= "-1 day"

Date +%y%m%d%h–date= "-1 hour"

See what the site is server

Curl-s–head "Http://www.baidu.com"

View Redhat version

Cat/etc/redhat-release #我这里显示 "CentOS release 5.5 (Final)"

View Linux Max Open file number wrote

Ulimit-a

# Focus on the screen display one line, you can see the maximum number of open files is 1024

Open files (-N) 1024

To set the number of open files:

Echo-ne "

* Soft Nofile 65536

* Hard Nofile 65536

">>/etc/security/limits.conf

After the launch of the terminal, in the implementation of ULIMIT-A, you can see that the changes have taken effect

Zip compressed file

Zip {dist} {src}

zip-p {password} {dist} {src}

Allow root login only

Cd/etc

Touch Nologin

Lock the user to see whether the machine is 64-bit or 32-bit

Uname-m #会显示: "i686", "x86_64"

Unable to Telnet (root only)

Passwd-l Hadoop

Unlock user (root only)

Passwd-u Hadoop

List the file paths of the RPM Setup program

RPM-QL hadoop-0.20

View system has software installed

Rpm-qa | grep Hadoop

View current server total CPU cores (number of cores)

More/proc/cpuinfo | grep ' Processor ' | Wc-l

#查看每个CPU的核数

More/proc/cpuinfo | grep ' CPU cores '

#计算当前服务cpu数量

Total number of cores/cores per CPU

#查看CPU位数

Getconf Long_bit

To view the installation path for a program

Whereis Java

View the path to the execution program

which Java

Modify DNS IP

Vi/etc/resolv.conf

View Memory

Free

See if the CPU supports 64 operating systems

If the result is greater than 0, the description supports 64bit mode (long mode)

Cat/proc/cpuinfo | grep Flags | grep ' LM ' | Wc-l

View a line of content

Sed-n ' 100{p;q} ' filename

To view groups to which the user belongs

grep "User name"/etc/group

View RPM Package Files

Rpm2cpio hadoop.rpm | Cpio-idmv

Add a path to the run-time library, one line at a path

Vi/etc/ld.so.conf

/usr/local/lib/

(or use an environment variable in such a way that does not require root access)

Export ld_library_path=/xxxxx: $LD _library_path

Modify file extensions via Shell under CentOS

Rename <oldname> <newname> <*.files>

#将所有html扩展名改为htm扩展名

Rename. html. htm *.html

Specific reference: http://www.cyberciti.biz/tips/renaming-multiple-files-at-a-shell-prompt.html

#通过mv也可以实现修改扩展名这个功能

MV GoodYear. {htm,html}

Sort command

#-U Remove Duplicate rows

#-R Descending (default to Ascending)

#-O output sorted after data, he with redirect ' > ' The biggest difference is the output data to the original file

Sort Seq.txt-o > Seq.txt

#-N Sort by numeric size

#-k Specifies sorting according to a column

Sort Num.txt-k2 # Sorted by second column (default delimiter is space, tab)

#-T specifies the column delimiter, only one character is supported

#-M Merge sort

Linux command line parameter reference

To run the command:

./test.sh 111 222 333 444

Echo Run file name: $

#./test.sh

Echo First parameter: $

#111

echo number of parameters: $#

#4

Echo Last: $_

#444

echo all parameters, parameters are considered to be multiple strings: [email protected]

#111 222 333 444

echo all parameters, parameter is considered a string: $*

#111 222 333 444

echo Program PID: $$

Echo Exit code: $?

Less command

TIP1: Typing 50p, can enter 50% of the document location, support decimals, such as 95.5p

Script Change Password

#方法一

echo 123123 |passwd–stdin ABC

#方法二

#echo "Root:[email protected]# $QW 12qw" |chpasswd

#pwdadm-C Root

Http://www.aixchina.net/club/thread-69699-1-1.html

One-line command to create a user and set a password

Useradd-p ' OpenSSL passwd <pwd> ' G <group_name> <username>

Create users and disable remote logins

Useradd-s/sbin/nologin AK47

Querying user crontab Running records

Cat/var/log/cron | grep <username>

Modifying the Linux User directory

usermod-d/home/hdfs-u HDFs

Disk Speed test

Hdparm-t/dev/sda1

Quick Find files (based on file name)

# Locate command is responsible for finding, updatedb command generating file index (daily)

Locate *qq*.txt

Chkconfig

Chkconfig–list | More # List all system services

Chkconfig <service_name> Off|on # Shut down, turn on system services

First SSH login not prompted

Configuring the SSH conf file stricthostkeychecking No

Top

C # Show program full path

M # Sort by memory

P # Sorted by CPU

Top-p <pid> # View Process Top

#RES表示物理内存占用, the PS command is RSS representation of physical memory

BZ2 File Decompression

BUNZIP2 yy.bz2

View the number of repetitions (shell-implemented group by + count)

# Uniq must first sort,uniq parameter-C, print group repeats the number of times

Cat xx. TXT | Sort | Uniq-c

The TAR command uses

TAR-ZCF my.tgz my # Compressed packaging

TAR-CF my.tgz My # do not compress packaging

TAR-ZXF my.tgz My # Unpacking package

TAR-XF my.tgz my # Uncompressed package

TAR-TF # View the TAR package structure

Find

#-o: Or condition

# Find all the. htm and. html files at the end of the current directory

Find. \ (-name "*.htm"-o-name "*.html" \)

#-a:and Conditions

Grep

#查找文本中包含boy和girl的行

Cat My.txt | Grep-e ' Boy|girl '

# Find file name based on text content, "-h" for output file name

Find. -name ' *city* '-ls-exec zgrep ' null ' {}-h \;

# "or" lookup

Method One: grep ' pattern1\|pattern2 ' filename

Method Two: grep-e ' pattern1|pattern2 ' filename

Method Three: Egrep ' pattern1|pattern2 ' filename

Method Four: grep-e pattern1-e pattern2 filename

# "and" lookup

Method One: grep-e ' pattern1.*pattern2 ' filename

Method Two: grep-e ' pattern1 ' filename | Grep-e ' pattern2 '

Modify hostname

Method One: hostname <new hostname>

Method Two: Vi/etc/sysconfig/network

To view the number of open files

Lsof |wc-l

Lsof-p PID |wc-l

See which programs are using disk

Iotop

Create a large file

DD If=/dev/zero of=test bs=1m count=1000

#更大文件可以用下面这个, come on.

DD If=/dev/zero of=test bs=1m count=0 seek=100000

Create a simulated n multiple small file

For

This article is from the "Richy Operations Log" blog, please make sure to keep this source http://richylu.blog.51cto.com/1481674/1846352

Common Linux Basic commands

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.