1,Linux 上的文件管理类命令都有哪些, 其常用的使用方法及其相关示例演示.
cp: copy files and directories
单源复制: cp [options]... [-T] source dest
多源复制: cp [options]... source... Directory
- cp [option]... -t directory source
- mv: copy files and directories
- mv [OPTION]... [-T] SOURCE DEST
- mv [OPTION]... SOURCE... DIRECTORY
- mv [OPTION]... -t DIRECTORY SOURCE...
- rm: remove files or directories
- rm [OPTION]... FILE...
2, 使用命令行展开功能, 创建 / tmp/a1, /tmp/a2, /tmp/a1/a, /tmp/a1/b, 在 / tmp 目录下创建目录: x_y, x_z, q_y, q_z
- $mkdir -pv /tmp/{
- a1/{
- a,b
- },a2
- }
- mkdir: created directory '/tmp/a1'
- mkdir: created directory '/tmp/a1/a'
- mkdir: created directory '/tmp/a1/b'
- mkdir: created directory '/tmp/a2'
- $mkdir -pv /tmp/{
- x,q
- }_{
- y,z
- }
- mkdir: created directory '/tmp/a1'
- mkdir: created directory '/tmp/a1/a'
- mkdir: created directory '/tmp/a1/b'
- mkdir: created directory '/tmp/a2'
3, 文件的元数据信息有哪些, 分别表示什么含义, 如何查看? 如何修改文件的时间戳信息.
元数据: 用来描述一个文件的特征的数据 (metadata), 例如大小, 创建时间, 修改时间以及文件数据块的分布信息等等
使用 stat 查看文件的元数据
stat: display file or file system status
使用 touch 命令来修改文件的时间戳
touch: change file timestamps
例如:
$ touch timetest.file 创建一个新文件
- ]$ stat timetest.file
- File: 'timetest.file'
- Size: 0 Blocks: 0 IO Block: 4096 regular empty file
- Device: fd00h/64768d Inode: 16803168 Links: 1
- Access: (0664/-rw-rw-r--) Uid: ( 1000/donguser) Gid: ( 1000/donguser)
- Context: unconfined_u:object_r:user_tmp_t:s0
- Access: 2019-07-14 17:30:26.385935252 +0800
- Modify: 2019-07-14 17:30:26.385935252 +0800
- Change: 2019-07-14 17:30:26.385935252 +0800
- Birth: -
修改 access time
- touch -at 190701020304.05 timetest.file
- [[email protected] tmp]$ stat timetest.file
- File: 'timetest.file'
- Size: 0 Blocks: 0 IO Block: 4096 regular empty file
- Device: fd00h/64768d Inode: 16803168 Links: 1
- Access: (0664/-rw-rw-r--) Uid: ( 1000/donguser) Gid: ( 1000/donguser)
- Context: unconfined_u:object_r:user_tmp_t:s0
- Access: 1907-01-02 03:04:05.000000000 +0800
- Modify: 2019-07-14 17:30:26.385935252 +0800
- Change: 2019-07-14 17:34:25.229921679 +0800
- Birth: -
修改 modify time, 使用 - m
change time 不能修改
4, 在 / tmp 目录下创建以 tfile 开头, 后跟当前日期和时间的文件, 文件名形如: tfile-2016-05-27-09-32-22.
touch tfile-$(date +%Y-%m-%d-%H-%M-%S)
5, 复制 / etc 目录下所有以 p 开头, 以非数字结尾的文件或目录到 / tmp/mytest1 目录中.
- mkdir /temp/mytest1/
- cp -r /etc/p*[^0-9] /tmp/mytest1
6, 创建用户 tom, 指定 UID 为 5001, 指定家目录为 / tmp/tom, 指定 shell 为 / bin/zsh, 指定基本组为 tom, 附加组为 jack
- # groupadd jack
- # useradd -u 5001 -d /tmp/tom -s /bin/szh -G jack tom
- # tail -n 1 /etc/passwd
- tom:x:5001:5004::/tmp/tom:/bin/szh
7, 常用的用户以及文件管理命令有哪些, 并演示命令以及用法.
用户管理命令:
useradd: 创建用户 adduser create a new user or update default new user information
-u: uid
-g : group id 指定基本组 ID, 此组要存在
-c : comment - - comment
-G --groups 指明用户所属的附加组, 多个组之间用, 隔开
-d : home - - home 通过复制 / etc/skel 此目录并重命名实现, 指定的家目录路径事先 存在, 则不会为用户复制环境配置文件
-s: shell --shell 指明 shell 指定的默认 shell, 而可用的 shell 列表在 / etc/shells 文件
-r: system --system 创建系统用户
-M: 不创建用户主目录
usermod: 修改用户属性
-u: uid
-g: 修改基本组 gid
-G -groups 修改用户所属的附加组, 原来的附加组会被覆盖
-a: append --append 与 -G 一同使用
-c - - comment
-d - - home : 一般和 - m 一同使用, 会移动用户原有的文件
- -l - - login name
- -s - - shell
-L - - lock: 锁定用户密码, 在用户原密码前加一个 "!"
-U - - unlock 解锁用户的密码
userdel: 删除用户
-r 删除用户时一并删除其家目录
组管理命令:
- groupadd: group [option] groupname
- -g : gid
- -r: system group id: 1-999
groupmod: 修改组属性
- -g : gid
- -n: name
groupdel: 删除组
描述 Linux 目录结构以及目录结构命名规定
- bin: Essential command binaries
- boot: Static files of the boot loader
- dev: Device files
- etc: Host-specific system configuration
- lib: Essential shared libraries and kernel modules
- media: Mount point for removable media
- mnt: Mount point for mounting a filesystem temporarily
- opt: Add-on application software packages
- run: Data relevant to running processes
- sbin: Essential system binaries
- srv: Data for services provided by this system
- tmp: Temporary files
- usr: Secondary hierarchy
- var:Variable data
来源: http://www.bubuko.com/infodetail-3123578.html