File and directory management commands

Keywords: yum ascii

mv cut file / directory

[root@localhost test]# mv yum yum_bak
[root@localhost test]# ls
yum_bak

rm delete file / directory

[root@localhost test]# rm -rf yum_bak

File view file type

[root@localhost test]# file /etc/yum.conf
/etc/yum.conf: ASCII text

cat view plain text (small) file content

[root@localhost test]# cat -n /etc/yum.conf
     1  [main]
     2  cachedir=/var/cache/yum/$basearch/$releasever
     3  keepcache=0
     4  debuglevel=2
     5  logfile=/var/log/yum.log
     6  exactarch=1
     7  obsoletes=1
     8  gpgcheck=1
     9  plugins=1

more viewing the contents of plain text (large) files

[root@localhost test]# file /etc/yum.conf
/etc/yum.conf: ASCII text

head view the first N lines of the plain text file

[root@localhost test]# head -n 5 /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log

tail view the last N lines of the plain text file

[root@localhost test]# tail -n 5 /etc/yum.conf
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

Refresh file content continuously

[root@localhost test]# tail -f test.log
hello
world

tr replace characters in plain text files

[root@localhost test]# cat test.log | tr o a
hella
warld

wc statistics text lines, words, bytes

[root@localhost test]# wc test.log
 2  2 12 test.log

stat view file specific storage and time

[root@localhost test]# stat test.log
  File: 'test.log'
  Size: 12              Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d    Inode: 204957191   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-01-01 01:59:30.369866673 +0800
Modify: 2019-01-01 01:58:33.647755947 +0800
Change: 2019-01-01 01:58:33.647755947 +0800
 Birth: -

diff compare text file differences

Is the comparison file the same

[root@localhost test]# diff --brief test.log test2.log
Files test.log and test2.log differ

Compare different contents of the file

[root@localhost test]# diff -c test.log test2.log
*** test.log    2019-01-01 01:58:33.647755947 +0800
--- test2.log   2019-01-01 02:05:57.301110030 +0800
***************
*** 1,2 ****
! hello
! world
--- 1 ----
! hello world

Posted by phpORcaffine on Sat, 16 Nov 2019 11:26:59 -0800