一些常用基础命令

查看类
    pwd : print name of current/working directory  打印当前工作目录;
         
          参数:
              -P :显示出确实的路径,而非使用链接 (link) 路径。

实例:

[[email protected] tmp]# pwd          #打印当前工作目录#
/tmp
[[email protected] var]# cd /var/mail
[[email protected] mail]# pwd         
/var/mail
[[email protected] mail]# pwd -P    
/var/spool/mail                #两条相同命令,加上-P结果有很大不同。原因在于var/ mail是链接

文件,链接的目标为/var/spool/mail.所以pwd -P最终显示结果为#

[[email protected] mail]# ls -al /var/mail
lrwxrwxrwx. 1 root root 10 Jan 16 16:24 /var/mail -> spool/mail
[[email protected] tmp]# echo $PWD    #显示$PWD与使用pwd命令基本相同#
/tmp

cd :Change the shell working directory 切换目录;
         
         .        代表当前目录;
         ..       代表上一层目录;
         -        代表前一个工作目录;
         ~        代表当前用户所在的家目录;
         ~account 代表account这个用户的家目录;

实例:

[[email protected] tmp]# cd /tmp     #进入/tmp目录
[[email protected] tmp]# 
[[email protected] tmp]# cd ~        #回到家目录,当前用户是rootr所以进入的为root的家目录#
[[email protected] ~]# 
[[email protected] ~]# cd -          #进入上一次工作目录#  
/tmp
[[email protected] tmp]#
[[email protected] tmp]# cd ..       #回到上级目录#
[[email protected] tmp]# 
ls : list directory contents 显示目录内容;

参数:
           -a : 显示全部的文件,包括隐藏文件并显示.与..目录;
           -A :显示全部的文件,包括隐藏文稿件但不包括.与..目录;
           -d :只显示目录的本身,不显示其目录内容;
           -h : 例出文件的大小;
           -l : 显示文件的详细文件属性信息;
           -n :列出 UID 与 GID 而非使用者与群组的名称;
           -F :根据文件、目录等信息提供附加数据结构;
              *:代表可执行文件; /:代表目录; =:代表 socket 档案; |:代表 FIFO 文件;@:表示链接文件
           -R :连同子目录所有内容一起显示出来;
           -S :以文件大小排序
      实例:

          [[email protected] var]# ls -alS
          total 16
          drwxr-xr-x. 25 root root 4096 Feb  7 09:48 lib
          drwxr-xr-x.  7 root root 4096 Feb  7 09:48 log
          drwxrwxrwt. 12 root root 4096 Feb  7 09:49 tmp
          drwxr-xr-x. 19 root root  267 Feb  7 09:48 .
          dr-xr-xr-x. 17 root root  224 Jan 16 16:34 ..
          -rw-r--r--.  1 root root  163 Jan 16 16:24 .updated
          drwxr-xr-x. 10 root root  118 Jan 16 16:29 spool
          drwxr-xr-x.  8 root root   92 Jan 16 16:29 cache
          drwxr-xr-x.  3 root root   34 Jan 16 16:29 db
          drwxr-xr-x.  3 root root   18 Jan 16 16:29 empty
          drwxr-xr-x.  3 root root   18 Jan 16 16:26 kerberos
          lrwxrwxrwx.  1 root root   11 Jan 16 16:24 lock -> ../run/lock
          lrwxrwxrwx.  1 root root   10 Jan 16 16:24 mail -> spool/mail
          drwxr-xr-x.  2 root root    6 Nov  5 23:38 adm

cat :concatenate files and print on the standard output 连结文件与打印标准输出;
          显示文件;创建文件;将多个文件合并为一个文件
          参数:
               -n : 对输出显示内容从1开始编号;
               -b : 与-n相同,但不对空白行编号;
               -e : 在每行结束显示 $ 。

实例:
                  [[email protected] var]# cat -ne /etc/sysconfig/network-scripts/ifcfg-ens33  
                  #显示此文件内容,对其内容进行编号并每行以$结尾 #

