31. Command: rm
The command ‘rm‘ stands for remove. rm is used to remove files (s) and directories.
?
Removing a directory
?
root@tecmint:~# rm PassportApplicationForm_Main_English_V1.0 rm: cannot remove `PassportApplicationForm_Main_English_V1.0': Is a directory?
?
The directory can’t be removed simply by ‘rm‘ command, you have to use ‘-rf‘ switch along with ‘rm‘.
root@tecmint:~# rm -rf PassportApplicationForm_Main_English_V1.0
?
Warning: “rm -rf” command is a destructive command if accidently you make it to the wrong directory. Once you ‘rm -rf‘ a directory all the files and the directory itself is lost forever, all of a sudden. Use it with caution.
?
32. Command: echo
echo as the name suggest echoes a text on the standard output. It has nothing to do with shell, nor does shell reads the output of echo command. However in an interactive script, echo passes the message to the user through terminal. It is one of the command that is commonly used in scripting, interactive scripting.
root@tecmint:~# echo "Tecmint.com is a very good website" Tecmint.com is a very good website
?
creating a small interactive script
1. create a file, named ‘interactive_shell.sh‘ on desktop. (Remember ‘.sh‘ extension is must).
2. copy and paste the below script, exactly same, as below.
#!/bin/bash echo "Please enter your name:" read name echo "Welcome to Linux $name"
?
Next, set execute permission and run the script.
root@tecmint:~# chmod 777 interactive_shell.sh
?
root@tecmint:~# ./interactive_shell.sh Please enter your name: Ravi Saive Welcome to Linux Ravi Saive
?
Note: ‘#!/bin/bash‘ tells the shell that it is an script an it is always a good idea to include it at the top of script. ‘read‘ reads the given input.
?
33. Command: passwd
This is an important command that is useful for changing own password in terminal. Obviously you need to know your current passowrd for Security reason.
root@tecmint:~# passwd Changing password for tecmint. (current) UNIX password: ******** Enter new UNIX password: ******** Retype new UNIX password: ******** Password unchanged [Here was passowrd remians unchanged, i.e., new password=old password] Enter new UNIX password: ##### Retype new UNIX password:#####
?
34. Command: lpr
This command print files named on command line, to named printer.
root@tecmint:~# lpr -P deskjet-4620-series 1-final.pdf
?
Note: The ‘lpq‘ command lets you view the status of a printer (whether it’s up or not), and the jobs (files) waiting to be printed.
?
35. Command: cmp
compare two files of any type and writes the results to the standard output. By default, ‘cmp‘ Returns 0 if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported.
?
To provide examples for this command, lets consider two files:
?
file1.txt
root@tecmint:~# cat file1.txt Hi My name is Tecmint
?
file2.txt
root@tecmint:~# cat file2.txt Hi My name is tecmint [dot] com
?