Using the Linux Command Line - LINUX: Easy Linux For Beginners, Your Step-By-Step Guide to Learning The Linux Operating System and Command Line (2015)

LINUX: Easy Linux For Beginners, Your Step-By-Step Guide to Learning The Linux Operating System and Command Line (2015)

Chapter Seven: Using the Linux Command Line

In Chapter Four, we discussed about the Linux Command Line or the terminal and how you can access it from your desktop. In the previous chapters, you were also able to use simple commands on the terminal. Each GUI action has a command-line equivalent. In this chapter, we will talk more about the different commands that you can use in Linux and also study the different shell features.

Using the Shell Features

You have now seen the capabilities of using the Bash shell. Performing tasks on the command line take lesser time than doing it in the GUI. To further enjoy the convenience of using the CLI (command line interface), here are some shell features that you should use:

· Command Completion

Launch a terminal and try typing an unfinished command.

For example, type the word below and press the Tab key.

unam

Notice that Linux will automatically complete the word to formuname. Next, remove the rest of the letters and just leave the letteru, Linux will then display all the list of commands that start with the letter ‘u’. This feature makes it even faster for a user to type commands. You can even do this for filenames or directory names too. Type the first few letters of the filename and Linux will do the rest for you.

This is also helpful when you are trying to remember a command since Linux will list out all the commands starting with the letters that you put in. Combine this functionality with man and you should be able to locate the command that you are looking for.

· Command History

Linux makes it easier for users too with the command history feature. The system remembers commands you have recently typed in so you no longer need to retype. Simply use the arrow keys to view previous commands.

Here are some of the techniques that you can use to make the most out of this feature:

Keys to Use

What it does

Arrow Up/Down

Display the previous commands from the more recent going to the oldest entered

Arrow Right/Left

Moves the cursor one character to the right/left

CTRL key + A

Transfers cursor to the beginning of the line

CTRL key + E

Transfers cursor to the end of the line

Delete key

The character under the cursor is deleted

Backspace

The character to the left of the cursor is removed

CTRL key + R

Search for a particular command from the command history. After you use CTRL key + R, type the first few letters of the command that you want to use

Table 9: Command Line History Shortcuts

System administrators make good use of these features because it makes admin tasks easier and faster to complete. Try the techniques on some of the commands you’ve learned and see how cool it is to work using the command line.

Essential Linux Commands

As a new Linux enthusiast, you can perform many of the tasks using the GUI. However, if you do fancy learning more commands that you can use in the shell prompt, here’s a cheat sheet of the most important Linux commands.

Command

What it Does

Help Commands

info

Shows online information about a command

man

Shows details of a command

whatis

Shows a short description of a specific keyword

type

Shows the location of a command file

alias

Assign a command alias – especially useful for long commands

unalias

Remove command alias

Managing Files and Directories

cd

Change directory

pwd

Displays the current directory

ln

Create links to files and directories

touch

To trigger a file stamp update for a file

Finding Files

find

Search for a file based on name

whereis

Search for executable files

which

Search for files in the directories part of the PATH variable

Processing Files

dd

Copy lines of data

diff

Display the results of comparing two files

more

Show a text file one page at a time – display can only go forward

less

Show a text file one page at a time – display can only go forward and backwards

wc

Display the count of the number of characters, words, and lines in a file

cat

Show a text file in one output

cut

Get sections of text in a file

grep

Display results of finding expressions in a file

sed

Perform editing commands then copy to a standard output

split

Specify a size to break a file into

sort

Arrange the lines in a file

uniq

Keep unique lines in a file and delete duplicates

Compressing a File

compress

Use to compress a file

uncompress

If a file was compressed with a compress command, use this to decompress

gunzip

Use GNU Zip to decompress files

gzip

Compress files with GNU Zip

tar

Archive files with one or more directories

Date and Time

cal

Show the calendar for the specified month or year

date

Show/Set the current date and time

Managing Processes

bg

Run a program or a process in the background

free

Check for the free memory

kill

Stop a process

nice

Run a program with a low priority

ps

Show current running processes

top

Show list of CPU and memory utilization of processes

reboot

Restart the computer

shutdown

Turn off computer

Table 10: List of Important Linux Commands

Now, try out the commands above. If you are unsure of how to use the options for the commands, use the help commands (especially man and info) to find out more.

***

In this chapter, I gave you a list of commands and techniques that you can try in the command line. Continue on practicing with these commands and to research more online. In the succeeding chapter, we will learn about securing your operating system.