Ubuntu常用命令

1.系统相关

1.1 查看本地机器上安装的相关库

dpkg --list | grep ares

1.2 查看系统版本信息

cat /proc/version

1.3 进程相关

1.3.1 查看当前正在运行的进程

ps -ef | grep your_process

1.3.2 终止进程

kill -9 [PID]

killall ProgressName

-9 表示强迫进程立即停止,通常用 ps 查看进程 PID ,用 kill 命令终止进程

1.3.3查看已安装的软件

dpkg --list

2. Mosquitto相关

2.1 开启mosquitto

mosquitto

2.2 启动订阅

mosquitto_sub -h 192.168.1.100 -t mtopic -u chisj -P chisj

2.3 创建用户

mosquitto_passwd -c /etc/mosquitto/pwfile.example userName
#接着键入2次密码,用户创建成功。
#-c 创建一个用户,如果加上-c会将以前创建的用户覆盖。添加用户时不需要加-c

3. 压缩、解压缩

3.1 压缩

3.1.1 ZIP

zip -r yasuo.zip abc.txt dir1 
#把一个文件abc.txt和一个目录dir1压缩成为yasuo.zip

3.1.2 tar

#将目录里所有jpg文件打包成tar.jpg
tar -cvf jpg.tar *.jpg

3.1.3 tar.gz

#将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jpg.tar.gz
tar -czf jpg.tar.gz *.jpg

3.1.4 tar.bz2

#将目录里所有jpg文件打包成jpg.tar后,并且将其用bzip2压缩,生成一个bzip2压缩过的包,命名为jpg.tar.bz2
tar -cjf jpg.tar.bz2 *.jpg 

3.1.5 tar.Z

#将目录里所有jpg文件打包成jpg.tar后,并且将其用compress压缩,生成一个umcompress压缩过的包,命名为jpg.tar.Z
tar -cZf jpg.tar.Z *.jpg

3.1.6 rar

#rar格式的压缩,需要先下载rar for linux
rar a jpg.rar *.jpg

3.1.7 zip

#zip格式的压缩,需要先下载zip for linux
zip jpg.zip *.jpg

3.2 解压

3.2.1 ZIP

unzip yasuo.zip

3.2.2 tar.gz

tar -xzvf file.tar.gz

3.2.3 tar.bz2

bizp -d file.tar.bz2
tar -xvf file.tar

3.2.4 tar.xz

#先 xz -d xxx.tar.xz 将 xxx.tar.xz解压成 xxx.tar 然后,再用 tar xvf xxx.tar来解包。
xz -d xxx.tar.xz
tar xvf xxx.tar

3.2.5 tar

tar -zxvf file.tar

3.2.6 rar

rar x xxx.rar

4. 用户操作

4.1 开启root账户

sudo passwd -u root
sudo passwd root
#根据提示输入新密码:
#end。

4.2 允许使用root ssh登录

参考Ubuntu 17.04 允许使用root ssh登录

  • 安装ssh
sudo apt install openssh-server
  • 设置root密码
sudo passwd root
  • 允许root用户登录,编辑sshd_config
sudo vim /etc/ssh/sshd_config
  • 找到#Authentication项下的:

    PermitRootLogin prohibit-password

    改成:

    PermitRootLogin yes
  • 重启ssh

sudo systemctl restart sshd

4.2 查看用户列表

cat /etc/passwd

4.3 增加一个用户

useradd -U user_name
# -U 表示创建一个和用户名相同的组
# 设置密码:
passwd user_name
useradd -r -m -s /bin/bash user_name
# -r:建立系统账号
# -m:自动建立用户的登入目录
# -s:指定用户登入后所使用的shell

4.4 删除用户

userdel -r user_name

5. 硬盘操作

5.1 设置开机自动挂载硬盘

参考Ubuntu Linux 永久挂载(mount)分区

6. 文件操作

6.1 linux主机之间互传文件

6.1.1 用scp命令行的方式

​ A、B 机都允许root登录,B主机IP:192.168.1.33,要把A主机上的/home/data文件夹传送到主机B上,运行命令(root权限运行):

scp /home/data root@192.168.1.33:/home/new-data
# /home/data 是A主机中要传的文件夹,后面的信息是B主机的信息。
# 根据提示输入B主机root密码

参考 两台centos之间传送文件

6.2 查找文件和文件内容

6.2.3 find命令

​ 通过find与grep相结合查找所有子文件中包含timersub关键字的文件,如果文件中包含该关键字,在终端中就会打印出来:

find / -name '*' | xargs grep -r 'timersub'

6.3 开启Samba文件共享服务器

  • 进入root账号

  • 检查更新

apt-get update && apt-get upgrade
  • 创建/选择共享目录
mkdir /home/sharedir
  • 修改目录权限
chmod 777 /home/sharedir
  • 编辑smb.conf文件,加入共享信息
vi /etc/samba/smb.conf

在文件末尾追加[share]配置信息:

smaba配置共享文件夹.png

[share]
comment = Shared Folder require password
path = /home/magic/share
public = yes
writable = yes
valid users = magic
create mask = 0777
directory mask = 0777
force user = nobody
force group = nogroup
available = yes
browseable = yes
  • 创建samba账号(如果不设置public=yes则需要账号密码访问)
touch /etc/samba/sambpasswd
smbpasswd -a yourAccountName
# 接着根据提示输入密码
  • 重启samba服务
service smbd restart
  • 在Windows中直接打开资源管理器输入\\ip回车即可访问。

  • end

6.4 安装deb文件

dpkg -i xxx.deb

7. 代码相关

7.1 添加库搜索路径

添加的搜索路径默认是放在/etc/ld.so.conf.d/ 目录下的所有文件中的,所以只需要在该目录下新建一个文件比如说opencv.conf,然后在该文件中加入.so文件的路径,比如/usr/local/lib 就可以了。

添加完后执行ldconfig使其生效

7.2 查看库依赖

查看一个so库所依赖的文件:

objdump -x build/libfytrackerkcf.so | grep NEEDED

8. 下载源

8.1 更换国内源

  • 备份原来的源
sudo cp /etc/apt/sources.list /etc/apt/sources_old.list
  • 更换源
sudo gedit /etc/apt/sources.list
  • 阿里源
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
  • 更新源
 sudo apt-get update
Last modification:May 28th, 2019 at 10:13 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment