linux_13 Basic Cat Command Examples in Linux
来源:互联网 发布:100到999的水仙花数vb 编辑:程序博客网 时间:2024/05/18 13:31
via: http://www.tecmint.com/13-basic-cat-command-examples-in-linux/
General Syntax
cat [OPTION] [FILE]...
1. Display Contains of File
In the below example, it will show contains of /etc/passwd file.
# cat /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologinnarad:x:500:500::/home/narad:/bin/bash
2. View Contains of Multiple Files in terminal
In below example, it will display contains of test and test1 file in terminal.
# cat test test1Hello everybodyHi world,
3. Create a File with Cat Command
We will create a file called test2 file with below command.
# cat >test2
Awaits input from user, type desired text and press CTRL+D (hold down Ctrl Key and type ‘d‘) to exit. The text will be written in test2 file. You can see contains of file with following catcommand.
# cat test2hello everyone, how do you do?
4. Use Cat Command with More & Less Options
If file having large number of contains that won’t fit in output terminal and screen scrolls up very fast, we can use parameters more and less with cat command as show above.
# cat song.txt | more# cat song.txt | less
5. Display Line Numbers in File
With -n option you could see the line numbers of a file song.txt in the output terminal.
# cat -n song.txt1 "Heal The World"2 There's A Place In3 Your Heart4 And I Know That It Is Love5 And This Place Could6 Be Much7 Brighter Than Tomorrow8 And If You Really Try9 You'll Find There's No Need10 To Cry11 In This Place You'll Feel12 There's No Hurt Or Sorrow
6. Display $ at the End of File
In the below, you can see with -e option that ‘$‘ is shows at the end of line and also in space showing ‘$‘ if there is any gap between paragraphs. This options is useful to squeeze multiple lines in a single line.
# cat -e testhello everyone, how do you do?$$Hey, am fine.$How's your training going on?$$
7. Display Tab separated Lines in File
In the below output, we could see TAB space is filled up with ‘^I‘ character.
# cat -T testhello ^Ieveryone, how do you do?Hey, ^Iam fine.^I^IHow's your training ^Igoing on?Let's do ^Isome practice in Linux.
8. Display Multiple Files at Once
In the below example we have three files test, test1 and test2 and able to view the contains of those file as shown above. We need to separate each file with ; (semi colon).
# cat test; cat test1; cat test2This is test fileThis is test1 file.This is test2 file.
9. Use Standard Output with Redirection Operator
We can redirect standard output of a file into a new file else existing file with ‘>‘ (greater than) symbol. Careful, existing contains of test1 will be overwritten by contains of test file.
# cat test > test1
10. Appending Standard Output with Redirection Operator
Appends in existing file with ‘>>‘ (double greater than) symbol. Here, contains of test file will be appended at the end of test1 file.
# cat test >> test1
11. Redirecting Standard Input with Redirection Operator
When you use the redirect with standard input ‘<‘ (less than symbol), it use file name test2 as a input for a command and output will be shown in a terminal.
# cat < test2This is test2 file.
12. Redirecting Multiple Files Contain in a Single File
This will create a file called test3 and all output will be redirected in a newly created file.
# cat test test1 test2 > test3
13. Sorting Contains of Multiple Files in a Single File
This will create a file test4 and output of cat command is piped to sort and result will be redirected in a newly created file.
# cat test test1 test2 test3 | sort > test4
This article shows the basic commands that may help you to explore cat command. You may refer man page of cat command if you want to know more options.
- linux_13 Basic Cat Command Examples in Linux
- Linux_13 Cat Command Examples For File Management
- 15 Basic ‘ls’ Command Examples in Linux
- basic examples of linux netstat command
- 10 basic examples of linux netstat command
- 10 basic examples of Linux ps command
- 12 TOP Command Examples in Linux
- 12 TOP Command Examples in Linux
- linux_18 Tar Command Examples in Linux
- HowTo: Use cat Command In Linux / UNIX
- 15 Practical Grep Command Examples In Linux / UNIX
- HowTo: Use grep Command In Linux / UNIX [ Examples ]
- HowTo: Use grep Command In Linux / UNIX – Examples
- Find command usage in Linux with excellent examples--reference
- 15 Practical Grep Command Examples In Linux / UNIX
- HowTo: Use grep Command In Linux / UNIX – Examples
- How To Use Ip Command In Linux with Examples
- Linux Command: chmod, cat
- linux_ubuntu解压zip乱码
- C++ 构造函数的初始化列表
- 微擎 后台背景修改
- linux_Switching From Windows to Nix
- Phoenix综述(史上最全Phoenix中文文档)
- linux_13 Basic Cat Command Examples in Linux
- 「·部署·」安装与使用 Spark-jobServer
- linux_20 Advanced Commands for Middle Level Linux Users
- linux_12 Practical Examples of Linux grep Command
- OpenGL_GLUT(一)_vs2013中配置gult库
- PL/SQL 基本语法
- Mysql如何为表字段添加索引???
- linux_10 Most Dangerous Commands – You Should Never Execute on Linux
- linux_How Do I Access or Mount Windows/USB NTFS Partition in RHEL/CentOS/Fedora