my linux command notes

Allow non-root users to use "sudo"
root to log in to the system, execute "visudo", and add a new rule according to the example (remember that the entered password is the current user password, not the root password)
#Do not need a password to execute the sudo command
hadoop ALL =(ALL) NOPASSWD: ALL
date
timestamp to date
date -d '1970-01-01 UTC 1312438633.724 seconds' +"%Y-%m-%d %T" #Display the

current date
echo `date -d now +% Y%m%d` #Display

yesterday's date
echo `date -d yesterday +%Y%m%d` #Add and

subtract time
date +%Y%m%d --date="-1 day"
date +%Y% m%d%H --date="-1 hour"

check what server the website is
curl -s --head "http://www.baidu.com"

check the redhat version
cat /etc/redhat-release #I show here "CentOS release 5.5 (Final)"
to check the maximum number of open files in linux and write
ulimit -a
# Pay attention to one of the lines on the screen, you can see that the maximum number of open files is 1024
open files (-n) 1024

Set the number of open files:

echo -ne "
* soft nofile 65536
* hard nofile 65536
" >>/etc/security/limits.conf

After launching the terminal, after executing ulimit -a, it can be seen that the modification has been Effective

zip compressed file
zip {dist} {src}
zip -P {password} {dist} {src}


Only root remote login is allowed
cd /etc
touch nologin

to lock the user, check whether the machine is 64-bit or 32-bit
uname -m # will display: "i686", "x86_64"
cannot log in remotely (root only)
passwd -l hadoop

unlock user (root only)
passwd -u hadoop

List the file path of the rpm installer
rpm -ql hadoop-0.20


Check the installed software
rpm -qa | grep hadoop

to view the total number of cpu cores on the current server (how many cores there are)
more /proc/cpuinfo | grep 'processor' | wc -l


#View the number of cores per CPU
more /proc/cpuinfo | grep 'cpu cores' #Calculate the


number of current service cpus, the
total number of cores / the number of cores per CPU #View the number of


CPU bits
getconf LONG_BIT

View the installation path of the program
whereis java

view The path of the execution program
which java

Java code Collection code
# Modify DNS IP 
vi /etc/resolv.conf 

Java code Collection code
# Check memory 
free 

# Check whether the CPU supports 64 operating systems, if the result is greater than 0, it supports 64 bit mode (long mode )
cat /proc/cpuinfo | grep flags | grep 'lm ' | wc -l #View

the content of a line
sed -n '100{p;q}' filename #View the

group a user belongs to
grep "username" /etc/group

# View the rpm package file
rpm2cpio hadoop.rpm | cpio -idmv #Add

a path to the runtime library, one path per line
vi /etc/ld.so.conf
/usr/local/lib/
(or using environment variables, this direction does not require root permissions)
export LD_LIBRARY_PATH=/xxxxx:$LD_LIBRARY_PATH

#Modify the file extension through the shell under centos, rename <oldname> <newname> <* .files> #Change
all html extensions to htm extensions
rename .html .htm *.html
Specific reference: http://www.cyberciti.biz/tips/renaming-multiple-files-at-a-shell-prompt .html #The
function of modifying the extension can also be realized through mv
mv goodYear.{htm,html}





sort command
# -u remove duplicate lines

# -r descending order (the default is ascending order)

# -o output sorted data, he and redirection The biggest difference of '>' is to output data to the original file
sort seq.txt -o > seq.txt

# -n sort according to numerical size

# -k specify sort according to a certain column
sort num.txt -k2 # sort according to the second column ( The default separator is space, tab)

# -t specifies the column separator, only one character is supported
# -m merge sort



linux command line parameter reference
Run the command:
./test.sh 111 222 333 444

echo Run file name: $0
#./test.sh

echo First parameter: $1
#111

echo Number of parameters: $#
#4

echo Last one: $_
#444

echo all parameters , parameters are considered as multiple strings: $@
#111 222 333 444

echo all parameters, parameters are considered as one string: $*
#111 222 333 444

echo program pid: $$

echo exit code: $?



less command
tip1: Type 50p, you can enter 50% of the document position, and decimals are supported, such as 95.5p


script to change the password and write #method
one
echo 123123 |passwd --stdin abc #method
two
#echo "root:!@#$QW12qw" |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 a user and prohibit remote login
useradd -s /sbin/nologin ak47

Query user crontab running records
cat /var/log/cron | grep <username>

modify linux user directory
usermod -d /home/hdfs -U hdfs
disk speed test
hdparm - t /dev/sda1

Quickly find files (based on file names)
# The locate command is responsible for finding, and the updatedb command generates a file index (daily)
locate *qq*.txt


chkconfig writes
chkconfig --list | more # List all system services

chkconfig < service_name> off|on # Turn off and turn on system



services without prompting for the first SSH login.
Configure StrictHostKeyChecking in the ssh conf file no


top
c # Display the full path of
the program m # Sort by memory
P # Sort by CPU

top -p <pid> # View Process top
#RES means physical memory usage, in the ps command, rss means physical memory

bz2 file decompression
bunzip2 yy.bz2

View the number of repetitions (group by + count implemented by the shell)
# Before uniq, you must sort first, and the uniq parameter -c will print the number of repetitions of the group
cat xx.TXT | sort | uniq -c

Use
tar -zcf my.tgz my for the tar command # Compressed and packaged
tar -cf my.tgz my # Uncompressed and packaged


tar -zxf my.tgz my # Uncompressed package
tar -xf my.tgz my # Uncompressed package

tar -tf # View tar package structure
find
#-o : or condition
# find all files ending in .htm and .html in the current directory
find . \( -name "*.htm" -o -name "*.html" \)

# -a: and condition
 
grep write
#find Lines containing boy and girl in the text
cat my.txt | grep -E 'boy|girl'

# Find the file name according to the text content, "-H" is used to output the file name
find . -name '*city*' -ls - exec zgrep 'null' {} -H \; 

# "or" search
Method 1: grep 'pattern1\|pattern2' filename
Method 2: grep -E 'pattern1|pattern2' filename
Method 3: egrep 'pattern1|pattern2' filename
Method 4: grep -e pattern1 -e pattern2 filename

# "and" to find
Method 1: grep -E 'pattern1.*pattern2' filename
Method 2: grep -E 'pattern1' filename | grep -E 'pattern2'


Modify hostname
Method 1: hostname <new hostname>
Method 2: vi /etc/sysconfig/network

View the number of open files
lsof |wc -l
lsof -p pid |wc -l

to see which programs are using disk
iotop


to create large files and write
dd if=/dev/zero of=test bs=1M count=1000

#For larger files, you can use the following, faster
dd if=/dev/ zero of=test bs=1M count=0 seek=100000

to see the program start time write
ps -eo pid,lstart|grep <pid>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326473533&siteId=291194637