Linux极速上手


此文章主要记录Linux中的入门级基础操作方法,对基础的Linux操作语句进行了整理

文件查看

pwd 列出当前目录的路径,查看当前所在的目录

[root@localhost ~]# pwd
/root

~表示用户的家目录

ls 列出当前目录下的所有文件

[root@localhost ~]# ls
anaconda-ks.cfg

ll (ls -l缩写)列出当前目录下的文件(带文件信息)

[root@localhost ~]# ll
total 4
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
[root@localhost ~]# ls -l
total 4
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg

ll-a 列出当前目录下的所有文件(包括隐藏文件)

[root@localhost ~]# ll -a
total 28
dr-xr-x---.  2 root root  135 Sep  8 17:38 .
dr-xr-xr-x. 17 root root  224 Sep  7 18:05 ..
-rw-------.  1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-------.  1 root root    8 Sep  8 17:38 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root  100 Dec 29  2013 .cshrc
-rw-r--r--.  1 root root  129 Dec 29  2013 .tcshrc
[root@localhost ~]# ^C
[root@localhost ~]# ^C
[root@localhost ~]# ^C
[root@localhost ~]# ^C
[root@localhost ~]# 

ll --help 查看ls用法,-help为帮助指令

[root@localhost ~]# ll --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
      ............

创建,重命名文件\文件夹

touch filename 创建空文件夹
创建空头文件hello.txt

[root@localhost ~]# touch hello.txt
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 18 21:51 hello.txt

mkdir 创建目录
创建目录 abc