1  TYPE="Ethernet"$ 
2  BOOTPROTO="dhcp"$
3  DEFROUTE="yes"$
4  PEERDNS="yes"$
5  PEERROUTES="yes"$
6  IPV4_FAILURE_FATAL="no"$
7  IPV6INIT="yes"$
8  IPV6_AUTOCONF="yes"$
9  IPV6_DEFROUTE="yes"$
10  IPV6_PEERDNS="yes"$
11  IPV6_PEERROUTES="yes"$
12  IPV6_FAILURE_FATAL="no"$
13  IPV6_ADDR_GEN_MODE="stable-privacy"$
14  NAME="ens33"$
15  UUID="b0fc63a7-1b0a-4107-ae8e-07c73aa90004"$
16  DEVICE="ens33"$
17  ONBOOT="yes"$
         
[[email protected] var]# cat > /tmp/cat.txt <<EOF   #创建文件cat.txt,并以EOF字符结尾#
> Hello Everybody
> Welcome to the world of Linux
> Good Lock!
> EOF
[[email protected] var]# cat /tmp/cat.txt
Hello Everybody
Welcome to the world of Linux
Good Lock!
[[email protected] var]# cat /tmp/cat1.txt              #查看cat1.txt内容#
Ending
2017.02.07
[[email protected] var]# cat /tmp/cat.txt > /tmp/cat1.txt   #把cat.txt文件复制到cat1.txt中并覆盖原cat1.txt文件内容#
[[email protected] var]# cat /tmp/cat1.txt                  #查看cat1.txt内容#
Hello Everybody
Welcome to the world of Linux
Good Lock!
[[email protected] ~]# cat /tmp/cat.txt                  #查看cat.txt内容#
Hello Everybody
Welcome to the world of Linux
Good Lock!
[[email protected] ~]# cat /tmp/cat1.txt                 #查看cat1.txt内容#
Ending.
[[email protected] ~]# cat /tmp/cat1.txt >> /tmp/cat.txt  #把cat1.txt文件内容复制添中到cat.txt内容下方#
[[email protected] ~]# cat /tmp/cat.txt                   #查看cat.txt内容#
Hello Everybody
Welcome to the world of Linux
Good Lock!
Ending.
2017.02

tac : concatenate and print files in reverse  反向显示内容
             tac是将cat反写,所以它的功能就与cat相反。cat 从第一排到最后一排,tac是从最后一排到第一排。
             [[email protected] ~]# tac /tmp/cat.txt
             2017.02
             Ending.
             Good Lock!
             Welcome to the world of Linux
             Hello Everybody

head :output the first part of files 显示出前N行;
          参数:
               -n :n为数字,代表要从头开始显示几行。默认显示十行,-20为显示20行;
               [[email protected] ~]# head /etc/inittab          #显示文件的前十行#
                # inittab is no longer used when using systemd.
                #
                # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
                #
                # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
                #
                # systemd uses ‘targets‘ instead of runlevels. By default, there are two main targets:
                #
                # multi-user.target: analogous to runlevel 3
                # graphical.target: analogous to runlevel 5

tail : output the last part of files 显示文件后N行;
          参数:-n :n为数字,代表要从头开始显示几行。默认显示十行,-20为显示20行;
          [[email protected] ~]# tail /etc/inittab
          #
          # multi-user.target: analogous to runlevel 3
          # graphical.target: analogous to runlevel 5
          #
          # To view current default target, run:
          # systemctl get-default
          #
          # To set a default target, run:
          # systemctl set-default TARGET.target
          #

more : file perusal filter for crt viewing 翻页查看;
          参数:
              空格键 (space):代表向下翻一页;
              Enter         :代表向下翻【一行】;
              /字符串         :代表在这个显示的内容当中,向下搜寻【字符串】;
              :f             :立刻显示出文件名以及目前显示的行数;
              q             :代表立刻离开 more ,不再显示该文件内容。

less : 与more相似,less命令允许用户向前向后浏览文件,而more命令只能向前浏览。用PageUp键和Pagedown键翻页,按Q退出。
          cat 连续显示、查看文件内容
          more 分页查看文件内容
          less 分页可控制查看文件内容

