Linux基础操作与命令
快捷键
Ctrl+c 取消当前操作
Ctrl+l 清屏
Ctrl+a 光标移到行首
Ctrl+e 光标移到行尾
Ctrl+u 把光标到行首的内容剪切/删除
Ctrl+y 粘贴
tab键:自动补全命令或路径
cd 和 pwd:pwd显示当前所在目录 cd切换目录
[root@oldboyedu59 ~]# pwd
/root
[root@oldboyedu59 ~]# cd /tmp/
[root@oldboyedu59 tmp]# pwd
/tmp
[root@oldboyedu59 tmp]# cd /etc/sysconfig/network-scripts/
[root@oldboyedu59 network-scripts]# pwd
/etc/sysconfig/network-scripts
cd ~ === cd
cd .. 进入当前目录的上一级目录
cd . 进入当前目录
[root@oldboyedu59 etc]# cd /etc/sysconfig/network-scripts/
[root@oldboyedu59 network-scripts]# cd /tmp/
[root@oldboyedu59 tmp]# cd -
/etc/sysconfig/network-scripts
ls:list 参数:-l 以列表方式显示信息
[root@oldboyedu59 ~]# mkdir /oldboy
[root@oldboyedu59 ~]# ls /oldboy/
[root@oldboyedu59 ~]# ls -l /oldboy/
total 0
mkdir:创建目录 -p :创建多层目录
[root@oldboyedu59 ~]# mkdir /data/ /lidao
[root@oldboyedu59 ~]# ls -l /data /lidao/
/data:
total 0
路径:
一切从根开始
绝对路径: 从根开始的路径 √
/data
/oldboy
/etc/sysconfig/network-scripts
相对路径: 不是从根开始的路径
data
oldboy
[root@oldboyedu59 ~]# mkdir /data/oldboy/lidao/a/b/c/d/e
mkdir: cannot create directory ‘/data/oldboy/lidao/a/b/c/d/e’: No such file or directory
mkdir 命令默认只能创建1层目录 创建多层报错
[root@oldboyedu59 ~]# mkdir -p /data/oldboy/lidao/a/b/c/d/e
[root@oldboyedu59 ~]# ls -l /data/oldboy/lidao/a/b/c/d/e/
total 0
touch:创建文件和修改文件时间戳(如果文件存在)
[root@oldboyedu59 ~]# touch /oldboy/oldboy.txt
[root@oldboyedu59 ~]# ls -l /oldboy/
total 0
-rw-r--r--. 1 root root 0 Mar 28 11:46 oldboy.txt
[root@oldboyedu59 ~]# mkdir -p /oldboy/alex/lidao /data/alex/lidao
[root@oldboyedu59 ~]# touch /oldboy/alex/lidao/oldboy.txt /data/alex/lidao/oldboy.txt
[root@oldboyedu59 ~]# ls -l /oldboy/alex/lidao/ /data/alex/lidao/
/data/alex/lidao/:
total 0
-rw-r--r--. 1 root root 0 Mar 28 11:58 oldboy.txt
/oldboy/alex/lidao/:
total 0
-rw-r--r--. 1 root root 0 Mar 28 11:58 oldboy.txt
echo:输出信息到屏幕(默认到屏幕)
{} :生成序列
[root@oldboyedu59 ~]# echo oldboy
oldboy
[root@oldboyedu59 ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[root@oldboyedu59 ~]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
[root@oldboyedu59 ~]# echo oldboy{1..10}
oldboy1 oldboy2 oldboy3 oldboy4 oldboy5 oldboy6 oldboy7 oldboy8 oldboy9 oldboy10
特殊:
[root@oldboyedu59 ~]# echo {01..10}
01 02 03 04 05 06 07 08 09 10
显示出 oldboy01.txt oldboy02.txt oldboy03.txt ..... oldboy10.txt
[root@oldboyedu59 ~]# echo oldboy{01..10}.txt
oldboy01.txt oldboy02.txt oldboy03.txt oldboy04.txt oldboy05.txt oldboy06.txt oldboy07.txt oldboy08.txt oldboy09.txt oldboy10.txt
[root@oldboyedu59 ~]# touch oldboy{01..10}.txt
[root@oldboyedu59 ~]# touch oldboy{01..10}.txt
[root@oldboyedu59 ~]# ls -l
total 16
-rw-------. 1 root root 1341 Mar 26 11:46 anaconda-ks.cfg
-rw-r--r--. 1 root root 10213 Mar 28 10:28 grep.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy01.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy02.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy03.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy04.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy05.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy06.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy07.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy08.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy09.txt
-rw-r--r--. 1 root root 0 Mar 28 12:16 oldboy10.txt
drwxr-xr-x. 2 root root 6 Mar 27 20:31 oldgirl
drwxr-xr-x. 2 root root 6 Mar 27 20:33 oldman、
cp:复制,默认无法复制目录
cp -r:递归复制 ,复制目录和目录内的内容
备份:后加.bak
cp -p :保持属性不变
cp -a: 相当于-pdr
cp -d: 与软连接
[root@oldboyedu59 ~]# cp -r /oldboy/ /tmp/
[root@oldboyedu59 ~]# ls -l /tmp/
total 4
-rwx------. 1 root root 836 Mar 26 11:46 ks-script-pzO18O
drwxr-xr-x. 3 root root 36 Mar 28 12:32 oldboy
drwxr-xr-x. 2 root root 6 Mar 27 20:30 oldboy59
-rw-r--r--. 1 root root 0 Mar 28 12:24 oldboy.txt
drwx------. 2 root root 6 Mar 26 11:56 vmware-root_6737-3853947227
drwx------. 2 root root 6 Mar 27 08:37 vmware-root_6762-2864843553
-rw-------. 1 root root 0 Mar 26 11:37 yum.log
[root@oldboyedu59 ~]# ls -l /oldboy/oldboy.txt
-rw-r--r--. 1 root root 0 Mar 28 11:47 /oldboy/oldboy.txt
[root@oldboyedu59 ~]# cp /oldboy/oldboy.txt /oldboy/oldboy.txt.bak
[root@oldboyedu59 ~]# ls -l /oldboy/
total 0
drwxr-xr-x. 3 root root 19 Mar 28 11:57 alex
-rw-r--r--. 1 root root 0 Mar 28 11:47 oldboy.txt
-rw-r--r--. 1 root root 0 Mar 28 12:38 oldboy.txt.bak