Click here for "Safe Air Conditioner Repair and Proper Freon Recovery".

Various ways to view files

Various ways to view files

●Displays the number of files in a directory

The ls command allows you to view files in the current directory or in a specific directory.
It can also tell you the number of files instead of the file or directory name.

In such a case, you can get the number of files by using the find command, which is a file search command, together with the wc command, which does the counting
Use the find command with the directory you want to count as an option, the file type with the “-type” option, and then use the pipe “|” to count the number of lines with the wc command with the “-l” option to display the number.

Display the number of files
[root@Lion ~]# find /home/koro/ -type f | wc -l
16 ←16 files exist


Display the number of directories

[root@Lion ~]# find /var/log -type d | wc -l
6 ←6 directories exist

●Display the contents of a text file in a table format

To convert data stored as bullets in a text file into a table format and display it, use the column command

Display the contents of a text file in a table format.
[root@Lion ~]# head -15 country_list.txt
Japan
Afghanistan
Algeria
Andorra
Angola
Antigua and Barbuda
Argentina
Armenia
Australia
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados


[root@Lion ~]# column country_list.txt
Japan Libyan Arab Jamahiriya
Afghanistan Liechtenstein
Algeria Lithuania
Andorra Luxembourg
Angola Madagascar
Antigua and Barbuda Malawi
Argentina Malaysia
Armenia Maldives
Australia Mali
Austria Malta
Azerbaijan Marshall Islands
Bahamas Mauritania
Bahrain Mauritius
Bangladesh Mexico
Barbados Micronesia

●Display the contents of a file with line numbers.

The cat command and the less command are commands that display the contents of a file.
To display the file with line numbers, execute the cat command with the “-n” option and the less command with the “-N” option to display the contents of the file with line numbers.

[root@Lion ~]# cat -n country_list.txt
1 Japan
2 Afghanistan
3 Algeria
4 Andorra
5 Angola
6 Antigua and Barbuda
7 Argentina
8 Armenia
9 Australia
10 Austria
11 Azerbaijan
12 Bahamas
13 Bahrain
14 Bangladesh


[root@Lion ~]# less -N country_list.txt
1 Japan
2 Afghanistan
3 Algeria
4 Andorra
5 Angola
6 Antigua and Barbuda
7 Argentina
8 Armenia
9 Australia
10 Austria
11 Azerbaijan
12 Bahamas
13 Bahrain
14 Bangladesh
タイトルとURLをコピーしました