Basic Shell Commands

Basic Shell Commands

1. ls - Using this command we can 
list all files in the current directory
       E.g. ls /home/abc
   

2. file - Using this command we can 
display what sort of file it is 
     E.g. file file.txt
     


3. cat - Using this command we can 
send contents of a file to screen
     
E.g. cat file.txt
   

4. pwd - pwd (print working directory) using this command we can show the current working directory
      E.g. pwd
 

5. cp-cp command is one of the basic commands for copying files and directories from one location to another.
      E.g. cp /home/abc/file.txt /home/abc/dir2


6. CD (Change Directory)- this command is used to change the current working directory to a new location/directory 
E.g. cd /home/abc/dir2 
(In the given picture first we have to check current directory (i.e. /home/abc) using pwd command and then wen can use cd /home/abc/dir2 (i.e. new directory location) to change current working directory to /home/abc/dir2)
7. Who- This command is used to see all users list using the system.
E.g. who




8. Who am I- This command is used to see currently login user
E.g. who am I




9. Date- Using this command we can see system date and time.
E.g. date

10. WC- This command is used to count lines, words and characters of the given file name.
E.g. wc file.txt
(In the given picture first, we need to check what is written inside the file.txt, so we can use cat file.txt command. Now we write command wc file.txt to count lines, words, and characters of file.txt and get an output as 1 1 6 that means file.txt contains 1 line, 1 word characters (5 characters (hello) new line)

11. Rm- This command is used to remove a file.
E.g. rm file.txt
(In the given picture first, we have to check current directory files using ls command and then we delete file.txt using rm file.txt command. Now again we can check all files using ls command to confirm removal of file.txt file)

12. mkdir - Using this command we can Make directory/folder
      E.g. mkdir notes

13. grep (Global regular expression print) - This command is used to search the file for the line that matches a given pattern.
E.g. grep file xyz.txt (In this command, file is given text pattern and xyz.txt is a file name)

14. mv - Using this command we can rename/move a file.
E.g. 
Renaming a file(file.txt):- mv file.txt file2.txt 
Moving a file(file2.txt):- mv file2.txt /home/abc/notes


15. chmod (Change Mode)- using this command we can change access permission of a file or directory.
We can use this command using the following syntax:
chmod {u / g / o / a} {+ / -} {r / w / x} {file / directory name}
Here:
u  stands for user who own the file/directory
g  stands for group file owner
o  stands for other users
a  stands for all system users
+  stands for add permission
-   stands for remove permission
r   stands for read permission
w  stands for write permission
x   stands for execute permission

E.g. chmod u+x-w xyz.txt

16. more- using this command we can view the contents of a text file one screen at a time in case the file is large and to scroll the display one line at a time we can press Enter key. If we want to scroll a screenful in one go, we can use the Space bar key and backward scrolling can be achieved by pressing b key.
E.g. more computer.txt


17. less- using this command we can view the contents of a text file one page at a time. To scroll the display one line at a time we can press Enter key. If we want to move forward one page, we can use the Space bar key and move backward one page by pressing key. At the end of the file, we can press the q key to exit from the file.
E.g. less computer.txt


18. head- using this command we can display x number of lines from the beginning of a file. By default, the head command will display the first 10 lines from the file.
E.g. head num.txt

19. tail- using this command we can display x number of lines from the ending of a file. By default, the tail command will display the last 10 lines from the file.

E.g. tail num.txt

20. sort- using this command we can sort the lines in a text file, numerically and alphabetically.
numalpha.txt file


E.g. sort numalpha.txt
We can use:
     -n to sort in numeric order
E.g. sort -n numalpha.txt
     -r to sort in reverse normal order
E.g. sort -r numalpha.txt
     -nr to sort in numeric reverse order
E.g. sort -nr numalpha.txt


21. passwd- passwd command is used to change the password of a user account. A standard user can run passwd to change their own password, and a system administrator or a superuser can use passwd to change their own and another user's password.

When we run passwd command, 
we received a prompt to enter the account's current password:
(current) UNIX password: abc123
If it is correct, we will then be asked to enter a new password:
Enter new UNIX password: Zxcv@1234
Now we need to enter the same password again, to verify it.
Retype new UNIX password: Zxcv@1234
If the passwords match, the password will be changed.


22. gedit- Using this command we can open Gedit Text Editor Application.
23. firefox- Using this command we can open Firefox Web Browser.
24. exit - Using this command we can Close terminal.


UNIT-301
Network Operating System