10 basic Linux commands for beginners

This article explains some of the most used Linux commands and their basic usage. All these commands should be entered at the command prompt and you must press the ENTER button to execute the desired command. Please note that all Linux commands are case sensitive.

cat – Shows the contents of files to the screen.
Usage:

# cat file.txt
# Hello World

Also this command can be used to count the number of lines, words and characters in a file:

cat | wc -l

– number of lines

cat | wc -w

– number of words

cat | wc -c

– number of characters
To search for a word in a file you can use:

# cat | grep <some word>

cd – Change directory
the ‘cd’ command should be used followed by the name of a directory including the full path to that directory. If you execute ‘cd’ without arguments the working directory will be switched to your ‘home directory’.
Usage:

# cd /path/to/directory_name/

To move one directory up, you can use the shortcut command:

# cd ..

cp – Copy files and directories
Usage:

# cp <SOURCE> <DESTINATION>

Example:

# cp /root/file /tmp/

With this command you will make a copy of ‘file’ located in the ‘/root’ directory to the ‘/tmp’ directory if it does not exist. It will overwrite it in case the ‘file’ already exists.

df – Check the amount of free disk space on the filesystems.
Usage:

# df

To get a more easily readable (human-readable) output of the command use:

# df -h

free – Gives information about used and free memory and swap space on a Linux machine.
Usage:

# free

The -b option shows the amount of memory in bytes; the -k option (set by default) shows it in kilobytes; the -m options shows it in megabytes.

Most common options for this command are:
-f : ignore nonexistent files, never prompt
-r : remove directories and their contents recursively
-v : explain what is being removed
Note: Always double check before removing any file or directory.

ls – Displays a list of files and directories in a specific directory.
If you enter just ‘ls’ without specifying a directory, it will display a list of files and directories in the working directory.
Usage:

# ls

Most common options for this command are:
-a : shows all files and folders including the hidden ones.
-l : use a long listing format

mv – Moves files and directories from one directory to another or renames a file or directory.
Usage:
Move ‘file’ from ‘/root’ to ‘/tmp’ directory

# mv /root/file /tmp/

Rename ‘file1’ to ‘file2’

# mv file1 file2

passwd – change user password
Usage:

# passwd <USERNAME>

If you execute just ‘passwd’ without specifying the username, you will change your root password.
Note: Never use passwords that are easily guessable, such as passwords based upon names, street addresses, dictionary words, significant dates, etc… A strong password consists of a combination of letters (both upper and lower case), numbers and special characters and it should be at least 8 characters long.

mkdir – Creates directory(ies) if they don’t already exist
Usage:

# mkdir <NEW_DIRECTORY>

Example:

# mkdir /var/www/<NEW_DIRECTORY>

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.