Linux common commands and frequently asked questions

Source: Internet
Author: User
Tags bz2 time zones

Frequently used commands to view system Information

Linux version
Uname-a Viewing system kernel information
Lsb_release-a viewing LSB (Linux standard Base) and distribution information
Cat/etc/issue View Linux Versions
Cat/etc/system-release
Cat/etc/redhat-release
ENV displays the current user's environment variables

CPU Information
Lscpu-display information about the CPU architecture
Cat/proc/cpuinfo
Vmstat-reports information about processes, memory, paging, block IO, traps, disks and CPU activity
Top

Memory information
Cat/proc/meminfo

Process
Ps-ef | grep Java View Java process
Kill-9 # # # # Kill Process
NETSTAT-TLNP | grep 8080 View port occupancy
Fuser Show which processes use the named files, sockets, or filesystems
FUSER-K-n TCP 80 kills processes that occupy 80 ports

TMPWATCH-AFV 5d/tmp Delete the TMP directory 5 days unused files
Update-alternatives--install/usr/bin/java Java/usr/lib/jvm/jdk1.7.0/bin/java

Add Repository

Centos/rhel 7:

# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Centos/rhel 6:

# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

You can also find the installation package on the following Web site:
Package Search
RPM Search
RPM Find

Installing the Development Kit

Yum install-y gcc gcc-c++ installation compiler
Yum install-y libstdc++ Libstdc++-devel
Yum Groupinstall "Development tools" installation development tools
(if there is no installed groups file error, please attach parameter--setopt=group_package_types=mandatory,default,optional)
Yum GroupInfo "Development tools" view the contents of a group development tools
Yum list installed list installed packages

Firewall configuration

Systemctl Start Firewalld
Firewall-cmd--state
Firewall-cmd--zone=public--add-port=5000/tcp

User Rights

Visudo Edit/etc/sudoers File

File/directory Operations

PWD Displays the current working path
CD-Return to the last directory
Mkdir-p/dir1/dir2 Create a directory tree
Cp-a dir1 dir2 Copy a directory

True > Test.txt Empty the contents of the file
Find
Time-related options:-atime,-ctime and-mtime, to-mtime description
-mtime N: = n is a number, meaning a file that has been modified in "one day" prior to the nth day
-mtime +n: Lists files that have been modified before n days (excluding n days themselves)
-mtime-n: Lists files that have changed content within n days (including n days itself)
-newer File:file for an existing file, list files that are newer than file
CentOS 7 supports the-NEWERXY parameter, which allows you to specify the time directly, please refer to the Find Help documentation.

