Creating files and adding data using cat command
Syntax :-
[root@localhost~]# cat <option> <arguments>
Example :- To create a file along with some data
[root@localhost~]# cat > salesreport
This file contains the sales report for the month Aug.
( Now press Ctrl+d to Save )
Example :- To create one more file along with some data
[root@localhost~]# cat > mktgreport
This file contains the mktg report for the month of Aug.
( Now press Ctrl+d to Save )
Example :- To read the contents of a file
[root@localhost~]# cat salesreport
This file contains the sales report for the month of Aug.
Example : - To append (add) to a file
[root@localhost~]# cat >> mktgreport
This year the efforts in mktg have increased.
Ctrl+D
Check the contents of the file mktgreport
[root@localhost~]# cat mktgreport
This file contains the mktg report for the month of Aug
This year the efforts in mktg have increased.
Example :- To merge contents of two files into a third file
[root@localhost~]# cat salesreport mktgreport >> completereport
Check the contents of the file Completereport
[root@localhost~]# cat completereport
This file contains the sales report for the month of Aug.
This file contains the mktg report for the month of Aug.
This year the efforts in mktg have increased.
Syntax :- Creating a single file with the touch command
[root@localhost~]# touch <filename>
Example :- Creating a single file with touch command
[root@localhost~]# touch file1
To check if the file has been created
[root@localhost~]# ls -ld file1
-rw-r--r--. 1 root root 0 Aug 23 09:13 file1
Example :- Creating multiple file using the touch command
[root@localhost~]# touch file2 file3 file4
To check if the file has been created
[root@localhost~]# ls -ld file*
-rw-r--r--. 1 root root 0 Aug 23 09:13 file1
-rw-r--r--. 1 root root 0 Aug 23 09:16 file2
-rw-r--r--. 1 root root 0 Aug 23 09:16 file3
-rw-r--r--. 1 root root 0 Aug 23 09:16 file4
To change the timestamp (date and time of modification) of a file or directory
Syntax :-
[root@localhost~]# touch <option> <arguments> <file or directory name>
Example :- To change to the current date and time
[root@localhost~]# touch file1
To check if the timestamp has changed
[root@localhost~]# ls -ld file1
-rw-r--r--. 1 root root 0 Aug 23 09:20 file1
Syntax :-
[root@localhost~]# touch -t YYYYMMDDHHMM <file or directory name>
Example :- To change to a different date and time
[root@localhost~]# touch -t 200905150842 file2
To check if the timestamp has changed
[root@localhost~]# ls -ld file2
-rw-r--r--. 1 root root 0 May 15 2009 file2
Syntax :-
[root@localhost~]# cat <option> <arguments>
Example :- To create a file along with some data
[root@localhost~]# cat > salesreport
This file contains the sales report for the month Aug.
( Now press Ctrl+d to Save )
Example :- To create one more file along with some data
[root@localhost~]# cat > mktgreport
This file contains the mktg report for the month of Aug.
( Now press Ctrl+d to Save )
Example :- To read the contents of a file
[root@localhost~]# cat salesreport
This file contains the sales report for the month of Aug.
Example : - To append (add) to a file
[root@localhost~]# cat >> mktgreport
This year the efforts in mktg have increased.
Ctrl+D
Check the contents of the file mktgreport
[root@localhost~]# cat mktgreport
This file contains the mktg report for the month of Aug
This year the efforts in mktg have increased.
Example :- To merge contents of two files into a third file
[root@localhost~]# cat salesreport mktgreport >> completereport
Check the contents of the file Completereport
[root@localhost~]# cat completereport
This file contains the sales report for the month of Aug.
This file contains the mktg report for the month of Aug.
This year the efforts in mktg have increased.
Creating 0 byte (empty) files using touch command
Syntax :- Creating a single file with the touch command
[root@localhost~]# touch <filename>
Example :- Creating a single file with touch command
[root@localhost~]# touch file1
To check if the file has been created
[root@localhost~]# ls -ld file1
-rw-r--r--. 1 root root 0 Aug 23 09:13 file1
Example :- Creating multiple file using the touch command
[root@localhost~]# touch file2 file3 file4
To check if the file has been created
[root@localhost~]# ls -ld file*
-rw-r--r--. 1 root root 0 Aug 23 09:13 file1
-rw-r--r--. 1 root root 0 Aug 23 09:16 file2
-rw-r--r--. 1 root root 0 Aug 23 09:16 file3
-rw-r--r--. 1 root root 0 Aug 23 09:16 file4
To change the timestamp (date and time of modification) of a file or directory
Syntax :-
[root@localhost~]# touch <option> <arguments> <file or directory name>
Example :- To change to the current date and time
[root@localhost~]# touch file1
To check if the timestamp has changed
[root@localhost~]# ls -ld file1
-rw-r--r--. 1 root root 0 Aug 23 09:20 file1
Syntax :-
[root@localhost~]# touch -t YYYYMMDDHHMM <file or directory name>
Example :- To change to a different date and time
[root@localhost~]# touch -t 200905150842 file2
To check if the timestamp has changed
[root@localhost~]# ls -ld file2
-rw-r--r--. 1 root root 0 May 15 2009 file2
0 comments:
Post a Comment