linux 命令一

1.[root@spark000 ~]# clear

清屏

2.[root@spark000 home]# vi test.log

i -》编辑

esc -》 命令模式

shift+:-->end 输入 wq 保存

 

3.[root@spark000 home]# cat test.log

as

查看文件内容

4 [root@spark000 home]# pwd

/home

查看当前路径

5 家目录

家目录: 用户所在的默认的目录

/root 超级管理员

/home/cqk

/home/xxxx

6 cd切换目录

cd path 切换到指定目录

[root@spark000 home]# cd /usr/local

[root@spark000 local]#

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

[root@spark000 home]# cd /usr/local

[root@spark000 local]# cd ~

cd - 切换到上一次目录

[root@spark000 local]# cd /home

[root@spark000 home]# cd -

/usr/local

[root@spark000 local]#

cd ../ 切换到上一层目录

[root@spark000 local]# cd ../

[root@spark000 usr]#

7

ls查看当前目录下的文件文件夹的名称

[root@spark000 ~]# ls

apache-tomcat-8.5.16.tar.gz

CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel

CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel.sha

cloudera-manager-centos7-cm5.13.1_x86_64.tar.gz

ifloop.sh

jdk-8u144-linux-x64.tar.gz

log4j.log

manifest.json

mysql-connector-java-5.1.44-bin.jar

opt

ls -l ==> ll 查看当前目录下的文件和文件夹的详细信息

[root@spark000 ~]# ll

total 2816416

-rw-r--r-- 1 root root 9417469 Aug 29 14:30 apache-tomcat-8.5.16.tar.gz

-rw-r--r-- 1 root root 1934231261 May 11 12:21 CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel

-rw-r--r-- 1 root root 41 May 11 12:00 CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel.sha

-rw-r--r-- 1 root root 753729280 May 11 11:57 cloudera-manager-centos7-cm5.13.1_x86_64.tar.gz

-rw-r--r-- 1 root root 104 Jun 20 10:00 ifloop.sh

-rw-r--r-- 1 root root 185515842 May 11 11:41 jdk-8u144-linux-x64.tar.gz

-rw-r--r-- 1 root root 740 May 11 16:01 log4j.log

-rw-r--r-- 1 root root 73766 Feb 23 2018 manifest.json

-rw-r--r-- 1 root root 999635 May 11 15:58 mysql-connector-java-5.1.44-bin.jar

drwxr-xr-x 2 root root 4096 May 11 12:43 opt

ls -l -a ==》ll-a查看隐藏文件

隐藏文件:文件或文件夹名称以.开头

[root@spark000 ~]# ll -a

total 2816468

drwxr-xr-x. 6 1106 4001 4096 Sep 26 11:53 .

dr-xr-xr-x. 18 root root 4096 May 29 14:01 ..

-rw-r--r-- 1 root root 9417469 Aug 29 14:30 apache-tomcat-8.5.16.tar.gz

-rw------- 1 root root 5201 Sep 30 08:54 .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 1934231261 May 11 12:21 CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel

-rw-r--r-- 1 root root 41 May 11 12:00 CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel.sha

-rw-r--r-- 1 root root 753729280 May 11 11:57 cloudera-manager-centos7-cm5.13.1_x86_64.tar.gz

-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc

drwxr-x--- 3 root root 4096 Sep 2 09:25 .FineReport80

-rw-r--r-- 1 root root 104 Jun 20 10:00 ifloop.sh

-rw-r--r-- 1 root root 185515842 May 11 11:41 jdk-8u144-linux-x64.tar.gz

-rw-r--r-- 1 root root 740 May 11 16:01 log4j.log

-rw-r--r-- 1 root root 73766 Feb 23 2018 manifest.json

-rw-r--r-- 1 root root 999635 May 11 15:58 mysql-connector-java-5.1.44-bin.jar

drwxr-xr-x 2 root root 4096 May 11 12:43 opt

drwxr-xr-x 2 root root 4096 May 11 11:47 .oracle_jre_usage

-rw-r--r-- 1 root root 7 Sep 26 11:50 ss

