Table of Contents
Share this Resource

UNIX Commands

What's Coming Up

1. Unix commands help you navigate files, manage directories and interact directly with the system. 
2. Basic commands such as pwd, ls, cd, cp and mv form the foundation of command-line usage. 
3. Search and text-processing commands help locate, filter and transform information efficiently. 
4. Advanced commands support process management, networking, remote access and system monitoring. 
5. Combining commands using pipes can create efficient workflows for complex tasks.

If you are in the tech industry or planning to take your first step, you need to remember that Unix has paved the way for modern operating systems (OS). Its legacy endures not only because of its robust architecture but also because of its command-line interface. If you can learn Unix commands, you can unlock this operating system's full potential.

Unix is highly popular because it can take you from the basics of file navigation and manipulation to the intricacies of process management, networking, and even scripting. In this blog, you will learn everything about UNIX commands from the basics. We will also provide you with a list of UNIX commands. Read on further to learn more!

Basic Unix Commands

In this section, you are going to learn all about the basic UNIX commands. Basic UNIX commands form the foundation of command-line interaction. These include "cd" for directory navigation, "ls" for listing files, and "mkdir" for creating directories. It will help you to perform essential tasks swiftly and efficiently. Mastering these is the initial step towards navigating and manipulating the Unix environment effectively.

1) Navigating the Directory

Navigating the directory structure is a fundamental skill in Unix command-line environments. Understanding how to traverse directories efficiently can assist you in navigating the intricate paths of your computer's file system. Whether you're a beginner or an experienced user, mastering directory navigation is essential for effectively managing files, accessing resources, and executing commands.

1) The command-line Navigator: The Command-Line Interface (CLI) is where you can interact with the Operating System by typing commands. The primary commands for navigation include:

a) Print Working Directory (pwd): This displays the current directory you're in, revealing your current location within the file system.

b) List (ls): The ‘ls’ command lists the files and directories within the current location. Adding options like ‘-l’ provides a detailed list, including file permissions, ownership, size, and timestamps.

c) Change Directory (cd): The ‘cd’ command allows you to move between directories. Using ‘cd’ followed by a directory name or path changes your location within the file system. 

2) Navigating the Pathways: Directories are organised hierarchically, resembling a tree structure. The top-level directory is called the root directory and is represented by a forward slash ("/"). From there, each directory can contain files and subdirectories, creating a branching structure.

Unix paths can be absolute or relative. An absolute path starts from the root directory and gives the complete location, such as /home/user/Downloads. A relative path identifies a location based on your current working directory.

For example, if your current location is /home/user, you can use cd Downloads as a relative path to move into /home/user/Downloads. Understanding both approaches makes it easier to navigate longer directory structures.

3) Navigation Examples in Coding: Let's say you want to navigate to a directory named "Projects" within your home directory and list its contents. Here's how you can achieve this in the Unix command-line environment:

a) Check Your Current Location: Use the ‘pwd’ command to know where you are.

Example: $ pwd

/home/user

b) List Your Home Directory's Contents: Use the ‘ls’ command to see what's in your home directory.

Example: $ ls

Documents Downloads Pictures Projects

c) Change to the "Projects" Directory: Use the ‘cd’ command to move into the "Projects" directory.

Example: $ cd Projects

d) List Contents of the "Projects" Directory: Use the ‘ls’ command again to see what's inside "Projects."

Example: $ ls

project1 project2 notes.txt

UNIX Fundamentals Course

2) File Manipulation

File manipulation is an important part of Unix. It allows you to create, modify, move, and delete files and directories precisely and efficiently. Whether you're a developer, system administrator, or a curious learner, understanding the commands for file manipulation is vital for effectively managing your system's resources and organising your work.

1) Creating and Deleting Files: Creating new files and directories is a fundamental skill. The ‘touch’ command is used for creating empty files, while ‘mkdir’ is employed to create directories. For example:

a) Creating a File: Use the ‘touch’ command followed by the desired file name to create a new file.

Example: $ touch new_file.txt

b) Creating a Directory: Utilise the ‘mkdir’ command followed by the directory name to create a new directory.

Example: $ mkdir new_directory

To manage your system efficiently, you must also know how to remove files and directories. The ‘rm’ command is used to delete files, and the ‘rmdir’ command is employed to remove empty directories.

