The Linux desktop environment has evolved into amazingly user-friendly, graphical and powerful tools. Not so for...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
the Linux server.
A system administrator must have a strong grasp of the Linux command line. There's a long commands list, but these top Linux commands are of immediate importance to the administration of servers and data centers.
Each command has a different purpose and should immediately go into the admin's toolkit. As you gain experience with using commands on Linux servers, you'll discover new ways to move around or shorten tasks with the command line; some of these tricks are included here.
The cd command should really be considered part of starting out with Linux server administration. The cd command moves an admin about the directory structure. For example, to move from your home directory to the ~/Downloads directory, you would issue the command cd ~/Downloads. If you're already in your home directory, you could just enter cd Downloads.
The cd command is helpful when you need to back out of a directory. For example, you are in Downloads, and you want to back out to ~/. Simply issue the command cd ../ to back up one directory. You can back out of multiple directories by adding more ../. For example, if you're working within ~/Downloads/A/B/C, you could return to ~/Downloads with the command cd ../../../.
This is a top Linux command for server admins because it allows you to copy files and directories. The usage is as following:
cp [OPTION] source destination
To copy ~/FILEA to ~/Downloads/, you would issue the command cp ~/FILEA ~/Downloads. You can also rename the file as you copy it: To copy ~/FILEA to ~/Downloads, but rename it FILEB, you would issue the command cp ~/FILEA ~/Downloads/FILEB.
One of the more important options for the cp command is the -p option. This option preserves the file attributes such as mode, ownership and timestamps. Issue the command as cp -p ~/FILEA ~/Downloads/FILEB to take advantage of this option.
The Linux crontab command allows an administrator to set up scheduled tasks on a system. The command is used as such:
crontab -u USER file
crontab -u USER [OPTION]
The best way to use crontab is with the options, which are:
l -l -- list the user's current crontab jobs
l -e -- edit the user's current crontab jobs
l -r -- remove the user's current crontab jobs
For example, to edit the crontab jobs for the user jlwallen, issue the command crontab -u jlwallen -e. You will then see that user's crontab jobs opened in the default text editor.
Edit the job as needed and then save the file. You can then list the user's crontab jobs with the command crontab -u jlwallen -l.
The grep command prints lines that match a pattern. This tool is useful on many levels. Usage is as follows:
grep [OPTIONS] PATTERN [FILE]
The Linux grep command helps admins to locate a specific line that, for example, includes the string wlan0 in a long configuration file named wireless. Relying on human capability would make this a drawn-out, difficult task. With the Linux command line, you issue grep as such
grep -n wlan0 wireless
When used with the -n option, grep includes the line number where the pattern is found. You can also use the -E option so that grep sees the PATTERN as a regular expression.
Your network may be protected by the best task-specific hardware you can buy. That doesn't mean you shouldn't have a solid understanding of one of the most powerful security tools available for the data center -- iptables. This is an incredibly complex Linux command that requires a significant investment of time to grasp. The basic structure of the command is:
iptables [-t table] [OPTION] chain rule-specification
To truly understand how to use iptables, you must first understand chains and tables. If you don't have a solid understanding of how chains and tables interrelate, start with the command man iptables and read up on the topic.
The kill command allows the Linux administrator to send a signal to a process. In order to use kill, you have to know which signal to send and the process ID (PID) to which you send the signal. The structure of the command is:
kill [OPTIONS] <PID>
To find what signals you can send to a process, issue the command kill -l. Most often, you will use kill -9 PID, where PID is the process to be killed, as the -9 signal is SIGKILL and safely shuts down the process. If you are unsure of the PID, but know the name of the process, you can always opt to use the killall command, such as killall -9 firefox to shut down Firefox processes.
The command lsof calls up a list of all open files. While there are quite a few other commands available for seeing all open files, this top Linux command allows you to see everything an admin needs. The problem here is that, without arguments, lsof displays an overwhelming amount of information. To limit the onslaught, try restricting by username:
lsof -u jlwallen
Another option is to limit lsof to listing only files opened on a certain port, such as:
lsof -i TCP:22
To see the status of modules in the Linux kernel, run the lsmod command. Effectively, lsmod lists out the contents in /proc/modules in a human readable format. A Linux admin easily troubleshoots server functionality issues by seeing what modules are currently loaded in the kernel. Networking down? Maybe the kernel module for your network interface has been dropped. Issue lsmod to see if that module is loaded. If not, you can always load it with the insmod command.
The mount command not only helps you mount file systems on Linux servers, it will list out what file systems are mounted and where. This command can be a real lifesaver when you have to troubleshoot where a drive has gone or if you need to add a new drive to a system.
When you run the command without arguments, mount will list out every mounted file system on your machine and that file system's mount point.
To mount a drive, use the command structure:
mount -t TYPE DEVICE DIRECTORY
Where TYPE is the file system type -- ext4, NTFS or another -- DEVICE is the physical device name of the drive, and DIRECTORY is where you want the drive mounted.
The ps command lists out all processes running on a Linux system. There are numerous ways to run the command as it will accept different command syntax. The easiest way to demonstrate the power of ps is to list out every process running as root in user format:
ps -U root -u root u
The output includes the username (root), the PID, CPU percentage used by a process, percentage of memory used by a process, when the process was started and the command.
To gain access to your current server, or to another server from the machine you are working on, use the secure shell (ssh). The command structure of secure shell is:
ssh -l USER -v ADDRESS_OF_DESTINATION
Where USER is the username to log in as and ADDRESS_OF_DESTINATION is the IP address or URL of the destination server to log into.
There is far more to this top Linux command than that. Read through the man page via man ssh carefully.
The best way to start or stop a service, such as networking, is the service command. The structure is as follows:
service script command [OPTIONS]
For example, to restart the networking service, issue the command
service networking restart
Linux administrators will, at some point, need to watch a log file as it is read to. For example, you are troubleshooting Apache and want to watch the error log in real time. The tail command makes this possible:
tail -f /var/log/apache2/error.log
Within the command window, the Linux OS displays everything written to the error log as it occurs. Tail is an incredibly powerful tool for troubleshooting any Linux server.
The w command shows Linux server admins who is logged into a server and what they are doing. Issue the w command without arguments to get all the information available to all users logged in, or specify a user like:
The above command will only output the information, available to the command, about user jlwallen.
These are some of the best Linux server commands for every system administrator. We could add plenty more to the list, but these commands will most certainly get you started on a route to mastering Linux server administration.
Systemd introduces a new method for file system control
Master the ip command
Create a Linux data center running these services
Dig Deeper on Linux servers
Jack Wallen asks:
Which Linux server commands do you find yourself using most?
0 ResponsesJoin the Discussion