tree : list contents of directories in a tree-like format. 分层树级结构显示内容
      [[email protected] ~]# tree /tmp
      /tmp
      ├── cat1.txt
      ├── cat.txt
      ├── systemd-private-9271cc4e10aa42e18e934ce49c91826b-vmtoolsd.service-NVM6f8
      │   └── tmp
      └── systemd-private-ac6dfc77c71646bd91b02da152e18f10-vmtoolsd.service-sia9xB
          └── tmp

4 directories, 2 files

file : determine file type 查看文件件类型

[[email protected] ~]# file /tmp/inittab
        /tmp/inittab: ASCII text

[[email protected] ~]# file /var/mail
        /var/mail: symbolic link to `spool/mail‘

修改类

touch : change file timestamps  创建空文件、改变文件时间
        -c: 指定的文件路径不存在时不予创建;
        -a: 仅修改access time;
        -m:仅修改modify time;
        -t STAMP
          [[CC]YY]MMDDhhmm[.ss]
    实例:
    [[email protected] tmp]# touch /tmp/test/1.txt
    [[email protected] tmp]# ls -l /tmp/test
    total 0
    -rw-r--r--. 1 root root 0 Feb 16 17:32 1.txt

mkdir:make directories 创建目录

-p: 自动按需创建父目录;
      -v: verbose,显示详细过程;
      -m MODE:直接给定权限;
    实例:
      [[email protected] tmp]# mkdir /tmp/2017
      [[email protected] tmp]# ls -al
      total 1464
      drwxrwxrwt. 10 root root     228 Feb 16 17:49 .
      dr-xr-xr-x. 17 root root     224 Feb 12 13:41 ..
      drwxr-xr-x.  2 root root       6 Feb 16 17:49 2017

创建多个目录

[[email protected] tmp]# mkdir ubuntu redhat slackware
      [[email protected] tmp]# ls -al
      total 1464
      drwxrwxrwt. 13 root root     273 Feb 16 17:54 .
      dr-xr-xr-x. 17 root root     224 Feb 12 13:41 ..
      drwxr-xr-x.  2 root root       6 Feb 16 17:49 2017
      drwxrwxrwt.  2 root root       6 Feb 16 10:51 .font-unix
      drwxrwxrwt.  2 root root       6 Feb 16 10:51 .ICE-unix
      -rw-r--r--.  1 root root     511 Feb 16 11:35 inittab
      -rw-------.  1 root root 1491821 Feb 15 22:25 messages
      drwxr-xr-x.  2 root root       6 Feb 16 17:54 redhat
      drwxr-xr-x.  2 root root       6 Feb 16 17:54 slackware
      drwxr-xr-x.  2 root root       6 Feb 16 17:54 ubuntu
   
      [[email protected] tmp]# mkdir -p ./1/2/3/
      [[email protected] tmp]# tree
      .
      ├── 1
      │   └── 2
      │       └── 3
      ├── 2017
      ├── inittab
      ├── messages
      ├── redhat
      ├── slackware
      ├── test
      │   └── 1.txt
      └── ubuntu

使用 -m 参数,我们可以给即将生成的新目录设置权限。
      [[email protected] ~]# mkdir -m=rw- rw
      [[email protected] ~]# ls -dl ./rw
      drw-r--r--. 2 root root 6 Feb 17 11:33 ./rw

[[email protected] ~]# mkdir -m=777 rwx
      [[email protected] ~]# ls -dl ./rwx
      drwxrwxrwx. 2 root root 6 Feb 17 11:40 ./rwx
      [[email protected] tmp]# mkdir -p -v -m 664 d1/d2/d3/d4
      mkdir: created directory ‘d1’
      mkdir: created directory ‘d1/d2’
      mkdir: created directory ‘d1/d2/d3’
      mkdir: created directory ‘d1/d2/d3/d4’

注意:路径基名方为命令的作用对象;基名之前的路径必须得存在;
    创建目录的首要条件是, 在想要创建目录的目标路径下你必须具有访问权限
        
    rmdir:remove empty directories

rmdir [OPTION]... DIRECTORY... 删除目录

-p:删除某目录后,如果其父目录为空,则一并删除之;
        -v: 显示过程;
      [[email protected] tmp]# mkdir -p a/b/c/d
      [[email protected] tmp]# tree
      .
      ├── a
      │   └── b
      │       └── c
      │           └── d
      ├── inittab
      ├── messages
      ├── redhat
      ├── slackware
      ├── test
      │   └── 1.txt
      └── ubuntu

10 directories, 3 files
      [[email protected] tmp]# rmdir -p -v a/b/c/d
      rmdir: removing directory, ‘a/b/c/d’
      rmdir: removing directory, ‘a/b/c’
      rmdir: removing directory, ‘a/b’
      rmdir: removing directory, ‘a’
 
   rm :  remove files or directories 删除或者目录

一不小心就下岗命令:rm -rf
      -f: 强制删除文件或目录;
      -i: 删除已有文件或者目录之前先询问用户;
      -r: 或-R递归处理,将指定目录下的所有文件与子目录一并处理;
      -v: 显示指令详细过程;

[[email protected] tmp]# rm -i -r -v 1/2/3/4
    rm: remove directory ‘1/2/3/4’? y
    removed directory: ‘1/2/3/4’

mv : mv - move (rename) files 移动
      --backup=<备份模式>:若需覆盖文件,则覆盖前先行备份; -b:当文件存在时,覆盖前,为其创建一个备份; -f:若目标文件或目录与现有的文件或目录重复,则直接覆盖现有的文件或目录;
       -i:交互式操作,覆盖前先行询问用户,如果源文件与目标文件或目标目录中的文件同名,则询问用户是否覆盖目标文件。用户输入”y”,表示将覆盖目标文件;输入”n”,表示取消对源文件的移动。这样可以避免误将文件覆盖。 --strip-trailing-slashes:删除源文件中的斜杠“/”;
       -S<后缀>:为备份文件指定后缀,而不使用默认的后缀;
       --target-directory=<目录>:指定源文件要移动到目标目录; -u:当源文件比目标文件新或者目标文件不存在时,才执行移动操作。

cp : mv - move (rename) files 复制
        -a:此参数的效果和同时指定"-dpR"参数相同; -d:当复制符号连接时,把目标文件或目录也建立为符号连接,并指向与源文件或目录连接的原始文件或目录; -f:强行复制文件或目录,不论目标文件或目录是否已存在;
        -i:覆盖既有文件之前先询问用户; -l:对源文件建立硬连接,而非复制文件; -p:保留源文件或目录的属性; -R/r:递归处理,将指定目录下的所有文件与子目录一并处理; -s:对源文件建立符号连接,而非复制文件; -u:使用这项参数后只会在源文件的更改时间较目标文件更新时或是名称相互对应的目标文件并不存在时,才复制文件; -S:在备份文件时,用指定的后缀“SUFFIX”代替文件的默认后缀; -b:覆盖已存在的文件目标前将目标文件备份;
         -v:详细显示命令执行的操作。

file : determine file type 确定文件类型

[[email protected] etc]# file /etc/inittab
        /etc/inittab: ASCII text

stat : stat - display file or file system status  显示文件元数据信息
      实例:
        [[email protected] etc]# stat /tmp
        File: ‘/tmp’
        Size: 4096        Blocks: 8          IO Block: 4096   directory
        Device: fd00h/64768d  Inode: 67160136    Links: 16
        Access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
        Context: system_u:object_r:tmp_t:s0
        Access: 2017-02-09 17:38:37.529189098 +0800
        Modify: 2017-02-09 17:38:28.661188955 +0800
        Change: 2017-02-09 17:38:28.661188955 +0800
         Birth: -

时间: 2025-01-01 00:42:52

一些常用基础命令的相关文章

Linux系统常用基础命令

Linux系统常用基础命令 cd->切换目录: pwd->显示当前所在的绝对目录; chmod->用于改变linux系统文件或目录的访问权限; ls->不仅可以查看linux文件夹包含的文件,而且可以查看文件权限(包括目录.文件夹.文件权限)查看目录信息等等; mkdir->创建文件夹; rm->删除一个目录中的一个或多个文件或目录; rmdir->从一个目录中删除一个或多个子目录项,删除某目录时也必须具有对其父目录的写权限;注意:不能删除非空目录; mv-&g

CentOS常用基础命令大全

这篇文章主要介绍了CentOS常用基础命令大全,学习centos的朋友需要掌握的知识,需要的朋友可以参考下 1.关机 (系统的关机.重启以及登出 ) 的命令shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdown -h hours:minutes & 按预定时间关闭系统 shutdown -c 取消按预定时间关闭系统 shutdown -r now 重启(1) reboot 重启(2) logout 注销2.查看系统信息的

linux公司常用基础命令必知必会

基础命令分为六部分来介绍,都是一些公司里常用的命令做了下汇总:◆ 安装和登录命令:login.shutdown.halt.reboot.install.mount.umount.chsh.exit.last:◆ 文件处理命令:file.mkdir.grep.dd.find.mv.ls.diff.cat.ln:◆ 系统管理相关命令:df.top.free.quota.at.lp.adduser.groupadd.kill.crontab:◆ 网络操作命令:ifconfig.ip.ping.nets

Linux常用基础命令

Linux基础命令 -----------------目录部分------------------- [pwd]显示当前所在的绝对目录 [cd] 切换目录 cd -  显示上一个工作目录 cd ~  显示当前用户的家目录 cd .  显示当前目录 cd .. 显示当前目录的上一级目录 [[email protected] ~]# cd /usr/ [[email protected] usr]# ls bin etc games include lib libexec local my sbin

MySQL 常用基础命令

一.启动与关闭 1.1 Linux下启动mysql 的命令: a. rpm包安装:service mysqld start b. 源码包安装:/usr/local/mysql/bin/mysqld_safe --user=mysql & 1.2 Linux下重启mysql 的命令: a. rpm包安装:service mysqld restart b. 源码包安装: 先关闭mysql /usr/local/mysql/bin/mysqladmin -uroot -p shutdown 再启动my

linux 常用基础命令 tar 详细介绍

[命令介绍] tar命令可以为linux的文件和目录创建档案.利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件.tar最初被用来在磁带上创建档案,现在,用户可以在任何设备上创建档案.利用tar命令,可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件或将几个文件组合成为一个文件以便于网络传输是非常有用的. 首先要弄清两个概念:打包和压缩. 打包是指将一大堆文件或目录变成一个总的文件: 压缩则是将一个大的文件通过一些压缩算法变成一个小文件.

linux 常用基础命令 cat 详细介绍

cat 输出文件内容: 命令说明:cat(Concatenate的缩写),一条linux内置命令,把一个或者多个文件连接在一起,并标准输出或输入.常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示.它常与重定向符号配合使用. 命令功能: a)  一次显示整个文件:catfilename b)  从键盘创建一个文件:cat> filename 只能创建新文件,不能编辑已有文件 c)  将几个文件合并为一个文件:catfile1 file2 > file 注: cat f

linux系统 常见/常用基础命令之 文件目录管理(创建,删除,查看,)

1.与路径相关命令: mkdir  创建目录命令,常用P选项,递增创建,mkdir -v,显示创建过程,mkdir -vp,显示创建过程与直接创建. tree   树状显示,tree -c   树状显示颜色. rmdir  只能删除目录 ,也可类似-vp(不能删除文件,只能删除空目录) rm     删除文件与目录, 加-r 对目录操作,再加上-f,去除询问是否删除(强制删除) cp     拷贝  对目录操作加 -r     rsync    也是拷贝 mv     移动或改名   覆盖时加绝

linux小白学习笔记(一)常用基础命令

ls                                    查看文件 (相当于dos下的dir)(其后可加路径,加 -a,可以查看隐藏文件) cd                                  改变当前路径(与dos下相同,cd +所在目录内文件夹名(相对路径),cd+/新路径(绝对路径),cd+..进入上个目录,cd进入根目录) clear                              清屏ls (相当于dos下的cle) 命令 “+ ”——he

linux 常用基础命令 vi

Vi 文本编辑器 1.  命令功能:vi是"visual interface"的缩写,vim是vi IMproved(增强版的vi).在Linux下的文本编辑器有很多种,vi (vim)是最常用的,也是各版本Linux的标配.注意:vi 仅仅是一个文本编辑器,可以给字符着色,可以自动补全,但是不像 Windows 下的 word 有排版功能.在一般的系统管理维护中vi就够用,如果想使用代码加亮的话可以使用vim. 2.  命令格式: [[email protected]~]#vi [选