Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Introduction to Basic Commands

What are Basic Commands?

Basic commands are the fundamental instructions that you can give to your Linux operating system through the command line interface. These commands allow you to navigate the filesystem, manage files and directories, and carry out essential administrative tasks.

Opening the Terminal

To start using basic commands, you need to open the terminal. The terminal is a text-based interface that allows you to interact with the operating system. On most Linux distributions, you can open the terminal by searching for "Terminal" in the application menu or by pressing Ctrl + Alt + T.

Navigating the Filesystem

1. The pwd Command

The pwd (print working directory) command displays the path of the current directory you are in.

Example:

pwd
/home/user

2. The ls Command

The ls command lists the contents of the current directory.

Example:

ls
Documents Downloads Pictures Music

3. The cd Command

The cd (change directory) command allows you to navigate between directories.

Example:

cd Documents

After running cd Documents, you can use pwd to confirm you are in the Documents directory:

pwd
/home/user/Documents

Managing Files and Directories

1. The touch Command

The touch command creates a new empty file.

Example:

touch newfile.txt

This command creates a new empty file named newfile.txt.

2. The mkdir Command

The mkdir (make directory) command creates a new directory.

Example:

mkdir newdir

This command creates a new directory named newdir.

3. The rm Command

The rm (remove) command deletes files.

Example:

rm newfile.txt

This command deletes the file named newfile.txt.

4. The rmdir Command

The rmdir (remove directory) command deletes empty directories.

Example:

rmdir newdir

This command deletes the directory named newdir, provided it is empty.

Viewing and Editing Files

1. The cat Command

The cat (concatenate) command displays the content of a file.

Example:

cat example.txt

This command displays the content of example.txt.

2. The nano Command

The nano command opens a text editor to create or edit files.

Example:

nano example.txt

This command opens example.txt in the nano text editor.

Getting Help

1. The man Command

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

Example:

man ls

This command displays the manual page for the ls command.

2. The --help Option

Most commands support the --help option to display a brief summary of their usage.

Example:

ls --help

This command provides a summary of the usage and options available for the ls command.