从零开始学kali命令行(3)

type 显示命令的类型

type msfconsole
msfconsole 是 /usr/bin/msfconsole
root@kali:~# type cp
cp 是 /bin/cp
root@kali:~# type ls
ls 是 `ls --color=auto' 的别名
root@kali:~# type cd
cd 是 shell 内嵌

which 显示一个可执行程序的位置

root@kali:~# which ls
/bin/ls
root@kali:~# which cd
root@kali:~# which clear
/usr/bin/clear

这个命令只对可执行程序有效,不包括内部命令和命令别名

help 得到 shell 内部命令的帮助

 help cd
cd: cd [-L|[-P [-e]]] [dir]
    Change the shell working directory.
    
    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.
    
    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.
    
    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.
    
    Options:
        -L	force symbolic links to be followed
        -P	use the physical directory structure without following symbolic
    	links
        -e	if the -P option is supplied, and the current working directory
    	cannot be determined successfully, exit with a non-zero status
    
    The default is to follow symbolic links, as if `-L' were specified.
    
    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.

cd: cd [-L|[-P [-e]]] [dir]
方括号,表示可选的项目。
竖杠字符表示互斥
这种表示法说明,cd 命令可能有一个 “-L” 选项或者”-P” 选项,进一步,可能有参数
“dir”

–help也可以显示帮助

mkdir --help
用法:mkdir [选项]... 目录...
若指定目录不存在则创建目录。

长选项必须使用的参数对于短选项时也是必需使用的。
  -m, --mode=模式   	设置权限模式(类似chmod),而不是rwxrwxrwx 减umask
  -p, --parents     	需要时创建目标目录的上层目录,但即使这些目录已存在也不当作错误处理
  -v, --verbose     	每次创建新目录都显示信息
  -Z, --context=CTX  	将每个创建的目录的SELinux 安全环境设置为CTX
      --help		显示此帮助信息并退出
      --version		显示版本信息并退出

请向bug-coreutils@gnu.org 报告mkdir 的错误
GNU coreutils 的主页:<http://www.gnu.org/software/coreutils/>
GNU 软件一般性帮助:<http://www.gnu.org/gethelp/>
请向<http://translationproject.org/team/zh_CN.html> 报告mkdir 的翻译错误
要获取完整文档,请运行:info coreutils 'mkdir invocation'

man 显示程序手册页
许多可执行程序,提供了一个正式的文档,叫做手册 (manpage)。一个特殊的叫做 man 的分页程序,可用来浏览他们。
手册一般地包含一个标题,命令语法的纲要,命令用途的说明,和命令选项列表,及每个选项的说明。
在大多数 Linux 系统中,man 使用 less 工具来显示参考手册
man 所显示的参考手册,被分成几个章节
1 用户命令
2 程序接口内核系统调用
3 C 库函数程序接口
4 特殊文件,比如说设备结点和驱动程序
5 文件格式
6 游戏娱乐,如屏幕保护程序
7 其他方面
8 系统管理员命令

两种用法
查找对应的章节和从头查找

man passwd
root@kali:~# man 5 passwd

apropos 显示适当的命令

apropos  passwd
chpasswd (8)         - 批量更新密码
gpasswd (1)          - 管理员 /etc/group 和 /etc/gshadow
passwd (1)           - 更改用户密码
passwd (5)           - 密码文件
chgpasswd (8)        - update group passwords in batch mode
Crypt::PasswdMD5 (3pm) - Provides interoperable MD5-based crypt() functions
exim4_passwd (5)     - Files in use by the Debian exim4 packages
exim4_passwd_client (5) - Files in use by the Debian exim4 packages
fgetpwent_r (3)      - get passwd file entry reentrantly
getpwent_r (3)       - get passwd file entry reentrantly
grub-mkpasswd-pbkdf2 (1) - generate hashed password for GRUB
htpasswd (1)         - Manage user files for basic authentication
lppasswd (1)         - add, change, or delete digest passwords.
mkpasswd (1)         - Overfeatured front end to crypt(3)
mksmbpasswd (8)      - formats a /etc/passwd entry for a smbpasswd file
pam_localuser (8)    - require users to be listed in /etc/passwd
passwd (1ssl)        - compute password hashes
passwd2des (3)       - RFS password encryption
smbpasswd (5)        - The Samba encrypted password file
smbpasswd (8)        - change a user's SMB password
SSL_CTX_set_default_passwd_cb (3ssl) - set passwd callback for encrypted PEM ...
SSL_CTX_set_default_passwd_cb_userdata (3ssl) - set passwd callback for encry...
tightvncpasswd (1)   - set passwords for VNC server
unshadow (8)         - combines passwd and shadow files
update-passwd (8)    - safely update /etc/passwd, /etc/shadow and /etc/group
vncpasswd (1)        - set passwords for VNC server

info 显示程序 Info 条目

info

alias创造别名命令

