15 Ubuntu Linux Commands Everyone Should Know

As a computer engineer, I’ve spent countless hours navigating the intricacies of Ubuntu Linux. Whether you’re a seasoned developer or a newcomer to the Linux world, mastering the command line is essential. Here are 15 fundamental Ubuntu commands that will enhance your efficiency and deepen your understanding of the system.


ls - List Directory Contents

Description: Displays the files and subdirectories within a directory.

Usage:

ls
ls -l   # Detailed list with permissions, ownership, and size
ls -a   # Includes hidden files (those starting with a dot)

cd - Change Directory

Description: Navigates between directories in the filesystem.

Usage:

cd /path/to/directory   # Move to a specific directory
cd ..                   # Go up one level
cd ~                    # Return to the home directory

pwd - Print Working Directory

Description: Displays the full path of the current directory.

Usage:

pwd

mkdir - Make Directory

Description: Creates a new directory.

Usage:

mkdir new_folder           # Creates 'new_folder' in the current directory
mkdir -p dir1/dir2/dir3    # Creates nested directories in one command

rm - Remove Files or Directories

Description: Deletes files or directories.

Usage:

rm file.txt                # Deletes 'file.txt'
rm -r directory/           # Recursively deletes a directory and its contents
rm -f file.txt             # Forces deletion without prompt

Use with caution, as deleted files may not be recoverable.


cp - Copy Files and Directories

Description: Copies files or directories from one location to another.

Usage:

cp source.txt destination.txt       # Copies 'source.txt' to 'destination.txt'
cp -r source_dir/ destination_dir/  # Recursively copies directories

mv - Move or Rename Files and Directories

Description: Moves or renames files and directories.

Usage:

mv old_name.txt new_name.txt        # Renames a file
mv /path/to/file /new/path/         # Moves file to a new directory

chmod - Change File Permissions

Description: Modifies the read, write, and execute permissions of files and directories.

Usage:

chmod u+x script.sh     # Adds execute permission for the user
chmod 755 script.sh     # Sets permissions using numeric notation

chown - Change File Ownership

Description: Changes the owner and group of files or directories.

Usage:

chown user:group file.txt       # Changes owner and group
sudo chown -R user:group dir/   # Recursively changes ownership in a directory

apt-get - Package Handling Utility

Description: Manages packages on Ubuntu, allowing installation, updates, and removal.

Usage:

sudo apt-get update              # Updates the package list
sudo apt-get upgrade             # Upgrades all upgradable packages
sudo apt-get install package     # Installs a new package

sudo - Execute Command as Superuser

Description: Runs commands with elevated (root) privileges.

Usage:

sudo command        # Executes 'command' with superuser privileges

Essential for administrative tasks that require higher permissions.


grep - Search Text Using Patterns

Description: Searches for specific patterns within files.

Usage:

grep "search_term" file.txt           # Searches for 'search_term' in 'file.txt'
grep -r "search_term" /path/to/dir/   # Recursively searches in a directory

find - Search for Files and Directories

Description: Locates files and directories based on various criteria.

Usage:

find /path/ -name "filename"          # Finds files with a specific name
find . -type f -mtime -1              # Finds files modified in the last day

tar - Archive Utility

Description: Creates and extracts compressed archives.

Usage:

tar -cvf archive.tar /path/to/dir/        # Creates an archive
tar -xvf archive.tar                      # Extracts an archive
tar -czvf archive.tar.gz /path/to/dir/    # Creates a compressed gzip archive

ssh - Secure Shell

Description: Connects to remote machines securely over the network.

Usage:

ssh user@remote_host              # Connects to a remote host
ssh -i /path/to/key user@host     # Uses a specific SSH key for authentication

Conclusion

Mastering these commands will significantly enhance your productivity and capability within the Ubuntu Linux environment. The command line is a powerful tool that, once understood, opens up a world of automation and control. Keep exploring, and don’t hesitate to delve deeper into each command’s manual page using man command_name to uncover even more possibilities.

Happy Coding!