一.linux基本命令

一.linux基本命令

1.文件操作

(1)touch:新建文件,不能新建同名文件,新件同名文件不会影响已有文件

book@www.100ask.org:~/Documents/test2$ touch a.c
book@www.100ask.org:~/Documents/test2$ vim a.c
book@www.100ask.org:~/Documents/test2$ ls -l
total 4
-rw-rw-r-- 1 book book 7 9月   8 13:50 a.c
book@www.100ask.org:~/Documents/test2$ touch a.c
book@www.100ask.org:~/Documents/test2$ ls -l
total 4
-rw-rw-r-- 1 book book 7 9月   8 13:50 a.c
book@www.100ask.org:~/Documents/test2$

(2)mv:修改文件名,目录名,移动路径

mv 旧文件名 新文件名

book@www.100ask.org:~/Documents/test2$ ls
a.c  b.c  test4  tests3
book@www.100ask.org:~/Documents/test2$ mv a.c aaa.c
book@www.100ask.org:~/Documents/test2$ ls
aaa.c  b.c  test4  tests3
book@www.100ask.org:~/Documents/test2$

mv 旧目录名 新目录名

book@www.100ask.org:~/Documents/test2$ ls
a.c  b.c  test3  test4
book@www.100ask.org:~/Documents/test2$ mv test3 tests3
book@www.100ask.org:~/Documents/test2$ ls
a.c  b.c  test4  tests3
book@www.100ask.org:~/Documents/test2$

mv 文件名 目录名

book@www.100ask.org:~/Documents/test2/test3$ ls -l
total 8
-rw-rw-r-- 1 book book 7 9月   8 13:57 a.c
-rw-rw-r-- 1 book book 7 9月   8 13:57 b.c
book@www.100ask.org:~/Documents/test2/test3$ mv a.c ../
book@www.100ask.org:~/Documents/test2/test3$ ls
b.c
book@www.100ask.org:~/Documents/test2/test3$ cd ..
book@www.100ask.org:~/Documents/test2$ ls
a.c  b.c  test3  test4
book@www.100ask.org:~/Documents/test2$

(3)rm:删除文件

rm [-i ] 文件名:删除当前目录下的和输入文件名同名的文件,-i 表示是否提醒确认删除

book@www.100ask.org:~/Documents/test2$ ls
aaa.c  b.c  test4  tests3
book@www.100ask.org:~/Documents/test2$ rm -i aaa.c
rm: remove regular file 'aaa.c'? y
book@www.100ask.org:~/Documents/test2$ ls
b.c  test4  tests3
book@www.100ask.org:~/Documents/test2$

(4)cat:将文件内容显示到终端上

cat 文件名:显示文件名中的内容

cat 文件名1 文件名2:显示文件名1和文件名2内容

book@www.100ask.org:~/Documents/test2$ cat a.c
int a=0;
int b=0;
this is a.c
book@www.100ask.org:~/Documents/test2$ cat a.c b.c
int a=0;
int b=0;
this is a.c
double f1=0.00;
this is b

cat -n 文件名 :显示文件名的同时显示行号

book@www.100ask.org:~/Documents/test2$ cat -n a.c
     1  int a=0;
     2  int b=0;
     3  this is a.c

2.目录操作

(1)pwd:显示当前所在的目录

book@www.100ask.org:~$ pwd
/home/book

(2)ls:显示当前目录下的文件

