首页 > 系统服务 > 详细

Linux基础命令练习

时间:2019-12-11 15:59:05      阅读:79      评论:0      收藏:0      [点我收藏+]

关机重启命令

init 0 关机
showdown -h now 关机
init 6 重启

查看用户

who 查看当前登录了哪些用户
tty 查看当前用户登录的终端
[root@localhost ~]# who
root     pts/0        2019-12-09 01:58 (192.168.209.1)
[root@localhost ~]# tty
/dev/pts/0
[root@localhost ~]# 
whoami 查看当前用户是谁
root@localhost ~]# whoami
root

date 日期,修改日期 (日期格式 月 日 时 分 年)

[root@localhost ~]# date
Mon Dec  9 02:54:48 EST 2019
[root@localhost ~]# date 110815492018
Thu Nov  8 15:49:00 EST 2018
cal 查看当前日历
[root@localhost ~]# cal
    November 2018   
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
查看固定日期的日历(日 月 年)
root@localhost ~]# cal 10 5 1997
      May 1997      
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

清屏

root@localhost ~]# clear 
或者ctel+l

passwd 修改密码,不加用户名就是修改当前用户

[root@localhost ~]# passwd 
Changing password for user root.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
echo修改密码,修改密码+管道符+passwd --stdin+用户
--stdin代表接收输入也就是接收passwd要输入的123
连起来就是把左边命令执行的结果作为右边命令的输入
[root@localhost ~]# echo 123 | passwd --stdin root
Changing password for user root.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# 

man、help查看帮助

root@localhost ~]# man passwd

















PASSWD(1)                              User utilities                             PASSWD(1)

NAME
       passwd - update user's authentication tokens

SYNOPSIS
       passwd  [-k]  [-l]  [-u  [-f]] [-d] [-e] [-n mindays] [-x maxdays] [-w warndays] [-i
       inactivedays] [-S] [--stdin] [username]

DESCRIPTION
       The passwd utility is used to update user's authentication token(s).

       This task is achieved through calls to the Linux-PAM and Libuser API.   Essentially,
       it  initializes  itself as a "passwd" service with Linux-PAM and utilizes configured
       password modules to authenticate and then update a user's password.

       A simple entry in the global Linux-PAM configuration file for this service would be:

        #
        # passwd service entry that does strength checking of
        # a proposed password before updating it.
        #
        passwd password requisite pam_cracklib.so retry=3
        passwd password required pam_unix.so use_authtok
        #

       Note, other module types are not required for  this  application  to  function  cor‐
       rectly.

OPTIONS
       -k, --keep
              The  option -k is used to indicate that the update should only be for expired
              authentication tokens (passwords); the user wishes to keep their  non-expired
              tokens as before.
[root@localhost ~]# passwd --help
Usage: passwd [OPTION...] <accountName>
 -k, --keep-tokens       keep non-expired authentication tokens
 -d, --delete            delete the password for the named account (root only)
 -l, --lock              lock the password for the named account (root only)
 -u, --unlock            unlock the password for the named account (root only)
 -e, --expire            expire the password for the named account (root only)
 -f, --force             force operation
 -x, --maximum=DAYS      maximum password lifetime (root only)
 -n, --minimum=DAYS      minimum password lifetime (root only)
 -w, --warning=DAYS      number of days warning users receives before password expiration
                         (root only)
 -i, --inactive=DAYS     number of days after password expiration when an account becomes
                         disabled (root only)
 -S, --status            report password status on the named account (root only)
 --stdin                 read new tokens from stdin (root only)

Help options:
 -?, --help              Show this help message
 --usage                 Display brief usage message

延伸:help后+管道符+less

告诉less把ls --help的命令结果变成分样的方式去查看

[root@localhost ~]# ls --help |less
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                               '--block-size=M' prints sizes in units of
                               1,048,576 bytes; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information);
                               with -l: show ctime and sort by name;
                               otherwise: sort by ctime, newest first
  -C                         list entries by columns
      --color[=WHEN]         colorize the output; WHEN can be 'never', 'auto',
                               or 'always' (the default); more info below
  -d, --directory            list directories themselves, not their contents
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of */=>@|) to entries
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                         like -l, but do not list owner
      --group-directories-first
                             group directories before files;
                               can be augmented with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             in a long listing, don't print group names
