Linux常用命令(01)

1.pwd

查看当前所在的位置 print working directory

查看当前root用户默认所在的位置
[root@centos ~]# pwd 输入命令
/root	 显示绝对路径
[root@centos ~]# 

2.ls

 ls      # 列出当前目录看下所有的文件

语法格式:
ls  直接回车  # 显示当前所在目录下所有的文件
ls  目录      # 指定显示某个目录下所有的文件
参数选项: ls -l 显示文件的详细信息
ls -l 有个外号: ll 当我们执行ll时实际系统为我们执行的是ls -l
        
注意: 以颜色区分 白色的为普通文件 类似windows的.txt文件
      蓝色为目录
	  
ls 直接回车 查看当前

[root@centos ~]# ls
anaconda-ks.cfg
[root@centos ~]# 


ls 指定查看/目录下所有文件 # / 根目录
[root@centos ~]# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
[root@centos ~]#

3.cd

切换路径 change directory
语法结构:
		 cd  目录
		 cd  /目录/目录/目录

案例

 进入到/opt目录 绝对路径
# 注意空格
[root@centos ~]# cd /opt/
[root@centos opt]# cd / opt
[root@centos /]# pwd
/
[root@centos /]# cd / opt fiejf fjwifj afjie
[root@centos /]# 
[root@centos /]# 

[root@centos /]# cd /o pt
-bash: cd: /o: No such file or directory
[root@centos opt]# cd
进入到深层目录/etc/sysconfig/
[root@centos ~]# cd /etc/sysconfig/
[root@centos sysconfig]# pwd
/etc/sysconfig
[root@centos sysconfig]# 
然后快速回到家目录
方法1: cd直接回车
[root@centos sysconfig]# cd
[root@centos ~]# 
方法2: 使用绝对路径回家
[root@centos sysconfig]# pwd
/etc/sysconfig
[root@centos sysconfig]# cd /root
[root@centos ~]# pwd
/root
方法3: 使用~回家
[root@centos sysconfig]# cd ~
[root@centos ~]# 

4.mkdir

创建目录 make directory语法结构:
	   mkdir  zzz                     # 在当前创建zzz目录
	   mkdir -p zzz/test/www    # 创建多级目录

案例

 在当前目录创建一个test目录

[root@centos ~]# mkdir test
[root@centos ~]# ll
total 8
-rw-------. 1 root root 1522 Feb 22 16:41 anaconda-ks.cfg
-rw-r--r--. 1 root root  158 Feb 24 10:55 hosts
drwxr-xr-x. 2 root root    6 Feb 24 11:18 test

[root@centos ~]# mkdir test
mkdir: cannot create directory ‘test’: File exists

mkdir 无法创建目录test 文件已存在

5.touch

创建普通文件 摸 类似windows创建的txt文档
         如果不存在则创建
         如果文件存在则更新文件的时间,不影响文件内容
  语法结构:
  		  touch 文件   # 在当前创建一个文件
  		  touch 文件1 文件2 文件3  # 一次创建多个文件
  		  touch /opt/test.txt   # 在指定目录下创建test.txt

案例

 在当前创建一个test.txt
[root@centos ~]# touch test.txt
[root@centos ~]# 
[root@centos ~]# ll
total 0
-rw-r--r--. 1 root root 0 Feb 24 12:00 test.txt

6.tree

tree命令: 
# 语法结构:    tree 目录/路径
[root@centos ~]# tree /opt/
/opt/
├── bbs
│   ├── 1.txt
│   └── 2.txt
├── blog
│   ├── 1.txt
│   └── 2.txt
└── www
    ├── 1.txt
    └── 2.txt

3 directories, 6 files

# -L显示最大深度等级为1级(默认显示所有的深度)
[root@centos ~]# tree -L 1 /opt/
/opt/
├── bbs
├── blog
└── www

7.帮助手册man help

#### 1.man cp

man   空格 命令
空格: 一次翻一页
f   : 一次往下翻一页
b   : 一次网上翻一页
↓  : 一次一行
↑  : 一次一行
q  : 退出帮助 quit

#### 2.help

help cd

8.shutdown

[root@centos ~]# shutdown		# 关机
[root@centos ~]# poweroff	    # 立刻关机
[root@centos ~]# halt		    # 立刻关机
[root@centos ~]# init 0          # 立刻关机
[root@centos ~]# reboot			# 重启操作系统



[root@centos ~]# shutdown -c     # 取消关机
[root@centos ~]# shutdown -h 5   # 5分钟后关机
[root@centos ~]# shutdown -h now # 立刻关机

9.重启

reboot 

init 6 

shutdown -r
posted @ 2024-01-21 18:24  只为心情愉悦  阅读(7)  评论(0编辑  收藏  举报