Linux系列:文件相关操作
1.查看文件
cat:查看小文件
more:按空格翻页查看;按Enter行查看;按Q退出
less:按空格翻页查看;按Enter行查看;P往回看;F往后看
head:查看前几行,默认前十行
tail:查看尾几行,默认尾部十行
[root@centos-master test]# less test.txt [root@centos-master test]# less test.txt [root@centos-master test]# head test.txt test! ot@centos-master ~]# history 1 2020-10-25 21:03:39 2 2020-09-17 20:43:52 ls[root@centos-master ~]# history 1 2020-10-25 21:03:39 2 2020-09-17 20:43:52 ls 3 2020-09-17 20:43:54 ls 4 2020-09-17 20:43:57 cd / 5 2020-09-17 20:43:58 ls 6 2020-09-17 20:50:31 cd / [root@centos-master test]# tail test.txt simple, never always make simple backups As a special case, cp makes a backup of SOURCE when the force and backup options are given and SOURCE and DEST are the same name for an existing, regular file. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'cp invocation' [root@centos-master test]# [root@centos-master test]# head -5 test.txt test! ot@centos-master ~]# history 1 2020-10-25 21:03:39 2 2020-09-17 20:43:52 ls[root@centos-master ~]# history 1 2020-10-25 21:03:39 [root@centos-master test]# tail -1 test.txt [root@centos-master test]#
2.移动、重命名:mv
[root@centos-master test]# mkdir testone [root@centos-master test]# ls testone [root@centos-master test]# mv testone/ testtwo [root@centos-master test]# ls testtwo [root@centos-master test]# mkdir dir1 [root@centos-master test]# mv testtwo/ dir1/ [root@centos-master test]# tree . `-- dir1 `-- testtwo 2 directories, 0 files [root@centos-master test]# mv --help Usage: mv [OPTION]... [-T] SOURCE DEST or: mv [OPTION]... SOURCE... DIRECTORY or: mv [OPTION]... -t DIRECTORY SOURCE... Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. Mandatory arguments to long options are mandatory for short options too. --backup[=CONTROL] make a backup of each existing destination file -b like --backup but does not accept an argument -f, --force do not prompt before overwriting -i, --interactive prompt before overwrite -n, --no-clobber do not overwrite an existing file If you specify more than one of -i, -f, -n, only the final one takes effect. --strip-trailing-slashes remove any trailing slashes from each SOURCE argument -S, --suffix=SUFFIX override the usual backup suffix -t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY -T, --no-target-directory treat DEST as a normal file -u, --update move only when the SOURCE file is newer than the destination file or when the destination file is missing -v, --verbose explain what is being done -Z, --context set SELinux security context of destination file to default type --help display this help and exit --version output version information and exit The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values: none, off never make backups (even if --backup is given) numbered, t make numbered backups existing, nil numbered if numbered backups exist, simple otherwise simple, never always make simple backups GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'mv invocation' [root@centos-master test]#
3.硬链接、软连接:ln
ln file1 file2 硬链接
ln -s file1 file2 软链接
目录是不能创建硬链接的
[root@centos-master test]# vim hello.c [root@centos-master test]# ls hello.c [root@centos-master test]# cat hello.c hello world! [root@centos-master test]# ln hello.c hello2.c [root@centos-master test]# ls hello2.c hello.c [root@centos-master test]# cat hello2.c hello world! [root@centos-master test]# ls -l total 8 -rw-r--r-- 2 root root 13 Dec 8 21:27 hello2.c -rw-r--r-- 2 root root 13 Dec 8 21:27 hello.c [root@centos-master test]# touch test.txt [root@centos-master test]# ls -l total 8 -rw-r--r-- 2 root root 13 Dec 8 21:27 hello2.c -rw-r--r-- 2 root root 13 Dec 8 21:27 hello.c -rw-r--r-- 1 root root 0 Dec 8 21:29 test.txt [root@centos-master test]# ln hello.c hello3.c [root@centos-master test]# ls -l total 12 -rw-r--r-- 3 root root 13 Dec 8 21:27 hello2.c -rw-r--r-- 3 root root 13 Dec 8 21:27 hello3.c -rw-r--r-- 3 root root 13 Dec 8 21:27 hello.c -rw-r--r-- 1 root root 0 Dec 8 21:29 test.txt [root@centos-master test]# rm hello3.c rm: remove regular file ‘hello3.c’? y [root@centos-master test]# ls -l total 8 -rw-r--r-- 2 root root 13 Dec 8 21:27 hello2.c -rw-r--r-- 2 root root 13 Dec 8 21:27 hello.c -rw-r--r-- 1 root root 0 Dec 8 21:29 test.txt [root@centos-master test]# cat hello2.c hello world! [root@centos-master test]# vim hello2.c [root@centos-master test]# cat hello.c test hello world! [root@centos-master test]# cat hello2.c test hello world! [root@centos-master test]#
4.查看文件信息:wc、od、du、df
od:查看二进制文件的信息
wc:查看普通文件的信息
第一个代表的是行 第二代表的是数目 以空格为分 第三个代表的是字节数
[root@centos-master test]# wc test.txt 2 9 19 test.txt [root@centos-master test]# cat test.txt 1 2 3 4 55 6 2 2 3
du:查看当前目录的信息 加上-h才能看懂
[root@centos-master test]# du 8 . [root@centos-master test]# tree . `-- test.txt 0 directories, 1 file [root@centos-master test]# du -h 8.0K . [root@centos-master test]#
df:磁盘的使用量
[root@centos-master test]# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 929552 0 929552 0% /dev tmpfs 941072 48 941024 1% /dev/shm tmpfs 941072 732 940340 1% /run tmpfs 941072 0 941072 0% /sys/fs/cgroup /dev/vda1 51473868 6327512 42949112 13% / tmpfs 188216 0 188216 0% /run/user/0 [root@centos-master test]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 908M 0 908M 0% /dev tmpfs 920M 48K 919M 1% /dev/shm tmpfs 920M 732K 919M 1% /run tmpfs 920M 0 920M 0% /sys/fs/cgroup /dev/vda1 50G 6.1G 41G 13% / tmpfs 184M 0 184M 0% /run/user/0 [root@centos-master test]#
5.命令解析器:which
只能查看一些外部的命令
[root@centos-master test]# which cp alias cp='cp -i' /usr/bin/cp [root@centos-master test]# which ls alias ls='ls --color=auto' /usr/bin/ls [root@centos-master test]# which cd /usr/bin/cd [root@centos-master test]#
微信:17873041739
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?