linux命令的学习
1.创建一个目录
常用命令有150个。
- mkdir make directorys创建目录 ---> mkdir /date
- ls list(列表) 列表目录文件 ls -ld /date 查看date目录下目录文件,不加目录就是当前目录 -l(long)长格式 -d(directorys)查看目录
- cd change directory 改变目录路径 eg: cd /etc
- 绝对路径
- windows绝对路径
- linux绝对路径 :必须从"/"开始
- 相对路径
- bucongtoukaishid
- pwd print work directory 打印工作目录(现实当前所在路径)
2.在linux创建一个目录
- touch 创建文件或更新时间戳,如果文件存在,我就只更新时间戳。
3.在文件下面增加一段文字
I am studying Linux.
1. 执行 vi oldboy.txt进入文档编辑模式
2. 然后按'i'或"o"或'a',进入INsert模式
3. 输入完毕后,按"ESC",选择"wq"退出。 wq: write quit q:退出,不保存
~vim 复杂编辑器(必须学会一个)~
echo 打印输出内容,配合'>','>>'可以为文件覆盖或者追加内容,还有一个较为复杂不常用的类似命令为'printf'
echo '111
222
333' >> oldgirl.txt
特殊符号:
* >或1> 输出重定向:把前面输出的东西覆盖文件,会清楚原文件的内容
* >>或1>> 输出追加重定向:把前面输出的东西追加给文件,不会清楚
* 0<或< 输入重定向:输入重定向用于改变命令的输入,后面指定输入内容,前面跟文件名
[root@linuxhua data]# echo 1 2 3 4 >1.txt
[root@linuxhua data]# cat 1.txt
1 2 3 4
[root@linuxhua data]# xargs -n 2 <1.txt
1 2
3 4
* 0<<或<< 输入追加重定向 :追加
red是一个pair ,首位标识
[root@linuxhua data]# cat 1.txt
[root@linuxhua data]# cat >>1.txt <<red
> hauhua
> is broken why?
> red
[root@linuxhua data]# cat 1.txt
hauhua
is broken why?
[root@linuxhua data]# echo yesornot 1>1.txt 2>2.txt
[root@linuxhua data]# cat 1.txt
yesornot
[root@linuxhua data]# cat 2.txt
执行正确、错误信息存放在2个文件中
[root@linuxhua data]# echo yesornot 1>1.txt 2>2.txt
[root@linuxhua data]# cat 1.txt
yesornot
[root@linuxhua data]# cat 2.txt
[root@linuxhua data]# cho error >1.txt 2>2.txt
[root@linuxhua data]# cat 2.txt
执行正确、错误信息都存在一个文件中
[root@linuxhua data]# echo error to one file &>1.txt
[root@linuxhua data]# cat 1.txt
error to one file
[root@linuxhua data]# ech add something &>>1.txt
[root@linuxhua data]# cat 1.txt
error to one file
bash: ech: command not found...
* cat:concatenate files and print on the standard output
4. 把oldboy.txt文件拷贝到/tmp下
* cp copy 拷贝文件或者目录,不加参数时,只能拷贝文件
如果想加目录拷贝,必须加 -r
4.把/data 目录移动到/root下
mv /data /root/
[root@linuxhua /]# dir
bin data etc lib media opt root sbin sys usr
boot dev home lib64 mnt proc run srv tmp var
[root@linuxhua /]# dir /root
anaconda-ks.cfg initial-setup-ks.cfg
[root@linuxhua /]# mv /data /root
[root@linuxhua /]# dir
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@linuxhua /]# dir root
anaconda-ks.cfg data initial-setup-ks.cfg
[root@linuxhua /]#
6. 进入root目录下的data进行删除操作
rm: remove 移动文件或者目录
[root@linuxhua data]# rm /root/data
rm: cannot remove ‘/root/data’: Is a directory
[root@linuxhua data]# rm 1.txt
rm: remove regular file ‘1.txt’? yes
[root@linuxhua data]# dir
20200210.txt 2.txt oldgirl.txt red 的用法
[root@linuxhua data]# rm red
rm: remove regular empty file ‘red’? yes
[root@linuxhua data]# rm 的用法
rm: remove regular file ‘的用法’? yes
[root@linuxhua data]# dir
20200210.txt 2.txt oldgirl.txt
[root@linuxhua data]#
-f 强制删除
-fr 强制删除,可删除目录
ps -ef |grep mysql ps -ef 查看所有的进程 grep 筛选 process status
另 提示: rm -fr force recursion 强制 、递归 kill 1548
在控制台执行man ps命令可以查看ps命令后面的命令选项的含义如下:
The options are as follows:
-A Display information about other users' processes, including those without controlling ter-
minals.
-a Display information about other users' processes as well as your own. This will skip any
processes which do not have a controlling terminal, unless the -x option is also specified.
-C Change the way the CPU percentage is calculated by using a ``raw'' CPU calculation that
ignores ``resident'' time (this normally has no effect).
-c Change the ``command'' column output to just contain the executable name, rather than the
full command line.
-d Like -A, but excludes session leaders.
-E Display the environment as well. This does not reflect changes in the environment after
process launch.
-e Identical to -A.
-f Display the uid, pid, parent pid, recent CPU usage, process start time, controlling tty,
elapsed CPU usage, and the associated command. If the -u option is also used, display the
user name rather then the numeric uid. When -o or -O is used to add to the display follow-
ing -f, the command field is not truncated as severely as it is in other formats.
-G Display information about processes which are running with the specified real group IDs.
-g Display information about processes with the specified process group leaders.
-h Repeat the information header as often as necessary to guarantee one header per page of
information.
-j Print information associated with the following keywords: user, pid, ppid, pgid, sess,
jobc, state, tt, time, and command.
-L List the set of keywords available for the -O and -o options.
-l Display information associated with the following keywords: uid, pid, ppid, flags, cpu,
pri, nice, vsz=SZ, rss, wchan, state=S, paddr=ADDR, tty, time, and command=CMD.
-M Print the threads corresponding to each task.
-m Sort by memory usage, instead of the combination of controlling terminal and process ID.
-O Add the information associated with the space or comma separated list of keywords speci-
fied, after the process ID, in the default information display. Keywords may be appended
with an equals (`=') sign and a string. This causes the printed header to use the speci-
fied string instead of the standard header.
-o Display information associated with the space or comma separated list of keywords speci-
fied. Multiple keywords may also be given in the form of more than one -o option. Key-
words may be appended with an equals (`=') sign and a string. This causes the printed
header to use the specified string instead of the standard header. If all keywords have
empty header texts, no header line is written.
-p Display information about processes which match the specified process IDs.
-r Sort by current CPU usage, instead of the combination of controlling terminal and process
ID.
-S Change the way the process time is calculated by summing all exited children to their par-
ent process.
-T Display information about processes attached to the device associated with the standard
input.
-t Display information about processes attached to the specified terminal devices.
-U Display the processes belonging to the specified real user IDs.
-u Display the processes belonging to the specified usernames.
-v Display information associated with the following keywords: pid, state, time, sl, re,
pagein, vsz, rss, lim, tsiz, %cpu, %mem, and command. The -v option implies the -m option.
-w Use 132 columns to display information, instead of the default which is your window size.
If the -w option is specified more than once, ps will use as many columns as necessary
without regard for your window size. When output is not to a terminal, an unlimited number
of columns are always used.
-X When displaying processes matched by other options, skip any processes which do not have a
controlling terminal.
-x When displaying processes matched by other options, include processes which do not have a
controlling terminal. This is the opposite of the -X option. If both -X and -x are speci-
fied in the same command, then ps will use the one which was specified last.
可见
-e和-A的意思是一样的,即显示有关其他用户进程的信息,包括那些没有控制终端的进程。
-f显示用户id,进程id,父进程id,最近CPU使用情况,进程开始时间等等。
find:五星级命令 查找
-type 文件类型
[root@linuxhua /]# find /root/data -type f -exec rm {} \;
[root@linuxhua /]# dir /root/data
[root@linuxhua /]# cd /root/data
[root@linuxhua data]# touch temprmflie.txt
[root@linuxhua data]# find /root/data -type f -name temprmflie.txt -exec rm {} \;
[root@linuxhua data]# touch 1.txt 2.txt 3.txt
[root@linuxhua data]# dir
1.txt 2.txt 3.txt
[root@linuxhua data]# find /root/data -type f -name '*.txt'
/root/data/1.txt
/root/data/2.txt
/root/data/3.txt
[root@linuxhua data]# find /root/data -type f -name '*.txt'|xargs rm
[root@linuxhua data]# dir
- 管道 ---------> '|'
删除 data下类型为文件、名字为'*.log'、修改事件为'15天前'的文件
[root@linuxhua data]# find /root/data -type f -name '*.log' -mtime +15 |xargs rm -f
删除目录
[root@linuxhua data]# find /root/data -type d -name '*.log' -mtime +15 |xargs rm -rf