:

命令格式解析

命令本身+选项+参数

[root@localhost ~]# passwd -S root
root PS 2018-11-07 0 99999 7 -1 (Password set, SHA512 crypt.)

查看根目录

[root@localhost /]# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

查看当前所在目录

[root@localhost ~]# pwd
/root

boot目录存放的一些东西,类似于启动盘

root@localhost /]# cd /boot/
You have mail in /var/spool/mail/root
[root@localhost boot]# ls
config-3.10.0-693.el7.x86_64
efi
grub
grub2
initramfs-0-rescue-7ec60be873584f3ca3222e7e066817c5.img
initramfs-3.10.0-693.el7.x86_64.img
initrd-plymouth.img
symvers-3.10.0-693.el7.x86_64.gz
System.map-3.10.0-693.el7.x86_64
vmlinuz-0-rescue-7ec60be873584f3ca3222e7e066817c5
vmlinuz-3.10.0-693.el7.x86_64
[root@localhost boot]# 

bin目录存放的是常用的命令

[root@localhost boot]# cd
[root@localhost ~]# cd /bin/
[root@localhost bin]# ls
[                      iptables-xml              readlink
addr2line              isosize                   realpath
alias                  jobs                      recode-sr-latin
apropos                join                      rename
ar                     journalctl                renice
arch                   kbdinfo                   reset
as                     kbd_mode                  resizecons
aserver                kbdrate                   rev
aulast                 kdumpctl                  rm

sbin目录存放的是系统命令

[root@localhost ~]# ls /sbin
accessdb                   grub2-get-kernel-settings   postkick
addgnupghome               grub2-install               postlock
addpart                    grub2-mkconfig              postlog
adduser                    grub2-ofpathname            postmap
agetty                     grub2-probe                 postmulti
alternatives               grub2-reboot                postqueue
anacron                    grub2-rpm-sort              postsuper
applygnupgdefaults         grub2-set-default           poweroff
arpd                       grub2-setpassword           ppp-watch

etc目录存放的是配置文件

[root@localhost bin]# cd /etc/
[root@localhost etc]# ls
adjtime                  GeoIP.conf                modules-load.d     rwtab
aliases                  GeoIP.conf.default        motd               rwtab.d
aliases.db               gnupg                     mtab               sasl2
alternatives             GREP_COLORS               my.cnf             securetty
anacrontab               groff                     my.cnf.d           security
asound.conf              group                     NetworkManager     selinux
audisp                   group-                    networks           services
audit                    grub2.cfg                 nsswitch.conf      sestatus.conf
bash_completion.d        grub.d                    nsswitch.conf.bak  shadow
bashrc                   gshadow                   openldap           shadow-

mnt目录是挂载目录

[root@localhost ~]# ls /mnt
[root@localhost ~]# 

绝对路径跟相对路径

[root@localhost ~]# ls /boot/grub/splash.xpm.gz 
/boot/grub/splash.xpm.gz
[root@localhost ~]# cd /boot/
[root@localhost boot]# ls grub/splash.xpm.gz 
grub/splash.xpm.gz
  • 只要不是以跟开头的路径都是相对路径。
  • 相对路径一定要参照当前位置。

目录的增删改查

mkdir增加目录

[root@localhost ~]# mkdir /a
[root@localhost ~]# mkdir /a/d
[root@localhost ~]# mkdir /a/e
[root@localhost ~]# mkdir /a/f
[root@localhost ~]# ls /a
d  e  f

递归建目录 -p

[root@localhost ~]# mkdir -p /b/g
[root@localhost ~]# ls /b
g

查看目录结构 -d

-d代表查看目录结构而不是目录的内容

[root@localhost ~]# ls -d /a/e
/a/e
[root@localhost ~]# 

移动或重命名目录mv

重命名

[root@localhost ~]# ls /a
d  e  f
[root@localhost ~]# mv /a/f /a/f1
[root@localhost ~]# ls /a
d  e  f1

移动目录

[root@localhost ~]# ls /a
d  e  f1
[root@localhost ~]# ls /b
g  g,h,j  h  t  y
[root@localhost ~]# mv /a/f1 /b
[root@localhost ~]# ls /b
f1  g  g,h,j  h  t  y

删除目录rm

如果目录下有多个子目录可以用rm -r,但是还是要递归确定删除。

[root@localhost ~]# rm -r /b
rm: descend into directory ‘/b’? y
rm: remove directory ‘/b/g’? y
rm: remove directory ‘/b/g,h,j’? y
rm: descend into directory ‘/b/h’? y
rm: remove directory ‘/b/h/b’? ^C
[root@localhost ~]# ls /b
f1  h  t  y

不需要提示,直接全部删除rm -r -f 可以写一起rm -rf,一旦删除就无法恢复。

[root@localhost ~]# rm -rf /b
[root@localhost ~]# ls /
a    boot  dev  home  lib64  mnt  proc  run   srv  tmp  var
bin  d     etc  lib   media  opt  root  sbin  sys  usr

我们可以用mv命令代替删除,将想删除的目录移动到/tmp下,这里相当于回收站。想恢复的话就用mv命令移动回来。

[root@localhost ~]# mv /a /tmp
[root@localhost ~]# ls/tmp
-bash: ls/tmp: No such file or directory
[root@localhost ~]# ls /tmp
a
ks-script-LYyMNT
systemd-private-0c9d2a41d4b74ab38268e43c4db6a922-chronyd.service-Tf8wRr
systemd-private-42483447ed7541d988884261074ceee9-chronyd.service-RwUmSC
systemd-private-495d923bfde54bde85e7f8cb31ffeeb9-chronyd.service-OKksLw
systemd-private-b257d2d6865849aa9671e346ee2a8966-chronyd.service-P0VvcH
systemd-private-bb99b72d1da6407da31f4078908ac69e-chronyd.service-owVTTH
systemd-private-be5c91c4d3f2465cb0ad8f9350a51a4d-chronyd.service-TjpoQS
systemd-private-d9c4ac62008e4c55b9f52d3d8a4b0202-chronyd.service-rj7TG6
yum.log

文件的增删改查

新建文件touch

[root@localhost ~]# touch /a.txt
[root@localhost ~]# ls /
a.txt  boot  etc   lib    media  opt   root  sbin  sys  usr
bin    dev   home  lib64  mnt    proc  run   srv   tmp  var

修改文件也是用mv

注意:这里我都操作是在root不是在/,所以我使用命令时加的有/的绝对路径。

[root@localhost ~]# mv /a.txt /b.txt
[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# ls /
bin   b.txt  etc   lib    media  opt   root  sbin  sys  usr
boot  dev    home  lib64  mnt    proc  run   srv   tmp  var

在/下就就可以用相对路径的操作是这样的。

[root@localhost ~]# cd /
[root@localhost /]# mv b.txt c.txt
[root@localhost /]# ls
bin   c.txt  etc   lib    media  opt   root  sbin  sys  usr
boot  dev    home  lib64  mnt    proc  run   srv   tmp  var

查看还是ls

[root@localhost /]# ls c.txt
c.txt

删除文件rm,使用rm命令它会提示,不想提示就加-f

[root@localhost /]# rm c.txt
rm: remove regular empty file ‘c.txt’? y
[root@localhost /]# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
[root@localhost /]# touch a.txt
[root@localhost /]# ls
a.txt  boot  etc   lib    media  opt   root  sbin  sys  usr
bin    dev   home  lib64  mnt    proc  run   srv   tmp  var
[root@localhost /]# rm -f a.txt
[root@localhost /]# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

Linux基础命令练习

原文:https://www.cnblogs.com/wang977/p/12022722.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!