[root@localhost ~]# mkdir abc
[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 18 21:53 abc
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 18 21:51 hello.txt

mkdir -p(目标文件即使存在也不会报错

[root@localhost ~]# mkdir -p abc
[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 18 21:53 abc
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 18 21:51 hello.txt
[root@localhost ~]# 

当我们创建新文件,并且不知道它是否存在时,可用-p参数,保证不会报错

mv 重命名文件\文件夹
修改abc名称为abc

[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 18 21:53 abc
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 18 21:51 hello.txt
[root@localhost ~]# mv abc abx
[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 18 21:53 abx
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 18 21:51 hello.txt

链接文件

硬链接(对原始文件的操作):

[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 18 21:53 abx
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 18 21:51 hello.txt
[root@localhost ~]# In hello.txt hlink
[root@localhost ~]# ln hello.txt hlink
[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 18 21:53 abx
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 2 root root    0 Sep 18 21:51 hello.txt
-rw-r--r--. 2 root root    0 Sep 18 21:51 hlink

软链接(相当于快捷方式,不能删除原文件) 在ln后添加-s

[root@localhost ~]# ln -s hello.txt hlink
ln: failed to create symbolic link ‘hlink’: File exists
[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 18 21:53 abx
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 2 root root    0 Sep 18 21:51 hello.t

切换目录

cd . 当前目录
一个 . 表示

[root@localhost ~]# pwd
/root
[root@localhost ~]# cd .
[root@localhost ~]# pwd
/root

**cd . .**去上一级目录
两个 . . 表示上一级目录

[root@localhost ~]# pwd
/root
[root@localhost ~]# cd ..
[root@localhost /]# pwd
/

在cd后指定目录,可切换到指定目录

[root@localhost /]# cd /
[root@localhost /]# pwd
/
[root@localhost /]# cd /bin/
[root@localhost bin]# pwd
/bin
[root@localhost bin]# 

**cd ~**去当前户主目录

[root@localhost test]# cd ~
[root@localhost ~]# pwd
/root

cd xxx/xxx直接跳转到某个目录

[root@localhost ~]# cd abx/test/
[root@localhost test]# pwd
/root/abx/test

删除文件\文件夹(目录)

rm命令可删除文件或目录,也可将其下面的所有文件及其子目录均删除掉
对于链接文件,仅删除整个链接文件,而原有文件保持不变
常见用法:
rm 删除文件(会有提示对话,输入y表示确认删除)

[root@localhost test]# ll
total 0
-rw-r--r--. 1 root root 0 Sep 19 15:28 abc.txt
-rw-r--r--. 1 root root 0 Sep 19 15:27 sbc.txt
[root@localhost test]# rm abc.txt
rm: remove regular empty file ‘abc.txt’? y
[root@localhost test]# ll
total 0
-rw-r--r--. 1 root root 0 Sep 19 15:27 sbc.txt

rm -r 删除目录(需要确认)
删除目录需要指定参数r,否则提示不能删除

[root@localhost abx]# rm -r test
rm: remove directory ‘test’? y
[root@localhost abx]# ll
total 0

rm -f 强制删除(无询问语句)

[root@localhost abx]# touch a.txt
[root@localhost abx]# ll
total 0
-rw-r--r--. 1 root root 0 Sep 19 15:40 a.txt
[root@localhost abx]# rm -f a.txt
[root@localhost abx]# ll
total 0

强制删除有一定的风险性,由于Linux中没有回收站,删除后文件无法找回

rm -rf 递归删除目录及文件

Linux中最为危险的操作,最具有破坏性

[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 19 15:40 abx
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
[root@localhost ~]# mkdir -p abx/test/aaa
[root@localhost ~]# cd abx/test/aaa/
[root@localhost aaa]# touch a.txt
[root@localhost aaa]# cd ~
[root@localhost ~]# rm -rf abx
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg

由于rf参数可递归删除任何数据,有极强的破坏力,所以需要慎用!!!

复制\粘贴\剪切

常用方法:
cp 复制&粘贴文件
复制hello.txt文件,复制后的文件名为hello~bak.txt

[root@localhost ~]# ll
total 4
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
[root@localhost ~]# cd hello.txt
-bash: cd: hello.txt: No such file or directory
[root@localhost ~]# touch hello.txt
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 19 15:51 hello.txt
[root@localhost ~]# cp hello.txt hello-bak.txt
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 19 15:52 hello-bak.txt
-rw-r--r--. 1 root root    0 Sep 19 15:51 hello.txt
[root@localhost ~]# 

cp -r 复制&粘贴文件或目录
复制目录,需指定参数r

[root@localhost ~]# mkdir abc
[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 19 23:32 abc
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 19 15:52 hello-bak.txt
-rw-r--r--. 1 root root    0 Sep 19 15:51 hello.txt
[root@localhost ~]# cp -r abc xyz
[root@localhost ~]# ll
total 4
drwxr-xr-x. 2 root root    6 Sep 19 23:32 abc
-rw-------. 1 root root 1246 Sep  7 18:06 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Sep 19 15:52 hello-bak.txt
-rw-r--r--. 1 root root    0 Sep 19 15:51 hello.txt
drwxr-xr-x. 2 root root    6 Sep 19 23:32 xyz

mv 移动(剪切)文件或目录
将目录xyz移动到abc下

[root@localhost ~]# ll abc/
total 0
[root@localhost ~]# mv xyz abc
[root@localhost ~]# ll abc/
total 0
drwxr-xr-x. 2 root root 6 Sep 19 23:32 xyz

内容查看

cat 显示文本内容

[root@localhost ~]# cat anaconda-ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
......

cat -b 显示行输出

[root@localhost ~]# cat -b anaconda-ks.cfg
     1  #version=DEVEL
     2  # System authorization information
     3  auth --enableshadow --passalgo=sha512
     4  # Use CDROM installation media
     5  cdrom
     .......

分屏显示more
根据屏幕大小显示部分内容

[root@localhost ~]# more anaconda-ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
........

输出及显示

echo 类似与Java中的System.out.println()
echo:不解析转义字符
echo -e:解析转义字符
echo $PATH: 输出环境变量

[root@localhost ~]# echo "Hello\t\t world"
Hello\t\t world
[root@localhost ~]# echo -e "hello\t\t world"
hello            world
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

磁盘使用情况

df 查看磁盘使用情况

[root@localhost ~]# df
Filesystem              1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root   8374272 1027072   7347200  13% /
devtmpfs                   485828       0    485828   0% /dev
tmpfs                      497944       0    497944   0% /dev/shm
tmpfs                      497944    7748    490196   2% /run
tmpfs                      497944       0    497944   0% /sys/fs/cgroup
/dev/sda1                 1038336  135276    903060  14% /boot
tmpfs                       99592       0     99592   0% /run/user/0

清屏小命令

clear 进行屏幕的清屏
使用后:

[root@localhost ~]# 

查看内存使用情况

free
free -m : 显示单位为MB
free -h : 根据值的大小,显示易于识别的单位

[root@localhost ~]# ^C
[root@localhost ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         121         712           7         138         690
Swap:          1023           0        1023
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           972M        121M        712M        7.6M        138M        690M

关机重启快捷命令

shut down -h now 关机
reboot -h now 重启
exit 退出当前登录状态

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要快速上手Linux内核,您可以按照以下步骤进行: 1. 了解Linux内核的基本概念:学习Linux内核的基础知识,如进程管理、内存管理、文件系统、设备驱动等。可以阅读相关的书籍、在线教程或参考官方文档。 2. 设置开发环境:在您的计算机上设置Linux开发环境。可以选择一个流行的Linux发行版(如Ubuntu、Fedora等),安装开发工具链和必要的软件包,以便进行内核编译和调试。 3. 下载并编译内核源代码:从Linux官方网站(https://www.kernel.org/)下载最新版本的内核源代码。按照官方提供的说明进行编译,生成可执行的内核映像文件。 4. 阅读和理解内核代码:开始阅读内核源代码,了解其结构和组织方式。可以从一些简单的模块或驱动程序开始,逐渐深入理解内核的不同部分。 5. 参与开发社区:加入Linux内核开发社区,参与讨论和交流,在邮件列表、论坛或IRC频道上与其他开发者互动。这将帮助您获得更多实践经验和指导。 6. 进行实际编程和调试:尝试编写简单的内核模块、驱动程序或补丁,并进行调试和测试。通过实际编程和解决实际问题,加深对内核的理解和掌握。 7. 学习内核调试技术:了解内核调试工具和技术,如GDB、Kprobes、Ftrace等。这些工具可以帮助您分析和调试内核代码,定位和修复问题。 8. 深入研究特定领域:根据自己的兴趣和需求,选择一个特定的领域进行深入研究,如网络协议栈、虚拟化、安全性等。探索Linux内核的各个子系统,并尝试在特定领域做出贡献。 请注意,学习Linux内核需要耐心和持续的努力。这只是一个快速上手的指南,真正的深入学习和掌握需要更多的时间和经验。建议在学习过程中保持对官方文档、书籍和其他资源的持续学习和参考。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值