1.如何查询Linux命令的用法
Linux 命令众多,如何知道一个命令的用法
① 使用man命令查询用法。但是man手册比较晦涩
[xiaokang@localhost ~]$ man tar
② 使用工具自带的help,比如 tar --help
[xiaokang@localhost ~]$ tar --help
③ 介绍一个man的替代工具 tldr。它收藏许多Linux命令并提供非常友好的示例。
[xiaokang@localhost ~]$ tldr tar
# tar
Archiving utility.
Often combined with a compression method, such as gzip or bzip.
More information: <https://www.gnu.org/software/tar>.
- Create an archive from files:
tar -cf target.tar file1 file2 file3
- Create a gzipped archive:
tar -czf target.tar.gz file1 file2 file3
- Extract an archive in a target directory:
tar -xf source.tar -C directory
- Extract a gzipped archive in the current directory:
tar -xzf source.tar.gz
- Extract a bzipped archive in the current directory:
tar -xjf source.tar.bz2
- Create a compressed archive, using archive suffix to determine the compression program:
tar -caf target.tar.xz file1 file2 file3
- List the contents of a tar file:
tar -tvf source.tar
- Extract files matching a pattern:
tar -xf source.tar --wildcards "*.html"
2.面试常考Linux问题:
- crontad:定时任务
例如:下单操作,需要在单个小时内付完款,通过定时任务每半个小时进行一下数据释放。
① 编辑当前用户的计数器设置,与vim操作是一样的
[xiaokang@localhost ~]$ crontab -e # 编辑crontab
crontab: no changes made to crontab
② 列出该用户的计数器设置
[xiaokang@localhost www]$ crontab -l
*/1 * * * * php /data/www/cron.php >> /tmp/cron.log # */1表示每隔1分钟执行一次
# * * * * * 分别代表分 时 日 月 周
- 如何搜索进程所占用端口和进程状态
[xiaokang@localhost ~]$ sudo netstat -anpl | grep memcached # 查看进程端口号
[sudo] password for xiaokang:
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 3689/memcached
tcp6 0 0 :::11211 :::* LISTEN 3689/memcached
udp 0 0 0.0.0.0:11211 0.0.0.0:* 3689/memcached
udp6 0 0 :::11211 :::* 3689/memcached
[xiaokang@localhost ~]$ ps -ef | grep memcached # 查看进程状态
xiaokang 4332 1 0 00:04 ? 00:00:00 memcached -d
xiaokang 4340 4252 0 00:05 pts/0 00:00:00 grep --color=auto mem
- 如何使用find查找文件
[root@192 tmp]# find . (点表示当前目录,列出当前文件下所有文件)
[root@192 tmp]# find /etc/ -name "*.conf" (星号表示所有字符,列出etc目录下以点conf结尾文件)
[root@192 tmp]# find . -type f (type表示类型,f表示文件,列出当前目录所有文件)
[root@192 tmp]# find . -type d (type表示类型,d表示文件夹,列出当前目录所有文件夹)
[root@192 tmp]# find . -ctime -1 (ctime表示当前时间,-1表示减一天,列出一天内修改过的文件)
# Ctrl+c 退出查看
- 软链接和硬链接区别
软链接有点类似于Windows中的快捷方式,里面保存的是指向源文件的绝对路径,当访问它的时候就会替换成指向文件的路径。对于操作系统是通过 inode值访问硬盘的区块,对于软链接来说inode值和源文件的inode值是不一样的,但是硬链接是一样的inode值。只要有文件inode值指向这个区块,这个文件就始终不会消失。软链接文件只是维持了从软链接到源文件的指向关系,不是源文件的内容。
硬链接相当于创建了一个普通文件,但硬链接的inode值和源文件的inode值相同都指向同一个区块。硬链接文件的内容和源文件的内容一模一样,相当于copy了一份源文件。
inode介绍:文件或目录的inode编号是一个用于标识的唯一数字,这个数字由内核分配给文件系统中的每一个对象。inode就像人的身份证。
- grep 与 find 区别
grep:grep命令是一种文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。其常用来查找匹配条件的行。
find:find命令从指定的起始目录开始,递归地搜索其各个子目录,查找满足寻找条件的文件。其常用来搜索匹配条件的文件。