book@www.100ask.org:~$ **ls -l**
total 44
drwxr-xr-x 2 book book 4096 4月  12  2018 Desktop
drwxr-xr-x 2 book book 4096 4月  12  2018 Documents
drwxr-xr-x 2 book book 4096 4月  12  2018 Downloads
-rw-r--r-- 1 book book 8980 4月  12  2018 examples.desktop
drwxr-xr-x 2 book book 4096 1月  17  2019 Music
drwxr-xr-x 3 book book 4096 1月  17  2019 Pictures
drwxr-xr-x 2 book book 4096 4月  12  2018 Public
drwxr-xr-x 2 book book 4096 4月  12  2018 Templates
drwxr-xr-x 2 book book 4096 1月  17  2019 Videos
book@www.100ask.org:~$ **ls -a**
.              .bash_logout  .compiz  .dmrc      examples.desktop  .ICEauthority  .mplayer  .profile                   Templates  .Xauthority       .xsession-errors.old
..             .bashrc       .config  Documents  .gconf            .local         Music     Public                     Videos     .xinputrc
.bash_history  .cache        Desktop  Downloads  .gnupg            .mozilla       Pictures  .sudo_as_admin_successful  .viminfo   .xsession-errors
book@www.100ask.org:~$ **ls -h**
Desktop  Documents  Downloads  examples.desktop  Music  Pictures  Public  Templates  Videos
book@www.100ask.org:~$ **ls**
Desktop  Documents  Downloads  examples.desktop  Music  Pictures  Public  Templates  Videos
book@www.100ask.org:~$ **ls /home/**
book

(3)cd: 切换目录

cd ~ 切换到当前用户的家目录

cd . 切换到当前路径

cd … 切换到上一级路径

cd …/… 切换到上上级路径

book@www.100ask.org:/$ cd /home/book/Documents/
book@www.100ask.org:~/Documents$ cd ~
book@www.100ask.org:~$ cd /
bin/        cdrom/      etc/        lib/        lib64/      media/      opt/        root/       sbin/       srv/        tftp/       usr/        work/
boot/       dev/        home/       lib32/      lost+found/ mnt/        proc/       run/        snap/       sys/        tmp/        var/
book@www.100ask.org:~$ cd /home/book/Documents/
book@www.100ask.org:~/Documents$ cd ..
book@www.100ask.org:~$ pwd
/home/book
book@www.100ask.org:~$ cd ../..
book@www.100ask.org:/$ pwd
/

(4)mkdir:新建目录

mkdir test1:新建目录

mkdir -p test2/test3:新建连续目录

book@www.100ask.org:~/Documents$ mkdir test1
book@www.100ask.org:~/Documents$ mkdir -p test2/test3

book@www.100ask.org:~/Documents$ ls
test1  test2  VMwareTools-10.1.15-6627299.tar.gz
book@www.100ask.org:~/Documents$ cd test
-bash: cd: test: No such file or directory
book@www.100ask.org:~/Documents$ cd test2
book@www.100ask.org:~/Documents/test2$ ls
test3

(5).rmdir:删除目录,不能删除非空目录

book@www.100ask.org:~/Documents/test2$ ls
test3
book@www.100ask.org:~/Documents/test2$ cd ..
book@www.100ask.org:~/Documents$ rmdir test2
rmdir: failed to remove 'test2': Directory not empty
book@www.100ask.org:~/Documents$ cd test2
book@www.100ask.org:~/Documents/test2$ rmdir test3/
book@www.100ask.org:~/Documents/test2$

(6)rm [-r] 目录名:表示删除当前目录下的选中目录

book@www.100ask.org:~/Documents/test2$ ls
b.c  test4  tests3
book@www.100ask.org:~/Documents/test2$ rm -r tests3
book@www.100ask.org:~/Documents/test2$ ls -l
total 8
-rw-rw-r-- 1 book book    7 9月   8 13:56 b.c
drwxrwxr-x 2 book book 4096 9月   8 13:58 test4
book@www.100ask.org:~/Documents/test2$

3.cp:复制

cp 源文件名 目标文件名 复制源文件并保存为目标文件名

cp [-i] 源文件名 目标目录名 复制源文件到目标目录,-i表示提示是否覆盖同名文件

cp [-r] 源目录名 目标目录名 -r表示递归复制

book@www.100ask.org:~/Documents/test2$ cp a.c b.c
book@www.100ask.org:~/Documents/test2$ ls -l
total 12
-rw-rw-r-- 1 book book    7 9月   8 13:50 a.c
-rw-rw-r-- 1 book book    7 9月   8 13:56 b.c
drwxrwxr-x 2 book book 4096 9月   8 13:56 test3
book@www.100ask.org:~/Documents/test2$ cp a.c b.c test3/
book@www.100ask.org:~/Documents/test2$ ls -a
.  ..  a.c  b.c  test3
book@www.100ask.org:~/Documents/test2$ cd test3/
book@www.100ask.org:~/Documents/test2/test3$ ls -l
total 8
-rw-rw-r-- 1 book book 7 9月   8 13:57 a.c
-rw-rw-r-- 1 book book 7 9月   8 13:57 b.c
book@www.100ask.org:~/Documents/test2/test3$ cd ..
book@www.100ask.org:~/Documents/test2$ cp -r test3/ test4
book@www.100ask.org:~/Documents/test2$ ls
a.c  b.c  test3  test4

4.清屏

(1)clear:清楚屏幕的显示内容

(2)reset:重新初始化屏幕,清除历史命令操作记录

5.配置环境变量export PATH =$PATH:/mydir 添加mydir目录到PATH环境变量

6.帮助文档

man 具体指令

info 具体指令

book@www.100ask.org:~/Documents/test2$ man ls
book@www.100ask.org:~/Documents/test2$
book@www.100ask.org:~/Documents/test2$ info ls
book@www.100ask.org:~/Documents/test2$
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值