Linux 101

Linux 101

Basic commands, use.

Linux is a collection of open-source Unix operating systems, that are based on the Linux Kernel(Kernel is like the heart of an Operating System). This includes all of the most popular Linux-based systems like Ubuntu, Fedora, Mint, Debian, etc. They’re called distributions or distros.

It has continued to gain popularity due to its open-source nature, which means People can freely modify and redistribute it under their own name. (code is available freely on the internet)

tux_linux_penguin_code_binary.jpg

From the time it has been first released(1991) many changes were made. When operating a Linux OS, you need to use a shell (an interface that gives you access to the operating system’s services). Most Linux distributions use a graphic user interface (GUI) as their shell, mainly to provide ease of use for their users.

eiciel-Linux-app-window.png

That being said, it’s recommended to use a command-line interface (CLI) because it’s more powerful and effective. Tasks that require a multi-step process through GUI can be done in a matter of seconds by typing commands into the CLI.

And also, Imagine yourself typing on a large screen filled with text commands and a plain background!! I guess that's what you thought of when you first heard the word "Linux"

history-command.png

If you're considering using Linux, there are many commands you need to know. I'll help you with some of the basic commands which would definitely be useful for you.

Basic Linux Commands

To use the commands you first need to open the command line which can be opened by clicking on the Activities item at the top left of the screen, then typing the first few letters of “terminal”, “command”, “prompt” or “shell”.(for Ubuntu, steps may differ depending on the distribution.)

fun fact:

folders are termed as directories in Linux.

1. mkdir Command:

use this command to create a new directory. If you type mkdir Hell a directory named Hell will be created.

There are other mkdir commands as well:

  • To generate a new directory in an existing one, use mkdir Hell/new
  • Use the p (parents) option to create a directory in between two existing directories. For example, mkdir -p Hell/f1/new will create the new “f1” directory.

2. cat Command:

cat (concatenate) is one of the most frequently used commands. It is used to list the contents of a file on the standard output. To run this command, type cat followed by the file’s name and its extension. For instance: cat file.txt. If the extension isn't mentioned .txt is the default one.

Other ways to use this command:

  • cat > filename creates a new file. (you can add content in it and use ctrl+c to interrupt.)
  • cat filename1 filename2>filename3 joins two files (1 and 2) and stores the output of them in a new file (3)

3. ls Command:

The ls command is used to view the contents of a directory. By default, this command will display the contents of your current working directory.

If you want to see the content of other directories, type ls and then the directory’s path. For example, enter ls /home/username/Num to view the content of Num.

Other ways to use this command:

  • ls -R will list all the files in the sub-directories as well.
  • ls -a will show the hidden files also.
  • ls-al will list the files and directories in a detailed manner.

4. pwd Command:

The pwd command is used to show the path of the current working directory. For example, if you are in a directory named "test", it shows /home/username/test.

5. cd Command:

This command is used to move to a specific directory from the current.

If you want to move to a sub-directory of the present, use cd name (name refers to the name of the sub-directory)

If you want to switch to a completely new directory you should mention the absolute path. For Example, if you want to move to /home/username/Test. you have to type cd /home/username/Test.

Other ways to use:

  • cd .. to move one directory up.
  • cd to go to the home directory.
  • cd- to move to your previous directory

6. cp Command:

Use the cp command to copy files from the current directory to a different directory. For instance, the command cp hat.jpg /home/username/Pictures would create a copy of hat.jpg (from your current directory) into the Pictures directory.

7. mv Command:

Use this command to move files. Arguments are similar to cp command. Use mv, filename, and the destination directory.

You can also use this to rename files, Syntax: mv oldname.ext newname.ext

8. rmdir Command:

If you need to delete a directory, use the rmdir command. However, rmdir only allows you to delete empty directories.

9. rm command:

Use this command to delete directories and also the contents within.

Fun fact: rmdir is same as rm -r

10. touch command:

This is used to create empty files. Example touch /home/username/Documents/sample.py creates an empty python file with a name sample under Documents directory. Note: This is similar to the cat command, the difference is this creates an empty file.

11. sudo command:

This command enables you to perform tasks that require administrative or root permissions. (Be careful while using this command.)

12. head command:

The head command is used to view the first lines of any text file. By default, it will show the first ten lines. If you want a specific number (5 for example) of lines the type head -n 5 filename.

13. tail command:

This command shows the last lines of any text file. (similar to the head command).

14. chmod command:

chmod is used to change the read, write, and execute permissions of files and directories. There are so many other things to discuss about this command, I'll make a separate blog about this.

15. echo command:

It prints to the output the argument passed to it. If you want to add "hello" to a file name.txt type echo hello >> name.txt

some other uses:

  • echo * shows the directories on the taskbar.
  • escape characters can be used while typing. Example: echo -e "hello\b hai" prints "hell hai" in the terminal

16. man command:

Using this command you can learn how to use any command in the shell itself. example: man echo will show the manual instructions of the echo command.

Special tips:

  • Ctrl+C and Ctrl+Z are used to stop any command that is currently working. Ctrl+C will stop and terminate the command, while Ctrl+Z will simply pause the command.

  • Ctrl+A moves you to the beginning of the line while Ctrl+E moves you to the end.

  • Use the clear command to clean all the existing lines.

  • Use the quit command to close the terminal.

These are some of the basic commands in Linux. You can remember these commands by using them daily. Knowing Linux commands will definitely be beneficial to you.

Happy Learning!!