Management
In a unix/linux system, everything is a file, or a process if it is not a file. First recognize the file system:
Linux file system
/var-frequently changing (variable) files, such as logs or databases
/USR-contains applications and files that are accessible to the vast majority of all users
/OPT-Provides an optional (optional) Application installation directory
/tmp-Temporary (temporary) file
/etc-Configuration files, startup scripts, etc. (etc)
/dev-Device files
/bin-Important binary (binary) applications
/boot (boot) configuration file
/sbin-Important system binaries (systems binaries) files
/sys-Systems (System) files
/home-Local user home directory
/lib-System library (libraries) file
Ls
(http://www.jb51.net/article/56474.htm)
20 Practical examples of the LS command
通过修改时间列出:ls -lt排序文件大小:ls -lhs测量大小: ls -l --block-size=M显示隐藏文件 ls -a只列出目录条目 ls -d */增加 / (斜线) 标记目录: ls -p排序时反转顺序: ls -r递归列出子目录: ls -R 扩展名排序: ls -lX统计某文件夹下文件的个数:ls -l |grep "^-"|wc -l统计某文件夹下目录的个数:ls -l |grep "^d"|wc -l统计当前文件夹下文件的个数,包括子文件夹里的 ls -lR|grep "^-"|wc -l
Program installation
yumrpm 卸载已经安装的rpm包 两个关键点: 1.如果提示有xxx.rpm包已经被installed了,那么先用rpm -e --nodeps xxx来卸载 2.如果存在多个版本的话,用rpm -e --allmatches来卸载linux 下如何安装 tar.gz包1)解压tar.gz包 ==》最常见的gz格式,则可以执行:“tar –xvzf 软件包名”,就可以一步完成解压与解包工作。 tar -zxvf 软件包名.tar.gz -C /home/hao 将软件包名.tar.gz解压到指定的目录下 (注意:-C为大写)2)进入解压后的文件目录下 执行“./configure”命令为编译做好准备; ./configure --prefix=/opt 表示安装到/opt目录3) 执行“make”命令进行软件编译;4) 执行“make install”完成安装;5) 执行“make clean”删除安装时产生的临时文件。
File decompression
tar tar -zxvf 软件包名.tar.gz -C /home/hao 将软件包名.tar.gz解压到指定的目录下 (注意:-C为大写)unzip
File operations
cpmvscp快速删除大量文件:1)先建立一个空目录mkdir /data/blank2)用rsync删除目标目录rsync --delete-before -d /data/blank/ /var/spool/clientmqueue/ln -s 源文件 目的文件(链接文件)ln -s log2013.log link2013ln -s /usr/local/nginx/sbin/nginx /usr/sbin/ln -s /usr/local/nginx/conf /etc/nginx1.源文件被删除后,并没有影响硬链接文件;软链接文件在centos系统下不断的闪烁,提示源文件已经不存在2.重建源文件后,软链接不在闪烁提示,说明已经链接成功,找到了链接文件系统;重建后,硬链接文件并没有受到源文件影响,硬链接文件的内容还是保留了删除前源文件的内容,说明硬链接已经失效
Permissions
Https://www.cnblogs.com/0xcafedaddy/p/7132860.html
- Common Linux file permissions:
444 -r--r--r--600 -rw-------644 -rw-r--r--666 -rw-rw-rw-700 -rwx------744 -rwxr--r--755 -rwxr-xr-x777 -rwxrwxrwx注:使用ll命令查看文件/文件夹属性时候,一共有10列,第一个小格表示是文件夹或者连接等等d表示文件夹,l表示连接文件,-表示文件
- User group Permissions Concept
从左至右:0位数字代表文件类型:d表示文件夹,l表示连接文件,-表示文件1-3位数字代表文件所有者的权限4-6位数字代表同组用户的权限7-9数字代表其他用户的权限
3. Digital concept Analysis
读(r)=4写(w)=2执行(x)=1读+写+执行=4+2+1=7通过4、2、1的组合,得到以下几种权限:0(没有权限)4(读取权限)5(4+1 | 读取+执行)6(4+2 | 读取+写入)7(4+2+1 | 读取+写入+执行)chmod 777 目录chmod -R 777 usr/
Linux centos Shutdown and restart command detailed and practical
Linux centos重启命令: ● 1、reboot ● 2、shutdown -r now 立刻重启(root用户使用) ● 3、shutdown -r 10 过10分钟自动重启(root用户使用) ● 4、shutdown -r 20:35 在时间为20:35时候重启(root用户使用) 如果是通过shutdown命令设置重启的话,可以用shutdown -c命令取消重启Linux centos关机命令: ● 1、halt 立刻关机 ● 2、poweroff 立刻关机 ● 3、shutdown -h now 立刻关机(root用户使用) ● 4、shutdown -h 10 10分钟后自动关机 如果是通过shutdown命令设置关机的话,可以用shutdown -c命令取消重启
Find
● find ○ find . -name “*” | xargs grep “hello abcserver” ○ find . -name "*" | xargs grep "test" ● locate(locate) 用来查找文件或目录。 locate命令要比find -name快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/mlocate/mlocate.db 。这个数据库中含有本地所有文件信息。Linux系统自动创建这个数据库,并且每天自动更新一次,因此,我们在用whereis和locate查找文件时,有时会找到已经被删除的数据,或者刚刚建立文件,却无法查找到,原因就是因为数据库文件没有被更新。为了避免这种情况,可以在使用locate之前,先使用updatedb命令,手动更新数据库。locate /etc/my
Viewing the resource system version
cat /etc/redhat-release
Hard Disk Resources
du-Disk Usagedf-Disk Freedu -ah --max-depth=1 /ddhome/usr/hadoop du -h du -lhdf -h df -THll -lhfdisk -l
View CPU Information
总核数 = 物理CPU个数 X 每颗物理CPU的核数 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数#查看物理CPU个数cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l#查看每个物理CPU中core的个数(即核数)cat /proc/cpuinfo| grep "cpu cores"| uniq#查看逻辑CPU的个数cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
Debugging
set -x 查看shell调试信息
Internet
View IP information in effect
ifconfig
Shutting down and starting the network card
ifdown loifup lo
View network Status
netstat-t 列出tcp协议端口-u 列出udp协议端口-n 不使用域名与服务名,使用IP和端口-l 列出监听状态的网络服务-a 列出所有的网络连接-r 路由信息-p 列出pid,进程idnetstat -anp|grep :22netstat -tunlnetstat -rnnetstat -an|grep ESTABLISHED #通过这条指令查看当前计算机开启了哪些服务。netstat -an|grep ESTABLISHED |wc -l #查看正在连接我的计算机
Grab Package Command
tcpdump ‘tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)‘ -w 80.captcpflow -a -o . -Fk -r 80.cap
Boot from Boot
/etc/rc.d/
init.d/: Binary files directory for various servers and programs
rc.* the Execution program connection directory for each startup level. Everything inside is a soft connection to the init.d/.
Service Boot from Boot
/etc/rc.d/rc*.dchkconfig --add servicechkconfig -level 5 service on
Script Boot from boot
etc/rc.d/rc.local直接在该文件末尾添加自定义脚本
Start log
/var/log/boot.log
Process View PS
PS naming determines which processes are running and running, whether the process is complete, if the process has no zombies, which processes are consuming too many resources, and so on. In short, most of the information can be obtained by executing the command. PS is to show the status of the instantaneous process, not dynamic continuous; If you want to monitor the process in real time, you should use the top command.
参数:-A :所有的进程均显示出来,与 -e 具有同样的效用;-a : 显示现行终端机下的所有进程,包括其他用户的进程;-u :以用户为主的进程状态 ;x :通常与 a 这个参数一起使用,可列出较完整信息。输出格式规划:l :较长、较详细的将该PID 的的信息列出;j :工作的格式 (jobs format)-f :做一个更为完整的输出。相关信息的意义为:F 代表这个程序的旗标 (flag), 4 代表使用者为 superuser;S 代表这个程序的状态 (STAT);UID 代表执行者身份PID 进程的ID号!PPID 父进程的ID;C CPU使用的资源百分比PRI指进程的执行优先权(Priority的简写),其值越小越早被执行;NI 这个进程的nice值,其表示进程可被执行的优先级的修正数值。ADDR 这个是内核函数,指出该程序在内存的那个部分。如果是个执行 的程序,一般就是『 - 』SZ 使用掉的内存大小;WCHAN 目前这个程序是否正在运作当中,若为 - 表示正在运作;TTY 登入者的终端机位置;TIME 使用掉的 CPU 时间。CMD 所下达的指令名称
PS Command Example
使用 -a 参数。-a 代表 all。同时加上x参数会显示没有控制终端的进程。$ ps -ax在需要查看特定用户进程的情况下,我们可以使用 -u 参数。比如我们要查看用户‘pungki‘的进程,可以通过下面的命令:$ ps -u pungki通过cpu和内存使用来过滤进程也许你希望把结果按照 CPU 或者内存用量来筛选,这样你就找到哪个进程占用了你的资源。要做到这一点,我们可以使用 aux 参数,来显示全面的信息:$ ps -aux | less根据 CPU 使用来升序排序$ ps -aux --sort -pcpu | less根据 内存使用 来升序排序$ ps -aux --sort -pmem | less显示前10个结果:$ ps -aux --sort -pcpu,+pmem | head -n 10通过进程名和PID过滤使用 -C 参数,后面跟你要找的进程的名字。比如想显示一个名为getty的进程的信息,就可以使用下面的命令:$ ps -C getty$ ps -f -C getty根据线程来过滤进程如果我们想知道特定进程的线程,可以使用-L 参数,后面加上特定的PID。$ ps -L 1213显示安全信息如果想要查看现在有谁登入了你的服务器。可以使用ps命令加上相关参数:$ ps -eo pid,user,args格式化输出root用户(真实的或有效的UID)创建的进程系统管理员想要查看由root用户运行的进程和这个进程的其他相关信息时,可以通过下面的命令:$ ps -U root -u root u使用PS实时监控进程状态ps 命令会显示你系统当前的进程状态,但是这个结果是静态的。当有一种情况,我们需要像上面第四点中提到的通过CPU和内存的使用率来筛选进程,并且我们希望结果能够每秒刷新一次。为此,我们可以将ps命令和watch命令结合起来。$ watch -n 1 ‘ps -aux --sort -pmem, -pcpu’如果输出太长,我们也可以限制它,比如前20条,我们可以使用head命令来做到。$ watch -n 1 ‘ps -aux --sort -pmem, -pcpu | head 20’
View system Open File Lsof
Lsof (list open files) is a tool that lists open files for the current system.
In a Linux environment, everything is in the form of files, with files that not only access regular data, but also access to network connectivity and hardware. So, such as Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) sockets, the system assigns a file descriptor to the application in the background, regardless of the nature of the file, which provides a common interface for the interaction between the application and the underlying operating system.
Because the application opens a descriptor list of files that provides a lot of information about the application itself, it is helpful to see the list through the Lsof tool for system monitoring and troubleshooting.
lsof输出各列信息的意义如下: COMMAND:进程的名称PID:进程标识符USER:进程所有者FD:文件描述符,应用程序通过文件描述符识别该文件。如cwd、txt等TYPE:文件类型,如DIR、REG等DEVICE:指定磁盘的名称SIZE:文件的大小NODE:索引节点(文件在磁盘上的标识)NAME:打开文件的确切名称lsof -i[46] [protocol][@hostname|hostaddr][:service|port]
Reference documents
Tips: This article belongs to their own study and practice of the process of recording, many pictures and text are pasted from the online article, no reference please forgive! If you have any questions please leave a message or e-mail notification, I will promptly reply.
Common commands for Linux systems (i)