Top 50+ Linux Commands .
Top 50 Linux commands.
- ls — The most frequently used command in Linux to list directories
- pwd — Print working directory command in Linux
- cd — Linux command to navigate through directories
- mkdir — Command used to create directories in Linux
- mv — Move or rename files in Linux
- cp — Similar usage as mv but for copying files in Linux
- rm — Delete files or directories
- touch — Create blank/empty files
- ln — Create symbolic links (shortcuts) to other files
- cat — Display file contents on the terminal
- clear — Clear the terminal display
- echo — Print any text that follows the command
- less — Linux command to display paged outputs in the terminal
- man — Access manual pages for all Linux commands
- uname — Linux command to get basic information about the OS
- whoami — Get the active username
- tar — Command to extract and compress files in Linux
- grep — Search for a string within an output
- head — Return the specified number of lines from the top
- tail — Return the specified number of lines from the bottom
- diff — Find the difference between two files
- cmp — Allows you to check if two files are identical
- comm — Combines the functionality of diff and cmp
- sort — Linux command to sort the content of a file while outputting
- export — Export environment variables in Linux
- zip — Zip files in Linux
- unzip — Unzip files in Linux
- ssh — Secure Shell command in Linux
- service — Linux command to start and stop services
- ps — Display active processes
- kill and killall — Kill active processes by process ID or name
- df — Display disk filesystem information
- mount — Mount file systems in Linux
- chmod — Command to change file permissions
- chown — Command for granting ownership of files or folders
- ifconfig — Display network interfaces and IP addresses
- traceroute — Trace all the network hops to reach the destination
- wget — Direct download files from the internet
- ufw — Firewall command
- iptables — Base firewall for all other firewall utilities to interface with
- apt, pacman, yum, rpm — Package managers depending on the distro
- sudo — Command to escalate privileges in Linux
- cal — View a command-line calendar
- alias — Create custom shortcuts for your regularly used commands
- dd — Majorly used for creating bootable USB sticks
- whereis — Locate the binary, source, and manual pages for a command
- whatis — Find what a command is used for
- top — View active processes live with their system usage
- useradd and usermod — Add new user or change existing users data
- passwd — Create or update passwords for existing users
The ls command in Linux.
The ls command is used to list files and directories in the current working directory.
The pwd command in Linux.
The pwd command allows you to print the current working directory on your terminal. It’s a very basic command and solves its purpose very well.
The cd command in Linux.
While working within the terminal, moving around within directories is pretty much a necessity.
root@ubuntu:~# cd <directory path>
As you can see in the above command, I simply typed cd /etc/ to get into the /etc directory. We used the pwd command to print the current working directory.
The mkdir command in Linux.
The mkdir command allows you to create directories from within the terminal. The default syntax is mkdir followed by the directory name.
root@ubuntu:~# mkdir <folder name>
The cp and mv commands .
The cp and mv commands are equivalent to the copy-paste and cut-paste in Windows.
root@ubuntu:~# cp <source> <destination>
In the above command, we created a copy of the file named Sample.
root@ubuntu:~# mv <source> <destination
In the previous section, we deleted the Sample-Copy file. The rm command is used to delete files and folders and is one of the important Linux commands you must know.
root@ubuntu:~# rm <file name>
root@ubuntu:~# rm -r <folder/directory name>
root@ubuntu:~# touch <file name>
The ln command in Linux.
To create a link to another file, we use the ln command. This is one of the important
root@ubuntu:~# ln -s <source path> <link name>
The cat, echo ,and less commands.
When you want to output the contents of a file, or print anything to the terminal output, we make use of the cat or echo commands.
root@ubuntu:~# cat <file name>
root@ubuntu:~# echo <Text to print on terminal>
As you can see in the above example, the cat command when used on our “New-File”, prints the contents of the file. At the same time, when we use echo command, it simply prints whatever follows after the command.
root@ubuntu:~# cat /boot/grub/grub.cfg | less
The man command in Linux.
The man command is a very useful Linux command you must know.
root@ubuntu:~# man <command>
The name & whoami commands.
The uname and whoami commands allow you to know some basic information which comes really handy when you work on multiple systems.
root@ubuntu:~# uname -a
The tar, zip and unzip commands.
The tar command in Linux is used to create and extract archived files in Linux.
root@ubuntu:~# zip <archive name> <file names separated by space>
root@ubuntu:~# unzip <archive name>
The grep command in Linux.
If you wish to search for a specific string within an output, the grep command comes into the picture.
root@ubuntu:~# <Any command with output> | grep "<string to find>"
the head and tail commands.
When outputting large files, the head and the tail commands come in handy. I’ve created a file named “Words” with a lot of words arranged alphabetically in it.
root@ubuntu:~# head <file name>
root@ubuntu:~# tail <file name>
As you can see, the head command showed 10 lines from the top of the file.
The tail command outputted the bottom 10 lines from the file.
The diff, comm,and cmp commands.
Linux offers multiple commands to compare files. The diff, comm, and cmp commands compare differences and are some of the most useful
root@ubuntu:~# diff <file 1> <file 2>
root@ubuntu:~# cmp <file 1> <file 2>
root@ubuntu:~# comm <file 1> <file2>
The sort command in Linux.
The sort command will provide a sorted output of the contents of a file.
root@ubuntu:~# sort <filename>
The export command in Linux.
The export command is specially used when exporting environment variables in runtime.
root@ubuntu:~# export <variable name>=<value>
The ssh command in Linux.
The ssh command allows us to connect to an external machine on the network with the use of the ssh protocol. The basic syntax of the ssh command is:
root@ubuntu:~ -->> ssh username@hostname
The service command in linux.
The service command in Linux is used for starting and stopping different services within the operating system.
root@ubuntu:~ -->> service ssh status
root@ubuntu:~ -->> service ssh stop
root@ubuntu:~ -->> service ssh start
The ps, kill, and killall command.
While we’re on the topic of processes, let’s see how we can find active processes and kill them.
root@ubuntu:~ -->> ps
root@ubuntu:~ -->> kill <process ID>
root@ubuntu:~ -->> killall <process name>
The df and mount command.
When working with Linux, the df and mount commands are very efficient utilities to mount filesystems and get details of the file system.
root@ubuntu:~ -->> mount /dev/cdrom /mnt
root@ubuntu:~ -->> df -h
In the above case, /dev/cdrom is the device that needs to be mounted.
The chmod and chown command.
The chmod and chown commands give us the functionality to change the file permissions and file ownership are the most important Linux commands you should know.
root@ubuntu:~ -->> chmod +x loop.sh
root@ubuntu:~ -->> chmod root:root loop.sh
The ifconfig and traceroute command.
Moving on to the networking section in Linux, we come across the ifconfig and traceroute commands which will be frequently used if you manage a network.
root@ubuntu:~ -->> ifconfig
There are multiple parameters that can be used but we’ll work with the basic command here.
When working with traceroute, you can simply specify the IP address, the hostname or the domain name of the endpoint.
root@ubuntu:~ -->> traceroute <destination address>
The wget command in Linux.
If you want to download a file from within the terminal, the wget command is one of the handiest command-line utilities available.
root@ubuntu:~ -->> wget <link to file>
OR
root@ubuntu:~ -->> wget -c <link to file>
The Ufw and Iptable commands
UFW and IPTables are firewall interfaces for the Linux Kernel’s netfilter firewall.
root@ubuntu:~# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
root@ubuntu:~# ufw allow 80
Package Managers in Linux
Different distros of Linux make use of different package managers. Since we’re working on a Ubuntu server, we have the apt package manager. But for someone working on a Fedora, Red Hat, Arch, or Centos machine, the package manager will be different.
- Debian and Debian-based distros — apt install <package name>
- Arch and Arch-based distros — pacman -S <package name>
- Red Hat and Red Hat-based distros — yum install <package name>
- Fedora and CentOS — yum install <package>
The sudo command in Linux.
This is the quote that’s displayed when a sudo enabled user(sudoer) first makes use of the sudo command to escalate privileges.
non-root-user@ubuntu:~# sudo <command you want to run>
Password:
Just add the word sudo before any command that you need to run with escalated privileges and that’s it.
The cal command in linux.
Ever wanted to view the calendar in the terminal? Me neither! But there apparently are people who wanted it to happen and well here it is.
root@ubuntu:~# cal
root@ubuntu:~# cal May 2019
The alias command.
Do you have some commands that you run very frequently while using the terminal?
root@ubuntu:~# alias lsl="ls -l"
OR
root@ubuntu:~# alias rmd="rm -r"
The dd command in Linux.
This command was created to convert and copy files from multiple file system formats.
root@ubuntu:~# dd if = /dev/sdb of = /dev/sda
The if and of arguments stand for input file and output file.
The whereis and whatis command.
The names of the commands make it very clear as to their functionality. But let’s demonstrate their functionality to make things more clear.
root@ubuntu:~# whatis sudo
sudo (8) - execute a command as another user
The top command in Linux.
A few sections earlier, we talked about the ps command. You observed that the ps command will output the active processes and end itself.
The useradd and usermod command.
The useradd or adduser commands are the exact same commands where adduser is just a symbolic link to the useradd command. This command allows us to create a new user in Linux.
root@ubuntu:~# useradd JournalDev -d /home/JD
The usermod command, on the other hand, is used to modify existing users. You can modify any value of the user including the groups, the permissions, etc.
root@ubuntu:~# usermod JournalDev -a -G sudo, audio, mysql
The Passwd Command in Linux.
Now that you know how to create new users, let’s also set the password for them. The passwd command lets you set the password for your own account, or if you have the permissions, set the password for other accounts.
The command usage is pretty simple:
root@ubuntu:~# passwd
New password:
If you add the username after passwd, you can set passwords for other users. Enter the new password twice and you’re done. That’s it! You will have a new password set for the user!