49 Most-Used Linux Commands You Should Know.

The Linux command line is a text-based computer interface. It's also known as the Shell, Terminal, Console, CLI, or Prompt, just to name a few. Any graphical user interface (GUI) is nothing more than a graphical representation of command-line applications.

49 Most-Used Linux Commands You Should Know.
Image credit: Unknown. Please contact us if you are the owner.




Using the CLI (Command Line Interface) is the most efficient, most accessible, and clearest way to accomplish nearly any task a computer is capable of performing. Once familiarized it is fairly easy and proficient to work from the terminal and that is why most Linux sysadmins prefer it over the GUI due to its versatility and performance.

There are "infinitely many" Linux commands out there and even longtime users may forget a command every once in a while, and we've thought this post could be in handy to skyrocket your Linux system experience. So if you’re considering using Linux, learning basic command lines will go a long way.

Below, are 49 useful Linux terminal commands our experts think every Linux beginner should know. Even the man command made #10 on our list.

COMMANDS You Should and Must Know

Let's dig into our 49 most-used and must-known Linux commands.
Those commands have many options, so it might be good to get some help by using the --help flag.

1. ls Command

ls is probably the first command every Linux user typed in their terminal. It allows you to list the contents of the directory you want (the current directory by default), including files and other nested directories.
If you want to see the content of other directories, type ls and then the directory’s path.

There are variations you can use with the ls command:

ls -R will list all the files in the sub-directories as well
ls -a will show the hidden files
ls -al will list the files and directories with detailed information like the permissions, size, owner, etc.

2. pwd Command

The pwd command stands for "print working directory", and it outputs the absolute path of the directory you're in.

3. cd Command

It stands for "change directory" and, as its name suggests, switches you to the directory you're trying to access.
There are some shortcuts to help you navigate quickly:

cd .. (with two dots) to move one directory up
cd to go straight to the home folder
cd - (with a hyphen) to move to your previous directory

4. cp Command

Use the cp command to copy files from the current directory to a different directory.

$ cp sample.jpg /home/ratata/pics

For instance, the above command would create a copy of sample.jpg (from your current directory) into the Pics directory.

5. mv Command

The primary use of the mv command is to move files, although it can also be used to rename files. The arguments in mv are similar to the cp command. You need to type mv, the file's name, and the destination’s directory as such:

$ mv file.txt /home/ratata/documents

To rename files:

$ mv oldname.txt newname.txt


6. touch Command

The touch command allows you to create a blank new file.

$ touch /var/www/index.html

The above example will create an HTML file entitled index under the var/www directory.

7. mkdir Command

Use mkdir command to make a new directory —

$ mkdir new_doc

The above command will create a directory called new_doc.

8. rmdir Command

Note
: Be very careful with this command and double-check which directory you are in. This will delete everything and there is no undo.
Use the rmdir command to delete only empty directories.

9. rm Command

Note: Be very careful with this command and double-check which directory you are in. This will delete everything and there is no undo.
The rm command is used to delete directories and the contents within them. If you only want to delete the directory — as an alternative to rmdir — use rm -r.

10. man Command

man displays the manual page of any other command (as long as it has one). To see the manual page of the touchcommand, type: man touch or if you want to refer to the man manual page type: man man

11. locate Command

Use this command to locate a file. Using the -i argument will make it case-insensitive, so you can search for a file even if you can't remember its exact name. To search for a file that contains two or more words, use an asterisk (*).

$ locate -i apple*pie

The above command will search for any file that contains the word "apple" and "pie", whether it is uppercase or lowercase.

12. find Command

Similar to the locate command, using find also searches for files and directories. The difference is, you use the find command to locate files within a given directory.

$ find /home/ -name abc.txt

The above command will search for a file called abc.txt within the home directory and its subdirectories.

Other variations when using the find are:

to find files in the current directory use

$ find . -name abc.txt

to look for directories use

$ find . -type d -name zxc. txt

13. grep Command

Grep is one of the most powerful utilities for working with text files. It searches for lines that match a regular expression and print them.

$ grep planet notepad.txt

It will search for the word planet in the notepad file. Lines that contain the searched word will be displayed fully.

14. chmod Command

chmod is used to change mode of a file; the read, write and execute permissions of files and directories. One of the most common use cases for chmod is to make a file executable by the user as such:

$ chmod +x script


15. chown Command

In Linux, all files are owned by a specific user. The chown command enables you to change or transfer the ownership of a file to the specified username.

$ chown ratata file.txt

The above command makes ratata as the owner of the file.txt.

16. sudo Command

Short for "SuperUser Do", this command enables you to perform tasks that require administrative or root permissions. It’ll ask for the administrator’s password.

17. df Command

Use df command to get a report on the system’s disk space usage, shown in percentage and KBs. If you want to see the report in human-readable, prints sizes in powers of 1024, type df -h.

18. du Command

Curious about how much space a file or a directory takes, the du (Disk Usage) command is the answer. If you want to see it in bytes, kilobytes, and megabytes, add the -h argument to the command line.

19. ps Command

It prints useful information about the programs you’re running, like process ID, TTY (TeleTYpewriter), time, and command name.

$ ps 
  
  PID TTY          TIME CMD
 1397 pts/1    00:00:00 ps
25171 pts/1    00:00:03 zsh

