Linux/Unix command-line interface provides a powerful environment for system administration and everyday tasks. Understanding the basic commands is crucial for efficiently navigating and managing files, directories, and processes. In this tutorial, we will cover some essential Linux/Unix commands along with practical examples to help you get started.
Basic Commands of Linux/Unix with Examples
- pwd – Print Working Directory: The
pwdcommand displays the current working directory, which is the directory you are currently in.
Example:
$ pwd
/home/user/Documents- ls – List Directory Contents: The
lscommand is used to list the contents of a directory, including files and subdirectories.
Example:
$ ls
file1.txt file2.txt directory1 directory2Common options for the ls command include:
-l: Long format, providing detailed information about files and directories.-a: Show hidden files and directories.-t: Sort by modification time.
- cd – Change Directory: The
cdcommand is used to change the current working directory.
Example:
$ cd /home/user/DocumentsTo navigate to the parent directory, use cd ... To navigate to the home directory, use cd or cd ~.
- mkdir – Make Directory: The
mkdircommand creates a new directory.
Example:
$ mkdir new_directory- touch – Create Empty File: The
touchcommand is used to create an empty file or update the timestamp of an existing file.
Example:
$ touch file.txt- cp – Copy Files and Directories: The
cpcommand is used to copy files and directories.
Example:
$ cp file.txt backup/file.txt- mv – Move or Rename Files and Directories: The
mvcommand is used to move or rename files and directories.
Example:
$ mv file.txt new_directory/file_new.txt- rm – Remove Files and Directories: The
rmcommand is used to remove files and directories.
Example:
$ rm file.txtCommon options for the rm command include:
-r: Recursively remove directories and their contents.-f: Force removal without confirmation.
- cat – Concatenate and Display File Content: The
catcommand displays the contents of one or more files.
Example:
$ cat file.txt
Tutorial: Basic Commands of Linux/Unix with Examples
Introduction: Linux/Unix command-line interface provides a powerful environment for system administration and everyday tasks. Understanding the basic commands is crucial for efficiently navigating and managing files, directories, and processes. In this tutorial, we will cover some essential Linux/Unix commands along with practical examples to help you get started.
- pwd – Print Working Directory: The
pwdcommand displays the current working directory, which is the directory you are currently in.
Example:
bashCopy code$ pwd
/home/user/Documents
- ls – List Directory Contents: The
lscommand is used to list the contents of a directory, including files and subdirectories.
Example:
shellCopy code$ ls
file1.txt file2.txt directory1 directory2
Common options for the ls command include:
-l: Long format, providing detailed information about files and directories.-a: Show hidden files and directories.-t: Sort by modification time.
- cd – Change Directory: The
cdcommand is used to change the current working directory.
Example:
shellCopy code$ cd /home/user/Documents
To navigate to the parent directory, use cd ... To navigate to the home directory, use cd or cd ~.
- mkdir – Make Directory: The
mkdircommand creates a new directory.
Example:
shellCopy code$ mkdir new_directory
- touch – Create Empty File: The
touchcommand is used to create an empty file or update the timestamp of an existing file.
Example:
shellCopy code$ touch file.txt
- cp – Copy Files and Directories: The
cpcommand is used to copy files and directories.
Example:
shellCopy code$ cp file.txt backup/file.txt
- mv – Move or Rename Files and Directories: The
mvcommand is used to move or rename files and directories.
Example:
shellCopy code$ mv file.txt new_directory/file_new.txt
- rm – Remove Files and Directories: The
rmcommand is used to remove files and directories.
Example:
shellCopy code$ rm file.txt
Common options for the rm command include:
-r: Recursively remove directories and their contents.-f: Force removal without confirmation.
- cat – Concatenate and Display File Content: The
catcommand displays the contents of one or more files.
Example:
$ cat file.txt- grep – Search for Patterns in Files: The
grepcommand is used to search for specific patterns or expressions within files.
Example:
$ grep "pattern" file.txt- ps – Process Status: The
pscommand displays information about active processes.
Example:
$ psCommon options for the ps command include:
-e: Show information about all processes.-f: Full-format listing.
- man – Manual Pages: The
mancommand displays the manual pages for other commands, providing detailed information about their usage and options.
Example:
$ man lsConclusion
These are some of the fundamental Linux/Unix commands that will help you navigate and manage files, directories, and processes. Practice using these commands and explore their options to become proficient in the command-line environment. Additionally, remember that most commands have extensive documentation in their manual pages, accessible through the man command, offering further insights into their usage and functionalities.