Linux shell basic3 dd wc comm chmod ls

时间:2021-11-28 16:42:24

Generating files of any size

/dev/zerois a character special device, which infinitely returns the zero byte (\0).

The above command will create a file called junk.datathat is exactly 1MB in size. Let's go

through the parameters: ifstands for – inputfile, ofstands for – outputfile, bsstands for

BYTES for a block, and countstands for the number of blocks of bsspecified to be copied.

dd if=/dev/zero of=junk.data bs=1M count=1

1+0 records in

1+0 records out

1048576 bytes (1.0 MB) copied, 0.00263553 s, 398 MB/s

Comm command demo:

[hadoop@namenode test]$ cat file1.txt file2.txt

1

2

3

4

1

2

4

5

[hadoop@namenode test]$ comm file1.txt file2.txt

1

2

3

4

5

[hadoop@namenode test]$ comm file1.txt file2.txt -1

1

2

4

5

[hadoop@namenode test]$ comm file1.txt file2.txt -2

1

2

3

4

[hadoop@namenode test]$ comm file1.txt file2.txt -3

3

5

[hadoop@namenode test]$ comm file1.txt file2.txt -3 -1

5

-1 removes first column from output

-2 removes the second column

-3 removes the third column

[hadoop@namenode test]$ ll

total 1052

-rw-rw-r--. 1 hadoop hadoop 99 Feb 16 08:34 all_txt_files.txt

-rw-rw-r--. 1 hadoop hadoop 8 Feb 17 03:29 file1.txt

-rw-rw-r--. 1 hadoop hadoop 8 Feb 17 03:29 file2.txt

-rw-rw-r--. 1 hadoop hadoop 1048576 Feb 17 03:20 junk.data

-rw-rw-r--. 1 hadoop hadoop 44 Feb 16 02:06 mul_bank.txt

-rw-rw-r--. 1 hadoop hadoop 30 Feb 16 08:55 num.txt

drwxrwxr-x. 2 hadoop hadoop 4096 Feb 16 03:05 sub

-rw-rw-r--. 1 hadoop hadoop 44 Feb 16 02:11 test.txt

"-"—if it is a regular file.

"d"—if it is a directory

"c"—for a character device

"b"—for a block device

"l"—if it is a symbolic link

"s"—for a socket

"p"—for a pipe

chmod u=rwx g=rw o=r filename

Here:

u =specifies user permissions

g =specifies group permissions

o =specifies others permissions

chmod a+x filename

a statnd for all.

Read,write,and execute permissions have unique octal numbers as follows:

r--=4

-w-=2

--x=1

Touch is a command that can create blank files or modify the timestamp of files if they

already exist.

Symbolic links are just pointers to other files.

ln -s targetfilename(directory) link_name

ln -s test.txt test_link.txt

Counting number of lines, words, and characters in a file

$ wc -l file # count number of lines as follows:

$ wc -w file #count words number

$ head -10 filename

$ tail -10 filename

Head used to get the first n lines of the file.

Tail is used to get the last n lines of the file.