Linux command notes

Source: Internet
Author: User
Tags root access

http://heipark.iteye.com/blog/1083805

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 count 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}

Only allow root Telnet cd/etc
Touch Nologin

Lock user, view machine 64-bit or 32-bit uname-m #会显示: "i686", "x86_64" cannot telnet (root only) passwd-l Hadoop

Unlock user (root only) passwd-u Hadoop

Lists the file paths of the RPM installer RPM-QL hadoop-0.20

View system already installed software 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 ipvi/etc/resolv.conf

#查看内存free

#查看CPU是否支持64操作系统, if the result is greater than 0, the description supports 64bit mode (long mode)
Cat/proc/cpuinfo | grep Flags | grep ' LM ' | Wc-l

#查看某行内容
Sed-n ' 100{p;q} ' filename

#查看用户所属组
grep "User name"/etc/group

#查看rpm包文件
Rpm2cpio hadoop.rpm | Cpio-idmv

#添加某个路径到运行时库, one line of 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

#centos下通过shell修改文件扩展名, 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 removes 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

The Linux command line parameter references the Run 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 Write # method one
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 a line command to create a user and set a password useradd-p ' OpenSSL passwd <pwd> '-G <group_ Name> <username>

Create a user and disable Telnet useradd-s/sbin/nologin AK47

Query user crontab run record Cat/var/log/cron | grep <username>

Modify the Linux User directory usermod-d/home/hdfs-u hdfs disk speed test hdparm-t/dev/sda1

Quick Find file (according to file name) # Locate command is responsible for finding, updatedb command generating file index (daily)
Locate *qq*.txt

Chkconfig wrote Chkconfig--list | More # List all system services

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


The first SSH login is not prompted to configure the SSH conf file stricthostkeychecking No


Top C # Display 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 repetitions (shell-implemented group by + count) # Uniq must first sort,uniq the parameter-C to print the group repeat number
Cat xx. TXT | Sort | Uniq-c

The tar command uses TAR-ZCF my.tgz my # compression 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 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 writes # finds lines in text that contain boy and 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

See the number of open files Lsof |wc-l
Lsof-p PID |wc-l

See which programs are using Disk Iotop

Create large file writes DD If=/dev/zero of=test bs=1m count=1000

#更大文件可以用下面这个, come on.
DD If=/dev/zero of=test bs=1m count=0 seek=100000

Linux command notes

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.