drwx------ 2 root root 4096 May 11 11:37 .ssh

-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc

-rw------- 1 root root 674 May 11 11:32 .viminfo

ls -l -h ll -h 文件的大小(不是文件夹)

[root@spark000 ~]# ll -h

total 2.7G

-rw-r--r-- 1 root root 9.0M Aug 29 14:30 apache-tomcat-8.5.16.tar.gz

-rw-r--r-- 1 root root 1.9G May 11 12:21 CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel

-rw-r--r-- 1 root root 41 May 11 12:00 CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel.sha

-rw-r--r-- 1 root root 719M May 11 11:57 cloudera-manager-centos7-cm5.13.1_x86_64.tar.gz

-rw-r--r-- 1 root root 104 Jun 20 10:00 ifloop.sh

-rw-r--r-- 1 root root 177M May 11 11:41 jdk-8u144-linux-x64.tar.gz

-rw-r--r-- 1 root root 740 May 11 16:01 log4j.log

-rw-r--r-- 1 root root 73K Feb 23 2018 manifest.json

-rw-r--r-- 1 root root 977K May 11 15:58 mysql-connector-java-5.1.44-bin.jar

drwxr-xr-x 2 root root 4.0K May 11 12:43 opt

-rw-r--r-- 1 root root 7 Sep 26 11:50 ss

 

ls -l -rt 按时间排序

[root@spark000 ~]# ll -rt

total 2816416

-rw-r--r-- 1 root root 73766 Feb 23 2018 manifest.json

-rw-r--r-- 1 root root 185515842 May 11 11:41 jdk-8u144-linux-x64.tar.gz

-rw-r--r-- 1 root root 753729280 May 11 11:57 cloudera-manager-centos7-cm5.13.1_x86_64.tar.gz

-rw-r--r-- 1 root root 41 May 11 12:00 CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel.sha

-rw-r--r-- 1 root root 1934231261 May 11 12:21 CDH-5.13.1-1.cdh5.13.1.p0.2-el7.parcel

drwxr-xr-x 2 root root 4096 May 11 12:43 opt

-rw-r--r-- 1 root root 999635 May 11 15:58 mysql-connector-java-5.1.44-bin.jar

-rw-r--r-- 1 root root 740 May 11 16:01 log4j.log

-rw-r--r-- 1 root root 104 Jun 20 10:00 ifloop.sh

-rw-r--r-- 1 root root 9417469 Aug 29 14:30 apache-tomcat-8.5.16.tar.gz

-rw-r--r-- 1 root root 7 Sep 26 11:50 ss

mkdir 文件夹名称 1层

[root@spark000 home]# mkdir cqk

[root@spark000 home]# ll

total 8

drwxr-xr-x 2 root root 4096 Sep 30 09:37 cqk

mkdir -p a/b/c -p级联创建

[root@spark000 home]# mkdir -p a/b/c

[root@spark000 home]# ll

total 20

drwxr-xr-x 3 root root 4096 Sep 30 09:43 a

drwxr-xr-x 2 root root 4096 Sep 30 09:37 cqk

-rw-r--r-- 1 root root 3 Sep 30 08:58 test.log

[root@spark000 home]# cd a

[root@spark000 a]# cd b

[root@spark000 b]# cd c

[root@spark000 c]# ll

total 0

[root@spark000 c]# pwd

/home/a/b/c

mkdir q w e 同一层创建3个目录

[root@spark000 home]# mkdir q w e

[root@spark000 home]# ll

total 24

drwxr-xr-x 3 root root 4096 Sep 30 09:43 a

drwxr-xr-x 2 root root 4096 Sep 30 09:37 cqk

drwxr-xr-x 2 root root 4096 Sep 30 09:46 e

drwxr-xr-x 2 root root 4096 Sep 30 09:46 q

-rw-r--r-- 1 root root 3 Sep 30 08:58 test.log

drwxr-xr-x 2 root root 4096 Sep 30 09:46 w

[root@spark000 home]#

 

8 创建文件

vi test.log

touch test.log

9.移动复制 多份

mv xxx yyyy

cp xxx yyyy 文件