find AIRLINE -name *0813* -type f | xargs du -ck  查找名字包含0813的文件并统计总大小,以Kb为单位find执行actionfind / -name \*.rpm -exec chmod 755 ‘{}‘ \;   从根目录搜索以 ‘.rpm‘ 结尾的文件并定义其权限,其中{}位置放置find执行结果,\; 为action结束标志find -type d -exec mkdir -p /new_folder/{} \;   复制当前目录下的目录结构find AIRLINE -wholename **/attach/*0813* -type f -exec rm -f {} \;  根据wholename查找文件并删除

which [-a] command to find the executable file (-A: Lists all the commands that can be found in the path directory, not just the first found command name)
Whereis [-BMSU] Filename/folder find from some specific directories
Locate [-ir] keyword find files based on/var/lib/mlocate database (perform updatedb update repository)

Common configuration file Network configuration

Ssh/etc/ssh/sshd_config
Network parameter/etc/sysconfig/network-scripts/ifcfg-eth0
Dns/etc/resolv.conf
Hosts/etc/hosts
Hostname/etc/hostname
Network/etc/sysconfig/network

NETWORKING=yes  NETWORKING_IPV6=no  HOSTNAME=xxx  GATEWAY=xxx.xxx.xxx.xxx  

Iptables/etc/sysconfig/iptables

System Configuration

Mount/etc/fstab

User Configuration

user/etc/passwd
User Password/etc/shadow
Group/etc/group
Group Password/etc/gshadow

Scheduled Tasks

/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
/etc/anacrontab

#period in days   delay in minutes   job-identifier          command1                          5                          cron.daily              nice run-parts /etc/cron.daily7                         25                         cron.weekly           nice run-parts /etc/cron.weekly@monthly           45                         cron.monthly         nice run-parts /etc/cron.monthly
Timer service Crond

Service Crond start/stop Start/Stop Timer services

Crontab Editing timed tasks
crontab [-u user] [-e |-l |-r]
-e Edit user ' s crontab
-l list user ' s crontab
-R Delete User ' s crontab
-ir prompt before deleting user ' s crontab

crontab [-u user] File
A task list file that is crontab with file and loaded into

Format of crontab file:
The rows in the crontab file consist of 6 fields separated by a space or TAB key between the different fields.
First 5 fields specify when the command will run
Minutes (0-59)
Hours (0-23)
Date (1-31)
Month (1-12)
Day of the week (0-6, of which 0 stands for Sunday)
The 6th field is the executed string

FAQ Yum Duplicate Errors

First look if uncomplete transactions with:yum-complete-transaction
If this doesn ' t-help-then take a-look at the Package-cleanup tool which are part of the Yum-utils package.
Package-cleanup--dupes Lists duplicate packages
Package-cleanup--cleandupes Removes duplicate packages

Ldconfig Dynamic Link Library Management

When the so file cannot be found (cannot open shared object file), use Ldconfig to configure the share. The configuration file is located in the/ETC/LD.SO.CONF.D directory.
For example, if the Mysql,so file is installed under/usr/lib64/mysql, you can create a mysql.conf file in the/ETC/LD.SO.CONF.D directory, where the content is/usr/lib64/mysql and then run:
$ sudo ldconfig-v

Linux time synchronization
yum install ntpservice ntpd start

Time is automatically synchronized from the parent NTP server after the service starts
/etc/ntp.conf as a profile, you can configure the parent server

The client can also not start the NTPD service by crontab sync time:

*/3 * * * *     (/usr/sbin/ntpdate 10.184.13.14 && /sbin/hwclock -w) &> /dev/null
Setting the time zone

CentOS 7

$ timedatectlLocal time: Tue 2016-11-22 06:07:42 UTC  Universal time: Tue 2016-11-22 06:07:42 UTCRTC time: Tue 2016-11-22 06:07:42  Time zone: UTC (UTC, +0000)  NTP enabled: yes  NTP synchronized: no  RTC in local TZ: no  DST active: n/a  

Timedatectl List-timezones Viewing time zones
Timedatectl Set-timezone Asia/shanghai Setting the time zone
Timedatectl Set-timezone UTC

CentOS 6

# vim /etc/sysconfig/clockZONE="UTC"cp /usr/share/zoneinfo/UTC /etc/localtime
Keys decrypted using the Ssh-agent and keychain caches

Keychain helps you-manage SSH and GPG keys in a convenient and secure manner. It acts as a frontend to Ssh-agent and Ssh-add, but allows you to easily has one long running ssh-agent process per Syste M, rather than the norm of one ssh-agent per login session.

This dramatically reduces the number of times you need to enter your passphrase. With keychain, the need to enter a passphrase once every time your local machine is rebooted. Keychain also makes it easy for remote cron jobs to securely "hooks in" to a long-running ssh-agent process, allowing your Scripts to take advantage of key-based logins.

Restrict multiple people to log in with the same user

Added in/etc/pam.d/login:

session required/lib/security/pam_limits.so

Then add the following to/etc/security/limits.conf:

* hard maxlogins 1
Data recovery

Installation Tool Extundelete

yum install e2fsprogs e2fslibs-dev

or download extundelete-x.x.x.tar.bz2, run TAR-JXVF extundelete-x.x.x.tar.bz2 and install after decompression.
To restore a directory, execute:

extundelete partition_name --restore-directory path/of/directory

Autoexpect-generate an Expect script from watching a session
Brother Bird's Linux private cuisine
Top 5 Yum repositories for Centos/rhel 7/6/5

Linux common commands and frequently asked questions

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.