Linux – The Command Line

Bourne Again Shell (BASH)

The ampersand suffix, is for starting a program, in the background. For example,

firefox &

Control-Z is for exiting, from a program that has control of the terminal.

The jobs command will list the currently running jobs.

Issue the fg (foreground) to give a job, control of the terminal.

Issue the bg (background) to place a job, in the background.

The printenv will list all of the environment variables.

To show the value, of an environment variable, issue the statement below:

printenv variable

To set the value, of an environment variable, issue the statement below:

variable=value

The export command will pass a variable value to the running processes.

export variable
export variable=value

Use the unset command, to remove an environment variable.

unset variable

Pipes

The output of one program, is used as input to the other.

printenv | grep Term

Redirection

A program’s output is sent to a file.

printenv > /tmp/directory_listing

To append to a file:

echo "Environment printing is complete. >> /tmp/directory_listing

To use a file as input:
grep “root” < /etc/passwd

Filename Expansion

The asterisk is for all filenames, and the question mark is for a single character. Use the backslash, to escape, these characters.

Environment Variables as Parameters

Precede the variable name with $.

Multiple Commands

Separate multiple commands with semicolons (;).

Documentation

The man command is the older way, of viewing information, about a particular program.

man program_name
info program_name

Change Ownership

The chown command is for changing the file or directory ownership.

chown [-R] username filename

Change Group

The chgrp command is for changing the file or directory group.
chgrp [-R] groupname filename

Change Mode

The chmod command is for changing the file or directory permission.

chmod permission filename

File Management

Copy File

To copy files, use the cp command.

Move File

To move files, use the mv command.

Compress File

To compress files, use the gzip command.

Create Directory

The mkdir command is for creating directories. The -p option is for parent directories.

Remove Directory

The rmdir command is for removing directories. The -p option is for parent directories.

Print Working Directory

The pwd command is for printing the working directory.

Cat

The cat command is for displaying file content.

More

The more command is for displaying information, screen full.

more /etc/passwd
ls | more

su

The su command is for switching user.

su - username

Reference

  1. Soyinka, A. (2009). Linux Administration: A Beginner's Guide. McGraw-Hill.

Leave a comment