Linux简单命令
01命令:Linux,#,ROOT代表进入管理员登录的用户,其他用户登录$提示符
一、 关机重启命令: shutdown -r now 在关闭进程后,系统会立即关机重启
shutdown -r +15 ,系统将于15分钟后重启 、reboot/init 6
关机:shutdown -h now
02 1、文件和目录管理 (pwd/cd/ls/mkdir/du)
2、文件操作命令(touch/file/cp/rm/mv/which/find/in)
3、文件内容操作命令(cat/more/less/head/tall/wc/grep)
4、归档及压缩命令(gzip/bzip2/tar)
二、短格式:[root@ACE ~]# ls l
ls: l: No such file or directory
[root@ACE ~]# ls -l 格式为,命令+参数(其中,Ls是查看;-是短格式引导符、参数词多个字母采用--)
total 64
-rw------- 1 root root 1157 Mar 31 18:15 anaconda-ks.cfg
[root@ACE ~]# ls -help
ls: invalid option -- e
Try `ls --help' for more information.
[root@ACE ~]# ls --help (LS命令是查看,-短格式参数错误、需要用长格式选项--引导)
Usage: ls [OPTION]... [FILE]... (help是帮助命令)
三、LS命令
[root@ACE ~]# ls -l list的缩写,查看。 -l是参数,查看文件
total 64
-rw------- 1 root root 1157 Mar 31 18:15 anaconda-ks.cfg
[root@ACE ~]# ll 通过实验发现,ll其实就是ls -l,是因为系统默认LL的参数代表ls -l
total 64
-rw------- 1 root root 1157 Mar 31 18:15 anaconda-ks.cfg
[root@ACE /]# mkdir -r abc
mkdir: invalid option -- r
Try `mkdir --help' for more information. 后面分析
[root@ACE /]# cd ~
[root@ACE ~]# mkdir -p a/b/c
[root@ACE ~]#
[root@ACE ~]# ls -r a 此处,ls 查看 -短引导 r参数, a文件名 ,发现小写r不能显示a文件下的B
b
[root@ACE ~]# ls -R a 参数-R能查看递归目录
a:
b
a/b:
c
a/b/c:
[root@ACE app]# ls -h 参数-h 不能直接显示具体数值
BCT oracle oraInventory ts_002.dbf
[root@ACE app]# ls -lh 参数-h要和L一起使用,显示文件以K/M等字节单位显示出来
total 11M
drwxr-xr-x 2 oracle oinstall 4.0K Apr 1 12:27 BCT
[root@ACE ~]# ls -a 参数-a能查看隐藏文件, .cshrc,小·前缀的为隐藏文件。
. .cshrc .gnome2_private .nautilus
三、小命令方式添加
01[root@ACE u01]# ls \ 通过\反向键可以强制换行两边需要留空格隔开
> -l
total 4
02.在vmware中输入命令经常需要鼠标右键粘贴,可以通过选中文字,鼠标中间点击粘贴快捷键,方便操作
03.在vmware中,有时候会出现当机状态,按键ctrl +c,直接关闭会话框重新操作,避免需要重启系统的尴尬局面
04.在·····补充
四、mkdir 创建新的目录make directory
[root@ACE /]# mkdir -r abc 事实告诉我们参数为-P才是连续创建目录,未指定-P,则表示在当前目录下创建一个文件
mkdir: invalid option -- r
Try `mkdir --help' for more information.
[root@ACE /]# cd ~
[root@ACE ~]# mkdir -p a/b/c
五、du 统计目录及文件所占空间情况
[root@ACE ~]# du 通计当前目录文件占用情况,单位不明确
12 ./.nautilus ·····
[root@ACE ~]# du -s 统计目录下所有文件总大小
4636
[root@ACE ~]# du -sh 加上参数h,以字节单位显示
4.6M .
[root@ACE ~]# du -ah 包括所有文件、不仅是目录,最后一行代表文件、目录所占空间总和
8.0K ./.bash_logout ···
4.6M
六、touch 新建空文件、或者更新文件改变时间
[root@ACE ~]# ls
a anaconda-ks.cfg Desktop install.log install.log.syslog
[root@ACE ~]# touch b
[root@ACE ~]# ll 没有文件B直接创建了
total 68
drwxr-xr-x 3 root root 4096 Apr 1 23:27 a
-rw------- 1 root root 1157 Mar 31 18:15 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Apr 2 00:00 b
[root@ACE ~]# touch a 通过上面比较,文件a的时间改变为了00:03,当前系统时间
[root@ACE ~]# ll
total 68
drwxr-xr-x 3 root root 4096 Apr 2 00:03
[root@ACE ~]# touch * 通过选定,当*代表所有文件,会发现所有文件时间都发生改变
[root@ACE ~]# ll
total 68
drwxr-xr-x 3 root root 4096 Apr 2 00:04 a
-rw------- 1 root root 1157 Apr 2 00:04 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Apr 2 00:04 b
drwxr-xr-x 2 root root 4096 Apr 2 00:04 Desktop
-rw-r--r-- 1 root root 38449 Apr 2 00:04 install.log
-rw-r--r-- 1 root root 3686 Apr 2 00:04 install.log.syslog
[root@ACE ~]# touch *
[root@ACE ~]# ll -a 继续查看,发现隐藏文件时间未发生改变
total 212
drwxr-x--- 16 root root 4096 Apr 2 00:00 .
drwxr-xr-x 27 root root 4096 Apr 1 22:58 ..
drwxr-xr-x 3 root root 4096 Apr 2 00:05 a
-rw------- 1 root root 1157 Apr 2 00:05 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Apr 2 00:05 b
-rw------- 1 root root 3182 Apr 1 22:56 .bas
[root@ACE ~]# touch .redhat 指定隐藏文件修改时间
[root@ACE ~]# touch * .* 指定以*所有文件、以.为首字符的文件*所有,发生改变
[root@ACE ~]# ll -a
total 212
drwxr-x--- 16 root root 4096 Apr 2 00:06 .
drwxr-xr-x 27 root root 4096 Apr 2 00:06 ..
drwxr-xr-x 3 root root 4096 Apr 2 00:06 a
-rw------- 1 root root 1157 Apr 2 00:06 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Apr 2 00:06 b
-rw------- 1 root root 3182 Apr 2 00:06 .
七、file命令 查看文件类型 ls file*
八、 pwd 查看当前工作目录,类同window里查看文件路径,c/ruanjian/aa
九、cd命令 切换工作目录
01,每个用户都有自己的家目录。
[root@ACE ~]# ls 查看当前文件目录下的文件
a anaconda-ks.cfg b Desktop install.log install.log.syslog
[root@ACE ~]# cd a 切换到a目录下
[root@ACE a]# pwd 查看当前工作目录
/root/a
[root@ACE a]# cd 不加路径,直接回到当前用户家目录
[root@ACE ~]# pwd
/root
[oracle@ACE ~]$ mkdir -p a/b/c 通过切换oracle用户验证命令
oracle@ACE ~]$ cd /a/b/c oracle家目录是、/home/oracle[
[oracle@ACE c]$ pwd
/home/oracle/a/b/c
[oracle@ACE c]$ cd
[oracle@ACE ~]$pwd
/home/oracle
[oracle@ACE ~]$ cd a/b/c 通过切换目录,..是代表用户家目录,返回上一级目录
[oracle@ACE c]$ cd ..
[oracle@ACE b]$ pwd
/home/oracle/a/b
[oracle@ACE b]$ cd c/ 通过..切换上一级目录可以不再当前目录下实现操作,创建文件
[oracle@ACE c]$ mkdir ../o 查看文件都可以实现
[oracle@ACE c]$ ls ..
c o
[oracle@ACE c]$
十、cp命令 copy复制
[oracle@ACE c]$ pwd
/home/oracle/a/b/c
[oracle@ACE c]$ cd ../../..
[oracle@ACE ~]$ ls
a db.rsp ts_system_09s0jdqu_1_1
control_0727.ctl ts_system_08s0jdph_1_1
[oracle@ACE ~]$ cp -r a b 参数-r,可以递归复制目录下内容、文件,一起复制
[oracle@ACE ~]$ ls 通过查看可以得知,复制源目录文件还存在
a control_0727.ctl ts_system_08s0jdph_1_1
b db.rsp ts_system_09s0jdqu_1_1
[oracle@ACE ~]$ ls b
b
[oracle@ACE ~]$ cd b
[oracle@ACE b]$ ls
b
参数-p保持源文件属性不变,在跨软件的时刻有时候需要
参数-f强制覆盖目标同名文件或目录
[root@ACE oracle]# ls
admin cfgtoollogs checkpoints diag oradata product 创建目录a,复制到上一级目录,还是a。造成重复,f覆盖;由于是目录,+参数r
[root@ACE oracle]# mkdir a
[root@ACE oracle]# mkdir ../a
[root@ACE oracle]# cp -rfi a ../a
[oracle@ACE ~]$ cp -rfi a ../a 同样的命令oracle用户不能操作,ll查看权限相同,证明是权限不足
cp: cannot create directory `../a': Permission denied
十一、rm命令 remove
[oracle@ACE b]$ cd a
[oracle@ACE a]$ ls
a1 b
[oracle@ACE a]$ cd ..
[oracle@ACE b]$ ls
a
[oracle@ACE b]$ rm -fr a 参数-f,强行删除文件或目录,不提醒
[oracle@ACE b]$ rm -ri b 参数-i,删除文件提醒确认
rm: descend into directory `b'? y
rm: remove directory `b/c'? y
[oracle@ACE ~]$ rm -r a1 参数-r,递归删除目录树
十二、mv命令 move
[oracle@ACE ~]$ ls
b d ts_system_08s0jdph_1_1
control_0727.ctl db.rsp ts_system_09s0jdqu_1_1
[oracle@ACE ~]$ mv d a 如果在当前目录,且移动的指定目录不存在,则相当于改文件名
[oracle@ACE ~]$ ls
a control_0727.ctl ts_system_08s0jdph_1_1
b db.rsp ts_system_09s0jdqu_1_1
[oracle@ACE ~]$ mv b c 可以直接移动目录到指定位置
[oracle@ACE ~]$ cd c
十三、which
[root@ACE ~]# which cd 可以查看环境变量,命令之所以生效是因为命令的结构信息放在环境变量且运行
/usr/bin/which: no cd in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@ACE ~]# which ls
alias ls='ls --color=tty'
/bin/ls
[root@ACE ~]# which in
/usr/bin/which: no in in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/
十四、fing 查找文件或目录
find -name 按照文件名称查找
-size 按照文件大小查找
-user 按文件属主查找
-type 按文件类型查找
[root@ACE ~]# ls -l 文件四种类型 d 目录、f普通文件、b块设备文件、c字符设备文件
total 68
drwxr-xr-x 3 root root 4096 Apr 2 00:06 a
-rw------- 1 root root 1157 Apr 2 00:06 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Apr 2 00:06 b
drwxr-xr-x 2 root root 4096 Apr 2 00:06 Desktop
十五、ln命令 给文件进行快捷方式,如果不加参数,相当于复制一个快捷方式,加参数s,表示创建快捷方式,指定到一个文件的过程。
[root@WE ~]# cd /u01
[root@WE u01]# ll
total 4
drwxr-xr-x 3 oracle oinstall 4096 May 1 21:06 app
[root@WE u01]# man ls | col -b > ls.txt
[root@WE u01]# ll
total 12
drwxr-xr-x 3 oracle oinstall 4096 May 1 21:06 app
-rw-r--r-- 1 root root 7300 May 2 07:29 ls.txt
[root@WE u01]# ln ls.txt ls.txt.aa 硬链接文件
[root@WE u01]# tail 20 ls.txt
tail: cannot open `20' for reading: No such file or directory
==> ls.txt <==
the info and ls programs are properly installed at your site, the com-
mand
info ls
should give you access to the complete manual.
ls 5.97 February 2010 LS(1)
You have new mail in /var/spool/mail/root
[root@WE u01]# tail ls.txt.aa
the info and ls programs are properly installed at your site, the com-
mand
info ls
should give you access to the complete manual.
ls 5.97 February 2010 LS(1)
[root@WE u01]# rm -rf ls.txt 在删除源文件后,目标文件可以打开
[root@WE u01]# head ls.txt.aa
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
[root@WE u01]# ln -s ls.txt.aa ls.txt 软链接,查看软链接文件,删除源文件后,失效
[root@WE u01]# head ls.txt
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
[root@WE u01]# rm ls.txt.aa
rm: remove regular file `ls.txt.aa'? y
[root@WE u01]# head ls.txt
head: cannot open `ls.txt' for reading: No such file or directory
文件内容操作命令---
十六、cat 显示文件的所有内容
语法:cat +文件
十七、由于cat查看的文件,当文档很长,观看效果极差,新增命令:more/less,分页显示。
语法: cat +文件|more/less
退出Q键
十八、head命令 查看文件开头一部分(默认10行)
语法:head +文件
指定行数head -(x行)+文件
十九、tail命令 查看文件结尾
tail +文件名
加参数+f 可以看到更新操作,打开一个文件,新建另一个窗口,复制数据进入,会发现数据改变
二十、wc命令 统计文件单词数量 参数:-l / -w / -c
[root@WE u01]# wc ls.txt 三个值:行数、单词数、字节数(含空格)
141 526 4156 ls.txt
[root@WE u01]# wc -l ls.txt
141 ls.txt
[root@WE u01]#
二十一、grep命令 在文件中查找并显示包含指定字符串的行,格式-i 忽视大小写 -v 反转查找,输出相反条件的值 ,查找"^","$",以………^.....$
例:过滤掉注释行,grep -v "^#" /etc/hosts 查找路径下HOSTS文件,#开头不显示,过滤
例:cat aa|grep -v "^B" 查看AA文件所有信息,过滤掉以B开头的信息,全部显示出来
归档及压缩命令
二十二、 gzip/bzip2 压缩命令
二十三、tar命令,常用。 tar +归档文件名或目录 ,如果解压到其它目录下,使用参数-C /xx
常用命令: -c 创建 文件名.tar 格式的包文件
-x 解开.tar 格式的包文件
-v 输出详细信息
-f 使用归档文件
-p: 打包时保留原始文件及目录的权限
-t 列表查看包内文件
例如:
[root@WE u01]# man ls | col -b > aa 查看帮助信息,ls命令所有,输出保存新建aa
[root@WE u01]# ll
total 12
-rw-r--r-- 1 root root 7300 May 2 11:05 aa
drwxr-xr-x 3 oracle oinstall 4096 May 1 21:06 app
[root@WE u01]# gzip aa 使用gzip压缩文件
[root@WE u01]# ll 查看发现文件后自动加.gz
total 8
-rw-r--r-- 1 root root 3022 May 2 11:05 aa.gz
drwxr-xr-x 3 oracle oinstall 4096 May 1 21:06 app
[root@WE u01]# gzip -d aa.gz gzIp文件使用蚕食-d 解压
[root@WE u01]# ll
total 12
-rw-r--r-- 1 root root 7300 May 2 11:05 aa
drwxr-xr-x 3 oracle oinstall 4096 May 1 21:06 app
[root@WE u01]# cat aa 能正常查看
LS(1) User Commands LS(1)
[root@SGJK ~]# cd /mnt 在vmware虚拟机中,安装TOOLS,会使用tar
[root@SGJK mnt]# tar -xvf VMwareTools-10.0.0-2977863.tar.gz -C /tmp
解压 -解压、输出详细信息、使用归档文件 文件tar.gz 压缩文件 -C指定解压目标目录
------
用户和组及权限管理
1.什么是用户什么是组。 个人理解,用户就是一个账号,组的产生来源于多个账号,为了方便管理,权限、分类。产生了组。
2.组分为:当前用户组,属组。有私有和附加之分
3.账号:由权限可以区分。Linux中,root是超级用户,Oracle中SYS是超级用户。
普通用户,增删改查很多没权限。
账号如何区分开来,有个UID,系统不认识root.普通用户,机器语言都是二进制代码,我们只需要知道UID、GID一个用户一个组
[root@WE ~]# id root
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@WE ~]# id oracle
uid=1001(oracle) gid=1000(oinstall) groups=1000(oinstall),1001(dba),1002(oper)
[root@WE etc]# tail -l /etc/passwd 密码文件查看,x是密码
oprofile:x:16:16:Special user account to be used by OProfile:/home/oprofile:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:4294967294:4294967294:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
avahi-autoipd:x:100:156:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
oracle:x:1001:1000::/home/oracle:/bin/bas
下方注释:1用户账号名称;2密码;3上次修改密码时间;4密码最短天数,默认0;5密码最迟有效天数;6提前多少天报警,口令过期,默认7;7密码过期之后多少天禁用账户;8账号失效时间,默认空值;9保留字段未使用
[root@WE etc]# tail -l /etc/shadow
oprofile:!!:17281:0:99999:7:::
squid:!!:17281:0:99999:7:::
xfs:!!:17281:0:99999:7:::
rpcuser:!!:17281:0:99999:7:::
nfsnobody:!!:17281:0:99999:7:::
haldaemon:!!:17281:0:99999:7:::
avahi-autoipd:!!:17281:0:99999:7:::
gdm:!!:17281:0:99999:7:::
sabayon:!!:17281:0:99999:7:::
oracle:!!:17287:0:99999:7:::
二十四、useradd 添加用户账号
参数-u 指定uid标记号
-d 指定宿主老大目录,不编辑默认/home/用户名
-e 指定账号失效时间
-g 指定用户基本组名(UID)
-G 指定用户附加组名(GID)
-M 不为用户建立,并且初始化宿主目录
-s 指定用户登录Shell
简单配置:
[root@WE etc]# useradd -u 550 set
[root@WE etc]# tail -l /etc/passwd
set:x:550:550::/home/set:/bin/bash
[root@WE etc]# useradd -u 600 -e 2017-05-03 sb
[root@WE etc]# tail -l /etc/passwd
sb:x:600:600::/home/sb:/bin/bash
··············································
二十五、简单配置 别名命令:例如删除为了安全,每次加-i 参数,麻烦,可以设置参数
.bashrc根下的文件:
[root@WE etc]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i' 默认使用rm 自动使用参数- i
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
[root@WE etc]# du -sh quotatab 查看XX目录总大小,H显示字节单位,懒得麻烦
8.0K quotatab
root: cd ~
root: vi .bashrc 编辑环境变量
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias du='du -h' 添加这行
root: . .bashrc 运行环境变量
[root@WE etc]# du -s quotatab 再次查看相同,默认自动使用参数-h,以字节显示
8.0K quotatab
二十六、用户口令 passwd
新建用户需要设置密码口令文件,直接passwd oracle
在Oracle当中是PASSWORD + 用户
二十七、usermod 参数-l更改账号登录名称 -L锁定账号 -U解锁账号
添加账号 useradd 删除 userdel
[root@WE ~]# useradd -u1000 -g 1000 sb
[root@WE ~]# userdel -r sb
[root@WE ~]# su - sb
su: user sb does not exist
添加组账号 groupadd -g 指定GID号
添加删除组成员: gpasswd -a 添加一个用户
-d 删除一个
-M 定义成员列表,逗号分隔
用户组账号查询: id + 用户
[root@WE ~]# id root
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@WE ~]# groups oracle
oracle : oinstall dba ope
[root@WE ~]# finger -l oracle 查看详细信息
Login: oracle Name: (null)
Directory: /home/oracle Shell: /bin/bash
Never logged in.
No mail.
No Plan.
二十八、权限。 访问权限、读写执行 chmod 文件、目录权限;chown文件、目录归属
[root@WE ~]# ll
total 100
-rw------- 1 root root 1680 Apr 25 21:35 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 Apr 26 10:28 Desktop
-rw-r--r-- 1 root root 62667 Apr 25 21:34 install.log
-rw-r--r-- 1 root root 5590 Apr 25 21:33 install.log.syslog
drwxr-xr-x 2 root root 4096 Apr 26 10:30 mount
r:可读 w :可写 x:可执行 -无权限
分别数字 4210
D代表目录,-普通文件,b 块设备,c字符型,l链接文件
后面九个字符,分别代表三组不同权限,第一组7 、二组5、三组5
三组分别代表,当前用户、属于哪个组,属主、其它用户
[root@WE ~]# cp install.log install.log.aaa
[root@WE ~]# ll
total 168
-rw-r--r-- 1 root root 62667 Apr 25 21:34 install.log
-rw-r--r-- 1 root root 62667 May 2 13:27 install.log.aaa
[root@WE ~]# chmod 777 install.log.aaa 测试修改权限,全部可读可写可执行4+2+1,三组
[root@WE ~]# ll
total 168
-rw-r--r-- 1 root root 62667 Apr 25 21:34 install.log
-rwxrwxrwx 1 root root 62667 May 2 13:27 install.log.aaa
属主:root :root
[root@WE ~]# chown oracle:oinstall install.log.aa
[root@WE ~]# ll | grep "i"; 修改归属
-rw-r--r-- 1 root root 62667 Apr 25 21:34 install.log
-rwxrwxrwx 1 oracle oinstall 62667 May 2 13:27 install.log.aaa
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步