
Linux Commands Tutorial, Welcome to the Ultimate Linux Commands Tutorial! In this comprehensive guide, you will learn essential Linux commands, from primary navigation to advanced system management. Whether you’re new to Linux or looking to enhance your command-line skills, this tutorial is designed to help you become proficient in using the Linux terminal
- Linux Commands Tutorial
- What is Linux?
- Why Use the Command Line?
- Basic Command Structure
- pwd
- ls
- cd
- touch
- mkdir
- cp
- mv
- rm
- cat
- more and less
- head and tail
- grep
- find
- chmod
- `chown
- chgrp
- ps
- kill
- top and htop
- > and >>
- <
- |
- tar
- gzip and gunzip
- uname
- df and du
- free
- shutdown and reboot
- ping
- ifconfig and ip
- ssh
- useradd and userdel
- passwd
- groupadd and groupdel
- nano, vim, and emacs
Linux Commands Tutorial
1. Introduction to Linux Commands
What is Linux?
Linux is an open-source operating system kernel that forms the basis of many popular operating systems (e.g., Ubuntu, CentOS, and Debian). It is known for its stability, security, and flexibility.
Why Use the Command Line?
The command line provides direct access to a Linux system’s core functionalities. It offers advantages like automation, remote management, and fine-grained control over your system.
Basic Command Structure
Linux commands typically follow this structure:
command [options] [arguments]command: The command you want to execute.options: Optional flags that modify the command’s behavior.arguments: Input values or file names that the command acts upon.
2. Navigating the File System
pwd
Syntax: pwd
Description: Prints the current working directory.
Example:
$ pwd
/home/usernamels
Syntax: ls [options] [directory]
Description: Lists files and directories in the specified directory.
Example:
$ ls
file1.txt file2.txt directory1 directory2cd
Syntax: cd [directory]
Description: Changes the current working directory.
Example:
$ cd /path/to/directory3. Working with Files and Directories
touch
Syntax: touch <filename>
Description: Create an empty file with the specified name.
Example:
$ touch newfile.txtmkdir
Syntax: mkdir <directoryname>
Description: Creates a new directory with the given name.
Example:
$ mkdir newdircp
Syntax: cp [options] <source> <destination>
Description: Copies files or directories from the source to the destination.
Example:
$ cp file1.txt /path/to/destination/mv
Syntax: mv <source> <destination>
Description: Moves or renames files or directories.
Example:
$ mv oldfile.txt newfile.txt
$ mv file1.txt /path/to/new/location/rm
Syntax: rm [options] <filename/directory>
Description: Removes files or directories.
Example:
$ rm unwantedfile.txt
$ rm -r directorytoremove/4. File Viewing and Manipulation
cat
Syntax: cat <filename>
Description: Concatenates and displays the contents of a file.
Example:
$ cat myfile.txtmore and less
Syntax: more <filename> / less <filename>
Description: View file contents page by page.
Example:
$ more largefile.txt
$ less hugefile.loghead and tail
Syntax: head [options] <filename> / tail [options] <filename>
Description: View the beginning or end of a file.
Example:
$ head -n 10 myfile.txt # Display the first 10 lines
$ tail -f log.txt # Display the end of a file and follow updatesgrep
Syntax: grep [options] <pattern> <filename>
Description: Search for text patterns in files.
Example:
$ grep "error" log.txtfind
Syntax: find <directory> [options] -name <filename>
Description: Search for files and directories in a specified directory.
Example:
$ find /path/to/search -name "*.txt"5. File Permissions and Ownership
chmod
Syntax: chmod [options] <permissions> <filename>
Description: Change file permissions.
Example:
$ chmod 644 myfile.txt # Give read and write permission to the owner, read-only to others`chown
`
Syntax: chown [options] <newowner>:<newgroup> <filename>
Description: Change file ownership.
Example:
$ chown user1:group1 myfile.txtchgrp
Syntax: chgrp [options] <newgroup> <filename>
Description: Change group ownership of a file.
Example:
$ chgrp group2 myfile.txt6. Working with Processes
ps
Syntax: ps [options]
Description: View information about running processes.
Example:
$ ps auxkill
Syntax: kill [options] <process_id>
Description: Terminate processes by their process ID (PID).
Example:
$ kill 1234top and htop
Description: Monitor system activity, including CPU, memory usage, and running processes.
Example:
$ top7. Redirection and Pipes
> and >>
Description: Redirect command output to files. > overwrites, >> appends.
Example:
$ ls > filelist.txt
$ echo "Hello, World!" >> greetings.txt<
Description: Redirect input from files.
Example:
$ cat < input.txt|
Description: Pipe command output to another command.
Example:
$ cat myfile.txt | grep "pattern"8. File Archiving and Compression
tar
Syntax: tar [options] <archive_name>.tar <files/directories>
Description: Archive files and directories into a tarball.
Example:
$ tar -cvf archive.tar file1.txt file2.txt directory1/gzip and gunzip
Syntax: gzip [options] <filename> / gunzip [options] <filename>
Description: Compress and decompress files using gzip compression.
Example:
$ gzip myfile.txt
$ gunzip myfile.txt.gz9. System Information and Management
uname
Syntax: uname [options]
Description: Display system information such as the kernel name and version.
Example:
$ uname -adf and du
Syntax: df [options] / du [options] <directory>
Description: Check disk usage for filesystems or directories.
Example:
$ df -h
$ du -sh /path/to/directoryfree
Syntax: free [options]
Description: Display free and used memory in the system.
Example:
$ free -mshutdown and reboot
Syntax: shutdown [options] / reboot [options]
Description: Shutdown or reboot the system.
Example:
$ shutdown -h now # Shutdown immediately
$ reboot # Reboot the system10. Networking and Connectivity
ping
Syntax: ping [options] <hostname/IP>
Description: Check network connectivity to a host.
Example:
$ ping google.comifconfig and ip
Syntax: ifconfig [interface] / ip [options] <object>
Description: Network configuration and display information about network interfaces.
Example:
$ ifconfig
$ ip address showssh
Syntax: ssh [options] <username>@<hostname>
Description: Securely log in to a remote system using SSH.
Example:
$ ssh username@remote-server.com11. User and Group Management
Linux Commands Tutorial
useradd and userdel
Syntax: useradd [options] <username> / userdel [options] <username>
Description: Create and delete user accounts.
Example:
$ useradd newuser
$ userdel olduserpasswd
Syntax: passwd [options] <username>
Description: Change user passwords.
Example:
$ passwd myusergroupadd and groupdel
Syntax: groupadd [options] <groupname> / groupdel [options] <groupname>
Description: Create and delete groups.
Example:
$ groupadd mygroup
$ groupdel oldgroup12. Linux Commands Tutorial | Text Editing
nano, vim, and emacs
Description: Popular text editors for creating and editing text files.
Example:
$ nano myfile.txt
$ vim myfile.txt
$ emacs myfile.txt13. Linux Commands Tutorial | Shell Scripting Basics
Learn the basics of shell scripting to automate tasks and perform more advanced operations. Create shell scripts using your preferred text editor and execute them in the terminal.
Linux Commands Tutorial | Conclusion
Congratulations! You’ve completed the Ultimate Linux Commands Tutorial. With these commands and concepts, you’ll be able to navigate the Linux file system, manage files and processes, configure your system, and perform various tasks efficiently using the command line. Happy Linux command-line learning!