Learn Basic Commands For Linux
Learn Basic Commands For Linux
What Is Linux?
Ubuntu Linux
Linux Mint
Debian
Fedora
Basic 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 file
system. It is denoted by a forward slash( / ). The user directory is
usually something like "/home/username".
2. ls — Use the "ls" command to know what files are in the directory
you are in. You can see all the hidden files by using the command “ls
-a”.
4. mkdir & rmdir — Use the mkdir command when you need to
create a folder or a directory. For example, if you want to make a
directory called “DIY”, then you can type “mkdir DIY”. Remember,
as told before, if you want to create a directory named “DIY
Hacking”, then you can type “mkdir DIY\ Hacking”. Use rmdir to
delete a directory. But rmdir can only be used to delete an empty
directory. To delete a directory containing files, use rm.
Intermediate Commands
3. nano, vi, jed — nano and vi are already installed text editors in the
Linux command line. The nano command is a good text editor that
denotes keywords with color and can recognize most languages.
And vi is simpler than nano. You can create a new file or modify a
file using this editor. For example, if you need to make a new file
named "check.txt", you can create it by using the command “nano
check.txt”. You can save your files after editing by using the
sequence Ctrl+X, then Y (or N for no). In my experience,
using nano for HTML editing doesn't seem as good, because of its
color, so I recommend jed text editor. We will come to installing
packages soon.
4. sudo — A widely used command in the Linux command
line, sudo stands for "SuperUser Do". So, if you want any command
to be done with administrative or root privileges, you can use
the sudo command. For example, if you want to edit a file like viz.
alsa-base.conf, which needs root permissions, you can use the
command – sudo nano alsa-base.conf. You can enter the root
command line using the command “sudo bash”, then type in your
user password. You can also use the command “su” to do this, but
you need to set a root password before that. For that, you can use the
command “sudo passwd”(not misspelled, it is passwd). Then type in
the new root password.
5. df — Use the df command 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”.
10. apt-get — Use apt to work with packages in the Linux command
line. Use apt-get to install packages. This requires root privileges, so
use the sudo command with it. For example, if you want to install the
text editor jed (as I mentioned earlier), we can type in the command
“sudo apt-get install jed”. Similarly, any packages can be installed
like this. It is good to update your repository each time you try to
install a new package. You can do that by typing “sudo apt-get
update”. You can upgrade the system by typing “sudo apt-get
upgrade”. We can also upgrade the distro by typing “sudo apt-get
dist-upgrade”. The command “apt-cache search” is used to search
for a package. If you want to search for one, you can type in “apt-
cache search jed”(this doesn't require root).
11. chmod — Use chmod to make a file executable and to change the
permissions granted to it in Linux. Imagine you have a python code
named numbers.py in your computer. You'll need to run “python
numbers.py” every time you need to run it. Instead of that, when you
make it executable, you'll just need to run “numbers.py” in the
terminal to run the file. To make a file executable, you can use the
command “chmod +x numbers.py” in this case. You can use
“chmod 755 numbers.py” to give it root permissions or “sudo
chmod +x numbers.py” for root executable. Here is some
more information about the chmod command.
You can use the 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.