The -aux options tell ps to show processes owned by all users. This is a useful diagnostic tool when you think a process might be running when it shouldn’t be, or that it might be consuming too many resources.

$ ps -aux | grep nginx


20. kill Command

Simply put, kill sends a TERM or kill signal to a process that terminates it.
You can kill processes by entering either the PID (processes ID) or the program’s binary name:

$ kill 134672

$ kill nginx



21. history Command

Can't quite remember a command, history comes in handy. This command displays a list of commands you’ve used in the past.

22. tail Command

tail prints the contents of a file with one major caveat: It only outputs the last lines. By default, it prints the last 10 lines, but you can modify that number with -n.

23. whoami Command

The whoami command (short for "who am i") displays the username currently in use.

24. uname Command

uname(short for "Unix name") prints the operative system information, which comes in handy when you don't know your current Linux version.

25. wget Command

wget (World Wide Web get) is a utility to retrieve content from the internet.

26. head Command

head comamnd outputs the first 10 lines of a text file, but you can set any number of lines you want to display with the -n flag:

27. ping Command

ping is the most popular networking terminal utility used to test network connectivity.

28. apt, yum, pacman Commands

Depend on which Linux distribution you’re using but you need a package managers to install, update, and remove the software you use every day. You can access these package managers through the command line.

29. echo Command

The echo command displays defined text in the terminal — it’s that simple; here displaying our current type of shell.

$ echo $SHELL

/bin/zsh

30. which Command

The which command outputs the full path of shell commands.

$ which htop

/usr/bin/htop


31. passwd Command

passwd allows you to change the passwords of user accounts. First, it prompts you to enter your current password, then asks you for a new password and confirmation.

32. shred Command

This command overrides the contents of a file repeatedly, and as a result, the given file becomes extremely difficult to recover.

$ shred whateverfile.txt

33. unzip Command

The unzip command allows you to extract the content of a .zip file from the terminal.

34. w Command

w command displays who is currently logged in into your machine and what they are doing.

$ w

 19:42:39 up 4 days, 23:54,  3 users,  load average: 0.70, 0.44, 0.44
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
batman    pts/0    192.168.1.123    Mon13   14:23   0.87s  0.87s -zsh
jupiter   pts/1    192.168.1.124    Mon13    1.00s  3.94s  0.02s w
spiderman pts/2    192.168.1.245    Sun18   14:18   2.59s  2.59s -zsh

35. useradd Command

The most common command to create users.

$ sudo useradd new_comer

36. userdel Command

userdel command will look for the system account files such as '/etc/password' and '/etc/group' and then it will delete all entries related to the user name from there.

37. wc Command

wc command counts the number of bytes, characters, words, and lines in a file or in standard input. Below with -l, --lines argument prints the newline counts.

$ wc -l fire.txt

14344418 fire.txt

38. netstat Command

This tool is used to view and monitor network statistics as such network connections, routing tables, interface statistics, masquerade connections, multicast memberships, etc...

to list all network ports:

$ netstat -a

to list TCP and UDP ports

$ netstat -tulpn


39. ufw Command

Uncomplicated Firewall is program for managing a netfilter firewall designed to be easy to use.

$ sudo ufw allow 1040/tcp

40. ssh Command

Use the ssh command to make a connection to a remote Linux computer and log into your account. To make a connection, you must provide your user name and the IP address or domain name of the remote computer.

41. free Command

The free command gives you a summary of the memory usage with your computer. It does this for both the main Random Access Memory (RAM) and swap memory. The -h (human) option is used to provide human-friendly numbers and units.

42. scp Command

scp is a secure copy program to transfer files or directories between Linux hosts on the network. It uses ssh protocol to transfer your data.

$ scp file.txt user@192.168.1.123:/home/ratata/box

43. rsync Command

rsync synchronizes files and directories between local machines to the remote machine. It can recursively copy files and directory, copy symlinks, preserve (permissions, group, modification time and ownership) file identity.

44. mount Command

mount is a command used in Linux to attached filesystems and drives and umount command is used to detach (unmount) any attached file systems or devices.


45. ip Command

The Linux ip command is similar to ifconfig, but more powerful and is intended to be a replacement for it. With ip you have the advantage of performing several network administration tasks with only one command.

46. last Command

last is a command-line utility that displays information about the last login sessions of the system users. It is very useful when you need to track user activity or investigate a possible security breach.

47. watch Command


It is used to run any arbitrary command at regular intervals and displays the output of the command on the terminal window. It is useful when you have to execute a command repeatedly and watch the command output change over time.

$ watch -n 10 df -h

The above example will monitor your disk space usage with the df command and refresh the screen every ten seconds.

48. top Command

Displays the processes of CPU. This command refreshes automatically, by default, and continues to show CPU processes until it's killed.

49. mkfs Command

mkfs command stands for "make file system" is utilized to make a file system (which is, a system for organizing a hierarchy of directories, subdirectories, and files) on a formatted storage device.

$ mkfs.ext4 /dev/sda1 (sda1 block will be formatted)


We've reached our counts, and hope you’ve enjoyed learning more and more about Linux. As with many things in life it can take some time to learn and Linux is no different, you’re going to need some practice before becoming familiar with these commands but once you master some of its tools, it becomes your best ally, and you won’t regret choosing it as your daily driver.

Thanks for checking in, and we hope this was helpful!
SNUBteam!

Keep Us Caffeinated  ⦿ ⦿