Basic Linux Commands
Basic Linux Commands
What Is Linux?
Linux is an operating system's kernel. You might have heard of UNIX.
Well, Linux is a UNIX clone. But it was actually created by Linus
Torvalds from Scratch. Linux is free and open-source, that means that
you can simply change anything in Linux and redistribute it in your own
name! There are several Linux Distributions, commonly called “distros”.
Ubuntu Linux
Red Hat Enterprise Linux
Linux Mint
Debian
Fedora
So, basically, a shell is a program that receives commands from the user
and gives it to the OS to process, and it shows the output. Linux's shell is
its main part. Its distros come in GUI (graphical user interface), but
basically, Linux has a CLI (command line interface). In this tutorial, we
are going to cover the basic commands that we use in the shell of Linux.
Linux Commands
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.
5. rm — Use the rm command to delete files and directories. But rm cannot simply delete a
directory. Use “rm -r” to delete a directory. In this case, it deletes both the folder and the files in
it.
6. 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”.
7. man & --help — To know more about a command and how to use it, use the man command.
It shows the manual pages of the command. For example, “man cd” shows the manual pages of
the cd command. Typing in the command name and the argument helps it show which ways the
command can be used (e.g., cd –help).
8. cp — Use the cp command to copy files through the command line. It takes two arguments:
The first is the location of the file to be copied, the second is where to copy.
9. mv — Use the mv command to move files through the command line. We can also use
the mv command to rename a file. For example, if we want to rename the file “text” to “new”,
we can use “mv text new”. It takes the two arguments, just like the cp command.
10. 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 uppercase or lowercase). 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 them using an asterisk (*). For
example, to locate a file containing the words "hello" and "this", you can use the command
“locate -i *hello*this”.
Intermediate Commands
1. echo — The "echo" command helps us move some data, usually text
into a file. For example, if you want to create a new text file or add to an
already made text file, you just need to type in, “echo hello, my name is
alok >> 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.
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.
9. uname — Use uname to show the information about the system your
Linux distro is running. Using the command “uname -a” prints most of
the information about the system. This prints the kernel release date,
version, processor type, etc.
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 sudocommand 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
haltand sudo reboot.
See the link for : UNIX Tutorial for
Beginners(very helpful for you )
http://www.ee.surrey.ac.uk/
Teaching/Unix/