50 useful Linux Commands – Part 1
Hello everyone, in this two part tutorial, we will learn some very basic Linux commands. Recently I have started learning basic Linux Commands. It is becoming mandatory to keep at least a basic knowledge about Linux Commands. Feel free to share your valuable opinions. Please also mention if you see any mistake as I am a beginner. So lets get started.
- Create a folder : “mkdir” command is used for creating a folder. For example, if you e=want to create a folder named “my_directory“, you have to run:
[php] mkdir my_directory [/php]
- Remove a folder: “mkdir” command is used to remove a folder. To remove a folder, you have to run:
[php] mkdir directory_name [/php]
- Show file and folder list: “ls” is one of the most used and popular command. It shows all the files and folders of a directory.
[php] "ls" [/php]
- Show file permissions with hidden file list: “ls” command has some limitations. Such as it doesn’t show the hidden files, also , “ls” doesn’t show the permissions of a file. To get these extra information, you have to run “ls -la”
[php] ls -la [/php]
- Copy file: To copy a file to a location, you have to run:
[php] cp file.txt Desktop/file.txt [/php]
Note: cp is copy command, then file name, finally directory where you want to copy the file
- Move a ile: “mv” command is used for moving a file from one directory to another directory.
[php] mv file.txt Desktop [/php]
Here, we are moving a file name "file.txt" to Desktop
- Read file: To read the internal contents of a file, you have to use “cat” command. Such as:
[php] cat file.txt [/php]
Note: “cat” is derived from “concatenate“
- Find location of a file: “locate” command is used if you want to know location of a specific file.
[php] locate file.txt [/php]
Note: This command will give you exact location of any file
- Search Indexing: Sometimes a newly created file may not be found by “locate” command. In that case, you have to update the indexing database. For that, you have to run “sudo updatedb”
[php] sudo updatedb [/php]
Note: updatedb creates or updates a database used by locate. “sudo” runs this command as superuser. More on this command later.
- Explain a command: If you want to know the details of a command, then you have to type “man command_name“. Form Example
[php] man ls[/php]
Note: this command will give all the details of the command with parameters.
- Read file: To read the internal contents of a file, you have to use cat command. Such as:
[php] cat file.txt [/php]
Note: cp is copy command, then file name, finally directory where you want to copy the file
- Give Read, Write & Execution Rights: To give full read, write and execution power to a file, you have to run below command
[php] chmod 777 file.txt [/php]
Note: You have to run this command as super admin
- Create user: For creating a new user, below command is used
[php] adduser[/php]
Note: After running the command, you have to provide user name, password and password confirmation
- Show all users: If you want to get the list of all users, run below command
[php] cat /etc/passwd [/php]
Note: Here we reading the “/etc/passwd” file, which contains all users info.
- Check user hashes: To get users stored hashes, run:
[php] cat /etc/shadow [/php]
Note: Be careful of this file. Do not give full access to this file for security reason.
- Switch user: For switching to another user, you have to run:
[php] su user_name [/php]
Note: Such as, if you want to switch to user jhon, run “su john“
- Search in a text file: If you want to search in a text file, you can use below command.
[php] cat file.txt | grep search_term [/php]
Note: Here “file.txt” is the file name and the pipe sign, then “grep” with search term.
- IP Details: In Windows, we run “ipconfig” to check basic IP related information. If you want to get these data in Linux, you have to run “ifconfig”
[php] ifconfig [/php]
Note: It will provide Interface Configuration related data
- Wireless info: If you want to get wireless info in Linux, you have to run “iwconfig”
[php] iwconfig [/php]
- Ping command: To check connectivity check from server to server, we run pung command
[php] ping 192.168.*.* [/php]
- Ping for specific time: You you want to run “ping” command for certain times, command is:
[php] ping -c 5 192.168.*.* [/php]
Note: above, we will run ping for 5 times
- IP address to MAC address mapping: To check IP-address-to-MAC-address mapping, we have to run
[php] arp [/php]
- Check Open ports: To check open ports, you have to run
[php] netstat -tuplen [/php]
- IP routing table: To check IP Routing table, you have to run:
[php] route [/php]
Note: cp is copy command, then file name, finally directory where you want to copy the file
- Update Packages list and Upgrade Packages: If you want to update all the packages list and also upgrade all the packages in one single command, you have to run
[php] apt update && apt upgrade [/php]