cat: It is used to create, display and concatenate file contents.
Syntax: cat [options] [FILE]…
- Show all.
- Omits line numbers for blank space in the output.
- A $ character will be printed at the end of each line prior to a new line.
- Displays a $ (dollar sign) at the end of each line.
- Line numbers for all the output lines.
- If the output has multiple empty lines it replaces it with one empty line.
- Displays the tab characters in the output.
- Non-printing characters (with the exception of tabs, new-lines, and form-feeds) are printed visibly.
Two basically three uses of the cat command.
- Create new files.
- Display the contents of an existing file.
- Concatenate the content of multiple files and display.
$ cat file1.c
- Above syntax will display the content of file1.c $ cat > file1.c
- Above syntax creates file1.c and allow us to insert content for this file.
- After inserting content you can use ctrl+d to exit the file.
- If the file with the same name exists then it will overwrite that file.
$ cat file1.c
- process management
- memory management file mgmt
$ cat file1.c >> file2.c
- It can concatenate the contents of two files. For this, you have to use append output redirection operator.
- The contents of file2.cwill appended to file1.c.
cp command copy files from one location to another. If the destination is an existing file, then the file is overwritten; if the destination is an existing directory, the file copied into the directory (the directory is not overwritten).
Syntax :- cp [options]… source destination
- Here, after cp command contents of both source file and destination file files are the same.
- Also, It will copy the content of source file to destination file.
- If the destination file doesn’t exist, it will create.
- Moreover, If it exists then it will overwrite without any warning.
- If there is only one file to be copied then destination can be the ordinary file or the directory file.
- archive files
- force copy by removing the destination file if needed
- interactive – ask before overwrite
- link files instead of copy
- follow symbolic links
- no file overwrite
- update – copy when the source is newer than dest
$ cp file1 file2
- The above cp command copies the content of file1.php to file2.php.
Copy folder and subfolders:
$ cp-R scripts scripts1
- The above cp command copy the folder and subfolders from scripts to scripts1.