Linux基本命令-02-文件管理
程序员文章站
2024-01-31 12:20:04
...
1.touch:创建文件或更新文件修改时间。
touch a.txt
[aaa@qq.com ~]# touch a.txt
[aaa@qq.com ~]# ls
anaconda-ks.cfg a.txt initial-setup-ks.cfg
2.cp:复制文件或文件夹
cp a.txt /home
[aaa@qq.com ~]# cp a.txt /home
[aaa@qq.com ~]# cd /home
[aaa@qq.com home]# ls
a.txt Z
如果复制的是文件夹则需要添加参数-r
cp -r file home/
如果复制的过程中有同名的文件则可以使用-f进行强制覆盖。
在Linux中为什么加了-f但是没有效果?
取消别名:\命令
\cp -rf file home/
3.mv:移动文件或文件夹
mv=move
mv 文件名 路径名
mv 文件名1 文件名2
[aaa@qq.com ~]# mv b.txt /home
[aaa@qq.com ~]# cd /home
[aaa@qq.com home]# ls
a.txt b.txt Z
4.rm:删除文件或文件夹
rm=remove
rm 文件名
[aaa@qq.com home]# rm a.txt
rm:是否删除普通空文件 "a.txt"?y
[aaa@qq.com home]# ls
b.txt Z
关掉提示警告: rm -f 文件名
[aaa@qq.com home]# rm -f b.txt
[aaa@qq.com home]# ls
Z
删除文件夹: rm -r 文件夹
[aaa@qq.com home]# mkdir file
[aaa@qq.com home]# ls
file Z
[aaa@qq.com home]# rm -r file
rm:是否删除目录 "file"?y
[aaa@qq.com home]# ls
Z
rm -rf 文件夹
[aaa@qq.com home]# mkdir file
[aaa@qq.com home]# ls
file Z
[aaa@qq.com home]# rm -rf file
[aaa@qq.com home]# ls
Z
5.cat:查看文件内容
more(也是查看,查看一大部分)和less(q=quit)(查看文件内容的一小部分)
[aaa@qq.com ~]# more anaconda-ks.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw --iscrypted $6$UhaJsq1A.IxwFwZN$joqiwlFqQz0PzvYKjYCKMfawvd4PgyQJikvXjUPhZguknzXoe7CVtPOu3vE7j041Ae.m4BOvlF1.Ppt
h9oMyE/
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --all --drives=sda
#part /boot --fstype=ext4 --size=500
#part pv.008002 --grow --size=1
#volgroup vg_leitingyan --pesize=4096 pv.008002
#logvol / --fstype=ext4 --name=lv_root --vgname=vg_leitingyan --grow --size=1024 --maxsize=51200
#logvol swap --name=lv_swap --vgname=vg_leitingyan --grow --size=2048 --maxsize=2048
%packages
@base
@client-mgmt-tools
@core
@debugging
@basic-desktop
@desktop-debugging
head(从文件头开始查看)和tail(从文件的尾开始查看)
[aaa@qq.com ~]# head anaconda-ks.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw --iscrypted $6$UhaJsq1A.IxwFwZN$joqiwlFqQz0PzvYKjYCKMfawvd4PgyQJikvXjUPhZguknzXoe7CVtPOu3vE7j041Ae.m4BOvlF1.Ppth9oMyE/
firewall --service=ssh
[aaa@qq.com ~]# tail anaconda-ks.cfg
genisoimage
device-mapper-persistent-data
abrt-gui
samba-winbind
certmonger
pam_krb5
krb5-workstation
libXmu
perl-DBD-SQLite
%end[aaa@qq.com ~]#
注意:这个tail命令可以用来跟踪日志。
6.grep:筛选
cat anaconda-ks.cfg | grep file
%end[aaa@qq.com ~]# cat anaconda-ks.cfg | grep file
# Kickstart file automatically generated by anaconda.
@network-file-system-client
[aaa@qq.com ~]#
上一篇: 抽象思想解读Linux进程描述符
下一篇: Admin-02 Linux系统