0%

Linux笔记

I think if you want to know the options, you just need to type man/info+options or option—help is enough.

Overview

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
pwd
cd
grep
touch
rm
ls
cat
cp
mv
rmdir
df # check the disk space of the hard partition
du # display the file directory or size
fask # check and repair the Linux file system
bzip2/bunzip2 # bunzip2 a.bz2 bzip2 a.bz2 f1 f2 f3
gzip/gunzip # gzip [-r] f1 f2 f2 gunzip a.gz
zip/unzip # same as zip
tar
# create a tar file - cvf
# list contents os the tar file - xvf
# create a file that uses tar and bzip2 to archive compressed files - cjvf
# expand and unarchive the bZIP tar file - xjvf
# archive and compressed with tar and gzip - czvf
ps # see which programs are being executed
top # view execution scenario and memory usage of the current
kill # terminate an executing process
date
chmod
su
useradd
ftop
bye
ping
telnet
netstat

Linux

Features of the Linux Operating System

  • Multiuser
  • Multiprogramming
  • Time-sharing
  • Multitasking
  • Virtual memory
  • Shared libraries
  • POSIX-compliance
  • Samba
  • Network Information Service
  • Cron scheduler
  • Office suites
  • Data archiving utilities
  • Licensing
  • Web Server
  • Other features: have many free software.

Advantages of Linux

  • Open-source
  • Reliability
  • Backward compatibility
  • Simple upgrade and installation process
  • Low total cost of ownership
  • Support for legacy devices
  • GUI interface
  • Multiple distributors
  • Excellent security features
  • Support for high user load
  • Support for development libraries

Distributors of Linux

  • Red Hat
  • Mandriva
  • Debian
  • SUSE
  • Slackware
  • Fedora

Consist

three main components

  • Kernel
  • Shell
  • Linux Utilities and Application Programs

文件系统

.gnome-desktop桌面

Commend

passwd

1
passwd

change the user password.
修改用户密码

root可以修改其他用户密码

1
passwd username

date

Show the date.
显示日期和时间

1
date
1
2
3
4
date "+opt"
Eg
date "+%T"
13:13:13
1
2
3
4
date "+text opt"
Eg
date "+DATE : %D"
DATE : 1/9/2019
Option Description
%m Displays month of the year
%d Displays day of the month
%y Displays year
%D Displays date as mm/dd/yy
%H Displays hour
%M Displays minutes
%S Displays seconds
%T Displays time as HH:MM:SS
%a Displays abbreviated weekday
%h Displays abbreviated month
%r Displays time in the AM/PM notation

clear

Clear Screen.
清屏

tput - Pending

tput 完成交互,专业性强的屏幕输出

Option Description
tput clear clear screen
tput sc save the position of cursor
tput cup change the position of cursor
tput civis Hide the cursor
tput cnorm Show the cursor
tput rc show the output
tput smso
tput rmso
tput blink
tput reset

who

显示当前登录的用户
第一列:登录名
第二列:终端类型和终端号
第三列:登录时间
第四列:The remote host name of the terminal from where the user has logged in. Note that this is shown only for users who have not logged in from the server.

1
who
Option Description
-m 当前登录用户名,等价于who am i
-q 只显示登录名和登录数
1
who am i

uptime

显示系统持续时间

分别是:当前时间,系统运行时间,登录用户数,平均CPU使用率

1
uptime

man

1
man +程序名

info

info比man要详细一些

1
info [options] [menu item]

Option Description
—apropos=string Search string
-o,—output=FILENAME output the information
-h,-help help
—version version

cd

change the current directory

1
2
3
4
5
6
7
cd ../ 切换到上一层目录

cd / 切换到系统根目录

cd ~ 切换到用户主目录

cd - 切换到上一个所在目录(返回)

ls

显示目录下的文件和子文件夹
ls -l

Column Description
1 文件类型和权限
2 Number of link
3 文件所有者
4 组所有者
5 文件大小
6,7,8 最后修改时间
9 文件名

文件类型

Symbol Description
- 普通文件
d 文件夹
b
c
l
s
p

| Option | Description |
| -a | 显示所有文件 |
| -F | |
| -R | |
| -r | |
| -S | |
| -A | |

cat

pwd

显示当前目录

1
pwd

mkdir

cp

rm

rmdir

删除文件夹

1
rmdir +文件夹名

mv

0<,1>,1>>,2>

文件重定向

Option Description
0<,< 读入
>,1> 输出到文件,重新写
>>,1>> 续写文件
2> 输出错误提示信息到文件

chmod

- --- --- ---
dir|document owner group otheruser

Symbol Meaning Number
r read 4
w write 2
x execute 1
- no 0
Symbol Meaning
u owner
g group
o otheruser
a alluser

chmod u|g|o|a +|- r|w|x file_name
chmod 777 file_name

filters

使用多个过滤器时用|分隔开,在最前面写文件名

grep

1
grep [option(s)] pattern [filename]

以行为单位筛选包含指定字符的行

Option Description
-n 显示行号
-c 输出匹配到行的个数
-v 反向查找,查找不匹配的行

wc

1
wc [option(s)] [filename]

计数工具

Option Description
-l 显示行数量
-w 显示单词数
-c 显示字符数

cut

1
cut [option(s)] [filename]

显示一列、一列字符

Option Description
-f 显示的列数,用逗号分隔,可用-连接
-c 显示每列字符的位数
-d<column_delimiter 列分隔符

tr

tr字符可以对来自标准输入的字符进行替换、压缩和删除,可以将一组字符编程另外一组字符。

例如

1
tr "[a-z]" "[A-Z]"

转换小写为大写
需要文件重定向来写入

Option Description
-c, -C, --complement 取代所有不属于第一字符集的字符
-d, --delete 删除所有属于第一字符集的字符
-s, --squeeze-repeats 把连续重复的字符以单独一个字符表示
-t, --truncate-set1 先删除第一字符集较第二字符集多出的字符

sort

排序

ascending(asc)正序
descending(desc)倒序

Option Description
-b 忽略每行前面开始出的空格字符
-c 检查文件是否已经按照顺序排序
-d 排序时,处理英文字母、数字及空格字符外,忽略其他的字符
-f 排序时,将小写字母视为大写字母
-i 排序时,除了040至176之间的ASCII字符外,忽略其他的字符
-m 将几个排序好的文件进行合并
-M 将前面3个字母依照月份的缩写进行排序
-n 依照数值的大小排序
-o 将排序后的结果存入指定的文件
-r 以相反的顺序来排序
-t<分隔字符> 指定排序时所用的栏位分隔字符
+<起始栏位>-<结束栏位> 以指定的栏位来排序,范围左闭右开
Have fun.