Linux常用命令

来源:互联网 发布:怎么整一家淘宝店 编辑:程序博客网 时间:2024/06/01 09:24

URL: http://man.linuxde.net/


man


DOS与Linux的断行字符

  • Notepad++,编辑,文档格式转换
  • dos2UNIX [-kn] file [newfile]
  • UNIX2dos [-kn] file [newfile] ——参数:
    • -k:不更新文件上次内容经过修改的时间
    • -n:保留旧文件,将转换后的内容输出到新文件

语系编码转换

iconv --listiconv -f 原本编码 -t 新编码 filename [-o newfile]

参数
- –list:列出iconv支持的语系数据
- -f:from,后接原本的编码格式
- -t:to,即后来的新编码是什么格式
- -o file:如果要保留原本的文件,那么使用-o新文件名,可以建立新编码文件。


Ubuntu 后台运行

  1. 程序后加上“&” ,即 “./myjob &”, 将命令放入到一个作业队列中,可以用命令“jobs” 查看

  2. 将1中的命令放在 “()”中, 即 “(./myjob &)”,所提交的作业并不在作业列表中,是无法通过jobs来查看的。

  3. 使用”nohup”, 即 “nohup ./myjob &”,忽略hangup信号,防止shell关闭时程序停掉。

  4. 使用”setsid”, 即“setsid ./myjob”。

  5. 对已经运行的程序可以用 “disown -hmyjob” 来使某个作业忽略HUP信号。

  6. 使用“screen”. screen 下的操作会在screen下运行,无法在jobs中查看到。常用的命令有:

a) 新建一个screen: screen-S my_screen_name. 建好后就可以进行所需要的操作了。
b) 暂时断开screen: Ctrl-a d
c) 重新打开screen: Ctrl-a screen_id
d) 查看所有screen状态: screen -ls
e) 终止screen: screen -S my_screen_name -Xkill
f) 在当前窗口新建窗口: Ctrl-a c
g) 退出当前窗口: exit
h) 显示所有窗口列表:Ctrl-a w


nohup

如果我们可以忽略SIGHUP信号,关掉窗口应该就不会影响程序的运行了。nohup命令可以达到这个目的,如果程序的标准输出/标准错误是终端,nohup默认将其重定向到nohup.out文件。值得注意的是nohup命令只是使得程序忽略SIGHUP信号,还需要使用标记&把它放在后台运行。

nohup <command> [argument…] &

虽然nohup很容易使用,但还是比较“简陋”的,对于简单的命令能够应付过来,对于复杂的需要人机交互的任务就麻烦了。

NAME
nohup - run a command immune to hangups, with output to a non-tty

SYNOPSIS
nohup COMMAND [ARG]…
nohup OPTION

DESCRIPTION
Run COMMAND, ignoring hangup signals.

   --help display this help and exit   --version          output version information and exit   If  standard  input is a terminal, redirect it from an unreadable file.   If standard output is a terminal, append output to 'nohup.out' if  pos‐   sible,  '$HOME/nohup.out'  otherwise.  If standard error is a terminal,   redirect it to standard output.  To save output  to  FILE,  use  'nohup   COMMAND > FILE'.

tmux


screen

sudo apt install screen

查看包版本:

dpkg -l | grep screen

screen

screen -S name

screen -r name

Ctrl-a ?:查看所有键绑定

Ctrl-a c(eate)

Ctrl-a p(revious)/n(ext)

Ctrl-a d(etach)

Ctrl-a k(ill)

screen -ls

screen -r <screen-pid>

我们可以利用screen这种功能来管理你的远程会话,保存你所有的工作内容。你是不是每次登录到系统都要开很多窗口,然后每天都要重复打开关闭这些窗口?让screen来帮你“保存”吧,你只需要打开一个ssh窗口,创建需要的screen窗口,退出的时候C-a d“保存”你的工作,下次登录后直接screen -r <screen_pid>就可以了。

最好能给每个窗口起一个名字,这样好记些。使用C-a A给窗口起名字。使用C-a w可以看到这些窗口名字

屏幕分割

  • 现在显示器那么大,将一个屏幕分割成不同区域显示不同的Screen窗口显然是个很酷的事情。可以使用快捷键C-a S将显示器水平分割,Screen 4.00.03版本以后,也支持垂直分屏,快捷键是C-a |
  • 分屏以后,可以使用C-a 在各个区块间切换,每一区块上都可以创建窗口并在其中运行进程。 可以用C-a X快捷键关闭当前焦点所在的屏幕区块,也可以用C-a Q关闭除当前区块之外其他的所有区块。关闭的区块中的窗口并不会关闭,还可以通过窗口切换找到它。

来自: http://man.linuxde.net/screen


Linux history

ctrl + R :搜索历史命令

