Linux学习一

一、命令行:
1、ls
[root@localhost ~]# ls -l my* //查找带my字样的文件
-rw-r–r–. 1 root root 0 Apr 11 2023 my_file
-rw-r–r–. 1 root root 0 Apr 11 2023 my_scrapt
-rw-r–r–. 1 root root 0 Apr 11 2023 my_script

ls -i, --inode //显示文件索引号
print the index number of each file

ls -l //显示详细列表
[root@localhost ~]# ls -l
total 4
-rw-------. 1 root root 1259 Apr 10 23:13 anaconda-ks.cfg
-rw-r–r–. 1 root root 0 Apr 11 2023 fall
-rw-r–r–. 1 root root 0 Apr 11 2023 fell
-rw-r–r–. 1 root root 0 Apr 11 2023 fill
-rw-r–r–. 1 root root 0 Apr 11 2023 full
-rw-r–r–. 1 root root 0 Apr 11 2023 my_file
-rw-r–r–. 1 root root 0 Apr 11 2023 my_scrapt
-rw-r–r–. 1 root root 0 Apr 11 2023 my_script
-rw-r–r–. 1 root root 0 Apr 11 11:46 test_one

2、touch
touch命令轻松创建空文件:
$ touch test_one
$ ls -l test_one
-rw-rw-r–. 1 christine christine 0 Feb 29 17:24 test_one
$

3、cp
$ ls -l test_one test_two //强制shell询问是否需要覆盖已有文件
-rw-rw-r–. 1 christine christine 0 Feb 29 17:26 test_one
-rw-rw-r–. 1 christine christine 0 Feb 29 17:46 test_two
$
$
cp -i test_one test_two cp: overwrite ‘test_two’? n
$

4、链接文件
符号链接
也叫软链接,类似与windows的快捷方式,可以通过ls -l查看,也可以通过ls -i查看文件索引号
$ ls -l test_file
-rw-rw-r–. 1 christine christine 74 Feb 29 15:50 test_file
$
$ ln -s test_file slink_test_file
$
$ ls -l *test_file lrwxrwxrwx. 1 christine christine 9 Mar 4 09:46 slink_test_file -> test_file
-rw-rw-r–. 1 christine christine 74 Feb 29 15:50 test_file
$
硬链接
以硬链接相连的文件共享同一个inode编号。这是因为两者其实就是同一个文件。
$ ls -l *test_one
-rw-rw-r–. 1 christine christine 0 Feb 29 17:26 test_one
$
$ ln test_one hlink_test_one
$
$ ls -li *test_one
1415016 -rw-rw-r–. 2 christine christine 0 Feb 29 17:26 hlink_test_one
1415016 -rw-rw-r–. 2 christine christine 0 Feb 29 17:26 test_one
$

5、文件重命名 mv
$ ls -li f?ll
1414976 -rw-rw-r–. 1 christine christine 0 Feb 29 16:12 fall
1415004 -rw-rw-r–. 1 christine christine 0 Feb 29 16:12 fell
1415005 -rw-rw-r–. 1 christine christine 0 Feb 29 16:12 fill
1415011 -rw-rw-r–. 1 christine christine 0 Feb 29 16:12 full
$
$ mv fall fzll
$
$ ls -li f?ll
1415004 -rw-rw-r–. 1 christine christine 0 Feb 29 16:12 fell
1415005 -rw-rw-r–. 1 christine christine 0 Feb 29 16:12 fill
1415011 -rw-rw-r–. 1 christine christine 0 Feb 29 16:12 full
1414976 -rw-rw-r–. 1 christine christine 0 Feb 29 16:12 fzll
$

6、删除文件或目录
rm -rf myfileone // -r remove directories and their contents recursively 递归删除目录及其内容
// -f ignore nonexistent files and arguments, never prompt 忽略不存 在的文件和参数,从不提示

二、监控命令
1、查探进程命令
ps
standard syntax:
ps -e
ps -ef
ps -eF
ps -ely

To see every process on the system using BSD
syntax:
ps ax
ps axu

To print a process tree:
ps -ejH
ps axjf

To get info about threads:
ps -eLf
ps axms

To get security info:
ps -eo euser,ruser,suser,fuser,f,comm,label
ps axZ
ps -eM

To see every process running as root
(real & effective ID) in user format:
ps -U root -u root u

也可以使用top命令查看

2、kill命令:kill命令可以通过PID向进程发送信号。在默认情况下,kill命令会向命令行中列出的所有PID发送TERM信号。要发送进程信号,必须是进程的属主或root用户:

kill -s HUP 3940

3、pkill:pkill命令可以使用程序名代替PID来终止进程,这就方便多了,可以使用通配符

pkill http*

警告 以root身份使用pkill命令时要格外小心。命令中的通配符很容易意外地将系统的重要进程终止。这可能会导致文件系统损坏。

3、监控磁盘空间
3.1、磁盘挂载 mount 格式: mount -t type device directory
例:mount -t vfat /dev/sdb1 /media/disk
·vfat:Windows FAT32文件系统,支持长文件名。
·ntfs:Windows NT及后续操作系统中广泛使用的高级文件系统。
·exfat:专门为可移动存储设备优化的Windows文件系统。
·iso9660:标准CD-ROM和DVD文件系统
3.2、移除设备,卸载 umount 格式:umount [directory | device ]
例:# umount /home/rich/mnt
umount: /home/rich/mnt: device is busy
umount: /home/rich/mnt: device is busy
# cd /home/rich
# umount /home/rich/mnt
# ls -l mnt total 0
#
3.3、df命令查看设备上还有多少磁盘空间
$ df -t ext4 -t vfat
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 19475088 7326256 11136508 40% /
/dev/sda2 524272 4 524268 1% /boot/efi
/dev/sdb1 983552 247264 736288 26% /media/
rich/54A1-7D7D
$

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值