Important terminal commands

Important terminal commands

·

2 min read

  1. chmod: The chmod command used to change the permissions of files and directories. It stands for "change mode."

To use it, you can type chmod followed by the permissions you want to set and the name of the file or directory. The permissions are specified using a three-digit octal number, where each digit represents the permissions for the owner, group, and others, respectively.

chmod 754 file.txt

It also allows you to specify permissions using symbolic notation. For example, to give read, write, and execute permissions to the owner and read and execute permissions to everyone else for a file named file.txt, you would type:

chmod u=rwx,g=rx,o=rx file.txt
  1. sudo: The sudo command allows users to run commands with the privileges of another user, typically the root user. It stands for "superuser do."
sudo apt-get install package-name

This command will prompt you for your password before executing the command. This is a security measure to ensure that only authorized users can run commands with elevated privileges. It is typically used to perform administrative tasks that require root access, such as installing software, modifying system files, and managing system services.

To know more about the command type the following command in your terminal:

man code
  1. grep: The grep command is used to search for patterns in text. It stands for "global regular expression print.

To use the grep command, you can type grep followed by the pattern you want to search for and the name of the file or files you want to search for. E.g.

grep hello file.txt 
//search multiple files by specifying the names of the files separated //by spaces
// grep hello file1.txt file2.txt file3.txt
  1. diff: The diff command that compares the contents of two files or directories and displays the differences between them.
diff file1.txt file2.txt

It will compare the two files line by line and display the differences between them. It will show lines that are present in one file but not the other, as well as lines that are different between the two files.

Some more useful terminal commands:

  1. wget: command used to download files from the internet. It stands for "web get."
wget https://example.com/file.zip
  1. zip: command used to create and manipulate zip archive files.
zip archive.zip file.txt
  1. top: It displays real-time information about the processes running on your system. It is commonly used to monitor the performance of the system and identify processes that are consuming resources

  2. find: used to search for files and directories on your system.

find . -name "*.txt"