Files and Directories of Linux Commands

Copy the folder scp -r dirName [email protected]:/usr/mpsp/ —— Copy the machine to 10.10.10.10

 

View scheduled tasks  : crontab -e

 

Check file size: ls -lh

 

Check folder size: du -sh *

 

Check disk space: df -h

 

String replacement: echo '2 2017-11-25 10:12:08' | sed 's/-//g' | sed 's/://g'

 

String replacement in a single file: sed -i "s/111/222/g" 2.txt         replaces the text " 111 " in file 2.txt with " 222 "

 

Check port occupancy: netstat –anp | grep 1499   – get pid ( 12628 )

 

                 ps -aux | grep 12628 - get the application name corresponding to the pid

 

ssh remote login : ssh 10.10.2.62 -l userName 

files and directories

 

cd /home into the '/home' directory '

 

cd .. go back to the previous directory

 

cd ../.. returns to the upper two levels of the directory

 

cd into the personal home directory

 

cd ~user1 into the personal home directory

 

cd - go back to the last directory you were in

 

pwd show working path

 

ls to view files in a directory

 

ls -F to view files in a directory

 

ls -l displays file and directory details

 

ls -a show hidden files

 

ls *[0-9]* Display file and directory names that contain numbers

 

tree shows the tree structure of files and directories starting from the root directory (1)

 

lstree displays the tree structure of files and directories starting from the root directory (2)

 

mkdir dir1 creates a directory called 'dir1' '

 

mkdir dir1 dir2 creates two directories at the same time

 

mkdir -p /tmp/dir1/dir2 creates a directory tree

 

rm -f file1 delete a file called 'file1' '

 

rmdir dir1 deletes a directory called 'dir1 '

 

rm -rf dir1 deletes a directory called 'dir1' and also deletes its contents

 

rm -rf dir1 dir2 deletes two directories and their contents at the same time

 

mv dir1 new_dir rename / move a directory

 

cp file1 file2 copies a file

 

cp dir/* . Copy all files in a directory to the current working directory

 

cp -a /tmp/dir1 . Copy a directory to the current working directory

 

cp -a dir1 dir2 copies a directory

 

ln -s file1 lnk1 creates a soft link to a file or directory

 

ln file1 lnk1 creates a physical link to a file or directory

 

touch -t 0712250000 file1 Modify timestamp of a file or directory - (YYMMDDhhmm)

 

file file1 outputs the mime type of the file as text

 

iconv -l 列出已知的编码

 

文件搜索

 

find / -name file1 '/' 开始进入根文件系统搜索文件和目录

 

find / -user user1 搜索属于用户 'user1' 的文件和目录

 

find /home/user1 -name \*.bin 在目录 '/ home/user1' 中搜索带有'.bin' 结尾的文件

 

find /usr/bin -type f -atime +100 搜索在过去100天内未被使用过的执行文件

 

find /usr/bin -type f -mtime -10 搜索在10天内被创建或者修改过的文件

 

find / -name \*.rpm -exec chmod 755 '{}' \; 搜索以 '.rpm' 结尾的文件并定义其权限

 

find / -xdev -name \*.rpm 搜索以 '.rpm' 结尾的文件,忽略光驱、捷盘等可移动设备

 

locate \*.ps 寻找以 '.ps' 结尾的文件 - 先运行 'updatedb' 命令

 

whereis halt 显示一个二进制文件、源码或man的位置

 

which halt 显示一个二进制文件或可执行文件的完整路径

 

文件的权限

 

 使用 "+" 设置权限,使用 "-" 用于取消

 

ls -lh 显示权限

 

ls /tmp | pr -T5 -W$COLUMNS 将终端划分成5栏显示

 

chmod ugo+rwx directory1 设置目录的所有人(u)、群组(g)以及其他人(o)以读(r )、写(w)和执行(x)的权限

 

chmod go-rwx directory1 删除群组(g)与其他人(o)对目录的读写执行权限

 

chown user1 file1 改变一个文件的所有人属性

 

chown -R user1 directory1 改变一个目录的所有人属性并同时改变改目录下所有文件的属性

 

chgrp group1 file1 改变文件的群组

 

chown user1:group1 file1 改变一个文件的所有人和群组属性

 

find / -perm -u+s 罗列一个系统中所有使用了SUID控制的文件

 

chmod u+s /bin/file1 设置一个二进制文件的 SUID - 运行该文件的用户也被赋予和所有者同样的权限

 

chmod u-s /bin/file1 禁用一个二进制文件的 SUID

 

chmod g+s /home/public 设置一个目录的SGID - 类似SUID ,不过这是针对目录的

 

chmod g-s /home/public 禁用一个目录的 SGID

 

chmod o+t /home/public 设置一个文件的 STIKY - 只允许合法所有人删除文件

 

chmod o-t /home/public 禁用一个目录的 STIKY

 

文件的特殊属性

 

使用 "+" 设置权限,使用 "-" 用于取消

 

chattr +a file1 只允许以追加方式读写文件

 

chattr +c file1 允许这个文件能被内核自动压缩/解压

 

chattr +d file1 在进行文件系统备份时,dump程序将忽略这个文件

 

chattr +i file1 设置成不可变的文件,不能被删除、修改、重命名或者链接

 

chattr +s file1 允许一个文件被安全地删除

 

chattr +S file1 一旦应用程序对这个文件执行了写操作,使系统立刻把修改的结果写到磁盘

 

chattr +u file1 若文件被删除,系统会允许你在以后恢复这个被删除的文件

 

lsattr 显示特殊的属性

 

查看文件内容

 

cat file1 从第一个字节开始正向查看文件的内容

 

tac file1 从最后一行开始反向查看一个文件的内容

 

more file1 查看一个长文件的内容

 

less file1 类似于 'more' 命令,但是它允许在文件中和正向操作一样的反向操作

 

head -2 file1 查看一个文件的前两行

 

tail -2 file1 查看一个文件的最后两行

tail -f /var/log/messages 实时查看被添加到一个文件中的内容

 

 

 

字符设置和文件格式转换

 

dos2unix filedos.txt fileunix.txt 将一个文本文件的格式从MSDOS转换成UNIX

 

unix2dos fileunix.txt filedos.txt 将一个文本文件的格式从UNIX转换成MSDOS

 

recode ..HTML < page.txt > page.html 将一个文本文件转换成html

recode -l | more 显示所有允许的转换格式

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326072283&siteId=291194637