Linux常用指令

这篇博客详细介绍了Linux系统中的文件目录管理、系统管理、用户管理、权限管理、资源管理和包管理等核心命令,包括ls、cd、mkdir、rm、cat、more、less、vi/vim、man、history、sudo、useradd、passwd、chown、chmod等,帮助读者掌握Linux日常操作。
摘要由CSDN通过智能技术生成

LINUX(二)

3. Linux命令

2.1 文件目录管理

2.1.1 目录操作

pwd 显示当前目录

print name of current/working directory

  • 示例
[root@CSDN ~]# pwd
/root
ls 列出目录内容

list directory contents

  • 语法
ls [参数] [FILE]
  • 参数
-a, --all #显示所有文件包含隐藏文件
-l 		  #显示详细信息
-h		  #可读性增强 
-t 		  #按时间排序 #ls -lt按时间倒序 
-r 		  #reverse 翻转 #ls -lrt 按时间升序 
-R        #recursive 递归性,一层层显示所有文件包含子目录的文件
  • 示例
[root@CSDN ~]# ls
anaconda-ks.cfg  Downloads           Music     Templates
Desktop          install.log         Pictures  Videos
Documents        install.log.syslog  Public

[root@CSDN ~]# ls -l
# ls -l的别名是ll
total 100
-rw-------. 1 root root  1614 Mar 30 23:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root  4096 May 14 11:51 Desktop
drwxr-xr-x. 2 root root  4096 May 14 11:51 Documents
drwxr-xr-x. 2 root root  4096 May 14 11:51 Downloads

[root@CSDN ~]# ll -h
total 100K
-rw-------. 1 root root 1.6K Mar 30 23:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K May 14 11:51 Desktop
drwxr-xr-x. 2 root root 4.0K May 14 11:51 Documents
drwxr-xr-x. 2 root root 4.0K May 14 11:51 Downloads

[root@CSDN ~]# ll -t
total 100
drwxr-xr-x. 2 root root  4096 May 14 11:51 Documents
drwxr-xr-x. 2 root root  4096 May 14 11:51 Downloads
drwxr-xr-x. 2 root root  4096 May 14 11:51 Music
drwxr-xr-x. 2 root root  4096 May 14 11:51 Pictures

[root@CSDN ~]# ll -R
.:
total 100
-rw-------. 1 root root  1614 Mar 30 23:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root  4096 May 14 11:51 Desktop
drwxr-xr-x. 2 root root  4096 May 14 11:51 Documents
drwxr-xr-x. 2 root root  4096 May 14 11:51 Downloads
-rw-r--r--. 1 root root 46562 Mar 30 23:54 install.log
-rw-r--r--. 1 root root 10031 Mar 30 23:52 install.log.syslog
drwxr-xr-x. 2 root root  4096 May 14 11:51 Music
drwxr-xr-x. 2 root root  4096 May 14 11:51 Pictures
drwxr-xr-x. 2 root root  4096 May 14 11:51 Public
drwxr-xr-x. 2 root root  4096 May 14 11:51 Templates
drwxr-xr-x. 2 root root  4096 May 14 11:51 Videos

./Desktop:
total 0

./Documents:
total 0

./Downloads:
total 0

./Music:
total 0

./Pictures:
total 0

./Public:
total 0

./Templates:
total 0

./Videos:
total 0

[root@CSDN ~]# ll -rt
total 100
-rw-r--r--. 1 root root 10031 Mar 30 23:52 install.log.syslog
-rw-r--r--. 1 root root 46562 Mar 30 23:54 install.log
-rw-------. 1 root root  1614 Mar 30 23:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root  4096 May 14 11:51 Desktop
drwxr-xr-x. 2 root root  4096 May 14 11:51 Videos
drwxr-xr-x. 2 root root  4096 May 14 11:51 Templates
drwxr-xr-x. 2 root root  4096 May 14 11:51 Public
drwxr-xr-x. 2 root root  4096 May 14 11:51 Pictures
drwxr-xr-x. 2 root root  4096 May 14 11:51 Music
drwxr-xr-x. 2 root root  4096 May 14 11:51 Downloads
drwxr-xr-x. 2 root root  4096 May 14 11:51 Documents
  • 第一列
    • 第一位:文件类型
      • -:普通文件
      • d:directory :目录(文件夹)
      • c:character 字符设备(如屏幕输入文字)
      • b:block 块设备(如硬盘或者分区)
      • l:快捷方式 link
    • 第二-第十位:权限位
    • 第十一位:ACL(访问控制列表,高级权限位)
  • 第二列:
    • 文件:硬链接数+1
    • 目录:第一级子目录数
  • 第三列:所属用户
  • 第四列:所属组
  • 第五列
    • 文件:大小
    • 文件夹:目录本身大小,不含内容
  • 第六列:访问或修改时间
  • 第七列:文件名(文件夹名)
cd 切换目录

Change the shell working directory.

  • 语法