2) Copying and Moving Files: Copying and moving files is essential for organising your work and managing data. The ‘cp’ command is used for copying, while the ‘mv’ command is used for moving files and directories.

a) Copying a File: Use the ‘cp’ command followed by the source and destination paths to copy a file.

Example: $ cp source_file.txt destination/

b) Moving a file: Utilise the ‘mv’ command to move a file from one location to another.

Example: $ mv file.txt new_directory/

3) Renaming Files and Directories: Renaming files and directories can be achieved using the ‘mv’ command. By providing the source name and the desired new name, you can effectively rename items.

a) Renaming a File: Use the ‘mv’ command to rename a file.

Example: $ mv old_name.txt new_name.txt

b) Renaming a Directory: Employ the ‘mv’ command to rename a directory.

Example: $ mv old_directory new_directory_name

Here are some more examples of how you can use them in your coding:

Imagine you want to create a backup copy of a file named "report.txt" and move it to a directory called "backup." Here's how you would execute these actions using Unix commands:

a) Creating a Backup: Use the ‘cp’ command to create a copy of the file.

$ cp report.txt report_backup.txt

b) Moving to a Directory: Use the ‘mv’ command to move the backup file to the "backup" directory.

$ mv report_backup.txt backup/

Trainer Insight

Don’t learn Unix commands only in isolation. Pipes (|) allow the output of one command to become the input of another, making it possible to build useful workflows from simple commands.

Master shell scripting and automate everyday tasks with the UNIX Shell Programming Training. Sign up now!

3) System Information

Unix provides a window into the inner workings of your system. This allows you to gather essential system information and gain insights into its performance. You can monitor and manage your system precisely, from disk usage statistics to memory utilisation. 

1) Command Gems for System Information:

Unix offers a suite of commands tailored to providing insights into your system's status:

a) Disk Free (‘df’): This displays information about disk space utilisation. It also shows the amount of disk space used and available on different file systems.

b) Disk Usage (‘du’): The ‘du’ command calculates the space used by files and directories, enabling you to identify which directories consume the most disk space.

c) top: The ‘top’ command presents real-time system resource usage, including CPU and memory utilisation, running processes, and more.

d) free: On Linux systems, this command offers a snapshot of memory usage, displaying physical and swap memory statistics. Other Unix systems may provide different utilities for viewing memory information.

2) Gathering Disk Usage Information: Knowing how disk space is allocated and utilised is essential for maintaining a healthy system. The ‘df’ and ‘du’ commands are indispensable for this purpose.

a) Viewing Disk Space Usage: Use the ‘df’ command to see disk space information for all mounted file systems.

$ df –h

b) Analysing Directory Usage: Employ the ‘du’ command to determine the space specific directories occupy.

$ du -h /home/user/documents

3) Monitoring System Resources: Unix offers commands to monitor system resources in real-time, helping you identify performance bottlenecks and resource-hungry processes.

a) Real-time System Overview: Run the top command to observe dynamic updates on system resource usage and active processes.

$ top

b) Memory Utilisation: Use the ‘free’ command to display memory statistics.

$ free -h

Exploring the Unix Commands List

Once you understand the basics, a command reference can make it easier to choose the right tool for a task:

Unix Commands List

Understanding Internal and External Commands in Unix

At the core of command-line interactions, Unix helps shape how you interact with your systems.

a) Internal Commands: Internal commands, often referred to as shell built-ins, are commands that the shell can execute directly without launching a separate external program. The exact set of built-ins can vary depending on the shell you use.

Commands such as ‘cd’ need to operate within the current shell so that they can change its working directory. Other utilities, including ‘echo’ and ‘pwd’, are also commonly available as shell built-ins, although external versions may exist on some systems. You can use shell tools such as type or command -V to check how a command is interpreted in your current environment.

b) External Commands: In contrast, external commands are standalone executables outside the shell's code. These commands are stored in separate executable files, often in directories specified by the system's PATH variable. When you enter an external command, the shell searches the appropriate locations to find the executable and then runs it.

The Unix commands list is teeming with external commands, ranging from basic utilities like ‘ls’, ‘grep’, and ‘sed’ to more complex tools for networking, system administration, and text processing. These commands offer a vast toolkit that extends beyond the shell's built-in capabilities, empowering users to tackle various tasks.