cp -r 文件夹

10.查看文件内容

cat xxx.log 一下子将内容刷新出来

more xxx.log 一页页按 【空格键】 翻下;【B】上

按 ctrl+z终止

11. > 箭头

> 覆盖

 

[root@spark000 home]# echo 123 > test.log

[root@spark000 home]# more test.log

123

[root@spark000 home]# echo 456 > test.log

[root@spark000 home]# more test.log

456

[root@spark000 home]#

>> 追加

[root@spark000 home]# echo 2345656 >> test.log

[root@spark000 home]# more test.log

123

2345656

12.环境变量文件

全局: /etc/profile

生效:source /etc/profile

个人: 家目录/.bash_profile

家目录/.bashrc

 

source 家目录/.bash_profile

. .bash_profile

13.切换用户

su cqk

su - cqk 进入家目录 执行环境变量文件生效

 

14.删除

rm xxx.log 删除文件询问是否还要删除

[root@spark000 home]# rm test.log

rm: remove regular file ‘test.log’?

rm -f xxx.log 不询问

[root@spark000 home]# rm -f text.log

[root@spark000 home]#

rm -r -f yyy 不询问 删除文件夹

[root@spark000 home]# rm -r -f a

[root@spark000 home]#

rm -rf yyy

[root@spark000 home]# rm -rf e

[root@spark000 home]#

15.查看历史命令

[root@spark000 home]# history

 

456 ll

457 rm test.log

458 ll

459 rm -f text.log

460 rm -f a

461 rm -r-f a

462 rm -r -f a

463 rm -rf e

464 histroy

465 history

执行第几行命令

[root@spark000 home]# !458

ll

total 12

drwxr-xr-x 2 root root 4096 Sep 30 15:50 cqk

drwxr-xr-x 2 root root 4096 Sep 30 09:46 q

drwxr-xr-x 2 root root 4096 Sep 30 09:46 w

[root@spark000 home]#

15.用户和用户组

[root@spark000 home]# ll /usr/sbin/user*

-rwxr-x---. 1 root root 118192 Nov 6 2016 /usr/sbin/useradd

-rwxr-x---. 1 root root 80360 Nov 6 2016 /usr/sbin/userdel

-rws--x--x. 1 root root 40312 Jun 10 2014 /usr/sbin/userhelper

-rwxr-x---. 1 root root 113840 Nov 6 2016 /usr/sbin/usermod

-rwsr-xr-x. 1 root root 11296 Nov 6 2016 /usr/sbin/usernetctl

 

[root@spark000 home]# ll /usr/sbin/group*

-rwxr-x---. 1 root root 65480 Nov 6 2016 /usr/sbin/groupadd

-rwxr-x---. 1 root root 57016 Nov 6 2016 /usr/sbin/groupdel

-rwxr-x---. 1 root root 57064 Nov 6 2016 /usr/sbin/groupmems

-rwxr-x---. 1 root root 76424 Nov 6 2016 /usr/sbin/groupmod

 

[root@spark000 ~]# useradd spark000

[root@spark000 ~]# id spark000

uid=1001(spark000) gid=1001(spark000) groups=1001(spark000)

spark000用户 spark000用户组 同时spark000用户组为主组

[root@spark000 ~]# userdel spark000

[root@spark000 ~]# useradd spark000

useradd: warning: the home directory already exists.

Not copying any file from skel directory into it.

Creating mailbox file: File exists

[root@spark000 home]# ll

total 16

drwxr-xr-x 2 root root 4096 Sep 30 15:50 cqk

drwxr-xr-x 2 root root 4096 Sep 30 09:46 q

drwx------ 2 spark000 spark000 4096 Sep 30 15:59 spark000

drwxr-xr-x 2 root root 4096 Sep 30 09:46 w

[root@spark000 ~]# su spark001

[spark001@spark000 root]$ pwd

/root

[root@spark000 ~]# su - spark001

Last login: Sun Sep 30 17:22:12 CST 2018 on pts/3

[spark001@spark000 ~]$ pwd

/home/spark001

 

 

 

你可能感兴趣的:(linux 命令一)