Linux 常用命令和用户管理01

Linux的基本概念

在用命令行的时候,一定要知道自己当前的目录。

  命令 说明 example
路径

.

..

/

~

相对路径

绝对路径

当前路径

上一路径

根目录

家目录

从当前位置开始算起

从根/家开始算起

.

../

cd /

cd ~

Desktop

~/Desktop

帮助

man

--help

帮助,信息多,可以看参数

帮助,简单

man ls

ls --help

参数

-d

-i

-r

-a

-p

direction 文件

interactive 交互

recrusive 迭代

all 全部

prot 端口

ls -d

cp -i Desktop/1.txt Desktop

rm -r Desktop

ls -a

ssh -p 22 [email protected]

显示文件结构

ls

tree

list 显示文件的列表

树 树状显示

ls -lha

tree -d Desktop

查看/修改文件内容

cat

more

grep

显示文本

分屏显示文本

搜索文本

cat -n Desktop/1.txt

more Desktop/1.txt

grep -n character file

文件相关

pwd

cd

touch

mkdir

rm

clear

mv 

cp

echo

> >>

|

print work directory 

change directory

create txt

create directory

remove

clear shell

move

cope

print to screen

输出到文件

pip, 输出做输入

pwd

cd Desktop

touch Desktop/1.txt

mkdir Desktop/1

rm -r Desktop/1

clear

mv Desktop/1 Document

cp -r Desktop/1 Document

echo print >>Desktop/1/1.txt

 

cat 1.txt | grep 1

ssh

shutdown

ping

ifconfig

ssh

scp

 

关机。重启

测试连接

查看IP

远程登录

远程传文件

shutdown -r now

ping 127.0.0.1

ifconfig | grep -n inet

ssh -p 22 [email protected]

scp -P 22 -r Desktop/1 [email protected]:Desktop

权限相关

sudo

groupadd

useradd

passwd 

groupdel

/etc/group

/etc/passwd

usermod

id

who

whoami

which

su

 

substitute user, 预设为root

加组

加用户

改密码

删组

组信息

用户信息

修改用户的组和附加组

查看用户的组和附加组

查看所有登录的账户

查看你登录的账户

查看信息

开启root

 

sudo groupadd dev

sudo groupadd dev

useradd -m -g dev usr1

passwd usr1

groupdel -r dev

cat /etc/group | grep -n dev

cat /etc/passwd | grep -n usr1

usermod -G dev2

id usr1

who

whoami

which python3

su

 

修改文件的权限

chown

chgrp

chmod

修改所有者

修改归属组

修改权限信息

chown -R usr1 Desktop/1

chgrp -R usr1 Desktop/1

chmod -R 777 Desktop/1

技巧:

1. tab 补齐

2.在shell里用arrow可以重复上一条指令

3.调节shell的字体大小 ctrl+shift+=

用户管理命令

1.su: 切换当前的用户。

su user2 #切换用户
su -user2 #切换用户,并且到新用户的home下
exit #退出当前用户
su #进入root账号

2.我们先解释一下在ls -lh下显示的文件权限信息,然后再解释改变文件权限信息的方式

drwxr-xr-x 2 usr2 pi     4096 11月  9 21:42 1
# explain for each character 
d: directory
rwx: read write execute, the first one is for the creator of this file
r-x: three authorizations for the group members
r-x: three authorization for the rest members

2: the the way to access this file. 
usr2: the owner of this file
pi: the group
4096: the size of this file
11.9: the creation date 
21:42: the last modification date
1: the file name

and the shell will tell the doc and directory use diff color
#

chown -R user dir #modify the owner of this file
chgrp -R user dir #modify the group of this file
chmod -R 755 dir # change the file authorization
chmod -R +/-rwx #the same command, but the function is limited, only for owner.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章