Here's a quick glimpse into their differences:

Note: The exact classification can vary by shell and system because some standard utilities may exist both as shell built-ins and as external executables.

Internal vs External Commands in UNIX

Advanced Unix Commands

Advanced Unix commands and Unix-like utilities are the tools of seasoned practitioners, offering sophisticated solutions to complex tasks and transforming the command-line interface into a playground of innovation and efficiency. Availability can vary by operating system, and some of the tools below may need to be installed separately.

1) Text Editors and Process Management:

Advanced Unix Commands often lead professionals to discover powerful text editors like nano and vim. These editors transcend simple text manipulation, offering features like syntax highlighting, search and replace, and even programming environments within the terminal.

Additionally, command-line process management reaches new heights with commands like ‘ps’, ‘kill’, and ‘jobs’. As a seasoned practitioner, you can meticulously monitor processes, terminate specific tasks, and manipulate background jobs, affording greater control over the system's operation.

2) Remote Access and Data Transfer:

Accessing remote systems and transferring data seamlessly is another hallmark of advanced Unix proficiency. Commands like ‘ssh’, secure copy (‘scp’), and ‘rsync’ allow you to connect to remote servers securely, copy files, and synchronise data across networks. This is essential for system administrators, developers, and anyone working in a distributed computing environment.

3) Networking and System Monitoring:

Advanced Unix commands also shine in the domain of networking and system monitoring. Tools such as netstat are still available on many Unix-like systems for viewing network information, while modern Linux systems commonly use alternatives such as ss.

The ping command tests connectivity to hosts, while curl supports data transfers between systems. Additional utilities, such as ‘nmap’, can scan networks to identify active hosts and services where they are installed.

For monitoring, utilities such as ‘htop’ can provide a visually rich view of system resource usage where they are installed. On Linux, tools such as ‘strace’ can trace system calls made by processes, while ‘lsof’ can provide information about files opened by processes. Other Unix systems may provide different tools for similar tasks.

4) Compression, Archiving, and Backup:

Advanced Unix Commands provide tools for archiving, compression, and backup tasks. The ‘tar’ command, combined with options like ‘z’ for ‘gzip’ compression and ‘j’ for ‘bzip2’ compression, allows you to create compressed archives of files and directories. You can automate regular backups to ensure data integrity when paired with the ‘cron’ utility for scheduled tasks.

Trainer Insight

Before running an unfamiliar command on important files or production systems, check its documentation using man, shell help where applicable or supported command-specific help options. Pay particular attention to commands that modify, overwrite or remove data.

Here are Some Examples for You:

Imagine you're a developer tasked with analysing a network-related issue on a remote Linux server. Advanced Unix-like commands come to your rescue:

1) Connecting Securely: Use the ‘ssh’ command to establish a secure remote connection to the server.

$ ssh username@remote_server

2) Checking Network Connections: Employ ‘ss’ to view listening TCP and UDP sockets.

$ ss -tuln

3) Tracing System Calls: Use ‘strace’ to trace the system calls of a specific process and understand its behaviour.

$ strace -p process_id

Beginner to Advanced Learning Path

Beginner: pwd → ls → cd → mkdir → touch
File Management: cp → mv → rm → find
Text Processing: grep → sort → sed → awk
System Management: ps → top → df → du
Advanced Usage: pipes → ssh → scp → rsync → scripting and automation

Make sure you are the sought-after skilled Administrator behind every reliable UNIX system. Sign up for the Administrating UNIX Systems Training now!

Jyoti Tura
Jyoti Tura

Senior Web & UX/UI Manager

Jyoti Tura is a Senior Web & UX/UI Manager with 7+ years of experience in front-end development, web development and user-focused interface design. Her technical expertise and managerial responsibilities support her knowledge across IT and Tech, Leadership and Management.

View Detail icon
cross

Upgrade Your Skills. Save More Today.

superSale Unlock up to 40% off today!

* WHO WILL BE FUNDING THE COURSE?

close

close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.

close

close

Press esc to close

close close

Back to course information

Thank you for your enquiry!

One of our training experts will be in touch shortly to go overy your training requirements.

close close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.