Linux Practice

System: CentOS6.5

12. yum download

#Download a package to a specified directory (eg / tmp):
 yum  install --downloadonly --downloaddir=/tmp <package-name> #However  
, on CentOS /RHEL 6 or earlier, you need to install A single yum plugin (named yum - plugin-downloadonly) can only be used with the --downloadonly command option
 yum  install  yum -plugin- downloadonly
#Note: If the downloaded package contains any unsatisfied dependencies, yum will download all the dependencies, but will not install them. Packages that have been installed through yum cannot be downloaded using this command

11. FTP operation on Linux

ftp
open ip port
name
password
passive #After entering this command, other commands will take effect
bin #The downloaded package can only be used after entering this command
ls
get
bye

10. ctrl+c cannot terminate telnet

ctrl + ]
quit

9. Linux hard connection and soft connection

ln - s file path soft link path
 ln file path hard link path
#Same point: it is all a file, and the modifications will be synchronized to the source file
#Difference: delete the soft link source file, the soft link will fail; delete the hard link or delete the source file, the file already exists, unless the source file and all hard links are deleted.
#Understanding: soft link - shortcut; hard link - another file path, delete all paths, and delete the source file

8. Configure SSH password-free login

SSH password-free login for root user

ssh-keygen -t rsa //Three times of carriage return to generate public and private key files
cd /root/.ssh //Enter the .ssh folder
cat id_rsa.pub >> authorized_keys //Copy the public key to authorized_keys
scp /root/.ssh/authorized_keys root@hostname:/root/.ssh/ //scp to the specified server
ssh hostname //Successful login to the specified server without password is successful
//To log in to a server without password, just scp your public key to that server
SSH password-free login for non-root users
ssh-keygen -t rsa //Three times of carriage return to generate public and private key files
cd ~/.ssh //Enter the .ssh folder
cat id_rsa.pub >> authorized_keys //Copy the public key to authorized_keys
scp ~/.ssh/authorized_keys username@hostname:~/.ssh/ //scp to the .ssh folder in the specified server user directory
chmod 700 ~/.ssh //Change permissions 

chmod 600 authorized_keys

ssh hostname //Successful login to the specified server without password is successful

 

7. Modify Hostname

hostname newHostname //Temporarily effective
vi /etc/sysconfig/network //It will take effect after restart
//Use both at the same time to satisfy the immediate effect and permanent modification

6. Write timing scripts to delete files regularly

//A. Write a shell script, create a new executable file auto-del-30-days-ago-log.sh, and assign runnable permissions
#touch /opt/soft/bin/auto-del-30-days-ago-log.sh
#chmod +x auto-del-30-days-ago-log.sh
#vi auto-del-30-days-ago-log.sh
#!/bin/sh
find /opt/soft/log/ -mtime +30 -name "*.log" -exec rm -rf {} \;
//B, join the system plan task
#crontab -e
10 0 * * * /opt/soft/log/auto-del-7-days-ago-log.sh >/dev/null 2>&1
//C. Create your own timed task through crontab -e. The meaning of 5 * is that the first * is the minute, the second * is the hour, the third * is the day, the fourth * is the month, The 5th * is the week and the 6th column is the order
service crond status View crontab service status:
service crond start start the service
service crond stop shuts down the service
service crond restart restarts the service
service crond reload reload configuration
//-mtime n Find the file according to the change time of the file, n is an integer.
//D. Description
/*n means the file change time distance is n days, -n means the file change time distance is within n days, +n means the file change time distance is n days ago.
-mtime 0 indicates that the file modification time is 0 days away from the current file, that is, the file is less than 1 day (24 hours) away from the current time.
-mtime 1 indicates that the file modification time is 1 day away from the current file, that is, the file is 1 day away from the current time (24 hours - 48 hours).
-mtime+1 indicates that the file modification time is greater than 1 day, that is, the file is 2 days (48 hours) away from the current time
-mtime -1 indicates that the file modification time is less than 1 day, that is, the file within 1 day (24 hours) from the current time
Why does -mtime+1 indicate that the file modification time is greater than 1 day, that is, the file that is 48 hours away from the current time, not 24 hours away?
Because the n value can only be an integer, that is, the nearest integer greater than 1 is 2, all -mtime+1 is not greater than the current time by 1 day (24 hours), but is greater than the current time by 2 days (48 hours)
find /opt/soft/bin/ -mtime +2 -name ".log" -exec rm -rf {} \; //Clean up the back of the command; don't throw it away
find: Linux search command, the user finds files with specified conditions;
/opt/soft/bin/: any directory you want to clean up;
-mtime: Last modified content time
+30: Find files older than 30 days, where numbers represent the number of days;
"*.log": The type of data you want to find, "*.jpg" means to find all files with the extension jpg
-exec: fixed writing method, execute;
rm -rf: Force deletion of files, including directories;
{} \; : Fixed notation, a pair of braces + space +\+;*/

 

5. Basic permission operation

ls -l (or direct ll) filename #ls -ld directoryname //View details including permissions
rwx read and write execution corresponds to 4 2 1
chmod +x a.sh #chmod -x a.sh //Add delete execution permission
chmod 666(4+2) filename #chmod 777(4+2+1) filename //General file 644, directory 755
//The three numbers correspond to the owner, user group, and others in order. For example, 755 identifies the owner's read and write execution (4+2+1), the user in the owner's user group is read and executed (4+1), and others are read and executed (4+1)

4. Background operation and output log

nohup XXX & // run in the background
command >server.log == command 1 >server.log //standard output
command >server.log 2>&1 //Redirect standard error to standard output. That is, both standard error and standard output are redirected to a server.log, not overwritten
// 0 - stdin 1 - stdout 2 - stderr

3. Parameter view

free -g //View memory, G is the unit 
df -h //View hard disk top //View memory, finer, similar to Windows Task Manager and then press shift+m ​​to sort according to memory from large to small

2. Find files by file name

find / -name httpd.conf //Find the file httpd.conf in the root directory, which means to search the entire hard disk
find /etc -name httpd.conf //File httpd.conf in /etc directory
find /etc -name '*srm*' //Use wildcard *(0 or any number). Indicates that the file name contains the string 'srm' in the /etc directory
find . -name 'srm*' //Indicates the current directory to find the file whose name starts with the string 'srm'

 

1. Firewall (root authority, the combination of the two will take effect immediately and permanently modify)

Temporarily close the firewall, it will take effect immediately, and it will be invalid after restarting

service iptables start //Open
service iptables stop //close
service iptables status //View firewall status

Permanently close the firewall, it will take effect after restart

chkconfig iptables on //Permanently open, it will take effect after restart
chkconfig iptables off //Permanent shutdown, take effect after restart

Guess you like

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