14 Must-Know Linux Commands
14 Must-Know Linux Commands
In this guide
In this e-guide:
The top Linux commands for
server administrators
As a Linux administrator, having a strong grasp of the Linux
The Linux IP command makes
network config easy command line is key; it not only increases your proficiency and
speed across shells, but ultimately allows you to use that same
Linux mount command reveals
storage device access path knowledge to manage any Linux distribution.
Getting more PRO+ exclusive
content
In this exclusive Linux e-guide, discover the top 14 must-know
Linux commands for server administrators, with 2 bonus
articles giving in-depth knowledge on the benefits of the “IP”
and “Mount” commands.
Page 1 of 25
In this guide The top Linux commands for server
The top Linux commands for
administrators
server administrators
http://searchdatacenter.techtarget.com/tip/The-top-Linux-commands-for-server-
The Linux IP command makes
network config easy administrators
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.
Cd
The cd command should really be considered part of starting out with Linux
server administration. The cd command moves an admin about the directory
Page 2 of 25
In this guide 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
The top Linux commands for
server administrators your home directory, you could just enter cd Downloads.
The Linux IP command makes The cd command is helpful when you need to back out of a directory. For
network config easy
example, you are in Downloads, and you want to back out to ~/. Simply issue
Linux mount command reveals
storage device access path 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
Getting more PRO+ exclusive
content ~/Downloads/A/B/C, you could return to ~/Downloads with the command cd
../../../.
Cp
This is a top Linux command for server admins because it allows you to copy
files and directories. The usage is as following:
Page 3 of 25
In this guide 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.
The top Linux commands for
server administrators Issue the command as cp -p ~/FILEA ~/Downloads/FILEB to take advantage of
this option.
The Linux IP command makes
network config easy
Crontab
Linux mount command reveals
storage device access path
The Linux crontab command allows an administrator to set up scheduled tasks
Getting more PRO+ exclusive on a system. The command is used as such:
content
or
The best way to use crontab is with the options, which are:
Page 4 of 25
In this guide 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
The top Linux commands for
server administrators default text editor.
The Linux IP command makes Edit the job as needed and then save the file. You can then list the user's
network config easy
crontab jobs with the command crontab -u jlwallen -l.
Linux mount command reveals
storage device access path
Grep
Getting more PRO+ exclusive
content
The grep command prints lines that match a pattern. This tool is useful on many
levels. Usage is as follows:
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
Page 5 of 25
In this guide 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
The top Linux commands for
server administrators regular expression.
Linux mount command reveals Your network may be protected by the best task-specific hardware you can buy.
storage device access path
That doesn't mean you shouldn't have a solid understanding of one of the most
Getting more PRO+ exclusive powerful security tools available for the data center -- iptables. This is an
content
incredibly complex Linux command that requires a significant investment of time
to grasp. The basic structure of the command is:
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.
Kill
Page 6 of 25
In this guide 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
The top Linux commands for
server administrators (PID) to which you send the signal. The structure of the command is:
Linux mount command reveals To find what signals you can send to a process, issue the command kill -l. Most
storage device access path
often, you will use kill -9 PID, where PID is the process to be killed, as the -9
Getting more PRO+ exclusive signal is SIGKILL and safely shuts down the process. If you are unsure of the
content
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.
Lsof
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
Page 7 of 25
In this guide Another option is to limit lsof to listing only files opened on a certain port, such
as:
The top Linux commands for
server administrators
lsof -i TCP:22
The Linux IP command makes
network config easy
Lsmod
Linux mount command reveals
storage device access path To see the status of modules in the Linux kernel, run the lsmod command.
Getting more PRO+ exclusive Effectively, lsmod lists out the contents in /proc/modules in a human readable
content
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.
Mount
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.
Page 8 of 25
In this guide 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.
The top Linux commands for
server administrators
To mount a drive, use the command structure:
The Linux IP command makes
network config easy
mount -t TYPE DEVICE DIRECTORY
Linux mount command reveals
storage device access path Where TYPE is the file system type -- ext4, NTFS or another -- DEVICE is the
Getting more PRO+ exclusive physical device name of the drive, and DIRECTORY is where you want the
content
drive mounted.
Ps
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
Page 9 of 25
In this guide 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
The top Linux commands for
server administrators started and the command.
Linux mount command reveals To gain access to your current server, or to another server from the machine
storage device access path
you are working on, use the secure shell (ssh). The command structure of
Getting more PRO+ exclusive secure shell is:
content
There is far more to this top Linux command than that. Read through the man
page via man ssh carefully.
Service
The best way to start or stop a service, such as networking, is the service
command. The structure is as follows:
Page 10 of 25
In this guide service script command [OPTIONS]
The top Linux commands for For example, to restart the networking service, issue the command
server administrators
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.
W command
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: w jlwallen
Page 11 of 25
In this guide The above command will only output the information, available to the command,
about user jlwallen.
The top Linux commands for
server administrators
These are some of the best Linux server commands for every system
The Linux IP command makes administrator. We could add plenty more to the list, but these commands will
network config easy
most certainly get you started on a route to mastering Linux server
Linux mount command reveals
storage device access path administration.
To start analyzing the network configuration on a Linux box, you'll need to find
out what it currently uses. The Linux ip command is the way to go. This
Page 12 of 25
In this guide command offers an extensive range of options to discover the current network
configuration of a machine.
The top Linux commands for
server administrators
The ip command works with arguments to specify what exactly displays. Use ip
The Linux IP command makes addr to find out about current networking, ip link to analyze status of network
network config easy
interfaces and ip route to see the routing table. All of these commands pair with
Linux mount command reveals
storage device access path the show command. So ip addr show (see Listing 1) will display current address
configuration, ip link show lets you see statistics about a link, and ip route show
Getting more PRO+ exclusive
content gives the current routing table.
Listing 1. This output is an example of using the ip addr show command to see
current address configuration.
Page 13 of 25
In this guide valid_lft forever preferred_lft forever
Page 14 of 25
In this guide In its output, the ip addr show command shows all interfaces that exist on your
Linux network config. Listing 1 shows two network interfaces. The interface
The top Linux commands for
server administrators named lo is the loopback interface, used for processes that communicate via
the IP protocol. The important interface in the listing is eth0, the first Ethernet
The Linux IP command makes
network config easy interface that was found on this server. On the interface you can see three
important parts of the configuration: the MAC address, indicated as link/ether,
Linux mount command reveals
storage device access path the IPv4 address as well as the IPv6 address. Verify that this information
Getting more PRO+ exclusive matches what should be used on your server.
content
Not all Linux systems will show eth0 as the standard Ethernet network card.
Modern Linux kernels use the biosdevname utility, which aims to make it easier
to identify a specific network interface. The device name is unique, such as
eno1677736, but also is not standardized between different Linux systems. So if
you see another device name that isn't eth0, don't panic -- that is expected and
normal behavior.
Another useful interface to monitor the current Linux network config is the ip -s
link command. This command shows current statistics about packets sent over
a network interface. Linux's ip -s link (see Listing 2) helps if you're experiencing
Page 15 of 25
In this guide problems on a network interface and want to make sure that no packets drop in
transit.
The top Linux commands for
server administrators
Listing 2. This ip -s link output allows an administrator to analyze network
The Linux IP command makes packet statistics.
network config easy
Getting more PRO+ exclusive 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state
content
UNKNOWN mode DEFAULT
97196 270 0 0 0 0
97196 270 0 0 0 0
Page 16 of 25
In this guide link/ether 52:54:00:95:7f:5f brd ff:ff:ff:ff:ff:ff
The top Linux commands for RX: bytes packets errors dropped overrun mcast
server administrators
Listing 3: Output from the Linux ip route show command helps verify routing
table configuration.
Page 17 of 25
In this guide 192.168.122.0/24 dev eth0 proto kernel scope link src 192.168.122.210
metric 100
The top Linux commands for
server administrators
What about ifconfig?
The Linux IP command makes
network config easy
The ifconfig command that shows current networking information on Linux
Linux mount command reveals servers has been deprecated for over a decade. What's wrong about using it?
storage device access path
The Linux networking stack has changed significantly since ifconfig's heyday --
Getting more PRO+ exclusive you will miss information on today's networks if working with ifconfig. The ip
content
command was introduced to manage all aspects of Linux network configuration
as the stack changed, and development on the ifconfig command was
discontinued.
Linux ifconfig is not accurate, for example, when the administrator wants to work
with network cards configured with additional IP addresses. If the additional IP
address was configured using the same routines as the ip command uses, you
won't see them using ifconfig. For that reason, on many recent Linux
distributions, the ifconfig command is no longer included.
Page 18 of 25
In this guide Linux mount command reveals storage
The top Linux commands for
device access path
server administrators
Linux file and directory access works through one large file system that starts on
the top with the root directory. This file system tree does not necessarily reside
on a single storage device. Administrators use the Linux mount command to
integrate multiple storage devices into the directory structure.
In Windows, storage device access is oriented to the device. You'll see optical
drives, USB keys and hard drives as separate devices in the Windows Explorer
overview, making it easy to access a new device.
Page 19 of 25
interfaces. If you insert a storage device in a server USB port, nothing will
In this guide
happen.
The top Linux commands for
server administrators To mount storage onto Linux servers, first decide which directory should access
the device. Then use the Linux mount command to activate it. The mount
The Linux IP command makes
network config easy command typically looks like mount /dev/sdb1 /mnt, where /dev/sdb1 is the
device and /mnt is the directory where you want to mount it.
Linux mount command reveals
storage device access path You have to know the exact name of the device to use the Linux mount
Getting more PRO+ exclusive
command. It usually starts with /dev/sd, in which sd can be interpreted as
content storage device. After sd, you'll see another letter, which is assigned when the
device is connected: /dev/sda is the first disk, then /dev/sdb is the second disk.
The number following the letter denotes the partition. As devices often, but not
always, only have one partition, you'll normally only see the number 1 assigned
to it.
Based on the previously mentioned information, you should be able to find the
name of the device that you want to mount onto the Linux server. But if you
don't, use the Linux prompt to find the information. Right after you have
connected the device to your computer, use the dmesg command. This
command shows recent kernel activity, including newly detected devices (see
listing 1).
Page 20 of 25
[18435.325715] usb 1-1: new high-speed USB device number 2 using ehci-pci
In this guide
[18435.504105] usb 1-1: New USB device found, idVendor=abcd,
The top Linux commands for
server administrators idProduct=1234
The Linux IP command makes [18435.504109] usb 1-1: New USB device strings: Mfr=1, Product=2,
network config easy
SerialNumber=3
Linux mount command reveals
storage device access path [18435.504110] usb 1-1: Product: UDisk
Page 21 of 25
[18436.730316] sd 33:0:0:0: [sdb] Write Protect is off
In this guide
[18436.730319] sd 33:0:0:0: [sdb] Mode Sense: 0b 00 00 08
The top Linux commands for
server administrators
[18436.732437] sd 33:0:0:0: [sdb] No Caching mode page found
The Linux IP command makes
network config easy [18436.872492] sd 33:0:0:0: [sdb] Assuming drive cache: write through
Getting more PRO+ exclusive [18436.917099] sd 33:0:0:0: [sdb] Assuming drive cache: write through
content
[18436.979578] sdb: sdb1
After dmesg has shown the name of the device, find out how many partitions
are available on the device by using cat /proc/partitions. This command shows
all partitions that are commonly known to the Linux kernel (see listing 2). This
information means you can use the mount command for the correct device. The
dmesg command also shows a lot of information about devices that you
probably don't really want to know about, which you can ignore.
Page 22 of 25
Listing 2. Use cat /proc/partitions to see how many partitions exist on a device.
In this guide
[root@server2 ~]# cat /proc/partitions
The top Linux commands for
server administrators
major minor #blocks name
The Linux IP command makes
network config easy 2 0 4 fd0
11 0 1048575 sr0
8 16 7808000 sdb
8 17 2318236 sdb1
Linux servers require you to dismount devices before removing them from the
system. The umount command dismounts devices, and only works if no files on
Page 23 of 25
the device are in use. Use the umount /dev/sdb1 command to disconnect the
In this guide
/dev/sdb1 device that was mounted in the preceding command.
The top Linux commands for
server administrators
Page 24 of 25
In this guide Getting more PRO+ exclusive content
The top Linux commands for This e-guide is made available to you, our member, through PRO+ Offers—a
server administrators
collection of free publications, training and special opportunities specifically
The Linux IP command makes gathered from our partners and across our network of sites.
network config easy
PRO+ Offers is a free benefit only available to members of the TechTarget
Linux mount command reveals
network of sites.
storage device access path
© 2016 TechTarget. No part of this publication may be transmitted or reproduced in any form or by any means without
written permission from the publisher.
Page 25 of 25