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:
mkdir my_directory
- Remove a folder: “mkdir” command is used to remove a folder. To remove a folder, you have to run:
mkdir directory_name
- 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.
"ls"
- 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”
ls -la
- Copy file: To copy a file to a location, you have to run:
cp file.txt Desktop/file.txt
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.
mv file.txt Desktop
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:
cat file.txt
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.
locate file.txt
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”
sudo updatedb
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
man ls
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:
cat file.txt
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
chmod 777 file.txt
Note: You have to run this command as super admin
- Create user: For creating a new user, below command is used
adduser
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
cat /etc/passwd
Note: Here we reading the “/etc/passwd” file, which contains all users info.
- Check user hashes: To get users stored hashes, run:
cat /etc/shadow
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:
su user_name
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.
cat file.txt | grep search_term
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”
ifconfig
Note: It will provide Interface Configuration related data
- Wireless info: If you want to get wireless info in Linux, you have to run “iwconfig”
iwconfig
- Ping command: To check connectivity check from server to server, we run pung command
ping 192.168.*.*
- Ping for specific time: You you want to run “ping” command for certain times, command is:
ping -c 5 192.168.*.*
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
arp
- Check Open ports: To check open ports, you have to run
netstat -tuplen
- IP routing table: To check IP Routing table, you have to run:
route
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
apt update && apt upgrade