Table of Contents
Linux is a top-rated platform on the internet. Linux is a free and open-source operating system, meaning anyone can use, modify, and distribute it without cost or restrictions.
It powers many devices and systems, including personal computers, servers, supercomputers, smartphones (Android), and embedded devices.
As per the stats, nearly 97% of websites on the internet use Linux servers and 55.9% of professional developers depend upon Linux for their professional needs.
Next,
Linux also has shortcuts! Yes, you heard it right.
Those shortcuts help to end the task quickly. Linux consists of commands and one or two words that perform various operations in no time. In this article, we will mention the handpicked list of Linux Commands.
So, it’s time to hit the road!
Linux commands provide you control over the system from the command line interface (CLI) instead of using a mouse or trackpad. They are text instructions written into the terminal to inform your system exactly what to do.
The commands you mentioned on the Linux terminal are case–sensitive and follow a syntax like “command – options arguments.” You can combine those commands for complex tasks using pipelines and redirection.
Check below a few key things to understand the Linux Commands:
If you’re a programmer and want to learn coding then you start practicing Linux commands without leaving Windows using the Windows Subsystem for Linux.
You can operate Linux within Windows without dual booting and get the best of both operating systems.
This is a common task on the Linux command line.
Syntax: ls [options] [directory]
Options in ls:
ls -l: Shows detailed information about files and directories, including permissions, owner, size, and modification date.
ls -a: Shows hidden files (those starting with a dot).
Syntax: cd [directory]
Options:
cd ~: Goes to your home directory.
cd ..: Goes up one directory level.
cd ~/pictures – Allow to move into the pictures folder in the home directory of the user you currently logged in with.
Syntax: mkdir [options] <directory>
Options:
mkdir -p: Creates parent directories if they don’t exist.
Syntax: rmdir [options] <directory>
Options:
-v: Verbose output when deleting directories
-p: Remove main directories recursively as per need.
Syntax: cp [options] source destination
Options:
cp -r: Copies directories recursively (including all subdirectories and files).
Syntax: cp -r /home/user/documents /backups/
Syntax: mv [options] source destination
Options:
-i: Check before overwriting any existing files at the destination location. This eliminates overwriting of data mistakenly done.
-v: Outgrow verbose output displays each file or directory as it’s moved. This is useful for approving the exact moved file.
Syntax: rm [options] name
Options:
rm -r: Deletes directories recursively (use with caution!).
rm -f: Forces deletion without prompting for confirmation.
Syntax: cat (older file name) > (newer file name)
Options:
–show-all, -A: It is the same as -vET.
–number-nonblank, -b: It tells the total non-empty output lines. Also, it overrides -n.
-e: It is the same as -vE.
–show-ends, -E: It displays the $ symbol at the completion of all lines.
Syntax: less [option] [name or location of the file]
Options:
-E – It auto exits at the end of the file.
-f – It forces non–regular files to be opened
-F – Exit if the entire file can be shown on the first screen
-g – Showcase the string that was found by the last search command.
Syntax: head [option] file_name
Options:
-n – display a specific number of lines
-c – display a specific number of bytes
-v – display the file name tag
-q – avoid separating the content of various files with a file name tag
Syntax: tail [+ -[number] [lbcr] ] [file]
Options:
-l, -b or -c
Syntax: find [path] [criteria]
Options:
-type f – Look for only normal files, eliminate directories.
-mtime +30 – Look for the file’s modification over 30 days ago.
-user jane – Look for files belonging to user “jane.”
syntax: du [options] [path]
Options:
-h – Shows file sizes in a readable way to humans in a format like K for Kilobytes rather than a byte count.
-s – Only display the total size for a directory, rather than listing each subdirectory and file.
-a – Highlight solo file sizes in addition to totals. Useful to locate large files.
Syntax: touch [options] file_name
Options
-a – alter the access time only
-c – file creation is suppressed if the file doesn’t exist
-d – Sets access and modification times with the help of specified STRING.
-m – changes modification time
-r – uses the access and modification times from the reference file
Syntax: chmod permission filename
Next in the list are search and filter commands that help you to alter and manipulate text right from the Linux command line.
17)grep: Filters text files for lines matching a specified pattern, case-sensitive by default.
Example: grep “error” log.txt (searches for “error” within log.txt)
Syntax: grep [options] pattern [files]
Options:
-i- Passover case distinctions in patterns
-R- Repetitively look for subdirectories
-c- Print only a count of matching lines
-v- reverse match, print non–matching lines
Example: sed ‘s/old/new/g’ file.txt (replaces “old” with “new” throughout file.txt)
syntax: sed options ‘commands’ input-file
Some beneficial sed commands:
s – Search and replace text
/pattern/d – Delete lines matching a pattern
10,20d – Delete lines 10-20
1,3!d – Delete all except lines 1-3
Syntax: awk ‘pattern {action}’ input-file
Advanced awk capabilities:
Allow to compute fields mathematically
Conditional statements
Develop functions for manipulating strings, numbers, and dates
Output formatting control
Syntax: sort [options] [file]
Useful sort options:
-n – Sort numerically instead of alphabetically
-r – Reverse the sort order
-k – Sort based on a specific field or column
Syntax: uniq [options] [input]
Options:
-c – Ending unique lines with the count of occurrences.
-d- showcase the duplicate lines
Syntax: wc [options] [file]
Options:
-l – Print only the line count.
-w – Print only the word count.
-c – Print only the byte count.
Archiving commands help you to bundle various files and directories into compressed archive files for easy portability and storage. Usual archive formats in Linux include .tar, .gz, and .zip
Features:
tar is the most versatile archiving command in Linux, capable of creating, extracting, listing, and modifying archives.
gzip and bzip2 are compression utilities often used in conjunction with tar to create compressed archives.
zip is a popular cross-platform archive format, often used for Windows compatibility.
rar is a proprietary format with higher compression ratios but is less common in Linux environments.
Choose the appropriate command based on the desired compression level, compatibility requirements, and personal preferences.
Syntax:
tar [options] filename
Useful tar options
-c – Develop a new .tar archive file.
-x – Extract files from a .tar archive.
-f – Tells archive filename rather than stdin/stdout.
-v – Verbose output showing archived files.
-z – Compress or uncompress the archive with gzip.
Syntax: unzip archive.zip
It is the same as gunzip, the unzip command extracts and uncompresses the files from the .zip archives.
Syntax: zip [options] archive.zip filenames
Options:
-r – Repetitively zip a directory
-e – Encrypt content with a strong password
The file transfer command helps you to move files between systems over a network. It’s beneficial for moving the files to remote servers or downloading the content from the internet.
Scp syntax copies files from a source path to a defined destination as user@host:
scp source user@host:destination
Example: scp file.txt user@remote_host:/home/user
Syntax: rsync [options] source destination
options
-a – Archive mode syncs repe
Archive mode syncs repetitively and holds permissions, times, etc.
-h – Human-readable output.
-v – Verbose output
Example: rsync -a /source/directory /destination/directory
Example: curl -o file.zip https://example.com/file.zip
Options:
-o – write output to file
-I – display response headers only
– L – follow rediects
It’s developed to transfer data across the network programmatically.
Example: wget https://example.com/file.zip
Options:
-c – resume interrupted download
-r – continuous downloading
-o – save to a particular filename
wget is suitable for automatic downloads and mirroring websites.
Example: sftp user@remote_host
It connects to the host to accept the commands like:
sftp user@host
get remotefile localfile
put localfile remotefile
It redeems the remotefile from the server and copies localfile to the remote host. Sftp has an interactive shell for moving the file systems, transferring files and directories, and managing the permissions and properties.
The chown command changes ownership of a file or directory. Ownership includes two components – the user who is the owner, and the group it belongs to.
Example:
chown steav:developers file.txt
The above-mentioned example will set the owner user to “steav” and the owner group to “developers”. Only the root superuser account is able to use Chown to monitor the file owners. It’s used to fix permission problems by monitoring the owner and group as per need.
This command controls the default permissions given to newly created files. It takes an octal mask as input that substracts from 666 for files and 777 for directories.
Example:
Umask 007
New files permission is default 750 instead of 666, and new directories to 700 instead of 777. Setting an unmask allows you to configure default file permissions rather than relying on system defaults. The umask command is beneficial for restricting permissions on new files without relying on someone’s guide and manually adding restrictions.
This command is beneficial to alter the access permissions or modes of files and directories. The permission modes inform who can read, write, or execute the file.
Example:
chmod 755 file.txt
These are three sets of permissions – owner, group, and public. Permissions are set using numeric modes from 0 to 7:
7 – read, write, and execute.
6 – read and write.
4 – read only.
0 – no permission.
You can set owner permissions to 7 (rwx), group to 5 (r-x), and public to 5 (r – x). You can also reference users and groups symbolically.
Chmod g+w file.text
The g+w syntax adds group write permission to the file.
Making a proper setting of file and directory permissions is important for Linux security and controlling access. Chmod leads to flexible control to configure permissions precisely as per the need.
Redirection is a powerful feature in Linux that allows you to change the standard input (stdin) and standard output (stdout) of commands. This means you can send the output of a command to a file, read input from a file instead of the keyboard, or even pipe the output of one command to the input of another command.
Example: ls -l > file_list.txt saves the output of ls -l to file_list.txt.
This will execute ls -l
to list the contents of the /home directory.
Then, instead of printing that output to the terminal, the > symbol captures that standard output and writes t to homelist.txt, overwriting any existing file contents.
Redirecting standard output is beneficial for saving command results to files for storage, debugging, or chaining commands together.
Example: echo “New text” >> file_list.txt adds “New text” to the end of file_list.txt.
This will append the last 10 lines of the syslog log file onto the end of logfile.txt. Unlike >, >> adds the output without erasing the current logfile .txt contents.
Appending is useful in gathering command output in one place without losing existing data.
Example: grep “error” < logfile.txt searches for “error” within logfile.txt.
The < redirection operator feeds a file’s contents as standard input to a command rather than taking input from the keyboard. Redirecting input is beneficial for batch–processing files and automating workflows.
Example: ls -l | less displays the output of ls -l in the less pager for easier viewing.
This pipe the output of ls -l into the less command where you can scroll via file listing. Piping is beneficial to chain together commands where the output of one feed the input of another. Further, developing the complex operations out of smaller single – purpose programs.
ps aux shows detailed information about all running processes.
For example:
ps aux
Options: aux – display processes for all users
–forest – shows tree of parent/child processes
ps gives you the flexibility to check what is going on in your system.
Useful for monitoring system performance and identifying resource-intensive processes.
For example:
top -u mysql
The above command checks the processes just for the “mysql” user. It’s beneficial for identifying resource-intensive programs.
It gives the signal to a process to terminate or kill it. Signals allow easy shutdown if the process handles them.
For example:
kill -11 12345
The above command sends the SIGTERM (11) signal to stop the process with PID 12345 smoothly.
For example:
pkill -9 firefox
It ends all firefox processes with SIGKILL (9). It targets operations by making equal name, user, and other criteria than PID.
Example: useradd della creates a user named “della” with default settings.
Use options to specify the home directory, shell, password expiration, etc.
Examples: usermod -l new_name old_name changes the username.
usermod -d /home/new_home john changes the home directory.
usermod -aG group1,group2 john adds the user to multiple groups.
usermod -L john locks the account (prevents login).
usermod -U john unlocks the account.
This forces the removal of user “della”, and also deletes the files.
Identifying options like -r and -f with userdel leads the user account to delete even if the user is logged in or has active operations.
Example: groupadd developers create a group named “developers”.
Options:
-r – develop a system group used for core system functions.
-g – Specify the new group’s GID instead of using the next available.
The above command creates a new “sysadmin” group with system privileges. When creating new groups, the -r or -g allows it to be set up correctly.
The passwd command sets or updates a user’s authentication password/tokens. This allows you to alter the login password.
For example:
passwd della
This prompts user “della” to enter a new password mutually. If you’ve forgot the password for an account then you can login to Linux with sudo or su privileges and change the password using the similar method.
Options:
-c [count] – limit packets sent
-i – [interval] – wait interval seconds between pings
In the above command, you ping google.com and output round–trip stats informing connectivity and latency. Generally, ping is useful to check if the system you’re trying to connect to is working and connected to the network.
Example:
ifconfig interface_name IP_address interface_name – name of the network interface.
IP_address – IP address that is assigned to the network interface.
Using ifconfig with no other arguments will give you a list of all the network interfaces that are available to use, along with IP and extra network information. ifconfig can be used to set addresses, enable / disable interfaces, and changes options.
For example:
netstat -pt tcp
This command will generate all the active TCP connections and the processes that are using them.
For example:
traceroute google.com
This monitors the path to connect google.com and generates each network hop.
This helps you to configure Linux netfilter firewall rules to check and process network packets. It develops policies and rules for how to handle the system in a different type of inbound and outbound connections and traffic.
For example:
iptables -A INPUT -s IP address -j DROP
The above command will block all input from IP
It offers superior control over the Linux kernel firewall to monitor routing, NAT, packet filtering, and other traffic control. It’s an important tool for protecting Linux servers.
Wrapping Up
Elevate your Linux game with these 50 beginner commands.
Our new blog post is all about Linux commands for beginners. Whether you’re looking to automate tasks, navigate directories, or manage files, these commands will help you get the job done.
Due to growing digitalization, Email Communication has become the backbone of professional interactions. Yet, surprisingly, many professionals struggle to craft…
As the digital landscape continues to evolve, securing your website has never been more crucial. SSL, or Secure Sockets Layer,…
As a web designer and web developer your experience must have reached to new height, right? Further, you need to…
In today's digital landscape, timing is everything. Whether you're a social media manager, business owner, or content creator, the success…
Are you a website owner? Maintaining the website is the prime concern for any website owner. Yes, it’s equally important…