The Linux terminal, also known as the command line or shell, is a powerful tool for interacting with your operating system. It allows you to perform various tasks, manage files and directories, and run programs using text commands. Though it might seem intimidating at first, learning to use the terminal can greatly enhance your productivity and give you more control over your system.
Accessing the Terminal
To open the terminal, you usually have a few options:
- Using Keyboard Shortcut: Press
Ctrl + Alt + T
simultaneously. This is the default shortcut in many Linux distributions. - Using the Application Launcher: Click on the Application Launcher icon (commonly represented by a grid or a symbol with four squares) and search for “Terminal.”
- Using Right-Click Menu: Right-click on the desktop or in a folder and select “Open in Terminal” or similar option.
Basic Commands
When you open the terminal, you’ll see a command prompt, which typically displays your username, hostname, and the current directory. After the prompt, you can enter commands and press Enter
to execute them. Here are some fundamental commands to get you started:
- File and Directory Navigation:
ls
lists files and directories in the current location.ls -l
pwd
prints the current working directory (full path).pwd
cd
changes directory.cd /path/to/directory
mkdir
creates a new directory.mkdir new_directory
touch
creates a new empty file.touch new_file.txt
rm
removes/deletes files or directories.rm file.txt rm -r directory/
cp
copies files or directories.cp file.txt /path/to/destination/
or to copy a directorycp -r directory/ /path/to/destination/
mv
moves or renames files/directories.mv file.txt new_location/
ormv old_file.txt new_file.txt
- File and Text Manipulation:
cat
concatenates and displays the content of a file.cat file.txt
more
orless
view the contents of a file one page at a time.more large_file.txt
orless big_log_file.txt
head
displays the beginning lines of a file.head file.txt head -n 5 file.txt
tail
displays the ending lines of a file.tail file.txt tail -n 10 file.txt
grep
searches for a pattern in a file.grep "search_term" file.txt
wc
counts lines, words, and characters in a file.wc file.txt
echo
prints a message or a variable’s value.echo "Hello, World!"
- File Permissions:
chmod
changes file permissions. Each permission uses 3 bits for each group: Read Write Execute.
Owner-111 (7 in decimal) Group-101 (5 in decimal) Others-101 (5 in decimal)chmod 755 file.txt
chown
changes file ownership.chown user:group file.txt
chgrp
changes group ownership.chgrp new_group file.txt
- Process Management:
ps
displays information about running processes.ps ps aux | grep process_name
kill
terminates processes by sending signals.kill process_id
- System Information:
- Archiving and Compression:
- User Management:
who
displays information about currently logged-in users.who
w
shows who is logged in and what they are doing.w
users
lists users currently logged in.users
adduser
oruseradd
adds a new user.adduser new_user
- Network:
- Command Help and Manuals:
man
displays the manual page for a command.man ls
--help
gets help and usage information for a command.ls --help
- Miscellaneous:
clear
clears the terminal screen.clear
history
displays a list of recently executed commands.history
date
displays the current date and time.date
- Use
sudo apt update
to update package manager on Debian or Ubuntu - install a package on Ubuntu use
sudo apt install package_name
Click here for list of packages.
Useful Tips
- Tab Completion: You can use the
Tab
key to auto-complete commands and file/directory names. If you type part of a command or name and pressTab
, the terminal will try to fill in the rest automatically. If there are multiple matches, pressingTab
twice will show all available options. - Command History: Use the up and down arrow keys to navigate through your command history. This way, you can quickly access previously used commands without retyping them.
- Keyboard Shortcuts: Some essential keyboard shortcuts in the terminal include
Ctrl + C
to abort a running command,Ctrl + D
to log out (or close the terminal if no process is running), andCtrl + L
to clear the screen. - Permissions: Be cautious when using commands like
rm -r
as they can delete files and directories permanently. Also, some commands may require administrative privileges. Usesudo
before such commands, but only when necessary, as they can have significant system-wide effects.