Linux Basic Commands
Ubuntu uses the Bash shell by default, which provides a range of commands to manage files, navigate directories, and control system settings. Here’s an overview of basic shell commands that are essential for working with Ubuntu.
1. File and Directory Commands
These commands help you manage files and directories on your system.
pwd: Prints the working directory (current location).
Example output:
ls: Lists files and directories in the current directory.
- Use
ls -l
for a long listing format, showing details like permissions, size, and modification date. - Use
ls -a
to show hidden files (those that start with.
).
- Use
cd: Changes the current directory.
cd ..
takes you up one level in the directory tree.cd ~
or simplycd
takes you to your home directory.
mkdir: Creates a new directory.
rmdir: Removes an empty directory.
touch: Creates a new empty file.
cp: Copies files or directories.
- Use
cp -r
to copy directories recursively.
- Use
mv: Moves or renames files and directories.
rm: Removes files or directories.
- Use
rm -r
to remove directories and their contents.
- Use
2. Viewing and Editing Files
These commands help you view and modify the content of files.
cat: Concatenates and displays the content of a file.
less: Allows you to scroll through the contents of a file.
head and tail: Display the beginning or end of a file.
nano: A simple text editor for editing files within the terminal.
3. System Information Commands
These commands give information about your system and its status.
uname: Displays system information.
df: Shows disk space usage for each file system.
du: Displays the disk usage of files and directories.
top: Shows running processes and resource usage in real-time.
ps: Lists currently running processes.
4. Network Commands
These commands help you manage network connections and configurations.
ping: Checks connectivity to a server.
ifconfig (requires root privileges): Displays network interfaces and their configurations.
wget: Downloads files from the internet.
5. Package Management Commands
These commands help you install, update, and manage software on Ubuntu using the APT package manager.
sudo apt update: Updates the package lists for upgrades and new packages.
sudo apt upgrade: Installs the latest versions of all installed packages.
sudo apt install: Installs a new package.
sudo apt remove: Removes an installed package.
6. Permissions Commands
These commands manage file and directory permissions.
chmod: Changes the permissions of a file or directory.
chown: Changes the ownership of a file or directory.
7. Searching Commands
These commands help you locate files and search content within files.
find: Searches for files and directories.
grep: Searches for a string within files.
8. Shortcuts in the Terminal
- Ctrl + C: Stops the currently running command.
- Ctrl + Z: Suspends the current command.
- Tab: Autocompletes the command or file name.
- Ctrl + R: Searches command history.
Summary
These basic shell commands provide foundational skills to navigate, manage files, install software, and monitor the system in Ubuntu. Mastering these commands can help you efficiently perform tasks and troubleshoot in a Linux environment.