linux的基本命令1

一.linux文件基本操作指令1

1.命令分类

内部命令:shell自身集成的

外部命令:需要安装工具才能使用的

使用type命令可以查看命令类型
[root@localhost boss01]# type cd
cd is a shell builtin
[root@localhost boss01]# type type
type is a shell builtin
[root@localhost boss01]# type mkdir
mkdir is /bin/mkdir

2.文件的基本操作指令

a.判断文件类型命令file
linux下有如下文件类型
-d 目录
-f 普通文件
-b 块文件,所有存储设备
-c 字符文件,所有输入输出设备
-l 链接文件
-p 管道文件
-s socket文件

案例
[root@localhost boss01]# file /home/
/home/: directory
[root@localhost boss01]# file /etc/passwd
/etc/passwd: ASCII text
[root@localhost dev]# file /dev/vcs
/dev/vcs: character special
[root@localhost dev]# file /dev/ram0
/dev/ram0: block special

b.ls列出目录内容
常见选项
-a    查看目录下的所有文件,包括隐藏文件
-l    长列表显示
-h    以人性化方式显示文件的大小
-d    只列出目录名,不列出目录下的文件
-t    按修改时间排序,最新事件在最前
-r    逆序排列
-S    按文件的大小排序,从大到小
-i    显示文件的inode号(索引号)
-R	   递归列出目录中的内容
-m    用逗号分隔显示内容

案例
[root@localhost tmp]# ls
test
[root@localhost tmp]# ls -l
total 0
-rw-r--r--. 1 root root 0 Mar  6 16:52 test
[root@localhost tmp]# ls -lrt /root/
total 108
-rw-r--r--. 1 root root 53013 Mar  4 15:39 install.log
drwxr-xr-x. 2 root root  4096 Mar  4 15:56 Videos
drwxr-xr-x. 2 root root  4096 Mar  4 15:56 Templates
drwxr-xr-x. 2 root root  4096 Mar  4 15:56 Public
drwxr-xr-x. 2 root root  4096 Mar  4 15:56 Pictures
drwxr-xr-x. 2 root root  4096 Mar  4 15:56 Music
drwxr-xr-x. 2 root root  4096 Mar  4 15:56 Downloads
drwxr-xr-x. 2 root root  4096 Mar  4 15:56 Documents
drwxr-xr-x. 2 root root  4096 Mar  4 15:56 Desktop
drwxr-xr-x. 3 root root  4096 Mar  6 16:49 b
c.创建目录(mkdir)
mkdir 目录名
[root@localhost tmp]# mkdir songxiaolong
创建级联目录
mkdir -p 目录路径
[root@localhost tmp]# mkdir -p ./a/b/c
[root@localhost tmp]# ll -d a/b/c/
drwxr-xr-x. 2 root root 4096 Mar  7 08:54 a/b/c/
d.创建文件(touch)
touch 文件名 或  touch file1 fil2..  或touch file{1..5}

[root@localhost tmp]# touch file{1..4}
[root@localhost tmp]# touch fil5 fil6


