DEV Community

Cover image for Linux Learning (Part:1)
Usman Siddique
Usman Siddique

Posted on

1

Linux Learning (Part:1)

I have been learning Linux for the past 3 weeks, and I have decided to share my knowledge with others and those who want to learn Linux like me.

I will divide all the topics into seven to eight parts(posts). This will help beginners like me learn and understand better. I am following the roadmap from Roadmap.sh.
To learn Linux I am using a terminal or command-line interface (CLI) on my Linux OS. You can install Linux OS on your system or create VM to use it.

I have listed all the commands(that I have learned) and their flags including their short description of what it does.
So, let's start happy learning.

Navigation Basics:

In Linux navigation between files and directories(folders) is very basic, yet very important that allows you to take full advantage of the command-line interface(CLI).

List Command (ls)

  • ls : List all the content of a directory(Folder).
  • ls -a : List all the files including hidden files.
  • ls -d .*/ : Lists all the directories (including hidden ones) in the current directory.
  • ls -l : List files in long list format.
  • ls -la : list all the files with all the data in a long list format.
  • ls -s : List file size in KiloBytes(KBs).
  • ls -ls : List file size in KBs in long list format.
  • ls .. : List contents of parent directory.
  • ls ../.. : List the contents of the grandparent directory (i.e. two levels above your current directory).
  • ls *.txt : List all the files with a .txt file extension but, you can add any file extension to list in the result.
  • ls Dir_Name/*.txt : List all the files with a .txt file extension in a mentioned directory.
  • ls Dir_Name/*.* : List all the files that have any file extension.
  • ls >output.txt : Saves the output of the ls command (which lists the contents of the current directory) to a file named output.txt

Change Directory Command(cd)

The cd command stands for Change Directory, and it is used to navigate between directories in a Linux system.

  • cd Directory_Name : To change the current working directory. Directory_Name will be the name of the directory you want to move into.
  • cs .. : To move up one level in the directory hierarchy, meaning it takes you to the parent directory of your current directory.
  • cd ../.. : To move up two levels in the directory hierarchy, meaning it takes you to the grandparent directory of your current directory.

File Creation(touch, echo)

touch and echo commands are used to create files. The touch command can only create an empty file whereas the echo can create and save any data in it while creating. You can do many other things with these commands, but I have listed only a few.

  • touch text_file.txt : Creates an empty file named text_file.txt.
  • echo "Hello, world!" > filename.txt : This creates a file filename.txt with the text "Hello, world!" in it. If the file already exists. it can overwrite it.
  • cat > filename : The cat command can also be used to create a new file. After running this, you can type the content you want to save in the file and when you are done, press Ctrl+D to save and exit.

Moving, Creating & Deleting Files / Directories

Learning commands like mv, mkdir and mv can be very helpful in daily life. It makes our work easy while working on CLI.

The mv command is used to move or rename files and directories.

  • mv file.txt /path/to/destination : This command will move the file.txt to the path given by you in /path/to/destination.
  • mv old_name.txt new_name.txt : This will rename the file from old_name.txt to new_name.txt

  • mkdir directory_name : Used to create directories (folders). This Linux command will create a directory named directory_name in the your current working directory.

  • mkdir dir1 dir2 dir3 : This will create multiple directories named dir1
    , dir2, dir3 in the current working directory.

  • mkdir /path/to/directory: This command allows you to create a directory in any other directory while staying in your current working directory.

  • rmdir directory_name : This command will remove the directory.
    The rmdir command will only delete empty directories meaning they don't contain any files or subdirectories.
    The mkdir and rmdir both deal with directories, but their functions are opposite, mkdir creates while rmdir deletes.

Editing Files

File editing can be tricky if you don't know about the text editors in the Linux operating system. Text editor can be used to edit files, configure some files or write scripts.
There are many text editors but, I have used only two popular editors vim and nano. Every text editor has its own learning curve and set of commands.

vim

Vim editor operates in many modes, I have listed important ones:

- Normal Mode: It is a default mode when we open a file in vim. It is used for navigation and text manipulation.
- Insert Mode: For editing text. Press i to enter this mode.
- Visual Mode: For selecting text. Press v to enter this mode.
- Command Mode: For executing commands like saving and quitting. Press : to enter this mode.
There is so much to learn about vim which is not possible for me to mention all here. You can watch Vim Beginners Guide playlist
by Learn Linux TV for better learning vim, I personally love watching his videos.

Nano

Nano is a simpler, more user-friendly text editor compared to Vim. It’s a great choice for beginners due to its easy-to-understand interface and built-in keyboard shortcuts.
You can watch this video on nano to learn more and some practical knowledge.

Note: All the descriptions of topics, subtopics and commands that I have written are what I have learned and being a human I can make mistakes. If you find any, feel free to point it out.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay