Here's a beginner friendly thread on quickly getting started with the basic commands of Linux command terminal using Ubuntu and having some fun, of course!
1. Release details
- There are several distributions of Linux (we call them distros)
- Let's first check the details of the Linux release we are using.
- We use the command
lsb_release -a
for this which gives the LSB (Linux Standard Base) information about our Linux distribution. - Read more here - en.wikipedia.org/wiki/Linux_Standard_Base and refspecs.linuxfoundation.org/lsb.shtml
2. User name
- Now its time to check the user name.
- The command
whoami
prints the effective user-id. - So, normally it would show the name you have assigned to your system, but when used
sudo
(Super User DO) command, it will show the user as root.
3. Print working directory
- Now that we know who's who, let's also see where are we.
- Basically, let's print the working directory.
- Use the
pwd
command. - Refer to the GUI in the image to compare.
4. List files in the directory
- So what's present in the working/current directory?
- We use
ls
command for that. - Can you notice the similarity between the CLI and GUI? (says 'Cooool' internally)
5. List hidden files too!
- Wait a minute! What about the hidden files?
- On the GUI, we have an option to "show hidden files". How do we see them on the terminal?
- Just use
-a
withls
and thou question shall be answered. And yeah, @JohnWickMovie rocks! Big fan!
6. Change directory
- It's now time for some action. Let us explore the folders and files present in our current working directory.
cd
command allows you to change directory to the directory you want to access.- For folders not in current directory, use full path.
7. Create file(s)
- So we moved to Desktop and it's empty.
- Let's create a text file here.
- This can be done using the
touch
command. Thefile.txt
file is currently empty. We'll do something about it.
8. Write some text into an empty file
- There are many ways to write/edit a file in the terminal.
- For now, lets use
echo
and>
. echo
basically prints what you feed to it.- The
>
operator will store the command value in the file mentioned. It will create the file if not present. cat
will print the file.Now, lets go back to where we started from - home directory.
- This can be done using
cd ..
command. TIP - Every command (generally) has a help option. Trycd --help
9. Linux File System
- In Linux, EVERYTHING is a file. Even a command.
- You can find the location of any command using
which
- which is also a command!
After that you can also print the whole file. Lets try this with
ls
.So, if we could do the above, can we modify the command file too? (Classic Prank Idea)
- Lets rename "ls" to "ls1" and see the action - Needs root permission.
Spoiler alert - it works!
- Now lets revert the changes (coders are good human beings)
- Notice that the directory has many other command files too, which we explored earlier. For example - touch, cat, pwd.
Finish
That's all for now, folks. Let me know if you found this helpful. Also feel free to add your inputs too!
Chapter 2 coming soon...