Linux Tutorial Website

Introduction

Linux commands are essential for navigating and manipulating the filesystem, managing files and directories, and performing various administrative tasks. This document provides an overview of some of the most common Linux commands, complete with descriptions, examples, and commonly used flags.

ls

The `ls` command lists the contents of a directory.

# List all files and directories in the current directory
ls

# List all files and directories, including hidden ones
ls -a

# List files and directories with detailed information
ls -l

# List files and directories with detailed information, including hidden ones
ls -la

Common flags:

  • `-a`: Show all files, including hidden files
  • `-l`: Use a long listing format
  • `-la`: Combine `-l` and `-a` to show detailed information for all files

cd

The `cd` command changes the current directory.

# Change to the home 
directory
cd

# Change to a specific directory
cd /path/to/directory

# Change to the parent directory
cd ..

# Change to the previous directory
cd -

Common flags:

  • None

mkdir

The `mkdir` command creates a new directory.

# Create a single directory
mkdir new_directory

# Create nested directories
mkdir -p parent_directory/child_directory

Common flags:

  • `-p`: Create parent directories as needed

rmdir

The `rmdir` command removes empty directories.

# Remove a single empty directory
rmdir empty_directory

# Remove nested empty directories
rmdir -p parent_directory/child_directory

Common flags:

  • `-p`: Remove parent directories if they become empty

rm

The `rm` command removes files or directories.

# Remove a file
rm file_name

# Remove a directory and its contents recursively
rm -r directory_name

# Force remove a file or directory
rm -f file_name_or_directory

# Prompt before every removal
rm -i file_name_or_directory

Common flags:

  • `-r`: Remove directories and their contents recursively
  • `-f`: Force removal without prompt
  • `-i`: Prompt before every removal

touch

The `touch` command creates a new empty file or updates the timestamp of an existing file.

# Create a new empty file
touch new_file

# Update the timestamp of an existing file
touch existing_file

Common flags:

  • None

cp

The `cp` command copies files or directories.

# Copy a file
cp source_file destination_file

# Copy a directory and its contents recursively
cp -r source_directory destination_directory

# Prompt before overwriting existing files
cp -i source_file destination_file

Common flags:

  • `-r`: Copy directories recursively
  • `-i`: Prompt before overwriting files

mv

The `mv` command moves or renames files and directories.

# Move a file to a different directory
mv file_name /path/to/directory

# Rename a file or directory
mv old_name new_name

# Prompt before overwriting existing files
mv -i source_file destination_file

Common flags:

  • `-i`: Prompt before overwriting files

ps

The `ps` command displays information about running processes.

# Display a snapshot of current processes
ps

# Display detailed information about all processes
ps -e

# Display a full listing of all processes
ps -ef

Common flags:

  • `-e`: Show information about all processes
  • `-f`: Show full format listing

man

The `man` command displays the manual page for a command.

# Display the manual page for a command
man command_name

# Display the manual page for a section
man section command_name

Common flags:

  • None

Author: Aleks (theshatterstone) (and ChatGPT)

Created: 2024-06-23 Sun 17:38

Validate