Linux Commands
1. pwd
When you first open the terminal, you are in the home directory of your user. To know which directory you are in, you can use the “pwd” command. It gives us the Absolute Path, which means the path that starts from the root. The root is the base of the Linux filesystem. It is denoted by a forward slash( / ). The user directory is usually something like /home/username.
2. ls
The “Is” command is used to know what files are there in the directory you are in. You can see all the hidden files by using the command “ls -a”.
3. cd
“cd” is the command used to go to a directory. For example, if you are in the home folder, and you want to go to the Downloads folder, then you can type in “cd Downloads”. Remember, this command is case sensitive and you have to type in the name of the folder exactly as it is. But there is a problem with these commands. Imagine you have a folder named “kali software”. In this case, when you type in “cd kali software”, the shell will take the second argument of the command as a different one, so you will get an error saying that the directory does not exist. Here, you can use a backward slash. That is, you can use “cd kali\ software” in this case. Spaces are denoted like this: If you just type “cd” and press Enter, it takes you to the home directory. To go back from a folder to the folder before that, you can type “cd ..” . The two dots represent back.
4. mkdir & rmdir
The mkdir command is used when you need to create a folder or a directory. For Example, if you want to make a directory called “abc”, then you can type “mkdir abc”. Remember, as told before, if you want to create a directory named “abc Hacking”, then you can type “mkdir abc\ Hacking”.
rmdir is the command used for deleting a directory. But, rmdir can only be used to delete an empty directory. To delete a directory containing files, rm is used.
The rm command is used to delete files and directories. rm cannot simply delete a directory. “rm -r” is used to delete a directory. In this case, it deletes both the folder and the files in it.
5. touch
The touch command is used to create a file. It can be anything, from an empty txt file to an empty zip file. For example – “touch new.txt”
6. man & –help
To know more about a command and on how to use it.
Example : man -cd -help
7. Install package
First download package and run following command.
Command: dpkg -i package_name.deb
Example: dpkg -i google-chrome-stable_current_amd64.deb
8. Uninstall package
First Run Following command that display all installed packages on your computer.
Command: dpkg --list
To uninstall get package full name and run following command
Command : sudo apt-get --purge remove Package_name
OR
apt-get --purge remove gimp Package_name
9. Process Management Command
ps: Display currently active processes.
ps aux: Display currently active processes with more Details.
Kill pid: Kill any Process with pid.
10. cp
The cp command is used to copy files through the command line. It takes two arguments, the first one is location of the file to be copied, the second is where to copy or go to directory were file is and pass file name and destination path.
11. mv
The mv command is used for move file and rename the file.
1) Move: To move take two arguments “File path” and “Destination path”.
2) Rename: To rename take two arguments “File Name” and “New File Name”.
12. locate
The locate command is used to locate a file in a Linux System, just like the search command in Windows. This command is useful when you don’t know where a file is saved or the actual name of the file. Using the “–i” argument with the command, helps to ignore the case (it doesn’t matter if it is Capital or Small). So, if you want a file that has the word “hello”, it gives the list of all the files in your Linux System containing the word “hello” when you type in “locate -i hello”. If you remember two words, you can separate it using asterisk (*). For example, to locate a file containing the words “hello” and “this”, you can use the command “locate –i *hello*this ”
13. echo
“echo” is a command that helps us move some data, usually text into a file. For example, if you want to create a new text file or add into an already made text file, then you just need to type in “echo hello, my name is dharmendra >> new.txt”. You do not need to separate the spaces by using the backward slash here because we put in two triangular brackets when we finish what we need to write.
14. cat
The cat command is used to display the contents of a file, usually used to easily view programs.
15. sudo
sudo is a widely used command in the Linux command line. sudo stands for “SuperUser Do”. So, if we want any command to be done with administrative or root privileges, then you can use the sudo command.if you want to change password:
16. df
The df command is used to see the available disk space in each of the partitions in your system. You can just type in df in the command line and you can see each mounted partition and their used/available space in % and in KBs. If you want it shown in megabytes, you can use the command “df -m”
17. du
du is a command to know the disk usage of a file in your System. If you want to know the disk usage for a particular folder or file in Linux, then you can type in the command df and the name of the folder or file. For example, if you want to know the disk space used by the folder Documents in Linux, you can use the command “du Documents”. You can also use the command “ls -lah” to view the file sizes of all the files in a folder.
18. tar
tar is a command used to work with tarballs (or files compressed in a tarball archive) in the Linux Command Line. It has a long list of uses. It can be used to compress and uncompress different types of tar archives like .tar, .tar.gz, .tar.bz2.etc. It works on the basis of the arguments given to it. For example, tar -cf for creating a .tar archive, -xf to untar a tar archive, -tvf to list the contents of the archive.etc.
19. uname
uname is a command used to show the Information about the system. Using the command “uname -a” prints most of the information about the system. This prints the Kernel release date, version, processor type. Etc.
20. hostname
hostname is a command used to know your name in your host or your network. Basically, it displays your hostname and IP address. Typing just “hostname” gives the output, your hostname. Typing in “hostname -I” gives you your IP address in your network.
21. ping
ping is a command used to check your connection to a server.
Tips and Tricks in Using Linux Command Line
- You can use clear command to clear the terminal if it gets filled up with too many commands!
- TAB can be used to fill up in Terminal. For example, You just need to type “cd Doc” and then TAB and the terminal fills the rest up and makes it “cd Documents”.
- Ctrl+C can be used to stop any command in terminal safely. If it doesn’t stop with that, then Ctrl+Z can be used to force stop it.
- You can exit from the terminal by using the exit command.
- You can power off or reboot the computer by using the command sudo halt and sudo reboot.


















Comments
Post a Comment