Skip to main content

Command Palette

Search for a command to run...

Basic Linux Commands

Updated
3 min read
Basic Linux Commands
A

I am a technical writer and software engineer

This is a beginner's guide to some of the most used Linux commands.

pwd

The command is used in operating systems to display the current working directory. pwd stands for print working directory. It displays the absolute path, which is the full path from the root directory to the current directory.

$pwd

The command has three tags as shown below:

ls

The ls command, which stands for list is a command in the terminal used to list files and directories.

$ls

There are several tags you can add to the command. The following are some of the most popular:

Syntax:

$ls -l
  • -l: it displays files in long format. You can read the permissions, ownership, size, and modification dates.
$ls -a
  • -a: Lists all files including the hidden files that start with a dot “.”
$ls -r
  • -r: Lists files in reverse order.
$ls -R
  • -R: Lists files recursively, showing contents of subdirectories as well.

cd

The cd command, change directory is used to change the current working directory to a specified folder.

$cd <dirname>

To go back to the parent directory of the current working directory, we add two dots like this cd ..

To return two folders, use the following syntax cd ../.. Getting back three folders would be cd ../../..

more

The more command displays the contents of a file in a paginated way. You view text one screenful at a time, making it ideal for handling or reading large files. Remember you have to input the more command to view the next screen.

$more sample.txt

clear

As the name suggests, you use it to clear the terminal.

mkdir

The mkdir command is used to create a new directory or folder in an existing working directory.

$mkdir <dirname>

echo

The echo command displays the specified text to the terminal. The code below will print Hello world to the terminal.

$echo Hello world

You can also use it to print text to a file. We can add these Linux commands to the README.md file using this syntax:

$echo these Linux commands >> README.md

touch

The touch command is used to create a file

$touch sample.txt

--help

The command is used to display what a command can do. For example, you can use it to see what mv command can do.

$mv --help

cp

The cp command is used to copy a file to a new destination. It takes the syntax cp <source_file> <new_file>. Contents in source_file will appear in the new_file.

$cp sample1.txt sample2.txt

mv

The mv command is used to move or rename a file. If you want to move a file to another directory, you use the mv <Filename> <Direcorty> syntax.

$mv sample.txt <dirname>

You use the mv<old_Name> <New_Name> syntax to rename a file.

$mv white.txt blue.txt

find

The find command is a command line utility for displaying a file hierarchy. You can use it to find files and folders and perform operations on them.

It allows you to search for a file or folder by name, creation or modification date, ownership, and permissions.

You can use the find -name <filename> syntax to show where a file is located.

// The command will show where the sample.txt file is located
$find -name sample.txt

rm

The rm command is used to remove a file from a working directory.

$rm sample.txt

rmdir

This variation of the rm command is used to remove directories from a working directory.

$rmdir <dirname>

rm -r

Used to remove directories and their contents recursively. It means it will delete not only the specified directory but also all files and subdirectories within it.

$rm -r <dirname>

More from this blog

withallan

17 posts

Documenting my software development journey