dark mode light mode Search Menu
Search

Linux Command List for Command Line Interfaces

jeff_golden on Flickr

The command line interface software tool is a key bit of technology every programmer should know. It's a mostly quick way to control a local or remote computer. This article provides a Linux command list for some of the most common commands you'll need to use and links to bigger lists you can print out.

While there are web-based interfaces to perform many tasks done with a command line tool, the difference really is the difference between a car with an automatic transmission (web-based, user interfaces) and a manual transmission (command line, keyboard driven). If you're serious, you learn both. Each tool has its overwhelming benefits.

Most people find they use the command line interface to perform a series of repetitive tasks. For example, I use Terminal, the command line tool on Macs, to log in to my server (the ssh command), update software on the server (yum), check processes running on the server (htop), backup files (tar), and so on.

It's also much faster to type commands, including time to look up some of the more obscure commands, than to use the control panel software on the server. Sometimes there is no option but command line software. For example, I can't use FTP software (FileZilla) to zip folders and files for backup but I can use FTP to download the remote zip file to my computer. So I zip the files with Terminal then use FTP to download the zip file from my server.

First we'll talk about how commands are structured, then get into the Linux command list.

Command Structure

Commands use a multi-part structure: the command and any switches and any folder or file path information. For example, this command:

tar cvf archive_name.tar dirname/

creates a tar (compressed) file with the name archive_name.tar in the folder location dirname. tar is the command name. cvf are switches to customize how archive_name.tar is to be created. Switches sometimes have a single dash before them, for example, -l or -p.

Don't worry about specifics of this command: tar is covered in detail below.

A Linux Command List

Here are some of the most frequent commands I use with a command line interface tool:

ssh

You have to connect to your server or computer, right? This first command to memorize, or have handy, is the command to connect to a remote computer. If you use a command line tool on your local computer, obviously you don't need this command.

ssh -l username www.yourwebsitedomain.com port

The command and parameters are:

  • ssh is the command name.
  • -l cues the ssh command a login name (username) immediately follows.
  • username is your login user name.
  • www.yourwebsitedomain.com is the URL (or IP address) of the remote computer.
  • port is the 2-4 digit port number the remote computer uses for ssh connections.

When you login with this ssh command, the remote computer will prompt you to enter the password. If you enter the correct password, the remote computer will start a secure connection.

Update, Install, and Remove Software

Commands to update and upgrade software vary based on the operating system of the computer. CentOS, for example, uses Yum. Ubuntu uses aptitude or similar software.

To update and upgrade a remote computer with CentOS as the operating system:

yum update app

The command and parameters are:

  • yum is both the command name and the name of the software used to download and install software on the remote computer.
  • update tells the computer to use yum to update and upgrade any software on the remote computer with an update available.
  • update can be replaced with install to install, for example, yum install htop will install htop monitoring software.
  • update can be replaced with remove to remove software, for example, yum remove htop will uninstall htop monitoring software.
  • app is the name of the application to be upgraded, installed, or removed. If no application is named, yum will upgrade the CentOS operating system and any installed software with pending upgrades.

To update a remote computer with Ubuntu as the operating system requires two steps, one to upload an update files and a second step to upgrade the software. This command will update the software on a computer running Ubuntu as the operating system:

sudo aptitude update

The command and parameters are:

  • sudo runs the aptitude command as the master or root account on the computer.
  • aptitude is both the command name and the name of the software used to update and upgrade software.
  • update tells the computer to use aptitude to update any software on the remote computer with an update available.

To then upgrade a remote computer with Ubuntu as the operating system:

sudo aptitude upgrade

The command and parameters are:

  • sudo runs the aptitude command as the master or root account on the computer.
  • aptitude is both the command name and the name of the software used to update and upgrade software.
  • upgrade tells the computer to use aptitude to upgrade any software on the remote computer with an update available.

tar

The tar command is used to backup folders and files into a single file compressed into the zip, tar, Gzip, or Bzip formats. Once compressed, the file can be moved off the computer if needed.

To create a new tar archive.

tar cvf filename.tar dirname/

To extract from an existing tar archive.

tar xvf filename.tar

The command and parameters are:

  • tar is the command name.
  • cvf and xvf specify whether to create ( c ) or extract ( x ) a compressed file.
  • filename.tar (or filename.gz or filename.bz2) is the file to create or extract.
  • if present, dirname/ is the name of a folder (directory) to compress into the specified filename file.

htop

You may need to install the htop software application. This software displays a list of all active processes currently running on the computer, as well as utilization information for the CPU and RAM.

The command is:

htop

When this command is entered, the htop application appears. Press the Ctrl and C keyboard keys to exit htop.

kill

One common use of the htop (and top) command is to identify computer processes that have run amok. You can stop, or kill, a process by using the kill command and the process ID number found by looking at the results of the htop or top command.

The command and parameters are:

kill pid
  • kill is the command name.
  • pid is the process ID number, usually retrieved from running the htop or top command.

ls

This command is the easiest way to navigate folders and files on a computer.

To display filesize in human readable format (e.g. KB, MB etc.,)

ls -lh

To order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr

ls -ltr

To list all files including hidden files:

ls -al

The command and parameters are:

  • ls is the command name
  • -lh is shorthand for list human.
  • -ltr is shorthand for list based on time in reverse order.
  • -al is shorthand for list all files.

cd

This command changes directories. Because you specify the directory folder name, the cd command is used with the ls command.

To start at the top of your computer folder structure, type this command:

cd \

Then type this command to see all the available folders:

ls -lh

Then type this command, where /foldername is based on what ls -lh reveals:

cd \foldername

The command and parameters are:

  • cd is the command name
  • \ is the root folder on the remote computer but you also can specify a folder path.

You also can type the whereis command to find the folder path to an application:

whereis app

The command and parameters are:

  • cd is the command name
  • app is the application name, for example, apache2.

df

If you find your server suddenly has no disk drive space, this command helps identify the largest files on the computer.

To display files based on file size:

df -h

The command and parameters are:

  • df is the command name
  • -h is shorthand for human-readable format to display command results.

restart

Sometimes I have to manually reboot the web server and database. Honestly, running this command always scares me: what if the server breaks? But it has worked every time.

To restart an application in Ubuntu:

sudo /etc/init.d/app restart

The command and parameters are:

  • restart is the command name.
  • sudo runs the command as the administrator on the remote computer.
  • /etc/init.d/ is the path to the application used to restart other applications.
  • /app is the name of the application to restart, for example, /apache2 or /mysql

To restart an application in CentOS:

restart app

The command and parameters are:

  • restart is the command name.
  • app is the name of the application to restart, for example, apache2 or mysql

Learn More

Command Quick Reference Guides

http://www.scribd.com/doc/2203531/UnixLinux-Commands-Quick-Reference
http://unix-commands.net/

Unix Man (Manual) Pages

A definition and short history of Unix command documentation.
https://en.wikipedia.org/wiki/Man_page

How to Read Man Pages

A tutorial from McGill University.
http://www.cs.mcgill.ca/~guide/help/man.html

FreeBSD Man Pages

A searchable set of man pages for a wide range of Unix operating systems in addition to FreeBSD.
http://www.freebsd.org/cgi/man.cgi

Install and Upgrade Software in Ubuntu

http://www.howtogeek.com/63997/how-to-install-programs-in-ubuntu-in-the-command-line/

CentOS Web Site

https://www.centos.org/

Ubuntu Web Site

http://www.ubuntu.com/

Related Posts