Top 50+ Linux Commands You MUST Know | 您所在的位置:网站首页 › 辰声电动车智能充电站怎么样 › Top 50+ Linux Commands You MUST Know |
// Tutorial //Top 50+ Linux Commands You MUST KnowPublished on August 3, 2022UNIX/Linux![]() By e09330e1749e4191a9dfe441e5129f ![]() While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial. Using Linux command on a regular basis? Today we’ll look at 50+ Linux commands you must know! The commands listed below are some of the most useful and most frequently used Linux commands. Let’s get right into it! Deploy your frontend applications from GitHub using DigitalOcean App Platform. Let DigitalOcean focus on scaling your app. Top 50 Linux Commands You Must Know as a Regular User 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 usersNow let’s dive a little deeper into each of these commands and understand them in more detail. We already have a lot of existing articles for each of those individual commands. For your convenience, we’ll add links to all the existing articles, and continue to update the article as new topics are covered. The ls command in LinuxThe ls command is used to list files and directories in the current working directory. This is going to be one of the most frequently used Linux commands you must know of. As you can see in the above image, using the command by itself without any arguments will give us an output with all the files and directories in the directory. The command offers a lot of flexibility in terms of displaying the data in the output. Learn more about the ls command (link to full article) The pwd command in LinuxThe 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. Now, your terminal prompt should usually have the complete directory anyway. But in case it doesn’t, this can be a quick command to see the directory that you’re in. Another application of this command is when creating scripts where this command can allow us to find the directory where the script has been saved. The cd command in LinuxWhile working within the terminal, moving around within directories is pretty much a necessity. The cd command is one of the important Linux commands you must know and it will help you to navigate through directories. Just type cd followed by directory as shown below. root@ubuntu:~# cdAs 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 LinuxThe mkdir command allows you to create directories from within the terminal. The default syntax is mkdir followed by the directory name. root@ubuntu:~# mkdirAs you can see in the above screenshot, we created the JournalDev directory with just this simple command. Learn more about the mkdir command (Link to article) The cp and mv commandsThe cp and mv commands are equivalent to the copy-paste and cut-paste in Windows. But since Linux doesn’t really have a command for renaming files, we also make use of the mv command to rename files and folders. root@ubuntu:~# cpIn the above command, we created a copy of the file named Sample. Let’s see how what happens if we use the mv command in the same manner. For this demonstration, I’ll delete the Sample-Copy file. root@ubuntu:~# mv > ssh username@hostnameLearn more about ssh command(Link to article) The service command in LinuxThe service command in Linux is used for starting and stopping different services within the operating system. The basic syntax of the command is as below. root@ubuntu:~ -->> service ssh status root@ubuntu:~ -->> service ssh stop root@ubuntu:~ -->> service ssh startAs you can see in the image, the ssh server is running on our system. The ps, kill, and killall commandsWhile we’re on the topic of processes, let’s see how we can find active processes and kill them. To find the running processes, we can simply type ps in the terminal prompt and get the list of running processes. root@ubuntu:~ -->> ps root@ubuntu:~ -->> kill root@ubuntu:~ -->> killallFor demonstration purposes, I’m creating a shell script with an infinite loop and will run it in the background. With the use of the & symbol, I can pass a process into the background. As you can see, a new bash process with PID 14490 is created. Now, to kill a process with the kill command, you can type kill followed b the PID of the process. But if you do not know the process ID and just want to kill the process with the name, you can make use of the killall command. You will notice that PID 14490 stayed active. That is because both the times, I killed the sleep process. Learn more about ps command (Link to article). The df and mount commandsWhen working with Linux, the df and mount commands are very efficient utilities to mount filesystems and get details of the file system. When I say mount, it means that we’ll connect the device to a folder so we can access the files from our filesystem. The default syntax to mount a filesystem is below: root@ubuntu:~ -->> mount /dev/cdrom /mnt root@ubuntu:~ -->> df -hIn the above case, /dev/cdrom is the device that needs to be mounted. Usually, a mountable device is found inside the /dev folder. /mnt is the destination folder to mount the device to. You can change it to any folder you want but I’ve used /mnt as it’s pretty much a system default folder for mounting devices. To see the mounted devices and get more information about them, we make use of the df command. Just typing df will give us the data in bytes which is not readable. So we’ll use the -h parameter to make the data human-readable. Learn more about the df command(Link to article) The chmod and chown commandsThe 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. The main difference between the functions of the two commands is that the chmod command allows changing file permissions, while chown allows us to change the file owners. The default syntax for both the commands is chmod filename and chown user:group filename root@ubuntu:~ -->> chmod +x loop.sh root@ubuntu:~ -->> chmod root:root loop.shIn the above example, we’re adding executable permissions to the loop.sh file with the chmod command. Apart from that, with the chown command, we’ve made it accessible only by root user and users within the root group. As you will notice, the root root part is now changed to www-data which is the new user who has full file ownership. Learn more about the chmod command(Link to article) and chown command (Link to article) The ifconfig and traceroute commandsMoving 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. The ifconfig command will give you the list of all the network interfaces along with the IP addresses, MAC addresses and other information about the interface. root@ubuntu:~ -->> ifconfigThere 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:~ -->> tracerouteNow obviously, localhost is just one hop (which is the network interface itself). You can try this same command with any other domain name or IP address to see all the routers that your data packets pass through to reach the destination. Learn more about the ifconfig command(Link to article) The wget command in LinuxIf you want to download a file from within the terminal, the wget command is one of the handiest command-line utilities available. This will be one of the important Linux commands you should know when working with source files. When you specify the link for download, it has to directly be a link to the file. If the file cannot be accessed by the wget command, it will simply download the webpage in HTML format instead of the actual file that you wanted. Let’s try an example. The basic syntax of the wget command is : root@ubuntu:~ -->> wget OR root@ubuntu:~ -->> wget -cThe -c argument allows us to resume an interrupted download. The ufw and iptables commandsUFW and IPTables are firewall interfaces for the Linux Kernel’s netfilter firewall. IPTables directly passes firewall rules to netfilter while UFW configures the rules in IPTables which then sends those rules to netfilter. Why do we need UFW when we have IPTables? Because IPTables is pretty difficult for a newbie. UFW makes things extremely easy. See the below example where we are trying to allow the port 80 for our webserver. root@ubuntu:~# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT root@ubuntu:~# ufw allow 80I’m sure you now know why UFW was created! Look at how easy the syntax becomes. Both these firewalls are very comprehensive and can allow you to create any kind of configuration required for your network. Learn at least the basics of UFW or IPTables firewall as these are the Linux commands you must know. Learn more opening ports on Linux(Link to article) Package Managers in LinuxDifferent 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 Arch and Arch-based distros - pacman -S Red Hat and Red Hat-based distros - yum install Fedora and CentOS - yum installGetting yourself well versed with the package manager of your distribution will make things much easier for you in the long run. So even if you have a GUI based package management tool installed, try an make use of the CLI based tool before you move on to the GUI utility. Add these to your list of Linux commands you must know. The sudo command in Linux“With great power, comes great responsibility” This is the quote that’s displayed when a sudo enabled user(sudoer) first makes use of the sudo command to escalate privileges. This command is equivalent to having logged in as root (based on what permissions you have as a sudoer). non-root-user@ubuntu:~# sudo Password:Just add the word sudo before any command that you need to run with escalated privileges and that’s it. It’s very simple to use, but can also be an added security risk if a malicious user gains access to a sudoer. Learn more about the sudo command (Link to article) The cal command in LinuxEver 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. The cal command displays a well-presented calendar on the terminal. Just enter the word cal on your terminal prompt. root@ubuntu:~# cal root@ubuntu:~# cal May 2019Even though I don’t need it, it’s a really cool addition! I’m sure there are people who are terminal fans and this is a really amazing option for them. The alias commandDo you have some commands that you run very frequently while using the terminal? It could be rm -r or ls -l, or it could be something longer like tar -xvzf. This is one of the productivity-boosting Linux commands you must know. If you know a command that you run very often, it’s time to create an alias. What’s an alias? In simple terms, it’s another name for a command that you’ve defined. root@ubuntu:~# alias lsl="ls -l" OR root@ubuntu:~# alias rmd="rm -r"Now every time you enter lsl or rmd in the terminal, you’ll receive the output that you’d have received if you had used the full commands. The examples here are for really small commands that you can still type by hand every time. But in some situations where a command has too many arguments that you need to type, it’s best to create a shorthand version of the same. Learn more about alias command (LInk to article) The dd command in LinuxThis command was created to convert and copy files from multiple file system formats. In the current day, the command is simply used to create bootable USB for Linux but there still are some things important you can do with the command. For example, if I wanted to back up the entire hard drive as is to another drive, I’ll make use of the dd command. root@ubuntu:~# dd if = /dev/sdb of = /dev/sdaThe if and of arguments stand for input file and output file. The whereis and whatis commandsThe names of the commands make it very clear as to their functionality. But let’s demonstrate their functionality to make things more clear. The whereis command will output the exact location of any command that you type in after the whereis command. root@ubuntu:~# whereis sudo sudo: /usr/bin/sudo /usr/lib/sudo /usr/share/man/man8/sudo.8.gzThe whatis command gives us an explanation of what a command actually is. Similar to the whereis command, you’ll receive the information for any command that you type after the whatis command. root@ubuntu:~# whatis sudo sudo (8) - execute a command as another user The top command in LinuxA few sections earlier, we talked about the ps command. You observed that the ps command will output the active processes and end itself. The top command is like a CLI version of the task manager in Windows. You get a live view of the processes and all the information accompanying those processes like memory usage, CPU usage, etc. To get the top command, all you need to do is type the word top in your terminal. 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/JDThe above command will create a new user named JournalDev with the home directory as /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. For example, if you want to add more groups to the user, you can type in: root@ubuntu:~# usermod JournalDev -a -G sudo, audio, mysqlLearn more on how to create and manage users on Linux (Link to article) The passwd command in LinuxNow 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! Final NoteThis happened to be a very long article but I’m sure will be something you can refer to whenever required. As we add more articles to JournalDev, we will continue to add links to those articles here. We hope this article was useful to you. If you have any questions, feel free to comment down below. Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases. Learn more about us About the authors![]() author Still looking for an answer?Ask a questionSearch for more helpWas this helpful? JournalDevDigitalOcean EmployeeAmazing! Perfect for newbies to Linux! PERFECT! THANK YOU! - Julian JournalDevDigitalOcean EmployeeThank you for your work. - jcag ![]() |
今日新闻 |
推荐新闻 |
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 |