ubuntu常用命令

详细命令列表可在线查阅:

http://wiki.ubuntu.org.cn/index.php?title=UbuntuSkills&variant=zh-cn

 

关机命令 sudo shutdown

1)shutdown –help 查看shutdown命令如何使用,当然也可以使用man shutdown命令。

2)shutdown -h now 现在立即关机

3)shutdown -r now 立即重启

4)shutdown -r +3 三分钟后重启

5)shutdown -h +3 “The System will shutdown after 3 minutes” 提示使用者将在三分钟后关机

6)shutdown -r 20:23 2023时将重启计算机

中断命令

1)执行完命令后(若没有转到后台),可以使用CTRL+C来中止命令

文件或目录处理

列出文件或目录下之文件名称

执行格式: ls [-atFlgR] [name] ( name 可为文件名或目录名称。)

Example :

ls 列出目前目录下之文件名。

ls –a 列出包含以.起始的隐藏档所有文件名。

ls –t 依照文件最后修改时间之顺序,依序列出文件名。

ls –F 列出目前目录下之文件名及其类型。”/” 结尾表示为目录名称,“*” 结尾表示为执行档,”@” 结尾表示为 symblic link

ls –l 列出目录下所有文件之许可权、拥有者、文件大小、修改时间及名称。

ls –lg 同上,并显示出文件之拥有者群组名称。

ls –R 显示出目录下,以及其所有子目录之文件名。( recursive listing )

目录之缩写:

使用者 login 时的 working directory ( 起始目录 )

username 指定某位 user working directory ( 起始目录 )

. 目前的工作目录 ( current working directory )

.. 目前目录的上一层目录 ( parent of working directory)

改变工作目录位置

执行格式:cd [name] name 可为目录名称、路径或目录缩写。

Example:

cd 改变目录位置,至使用者 login 时的 working directory (起始目录)

cd dir1 改变目录位置,至 dir1 之目录位置下。

cd ~user 改变目录位置,至使用者的 working directory (起始目录)

cd .. 改变目录位置,至目前目录的上层( parent of working directory)

cd ../user 改变目录位置,至相对路径 user 之目录位置下。

复制文件

执行格式: cp [-r] source destination

Example:

cp file1 file2 将文件 file1 复制成 file2

cp file1 dir1 将文件 file1 复制到目录 dir1 下,文件名仍为 file1

cp /tmp/file1 将目录 /tmp 下的文件 file1 复制到现行目录下,文件名仍为 file1

cp /tmp/file1 file2 将目录 /tmp 下的文件 file1 复制到现行目录下,文件名为 file2

cp -r dir1 dir2 (recursive copy) 复制整个目录。若目录dir2存在,则将目录dir1,及其所有文件和子目录,复制到目录 dir2 下,新目录名称为 dir1。若目录 dir2 不存在,则将dir1,及其所有文件和子目录,复制为目录 dir2

移动或更改文件、目录名称

执行格式: mv source destination

Example:

mv file1 file2 将文件 file1,更改文件名为 file2

mv file1 dir1 将文件 file1,移到目录 dir1下,文件名仍为 file1

mv dir1 dir2 若目录 dir2 存在,则将目录 dir1,及其所有文件和子目录,移到目录 dir2 下,新目录名称为 dir1。若目录 dir2 不存在,则将dir1,及其所有文件和子目录,更改为目录 dir21

建立新目录

执行格式: mkdir directory-name

Exmaple

mkdir dir1 建立一新目录 dir1

删除目录

执行格式: rmr directory-name rm directory-name

Example

rmdir dir1 删除目录 dir1,但 dir1 下必须没有文件存在,否则无法删除。

rm -r dir1 删除目录 dir1,及其下所有文件及子目录。

删除文件

执行格式: rm filename (filename 可为文件名,或文件名缩写符号。)

Example

rm file1 删除文件名为 file1 之文件。

rm file? 删除文件名中有五个字符,前四个字符为file 之所有文件。

rm f* 删除文件名中,以 f 为字首之所有文件。

文件名的缩写符号

? 代表文件名称中之单一字符。

* 代表文件名称中之一字串。

列出目前所在之目录位置

执行格式: pwd

查看文件内容

执行格式: cat filename

Example

cat file1 以连续显示方式,查看文件名 file1 之内容。

执行格式: more filename cat filename | more

Example

more file1 以分页方式,查看文件名 file1 之内容。 cat file1 | more 同上。

文件模式之设定

改变文件或目录之读、写、执行之允许权

执行格式:chmod [-R] mode name

( name 可为文件名或目录名;mode可为 3 8 位元之数字,或利用ls -l 命令,列出文件或目录之读、写、执行允许权之文字缩写。)

mode : rwx rwx rwx r:read w:write x:execute

user group other

缩写 : (u) (g) (o)

Example :

%chmod 755 dir1 将目录dir1,设定成任何使用者,皆有读取及执行之权利,但只有拥有者可做修改。

%chmod 700 file1 将文件file1,设定只有拥有者可以读、写和执行。

%chmod o+x file2 将文件file2,增加拥有者可以执行之权利。

%chmod g+x file3 将文件file3,增加群组使用者可执行之权利。

%chmod o-r file4 将文件file4,除去其它使用者可读取之权利。

文件之字串找寻

执行格式:grep string file

Example

grep abc file1 寻找文件file1中,列出字串 abc 所在之整行文字内容。

找寻文件或命令之路径

执行格式:whereis command ( 显示命令之路径。)

执行格式:which command ( 显示命令之路径,及使用者所定义之别名。)

执行格式:whatis command ( 显示命令功能之摘要。)

执行格式:find search-path -name filename -print( 搜寻指定路径下,某文件之路径 。)

Example

%find / -name file1 -print ( 自根目录下,寻找文件名为 file1 之路径。.

查看系统之 process

执行格式:ps [-aux]

Example:

%ps ps –x (查看系统中,属于自己的 process)

%ps –au (查看系统中,所有使用者的 process)

%ps –aux (查看系统中,包含系统内部,及所有使用者的 process)

结束或终止 process

执行格式:kill [-9] PID ( PID 为利用 ps 命令所查出之 process ID)

Example:

%kill 456 kill -9 456 终止 process ID 456 process

pipe-line 之使用

执行格式:command1 | command2

command1 执行结果,送到 command2 做为 command2 的输入。

Example:

%ls -Rl | more 以分页方式,列出目前目录下所有文件,及子目录之名称。

%cat file1 | more 以分页方式,列出文件 file1 之内容。

I/O control

标准输入之控制

执行格式:command-line < file file 做为 command-line 之输入。

标准输出之控制

执行格式:command > filename command 之执行结果,送至指定的 filename 中。

Example: %ls -l > list 将执行 “ls -l” 命令之结果,写入文件 list 中。

改变自己的 username 进入其他使用者的帐号,拥有其使用权利。

执行格式: su username

Example:

%su user 进入使用者 user 之帐号

passwrod: 输入使用者 user 之密码

 

详细命令列表可在线查阅:

http://wiki.ubuntu.org.cn/index.php?title=UbuntuSkills&variant=zh-cn

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值