linux系统命令 回顾
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux系统命令 回顾相关的知识,希望对你有一定的参考价值。
解释下什么是 GPL,GNU,自由软件?
GPL:(通用公共许可证):一种授权,任何人有权取得、修改、重新发布自由软件的权力。
GNU:(革奴计划):目标是创建一套完全自由、开放的的操作系统。
自由软件:是一种可以不受限制地自由使用、复制、研究、修改和分发的软件。主要许可证有 GPL 和 BSD 许可证两
种。
linux系统构成:内核+外围程序
uname -r
默认:
[当前用户@主机 工作目录]#/$
可以改变
$PS1
[[email protected] ~]# echo $PS1
[\[email protected]\h \W]\$
You have new mail in /var/spool/mail/root
[[email protected] ~]# PS1=‘\[email protected]\t \$‘
[email protected]:43:15 #
[email protected]:43:16 #
#man bash
内部命令:shell程序一部分,系统启动时驻留在内核中
外部命令:不在shell程序中,其命令过程由shell程序控制
[[email protected] 桌面]# type ls
ls is aliased to `ls --color=auto‘
[[email protected] 桌面]# type cd
cd is a shell builtin
[[email protected] 桌面]# which ls
alias ls=‘ls --color=auto‘
/bin/ls
[[email protected] 桌面]# which cd
/usr/bin/which: no cd in (/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin)
[[email protected] 桌面]# enable 都是内部命令
enable .
enable :
enable [
enable alias
touch 创建文件和更新时间戳
stat 查看文件状态
[[email protected] ~]# stat 1.txtt
File: "1.txtt"
Size: 19 Blocks: 8 IO Block: 4096 普通文件
Device: 802h/2050d Inode: 10618267 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-04-05 10:31:05.094196869 +0800
Modify: 2017-04-05 10:31:30.275196833 +0800
Change: 2017-04-05 10:31:30.275196833 +0800
[[email protected] ~]# touch 1.txtt
[[email protected] ~]# cat 1.txtt
123456
1sdafafasdf
[[email protected] ~]# stat 1.txtt
File: "1.txtt"
Size: 19 Blocks: 8 IO Block: 4096 普通文件
Device: 802h/2050d Inode: 10618267 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-04-05 10:34:12.915295258 +0800
Modify: 2017-04-05 10:34:06.731295266 +0800
Change: 2017-04-05 10:34:06.731295266 +0800
[[email protected] ~]# echo 1212 >>1.txtt
[[email protected] ~]# stat 1.txtt
File: "1.txtt"
Size: 24 Blocks: 8 IO Block: 4096 普通文件
Device: 802h/2050d Inode: 10618267 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-04-05 10:34:12.915295258 +0800
Modify: 2017-04-05 10:37:34.476433508 +0800
Change: 2017-04-05 10:37:34.476433508 +0800
[[email protected] ~]# tac 1.txtt
111
1212
1sdafafasdf
123456
[[email protected] ~]# cat 1.txtt
123456
1sdafafasdf
1212
111
[[email protected] 桌面]# echo 111 >1.txt
[[email protected] 桌面]# cat 1.txt >b.txt
[[email protected] 桌面]# cat b.txt
111
做光盘镜像
dd if=/dev/cdrom of=rhel6.iso
cp /dev/cdrom rhel6.iso
cat /dev/cdrom > rehl6.iso
cat 合并文件
[[email protected] 桌面]# cat 1.txt
111
[[email protected] 桌面]# cat b.txt
1 111
[[email protected] 桌面]# cat 1.txt b.txt >new.txt
[[email protected] 桌面]# cat new.txt
111
1 111
[[email protected] 桌面]# cat 1.txt
111
adasd
[[email protected] 桌面]# tr ‘a-z‘ ‘A-Z‘ <1.txt 导出
111
ADASD
[[email protected] 桌面]# echo 1212 >>1.txtt
[[email protected] 桌面]# ls -i 1.txtt
10749834 1.txtt
[[email protected] 桌面]# ln 1.txtt hello.txtt
[[email protected] 桌面]# ls -i hello.txtt
10749834 hello.txtt
[[email protected] 桌面]# du -h 1.txtt
4.0K 1.txtt
[[email protected] 桌面]# du -h hello.txtt
4.0K hello.txtt
[[email protected] 桌面]# md5sum 1.txtt
b5e808f2a41cb05f73fd604ab1b3bda6 1.txtt
You have new mail in /var/spool/mail/root
[[email protected] 桌面]# md5sum hello.txtt
b5e808f2a41cb05f73fd604ab1b3bda6 hello.txtt
——————————
两个小于号
————————————
[[email protected] 桌面]# cat merepo.sh
#!/bin/bash
cat <<EOF > /etc/yum.repos.d/server.repo
[Server]
name=Server
baseurl=ftp://172.40.55.104
enabled=1
gpgcheck=0
EOF
[[email protected] 桌面]# rm -fr /etc/yum.repos.d/*
[[email protected] 桌面]# sh merepo.sh
[[email protected] 桌面]# ls /etc/yum.repos.d/
server.repo
[[email protected] 桌面]# yum repolist
已加载插件:fastestmirror, refresh-packagekit, security
Determining fastest mirrors
Server | 4.1 kB 00:00
Server/primary_db | 3.1 MB 00:00
仓库标识 仓库名称 状态
Server Server 3,819
repolist: 3,819
——————————————————————————————
[[email protected] 桌面]# ls -l $(cat /etc/passwd)
[[email protected] 桌面]# cat /root |xargs ls -l
[[email protected] 桌面]# egrep -n ‘adm‘ /etc/passwd
4:adm:x:3:4:adm:/var/adm:/sbin/nologin
[[email protected] 桌面]# egrep -n -B2 -A3 ‘adm‘ /etc/passwd
2-bin:x:1:1:bin:/bin:/sbin/nologin
3-daemon:x:2:2:daemon:/sbin:/sbin/nologin
4:adm:x:3:4:adm:/var/adm:/sbin/nologin
5-lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6-sync:x:5:0:sync:/sbin:/bin/sync
7-shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
[[email protected] 桌面]# egrep --color -o ‘var|dev‘ /etc/passwd
var
var
[[email protected] 桌面]# grep --color root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[[email protected] 桌面]# grep --color -o root /etc/passwd
root
root
[[email protected] 桌面]# tar acf security.tar.gz security
[[email protected] 桌面]# find /tmp/clu -type f -exec chmod 644 {} \;
[[email protected] 桌面]# find /tmp/clu -type d -exec chmod 750 {} \;
vi中 命令补齐:
hostna
ctrl+N ctrl+P
RPM下载
http://rpmfind.net
http://rpm.pbone.net
http://mirrors.163.com
http://mirrors.aliyun.com
本地rpm包用yum装:可以自动解决依赖关系
yum -y install li*.rpm
|————————————————————————————————————————————————
本地yum缓存先做好,做好后可以拷到不能联网的电脑上,装包时候的依赖就可以用
[[email protected] 桌面]# vim /etc/yum.conf
2 cachedir=/tmp/mypacks
3 keepcache=1
[[email protected] 桌面]#yum -y install system-config-kickstart
[[email protected] 桌面]#ls /tmp/mypacks/Server/packages/ 把这个yum依赖的拷贝就可以
————————————————————————————————————————————————
架构不一样
yum-rhn-plugin-0.9.1-58.el6.noarch.rpm 都可以
zlib-devel-1.2.3-29.el6.i686.rpm 32位
zlib-devel-1.2.3-29.el6.x86_64.rpm 64位
创建用户默认配置文件
[[email protected] 桌面]#vim /etc/login.defs
33 UID_MIN 660
34 UID_MAX 60000
[[email protected] 桌面]# useradd tt
[[email protected] 桌面]# id tt
uid=660(tt) gid=660(tt) 组=660(tt)
/etc/skel
/etc/passwd /etc/shadow
/etc/group /etc/gshadow
[[email protected] 桌面]useradd -u 555 zhangsan
[[email protected] 桌面]#vim /root/.bash_history 每次退出 命令都写在这里
[[email protected] 桌面]#vim /root/.bash_logout (每次退出都删除历史命令)
# ~/.bash_logout
history -c
~
[[email protected] 桌面]# chage -M 90 bob (指定密码最大天数,-m最小天数)
[[email protected] 桌面]# chage -l bob 列出密码有效期信息
[[email protected] 桌面]# chage -E 20170605 bob 指定帐号过期时间
[[email protected] 桌面]# chage -d 0 bob 密码立即过期 使用就改密码
[[email protected] ~]# echo "log-$(date +%F).tar.gz"
log-2017-04-05.tar.gz
如果导入了这个私匙信息,就不需要写gpgcheck=0
[[email protected] ~]# rpm --import ftp://172.40.55.104/RPM-GPG-KEY-redhat-release
——————————————————————————————————
chmod -R u=rwX,g=rX,o=rX /tmp/ss (大X 目录就是755,文件644)
[[email protected] ~]# chmod -R u=rwX,g=rX,o=rX /tmp/ss
[[email protected] ~]# ll -l /tmp/ss
总用量 16
drwxr-xr-x. 116 root root 12288 4月 5 16:45 etc
-rw-r--r--. 1 root root 2031 4月 5 16:44 passwd
————————————————————————————————————————
命令运行期间是由身份的
suid:命令以属主身份运行命令 u+s
[[email protected] ~]# chmod u+s /bin/ls
[[email protected] ~]# ll /bin/ls
-rwsr-xr-x. 1 root root 117024 10月 15 2014 /bin/ls
[[email protected] ~]# su - bob
[[email protected] ~]$ ls /root
1.txtt
2.txt
——————————————————
[[email protected] 桌面]# su - bob
[[email protected] ~]$ touch 1.txt
[[email protected] ~]# which touch
/bin/touch
You have new mail in /var/spool/mail/root
[[email protected] ~]# chmod u+s /bin/touch 这是一样的 [[email protected] ~]# chmod 4755/bin/touch
[[email protected] ~]$ touch 2.txt (这个是以root身份创建的)
[[email protected] ~]$ ll -lhd 1.txt 2.txt
-rw-rw-r--. 1 bob bob 0 4月 5 16:57 1.txt
-rw-rw-r--. 1 root bob 0 4月 5 16:57 2.txt
————————————————————————————————————————
sgid:继承父目录属组 g+s
[[email protected] ~]# mkdir /tmp/demo
[[email protected] ~]# chgrp bob /tmp/demo 都一样 chown :bob /tmp/demo
[[email protected] ~]# ll -d /tmp/demo
drwxr-xr-x. 2 root bob 4096 4月 5 17:05 /tmp/demo
[[email protected] ~]# cp /etc/hosts /tmp/demo
[[email protected] ~]# ll /tmp/demo
总用量 4
-rw-r--r--. 1 root root 187 4月 5 17:06 hosts
[[email protected] ~]# chmod g+s /tmp/demo 给目录加了g+s权限后 之后该目录下的文件都是该用户
[[email protected] ~]# ll -l /etc/passwd
-rw-r--r--. 1 root root 2031 4月 5 15:48 /etc/passwd
[[email protected] ~]# cp /etc/passwd /tmp/demo
[[email protected] ~]# ll /tmp/demo/
总用量 8
-rw-r--r--. 1 root root 187 4月 5 17:06 hosts
-rw-r--r--. 1 root bob 2031 4月 5 17:07 passwd
sticky bit:用户只能删除自己的文件
[[email protected] 桌面]# setfacl -m u:bob:rwx rem_com.sh 给某一个用户对该文件权限 粘耻位
一个扇区512字节
机械盘 -----》固态盘(开机直接操作不许要等一下)
分区后刷新几种方式:
partx -a /dev/sdb
reboot
分区形式存在的swap性能更高 文件的更差
所以用的时候可以在/etc/fstab中给分区swap和文件的做优先级 使用时
本文出自 “12336621” 博客,请务必保留此出处http://12346621.blog.51cto.com/12336621/1913140
以上是关于linux系统命令 回顾的主要内容,如果未能解决你的问题,请参考以下文章