Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, May 29, 2024

The Linux command line for beginners

Overview

The Linux command line, also known as the terminal or shell, is a powerful tool that allows users to interact directly with the operating system. While it might seem intimidating at first, mastering a few basic commands can significantly enhance your efficiency and ability to manage your system. This overview introduces some essential commands that will help beginners navigate the Linux command line with confidence.




File and Directory Operations

Listing Files

  1. ls : Lists files and directories in the current directory. 
  2. ls -l : Lists files and directories with detailed information.
  3. ls -a : Lists all files, including hidden files.

Changing Directories

  1. cd [directory] : Changes the current directory to the specified directory.
  2. cd .. : Moves up one directory level.
  3. cd ~ : Changes to the home directory.

Creating Directories

  1. mkdir [directory] : Creates a new directory.

Removing Directories

  1. rmdir [directory] : Removes an empty directory.
  2. rm -r [directory] : Removes a directory and its contents recursively.

Copying Files and Directories

  1. cp [source] [destination] : Copies a file.
  2. cp -r [source_directory] [destination_directory] : Copies a directory and its contents.
  3. Moving/Renaming Files and Directories
  4. mv [source] [destination] : Moves or renames a file or directory.

Removing Files

  1. rm [file] : Removes a file.
  2. rm -r [directory] : Removes a directory and its contents.


Viewing and Editing Files

Viewing File Contents

  1. cat [file] : Displays the contents of a file.
  2. more [file] : Displays file contents one screen at a time.
  3. less [file] : Similar to more, but with backward navigation.
  4. head [file] : Displays the first 10 lines of a file.
  5. tail [file] : Displays the last 10 lines of a file.
  6. tail -f [file] : Displays the last 10 lines of a file and updates in real-time.

Editing Files

  1. nano [file] : Opens a file in the Nano text editor.
  2. vi [file] or vim [file] : Opens a file in the Vi/Vim text editor.

File Permissions

Changing File Permissions

chmod [permissions] [file] : Changes the permissions of a file or directory.
 
Example: chmod 755 [file] : Sets read, write, and execute permissions for the owner, and read and execute permissions for others.

Changing File Ownership

chown [owner]:[group] [file] : Changes the owner and group of a file or directory.
 
Example: chown user:group [file] : Changes the owner to 'user' and the group to 'group'.

System Information

Current Directory 

pwd : Prints the current working directory.

Disk Usage

  1. df : Displays disk space usage.
  2. du : Shows disk usage of files and directories.
  3. du -h [directory] : Shows disk usage in human-readable format.

System Information

uname -a : Displays all system information.
top : Displays running processes and system resource usage.
ps : Displays current processes.
ps aux : Shows detailed information about all running processes.

Networking

Checking Network Connectivity

ping [host] : Checks connectivity to a host.
ifconfig or ip a : Displays network interfaces and configurations.
netstat : Displays network connections, routing tables, and more.
ssh [user]@[host] : Connects to a remote host via SSH.

These commands are just the basics, but they cover many of the common tasks you'll need to perform in a Linux environment.