15 Operating Commands in Linux OS

Mention all operating commands in Linux OS and explanations each function, including example.

Avatar

In Linux, there are numerous operating commands available that serve different purposes. Here are some commonly used ones, along with a brief explanation of their functions:

1. ls:
The “ls” command lists the files and directories in the current directory. It provides information such as permissions, ownership, size, and modification timestamps.

To list files and directories in the current directory: ls
To list files and directories with detailed information: ls -l
To list all files and directories, including hidden ones: ls -a

2. cd:
The “cd” command is used to change the current directory. By specifying a directory path as an argument, you can navigate to a different location within the file system.

To change to a specific directory: cd /path/to/directory
To go back to the previous directory: cd ..
To go to the home directory: cd

3. pwd:
The “pwd” command displays the current working directory. It shows the path of the directory you are currently in.

To display the current working directory: pwd

4. mkdir:
The “mkdir” command is used to create a new directory. It takes the name of the directory as an argument and creates it within the current directory.

To create a new directory: mkdir new_directory
To create nested directories: mkdir -p parent_directory/new_directory

5. rm:
The “rm” command is used to remove or delete files and directories. It can be used with options like “-r” to recursively remove directories and their contents.

To remove a file: rm file.txt
To remove a directory and its contents recursively: rm -r directory

6. cp:
The “cp” command is used to copy files and directories. It requires the source file/directory and the destination as arguments.

To copy a file to a different location: cp file.txt destination_directory
To copy a directory and its contents recursively: cp -r directory destination_directory

7. mv:
The “mv” command is used to move or rename files and directories. It can be used to move files/directories from one location to another or to rename them.

To move a file to a different location: mv file.txt destination_directory
To rename a file or directory: mv old_name new_name

8. cat:
The “cat” command displays the contents of a file on the standard output. It is often used to view text files or concatenate multiple files together.

To display the contents of a file: cat file.txt
To display multiple files concatenated: cat file1.txt file2.txt

9. grep:
The “grep” command is used for searching patterns within files. It allows you to search for specific strings or patterns and display matching lines.

To search for a specific string in a file: grep “search_string” file.txt
To search for a pattern recursively in a directory: grep -r “pattern” directory

10. chmod:
The “chmod” command is used to change the permissions of files and directories. It allows you to modify the read, write, and execute permissions for the owner, group, and others.

To change the permissions of a file or directory: chmod permissions file.txt
To recursively change permissions of a directory and its contents: chmod -R permissions directory

11. chown:
The “chown” command is used to change the ownership of files and directories. It enables you to change the user and group ownership of a file or directory.

To change the ownership of a file or directory: chown user:group file.txt
To recursively change ownership of a directory and its contents: chown -R user:group directory

12. tar:
The “tar” command is used for creating and manipulating archive files, often referred to as “tarballs.” It is commonly used with options like “-x” to extract files, “-c” to create archives, and “-z” to compress or decompress files.

To create a tar archive of files: tar -cvf archive.tar file1.txt file2.txt
To extract files from a tar archive: tar -xvf archive.tar
To compress files into a tar.gz archive: tar -czvf archive.tar.gz file1.txt file2.txt

13. ssh:
The “ssh” command is used to establish a secure shell connection to a remote machine. It allows you to remotely log in to another system and execute commands securely.

To connect to a remote server via SSH: ssh username@remote_server
To specify a custom port for SSH connection: ssh -p port username@remote_server

14. sudo:
The “sudo” command allows users with the appropriate privileges to execute commands as another user, typically the root user. It is often used to perform administrative tasks.

To execute a command with root privileges: sudo command
To edit a system file with root privileges: sudo nano /path/to/file

15. apt-get/yum/dnf:
These are package management commands used in different Linux distributions. They allow you to install, update, and remove software packages from your system.

To install a package: apt-get install package_name
To update installed packages: apt-get update
To remove a package: apt-get remove package_name

 

These are just some basic examples of how these commands can be used. Each command has additional options and functionalities that can be explored further through their respective manual pages (man <command>).

These are just a few examples of commonly used Linux commands. Linux provides a vast array of commands, each serving a specific purpose, allowing users to perform various tasks efficiently from the command line interface.

Leave a Reply

Your email address will not be published. Required fields are marked *