stat可以查看文件的状态信息
[root@localhost tmp]# stat fil6
  File: `fil6'
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d	Inode: 929842      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-03-07 08:57:17.877829660 +0800   acess为文件最后一次访问时间
Modify: 2019-03-07 08:57:17.877829660 +0800   modify为文件最后一次修改时间
Change: 2019-03-07 08:57:17.877829660 +0800   change为文件属性时间

touch还可以修改文件的时间
touch 已存在的文件名   会修改文件的以上3个时间

[root@localhost tmp]# touch -a file1 -t 201903070920    修改文件点访问时间
[root@localhost tmp]# touch -m file1 -t 201903061330    修改文件修改时间

[root@localhost tmp]# touch -d "20190306 14:30:30" file1  修改文件日志和时间,可以分开修改
e.查看文件内容

cat/tac

more/less

head/tail head -n 展示文件前n行,不加-n默认展示前10行;tail -n同head,但从文件末尾想前展示,tail -f 常用语查看动态文件

ldd

案例
[root@localhost tmp]# cat file1
12345
hello
[root@localhost tmp]# head -1 file1
12345
[root@localhost tmp]# tail -1 file1
hello

f.拷贝文件(cp)

格式: cp [选项] 要拷贝的文件  要拷贝的目的地
常用选项:
-a			递归拷贝文件,包括目录及文件属性信息
-r			拷贝目录
-p			拷贝文件包含文件的属性信息
-v			显示拷贝过程信息

案例如下
[root@localhost tmp]# cp -a /etc/passwd /tmp/
[root@localhost tmp]# ll /tmp/passwd 
-rw-r--r--. 1 root root 2184 Nov 11  2020 /tmp/passwd
[root@localhost tmp]# cp -r /home/inst01/  /tmp/
[root@localhost tmp]# ll -d /tmp/inst01/
drwx------. 4 root root 4096 Mar  7 09:10 /tmp/inst01/
g.移动或重命名文件(mv)
移动文件用法(不同路径下):
# mv 需要移动的文件  移动到新的路径下
注意:文件的路径不一样
[root@localhost tmp]# mv /tmp/file1  /home/
[root@localhost tmp]# ll /home/file1 
-rw-r--r--. 1 root root 12 Mar  7 09:04 /home/file1

重命名用法(相同路径下):
# mv 原来文件的名字  新文件的名字
[root@localhost tmp]#  mv file2 new_file2
[root@localhost tmp]# ll new_file2 
-rw-r--r--. 1 root root 0 Mar  7 08:51 new_file2

h.删除文件(rm)
格式:rm [选项] 要删除的文件
-r 递归,删除目录
-f 强制删除,不提示

[root@localhost tmp]# rm -r songxiaolong/
rm: remove directory `songxiaolong'? y
[root@localhost tmp]# 
[root@localhost tmp]# rm -rf file3
[root@localhost tmp]# ll file3
ls: cannot access file3: No such file or directory

二.如何获取帮助

1.help命令

命令 --help或help 命令

2.man 命令

# man man 
       ANUAL SECTIONS
       The standard sections of the manual include:
       1      User Commands         				所有用户使用命令
       2      System Calls                		系统调用
       3      C Library Functions   				函数库
       4      Devices and Special Files  			设备与特殊文件
       5      File Formats and Conventions      文档格式说明
       6      Games et. Al.     						游戏
       7      Miscellanea        					杂项
       8      System Administration tools and Deamons       系统管理员与程序用户相关
       
# man -f passwd               列出所有章节中的passwd手册
# man 1 passwd                passwd命令的帮助
# man 5 passwd                用户配置文件的帮助
# man -a passwd    				在所有章节中查找
# man -k passwd  					以关键字导出man page

程序猿手册  man 23467 
管理员手册  man 158

三.Bash的标准输入输出

1.名词解释

标准输入(stdin):键盘上的输入 文件描述符—0

标准输出(stdout):屏幕上正确的输出 文件描述符—1

标准错误(stderr):屏幕上错误的输出 文件描述符—2

扫描二维码关注公众号,回复: 5730563 查看本文章

2.相关符号

>:标准输出重定向,==覆盖==重定向,`1>或>`标准输出重定向,`2>`标准错误重定向
>>:重定向追加,`1>>`标准输出追加,`2>>`标准错误追加
<:标准输入
&>:标准输出标准错误重定向

[root@localhost tmp]# cat passwd >file5
[root@localhost tmp]# aaa 2> file6
[root@localhost tmp]# cat file6
bash: aaa: command not found
[root@localhost tmp]# 

3.echo命令

echo会将输入的字符串送往标准输出,并换行

常见选项:
-n :不输出最后的换行符“\n”
-e:解释转义字符(字符串中出现\n、\t等特殊字符,则特别加以处理,而不会将它当成一般文字输出)

[root@localhost tmp]# echo hello
hello
[root@localhost tmp]# echo -n hello
hello[root@localhost tmp]# 

猜你喜欢

转载自blog.csdn.net/sxlong_work/article/details/88764923