使用HISTTIMEFORMAT在历史中显示TIMESTAMP
export HISTTIMEFORMAT = '%F %T'

用HISTSIZE控制历史命令的总数
vi ~/.bash_profile --> HISTSIZE=450 HISTFLESIZE=450

用HISTFILE改变存放历史命令的文件名
vi ~/.bash_profile --> HISTFILE=/root/.commandline_warrior

使用HISTCONTROL来消除命令历史中连续重复条目export HISTCONTROL=ignoredups

使用HISTCONTROL强制history忽略某条特定指令export HISTCONTROL=ignorespace

用HISTIGNORE让history在存储时忽略某些指令
export HISTIGNORE="pwd:ls:"

然而,如果你想永久地配置该变量,用你最喜欢的编辑器打开文件 ~/.bashrc。
$ vi ~/.bashrc

然后在下方添加
export HISTTIMEFORMAT=’%F %T’

保存文件并退出,然后,运行下面的命令以便改动当即生效:
$ source ~/.bashrc


引导

cd /boot/grub/ –> vim grub.cfg


监控主机状态

who

top

ps -aux

df -h

du -h

查看显卡状态:

nvidia-smi


env

echo $PATH

export ..

source ~/.bashrc用户的

source /etc/profile系统下的,慎用!

root@dluta914:/etc/network# cat ~/.bashrc | grep -i 'profile'


locate

updatedb –> locate cuda


root

su

sudo -s

sudo -i

让普通用户拥有root的权限:
- 1.root登录
- 2.adduser 用户名
- 3.passwd 用户名
- 确定密码
- 4.修改/etc/passwd即可,把用户名的ID和ID组修改成0。


用户管理

useradd -d /home/username -m -s /bin/bash username

添加用户:useradd user_name

配置文件:sudo cp .bashrc /home/user_name/

删除用户userdel -r user_name


linux 给用户加sudo权限

1、用root帐号登录或者su到root。

2、增加sudoers文件的写权限: chmod u+w /etc/sudoers

3、vim /etc/sudoers 找到 root ALL=(ALL) ALL 在这行下边添加 dituhui ALL=(ALL) ALL (ps:dituhui代表是你要添加sudo权限的用户名)

4、除去sudoers文件的写权限: chmod u-w /etc/sudoers


linux下添加用户并赋予root权限

1、添加用户,首先用adduser命令添加一个普通用户,命令如下:

adduser tommy

//添加一个名为tommy的用户

passwd tommy //修改密码
Changing password for user tommy.
New UNIX password: //在这里输入新密码
Retype new UNIX password: //再次输入新密码
passwd: all authentication tokens updated successfully.
2、赋予root权限

方法一:修改 /etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉

/## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL

然后修改用户,使其属于root组(wheel),命令如下:

usermod -g root tommy

修改完毕,现在可以用tommy帐号登录,然后用命令 su – ,即可获得root权限进行操作。

方法二:修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:

/## Allow root to run any commands anywhere
root ALL=(ALL) ALL
tommy ALL=(ALL) ALL

修改完毕,现在可以用tommy帐号登录,然后用命令 sudo – ,即可获得root权限进行操作。

方法三:修改 /etc/passwd 文件,找到如下行,把用户ID修改为 0 ,如下所示:
tommy:x:0:33:tommy:/data/webroot:/bin/bash


软件安装

distribution代表 軟體管理機制 使用指令 線上升級機制(指令) Red Hat/Fedora RPM rpm, rpmbuild YUM (yum) Debian/Ubuntu DPKG dpkg APT (apt-get)

apt

sudo apt-cache search

sudo apt install package

sudo apt-get update

更新所有已安装的软件包:
sudo apt-get upgrade

将系统升级到新版本
sudo apt-get dist-upgrade

卸载 apt --purge remove packagedpkg --purge package

apt clean apt autoclean


dpkg

dpkg -i package.deb #安装包 dpkg -r package #删除包 dpkg -P package #删除包(包括配置文件) dpkg -L package #列出与该包关联的文件 dpkg -l package #显示该包的版本 dpkg --unpack package.deb #解开deb包的内容 dpkg -S keyword #搜索所属的包内容 dpkg -l #列出当前已安装的包 dpkg -c package.deb #列出deb包的内容 dpkg --configure package #配置包

远程SSH连接

ssh user_name@202.118.75.247 -p 722


SFTP远程传输文件

sftp -o port=4322 sun@202.118.75.247

get -r /home/paper_2_data/ /home/papers/paper_2/data/

put -r /home/papers/paper_2/data/ /home/paper_2_data/

**SFTP:
get 从远端下载文件
put 将本地文件上传到远程。**


Putty –> pscp传输文件

C:\Users\Administrator>pscp -scp -r -P 722 g:\CNN\used_fort_test sun@202.118.75.247:~/

原创粉丝点击