who , echo and cat command in Unix Lab (BCA-506P) - Practical-2

 

Execute the following list of basic commands in UNIX:

(i) who (ii) echo (iii) cat

(1) who

In Unix, “who” command allows to show or print the number of users who has been logged into your Unix computer system currently. 
Who command in Unix is used to determine the below information:
  • Time at which the last system boot was done.
  • Run the level of the current timestamp of the system.
  • List of users who are logged in to the system and many more.
 

(2) echo

echo command is used to display some text on the screen


The above command will show the message "Hello, This is my Unix terminal window" on the screen



The above command "echo -e "one \n two" will show the two string in different line
 

(3) cat

cat command is used to create new file, append contents to existing file, view the content of the file and concatenate multiple files to a single file.


Display Contents of a File in Unix

The command "cat myfile1.txt" will show the contents of file "myfile1.txt" on the screen


Display Contents of multiple Files in Unix

The command "cat onefile.txt twofile.txt" will show the contents of both the file  on the screen



Create a file in Unix

The user can create a new file and save content in it with the ">" symbol (known as the “output redirection operator”) will redirect the output of the command to the file specified by the filename

After executing the command, an indicator will blink in the new line. Write the content for the file and press the “CTRL + D” keys to save and exit the file:

The command "cat > mytestfile1.txt" will creates new file.



Append text to an existing file in Unix

The command "cat >> onefile.txt" will append some new text to the end of he file onefile.txt.



Copy the content of old file to new file in Unix

Sometimes, the user wants to create a copy of the contents stored in a file into a new file for different purposes, such as backup. Here, ">" operator will read the content of the “onefile.txt” file sequentially and will place it into a new file named “onefilecopy.txt“.

The command "cat onefile.txt > onefilecopy.txt"  is used--



Display the line number in the file in Unix

If you want to show line numbers prior to each line of the file’s content, use the "-n" option to display the line number in the output without any changes to the original content of the file.

The command "cat -n onefile.txt"  is used--






Post a Comment

0 Comments