Basic Commands

Prompt

Learn the common basic commands used on the Linux command line.

Tutorial Video

Walk-Through

This challenge will give you experience running basic Linux commands. To solve these challenges, you will be using a Linux Command Line Interface (aka terminal or shell).

Background:

When running a Linux command, different options can be provided to get a specific behavior. One of these is arguments. Arguments always follow the name of the program and could provide information such as the file you wish to run the program on. You may also see arguments referred to as “options” or “flags”.

The syntax for arguments is set by the author of the program. You can often type in the name of the command followed by --help to get information on how to use the program.

For some programs, you can use the man (manual) program to pull up the instructions. If a program has a manual entry, you can open the manual by typing man followed by the name of the program.

Below is the man page for the ls command. You can view it by entering man ls into the command line:

Enter
Enter man followed by the command name to get the manual page for a specific command.

If the -a argument is used with the ls command, all of the files, even the hidden ones which start with . will be listed.

The output of
The output of ls -a

Multiple arguments can be added together. The -l argument will list the read, write, execute permissions, the users who can access the file, the file size, and the date modified.

The output of
The output of ls -la Some common Linux commands are listed in a table below . Read the manual pages to learn more about different arguments. Understanding how commands can be used is a key part of using Linux.

Guide:

  • Standard Streams
  • The output of one program can be used as the input to another program. This utilizes a system in Linux called standard streams. There are three standard streams in Linux:

    standard input (stdin) - data going into a program

    standard output (stdout) - data coming out of a program

    standard error (stderr) - errors coming out of a program

The greater than symbol is used to redirect stdout data of a command to a file. For example, echo “I Love Linux” > linux.txt will create a file named “linux.txt” (if it doesn’t already exist) and add “I Love Linux” to it.

Entering echo “Penguins are Cool” > linux.txt will overwrite the pre-existing linux.txt file with the new contents.

Using two greater than symbols will allow contents to be added to the current file contents. echo “I Love Linux” >> linux.txt

The use of the greater than symbol is important to how output is written to files.
The use of the greater than symbol is important to how output is written to files.

The less than symbol can be used in a variety of ways. One is to redirect contents of a file (or stdin) to a certain command. Shown below is the stdout of names.csv using the cat command. But the contents of the names.csv file can be re-directed to the cut command. cut -d ',' -f 1 is used below to show the contents of the first column of a file which is determined by using a comma and the separator, or delimiter, of the columns.

This screenshot shows the stout of the cat command on the names.csv file.
This screenshot shows the stout of the cat command on the names.csv file.
This screenshot shows the names.csv file used as stdin for the cut command. Only the first names in the file are shown as a result of the command.
This screenshot shows the names.csv file used as stdin for the cut command. Only the first names in the file are shown as a result of the command.
  • Stringing Commands
  • The stdout of one program can be made into the stdin of another program. This is done by using the pipe operator, which is represented with the vertical bar, and allows you string commands together.

    For example, to find the number of people with the first name of “Jordan” from the names.csv file, try using cut -d "," -f 1 < names.csv | grep Jordan. Here, the grep command takes the output from the first portion of the command and only outputs strings that match “Jordan”:

image

It would be easier if a number was given as an output instead of needing to count. What if there were thousands of people named Jordan in the file? The number of lines that are output can be counted using wc -l:

The output of
The output of cut -d ‘,’ -f1 <names.csv | grep Jordan | wc -l is hidden

Chaining multiple Linux commands can become useful in manipulating and analyzing data. Practice running different commands using these different customization tools. Below is a table of common Linux commands.

Please note that within the terminals provided by Cyber Skyline, you will only have access to the tools that are pre-installed. You may not be able to install tools that are not already included in the terminal.

You should become comfortable and will be expected to search online for command line tools that can help you accomplish a task from the terminal. You can also use the built-in help or manual pages to learn how to use a tool.

Program
Description
Example
Example Description
ls
“list” - Display files and directories
ls /
Display all files and directories in the “/” folder
cat
“concatenate” - Print out the contents of a file
cat example.txt
Print out the contents of the “example.txt” file
cd
“change directories” - Switch the current folder that the command line is working on
cd /
Change the terminal to the “/” folder
mv
“move” - Move a file or folder from one location to another or rename a file
mv /root/old.txt /tmp/new.txt
Move the “old.txt” from the the “/root” folder to the “/tmp” folder and rename the file to “new.txt”
cp
“copy” - Make a copy of a file or folder
cp original.txt copy.txt
Makes a duplicate of “original.txt” named “copy.txt”
mkdir
“make directory” - Makes a new folder
mkdir test
Makes a new folder named “test”
rm
“remove” - Deletes a file or folder permanently
rm example.txt
Permanently deletes the “example.txt” file
pwd
“print working directory” - Displays the absolute file path of the directory the command line is currently in
pwd
Prints the full path of the current directory
history
Prints a chronological log of the past commands that were entered
history
Prints the log of past commands
echo
Prints the provided string to standard output
echo "test"
Prints the string, “test” to standard output
grep
“global regular expression print” - search for text that matches a specific pattern
grep match example.txt
Prints lines that contain the text “match” in example.txt
wc
“word count” - Gets a line count (followed by a word count and a byte count) of a file or text stream
wc example.txt
Prints the number of lines in example.txt
cut
Extract column(s) from a file or text stream. Columns must be delineated by a consistent character
cut example.txt -d , -f 2
Prints out the column at index 2 from example.txt
sort
Sorts the lines from a file or text stream.
sort example.txt
Prints the sorted output of the lines from example.txt
uniq
“Unique” - Prints the result of removing duplicate lines from a file or text stream
uniq example.txt
Prints out the result of removing any duplicate lines from example.txt.
man
“manual” - Displays the manual for a program
man echo
Display the manual for the “echo” program

Useful tools for learning Linux:

Questions

1. What character can you use to redirect the output of one program as the input to another program

Search online for this question as-is. Make sure to find an answer that is specific to redirecting from output from one program to another program (and not to a file)

2. What character can you use the redirect the output of a program to a file?

Search online for this question as-is. Make sure to find an answer that is specific to redirecting from output from one program to a file (and not to another program)

3. How many people have a first name of Jordan in names.csv?

cut -d "," -f 1 < names.csv | grep Jordan | wc -l

©️ 2025 Cyber Skyline. All Rights Reserved. Unauthorized reproduction or distribution of this copyrighted work is illegal.