linux 命令记录,linux记录


1.  SSH 命令

ssh命令用于远程登录上Linux主机。

常用格式:ssh [-l login_name] [-p port] [user@]hostname
更详细的可以用ssh -h查看。

举例

不指定用户:

ssh 192.168.0.11

指定用户:

ssh -l root 192.168.0.11

ssh root@192.168.0.11


如果修改过ssh登录端口的可以:

ssh -p 12333 192.168.0.11

ssh -l root -p 12333 216.230.230.114

ssh -p 12333 root@216.230.230.114

另外修改配置文件/etc/ssh/sshd_config,可以改ssh登录端口和禁止root登录。改端口可以防止被端口扫描。

编辑配置文件:

vim /etc/ssh/sshd_config

找到#Port 22,去掉注释,修改成一个五位的端口:

Port 12333

找到#PermitRootLogin yes,去掉注释,修改为:

PermitRootLogin no

重启sshd服务:

service sshd restart

 

2.

Linux scp命令用于Linux之间复制文件和目录,具体如何使用这里好好介绍一下,从本地复制到远程、从远程复制到本地是两种使用方式。这里有具体举例:

==================

Linux scp 命令

==================

scp 可以在 2个 linux 主机间复制文件;

命令基本格式:

scp [可选参数] file_source file_target

======

从 本地 复制到 远程

======

* 复制文件:

* 命令格式:

scp local_file remote_username@remote_ip:remote_folder

或者

scp local_file remote_username@remote_ip:remote_file

或者

scp local_file remote_ip:remote_folder

或者

scp local_file remote_ip:remote_file

第1,2个指定了用户名,命令执行后需要再输入密码,第1个仅指定了远程的目录,文件名字不变,第2个指定了文件名;

第3,4个没有指定用户名,命令执行后需要输入用户名和密码,第3个仅指定了远程的目录,文件名字不变,第4个指定了文件名;

* 例子:

scp /home/space/music/1.mp3 root@www.cumt.edu.cn:/home/root/others/music

scp /home/space/music/1.mp3 root@www.cumt.edu.cn:/home/root/others/music/001.mp3

scp /home/space/music/1.mp3 www.cumt.edu.cn:/home/root/others/music

scp /home/space/music/1.mp3 www.cumt.edu.cn:/home/root/others/music/001.mp3

* 复制目录:

* 命令格式:

scp -r local_folder remote_username@remote_ip:remote_folder

或者

scp -r local_folder remote_ip:remote_folder

第1个指定了用户名,命令执行后需要再输入密码;

第2个没有指定用户名,命令执行后需要输入用户名和密码;

* 例子:

scp -r /home/space/music/ root@www.cumt.edu.cn:/home/root/others/

scp -r /home/space/music/ www.cumt.edu.cn:/home/root/others/

上面 命令 将 本地 music 目录 复制 到 远程 others 目录下,即复制后有 远程 有 ../others/music/ 目录

======

从 远程 复制到 本地

======

从 远程 复制到 本地,只要将 从 本地 复制到 远程 的命令 的 后2个参数 调换顺序 即可;

例如:

scp root@www.cumt.edu.cn:/home/root/others/music /home/space/music/1.mp3

scp -r www.cumt.edu.cn:/home/root/others/ /home/space/music/

最简单的应用如下 :

scp 本地用户名 @IP 地址 : 文件名 1 远程用户名 @IP 地址 : 文件名 2

[ 本地用户名 @IP 地址 :] 可以不输入 , 可能需要输入远程用户名所对应的密码 .

可能有用的几个参数 :

-v 和大多数 linux 命令中的 -v 意思一样 , 用来显示进度 . 可以用来查看连接 , 认证 , 或是配置错误 .

-C 使能压缩选项 .

-P 选择端口 . 注意 -p 已经被 rcp 使用 .

-4 强行使用 IPV4 地址 .

-6 强行使用 IPV6 地址 .

Linux scp命令的使用方法应该可以满足大家对Linux文件和目录的复制使用了。

 

3.

mv命令是move的缩写,可以用来移动文件或者将文件改名(move (rename) files),是Linux系统下常用的命令,经常用来备份文件或者目录。该命令如同MSDOS下的ren和move的组合。

 

常用参数

格式:mv file1 file2

将文件file1改名为file2。

 

格式:mv file dir

将文件file移动到目录dir中。

 

格式:mv file1 file2 file3 dir

格式:mv -t dir file1 file2 file3

将文件file1,file2和file3移动到目录dir中。

 

格式:mv -i file1 file2

将文件file1改名为file2,如果file2已经存在,则询问是否覆盖。i=interactive, prompt before overwrite。

一般情况下,我们使用的mv是一个别名:alias mv='mv -i'

 

格式:mv -f file1 file2

将文件file1改名为file2,即使file2存在,也是直接覆盖掉。f=force, do not prompt before overwriting。这是个危险的选项,最好不用加上它。

 

格式:mv dir1 dir2

如果目录dir2不存在,将目录dir1改名为dir2;否则,将dir1移动到dir2中。

 

使用示例

示例一 文件改名的例子

[root@jfht ~]# ls fangsong.ttf
fangsong.ttf
[root@jfht ~]# mv fangsong.ttf 仿宋_GB2312.ttf
[root@jfht ~]# ls fangsong.ttf 仿宋_GB2312.ttf 
ls: fangsong.ttf: 没有那个文件或目录
仿宋_GB2312.ttf
[root@jfht ~]# mv 仿宋_GB2312.ttf fangsong.ttf
[root@jfht ~]# ls fangsong.ttf 仿宋_GB2312.ttf
ls: 仿宋_GB2312.ttf: 没有那个文件或目录
fangsong.ttf
[root@jfht ~]#

 

示例二 移动文件的例子

最近发现/目录下有很多日志文件(某个日志路径 配置 有问题),想把它清除掉,先移动到/tmp目录中,tmpwatch会自动帮你去删除它们。

[root@web ~]# ls /LOG* | wc -l
3484
[root@web ~]# mv /LOG* /tmp
[root@web ~]# ls /LOG* | wc -l
ls: /LOG*: 没有那个文件或目录
0
[root@web ~]#

 

示例三 mv是一个别名

[root@web tmp]# type -a mv
mv is aliased to `mv -i'
mv is /bin/mv

[root@web tmp]# touch 1.txt 2.txt
[root@web tmp]# mv 1.txt 2.txt
mv:是否覆盖“2.txt”? y
[root@web tmp]#

 

问题思考

相关资料

【1】中国IT实验室 linux下的mv命令使用详解
http://linux.chinaitlab.com/command/38019.html
【2】时光漂流瓶 linux下mv命令使用方法
http://www.9usb.net/200902/linux-mv.html
【3】Linux安全在线 linux mv命令参数及用法详解---移动或重命名文件或目录
http://www.linuxso.com/command/mv.html

 

4.

Is there a way/command to get a listing of all the commands available on my system from the commandline prompt?

 

Usually pressing tab once or twice will display a message such as:

Display all 435 possibilities? (y or n)

Pressing Y will display all commands you can run that are on your default path.

相关内容

    暂无相关文章