Post

10 Essential Linux Commands Every Beginner Should Know

10 Essential Linux Commands Every Beginner Should Know

Linux is a powerful operating system, and mastering its command line can greatly enhance your productivity. Here are ten essential Linux commands every beginner should know, along with detailed explanations, examples, and tips.


1. ls - List Files and Directories

The ls command lists the contents of a directory. By default, it shows the files and directories in the current directory.

Basic Usage:

1
ls

Common Options:

  • ls -l: Displays detailed information about each file, including permissions, owner, size, and modification date.
  • ls -a: Shows all files, including hidden files (those starting with .).
  • ls -lh: Displays file sizes in a human-readable format (e.g., KB, MB, GB).
  • ls -R: Lists files in the current directory and all subdirectories recursively.

Example:

1
ls -alh

This command lists all files (including hidden ones) with detailed information in a human-readable format.

Tip:

Use ls --color=auto to enable colored output, which makes it easier to distinguish between files and directories.


2. cd - Change Directory

The cd command is used to navigate between directories.

Basic Usage:

1
cd /path/to/directory

Useful Shortcuts:

  • cd ..: Moves up one directory level.
  • cd ~: Moves to the home directory of the current user.
  • cd -: Switches to the previous directory.

Example:

1
cd /var/log

This command navigates to the /var/log directory.

Tip:

Use pwd (explained below) to confirm your current directory after using cd.


3. pwd - Print Working Directory

The pwd command displays the full path of the current directory.

Usage:

1
pwd

Example:

1
pwd

If you are in /home/user/documents, the output will be:

1
/home/user/documents

Tip:

This command is especially useful when you’re navigating deeply nested directories and want to confirm your location.


4. cp - Copy Files and Directories

The cp command copies files or directories from one location to another.

Basic Usage:

1
cp source.txt destination.txt

Common Options:

  • cp -r: Copies directories recursively, including all their contents.
  • cp -i: Prompts before overwriting files.
  • cp -v: Displays the files being copied.

Example:

1
cp -r /source/folder /destination/folder

This command copies the entire /source/folder to /destination/folder.

Tip:

Always double-check the destination path to avoid overwriting important files.


5. mv - Move or Rename Files and Directories

The mv command moves files or directories to a new location or renames them.

Basic Usage:

1
mv oldname.txt newname.txt

Example:

1
mv file.txt /home/user/documents/

This command moves file.txt to the /home/user/documents/ directory.

Tip:

To rename a file, simply specify the new name in the destination path.


6. rm - Remove Files and Directories

The rm command deletes files or directories.

Basic Usage:

1
rm file.txt

Common Options:

  • rm -r: Removes directories and their contents recursively.
  • rm -i: Prompts before deleting each file.
  • rm -f: Forces deletion without confirmation.

Example:

1
rm -rf /path/to/directory

This command forcefully deletes the specified directory and all its contents. Use with caution!

Tip:

Always double-check the path before using rm, especially with the -rf option, as it can permanently delete important data.


7. touch - Create or Update Files

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

Basic Usage:

1
touch newfile.txt

Example:

1
touch file1.txt file2.txt

This command creates two empty files: file1.txt and file2.txt.

Tip:

Use touch to quickly create placeholder files when setting up a project.


8. cat - Display File Contents

The cat command displays the contents of a file.

Basic Usage:

1
cat file.txt

Common Options:

  • cat -n: Displays line numbers.
  • cat file1.txt file2.txt > combined.txt: Combines multiple files into one.

Example:

1
cat /etc/passwd

This command displays the contents of the /etc/passwd file.

Tip:

For large files, use less or more instead of cat to view the contents page by page.


9. mkdir - Create Directories

The mkdir command creates new directories.

Basic Usage:

1
mkdir new_folder

Common Options:

  • mkdir -p: Creates parent directories as needed.

Example:

1
mkdir -p /home/user/projects/new_project

This command creates the new_project directory, along with any missing parent directories.

Tip:

Use mkdir -p to avoid errors when creating nested directories.


10. man - View Command Manuals

The man command displays the manual page for a command, providing detailed information about its usage.

Basic Usage:

1
man command

Example:

1
man ls

This command opens the manual page for the ls command.

Tip:

Use / to search for keywords within the manual page. For example, type /option to find all mentions of “option.”


Additional Tips for Beginners

  • Tab Completion: Press Tab to auto-complete file or directory names.
  • Command History: Use the Up and Down arrow keys to navigate through your command history.
  • Clear Screen: Use clear to clear the terminal screen.
  • Exit Terminal: Use exit to close the terminal session.

Mastering these commands will help you navigate and manage your Linux system efficiently. Practice them regularly, and don’t hesitate to explore the man pages for more advanced options!

This post is licensed under CC BY 4.0 by the author.