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
Java code
- # Modify DNS IP
- Vi/etc/resolv.conf
Java code
- #查看内存
- 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
======================================
1. Check if the remote port is open for bash:
echo >/dev/tcp/8.8.8.8/53 && echo "open"
2. Turn the process into the background:
Ctrl + z
3. Transfer the process to the foreground:
fg
4. Generates a random hexadecimal number, where n is the number of characters:
openssl rand -hex n
5. Execute a command in a file in the current shell:
source /home/user/file.name
6. Intercept the first 5 characters:
${variable:0:5}
7.SSH Debug Mode:
ssh -vvv user@ip_address
8.SSH with PEM key:
ssh user@ip_address -i key.pem
9. Crawl the complete Site directory structure with wget and store it in a local directory:
"index.html*" http://hostname/ -P /home/user/dirs
10. Create more than one directory at a time:
mkdir -p /home/user/{test,test1,test2}
11. List the process tree that includes the child processes:
ps axwef
12. Create the War file:
jar -cvf name.war file
13. Test HDD Write Speed:
if=/dev/zero of=/tmp/output.img bs=8k count=256k; rm -rf /tmp/output.img
14. Test Drive Read Speed:
hdparm -Tt /dev/sda
15. Get the MD5 hash of the text:
"text" | md5sum
16. Check the XML format:
xmllint --noout file.xml
17. Extract the tar.gz into the new directory:
tar zxvf package.tar.gz -C new_dir
18. Get the HTTP header information using curl:
curl -I http://www.example.com
19. Modify the timestamp (YYMMDDHHMM) of the file or directory:
0712250000 file
20. Perform an FTP download with the wget command:
wget -m ftp://username:password@hostname
21. Generate a random password (the example is 16 characters in length):
LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;
22. Quickly back up a file:
cp some_file_name{,.bkp}
23. Access the Windows shared directory:
"DOMAIN\user" //dc.domain.com/share/test/dir
24. The command in the execution history (this is line 100th):
!100
25. Unzip:
unzip package_name.zip -d dir_name
26. Enter multiple lines of text (CTRL + D exit):
cat > test.txt
27. Create an empty file or empty an existing file:
\> test.txt
28. Sync time with Ubuntu NTP server:
ntpdate ntp.ubuntu.com
29. Display all TCP4 listening ports with netstat:
‘{print $4}‘ | cut -f2 -d: | grep -o ‘[0-9]*‘
30.qcow2 image File Conversion:
qemu-img convert -f qcow2 -O raw precise-server-cloudimg-amd64-disk1.img \precise-server-cloudimg-amd64-disk1.raw
31. Run the file repeatedly, showing its output (by default, 2 seconds):
watch ps -ef
32. List of all users:
getent passwd
33.Mount root in Read/write mode:
mount -o remount,rw /
34. Mount a directory (this is a case where links cannot be used):
mount --bind /source /destination
35. Dynamically update DNS server:
86400 A $IPsendEOF
36. Recursive grep all directories:
"some_text" /path/to/dir
37. List the top 10 largest files:
‘{ if($7 > 1048576) print $7/1048576 "MB "$9 }‘ | sort -n -u | tail
38. Show remaining memory (MB):
‘/[0-9]/{ print $4" MB" }‘
39. Open vim and jump to the end of the file:
vim + some_file_name
40.Git clones the specified branch (master):
git clone git@github.com:name/app.git -b master
41.Git Switch to another branch (develop):
git checkout develop
42.Git Delete Branch (myfeature):
git branch -d myfeature
43.Git Delete Remote Branch
git push origin :branchName
44.Git Push the new branch to the remote server:
git push -u origin mynewfeature
45. Last Cat command in print history:
!cat:p
46. Last cat command in the Run history:
!cat
47. Find all the empty empty directories under/home/user:
1 -type d -empty
48. Get the contents of the 第50-60 line in the Test.txt file:
‘50,60p‘
49. Run the last command (if the last command is Mkdir/root/test, the following will run: sudo mkdir/root/test):
sudo !!
50. Create temporary RAM file System –ramdisk (create/tmpram directory first):
mount -t tmpfs tmpfs /tmpram -o size=512m
51.Grep whole words:
"name" test.txt
52. Append text to a file in case you need to elevate your privileges:
"some text" | sudo tee -a /path/file
53. List all kill signal parameters:
kill -l
54. Prohibit logging of the last session in bash history:
kill -9 $$
55. Scan the network for open ports:
8081 172.20.0.0/16
56. Set up git email:
git config --global user.email "[email protected]"
57.To sync with Master If you have unpublished commits:
git pull --rebase origin master
58. Move all files with "TXT" in the file name into the/home/user directory:
"*txt*" -exec mv -v {} /home/user \;
59. Display the file in rows and lines:
paste test.txt test1.txt
Progress bar in 60.shell:
pv data.log
61. Use Netcat to send data to Graphite server:
"hosts.sampleHost 10 `date +%s`" | nc 192.168.200.2 3000
62. Convert Tabs to spaces:
expand test.txt > test1.txt
63.Skip Bash History:
< space >cmd
64. Go to the previous working directory:
cd -
65. Split the large volume tar.gz file (each 100MB) and merge it back in:
100m /path/to/large/archive /path/to/output/filescat files* > archive
66. Use Curl to get the HTTP status code:
"%{http_code}\\n" www.example.com -o /dev/null
67. Set the root password to enhance MySQL security installation:
/usr/bin/mysql_secure_installation
68. When Ctrl + C is not good to make:
Ctrl + \
69. Get the file owner:
stat -c %U file.txt
70.block Device List:
lsblk -f
71. Locate the file with a space at the end of the file name:
find . -type f -exec egrep -l " +$" {} \;
72. Find the file with the tab indent in the filename
find . -type f -exec egrep -l $‘\t‘ {} \;
73. Print a horizontal line with "=": Select Copy to put in notes
‘%100s\n‘ | tr ‘ ‘ =
Related connections:
My Linux command notes
73 Daily Linux Shell command Summary, there is always one you need
Linux Command Rollup 1