Basic Linux Commands

Introduction to Linux

  • Linux is an open-source operating system kernel.It is suitable for diverse environments.

  • It has a powerful command-line interface (CLI) alongside user-friendly graphical interfaces.

  • Multiuser and Multitasking: It supports multiple users and tasks running concurrently. This makes it suitable for servers, where many users might need access, and for desktops, which require multitasking capabilities.

  • Security: Linux's open-source nature facilitates security audits and timely updates.

  • Variety of Distributions: Some popular ones include Ubuntu, Fedora, Debian, CentOS, and Arch Linux.

  • Package Management: Linux distributions use package management systems (e.g., APT, YUM, and Pacman) to facilitate the installation, removal, and updating of software.

  • Linux is a popular choice for servers, embedded systems, and personal computers.

  • Linux has GPL :General Public License

  • It focuses on shell scripting,networking, terminal,programming.

  • It is secure.

  • Updates are less than window

Some linux basic commands

File and Directory Management

**ls (list) :**List all contents (files and directories) in the current directory.

    • ls-h: Human-readable file sizes.

      • ls -a: List all files and directories, including hidden ones.

      • ls -l: List files and directories in detailed format.

      • ls -t: List files and directories sorted by modification time.

      • ls -rt: List files and directories in reverse order of their names

  1. pwd (print working directory) : Print the name of the directory that the user is currently working in.

  2. **cd(change directory):**allows the user to change to a specified directory.

  3. mkdir(make directory): allows the user to create a new directory..

    • Usage: mkdir directory_name

    • Along with mkdir we can use the "-p" flag which will create sub-directories (directories within a directory) if it does not exist.

  4. touch :Create an empty file.

    • Usage: touch file_name
  5. cp :Copy files or directories.

    • Usage: cp source_file destination_directory

    • cp -r: Copy directories recursively.

  6. mv :Move or rename files or directories.

    • Usage:mv source_file destination
  7. rm (remove): Remove files or directories.

    • Usage: rm file_name

    • rm -r: Remove directories recursively.

With this command, we can use the "-r" flag, which removes the files recursively within a directory but do not use "-rf" which will forcefully delete the files and will not give a prompt when deleting important files.

File viewing and Editing

  1. cat(concatenate): Display the contents of a file.

    • Usage: cat file_name
  2. more and less Display file contents one screen at a time.

    • Usage: more file_name & less file_name
  3. head and tail Display the beginning or end of a file.

    • Usage: head file_name & tail file_name
  4. grep Search for text in files using patterns.

    • Usage: grep "pattern" file_name

File permission and ownership

  1. chmod :Change file permissions.

    • Usage: chmod permissions file_name

    • ls -l : to see permission of file or dir

  2. chown command : change ownership

Process Management

  1. ps : List running processes.

  2. kill: Terminate processes.

    • Usage: kill PID
  3. top: Display active processes in real-time

  • man :Access the manual pages for commands.

    • Usage: man command_name

System Information

  • df: Display disk space usage

  • du: Display file and directory space usage

  • lscpu :Display CPU

Compress and archieve

  • tar: Archive and compress files.

    • Usage: tar options archive_name files/directories

      • -c: Create a new archive.

      • -z: Compress the archive using gzip.

  • wget : Download files from the internet.

    • Usage: wget URL

Network Commands:

  • ping: Check network connectivity to a specific host.

  • ifconfig or ip: Display network interface information.

Administrative Tasks

whoami:displays the username of the current user when this command is entered.

Sudo:execute commands with administrative privileges

grep <search_word> <filename> //searches for word in a file
   -i overlook case sensitivity

   -R looks through dir as well.

   -v reverse search, searches everything except given search word

sed /s/<search-word>/<reaplce_word>/g //sed allows editing of file without opening it
        /s search

        /g global

less <filename> // reads  file without allowing to edit. (readonly)
7
Subscribe to my newsletter

Read articles from Ruchi Lamichhane directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ruchi Lamichhane
Ruchi Lamichhane

I am a tech ethusiast with passion for technology, embracing the world of continuous integration, automation, and collaboration to make a meaningful impact in the dynamic realm of DevOps.