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 + Tsimultaneously. 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:
lslists files and directories in the current location.ls -lpwdprints the current working directory (full path).pwdcdchanges directory.cd /path/to/directorymkdircreates a new directory.mkdir new_directorytouchcreates a new empty file.touch new_file.txtrmremoves/deletes files or directories.rm file.txt rm -r directory/cpcopies files or directories.cp file.txt /path/to/destination/or to copy a directorycp -r directory/ /path/to/destination/mvmoves or renames files/directories.mv file.txt new_location/ormv old_file.txt new_file.txt
- File and Text Manipulation:
catconcatenates and displays the content of a file.cat file.txtmoreorlessview the contents of a file one page at a time.more large_file.txtorless big_log_file.txtheaddisplays the beginning lines of a file.head file.txt head -n 5 file.txttaildisplays the ending lines of a file.tail file.txt tail -n 10 file.txtgrepsearches for a pattern in a file.grep "search_term" file.txtwccounts lines, words, and characters in a file.wc file.txtechoprints a message or a variable’s value.echo "Hello, World!"
- File Permissions:
chmodchanges 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.txtchownchanges file ownership.chown user:group file.txtchgrpchanges group ownership.chgrp new_group file.txt
- Process Management:
psdisplays information about running processes.ps ps aux | grep process_namekillterminates processes by sending signals.kill process_id
- System Information:
- Archiving and Compression:
- User Management:
whodisplays information about currently logged-in users.whowshows who is logged in and what they are doing.wuserslists users currently logged in.usersadduseroruseraddadds a new user.adduser new_user
- Network:
- Command Help and Manuals:
mandisplays the manual page for a command.man ls--helpgets help and usage information for a command.ls --help
- Miscellaneous:
clearclears the terminal screen.clearhistorydisplays a list of recently executed commands.historydatedisplays the current date and time.date- Use
sudo apt updateto update package manager on Debian or Ubuntu - install a package on Ubuntu use
sudo apt install package_nameClick here for list of packages.
Useful Tips
- Tab Completion: You can use the
Tabkey 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, pressingTabtwice 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 + Cto abort a running command,Ctrl + Dto log out (or close the terminal if no process is running), andCtrl + Lto clear the screen. - Permissions: Be cautious when using commands like
rm -ras they can delete files and directories permanently. Also, some commands may require administrative privileges. Usesudobefore such commands, but only when necessary, as they can have significant system-wide effects.
