---
title: "linux常用命令"
author: "java_my_life"
date: "2011-08-23T19:30:34Z"
tags: []
categories: ["操作系统"]
slug: "linux"
draft: false
lastmod: "2020-09-30T09:32:47Z"
id: 1156283
url: "https://java-my-life.iteye.com/blog/1156283"
---

Ubuntu 下安装 OpenSSH Server 是无比轻松的一件事情，需要的命令只有一条：

```
sudo apt-get install openssh-server
```

Ubuntu下更新源的方法

```
apt-get update
```

Ubuntu下查看java执行路径

```
which java
```

Ubuntu下查看jdk路径

```
update-alternatives --config java
```

 Ubuntu下查看操作系统为多少位

```
getconf -a|grep LONG_BIT
```

  Ubuntu下查看文件

```
cat filename 
```

Ubuntu查看语言环境

```
locale
```

Ubuntu查看端口是否打开

 

```
nc -zv localhost 1-65535
```

Ubuntu查看端口是否打开

```
netstat -an | grep 23
```

Ubuntu查看本机开放端口

```
netstat -ant
```

 Ubuntu中查看占用某一端口的进程是什么

```
lsof -i:21
```

  Ubuntu查看本机端口开放情况

```
netstat -lnp
```

 后台运行任务 &：表示远程断开连接后，退出任务。如果想客户端断开后任务依然执行，就需要使用nohup

 

```
nohup sh /usr/test.sh &
```

 查看正在执行的后台任务，-l：表示显示任务PID

```
jobs -l
```

 将后台任务调至前台继续执行，如果有多个，可以在后面加上任务号将其选出，如：fg 2

```
fg
```

 查看磁盘空间

```
df -hl
```

 查看当前目录大小

```
du -lh --max-depth=1
```

  添加用户

```
useradd test
```

  设置用户密码

```
passwd test
```

  切换用户

```
su test
```

  将/a目录的属主改成test用户

```
chown test /a
```

  将/a目录的权限改成755 属主拥有完全控制权

```
chmod 755 /a
```

   查看定时任务日志

```
tail -f /var/logs/cron
```

   查看正在运行的定时任务

```
crontab -l
```

   查看正在运行的定时任务

```
crontab -l
```

   添加定时任务

```
crontab -e
```

   Linux截取文件中某时间段的内容

```
sed -n '/15:32:30/,/16:12:09/p' access_log >log.txt
```

   查看端口使用情况

```
ss -ntlp
```

   查看端口被哪些IP访问

```
netstat -tun | grep ":80"
```

   查看某进程已打开的文件数

```
cat /proc/pid/limits
```