cd [DIR] 
cd 绝对路径 #如 cd /boot 
cd 相对路径 #如 cd boot #前提你在/下 
cd - #从哪里来回哪里去 
cd #回家 
cd ~ #回家 
cd ~用户名 #切换到指定用户的家目录下
  • 绝对路径:以/开头,/代表根目录
  • 相对路径:不以/开头,相对于当前目录位置
    • 点(.):代表当前目录
    • 点点(…):代表上级目录(父目录)
      • 只有/没有父目录
  • 所有的命令中都可以对文件或目录用相对路径或绝对路径来表示,跟cd命令无关
  • 示例
    • 切换到/boot,显示当前目录,显示当前目录下的所有内容的详细信息
    • 不进行切换,显示/var/log目录下的所有内容的详细信息
[root@CSDN ~]# cd /boot
[root@CSDN boot]# pwd
/boot
[root@CSDN boot]# ll -a
total 33126
dr-xr-xr-x.  5 root root     1024 Mar 30 23:53 .
dr-xr-xr-x. 25 root root     4096 May 14 11:50 ..
-rw-r--r--.  1 root root   108164 Mar 22  2017 config-2.6.32-696.el6.x86_64
drwxr-xr-x.  3 root root     1024 Mar 30 23:52 efi
drwxr-xr-x.  2 root root     1024 Mar 30 23:54 grub
-rw-------.  1 root root 26667930 Mar 30 23:54 initramfs-2.6.32-696.el6.x86_64.img
drwx------.  2 root root    12288 Mar 30 23:46 lost+found
-rw-r--r--.  1 root root   215634 Mar 22  2017 symvers-2.6.32-696.el6.x86_64.gz
-rw-r--r--.  1 root root  2622364 Mar 22  2017 System.map-2.6.32-696.el6.x86_64
-rwxr-xr-x.  1 root root  4274992 Mar 22  2017 vmlinuz-2.6.32-696.el6.x86_64
-rw-r--r--.  1 root root      166 Mar 22  2017 .vmlinuz-2.6.32-696.el6.x86_64.hmac

[root@CSDN boot]# ll /var/log/
total 1408
-rw-------. 1 root root   2368 Mar 30 23:54 anaconda.ifcfg.log
-rw-------. 1 root root  22563 Mar 30 23:54 anaconda.log
-rw-------. 1 root root  35814 Mar 30 23:54 anaconda.program.log
-rw-------. 1 root root 109997 Mar 30 23:54 anaconda.storage.log
-rw-------. 1 root root 118704 Mar 30 23:54 anaconda.syslog
-rw-------. 1 root root  28879 Mar 30 23:54 anaconda.xlog
-rw-------. 1 root root 121828 Mar 30 23:54 anaconda.yum.log
drwxr-x---. 2 root root   4096 Mar 30 23:56 audit
-rw-r--r--. 1 root root   2362 May 14 11:50 boot.log
-rw-------. 1 root utmp      0 Mar 30 23:49 btmp
drwxr-xr-x. 2 root root   4096 Mar 30 23:56 ConsoleKit
-rw-------. 1 root root   1423 May 14 11:50 cron
drwxr-xr-x. 2 lp   sys    4096 Mar 22  2017 cups
-rw-r--r--. 1 root root  69331 May 14 11:50 dmesg
-rw-r--r--. 1 root root  69331 May 14 11:32 dmesg.old
-rw-r--r--. 1 root root 240142 Mar 30 23:54 dracut.log
drwxrwx--T. 2 root gdm    4096 May 14 11:50 gdm
drwx------. 2 root root   4096 Mar 22  2017 httpd
-rw-r--r--. 1 root root 145708 May 14 11:52 lastlog
-rw-------. 1 root root   1274 May 14 11:50 maillog
-rw-------. 1 root root 322019 May 14 11:52 messages
drwxr-xr-x. 2 ntp  ntp    4096 Feb  6  2017 ntpstats
-rw-r--r--. 1 root root     89 May 14 11:50 pm-powersave.log
drwx------. 2 root root   4096 Mar 16  2015 ppp
drwxr-xr-x. 2 root root   4096 Aug 19  2013 prelink
drwxr-xr-x. 2 root root   4096 May 14 11:32 sa
drwx------. 3 root root   4096 Mar 30 23:49 samba
-rw-------. 1 root root   7990 May 14 11:52 secure
-rw-------. 1 root root      0 Mar 30 23:56 spice-vdagent.log
-rw-------. 1 root root      0 Mar 30 23:50 spooler
drwxr-x---. 2 root root   4096 Mar 23  2017 sssd
-rw-------. 1 root root      0 Mar 30 23:48 tallylog
-rw-r--r--. 1 root root      0 Mar 30 23:56 wpa_supplicant.log
-rw-rw-r--. 1 root utmp  29952 May 14 11:52 wtmp
-rw-r--r--. 1 root root  58244 May 14 11:57 Xorg.0.log
-rw-r--r--. 1 root root  59418 May 14 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大肠干挑面多加蒜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值