linux 命令
wc -l 读取行数
ls -d 显示目录本身。ls -i显示i节点
ls -lF 在每个文件名后附上一个字符以说明该文件的类型,“*”表示可执行的普通
文件;“/”表示目录;“@”表示符号链接;“|”表示FIFOs;“=”表示套
接字(sockets)。
目录处理:
mkdir -p 创建递归目录
cp -p 保持文件的属性 cp -r 复制目录
rm -r 删除目录 -f 强制删除
文件处理:
touch
cat > filename << EOF //建立文本文件 最后输入EOF结束
cat -n 显示行号 tac 反向显示
more 空格 f 键 下翻页。回车: 一行
less: 同上。 可以向前翻页
/关键词: 查找。n 下一个
head -n 行数 tail -n 。 tail -f 动态显示
ln -s 原文件 目标文件 软链接相当于快捷方式。权限由最终的文件决定。
硬链接与cp命令相似,但区别是硬链接文件修改后同步更新。硬链接的i节点相同。
硬链接不能跨分区,也不能对目录进行硬链接。
权限管理:
chmod u+x filename
-R 递归修改 //R W X : 4 2 1
file的r w x 文件夹的r:可读 ls w:操作文件夹中的文件 rm 。。x: 进入的权限
chown:root 操作 chgrp:改变组
添加用户: useradd passwd 添加组:groupadd
umask -S 显示缺省 umask 555 修改
文件搜索:
find 搜索范围 匹配条件
名字查找:
find /etc -name init //文件名搜索 只找init
模糊含init的:
find /etc -name *init*
find /etc -name int??? //? 匹配单个字母
find /etc -iname init //不区别大小写
文件大小查找:
find /etc -size +1024 //+号:大于1个数据块为512字节
//- = 小于 等于
时间查找:
-amin 访问时间 access
-cmin 文件属性改变 change
-mmin 文件内容 modify
find /etc -mmin -30 //30分钟内内容改变的文件
-a :and 两个条件都满足
find /etc -size +23 -a -size -33
-o : or
-type: 类型// f 文件 d 目录
-exec/-ok {}\;对结果执行操作 \\ok 提出是否确认
find /etc -name inittab -exec ls -l {} \;
find /etc -name init* -a -type f -exec ls-l {} \;
-inum i节点查找
其他查找命令:
locate: 在数据资料库中查找文件. updatedb 更新库 -i 不区分大小写
which:搜索命令所在目录及别名信息: which ls
whereis: 搜索命令及帮助文档的位置。
把一个文件复制多份:
cat file | tee filename{1,2,3,...}
linux 任务管理-后台运行与终止
jobs -l 显示pid
fg、bg、jobs、&、ctrl + z命令
fg %1 ....
kill %1, kill pidnumber
kill除了可以终止进程,还能给进程发送其它信号,使用kill -l 可以察看kill支持的信号。
killall filename1 filename2 filename3
sudo mount -t ntfs-3g /dev/sdc /mnt/window
sudo umount /mnt/window
#sdc 移动硬盘
sort 命令:
ls -l /usr/bin | sort -nr -k 5 | head
sort --key=1,1 --key=2n distros.txt \\-k 1,1 -k 2n
Since we wanted to limit the sort to just the first field, we speci -
fied 1,1 which means “start at field one and end at field one.” In the second instance, we
specified 2n, which means that field 2 is the sort key and that the sort should be numeric.
An option letter may be included at the end of a key specifier to indicate the type of sort
to be performed. These option letters are the same as the global options for the sort pro-
gram: b (ignore leading blanks), n (numeric sort), r (reverse sort), and so on.
sort -k 3.7nbr -k 3.1nbr -k 3.4nbr distros.txt \\第3段第7个字符开始然后 3.1,3.4排
sort -t ':' -k 7 /etc/passwd | head
uniq命令 要先sort再使用
expand 命令: convert tabs to spaces
cut命令:
cut -f 3 distros.txt //tab为分割符的 第3段
cut -f 3 distros.txt | cut -c 7-10 // -c表示7到第10个字符
cut -d ':' -f 1 /etc/passwd | head
paste命令
sort -k 3.7nbr -k 3.1nbr -k 3.4nbr distros.txt > distros-by-date.txt
cut -f 1,2 distros-by-date.txt > distros-versions.txt //截留1和2段
cut -f 3 distros-by-date.txt > distros-dates.txt
paste distros-dates.txt distros-versions.txt
join命令:
两个文件中有一列是相同的才生效.
文件比较:
comm file1 file2 //files should be sorted
显示3列: 1列为file1独有. 2列为file2独有 3列为共有
comm -12 file1 file2 //只显示第3列 压制1和2列的意思
diff命令:
r1ar2 Append the lines at the position r2 in the second file to the position r1 in the first file.
r1cr2 Change (replace) the lines at position r1 with the lines at the position r2 in the second file.
r1dr2 Delete the lines in the first file at position r1, which would have appeared at range r2 in the second file
diff -c file1.txt file2.txt
blank A line shown for context. It does not indicate a difference between files
- A line deleted. This line will appear in the first file but not in the second file.
+ A line added. This line will appear in the second file but not in the first file.
! A line changed. The two versions of the line will be displayed, each in its respective section of the change group.
diff -u file1.txt file2.txt
blank This line is shared by both files.
- This line was removed from the first file.
+ This line was added to the first file.
patch命令:
diff -Naur old_file new_file > diff_file
patch < diff_file
系统方面:
free uptime ps aux top w watch -n 1 uptime uname last who history sosreport
查看文件:
od cat more tail -f (刷新) head tr (转换) stat(查文件的具体信息)
dd if=/dev/cdrom of=RHEL-server-7.0-x86_64-LinuxProbe.Com.iso
用户管理:
passwd useradd usermod userdel groupadd