linux一行可以输入多个命令,每个命令以;分割

 pwd;ls;ls -l
/root
auto.hard  automate.rc  Desktop  trape  trape-sym
总用量 16
-rw-r--r-- 2 root root  175  5月 11 12:48 auto.hard
-rw-r--r-- 2 root root  175  5月 11 12:48 automate.rc
drwxr-xr-x 2 root root 4096  4月  7 18:40 Desktop
drwxr-xr-x 6 root root 4096  5月  5 17:37 trape
lrwxrwxrwx 1 root root    5  6月  2 09:46 trape-sym -> trape

下面创造别名
首先查一下用没有被用过

 type haha
bash: type: haha: 未找到
root@kali:~# alias haha='pwd;ls;ls -l'

alias 别名=‘输入你想要的命令’

haha
/root
auto.hard  automate.rc  Desktop  trape  trape-sym
总用量 16
-rw-r--r-- 2 root root  175  5月 11 12:48 auto.hard
-rw-r--r-- 2 root root  175  5月 11 12:48 automate.rc
drwxr-xr-x 2 root root 4096  4月  7 18:40 Desktop
drwxr-xr-x 6 root root 4096  5月  5 17:37 trape
lrwxrwxrwx 1 root root    5  6月  2 09:46 trape-sym -> trape
type haha
haha 是 `pwd;ls;ls -l' 的别名
root@kali:~# type ls
ls`ls --color=auto' 的别名

刚才的这个应该可以理解了吧,ls也是这样的别名
删除别名

unalias haha
root@kali:~# type haha
bash: type: haha: 未找到
root@kali:~# haha
bash: haha: 未找到命令

重定向
linux很强大的功能就是重定向
什么是重定向?简单地说,就是输入和输出的定向,一般来说linux的输入来自于键盘,输出于屏幕,然而我们可以利用重定向把输入调整为从文件读取,输出调整为输出到文件中,这样有利于保存

ls > test.txt
root@kali:~# ls
auto.hard  automate.rc  Desktop  test.txt  trape  trape-sym
root@kali:~# vi test.txt
auto.hard
automate.rc
Desktop
test.txt
trape
trape-sym

> 加保存的文件名 ,就会把执行的结果保存下来

ls /root/sadas > test.txt
ls: 无法访问/root/sadas: 没有那个文件或目录
vi test.txt

刚才是执行成功了,把执行结果保存了,但这次执行失败了,错误信息输出了出来,而且test.txt被清空了,因为>默认只保存执行成功结果,这里由于结果为空,就清空了test.txt

ls > test.txt
root@kali:~# ls -l >> test.txt
vi test.txt 
auto.hard
automate.rc
Desktop
test.txt
trape
trape-sym
总用量 20
-rw-r--r-- 2 root root  175  5月 11 12:48 auto.hard
-rw-r--r-- 2 root root  175  5月 11 12:48 automate.rc
drwxr-xr-x 2 root root 4096  4月  7 18:40 Desktop
-rw-r--r-- 1 root root   55  6月  3 12:03 test.txt
drwxr-xr-x 6 root root 4096  5月  5 17:37 trape
lrwxrwxrwx 1 root root    5  6月  2 09:46 trape-sym -> trape

ls > test.txt
vi test.txt
auto.hard
automate.rc
Desktop
test.txt
trape
trape-sym

>>是在文件后面追加,>是重写…这是他们的一个 差别

标准输入,输出和错误,shell 内部参考它们为文件描述符 0,1 和 2
如果要保存错误信息可以用

 ls /root/dsad 2> test.txt
root@kali:~# vi test.txt
ls: 无法访问/root/dsad: 没有那个文件或目录

如果想把输出结果和错误都保存
加一个&即可

ls -l /bin/usr &> ls.txt

解释一下为什么这样.因为老版本的命令是
ls -l /bin/usr > ls.txt 2>&1
ls -l /bin/usr > ls.txt大家都熟悉,2>&1就是把错误信息保存到输出结果文件中,2>&1,后来简写就变成上面那个了

cat 命令

root@kali:/dev# cat

因为我们没有给任何参数,他将从标准输入就是键盘,输出到标准输出-屏幕
输出结束可以按住回车,这样会再下一行输出出来,然后可以继续输入,只是上一行的内容已经保存好了,按住 Ctrl 键同时按下 “d”,会直接在输入内容后面输出,这两种都是告诉cat输入结束

cat > 文件名
创建一个新的文件并且把输入结果保存,输入完ctrl+d结束

 cat >  1.txt
dasdsad
xixi
vi 1.txt
dasdsad
xixi    

cat 已有的文件
查看文件内容

 cat 1.txt
dasdsad
xixi

cat < 已有文件
把标准输入改为文件内容 并输出到标准输出
如果再加上>号就会输出到心得文件里面

cat < 1.txt   > 2.txt
root@kali:~# cat 2.txt
dasdsad
xixi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值